Skip to content

Commit

Permalink
Fixed an problem where deep copy did not work when passing decoded fr…
Browse files Browse the repository at this point in the history
…ame to the filters.
  • Loading branch information
Keukhan committed Nov 23, 2023
1 parent 29debd0 commit 0119f61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/projects/transcoder/transcoder_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,24 @@ class MediaFrame
}
}

// This function should only be called before filtering (_track_id 0, 1)
std::shared_ptr<MediaFrame> CloneFrame()
// This function should only be called before filtering
std::shared_ptr<MediaFrame> CloneFrame(bool deep_copy = false)
{
auto frame = std::make_shared<MediaFrame>();

if(_priv_data != nullptr){
frame->SetPrivData(::av_frame_clone(_priv_data));
if(_priv_data != nullptr)
{
// Create a new frame that references the same data as src
auto clone_priv_data = ::av_frame_clone(_priv_data);
if (clone_priv_data != nullptr)
{
if (deep_copy == true)
{
::av_frame_make_writable(clone_priv_data);
}

frame->SetPrivData(clone_priv_data);
}
}

frame->SetMediaType(_media_type);
Expand Down
2 changes: 1 addition & 1 deletion src/projects/transcoder/transcoder_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ void TranscoderStream::SpreadToFilters(int32_t decoder_id, std::shared_ptr<Media

for (auto &filter_id : filter_ids)
{
auto frame_clone = frame->CloneFrame();
auto frame_clone = frame->CloneFrame(true);
if (frame_clone == nullptr)
{
logte("%s Failed to clone frame", _log_prefix.CStr());
Expand Down

0 comments on commit 0119f61

Please sign in to comment.