FFmpeg
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 #include "libavutil/cpu.h"
26 
27 #include "audio.h"
28 #include "avfilter.h"
29 #include "framepool.h"
30 #include "internal.h"
31 
33  {
34  .name = "default",
35  .type = AVMEDIA_TYPE_AUDIO,
36  }
37 };
38 
40 {
41  return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
42 }
43 
45 {
46  AVFrame *frame = NULL;
48  int align = av_cpu_max_align();
49 #if FF_API_OLD_CHANNEL_LAYOUT
51  int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
52 
53  av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
55 #endif
56 
57  if (!link->frame_pool) {
59  nb_samples, link->format, align);
60  if (!link->frame_pool)
61  return NULL;
62  } else {
63  int pool_channels = 0;
64  int pool_nb_samples = 0;
65  int pool_align = 0;
66  enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
67 
68  if (ff_frame_pool_get_audio_config(link->frame_pool,
69  &pool_channels, &pool_nb_samples,
70  &pool_format, &pool_align) < 0) {
71  return NULL;
72  }
73 
74  if (pool_channels != channels || pool_nb_samples < nb_samples ||
75  pool_format != link->format || pool_align != align) {
76 
77  ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
79  nb_samples, link->format, align);
80  if (!link->frame_pool)
81  return NULL;
82  }
83  }
84 
85  frame = ff_frame_pool_get(link->frame_pool);
86  if (!frame)
87  return NULL;
88 
89  frame->nb_samples = nb_samples;
90 #if FF_API_OLD_CHANNEL_LAYOUT
94 #endif
98  return NULL;
99  }
101 
103 
104  return frame;
105 }
106 
108 {
109  AVFrame *ret = NULL;
110 
111  if (link->dstpad->get_buffer.audio)
112  ret = link->dstpad->get_buffer.audio(link, nb_samples);
113 
114  if (!ret)
115  ret = ff_default_get_audio_buffer(link, nb_samples);
116 
117  return ret;
118 }
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:107
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
av_samples_set_silence
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:246
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:312
av_get_channel_layout_nb_channels
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: channel_layout.c:328
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
FFFramePool
Frame pool.
Definition: framepool.c:30
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
avassert.h
AVFrame::channel_layout
attribute_deprecated uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:575
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ff_null_get_audio_buffer
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:39
channels
channels
Definition: aptx.h:31
ff_frame_pool_get
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reussing old buffers from the pool when available.
Definition: framepool.c:190
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
frame
static AVFrame * frame
Definition: demux_decode.c:54
NULL
#define NULL
Definition: coverity.c:32
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:32
av_cpu_max_align
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition: cpu.c:268
ff_frame_pool_uninit
void ff_frame_pool_uninit(FFFramePool **pool)
Deallocate the frame pool.
Definition: framepool.c:283
cpu.h
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:567
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
internal.h
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
ff_frame_pool_audio_init
FFFramePool * ff_frame_pool_audio_init(AVBufferRef *(*alloc)(size_t size), int channels, int nb_samples, enum AVSampleFormat format, int align)
Allocate and initialize an audio frame pool.
Definition: framepool.c:114
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
ret
ret
Definition: filter_design.txt:187
framepool.h
channel_layout.h
avfilter.h
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:647
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
audio.h
ff_default_get_audio_buffer
AVFrame * ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
default handler for get_audio_buffer() for audio inputs
Definition: audio.c:44
ff_frame_pool_get_audio_config
int ff_frame_pool_get_audio_config(FFFramePool *pool, int *channels, int *nb_samples, enum AVSampleFormat *format, int *align)
Get the audio frame pool configuration.
Definition: framepool.c:171