diff mbox

[FFmpeg-devel,RFC,v2] avutil/frame: fix remove_side_data

Message ID 20191102174118.26063-1-quinkblack@foxmail.com
State Accepted
Commit 20c5f4d8358e5dab2eb87e611167987a4840122a
Headers show

Commit Message

Zhao Zhili Nov. 2, 2019, 5:41 p.m. UTC
remove_side_data is supposed to remove a single instance by design.
Since new_side_data() doesn't forbid add multiple instances of the
same type, remove_side_data should deal with that.
---
I'm afraid this patch makes it harder to enforce single entry per type.

 libavutil/frame.c | 2 +-
 libavutil/frame.h | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

Comments

Marton Balint Nov. 10, 2019, 7:32 p.m. UTC | #1
On Sun, 3 Nov 2019, Zhao Zhili wrote:

> remove_side_data is supposed to remove a single instance by design.
> Since new_side_data() doesn't forbid add multiple instances of the
> same type, remove_side_data should deal with that.
> ---
> I'm afraid this patch makes it harder to enforce single entry per type.
>
> libavutil/frame.c | 2 +-
> libavutil/frame.h | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)

Thanks, I will apply this soon.

Regards,
Marton

>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index dcf1fc3d17..e4038096c2 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -806,7 +806,7 @@ void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
> {
>     int i;
> 
> -    for (i = 0; i < frame->nb_side_data; i++) {
> +    for (i = frame->nb_side_data - 1; i >= 0; i--) {
>         AVFrameSideData *sd = frame->side_data[i];
>         if (sd->type == type) {
>             free_side_data(&frame->side_data[i]);
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index 5d3231e7bb..b5afb58634 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -920,8 +920,7 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
>                                         enum AVFrameSideDataType type);
> 
> /**
> - * If side data of the supplied type exists in the frame, free it and remove it
> - * from the frame.
> + * Remove and free all side data instances of the given type.
>  */
> void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);
> 
> -- 
> 2.17.1
>
>
>
> _______________________________________________
> 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".
Marton Balint Nov. 11, 2019, 9:35 p.m. UTC | #2
On Sun, 10 Nov 2019, Marton Balint wrote:

>
>
> On Sun, 3 Nov 2019, Zhao Zhili wrote:
>
>> remove_side_data is supposed to remove a single instance by design.
>> Since new_side_data() doesn't forbid add multiple instances of the
>> same type, remove_side_data should deal with that.
>> ---
>> I'm afraid this patch makes it harder to enforce single entry per type.
>>
>> libavutil/frame.c | 2 +-
>> libavutil/frame.h | 3 +--
>> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> Thanks, I will apply this soon.

Thanks, applied.

Regards,
Marton
diff mbox

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index dcf1fc3d17..e4038096c2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -806,7 +806,7 @@  void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
 {
     int i;
 
-    for (i = 0; i < frame->nb_side_data; i++) {
+    for (i = frame->nb_side_data - 1; i >= 0; i--) {
         AVFrameSideData *sd = frame->side_data[i];
         if (sd->type == type) {
             free_side_data(&frame->side_data[i]);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 5d3231e7bb..b5afb58634 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -920,8 +920,7 @@  AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
                                         enum AVFrameSideDataType type);
 
 /**
- * If side data of the supplied type exists in the frame, free it and remove it
- * from the frame.
+ * Remove and free all side data instances of the given type.
  */
 void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type);