Skip to content

Commit

Permalink
avformat: Avoid allocation for AVStreamInternal
Browse files Browse the repository at this point in the history
Do this by allocating AVStream together with the data that is
currently in AVStreamInternal; or rather: Put AVStream at the
beginning of a new structure called FFStream (which encompasses
more than just the internal fields and is a proper context in its own
right, hence the name) and remove AVStreamInternal altogether.

Signed-off-by: Andreas Rheinhardt <[email protected]>
  • Loading branch information
mkver committed Sep 17, 2021
1 parent 9f05b3b commit 40bdd8c
Show file tree
Hide file tree
Showing 87 changed files with 745 additions and 606 deletions.
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->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;

ff_id3v1_read(s);
if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
Expand Down
8 changes: 5 additions & 3 deletions libavformat/aadec.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static int aa_read_header(AVFormatContext *s)
AADemuxContext *c = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st;
FFStream *sti;
int ret;

/* parse .aa header */
Expand Down Expand Up @@ -178,11 +179,12 @@ static int aa_read_header(AVFormatContext *s)
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
sti = ffstream(st);
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
if (!strcmp(codec_name, "mp332")) {
st->codecpar->codec_id = AV_CODEC_ID_MP3;
st->codecpar->sample_rate = 22050;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
sti->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 @@ -191,15 +193,15 @@ static int aa_read_header(AVFormatContext *s)
st->codecpar->channels = 1;
st->codecpar->sample_rate = 8500;
st->codecpar->bit_rate = 8500;
st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
sti->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->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
sti->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->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/ape.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
if (index < 0)
return -1;

if ((ret = avio_seek(s->pb, st->internal->index_entries[index].pos, SEEK_SET)) < 0)
if ((ret = avio_seek(s->pb, ffstream(st)->index_entries[index].pos, SEEK_SET)) < 0)
return ret;
ape->currentframe = index;
return 0;
Expand Down
19 changes: 11 additions & 8 deletions libavformat/asfdec_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
ASFContext *asf = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st;
FFStream *sti;
ASFStream *asf_st;
ff_asf_guid g;
enum AVMediaType type;
Expand All @@ -317,6 +318,7 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
sti = ffstream(st);
avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
start_time = asf->hdr.preroll;

Expand Down Expand Up @@ -378,13 +380,13 @@ static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
if (is_dvr_ms_audio) {
// codec_id and codec_tag are unreliable in dvr_ms
// files. Set them later by probing stream.
st->internal->request_probe = 1;
sti->request_probe = 1;
st->codecpar->codec_tag = 0;
}
if (st->codecpar->codec_id == AV_CODEC_ID_AAC)
st->internal->need_parsing = AVSTREAM_PARSE_NONE;
sti->need_parsing = AVSTREAM_PARSE_NONE;
else
st->internal->need_parsing = AVSTREAM_PARSE_FULL;
sti->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 +445,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->internal->need_parsing = AVSTREAM_PARSE_FULL;
sti->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 +455,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->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
sti->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4)
st->internal->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
sti->need_parsing = AVSTREAM_PARSE_FULL_ONCE;
}
pos2 = avio_tell(pb);
avio_skip(pb, size - (pos2 - pos1 + 24));
Expand Down Expand Up @@ -1557,6 +1559,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
{
ASFContext *asf = s->priv_data;
AVStream *st = s->streams[stream_index];
FFStream *const sti = ffstream(st);
int ret = 0;

if (s->packet_size <= 0)
Expand Down Expand Up @@ -1584,11 +1587,11 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
asf->index_read = -1;
}

if (asf->index_read > 0 && st->internal->index_entries) {
if (asf->index_read > 0 && sti->index_entries) {
int index = av_index_search_timestamp(st, pts, flags);
if (index >= 0) {
/* find the position */
uint64_t pos = st->internal->index_entries[index].pos;
uint64_t pos = sti->index_entries[index].pos;

/* do the seek */
av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos);
Expand Down
10 changes: 6 additions & 4 deletions libavformat/asfdec_o.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,13 +1513,15 @@ static int asf_read_seek(AVFormatContext *s, int stream_index,
int64_t timestamp, int flags)
{
ASFContext *asf = s->priv_data;
AVStream *const st = s->streams[stream_index];
FFStream *const sti = ffstream(st);
int idx, ret;

if (s->streams[stream_index]->internal->nb_index_entries && asf->is_simple_index) {
idx = av_index_search_timestamp(s->streams[stream_index], timestamp, flags);
if (idx < 0 || idx >= s->streams[stream_index]->internal->nb_index_entries)
if (sti->nb_index_entries && asf->is_simple_index) {
idx = av_index_search_timestamp(st, timestamp, flags);
if (idx < 0 || idx >= sti->nb_index_entries)
return AVERROR_INVALIDDATA;
avio_seek(s->pb, s->streams[stream_index]->internal->index_entries[idx].pos, SEEK_SET);
avio_seek(s->pb, sti->index_entries[idx].pos, SEEK_SET);
} else {
if ((ret = ff_seek_frame_binary(s, stream_index, timestamp, flags)) < 0)
return ret;
Expand Down
6 changes: 4 additions & 2 deletions libavformat/av1dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static int av1_read_header(AVFormatContext *s)
AV1DemuxContext *const c = s->priv_data;
const AVBitStreamFilter *filter = av_bsf_get_by_name("av1_frame_merge");
AVStream *st;
FFStream *sti;
int ret;

if (!filter) {
Expand All @@ -72,12 +73,13 @@ static int av1_read_header(AVFormatContext *s)
st = avformat_new_stream(s, NULL);
if (!st)
return AVERROR(ENOMEM);
sti = ffstream(st);

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

st->internal->avctx->framerate = c->framerate;
sti->avctx->framerate = c->framerate;
// taken from rawvideo demuxers
avpriv_set_pts_info(st, 64, 1, 1200000);

Expand Down
8 changes: 0 additions & 8 deletions libavformat/avformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,6 @@ typedef struct AVIndexEntry {
*/
#define AV_DISPOSITION_TIMED_THUMBNAILS 0x0800

typedef struct AVStreamInternal AVStreamInternal;

/**
* To specify text track kind (different from subtitles default).
*/
Expand Down Expand Up @@ -1003,12 +1001,6 @@ typedef struct AVStream {
*
*/
int pts_wrap_bits;

/**
* An opaque field for libavformat internal usage.
* Must not be accessed in any way by callers.
*/
AVStreamInternal *internal;
} AVStream;

struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);
Expand Down
Loading

0 comments on commit 40bdd8c

Please sign in to comment.