From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 03/20] avformat/matroskadec: Use dedicated pointer for access to codecpar
Date: Mon, 4 Sep 2023 13:27:42 +0200
Message-ID: <AS8P250MB074472D799446C4D92D0BD498FE9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB0744314AD7A516CFC71F61BF8FE9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
Shortens code and improves readability.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavformat/matroskadec.c | 98 ++++++++++++++++++++-------------------
1 file changed, 50 insertions(+), 48 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index ac3800b880..fd28ff8ab2 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2513,6 +2513,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
enum AVCodecID codec_id = AV_CODEC_ID_NONE;
EbmlList *encodings_list = &track->encodings;
MatroskaTrackEncoding *encodings = encodings_list->elem;
+ AVCodecParameters *par;
uint8_t *extradata = NULL;
int extradata_size = 0;
int extradata_offset = 0;
@@ -2653,6 +2654,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
return AVERROR(ENOMEM);
}
sti = ffstream(st);
+ par = st->codecpar;
if (track->flag_default)
st->disposition |= AV_DISPOSITION_DEFAULT;
@@ -2711,12 +2713,12 @@ static int matroska_parse_tracks(AVFormatContext *s)
ffio_init_context(&b, track->codec_priv.data,
track->codec_priv.size,
0, NULL, NULL, NULL, NULL);
- ret = ff_get_wav_header(s, &b.pub, st->codecpar,
+ ret = ff_get_wav_header(s, &b.pub, par,
track->codec_priv.size, 0);
if (ret < 0)
return ret;
- codec_id = st->codecpar->codec_id;
- fourcc = st->codecpar->codec_tag;
+ codec_id = par->codec_id;
+ fourcc = par->codec_tag;
extradata_offset = FFMIN(track->codec_priv.size, 18);
} else if (!strcmp(track->codec_id, "A_QUICKTIME")
/* Normally 36, but allow noncompliant private data */
@@ -2882,7 +2884,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
if (track->audio.sub_packet_h & 1 || 2 * track->audio.frame_size
!= (int64_t)track->audio.sub_packet_h * track->audio.coded_framesize)
return AVERROR_INVALIDDATA;
- st->codecpar->block_align = track->audio.coded_framesize;
+ par->block_align = track->audio.coded_framesize;
track->codec_priv.size = 0;
} else {
if (codec_id == AV_CODEC_ID_SIPR) {
@@ -2890,11 +2892,11 @@ static int matroska_parse_tracks(AVFormatContext *s)
if (flavor > 3)
return AVERROR_INVALIDDATA;
track->audio.sub_packet_size = ff_sipr_subpk_size[flavor];
- st->codecpar->bit_rate = sipr_bit_rate[flavor];
+ par->bit_rate = sipr_bit_rate[flavor];
} else if (track->audio.sub_packet_size <= 0 ||
track->audio.frame_size % track->audio.sub_packet_size)
return AVERROR_INVALIDDATA;
- st->codecpar->block_align = track->audio.sub_packet_size;
+ par->block_align = track->audio.sub_packet_size;
extradata_offset = 78;
}
track->audio.buf = av_malloc_array(track->audio.sub_packet_h,
@@ -2928,21 +2930,21 @@ static int matroska_parse_tracks(AVFormatContext *s)
// [0x30..0x37] are component tags utilized for
// non-mobile captioning service ("profile A").
if (component_tag >= 0x30 && component_tag <= 0x37) {
- st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_A;
+ 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) {
- st->codecpar->profile = FF_PROFILE_ARIB_PROFILE_C;
+ par->profile = FF_PROFILE_ARIB_PROFILE_C;
}
break;
default:
break;
}
- if (st->codecpar->profile == FF_PROFILE_UNKNOWN)
+ 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);
@@ -2955,16 +2957,16 @@ static int matroska_parse_tracks(AVFormatContext *s)
av_log(matroska->ctx, AV_LOG_INFO,
"Unknown/unsupported AVCodecID %s.\n", track->codec_id);
- st->codecpar->codec_id = codec_id;
+ par->codec_id = codec_id;
- if (!st->codecpar->extradata) {
+ if (!par->extradata) {
if (extradata) {
- st->codecpar->extradata = extradata;
- st->codecpar->extradata_size = extradata_size;
+ par->extradata = extradata;
+ par->extradata_size = extradata_size;
} else if (track->codec_priv.data && track->codec_priv.size > 0) {
- if (ff_alloc_extradata(st->codecpar, track->codec_priv.size))
+ if (ff_alloc_extradata(par, track->codec_priv.size))
return AVERROR(ENOMEM);
- memcpy(st->codecpar->extradata,
+ memcpy(par->extradata,
track->codec_priv.data + extradata_offset,
track->codec_priv.size);
}
@@ -2975,32 +2977,32 @@ static int matroska_parse_tracks(AVFormatContext *s)
int display_width_mul = 1;
int display_height_mul = 1;
- st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
- st->codecpar->codec_tag = fourcc;
+ par->codec_type = AVMEDIA_TYPE_VIDEO;
+ par->codec_tag = fourcc;
if (bit_depth >= 0)
- st->codecpar->bits_per_coded_sample = bit_depth;
- st->codecpar->width = track->video.pixel_width;
- st->codecpar->height = track->video.pixel_height;
+ par->bits_per_coded_sample = bit_depth;
+ par->width = track->video.pixel_width;
+ par->height = track->video.pixel_height;
if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED)
- st->codecpar->field_order = mkv_field_order(matroska, track->video.field_order);
+ par->field_order = mkv_field_order(matroska, track->video.field_order);
else if (track->video.interlaced == MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE)
- st->codecpar->field_order = AV_FIELD_PROGRESSIVE;
+ par->field_order = AV_FIELD_PROGRESSIVE;
if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
mkv_stereo_mode_display_mul(track->video.stereo_mode, &display_width_mul, &display_height_mul);
if (track->video.display_unit < MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN) {
if (track->video.display_width && track->video.display_height &&
- st->codecpar->height < INT64_MAX / track->video.display_width / display_width_mul &&
- st->codecpar->width < INT64_MAX / track->video.display_height / display_height_mul)
+ par->height < INT64_MAX / track->video.display_width / display_width_mul &&
+ par->width < INT64_MAX / track->video.display_height / display_height_mul)
av_reduce(&st->sample_aspect_ratio.num,
&st->sample_aspect_ratio.den,
- st->codecpar->height * track->video.display_width * display_width_mul,
- st->codecpar->width * track->video.display_height * display_height_mul,
+ par->height * track->video.display_width * display_width_mul,
+ par->width * track->video.display_height * display_height_mul,
INT_MAX);
}
- if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
+ if (par->codec_id != AV_CODEC_ID_HEVC)
sti->need_parsing = AVSTREAM_PARSE_HEADERS;
if (track->default_duration) {
@@ -3052,35 +3054,35 @@ static int matroska_parse_tracks(AVFormatContext *s)
if (ret < 0)
return ret;
} else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
- st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
- st->codecpar->codec_tag = fourcc;
- st->codecpar->sample_rate = track->audio.out_samplerate;
+ par->codec_type = AVMEDIA_TYPE_AUDIO;
+ par->codec_tag = fourcc;
+ par->sample_rate = track->audio.out_samplerate;
// channel layout may be already set by codec private checks above
- if (!av_channel_layout_check(&st->codecpar->ch_layout)) {
- st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
- st->codecpar->ch_layout.nb_channels = track->audio.channels;
+ if (!av_channel_layout_check(&par->ch_layout)) {
+ par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
+ par->ch_layout.nb_channels = track->audio.channels;
}
- if (!st->codecpar->bits_per_coded_sample)
- st->codecpar->bits_per_coded_sample = track->audio.bitdepth;
- if (st->codecpar->codec_id == AV_CODEC_ID_MP3 ||
- st->codecpar->codec_id == AV_CODEC_ID_MLP ||
- st->codecpar->codec_id == AV_CODEC_ID_TRUEHD)
+ if (!par->bits_per_coded_sample)
+ par->bits_per_coded_sample = track->audio.bitdepth;
+ if (par->codec_id == AV_CODEC_ID_MP3 ||
+ par->codec_id == AV_CODEC_ID_MLP ||
+ par->codec_id == AV_CODEC_ID_TRUEHD)
sti->need_parsing = AVSTREAM_PARSE_FULL;
- else if (st->codecpar->codec_id != AV_CODEC_ID_AAC)
+ else if (par->codec_id != AV_CODEC_ID_AAC)
sti->need_parsing = AVSTREAM_PARSE_HEADERS;
if (track->codec_delay > 0) {
- st->codecpar->initial_padding = av_rescale_q(track->codec_delay,
- (AVRational){1, 1000000000},
- (AVRational){1, st->codecpar->codec_id == AV_CODEC_ID_OPUS ?
- 48000 : st->codecpar->sample_rate});
+ par->initial_padding = av_rescale_q(track->codec_delay,
+ (AVRational){1, 1000000000},
+ (AVRational){1, par->codec_id == AV_CODEC_ID_OPUS ?
+ 48000 : par->sample_rate});
}
if (track->seek_preroll > 0) {
- st->codecpar->seek_preroll = av_rescale_q(track->seek_preroll,
- (AVRational){1, 1000000000},
- (AVRational){1, st->codecpar->sample_rate});
+ par->seek_preroll = av_rescale_q(track->seek_preroll,
+ (AVRational){1, 1000000000},
+ (AVRational){1, par->sample_rate});
}
} else if (codec_id == AV_CODEC_ID_WEBVTT) {
- st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ par->codec_type = AVMEDIA_TYPE_SUBTITLE;
if (!strcmp(track->codec_id, "D_WEBVTT/CAPTIONS")) {
st->disposition |= AV_DISPOSITION_CAPTIONS;
@@ -3090,7 +3092,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
st->disposition |= AV_DISPOSITION_METADATA;
}
} else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
- st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
+ par->codec_type = AVMEDIA_TYPE_SUBTITLE;
if (track->flag_textdescriptions)
st->disposition |= AV_DISPOSITION_DESCRIPTIONS;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-09-04 11:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 11:26 [FFmpeg-devel] [PATCH 01/20] fate/matroska: Add test for remuxing non-rotation displaymatrix Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 02/20] avformat/matroskadec: Set several stream parameters earlier Andreas Rheinhardt
2023-09-04 11:27 ` Andreas Rheinhardt [this message]
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 04/20] avformat/matroskadec: Redo handling extradata allocation Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 05/20] avformat/matroskadec: Set AVCodecParameters earlier Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 06/20] avformat/matroskdec: Factor audio parsing out of matroska_parse_tracks() Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 07/20] avformat/matroskadec: Remove redundant checks Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 08/20] avformat/matroskadec: Reindent after the previous commit Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 09/20] avformat/matroskadec: Factor video parsing out of matroska_parse_tracks() Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 10/20] avformat/matroskadec: Reindent after the previous commit Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 11/20] avformat/matroskadec: Move reading color space to a better place Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 12/20] avformat/matroskadec: Avoid clobbering CodecPrivate size Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 13/20] avformat/matroskadec: Use av_dict_set_int() where appropriate Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 14/20] avformat/matroskadec: Factor parsing subtitle codecs out Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 15/20] avformat/matroskadec: Factor generic parsing of video tracks out Andreas Rheinhardt
2023-09-04 11:46 ` James Almer
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 16/20] avformat/matroskadec: Reindent after the previous commit Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 17/20] avformat/matroskadec: Factor generic parsing of audio tracks out Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 18/20] avformat/matroskdec: Reindent after the previous commit Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 19/20] avformat/matroskadec: Move WEBVTT code to mkv_parse_subtitle_codec() Andreas Rheinhardt
2023-09-04 11:27 ` [FFmpeg-devel] [PATCH 20/20] avformat/matroskadec: Factor parsing content encodings out Andreas Rheinhardt
2023-09-06 9:37 ` [FFmpeg-devel] [PATCH 01/20] fate/matroska: Add test for remuxing non-rotation displaymatrix Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8P250MB074472D799446C4D92D0BD498FE9A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git