Search in sources :

Example 1 with CodecException

use of android.media.MediaCodec.CodecException in project robolectric by robolectric.

the class ShadowMediaCodecTest method inSyncMode_afterFlushCannotQueueInputBufferThatIsNotDequeued.

@Test
public void inSyncMode_afterFlushCannotQueueInputBufferThatIsNotDequeued() throws IOException {
    MediaCodec codec = createSyncEncoder();
    int inputIndex = codec.dequeueInputBuffer(/* timeoutUs= */
    0);
    codec.getInputBuffer(inputIndex).put(generateByteArray(/* size= */
    128));
    codec.flush();
    try {
        codec.queueInputBuffer(inputIndex, /* offset= */
        0, /* size= */
        128, /* presentationTimeUs= */
        0, /* flags= */
        0);
        fail();
    } catch (CodecException expected) {
    }
}
Also used : MediaCodec(android.media.MediaCodec) CodecException(android.media.MediaCodec.CodecException) Test(org.junit.Test)

Example 2 with CodecException

use of android.media.MediaCodec.CodecException in project robolectric by robolectric.

the class ShadowMediaCodecTest method queueInputBuffer_withInvalidIndex_throws.

@Test
public void queueInputBuffer_withInvalidIndex_throws() throws IOException {
    List<Integer> inputBuffers = new ArrayList<>();
    MediaCodecCallback callback = new MediaCodecCallback() {

        @Override
        public void onInputBufferAvailable(MediaCodec codec, int inputBufferId) {
            inputBuffers.add(inputBufferId);
        }
    };
    MediaCodec codec = createAsyncEncoder(callback);
    int invalidInputIndex = inputBuffers.isEmpty() ? 0 : max(inputBuffers) + 1;
    try {
        codec.queueInputBuffer(invalidInputIndex, /* offset= */
        0, /* size= */
        128, /* presentationTimeUs= */
        0, /* flags= */
        0);
        fail();
    } catch (CodecException expected) {
    }
}
Also used : MediaCodec(android.media.MediaCodec) ArrayList(java.util.ArrayList) CodecException(android.media.MediaCodec.CodecException) Test(org.junit.Test)

Example 3 with CodecException

use of android.media.MediaCodec.CodecException in project robolectric by robolectric.

the class ShadowMediaCodecTest method inSyncMode_queueInputBufferTwice_throws.

@Test
public void inSyncMode_queueInputBufferTwice_throws() throws IOException {
    MediaCodec codec = createSyncEncoder();
    int inputIndex = codec.dequeueInputBuffer(/* timeoutUs= */
    0);
    codec.getInputBuffer(inputIndex).put(generateByteArray(/* size= */
    128));
    codec.queueInputBuffer(inputIndex, /* offset= */
    0, /* size= */
    128, /* presentationTimeUs= */
    0, /* flags= */
    0);
    try {
        codec.queueInputBuffer(inputIndex, /* offset= */
        0, /* size= */
        128, /* presentationTimeUs= */
        0, /* flags= */
        0);
        fail();
    } catch (CodecException expected) {
    }
}
Also used : MediaCodec(android.media.MediaCodec) CodecException(android.media.MediaCodec.CodecException) Test(org.junit.Test)

Example 4 with CodecException

use of android.media.MediaCodec.CodecException in project robolectric by robolectric.

the class ShadowMediaCodecTest method inSyncMode_queueingInputBufferWithoutDequeue_throws.

@Test
public void inSyncMode_queueingInputBufferWithoutDequeue_throws() throws IOException {
    MediaCodec codec = createSyncEncoder();
    try {
        codec.queueInputBuffer(/* index= */
        0, /* offset= */
        0, /* size= */
        0, /* presentationTimeUs= */
        0, /* flags= */
        0);
        fail();
    } catch (CodecException expected) {
    }
}
Also used : MediaCodec(android.media.MediaCodec) CodecException(android.media.MediaCodec.CodecException) Test(org.junit.Test)

Aggregations

MediaCodec (android.media.MediaCodec)4 CodecException (android.media.MediaCodec.CodecException)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1