From 9deba6204ed353cbaa2f4a67b79b2523d9bc6c4b Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 19 Nov 2021 10:33:51 +0000 Subject: [PATCH] Set LogSessionId on MediaParser for DASH sources. This requires some plumbing through DashMediaPeriod and DashChunkSource. PiperOrigin-RevId: 411012115 --- .../source/chunk/BundledChunkExtractor.java | 3 ++- .../exoplayer2/source/chunk/ChunkExtractor.java | 6 +++++- .../source/chunk/MediaParserChunkExtractor.java | 17 ++++++++++++++--- .../exoplayer2/source/dash/DashChunkSource.java | 5 ++++- .../exoplayer2/source/dash/DashMediaPeriod.java | 9 +++++++-- .../exoplayer2/source/dash/DashMediaSource.java | 3 ++- .../source/dash/DefaultDashChunkSource.java | 14 ++++++++++---- .../source/dash/DashMediaPeriodTest.java | 4 +++- .../source/dash/DefaultDashChunkSourceTest.java | 10 +++++++--- 9 files changed, 54 insertions(+), 17 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BundledChunkExtractor.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BundledChunkExtractor.java index e2e3ae0914..5b2362f3e1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BundledChunkExtractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/BundledChunkExtractor.java @@ -51,7 +51,8 @@ public final class BundledChunkExtractor implements ExtractorOutput, ChunkExtrac format, enableEventMessageTrack, closedCaptionFormats, - playerEmsgTrackOutput) -> { + playerEmsgTrackOutput, + playerId) -> { @Nullable String containerMimeType = format.containerMimeType; Extractor extractor; if (MimeTypes.isText(containerMimeType)) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractor.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractor.java index c1e1762163..afbf4eebf1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkExtractor.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.chunk; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.extractor.ChunkIndex; import com.google.android.exoplayer2.extractor.ExtractorInput; import com.google.android.exoplayer2.extractor.TrackOutput; @@ -42,6 +43,8 @@ public interface ChunkExtractor { * @param representationFormat The format of the representation to extract from. * @param enableEventMessageTrack Whether to enable the event message track. * @param closedCaptionFormats The {@link Format Formats} of the Closed-Caption tracks. + * @param playerEmsgTrackOutput The {@link TrackOutput} for extracted EMSG messages, or null. + * @param playerId The {@link PlayerId} of the player using this chunk extractor. * @return A new {@link ChunkExtractor} instance, or null if not applicable. */ @Nullable @@ -50,7 +53,8 @@ public interface ChunkExtractor { Format representationFormat, boolean enableEventMessageTrack, List closedCaptionFormats, - @Nullable TrackOutput playerEmsgTrackOutput); + @Nullable TrackOutput playerEmsgTrackOutput, + PlayerId playerId); } /** Provides {@link TrackOutput} instances to be written to during extraction. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/MediaParserChunkExtractor.java b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/MediaParserChunkExtractor.java index e04ee5cf4a..9f367aa876 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/MediaParserChunkExtractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/chunk/MediaParserChunkExtractor.java @@ -30,6 +30,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.extractor.ChunkIndex; import com.google.android.exoplayer2.extractor.DummyTrackOutput; import com.google.android.exoplayer2.extractor.ExtractorInput; @@ -42,6 +43,7 @@ import com.google.android.exoplayer2.source.mediaparser.OutputConsumerAdapterV30 import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.MimeTypes; +import com.google.android.exoplayer2.util.Util; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -58,10 +60,12 @@ public final class MediaParserChunkExtractor implements ChunkExtractor { format, enableEventMessageTrack, closedCaptionFormats, - playerEmsgTrackOutput) -> { + playerEmsgTrackOutput, + playerId) -> { if (!MimeTypes.isText(format.containerMimeType)) { // Container is either Matroska or Fragmented MP4. - return new MediaParserChunkExtractor(primaryTrackType, format, closedCaptionFormats); + return new MediaParserChunkExtractor( + primaryTrackType, format, closedCaptionFormats, playerId); } else { // This is either RAWCC (unsupported) or a text track that does not require an extractor. Log.w(TAG, "Ignoring an unsupported text track."); @@ -86,10 +90,14 @@ public final class MediaParserChunkExtractor implements ChunkExtractor { * @param manifestFormat The chunks {@link Format} as obtained from the manifest. * @param closedCaptionFormats A list containing the {@link Format Formats} of the closed-caption * tracks in the chunks. + * @param playerId The {@link PlayerId} of the player this chunk extractor is used for. */ @SuppressLint("WrongConstant") public MediaParserChunkExtractor( - @C.TrackType int primaryTrackType, Format manifestFormat, List closedCaptionFormats) { + @C.TrackType int primaryTrackType, + Format manifestFormat, + List closedCaptionFormats, + PlayerId playerId) { outputConsumerAdapter = new OutputConsumerAdapterV30( manifestFormat, primaryTrackType, /* expectDummySeekMap= */ true); @@ -114,6 +122,9 @@ public final class MediaParserChunkExtractor implements ChunkExtractor { MediaParserUtil.toCaptionsMediaFormat(closedCaptionFormats.get(i))); } mediaParser.setParameter(PARAMETER_EXPOSE_CAPTION_FORMATS, closedCaptionMediaFormats); + if (Util.SDK_INT >= 31) { + MediaParserUtil.setLogSessionIdOnMediaParser(mediaParser, playerId); + } outputConsumerAdapter.setMuxedCaptionFormats(closedCaptionFormats); trackOutputProviderAdapter = new TrackOutputProviderAdapter(); dummyTrackOutput = new DummyTrackOutput(); diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashChunkSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashChunkSource.java index 0cd6ac1c11..9897575081 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashChunkSource.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashChunkSource.java @@ -19,6 +19,7 @@ import android.os.SystemClock; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.source.chunk.ChunkSource; import com.google.android.exoplayer2.source.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler; import com.google.android.exoplayer2.source.dash.manifest.DashManifest; @@ -49,6 +50,7 @@ public interface DashChunkSource extends ChunkSource { * @param closedCaptionFormats The {@link Format Formats} of closed caption tracks to be output. * @param transferListener The transfer listener which should be informed of any data transfers. * May be null if no listener is available. + * @param playerId The {@link PlayerId} of the player using this chunk source. * @return The created {@link DashChunkSource}. */ DashChunkSource createDashChunkSource( @@ -63,7 +65,8 @@ public interface DashChunkSource extends ChunkSource { boolean enableEventMessageTrack, List closedCaptionFormats, @Nullable PlayerTrackEmsgHandler playerEmsgHandler, - @Nullable TransferListener transferListener); + @Nullable TransferListener transferListener, + PlayerId playerId); } /** diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java index 062117563d..33b9fb2fcc 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java @@ -25,6 +25,7 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.SeekParameters; +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.offline.StreamKey; @@ -96,6 +97,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; trackEmsgHandlerBySampleStream; private final MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher; private final DrmSessionEventListener.EventDispatcher drmEventDispatcher; + private final PlayerId playerId; @Nullable private Callback callback; private ChunkSampleStream[] sampleStreams; @@ -120,7 +122,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; LoaderErrorThrower manifestLoaderErrorThrower, Allocator allocator, CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory, - PlayerEmsgCallback playerEmsgCallback) { + PlayerEmsgCallback playerEmsgCallback, + PlayerId playerId) { this.id = id; this.manifest = manifest; this.baseUrlExclusionList = baseUrlExclusionList; @@ -135,6 +138,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; this.manifestLoaderErrorThrower = manifestLoaderErrorThrower; this.allocator = allocator; this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory; + this.playerId = playerId; playerEmsgHandler = new PlayerEmsgHandler(manifest, playerEmsgCallback, allocator); sampleStreams = newSampleStreamArray(0); eventSampleStreams = new EventSampleStream[0]; @@ -777,7 +781,8 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; enableEventMessageTrack, embeddedClosedCaptionTrackFormats, trackPlayerEmsgHandler, - transferListener); + transferListener, + playerId); ChunkSampleStream stream = new ChunkSampleStream<>( trackGroupInfo.trackType, diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java index 701e07f71b..d3a490b08b 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java @@ -598,7 +598,8 @@ public final class DashMediaSource extends BaseMediaSource { manifestLoadErrorThrower, allocator, compositeSequenceableLoaderFactory, - playerEmsgCallback); + playerEmsgCallback, + getPlayerId()); periodsById.put(mediaPeriod.id, mediaPeriod); return mediaPeriod; } diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java index 3d850161df..aaca62086a 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSource.java @@ -25,6 +25,7 @@ import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.SeekParameters; +import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.extractor.ChunkIndex; import com.google.android.exoplayer2.source.BehindLiveWindowException; import com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator; @@ -110,7 +111,8 @@ public class DefaultDashChunkSource implements DashChunkSource { boolean enableEventMessageTrack, List closedCaptionFormats, @Nullable PlayerTrackEmsgHandler playerEmsgHandler, - @Nullable TransferListener transferListener) { + @Nullable TransferListener transferListener, + PlayerId playerId) { DataSource dataSource = dataSourceFactory.createDataSource(); if (transferListener != null) { dataSource.addTransferListener(transferListener); @@ -129,7 +131,8 @@ public class DefaultDashChunkSource implements DashChunkSource { maxSegmentsPerLoad, enableEventMessageTrack, closedCaptionFormats, - playerEmsgHandler); + playerEmsgHandler, + playerId); } } @@ -171,6 +174,7 @@ public class DefaultDashChunkSource implements DashChunkSource { * @param closedCaptionFormats The {@link Format Formats} of closed caption tracks to be output. * @param playerTrackEmsgHandler The {@link PlayerTrackEmsgHandler} instance to handle emsg * messages targeting the player. Maybe null if this is not necessary. + * @param playerId The {@link PlayerId} of the player using this chunk source. */ public DefaultDashChunkSource( ChunkExtractor.Factory chunkExtractorFactory, @@ -186,7 +190,8 @@ public class DefaultDashChunkSource implements DashChunkSource { int maxSegmentsPerLoad, boolean enableEventMessageTrack, List closedCaptionFormats, - @Nullable PlayerTrackEmsgHandler playerTrackEmsgHandler) { + @Nullable PlayerTrackEmsgHandler playerTrackEmsgHandler, + PlayerId playerId) { this.manifestLoaderErrorThrower = manifestLoaderErrorThrower; this.manifest = manifest; this.baseUrlExclusionList = baseUrlExclusionList; @@ -217,7 +222,8 @@ public class DefaultDashChunkSource implements DashChunkSource { representation.format, enableEventMessageTrack, closedCaptionFormats, - playerTrackEmsgHandler), + playerTrackEmsgHandler, + playerId), /* segmentNumShift= */ 0, representation.getIndex()); } diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DashMediaPeriodTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DashMediaPeriodTest.java index 5c7600ee51..2938fe534f 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DashMediaPeriodTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DashMediaPeriodTest.java @@ -21,6 +21,7 @@ import android.net.Uri; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.Format; +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.source.CompositeSequenceableLoaderFactory; @@ -212,7 +213,8 @@ public final class DashMediaPeriodTest { mock(LoaderErrorThrower.class), mock(Allocator.class), mock(CompositeSequenceableLoaderFactory.class), - mock(PlayerEmsgCallback.class)); + mock(PlayerEmsgCallback.class), + PlayerId.UNSET); } private static DashManifest parseManifest(String fileName) throws IOException { diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSourceTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSourceTest.java index 7343c07bff..f43be2c9bf 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSourceTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/DefaultDashChunkSourceTest.java @@ -26,6 +26,7 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; +import com.google.android.exoplayer2.analytics.PlayerId; import com.google.android.exoplayer2.source.LoadEventInfo; import com.google.android.exoplayer2.source.MediaLoadData; import com.google.android.exoplayer2.source.TrackGroup; @@ -95,7 +96,8 @@ public class DefaultDashChunkSourceTest { /* maxSegmentsPerLoad= */ 1, /* enableEventMessageTrack= */ false, /* closedCaptionFormats */ ImmutableList.of(), - /* playerTrackEmsgHandler= */ null); + /* playerTrackEmsgHandler= */ null, + PlayerId.UNSET); long nowInPeriodUs = Util.msToUs(nowMs - manifest.availabilityStartTimeMs); ChunkHolder output = new ChunkHolder(); @@ -143,7 +145,8 @@ public class DefaultDashChunkSourceTest { /* maxSegmentsPerLoad= */ 1, /* enableEventMessageTrack= */ false, /* closedCaptionFormats */ ImmutableList.of(), - /* playerTrackEmsgHandler= */ null); + /* playerTrackEmsgHandler= */ null, + PlayerId.UNSET); ChunkHolder output = new ChunkHolder(); chunkSource.getNextChunk( @@ -326,7 +329,8 @@ public class DefaultDashChunkSourceTest { /* maxSegmentsPerLoad= */ 1, /* enableEventMessageTrack= */ false, /* closedCaptionFormats */ ImmutableList.of(), - /* playerTrackEmsgHandler= */ null); + /* playerTrackEmsgHandler= */ null, + PlayerId.UNSET); } private LoadErrorHandlingPolicy.LoadErrorInfo createFakeLoadErrorInfo(