26 #include "libavutil/avstring.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/channel_layout.h"
29 #include "libavutil/opt.h"
30 #include "libswresample/swresample.h"
49 #define OFFSET(x) offsetof(AMergeContext, x)
50 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
53 {
"inputs",
"specify the number of inputs",
OFFSET(nb_inputs),
80 int i, overlap = 0, nb_ch = 0;
86 "No channel layout for input %d\n", i + 1);
96 if (outlayout & inlayout[i])
98 outlayout |= inlayout[i];
107 "Input channel layouts overlap: "
108 "output layout will be determined by the number of distinct input channels\n");
109 for (i = 0; i < nb_ch; i++)
113 outlayout = ((int64_t)1 << nb_ch) - 1;
116 int c, out_ch_number = 0;
118 route[0] = am->
route;
120 route[i] = route[i - 1] + am->
in[i - 1].
nb_ch;
121 for (c = 0; c < 64; c++)
123 if ((inlayout[i] >> c) & 1)
124 *(route[i]++) = out_ch_number++;
150 "Inputs must have the same sample rate "
151 "%d for in%d vs %d\n",
162 av_bprintf(&bp,
"%sin%d:", i ?
" + " :
"", i);
208 for (i = 0; i < nb_inputs; i++)
209 nb_ch += in[i].nb_ch;
212 for (i = 0; i < nb_inputs; i++) {
213 for (c = 0; c < in[i].nb_ch; c++) {
214 memcpy((*outs) + bps * *(route_cur++), ins[i], bps);
218 *outs += nb_ch *
bps;
228 int nb_samples, ns, i;
232 for (input_number = 0; input_number < am->
nb_inputs; input_number++)
233 if (inlink == ctx->
inputs[input_number])
252 outs = outbuf->
data[0];
255 ins[i] = inbuf[i]->
data[0] +
263 ctx->outputs[0]->time_base);
265 outbuf->nb_samples = nb_samples;
266 outbuf->channel_layout = outlink->channel_layout;
271 for (i = 0; i < am->nb_inputs; i++)
272 ns =
FFMIN(ns, inbuf[i]->nb_samples - am->in[i].pos);
277 copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 1);
280 copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 2);
283 copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, 4);
286 copy_samples(am->nb_inputs, am->in, am->route, ins, &outs, ns, am->bps);
291 for (i = 0; i < am->nb_inputs; i++) {
292 am->in[i].nb_samples -= ns;
294 if (am->in[i].pos == inbuf[i]->nb_samples) {
299 ins[i] = inbuf[i] ? inbuf[i]->data[0] : NULL;
341 "a single multi-channel stream."),
348 .priv_class = &amerge_class,
static AVFrame * ff_bufqueue_get(struct FFBufQueue *queue)
Get the first buffer from the queue and remove it.
struct AMergeContext::amerge_input * in
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
int nb_ch
number of channels for the input
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static enum AVSampleFormat formats[]
void av_frame_set_channels(AVFrame *frame, int val)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Structure holding the queue.
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
struct AVFilterChannelLayouts * in_channel_layouts
static enum AVSampleFormat ff_packed_sample_fmts_array[]
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static av_cold int init(AVFilterContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
static av_cold void uninit(AVFilterContext *ctx)
A filter pad used for either input or output.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
A link between two filters.
static const AVFilterPad amerge_outputs[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
static const AVOption amerge_options[]
int sample_rate
samples per second
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
uint64_t * channel_layouts
list of channel layouts
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Init a print buffer.
AVFrame * queue[FF_BUFQUEUE_SIZE]
static int request_frame(AVFilterLink *outlink)
static int config_output(AVFilterLink *outlink)
Buffer to print data progressively.
static int ff_bufqueue_is_full(struct FFBufQueue *queue)
Test if a buffer queue is full.
static void ff_bufqueue_discard_all(struct FFBufQueue *queue)
Unref and remove all buffers from the queue.
size_t char * av_asprintf(const char *fmt,...) av_printf_format(1
Print arguments following specified format into a large enough auto allocated buffer.
int format
agreed upon media format
A list of supported channel layouts.
Main libavfilter public API header.
AVFilterLink ** outputs
array of pointers to output links
static int query_formats(AVFilterContext *ctx)
#define AV_LOG_INFO
Standard information.
AVFilterPad * input_pads
array of input pads
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
AVFilterLink ** inputs
array of pointers to input links
rational number numerator/denominator
AVFilterContext * dst
dest filter
enum MovChannelLayoutTag * layouts
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
int nb_channel_layouts
number of channel layouts
#define SWR_CH_MAX
Maximum number of channels.
uint64_t channel_layout
channel layout of current buffer (see libavutil/channel_layout.h)
void av_bprintf(AVBPrint *buf, const char *fmt,...) av_printf_format(2
Append a formatted string to a print buffer.
int route[SWR_CH_MAX]
channels routing, see copy_samples
#define AVFILTER_DEFINE_CLASS(fname)
AVFilter avfilter_af_amerge
struct AVFilterChannelLayouts * out_channel_layouts
static void copy_samples(int nb_inputs, struct amerge_input in[], int *route, uint8_t *ins[], uint8_t **outs, int ns, int bps)
Copy samples from several input streams to one output stream.
static void ff_bufqueue_add(void *log, struct FFBufQueue *queue, AVFrame *buf)
Add a buffer to the queue.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
#define AV_NOPTS_VALUE
Undefined timestamp value.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout)
Append a description of a channel layout to a bprint buffer.
static AVFrame * ff_bufqueue_peek(struct FFBufQueue *queue, unsigned index)
Get a buffer from the queue without altering it.
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.