Commit f946ade1 by tonihei

Set LogSessionId on MediaParser for progressive playbacks.

PiperOrigin-RevId: 410766492
parent f6f03866
......@@ -26,12 +26,15 @@ import android.net.Uri;
import android.util.Pair;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.source.mediaparser.InputReaderAdapterV30;
import com.google.android.exoplayer2.source.mediaparser.MediaParserUtil;
import com.google.android.exoplayer2.source.mediaparser.OutputConsumerAdapterV30;
import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException;
import java.util.List;
import java.util.Map;
......@@ -52,7 +55,7 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac
private String parserName;
@SuppressLint("WrongConstant")
public MediaParserExtractorAdapter() {
public MediaParserExtractorAdapter(PlayerId playerId) {
// TODO: Add support for injecting the desired extractor list.
outputConsumerAdapter = new OutputConsumerAdapterV30();
inputReaderAdapter = new InputReaderAdapterV30();
......@@ -61,6 +64,9 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac
mediaParser.setParameter(PARAMETER_IN_BAND_CRYPTO_INFO, true);
mediaParser.setParameter(PARAMETER_INCLUDE_SUPPLEMENTAL_DATA, true);
parserName = MediaParser.PARSER_NAME_UNKNOWN;
if (Util.SDK_INT >= 31) {
MediaParserUtil.setLogSessionIdOnMediaParser(mediaParser, playerId);
}
}
@Override
......
......@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
import android.net.Uri;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.PositionHolder;
......@@ -31,8 +32,12 @@ public interface ProgressiveMediaExtractor {
/** Creates {@link ProgressiveMediaExtractor} instances. */
interface Factory {
/** Returns a new {@link ProgressiveMediaExtractor} instance. */
ProgressiveMediaExtractor createProgressiveMediaExtractor();
/**
* Returns a new {@link ProgressiveMediaExtractor} instance.
*
* @param playerId The {@link PlayerId} of the player this extractor is used for.
*/
ProgressiveMediaExtractor createProgressiveMediaExtractor(PlayerId playerId);
}
/**
......
......@@ -77,7 +77,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* Factory(dataSourceFactory, () -> new BundledExtractorsAdapter(extractorsFactory)}.
*/
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
this(dataSourceFactory, () -> new BundledExtractorsAdapter(extractorsFactory));
this(dataSourceFactory, playerId -> new BundledExtractorsAdapter(extractorsFactory));
}
/**
......@@ -105,7 +105,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
@Deprecated
public Factory setExtractorsFactory(@Nullable ExtractorsFactory extractorsFactory) {
this.progressiveMediaExtractorFactory =
() ->
playerId ->
new BundledExtractorsAdapter(
extractorsFactory != null ? extractorsFactory : new DefaultExtractorsFactory());
return this;
......@@ -313,7 +313,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
return new ProgressiveMediaPeriod(
localConfiguration.uri,
dataSource,
progressiveMediaExtractorFactory.createProgressiveMediaExtractor(),
progressiveMediaExtractorFactory.createProgressiveMediaExtractor(getPlayerId()),
drmSessionManager,
createDrmEventDispatcher(id),
loadableLoadErrorHandlingPolicy,
......
......@@ -17,7 +17,10 @@ package com.google.android.exoplayer2.source.mediaparser;
import android.media.MediaFormat;
import android.media.MediaParser;
import android.media.metrics.LogSessionId;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.analytics.PlayerId;
/**
* Miscellaneous constants and utility methods related to the {@link MediaParser} integration.
......@@ -57,4 +60,27 @@ public final class MediaParserUtil {
}
return mediaFormat;
}
/**
* Calls {@link MediaParser#setLogSessionId(LogSessionId)}.
*
* @param mediaParser The {@link MediaParser} to call the method on.
* @param playerId The {@link PlayerId} to obtain the {@link LogSessionId} from.
*/
@RequiresApi(31)
public static void setLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId) {
Api31.setLogSessionIdOnMediaParser(mediaParser, playerId);
}
@RequiresApi(31)
private static final class Api31 {
private Api31() {}
public static void setLogSessionIdOnMediaParser(MediaParser mediaParser, PlayerId playerId) {
LogSessionId logSessionId = playerId.getLogSessionId();
if (!logSessionId.equals(LogSessionId.LOG_SESSION_ID_NONE)) {
mediaParser.setLogSessionId(logSessionId);
}
}
}
}
......@@ -22,6 +22,7 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
......@@ -48,7 +49,8 @@ public final class ProgressiveMediaPeriodTest {
@Test
public void prepareUsingMediaParser_updatesSourceInfoBeforeOnPreparedCallback()
throws TimeoutException {
testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(new MediaParserExtractorAdapter());
testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(
new MediaParserExtractorAdapter(PlayerId.UNSET));
}
private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment