diff mbox series

[FFmpeg-devel,1/2] avformat/mov: factorize getting the current item

Message ID 20240930174119.6426-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/2] avformat/mov: factorize getting the current item | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

James Almer Sept. 30, 2024, 5:41 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/mov.c | 58 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 24 deletions(-)

Comments

Anton Khirnov Sept. 30, 2024, 5:44 p.m. UTC | #1
Quoting James Almer (2024-09-30 19:41:18)
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/mov.c | 58 +++++++++++++++++++++++++++--------------------
>  1 file changed, 34 insertions(+), 24 deletions(-)
> 
> diff --git a/libavformat/mov.c b/libavformat/mov.c
> index 67e87094cf..b3b92bbb91 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 *get_curr_item(MOVContext *c)

A bit generic, given it's HEIF-specific. How about something like
heif_cur_item()?
James Almer Sept. 30, 2024, 5:51 p.m. UTC | #2
On 9/30/2024 2:44 PM, Anton Khirnov wrote:
> Quoting James Almer (2024-09-30 19:41:18)
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavformat/mov.c | 58 +++++++++++++++++++++++++++--------------------
>>   1 file changed, 34 insertions(+), 24 deletions(-)
>>
>> diff --git a/libavformat/mov.c b/libavformat/mov.c
>> index 67e87094cf..b3b92bbb91 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 *get_curr_item(MOVContext *c)
> 
> A bit generic, given it's HEIF-specific. How about something like
> heif_cur_item()?

Sure, changed locally.
James Almer Oct. 2, 2024, 12:23 p.m. UTC | #3
On 9/30/2024 2:41 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>   libavformat/mov.c | 58 +++++++++++++++++++++++++++--------------------
>   1 file changed, 34 insertions(+), 24 deletions(-)

Will apply set.
diff mbox series

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 67e87094cf..b3b92bbb91 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 *get_curr_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 = get_curr_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 = get_curr_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 = get_curr_item(c);
+    if (item) {
+        // angle * 90 specifies the angle (in anti-clockwise direction)
+        // in units of degrees.
+        item->rotation = angle * 90;
     }
 
     return 0;