Skip to content

Commit

Permalink
avformat: move AVStream.{parser,need_parsing} to AVStreamInternal
Browse files Browse the repository at this point in the history
Those are private fields, no reason to have them exposed in a public
header.

Signed-off-by: James Almer <[email protected]>
  • Loading branch information
jamrial committed May 7, 2021
1 parent fab2ed4 commit b9c5fdf
Show file tree
Hide file tree
Showing 54 changed files with 168 additions and 159 deletions.
2 changes: 1 addition & 1 deletion libavdevice/v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ static int v4l2_read_header(AVFormatContext *ctx)
st->codecpar->codec_tag =
avcodec_pix_fmt_to_codec_tag(st->codecpar->format);
else if (codec_id == AV_CODEC_ID_H264) {
st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
avpriv_stream_set_need_parsing(st, AVSTREAM_PARSE_FULL_ONCE);
}
if (desired_format == V4L2_PIX_FMT_YVU420)
st->codecpar->codec_tag = MKTAG('Y', 'V', '1', '2');
Expand Down
2 changes: 1 addition & 1 deletion libavformat/aacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static int adts_aac_read_header(AVFormatContext *s)

st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = s->iformat->raw_codec_id;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;

ff_id3v1_read(s);
if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
Expand Down
6 changes: 3 additions & 3 deletions libavformat/aadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static int aa_read_header(AVFormatContext *s)
if (!strcmp(codec_name, "mp332")) {
st->codecpar->codec_id = AV_CODEC_ID_MP3;
st->codecpar->sample_rate = 22050;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 8, 32000 * TIMEPREC);
// encoded audio frame is MP3_FRAME_SIZE bytes (+1 with padding, unlikely)
} else if (!strcmp(codec_name, "acelp85")) {
Expand All @@ -192,15 +192,15 @@ static int aa_read_header(AVFormatContext *s)
st->codecpar->channels = 1;
st->codecpar->sample_rate = 8500;
st->codecpar->bit_rate = 8500;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 8, 8500 * TIMEPREC);
} else if (!strcmp(codec_name, "acelp16")) {
st->codecpar->codec_id = AV_CODEC_ID_SIPR;
st->codecpar->block_align = 20;
st->codecpar->channels = 1;
st->codecpar->sample_rate = 16000;
st->codecpar->bit_rate = 16000;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 8, 16000 * TIMEPREC);
}

Expand Down
2 changes: 1 addition & 1 deletion libavformat/acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int acm_read_header(AVFormatContext *s)
return AVERROR_INVALIDDATA;
st->start_time = 0;
st->duration = AV_RL32(st->codecpar->extradata + 4) / st->codecpar->channels;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);

return 0;
Expand Down
10 changes: 5 additions & 5 deletions libavformat/asfdec_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
st->codecpar->codec_tag = 0;
}
if (st->codecpar->codec_id == AV_CODEC_ID_AAC)
st->need_parsing = AVSTREAM_PARSE_NONE;
st->internal->need_parsing = AVSTREAM_PARSE_NONE;
else
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
/* We have to init the frame size at some point .... */
pos2 = avio_tell(pb);
if (size >= (pos2 + 8 - pos1 + 24)) {
Expand Down Expand Up @@ -443,7 +443,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
st->codecpar->codec_tag = tag1;
st->codecpar->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1);
if (tag1 == MKTAG('D', 'V', 'R', ' ')) {
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
/* issue658 contains wrong w/h and MS even puts a fake seq header
* with wrong w/h in extradata while a correct one is in the stream.
* maximum lameness */
Expand All @@ -453,9 +453,9 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
st->codecpar->extradata_size = 0;
}
if (st->codecpar->codec_id == AV_CODEC_ID_H264)
st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4)
st->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
}
pos2 = avio_tell(pb);
avio_skip(pb, size - (pos2 - pos1 + 24));
Expand Down
2 changes: 1 addition & 1 deletion libavformat/av1dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int read_header(AVFormatContext *s, const AVRational *framerate, AVBSFCon

st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_AV1;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

st->internal->avctx->framerate = *framerate;
// taken from rawvideo demuxers
Expand Down
4 changes: 0 additions & 4 deletions libavformat/avformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,6 @@ typedef struct AVStream {
*/
int codec_info_nb_frames;

/* av_read_frame() support */
enum AVStreamParseType need_parsing;
struct AVCodecParserContext *parser;

/**
* Stream Identifier
* This is the MPEG-TS stream identifier +1
Expand Down
16 changes: 8 additions & 8 deletions libavformat/avidec.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,19 +824,19 @@ static int avi_read_header(AVFormatContext *s)

/* This is needed to get the pict type which is necessary
* for generating correct pts. */
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4 &&
ast->handler == MKTAG('X', 'V', 'I', 'D'))
st->codecpar->codec_tag = MKTAG('X', 'V', 'I', 'D');

if (st->codecpar->codec_tag == MKTAG('V', 'S', 'S', 'H'))
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
if (st->codecpar->codec_id == AV_CODEC_ID_RV40)
st->need_parsing = AVSTREAM_PARSE_NONE;
st->internal->need_parsing = AVSTREAM_PARSE_NONE;
if (st->codecpar->codec_id == AV_CODEC_ID_HEVC &&
st->codecpar->codec_tag == MKTAG('H', '2', '6', '5'))
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;

if (st->codecpar->codec_id == AV_CODEC_ID_AVRN &&
st->codecpar->codec_tag == MKTAG('A', 'V', 'R', 'n') &&
Expand Down Expand Up @@ -880,16 +880,16 @@ static int avi_read_header(AVFormatContext *s)
avio_skip(pb, 1);
/* Force parsing as several audio frames can be in
* one packet and timestamps refer to packet start. */
st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
st->internal->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;
/* ADTS header is in extradata, AAC without header must be
* stored as exact frames. Parser not needed and it will
* fail. */
if (st->codecpar->codec_id == AV_CODEC_ID_AAC &&
st->codecpar->extradata_size)
st->need_parsing = AVSTREAM_PARSE_NONE;
st->internal->need_parsing = AVSTREAM_PARSE_NONE;
// The flac parser does not work with AVSTREAM_PARSE_TIMESTAMPS
if (st->codecpar->codec_id == AV_CODEC_ID_FLAC)
st->need_parsing = AVSTREAM_PARSE_NONE;
st->internal->need_parsing = AVSTREAM_PARSE_NONE;
/* AVI files with Xan DPCM audio (wrongly) declare PCM
* audio in the header but have Axan as stream_code_tag. */
if (ast->handler == AV_RL32("Axan")) {
Expand Down Expand Up @@ -1052,7 +1052,7 @@ static int avi_read_header(AVFormatContext *s)
AVStream *st = s->streams[i];
if ( st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO
|| st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO)
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
}

for (i = 0; i < s->nb_streams; i++) {
Expand Down
2 changes: 1 addition & 1 deletion libavformat/dtshddec.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int dtshd_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_DTS;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;

for (;;) {
chunk_type = avio_rb64(pb);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/electronicarts.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ static int init_video_stream(AVFormatContext *s, VideoProperties *video)
st->codecpar->codec_id = video->codec;
// parsing is necessary to make FFmpeg generate correct timestamps
if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO)
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
st->codecpar->codec_tag = 0; /* no fourcc */
st->codecpar->width = video->width;
st->codecpar->height = video->height;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/flacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int flac_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_FLAC;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
/* the parameters will be extracted from the compressed bitstream */

/* if fLaC marker is not found, assume there is no header */
Expand Down
4 changes: 2 additions & 2 deletions libavformat/flvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
break;
case FLV_CODECID_MP3:
apar->codec_id = AV_CODEC_ID_MP3;
astream->need_parsing = AVSTREAM_PARSE_FULL;
astream->internal->need_parsing = AVSTREAM_PARSE_FULL;
break;
case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
// in case metadata does not otherwise declare samplerate
Expand Down Expand Up @@ -362,7 +362,7 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream,
break;
case FLV_CODECID_H264:
par->codec_id = AV_CODEC_ID_H264;
vstream->need_parsing = AVSTREAM_PARSE_HEADERS;
vstream->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
ret = 3; // not 4, reading packet type will consume one byte
break;
case FLV_CODECID_MPEG4:
Expand Down
6 changes: 3 additions & 3 deletions libavformat/gxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
case 20:
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_MPEG2VIDEO;
st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
break;
case 22:
case 23:
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_MPEG1VIDEO;
st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc.
break;
case 9:
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
Expand Down Expand Up @@ -169,7 +169,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) {
case 29: /* AVCHD */
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_H264;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
break;
// timecode tracks:
case 7:
Expand Down
4 changes: 2 additions & 2 deletions libavformat/img2dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int ff_img_read_header(AVFormatContext *s1)
s->is_pipe = 0;
else {
s->is_pipe = 1;
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
}

if (s->ts_from_file == 2) {
Expand Down Expand Up @@ -482,7 +482,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
return AVERROR_EOF;
if (s->frame_size > 0) {
size[0] = s->frame_size;
} else if (!s1->streams[0]->parser) {
} else if (!s1->streams[0]->internal->parser) {
size[0] = avio_size(s1->pb);
} else {
size[0] = 4096;
Expand Down
6 changes: 6 additions & 0 deletions libavformat/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,14 @@ struct AVStreamInternal {
* Number of packets to buffer for codec probing
*/
int probe_packets;

/* av_read_frame() support */
enum AVStreamParseType need_parsing;
struct AVCodecParserContext *parser;
};

void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type);

#ifdef __GNUC__
#define dynarray_add(tab, nb_ptr, elem)\
do {\
Expand Down
2 changes: 1 addition & 1 deletion libavformat/ipudec.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int ipu_read_header(AVFormatContext *s)
st->start_time = 0;
st->duration =
st->nb_frames = avio_rl32(pb);
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 1, 25);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/iv8.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int read_header(AVFormatContext *s)

st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_MPEG4;
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
avpriv_set_pts_info(st, 64, 1, 90000);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/ivfdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int read_header(AVFormatContext *s)
st->duration = avio_rl32(s->pb);
avio_skip(s->pb, 4); // unused

st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

if (!time_base.den || !time_base.num) {
av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
Expand Down
4 changes: 2 additions & 2 deletions libavformat/lmlm4.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ static int lmlm4_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
st->codecpar->codec_id = AV_CODEC_ID_MPEG4;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
avpriv_set_pts_info(st, 64, 1001, 30000);

if (!(st = avformat_new_stream(s, NULL)))
return AVERROR(ENOMEM);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_MP2;
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

/* the parameters will be extracted from the compressed bitstream */
return 0;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/loasdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static int loas_read_header(AVFormatContext *s)

st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = s->iformat->raw_codec_id;
st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;

//LCM of all possible AAC sample rates
avpriv_set_pts_info(st, 64, 1, 28224000);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/lxfdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static int lxf_read_header(AVFormatContext *s)
st->codecpar->bit_rate = 1000000 * ((video_params >> 14) & 0xFF);
st->codecpar->codec_tag = video_params & 0xF;
st->codecpar->codec_id = ff_codec_get_id(lxf_tags, st->codecpar->codec_tag);
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

av_log(s, AV_LOG_DEBUG, "record: %x = %i-%02i-%02i\n",
record_date, 1900 + (record_date & 0x7F), (record_date >> 7) & 0xF,
Expand Down
6 changes: 3 additions & 3 deletions libavformat/matroskadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2806,7 +2806,7 @@ static int matroska_parse_tracks(AVFormatContext *s)
255);
}
if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;

if (track->default_duration) {
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
Expand Down Expand Up @@ -2864,9 +2864,9 @@ static int matroska_parse_tracks(AVFormatContext *s)
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)
st->need_parsing = AVSTREAM_PARSE_FULL;
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
else if (st->codecpar->codec_id != AV_CODEC_ID_AAC)
st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
if (track->codec_delay > 0) {
st->codecpar->initial_padding = av_rescale_q(track->codec_delay,
(AVRational){1, 1000000000},
Expand Down
2 changes: 1 addition & 1 deletion libavformat/mgsts.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int read_header(AVFormatContext *s)
if (!st)
return AVERROR(ENOMEM);

st->need_parsing = AVSTREAM_PARSE_HEADERS;
st->internal->need_parsing = AVSTREAM_PARSE_HEADERS;
st->start_time = 0;
st->nb_frames =
st->duration = avio_rb32(pb);
Expand Down
Loading

0 comments on commit b9c5fdf

Please sign in to comment.