+
+#endif // CONFIG_SHOWWAVES_FILTER
+
+#if CONFIG_SHOWWAVESPIC_FILTER
+
+#define OFFSET(x) offsetof(ShowWavesContext, x)
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
+
+static const AVOption showwavespic_options[] = {
+ { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
+ { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "600x240"}, 0, 0, FLAGS },
+ { "split_channels", "draw channels separately", OFFSET(split_channels), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(showwavespic);
+
+static int showwavespic_config_input(AVFilterLink *inlink)
+{
+ AVFilterContext *ctx = inlink->dst;
+ ShowWavesContext *showwaves = ctx->priv;
+
+ if (showwaves->single_pic) {
+ showwaves->sum = av_mallocz_array(inlink->channels, sizeof(*showwaves->sum));
+ if (!showwaves->sum)
+ return AVERROR(ENOMEM);
+ }
+
+ return 0;
+}
+
+static int showwavespic_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
+{
+ AVFilterContext *ctx = inlink->dst;
+ AVFilterLink *outlink = ctx->outputs[0];
+ ShowWavesContext *showwaves = ctx->priv;
+ int16_t *p = (int16_t *)insamples->data[0];
+ int ret = 0;
+
+ if (showwaves->single_pic) {
+ struct frame_node *f;
+
+ ret = alloc_out_frame(showwaves, p, inlink, outlink, insamples);
+ if (ret < 0)
+ goto end;
+
+ /* queue the audio frame */
+ f = av_malloc(sizeof(*f));
+ if (!f) {
+ ret = AVERROR(ENOMEM);
+ goto end;
+ }
+ f->frame = insamples;
+ f->next = NULL;
+ if (!showwaves->last_frame) {
+ showwaves->audio_frames =
+ showwaves->last_frame = f;
+ } else {
+ showwaves->last_frame->next = f;
+ showwaves->last_frame = f;
+ }
+ showwaves->total_samples += insamples->nb_samples;
+
+ return 0;
+ }
+
+end:
+ av_frame_free(&insamples);
+ return ret;
+}
+
+static const AVFilterPad showwavespic_inputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .config_props = showwavespic_config_input,
+ .filter_frame = showwavespic_filter_frame,
+ },
+ { NULL }
+};
+
+static const AVFilterPad showwavespic_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .config_props = config_output,
+ .request_frame = request_frame,
+ },
+ { NULL }
+};
+
+AVFilter ff_avf_showwavespic = {
+ .name = "showwavespic",
+ .description = NULL_IF_CONFIG_SMALL("Convert input audio to a video output single picture."),
+ .init = init,
+ .uninit = uninit,
+ .query_formats = query_formats,
+ .priv_size = sizeof(ShowWavesContext),
+ .inputs = showwavespic_inputs,
+ .outputs = showwavespic_outputs,
+ .priv_class = &showwavespic_class,
+};
+
+#endif // CONFIG_SHOWWAVESPIC_FILTER