1 |
From 6565d85b02f823b74109558c8e708a7aa537f7d0 Mon Sep 17 00:00:00 2001 |
2 |
From: elupus <elupus@xbmc.org> |
3 |
Date: Fri, 23 Mar 2012 21:06:50 +0100 |
4 |
Subject: [PATCH 134/145] Convert to avcodec_decode_audio4 and drop |
5 |
avcodec_decode_audio3. (cherry picked from commit |
6 |
525834b388b3f0c7d2cece694b8893684a7715b7) |
7 |
|
8 |
--- |
9 |
lib/DllAvCodec.h | 8 +++---- |
10 |
lib/DllAvUtil.h | 5 ++++ |
11 |
.../DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp | 25 +++++++++++--------- |
12 |
.../DVDCodecs/Audio/DVDAudioCodecFFmpeg.h | 2 +- |
13 |
4 files changed, 24 insertions(+), 16 deletions(-) |
14 |
|
15 |
diff --git a/lib/DllAvCodec.h b/lib/DllAvCodec.h |
16 |
index 7993408..9a4164a 100644 |
17 |
--- a/lib/DllAvCodec.h |
18 |
+++ b/lib/DllAvCodec.h |
19 |
@@ -91,7 +91,7 @@ public: |
20 |
virtual AVFrame *avcodec_alloc_frame(void)=0; |
21 |
virtual int avpicture_fill(AVPicture *picture, uint8_t *ptr, PixelFormat pix_fmt, int width, int height)=0; |
22 |
virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)=0; |
23 |
- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt)=0; |
24 |
+ virtual int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)=0; |
25 |
virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)=0; |
26 |
virtual int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples)=0; |
27 |
virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height)=0; |
28 |
@@ -160,7 +160,7 @@ public: |
29 |
virtual AVFrame *avcodec_alloc_frame() { return ::avcodec_alloc_frame(); } |
30 |
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); } |
31 |
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); } |
32 |
- 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); } |
33 |
+ 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); } |
34 |
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); } |
35 |
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); } |
36 |
virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height) { return ::avpicture_get_size(pix_fmt, width, height); } |
37 |
@@ -222,7 +222,7 @@ class DllAvCodec : public DllDynamic, DllAvCodecInterface |
38 |
DEFINE_FUNC_ALIGNED1(void, __cdecl, avcodec_flush_buffers, AVCodecContext*) |
39 |
DEFINE_FUNC_ALIGNED3(int, __cdecl, avcodec_open2_dont_call, AVCodecContext*, AVCodec *, AVDictionary **) |
40 |
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_video2, AVCodecContext*, AVFrame*, int*, AVPacket*) |
41 |
- DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio3, AVCodecContext*, int16_t*, int*, AVPacket*) |
42 |
+ DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio4, AVCodecContext*, AVFrame*, int*, AVPacket*) |
43 |
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_subtitle2, AVCodecContext*, AVSubtitle*, int*, AVPacket*) |
44 |
DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_encode_audio, AVCodecContext*, uint8_t*, int, const short*) |
45 |
DEFINE_FUNC_ALIGNED1(AVCodecContext*, __cdecl, avcodec_alloc_context3, AVCodec *) |
46 |
@@ -272,7 +272,7 @@ class DllAvCodec : public DllDynamic, DllAvCodecInterface |
47 |
RESOLVE_METHOD_RENAME(avcodec_register_all, avcodec_register_all_dont_call) |
48 |
RESOLVE_METHOD(avpicture_fill) |
49 |
RESOLVE_METHOD(avcodec_decode_video2) |
50 |
- RESOLVE_METHOD(avcodec_decode_audio3) |
51 |
+ RESOLVE_METHOD(avcodec_decode_audio4) |
52 |
RESOLVE_METHOD(avcodec_decode_subtitle2) |
53 |
RESOLVE_METHOD(avcodec_encode_audio) |
54 |
RESOLVE_METHOD(avpicture_get_size) |
55 |
diff --git a/lib/DllAvUtil.h b/lib/DllAvUtil.h |
56 |
index 990317c..ad41a14 100644 |
57 |
--- a/lib/DllAvUtil.h |
58 |
+++ b/lib/DllAvUtil.h |
59 |
@@ -101,6 +101,7 @@ public: |
60 |
virtual int av_get_bytes_per_sample(enum AVSampleFormat p1) = 0; |
61 |
virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) = 0; |
62 |
virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)=0; |
63 |
+ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) = 0; |
64 |
}; |
65 |
|
66 |
#if (defined USE_EXTERNAL_FFMPEG) |
67 |
@@ -135,6 +136,8 @@ public: |
68 |
{ return ::av_get_bytes_per_sample(p1); } |
69 |
virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags){ return ::av_dict_get(m, key, prev, flags); } |
70 |
virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags) { return ::av_dict_set(pm, key, value, flags); } |
71 |
+ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) |
72 |
+ { return ::av_samples_get_buffer_size(linesize, nb_channels, nb_samples, sample_fmt, align); } |
73 |
|
74 |
// DLL faking. |
75 |
virtual bool ResolveExports() { return true; } |
76 |
@@ -174,6 +177,7 @@ class DllAvUtilBase : public DllDynamic, DllAvUtilInterface |
77 |
DEFINE_METHOD1(int, av_get_bytes_per_sample, (enum AVSampleFormat p1)) |
78 |
DEFINE_METHOD4(AVDictionaryEntry *, av_dict_get, (AVDictionary *p1, const char *p2, const AVDictionaryEntry *p3, int p4)) |
79 |
DEFINE_METHOD4(int, av_dict_set, (AVDictionary **p1, const char *p2, const char *p3, int p4)); |
80 |
+ DEFINE_METHOD5(int, av_samples_get_buffer_size, (int *p1, int p2, int p3, enum AVSampleFormat p4, int p5)) |
81 |
|
82 |
public: |
83 |
BEGIN_METHOD_RESOLVE() |
84 |
@@ -198,6 +202,7 @@ class DllAvUtilBase : public DllDynamic, DllAvUtilInterface |
85 |
RESOLVE_METHOD(av_get_bytes_per_sample) |
86 |
RESOLVE_METHOD(av_dict_get) |
87 |
RESOLVE_METHOD(av_dict_set) |
88 |
+ RESOLVE_METHOD(av_samples_get_buffer_size) |
89 |
END_METHOD_RESOLVE() |
90 |
}; |
91 |
|
92 |
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp |
93 |
index 2e8766e..ad8a95c 100644 |
94 |
--- a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp |
95 |
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp |
96 |
@@ -29,10 +29,6 @@ |
97 |
|
98 |
CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec() |
99 |
{ |
100 |
- m_iBufferSize1 = 0; |
101 |
- m_pBuffer1 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16); |
102 |
- memset(m_pBuffer1, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); |
103 |
- |
104 |
m_iBufferSize2 = 0; |
105 |
m_pBuffer2 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16); |
106 |
memset(m_pBuffer2, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); |
107 |
@@ -45,11 +41,11 @@ CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec() |
108 |
m_channelMap[0] = PCM_INVALID; |
109 |
m_channels = 0; |
110 |
m_layout = 0; |
111 |
+ m_pFrame1 = NULL; |
112 |
} |
113 |
|
114 |
CDVDAudioCodecFFmpeg::~CDVDAudioCodecFFmpeg() |
115 |
{ |
116 |
- _aligned_free(m_pBuffer1); |
117 |
_aligned_free(m_pBuffer2); |
118 |
Dispose(); |
119 |
} |
120 |
@@ -103,6 +99,7 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options |
121 |
return false; |
122 |
} |
123 |
|
124 |
+ m_pFrame1 = m_dllAvCodec.avcodec_alloc_frame(); |
125 |
m_bOpenedCodec = true; |
126 |
m_iSampleFormat = AV_SAMPLE_FMT_NONE; |
127 |
return true; |
128 |
@@ -110,6 +107,9 @@ bool CDVDAudioCodecFFmpeg::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options |
129 |
|
130 |
void CDVDAudioCodecFFmpeg::Dispose() |
131 |
{ |
132 |
+ if (m_pFrame1) m_dllAvUtil.av_free(m_pFrame1); |
133 |
+ m_pFrame1 = NULL; |
134 |
+ |
135 |
if (m_pConvert) |
136 |
{ |
137 |
m_dllAvCodec.av_audio_convert_free(m_pConvert); |
138 |
@@ -134,7 +134,7 @@ void CDVDAudioCodecFFmpeg::Dispose() |
139 |
|
140 |
int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize) |
141 |
{ |
142 |
- int iBytesUsed; |
143 |
+ int iBytesUsed, got_frame; |
144 |
if (!m_pCodecContext) return -1; |
145 |
|
146 |
m_iBufferSize1 = AVCODEC_MAX_AUDIO_FRAME_SIZE ; |
147 |
@@ -144,10 +144,13 @@ int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize) |
148 |
m_dllAvCodec.av_init_packet(&avpkt); |
149 |
avpkt.data = pData; |
150 |
avpkt.size = iSize; |
151 |
- iBytesUsed = m_dllAvCodec.avcodec_decode_audio3( m_pCodecContext |
152 |
- , (int16_t*)m_pBuffer1 |
153 |
- , &m_iBufferSize1 |
154 |
+ iBytesUsed = m_dllAvCodec.avcodec_decode_audio4( m_pCodecContext |
155 |
+ , m_pFrame1 |
156 |
+ , &got_frame |
157 |
, &avpkt); |
158 |
+ if (iBytesUsed < 0 || !got_frame) |
159 |
+ return iBytesUsed; |
160 |
+ m_iBufferSize1 = m_dllAvUtil.av_samples_get_buffer_size(NULL, m_pCodecContext->channels, m_pFrame1->nb_samples, m_pCodecContext->sample_fmt, 1); |
161 |
|
162 |
/* some codecs will attempt to consume more data than what we gave */ |
163 |
if (iBytesUsed > iSize) |
164 |
@@ -183,7 +186,7 @@ int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize) |
165 |
return iBytesUsed; |
166 |
} |
167 |
|
168 |
- const void *ibuf[6] = { m_pBuffer1 }; |
169 |
+ const void *ibuf[6] = { m_pFrame1->data[0] }; |
170 |
void *obuf[6] = { m_pBuffer2 }; |
171 |
int istr[6] = { m_dllAvUtil.av_get_bytes_per_sample(m_pCodecContext->sample_fmt) }; |
172 |
int ostr[6] = { 2 }; |
173 |
@@ -207,7 +210,7 @@ int CDVDAudioCodecFFmpeg::GetData(BYTE** dst) |
174 |
{ |
175 |
if(m_iBufferSize1) |
176 |
{ |
177 |
- *dst = m_pBuffer1; |
178 |
+ *dst = m_pFrame1->data[0]; |
179 |
return m_iBufferSize1; |
180 |
} |
181 |
if(m_iBufferSize2) |
182 |
diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h |
183 |
index 0446213..4c01499 100644 |
184 |
--- a/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h |
185 |
+++ b/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h |
186 |
@@ -50,7 +50,7 @@ protected: |
187 |
enum AVSampleFormat m_iSampleFormat; |
188 |
enum PCMChannels m_channelMap[PCM_MAX_CH + 1]; |
189 |
|
190 |
- BYTE *m_pBuffer1; |
191 |
+ AVFrame* m_pFrame1; |
192 |
int m_iBufferSize1; |
193 |
|
194 |
BYTE *m_pBuffer2; |
195 |
-- |
196 |
1.7.10 |
197 |
|