@@ -1146,6 +1146,19 @@ int dec_open(Decoder **pdec, Scheduler *sch,
goto fail;
}
+ if (dp->dec_ctx->hw_device_ctx) {
+ // Update decoder extra_hw_frames option to account for the
+ // frames held in queues inside the ffmpeg utility. This is
+ // called after avcodec_open2() because the user-set value of
+ // extra_hw_frames becomes valid in there, and we need to add
+ // this on top of it.
+ int extra_frames = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+ if (dp->dec_ctx->extra_hw_frames >= 0)
+ dp->dec_ctx->extra_hw_frames += extra_frames;
+ else
+ dp->dec_ctx->extra_hw_frames = extra_frames;
+ }
+
ret = check_avoptions(*dec_opts);
if (ret < 0)
goto fail;
@@ -361,7 +361,21 @@ static int queue_alloc(ThreadQueue **ptq, unsigned nb_streams, unsigned queue_si
ThreadQueue *tq;
ObjPool *op;
- queue_size = queue_size > 0 ? queue_size : 8;
+ if (queue_size <= 0) {
+ if (type == QUEUE_FRAMES)
+ queue_size = DEFAULT_FRAME_THREAD_QUEUE_SIZE;
+ else
+ queue_size = DEFAULT_PACKET_THREAD_QUEUE_SIZE;
+ }
+
+ if (type == QUEUE_FRAMES) {
+ // This queue length is used in the decoder code to ensure that
+ // there are enough entries in fixed-size frame pools to account
+ // for frames held in queues inside the ffmpeg utility. If this
+ // can ever dynamically change then the corresponding decode
+ // code needs to be updated as well.
+ av_assert0(queue_size == DEFAULT_FRAME_THREAD_QUEUE_SIZE);
+ }
op = (type == QUEUE_PACKETS) ? objpool_alloc_packets() :
objpool_alloc_frames();
@@ -233,6 +233,18 @@ int sch_add_filtergraph(Scheduler *sch, unsigned nb_inputs, unsigned nb_outputs,
*/
int sch_add_mux(Scheduler *sch, SchThreadFunc func, int (*init)(void *),
void *ctx, int sdp_auto, unsigned thread_queue_size);
+
+/**
+ * Default size of a packet thread queue. For muxing this can be overridden by
+ * the thread_queue_size option as passed to a call to sch_add_mux().
+ */
+#define DEFAULT_PACKET_THREAD_QUEUE_SIZE 8
+
+/**
+ * Default size of a frame thread queue.
+ */
+#define DEFAULT_FRAME_THREAD_QUEUE_SIZE 8
+
/**
* Add a muxed stream for a previously added muxer.
*