From 6d8db7d232285922bd8cbb884e6e10329bdd1e93 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 1 Aug 2019 19:09:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MediaFile/MP4Muxer.cpp | 19 +++++++++++-------- src/MediaFile/MP4Muxer.h | 7 ++++--- tests/test_server.cpp | 5 ++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/MediaFile/MP4Muxer.cpp b/src/MediaFile/MP4Muxer.cpp index f9f736df..d9876507 100644 --- a/src/MediaFile/MP4Muxer.cpp +++ b/src/MediaFile/MP4Muxer.cpp @@ -39,7 +39,7 @@ namespace mediakit{ #define ftell64 ftell #endif -MP4MuxerBase::MP4MuxerBase(int flags) { +void MP4MuxerBase::init(int flags) { static struct mov_buffer_t s_io = { [](void* ctx, void* data, uint64_t bytes) { MP4MuxerBase *thiz = (MP4MuxerBase *)ctx; @@ -67,10 +67,6 @@ MP4MuxerBase::MP4MuxerBase(int flags) { /////////////////////////////////// -MP4Muxer::MP4Muxer(int flags) : MP4MuxerBase(flags) { -} - - void MP4Muxer::onTrackFrame(const Frame::Ptr &frame) { if(frame->configFrame()){ //忽略配置帧 @@ -196,15 +192,23 @@ MP4MuxerFile::MP4MuxerFile(const char *file) { _file.reset(fp,[file_buf](FILE *fp) { fclose(fp); }); + + init(MOV_FLAG_FASTSTART); } +MP4MuxerFile::~MP4MuxerFile() { + _mov_writter = nullptr; +} int MP4MuxerFile::onRead(void *data, uint64_t bytes) { - return fread(data, 1, bytes, _file.get()); + 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 fwrite(data, 1, bytes, _file.get()); + return bytes == fwrite(data, 1, bytes, _file.get()) ? 0 : ferror(_file.get()); } @@ -224,7 +228,6 @@ uint64_t MP4MuxerFile::onTell() { return ftell64(_file.get()); } - }//namespace mediakit #endif//#ifdef ENABLE_MP4RECORD diff --git a/src/MediaFile/MP4Muxer.h b/src/MediaFile/MP4Muxer.h index 80d82a54..88f7a028 100644 --- a/src/MediaFile/MP4Muxer.h +++ b/src/MediaFile/MP4Muxer.h @@ -44,20 +44,21 @@ namespace mediakit{ class MP4MuxerBase{ public: - MP4MuxerBase(int flags = MOV_FLAG_FASTSTART); + MP4MuxerBase() = default; virtual ~MP4MuxerBase() = default; 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_writter; }; class MP4Muxer : public MediaSink , public MP4MuxerBase{ public: - MP4Muxer(int flags = MOV_FLAG_FASTSTART) ; + MP4Muxer() = default; ~MP4Muxer() override = default; protected: /** @@ -81,7 +82,7 @@ class MP4MuxerFile : public MP4Muxer { public: typedef std::shared_ptr Ptr; MP4MuxerFile(const char *file); - ~MP4MuxerFile() = default; + ~MP4MuxerFile(); protected: int onRead(void* data, uint64_t bytes) override; int onWrite(const void* data, uint64_t bytes) override; diff --git a/tests/test_server.cpp b/tests/test_server.cpp index df30a0c8..c34fd255 100644 --- a/tests/test_server.cpp +++ b/tests/test_server.cpp @@ -239,8 +239,7 @@ int main(int argc,char *argv[]) { //这里是拉流地址,支持rtmp/rtsp协议,负载必须是H264+AAC //如果是其他不识别的音视频将会被忽略(譬如说h264+adpcm转发后会去除音频) - auto urlList = {"rtmp://live.hkstv.hk.lxdns.com/live/hks1", - "rtmp://live.hkstv.hk.lxdns.com/live/hks2" + auto urlList = {"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov" //rtsp链接支持输入用户名密码 /*"rtsp://admin:jzan123456@192.168.0.122/"*/}; map proxyMap; @@ -259,7 +258,7 @@ int main(int argc,char *argv[]) { //rtsp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4 //rtmp://127.0.0.1/record/live/0/2017-04-11/11-09-38.mp4 - PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST, "live", to_string(i).data())); + PlayerProxy::Ptr player(new PlayerProxy(DEFAULT_VHOST, "live", to_string(i).data(),false,false,false,true)); //指定RTP over TCP(播放rtsp时有效) (*player)[kRtpType] = Rtsp::RTP_TCP; //开始播放,如果播放失败或者播放中止,将会自动重试若干次,重试次数在配置文件中配置,默认一直重试