Ticket #8382: Faad2.Patch

File Faad2.Patch, 8.1 KB (added by psgman24@…, 15 years ago)

First patch for mplayer (libfaad)

Line 
1Index: libmpcodecs/ad_faad.c
2===================================================================
3--- libmpcodecs/ad_faad.c (リビゞョン 29813)
4+++ libmpcodecs/ad_faad.c (䜜業コピヌ)
5@@ -296,6 +296,17 @@
6 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%ld Bytes)!\n",
7 sh->samplesize*faac_finfo.samples);
8
9+ if (sh->channels != faac_finfo.channels)
10+ {
11+ mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "FAAD: changed the number of channels(to %d)\n", faac_finfo.channels);
12+ sh->channels = faac_finfo.channels;
13+ }
14+ if (sh->samplerate != faac_finfo.samplerate)
15+ {
16+ mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "FAAD: changed the sampling rate(to %lu)\n", faac_finfo.samplerate);
17+ sh->samplerate = faac_finfo.samplerate;
18+ }
19+
20 if (sh->channels >= 5)
21 reorder_channel_copy_nch(faac_sample_buffer,
22 AF_CHANNEL_LAYOUT_AAC_DEFAULT,
23Index: libfaad2/decoder.c
24===================================================================
25--- libfaad2/decoder.c (リビゞョン 29813)
26+++ libfaad2/decoder.c (䜜業コピヌ)
27@@ -252,7 +252,7 @@
28 {
29 int32_t x;
30 hDecoder->latm_header_present = 1;
31- x = NeAACDecInit2(hDecoder, &l->ASC, (l->ASCbits+7)/8, samplerate, channels);
32+ x = NeAACDecInit2(hDecoder, l->ASC, (l->ASCbits+7)/8, samplerate, channels);
33 if(x!=0)
34 hDecoder->latm_header_present = 0;
35 return x;
36@@ -300,7 +300,6 @@
37 }
38 faad_endbits(&ld);
39 }
40- hDecoder->channelConfiguration = *channels;
41
42 #if (defined(PS_DEC) || defined(DRM_PS))
43 /* check if we have a mono file */
44@@ -311,6 +310,8 @@
45 }
46 #endif
47
48+ hDecoder->channelConfiguration = *channels;
49+
50 #ifdef SBR_DEC
51 /* implicit signalling */
52 if (*samplerate <= 24000 && !(hDecoder->config.dontUpSampleImplicitSBR))
53@@ -568,8 +569,14 @@
54 chdir = hInfo->num_front_channels;
55 if (chdir & 1)
56 {
57+#if (defined(PS_DEC) || defined(DRM_PS))
58+ /* When PS is enabled output is always stereo */
59+ hInfo->channel_position[chpos++] = FRONT_CHANNEL_LEFT;
60+ hInfo->channel_position[chpos++] = FRONT_CHANNEL_RIGHT;
61+#else
62 hInfo->channel_position[chpos++] = FRONT_CHANNEL_CENTER;
63 chdir--;
64+#endif
65 }
66 for (i = 0; i < chdir; i += 2)
67 {
68@@ -608,8 +615,15 @@
69 switch (hDecoder->channelConfiguration)
70 {
71 case 1:
72+#if (defined(PS_DEC) || defined(DRM_PS))
73+ hInfo->num_front_channels = 2;
74+ /* When PS is enabled output is always stereo */
75+ hInfo->channel_position[0] = FRONT_CHANNEL_LEFT;
76+ hInfo->channel_position[1] = FRONT_CHANNEL_RIGHT;
77+#else
78 hInfo->num_front_channels = 1;
79 hInfo->channel_position[0] = FRONT_CHANNEL_CENTER;
80+#endif
81 break;
82 case 2:
83 hInfo->num_front_channels = 2;
84@@ -852,6 +866,16 @@
85 if ((hInfo->error = adts_frame(&adts, &ld)) > 0)
86 goto error;
87
88+ if (adts.channel_configuration != hDecoder->fr_channels)
89+ {
90+ //hDecoder->postSeekResetFlag = 1;
91+ //hDecoder->pce_set = 0;
92+ //memset(hDecoder->element_id, 0, sizeof(hDecoder->element_id));
93+ memset(hDecoder->element_output_channels, 0,
94+ sizeof(hDecoder->element_output_channels));
95+ memset(hDecoder->element_alloced, 0,
96+ sizeof(hDecoder->element_alloced));
97+ }
98 /* MPEG2 does byte_alignment() here,
99 * but ADTS header is always multiple of 8 bits in MPEG2
100 * so not needed to actually do it.
101@@ -938,6 +962,8 @@
102 output_channels = 2;
103 }
104 #endif
105+ if (hDecoder->adts_header_present || hDecoder->adif_header_present)
106+ hDecoder->channelConfiguration = output_channels;
107
108 /* Make a channel configuration based on either a PCE or a channelConfiguration */
109 create_channel_config(hDecoder, hInfo);
110@@ -963,6 +989,7 @@
111 #if (defined(PS_DEC) || defined(DRM_PS))
112 hInfo->ps = hDecoder->ps_used_global;
113 #endif
114+//{fprintf(stderr, "chconfig:%d fr-ch:%d hI-ch:%d elm_out[0]:%d alloced:%d up:%d ps:%d\n", hDecoder->channelConfiguration, hDecoder->fr_channels, hInfo->channels, hDecoder->element_output_channels[0], hDecoder->alloced_channels, hDecoder->upMatrix, hDecoder->ps_used[0]);}
115
116 /* check if frame has channel elements */
117 if (channels == 0)
118--- libfaad2/output.c (リビゞョン 29813)
119+++ libfaad2/output.c (䜜業コピヌ)
120@@ -104,6 +104,7 @@
121 }
122 break;
123 case CONV(2,0):
124+ case CONV(2,1):
125 if (hDecoder->upMatrix)
126 {
127 ch = hDecoder->internal_channel[0];
128@@ -569,6 +570,19 @@
129 if (format != FAAD_FMT_16BIT)
130 return output_to_PCM_sux(hDecoder, input, sample_buffer, channels, frame_len, format);
131
132+ if (hDecoder->upMatrix) {
133+ for(i = 0; i < frame_len; i++)
134+ {
135+ int32_t tmp = input[hDecoder->internal_channel[0]][i];
136+ tmp += (1 << (REAL_BITS-1));
137+ tmp >>= REAL_BITS;
138+ if ((tmp+0x8000) & ~0xffff) tmp = ~(tmp>>31)-0x8000;
139+ for (ch = 0; ch < channels; ch++)
140+ *(short_sample_buffer++) = tmp;
141+ }
142+ return sample_buffer;
143+ }
144+
145 if (hDecoder->downMatrix) {
146 for(i = 0; i < frame_len; i++)
147 {
148Index: libfaad2/specrec.c
149===================================================================
150--- libfaad2/specrec.c (リビゞョン 29813)
151+++ libfaad2/specrec.c (䜜業コピヌ)
152@@ -847,9 +847,31 @@
153 output_channels = 1;
154 #endif
155
156+/*
157 if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0 ||
158 hDecoder->element_output_channels[hDecoder->fr_ch_ele] < output_channels) {
159 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
160+*/
161+ if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0)
162+ {
163+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
164+ } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) {
165+ /* element inconsistency */
166+
167+ /* this only happens if PS is actually found but not in the first frame
168+ * this means that there is only 1 bitstream element!
169+ */
170+
171+ /* reset the allocation */
172+ hDecoder->element_alloced[hDecoder->fr_ch_ele] = 0;
173+
174+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
175+
176+ //return 21;
177+ }
178+
179+ if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0)
180+ {
181 retval = allocate_single_channel(hDecoder, sce->channel, output_channels);
182 if (retval > 0)
183 return retval;
184@@ -995,10 +1017,12 @@
185 {
186 return 23;
187 }
188+#endif
189
190 /* copy L to R when no PS is used */
191 #if (defined(PS_DEC) || defined(DRM_PS))
192- if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0) && (output_channels == 2))
193+ if ((hDecoder->ps_used[hDecoder->fr_ch_ele] == 0) &&
194+ (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2))
195 {
196 uint8_t ele = hDecoder->fr_ch_ele;
197 uint8_t ch = sce->channel;
198@@ -1008,7 +1032,6 @@
199 memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size);
200 }
201 #endif
202-#endif
203
204 return 0;
205 }
206Index: libfaad2/syntax.c
207===================================================================
208--- libfaad2/syntax.c (リビゞョン 29813)
209+++ libfaad2/syntax.c (䜜業コピヌ)
210@@ -1514,6 +1514,7 @@
211 if ((result = rvlc_decode_scale_factors(ics, ld)) > 0)
212 return result;
213 }
214+#endif
215
216 if (hDecoder->object_type >= ER_OBJECT_START)
217 {
218@@ -1528,6 +1529,7 @@
219 return result;
220 #endif
221
222+#ifdef ERROR_RESILIENCE
223 if (hDecoder->aacSpectralDataResilienceFlag)
224 {
225 /* error resilient spectral data decoding */
226@@ -2128,7 +2130,7 @@
227 n++;
228 drc->num_bands += band_incr;
229
230- for (i = 0; i < drc->num_bands; i++);
231+ for (i = 0; i < drc->num_bands; i++)
232 {
233 drc->band_top[i] = (uint8_t)faad_getbits(ld, 8
234 DEBUGVAR(1,97,"dynamic_range_info(): band_top"));