From ec922922ac6053594ba235e8c1515576947e2fe4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 2 Feb 2014 08:29:32 +0000 Subject: [PATCH] Update audio_decoder --- .../daz-plugins/audio_decoder/ad_ffmpeg.c | 20 +++++++++++++------ .../daz-plugins/audio_decoder/ad_plugin.c | 7 ++++--- .../daz-plugins/audio_decoder/ad_soundfile.c | 11 +++++----- .../daz-plugins/audio_decoder/ffcompat.h | 18 +++++++++++++++-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c b/source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c index b54697b24..fd28a06ec 100644 --- a/source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c +++ b/source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c @@ -23,7 +23,7 @@ #include #include -#include "audio_decoder/ad_plugin.h" +#include "ad_plugin.h" #ifdef HAVE_FFMPEG @@ -215,16 +215,24 @@ static ssize_t ad_read_ffmpeg(void *sf, float* d, size_t len) { /* decode all chunks in packet */ int data_size= AVCODEC_MAX_AUDIO_FRAME_SIZE; -#if 0 // TODO ffcompat.h -- this works but is not optimal (channels may not be planar/interleaved) - AVFrame avf; // TODO statically allocate + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 0, 0) + /* This works but is not optimal (channels may not be planar/interleaved) */ + AVFrame avf; // TODO statically allocate as poart of priv->.. memset(&avf, 0, sizeof(AVFrame)); // not sure if that is needed int got_frame = 0; -ret = avcodec_decode_audio4(priv->codecContext, &avf, &got_frame, &priv->packet); + ret = avcodec_decode_audio4(priv->codecContext, &avf, &got_frame, &priv->packet); data_size = avf.linesize[0]; memcpy(priv->m_tmpBuffer, avf.data[0], avf.linesize[0] * sizeof(uint8_t)); -#else // this was deprecated in LIBAVCODEC_VERSION_MAJOR 53 - ret = avcodec_decode_audio3(priv->codecContext, +#elif LIBAVUTIL_VERSION_INT > AV_VERSION_INT(49, 15, 0) && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(52, 20, 1) // ?? + // this was deprecated in LIBAVCODEC_VERSION_MAJOR 53 + ret = avcodec_decode_audio3(priv->codecContext, priv->m_tmpBuffer, &data_size, &priv->packet); +#else + int len = priv->packet.size; + uint8_t *ptr = priv->packet.data; + ret = avcodec_decode_audio2(priv->codecContext, + priv->m_tmpBuffer, &data_size, ptr, len); #endif if (ret < 0 || ret > priv->pkt_len) { diff --git a/source/modules/daz-plugins/audio_decoder/ad_plugin.c b/source/modules/daz-plugins/audio_decoder/ad_plugin.c index addf94a42..92a251bbc 100644 --- a/source/modules/daz-plugins/audio_decoder/ad_plugin.c +++ b/source/modules/daz-plugins/audio_decoder/ad_plugin.c @@ -16,6 +16,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #include #include #include @@ -23,7 +24,7 @@ #include #include -#include "audio_decoder/ad_plugin.h" +#include "ad_plugin.h" int ad_debug_level = 0; @@ -118,7 +119,7 @@ ssize_t ad_read_mono_dbl(void *sf, struct adinfo *nfo, double* d, size_t len){ buf = (float*) realloc((void*)buf, bufsiz * sizeof(float)); } - len = (size_t)ad_read(sf, buf, bufsiz); + len = ad_read(sf, buf, bufsiz); for (f=0;f< (len/chn);f++) { double val=0.0; @@ -127,7 +128,7 @@ ssize_t ad_read_mono_dbl(void *sf, struct adinfo *nfo, double* d, size_t len){ } d[f]= val/chn; } - return (ssize_t)len/chn; + return len/chn; } diff --git a/source/modules/daz-plugins/audio_decoder/ad_soundfile.c b/source/modules/daz-plugins/audio_decoder/ad_soundfile.c index db90ba3dc..a140da78d 100644 --- a/source/modules/daz-plugins/audio_decoder/ad_soundfile.c +++ b/source/modules/daz-plugins/audio_decoder/ad_soundfile.c @@ -16,6 +16,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + #include #include #include @@ -24,7 +25,7 @@ #include #include -#include "audio_decoder/ad_plugin.h" +#include "ad_plugin.h" /* internal abstraction */ @@ -52,12 +53,12 @@ static int ad_info_sndfile(void *sf, struct adinfo *nfo) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; if (nfo) { - nfo->channels = (unsigned int)priv->sfinfo.channels; + nfo->channels = priv->sfinfo.channels; nfo->frames = priv->sfinfo.frames; - nfo->sample_rate = (unsigned int)priv->sfinfo.samplerate; + nfo->sample_rate = priv->sfinfo.samplerate; nfo->length = priv->sfinfo.samplerate ? (priv->sfinfo.frames * 1000) / priv->sfinfo.samplerate : 0; nfo->bit_depth = parse_bit_depth(priv->sfinfo.format); - nfo->bit_rate = nfo->bit_depth * priv->sfinfo.channels * priv->sfinfo.samplerate; + nfo->bit_rate = nfo->bit_depth * nfo->channels * nfo->sample_rate; nfo->meta_data = NULL; } return 0; @@ -98,7 +99,7 @@ static int64_t ad_seek_sndfile(void *sf, int64_t pos) { static ssize_t ad_read_sndfile(void *sf, float* d, size_t len) { sndfile_audio_decoder *priv = (sndfile_audio_decoder*) sf; if (!priv) return -1; - return sf_read_float (priv->sffile, d, (sf_count_t)len); + return sf_read_float (priv->sffile, d, len); } static int ad_eval_sndfile(const char *f) { diff --git a/source/modules/daz-plugins/audio_decoder/ffcompat.h b/source/modules/daz-plugins/audio_decoder/ffcompat.h index 06286272f..3614af069 100644 --- a/source/modules/daz-plugins/audio_decoder/ffcompat.h +++ b/source/modules/daz-plugins/audio_decoder/ffcompat.h @@ -1,6 +1,6 @@ /* ffmpeg compatibility wrappers * - * Copyright 2012 Robin Gareus + * Copyright 2012,2013 Robin Gareus * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,15 +26,27 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef FFCOMPAT_H +#define FFCOMPAT_H + #include #include +#include + +#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE +#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 +#endif + +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(50, 0, 0) +#define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO +#endif #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53, 2, 0) static inline int avformat_open_input(AVFormatContext **ps, const char *filename, void *fmt, void **options) { return av_open_input_file(ps, filename, NULL, 0, NULL); } -#endif +#endif /* avformat < 53.2.0 */ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53, 5, 0) static inline AVCodecContext * @@ -79,3 +91,5 @@ avformat_close_input(AVFormatContext **s) } #endif /* < 53.5.0 */ + +#endif /* FFCOMPAT_H */