From patchwork Thu May 7 06:17:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: leozhang X-Patchwork-Id: 19523 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 433754496D2 for ; Thu, 7 May 2020 09:17:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28312689E33; Thu, 7 May 2020 09:17:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smg-bj-02.qiyi.com (unknown [202.108.14.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7C4D5689CDF for ; Thu, 7 May 2020 09:17:12 +0300 (EEST) X-AuditID: ca6c0e64-3bfff70000008de1-ae-5eb3a7e5db51 Received: from mail.iqiyi.com (Unknown_Domain [10.16.130.3]) by smg-bj-02.qiyi.com (Qiyi mail Gateway) with SMTP id 31.C9.36321.5E7A3BE5; Thu, 7 May 2020 14:17:09 +0800 (HKT) From: leozhang To: Date: Thu, 7 May 2020 14:17:05 +0800 Message-ID: <1588832225-63654-1-git-send-email-leozhang@qiyi.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.13.40.147] X-ClientProxiedBy: BJ-CAS25.iqiyi.pps (10.11.50.117) To EXCH28B.iqiyi.pps (10.16.148.55) Subject: [FFmpeg-devel] [PATCH v2 2/3] avformat/fifo: add a seperate function which sleeps any specified duration 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Suggested-by: Nicolas George Reviewed-by: Nicolas George Reviewed-by: Marton Balint Reviewed-by: Andreas Rheinhardt Signed-off-by: leozhang --- libavformat/fifo.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavformat/fifo.c b/libavformat/fifo.c index 7acc420..b819aeb 100644 --- a/libavformat/fifo.c +++ b/libavformat/fifo.c @@ -123,6 +123,13 @@ typedef struct FifoMessage { AVPacket pkt; } FifoMessage; +static void fifo_sleep(int64_t duration) +{ + for (; duration > 600000000; duration -= 600000000) + av_usleep(600000000); + av_usleep(duration); +} + static int fifo_thread_write_header(FifoThreadContext *ctx) { AVFormatContext *avf = ctx->avf; @@ -214,9 +221,7 @@ static int fifo_thread_write_packet(FifoThreadContext *ctx, AVPacket *pkt) if (sleep > 0) { av_log(avf, AV_LOG_DEBUG, "sleeping %"PRIi64" us\n", sleep); - for (; sleep > 600000000; sleep -= 600000000) - av_usleep(600000000); - av_usleep(sleep); + fifo_sleep(sleep); } }