FFmpeg: libavfilter/af_join.c Source File
Go to the documentation of this file. 1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /**
20 * @file
21 * Audio join filter
22 *
23 * Join multiple audio inputs as different channels in
24 * a single output
25 */
26
32
38
40 int input;
///< input stream index
41 int in_channel_idx;
///< index of in_channel in the input stream data
45
48
52
55
57
58 /**
59 * Temporary storage for input frames, until we get one on each input.
60 */
62
63 /**
64 * Temporary storage for buffer references, for assembling the output frame.
65 */
68
69 #define OFFSET(x) offsetof(JoinContext, x)
70 #define A AV_OPT_FLAG_AUDIO_PARAM
71 #define F AV_OPT_FLAG_FILTERING_PARAM
74 { "channel_layout", "Channel layout of the "
76 { "map", "A comma-separated list of channels maps in the format "
77 "'input_stream.input_channel-output_channel.",
80 };
81
82 #define MAP_SEPARATOR '|'
83
85
87 {
90
91 while (cur && *cur) {
93 char *sep, *next, *p;
94 int input_idx, out_ch_idx;
95
97 if (next)
98 *next++ = 0;
99
100 /* split the map into input and output parts */
101 if (!(sep = strchr(cur, '-'))) {
103 "map '%s'\n", cur);
105 }
106 *sep++ = 0;
107
108 /* parse output channel */
110 if (out_ch_idx < 0) {
113 }
114
115 map = &
s->channels[out_ch_idx];
116
117 if (
map->input >= 0) {
119 "'%s'.\n", sep);
121 }
122
123 /* parse input channel */
124 input_idx = strtol(cur, &cur, 0);
125 if (input_idx < 0 || input_idx >=
s->inputs) {
127 input_idx);
129 }
130
131 if (*cur)
132 cur++;
133
134 map->input = input_idx;
136 map->in_channel_idx = strtol(cur, &p, 0);
137 if (p == cur) {
138 /* channel specifier is not a number, handle as channel name */
140 if (
map->in_channel < 0) {
143 }
144 }
else if (
map->in_channel_idx < 0) {
147 }
148
149 cur = next;
150 }
151 return 0;
152 }
153
155 {
158
159 s->channels =
av_calloc(
s->ch_layout.nb_channels,
sizeof(*
s->channels));
160 s->buffers =
av_calloc(
s->ch_layout.nb_channels,
sizeof(*
s->buffers));
161 s->input_frames =
av_calloc(
s->inputs,
sizeof(*
s->input_frames));
162 if (!
s->channels || !
s->buffers|| !
s->input_frames)
164
165 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
167 s->channels[
i].input = -1;
168 s->channels[
i].in_channel_idx = -1;
170 }
171
174
175 for (
i = 0;
i <
s->inputs;
i++) {
177
182
185 }
186
187 return 0;
188 }
189
191 {
194
195 for (
i = 0;
i <
s->inputs &&
s->input_frames;
i++) {
197 }
198
202 }
203
205 {
209
213
214 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
218 }
219
223
224 return 0;
225 }
226
231
233 {
235 memmove(chl->
ch + idx, chl->
ch + idx + 1,
236 (chl->
nb_ch - idx - 1) *
sizeof(*chl->
ch));
239 }
240
241 /*
242 * If ch is present in chl, remove it from the list and return it.
243 * Otherwise return AV_CHAN_NONE.
244 */
246 {
247 for (
int i = 0;
i < chl->
nb_ch;
i++)
248 if (chl->
ch[
i] == ch)
251 }
252
255 {
257
258 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
262 return;
263 }
264 }
265 }
266
269 {
271
272 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
276 return;
277 }
278 }
279 }
280
282 {
285 // unused channels from each input
287 char inbuf[64], outbuf[64];
289
290 /* initialize unused channel list for each input */
291 inputs_unused =
av_calloc(
ctx->nb_inputs,
sizeof(*inputs_unused));
292 if (!inputs_unused)
294 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
298
304 }
305
306 for (
int ch_idx = 0; ch_idx < iu->
nb_ch; ch_idx++) {
308 if (iu->
ch[ch_idx] < 0) {
309 /* no channel ordering information in this input,
310 * so don't auto-map from it */
312 break;
313 }
314 }
315 }
316
317 /* process user-specified maps */
318 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
323
325 continue;
326
328 ichl = &
inlink->ch_layout;
329 iu = &inputs_unused[ch->
input];
330
331 /* get the index for the channels defined by name */
337 "input stream #%d.\n", inbuf,
341 }
342 }
343
344 /* make sure channels specified by index actually exist */
350 }
351
353 }
354
355 /* guess channel maps when not explicitly defined */
356 /* first try unused matching channels */
357 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
359
362 }
363
364 /* if the above failed, try to find _any_ unused input channel */
365 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
367
370
374 "output channel '%s'.\n",
375 outbuf);
378 }
379
383 }
384
386 }
387
388 /* print mappings */
390 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
396
402 }
404
405 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
406 if (inputs_unused[
i].nb_ch ==
ctx->inputs[
i]->ch_layout.nb_channels)
409 }
410
412 for (
i = 0;
i <
ctx->nb_inputs;
i++)
416 }
417
419 {
423 int linesize = INT_MAX;
424 int nb_samples = INT_MAX;
425 int nb_buffers = 0;
427
428 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
429 if (!
s->input_frames[
i]) {
430 nb_samples = 0;
431 break;
432 } else {
433 nb_samples =
FFMIN(nb_samples,
s->input_frames[
i]->nb_samples);
434 }
435 }
436 if (!nb_samples)
437 goto eof;
438
439 /* setup the output frame */
449 }
450 }
451
452 /* copy the data pointers */
453 for (
i = 0;
i <
s->ch_layout.nb_channels;
i++) {
457
460
461 /* add the buffer where this plan is stored to the list if it's
462 * not already there */
464 if (!buf) {
467 }
468 for (j = 0; j < nb_buffers; j++)
469 if (
s->buffers[j]->buffer == buf->
buffer)
470 break;
472 s->buffers[nb_buffers++] = buf;
473 }
474
475 /* create references to the buffers we copied to output */
484 }
485 }
491 }
492 }
499 }
500 }
501
506
516 }
517
522
523 for (
i = 0;
i <
ctx->nb_inputs;
i++)
525
527
531 eof:
532 for (
i = 0;
i <
ctx->nb_inputs;
i++) {
535 !
s->input_frames[
i]) {
537 break;
538 }
539 }
540
541 return 0;
542 }
543
545 {
548 int nb_samples = 0;
550
552
553 if (!
s->input_frames[0]) {
559 }
560
563 return 0;
564 }
565 }
566
567 if (
s->input_frames[0])
568 nb_samples =
s->input_frames[0]->nb_samples;
569
570 for (
i = 1;
i <
ctx->nb_inputs && nb_samples > 0;
i++) {
571 if (
s->input_frames[
i])
572 continue;
578 }
579
580 if (!
s->eof && !
s->input_frames[
i]) {
582 return 0;
583 }
584 }
585
587 }
588
590 {
594 },
595 };
596
600 "multi-channel output."),
602 .priv_class = &join_class,
610 };
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers,...
A list of supported channel layouts.
#define AV_LOG_WARNING
Something somehow does not look correct.
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t duration
Duration of the frame, in the same units as pts.
enum MovChannelLayoutTag * layouts
#define AVERROR_EOF
End of file.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
char * av_asprintf(const char *fmt,...)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch, ChannelList *inputs)
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
#define FILTER_QUERY_FUNC(func)
#define AV_LOG_VERBOSE
Detailed information.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
const char * name
Filter name.
int nb_channels
Number of channels in this layout.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
A link between two filters.
static enum AVChannel channel_list_pop(ChannelList *chl, int idx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
int input
input stream index
AVChannelLayout ch_layout
Channel layout of the audio data.
static int join_query_formats(AVFilterContext *ctx)
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
AVBufferRef ** buffers
Temporary storage for buffer references, for assembling the output frame.
A filter pad used for either input or output.
AVFrame ** input_frames
Temporary storage for input frames, until we get one on each input.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int parse_maps(AVFilterContext *ctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch, ChannelList *inputs)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout, const char *str)
Get the index in a channel layout of a channel described by the given string.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Describe the class of an AVClass context structure.
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
int ff_append_inpad_free_name(AVFilterContext *f, AVFilterPad *p)
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 inputs
static const AVOption join_options[]
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
AVBufferRef * av_frame_get_plane_buffer(const AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
int(* init)(AVBSFContext *ctx)
AVChannelLayout ch_layout
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
An AVChannelLayout holds information about the channel layout of audio data.
int sample_rate
Sample rate of the audio data.
int format
agreed upon media format
static AVRational av_make_q(int num, int den)
Create an AVRational.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVFilterContext * src
source filter
int in_channel_idx
index of in_channel in the input stream data
static av_cold void join_uninit(AVFilterContext *ctx)
int sample_rate
samples per second
static void uninit(AVBSFContext *ctx)
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string in an abbreviated form describing a given channel.
uint8_t ** extended_data
pointers to the data planes/channels.
#define av_malloc_array(a, b)
const char * name
Pad name.
int ff_inlink_queued_samples(AVFilterLink *link)
void * av_calloc(size_t nmemb, size_t size)
static int activate(AVFilterContext *ctx)
static const AVFilterPad avfilter_af_join_outputs[]
enum AVMediaType type
AVFilterPad type.
enum AVChannel av_channel_from_string(const char *str)
This is the inverse function of av_channel_name().
@ AV_CHAN_NONE
Invalid channel index.
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
A reference to a data buffer.
const VDPAUPixFmtMap * map
AVChannelLayout ch_layout
channel layout of current buffer (see libavutil/channel_layout.h)
static int join_config_output(AVFilterLink *outlink)
#define FILTER_OUTPUTS(array)
static av_cold int join_init(AVFilterContext *ctx)
const AVFilter ff_af_join
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
static int try_push_frame(AVFilterContext *ctx)
static enum AVChannel channel_list_pop_ch(ChannelList *chl, enum AVChannel ch)
AVFILTER_DEFINE_CLASS(join)
int nb_extended_buf
Number of elements in extended_buf.
Generated on Thu Sep 26 2024 23:15:30 for FFmpeg by
doxygen
1.8.17