Commit f946ade1 by tonihei

Set LogSessionId on MediaParser for progressive playbacks.

PiperOrigin-RevId: 410766492
parent f6f03866
...@@ -26,12 +26,15 @@ import android.net.Uri; ...@@ -26,12 +26,15 @@ import android.net.Uri;
import android.util.Pair; import android.util.Pair;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C; 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.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.PositionHolder; import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.source.mediaparser.InputReaderAdapterV30; 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.source.mediaparser.OutputConsumerAdapterV30;
import com.google.android.exoplayer2.upstream.DataReader; import com.google.android.exoplayer2.upstream.DataReader;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -52,7 +55,7 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac ...@@ -52,7 +55,7 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac
private String parserName; private String parserName;
@SuppressLint("WrongConstant") @SuppressLint("WrongConstant")
public MediaParserExtractorAdapter() { public MediaParserExtractorAdapter(PlayerId playerId) {
// TODO: Add support for injecting the desired extractor list. // TODO: Add support for injecting the desired extractor list.
outputConsumerAdapter = new OutputConsumerAdapterV30(); outputConsumerAdapter = new OutputConsumerAdapterV30();
inputReaderAdapter = new InputReaderAdapterV30(); inputReaderAdapter = new InputReaderAdapterV30();
...@@ -61,6 +64,9 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac ...@@ -61,6 +64,9 @@ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtrac
mediaParser.setParameter(PARAMETER_IN_BAND_CRYPTO_INFO, true); mediaParser.setParameter(PARAMETER_IN_BAND_CRYPTO_INFO, true);
mediaParser.setParameter(PARAMETER_INCLUDE_SUPPLEMENTAL_DATA, true); mediaParser.setParameter(PARAMETER_INCLUDE_SUPPLEMENTAL_DATA, true);
parserName = MediaParser.PARSER_NAME_UNKNOWN; parserName = MediaParser.PARSER_NAME_UNKNOWN;
if (Util.SDK_INT >= 31) {
MediaParserUtil.setLogSessionIdOnMediaParser(mediaParser, playerId);
}
} }
@Override @Override
......
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source;
import android.net.Uri; import android.net.Uri;
import com.google.android.exoplayer2.C; 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.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorOutput; import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.PositionHolder; import com.google.android.exoplayer2.extractor.PositionHolder;
...@@ -31,8 +32,12 @@ public interface ProgressiveMediaExtractor { ...@@ -31,8 +32,12 @@ public interface ProgressiveMediaExtractor {
/** Creates {@link ProgressiveMediaExtractor} instances. */ /** Creates {@link ProgressiveMediaExtractor} instances. */
interface Factory { 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 ...@@ -77,7 +77,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
* Factory(dataSourceFactory, () -> new BundledExtractorsAdapter(extractorsFactory)}. * Factory(dataSourceFactory, () -> new BundledExtractorsAdapter(extractorsFactory)}.
*/ */
public Factory(DataSource.Factory dataSourceFactory, ExtractorsFactory 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 ...@@ -105,7 +105,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
@Deprecated @Deprecated
public Factory setExtractorsFactory(@Nullable ExtractorsFactory extractorsFactory) { public Factory setExtractorsFactory(@Nullable ExtractorsFactory extractorsFactory) {
this.progressiveMediaExtractorFactory = this.progressiveMediaExtractorFactory =
() -> playerId ->
new BundledExtractorsAdapter( new BundledExtractorsAdapter(
extractorsFactory != null ? extractorsFactory : new DefaultExtractorsFactory()); extractorsFactory != null ? extractorsFactory : new DefaultExtractorsFactory());
return this; return this;
...@@ -313,7 +313,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource ...@@ -313,7 +313,7 @@ public final class ProgressiveMediaSource extends BaseMediaSource
return new ProgressiveMediaPeriod( return new ProgressiveMediaPeriod(
localConfiguration.uri, localConfiguration.uri,
dataSource, dataSource,
progressiveMediaExtractorFactory.createProgressiveMediaExtractor(), progressiveMediaExtractorFactory.createProgressiveMediaExtractor(getPlayerId()),
drmSessionManager, drmSessionManager,
createDrmEventDispatcher(id), createDrmEventDispatcher(id),
loadableLoadErrorHandlingPolicy, loadableLoadErrorHandlingPolicy,
......
...@@ -17,7 +17,10 @@ package com.google.android.exoplayer2.source.mediaparser; ...@@ -17,7 +17,10 @@ package com.google.android.exoplayer2.source.mediaparser;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.media.MediaParser; import android.media.MediaParser;
import android.media.metrics.LogSessionId;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.analytics.PlayerId;
/** /**
* Miscellaneous constants and utility methods related to the {@link MediaParser} integration. * Miscellaneous constants and utility methods related to the {@link MediaParser} integration.
...@@ -57,4 +60,27 @@ public final class MediaParserUtil { ...@@ -57,4 +60,27 @@ public final class MediaParserUtil {
} }
return mediaFormat; 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; ...@@ -22,6 +22,7 @@ import android.net.Uri;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; 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.DrmSessionEventListener;
import com.google.android.exoplayer2.drm.DrmSessionManager; import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor; import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
...@@ -48,7 +49,8 @@ public final class ProgressiveMediaPeriodTest { ...@@ -48,7 +49,8 @@ public final class ProgressiveMediaPeriodTest {
@Test @Test
public void prepareUsingMediaParser_updatesSourceInfoBeforeOnPreparedCallback() public void prepareUsingMediaParser_updatesSourceInfoBeforeOnPreparedCallback()
throws TimeoutException { throws TimeoutException {
testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(new MediaParserExtractorAdapter()); testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback(
new MediaParserExtractorAdapter(PlayerId.UNSET));
} }
private static void testExtractorsUpdatesSourceInfoBeforeOnPreparedCallback( 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