Set LogSessionId on MediaParser for DASH sources.

This requires some plumbing through DashMediaPeriod and DashChunkSource.

PiperOrigin-RevId: 411012115
This commit is contained in:
tonihei 2021-11-19 10:33:51 +00:00
parent 4a0ea37aae
commit 9deba6204e
9 changed files with 54 additions and 17 deletions

View file

@ -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)) {

View file

@ -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<Format> closedCaptionFormats,
@Nullable TrackOutput playerEmsgTrackOutput);
@Nullable TrackOutput playerEmsgTrackOutput,
PlayerId playerId);
}
/** Provides {@link TrackOutput} instances to be written to during extraction. */

View file

@ -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<Format> closedCaptionFormats) {
@C.TrackType int primaryTrackType,
Format manifestFormat,
List<Format> 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();

View file

@ -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<Format> closedCaptionFormats,
@Nullable PlayerTrackEmsgHandler playerEmsgHandler,
@Nullable TransferListener transferListener);
@Nullable TransferListener transferListener,
PlayerId playerId);
}
/**

View file

@ -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<DashChunkSource>[] 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<DashChunkSource> stream =
new ChunkSampleStream<>(
trackGroupInfo.trackType,

View file

@ -598,7 +598,8 @@ public final class DashMediaSource extends BaseMediaSource {
manifestLoadErrorThrower,
allocator,
compositeSequenceableLoaderFactory,
playerEmsgCallback);
playerEmsgCallback,
getPlayerId());
periodsById.put(mediaPeriod.id, mediaPeriod);
return mediaPeriod;
}

View file

@ -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<Format> 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<Format> 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());
}

View file

@ -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 {

View file

@ -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(