History

avformat/mov: fix setting tile grid stream offsets when a stream is referenced more than once

The amount of tiles does not necessarely need to match the amount of streams referenced in the grid, as there could be duplicates. Don't silently ignore EEXIST return codes from avformat_stream_group_add_stream() and instead store the index of the duplicate stream.

James Almer committed 1 year ago

Commit bf0786d1 parent cd174c72 files · +18 −5Browse files

Showing the changes to libavformat (2 of 2 files). Show all

Unified · Split

2 files
  1. libavformat/isom.h +1 −0
  2. libavformat/mov.c +17 −5
libavformat/isom.h+1−0
@@ -299,6 +299,7 @@ typedef struct HEIFGrid { · 298 unmodified lines
299299 HEIFItem *item;
300300 HEIFItem **tile_item_list;
301301 int16_t *tile_id_list;
302+ unsigned *tile_idx_list;
302303 int nb_tiles;
303304 } HEIFGrid;
304305
libavformat/mov.c+17−5
@@ -9020,8 +9020,9 @@ static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version) · 9019 unmodified lines
90209020
90219021 entries = avio_rb16(pb);
90229022 grid->tile_id_list = av_malloc_array(entries, sizeof(*grid->tile_id_list));
9023+ grid->tile_idx_list = av_calloc(entries, sizeof(*grid->tile_idx_list));
90239024 grid->tile_item_list = av_calloc(entries, sizeof(*grid->tile_item_list));
9024− if (!grid->tile_id_list || !grid->tile_item_list)
9025+ if (!grid->tile_id_list || !grid->tile_item_list || !grid->tile_idx_list)
90259026 return AVERROR(ENOMEM);
90269027 /* 'to' item ids */
90279028 for (i = 0; i < entries; i++)
@@ -9918,6 +9919,7 @@ static int mov_read_close(AVFormatContext *s) · 890 unmodified lines
99189919 av_freep(&mov->heif_item);
99199920 for (i = 0; i < mov->nb_heif_grid; i++) {
99209921 av_freep(&mov->heif_grid[i].tile_id_list);
9922+ av_freep(&mov->heif_grid[i].tile_idx_list);
99219923 av_freep(&mov->heif_grid[i].tile_item_list);
99229924 }
99239925 av_freep(&mov->heif_grid);
@@ -10170,7 +10172,7 @@ static int read_image_grid(AVFormatContext *s, const HEIFGrid *grid, · 246 unmodified lines
1017010172 if (i == tile_grid->nb_tiles)
1017110173 return AVERROR_INVALIDDATA;
1017210174
10173− tile_grid->offsets[i].idx = i;
10175+ tile_grid->offsets[i].idx = grid->tile_idx_list[i];
1017410176 tile_grid->offsets[i].horizontal = x;
1017510177 tile_grid->offsets[i].vertical = y;
1017610178
@@ -10261,7 +10263,7 @@ static int read_image_iovl(AVFormatContext *s, const HEIFGrid *grid, · 84 unmodified lines
1026110263 }
1026210264
1026310265 for (int i = 0; i < tile_grid->nb_tiles; i++) {
10264− tile_grid->offsets[i].idx = grid->tile_item_list[i]->st->index;
10266+ tile_grid->offsets[i].idx = grid->tile_idx_list[i];
1026510267 tile_grid->offsets[i].horizontal = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb);
1026610268 tile_grid->offsets[i].vertical = (flags & 1) ? avio_rb32(s->pb) : avio_rb16(s->pb);
1026710269 av_log(c->fc, AV_LOG_TRACE, "iovl: stream_idx[%d] %u, "
@@ -10313,10 +10315,20 @@ static int mov_parse_tiles(AVFormatContext *s) · 45 unmodified lines
1031310315 }
1031410316
1031510317 grid->tile_item_list[j] = item;
10318+ grid->tile_idx_list[j] = stg->nb_streams;
1031610319
1031710320 err = avformat_stream_group_add_stream(stg, st);
10318− if (err < 0 && err != AVERROR(EEXIST))
10319− return err;
10321+ if (err < 0) {
10322+ int l;
10323+ if (err != AVERROR(EEXIST))
10324+ return err;
10325+
10326+ for (l = 0; l < stg->nb_streams; l++)
10327+ if (stg->streams[l]->index == st->index)
10328+ break;
10329+ av_assert0(l < stg->nb_streams);
10330+ grid->tile_idx_list[j] = l;
10331+ }
1032010332
1032110333 if (item->item_id != mov->primary_item_id)
1032210334 st->disposition |= AV_DISPOSITION_DEPENDENT;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t