Search in sources :

Example 1 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class FormatTest method testParcelable.

public void testParcelable() {
    DrmInitData.SchemeData DRM_DATA_1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, TestUtil.buildTestData(128, 1));
    DrmInitData.SchemeData DRM_DATA_2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, TestUtil.buildTestData(128, 1));
    DrmInitData drmInitData = new DrmInitData(DRM_DATA_1, DRM_DATA_2);
    byte[] projectionData = new byte[] { 1, 2, 3 };
    Metadata metadata = new Metadata(new TextInformationFrame("id1", "description1", "value1"), new TextInformationFrame("id2", "description2", "value2"));
    Format formatToParcel = new Format("id", MimeTypes.VIDEO_MP4, MimeTypes.VIDEO_H264, null, 1024, 2048, 1920, 1080, 24, 90, 2, projectionData, C.STEREO_MODE_TOP_BOTTOM, 6, 44100, C.ENCODING_PCM_24BIT, 1001, 1002, 0, "und", Format.NO_VALUE, Format.OFFSET_SAMPLE_RELATIVE, INIT_DATA, drmInitData, metadata);
    Parcel parcel = Parcel.obtain();
    formatToParcel.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    Format formatFromParcel = Format.CREATOR.createFromParcel(parcel);
    assertEquals(formatToParcel, formatFromParcel);
    parcel.recycle();
}
Also used : DrmInitData(com.google.android.exoplayer2.drm.DrmInitData) MediaFormat(android.media.MediaFormat) Parcel(android.os.Parcel) Metadata(com.google.android.exoplayer2.metadata.Metadata) TextInformationFrame(com.google.android.exoplayer2.metadata.id3.TextInformationFrame)

Example 2 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class ExtractorMediaPeriod method maybeFinishPrepare.

// Internal methods.
private void maybeFinishPrepare() {
    if (released || prepared || seekMap == null || !tracksBuilt) {
        return;
    }
    int trackCount = sampleQueues.size();
    for (int i = 0; i < trackCount; i++) {
        if (sampleQueues.valueAt(i).getUpstreamFormat() == null) {
            return;
        }
    }
    loadCondition.close();
    TrackGroup[] trackArray = new TrackGroup[trackCount];
    trackIsAudioVideoFlags = new boolean[trackCount];
    trackEnabledStates = new boolean[trackCount];
    durationUs = seekMap.getDurationUs();
    for (int i = 0; i < trackCount; i++) {
        Format trackFormat = sampleQueues.valueAt(i).getUpstreamFormat();
        trackArray[i] = new TrackGroup(trackFormat);
        String mimeType = trackFormat.sampleMimeType;
        boolean isAudioVideo = MimeTypes.isVideo(mimeType) || MimeTypes.isAudio(mimeType);
        trackIsAudioVideoFlags[i] = isAudioVideo;
        haveAudioVideoTracks |= isAudioVideo;
    }
    tracks = new TrackGroupArray(trackArray);
    prepared = true;
    sourceListener.onSourceInfoRefreshed(new SinglePeriodTimeline(durationUs, seekMap.isSeekable()), null);
    callback.onPrepared(this);
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 3 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class WavHeaderReader method peek.

/**
   * Peeks and returns a {@code WavHeader}.
   *
   * @param input Input stream to peek the WAV header from.
   * @throws ParserException If the input file is an incorrect RIFF WAV.
   * @throws IOException If peeking from the input fails.
   * @throws InterruptedException If interrupted while peeking from input.
   * @return A new {@code WavHeader} peeked from {@code input}, or null if the input is not a
   *     supported WAV format.
   */
public static WavHeader peek(ExtractorInput input) throws IOException, InterruptedException {
    Assertions.checkNotNull(input);
    // Allocate a scratch buffer large enough to store the format chunk.
    ParsableByteArray scratch = new ParsableByteArray(16);
    // Attempt to read the RIFF chunk.
    ChunkHeader chunkHeader = ChunkHeader.peek(input, scratch);
    if (chunkHeader.id != Util.getIntegerCodeForString("RIFF")) {
        return null;
    }
    input.peekFully(scratch.data, 0, 4);
    scratch.setPosition(0);
    int riffFormat = scratch.readInt();
    if (riffFormat != Util.getIntegerCodeForString("WAVE")) {
        Log.e(TAG, "Unsupported RIFF format: " + riffFormat);
        return null;
    }
    // Skip chunks until we find the format chunk.
    chunkHeader = ChunkHeader.peek(input, scratch);
    while (chunkHeader.id != Util.getIntegerCodeForString("fmt ")) {
        input.advancePeekPosition((int) chunkHeader.size);
        chunkHeader = ChunkHeader.peek(input, scratch);
    }
    Assertions.checkState(chunkHeader.size >= 16);
    input.peekFully(scratch.data, 0, 16);
    scratch.setPosition(0);
    int type = scratch.readLittleEndianUnsignedShort();
    int numChannels = scratch.readLittleEndianUnsignedShort();
    int sampleRateHz = scratch.readLittleEndianUnsignedIntToInt();
    int averageBytesPerSecond = scratch.readLittleEndianUnsignedIntToInt();
    int blockAlignment = scratch.readLittleEndianUnsignedShort();
    int bitsPerSample = scratch.readLittleEndianUnsignedShort();
    int expectedBlockAlignment = numChannels * bitsPerSample / 8;
    if (blockAlignment != expectedBlockAlignment) {
        throw new ParserException("Expected block alignment: " + expectedBlockAlignment + "; got: " + blockAlignment);
    }
    @C.PcmEncoding int encoding = Util.getPcmEncoding(bitsPerSample);
    if (encoding == C.ENCODING_INVALID) {
        Log.e(TAG, "Unsupported WAV bit depth: " + bitsPerSample);
        return null;
    }
    if (type != TYPE_PCM && type != TYPE_WAVE_FORMAT_EXTENSIBLE) {
        Log.e(TAG, "Unsupported WAV format type: " + type);
        return null;
    }
    // If present, skip extensionSize, validBitsPerSample, channelMask, subFormatGuid, ...
    input.advancePeekPosition((int) chunkHeader.size - 16);
    return new WavHeader(numChannels, sampleRateHz, averageBytesPerSecond, blockAlignment, bitsPerSample, encoding);
}
Also used : ParsableByteArray(com.google.android.exoplayer2.util.ParsableByteArray) ParserException(com.google.android.exoplayer2.ParserException)

Example 4 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class SimpleDecoderAudioRenderer method drainOutputBuffer.

private boolean drainOutputBuffer() throws ExoPlaybackException, AudioDecoderException, AudioTrack.ConfigurationException, AudioTrack.InitializationException, AudioTrack.WriteException {
    if (outputBuffer == null) {
        outputBuffer = decoder.dequeueOutputBuffer();
        if (outputBuffer == null) {
            return false;
        }
        decoderCounters.skippedOutputBufferCount += outputBuffer.skippedOutputBufferCount;
    }
    if (outputBuffer.isEndOfStream()) {
        if (decoderReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
            // We're waiting to re-initialize the decoder, and have now processed all final buffers.
            releaseDecoder();
            maybeInitDecoder();
            // The audio track may need to be recreated once the new output format is known.
            audioTrackNeedsConfigure = true;
        } else {
            outputBuffer.release();
            outputBuffer = null;
            processEndOfStream();
        }
        return false;
    }
    if (audioTrackNeedsConfigure) {
        Format outputFormat = getOutputFormat();
        audioTrack.configure(outputFormat.sampleMimeType, outputFormat.channelCount, outputFormat.sampleRate, outputFormat.pcmEncoding, 0);
        audioTrackNeedsConfigure = false;
    }
    if (audioTrack.handleBuffer(outputBuffer.data, outputBuffer.timeUs)) {
        decoderCounters.renderedOutputBufferCount++;
        outputBuffer.release();
        outputBuffer = null;
        return true;
    }
    return false;
}
Also used : Format(com.google.android.exoplayer2.Format)

Example 5 with Format

use of com.google.android.exoplayer2.Format in project ExoPlayer by google.

the class OfflineLicenseHelper method download.

/**
   * Downloads an offline license.
   *
   * @param dataSource The {@link HttpDataSource} to be used for download.
   * @param dashManifest The {@link DashManifest} of the DASH content.
   * @return The downloaded offline license key set id.
   * @throws IOException If an error occurs reading data from the stream.
   * @throws InterruptedException If the thread has been interrupted.
   * @throws DrmSessionException Thrown when there is an error during DRM session.
   */
public byte[] download(HttpDataSource dataSource, DashManifest dashManifest) throws IOException, InterruptedException, DrmSessionException {
    // as per DASH IF Interoperability Recommendations V3.0, 7.5.3.
    if (dashManifest.getPeriodCount() < 1) {
        return null;
    }
    Period period = dashManifest.getPeriod(0);
    int adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_VIDEO);
    if (adaptationSetIndex == C.INDEX_UNSET) {
        adaptationSetIndex = period.getAdaptationSetIndex(C.TRACK_TYPE_AUDIO);
        if (adaptationSetIndex == C.INDEX_UNSET) {
            return null;
        }
    }
    AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
    if (adaptationSet.representations.isEmpty()) {
        return null;
    }
    Representation representation = adaptationSet.representations.get(0);
    DrmInitData drmInitData = representation.format.drmInitData;
    if (drmInitData == null) {
        Format sampleFormat = DashUtil.loadSampleFormat(dataSource, representation);
        if (sampleFormat != null) {
            drmInitData = sampleFormat.drmInitData;
        }
        if (drmInitData == null) {
            return null;
        }
    }
    blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
    return drmSessionManager.getOfflineLicenseKeySetId();
}
Also used : Format(com.google.android.exoplayer2.Format) Period(com.google.android.exoplayer2.source.dash.manifest.Period) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation)

Aggregations

Format (com.google.android.exoplayer2.Format)246 Test (org.junit.Test)178 Nullable (androidx.annotation.Nullable)65 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)61 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)55 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)35 ArrayList (java.util.ArrayList)32 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)26 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)26 MediaFormat (android.media.MediaFormat)22 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)22 SuppressLint (android.annotation.SuppressLint)18 Metadata (com.google.android.exoplayer2.metadata.Metadata)18 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)18 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)16 ImmutableList (com.google.common.collect.ImmutableList)16 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)15 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)15 SurfaceTexture (android.graphics.SurfaceTexture)14 Surface (android.view.Surface)14