]> git.sesse.net Git - ffmpeg/blob - libavfilter/af_ashowinfo.c
AVFrame: deprecate all now unused fields
[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 #include "internal.h"
38
39 typedef struct AShowInfoContext {
40     /**
41      * Scratch space for individual plane checksums for planar audio
42      */
43     uint32_t *plane_checksums;
44
45     /**
46      * Frame counter
47      */
48     uint64_t frame;
49 } AShowInfoContext;
50
51 static int config_input(AVFilterLink *inlink)
52 {
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);
58
59     return 0;
60 }
61
62 static void uninit(AVFilterContext *ctx)
63 {
64     AShowInfoContext *s = ctx->priv;
65     av_freep(&s->plane_checksums);
66 }
67
68 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
69 {
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->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->nb_samples * block_align;
78     int planes      = planar ? channels : 1;
79     int i;
80
81     for (i = 0; i < planes; i++) {
82         uint8_t *data = buf->extended_data[i];
83
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];
87     }
88
89     av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1,
90                                  buf->channel_layout);
91
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 "
95            "checksum:%08X ",
96            s->frame, buf->pts, buf->pts * av_q2d(inlink->time_base),
97            av_get_sample_fmt_name(buf->format), chlayout_str,
98            buf->sample_rate, buf->nb_samples,
99            checksum);
100
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");
105
106     s->frame++;
107     return ff_filter_frame(inlink->dst->outputs[0], buf);
108 }
109
110 static const AVFilterPad inputs[] = {
111     {
112         .name       = "default",
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     },
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 };