asrc_anullsrc.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * Libav is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with Libav; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
24 #include "avfilter.h"
25 #include "libavutil/audioconvert.h"
26 
27 typedef struct {
28  uint64_t channel_layout;
29  int64_t sample_rate;
30 } ANullContext;
31 
32 static int init(AVFilterContext *ctx, const char *args, void *opaque)
33 {
34  ANullContext *priv = ctx->priv;
35  char channel_layout_str[128] = "";
36 
37  priv->sample_rate = 44100;
39 
40  if (args)
41  sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str);
42 
43  if (priv->sample_rate < 0) {
44  av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate);
45  return AVERROR(EINVAL);
46  }
47 
48  if (*channel_layout_str)
49  if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str))
50  && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) {
51  av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n",
52  channel_layout_str);
53  return AVERROR(EINVAL);
54  }
55 
56  return 0;
57 }
58 
59 static int config_props(AVFilterLink *outlink)
60 {
61  ANullContext *priv = outlink->src->priv;
62  char buf[128];
63  int chans_nb;
64 
65  outlink->sample_rate = priv->sample_rate;
66  outlink->channel_layout = priv->channel_layout;
67 
69  av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout);
70  av_log(outlink->src, AV_LOG_INFO,
71  "sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n",
72  priv->sample_rate, priv->channel_layout, buf);
73 
74  return 0;
75 }
76 
77 static int request_frame(AVFilterLink *link)
78 {
79  return -1;
80 }
81 
83  .name = "anullsrc",
84  .description = NULL_IF_CONFIG_SMALL("Null audio source, never return audio frames."),
85 
86  .init = init,
87  .priv_size = sizeof(ANullContext),
88 
89  .inputs = (AVFilterPad[]) {{ .name = NULL}},
90 
91  .outputs = (AVFilterPad[]) {{ .name = "default",
92  .type = AVMEDIA_TYPE_AUDIO,
93  .config_props = config_props,
94  .request_frame = request_frame, },
95  { .name = NULL}},
96 };
AVFilter avfilter_asrc_anullsrc
Definition: asrc_anullsrc.c:82
#define AV_CH_LAYOUT_STEREO
Definition: audioconvert.h:77
static int request_frame(AVFilterLink *link)
Definition: asrc_anullsrc.c:77
static int config_props(AVFilterLink *outlink)
Definition: asrc_anullsrc.c:59
audio conversion routines
A filter pad used for either input or output.
Definition: avfilter.h:312
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
void * priv
private data for use by the filter
Definition: avfilter.h:553
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: audioconvert.c:126
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
int64_t sample_rate
Definition: asrc_anullsrc.c:29
NULL
Definition: eval.c:50
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
uint64_t channel_layout
Definition: asrc_anullsrc.c:28
Filter definition.
Definition: avfilter.h:497
const char * name
filter name
Definition: avfilter.h:498
static int init(AVFilterContext *ctx, const char *args, void *opaque)
Definition: asrc_anullsrc.c:32
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, 0 if no match.
Definition: audioconvert.c:80
An instance of a filter.
Definition: avfilter.h:538
#define AV_LOG_INFO
Definition: log.h:119
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Definition: audioconvert.c:92