1 STATIC
void fatal(u8
*fmt
, ...)
5 npv_perr("audio:filter:");
10 STATIC
void warning(u8
*fmt
, ...)
14 npv_perr("audio:filter:");
16 npv_vwarning(fmt
, ap
);
19 STATIC
void pout(u8
*fmt
, ...)
23 npv_pout("audio:filter:");
28 STATIC
bool is_recfg_required(avutil_audio_set_ref_t
*src_set
)
31 if (av_channel_layout_compare(&src_set
->ch_layout
,
32 &abufsrc_l
.key
.chans_layout
) != 0
33 || src_set
->rate
!= abufsrc_l
.key
.rate
34 || src_set
->fmt
!= abufsrc_l
.key
.fmt
)
38 STATIC
void abufsrc_cfg(avutil_rational_t tb
, AVChannelLayout
*chans_layout
,
39 int rate
, enum avutil_audio_fr_fmt_t fmt
, bool print_info
)
42 u8 chans_layout_str
[STR_SZ
]; /* should be overkill */
44 abufsrc_l
.this = avfilter_get_by_name("abuffer");
45 if (abufsrc_l
.this == 0)
46 fatal("audio buffer source:could not find the filter\n");
47 abufsrc_l
.ctx
= avfilter_graph_alloc_filt(graph_l
, abufsrc_l
.this,
49 if (abufsrc_l
.ctx
== 0)
50 fatal("audio buffer source context:could not allocate the instance in the filter graph\n");
51 r
= avutil_opt_set(abufsrc_l
.ctx
, "sample_fmt",
52 avutil_get_audio_fr_fmt_name(fmt
),
53 AVUTIL_OPT_SEARCH_CHILDREN
);
55 fatal("audio buffer source context:unable to set the decoder frame format option\n");
56 r
= avutil_opt_set_int(abufsrc_l
.ctx
, "sample_rate",
57 rate
, AVUTIL_OPT_SEARCH_CHILDREN
);
59 fatal("audio buffer source context:unable to set the decoder rate option\n");
60 av_channel_layout_describe(chans_layout
, chans_layout_str
,
61 sizeof(chans_layout_str
));
63 pout("audio buffer source context:using channels layout \"%s\"\n", chans_layout_str
);
64 r
= avutil_opt_set(abufsrc_l
.ctx
, "channel_layout", chans_layout_str
,
65 AVUTIL_OPT_SEARCH_CHILDREN
);
67 fatal("audio buffer source context:unable to set the decoder channel layout option\n");
68 r
= avutil_opt_set_q(abufsrc_l
.ctx
, "time_base", tb
,
69 AVUTIL_OPT_SEARCH_CHILDREN
);
71 fatal("audio buffer source context:unable to set the time base option\n");
72 r
= avfilter_init_str(abufsrc_l
.ctx
, 0);
74 fatal("audio buffer source context:unable to initialize\n");
76 STATIC
void vol_cfg(bool muted
, double vol_cfg
)
79 u8 vol_l10n_str
[sizeof("xxx.xx")]; /* should be overkill */
82 vol_l
= avfilter_get_by_name("volume");
84 fatal("volume:could not find the filter\n");
85 vol_ctx_l
= avfilter_graph_alloc_filt(graph_l
, vol_l
, "vol");
87 fatal("volume context:could not allocate the instance in the filter graph\n");
92 /* yeah the radix is localized, can be '.', ','... */
93 snprintf(vol_l10n_str
, sizeof(vol_l10n_str
), "%f", vol
);
94 r
= avutil_opt_set(vol_ctx_l
, "volume", vol_l10n_str
,
95 AVUTIL_OPT_SEARCH_CHILDREN
);
97 fatal("volume context:unable to set the volume option\n");
98 r
= avfilter_init_str(vol_ctx_l
, 0);
100 fatal("volume buffer context:unable to initialize\n");
102 STATIC
void afmt_cfg(AVChannelLayout
*chans_layout
, int rate
,
103 enum avutil_audio_fr_fmt_t fmt
, bool print_info
)
106 u8 rate_str
[sizeof("dddddd")];
107 u8 chans_layout_str
[STR_SZ
]; /* should be overkill */
109 afmt_l
= avfilter_get_by_name("aformat");
111 fatal("audio format:could not find the filter");
112 afmt_ctx_l
= avfilter_graph_alloc_filt(graph_l
, afmt_l
, "afmt");
114 fatal("audio format:could not allocate the instance in the filter graph\n");
115 r
= avutil_opt_set(afmt_ctx_l
, "sample_fmts",
116 avutil_get_audio_fr_fmt_name(fmt
), AVUTIL_OPT_SEARCH_CHILDREN
);
118 fatal("audio format context:could to set the pcm sample format\n");
119 snprintf(rate_str
, sizeof(rate_str
), "%d", rate
);
120 r
= avutil_opt_set(afmt_ctx_l
, "sample_rates", rate_str
,
121 AVUTIL_OPT_SEARCH_CHILDREN
);
123 fatal("audio format context:could not set the pcm rate\n");
124 av_channel_layout_describe(chans_layout
, chans_layout_str
,
125 sizeof(chans_layout_str
));
126 r
= avutil_opt_set(afmt_ctx_l
, "channel_layouts", chans_layout_str
,
127 AVUTIL_OPT_SEARCH_CHILDREN
);
129 fatal("audio format context:could not set the layout of channels\n");
131 pout("audio format context:channel layout is \"%s\"\n", chans_layout_str
);
132 r
= avfilter_init_str(afmt_ctx_l
, 0);
134 fatal("audio format context:unable to initialize\n");
136 STATIC
void abufsink_cfg(void)
140 abufsink_l
= avfilter_get_by_name("abuffersink");
142 fatal("audio buffer sink:could not find the filter\n");
143 filt_p
.abufsink_ctx
= avfilter_graph_alloc_filt(graph_l
, abufsink_l
,
145 if (filt_p
.abufsink_ctx
== 0)
146 fatal("audio buffer sink context:could not allocate the instance in the filter graph\n");
147 r
= avfilter_init_str(filt_p
.abufsink_ctx
, 0);
149 fatal("audio buffer sink context:unable to initialize\n");
151 STATIC
void init_once_local(void)
154 memset(&abufsrc_l
, 0, sizeof(abufsrc_l
));
160 /* floating point strs are localized... erk... */
161 snprintf(double_zero_l10n_str_l
, sizeof(double_zero_l10n_str_l
),
164 STATIC
void init_once_public(double initial_vol
)
166 filt_p
.set
= avutil_audio_set_ref_alloc();
168 fatal("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n");
169 filt_p
.pcm_written_ufrs_n
= 0;
170 filt_p
.vol
= initial_vol
;
171 filt_p
.muted
= false;
172 filt_p
.abufsink_ctx
= 0;