2 #define PUSHED_ONE_SET 1
4 #define FILT_SWITCHED_TO_DRAINING 3
5 STATIC u8
filt_push_dec_sets(void)
9 avutil_audio_set_ref_t
**a
;
11 npv_audio_dec_sets_lock();
12 if (npv_audio_dec_sets_p
.n
== 0) {
13 if (npv_audio_dec_sets_p
.eof_receive
) {
14 ri
= avfilter_bufsrc_add_audio_set_flags(abufsrc_ctx_l
,
15 0, AVFILTER_BUFSRC_FLAG_PUSH
16 | AVFILTER_BUFSRC_FLAG_KEEP_REF
);
18 fatal("ffmpeg:unable to notify the end of data to the filter source audio buffer context\n");
19 pout("ffmpeg:interactive filter switched to draining\n");
20 r8
= FILT_SWITCHED_TO_DRAINING
;
26 a
= npv_audio_dec_sets_p
.a
;
27 /* the dec_sets_p bufs will be unref in avcodec_audio_receive_set */
28 ri
= avfilter_bufsrc_add_audio_set_flags(abufsrc_ctx_l
, a
[0],
29 AVFILTER_BUFSRC_FLAG_PUSH
| AVFILTER_BUFSRC_FLAG_KEEP_REF
);
31 /* rotate the ptrs if needed */
32 if (npv_audio_dec_sets_p
.n
> 1) {
33 avutil_audio_set_ref_t
*save
;
36 memmove(&a
[0], &a
[1], sizeof(*a
)
37 * (npv_audio_dec_sets_p
.n
- 1));
38 a
[npv_audio_dec_sets_p
.n
- 1] = save
;
40 npv_audio_dec_sets_p
.n
--;
43 } else if (ri
== AVERROR(EAGAIN
)) {
47 fatal("ffmpeg:unable to submit a decoder set of frames to the filter source audio buffer context\n");
49 npv_audio_dec_sets_unlock();
55 #undef PUSHED_NULL_SET
56 #undef FILT_SWITCHED_TO_DRAINING
58 #define HAVE_FILT_SET 1
60 STATIC u8
filt_set_try_get(void)
64 * the last dec set should switch the filt in draining mode, and
65 * filt_p.set won't matter.
67 r
= avfilter_bufsink_get_audio_set(abufsink_ctx_l
, filt_p
.set
);
68 if (r
== AVERROR(EAGAIN
)) {
71 filt_p
.pcm_written_ufrs_n
= 0;
73 } else if (r
== AVUTIL_AVERROR_EOF
) {
76 fatal("ffmpeg:error while getting frames from the filter\n");
81 #define DONT_PRINT_INFO false
82 STATIC
void filt_flush(void)
84 enum avutil_audio_fr_fmt_t dst_fmt
;
87 uint64_t dst_chans_layout
;
89 avutil_audio_set_unref(filt_p
.set
);
90 filt_p
.pcm_written_ufrs_n
= 0;
92 npv_audio_pcm2ff(npv_audio_pcm_p
, &dst_fmt
, &dst_rate
, &dst_chans_n
,
93 &dst_chans_layout
, DONT_PRINT_INFO
);
95 npv_audio_dec_ctx_p
->fr_fmt
, npv_audio_dec_ctx_p
->fr_rate
,
96 npv_audio_dec_ctx_p
->chans_n
, npv_audio_dec_ctx_p
->chans_layout
,
97 filt_p
.muted
, filt_p
.vol
,
98 dst_fmt
, dst_rate
, dst_chans_n
, dst_chans_layout
,
101 #undef DONT_PRINT_INFO
102 STATIC
void init_once(double initial_vol
)
105 init_once_public(initial_vol
);
107 STATIC
void cfg(enum avutil_audio_fr_fmt_t src_fmt
, int src_rate
,
108 int src_chans_n
, uint64_t src_chans_layout
,
109 bool muted
, double vol
,
110 enum avutil_audio_fr_fmt_t dst_fmt
, int dst_rate
,
111 int dst_chans_n
, uint64_t dst_chans_layout
,
117 avfilter_graph_free(&graph_l
);
119 graph_l
= avfilter_graph_alloc();
121 fatal("unable to create filter graph\n");
122 abufsrc_cfg(src_fmt
, src_rate
, src_chans_n
, src_chans_layout
,
125 afmt_cfg(dst_fmt
, dst_rate
, dst_chans_n
, dst_chans_layout
, print_info
);
127 r
= avfilter_link(abufsrc_ctx_l
, 0, vol_ctx_l
, 0);
129 fatal("unable to connect the audio buffer source filter to the volume filter\n");
130 r
= avfilter_link(vol_ctx_l
, 0, afmt_ctx_l
, 0);
132 fatal("unable to connect the volume filter to the audio format filter\n");
133 r
= avfilter_link(afmt_ctx_l
, 0, abufsink_ctx_l
, 0);
135 fatal("unable to connect the audio format filter to the audio buffer sink filter\n");
136 r
= avfilter_graph_config(graph_l
, 0);
138 fatal("unable to configure the filter graph\n");
139 /*--------------------------------------------------------------------*/
142 dump_str
= avfilter_graph_dump(graph_l
, 0);
144 warning("unable to get a filter graph description\n");
147 pout("GRAPH START-------------------------------------------------------\n");
148 npv_pout("%s", dump_str
);
149 avutil_free(dump_str
);
150 pout("GRAPH END---------------------------------------------------------\n");
152 STATIC
void npv_audio_filt_cmd_mute(void)
155 u8 vol_l10n_str
[sizeof("xxx.xx")]; /* should be overkill */
159 pout("COMMAND:unmuting\n");
161 snprintf(vol_l10n_str
, sizeof(vol_l10n_str
), "%f", filt_p
.vol
);
162 r
= avfilter_graph_send_cmd(graph_l
, "vol", "volume",
163 vol_l10n_str
, resp
, sizeof(resp
), 0);
165 warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp
);
167 filt_p
.muted
= false;
170 pout("COMMAND:muting\n");
172 r
= avfilter_graph_send_cmd(graph_l
, "vol", "volume",
173 double_zero_l10n_str_l
, resp
, sizeof(resp
), 0);
175 warning("ffmpeg:volume context:unable to mute the volume to 0:response from volume filter:%s\n", resp
);
181 STATIC
void npv_audio_filt_cmd_vol_down(void)
184 u8 vol_l10n_str
[sizeof("xxx.xx")]; /* should be overkill */
187 filt_p
.vol
-= VOL_DELTA
;
190 snprintf(vol_l10n_str
, sizeof(vol_l10n_str
), "%f", filt_p
.vol
);
191 pout("COMMAND:volume down to value %s\n", vol_l10n_str
);
193 r
= avfilter_graph_send_cmd(graph_l
, "vol", "volume",
194 vol_l10n_str
, resp
, sizeof(resp
), 0);
196 warning("ffmpeg:volume context:unable to set the volume down to \"%s\":response from volume filter:\"%s\"\n", resp
);
199 STATIC
void npv_audio_filt_cmd_vol_up(void)
202 u8 vol_l10n_str
[sizeof("xxx.xx")]; /* should be overkill */
205 filt_p
.vol
+= VOL_DELTA
;
208 snprintf(vol_l10n_str
, sizeof(vol_l10n_str
), "%f", filt_p
.vol
);
209 pout("COMMAND:volume up to value %s\n", vol_l10n_str
);
211 r
= avfilter_graph_send_cmd(graph_l
, "vol", "volume",
212 vol_l10n_str
, resp
, sizeof(resp
), 0);
214 warning("ffmpeg:volume context:unable to set the volume up to \"%s\":response from volume filter:\"%s\"\n", resp
);