[FFmpeg-devel] [PATCH 02/15] avformat/hls: Don't access FFInputFormat.raw_codec_id

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat Mar 23 04:06:10 EET 2024


It is an implementation detail of other input formats whether
they use raw_codec_id or not. The HLS demuxer should not rely
on this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavformat/hls.c                   | 10 ++++++----
 libavformat/hls_sample_encryption.c |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index f6b44c2e35..94defa9384 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2100,10 +2100,12 @@ static int hls_read_header(AVFormatContext *s)
          */
         if (seg && seg->key_type == KEY_SAMPLE_AES && pls->is_id3_timestamped &&
             pls->audio_setup_info.codec_id != AV_CODEC_ID_NONE) {
-            void *iter = NULL;
-            while ((in_fmt = av_demuxer_iterate(&iter)))
-                if (ffifmt(in_fmt)->raw_codec_id == pls->audio_setup_info.codec_id)
-                    break;
+            av_assert1(pls->audio_setup_info.codec_id == AV_CODEC_ID_AAC ||
+                       pls->audio_setup_info.codec_id == AV_CODEC_ID_AC3 ||
+                       pls->audio_setup_info.codec_id == AV_CODEC_ID_EAC3);
+            // Keep this list in sync with ff_hls_senc_read_audio_setup_info()
+            in_fmt = av_find_input_format(pls->audio_setup_info.codec_id == AV_CODEC_ID_AAC ? "aac" :
+                                          pls->audio_setup_info.codec_id == AV_CODEC_ID_AC3 ? "ac3" : "eac3");
         } else {
             pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
             pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? s->max_analyze_duration : 4 * AV_TIME_BASE;
diff --git a/libavformat/hls_sample_encryption.c b/libavformat/hls_sample_encryption.c
index d5b4c11b66..f412836d4f 100644
--- a/libavformat/hls_sample_encryption.c
+++ b/libavformat/hls_sample_encryption.c
@@ -64,6 +64,7 @@ void ff_hls_senc_read_audio_setup_info(HLSAudioSetupInfo *info, const uint8_t *b
 
     info->codec_tag = AV_RL32(buf);
 
+    /* Always keep this list in sync with the one from hls_read_header() */
     if (info->codec_tag == MKTAG('z','a','a','c'))
         info->codec_id = AV_CODEC_ID_AAC;
     else if (info->codec_tag == MKTAG('z','a','c','3'))
-- 
2.40.1



More information about the ffmpeg-devel mailing list