Search in sources :

Example 76 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class MediaItem method fromBundle.

// Unbundling to ClippingProperties while it still exists.
@SuppressWarnings("deprecation")
private static MediaItem fromBundle(Bundle bundle) {
    String mediaId = checkNotNull(bundle.getString(keyForField(FIELD_MEDIA_ID), DEFAULT_MEDIA_ID));
    @Nullable Bundle liveConfigurationBundle = bundle.getBundle(keyForField(FIELD_LIVE_CONFIGURATION));
    LiveConfiguration liveConfiguration;
    if (liveConfigurationBundle == null) {
        liveConfiguration = LiveConfiguration.UNSET;
    } else {
        liveConfiguration = LiveConfiguration.CREATOR.fromBundle(liveConfigurationBundle);
    }
    @Nullable Bundle mediaMetadataBundle = bundle.getBundle(keyForField(FIELD_MEDIA_METADATA));
    MediaMetadata mediaMetadata;
    if (mediaMetadataBundle == null) {
        mediaMetadata = MediaMetadata.EMPTY;
    } else {
        mediaMetadata = MediaMetadata.CREATOR.fromBundle(mediaMetadataBundle);
    }
    @Nullable Bundle clippingConfigurationBundle = bundle.getBundle(keyForField(FIELD_CLIPPING_PROPERTIES));
    ClippingProperties clippingConfiguration;
    if (clippingConfigurationBundle == null) {
        clippingConfiguration = ClippingProperties.UNSET;
    } else {
        clippingConfiguration = ClippingConfiguration.CREATOR.fromBundle(clippingConfigurationBundle);
    }
    return new MediaItem(mediaId, clippingConfiguration, /* localConfiguration= */
    null, liveConfiguration, mediaMetadata);
}
Also used : Bundle(android.os.Bundle) Nullable(androidx.annotation.Nullable)

Example 77 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class VpxDecoder method decode.

@Override
@Nullable
protected VpxDecoderException decode(DecoderInputBuffer inputBuffer, VideoDecoderOutputBuffer outputBuffer, boolean reset) {
    if (reset && lastSupplementalData != null) {
        // Don't propagate supplemental data across calls to flush the decoder.
        lastSupplementalData.clear();
    }
    ByteBuffer inputData = Util.castNonNull(inputBuffer.data);
    int inputSize = inputData.limit();
    CryptoInfo cryptoInfo = inputBuffer.cryptoInfo;
    final long result = inputBuffer.isEncrypted() ? vpxSecureDecode(vpxDecContext, inputData, inputSize, cryptoConfig, cryptoInfo.mode, Assertions.checkNotNull(cryptoInfo.key), Assertions.checkNotNull(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);
            CryptoException cause = new CryptoException(vpxGetErrorCode(vpxDecContext), message);
            return new VpxDecoderException(message, cause);
        } else {
            return new VpxDecoderException("Decode error: " + vpxGetErrorMessage(vpxDecContext));
        }
    }
    if (inputBuffer.hasSupplementalData()) {
        ByteBuffer supplementalData = Assertions.checkNotNull(inputBuffer.supplementalData);
        int size = supplementalData.remaining();
        if (size > 0) {
            if (lastSupplementalData == null || lastSupplementalData.capacity() < size) {
                lastSupplementalData = ByteBuffer.allocate(size);
            } else {
                lastSupplementalData.clear();
            }
            lastSupplementalData.put(supplementalData);
            lastSupplementalData.flip();
        }
    }
    if (!inputBuffer.isDecodeOnly()) {
        outputBuffer.init(inputBuffer.timeUs, outputMode, lastSupplementalData);
        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.");
        }
        outputBuffer.format = inputBuffer.format;
    }
    return null;
}
Also used : CryptoInfo(com.google.android.exoplayer2.decoder.CryptoInfo) CryptoException(com.google.android.exoplayer2.decoder.CryptoException) ByteBuffer(java.nio.ByteBuffer) Nullable(androidx.annotation.Nullable)

Example 78 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class DrmInitData method createSessionCreationData.

/**
 * Merges {@link DrmInitData} obtained from a media manifest and a media stream.
 *
 * <p>The result is generated as follows.
 *
 * <ol>
 *   <li>Include all {@link SchemeData}s from {@code manifestData} where {@link
 *       SchemeData#hasData()} is true.
 *   <li>Include all {@link SchemeData}s in {@code mediaData} where {@link SchemeData#hasData()}
 *       is true and for which we did not include an entry from the manifest targeting the same
 *       UUID.
 *   <li>If available, the scheme type from the manifest is used. If not, the scheme type from the
 *       media is used.
 * </ol>
 *
 * @param manifestData DRM session acquisition data obtained from the manifest.
 * @param mediaData DRM session acquisition data obtained from the media.
 * @return A {@link DrmInitData} obtained from merging a media manifest and a media stream.
 */
@Nullable
public static DrmInitData createSessionCreationData(@Nullable DrmInitData manifestData, @Nullable DrmInitData mediaData) {
    ArrayList<SchemeData> result = new ArrayList<>();
    String schemeType = null;
    if (manifestData != null) {
        schemeType = manifestData.schemeType;
        for (SchemeData data : manifestData.schemeDatas) {
            if (data.hasData()) {
                result.add(data);
            }
        }
    }
    if (mediaData != null) {
        if (schemeType == null) {
            schemeType = mediaData.schemeType;
        }
        int manifestDatasCount = result.size();
        for (SchemeData data : mediaData.schemeDatas) {
            if (data.hasData() && !containsSchemeDataWithUuid(result, manifestDatasCount, data.uuid)) {
                result.add(data);
            }
        }
    }
    return result.isEmpty() ? null : new DrmInitData(schemeType, result);
}
Also used : ArrayList(java.util.ArrayList) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) Nullable(androidx.annotation.Nullable)

Example 79 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class MetadataRenderer method decodeWrappedMetadata.

/**
 * Iterates through {@code metadata.entries} and checks each one to see if contains wrapped
 * metadata. If it does, then we recursively decode the wrapped metadata. If it doesn't (recursion
 * base-case), we add the {@link Metadata.Entry} to {@code decodedEntries} (output parameter).
 */
private void decodeWrappedMetadata(Metadata metadata, List<Metadata.Entry> decodedEntries) {
    for (int i = 0; i < metadata.length(); i++) {
        @Nullable Format wrappedMetadataFormat = metadata.get(i).getWrappedMetadataFormat();
        if (wrappedMetadataFormat != null && decoderFactory.supportsFormat(wrappedMetadataFormat)) {
            MetadataDecoder wrappedMetadataDecoder = decoderFactory.createDecoder(wrappedMetadataFormat);
            // wrappedMetadataFormat != null so wrappedMetadataBytes must be non-null too.
            byte[] wrappedMetadataBytes = Assertions.checkNotNull(metadata.get(i).getWrappedMetadataBytes());
            buffer.clear();
            buffer.ensureSpaceForWrite(wrappedMetadataBytes.length);
            castNonNull(buffer.data).put(wrappedMetadataBytes);
            buffer.flip();
            @Nullable Metadata innerMetadata = wrappedMetadataDecoder.decode(buffer);
            if (innerMetadata != null) {
                // The decoding succeeded, so we'll try another level of unwrapping.
                decodeWrappedMetadata(innerMetadata, decodedEntries);
            }
        } else {
            // Entry doesn't contain any wrapped metadata, so output it directly.
            decodedEntries.add(metadata.get(i));
        }
    }
}
Also used : Format(com.google.android.exoplayer2.Format) Nullable(androidx.annotation.Nullable)

Example 80 with Nullable

use of androidx.annotation.Nullable in project ExoPlayer by google.

the class DownloadHelper method runTrackSelection.

/**
 * Runs the track selection for a given period index with the current parameters. The selected
 * tracks will be added to {@link #trackSelectionsByPeriodAndRenderer}.
 */
@RequiresNonNull({ "trackGroupArrays", "trackSelectionsByPeriodAndRenderer", "mediaPreparer", "mediaPreparer.timeline" })
private TrackSelectorResult runTrackSelection(int periodIndex) {
    try {
        TrackSelectorResult trackSelectorResult = trackSelector.selectTracks(rendererCapabilities, trackGroupArrays[periodIndex], new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)), mediaPreparer.timeline);
        for (int i = 0; i < trackSelectorResult.length; i++) {
            @Nullable ExoTrackSelection newSelection = trackSelectorResult.selections[i];
            if (newSelection == null) {
                continue;
            }
            List<ExoTrackSelection> existingSelectionList = trackSelectionsByPeriodAndRenderer[periodIndex][i];
            boolean mergedWithExistingSelection = false;
            for (int j = 0; j < existingSelectionList.size(); j++) {
                ExoTrackSelection existingSelection = existingSelectionList.get(j);
                if (existingSelection.getTrackGroup().equals(newSelection.getTrackGroup())) {
                    // Merge with existing selection.
                    scratchSet.clear();
                    for (int k = 0; k < existingSelection.length(); k++) {
                        scratchSet.put(existingSelection.getIndexInTrackGroup(k), 0);
                    }
                    for (int k = 0; k < newSelection.length(); k++) {
                        scratchSet.put(newSelection.getIndexInTrackGroup(k), 0);
                    }
                    int[] mergedTracks = new int[scratchSet.size()];
                    for (int k = 0; k < scratchSet.size(); k++) {
                        mergedTracks[k] = scratchSet.keyAt(k);
                    }
                    existingSelectionList.set(j, new DownloadTrackSelection(existingSelection.getTrackGroup(), mergedTracks));
                    mergedWithExistingSelection = true;
                    break;
                }
            }
            if (!mergedWithExistingSelection) {
                existingSelectionList.add(newSelection);
            }
        }
        return trackSelectorResult;
    } catch (ExoPlaybackException e) {
        // DefaultTrackSelector does not throw exceptions during track selection.
        throw new UnsupportedOperationException(e);
    }
}
Also used : TrackSelectorResult(com.google.android.exoplayer2.trackselection.TrackSelectorResult) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

Nullable (androidx.annotation.Nullable)1124 View (android.view.View)188 Bundle (android.os.Bundle)111 IOException (java.io.IOException)99 NonNull (androidx.annotation.NonNull)96 ArrayList (java.util.ArrayList)95 Context (android.content.Context)93 TextView (android.widget.TextView)92 Cursor (android.database.Cursor)71 SuppressLint (android.annotation.SuppressLint)69 Uri (android.net.Uri)66 RecyclerView (androidx.recyclerview.widget.RecyclerView)59 List (java.util.List)58 ViewGroup (android.view.ViewGroup)56 Test (org.junit.Test)55 Intent (android.content.Intent)53 Recipient (org.thoughtcrime.securesms.recipients.Recipient)52 R (org.thoughtcrime.securesms.R)46 LayoutInflater (android.view.LayoutInflater)45 ImageView (android.widget.ImageView)43