56 #define INPUT_SAMPLERATE     48000 
   57 #define INPUT_FORMAT         AV_SAMPLE_FMT_FLTP 
   58 #define INPUT_CHANNEL_LAYOUT AV_CH_LAYOUT_5POINT0 
   60 #define VOLUME_VAL 0.90 
   84         fprintf(stderr, 
"Unable to create filter graph.\n");
 
   92         fprintf(stderr, 
"Could not find the abuffer filter.\n");
 
   98         fprintf(stderr, 
"Could not allocate the abuffer instance.\n");
 
  113         fprintf(stderr, 
"Could not initialize the abuffer filter.\n");
 
  120         fprintf(stderr, 
"Could not find the volume filter.\n");
 
  126         fprintf(stderr, 
"Could not allocate the volume instance.\n");
 
  136         fprintf(stderr, 
"Could not initialize the volume filter.\n");
 
  144         fprintf(stderr, 
"Could not find the aformat filter.\n");
 
  150         fprintf(stderr, 
"Could not allocate the aformat instance.\n");
 
  156     snprintf(options_str, 
sizeof(options_str),
 
  157              "sample_fmts=%s:sample_rates=%d:channel_layouts=0x%"PRIx64,
 
  170         fprintf(stderr, 
"Could not find the abuffersink filter.\n");
 
  175     if (!abuffersink_ctx) {
 
  176         fprintf(stderr, 
"Could not allocate the abuffersink instance.\n");
 
  183         fprintf(stderr, 
"Could not initialize the abuffersink instance.\n");
 
  195         fprintf(stderr, 
"Error connecting filters\n");
 
  208     *sink  = abuffersink_ctx;
 
  219     int planes     = planar ? channels : 1;
 
  224     for (i = 0; i < 
planes; i++) {
 
  230         fprintf(stdout, 
"plane %d: 0x", i);
 
  231         for (j = 0; j < 
sizeof(
checksum); j++)
 
  232             fprintf(stdout, 
"%02X", checksum[j]);
 
  233         fprintf(stdout, 
"\n");
 
  235     fprintf(stdout, 
"\n");
 
  246 #define FRAME_SIZE 1024 
  260     for (i = 0; i < 5; i++) {
 
  264             data[j] = sin(2 * 
M_PI * (frame_num + j) * (i + 1) / FRAME_SIZE);
 
  270 int main(
int argc, 
char *argv[])
 
  278     int err, nb_frames, i;
 
  281         fprintf(stderr, 
"Usage: %s <duration>\n", argv[0]);
 
  285     duration  = atof(argv[1]);
 
  287     if (nb_frames <= 0) {
 
  288         fprintf(stderr, 
"Invalid duration: %s\n", argv[1]);
 
  295         fprintf(stderr, 
"Error allocating the frame\n");
 
  301         fprintf(stderr, 
"Error allocating the MD5 context\n");
 
  308         fprintf(stderr, 
"Unable to init filter graph:");
 
  313     for (i = 0; i < nb_frames; i++) {
 
  317             fprintf(stderr, 
"Error generating input frame:");
 
  325             fprintf(stderr, 
"Error submitting the frame to the filtergraph:");
 
  334                 fprintf(stderr, 
"Error processing the filtered frame:");
 
  346         } 
else if (err < 0) {
 
  348             fprintf(stderr, 
"Error filtering the data:");
 
  361     fprintf(stderr, 
"%s\n", errstr);
 
This structure describes decoded (raw) audio or video data. 
 
ptrdiff_t const GLvoid * data
 
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
 
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph. 
 
Main libavfilter public API header. 
 
Memory handling functions. 
 
Memory buffer source API. 
 
AVFilterGraph * filter_graph
 
int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
Check validity and configure all the links and formats in the graph. 
 
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL. 
 
#define AV_CH_LAYOUT_STEREO
 
static int get_input(AVFrame *frame, int frame_num)
 
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout. 
 
memory buffer sink API for audio and video 
 
int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)
Link two filters together. 
 
struct AVMD5 * av_md5_alloc(void)
Allocate an AVMD5 context. 
 
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values. 
 
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user). 
 
#define AVERROR_EOF
End of file. 
 
void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len)
Hash an array of data. 
 
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar. 
 
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
 
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g. 
 
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
 
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
 
static int process_output(struct AVMD5 *md5, AVFrame *frame)
 
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized. 
 
int main(int argc, char *argv[])
 
uint64_t channel_layout
Channel layout of the audio data. 
 
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name. 
 
static const struct @304 planes[]
 
audio channel layout utility functions 
 
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first. 
 
static int init_filter_graph(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink)
 
static volatile int checksum
 
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters. 
 
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. 
 
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
 
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), F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S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch const uint8_t **in ch off *out planar
 
void av_md5_init(AVMD5 *ctx)
Initialize MD5 hashing. 
 
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry. 
 
#define INPUT_CHANNEL_LAYOUT
 
int sample_rate
Sample rate of the audio data. 
 
Rational number (pair of numerator and denominator). 
 
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data. 
 
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields. 
 
#define AVERROR_FILTER_NOT_FOUND
Filter not found. 
 
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample. 
 
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
Initialize a filter with the supplied dictionary of options. 
 
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf. 
 
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph. 
 
Public header for MD5 hash function implementation. 
 
uint8_t ** extended_data
pointers to the data planes/channels. 
 
int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
Get a frame with filtered data from sink and put it in frame. 
 
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
 
int nb_samples
number of audio samples (per channel) described by this frame 
 
int attribute_align_arg av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame)
Add a frame to the buffer source.