Search in sources :

Example 16 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class EventSampleStreamTest method readDataReturnDataAfterFormat.

/**
 * Tests that {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} will
 * return sample data after the first call.
 */
@Test
public void readDataReturnDataAfterFormat() {
    long presentationTimeUs = 1000000;
    EventMessage eventMessage = newEventMessageWithId(1);
    EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs }, new EventMessage[] { eventMessage });
    EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
    // first read - read format
    readData(sampleStream);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
}
Also used : EventMessage(com.google.android.exoplayer2.metadata.emsg.EventMessage) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Example 17 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class HlsSampleStreamWrapper method readData.

public int readData(int sampleQueueIndex, FormatHolder formatHolder, DecoderInputBuffer buffer, @ReadFlags int readFlags) {
    if (isPendingReset()) {
        return C.RESULT_NOTHING_READ;
    }
    // TODO: Split into discard (in discardBuffer) and format change (here and in skipData) steps.
    if (!mediaChunks.isEmpty()) {
        int discardToMediaChunkIndex = 0;
        while (discardToMediaChunkIndex < mediaChunks.size() - 1 && finishedReadingChunk(mediaChunks.get(discardToMediaChunkIndex))) {
            discardToMediaChunkIndex++;
        }
        Util.removeRange(mediaChunks, 0, discardToMediaChunkIndex);
        HlsMediaChunk currentChunk = mediaChunks.get(0);
        Format trackFormat = currentChunk.trackFormat;
        if (!trackFormat.equals(downstreamTrackFormat)) {
            mediaSourceEventDispatcher.downstreamFormatChanged(trackType, trackFormat, currentChunk.trackSelectionReason, currentChunk.trackSelectionData, currentChunk.startTimeUs);
        }
        downstreamTrackFormat = trackFormat;
    }
    if (!mediaChunks.isEmpty() && !mediaChunks.get(0).isPublished()) {
        // Don't read into preload chunks until we can be sure they are permanently published.
        return C.RESULT_NOTHING_READ;
    }
    int result = sampleQueues[sampleQueueIndex].read(formatHolder, buffer, readFlags, loadingFinished);
    if (result == C.RESULT_FORMAT_READ) {
        Format format = Assertions.checkNotNull(formatHolder.format);
        if (sampleQueueIndex == primarySampleQueueIndex) {
            // Fill in primary sample format with information from the track format.
            int chunkUid = sampleQueues[sampleQueueIndex].peekSourceId();
            int chunkIndex = 0;
            while (chunkIndex < mediaChunks.size() && mediaChunks.get(chunkIndex).uid != chunkUid) {
                chunkIndex++;
            }
            Format trackFormat = chunkIndex < mediaChunks.size() ? mediaChunks.get(chunkIndex).trackFormat : Assertions.checkNotNull(upstreamTrackFormat);
            format = format.withManifestFormatInfo(trackFormat);
        }
        formatHolder.format = format;
    }
    return result;
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 18 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class FfmpegDecoder method decode.

@Override
public FfmpegDecoderException decode(DecoderInputBuffer inputBuffer, SimpleOutputBuffer outputBuffer, boolean reset) {
    if (reset) {
        nativeContext = ffmpegReset(nativeContext, extraData);
        if (nativeContext == 0) {
            return new FfmpegDecoderException("Error resetting (see logcat).");
        }
    }
    ByteBuffer inputData = inputBuffer.data;
    int inputSize = inputData.limit();
    ByteBuffer outputData = outputBuffer.init(inputBuffer.timeUs, OUTPUT_BUFFER_SIZE);
    int result = ffmpegDecode(nativeContext, inputData, inputSize, outputData, OUTPUT_BUFFER_SIZE);
    if (result < 0) {
        return new FfmpegDecoderException("Error decoding (see logcat). Code: " + result);
    }
    if (!hasOutputFormat) {
        channelCount = ffmpegGetChannelCount(nativeContext);
        sampleRate = ffmpegGetSampleRate(nativeContext);
        if (sampleRate == 0 && "alac".equals(codecName)) {
            // ALAC decoder did not set the sample rate in earlier versions of FFMPEG.
            // See https://trac.ffmpeg.org/ticket/6096
            ParsableByteArray parsableExtraData = new ParsableByteArray(extraData);
            parsableExtraData.setPosition(extraData.length - 4);
            sampleRate = parsableExtraData.readUnsignedIntToInt();
        }
        hasOutputFormat = true;
    }
    outputBuffer.data.position(0);
    outputBuffer.data.limit(result);
    return null;
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ByteBuffer(java.nio.ByteBuffer)

Example 19 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class VpxDecoder method decode.

@Override
protected VpxDecoderException decode(DecoderInputBuffer inputBuffer, VpxOutputBuffer outputBuffer, boolean reset) {
    ByteBuffer inputData = inputBuffer.data;
    int inputSize = inputData.limit();
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    final long result = inputBuffer.isEncrypted() ? vpxSecureDecode(vpxDecContext, inputData, inputSize, exoMediaCrypto, cryptoInfo.mode, cryptoInfo.key, cryptoInfo.iv, cryptoInfo.numSubSamples, cryptoInfo.numBytesOfClearData, cryptoInfo.numBytesOfEncryptedData) : vpxDecode(vpxDecContext, inputData, inputSize);
    if (result != NO_ERROR) {
        if (result == DRM_ERROR) {
            String message = "Drm error: " + vpxGetErrorMessage(vpxDecContext);
            DecryptionException cause = new DecryptionException(vpxGetErrorCode(vpxDecContext), message);
            return new VpxDecoderException(message, cause);
        } else {
            return new VpxDecoderException("Decode error: " + vpxGetErrorMessage(vpxDecContext));
        }
    }
    outputBuffer.init(inputBuffer.timeUs, outputMode);
    int getFrameResult = vpxGetFrame(vpxDecContext, outputBuffer);
    if (getFrameResult == 1) {
        outputBuffer.addFlag(C.BUFFER_FLAG_DECODE_ONLY);
    } else if (getFrameResult == -1) {
        return new VpxDecoderException("Buffer initialization failed.");
    }
    return null;
}
Also used : CryptoInfo(com.google.android.exoplayer2.decoder.CryptoInfo) ByteBuffer(java.nio.ByteBuffer) DecryptionException(com.google.android.exoplayer2.drm.DecryptionException)

Example 20 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class HlsSampleStreamWrapper method readData.

/* package */
int readData(int group, FormatHolder formatHolder, DecoderInputBuffer buffer, boolean requireFormat) {
    if (isPendingReset()) {
        return C.RESULT_NOTHING_READ;
    }
    while (mediaChunks.size() > 1 && finishedReadingChunk(mediaChunks.getFirst())) {
        mediaChunks.removeFirst();
    }
    HlsMediaChunk currentChunk = mediaChunks.getFirst();
    Format trackFormat = currentChunk.trackFormat;
    if (!trackFormat.equals(downstreamTrackFormat)) {
        eventDispatcher.downstreamFormatChanged(trackType, trackFormat, currentChunk.trackSelectionReason, currentChunk.trackSelectionData, currentChunk.startTimeUs);
    }
    downstreamTrackFormat = trackFormat;
    return sampleQueues.valueAt(group).readData(formatHolder, buffer, requireFormat, loadingFinished, lastSeekPositionUs);
}
Also used : Format(com.google.android.exoplayer2.Format)

Aggregations

Test (org.junit.Test)11 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)9 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)8 EventMessage (com.google.android.exoplayer2.metadata.emsg.EventMessage)8 Nullable (androidx.annotation.Nullable)7 Format (com.google.android.exoplayer2.Format)7 ByteBuffer (java.nio.ByteBuffer)6 FormatHolder (com.google.android.exoplayer2.FormatHolder)5 CryptoInfo (com.google.android.exoplayer2.decoder.CryptoInfo)5 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)3 Before (org.junit.Before)3 CryptoException (com.google.android.exoplayer2.decoder.CryptoException)2 DecryptionException (com.google.android.exoplayer2.drm.DecryptionException)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2 SurfaceTexture (android.graphics.SurfaceTexture)1 Handler (android.os.Handler)1 Surface (android.view.Surface)1