diff mbox series

[FFmpeg-devel,4/8] avcodec/frame_thread_encoder: Avoid creating reference to frame

Message ID 20210208122330.555354-4-andreas.rheinhardt@gmail.com
State Accepted
Commit 76d428e090e0a547b2e6be6dbd22cf87817adec7
Headers show
Series [FFmpeg-devel,1/8] avcodec/frame_thread_encoder: Improve type safety | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 8, 2021, 12:23 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/encode.c               |  4 ++++
 libavcodec/frame_thread_encoder.c | 11 ++++-------
 libavcodec/frame_thread_encoder.h |  3 ++-
 3 files changed, 10 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 29f41c3f92..282337e453 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -152,6 +152,10 @@  static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
 
     if (CONFIG_FRAME_THREAD_ENCODER &&
         avci->frame_thread_encoder && (avctx->active_thread_type & FF_THREAD_FRAME))
+        /* This might modify frame, but it doesn't matter, because
+         * the frame properties used below are not used for video
+         * (due to the delay inherent in frame threaded encoding, it makes
+         *  no sense to use the properties of the current frame anyway). */
         ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
     else {
         ret = avctx->codec->encode2(avctx, avpkt, frame, &got_packet);
diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index bcd3c94f8b..7c2894c933 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -286,10 +286,11 @@  void ff_frame_thread_encoder_free(AVCodecContext *avctx){
     av_freep(&avctx->internal->frame_thread_encoder);
 }
 
-int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr){
+int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+                                 AVFrame *frame, int *got_packet_ptr)
+{
     ThreadContext *c = avctx->internal->frame_thread_encoder;
     Task *outtask, task;
-    int ret;
 
     av_assert1(!*got_packet_ptr);
 
@@ -297,11 +298,7 @@  int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVF
         AVFrame *new = av_frame_alloc();
         if(!new)
             return AVERROR(ENOMEM);
-        ret = av_frame_ref(new, frame);
-        if(ret < 0) {
-            av_frame_free(&new);
-            return ret;
-        }
+        av_frame_move_ref(new, frame);
 
         task.index = c->task_index;
         task.indata = (void*)new;
diff --git a/libavcodec/frame_thread_encoder.h b/libavcodec/frame_thread_encoder.h
index 1f79553f20..c400d6b32c 100644
--- a/libavcodec/frame_thread_encoder.h
+++ b/libavcodec/frame_thread_encoder.h
@@ -25,6 +25,7 @@ 
 
 int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options);
 void ff_frame_thread_encoder_free(AVCodecContext *avctx);
-int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr);
+int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+                                 AVFrame *frame, int *got_packet_ptr);
 
 #endif /* AVCODEC_FRAME_THREAD_ENCODER_H */