From e03d15053d3cfd618fa5d754cc22ebed2a67070c Mon Sep 17 00:00:00 2001 From: wxf Date: Tue, 3 Aug 2021 21:48:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84,=20?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=85=B3=E7=B3=BB,=20=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E7=BB=A7=E6=89=BF=20MP4FileDisk,=20=E6=94=B9=E4=B8=BA=E6=88=90?= =?UTF-8?q?=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #1018 --- src/Record/MP4Demuxer.cpp | 17 ++++++++++++----- src/Record/MP4Demuxer.h | 10 ++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Record/MP4Demuxer.cpp b/src/Record/MP4Demuxer.cpp index f44265f4..7df9ed27 100644 --- a/src/Record/MP4Demuxer.cpp +++ b/src/Record/MP4Demuxer.cpp @@ -22,17 +22,24 @@ namespace mediakit { MP4Demuxer::MP4Demuxer() {} MP4Demuxer::~MP4Demuxer() { - _mov_reader = nullptr; - closeFile(); + closeMP4(); } -void MP4Demuxer::openMP4(const string &file){ - openFile(file.data(),"rb+"); - _mov_reader = createReader(); +void MP4Demuxer::openMP4(const string &file) { + closeMP4(); + + _mp4_file = std::make_shared(); + _mp4_file->openFile(file.data(), "rb+"); + _mov_reader = _mp4_file->createReader(); getAllTracks(); _duration_ms = mov_reader_getduration(_mov_reader.get()); } +void MP4Demuxer::closeMP4() { + _mov_reader.reset(); + _mp4_file.reset(); +} + int MP4Demuxer::getAllTracks() { static mov_reader_trackinfo_t s_on_track = { [](void *param, uint32_t track, uint8_t object, int width, int height, const void *extra, size_t bytes) { diff --git a/src/Record/MP4Demuxer.h b/src/Record/MP4Demuxer.h index 5d19b3a9..9eb64276 100644 --- a/src/Record/MP4Demuxer.h +++ b/src/Record/MP4Demuxer.h @@ -16,7 +16,7 @@ #include "Util/ResourcePool.h" namespace mediakit { -class MP4Demuxer : public MP4FileDisk, public TrackSource{ +class MP4Demuxer : public TrackSource { public: typedef std::shared_ptr Ptr; @@ -32,6 +32,11 @@ public: */ void openMP4(const string &file); + /** + * @brief 关闭 mp4 文件 + */ + void closeMP4(); + /** * 移动时间轴至某处 * @param stamp_ms 预期的时间轴位置,单位毫秒 @@ -67,7 +72,8 @@ private: Frame::Ptr makeFrame(uint32_t track_id, const Buffer::Ptr &buf, int64_t pts, int64_t dts); private: - Reader _mov_reader; + MP4FileDisk::Ptr _mp4_file; + MP4FileDisk::Reader _mov_reader; uint64_t _duration_ms = 0; map _track_to_codec; ResourcePool _buffer_pool;