From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id CBE4742237 for ; Thu, 16 Dec 2021 23:42:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6489168AFBA; Fri, 17 Dec 2021 01:42:35 +0200 (EET) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073051.outbound.protection.outlook.com [40.92.73.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CF71668A22C for ; Fri, 17 Dec 2021 01:42:28 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eeLYkr1IkxXT/ZgLt/YOYS8Be0wieJNxuWU4Glw1EBHlLCxeGBn5v3BtyOkd1cpydjCKCGqPP1roJlYYcvqMt7v16SCV4SHOHJTMKPwXJ6F/DlMfpUJGFT2ps26RwxrOT+6aSVS+wCsPzrgS/DKeXyMBDALBxhmwT4EjEiMKZZje3b2Ytko7ZcDY1cqXTpp0xxuCCNOUwddWZAtRnIgxZHij+A2ezSVWcBT/XoCcKhNWoGNlxg+sjf94s7e5AdbHDBSWPvwlVbRGdi8tF60kSDicScd23+ZY5/RPfw5mav7ryCpY3sLEpVSB9wv91f6peAoonhP8kyL5togb2czbjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Z4h+HXGX+eX8EYTDiSD7YbsGB24JszMpYFAKP6P6Mw4=; b=Hr3L591BmTZZ9vkSIlJwka9UyO0MYe/t2NoO+nOmQYWvlGbptpSRxLng3yeHH0vtPezrR2dpiU4iFCX7gwsuZdC4yHhWaCnfq2CaXEKdaZLUDrz9NlYX6ga03tRiMuwNCJ9DwfASbDlPiSlPlJJXCPTxY//UzHrgBDCiNayoD07Yt7wo9RlOSrs3vfFMe6wRBFheP9kGAMy9G/986kEdJACI7B2rHezIPkjveSEIJ8izlfOWHwr+QFfTCEBkUqJFCVVnuGEFrhFbAF3/g+hB6X9o/I7LB7b8MCOzQPnNiQImXpgOgF5v9BaO43BTLkLiLUdeZZF/Ctlz1oxB78qPfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Z4h+HXGX+eX8EYTDiSD7YbsGB24JszMpYFAKP6P6Mw4=; b=KmkeQcb4ZQC2wXZse7QVbZWN9cjZ1YSIPqD1WxSXAYzN689qp03Uzu3Mu5rm1ML/JmDkQd9+vorsDPXV+L19/8YFiaOHUoLIegsuM0GuZsJ8YOOrUgUcDiAWJbNzv8ziBWaBIoXPwW3YN2j01k/Se80XMc2ZJ8gtJYSbdkk9kJR9hlmB3148wn9jq4QajLoyB0KV3AOS63XCJ97CNBfxSFtJrRQ+oHhYqbHgAyI9+4WHee3H1hAmh/HBD7DEsiouMQkLfI34wuobmWtGrVWnuu9iLawIWL1ReVuSCdD4oKLvikHuSf3/bDXYCGlbNsKRBJgCP6yFsiBTK6AbxP29fw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4214.eurprd03.prod.outlook.com (2603:10a6:20b:6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.14; Thu, 16 Dec 2021 23:42:26 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%6]) with mapi id 15.20.4801.015; Thu, 16 Dec 2021 23:42:26 +0000 Message-ID: Date: Fri, 17 Dec 2021 00:42:25 +0100 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20211213152042.5900-1-anton@khirnov.net> <20211213152042.5900-21-anton@khirnov.net> From: Andreas Rheinhardt In-Reply-To: <20211213152042.5900-21-anton@khirnov.net> X-TMN: [Oa5Inipt0OmhPa7F7IbXRLikEI+LkQLX] X-ClientProxiedBy: AS9PR06CA0403.eurprd06.prod.outlook.com (2603:10a6:20b:461::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1acd3b15-d3cb-4818-54b8-08d9c0edb6f8 X-MS-TrafficTypeDiagnostic: AM6PR03MB4214:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7kxw55JRRgXi86k1dqtVLKDG9nsbCn2QyRnE0Wasi+0jL4ugwtQ7i1gdElFzCXg69Km+efzWNCbViO7htGKAsZOq0dIFMd/2yzkuOPglHxIEcx9ATGR+vsWEn0xswzUqJRyPZsLDoAkkMeyD7Q1sAChFKM1zdvrDCjbS3GlN6ke/xtU5O5ZSK1CiALiH67ri7dmdIl61y5pskMJp1enKllkPnbgVHfDmC+a2HiDr//vJ4iyCyRWFQSwt0cAEm7YQo+3c5BZT9fAQSBgLGfZUcoqhdImtAB/hBjpywBnVWaprPeOaF5DPsYzF1LsFAX3FzFMR8WDH5At/7iqDJB8Vj/1BkUh10EkuLQjRSAQ/QuK5YxYNFuYm8yR3VV6ayS4HyjahQ5ImxHoVjQh3srZESJxtogNgxLkey2NWxIz2L9Tfn87gI2Tdm7BZHyszaTaE4yJwLQvtsMVPrM3JlDLItEfr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JMFdxMC9xNXNGT3NxN3FWdStaS0hKa1NDTy8yeXJKeG9kM2Uv?= =?utf-8?B?SzV3ZUVrYlN4MDF1dm1mbThYNCszbnM1NEdkNUxXb0ZPQ1c1U045RGd5dmhp?= =?utf-8?B?MnlVd0cvNGw4ZzZ2WFNlUHJwcU5HSEdaOHYwRDBiNDNyeDZMdHVtT0gvVUlE?= =?utf-8?B?RExGa0hUaGVmWEt1RHAvdjEvTDg5MGpOUUwxTE41bUxHWG5PS0dsSXl0ckFu?= =?utf-8?B?NXlHOEw2aGt3Sm9yclRTWXM2NXpkbk1TczVvbno0djJsMXI4cjZtN2hMemtB?= =?utf-8?B?RjdrcGRFVFAzRDJOdVB2Wkk4K2k5Tzl6TTdsQ0J4S2RJSGlJQ1BrZFNiZllw?= =?utf-8?B?TjhYV3pEY2ZnTDYxUldBU2QwTk9IMkd0bXJqMHl1Z0hSdUFqNCs1dlZYbU1J?= =?utf-8?B?UC9OUHJSMEliN0hFWGxmWEFCYUp5dWlqSUxVZWNoWnlaUUlJa0NmRXNHb1du?= =?utf-8?B?WEN5TnM5aVBFb2NNejgxb1MrMWN6VUFCdExCNTNVanJSUWNiNlp1aVMzZjh2?= =?utf-8?B?K294RVFjQnVjbkY2Vlh1TjlpSWFOUFlucC9lRXFqcG5YMFVadz09?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1acd3b15-d3cb-4818-54b8-08d9c0edb6f8 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2021 23:42:26.0863 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR03MB4214 Subject: Re: [FFmpeg-devel] [PATCH 21/24] ffmpeg_mux: split of_write_packet() 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Anton Khirnov: > It is currently called from two places: > - output_packet() in ffmpeg.c, which submits the newly available output > packet to the muxer > - from of_check_init() in ffmpeg_mux.c after the header has been > written, to flush the muxing queue > > Some packets will thus be processed by this function twice, so it > requires an extra parameter to indicate the place it is called from and > avoid modifying some state twice. > > This is fragile and hard to follow, so split this function into two. > Also rename of_write_packet() to of_submit_packet() to better reflect > its new purpose. > --- > fftools/ffmpeg.c | 4 +-- > fftools/ffmpeg.h | 3 +-- > fftools/ffmpeg_mux.c | 63 ++++++++++++++++++++++++-------------------- > 3 files changed, 37 insertions(+), 33 deletions(-) > > diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c > index e9a5c0f523..bbedf867b4 100644 > --- a/fftools/ffmpeg.c > +++ b/fftools/ffmpeg.c > @@ -728,11 +728,11 @@ static void output_packet(OutputFile *of, AVPacket *pkt, > if (ret < 0) > goto finish; > while ((ret = av_bsf_receive_packet(ost->bsf_ctx, pkt)) >= 0) > - of_write_packet(of, pkt, ost, 0); > + of_submit_packet(of, pkt, ost); > if (ret == AVERROR(EAGAIN)) > ret = 0; > } else if (!eof) > - of_write_packet(of, pkt, ost, 0); > + of_submit_packet(of, pkt, ost); > > finish: > if (ret < 0 && ret != AVERROR_EOF) { > diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h > index e6e472f994..76c8dfa4c8 100644 > --- a/fftools/ffmpeg.h > +++ b/fftools/ffmpeg.h > @@ -684,8 +684,7 @@ int of_check_init(OutputFile *of); > int of_write_trailer(OutputFile *of); > void of_close(OutputFile **pof); > > -void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, > - int unqueue); > +void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost); > int of_finished(OutputFile *of); > int64_t of_bytes_written(OutputFile *of); > AVChapter * const * > diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c > index d4b674c9e2..e97ec8ab93 100644 > --- a/fftools/ffmpeg_mux.c > +++ b/fftools/ffmpeg_mux.c > @@ -102,39 +102,12 @@ static int queue_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) > return 0; > } > > -void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, > - int unqueue) > +static void write_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) > { > AVFormatContext *s = of->ctx; > AVStream *st = ost->st; > int ret; > > - /* > - * Audio encoders may split the packets -- #frames in != #packets out. > - * But there is no reordering, so we can limit the number of output packets > - * by simply dropping them here. > - * Counting encoded video frames needs to be done separately because of > - * reordering, see do_video_out(). > - * Do not count the packet when unqueued because it has been counted when queued. > - */ > - if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed) && !unqueue) { > - if (ost->frame_number >= ost->max_frames) { > - av_packet_unref(pkt); > - return; > - } > - ost->frame_number++; > - } Factoring this chunk out of write_packet() (effectively inlining unqueue) looks good (and I actually pondered it myself), > - > - /* the muxer is not initialized yet, buffer the packet */ > - if (!of->mux->header_written) { > - ret = queue_packet(of, ost, pkt); > - if (ret < 0) { > - av_packet_unref(pkt); > - exit_program(1); > - } > - return; > - } > - but I could not prove that the header has already been written in case unqueue == 0. Can you guarantee this to be so and explain it to me? > if ((st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && video_sync_method == VSYNC_DROP) || > (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && audio_sync_method < 0)) > pkt->pts = pkt->dts = AV_NOPTS_VALUE; > @@ -225,6 +198,38 @@ void of_write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, > } > } > > +void of_submit_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost) > +{ > + AVStream *st = ost->st; > + int ret; > + > + /* > + * Audio encoders may split the packets -- #frames in != #packets out. > + * But there is no reordering, so we can limit the number of output packets > + * by simply dropping them here. > + * Counting encoded video frames needs to be done separately because of > + * reordering, see do_video_out(). > + */ > + if (!(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ost->encoding_needed)) { > + if (ost->frame_number >= ost->max_frames) { > + av_packet_unref(pkt); > + return; > + } > + ost->frame_number++; > + } > + > + if (of->mux->header_written) { > + write_packet(of, ost, pkt); > + } else { > + /* the muxer is not initialized yet, buffer the packet */ > + ret = queue_packet(of, ost, pkt); > + if (ret < 0) { > + av_packet_unref(pkt); > + exit_program(1); > + } > + } > +} > + > static int print_sdp(void) > { > char sdp[16384]; > @@ -324,7 +329,7 @@ int of_check_init(OutputFile *of) > AVPacket *pkt; > av_fifo_generic_read(ms->muxing_queue, &pkt, sizeof(pkt), NULL); > ms->muxing_queue_data_size -= pkt->size; > - of_write_packet(of, pkt, ost, 1); > + write_packet(of, ost, pkt); > av_packet_free(&pkt); > } > } > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".