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
void abufsrc_cfg(enum avutil_audio_fr_fmt_t fmt
, int rate
, int chans_n
,
29 uint64_t chans_layout
, bool print_info
)
32 avutil_rational_t time_base
;
33 u8 chans_layout_str
[STR_SZ
]; /* should be overkill */
35 abufsrc_l
= avfilter_get_by_name("abuffer");
37 fatal("audio buffer source:could not find the filter\n");
38 abufsrc_ctx_l
= avfilter_graph_alloc_filt(graph_l
, abufsrc_l
,
40 if (abufsrc_ctx_l
== 0)
41 fatal("audio buffer source context:could not allocate the instance in the filter graph\n");
42 r
= avutil_opt_set(abufsrc_ctx_l
, "sample_fmt",
43 avutil_get_audio_fr_fmt_name(fmt
),
44 AVUTIL_OPT_SEARCH_CHILDREN
);
46 fatal("audio buffer source context:unable to set the decoder frame format option\n");
47 r
= avutil_opt_set_int(abufsrc_ctx_l
, "sample_rate",
48 rate
, AVUTIL_OPT_SEARCH_CHILDREN
);
50 fatal("audio buffer source context:unable to set the decoder rate option\n");
52 * XXX: at the time of coding, bug for 1 chans layout... or I did miss
53 * some valuable information
55 avutil_get_chans_layout_str(chans_layout_str
, sizeof(chans_layout_str
),
56 chans_n
, chans_layout
);
58 pout("audio buffer source context:using channels layout \"%s\" (%d pcm channels)\n", chans_layout_str
, chans_n
);
59 r
= avutil_opt_set(abufsrc_ctx_l
, "channel_layout", chans_layout_str
,
60 AVUTIL_OPT_SEARCH_CHILDREN
);
62 fatal("audio buffer source context:unable to set the decoder channel layout option\n");
63 r
= avfilter_init_str(abufsrc_ctx_l
, 0);
65 fatal("audio buffer source context:unable to initialize\n");
67 STATIC
void vol_cfg(bool muted
, double vol_cfg
)
70 u8 vol_l10n_str
[sizeof("xxx.xx")]; /* should be overkill */
73 vol_l
= avfilter_get_by_name("volume");
75 fatal("volume:could not find the filter\n");
76 vol_ctx_l
= avfilter_graph_alloc_filt(graph_l
, vol_l
, "vol");
78 fatal("volume context:could not allocate the instance in the filter graph\n");
83 /* yeah the radix is localized, can be '.', ','... */
84 snprintf(vol_l10n_str
, sizeof(vol_l10n_str
), "%f", vol
);
85 r
= avutil_opt_set(vol_ctx_l
, "volume", vol_l10n_str
,
86 AVUTIL_OPT_SEARCH_CHILDREN
);
88 fatal("volume context:unable to set the volume option\n");
89 r
= avfilter_init_str(vol_ctx_l
, 0);
91 fatal("volume buffer context:unable to initialize\n");
93 STATIC
void afmt_cfg(enum avutil_audio_fr_fmt_t fmt
, int rate
, int chans_n
,
94 uint64_t chans_layout
, bool print_info
)
97 u8 rate_str
[sizeof("dddddd")];
98 u8 chans_layout_str
[STR_SZ
]; /* should be overkill */
100 afmt_l
= avfilter_get_by_name("aformat");
102 fatal("audio format:could not find the filter");
103 afmt_ctx_l
= avfilter_graph_alloc_filt(graph_l
, afmt_l
, "afmt");
105 fatal("audio format:could not allocate the instance in the filter graph\n");
106 r
= avutil_opt_set(afmt_ctx_l
, "sample_fmts",
107 avutil_get_audio_fr_fmt_name(fmt
), AVUTIL_OPT_SEARCH_CHILDREN
);
109 fatal("audio format context:could to set the pcm sample format\n");
110 snprintf(rate_str
, sizeof(rate_str
), "%d", rate
);
111 r
= avutil_opt_set(afmt_ctx_l
, "sample_rates", rate_str
,
112 AVUTIL_OPT_SEARCH_CHILDREN
);
114 fatal("audio format context:could not set the pcm rate\n");
115 avutil_get_chans_layout_str(chans_layout_str
, sizeof(chans_layout_str
),
116 chans_n
, chans_layout
);
117 r
= avutil_opt_set(afmt_ctx_l
, "channel_layouts", chans_layout_str
,
118 AVUTIL_OPT_SEARCH_CHILDREN
);
120 fatal("audio format context:could not set the layout of channels\n");
122 pout("audio format context:channel layout is \"%s\"\n", chans_layout_str
);
123 r
= avfilter_init_str(afmt_ctx_l
, 0);
125 fatal("audio format context:unable to initialize\n");
127 STATIC
void abufsink_cfg(void)
131 abufsink_l
= avfilter_get_by_name("abuffersink");
133 fatal("audio buffer sink:could not find the filter\n");
134 abufsink_ctx_l
= avfilter_graph_alloc_filt(graph_l
, abufsink_l
,
136 if (abufsink_ctx_l
== 0)
137 fatal("audio buffer sink context:could not allocate the instance in the filter graph\n");
138 r
= avfilter_init_str(abufsink_ctx_l
, 0);
140 fatal("audio buffer sink context:unable to initialize\n");
142 STATIC
void init_once_local(void)
153 /* floating point strs are localized... */
154 snprintf(double_zero_l10n_str_l
, sizeof(double_zero_l10n_str_l
),
157 STATIC
void init_once_public(double initial_vol
)
159 filt_p
.set
= avutil_audio_set_ref_alloc();
161 fatal("ffmpeg:unable to allocate a reference on set of frames for the public part of the interactive latency filter\n");
162 filt_p
.pcm_written_ufrs_n
= 0;
163 filt_p
.vol
= initial_vol
;
164 filt_p
.muted
= false;