From patchwork Wed Aug 24 08:43:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 37450 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp2372003pzh; Wed, 24 Aug 2022 01:46:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lLPJp8A0PCkfsJsPrIH2r9ZzmVmPOK6mJtORDX0tIPG8cDkVZjvr4qTiFsTNI4iS+4Cb7 X-Received: by 2002:a17:907:7256:b0:73d:9c6b:35e2 with SMTP id ds22-20020a170907725600b0073d9c6b35e2mr2182663ejc.197.1661330785077; Wed, 24 Aug 2022 01:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661330785; cv=none; d=google.com; s=arc-20160816; b=uCzoJd78napIX235wmWjeDpmh44wPL/pnfPjtG4XEw0Hs4cWOZ7we+bR7a6HLbORQB nyJcPeAhIW/m6c0wBV99CWZAUF5kpN+6mdlB8Kt1M/FiBjr+s9AygtP6issLcPmKMrLj SD3Sqf8rUy4/Z2v9OstE5JggkPCAIVju6GITS0qgZ5GGLrKEhjoOiEqw09VjQfRPtnhN nv69SRV8BwytaoYtFy9FIsiosQKme2qhcR9DNTqv1m6csz6odhakpeYdPX1rg7UpqAJF rcbNYD9M7C8YB2kqInTchAOyfT7GMW+yQcs4C3QzIce3EQeAKASzihmRi23BZTzGgQcY Yqlg== 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=z+rGh2yr7m7uzPY2QO64/Q2sIQVLrX5H/8UcfxkilJQ=; b=nAQMERdnOCXJQaf7Tbz3aDj0M2OFonv0aM42f3SfO57mVNiJcieNeDslbq3kJRtADj SiSW8hB68zvseMu6pWNVWHY4LRdjx+bP4c/Y7cj0SF1OR7zwoGFPDBXTwraQHv9kwkCj ilRMiNPtAdX1TZn+kiE8rYCe2OyonzLbaYPH9XkxKzuSorTcC42rzhk2yGpOG8B51LXK 4K6i/hu6krrkckhv57VA2iFhH3z6eIzPib9RAO+1r4iDJFcjl1aomSBYeDDTIAoMSNGF oQ86SUKpi9wgsLr9VXjkqtVCdNXe0tWdK2uPe7pmhtz4jgaBY9HcbS9PKKakhpv093/2 V02Q== 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 l21-20020a1709065a9500b0073d567769a9si1368656ejq.437.2022.08.24.01.46.24; Wed, 24 Aug 2022 01:46:25 -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 14C3B68BA75; Wed, 24 Aug 2022 11:44:07 +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 6327E68BA1B for ; Wed, 24 Aug 2022 11:43:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3AA14240D1F for ; Wed, 24 Aug 2022 10:43:46 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id DSAJqzMzYDs5 for ; Wed, 24 Aug 2022 10:43:45 +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 B9CCC240D21 for ; Wed, 24 Aug 2022 10:43:41 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id B9DEA3A2638; Wed, 24 Aug 2022 10:43:35 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Aug 2022 10:43:17 +0200 Message-Id: <20220824084318.333-17-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220824084318.333-1-anton@khirnov.net> References: <20220824084318.333-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] lavf/dv: do not update AVCodecParameters.sample_rate while demuxing 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: 4uHQ9spHOoVe Demuxers are not allowed to do this and few callers, if any, will handle this correctly. Send the AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE side data instead. --- libavformat/dv.c | 49 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/libavformat/dv.c b/libavformat/dv.c index 9c8b0a262c..ffed1a7a90 100644 --- a/libavformat/dv.c +++ b/libavformat/dv.c @@ -33,6 +33,7 @@ #include #include "avformat.h" +#include "demux.h" #include "internal.h" #include "libavcodec/dv_profile.h" #include "libavcodec/dv.h" @@ -46,7 +47,7 @@ #if CONFIG_DV_DEMUXER // Must be kept in sync with AVPacket -struct DVPacket { +typedef struct DVPacket { int64_t pts; uint8_t *data; int size; @@ -54,7 +55,10 @@ struct DVPacket { int flags; int64_t pos; int64_t duration; -}; + + int sample_rate; + int last_sample_rate; +} DVPacket; struct DVDemuxContext { const AVDVProfile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */ @@ -237,7 +241,7 @@ static int dv_extract_audio(const uint8_t *frame, uint8_t **ppcm, static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) { const uint8_t *as_pack; - int freq, stype, smpls, quant, i, ach; + int freq, stype, smpls, quant, i, ach, sr; as_pack = dv_extract_pack(frame, DV_AUDIO_SOURCE); if (!as_pack || !c->sys) { /* No audio ? */ @@ -255,6 +259,7 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) "Unrecognized audio sample rate index (%d)\n", freq); return 0; } + sr = dv_audio_frequency[freq]; if (stype > 3) { av_log(c->fctx, AV_LOG_ERROR, "stype %d is invalid\n", stype); @@ -280,7 +285,10 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE; c->ast[i]->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; c->ast[i]->start_time = 0; - c->ast[i]->codecpar->bit_rate = 2 * dv_audio_frequency[freq] * 16; + c->ast[i]->codecpar->bit_rate = 2 * sr * 16; + + c->ast[i]->codecpar->sample_rate = sr; + c->audio_pkt[i].last_sample_rate = sr; c->audio_pkt[i].size = 0; c->audio_pkt[i].data = c->audio_buf[i]; @@ -290,7 +298,8 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame) c->audio_pkt[i].duration = 0; c->audio_pkt[i].pos = -1; } - c->ast[i]->codecpar->sample_rate = dv_audio_frequency[freq]; + + c->audio_pkt[i].sample_rate = sr; } c->ach = ach; @@ -380,16 +389,26 @@ int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt) for (i = 0; i < c->ach; i++) { if (c->ast[i] && c->audio_pkt[i].size) { - pkt->size = c->audio_pkt[i].size; - pkt->data = c->audio_pkt[i].data; - pkt->stream_index = c->audio_pkt[i].stream_index; - pkt->flags = c->audio_pkt[i].flags; - pkt->pts = c->audio_pkt[i].pts; - pkt->duration = c->audio_pkt[i].duration; - pkt->pos = c->audio_pkt[i].pos; - - c->audio_pkt[i].size = 0; - size = pkt->size; + DVPacket *dpkt = &c->audio_pkt[i]; + + pkt->size = dpkt->size; + pkt->data = dpkt->data; + pkt->stream_index = dpkt->stream_index; + pkt->flags = dpkt->flags; + pkt->pts = dpkt->pts; + pkt->duration = dpkt->duration; + pkt->pos = dpkt->pos; + + dpkt->size = 0; + size = pkt->size; + + if (dpkt->last_sample_rate != dpkt->sample_rate) { + int ret = ff_add_param_change(pkt, 0, 0, dpkt->sample_rate, 0, 0); + if (ret < 0) + return ret; + dpkt->last_sample_rate = dpkt->sample_rate; + } + break; } }