From patchwork Sat Jul 18 20:07:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 21181 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 D0DEE44A173 for ; Sat, 18 Jul 2020 23:08:07 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A405768B7A4; Sat, 18 Jul 2020 23:08:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 04A3068B5B3 for ; Sat, 18 Jul 2020 23:08:00 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 255B2E4303; Sat, 18 Jul 2020 22:08:00 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UkPluB0sjQw4; Sat, 18 Jul 2020 22:07:57 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 86FEFE3E33; Sat, 18 Jul 2020 22:07:57 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Jul 2020 22:07:51 +0200 Message-Id: <20200718200751.29343-1-cus@passwd.hu> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: make specifying thread_queue_size turn on threaded input 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Threaded input can increase smoothness of e.g. x11grab significantly. Before this patch, in order to activate threaded input the user had to specify a "dummy" additional input, with this change it is no longer required. Signed-off-by: Marton Balint --- doc/ffmpeg.texi | 5 +++-- fftools/ffmpeg.c | 6 ++++-- fftools/ffmpeg_opt.c | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 70b8965d7f..267ddfe8b5 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1689,8 +1689,9 @@ not start from timestamp 0, such as transport streams. @item -thread_queue_size @var{size} (@emph{input}) This option sets the maximum number of queued packets when reading from the file or device. With low latency / high rate live streams, packets may be -discarded if they are not read in a timely manner; raising this value can -avoid it. +discarded if they are not read in a timely manner; setting this value can +force ffmpeg to use a separate input thread and read packets as soon as they +arrive. By default ffmpeg only do this if multiple inputs are specified. @item -sdp_file @var{file} (@emph{global}) Print sdp information for an output stream to @var{file}. diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448ea2b..173ac3c9a0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4051,7 +4051,9 @@ static int init_input_thread(int i) int ret; InputFile *f = input_files[i]; - if (nb_input_files == 1) + if (f->thread_queue_size < 0) + f->thread_queue_size = (nb_input_files > 1 ? 8 : 0); + if (!f->thread_queue_size) return 0; if (f->ctx->pb ? !f->ctx->pb->seekable : @@ -4105,7 +4107,7 @@ static int get_input_packet(InputFile *f, AVPacket *pkt) } #if HAVE_THREADS - if (nb_input_files > 1) + if (f->thread_queue_size) return get_input_packet_mt(f, pkt); #endif return av_read_frame(f->ctx, pkt); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 9d1489ce01..853550a142 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -228,6 +228,7 @@ static void init_options(OptionsContext *o) o->limit_filesize = UINT64_MAX; o->chapters_input_file = INT_MAX; o->accurate_seek = 1; + o->thread_queue_size = -1; } static int show_hwaccels(void *optctx, const char *opt, const char *arg) @@ -1270,7 +1271,7 @@ static int open_input_file(OptionsContext *o, const char *filename) f->duration = 0; f->time_base = (AVRational){ 1, 1 }; #if HAVE_THREADS - f->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8; + f->thread_queue_size = o->thread_queue_size; #endif /* check if all codec options have been used */