]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_ashowinfo.c
Include libavutil/channel_layout.h instead of libavutil/audioconvert.h
[ffmpeg] / libavfilter / af_ashowinfo.c
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  *
4  * This file is part of Libav.
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /**
22  * @file
23  * filter for showing textual audio frame information
24  */
25
26 #include <inttypes.h>
27 #include <stddef.h>
28
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"
34
35 #include "audio.h"
36 #include "avfilter.h"
37
38 typedef struct AShowInfoContext {
39     /**
40      * Scratch space for individual plane checksums for planar audio
41      */
42     uint32_t *plane_checksums;
43
44     /**
45      * Frame counter
46      */
47     uint64_t frame;
48 } AShowInfoContext;
49
50 static int config_input(AVFilterLink *inlink)
51 {
52     AShowInfoContext *s = inlink->dst->priv;
53     int channels = av_get_channel_layout_nb_channels(inlink->channel_layout);
54     s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums));
55     if (!s->plane_checksums)
56         return AVERROR(ENOMEM);
57
58     return 0;
59 }
60
61 static void uninit(AVFilterContext *ctx)
62 {
63     AShowInfoContext *s = ctx->priv;
64     av_freep(&s->plane_checksums);
65 }
66
67 static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
68 {
69     AVFilterContext *ctx = inlink->dst;
70     AShowInfoContext *s  = ctx->priv;
71     char chlayout_str[128];
72     uint32_t checksum = 0;
73     int channels    = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
74     int planar      = av_sample_fmt_is_planar(buf->format);
75     int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
76     int data_size   = buf->audio->nb_samples * block_align;
77     int planes      = planar ? channels : 1;
78     int i;
79
80     for (i = 0; i < planes; i++) {
81         uint8_t *data = buf->extended_data[i];
82
83         s->plane_checksums[i] = av_adler32_update(0, data, data_size);
84         checksum = i ? av_adler32_update(checksum, data, data_size) :
85                        s->plane_checksums[0];
86     }
87
88     av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
89                                  buf->audio->channel_layout);
90
91     av_log(ctx, AV_LOG_INFO,
92            "n:%"PRIu64" pts:%"PRId64" pts_time:%f "
93            "fmt:%s chlayout:%s rate:%d nb_samples:%d "
94            "checksum:%08X ",
95            s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
96            av_get_sample_fmt_name(buf->format), chlayout_str,
97            buf->audio->sample_rate, buf->audio->nb_samples,
98            checksum);
99
100     av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
101     for (i = 0; i < planes; i++)
102         av_log(ctx, AV_LOG_INFO, "%08X ", s->plane_checksums[i]);
103     av_log(ctx, AV_LOG_INFO, "]\n");
104
105     s->frame++;
106     return ff_filter_samples(inlink->dst->outputs[0], buf);
107 }
108
109 static const AVFilterPad inputs[] = {
110     {
111         .name       = "default",
112         .type             = AVMEDIA_TYPE_AUDIO,
113         .get_audio_buffer = ff_null_get_audio_buffer,
114         .config_props     = config_input,
115         .filter_samples   = filter_samples,
116         .min_perms        = AV_PERM_READ,
117     },
118     { NULL },
119 };
120
121 static const AVFilterPad outputs[] = {
122     {
123         .name = "default",
124         .type = AVMEDIA_TYPE_AUDIO,
125     },
126     { NULL },
127 };
128
129 AVFilter avfilter_af_ashowinfo = {
130     .name        = "ashowinfo",
131     .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
132     .priv_size   = sizeof(AShowInfoContext),
133     .uninit      = uninit,
134     .inputs      = inputs,
135     .outputs     = outputs,
136 };