Search in sources :

Example 26 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class OutputConsumerAdapterV30 method toExoPlayerCryptoData.

@Nullable
private CryptoData toExoPlayerCryptoData(int trackIndex, @Nullable CryptoInfo cryptoInfo) {
    if (cryptoInfo == null) {
        return null;
    }
    @Nullable CryptoInfo lastReceivedCryptoInfo = lastReceivedCryptoInfos.get(trackIndex);
    CryptoData cryptoDataToOutput;
    // MediaParser keeps identity and value equality aligned for efficient comparison.
    if (lastReceivedCryptoInfo == cryptoInfo) {
        // They match, we can reuse the last one we created.
        cryptoDataToOutput = Assertions.checkNotNull(lastOutputCryptoDatas.get(trackIndex));
    } else {
        // They don't match, we create a new CryptoData.
        // TODO: Access pattern encryption info directly once the Android SDK makes it visible.
        // See [Internal ref: b/154248283].
        int encryptedBlocks;
        int clearBlocks;
        try {
            Matcher matcher = REGEX_CRYPTO_INFO_PATTERN.matcher(cryptoInfo.toString());
            matcher.find();
            encryptedBlocks = Integer.parseInt(Util.castNonNull(matcher.group(1)));
            clearBlocks = Integer.parseInt(Util.castNonNull(matcher.group(2)));
        } catch (RuntimeException e) {
            // Should never happen.
            Log.e(TAG, "Unexpected error while parsing CryptoInfo: " + cryptoInfo, e);
            // Assume no-pattern encryption.
            encryptedBlocks = 0;
            clearBlocks = 0;
        }
        cryptoDataToOutput = new CryptoData(cryptoInfo.mode, cryptoInfo.key, encryptedBlocks, clearBlocks);
        lastReceivedCryptoInfos.set(trackIndex, cryptoInfo);
        lastOutputCryptoDatas.set(trackIndex, cryptoDataToOutput);
    }
    return cryptoDataToOutput;
}
Also used : CryptoData(com.google.android.exoplayer2.extractor.TrackOutput.CryptoData) CryptoInfo(android.media.MediaCodec.CryptoInfo) Matcher(java.util.regex.Matcher) Nullable(androidx.annotation.Nullable) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) SuppressLint(android.annotation.SuppressLint) Nullable(androidx.annotation.Nullable)

Example 27 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class MediaCodecVideoRenderer method onOutputFormatChanged.

@Override
protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat) {
    @Nullable MediaCodecAdapter codec = getCodec();
    if (codec != null) {
        // Must be applied each time the output format changes.
        codec.setVideoScalingMode(scalingMode);
    }
    if (tunneling) {
        currentWidth = format.width;
        currentHeight = format.height;
    } else {
        Assertions.checkNotNull(mediaFormat);
        boolean hasCrop = mediaFormat.containsKey(KEY_CROP_RIGHT) && mediaFormat.containsKey(KEY_CROP_LEFT) && mediaFormat.containsKey(KEY_CROP_BOTTOM) && mediaFormat.containsKey(KEY_CROP_TOP);
        currentWidth = hasCrop ? mediaFormat.getInteger(KEY_CROP_RIGHT) - mediaFormat.getInteger(KEY_CROP_LEFT) + 1 : mediaFormat.getInteger(MediaFormat.KEY_WIDTH);
        currentHeight = hasCrop ? mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP) + 1 : mediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
    }
    currentPixelWidthHeightRatio = format.pixelWidthHeightRatio;
    if (Util.SDK_INT >= 21) {
        // to flip the width, height and pixel aspect ratio to reflect the rotation that was applied.
        if (format.rotationDegrees == 90 || format.rotationDegrees == 270) {
            int rotatedHeight = currentWidth;
            currentWidth = currentHeight;
            currentHeight = rotatedHeight;
            currentPixelWidthHeightRatio = 1 / currentPixelWidthHeightRatio;
        }
    } else {
        // On API level 20 and below the decoder does not apply the rotation.
        currentUnappliedRotationDegrees = format.rotationDegrees;
    }
    frameReleaseHelper.onFormatChanged(format.frameRate);
}
Also used : MediaCodecAdapter(com.google.android.exoplayer2.mediacodec.MediaCodecAdapter) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 28 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class CacheFileMetadataIndex method remove.

/**
 * Removes metadata.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @param name The name of the file whose metadata is to be removed.
 * @throws DatabaseIOException If an error occurs removing the metadata.
 */
@WorkerThread
public void remove(String name) throws DatabaseIOException {
    Assertions.checkNotNull(tableName);
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] { name });
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

Example 29 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class CacheFileMetadataIndex method removeAll.

/**
 * Removes metadata.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @param names The names of the files whose metadata is to be removed.
 * @throws DatabaseIOException If an error occurs removing the metadata.
 */
@WorkerThread
public void removeAll(Set<String> names) throws DatabaseIOException {
    Assertions.checkNotNull(tableName);
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        writableDatabase.beginTransactionNonExclusive();
        try {
            for (String name : names) {
                writableDatabase.delete(tableName, WHERE_NAME_EQUALS, new String[] { name });
            }
            writableDatabase.setTransactionSuccessful();
        } finally {
            writableDatabase.endTransaction();
        }
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

Example 30 with Assertions.checkNotNull

use of com.google.android.exoplayer2.util.Assertions.checkNotNull in project ExoPlayer by google.

the class Cea608Decoder method getDisplayCues.

private List<Cue> getDisplayCues() {
    // CEA-608 does not define middle and end alignment, however content providers artificially
    // introduce them using whitespace. When each cue is built, we try and infer the alignment based
    // on the amount of whitespace either side of the text. To avoid consecutive cues being aligned
    // differently, we force all cues to have the same alignment, with start alignment given
    // preference, then middle alignment, then end alignment.
    @Cue.AnchorType int positionAnchor = Cue.ANCHOR_TYPE_END;
    int cueBuilderCount = cueBuilders.size();
    List<@NullableType Cue> cueBuilderCues = new ArrayList<>(cueBuilderCount);
    for (int i = 0; i < cueBuilderCount; i++) {
        @Nullable Cue cue = cueBuilders.get(i).build(/* forcedPositionAnchor= */
        Cue.TYPE_UNSET);
        cueBuilderCues.add(cue);
        if (cue != null) {
            positionAnchor = min(positionAnchor, cue.positionAnchor);
        }
    }
    // Skip null cues and rebuild any that don't have the preferred alignment.
    List<Cue> displayCues = new ArrayList<>(cueBuilderCount);
    for (int i = 0; i < cueBuilderCount; i++) {
        @Nullable Cue cue = cueBuilderCues.get(i);
        if (cue != null) {
            if (cue.positionAnchor != positionAnchor) {
                // The last time we built this cue it was non-null, it will be non-null this time too.
                cue = Assertions.checkNotNull(cueBuilders.get(i).build(positionAnchor));
            }
            displayCues.add(cue);
        }
    }
    return displayCues;
}
Also used : Cue(com.google.android.exoplayer2.text.Cue) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)28 Format (com.google.android.exoplayer2.Format)10 ArrayList (java.util.ArrayList)9 MediaItem (com.google.android.exoplayer2.MediaItem)8 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)5 Matcher (java.util.regex.Matcher)5 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 Uri (android.net.Uri)4 MediaSource (com.google.android.exoplayer2.source.MediaSource)4 DataSource (com.google.android.exoplayer2.upstream.DataSource)4 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 SQLException (android.database.SQLException)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 Bundle (android.os.Bundle)3 CallbackMediaItem (androidx.media2.common.CallbackMediaItem)3 C (com.google.android.exoplayer2.C)3 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)3