aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2024-10-05 10:32:14 -0300
committerJames Almer <jamrial@gmail.com>2024-10-05 14:36:28 -0300
commitd5eb0e7fb334b83849a8515d83f8a3acb5a762c6 (patch)
tree130143ff92cd19f66e306ab16cde5e421aea8f3a
parentcdda4c4d50d0d45ae7452e7faff370246a9667e1 (diff)
downloadffmpeg-d5eb0e7fb334b83849a8515d83f8a3acb5a762c6.tar.gz
avformat/mov: split off heif item initialization to its own function
Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--libavformat/mov.c112
1 files changed, 62 insertions, 50 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c
index bec834023c..a1cace6474 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10227,6 +10227,65 @@ static int mov_parse_tiles(AVFormatContext *s)
return 0;
}
+static int mov_parse_heif_items(AVFormatContext *s)
+{
+ MOVContext *mov = s->priv_data;
+ int err;
+
+ for (int i = 0; i < mov->nb_heif_item; i++) {
+ HEIFItem *item = &mov->heif_item[i];
+ MOVStreamContext *sc;
+ AVStream *st;
+ int64_t offset = 0;
+
+ if (!item->st) {
+ if (item->item_id == mov->thmb_item_id) {
+ av_log(s, AV_LOG_ERROR, "HEIF thumbnail doesn't reference a stream\n");
+ return AVERROR_INVALIDDATA;
+ }
+ continue;
+ }
+ if (item->is_idat_relative) {
+ if (!mov->idat_offset) {
+ av_log(s, AV_LOG_ERROR, "Missing idat box for item %d\n", item->item_id);
+ return AVERROR_INVALIDDATA;
+ }
+ offset = mov->idat_offset;
+ }
+
+ st = item->st;
+ sc = st->priv_data;
+ st->codecpar->width = item->width;
+ st->codecpar->height = item->height;
+
+ if (sc->sample_count != 1 || sc->chunk_count != 1)
+ return AVERROR_INVALIDDATA;
+
+ sc->sample_sizes[0] = item->extent_length;
+ sc->chunk_offsets[0] = item->extent_offset + offset;
+
+ if (item->item_id == mov->primary_item_id)
+ st->disposition |= AV_DISPOSITION_DEFAULT;
+
+ if (item->rotation || item->hflip || item->vflip) {
+ err = set_display_matrix_from_item(&st->codecpar->coded_side_data,
+ &st->codecpar->nb_coded_side_data, item);
+ if (err < 0)
+ return err;
+ }
+
+ mov_build_index(mov, st);
+ }
+
+ if (mov->nb_heif_grid) {
+ err = mov_parse_tiles(s);
+ if (err < 0)
+ return err;
+ }
+
+ return 0;
+}
+
static AVStream *mov_find_reference_track(AVFormatContext *s, AVStream *st,
int first_index)
{
@@ -10284,56 +10343,9 @@ static int mov_read_header(AVFormatContext *s)
av_log(mov->fc, AV_LOG_TRACE, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb));
if (mov->found_iloc && mov->found_iinf) {
- for (i = 0; i < mov->nb_heif_item; i++) {
- HEIFItem *item = &mov->heif_item[i];
- MOVStreamContext *sc;
- AVStream *st;
- int64_t offset = 0;
-
- if (!item->st) {
- if (item->item_id == mov->thmb_item_id) {
- av_log(s, AV_LOG_ERROR, "HEIF thumbnail doesn't reference a stream\n");
- return AVERROR_INVALIDDATA;
- }
- continue;
- }
- if (item->is_idat_relative) {
- if (!mov->idat_offset) {
- av_log(s, AV_LOG_ERROR, "Missing idat box for item %d\n", item->item_id);
- return AVERROR_INVALIDDATA;
- }
- offset = mov->idat_offset;
- }
-
- st = item->st;
- sc = st->priv_data;
- st->codecpar->width = item->width;
- st->codecpar->height = item->height;
-
- if (sc->sample_count != 1 || sc->chunk_count != 1)
- return AVERROR_INVALIDDATA;
-
- sc->sample_sizes[0] = item->extent_length;
- sc->chunk_offsets[0] = item->extent_offset + offset;
-
- if (item->item_id == mov->primary_item_id)
- st->disposition |= AV_DISPOSITION_DEFAULT;
-
- if (item->rotation || item->hflip || item->vflip) {
- int ret = set_display_matrix_from_item(&st->codecpar->coded_side_data,
- &st->codecpar->nb_coded_side_data, item);
- if (ret < 0)
- return ret;
- }
-
- mov_build_index(mov, st);
- }
-
- if (mov->nb_heif_grid) {
- err = mov_parse_tiles(s);
- if (err < 0)
- return err;
- }
+ err = mov_parse_heif_items(s);
+ if (err < 0)
+ return err;
}
// prevent iloc and iinf boxes from being parsed while reading packets.
// this is needed because an iinf box may have been parsed but ignored