avcodec/frame_thread_encoder: Avoid creating reference to frame

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2021-02-07 13:46:11 +01:00
parent fbf242a51d
commit 76d428e090
3 changed files with 10 additions and 8 deletions

View File

@ -152,6 +152,10 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
if (CONFIG_FRAME_THREAD_ENCODER && if (CONFIG_FRAME_THREAD_ENCODER &&
avci->frame_thread_encoder && (avctx->active_thread_type & FF_THREAD_FRAME)) 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); ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
else { else {
ret = avctx->codec->encode2(avctx, avpkt, frame, &got_packet); ret = avctx->codec->encode2(avctx, avpkt, frame, &got_packet);

View File

@ -286,10 +286,11 @@ void ff_frame_thread_encoder_free(AVCodecContext *avctx){
av_freep(&avctx->internal->frame_thread_encoder); 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; ThreadContext *c = avctx->internal->frame_thread_encoder;
Task *outtask, task; Task *outtask, task;
int ret;
av_assert1(!*got_packet_ptr); 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(); AVFrame *new = av_frame_alloc();
if(!new) if(!new)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
ret = av_frame_ref(new, frame); av_frame_move_ref(new, frame);
if(ret < 0) {
av_frame_free(&new);
return ret;
}
task.index = c->task_index; task.index = c->task_index;
task.indata = (void*)new; task.indata = (void*)new;

View File

@ -25,6 +25,7 @@
int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options); int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options);
void ff_frame_thread_encoder_free(AVCodecContext *avctx); 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 */ #endif /* AVCODEC_FRAME_THREAD_ENCODER_H */