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 
52  if (!li->frame_pool) {
54  nb_samples, link->format, align);
55  if (!li->frame_pool)
56  return NULL;
57  } else {
58  int pool_channels = 0;
59  int pool_nb_samples = 0;
60  int pool_align = 0;
61  enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
62 
64  &pool_channels, &pool_nb_samples,
65  &pool_format, &pool_align) < 0) {
66  return NULL;
67  }
68 
69  if (pool_channels != channels || pool_nb_samples < nb_samples ||
70  pool_format != link->format || pool_align != align) {
71 
74  nb_samples, link->format, align);
75  if (!li->frame_pool)
76  return NULL;
77  }
78  }
79 
81  if (!frame)
82  return NULL;
83 
84  frame->nb_samples = nb_samples;
86  av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
88  return NULL;
89  }
90  frame->sample_rate = link->sample_rate;
91 
92  av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
93 
94  return frame;
95 }
96 
98 {
99  AVFrame *ret = NULL;
100 
101  if (link->dstpad->get_buffer.audio)
102  ret = link->dstpad->get_buffer.audio(link, nb_samples);
103 
104  if (!ret)
105  ret = ff_default_get_audio_buffer(link, nb_samples);
106 
107  return ret;
108 }
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:97
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
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:308
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
FilterLinkInternal
Definition: avfilter_internal.h:33
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:775
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
avassert.h
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
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:191
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
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:270
avfilter_internal.h
ff_frame_pool_uninit
void ff_frame_pool_uninit(FFFramePool **pool)
Deallocate the frame pool.
Definition: framepool.c:279
cpu.h
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:573
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:461
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
internal.h
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:115
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
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:440
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:172