Commit 46be8a38 by xiongziliang

重写MP4点播

parent f03365ef
media-server @ 9f12aee3
Subproject commit 737b8d852eeb1a36bc77854f327fbbef7cfb81be Subproject commit 9f12aee385993d14b18a1d773be5eedbbe4fa2c2
...@@ -40,7 +40,7 @@ set(ENABLE_MYSQL false) ...@@ -40,7 +40,7 @@ set(ENABLE_MYSQL false)
set(ENABLE_MP4V2 true) set(ENABLE_MP4V2 true)
set(ENABLE_FAAC false) set(ENABLE_FAAC false)
set(ENABLE_X264 false) set(ENABLE_X264 false)
set(ENABLE_MP4RECORD true) set(ENABLE_MP4 true)
#添加两个静态库 #添加两个静态库
if(ENABLE_HLS) if(ENABLE_HLS)
...@@ -52,9 +52,9 @@ else() ...@@ -52,9 +52,9 @@ else()
endif() endif()
if(ENABLE_MP4RECORD) if(ENABLE_MP4)
message(STATUS "ENABLE_MP4RECORD defined") message(STATUS "ENABLE_MP4 defined")
add_definitions(-DENABLE_MP4RECORD) add_definitions(-DENABLE_MP4)
list(APPEND LINK_LIB_LIST mov flv) list(APPEND LINK_LIB_LIST mov flv)
endif() endif()
...@@ -87,7 +87,7 @@ if(ENABLE_HLS) ...@@ -87,7 +87,7 @@ if(ENABLE_HLS)
endif(WIN32) endif(WIN32)
endif() endif()
if(ENABLE_MP4RECORD) if(ENABLE_MP4)
aux_source_directory(${MediaServer_Root}/libmov/include src_mov) aux_source_directory(${MediaServer_Root}/libmov/include src_mov)
aux_source_directory(${MediaServer_Root}/libmov/source src_mov) aux_source_directory(${MediaServer_Root}/libmov/source src_mov)
include_directories(${MediaServer_Root}/libmov/include) include_directories(${MediaServer_Root}/libmov/include)
......
...@@ -43,10 +43,9 @@ INCLUDE_DIRECTORIES(${MediaKit_Root}) ...@@ -43,10 +43,9 @@ INCLUDE_DIRECTORIES(${MediaKit_Root})
set(ENABLE_HLS true) set(ENABLE_HLS true)
set(ENABLE_OPENSSL true) set(ENABLE_OPENSSL true)
set(ENABLE_MYSQL false) set(ENABLE_MYSQL false)
set(ENABLE_MP4V2 true)
set(ENABLE_FAAC false) set(ENABLE_FAAC false)
set(ENABLE_X264 false) set(ENABLE_X264 false)
set(ENABLE_MP4RECORD true) set(ENABLE_MP4 true)
set(ENABLE_RTPPROXY true) set(ENABLE_RTPPROXY true)
set(LINK_LIB_LIST zlmediakit zltoolkit) set(LINK_LIB_LIST zlmediakit zltoolkit)
...@@ -70,15 +69,6 @@ if (MYSQL_FOUND AND ENABLE_MYSQL) ...@@ -70,15 +69,6 @@ if (MYSQL_FOUND AND ENABLE_MYSQL)
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES}) list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
endif () endif ()
#查找MP4V2是否安装
find_package(MP4V2 QUIET)
if (MP4V2_FOUND AND ENABLE_MP4V2)
include_directories(${MP4V2_INCLUDE_DIR})
list(APPEND LINK_LIB_LIST ${MP4V2_LIBRARY})
add_definitions(-DENABLE_MP4V2)
message(STATUS "found library:${MP4V2_LIBRARY},ENABLE_MP4V2 defined")
endif ()
#查找x264是否安装 #查找x264是否安装
find_package(X264 QUIET) find_package(X264 QUIET)
if (X264_FOUND AND ENABLE_X264) if (X264_FOUND AND ENABLE_X264)
...@@ -127,9 +117,9 @@ if(ENABLE_HLS) ...@@ -127,9 +117,9 @@ if(ENABLE_HLS)
endif() endif()
#添加mov、flv库用于MP4录制 #添加mov、flv库用于MP4录制
if(ENABLE_MP4RECORD) if(ENABLE_MP4)
message(STATUS "ENABLE_MP4RECORD defined") message(STATUS "ENABLE_MP4 defined")
add_definitions(-DENABLE_MP4RECORD) add_definitions(-DENABLE_MP4)
aux_source_directory(${MediaServer_Root}/libmov/include src_mov) aux_source_directory(${MediaServer_Root}/libmov/include src_mov)
aux_source_directory(${MediaServer_Root}/libmov/source src_mov) aux_source_directory(${MediaServer_Root}/libmov/source src_mov)
......
...@@ -362,7 +362,7 @@ void installWebHook(){ ...@@ -362,7 +362,7 @@ void installWebHook(){
do_http_hook(hook_stream_not_found,body, nullptr); do_http_hook(hook_stream_not_found,body, nullptr);
}); });
#ifdef ENABLE_MP4RECORD #ifdef ENABLE_MP4
//录制mp4文件成功后广播 //录制mp4文件成功后广播
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastRecordMP4,[](BroadcastRecordMP4Args){ NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastRecordMP4,[](BroadcastRecordMP4Args){
if(!hook_enable || hook_record_mp4.empty()){ if(!hook_enable || hook_record_mp4.empty()){
...@@ -382,7 +382,7 @@ void installWebHook(){ ...@@ -382,7 +382,7 @@ void installWebHook(){
//执行hook //执行hook
do_http_hook(hook_record_mp4,body, nullptr); do_http_hook(hook_record_mp4,body, nullptr);
}); });
#endif //ENABLE_MP4RECORD #endif //ENABLE_MP4
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){ NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){
if(!hook_enable || hook_shell_login.empty() || sender.get_peer_ip() == "127.0.0.1"){ if(!hook_enable || hook_shell_login.empty() || sender.get_peer_ip() == "127.0.0.1"){
......
...@@ -152,12 +152,12 @@ void DevChannel::inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t u ...@@ -152,12 +152,12 @@ void DevChannel::inputAAC(const char *pcDataWithoutAdts,int iDataLen, uint32_t u
uiStamp = (uint32_t)_aTicker[1].elapsedTime(); uiStamp = (uint32_t)_aTicker[1].elapsedTime();
} }
if(pcAdtsHeader + 7 == pcDataWithoutAdts){ if(pcAdtsHeader + 7 == pcDataWithoutAdts){
inputFrame(std::make_shared<AACFrameNoCacheAble>((char *)pcDataWithoutAdts - 7,iDataLen + 7,uiStamp,7)); inputFrame(std::make_shared<AACFrameNoCacheAble>((char *)pcDataWithoutAdts - 7,iDataLen + 7,uiStamp,0,7));
} else { } else {
char *dataWithAdts = new char[iDataLen + 7]; char *dataWithAdts = new char[iDataLen + 7];
memcpy(dataWithAdts,pcAdtsHeader,7); memcpy(dataWithAdts,pcAdtsHeader,7);
memcpy(dataWithAdts + 7 , pcDataWithoutAdts , iDataLen); memcpy(dataWithAdts + 7 , pcDataWithoutAdts , iDataLen);
inputFrame(std::make_shared<AACFrameNoCacheAble>(dataWithAdts,iDataLen + 7,uiStamp,7)); inputFrame(std::make_shared<AACFrameNoCacheAble>(dataWithAdts,iDataLen + 7,uiStamp,0,7));
delete [] dataWithAdts; delete [] dataWithAdts;
} }
} }
......
...@@ -276,7 +276,7 @@ MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost_tmp ...@@ -276,7 +276,7 @@ MediaSource::Ptr MediaSource::find(const string &schema, const string &vhost_tmp
if(!ret && bMake){ if(!ret && bMake){
//未查找媒体源,则创建一个 //未查找媒体源,则创建一个
ret = MP4Reader::onMakeMediaSource(schema, vhost,app,id); ret = onMakeMediaSource(schema, vhost,app,id);
} }
return ret; return ret;
} }
......
...@@ -112,7 +112,7 @@ class AACFrameNoCacheAble : public FrameNoCacheAble { ...@@ -112,7 +112,7 @@ class AACFrameNoCacheAble : public FrameNoCacheAble {
public: public:
typedef std::shared_ptr<AACFrameNoCacheAble> Ptr; typedef std::shared_ptr<AACFrameNoCacheAble> Ptr;
AACFrameNoCacheAble(char *ptr,uint32_t size,uint32_t dts,int prefixeSize = 7){ AACFrameNoCacheAble(char *ptr,uint32_t size,uint32_t dts,uint32_t pts = 0,int prefixeSize = 7){
_ptr = ptr; _ptr = ptr;
_size = size; _size = size;
_dts = dts; _dts = dts;
......
...@@ -268,7 +268,7 @@ public: ...@@ -268,7 +268,7 @@ public:
*/ */
void inputFrame(const Frame::Ptr &frame) override{ void inputFrame(const Frame::Ptr &frame) override{
int type = H265_TYPE(*((uint8_t *)frame->data() + frame->prefixSize())); int type = H265_TYPE(*((uint8_t *)frame->data() + frame->prefixSize()));
if(type == H265Frame::NAL_VPS){ if(frame->configFrame()){
bool first_frame = true; bool first_frame = true;
splitH264(frame->data() + frame->prefixSize(), splitH264(frame->data() + frame->prefixSize(),
frame->size() - frame->prefixSize(), frame->size() - frame->prefixSize(),
......
...@@ -215,7 +215,7 @@ public: ...@@ -215,7 +215,7 @@ public:
auto iAudioIndex = frame->dts() / MUTE_ADTS_DATA_MS; auto iAudioIndex = frame->dts() / MUTE_ADTS_DATA_MS;
if(_iAudioIndex != iAudioIndex){ if(_iAudioIndex != iAudioIndex){
_iAudioIndex = iAudioIndex; _iAudioIndex = iAudioIndex;
auto aacFrame = std::make_shared<AACFrameCacheAble>((char *)MUTE_ADTS_DATA, MUTE_ADTS_DATA_LEN, _iAudioIndex * MUTE_ADTS_DATA_MS); auto aacFrame = std::make_shared<AACFrameCacheAble>((char *)MUTE_ADTS_DATA, MUTE_ADTS_DATA_LEN, _iAudioIndex * MUTE_ADTS_DATA_MS, 0);
FrameDispatcher::inputFrame(aacFrame); FrameDispatcher::inputFrame(aacFrame);
} }
} }
......
...@@ -24,53 +24,35 @@ ...@@ -24,53 +24,35 @@
* SOFTWARE. * SOFTWARE.
*/ */
#ifdef ENABLE_MP4RECORD #ifdef ENABLE_MP4
#include "MP4Muxer.h" #include "MP4Muxer.h"
#include "Util/File.h" #include "Util/File.h"
#include "Common/config.h"
namespace mediakit{ namespace mediakit{
#if defined(_WIN32) || defined(_WIN64) MP4Muxer::MP4Muxer(const char *file) {
#define fseek64 _fseeki64 _file_name = file;
#define ftell64 _ftelli64 openMP4();
#else }
#define fseek64 fseek
#define ftell64 ftell
#endif
void MP4MuxerBase::init(int flags) { MP4Muxer::~MP4Muxer() {
static struct mov_buffer_t s_io = { closeMP4();
[](void* ctx, void* data, uint64_t bytes) { }
MP4MuxerBase *thiz = (MP4MuxerBase *)ctx;
return thiz->onRead(data,bytes); void MP4Muxer::openMP4(){
}, closeMP4();
[](void* ctx, const void* data, uint64_t bytes){ openFile(_file_name.data(), "wb+");
MP4MuxerBase *thiz = (MP4MuxerBase *)ctx; _mov_writter = createWriter();
return thiz->onWrite(data,bytes); }
}, void MP4Muxer::closeMP4(){
[](void* ctx, uint64_t offset) { _mov_writter = nullptr;
MP4MuxerBase *thiz = (MP4MuxerBase *)ctx; closeFile();
return thiz->onSeek(offset);
},
[](void* ctx){
MP4MuxerBase *thiz = (MP4MuxerBase *)ctx;
return thiz->onTell();
}
};
_mov_writter.reset(mov_writer_create(&s_io,this,flags),[](mov_writer_t *ptr){
if(ptr){
mov_writer_destroy(ptr);
}
});
} }
///////////////////////////////////
void MP4Muxer::resetTracks() { void MP4Muxer::resetTracks() {
_codec_to_trackid.clear(); _codec_to_trackid.clear();
_started = false; _started = false;
_have_video = false; _have_video = false;
openMP4();
} }
void MP4Muxer::inputFrame(const Frame::Ptr &frame) { void MP4Muxer::inputFrame(const Frame::Ptr &frame) {
...@@ -263,70 +245,5 @@ void MP4Muxer::addTrack(const Track::Ptr &track) { ...@@ -263,70 +245,5 @@ void MP4Muxer::addTrack(const Track::Ptr &track) {
} }
} }
MP4MuxerFile::MP4MuxerFile(const char *file){
_file_name = file;
openFile(file);
}
void MP4MuxerFile::openFile(const char *file) {
//创建文件
auto fp = File::createfile_file(file,"wb+");
if(!fp){
throw std::runtime_error(string("打开文件失败:") + file);
}
GET_CONFIG(uint32_t,mp4BufSize,Record::kFileBufSize);
//新建文件io缓存
std::shared_ptr<char> file_buf(new char[mp4BufSize],[](char *ptr){
if(ptr){
delete [] ptr;
}
});
if(file_buf){
//设置文件io缓存
setvbuf(fp, file_buf.get(), _IOFBF, mp4BufSize);
}
//创建智能指针
_file.reset(fp,[file_buf](FILE *fp) {
fclose(fp);
});
GET_CONFIG(bool, mp4FastStart, Record::kFastStart);
init(mp4FastStart ? MOV_FLAG_FASTSTART : 0);
}
MP4MuxerFile::~MP4MuxerFile() {
_mov_writter = nullptr;
}
int MP4MuxerFile::onRead(void *data, uint64_t bytes) {
if (bytes == fread(data, 1, bytes, _file.get())){
return 0;
}
return 0 != ferror(_file.get()) ? ferror(_file.get()) : -1 /*EOF*/;
}
int MP4MuxerFile::onWrite(const void *data, uint64_t bytes) {
return bytes == fwrite(data, 1, bytes, _file.get()) ? 0 : ferror(_file.get());
}
int MP4MuxerFile::onSeek(uint64_t offset) {
return fseek64(_file.get(), offset, SEEK_SET);
}
uint64_t MP4MuxerFile::onTell() {
return ftell64(_file.get());
}
void MP4MuxerFile::resetTracks(){
MP4Muxer::resetTracks();
openFile(_file_name.data());
}
}//namespace mediakit }//namespace mediakit
#endif//#ifdef ENABLE_MP4
#endif//#ifdef ENABLE_MP4RECORD
...@@ -27,40 +27,21 @@ ...@@ -27,40 +27,21 @@
#ifndef ZLMEDIAKIT_MP4MUXER_H #ifndef ZLMEDIAKIT_MP4MUXER_H
#define ZLMEDIAKIT_MP4MUXER_H #define ZLMEDIAKIT_MP4MUXER_H
#ifdef ENABLE_MP4RECORD #ifdef ENABLE_MP4
#include "Common/MediaSink.h" #include "Common/MediaSink.h"
#include "mov-writer.h"
#include "mpeg4-hevc.h"
#include "mpeg4-avc.h"
#include "mpeg4-aac.h"
#include "mov-buffer.h"
#include "mov-format.h"
#include "Extension/AAC.h" #include "Extension/AAC.h"
#include "Extension/H264.h" #include "Extension/H264.h"
#include "Extension/H265.h" #include "Extension/H265.h"
#include "Common/Stamp.h" #include "Common/Stamp.h"
#include "MP4.h"
namespace mediakit{ namespace mediakit{
class MP4MuxerBase{ class MP4Muxer : public MediaSinkInterface, public MP4File{
public: public:
MP4MuxerBase() = default; MP4Muxer(const char *file);
virtual ~MP4MuxerBase() = default; ~MP4Muxer() override;
protected:
virtual int onRead(void* data, uint64_t bytes) = 0;
virtual int onWrite(const void* data, uint64_t bytes) = 0;
virtual int onSeek( uint64_t offset) = 0;
virtual uint64_t onTell() = 0;
void init(int flags);
protected:
std::shared_ptr<mov_writer_t> _mov_writter;
};
class MP4Muxer : public MediaSinkInterface , public MP4MuxerBase{
public:
MP4Muxer() = default;
~MP4Muxer() override = default;
/** /**
* 添加已经ready状态的track * 添加已经ready状态的track
...@@ -75,6 +56,11 @@ public: ...@@ -75,6 +56,11 @@ public:
* 重置所有track * 重置所有track
*/ */
void resetTracks() override ; void resetTracks() override ;
private:
void openMP4();
void closeMP4();
private: private:
struct track_info{ struct track_info{
int track_id = -1; int track_id = -1;
...@@ -84,28 +70,10 @@ private: ...@@ -84,28 +70,10 @@ private:
List<Frame::Ptr> _frameCached; List<Frame::Ptr> _frameCached;
bool _started = false; bool _started = false;
bool _have_video = false; bool _have_video = false;
}; MP4File::Writer _mov_writter;
class MP4MuxerFile : public MP4Muxer {
public:
typedef std::shared_ptr<MP4MuxerFile> Ptr;
MP4MuxerFile(const char *file);
~MP4MuxerFile();
void resetTracks() override ;
protected:
int onRead(void* data, uint64_t bytes) override;
int onWrite(const void* data, uint64_t bytes) override;
int onSeek( uint64_t offset) override;
uint64_t onTell() override ;
void openFile(const char *file);
private:
std::shared_ptr<FILE> _file;
string _file_name; string _file_name;
}; };
}//namespace mediakit }//namespace mediakit
#endif//#ifdef ENABLE_MP4
#endif//#ifdef ENABLE_MP4RECORD
#endif //ZLMEDIAKIT_MP4MUXER_H #endif //ZLMEDIAKIT_MP4MUXER_H
...@@ -26,21 +26,16 @@ ...@@ -26,21 +26,16 @@
#ifndef SRC_MEDIAFILE_MEDIAREADER_H_ #ifndef SRC_MEDIAFILE_MEDIAREADER_H_
#define SRC_MEDIAFILE_MEDIAREADER_H_ #define SRC_MEDIAFILE_MEDIAREADER_H_
#ifdef ENABLE_MP4
#include "MP4Demuxer.h"
#include "Common/MultiMediaSourceMuxer.h" #include "Common/MultiMediaSourceMuxer.h"
#include "Extension/AAC.h"
#ifdef ENABLE_MP4V2
#include <mp4v2/mp4v2.h>
#endif //ENABLE_MP4V2
using namespace toolkit; using namespace toolkit;
namespace mediakit { namespace mediakit {
class MP4Reader : public std::enable_shared_from_this<MP4Reader> ,public MediaSourceEvent{ class MP4Reader : public std::enable_shared_from_this<MP4Reader> ,public MediaSourceEvent{
public: public:
typedef std::shared_ptr<MP4Reader> Ptr; typedef std::shared_ptr<MP4Reader> Ptr;
virtual ~MP4Reader(); virtual ~MP4Reader() = default;
/** /**
* 流化一个mp4文件,使之转换成RtspMediaSource和RtmpMediaSource * 流化一个mp4文件,使之转换成RtspMediaSource和RtmpMediaSource
...@@ -50,82 +45,54 @@ public: ...@@ -50,82 +45,54 @@ public:
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件 * @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
*/ */
MP4Reader(const string &strVhost,const string &strApp, const string &strId,const string &filePath = ""); MP4Reader(const string &strVhost,const string &strApp, const string &strId,const string &filePath = "");
/** /**
* 开始流化MP4文件,需要指出的是,MP4Reader对象一经过调用startReadMP4方法,它的强引用会自持有, * 开始流化MP4文件,需要指出的是,MP4Reader对象一经过调用startReadMP4方法,它的强引用会自持有,
* 意思是在文件流化结束之前或中断之前,MP4Reader对象是不会被销毁的(不管有没有被外部对象持有) * 意思是在文件流化结束之前或中断之前,MP4Reader对象是不会被销毁的(不管有没有被外部对象持有)
*/ */
void startReadMP4(); void startReadMP4();
/**
* 自动生成MP4Reader对象然后查找相关的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);
private: private:
//MediaSourceEvent override //MediaSourceEvent override
bool seekTo(MediaSource &sender,uint32_t ui32Stamp) override; bool seekTo(MediaSource &sender,uint32_t ui32Stamp) override;
bool close(MediaSource &sender,bool force) override; bool close(MediaSource &sender,bool force) override;
int totalReaderCount(MediaSource &sender) override; int totalReaderCount(MediaSource &sender) override;
#ifdef ENABLE_MP4V2
void seek(uint32_t iSeekTime,bool bReStart = true);
inline void setSeekTime(uint32_t iSeekTime);
inline uint32_t getVideoCurrentTime();
inline MP4SampleId getVideoSampleId(int iTimeInc = 0);
inline MP4SampleId getAudioSampleId(int iTimeInc = 0);
bool readSample(int iTimeInc, bool justSeekSyncFrame);
inline bool readVideoSample(int iTimeInc,bool justSeekSyncFrame);
inline bool readAudioSample(int iTimeInc,bool justSeekSyncFrame);
inline void writeH264(uint8_t *pucData,int iLen,uint32_t dts,uint32_t pts);
inline void writeAAC(uint8_t *pucData,int iLen,uint32_t uiStamp);
private:
MP4FileHandle _hMP4File = MP4_INVALID_FILE_HANDLE;
MP4TrackId _video_trId = MP4_INVALID_TRACK_ID;
uint32_t _video_ms = 0;
uint32_t _video_num_samples = 0;
uint32_t _video_sample_max_size = 0;
uint32_t _video_width = 0;
uint32_t _video_height = 0;
uint32_t _video_framerate = 0;
string _strPps;
string _strSps;
bool _bSyncSample = false;
MP4TrackId _audio_trId = MP4_INVALID_TRACK_ID;
uint32_t _audio_ms = 0;
uint32_t _audio_num_samples = 0;
uint32_t _audio_sample_max_size = 0;
uint32_t _audio_sample_rate = 0;
uint32_t _audio_num_channels = 0;
string _strAacCfg;
AACFrame _adts;
int _iDuration = 0; bool readSample();
uint32_t nextStampForStop();
void setNextStampForStop(uint32_t ui32Stamp);
bool seekTo(uint32_t ui32Stamp);
private:
recursive_mutex _mtx;
MultiMediaSourceMuxer::Ptr _mediaMuxer; MultiMediaSourceMuxer::Ptr _mediaMuxer;
MP4SampleId _video_current = 0; uint32_t _seek_to;
MP4SampleId _audio_current = 0; Ticker _seek_ticker;
std::shared_ptr<uint8_t> _pcVideoSample;
int _iSeekTime = 0 ;
Ticker _ticker;
Ticker _alive; Ticker _alive;
recursive_mutex _mtx;
Timer::Ptr _timer; Timer::Ptr _timer;
EventPoller::Ptr _poller; EventPoller::Ptr _poller;
#endif //ENABLE_MP4V2 MP4Demuxer::Ptr _demuxer;
bool _have_video = false;
}; };
} /* namespace mediakit */ } /* namespace mediakit */
#endif //ENABLE_MP4
namespace mediakit {
/**
* 自动生成MP4Reader对象然后查找相关的MediaSource对象
* @param strSchema 协议名
* @param strVhost 虚拟主机
* @param strApp 应用名
* @param strId 流id
* @param filePath 文件路径,如果为空则根据配置文件和上面参数自动生成,否则使用指定的文件
* @param checkApp 是否检查app,防止服务器上文件被乱访问
* @return MediaSource
*/
MediaSource::Ptr onMakeMediaSource(const string &strSchema,
const string &strVhost,
const string &strApp,
const string &strId,
const string &filePath = "",
bool checkApp = true);
} /* namespace mediakit */
#endif /* SRC_MEDIAFILE_MEDIAREADER_H_ */ #endif /* SRC_MEDIAFILE_MEDIAREADER_H_ */
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#ifdef ENABLE_MP4RECORD #ifdef ENABLE_MP4
#include <ctime> #include <ctime>
#include <sys/stat.h> #include <sys/stat.h>
#include "Common/config.h" #include "Common/config.h"
...@@ -69,7 +69,7 @@ void MP4Recorder::createFile() { ...@@ -69,7 +69,7 @@ void MP4Recorder::createFile() {
+ strTime + ".mp4"; + strTime + ".mp4";
try { try {
_muxer = std::make_shared<MP4MuxerFile>(strFileTmp.data()); _muxer = std::make_shared<MP4Muxer>(strFileTmp.data());
for(auto &track :_tracks){ for(auto &track :_tracks){
//添加track //添加track
_muxer->addTrack(track); _muxer->addTrack(track);
...@@ -91,7 +91,7 @@ void MP4Recorder::asyncClose() { ...@@ -91,7 +91,7 @@ void MP4Recorder::asyncClose() {
//获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间 //获取文件录制时间,放在关闭mp4之前是为了忽略关闭mp4执行时间
const_cast<MP4Info&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime; const_cast<MP4Info&>(info).ui64TimeLen = ::time(NULL) - info.ui64StartedTime;
//关闭mp4非常耗时,所以要放在后台线程执行 //关闭mp4非常耗时,所以要放在后台线程执行
const_cast<MP4MuxerFile::Ptr &>(muxer).reset(); const_cast<MP4Muxer::Ptr &>(muxer).reset();
//临时文件名改成正式文件名,防止mp4未完成时被访问 //临时文件名改成正式文件名,防止mp4未完成时被访问
rename(strFileTmp.data(),strFile.data()); rename(strFileTmp.data(),strFile.data());
//获取文件大小 //获取文件大小
...@@ -145,4 +145,4 @@ void MP4Recorder::resetTracks() { ...@@ -145,4 +145,4 @@ void MP4Recorder::resetTracks() {
} /* namespace mediakit */ } /* namespace mediakit */
#endif //ENABLE_MP4RECORD #endif //ENABLE_MP4
...@@ -54,7 +54,7 @@ public: ...@@ -54,7 +54,7 @@ public:
string strVhost;//vhost string strVhost;//vhost
}; };
#ifdef ENABLE_MP4RECORD #ifdef ENABLE_MP4
class MP4Recorder : public MediaSinkInterface{ class MP4Recorder : public MediaSinkInterface{
public: public:
typedef std::shared_ptr<MP4Recorder> Ptr; typedef std::shared_ptr<MP4Recorder> Ptr;
...@@ -90,11 +90,11 @@ private: ...@@ -90,11 +90,11 @@ private:
Ticker _createFileTicker; Ticker _createFileTicker;
MP4Info _info; MP4Info _info;
bool _haveVideo = false; bool _haveVideo = false;
MP4MuxerFile::Ptr _muxer; MP4Muxer::Ptr _muxer;
list<Track::Ptr> _tracks; list<Track::Ptr> _tracks;
}; };
#endif ///ENABLE_MP4RECORD #endif ///ENABLE_MP4
} /* namespace mediakit */ } /* namespace mediakit */
......
...@@ -364,7 +364,7 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const st ...@@ -364,7 +364,7 @@ std::shared_ptr<MediaSinkInterface> Recorder::createRecorder(type type, const st
} }
case Recorder::type_mp4: { case Recorder::type_mp4: {
#if defined(ENABLE_MP4RECORD) #if defined(ENABLE_MP4)
return std::make_shared<MP4Recorder>(path, vhost, app, stream_id); return std::make_shared<MP4Recorder>(path, vhost, app, stream_id);
#endif #endif
return nullptr; return nullptr;
......
...@@ -282,7 +282,7 @@ void RtpProcess::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d ...@@ -282,7 +282,7 @@ void RtpProcess::onDecode(int stream,int codecid,int flags,int64_t pts,int64_t d
WarnL << "audio track change to AAC from codecid:" << getCodecName(_codecid_audio); WarnL << "audio track change to AAC from codecid:" << getCodecName(_codecid_audio);
return; return;
} }
_muxer->inputFrame(std::make_shared<AACFrameNoCacheAble>((char *) data, bytes, dts, 7)); _muxer->inputFrame(std::make_shared<AACFrameNoCacheAble>((char *) data, bytes, dts, 0, 7));
break; break;
} }
default: default:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论