[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#721052: aqualung: lacks support AC3, AAC, WavPack, WMA, etc. after being rebuilt against libav 9



Control: tags -1 patch

Hi,

On 12.05.2014 16:39, Moritz Muehlenhoff wrote:
Sebastian Ramacher wrote:
aqualung fails to detect libav when rebuilt against libav 9. The build
log to rebuil aqualung against libav 9 contains:

This still holds with libav10.

Attached is a fix for this that I backported from upstream.

But since the last upstream release is from 2010, it might make more sense to update to a recent SVN snapshot instead of applying this patch.

Best regards,
Andreas
diff --git a/debian/control b/debian/control
index fe49870..7bb0f78 100644
--- a/debian/control
+++ b/debian/control
@@ -26,7 +26,8 @@ Build-Depends: debhelper (>= 5), autotools-dev,
  imagemagick,
  libpulse-dev,
  liblua5.1-0-dev | liblua5.1-dev,
- libmp3lame-dev
+ libmp3lame-dev,
+ dh-autoreconf
 Standards-Version: 3.8.4
 Homepage: http://aqualung.sourceforge.net/
 
diff --git a/debian/patches/Support-newer-lavc.patch b/debian/patches/Support-newer-lavc.patch
new file mode 100644
index 0000000..b287ad7
--- /dev/null
+++ b/debian/patches/Support-newer-lavc.patch
@@ -0,0 +1,317 @@
+Description: Backport support for newer lavc.
+
+Origin: https://github.com/jeremyevans/aqualung/blob/master/src/decoder/dec_lavc.c
+Author: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
+Last-Update: <2014-05-21>
+
+--- aqualung-0.9~beta11.orig/configure.ac
++++ aqualung-0.9~beta11/configure.ac
+@@ -660,10 +660,7 @@ else
+ 		fi
+ 	fi
+ 
+-	AC_CHECK_LIB(avformat, av_open_input_file, [avf_lib=yes], [avf_lib=no], [-lavcodec -lavutil -lz])
+-	AC_CHECK_LIB(avcodec, avcodec_open, [avc_lib=yes], [avc_lib=no], [-lavformat -lavutil -lz])
+-
+-	if test "$avc_hdr" = "yes" -a "$avf_hdr" = "yes" -a "$avc_lib" = "yes" -a "$avf_lib" = "yes" ; then
++	if test "$avc_hdr" = "yes" -a "$avf_hdr" = "yes" ; then
+ 	        lavc_LIBS="-lavformat -lavcodec -lavutil -lz"
+ 		AC_DEFINE([HAVE_LAVC], [1], [Defined if compile with LAVC support])
+ 	        lavc="yes"
+--- aqualung-0.9~beta11.orig/src/decoder/dec_lavc.c
++++ aqualung-0.9~beta11/src/decoder/dec_lavc.c
+@@ -15,27 +15,149 @@
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ 
+-    $Id: dec_lavc.c 1068 2009-07-24 12:02:30Z peterszilagyi $
++    $Id$
+ */
+ 
+-
+ #include <config.h>
+ 
++#include <stddef.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+-#include <string.h>
++#include <sys/types.h>
+ #include <ctype.h>
++#include <libavutil/avutil.h>
+ 
++#include "../common.h"
++#include "../rb.h"
+ #include "dec_lavc.h"
+ 
+ 
+-#ifdef HAVE_LAVC
+-
+ /* uncomment this to get some debug info */
+ /* #define LAVC_DEBUG */
+ 
+ extern size_t sample_size;
+ 
++/* interleaved: */
++void conv_fmt_u8(int n_samples, int sample_size, float * fsamples, AVFrame * frame) {
++	int i;
++	for (i = 0; i < n_samples; i++) {
++		*fsamples++ = (*((uint8_t*)(frame->extended_data[0] + i*sample_size)) - 128) / 256.f;
++	}
++}
++void conv_fmt_s16(int n_samples, int sample_size, float * fsamples, AVFrame * frame) {
++	int i;
++	for (i = 0; i < n_samples; i++) {
++		*fsamples++ = *((int16_t*)(frame->extended_data[0] + i*sample_size)) / 32768.f;
++	}
++}
++void conv_fmt_s32(int n_samples, int sample_size, float * fsamples, AVFrame * frame) {
++	int i;
++	for (i = 0; i < n_samples; i++) {
++		*fsamples++ = *((int32_t*)(frame->extended_data[0] + i*sample_size)) / 2147483648.f;
++	}
++}
++void conv_fmt_flt(int n_samples, int sample_size, float * fsamples, AVFrame * frame) {
++	int i;
++	for (i = 0; i < n_samples; i++) {
++		*fsamples++ = *((float*)(frame->extended_data[0] + i*sample_size));
++	}
++}
++void conv_fmt_dbl(int n_samples, int sample_size, float * fsamples, AVFrame * frame) {
++	int i;
++	for (i = 0; i < n_samples; i++) {
++		*fsamples++ = *((double*)(frame->extended_data[0] + i*sample_size));
++	}
++}
++
++/* planar: */
++void conv_fmt_u8p(int n_samples, int channels, int sample_size, float * fsamples, AVFrame * frame) {
++	int i, ch;
++	for (i = 0; i < n_samples; i++) {
++		for (ch = 0; ch < channels; ch++) {
++			*fsamples++ = (*((uint8_t*)(frame->extended_data[ch] + i*sample_size)) - 128) / 256.f;
++		}
++	}
++}
++void conv_fmt_s16p(int n_samples, int channels, int sample_size, float * fsamples, AVFrame * frame) {
++	int i, ch;
++	for (i = 0; i < n_samples; i++) {
++		for (ch = 0; ch < channels; ch++) {
++			*fsamples++ = *((int16_t*)(frame->extended_data[ch] + i*sample_size)) / 32768.f;
++		}
++	}
++}
++void conv_fmt_s32p(int n_samples, int channels, int sample_size, float * fsamples, AVFrame * frame) {
++	int i, ch;
++	for (i = 0; i < n_samples; i++) {
++		for (ch = 0; ch < channels; ch++) {
++			*fsamples++ = *((int32_t*)(frame->extended_data[ch] + i*sample_size)) / 2147483648.f;
++		}
++	}
++}
++void conv_fmt_fltp(int n_samples, int channels, int sample_size, float * fsamples, AVFrame * frame) {
++	int i, ch;
++	for (i = 0; i < n_samples; i++) {
++		for (ch = 0; ch < channels; ch++) {
++			*fsamples++ = *((float*)(frame->extended_data[ch] + i*sample_size));
++		}
++	}
++}
++void conv_fmt_dblp(int n_samples, int channels, int sample_size, float * fsamples, AVFrame * frame) {
++	int i, ch;
++	for (i = 0; i < n_samples; i++) {
++		for (ch = 0; ch < channels; ch++) {
++			*fsamples++ = *((double*)(frame->extended_data[ch] + i*sample_size));
++		}
++	}
++}
++
++/* Loosely based on avcodec_decode_audio3() implementation found at:
++ * https://raw.github.com/FFmpeg/FFmpeg/master/libavcodec/utils.c
++ */
++int decode_audio(AVCodecContext *avctx, float *fsamples, int *frame_size_ptr, AVPacket *avpkt) {
++	int ret;
++	AVFrame frame = { { 0 } };
++	int got_frame = 0;
++	
++	ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt);
++	if (ret >= 0 && got_frame) {
++		int plane_size;
++		int planar = av_sample_fmt_is_planar(avctx->sample_fmt);
++		int sample_size = av_get_bytes_per_sample(avctx->sample_fmt);
++		int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels,
++							   frame.nb_samples, avctx->sample_fmt, 1);
++		int n_samples = plane_size / sample_size;
++		if (*frame_size_ptr < data_size) {
++			av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for "
++			       "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
++			return AVERROR(EINVAL);
++		}
++
++		switch (avctx->sample_fmt) {
++		/* interleaved: */
++		case AV_SAMPLE_FMT_U8: conv_fmt_u8(n_samples, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_S16: conv_fmt_s16(n_samples, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_S32: conv_fmt_s32(n_samples, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_FLT: conv_fmt_flt(n_samples, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_DBL: conv_fmt_dbl(n_samples, sample_size, fsamples, &frame); break;
++		/* planar: */
++		case AV_SAMPLE_FMT_U8P: conv_fmt_u8p(n_samples, avctx->channels, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_S16P: conv_fmt_s16p(n_samples, avctx->channels, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_S32P: conv_fmt_s32p(n_samples, avctx->channels, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_FLTP: conv_fmt_fltp(n_samples, avctx->channels, sample_size, fsamples, &frame); break;
++		case AV_SAMPLE_FMT_DBLP: conv_fmt_dblp(n_samples, avctx->channels, sample_size, fsamples, &frame); break;
++		default:
++			fprintf(stderr, "Fatal error: dec_lavc.c: decode_audio #1: invalid sample format %s\n",
++				av_get_sample_fmt_name(avctx->sample_fmt));
++			exit(1); // no, we really don't want to handle this gracefully
++		}
++		*frame_size_ptr = planar ? n_samples * avctx->channels : n_samples;
++	} else {
++		*frame_size_ptr = 0;
++	}
++	return ret;
++}
++
+ /* return 1 if reached end of stream, 0 else */
+ int
+ decode_lavc(decoder_t * dec) {
+@@ -44,24 +166,37 @@ decode_lavc(decoder_t * dec) {
+         file_decoder_t * fdec = dec->fdec;
+ 
+ 	AVPacket packet;
+-        int16_t samples[AVCODEC_MAX_AUDIO_FRAME_SIZE];
+-        float fsamples[AVCODEC_MAX_AUDIO_FRAME_SIZE];
+-        int n_bytes = AVCODEC_MAX_AUDIO_FRAME_SIZE;
++#if LIBAVCODEC_VERSION_MAJOR < 53
++        int16_t samples[MAX_AUDIO_FRAME_SIZE];
++        int n_bytes = MAX_AUDIO_FRAME_SIZE;
++#endif /* LIBAVCODEC_VERSION_MAJOR >= 53 */
++        float fsamples[MAX_AUDIO_FRAME_SIZE];
++	int n_samples = MAX_AUDIO_FRAME_SIZE;
++	int i;
+ 
+ 	if (av_read_frame(pd->avFormatCtx, &packet) < 0)
+ 		return 1;
+ 
+-	if (packet.stream_index == pd->audioStream) {
++	if (!(packet.stream_index == pd->audioStream))
++		goto end;
+ 
+-		avcodec_decode_audio3(pd->avCodecCtx, samples, &n_bytes, &packet);
+-		if (n_bytes > 0) {
+-			int i;
+-			for (i = 0; i < n_bytes/2; i++) {
+-				fsamples[i] = samples[i] * fdec->voladj_lin / 32768.f;
+-			}
+-			rb_write(pd->rb, (char *)fsamples, n_bytes/2 * sample_size);
+-		}
++#if LIBAVCODEC_VERSION_MAJOR < 53
++	avcodec_decode_audio3(pd->avCodecCtx, samples, &n_bytes, &packet);
++	if (n_bytes <= 0) goto end;
++	n_samples = n_bytes / 2;
++	for (i = 0; i < n_samples; i++) {
++		fsamples[i] = samples[i] * fdec->voladj_lin / 32768.f;
+ 	}
++#else /* LIBAVCODEC_VERSION_MAJOR >= 53 */
++	decode_audio(pd->avCodecCtx, fsamples, &n_samples, &packet);
++	if (n_samples <= 0) goto end;
++	for (i = 0; i < n_samples; i++) {
++		fsamples[i] *= fdec->voladj_lin;
++	}
++#endif /* LIBAVCODEC_VERSION_MAJOR >= 53 */
++
++	rb_write(pd->rb, (char *)fsamples, n_samples * sample_size);
++end:
+ 	av_free_packet(&packet);
+         return 0;
+ }
+@@ -111,11 +246,23 @@ lavc_decoder_open(decoder_t * dec, char
+ 	file_decoder_t * fdec = dec->fdec;
+ 	int i;
+ 
++#if LIBAVFORMAT_VERSION_MAJOR < 53
++	if (av_open_input_file(&pd->avFormatCtx, filename, NULL, 0, NULL) != 0)
++#else /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
+ 	if (avformat_open_input(&pd->avFormatCtx, filename, NULL, NULL) != 0)
++#endif /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
++	{
+ 		return DECODER_OPEN_BADLIB;
++	}
+ 
++#if LIBAVFORMAT_VERSION_MAJOR < 53
+ 	if (av_find_stream_info(pd->avFormatCtx) < 0)
++#else /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
++	if (avformat_find_stream_info(pd->avFormatCtx, NULL) < 0)
++#endif /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
++	{
+ 		return DECODER_OPEN_BADLIB;
++	}
+ 
+ 	/* debug */
+ #ifdef LAVC_DEBUG
+@@ -133,6 +280,10 @@ lavc_decoder_open(decoder_t * dec, char
+ 		return DECODER_OPEN_BADLIB;
+ 
+ 	pd->avCodecCtx = pd->avFormatCtx->streams[pd->audioStream]->codec;
++#if LIBAVCODEC_VERSION_MAJOR >= 53
++	pd->avCodecCtx->get_buffer = avcodec_default_get_buffer;
++	pd->avCodecCtx->release_buffer = avcodec_default_release_buffer;
++#endif /* LIBAVCODEC_VERSION_MAJOR >= 53 */
+ 
+ 	pd->time_base = pd->avFormatCtx->streams[pd->audioStream]->time_base;
+ 
+@@ -140,8 +291,14 @@ lavc_decoder_open(decoder_t * dec, char
+ 	if (pd->avCodec == NULL)
+ 		return DECODER_OPEN_BADLIB;
+ 
++#if LIBAVCODEC_VERSION_MAJOR < 53
+ 	if (avcodec_open(pd->avCodecCtx, pd->avCodec) < 0)
++#else /* LIBAVCODEC_VERSION_MAJOR >= 53 */
++	if (avcodec_open2(pd->avCodecCtx, pd->avCodec, NULL) < 0)
++#endif /* LIBAVCODEC_VERSION_MAJOR >= 53 */
++	{
+ 		return DECODER_OPEN_BADLIB;
++	}
+ 
+ 	if ((pd->avCodecCtx->channels != 1) && (pd->avCodecCtx->channels != 2)) {
+ 		fprintf(stderr,
+@@ -184,7 +341,13 @@ lavc_decoder_close(decoder_t * dec) {
+ 	lavc_pdata_t * pd = (lavc_pdata_t *)dec->pdata;
+ 
+ 	avcodec_close(pd->avCodecCtx);
++
++#if LIBAVFORMAT_VERSION_MAJOR < 53
+ 	av_close_input_file(pd->avFormatCtx);
++#else /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
++	avformat_close_input(&pd->avFormatCtx);
++#endif /* LIBAVFORMAT_VERSION_MAJOR >= 53 */
++
+ 	rb_free(pd->rb);
+ }
+ 
+@@ -237,13 +400,6 @@ lavc_decoder_seek(decoder_t * dec, unsig
+ }
+ 
+ 
+-#else
+-decoder_t *
+-lavc_decoder_init(file_decoder_t * fdec) {
+-
+-	return NULL;
+-}
+-#endif /* HAVE_LAVC */
+ 
+ // vim: shiftwidth=8:tabstop=8:softtabstop=8 :  
+ 
+--- aqualung-0.9~beta11.orig/src/decoder/dec_lavc.h
++++ aqualung-0.9~beta11/src/decoder/dec_lavc.h
+@@ -50,7 +50,8 @@
+ 
+ #ifdef HAVE_LAVC
+ 
+-#define RB_LAVC_SIZE (3*AVCODEC_MAX_AUDIO_FRAME_SIZE)
++#define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio
++#define RB_LAVC_SIZE (3*MAX_AUDIO_FRAME_SIZE)
+ 
+ typedef struct _lavc_pdata_t {
+         rb_t * rb;
diff --git a/debian/patches/series b/debian/patches/series
index cfdbf2f..ccea456 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -3,3 +3,4 @@
 003-autogen.sh.dpatch
 004_missing-library.dpatch
 005_libav-0.7.dpatch
+Support-newer-lavc.patch
diff --git a/debian/rules b/debian/rules
index aa54212..e19eb4d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -17,6 +17,7 @@ DESTDIR = $(CURDIR)/debian/aqualung
 
 config.status: configure
 	dh_testdir
+	dh_autoreconf
 ifneq "$(wildcard /usr/share/misc/config.sub)" ""
 	cp -f /usr/share/misc/config.sub config.sub
 endif
@@ -44,6 +45,7 @@ clean:
 	rm -f build-stamp config.log config.guess config.sub
 	[ ! -f Makefile ] || $(MAKE) distclean
 	dh_clean
+	dh_autoreconf_clean
 
 install: build
 	dh_testdir

Reply to: