Ticket #8382: Faad2-1.Patch

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

Second patch for mplayer (libfaad)

Line 
1Index: libfaad2/decoder.c
2===================================================================
3--- libfaad2/decoder.c  (リビゞョン 29813)
4+++ libfaad2/decoder.c  (䜜業コピヌ)
5@@ -289,7 +289,8 @@
6             hDecoder->object_type = adts.profile + 1;
7 
8             *samplerate = get_sample_rate(hDecoder->sf_index);
9-            *channels = (adts.channel_configuration > 6) ?
10+            *channels = (adts.channel_configuration > 6 ||
11+                         adts.channel_configuration == 0) ?
12                 2 : adts.channel_configuration;
13         }
14 
15@@ -866,6 +867,13 @@
16         if ((hInfo->error = adts_frame(&adts, &ld)) > 0)
17             goto error;
18 
19+        /* ADTS.ch_config is set to 0 when dual-mono, 2-2, 2-1 in ISDB.
20+           FIXME: but always assume dual-mono to avoid parsing PCE.
21+                  (use of 2-2, 2-1 config is discouraged anyway. )
22+         */   
23+        if (adts.channel_configuration == 0)
24+            adts.channel_configuration = 2;
25+
26         if (adts.channel_configuration != hDecoder->fr_channels)
27         {
28             //hDecoder->postSeekResetFlag = 1;
29@@ -967,6 +975,9 @@
30 
31     /* Make a channel configuration based on either a PCE or a channelConfiguration */
32     create_channel_config(hDecoder, hInfo);
33+    // restore hInfo->pce_set which was increased by "in-stream" PCE
34+    if (hDecoder->pce_set >= 2)
35+        hDecoder->pce_set -= 2;
36 
37     /* number of samples in this frame */
38     hInfo->samples = frame_len*output_channels;
39@@ -1107,6 +1118,9 @@
40     return sample_buffer;
41 
42 error:
43+    // restore hInfo->pce_set which was increased by "in-stream" PCE
44+    if (hDecoder->pce_set >= 2)
45+        hDecoder->pce_set -= 2;
46 
47     faad_endbits(&ld);
48 
49Index: libfaad2/syntax.c
50===================================================================
51--- libfaad2/syntax.c   (リビゞョン 29813)
52+++ libfaad2/syntax.c   (䜜業コピヌ)
53@@ -462,10 +462,12 @@
54             case ID_PCE:
55                 /* 14496-4: 5.6.4.1.2.1.3: */
56                 /* program_configuration_element()'s in access units shall be ignored */
57-                program_config_element(pce, ld);
58-                //if ((hInfo->error = program_config_element(pce, ld)) > 0)
59-                //    return;
60-                //hDecoder->pce_set = 1;
61+                // modified by 0p1pp1, for dual-mono etc. in ISDB-T/S
62+                // see ARB-STD-B32 ...
63+                // program_config_element(pce, ld);
64+                if ((hInfo->error = program_config_element(pce, ld)) > 0)
65+                    return;
66+                hDecoder->pce_set += 2; // will be restored later
67                 break;
68             case ID_FIL:
69                 /* one sbr_info describes a channel_element not a channel! */
70Index: libmpcodecs/ad_faad.c
71===================================================================
72--- libmpcodecs/ad_faad.c       (リビゞョン 29813)
73+++ libmpcodecs/ad_faad.c       (䜜業コピヌ)
74@@ -145,6 +145,10 @@
75     sh->a_in_buffer_len -= (faac_init > 0)?faac_init:0; // how many bytes init consumed
76     // XXX FIXME: shouldn't we memcpy() here in a_in_buffer ?? --A'rpi
77 
78+    if(faac_channels <= 2) { // fix nch for later config changes (to 5.1ch)
79+      faac_conf->downMatrix = 1;
80+      faacDecSetConfiguration(faac_hdec, faac_conf);
81+    }
82   } else { // We have ES DS in codecdata
83     faacDecConfigurationPtr faac_conf = faacDecGetCurrentConfiguration(faac_hdec);
84     if (audio_output_channels <= 2) {
85@@ -296,16 +300,17 @@
86       mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FAAD: Successfully decoded frame (%ld Bytes)!\n",
87       sh->samplesize*faac_finfo.samples);
88 
89-      if (sh->channels != faac_finfo.channels)
90+      if (sh->channels != faac_finfo.channels ||
91+          sh->samplerate != faac_finfo.samplerate)
92       {
93-          mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "FAAD: changed the number of channels(to %d)\n", faac_finfo.channels);
94+          mp_msg(MSGT_DECAUDIO, MSGL_INFO, "FAAD: changed audio configuration to (%dch, %ldHz)\n", faac_finfo.channels, faac_finfo.samplerate);
95           sh->channels = faac_finfo.channels;
96-      }
97-      if (sh->samplerate != faac_finfo.samplerate)
98-      {
99-          mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "FAAD: changed the sampling rate(to %lu)\n", faac_finfo.samplerate);
100           sh->samplerate = faac_finfo.samplerate;
101+          //sh->o_bps will be updated later in fill_audio_out_buffers()
102+          sh->reconfig = 1;
103+          return len;
104       }
105+      sh->reconfig = 0;
106 
107       if (sh->channels >= 5)
108         reorder_channel_copy_nch(faac_sample_buffer,Index: libmpcodecs/dec_audio.c
109===================================================================
110--- libmpcodecs/dec_audio.c     (リビゞョン 29813)
111+++ libmpcodecs/dec_audio.c     (䜜業コピヌ)
112@@ -370,7 +370,7 @@
113        int minlen = len - sh->a_buffer_len;
114        int maxlen = sh->a_buffer_size - sh->a_buffer_len;
115        int ret = sh->ad_driver->decode_audio(sh, buf, minlen, maxlen);
116-       if (ret <= 0) {
117+       if (ret <= 0 || sh->reconfig) {
118            error = -1;
119            len = sh->a_buffer_len;
120            break;
121Index: libmpdemux/stheader.h
122===================================================================
123--- libmpdemux/stheader.h       (リビゞョン 29813)
124+++ libmpdemux/stheader.h       (䜜業コピヌ)
125@@ -70,6 +70,7 @@
126   int pts_bytes; // bytes output by decoder after last known pts
127   char* lang; // track language
128   int default_track;
129+  int reconfig; // whether to re-configure audio filter at the next iteration
130 } sh_audio_t;
131 
132 typedef struct {
133Index: mencoder.c
134===================================================================
135--- mencoder.c  (リビゞョン 29813)
136+++ mencoder.c  (䜜業コピヌ)
137@@ -320,6 +320,13 @@
138 
139 //---------------------------------------------------------------------------
140 
141+// Needed for reconfiguring audio stream
142+static struct {
143+    int new_srate;
144+    muxer_stream_t *mux_a;
145+    audio_encoder_t *aencoder;
146+} reconf_data;
147+
148 static int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){
149     int size=0;
150     int at_eof=0;
151@@ -327,6 +334,21 @@
152        int len=total-size;
153                if(len>MAX_OUTBURST) len=MAX_OUTBURST;
154                if (decode_audio(sh_audio, len) < 0) at_eof=1;
155+               if (sh_audio->reconfig) {
156+                       int out_srate = reconf_data.mux_a->wf->nSamplesPerSec;
157+                       int out_channels = reconf_data.mux_a->wf->nChannels;
158+                       int out_format = reconf_data.aencoder->input_format;
159+                       if (!init_audio_filters(sh_audio, reconf_data.new_srate,
160+                                               &out_srate, &out_channels,
161+                                               &out_format)) {
162+                               mp_msg(MSGT_CPLAYER, MSGL_FATAL,
163+                                      MSGTR_NoMatchingFilter);
164+                               mencoder_exit(1, NULL);
165+                       }
166+                       reconf_data.mux_a->wf->nSamplesPerSec = out_srate;
167+                       reconf_data.mux_a->wf->nChannels = out_channels;
168+                       at_eof = 0;
169+               }
170                if(len>sh_audio->a_out_buffer_len) len=sh_audio->a_out_buffer_len;
171                fast_memcpy(buffer+size,sh_audio->a_out_buffer,len);
172                sh_audio->a_out_buffer_len-=len; size+=len;
173@@ -910,6 +932,11 @@
174       mencoder_exit(1,NULL);
175     }
176 }
177+
178+reconf_data.mux_a = mux_a;
179+reconf_data.new_srate = new_srate;
180+reconf_data.aencoder = aencoder;
181+
182 switch(mux_a->codec){
183 case ACODEC_COPY:
184     if (playback_speed != 1.0) mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_NoSpeedWithFrameCopy);
185Index: mplayer.c
186===================================================================
187--- mplayer.c   (リビゞョン 29813)
188+++ mplayer.c   (䜜業コピヌ)
189@@ -1604,7 +1604,14 @@
190 ///@}
191 // OSDMsgStack
192 
193+// for "in-stream" audio config switch
194+void reconfig_audio_chain(void) {
195+  if(!build_afilter_chain(mpctx->sh_audio, &ao_data))
196+    mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
197 
198+  return;
199+}
200+
201 void reinit_audio_chain(void) {
202 if(mpctx->sh_audio){
203   current_module="init_audio_codec";
204@@ -2044,6 +2051,14 @@
205 
206     current_module="play_audio";
207 
208+    if (mpctx->sh_audio->reconfig) {
209+        mpctx->sh_audio->o_bps = mpctx->sh_audio->channels *
210+                                 mpctx->sh_audio->samplerate *
211+                                 mpctx->sh_audio->samplesize;
212+        if(!build_afilter_chain(mpctx->sh_audio, &ao_data))
213+            mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter);
214+    }
215+
216     while (1) {
217        int sleep_time;
218        // all the current uses of ao_data.pts seem to be in aos that handle
219@@ -2108,6 +2123,9 @@
220            mp_msg(MSGT_CPLAYER, MSGL_WARN, "Audio output truncated at end.\n");
221            sh_audio->a_out_buffer_len = 0;
222        }
223+
224+        if (sh_audio->reconfig)
225+            break;
226     }
227     return 1;
228 }
229