History

fftools/ffmpeg_filter: reinitialize the filterchain if downmix metadata changed between frames

James Almer committed 1 year ago

Commit 4f9afbb1 parent 6a282cd1 file · +28 −1Browse files

Unified · Split

fftools/ffmpeg_filter.c+28−1
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avstring.h"
3131 #include "libavutil/bprint.h"
3232 #include "libavutil/channel_layout.h"
33+#include "libavutil/downmix_info.h"
3334 #include "libavutil/mem.h"
3435 #include "libavutil/opt.h"
3536 #include "libavutil/pixdesc.h"
@@ -150,6 +151,9 @@ typedef struct InputFilterPriv { · 114 unmodified lines
150151 int displaymatrix_applied;
151152 int32_t displaymatrix[9];
152153
154+ int downmixinfo_present;
155+ AVDownmixInfo downmixinfo;
156+
153157 struct {
154158 AVFrame *frame;
155159
@@ -2119,6 +2123,19 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr · 1963 unmodified lines
21192123 memcpy(ifp->displaymatrix, sd->data, sizeof(ifp->displaymatrix));
21202124 ifp->displaymatrix_present = !!sd;
21212125
2126+ /* Copy downmix related side data to InputFilterPriv so it may be propagated
2127+ * to the filter chain even though it's not "global", as filters like aresample
2128+ * require this information during init and not when remixing a frame */
2129+ sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO);
2130+ if (sd) {
2131+ ret = av_frame_side_data_clone(&ifp->side_data,
2132+ &ifp->nb_side_data, sd, 0);
2133+ if (ret < 0)
2134+ return ret;
2135+ memcpy(&ifp->downmixinfo, sd->data, sizeof(ifp->downmixinfo));
2136+ }
2137+ ifp->downmixinfo_present = !!sd;
2138+
21222139 return 0;
21232140 }
21242141
@@ -2832,7 +2849,8 @@ enum ReinitReason { · 707 unmodified lines
28322849 VIDEO_CHANGED = (1 << 0),
28332850 AUDIO_CHANGED = (1 << 1),
28342851 MATRIX_CHANGED = (1 << 2),
2835− HWACCEL_CHANGED = (1 << 3)
2852+ DOWNMIX_CHANGED = (1 << 3),
2853+ HWACCEL_CHANGED = (1 << 4)
28362854 };
28372855
28382856 static const char *unknown_if_null(const char *str)
@@ -2873,6 +2891,13 @@ static int send_frame(FilterGraph *fg, FilterGraphThread *fgt, · 34 unmodified lines
28732891 } else if (ifp->displaymatrix_present)
28742892 need_reinit |= MATRIX_CHANGED;
28752893
2894+ if (sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO)) {
2895+ if (!ifp->downmixinfo_present ||
2896+ memcmp(sd->data, &ifp->downmixinfo, sizeof(ifp->downmixinfo)))
2897+ need_reinit |= DOWNMIX_CHANGED;
2898+ } else if (ifp->downmixinfo_present)
2899+ need_reinit |= DOWNMIX_CHANGED;
2900+
28762901 if (!(ifp->opts.flags & IFILTER_FLAG_REINIT) && fgt->graph)
28772902 need_reinit = 0;
28782903
@@ -2927,6 +2952,8 @@ static int send_frame(FilterGraph *fg, FilterGraphThread *fgt, · 48 unmodified lines
29272952 }
29282953 if (need_reinit & MATRIX_CHANGED)
29292954 av_bprintf(&reason, "display matrix changed, ");
2955+ if (need_reinit & DOWNMIX_CHANGED)
2956+ av_bprintf(&reason, "downmix medatata changed, ");
29302957 if (need_reinit & HWACCEL_CHANGED)
29312958 av_bprintf(&reason, "hwaccel changed, ");
29322959 if (reason.len > 1)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t