diff mbox

[FFmpeg-devel] avutil/frame: allow only one element per type in frame side data

Message ID 20170726001042.5984-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer July 26, 2017, 12:10 a.m. UTC
Same rationale as with packet side data, it was never meant to do otherwise
as av_frame_get_side_data returns the first entry it finds of a given type.

Based on code from libavformat's av_stream_add_side_data().

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/frame.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

James Almer July 29, 2017, 4:12 a.m. UTC | #1
On 7/25/2017 9:10 PM, James Almer wrote:
> Same rationale as with packet side data, it was never meant to do otherwise
> as av_frame_get_side_data returns the first entry it finds of a given type.
> 
> Based on code from libavformat's av_stream_add_side_data().
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavutil/frame.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 24d5d5f184..c41d4be8cc 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -638,10 +638,24 @@ static AVFrameSideData *frame_new_side_data(AVFrame *frame,
>                                              AVBufferRef *buf)
>  {
>      AVFrameSideData *ret, **tmp;
> +    int i;
>  
>      if (!buf)
>          return NULL;
>  
> +    for (i = 0; i < frame->nb_side_data; i++) {
> +        AVFrameSideData *sd = frame->side_data[i];
> +
> +        if (sd->type == type) {
> +            av_buffer_unref(&sd->buf);
> +            av_dict_free(&sd->metadata);
> +            sd->buf  = buf;
> +            sd->data = sd->buf->data;
> +            sd->size = buf->size;
> +            return sd;
> +        }
> +    }
> +
>      if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
>          goto fail;

Ping.
James Almer Aug. 6, 2017, 1:52 a.m. UTC | #2
On 7/29/2017 1:12 AM, James Almer wrote:
> On 7/25/2017 9:10 PM, James Almer wrote:
>> Same rationale as with packet side data, it was never meant to do otherwise
>> as av_frame_get_side_data returns the first entry it finds of a given type.
>>
>> Based on code from libavformat's av_stream_add_side_data().
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavutil/frame.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>>
>> diff --git a/libavutil/frame.c b/libavutil/frame.c
>> index 24d5d5f184..c41d4be8cc 100644
>> --- a/libavutil/frame.c
>> +++ b/libavutil/frame.c
>> @@ -638,10 +638,24 @@ static AVFrameSideData *frame_new_side_data(AVFrame *frame,
>>                                              AVBufferRef *buf)
>>  {
>>      AVFrameSideData *ret, **tmp;
>> +    int i;
>>  
>>      if (!buf)
>>          return NULL;
>>  
>> +    for (i = 0; i < frame->nb_side_data; i++) {
>> +        AVFrameSideData *sd = frame->side_data[i];
>> +
>> +        if (sd->type == type) {
>> +            av_buffer_unref(&sd->buf);
>> +            av_dict_free(&sd->metadata);
>> +            sd->buf  = buf;
>> +            sd->data = sd->buf->data;
>> +            sd->size = buf->size;
>> +            return sd;
>> +        }
>> +    }
>> +
>>      if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
>>          goto fail;
> 
> Ping.
> 

I'll apply this soon unless someone objects.
diff mbox

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 24d5d5f184..c41d4be8cc 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -638,10 +638,24 @@  static AVFrameSideData *frame_new_side_data(AVFrame *frame,
                                             AVBufferRef *buf)
 {
     AVFrameSideData *ret, **tmp;
+    int i;
 
     if (!buf)
         return NULL;
 
+    for (i = 0; i < frame->nb_side_data; i++) {
+        AVFrameSideData *sd = frame->side_data[i];
+
+        if (sd->type == type) {
+            av_buffer_unref(&sd->buf);
+            av_dict_free(&sd->metadata);
+            sd->buf  = buf;
+            sd->data = sd->buf->data;
+            sd->size = buf->size;
+            return sd;
+        }
+    }
+
     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
         goto fail;