diff mbox

[FFmpeg-devel,1/2] frame: handle add side data with the same type

Message ID 20191025050002.32599-1-quinkblack@foxmail.com
State Superseded
Headers show

Commit Message

zhilizhao Oct. 25, 2019, 5 a.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavutil/frame.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

zhilizhao Nov. 1, 2019, 10:19 a.m. UTC | #1
Ping for review, thanks!

> On Oct 25, 2019, at 1:00 PM, quinkblack@foxmail.com wrote:
> 
> From: Zhao Zhili <zhilizhao@tencent.com>
> 
> ---
> libavutil/frame.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
> 
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index dcf1fc3d17..bb20e99331 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -692,10 +692,23 @@ AVFrameSideData *av_frame_new_side_data_from_buf(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 = buf->data;
> +            sd->size = buf->size;
> +            return sd;
> +        }
> +    }
> +
>     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
>         return NULL;
> 
> -- 
> 2.22.0
>
Marton Balint Nov. 1, 2019, 11:10 a.m. UTC | #2
On Fri, 1 Nov 2019, "zhilizhao(赵志立)" wrote:

> Ping for review, thanks!

You should update the documentation for the function, that it replaces 
existing side data of the same type. You should also make sure it works as 
it is documented now: on failure, the frame is unchanged.

Regards,
Marton

>
>> On Oct 25, 2019, at 1:00 PM, quinkblack@foxmail.com wrote:
>> 
>> From: Zhao Zhili <zhilizhao@tencent.com>
>> 
>> ---
>> libavutil/frame.c | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>> 
>> diff --git a/libavutil/frame.c b/libavutil/frame.c
>> index dcf1fc3d17..bb20e99331 100644
>> --- a/libavutil/frame.c
>> +++ b/libavutil/frame.c
>> @@ -692,10 +692,23 @@ AVFrameSideData *av_frame_new_side_data_from_buf(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 = buf->data;
>> +            sd->size = buf->size;
>> +            return sd;
>> +        }
>> +    }
>> +
>>     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
>>         return NULL;
>> 
>> -- 
>> 2.22.0
>> 
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index dcf1fc3d17..bb20e99331 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -692,10 +692,23 @@  AVFrameSideData *av_frame_new_side_data_from_buf(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 = buf->data;
+            sd->size = buf->size;
+            return sd;
+        }
+    }
+
     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
         return NULL;