2016-01-25 28 views
10

In Android 4.4.2, sto usando MediaCodec per decodificare i file mp3. Sto usando queueInputBuffer() per mettere in coda un frame mp3 in ingresso e dequeueOutputBuffer() per ottenere i frame decodificati. Ma il decodificatore emette l'uscita decodificata dall'8 ° fotogramma in poi (in base allo bufferInfo.presentationTimeUs) e salta 7 fotogrammi iniziali. Questo scenario si verifica solo per pochi flussi ma non per tutti i flussi. Inoltre, questo tipo di comportamento è coerente su molte esecuzioni.Android MediaCodec non decodifica tutti i buffer di input

Voglio l'output decodificato di tutti i frame e non voglio che i frame vengano saltati. Qualcuno può aiutarmi a capire perché i frame vengono saltati? Assicuro che il flusso non è corrotto. Poiché ottengo INFO_TRY_AGAIN fino al settimo fotogramma, quando l'indice del buffer valido viene restituito da "dequeueOutputBuffer", il tempo di presentazione è sempre di 8 fotogrammi.

seguito è il codice accodamento:

Log.e(TAG, "audptOffset = "+audptOffset+"input PT = "+audpt); 
       audcodec.queueInputBuffer(audInbufIndex, 0, audchunkSize, audpt, 0); 

seguito come lo chiamo dequeue e scriva AudioTrack:

if(!audoutputDone){ 
       if(!waitForAudioRelease){ 
        auoutBufIndex = audcodec.dequeueOutputBuffer(auinfo, 100); 
        Log.e(TAG, "Output PT = " + auinfo.presentationTimeUs+"auoutBufIndex = "+auoutBufIndex); 
       } 
       if (auoutBufIndex >= 0) { 
        waitForAudioRelease = true; 
       } else if (auoutBufIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) { 
        auddecOutBufArray = audcodec.getOutputBuffers(); 
       } else if (auoutBufIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) { 
        MediaFormat newFormat = audcodec.getOutputFormat(); 
        int sampleRate1 = newFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE); 
        int channelCount1 =newFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT); 
        Log.e(TAG, "INFO_OUTPUT_FORMAT_CHANGED"); 
        int minBufSize1 = AudioTrack.getMinBufferSize(sampleRate1, (channelCount1==2)? 
          AudioFormat.CHANNEL_OUT_STEREO:AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT); 
        audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, 
          sampleRate1, (channelCount1==2)?AudioFormat.CHANNEL_OUT_STEREO:AudioFormat.CHANNEL_OUT_MONO, 
          AudioFormat.ENCODING_PCM_16BIT, minBufSize1, 
          AudioTrack.MODE_STREAM); 
        audioTrack.play(); 
        waitForAudioRelease = false; 
       } 
       audionowUs = System.currentTimeMillis(); 
       if (auoutBufIndex >= 0) {    
        auwhenRealUs = (auinfo.presentationTimeUs/1000) + mStartTimeRealMs - (audptOffset/1000); 
        aulateByUs = audionowUs - auwhenRealUs; 


        if(!audioWaitTillStartTime){ 
         while((mStartTimeRealMs+((auinfo.presentationTimeUs/1000) - (audptOffset/1000))) >= audionowUs){ 
          try { 
           Thread.sleep(10); 
          } catch (InterruptedException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
          } 
          audionowUs = System.currentTimeMillis(); 
         } 
         Log.e(TAG,"Play is going to start PT Difference = "+((auinfo.presentationTimeUs/1000) - (audptOffset/1000))); 
        } 

Aggiungendo più registri:

02-22 17:46:03.164: E/CL(28650): received play command from server 
02-22 17:46:03.209: E/RealTimeClient(28650): created decoder for audio/mpeg 
02-22 17:46:03.234: E/Music(28650): Output PT = 0 
02-22 17:46:03.234: E/Music(28650): pt of first frame received 1215000 
02-22 17:46:03.234: E/Music(28650): Input PT = 1215000 
02-22 17:46:03.234: E/Music(28650): Output PT = 0 
02-22 17:46:03.234: E/Music(28650): Input PT = 1241122 
02-22 17:46:03.239: E/Music(28650): Output PT = 0 
02-22 17:46:03.239: E/Music(28650): Input PT = 1267244 
02-22 17:46:03.239: E/Music(28650): Output PT = 0 
02-22 17:46:03.239: E/Music(28650): Input PT = 1293367 
02-22 17:46:03.239: E/Music(28650): Output PT = 0 
02-22 17:46:03.239: E/Music(28650): Input PT = 1319489 
02-22 17:46:03.239: E/Music(28650): Output PT = 0 
02-22 17:46:03.244: E/Music(28650): INFO_OUTPUT_FORMAT_CHANGED 
02-22 17:46:03.249: I/Reverb(28650): getpid() 28650, IPCThreadState::self()->getCallingPid() 28650 
02-22 17:46:03.249: E/Reverb(28650): Reverb::StartElementHandler, wrong element or attributes: boolean 
02-22 17:46:03.249: E/Music(28650): Input PT = 1345612 
02-22 17:46:03.254: E/Music(28650): Output PT = 1293367 
02-22 17:46:03.259: E/Music(28650): Input PT = 1371734 
02-22 17:46:03.259: E/Music(28650): Input PT = 1397857 
02-22 17:46:03.259: E/Music(28650): Input PT = 1423979 
02-22 17:46:03.259: E/Music(28650): Input PT = 1450102 
02-22 17:46:03.264: E/Music(28650): Input PT = 1476224 
02-22 17:46:03.269: E/Music(28650): Input PT = 1502346 
02-22 17:46:03.269: E/Music(28650): Input PT = 1528469 
02-22 17:46:03.269: E/Music(28650): Input PT = 1554591 
02-22 17:46:03.269: E/Music(28650): Input PT = 1580714 
02-22 17:46:03.269: E/Music(28650): Input PT = 1606836 
02-22 17:46:03.269: E/Music(28650): Input PT = 1632959 
02-22 17:46:03.269: E/Music(28650): Input PT = 1659081 
02-22 17:46:04.124: W/AudioTrack(28650): releaseBuffer() track 0x5e2faf28 name=0x3 disabled, restarting 
02-22 17:46:04.129: E/Music(28650): Output PT = 1319489 
02-22 17:46:04.129: E/Music(28650): Input PT = 1685204 
02-22 17:46:04.159: E/Music(28650): Output PT = 1345612 
+0

hai l'output del registro? a volte il decodificatore restituisce messaggi nell'output del log. –

+0

@GabrielBursztyn Decoder non ha gettato in modo specifico alcun messge in questo senso, comunque simulerò e registrerò i log al più presto – nmxprime

+0

@GabrielBursztyn, Aggiunto più registri, questo può aiutare – nmxprime

risposta

1

MPEG-1 Layer III (MP3) ha frame dipendenti, non puoi iniziare da qualsiasi frame come Layer I o Layer II. Citando il numero link fornito, "Nel peggiore dei casi, potrebbero essere necessari 9 frame di input prima di poter decodificare un singolo frame." Questo è molto probabilmente quello che stai vedendo. Sebbene ognuno dei primi 7 fotogrammi abbia un PTS associato, non è fino a quando non si raggiunge l'ottavo fotogramma che il decodificatore è effettivamente in grado di decodificare completamente un fotogramma e iniziare la riproduzione. La riproduzione inizia con l'ottavo fotogramma PTS. Dovresti analizzare dolorosamente i byte del flusso in questione a mano per verificare completamente che cosa stia succedendo, ma sospetto che tu stia effettivamente giocando tutti i fotogrammi.

+0

'La riproduzione inizia con PTS dell'8 ° frame - significa, PTS di l'output del primo frame viene aggiornato con PTS dell'ottavo frame? – nmxprime

+0

Aggiunti altri registri, questo può aiutare a capire meglio. – nmxprime

+0

Nel peggiore dei casi, non è possibile riprodurre i primi 8 fotogrammi perché non ci sono abbastanza informazioni per creare una cornice completamente decodificata. Questi PTS saranno ignorati e il primo PTS da trasmettere sarà associato al primo fotogramma completamente decodificato (potrebbe essere uno dei primi 9 fotogrammi) che può essere passato in un lettore audio. Se inserisci un frame parzialmente decodificato con il suo PTS nel lettore, sentirai spazzatura. Dopo aver ottenuto il primo frame completamente decodificato, vedrai ogni PTS che inserisci come output. Questo sembra essere esattamente ciò che sta accadendo nel registro. – Kaleb