void-packages/srcpkgs/xbmc/patches/340_all_decode_audio4.patch

187 lines
9.7 KiB
Diff

commit 525834b388b3f0c7d2cece694b8893684a7715b7
Author: elupus <elupus@xbmc.org>
Date: Fri Mar 23 21:06:50 2012 +0100
Convert to avcodec_decode_audio4 and drop avcodec_decode_audio3.
diff --git a/lib/DllAvCodec.h b/lib/DllAvCodec.h
index 7993408..9a4164a 100644
--- a/lib/DllAvCodec.h
+++ b/lib/DllAvCodec.h
@@ -91,7 +91,7 @@ public:
virtual AVFrame *avcodec_alloc_frame(void)=0;
virtual int avpicture_fill(AVPicture *picture, uint8_t *ptr, PixelFormat pix_fmt, int width, int height)=0;
virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)=0;
- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt)=0;
+ virtual int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)=0;
virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)=0;
virtual int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples)=0;
virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height)=0;
@@ -160,7 +160,7 @@ public:
virtual AVFrame *avcodec_alloc_frame() { return ::avcodec_alloc_frame(); }
virtual int avpicture_fill(AVPicture *picture, uint8_t *ptr, PixelFormat pix_fmt, int width, int height) { return ::avpicture_fill(picture, ptr, pix_fmt, width, height); }
virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) { return ::avcodec_decode_video2(avctx, picture, got_picture_ptr, avpkt); }
- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt) { return ::avcodec_decode_audio3(avctx, samples, frame_size_ptr, avpkt); }
+ virtual int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt) { return ::avcodec_decode_audio4(avctx, frame, got_frame_ptr, avpkt); }
virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { return ::avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, avpkt); }
virtual int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples) { return ::avcodec_encode_audio(avctx, buf, buf_size, samples); }
virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height) { return ::avpicture_get_size(pix_fmt, width, height); }
@@ -222,7 +222,7 @@ class DllAvCodec : public DllDynamic, DllAvCodecInterface
DEFINE_FUNC_ALIGNED1(void, __cdecl, avcodec_flush_buffers, AVCodecContext*)
DEFINE_FUNC_ALIGNED3(int, __cdecl, avcodec_open2_dont_call, AVCodecContext*, AVCodec *, AVDictionary **)
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_video2, AVCodecContext*, AVFrame*, int*, AVPacket*)
- DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio3, AVCodecContext*, int16_t*, int*, AVPacket*)
+ DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio4, AVCodecContext*, AVFrame*, int*, AVPacket*)
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_subtitle2, AVCodecContext*, AVSubtitle*, int*, AVPacket*)
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_encode_audio, AVCodecContext*, uint8_t*, int, const short*)
DEFINE_FUNC_ALIGNED1(AVCodecContext*, __cdecl, avcodec_alloc_context3, AVCodec *)
@@ -272,7 +272,7 @@ class DllAvCodec : public DllDynamic, DllAvCodecInterface
RESOLVE_METHOD_RENAME(avcodec_register_all, avcodec_register_all_dont_call)
RESOLVE_METHOD(avpicture_fill)
RESOLVE_METHOD(avcodec_decode_video2)
- RESOLVE_METHOD(avcodec_decode_audio3)
+ RESOLVE_METHOD(avcodec_decode_audio4)
RESOLVE_METHOD(avcodec_decode_subtitle2)
RESOLVE_METHOD(avcodec_encode_audio)
RESOLVE_METHOD(avpicture_get_size)
diff --git a/lib/DllAvUtil.h b/lib/DllAvUtil.h
index 990317c..ad41a14 100644
--- a/lib/DllAvUtil.h
+++ b/lib/DllAvUtil.h
@@ -101,6 +101,7 @@ public:
virtual int av_get_bytes_per_sample(enum AVSampleFormat p1) = 0;
virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) = 0;
virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)=0;
+ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) = 0;
};
#if (defined USE_EXTERNAL_FFMPEG)
@@ -135,6 +136,8 @@ public:
{ return ::av_get_bytes_per_sample(p1); }
virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags){ return ::av_dict_get(m, key, prev, flags); }
virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags) { return ::av_dict_set(pm, key, value, flags); }
+ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
+ { return ::av_samples_get_buffer_size(linesize, nb_channels, nb_samples, sample_fmt, align); }
// DLL faking.
virtual bool ResolveExports() { return true; }
@@ -174,6 +177,7 @@ class DllAvUtilBase : public DllDynamic, DllAvUtilInterface
DEFINE_METHOD1(int, av_get_bytes_per_sample, (enum AVSampleFormat p1))
DEFINE_METHOD4(AVDictionaryEntry *, av_dict_get, (AVDictionary *p1, const char *p2, const AVDictionaryEntry *p3, int p4))
DEFINE_METHOD4(int, av_dict_set, (AVDictionary **p1, const char *p2, const char *p3, int p4));
+ DEFINE_METHOD5(int, av_samples_get_buffer_size, (int *p1, int p2, int p3, enum AVSampleFormat p4, int p5))
public:
BEGIN_METHOD_RESOLVE()
@@ -198,6 +202,7 @@ class DllAvUtilBase : public DllDynamic, DllAvUtilInterface
RESOLVE_METHOD(av_get_bytes_per_sample)
RESOLVE_METHOD(av_dict_get)
RESOLVE_METHOD(av_dict_set)
+ RESOLVE_METHOD(av_samples_get_buffer_size)
END_METHOD_RESOLVE()
};
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
index 2e8766e..ad8a95c 100644
--- a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp
@@ -29,10 +29,6 @@
CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec()
{
- m_iBufferSize1 = 0;
- m_pBuffer1 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16);
- memset(m_pBuffer1, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
-
m_iBufferSize2 = 0;
m_pBuffer2 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16);
memset(m_pBuffer2, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
@@ -45,11 +41,11 @@ CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec()
m_channelMap[0] = PCM_INVALID;
m_channels = 0;
m_layout = 0;
+ m_pFrame1 = NULL;
}
CDVDAudioCodecFFmpeg::~CDVDAudioCodecFFmpeg()
{
- _aligned_free(m_pBuffer1);
_aligned_free(m_pBuffer2);
Dispose();
}
@@ -103,6 +99,7 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
return false;
}
+ m_pFrame1 = m_dllAvCodec.avcodec_alloc_frame();
m_bOpenedCodec = true;
m_iSampleFormat = AV_SAMPLE_FMT_NONE;
return true;
@@ -110,6 +107,9 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options
void CDVDAudioCodecFFmpeg::Dispose()
{
+ if (m_pFrame1) m_dllAvUtil.av_free(m_pFrame1);
+ m_pFrame1 = NULL;
+
if (m_pConvert)
{
m_dllAvCodec.av_audio_convert_free(m_pConvert);
@@ -134,7 +134,7 @@ void CDVDAudioCodecFFmpeg::Dispose()
int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize)
{
- int iBytesUsed;
+ int iBytesUsed, got_frame;
if (!m_pCodecContext) return -1;
m_iBufferSize1 = AVCODEC_MAX_AUDIO_FRAME_SIZE ;
@@ -144,10 +144,13 @@ int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize)
m_dllAvCodec.av_init_packet(&avpkt);
avpkt.data = pData;
avpkt.size = iSize;
- iBytesUsed = m_dllAvCodec.avcodec_decode_audio3( m_pCodecContext
- , (int16_t*)m_pBuffer1
- , &m_iBufferSize1
+ iBytesUsed = m_dllAvCodec.avcodec_decode_audio4( m_pCodecContext
+ , m_pFrame1
+ , &got_frame
, &avpkt);
+ if (iBytesUsed < 0 || !got_frame)
+ return iBytesUsed;
+ m_iBufferSize1 = m_dllAvUtil.av_samples_get_buffer_size(NULL, m_pCodecContext->channels, m_pFrame1->nb_samples, m_pCodecContext->sample_fmt, 1);
/* some codecs will attempt to consume more data than what we gave */
if (iBytesUsed > iSize)
@@ -183,7 +186,7 @@ int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize)
return iBytesUsed;
}
- const void *ibuf[6] = { m_pBuffer1 };
+ const void *ibuf[6] = { m_pFrame1->data[0] };
void *obuf[6] = { m_pBuffer2 };
int istr[6] = { m_dllAvUtil.av_get_bytes_per_sample(m_pCodecContext->sample_fmt) };
int ostr[6] = { 2 };
@@ -207,7 +210,7 @@ int CDVDAudioCodecFFmpeg::GetData(BYTE** dst)
{
if(m_iBufferSize1)
{
- *dst = m_pBuffer1;
+ *dst = m_pFrame1->data[0];
return m_iBufferSize1;
}
if(m_iBufferSize2)
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h
index 0446213..4c01499 100644
--- a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h
@@ -50,7 +50,7 @@ protected:
enum AVSampleFormat m_iSampleFormat;
enum PCMChannels m_channelMap[PCM_MAX_CH + 1];
- BYTE *m_pBuffer1;
+ AVFrame* m_pFrame1;
int m_iBufferSize1;
BYTE *m_pBuffer2;