#define av_frame_free avcodec_free_frame
#endif
+#define HAVE_AVCODEC_FREE_CONTEXT (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 69, 100))
+#define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
+
struct a52_ctx {
snd_pcm_ioplug_t io;
snd_pcm_t *slave;
static void a52_free(struct a52_ctx *rec)
{
if (rec->avctx) {
- avcodec_close(rec->avctx);
+ #if HAVE_AVCODEC_FREE_CONTEXT
+ avcodec_free_context(&rec->avctx);
+ #else
+ avcodec_close(rec->avctx);
+ #endif
av_free(rec->avctx);
rec->avctx = NULL;
}
static void set_channel_layout(snd_pcm_ioplug_t *io)
{
struct a52_ctx *rec = io->private_data;
+#if HAVE_CH_LAYOUT
+ switch (io->channels) {
+ case 2:
+ rec->avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+ break;
+ case 4:
+ rec->avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD;
+ break;
+ case 6:
+ rec->avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
+ break;
+ default:
+ break;
+ }
+#else
switch (io->channels) {
case 2:
rec->avctx->channel_layout = AV_CH_LAYOUT_STEREO;
default:
break;
}
+#endif
}
#else
#define set_channel_layout(io) /* NOP */
rec->frame->nb_samples = rec->avctx->frame_size;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(58, 91, 0)
rec->frame->format = rec->avctx->sample_fmt;
+#if HAVE_CH_LAYOUT
+ av_channel_layout_from_mask(&rec->frame->ch_layout, rec->avctx->ch_layout.u.mask);
+#else
rec->frame->channels = rec->avctx->channels;
rec->frame->channel_layout = rec->avctx->channel_layout;
+#endif
if (av_frame_get_buffer(rec->frame, 0))
return -ENOMEM;
#else
rec->avctx->bit_rate = rec->bitrate * 1000;
rec->avctx->sample_rate = io->rate;
+#if HAVE_CH_LAYOUT
+ rec->avctx->ch_layout.nb_channels = io->channels;
+#else
rec->avctx->channels = io->channels;
+#endif
rec->avctx->sample_fmt = rec->av_format;
set_channel_layout(io);
#include <alsa/pcm_rate.h>
#include <libswresample/swresample.h>
+#include <libavcodec/avcodec.h>
+#include <libavutil/avutil.h>
#include <libavutil/channel_layout.h>
#include <libavutil/opt.h>
#include <libavutil/mathematics.h>
#include <libavutil/samplefmt.h>
+/* some compatibility wrappers */
+#ifndef AV_VERSION_INT
+#define AV_VERSION_INT(a, b, c) (((a) << 16) | ((b) << 8) | (c))
+#endif
+#ifndef LIBAVUTIL_VERSION_INT
+#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
+LIBAVUTIL_VERSION_MINOR, \
+LIBAVUTIL_VERSION_MICRO)
+#endif
+
+#define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
static unsigned int filter_size = 16;
if (!rate->avr)
return -ENOMEM;
+#if HAVE_CH_LAYOUT
+ AVChannelLayout layout;
+ av_channel_layout_default(&layout, rate->channels);
+ av_opt_set_chlayout(rate->avr, "in_chlayout", &layout, 0);
+ av_opt_set_chlayout(rate->avr, "out_chlayout", &layout, 0);
+#else
av_opt_set_channel_layout(rate->avr, "in_channel_layout",
- av_get_default_channel_layout(rate->channels), 0);
+ av_get_default_channel_layout(rate->channels), 0);
av_opt_set_channel_layout(rate->avr, "out_channel_layout",
- av_get_default_channel_layout(rate->channels), 0);
+ av_get_default_channel_layout(rate->channels), 0);
+#endif
av_opt_set_int(rate->avr, "in_sample_rate", rate->in_rate, 0);
av_opt_set_int(rate->avr, "out_sample_rate", rate->out_rate, 0);
fmt = support_multi_format(rate) ? info->in.format : SND_PCM_FORMAT_S16;