FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
audio.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Stefano Sabatini | stefasab at gmail.com
3  * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
25 
26 #include "audio.h"
27 #include "avfilter.h"
28 #include "internal.h"
29 
31 {
32  return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
33 }
34 
36 {
38  int channels = link->channels;
39  int ret;
40 
42 
43  if (!frame)
44  return NULL;
45 
46  frame->nb_samples = nb_samples;
47  frame->format = link->format;
48  av_frame_set_channels(frame, link->channels);
49  frame->channel_layout = link->channel_layout;
50  frame->sample_rate = link->sample_rate;
51  ret = av_frame_get_buffer(frame, 0);
52  if (ret < 0) {
53  av_frame_free(&frame);
54  return NULL;
55  }
56 
57  av_samples_set_silence(frame->extended_data, 0, nb_samples, channels,
58  link->format);
59 
60 
61  return frame;
62 }
63 
64 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
65 {
66  AVFrame *ret = NULL;
67 
68  if (link->dstpad->get_audio_buffer)
69  ret = link->dstpad->get_audio_buffer(link, nb_samples);
70 
71  if (!ret)
72  ret = ff_default_get_audio_buffer(link, nb_samples);
73 
74  return ret;
75 }
void av_frame_set_channels(AVFrame *frame, int val)
#define NULL
Definition: coverity.c:32
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
Main libavfilter public API header.
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:145
static AVFrame * frame
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:237
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:64
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:158
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:353
audio channel layout utility functions
AVFrame * ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
get_audio_buffer() handler for filters which simply pass audio along
Definition: audio.c:30
AVFrame *(* get_audio_buffer)(AVFilterLink *link, int nb_samples)
Callback function to get an audio buffer.
Definition: internal.h:80
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
int sample_rate
Sample rate of the audio data.
Definition: frame.h:348
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:319
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:275
common internal and external API header
AVFrame * ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
default handler for get_audio_buffer() for audio inputs
Definition: audio.c:35
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:231
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:241