From patchwork Tue May 21 09:02:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 49095 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp5097639pzb; Tue, 21 May 2024 02:05:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWgQa8aODLIBxekryTboNqnmdTB7Eb9wgvc0sdNLHYzNYgT7eBskuxeUIwzg29BK+dIGbZvzP8w+hkwp4DosrT6yxu2FrIrjQzWEQ== X-Google-Smtp-Source: AGHT+IHLvasxJAqWDeJRIVRApwj7ry/JZyQRfeg6CzFBWizVujvzVy6X2FkpoW5zz8WLp49O++tr X-Received: by 2002:a2e:9e14:0:b0:2e1:c97b:6f1f with SMTP id 38308e7fff4ca-2e5203a795emr202055491fa.51.1716282353170; Tue, 21 May 2024 02:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716282353; cv=none; d=google.com; s=arc-20160816; b=ko9cI0Q3F37748l3MbPRTXH2lCoJzUcB0hk3jd4lhdEI5e0H8trENWH7x57T2Lsuot eMWS3aaxMVu7QXSq03nG3rPnG4X0AZ9lHTXsSao53Wc5/ggPKkdiytu+iSjBPC8hWszp iSxmkOEpP6iTcC8WLyA0WgzITI//G5g1cc8taxE+Oreu/GkgoU+hpctQa5ronRCSMaRS ePWwenK4lhMHNSJ/MxHXaxPBCxavmGlsF/KKX3e1Kuw9VfMpj5/mWqfQhE0CJsbJgrko oobVRo7ZtKK1G2O3rrwgjbHwJxPIAq59Wlya7T8o6pkUtOB7kvcyBMeoxqwbfTlMDSM9 oSJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:dkim-signature:delivered-to; bh=N7XW3DzJEH1NveE7KDz+f1m+YWuP+EPM4PzgtmunYkQ=; fh=LnlYe9qYwgML7nWWXqAumr7YCmPjjpEPjQf6GasgJC0=; b=vhTlJtYNLdK5GS6+91xpTOZMQke0Jo1cBWiHVc47VTzpw9IkROz5E2EqBgH83QDxeL xyeNYFbkgtCpNuxRp0CDTbknxHlNN2FK7tvxWDU/K4bFdWpSqBJ1r3HKuzSzpeVZOA+u 7epQXJdTvR1ysJi98z9QmRNPm4h7fA0spbWzd76IFNrQheO/5kgpojondD08RkZBpPuE GUeIF2ZpNOgJ6DaalGB9wLnYgmW00+F3qhzUGG2Q7J9vzQ9bH97I/EKzmt6FH7qCFJRA FUCYbGo3ff6bAfLUHzH1QjGgM1uFiOgmKKtofWivt6bW5ttt4zELCmdbE/KyyTJIHpOT 9lOQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=TMBPAs9B; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2e4d0ce30c6si77288201fa.157.2024.05.21.02.05.52; Tue, 21 May 2024 02:05: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; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=TMBPAs9B; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 280E268D294; Tue, 21 May 2024 12:03:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 472FD68D392 for ; Tue, 21 May 2024 12:03:43 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id D754427FFD298; Tue, 21 May 2024 11:03:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1716282218; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U3P6IKRdJP8K+iN/gEUIVGT/h7SBYq7YFLCQrmFiMhg=; b=TMBPAs9BbnenoyUFYgnvzl7+fHm/dQ+hd6cY9PGnbp3ghwRNFRAnCdFwYIQTJNVhrhAhQ/ aN8QojK18fUwiG7j5D0zZhqo3ohu2Iz4R17o0F9RMB8Te0cWLXB+d0P0GrqbRCZugo7eHC icifcTodkyyWawyix70H7x4hU8+4y1hP5zvKbA/jGD0LyAxv4chzs3X7ck/2hIMQcsWUpM 10jIxh69NBJXDQTLFTWFjYDh4NwHWc+eAZzdJOBGG/spCNg0Jd60W3bQoYNUFviokGlBG9 a/kh+mUckb6Sm6u4t3db1HSv7I2JzDUpuvBB0JiOFvpU64bfttJXl4ONg1Lw4A== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 May 2024 11:02:17 +0200 Message-ID: <20240521090316.782-9-timo@rothenpieler.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240521090316.782-1-timo@rothenpieler.org> References: <20240521090316.782-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/13] avformat/flvdec: parse enhanced rtmp multichannel info 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 Cc: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BmSrXJx2Tywe --- libavformat/flvdec.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index ee2a1931b2..890958351a 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -1335,8 +1335,6 @@ retry: enhanced_flv = 1; pkt_type = flags & ~FLV_AUDIO_CODECID_MASK; - channels = 0; - if (pkt_type == AudioPacketTypeMultitrack) { av_log(s, AV_LOG_ERROR, "Multitrack audio is unsupported!\n"); return AVERROR_PATCHWELCOME; @@ -1546,12 +1544,9 @@ retry_duration: avcodec_parameters_free(&par); } } else if (stream_type == FLV_STREAM_TYPE_AUDIO) { - if (!st->codecpar->codec_id) { + if (!st->codecpar->codec_id) flv_set_audio_codec(s, st, st->codecpar, codec_id ? codec_id : (flags & FLV_AUDIO_CODECID_MASK)); - flv->last_sample_rate = 0; - flv->last_channels = 0; - } // These are not signalled in the flags anymore channels = 0; @@ -1562,26 +1557,40 @@ retry_duration: channels = avio_r8(s->pb); size -= 2; + av_channel_layout_uninit(&st->codecpar->ch_layout); + if (channel_order == AudioChannelOrderCustom) { + ret = av_channel_layout_custom_init(&st->codecpar->ch_layout, channels); + if (ret < 0) + return ret; + for (i = 0; i < channels; i++) { - avio_r8(s->pb); // audio channel mapping + uint8_t id = avio_r8(s->pb); size--; + + if (id < 18) + st->codecpar->ch_layout.u.map[i].id = id; + else if (id >= 18 && id <= 23) + st->codecpar->ch_layout.u.map[i].id = id - 18 + AV_CHAN_LOW_FREQUENCY_2; + else if (id == 0xFE) + st->codecpar->ch_layout.u.map[i].id = AV_CHAN_UNUSED; + else + st->codecpar->ch_layout.u.map[i].id = AV_CHAN_UNKNOWN; } } else if (channel_order == AudioChannelOrderNative) { - avio_rb32(s->pb); // audio channel flags + uint64_t mask = avio_rb32(s->pb); size -= 4; - } - if (!av_channel_layout_check(&st->codecpar->ch_layout)) { - ///TODO: This can be much more sophisticated with above info. + // The first 18 entries in the mask match ours, but the remaining 6 entries start at AV_CHAN_LOW_FREQUENCY_2 + mask = (mask & 0x3FFFF) | ((mask & 0xFC0000) << (AV_CHAN_LOW_FREQUENCY_2 - 18)); + ret = av_channel_layout_from_mask(&st->codecpar->ch_layout, mask); + if (ret < 0) + return ret; + } else { av_channel_layout_default(&st->codecpar->ch_layout, channels); - flv->last_channels = channels; } - if (channels != flv->last_channels) { - flv->last_channels = channels; - ff_add_param_change(pkt, channels, 0, 0, 0, 0); - } + av_log(s, AV_LOG_DEBUG, "Set channel data from MultiChannel info.\n"); goto leave; }