FFmpeg
Loading...
Searching...
No Matches
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#include "libavutil/eval.h"
27
28#include "audio.h"
29#include "avfilter.h"
30#include "avfilter_internal.h"
31#include "filters.h"
32#include "framepool.h"
33
35 {
36 .name = "default",
37 .type = AVMEDIA_TYPE_AUDIO,
38 }
39};
40
42{
43 return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
44}
45
47{
49 FilterLinkInternal *const li = ff_link_internal(link);
50 int channels = link->ch_layout.nb_channels;
51 int align = av_cpu_max_align();
52
54 link->format, align) < 0)
55 return NULL;
56
58 if (!frame)
59 return NULL;
60
61 frame->nb_samples = nb_samples;
63 av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
65 return NULL;
66 }
67 frame->sample_rate = link->sample_rate;
68
69 av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
70
71 return frame;
72}
73
75{
76 AVFrame *ret = NULL;
77
78 if (link->dstpad->get_buffer.audio)
79 ret = link->dstpad->get_buffer.audio(link, nb_samples);
80
81 if (!ret)
82 ret = ff_default_get_audio_buffer(link, nb_samples);
83
84 return ret;
85}
86
87int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
88{
89 char *tail;
90 double srate = av_strtod(arg, &tail);
91 if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
92 av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
93 return AVERROR(EINVAL);
94 }
95 *ret = srate;
96 return 0;
97}
98
99int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
100 void *log_ctx)
101{
102 AVChannelLayout chlayout = { 0 };
103 int res;
104
105 res = av_channel_layout_from_string(&chlayout, arg);
106 if (res < 0) {
107 av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
108 return AVERROR(EINVAL);
109 }
110
111 if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
112 av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
113 return AVERROR(EINVAL);
114 }
115 *ret = chlayout;
116 if (nret)
117 *nret = chlayout.nb_channels;
118
119 return 0;
120}
channels
Definition aptx.h:31
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
Parse a sample rate.
Definition audio.c:87
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:41
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:34
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, void *log_ctx)
Parse a channel layout or a corresponding integer representation.
Definition audio.c:99
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition audio.c:74
AVFrame * ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
default handler for get_audio_buffer() for audio inputs
Definition audio.c:46
simple assert() macros that are a bit more flexible than ISO C assert().
Main libavfilter public API header.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
static BitStreamFilterLinkInternal * ff_link_internal(AVBitStreamFilterLink *link)
Public libavutil channel layout APIs header.
common internal and external API header
#define NULL
Definition coverity.c:32
static AVFrame * frame
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition eval.c:110
simple arithmetic expression evaluator
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
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
const char * arg
Definition jacosubdec.c:65
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reusing old buffers from the pool when available.
Definition framepool.c:128
int ff_frame_pool_audio_reinit(FFFramePool *pool, int channels, int nb_samples, enum AVSampleFormat format, int align)
Recreate the audio frame pool if its current configuration differs from the provided configuration.
Definition framepool.c:244
size_t av_cpu_max_align(void)
Get the maximum data alignment that may be required by FFmpeg.
Definition cpu.c:287
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
int nb_channels
Number of channels in this layout.
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
A filter pad used for either input or output.
Definition filters.h:40
AVFrame *(* audio)(AVFilterLink *link, int nb_samples)
Definition filters.h:82
union AVFilterPad::@363170257351226013155122005037023043242205350137 get_buffer
Callback functions to get a video/audio buffers.
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
FFFramePool frame_pool
Pool of frames used for allocations.
#define av_log(a,...)