mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avformat/matroskadec: Factor video parsing out of matroska_parse_tracks()
More exactly, factor codec-specific video parsing out of matroska_parse_tracks(). This is intended to improve readability. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
8eaf23a160
commit
15f96bb074
@ -2734,6 +2734,75 @@ static int mka_parse_audio_codec(MatroskaTrack *track, AVCodecParameters *par,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Performs the codec-specific part of parsing a video track. */
|
||||
static int mkv_parse_video_codec(MatroskaTrack *track, AVCodecParameters *par,
|
||||
const MatroskaDemuxContext *matroska,
|
||||
int *extradata_offset)
|
||||
{
|
||||
if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") &&
|
||||
track->codec_priv.size >= 40) {
|
||||
track->ms_compat = 1;
|
||||
par->bits_per_coded_sample = AV_RL16(track->codec_priv.data + 14);
|
||||
par->codec_tag = AV_RL32(track->codec_priv.data + 16);
|
||||
par->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
|
||||
par->codec_tag);
|
||||
if (!par->codec_id)
|
||||
par->codec_id = ff_codec_get_id(ff_codec_movvideo_tags,
|
||||
par->codec_tag);
|
||||
*extradata_offset = 40;
|
||||
return 0;
|
||||
} else if (!strcmp(track->codec_id, "V_QUICKTIME") &&
|
||||
track->codec_priv.size >= 21) {
|
||||
enum AVCodecID codec_id;
|
||||
uint32_t fourcc;
|
||||
int ret = get_qt_codec(track, &fourcc, &codec_id);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (codec_id == AV_CODEC_ID_NONE && AV_RL32(track->codec_priv.data+4) == AV_RL32("SMI ")) {
|
||||
fourcc = MKTAG('S','V','Q','3');
|
||||
codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc);
|
||||
}
|
||||
par->codec_id = codec_id;
|
||||
if (codec_id == AV_CODEC_ID_NONE)
|
||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
||||
"mov FourCC not found %s.\n", av_fourcc2str(fourcc));
|
||||
if (track->codec_priv.size >= 86) {
|
||||
FFIOContext b;
|
||||
unsigned bit_depth = AV_RB16(track->codec_priv.data + 82);
|
||||
ffio_init_context(&b, track->codec_priv.data,
|
||||
track->codec_priv.size,
|
||||
0, NULL, NULL, NULL, NULL);
|
||||
if (ff_get_qtpalette(codec_id, &b.pub, track->palette)) {
|
||||
bit_depth &= 0x1F;
|
||||
track->has_palette = 1;
|
||||
}
|
||||
par->bits_per_coded_sample = bit_depth;
|
||||
}
|
||||
par->codec_tag = fourcc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (par->codec_id) {
|
||||
case AV_CODEC_ID_RV10:
|
||||
case AV_CODEC_ID_RV20:
|
||||
case AV_CODEC_ID_RV30:
|
||||
case AV_CODEC_ID_RV40:
|
||||
*extradata_offset = 26;
|
||||
break;
|
||||
case AV_CODEC_ID_PRORES:
|
||||
if (track->codec_priv.size == 4)
|
||||
par->codec_tag = AV_RL32(track->codec_priv.data);
|
||||
break;
|
||||
case AV_CODEC_ID_VP9:
|
||||
/* we don't need any value stored in CodecPrivate.
|
||||
make sure that it's not exported as extradata. */
|
||||
track->codec_priv.size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int matroska_parse_tracks(AVFormatContext *s)
|
||||
{
|
||||
MatroskaDemuxContext *matroska = s->priv_data;
|
||||
@ -2749,7 +2818,6 @@ static int matroska_parse_tracks(AVFormatContext *s)
|
||||
AVCodecParameters *par;
|
||||
int extradata_offset = 0;
|
||||
uint32_t fourcc = 0;
|
||||
FFIOContext b;
|
||||
AVStream *st;
|
||||
FFStream *sti;
|
||||
char* key_id_base64 = NULL;
|
||||
@ -2934,55 +3002,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
|
||||
return ret;
|
||||
if (ret == SKIP_TRACK)
|
||||
continue;
|
||||
} else
|
||||
if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") &&
|
||||
track->codec_priv.size >= 40) {
|
||||
track->ms_compat = 1;
|
||||
par->bits_per_coded_sample = AV_RL16(track->codec_priv.data + 14);
|
||||
par->codec_tag = AV_RL32(track->codec_priv.data + 16);
|
||||
par->codec_id = ff_codec_get_id(ff_codec_bmp_tags,
|
||||
par->codec_tag);
|
||||
if (!par->codec_id)
|
||||
par->codec_id = ff_codec_get_id(ff_codec_movvideo_tags,
|
||||
par->codec_tag);
|
||||
extradata_offset = 40;
|
||||
} else if (!strcmp(track->codec_id, "V_QUICKTIME") &&
|
||||
track->codec_priv.size >= 21) {
|
||||
uint32_t fourcc;
|
||||
int ret = get_qt_codec(track, &fourcc, &codec_id);
|
||||
} else if (track->type == MATROSKA_TRACK_TYPE_VIDEO) {
|
||||
ret = mkv_parse_video_codec(track, par, matroska,
|
||||
&extradata_offset);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (codec_id == AV_CODEC_ID_NONE && AV_RL32(track->codec_priv.data+4) == AV_RL32("SMI ")) {
|
||||
fourcc = MKTAG('S','V','Q','3');
|
||||
codec_id = ff_codec_get_id(ff_codec_movvideo_tags, fourcc);
|
||||
}
|
||||
par->codec_id = codec_id;
|
||||
if (codec_id == AV_CODEC_ID_NONE)
|
||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
||||
"mov FourCC not found %s.\n", av_fourcc2str(fourcc));
|
||||
if (track->codec_priv.size >= 86) {
|
||||
unsigned bit_depth = AV_RB16(track->codec_priv.data + 82);
|
||||
ffio_init_context(&b, track->codec_priv.data,
|
||||
track->codec_priv.size,
|
||||
0, NULL, NULL, NULL, NULL);
|
||||
if (ff_get_qtpalette(codec_id, &b.pub, track->palette)) {
|
||||
bit_depth &= 0x1F;
|
||||
track->has_palette = 1;
|
||||
}
|
||||
par->bits_per_coded_sample = bit_depth;
|
||||
}
|
||||
par->codec_tag = fourcc;
|
||||
} else if (codec_id == AV_CODEC_ID_RV10 ||
|
||||
codec_id == AV_CODEC_ID_RV20 ||
|
||||
codec_id == AV_CODEC_ID_RV30 ||
|
||||
codec_id == AV_CODEC_ID_RV40) {
|
||||
extradata_offset = 26;
|
||||
} else if (codec_id == AV_CODEC_ID_PRORES && track->codec_priv.size == 4) {
|
||||
par->codec_tag = AV_RL32(track->codec_priv.data);
|
||||
} else if (codec_id == AV_CODEC_ID_VP9) {
|
||||
/* we don't need any value stored in CodecPrivate.
|
||||
make sure that it's not exported as extradata. */
|
||||
track->codec_priv.size = 0;
|
||||
} 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);
|
||||
|
Loading…
Reference in New Issue
Block a user