mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-19 23:02:21 +08:00
完善mp4推流
This commit is contained in:
@@ -33,10 +33,12 @@ using namespace toolkit;
|
||||
namespace mediakit {
|
||||
|
||||
#ifdef ENABLE_MP4V2
|
||||
MediaReader::MediaReader(const string &strVhost,const string &strApp, const string &strId) {
|
||||
GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
|
||||
|
||||
auto strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
|
||||
MediaReader::MediaReader(const string &strVhost,const string &strApp, const string &strId,const string &filePath ) {
|
||||
auto strFileName = filePath;
|
||||
if(strFileName.empty()){
|
||||
GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
|
||||
strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
|
||||
}
|
||||
|
||||
_hMP4File = MP4Read(strFileName.data());
|
||||
if(_hMP4File == MP4_INVALID_FILE_HANDLE){
|
||||
@@ -302,15 +304,19 @@ void MediaReader::seek(uint32_t iSeekTime,bool bReStart){
|
||||
|
||||
|
||||
|
||||
MediaSource::Ptr MediaReader::onMakeMediaSource(const string &strSchema,const string &strVhost,const string &strApp, const string &strId){
|
||||
MediaSource::Ptr MediaReader::onMakeMediaSource(const string &strSchema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const string &filePath,
|
||||
bool checkApp ){
|
||||
#ifdef ENABLE_MP4V2
|
||||
GET_CONFIG_AND_REGISTER(string,appName,Record::kAppName);
|
||||
|
||||
if (strApp != appName) {
|
||||
if (checkApp && strApp != appName) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
MediaReader::Ptr pReader(new MediaReader(strVhost,strApp, strId));
|
||||
MediaReader::Ptr pReader(new MediaReader(strVhost,strApp, strId,filePath));
|
||||
pReader->startReadMP4();
|
||||
return MediaSource::find(strSchema,strVhost,strApp, strId, false);
|
||||
} catch (std::exception &ex) {
|
||||
|
||||
@@ -41,19 +41,56 @@ namespace mediakit {
|
||||
class MediaReader : public std::enable_shared_from_this<MediaReader> ,public MediaSourceEvent{
|
||||
public:
|
||||
typedef std::shared_ptr<MediaReader> Ptr;
|
||||
MediaReader(const string &strVhost,const string &strApp, const string &strId);
|
||||
virtual ~MediaReader();
|
||||
static MediaSource::Ptr onMakeMediaSource(const string &strSchema,const string &strVhost,const string &strApp, const string &strId);
|
||||
public:
|
||||
bool seekTo(uint32_t ui32Stamp) override;
|
||||
bool close() override;
|
||||
|
||||
/**
|
||||
* 流化一个mp4文件,使之转换成RtspMediaSource和RtmpMediaSource
|
||||
* @param strVhost 虚拟主机
|
||||
* @param strApp 应用名
|
||||
* @param strId 流id
|
||||
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
|
||||
*/
|
||||
MediaReader(const string &strVhost,const string &strApp, const string &strId,const string &filePath = "");
|
||||
/**
|
||||
* 开始流化MP4文件,需要指出的是,MediaReader对象一经过调用startReadMP4方法,它的强引用会自持有,
|
||||
* 意思是在文件流化结束之前或中断之前,MediaReader对象是不会被销毁的(不管有没有被外部对象持有)
|
||||
*/
|
||||
void startReadMP4();
|
||||
|
||||
/**
|
||||
* 设置时移偏移量
|
||||
* @param ui32Stamp 偏移量,单位毫秒
|
||||
* @return
|
||||
*/
|
||||
bool seekTo(uint32_t ui32Stamp) override;
|
||||
|
||||
/**
|
||||
* 关闭MediaReader的流化进程,会触发该对象放弃自持有
|
||||
* @return
|
||||
*/
|
||||
bool close() override;
|
||||
|
||||
/**
|
||||
* 自动生成MediaReader对象然后查找相关的MediaSource对象
|
||||
* @param strSchema 协议名
|
||||
* @param strVhost 虚拟主机
|
||||
* @param strApp 应用名
|
||||
* @param strId 流id
|
||||
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
|
||||
* @param checkApp 是否检查app,防止服务器上文件被乱访问
|
||||
* @return MediaSource
|
||||
*/
|
||||
static MediaSource::Ptr onMakeMediaSource(const string &strSchema,
|
||||
const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const string &filePath = "",
|
||||
bool checkApp = true);
|
||||
#ifdef ENABLE_MP4V2
|
||||
private:
|
||||
void seek(uint32_t iSeekTime,bool bReStart = true);
|
||||
inline void setSeekTime(uint32_t iSeekTime);
|
||||
inline uint32_t getVideoCurrentTime();
|
||||
void startReadMP4();
|
||||
inline MP4SampleId getVideoSampleId(int iTimeInc = 0);
|
||||
inline MP4SampleId getAudioSampleId(int iTimeInc = 0);
|
||||
bool readSample(int iTimeInc, bool justSeekSyncFrame);
|
||||
|
||||
Reference in New Issue
Block a user