summaryrefslogtreecommitdiff
path: root/libavcodec/frame_thread_encoder.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-23 23:26:57 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-08-27 02:23:43 +0200
commit1e6307f46c486d17f670043672d49335ea1bae97 (patch)
treeef6469a2bd472ee8189f6d9ce0a4f288cfd57e55 /libavcodec/frame_thread_encoder.c
parent4dddcd08c47850fbf3cef2ff6b31f65133856e0f (diff)
avcodec/encode, frame_thread_encoder: Unify calling encode callback
The encode-callback (the callback used by the FF_CODEC_CB_TYPE_ENCODE encoders) is currently called in two places: encode_simple_internal() and by the worker threads of frame-threaded encoders. After the call, some packet properties are set based upon the corresponding AVFrame properties and the packet is made refcounted if it isn't already. So there is some code duplication. There was also non-duplicated code in encode_simple_internal() which is executed even when using frame-threading. This included an emms_c() (which is needed for frame-threading, too, if it is needed for the single-threaded case, because there are allocations (via av_packet_make_refcounted()) immediately after returning from the encode-callback). Furthermore, some further properties are only set in encode_simple_internal(): For audio, pts and duration are derived from the corresponding fields of the frame if the encoder does not have the AV_CODEC_CAP_DELAY set. Yet this is wrong for frame-threaded encoders, because frame-threading always introduces delay regardless of whether the underlying codec has said cap. This only worked because there are no frame-threaded audio encoders. This commit fixes the code duplication and the above issue by factoring this code out and reusing it in both places. It would work in case of audio codecs with frame-threading, because now the values are derived from the correct AVFrame. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/frame_thread_encoder.c')
-rw-r--r--libavcodec/frame_thread_encoder.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c
index b5765b6343..1faaef522e 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -24,14 +24,12 @@
#include "libavutil/avassert.h"
#include "libavutil/cpu.h"
-#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "avcodec.h"
-#include "codec_internal.h"
+#include "encode.h"
#include "internal.h"
#include "pthread_internal.h"
-#include "thread.h"
#define MAX_THREADS 64
/* There can be as many as MAX_THREADS + 1 outstanding tasks.
@@ -80,7 +78,7 @@ static void * attribute_align_arg worker(void *v){
ThreadContext *c = avctx->internal->frame_thread_encoder;
while (!atomic_load(&c->exit)) {
- int got_packet = 0, ret;
+ int ret;
AVPacket *pkt;
AVFrame *frame;
Task *task;
@@ -105,14 +103,7 @@ static void * attribute_align_arg worker(void *v){
frame = task->indata;
pkt = task->outdata;
- ret = ffcodec(avctx->codec)->cb.encode(avctx, pkt, frame, &got_packet);
- if(got_packet) {
- int ret2 = av_packet_make_refcounted(pkt);
- if (ret >= 0 && ret2 < 0)
- ret = ret2;
- pkt->pts = pkt->dts = frame->pts;
- }
- task->got_packet = got_packet;
+ ret = ff_encode_encode_cb(avctx, pkt, frame, &task->got_packet);
pthread_mutex_lock(&c->buffer_mutex);
av_frame_unref(frame);
pthread_mutex_unlock(&c->buffer_mutex);