2 * Copyright (c) 2011 Stefano Sabatini
4 * This file is part of Libav.
6 * Libav 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.
11 * Libav 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * filter for showing textual audio frame information
29 #include "libavutil/adler32.h"
30 #include "libavutil/attributes.h"
31 #include "libavutil/channel_layout.h"
32 #include "libavutil/common.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/samplefmt.h"
40 typedef struct AShowInfoContext {
42 * Scratch space for individual plane checksums for planar audio
44 uint32_t *plane_checksums;
52 static int config_input(AVFilterLink *inlink)
54 AShowInfoContext *s = inlink->dst->priv;
55 int channels = av_get_channel_layout_nb_channels(inlink->channel_layout);
56 s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums));
57 if (!s->plane_checksums)
58 return AVERROR(ENOMEM);
63 static av_cold void uninit(AVFilterContext *ctx)
65 AShowInfoContext *s = ctx->priv;
66 av_freep(&s->plane_checksums);
69 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
71 AVFilterContext *ctx = inlink->dst;
72 AShowInfoContext *s = ctx->priv;
73 char chlayout_str[128];
74 uint32_t checksum = 0;
75 int channels = av_get_channel_layout_nb_channels(buf->channel_layout);
76 int planar = av_sample_fmt_is_planar(buf->format);
77 int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
78 int data_size = buf->nb_samples * block_align;
79 int planes = planar ? channels : 1;
82 for (i = 0; i < planes; i++) {
83 uint8_t *data = buf->extended_data[i];
85 s->plane_checksums[i] = av_adler32_update(0, data, data_size);
86 checksum = i ? av_adler32_update(checksum, data, data_size) :
87 s->plane_checksums[0];
90 av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
93 av_log(ctx, AV_LOG_INFO,
94 "n:%"PRIu64" pts:%"PRId64" pts_time:%f "
95 "fmt:%s chlayout:%s rate:%d nb_samples:%d "
97 s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
98 av_get_sample_fmt_name(buf->format), chlayout_str,
99 buf->sample_rate, buf->nb_samples,
102 av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
103 for (i = 0; i < planes; i++)
104 av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
105 av_log(ctx, AV_LOG_INFO, "]\n");
108 return ff_filter_frame(inlink->dst->outputs[0], buf);
111 static const AVFilterPad inputs[] = {
114 .type = AVMEDIA_TYPE_AUDIO,
115 .get_audio_buffer = ff_null_get_audio_buffer,
116 .config_props = config_input,
117 .filter_frame = filter_frame,
122 static const AVFilterPad outputs[] = {
125 .type = AVMEDIA_TYPE_AUDIO,
130 AVFilter avfilter_af_ashowinfo = {
132 .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
133 .priv_size = sizeof(AShowInfoContext),