From patchwork Tue Mar 10 09:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dai, Jianhui J" X-Patchwork-Id: 18105 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id AF3EE44931B for ; Tue, 10 Mar 2020 11:37:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 918886881E1; Tue, 10 Mar 2020 11:37:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8502A688170 for ; Tue, 10 Mar 2020 11:36:55 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Mar 2020 02:36:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,518,1574150400"; d="scan'208";a="321740526" Received: from webrtc67.sh.intel.com ([10.239.61.11]) by orsmga001.jf.intel.com with ESMTP; 10 Mar 2020 02:36:52 -0700 From: Jianhui Dai To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Mar 2020 17:36:40 +0800 Message-Id: <20200310093640.79848-1-jianhui.j.dai@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] pthread_frame: attempt to get frame to reduce latency X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Jianhui Dai MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Avoid constant N frames latency in video streaming. Signed-off-by: Jianhui Dai --- 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];