From 07f3c6dde4cb4b8e68e1bce59e061ceb874823cb Mon Sep 17 00:00:00 2001 From: PioLing <964472638@qq.com> Date: Thu, 14 Dec 2023 14:14:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81codec=E7=9A=84frame=20(#3126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Extension/Factory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Extension/Factory.cpp b/src/Extension/Factory.cpp index 9904a784..49feeb94 100644 --- a/src/Extension/Factory.cpp +++ b/src/Extension/Factory.cpp @@ -197,8 +197,8 @@ AMFValue Factory::getAmfByCodecId(CodecId codecId) { Frame::Ptr Factory::getFrameFromPtr(CodecId codec, const char *data, size_t bytes, uint64_t dts, uint64_t pts) { auto it = s_plugins.find(codec); if (it == s_plugins.end()) { - WarnL << "Unsupported codec: " << getCodecName(codec); - return nullptr; + // 创建不支持codec的frame + return std::make_shared(codec, (char *)data, bytes, dts, pts); } return it->second->getFrameFromPtr(data, bytes, dts, pts); } From c0bb7db4762c11db98b620f5172e30b0344b8e08 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Thu, 14 Dec 2023 17:28:21 +0800 Subject: [PATCH 2/2] BugFix: crash when FrameMerger::flush In a lambda expression, temporary stack variables should not be captured; otherwise, the variables may have become invalid when FrameMerger::flush is called. --- src/Record/MP4Muxer.cpp | 2 +- src/Record/MPEG.cpp | 2 +- src/Rtp/Decoder.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Record/MP4Muxer.cpp b/src/Record/MP4Muxer.cpp index 37c6cfd7..5d40be1d 100644 --- a/src/Record/MP4Muxer.cpp +++ b/src/Record/MP4Muxer.cpp @@ -104,7 +104,7 @@ bool MP4MuxerInterface::inputFrame(const Frame::Ptr &frame) { case CodecH264: case CodecH265: { // 这里的代码逻辑是让SPS、PPS、IDR这些时间戳相同的帧打包到一起当做一个帧处理, - track.merger.inputFrame(frame, [&](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool have_idr) { + track.merger.inputFrame(frame, [this, &track](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool have_idr) { int64_t dts_out, pts_out; track.stamp.revise(dts, pts, dts_out, pts_out); mp4_writer_write(_mov_writter.get(), track.track_id, buffer->data(), buffer->size(), pts_out, dts_out, have_idr ? MOV_AV_FLAG_KEYFREAME : 0); diff --git a/src/Record/MPEG.cpp b/src/Record/MPEG.cpp index ef844277..bca086dc 100644 --- a/src/Record/MPEG.cpp +++ b/src/Record/MPEG.cpp @@ -55,7 +55,7 @@ bool MpegMuxer::inputFrame(const Frame::Ptr &frame) { case CodecH264: case CodecH265: { // 这里的代码逻辑是让SPS、PPS、IDR这些时间戳相同的帧打包到一起当做一个帧处理, - return track.merger.inputFrame(frame, [&](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool have_idr) { + return track.merger.inputFrame(frame, [this, &track](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool have_idr) { _key_pos = have_idr; // 取视频时间戳为TS的时间戳 _timestamp = dts; diff --git a/src/Rtp/Decoder.cpp b/src/Rtp/Decoder.cpp index dacd3ab5..ca4b20b7 100644 --- a/src/Rtp/Decoder.cpp +++ b/src/Rtp/Decoder.cpp @@ -111,7 +111,7 @@ void DecoderImp::onDecode(int stream, int codecid, int flags, int64_t pts, int64 onTrack(stream, Factory::getTrackByCodecId(codec, 8000, 1, 16)); } if (!ref.first) { - WarnL << "not support codec :" << getCodecName(codec); + WarnL << "Unsupported codec :" << getCodecName(codec); return; } auto frame = Factory::getFrameFromPtr(codec, (char *)data, bytes, dts, pts); @@ -119,7 +119,7 @@ void DecoderImp::onDecode(int stream, int codecid, int flags, int64_t pts, int64 onFrame(stream, frame); return; } - ref.second.inputFrame(frame, [&](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool) { + ref.second.inputFrame(frame, [this, stream, codec](uint64_t dts, uint64_t pts, const Buffer::Ptr &buffer, bool) { onFrame(stream, Factory::getFrameFromBuffer(codec, buffer, dts, pts)); }); }