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 "avfilter_internal.h"
30 #include "framepool.h"
31 #include "internal.h"
32 
34  {
35  .name = "default",
36  .type = AVMEDIA_TYPE_AUDIO,
37  }
38 };
39 
41 {
42  return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
43 }
44 
46 {
47  AVFrame *frame = NULL;
50  int align = av_cpu_max_align();
51 #if FF_API_OLD_CHANNEL_LAYOUT
53  int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
54 
55  av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
57 #endif
58 
59  if (!li->frame_pool) {
61  nb_samples, link->format, align);
62  if (!li->frame_pool)
63  return NULL;
64  } else {
65  int pool_channels = 0;
66  int pool_nb_samples = 0;
67  int pool_align = 0;
68  enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
69 
71  &pool_channels, &pool_nb_samples,
72  &pool_format, &pool_align) < 0) {
73  return NULL;
74  }
75 
76  if (pool_channels != channels || pool_nb_samples < nb_samples ||
77  pool_format != link->format || pool_align != align) {
78 
81  nb_samples, link->format, align);
82  if (!li->frame_pool)
83  return NULL;
84  }
85  }
86 
88  if (!frame)
89  return NULL;
90 
91  frame->nb_samples = nb_samples;
92 #if FF_API_OLD_CHANNEL_LAYOUT
96 #endif
100  return NULL;
101  }
103 
105 
106  return frame;
107 }
108 
110 {
111  AVFrame *ret = NULL;
112 
113  if (link->dstpad->get_buffer.audio)
114  ret = link->dstpad->get_buffer.audio(link, nb_samples);
115 
116  if (!ret)
117  ret = ff_default_get_audio_buffer(link, nb_samples);
118 
119  return ret;
120 }
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:109
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
ff_link_internal
static FilterLinkInternal * ff_link_internal(AVFilterLink *link)
Definition: avfilter_internal.h:82
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:318
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:330
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
FilterLinkInternal
Definition: avfilter_internal.h:33
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:33
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:40
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:33
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
avfilter_internal.h
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:39
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:669
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:45
FilterLinkInternal::frame_pool
struct FFFramePool * frame_pool
Definition: avfilter_internal.h:36
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