diff --git a/3rdpart/media-server b/3rdpart/media-server index 97cf5e47..24519a59 160000 --- a/3rdpart/media-server +++ b/3rdpart/media-server @@ -1 +1 @@ -Subproject commit 97cf5e47a5af1ff3d4d187f3ebffd9254595df75 +Subproject commit 24519a594c2c634b21fbe09fad28d54c4eba0885 diff --git a/src/Record/MP4Demuxer.cpp b/src/Record/MP4Demuxer.cpp index 184035b9..94394e63 100644 --- a/src/Record/MP4Demuxer.cpp +++ b/src/Record/MP4Demuxer.cpp @@ -142,7 +142,9 @@ struct Context{ BufferRaw::Ptr buffer; }; -Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame) { +Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame, bool &eof) { + keyFrame = false; + eof = false; static mov_reader_onread mov_reader_onread = [](void *param, uint32_t track_id, const void *buffer, size_t bytes, int64_t pts, int64_t dts, int flags) { Context *ctx = (Context *) param; ctx->pts = pts; @@ -162,17 +164,21 @@ Frame::Ptr MP4Demuxer::readFrame(bool &keyFrame) { Context ctx = {this, 0}; auto ret = mov_reader_read2(_mov_reader.get(), mov_onalloc, mov_reader_onread, &ctx); switch (ret) { - case 0 : + case 0 : { + eof = true; return nullptr; + } case 1 : { keyFrame = ctx.flags & MOV_AV_FLAG_KEYFREAME; return makeFrame(ctx.track_id, ctx.buffer, ctx.pts, ctx.dts); } - default: + default : { + eof = true; WarnL << "读取mp4文件数据失败:" << ret; return nullptr; + } } } diff --git a/src/Record/MP4Demuxer.h b/src/Record/MP4Demuxer.h index 3d415db2..a626d05c 100644 --- a/src/Record/MP4Demuxer.h +++ b/src/Record/MP4Demuxer.h @@ -22,7 +22,7 @@ public: MP4Demuxer(const char *file); ~MP4Demuxer() override; int64_t seekTo(int64_t stamp_ms); - Frame::Ptr readFrame(bool &keyFrame); + Frame::Ptr readFrame(bool &keyFrame, bool &eof); vector getTracks(bool trackReady) const override ; uint64_t getDurationMS() const; private: diff --git a/src/Record/MP4Reader.cpp b/src/Record/MP4Reader.cpp index 025a9c39..1e78c617 100644 --- a/src/Record/MP4Reader.cpp +++ b/src/Record/MP4Reader.cpp @@ -48,11 +48,10 @@ MP4Reader::MP4Reader(const string &strVhost,const string &strApp, const string & bool MP4Reader::readSample() { bool keyFrame = false; bool eof = false; - while (true) { - auto frame = _demuxer->readFrame(keyFrame); + while (!eof) { + auto frame = _demuxer->readFrame(keyFrame, eof); if (!frame) { - eof = true; - break; + continue; } _mediaMuxer->inputFrame(frame); if (frame->dts() > getCurrentStamp()) { @@ -122,11 +121,12 @@ bool MP4Reader::seekTo(uint32_t ui32Stamp){ } //搜索到下一帧关键帧 bool keyFrame = false; - while (true) { - auto frame = _demuxer->readFrame(keyFrame); + bool eof = false; + while (!eof) { + auto frame = _demuxer->readFrame(keyFrame, eof); if(!frame){ //文件读完了都未找到下一帧关键帧 - return false; + continue; } if(keyFrame || frame->keyFrame() || frame->configFrame()){ //定位到key帧 @@ -136,6 +136,7 @@ bool MP4Reader::seekTo(uint32_t ui32Stamp){ return true; } } + return false; } bool MP4Reader::close(MediaSource &sender,bool force){