diff --git a/libavformat/mov.c b/libavformat/mov.c index 67e87094cf..14e8dab2e6 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -189,6 +189,24 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, return p - dst; } +/** + * Get the current item in the parsing process. + */ +static HEIFItem *heif_cur_item(MOVContext *c) +{ + HEIFItem *item = NULL; + + for (int i = 0; i < c->nb_heif_item; i++) { + if (c->heif_item[i].item_id != c->cur_item_id) + continue; + + item = &c->heif_item[i]; + break; + } + + return item; +} + /** * Get the current stream in the parsing process. This can either be the * latest stream added to the context, or the stream referenced by an item. @@ -196,23 +214,17 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, static AVStream *get_curr_st(MOVContext *c) { AVStream *st = NULL; + HEIFItem *item; if (c->fc->nb_streams < 1) return NULL; - for (int i = 0; i < c->nb_heif_item; i++) { - HEIFItem *item = &c->heif_item[i]; - - if (!item->st) - continue; - if (item->st->id != c->cur_item_id) - continue; + if (c->cur_item_id == -1) + return c->fc->streams[c->fc->nb_streams-1]; + item = heif_cur_item(c); + if (item) st = item->st; - break; - } - if (!st && c->cur_item_id == -1) - st = c->fc->streams[c->fc->nb_streams-1]; return st; } @@ -8913,6 +8925,7 @@ static int mov_read_iref(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + HEIFItem *item; uint32_t width, height; avio_r8(pb); /* version */ @@ -8923,12 +8936,10 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "ispe: item_id %d, width %u, height %u\n", c->cur_item_id, width, height); - for (int i = 0; i < c->nb_heif_item; i++) { - if (c->heif_item[i].item_id == c->cur_item_id) { - c->heif_item[i].width = width; - c->heif_item[i].height = height; - break; - } + item = heif_cur_item(c); + if (item) { + item->width = width; + item->height = height; } return 0; @@ -8936,6 +8947,7 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) { + HEIFItem *item; int angle; angle = avio_r8(pb) & 0x3; @@ -8943,13 +8955,11 @@ static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "irot: item_id %d, angle %u\n", c->cur_item_id, angle); - for (int i = 0; i < c->nb_heif_item; i++) { - if (c->heif_item[i].item_id == c->cur_item_id) { - // angle * 90 specifies the angle (in anti-clockwise direction) - // in units of degrees. - c->heif_item[i].rotation = angle * 90; - break; - } + item = heif_cur_item(c); + if (item) { + // angle * 90 specifies the angle (in anti-clockwise direction) + // in units of degrees. + item->rotation = angle * 90; } return 0;