Search in sources :

Example 61 with Assertions.checkNotNull

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

the class MetadataRenderer method readMetadata.

private void readMetadata() {
    if (!inputStreamEnded && pendingMetadata == null) {
        buffer.clear();
        FormatHolder formatHolder = getFormatHolder();
        @ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
        0);
        if (result == C.RESULT_BUFFER_READ) {
            if (buffer.isEndOfStream()) {
                inputStreamEnded = true;
            } else {
                buffer.subsampleOffsetUs = subsampleOffsetUs;
                buffer.flip();
                @Nullable Metadata metadata = castNonNull(decoder).decode(buffer);
                if (metadata != null) {
                    List<Metadata.Entry> entries = new ArrayList<>(metadata.length());
                    decodeWrappedMetadata(metadata, entries);
                    if (!entries.isEmpty()) {
                        Metadata expandedMetadata = new Metadata(entries);
                        pendingMetadata = expandedMetadata;
                        pendingMetadataTimestampUs = buffer.timeUs;
                    }
                }
            }
        } else if (result == C.RESULT_FORMAT_READ) {
            subsampleOffsetUs = Assertions.checkNotNull(formatHolder.format).subsampleOffsetUs;
        }
    }
}
Also used : ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Example 62 with Assertions.checkNotNull

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

the class FrameworkMediaDrm method getSchemeData.

private static SchemeData getSchemeData(UUID uuid, List<SchemeData> schemeDatas) {
    if (!C.WIDEVINE_UUID.equals(uuid)) {
        // For non-Widevine CDMs always use the first scheme data.
        return schemeDatas.get(0);
    }
    if (Util.SDK_INT >= 28 && schemeDatas.size() > 1) {
        // For API level 28 and above, concatenate multiple PSSH scheme datas if possible.
        SchemeData firstSchemeData = schemeDatas.get(0);
        int concatenatedDataLength = 0;
        boolean canConcatenateData = true;
        for (int i = 0; i < schemeDatas.size(); i++) {
            SchemeData schemeData = schemeDatas.get(i);
            byte[] schemeDataData = Assertions.checkNotNull(schemeData.data);
            if (Util.areEqual(schemeData.mimeType, firstSchemeData.mimeType) && Util.areEqual(schemeData.licenseServerUrl, firstSchemeData.licenseServerUrl) && PsshAtomUtil.isPsshAtom(schemeDataData)) {
                concatenatedDataLength += schemeDataData.length;
            } else {
                canConcatenateData = false;
                break;
            }
        }
        if (canConcatenateData) {
            byte[] concatenatedData = new byte[concatenatedDataLength];
            int concatenatedDataPosition = 0;
            for (int i = 0; i < schemeDatas.size(); i++) {
                SchemeData schemeData = schemeDatas.get(i);
                byte[] schemeDataData = Assertions.checkNotNull(schemeData.data);
                int schemeDataLength = schemeDataData.length;
                System.arraycopy(schemeDataData, 0, concatenatedData, concatenatedDataPosition, schemeDataLength);
                concatenatedDataPosition += schemeDataLength;
            }
            return firstSchemeData.copyWithData(concatenatedData);
        }
    }
    // the first V0 box.
    for (int i = 0; i < schemeDatas.size(); i++) {
        SchemeData schemeData = schemeDatas.get(i);
        int version = PsshAtomUtil.parseVersion(Assertions.checkNotNull(schemeData.data));
        if (Util.SDK_INT < 23 && version == 0) {
            return schemeData;
        } else if (Util.SDK_INT >= 23 && version == 1) {
            return schemeData;
        }
    }
    // If all else fails, use the first scheme data.
    return schemeDatas.get(0);
}
Also used : SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) SuppressLint(android.annotation.SuppressLint)

Example 63 with Assertions.checkNotNull

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

the class FrameworkMediaDrm method getKeyRequest.

// Return values of MediaDrm.KeyRequest.getRequestType are equal to KeyRequest.RequestType.
@SuppressLint("WrongConstant")
@Override
public KeyRequest getKeyRequest(byte[] scope, @Nullable List<DrmInitData.SchemeData> schemeDatas, int keyType, @Nullable HashMap<String, String> optionalParameters) throws NotProvisionedException {
    SchemeData schemeData = null;
    byte[] initData = null;
    String mimeType = null;
    if (schemeDatas != null) {
        schemeData = getSchemeData(uuid, schemeDatas);
        initData = adjustRequestInitData(uuid, Assertions.checkNotNull(schemeData.data));
        mimeType = adjustRequestMimeType(uuid, schemeData.mimeType);
    }
    MediaDrm.KeyRequest request = mediaDrm.getKeyRequest(scope, initData, mimeType, keyType, optionalParameters);
    byte[] requestData = adjustRequestData(uuid, request.getData());
    String licenseServerUrl = request.getDefaultUrl();
    if (MOCK_LA_URL_VALUE.equals(licenseServerUrl)) {
        licenseServerUrl = "";
    }
    if (TextUtils.isEmpty(licenseServerUrl) && schemeData != null && !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
        licenseServerUrl = schemeData.licenseServerUrl;
    }
    @KeyRequest.RequestType int requestType = Util.SDK_INT >= 23 ? request.getRequestType() : KeyRequest.REQUEST_TYPE_UNKNOWN;
    return new KeyRequest(requestData, licenseServerUrl, requestType);
}
Also used : MediaDrm(android.media.MediaDrm) SchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 64 with Assertions.checkNotNull

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

the class OfflineLicenseHelper method blockingKeyRequest.

private byte[] blockingKeyRequest(@Mode int licenseMode, @Nullable byte[] offlineLicenseKeySetId, Format format) throws DrmSessionException {
    drmSessionManager.setPlayer(handlerThread.getLooper(), PlayerId.UNSET);
    drmSessionManager.prepare();
    DrmSession drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, format);
    DrmSessionException error = drmSession.getError();
    byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
    drmSession.release(eventDispatcher);
    drmSessionManager.release();
    if (error != null) {
        throw error;
    }
    return Assertions.checkNotNull(keySetId);
}
Also used : DrmSessionException(com.google.android.exoplayer2.drm.DrmSession.DrmSessionException)

Example 65 with Assertions.checkNotNull

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

the class CacheFileMetadataIndex method set.

/**
 * Sets metadata for a given file.
 *
 * <p>This method may be slow and shouldn't normally be called on the main thread.
 *
 * @param name The name of the file.
 * @param length The file length.
 * @param lastTouchTimestamp The file last touch timestamp.
 * @throws DatabaseIOException If an error occurs setting the metadata.
 */
@WorkerThread
public void set(String name, long length, long lastTouchTimestamp) throws DatabaseIOException {
    Assertions.checkNotNull(tableName);
    try {
        SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(COLUMN_NAME, name);
        values.put(COLUMN_LENGTH, length);
        values.put(COLUMN_LAST_TOUCH_TIMESTAMP, lastTouchTimestamp);
        writableDatabase.replaceOrThrow(tableName, /* nullColumnHack= */
        null, values);
    } catch (SQLException e) {
        throw new DatabaseIOException(e);
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) DatabaseIOException(com.google.android.exoplayer2.database.DatabaseIOException) WorkerThread(androidx.annotation.WorkerThread)

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