History

avformat/mov: factorize getting the current item

James Almer committed 2 years ago

Commit 58c265d1 parent c8cc58a1 file · +34 −24Browse files

Unified · Split

libavformat/mov.c+34−24
@@ -189,6 +189,24 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, · 188 unmodified lines
189189 return p - dst;
190190 }
191191
192+/**
193+ * Get the current item in the parsing process.
194+ */
195+static HEIFItem *heif_cur_item(MOVContext *c)
196+{
197+ HEIFItem *item = NULL;
198+
199+ for (int i = 0; i < c->nb_heif_item; i++) {
200+ if (c->heif_item[i].item_id != c->cur_item_id)
201+ continue;
202+
203+ item = &c->heif_item[i];
204+ break;
205+ }
206+
207+ return item;
208+}
209+
192210 /**
193211 * Get the current stream in the parsing process. This can either be the
194212 * 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, · 1 unmodified line
196214 static AVStream *get_curr_st(MOVContext *c)
197215 {
198216 AVStream *st = NULL;
217+ HEIFItem *item;
199218
200219 if (c->fc->nb_streams < 1)
201220 return NULL;
202221
203− for (int i = 0; i < c->nb_heif_item; i++) {
204− HEIFItem *item = &c->heif_item[i];
205−
206− if (!item->st)
207− continue;
208− if (item->st->id != c->cur_item_id)
209− continue;
222+ if (c->cur_item_id == -1)
223+ return c->fc->streams[c->fc->nb_streams-1];
210224
225+ item = heif_cur_item(c);
226+ if (item)
211227 st = item->st;
212− break;
213− }
214− if (!st && c->cur_item_id == -1)
215− st = c->fc->streams[c->fc->nb_streams-1];
216228
217229 return st;
218230 }
@@ -8913,6 +8925,7 @@ static int mov_read_iref(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 8694 unmodified lines
89138925
89148926 static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom)
89158927 {
8928+ HEIFItem *item;
89168929 uint32_t width, height;
89178930
89188931 avio_r8(pb); /* version */
@@ -8923,12 +8936,10 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 4 unmodified lines
89238936 av_log(c->fc, AV_LOG_TRACE, "ispe: item_id %d, width %u, height %u\n",
89248937 c->cur_item_id, width, height);
89258938
8926− for (int i = 0; i < c->nb_heif_item; i++) {
8927− if (c->heif_item[i].item_id == c->cur_item_id) {
8928− c->heif_item[i].width = width;
8929− c->heif_item[i].height = height;
8930− break;
8931− }
8939+ item = heif_cur_item(c);
8940+ if (item) {
8941+ item->width = width;
8942+ item->height = height;
89328943 }
89338944
89348945 return 0;
@@ -8936,6 +8947,7 @@ static int mov_read_ispe(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1 unmodified line
89368947
89378948 static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom)
89388949 {
8950+ HEIFItem *item;
89398951 int angle;
89408952
89418953 angle = avio_r8(pb) & 0x3;
@@ -8943,13 +8955,11 @@ static int mov_read_irot(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1 unmodified line
89438955 av_log(c->fc, AV_LOG_TRACE, "irot: item_id %d, angle %u\n",
89448956 c->cur_item_id, angle);
89458957
8946− for (int i = 0; i < c->nb_heif_item; i++) {
8947− if (c->heif_item[i].item_id == c->cur_item_id) {
8948− // angle * 90 specifies the angle (in anti-clockwise direction)
8949− // in units of degrees.
8950− c->heif_item[i].rotation = angle * 90;
8951− break;
8952− }
8958+ item = heif_cur_item(c);
8959+ if (item) {
8960+ // angle * 90 specifies the angle (in anti-clockwise direction)
8961+ // in units of degrees.
8962+ item->rotation = angle * 90;
89538963 }
89548964
89558965 return 0;

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