LCOV - code coverage report
Current view: top level - libavfilter - avf_showvolume.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 217 0.0 %
Date: 2018-05-20 11:54:08 Functions: 0 13 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2015 Paul B Mahol
       3             :  *
       4             :  * This file is part of FFmpeg.
       5             :  *
       6             :  * FFmpeg is free software; you can redistribute it and/or
       7             :  * modify it under the terms of the GNU Lesser General Public
       8             :  * License as published by the Free Software Foundation; either
       9             :  * version 2.1 of the License, or (at your option) any later version.
      10             :  *
      11             :  * FFmpeg is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with FFmpeg; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include "libavutil/avstring.h"
      22             : #include "libavutil/channel_layout.h"
      23             : #include "libavutil/eval.h"
      24             : #include "libavutil/intreadwrite.h"
      25             : #include "libavutil/opt.h"
      26             : #include "libavutil/parseutils.h"
      27             : #include "libavutil/xga_font_data.h"
      28             : #include "avfilter.h"
      29             : #include "formats.h"
      30             : #include "audio.h"
      31             : #include "video.h"
      32             : #include "internal.h"
      33             : 
      34             : static const char *const var_names[] = {   "VOLUME",   "CHANNEL",   "PEAK",        NULL };
      35             : enum                                   { VAR_VOLUME, VAR_CHANNEL, VAR_PEAK, VAR_VARS_NB };
      36             : enum DisplayScale   { LINEAR, LOG, NB_DISPLAY_SCALE };
      37             : 
      38             : typedef struct ShowVolumeContext {
      39             :     const AVClass *class;
      40             :     int w, h;
      41             :     int b;
      42             :     double f;
      43             :     AVRational frame_rate;
      44             :     char *color;
      45             :     int orientation;
      46             :     int step;
      47             :     float bgopacity;
      48             :     int mode;
      49             : 
      50             :     AVFrame *out;
      51             :     AVExpr *c_expr;
      52             :     int draw_text;
      53             :     int draw_volume;
      54             :     double *values;
      55             :     uint32_t *color_lut;
      56             :     float *max;
      57             :     float rms_factor;
      58             :     int display_scale;
      59             : 
      60             :     double draw_persistent_duration; /* in second */
      61             :     uint8_t persistant_max_rgba[4];
      62             :     int persistent_max_frames; /* number of frames to check max value */
      63             :     float *max_persistent; /* max value for draw_persistent_max for each channel */
      64             :     int *nb_frames_max_display; /* number of frame for each channel, for displaying the max value */
      65             : 
      66             :     void (*meter)(float *src, int nb_samples, float *max, float factor);
      67             : } ShowVolumeContext;
      68             : 
      69             : #define OFFSET(x) offsetof(ShowVolumeContext, x)
      70             : #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
      71             : 
      72             : static const AVOption showvolume_options[] = {
      73             :     { "rate", "set video rate",  OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
      74             :     { "r",    "set video rate",  OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
      75             :     { "b", "set border width",   OFFSET(b), AV_OPT_TYPE_INT, {.i64=1}, 0, 5, FLAGS },
      76             :     { "w", "set channel width",  OFFSET(w), AV_OPT_TYPE_INT, {.i64=400}, 80, 8192, FLAGS },
      77             :     { "h", "set channel height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=20}, 1, 900, FLAGS },
      78             :     { "f", "set fade",           OFFSET(f), AV_OPT_TYPE_DOUBLE, {.dbl=0.95}, 0, 1, FLAGS },
      79             :     { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="PEAK*255+floor((1-PEAK)*255)*256+0xff000000"}, 0, 0, FLAGS },
      80             :     { "t", "display channel names", OFFSET(draw_text), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
      81             :     { "v", "display volume value", OFFSET(draw_volume), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
      82             :     { "dm", "duration for max value display", OFFSET(draw_persistent_duration), AV_OPT_TYPE_DOUBLE, {.dbl=0.}, 0, 9000, FLAGS},
      83             :     { "dmc","set color of the max value line", OFFSET(persistant_max_rgba), AV_OPT_TYPE_COLOR, {.str = "orange"}, CHAR_MIN, CHAR_MAX, FLAGS },
      84             :     { "o", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "orientation" },
      85             :     {   "h", "horizontal", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "orientation" },
      86             :     {   "v", "vertical",   0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "orientation" },
      87             :     { "s", "set step size", OFFSET(step), AV_OPT_TYPE_INT, {.i64=0}, 0, 5, FLAGS },
      88             :     { "p", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, FLAGS },
      89             :     { "m", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "mode" },
      90             :     {   "p", "peak", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
      91             :     {   "r", "rms",  0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
      92             :     { "ds", "set display scale", OFFSET(display_scale), AV_OPT_TYPE_INT, {.i64=LINEAR}, LINEAR, NB_DISPLAY_SCALE - 1, FLAGS, "display_scale" },
      93             :     {   "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=LINEAR}, 0, 0, FLAGS, "display_scale" },
      94             :     {   "log", "log",  0, AV_OPT_TYPE_CONST, {.i64=LOG}, 0, 0, FLAGS, "display_scale" },
      95             :     { NULL }
      96             : };
      97             : 
      98             : AVFILTER_DEFINE_CLASS(showvolume);
      99             : 
     100           0 : static av_cold int init(AVFilterContext *ctx)
     101             : {
     102           0 :     ShowVolumeContext *s = ctx->priv;
     103             :     int ret;
     104             : 
     105           0 :     if (s->color) {
     106           0 :         ret = av_expr_parse(&s->c_expr, s->color, var_names,
     107             :                             NULL, NULL, NULL, NULL, 0, ctx);
     108           0 :         if (ret < 0)
     109           0 :             return ret;
     110             :     }
     111             : 
     112           0 :     return 0;
     113             : }
     114             : 
     115           0 : static int query_formats(AVFilterContext *ctx)
     116             : {
     117           0 :     AVFilterFormats *formats = NULL;
     118           0 :     AVFilterChannelLayouts *layouts = NULL;
     119           0 :     AVFilterLink *inlink = ctx->inputs[0];
     120           0 :     AVFilterLink *outlink = ctx->outputs[0];
     121             :     static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
     122             :     static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
     123             :     int ret;
     124             : 
     125           0 :     formats = ff_make_format_list(sample_fmts);
     126           0 :     if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
     127           0 :         return ret;
     128             : 
     129           0 :     layouts = ff_all_channel_counts();
     130           0 :     if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
     131           0 :         return ret;
     132             : 
     133           0 :     formats = ff_all_samplerates();
     134           0 :     if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
     135           0 :         return ret;
     136             : 
     137           0 :     formats = ff_make_format_list(pix_fmts);
     138           0 :     if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
     139           0 :         return ret;
     140             : 
     141           0 :     return 0;
     142             : }
     143             : 
     144           0 : static void find_peak(float *src, int nb_samples, float *peak, float factor)
     145             : {
     146             :     int i;
     147             : 
     148           0 :     *peak = 0;
     149           0 :     for (i = 0; i < nb_samples; i++)
     150           0 :         *peak = FFMAX(*peak, FFABS(src[i]));
     151           0 : }
     152             : 
     153           0 : static void find_rms(float *src, int nb_samples, float *rms, float factor)
     154             : {
     155             :     int i;
     156             : 
     157           0 :     for (i = 0; i < nb_samples; i++)
     158           0 :         *rms += factor * (src[i] * src[i] - *rms);
     159           0 : }
     160             : 
     161           0 : static int config_input(AVFilterLink *inlink)
     162             : {
     163           0 :     AVFilterContext *ctx = inlink->dst;
     164           0 :     ShowVolumeContext *s = ctx->priv;
     165             :     int nb_samples;
     166             : 
     167           0 :     nb_samples = FFMAX(1024, ((double)inlink->sample_rate / av_q2d(s->frame_rate)) + 0.5);
     168           0 :     inlink->partial_buf_size =
     169           0 :     inlink->min_samples =
     170           0 :     inlink->max_samples = nb_samples;
     171           0 :     s->values = av_calloc(inlink->channels * VAR_VARS_NB, sizeof(double));
     172           0 :     if (!s->values)
     173           0 :         return AVERROR(ENOMEM);
     174             : 
     175           0 :     s->color_lut = av_calloc(s->w, sizeof(*s->color_lut) * inlink->channels);
     176           0 :     if (!s->color_lut)
     177           0 :         return AVERROR(ENOMEM);
     178             : 
     179           0 :     s->max = av_calloc(inlink->channels, sizeof(*s->max));
     180           0 :     if (!s->max)
     181           0 :         return AVERROR(ENOMEM);
     182             : 
     183           0 :     s->rms_factor = 10000. / inlink->sample_rate;
     184             : 
     185           0 :     switch (s->mode) {
     186           0 :     case 0: s->meter = find_peak; break;
     187           0 :     case 1: s->meter = find_rms;  break;
     188           0 :     default: return AVERROR_BUG;
     189             :     }
     190             : 
     191           0 :     if (s->draw_persistent_duration > 0.) {
     192           0 :         s->persistent_max_frames = (int) FFMAX(av_q2d(s->frame_rate) * s->draw_persistent_duration, 1.);
     193           0 :         s->max_persistent = av_calloc(inlink->channels * s->persistent_max_frames, sizeof(*s->max_persistent));
     194           0 :         s->nb_frames_max_display = av_calloc(inlink->channels * s->persistent_max_frames, sizeof(*s->nb_frames_max_display));
     195             :     }
     196           0 :     return 0;
     197             : }
     198             : 
     199           0 : static int config_output(AVFilterLink *outlink)
     200             : {
     201           0 :     ShowVolumeContext *s = outlink->src->priv;
     202           0 :     AVFilterLink *inlink = outlink->src->inputs[0];
     203             :     int ch;
     204             : 
     205           0 :     if (s->orientation) {
     206           0 :         outlink->h = s->w;
     207           0 :         outlink->w = s->h * inlink->channels + (inlink->channels - 1) * s->b;
     208             :     } else {
     209           0 :         outlink->w = s->w;
     210           0 :         outlink->h = s->h * inlink->channels + (inlink->channels - 1) * s->b;
     211             :     }
     212             : 
     213           0 :     outlink->sample_aspect_ratio = (AVRational){1,1};
     214           0 :     outlink->frame_rate = s->frame_rate;
     215             : 
     216           0 :     for (ch = 0; ch < inlink->channels; ch++) {
     217             :         int i;
     218             : 
     219           0 :         for (i = 0; i < s->w; i++) {
     220           0 :             float max = i / (float)(s->w - 1);
     221             : 
     222           0 :             s->values[ch * VAR_VARS_NB + VAR_PEAK] = max;
     223           0 :             s->values[ch * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
     224           0 :             s->values[ch * VAR_VARS_NB + VAR_CHANNEL] = ch;
     225           0 :             s->color_lut[ch * s->w + i] = av_expr_eval(s->c_expr, &s->values[ch * VAR_VARS_NB], NULL);
     226             :         }
     227             :     }
     228             : 
     229           0 :     return 0;
     230             : }
     231             : 
     232           0 : static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
     233             : {
     234             :     const uint8_t *font;
     235             :     int font_height;
     236             :     int i;
     237             : 
     238           0 :     font = avpriv_cga_font,   font_height =  8;
     239             : 
     240           0 :     for (i = 0; txt[i]; i++) {
     241             :         int char_y, mask;
     242             : 
     243           0 :         if (o) { /* vertical orientation */
     244           0 :             for (char_y = font_height - 1; char_y >= 0; char_y--) {
     245           0 :                 uint8_t *p = pic->data[0] + (y + i * 10) * pic->linesize[0] + x * 4;
     246           0 :                 for (mask = 0x80; mask; mask >>= 1) {
     247           0 :                     if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
     248           0 :                         AV_WN32(&p[char_y * 4], ~AV_RN32(&p[char_y * 4]));
     249           0 :                     p += pic->linesize[0];
     250             :                 }
     251             :             }
     252             :         } else { /* horizontal orientation */
     253           0 :             uint8_t *p = pic->data[0] + y * pic->linesize[0] + (x + i * 8) * 4;
     254           0 :             for (char_y = 0; char_y < font_height; char_y++) {
     255           0 :                 for (mask = 0x80; mask; mask >>= 1) {
     256           0 :                     if (font[txt[i] * font_height + char_y] & mask)
     257           0 :                         AV_WN32(p, ~AV_RN32(p));
     258           0 :                     p += 4;
     259             :                 }
     260           0 :                 p += pic->linesize[0] - 8 * 4;
     261             :             }
     262             :         }
     263             :     }
     264           0 : }
     265             : 
     266           0 : static void clear_picture(ShowVolumeContext *s, AVFilterLink *outlink)
     267             : {
     268             :     int i, j;
     269           0 :     const uint32_t bg = (uint32_t)(s->bgopacity * 255) << 24;
     270             : 
     271           0 :     for (i = 0; i < outlink->h; i++) {
     272           0 :         uint32_t *dst = (uint32_t *)(s->out->data[0] + i * s->out->linesize[0]);
     273           0 :         for (j = 0; j < outlink->w; j++)
     274           0 :             AV_WN32A(dst + j, bg);
     275             :     }
     276           0 : }
     277             : 
     278           0 : static inline int calc_max_draw(ShowVolumeContext *s, AVFilterLink *outlink, float max)
     279             : {
     280             :     float max_val;
     281           0 :     if (s->display_scale == LINEAR) {
     282           0 :         max_val = max;
     283             :     } else { /* log */
     284           0 :         max_val = av_clipf(0.21 * log10(max) + 1, 0, 1);
     285             :     }
     286           0 :     if (s->orientation) { /* vertical */
     287           0 :         return outlink->h - outlink->h * max_val;
     288             :     } else { /* horizontal */
     289           0 :         return s->w * max_val;
     290             :     }
     291             : }
     292             : 
     293           0 : static inline void calc_persistent_max(ShowVolumeContext *s, float max, int channel)
     294             : {
     295             :     /* update max value for persistent max display */
     296           0 :     if ((max >= s->max_persistent[channel]) || (s->nb_frames_max_display[channel] >= s->persistent_max_frames)) { /* update max value for display */
     297           0 :         s->max_persistent[channel] = max;
     298           0 :         s->nb_frames_max_display[channel] = 0;
     299             :     } else {
     300           0 :         s->nb_frames_max_display[channel] += 1; /* incremente display frame count */
     301             :     }
     302           0 : }
     303             : 
     304           0 : static inline void draw_max_line(ShowVolumeContext *s, int max_draw, int channel)
     305             : {
     306             :     int k;
     307           0 :     if (s->orientation) { /* vertical */
     308           0 :         uint8_t *dst = s->out->data[0] + max_draw * s->out->linesize[0] + channel * (s->b + s->h) * 4;
     309           0 :         for (k = 0; k < s->h; k++) {
     310           0 :             memcpy(dst + k * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
     311             :         }
     312             :     } else { /* horizontal */
     313           0 :         for (k = 0; k < s->h; k++) {
     314           0 :             uint8_t *dst = s->out->data[0] + (channel * s->h + channel * s->b + k) * s->out->linesize[0];
     315           0 :             memcpy(dst + max_draw * 4, s->persistant_max_rgba, sizeof(s->persistant_max_rgba));
     316             :         }
     317             :     }
     318           0 : }
     319             : 
     320           0 : static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
     321             : {
     322           0 :     AVFilterContext *ctx = inlink->dst;
     323           0 :     AVFilterLink *outlink = ctx->outputs[0];
     324           0 :     ShowVolumeContext *s = ctx->priv;
     325           0 :     const int step = s->step;
     326             :     int c, j, k, max_draw;
     327             :     AVFrame *out;
     328             : 
     329           0 :     if (!s->out || s->out->width  != outlink->w ||
     330           0 :                    s->out->height != outlink->h) {
     331           0 :         av_frame_free(&s->out);
     332           0 :         s->out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
     333           0 :         if (!s->out) {
     334           0 :             av_frame_free(&insamples);
     335           0 :             return AVERROR(ENOMEM);
     336             :         }
     337           0 :         clear_picture(s, outlink);
     338             :     }
     339           0 :     s->out->pts = insamples->pts;
     340             : 
     341           0 :     if ((s->f < 1.) && (s->f > 0.)) {
     342           0 :         for (j = 0; j < outlink->h; j++) {
     343           0 :             uint8_t *dst = s->out->data[0] + j * s->out->linesize[0];
     344           0 :             const uint32_t alpha = s->bgopacity * 255;
     345             : 
     346           0 :             for (k = 0; k < outlink->w; k++) {
     347           0 :                 dst[k * 4 + 0] = FFMAX(dst[k * 4 + 0] * s->f, 0);
     348           0 :                 dst[k * 4 + 1] = FFMAX(dst[k * 4 + 1] * s->f, 0);
     349           0 :                 dst[k * 4 + 2] = FFMAX(dst[k * 4 + 2] * s->f, 0);
     350           0 :                 dst[k * 4 + 3] = FFMAX(dst[k * 4 + 3] * s->f, alpha);
     351             :             }
     352             :         }
     353           0 :     } else if (s->f == 0.) {
     354           0 :         clear_picture(s, outlink);
     355             :     }
     356             : 
     357           0 :     if (s->orientation) { /* vertical */
     358           0 :         for (c = 0; c < inlink->channels; c++) {
     359           0 :             float *src = (float *)insamples->extended_data[c];
     360           0 :             uint32_t *lut = s->color_lut + s->w * c;
     361             :             float max;
     362             : 
     363           0 :             s->meter(src, insamples->nb_samples, &s->max[c], s->rms_factor);
     364           0 :             max = s->max[c];
     365             : 
     366           0 :             s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
     367           0 :             max = av_clipf(max, 0, 1);
     368           0 :             max_draw = calc_max_draw(s, outlink, max);
     369             : 
     370           0 :             for (j = max_draw; j < s->w; j++) {
     371           0 :                 uint8_t *dst = s->out->data[0] + j * s->out->linesize[0] + c * (s->b + s->h) * 4;
     372           0 :                 for (k = 0; k < s->h; k++) {
     373           0 :                     AV_WN32A(&dst[k * 4], lut[s->w - j - 1]);
     374           0 :                     if (j & step)
     375           0 :                         j += step;
     376             :                 }
     377             :             }
     378             : 
     379           0 :             if (s->h >= 8 && s->draw_text) {
     380           0 :                 const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
     381           0 :                 if (!channel_name)
     382           0 :                     continue;
     383           0 :                 drawtext(s->out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1);
     384             :             }
     385             : 
     386           0 :             if (s->draw_persistent_duration > 0.) {
     387           0 :                 calc_persistent_max(s, max, c);
     388           0 :                 max_draw = FFMAX(0, calc_max_draw(s, outlink, s->max_persistent[c]) - 1);
     389           0 :                 draw_max_line(s, max_draw, c);
     390             :             }
     391             :         }
     392             :     } else { /* horizontal */
     393           0 :         for (c = 0; c < inlink->channels; c++) {
     394           0 :             float *src = (float *)insamples->extended_data[c];
     395           0 :             uint32_t *lut = s->color_lut + s->w * c;
     396             :             float max;
     397             : 
     398           0 :             s->meter(src, insamples->nb_samples, &s->max[c], s->rms_factor);
     399           0 :             max = s->max[c];
     400             : 
     401           0 :             s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
     402           0 :             max = av_clipf(max, 0, 1);
     403           0 :             max_draw = calc_max_draw(s, outlink, max);
     404             : 
     405           0 :             for (j = 0; j < s->h; j++) {
     406           0 :                 uint8_t *dst = s->out->data[0] + (c * s->h + c * s->b + j) * s->out->linesize[0];
     407             : 
     408           0 :                 for (k = 0; k < max_draw; k++) {
     409           0 :                     AV_WN32A(dst + k * 4, lut[k]);
     410           0 :                     if (k & step)
     411           0 :                         k += step;
     412             :                 }
     413             :             }
     414             : 
     415           0 :             if (s->h >= 8 && s->draw_text) {
     416           0 :                 const char *channel_name = av_get_channel_name(av_channel_layout_extract_channel(insamples->channel_layout, c));
     417           0 :                 if (!channel_name)
     418           0 :                     continue;
     419           0 :                 drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0);
     420             :             }
     421             : 
     422           0 :             if (s->draw_persistent_duration > 0.) {
     423           0 :                 calc_persistent_max(s, max, c);
     424           0 :                 max_draw = FFMAX(0, calc_max_draw(s, outlink, s->max_persistent[c]) - 1);
     425           0 :                 draw_max_line(s, max_draw, c);
     426             :             }
     427             :         }
     428             :     }
     429             : 
     430           0 :     av_frame_free(&insamples);
     431           0 :     out = av_frame_clone(s->out);
     432           0 :     if (!out)
     433           0 :         return AVERROR(ENOMEM);
     434           0 :     av_frame_make_writable(out);
     435             : 
     436             :     /* draw volume level */
     437           0 :     for (c = 0; c < inlink->channels && s->h >= 8 && s->draw_volume; c++) {
     438             :         char buf[16];
     439             : 
     440           0 :         if (s->orientation) { /* vertical */
     441           0 :             snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
     442           0 :             drawtext(out, c * (s->h + s->b) + (s->h - 8) / 2, 2, buf, 1);
     443             :         } else { /* horizontal */
     444           0 :             snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
     445           0 :             drawtext(out, FFMAX(0, s->w - 8 * (int)strlen(buf)), c * (s->h + s->b) + (s->h - 8) / 2, buf, 0);
     446             :         }
     447             :     }
     448             : 
     449           0 :     return ff_filter_frame(outlink, out);
     450             : }
     451             : 
     452           0 : static av_cold void uninit(AVFilterContext *ctx)
     453             : {
     454           0 :     ShowVolumeContext *s = ctx->priv;
     455             : 
     456           0 :     av_frame_free(&s->out);
     457           0 :     av_expr_free(s->c_expr);
     458           0 :     av_freep(&s->values);
     459           0 :     av_freep(&s->color_lut);
     460           0 :     av_freep(&s->max);
     461           0 : }
     462             : 
     463             : static const AVFilterPad showvolume_inputs[] = {
     464             :     {
     465             :         .name         = "default",
     466             :         .type         = AVMEDIA_TYPE_AUDIO,
     467             :         .config_props = config_input,
     468             :         .filter_frame = filter_frame,
     469             :     },
     470             :     { NULL }
     471             : };
     472             : 
     473             : static const AVFilterPad showvolume_outputs[] = {
     474             :     {
     475             :         .name         = "default",
     476             :         .type         = AVMEDIA_TYPE_VIDEO,
     477             :         .config_props = config_output,
     478             :     },
     479             :     { NULL }
     480             : };
     481             : 
     482             : AVFilter ff_avf_showvolume = {
     483             :     .name          = "showvolume",
     484             :     .description   = NULL_IF_CONFIG_SMALL("Convert input audio volume to video output."),
     485             :     .init          = init,
     486             :     .uninit        = uninit,
     487             :     .query_formats = query_formats,
     488             :     .priv_size     = sizeof(ShowVolumeContext),
     489             :     .inputs        = showvolume_inputs,
     490             :     .outputs       = showvolume_outputs,
     491             :     .priv_class    = &showvolume_class,
     492             : };

Generated by: LCOV version 1.13