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/channel_layout.h"
31
#include "libavutil/common.h"
32
#include "libavutil/mem.h"
33
#include "libavutil/samplefmt.h"
39
typedef struct AShowInfoContext {
41
* Scratch space for individual plane checksums for planar audio
43
uint32_t *plane_checksums;
51
static int config_input(AVFilterLink *inlink)
53
AShowInfoContext *s = inlink->dst->priv;
54
int channels = av_get_channel_layout_nb_channels(inlink->channel_layout);
55
s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums));
56
if (!s->plane_checksums)
57
return AVERROR(ENOMEM);
62
static void uninit(AVFilterContext *ctx)
64
AShowInfoContext *s = ctx->priv;
65
av_freep(&s->plane_checksums);
68
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
70
AVFilterContext *ctx = inlink->dst;
71
AShowInfoContext *s = ctx->priv;
72
char chlayout_str[128];
73
uint32_t checksum = 0;
74
int channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
75
int planar = av_sample_fmt_is_planar(buf->format);
76
int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
77
int data_size = buf->audio->nb_samples * block_align;
78
int planes = planar ? channels : 1;
81
for (i = 0; i < planes; i++) {
82
uint8_t *data = buf->extended_data[i];
84
s->plane_checksums[i] = av_adler32_update(0, data, data_size);
85
checksum = i ? av_adler32_update(checksum, data, data_size) :
86
s->plane_checksums[0];
89
av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
90
buf->audio->channel_layout);
92
av_log(ctx, AV_LOG_INFO,
93
"n:%"PRIu64" pts:%"PRId64" pts_time:%f "
94
"fmt:%s chlayout:%s rate:%d nb_samples:%d "
96
s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
97
av_get_sample_fmt_name(buf->format), chlayout_str,
98
buf->audio->sample_rate, buf->audio->nb_samples,
101
av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
102
for (i = 0; i < planes; i++)
103
av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
104
av_log(ctx, AV_LOG_INFO, "]\n");
107
return ff_filter_frame(inlink->dst->outputs[0], buf);
110
static const AVFilterPad inputs[] = {
113
.type = AVMEDIA_TYPE_AUDIO,
114
.get_audio_buffer = ff_null_get_audio_buffer,
115
.config_props = config_input,
116
.filter_frame = filter_frame,
117
.min_perms = AV_PERM_READ,
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),