Browse Source

Update audio_decoder

tags/1.9.4
falkTX 11 years ago
parent
commit
ec922922ac
4 changed files with 40 additions and 16 deletions
  1. +14
    -6
      source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c
  2. +4
    -3
      source/modules/daz-plugins/audio_decoder/ad_plugin.c
  3. +6
    -5
      source/modules/daz-plugins/audio_decoder/ad_soundfile.c
  4. +16
    -2
      source/modules/daz-plugins/audio_decoder/ffcompat.h

+ 14
- 6
source/modules/daz-plugins/audio_decoder/ad_ffmpeg.c View File

@@ -23,7 +23,7 @@
#include <unistd.h>
#include <math.h>

#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) {


+ 4
- 3
source/modules/daz-plugins/audio_decoder/ad_plugin.c View File

@@ -16,6 +16,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

*/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -23,7 +24,7 @@
#include <unistd.h>
#include <math.h>

#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;
}




+ 6
- 5
source/modules/daz-plugins/audio_decoder/ad_soundfile.c View File

@@ -16,6 +16,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,7 +25,7 @@
#include <math.h>
#include <sndfile.h>

#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) {


+ 16
- 2
source/modules/daz-plugins/audio_decoder/ffcompat.h View File

@@ -1,6 +1,6 @@
/* ffmpeg compatibility wrappers
*
* Copyright 2012 Robin Gareus <robin@gareus.org>
* Copyright 2012,2013 Robin Gareus <robin@gareus.org>
*
* 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 <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>

#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 */

Loading…
Cancel
Save