readSampleData () медиа-кодека, дающего ошибку сегментации после возобновления

Я играю закодированное видео, используя медиа-кодек и медиаэкстрактор. Сейчас я пытаюсь реализовать паузу и возобновить для игрока. Вот мой код для запуска метода потока игрока

 public void run() {
            int frameCount = 0;
            if (decoder == null) {
                Log.e("DecodeActivity", "Can't find video info!");
                return;
            }
            while (!mPlayer.isInterrupted()) {
                if (!isEOS) {
                    try {
                        inIndex = decoder.dequeueInputBuffer(10000);
                    } catch (IllegalStateException e) {

                        // Ignore the exception and break.
                        break;
                    }
                    if (inIndex >= 0) {
                        ByteBuffer buffer = inputBuffers[inIndex];
                        int sampleSize = 0;
                        if(frameCount != 0) {
                        try {
                            System.out.println("buffer len = "+ buffer.capacity() + buffer);

                                sampleSize = extractor.readSampleData(buffer, 0);

                            System.out.println("read a sample......................");
                            }  catch (RuntimeException re) {
                                re.printStackTrace();
                            }catch (Exception e) {
                                e.printStackTrace();
                                // Ignore the exception.
                            }
                        System.out.println("ENC LENGTH"+sampleSize);
                        }
                        ++frameCount;
                        if (sampleSize < 0) {
                            // We shouldn't stop the play back at this point, just pass the EOS
                            // flag to decoder, we will get it again from the
                            // dequeueOutputBuffer
                            Log.d("DecodeActivity", "InputBuffer BUFFER_FLAG_END_OF_STREAM");
                            System.out.println("DecodeActivity InputBuffer BUFFER_FLAG_END_OF_STREAM");
                            decoder.queueInputBuffer(inIndex, 0, 0, 0, MediaCodec.BUFFER_FLAG_END_OF_STREAM);
                            isEOS = true;
                        } else {
                            try {
                                decoder.queueInputBuffer(inIndex, 0, sampleSize, extractor.getSampleTime(), 0);
                                extractor.advance();
                            } catch (IllegalStateException e) {

                                // Ignore the exception.
                            }
                        }
                    }
                }
                int outIndex = 0;
                try {
                        outIndex = decoder.dequeueOutputBuffer(info, 10000);
                    } catch (IllegalStateException e) {

                        // Ignore the exception and break.
                        break;
                    }
                switch (outIndex) {
                    case MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED:
                        Log.d("DecodeActivity", "INFO_OUTPUT_BUFFERS_CHANGED");
                        outputBuffers = decoder.getOutputBuffers();
                        break;
                    case MediaCodec.INFO_OUTPUT_FORMAT_CHANGED:
                        Log.d("DecodeActivity", "New format " + decoder.getOutputFormat());
                        break;
                    case MediaCodec.INFO_TRY_AGAIN_LATER:
                        Log.d("DecodeActivity", "dequeueOutputBuffer timed out!");
                        break;
                    default:
                        ByteBuffer buffer = outputBuffers[outIndex];
                        Log.v("DecodeActivity", "We can't use this buffer but render it due to the API limit, " + buffer);

                        // We use a very simple clock to keep the video FPS, or the video
                        // playback will be too fast
                        while (info.presentationTimeUs / 1000 > System.currentTimeMillis() - startMs) {
                            try {
                                sleep(10);
                            } catch (InterruptedException e) {

                                e.printStackTrace();
                                break;
                            }
                        }
                        try {

                            System.out.println("Diaplayed a frame................");
                                decoder.releaseOutputBuffer(outIndex, true);
                                sleep(35);
                        } catch (IllegalStateException e) {

                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        break;
                }
                // All decoded frames have been rendered, we can stop playing now
                if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
                    Log.d("DecodeActivity", "OutputBuffer BUFFER_FLAG_END_OF_STREAM");
                    //finish();
                }
            }
        }

Все используемые переменные объявлены глобально.

Вот мой код для паузы и возобновления с помощью кнопки

public void holdButton(View view) {

    if(onHold == false) {       
        System.out.println("HoldCall................");
        onHold = true;
        stopPlayer();
        decoder.stop();

    } else {
        System.out.println("ResumeCall................");
        onHold = false;
        initPlayerThread(sv.getHolder());
        startPlayer();
    }
}

public void initPlayerThread(SurfaceHolder holder) {
    if (mPlayer == null) {
        System.out.println("PlayerThread new.................");
        mPlayer = new PlayerThread(holder.getSurface());
        System.out.println("PlayerThread going to start.................");     
    } else {
        mPlayer = null;
        mPlayer = new PlayerThread(holder.getSurface(), 2);
        System.out.println("PlayerThread started.................");
    }
}    

PlayerThread(holder.getSurface(), 2); 

просто запустит декодер. Когда я нажимаю кнопку HoldButton, она приостанавливается, но при повторном нажатии она должна возобновиться, но при возобновлении

extractor.readSampleData(buffer, 0);

Эта строка дает ошибку сегментации. Иногда при нажатии на кнопку Hold для паузы также это происходит.

Я не могу понять проблему.

Пожалуйста помоги....................

Спасибо...

Вот моя информация logcat после резюме.

11-24 23:55:02.969: D/DecodeActivity(1941): dequeueOutputBuffer timed out!
11-24 23:55:02.969: I/System.out(1941): read a sample......................
11-24 23:55:02.981: I/System.out(1941): buffer len = 65536java.nio.DirectByteBuffer[position=0,limit=65536,capacity=65536]
11-24 23:55:02.981: I/System.out(1941): read a sample......................
11-24 23:55:02.989: I/System.out(1941): ENC LENGTH552
11-24 23:55:03.000: I/System.out(1941): HoldCall................
11-24 23:55:03.021: D/DecodeActivity(1941): dequeueOutputBuffer timed out!
11-24 23:55:03.040: I/System.out(1941): read a sample......................
11-24 23:55:03.049: D/DecodeActivity(1941): dequeueOutputBuffer timed out!
11-24 23:55:03.239: I/Choreographer(1941): Skipped 32 frames!  The application may be doing too much work on its main thread.
11-24 23:55:10.209: I/System.out(1941): ResumeCall................
11-24 23:55:10.269: I/OMXClient(1941): Using client-side OMX mux.
11-24 23:55:10.359: I/System.out(1941): PlayerThread started.................
11-24 23:55:10.409: I/System.out(1941): in run......................
11-24 23:55:10.419: I/System.out(1941): read a sample......................
11-24 23:55:10.429: I/System.out(1941): buffer len = 65536java.nio.DirectByteBuffer[position=0,limit=65536,capacity=65536]
11-24 23:55:10.449: A/libc(1941): Fatal signal 11 (SIGSEGV) at 0x4a3bd000 (code=2), thread 2005 (Thread-101)

Я не мог понять причину этого................

0 ответов

Другие вопросы по тегам