aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/cafdec.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-08-24 19:41:16 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-09-17 13:22:25 +0200
commit40bdd8cc05d9c98a18cf2b1c2a00c8a5a7b38113 (patch)
tree0fc408f78b9b6934ac351cd4499c07737f8f6a62 /libavformat/cafdec.c
parent9f05b3ba604a30eeb6f5ff877b8b5b5c93a268d7 (diff)
downloadffmpeg-40bdd8cc05d9c98a18cf2b1c2a00c8a5a7b38113.tar.gz
avformat: Avoid allocation for AVStreamInternal
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 <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/cafdec.c')
-rw-r--r--libavformat/cafdec.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 4df8744b79..3ff0558afe 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -342,7 +342,7 @@ found_data:
if (caf->bytes_per_packet > 0 && caf->frames_per_packet > 0) {
if (caf->data_size > 0)
st->nb_frames = (caf->data_size / caf->bytes_per_packet) * caf->frames_per_packet;
- } else if (st->internal->nb_index_entries && st->duration > 0) {
+ } else if (ffstream(st)->nb_index_entries && st->duration > 0) {
if (st->codecpar->sample_rate && caf->data_size / st->duration > INT64_MAX / st->codecpar->sample_rate / 8) {
av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %d * 8 * %"PRId64"\n",
st->codecpar->sample_rate, caf->data_size / st->duration);
@@ -372,6 +372,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
{
AVIOContext *pb = s->pb;
AVStream *st = s->streams[0];
+ FFStream *const sti = ffstream(st);
CafContext *caf = s->priv_data;
int res, pkt_size = 0, pkt_frames = 0;
int64_t left = CAF_MAX_PKT_SIZE;
@@ -395,13 +396,13 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
pkt_size = (CAF_MAX_PKT_SIZE / pkt_size) * pkt_size;
pkt_size = FFMIN(pkt_size, left);
pkt_frames = pkt_size / caf->bytes_per_packet;
- } else if (st->internal->nb_index_entries) {
- if (caf->packet_cnt < st->internal->nb_index_entries - 1) {
- pkt_size = st->internal->index_entries[caf->packet_cnt + 1].pos - st->internal->index_entries[caf->packet_cnt].pos;
- pkt_frames = st->internal->index_entries[caf->packet_cnt + 1].timestamp - st->internal->index_entries[caf->packet_cnt].timestamp;
- } else if (caf->packet_cnt == st->internal->nb_index_entries - 1) {
- pkt_size = caf->num_bytes - st->internal->index_entries[caf->packet_cnt].pos;
- pkt_frames = st->duration - st->internal->index_entries[caf->packet_cnt].timestamp;
+ } else if (sti->nb_index_entries) {
+ if (caf->packet_cnt < sti->nb_index_entries - 1) {
+ pkt_size = sti->index_entries[caf->packet_cnt + 1].pos - sti->index_entries[caf->packet_cnt].pos;
+ pkt_frames = sti->index_entries[caf->packet_cnt + 1].timestamp - sti->index_entries[caf->packet_cnt].timestamp;
+ } else if (caf->packet_cnt == sti->nb_index_entries - 1) {
+ pkt_size = caf->num_bytes - sti->index_entries[caf->packet_cnt].pos;
+ pkt_frames = st->duration - sti->index_entries[caf->packet_cnt].timestamp;
} else {
return AVERROR(EIO);
}
@@ -428,6 +429,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
int64_t timestamp, int flags)
{
AVStream *st = s->streams[0];
+ FFStream *const sti = ffstream(st);
CafContext *caf = s->priv_data;
int64_t pos, packet_cnt, frame_cnt;
@@ -440,10 +442,10 @@ static int read_seek(AVFormatContext *s, int stream_index,
pos = FFMIN(pos, caf->data_size);
packet_cnt = pos / caf->bytes_per_packet;
frame_cnt = caf->frames_per_packet * packet_cnt;
- } else if (st->internal->nb_index_entries) {
+ } else if (sti->nb_index_entries) {
packet_cnt = av_index_search_timestamp(st, timestamp, flags);
- frame_cnt = st->internal->index_entries[packet_cnt].timestamp;
- pos = st->internal->index_entries[packet_cnt].pos;
+ frame_cnt = sti->index_entries[packet_cnt].timestamp;
+ pos = sti->index_entries[packet_cnt].pos;
} else {
return -1;
}