From patchwork Sat Jul 23 14:09:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36930 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a9d:f07:0:b0:61c:acf1:bf6b with SMTP id 7csp644588ott; Sat, 23 Jul 2022 07:13:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYsH0AP7gg9rSbV/mSRklRaKLYkjEwRawkntUbOn5PiXaF7aMKxJVIRJI4P5ZwjQORaP3J X-Received: by 2002:a05:6402:428c:b0:43b:cd8:b679 with SMTP id g12-20020a056402428c00b0043b0cd8b679mr4556619edc.404.1658585633236; Sat, 23 Jul 2022 07:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658585633; cv=none; d=google.com; s=arc-20160816; b=BAkvXmTu3+73dZzaiEriNYXMVKyiMK8PgFCMVfwkBaQRTwA5c6nohHf06IqD6/etiX ziAg3zyCvS5LQt7ryVMvPugaiv0imksfVY1h9drif4wBXcjLKUdmlzoeIC1yQ66KJ/bu EKkh3r3U85KM1m/rF0zeXdboW3CjIWEH+NhkpdOySY/0eXLAUGsDyW+UjyDyIykiMWIi PDAwLaEJJ65OEr1wxfnfKJ3hi6jS9rfjeu6N0HG7yF+7maQSuuLVEzCBgztq+wbgiBDV 1BUnWK9XUfqDe9YOhtutWGezX4Z5+VihuNsZgEkN9CC4sK7wDyn+oNSMlSBb0VBG0Dx7 ehDQ== 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=raOwEscBVZT4UBBJQ7/4Gl+DxsgxiY7Kr8w5Dqdd1lg=; b=v9BRgW9uIs75/sdsvI1DBz25ZFxtqNOjqidJrOfNTQUwyxwi57Qtt1hB08PeC8ABcO Vy1l7CpQK7DzQWVFBs9ocn77cfSSP1RK0MusioIq4ClEdFL0cVe3fVxnLdZMtxuVP21F twQeu5ls8ZeDOWstrVmp/OhvUQvVgMNG/b/wkUbgNpndH/401/Lq4fOn7L6+mVr8X18E KXuNL5HD6i2goWUImevLIjr+Elu+yBHqiqwkJr75LiNxhI9mv7nPcv0cx8j6TK2mSDtV +NPAqDNQKFTQL7OnRbbVeS8ZLFcvj965TBC55wdEYx5LCd4YdmMBq3/8QBRqgKIqOWL1 IniQ== 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 hr34-20020a1709073fa200b0072ecfeec4cbsi10140524ejc.463.2022.07.23.07.13.52; Sat, 23 Jul 2022 07:13:53 -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 410D268B8F0; Sat, 23 Jul 2022 17:10:49 +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 60FC568B808 for ; Sat, 23 Jul 2022 17:10:27 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7214424050B for ; Sat, 23 Jul 2022 16:10:23 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id HnUetkFBqKQL for ; Sat, 23 Jul 2022 16:10:22 +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 928EC240555 for ; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 964FB3A04C6; Sat, 23 Jul 2022 16:10:19 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Jul 2022 16:09:41 +0200 Message-Id: <20220723140952.31814-16-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220723140952.31814-1-anton@khirnov.net> References: <20220723140952.31814-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/27] fftools/ffmpeg_mux: move some functions closer to their only callers 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: NDTwgc6LYbuk Content-Length: 6711 --- fftools/ffmpeg_mux.c | 196 +++++++++++++++++++++---------------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 7f6da997a4..08a76f0066 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -74,48 +74,6 @@ struct Muxer { static int want_sdp = 1; -static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) -{ - MuxStream *ms = &of->mux->streams[ost->index]; - AVPacket *tmp_pkt = NULL; - int ret; - - if (!av_fifo_can_write(ms->muxing_queue)) { - size_t cur_size = av_fifo_can_read(ms->muxing_queue); - size_t pkt_size = pkt ? pkt->size : 0; - unsigned int are_we_over_size = - (ms->muxing_queue_data_size + pkt_size) > ost->muxing_queue_data_threshold; - size_t limit = are_we_over_size ? ost->max_muxing_queue_size : SIZE_MAX; - size_t new_size = FFMIN(2 * cur_size, limit); - - if (new_size <= cur_size) { - av_log(NULL, AV_LOG_ERROR, - "Too many packets buffered for output stream %d:%d.\n", - ost->file_index, ost->st->index); - return AVERROR(ENOSPC); - } - ret = av_fifo_grow2(ms->muxing_queue, new_size - cur_size); - if (ret < 0) - return ret; - } - - if (pkt) { - ret = av_packet_make_refcounted(pkt); - if (ret < 0) - return ret; - - tmp_pkt = av_packet_alloc(); - if (!tmp_pkt) - return AVERROR(ENOMEM); - - av_packet_move_ref(tmp_pkt, pkt); - ms->muxing_queue_data_size += tmp_pkt->size; - } - av_fifo_write(ms->muxing_queue, &tmp_pkt, 1); - - return 0; -} - static int64_t filesize(AVIOContext *pb) { int64_t ret = -1; @@ -289,62 +247,6 @@ finish: return (void*)(intptr_t)ret; } -static int print_sdp(void) -{ - char sdp[16384]; - int i; - int j, ret; - AVIOContext *sdp_pb; - AVFormatContext **avc; - - for (i = 0; i < nb_output_files; i++) { - if (!output_files[i]->mux->header_written) - return 0; - } - - avc = av_malloc_array(nb_output_files, sizeof(*avc)); - if (!avc) - return AVERROR(ENOMEM); - for (i = 0, j = 0; i < nb_output_files; i++) { - if (!strcmp(output_files[i]->format->name, "rtp")) { - avc[j] = output_files[i]->mux->fc; - j++; - } - } - - if (!j) { - av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); - ret = AVERROR(EINVAL); - goto fail; - } - - ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); - if (ret < 0) - goto fail; - - if (!sdp_filename) { - printf("SDP:\n%s\n", sdp); - fflush(stdout); - } else { - ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); - goto fail; - } - - avio_print(sdp_pb, sdp); - avio_closep(&sdp_pb); - av_freep(&sdp_filename); - } - - // SDP successfully written, allow muxer threads to start - ret = 1; - -fail: - av_freep(&avc); - return ret; -} - static int submit_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) { Muxer *mux = of->mux; @@ -368,6 +270,48 @@ finish: return ret == AVERROR_EOF ? 0 : ret; } +static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) +{ + MuxStream *ms = &of->mux->streams[ost->index]; + AVPacket *tmp_pkt = NULL; + int ret; + + if (!av_fifo_can_write(ms->muxing_queue)) { + size_t cur_size = av_fifo_can_read(ms->muxing_queue); + size_t pkt_size = pkt ? pkt->size : 0; + unsigned int are_we_over_size = + (ms->muxing_queue_data_size + pkt_size) > ost->muxing_queue_data_threshold; + size_t limit = are_we_over_size ? ost->max_muxing_queue_size : SIZE_MAX; + size_t new_size = FFMIN(2 * cur_size, limit); + + if (new_size <= cur_size) { + av_log(NULL, AV_LOG_ERROR, + "Too many packets buffered for output stream %d:%d.\n", + ost->file_index, ost->st->index); + return AVERROR(ENOSPC); + } + ret = av_fifo_grow2(ms->muxing_queue, new_size - cur_size); + if (ret < 0) + return ret; + } + + if (pkt) { + ret = av_packet_make_refcounted(pkt); + if (ret < 0) + return ret; + + tmp_pkt = av_packet_alloc(); + if (!tmp_pkt) + return AVERROR(ENOMEM); + + av_packet_move_ref(tmp_pkt, pkt); + ms->muxing_queue_data_size += tmp_pkt->size; + } + av_fifo_write(ms->muxing_queue, &tmp_pkt, 1); + + return 0; +} + int of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) { int ret; @@ -456,6 +400,62 @@ static int thread_start(OutputFile *of) return 0; } +static int print_sdp(void) +{ + char sdp[16384]; + int i; + int j, ret; + AVIOContext *sdp_pb; + AVFormatContext **avc; + + for (i = 0; i < nb_output_files; i++) { + if (!output_files[i]->mux->header_written) + return 0; + } + + avc = av_malloc_array(nb_output_files, sizeof(*avc)); + if (!avc) + return AVERROR(ENOMEM); + for (i = 0, j = 0; i < nb_output_files; i++) { + if (!strcmp(output_files[i]->format->name, "rtp")) { + avc[j] = output_files[i]->mux->fc; + j++; + } + } + + if (!j) { + av_log(NULL, AV_LOG_ERROR, "No output streams in the SDP.\n"); + ret = AVERROR(EINVAL); + goto fail; + } + + ret = av_sdp_create(avc, j, sdp, sizeof(sdp)); + if (ret < 0) + goto fail; + + if (!sdp_filename) { + printf("SDP:\n%s\n", sdp); + fflush(stdout); + } else { + ret = avio_open2(&sdp_pb, sdp_filename, AVIO_FLAG_WRITE, &int_cb, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Failed to open sdp file '%s'\n", sdp_filename); + goto fail; + } + + avio_print(sdp_pb, sdp); + avio_closep(&sdp_pb); + av_freep(&sdp_filename); + } + + // SDP successfully written, allow muxer threads to start + ret = 1; + +fail: + av_freep(&avc); + return ret; +} + /* open the muxer when all the streams are initialized */ int of_check_init(OutputFile *of) {