From patchwork Tue Oct 18 12:36:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38778 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2082690pzb; Tue, 18 Oct 2022 05:38:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6hnIrovUxOwGZTRjp4tJ58Rzzfco+ZSpyRQP3QH5AdzWLgd58ZGX9st9I5hZRPQw3DPvFE X-Received: by 2002:a17:906:4fcb:b0:791:9a26:376f with SMTP id i11-20020a1709064fcb00b007919a26376fmr2232286ejw.431.1666096715767; Tue, 18 Oct 2022 05:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096715; cv=none; d=google.com; s=arc-20160816; b=AGsC54UXoa2RdWqL9mM+SEt2g6DWhUohIPy5qLpSI//53DAmt24EkB4lLE7Wgfr3Q2 xkKzDT/W/h9iJklPT6oLXnI6DTMQomvnsiOZCQWJKQjDqxn8BGFDtHPbTKDnMQyM55FB cocmPLL87cXROfoS9Sf5f+IE18JlrpFvgelqkvcvox5xXwljZCnNc2/uhAVrwkkzIykF DwvZhH1omMDg0YTqmml+o02irXsExJ4g6gXuTq58DbmKLSoaWwQM1AQgAEheepy2dAD4 TDxmNaNYqt2szk+QRjfHbBLR7fChknU0jHFpCHsdEh9yddjmoD2RgCu6gkJ6rQaXIT4V NsfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=hDQfewsgqxUZMn0iJDBpiGmnWDWSU9ZsRKunHqcmxNc=; b=S9xN5lX60t2bppfbNX2eJfklbw6leQl+wPYKKfzSjSM+br5WzGgT5Zcf71IUjP3HyF IxaL7B/68s6JCeHzRu2ZOQVdAWS0ota+411cV0a6tljo1EUY6gL/p+yqSu/KjTuYzO7i l1h8+WwvqLZl5Q8EkeYlSnS4BMrzbw+CYcxiOfmVFpi3322wpE1RKMbj0F87soaJoYI3 B2IlTOLpmHY0d8303qPylIqyG2PfypkeumtujzUon2t+s/95gjtcnw14g0Yrf214ZIcR UzHS8ZwHGJLbh53ltC+JdrGNMjSTSsUXyF0fjq6aBa68lJ6XUKECxaIOkMI+OTAxgEn9 GH6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b31-20020a509f22000000b00453aa9656a3si9967467edf.466.2022.10.18.05.38.35; Tue, 18 Oct 2022 05:38:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 85ABF68B7F8; Tue, 18 Oct 2022 15:38:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59F9468BCE1 for ; Tue, 18 Oct 2022 15:38:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D82B42404F5 for ; Tue, 18 Oct 2022 14:38:14 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id M8k-vKm9jS7G for ; Tue, 18 Oct 2022 14:38:14 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 935FC2404E4 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 999BE3A0922 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:43 +0200 Message-Id: <20221018123701.25002-2-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/20] fftools/ffmpeg_demux: add demuxer private data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: ybDdPxP7OKac Move InputFile.loop into it. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_demux.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 085a775a43..35410ec4a1 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -434,7 +434,6 @@ typedef struct InputFile { int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ int ist_index; /* index of first stream in input_streams */ - int loop; /* set number of times input stream should be looped */ int64_t duration; /* actual duration of the longest stream in a file at the moment when looping happens */ AVRational time_base; /* time base of the duration */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index d2b0bc9a6d..f92500abf9 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -45,6 +45,13 @@ static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL}; static const char *const opt_name_autorotate[] = {"autorotate", NULL}; +typedef struct Demuxer { + InputFile f; + + /* number of times input stream should be looped */ + int loop; +} Demuxer; + typedef struct DemuxMsg { AVPacket *pkt; int looping; @@ -53,6 +60,11 @@ typedef struct DemuxMsg { int repeat_pict; } DemuxMsg; +static Demuxer *demuxer_from_ifile(InputFile *f) +{ + return (Demuxer*)f; +} + static void report_new_stream(InputFile *file, const AVPacket *pkt) { AVStream *st = file->ctx->streams[pkt->stream_index]; @@ -84,8 +96,9 @@ static void ifile_duration_update(InputFile *f, InputStream *ist, } } -static int seek_to_start(InputFile *ifile) +static int seek_to_start(Demuxer *d) { + InputFile *ifile = &d->f; AVFormatContext *is = ifile->ctx; InputStream *ist; int ret; @@ -127,8 +140,8 @@ static int seek_to_start(InputFile *ifile) } } - if (ifile->loop > 0) - ifile->loop--; + if (d->loop > 0) + d->loop--; return ret; } @@ -195,7 +208,8 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) static void *input_thread(void *arg) { - InputFile *f = arg; + Demuxer *d = arg; + InputFile *f = &d->f; AVPacket *pkt; unsigned flags = f->non_blocking ? AV_THREAD_MESSAGE_NONBLOCK : 0; int ret = 0; @@ -216,12 +230,12 @@ static void *input_thread(void *arg) continue; } if (ret < 0) { - if (f->loop) { + if (d->loop) { /* signal looping to the consumer thread */ msg.looping = 1; ret = av_thread_message_queue_send(f->in_thread_queue, &msg, 0); if (ret >= 0) - ret = seek_to_start(f); + ret = seek_to_start(d); if (ret >= 0) continue; @@ -320,6 +334,7 @@ static int init_input_thread(int i) { int ret; InputFile *f = input_files[i]; + Demuxer *d = demuxer_from_ifile(f); if (f->thread_queue_size <= 0) f->thread_queue_size = (nb_input_files > 1 ? 8 : 1); @@ -332,7 +347,7 @@ static int init_input_thread(int i) if (ret < 0) return ret; - if (f->loop) { + if (d->loop) { int nb_audio_dec = 0; for (int i = 0; i < f->nb_streams; i++) { @@ -350,7 +365,7 @@ static int init_input_thread(int i) } } - if ((ret = pthread_create(&f->thread, NULL, input_thread, f))) { + if ((ret = pthread_create(&f->thread, NULL, input_thread, d))) { av_log(NULL, AV_LOG_ERROR, "pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.\n", strerror(ret)); ret = AVERROR(ret); goto fail; @@ -720,6 +735,7 @@ static void dump_attachment(AVStream *st, const char *filename) int ifile_open(OptionsContext *o, const char *filename) { + Demuxer *d; InputFile *f; AVFormatContext *ic; const AVInputFormat *file_iformat = NULL; @@ -923,7 +939,8 @@ int ifile_open(OptionsContext *o, const char *filename) /* dump the file content */ av_dump_format(ic, nb_input_files, filename, 0); - f = ALLOC_ARRAY_ELEM(input_files, nb_input_files); + d = allocate_array_elem(&input_files, sizeof(*d), &nb_input_files); + f = &d->f; f->ctx = ic; f->index = nb_input_files - 1; @@ -936,7 +953,7 @@ int ifile_open(OptionsContext *o, const char *filename) f->nb_streams = ic->nb_streams; f->rate_emu = o->rate_emu; f->accurate_seek = o->accurate_seek; - f->loop = o->loop; + d->loop = o->loop; f->duration = 0; f->time_base = (AVRational){ 1, 1 };