diff mbox series

[FFmpeg-devel] avfilter/avfiltergraph: remove unnecessary channel layout copy

Message ID 20220805231759.2922-1-jamrial@gmail.com
State Accepted
Commit d93e29154f029980c2777a6688ab332e5920b6db
Headers show
Series [FFmpeg-devel] avfilter/avfiltergraph: remove unnecessary channel layout copy | 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 Aug. 5, 2022, 11:17 p.m. UTC
It's not modified, so we can simply use a const pointer to it.
Also check the return value of the other copy in the function while at it.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/avfiltergraph.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Nicolas George Aug. 6, 2022, 11:42 a.m. UTC | #1
James Almer (12022-08-05):
> It's not modified, so we can simply use a const pointer to it.
> Also check the return value of the other copy in the function while at it.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavfilter/avfiltergraph.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)

Ok, thanks.

Regards,
James Almer Aug. 6, 2022, 11:54 p.m. UTC | #2
On 8/6/2022 8:42 AM, Nicolas George wrote:
> James Almer (12022-08-05):
>> It's not modified, so we can simply use a const pointer to it.
>> Also check the return value of the other copy in the function while at it.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>   libavfilter/avfiltergraph.c | 15 ++++++++-------
>>   1 file changed, 8 insertions(+), 7 deletions(-)
> 
> Ok, thanks.
> 
> Regards,

Applied.
diff mbox series

Patch

diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b7dbfc063b..53f468494d 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -729,12 +729,12 @@  static int reduce_formats_on_filter(AVFilterContext *filter)
     /* reduce channel layouts */
     for (i = 0; i < filter->nb_inputs; i++) {
         AVFilterLink *inlink = filter->inputs[i];
-        AVChannelLayout fmt = { 0 };
+        const AVChannelLayout *fmt;
 
         if (!inlink->outcfg.channel_layouts ||
             inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
             continue;
-        av_channel_layout_copy(&fmt, &inlink->outcfg.channel_layouts->channel_layouts[0]);
+        fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
 
         for (j = 0; j < filter->nb_outputs; j++) {
             AVFilterLink *outlink = filter->outputs[j];
@@ -745,24 +745,25 @@  static int reduce_formats_on_filter(AVFilterContext *filter)
                 continue;
 
             if (fmts->all_layouts &&
-                (KNOWN(&fmt) || fmts->all_counts)) {
+                (KNOWN(fmt) || fmts->all_counts)) {
                 /* Turn the infinite list into a singleton */
                 fmts->all_layouts = fmts->all_counts  = 0;
-                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, &fmt) < 0)
+                if (ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt) < 0)
                     ret = 1;
                 break;
             }
 
             for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
-                if (!av_channel_layout_compare(&fmts->channel_layouts[k], &fmt)) {
-                    av_channel_layout_copy(&fmts->channel_layouts[0], &fmt);
+                if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
+                    ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
+                    if (ret < 0)
+                        return ret;
                     fmts->nb_channel_layouts = 1;
                     ret = 1;
                     break;
                 }
             }
         }
-        av_channel_layout_uninit(&fmt);
     }
 
     return ret;