summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-03 23:08:14 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-07 00:28:27 +0200
commit7b5b6ebdac86e7a93a59bb5a6f8f5b0996450d24 (patch)
tree8149a1f2fad9665fc952791a810d07a4d3f826d4 /libavformat/matroskadec.c
parenta64c2e0e0b7bae16dedea48203bc08909b74dd98 (diff)
avformat/matroskadec: Factor parsing subtitle codecs out
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c75
1 files changed, 46 insertions, 29 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index ee546bfffb..97e944df7c 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2803,6 +2803,48 @@ static int mkv_parse_video_codec(MatroskaTrack *track, AVCodecParameters *par,
return 0;
}
+/* Performs the codec-specific part of parsing a subtitle track. */
+static int mkv_parse_subtitle_codec(MatroskaTrack *track, AVCodecParameters *par,
+ const MatroskaDemuxContext *matroska)
+{
+ switch (par->codec_id) {
+ case AV_CODEC_ID_ARIB_CAPTION:
+ if (track->codec_priv.size == 3) {
+ int component_tag = track->codec_priv.data[0];
+ int data_component_id = AV_RB16(track->codec_priv.data + 1);
+
+ switch (data_component_id) {
+ case 0x0008:
+ // [0x30..0x37] are component tags utilized for
+ // non-mobile captioning service ("profile A").
+ if (component_tag >= 0x30 && component_tag <= 0x37) {
+ par->profile = FF_PROFILE_ARIB_PROFILE_A;
+ }
+ break;
+ case 0x0012:
+ // component tag 0x87 signifies a mobile/partial reception
+ // (1seg) captioning service ("profile C").
+ if (component_tag == 0x87) {
+ par->profile = FF_PROFILE_ARIB_PROFILE_C;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (par->profile == FF_PROFILE_UNKNOWN)
+ av_log(matroska->ctx, AV_LOG_WARNING,
+ "Unknown ARIB caption profile utilized: %02x / %04x\n",
+ component_tag, data_component_id);
+
+ track->codec_priv.size = 0;
+ }
+ break;
+ }
+
+ return 0;
+}
+
static int matroska_parse_tracks(AVFormatContext *s)
{
MatroskaDemuxContext *matroska = s->priv_data;
@@ -3006,35 +3048,10 @@ static int matroska_parse_tracks(AVFormatContext *s)
&extradata_offset);
if (ret < 0)
return ret;
- } else if (codec_id == AV_CODEC_ID_ARIB_CAPTION && track->codec_priv.size == 3) {
- int component_tag = track->codec_priv.data[0];
- int data_component_id = AV_RB16(track->codec_priv.data + 1);
-
- switch (data_component_id) {
- case 0x0008:
- // [0x30..0x37] are component tags utilized for
- // non-mobile captioning service ("profile A").
- if (component_tag >= 0x30 && component_tag <= 0x37) {
- par->profile = FF_PROFILE_ARIB_PROFILE_A;
- }
- break;
- case 0x0012:
- // component tag 0x87 signifies a mobile/partial reception
- // (1seg) captioning service ("profile C").
- if (component_tag == 0x87) {
- par->profile = FF_PROFILE_ARIB_PROFILE_C;
- }
- break;
- default:
- break;
- }
-
- if (par->profile == FF_PROFILE_UNKNOWN)
- av_log(matroska->ctx, AV_LOG_WARNING,
- "Unknown ARIB caption profile utilized: %02x / %04x\n",
- component_tag, data_component_id);
-
- track->codec_priv.size = 0;
+ } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
+ ret = mkv_parse_subtitle_codec(track, par, matroska);
+ if (ret < 0)
+ return ret;
}
if (par->codec_id == AV_CODEC_ID_NONE)