Avoid constant N frames latency in video streaming.
Signed-off-by: Jianhui Dai <[email protected]>
---
libavcodec/pthread_frame.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index b5bd494474..aeb42800ef 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -130,11 +130,6 @@ typedef struct FrameThreadContext {
int next_decoding; ///< The next context to submit a packet to.
int next_finished; ///< The next context to return output from.
-
- int delaying; /**<
- * Set for the first N packets, where N is
the number of threads.
- * While it is set,
ff_thread_en/decode_frame won't return any results.
- */
} FrameThreadContext;
#define THREAD_SAFE_CALLBACKS(avctx) \
@@ -492,14 +487,8 @@ int ff_thread_decode_frame(AVCodecContext *avctx,
if (err)
goto finish;
- /*
- * If we're still receiving the initial packets, don't return a frame.
- */
-
- if (fctx->next_decoding > (avctx->thread_count-1-(avctx->codec_id ==
AV_CODEC_ID_FFV1)))
- fctx->delaying = 0;
-
- if (fctx->delaying) {
+ if (((fctx->next_decoding + 1) % avctx->thread_count) != finished &&
+ atomic_load(&fctx->threads[finished].state) != STATE_INPUT_READY) {
*got_picture_ptr=0;
if (avpkt->size) {
err = avpkt->size;
@@ -763,7 +752,6 @@ int ff_frame_thread_init(AVCodecContext *avctx)
pthread_cond_init(&fctx->async_cond, NULL);
fctx->async_lock = 1;
- fctx->delaying = 1;
for (i = 0; i < thread_count; i++) {
AVCodecContext *copy = av_malloc(sizeof(AVCodecContext));
@@ -854,7 +842,6 @@ void ff_thread_flush(AVCodecContext *avctx)
}
fctx->next_decoding = fctx->next_finished = 0;
- fctx->delaying = 1;
fctx->prev_thread = NULL;
for (i = 0; i < avctx->thread_count; i++) {
PerThreadContext *p = &fctx->threads[i];
--
2.17.1
_______________________________________________
ffmpeg-devel mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".