Java Code Examples for com.google.android.exoplayer2.C#TRACK_TYPE_VIDEO

The following examples show how to use com.google.android.exoplayer2.C#TRACK_TYPE_VIDEO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MimeTypes.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the {@link C}{@code .TRACK_TYPE_*} constant that corresponds to a specified MIME type.
 * {@link C#TRACK_TYPE_UNKNOWN} if the MIME type is not known or the mapping cannot be
 * established.
 *
 * @param mimeType The MIME type.
 * @return The {@link C}{@code .TRACK_TYPE_*} constant that corresponds to a specified MIME type.
 */
public static int getTrackType(@Nullable String mimeType) {
  if (TextUtils.isEmpty(mimeType)) {
    return C.TRACK_TYPE_UNKNOWN;
  } else if (isAudio(mimeType)) {
    return C.TRACK_TYPE_AUDIO;
  } else if (isVideo(mimeType)) {
    return C.TRACK_TYPE_VIDEO;
  } else if (isText(mimeType) || APPLICATION_CEA608.equals(mimeType)
      || APPLICATION_CEA708.equals(mimeType) || APPLICATION_MP4CEA608.equals(mimeType)
      || APPLICATION_SUBRIP.equals(mimeType) || APPLICATION_TTML.equals(mimeType)
      || APPLICATION_TX3G.equals(mimeType) || APPLICATION_MP4VTT.equals(mimeType)
      || APPLICATION_RAWCC.equals(mimeType) || APPLICATION_VOBSUB.equals(mimeType)
      || APPLICATION_PGS.equals(mimeType) || APPLICATION_DVBSUBS.equals(mimeType)) {
    return C.TRACK_TYPE_TEXT;
  } else if (APPLICATION_ID3.equals(mimeType)
      || APPLICATION_EMSG.equals(mimeType)
      || APPLICATION_SCTE35.equals(mimeType)) {
    return C.TRACK_TYPE_METADATA;
  } else if (APPLICATION_CAMERA_MOTION.equals(mimeType)) {
    return C.TRACK_TYPE_CAMERA_MOTION;
  } else {
    return getTrackTypeForCustomMimeType(mimeType);
  }
}
 
Example 2
Source File: EventLogger.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static String getTrackTypeString(int trackType) {
  switch (trackType) {
    case C.TRACK_TYPE_AUDIO:
      return "audio";
    case C.TRACK_TYPE_DEFAULT:
      return "default";
    case C.TRACK_TYPE_METADATA:
      return "metadata";
    case C.TRACK_TYPE_CAMERA_MOTION:
      return "camera motion";
    case C.TRACK_TYPE_NONE:
      return "none";
    case C.TRACK_TYPE_TEXT:
      return "text";
    case C.TRACK_TYPE_VIDEO:
      return "video";
    default:
      return trackType >= C.TRACK_TYPE_CUSTOM_BASE ? "custom (" + trackType + ")" : "?";
  }
}
 
Example 3
Source File: PlaybackStatsListener.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies the tracker that the track selection for the current playback changed.
 *
 * @param eventTime The {@link EventTime}.
 * @param trackSelections The new {@link TrackSelectionArray}.
 */
public void onTracksChanged(EventTime eventTime, TrackSelectionArray trackSelections) {
  boolean videoEnabled = false;
  boolean audioEnabled = false;
  for (TrackSelection trackSelection : trackSelections.getAll()) {
    if (trackSelection != null && trackSelection.length() > 0) {
      int trackType = MimeTypes.getTrackType(trackSelection.getFormat(0).sampleMimeType);
      if (trackType == C.TRACK_TYPE_VIDEO) {
        videoEnabled = true;
      } else if (trackType == C.TRACK_TYPE_AUDIO) {
        audioEnabled = true;
      }
    }
  }
  if (!videoEnabled) {
    maybeUpdateVideoFormat(eventTime, /* newFormat= */ null);
  }
  if (!audioEnabled) {
    maybeUpdateAudioFormat(eventTime, /* newFormat= */ null);
  }
}
 
Example 4
Source File: Util.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a string representation of a {@code TRACK_TYPE_*} constant defined in {@link C}.
 *
 * @param trackType A {@code TRACK_TYPE_*} constant,
 * @return A string representation of this constant.
 */
public static String getTrackTypeString(int trackType) {
  switch (trackType) {
    case C.TRACK_TYPE_AUDIO:
      return "audio";
    case C.TRACK_TYPE_DEFAULT:
      return "default";
    case C.TRACK_TYPE_METADATA:
      return "metadata";
    case C.TRACK_TYPE_CAMERA_MOTION:
      return "camera motion";
    case C.TRACK_TYPE_NONE:
      return "none";
    case C.TRACK_TYPE_TEXT:
      return "text";
    case C.TRACK_TYPE_VIDEO:
      return "video";
    default:
      return trackType >= C.TRACK_TYPE_CUSTOM_BASE ? "custom (" + trackType + ")" : "?";
  }
}
 
Example 5
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Maps a {@link C} {@code TRACK_TYPE_*} constant to the corresponding {@link C}
 * {@code DEFAULT_*_BUFFER_SIZE} constant.
 *
 * @param trackType The track type.
 * @return The corresponding default buffer size in bytes.
 */
public static int getDefaultBufferSize(int trackType) {
  switch (trackType) {
    case C.TRACK_TYPE_DEFAULT:
      return C.DEFAULT_MUXED_BUFFER_SIZE;
    case C.TRACK_TYPE_AUDIO:
      return C.DEFAULT_AUDIO_BUFFER_SIZE;
    case C.TRACK_TYPE_VIDEO:
      return C.DEFAULT_VIDEO_BUFFER_SIZE;
    case C.TRACK_TYPE_TEXT:
      return C.DEFAULT_TEXT_BUFFER_SIZE;
    case C.TRACK_TYPE_METADATA:
      return C.DEFAULT_METADATA_BUFFER_SIZE;
    default:
      throw new IllegalStateException();
  }
}
 
Example 6
Source File: SoftVideoRenderer.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
/**
 * @param scaleToFit Whether video frames should be scaled to fit when rendering.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param maxDroppedFramesToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link VideoRendererEventListener#onDroppedFrames(int, long)}.
 * @param drmSessionManager For use with encrypted media. May be null if support for encrypted
 *     media is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisition. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 */
public SoftVideoRenderer(boolean scaleToFit, long allowedJoiningTimeMs,
                         Handler eventHandler, VideoRendererEventListener eventListener,
                         int maxDroppedFramesToNotify, DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
                         boolean playClearSamplesWithoutKeys) {
  super(C.TRACK_TYPE_VIDEO);
  this.scaleToFit = scaleToFit;
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.drmSessionManager = drmSessionManager;
  this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
  this.outputBufferRenderer = new FrameRenderer();
  joiningDeadlineMs = C.TIME_UNSET;
  clearReportedVideoSize();
  formatHolder = new FormatHolder();
  flagsOnlyBuffer = DecoderInputBuffer.newFlagsOnlyInstance();
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  decoderReinitializationState = REINITIALIZATION_STATE_NONE;
}
 
Example 7
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private SampleQueue createSampleQueue(int id, int type) {
  int trackCount = sampleQueues.length;

  SampleQueue trackOutput = new PrivTimestampStrippingSampleQueue(allocator);
  trackOutput.setSampleOffsetUs(sampleOffsetUs);
  trackOutput.sourceId(chunkUid);
  trackOutput.setUpstreamFormatChangeListener(this);
  sampleQueueTrackIds = Arrays.copyOf(sampleQueueTrackIds, trackCount + 1);
  sampleQueueTrackIds[trackCount] = id;
  sampleQueues = Arrays.copyOf(sampleQueues, trackCount + 1);
  sampleQueues[trackCount] = trackOutput;
  sampleQueueIsAudioVideoFlags = Arrays.copyOf(sampleQueueIsAudioVideoFlags, trackCount + 1);
  sampleQueueIsAudioVideoFlags[trackCount] =
      type == C.TRACK_TYPE_AUDIO || type == C.TRACK_TYPE_VIDEO;
  haveAudioVideoSampleQueues |= sampleQueueIsAudioVideoFlags[trackCount];
  sampleQueueMappingDoneByType.add(type);
  sampleQueueIndicesByType.append(type, trackCount);
  if (getTrackTypeScore(type) > getTrackTypeScore(primarySampleQueueType)) {
    primarySampleQueueIndex = trackCount;
    primarySampleQueueType = type;
  }
  sampleQueuesEnabledStates = Arrays.copyOf(sampleQueuesEnabledStates, trackCount + 1);
  return trackOutput;
}
 
Example 8
Source File: SsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    if (sampleStream.primaryTrackType == C.TRACK_TYPE_VIDEO) {
      return sampleStream.getAdjustedSeekPositionUs(positionUs, seekParameters);
    }
  }
  return positionUs;
}
 
Example 9
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example 10
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  for (ChunkSampleStream<SsChunkSource> sampleStream : sampleStreams) {
    if (sampleStream.primaryTrackType == C.TRACK_TYPE_VIDEO) {
      return sampleStream.getAdjustedSeekPositionUs(positionUs, seekParameters);
    }
  }
  return positionUs;
}
 
Example 11
Source File: ExoPlayerView.java    From react-native-video with MIT License 5 votes vote down vote up
private void updateForCurrentTrackSelections() {
    if (player == null) {
        return;
    }
    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            // Video enabled so artwork must be hidden. If the shutter is closed, it will be opened in
            // onRenderedFirstFrame().
            return;
        }
    }
    // Video disabled so the shutter must be closed.
    shutterView.setVisibility(VISIBLE);
}
 
Example 12
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example 13
Source File: RendererTrackIndexExtractorTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public int getRendererTypeFor(int index) {
    if (index == 0) {
        return C.TRACK_TYPE_VIDEO;
    }

    return -1;
}
 
Example 14
Source File: MediaCodecVideoRenderer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param context A context.
 * @param mediaCodecSelector A decoder selector.
 * @param allowedJoiningTimeMs The maximum duration in milliseconds for which this video renderer
 *     can attempt to seamlessly join an ongoing playback.
 * @param drmSessionManager For use with encrypted content. May be null if support for encrypted
 *     content is not required.
 * @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
 *     For example a media file may start with a short clear region so as to allow playback to
 *     begin in parallel with key acquisition. This parameter specifies whether the renderer is
 *     permitted to play clear regions of encrypted media files before {@code drmSessionManager}
 *     has obtained the keys necessary to decrypt encrypted regions of the media.
 * @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
 *     null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param maxDroppedFramesToNotify The maximum number of frames that can be dropped between
 *     invocations of {@link VideoRendererEventListener#onDroppedFrames(int, long)}.
 */
public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector,
    long allowedJoiningTimeMs,
    @Nullable DrmSessionManager<FrameworkMediaCrypto> drmSessionManager,
    boolean playClearSamplesWithoutKeys, @Nullable Handler eventHandler,
    @Nullable VideoRendererEventListener eventListener, int maxDroppedFramesToNotify) {
  super(
      C.TRACK_TYPE_VIDEO,
      mediaCodecSelector,
      drmSessionManager,
      playClearSamplesWithoutKeys,
      /* assumedMinimumCodecOperatingRate= */ 30);
  this.allowedJoiningTimeMs = allowedJoiningTimeMs;
  this.maxDroppedFramesToNotify = maxDroppedFramesToNotify;
  this.context = context.getApplicationContext();
  frameReleaseTimeHelper = new VideoFrameReleaseTimeHelper(this.context);
  eventDispatcher = new EventDispatcher(eventHandler, eventListener);
  deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
  pendingOutputStreamOffsetsUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  pendingOutputStreamSwitchTimesUs = new long[MAX_PENDING_OUTPUT_STREAM_OFFSET_COUNT];
  outputStreamOffsetUs = C.TIME_UNSET;
  lastInputTimeUs = C.TIME_UNSET;
  joiningDeadlineMs = C.TIME_UNSET;
  currentWidth = Format.NO_VALUE;
  currentHeight = Format.NO_VALUE;
  currentPixelWidthHeightRatio = Format.NO_VALUE;
  pendingPixelWidthHeightRatio = Format.NO_VALUE;
  scalingMode = C.VIDEO_SCALING_MODE_DEFAULT;
  clearReportedVideoSize();
}
 
Example 15
Source File: HlsSampleStreamWrapper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Scores a track type. Where multiple tracks are muxed into a container, the track with the
 * highest score is the primary track.
 *
 * @param trackType The track type.
 * @return The score.
 */
private static int getTrackTypeScore(int trackType) {
  switch (trackType) {
    case C.TRACK_TYPE_VIDEO:
      return 3;
    case C.TRACK_TYPE_AUDIO:
      return 2;
    case C.TRACK_TYPE_TEXT:
      return 1;
    default:
      return 0;
  }
}
 
Example 16
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Scores a track type. Where multiple tracks are muxed into a container, the track with the
 * highest score is the primary track.
 *
 * @param trackType The track type.
 * @return The score.
 */
private static int getTrackTypeScore(int trackType) {
  switch (trackType) {
    case C.TRACK_TYPE_VIDEO:
      return 3;
    case C.TRACK_TYPE_AUDIO:
      return 2;
    case C.TRACK_TYPE_TEXT:
      return 1;
    default:
      return 0;
  }
}
 
Example 17
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
protected int parseContentType(XmlPullParser xpp) {
  String contentType = xpp.getAttributeValue(null, "contentType");
  return TextUtils.isEmpty(contentType) ? C.TRACK_TYPE_UNKNOWN
      : MimeTypes.BASE_TYPE_AUDIO.equals(contentType) ? C.TRACK_TYPE_AUDIO
      : MimeTypes.BASE_TYPE_VIDEO.equals(contentType) ? C.TRACK_TYPE_VIDEO
      : MimeTypes.BASE_TYPE_TEXT.equals(contentType) ? C.TRACK_TYPE_TEXT
      : C.TRACK_TYPE_UNKNOWN;
}
 
Example 18
Source File: CustomizePlayerView.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
private void updateForCurrentTrackSelections(boolean isNewPlayer) {
    if (player == null || player.getCurrentTrackGroups().isEmpty()) {
        if (!keepContentOnPlayerReset) {
            hideArtwork();
            closeShutter();
        }
        return;
    }

    if (isNewPlayer && !keepContentOnPlayerReset) {
        closeShutter();
    }

    TrackSelectionArray selections = player.getCurrentTrackSelections();
    for (int i = 0; i < selections.length; i++) {
        if (player.getRendererType(i) == C.TRACK_TYPE_VIDEO && selections.get(i) != null) {
            hideArtwork();
            return;
        }
    }

    closeShutter();
    if (useArtwork) {
        for (int i = 0; i < selections.length; i++) {
            TrackSelection selection = selections.get(i);
            if (selection != null) {
                for (int j = 0; j < selection.length(); j++) {
                    Metadata metadata = selection.getFormat(j).metadata;
                    if (metadata != null && setArtworkFromMetadata(metadata)) {
                        return;
                    }
                }
            }
        }
        if (setArtworkFromBitmap(defaultArtwork)) {
            return;
        }
    }
    // Artwork disabled or unavailable.
    hideArtwork();
}
 
Example 19
Source File: DefaultTrackSelector.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Called from {@link #selectTracks(MappedTrackInfo, int[][][], int[])} to make a track selection
 * for each renderer, prior to overrides and disabled flags being applied.
 *
 * <p>The implementation should not account for overrides and disabled flags. Track selections
 * generated by this method will be overridden to account for these properties.
 *
 * @param mappedTrackInfo Mapped track information.
 * @param rendererFormatSupports The result of {@link RendererCapabilities#supportsFormat} for
 *     each mapped track, indexed by renderer, track group and track (in that order).
 * @param rendererMixedMimeTypeAdaptationSupports The result of {@link
 *     RendererCapabilities#supportsMixedMimeTypeAdaptation()} for each renderer.
 * @return Track selections for each renderer. A null selection indicates the renderer should be
 *     disabled, unless RendererCapabilities#getTrackType()} is {@link C#TRACK_TYPE_NONE}.
 * @throws ExoPlaybackException If an error occurs while selecting the tracks.
 */
protected @NullableType TrackSelection[] selectAllTracks(
    MappedTrackInfo mappedTrackInfo,
    int[][][] rendererFormatSupports,
    int[] rendererMixedMimeTypeAdaptationSupports,
    Parameters params)
    throws ExoPlaybackException {
  int rendererCount = mappedTrackInfo.getRendererCount();
  @NullableType TrackSelection[] rendererTrackSelections = new TrackSelection[rendererCount];

  boolean seenVideoRendererWithMappedTracks = false;
  boolean selectedVideoTracks = false;
  for (int i = 0; i < rendererCount; i++) {
    if (C.TRACK_TYPE_VIDEO == mappedTrackInfo.getRendererType(i)) {
      if (!selectedVideoTracks) {
        rendererTrackSelections[i] =
            selectVideoTrack(
                mappedTrackInfo.getTrackGroups(i),
                rendererFormatSupports[i],
                rendererMixedMimeTypeAdaptationSupports[i],
                params,
                adaptiveTrackSelectionFactory);
        selectedVideoTracks = rendererTrackSelections[i] != null;
      }
      seenVideoRendererWithMappedTracks |= mappedTrackInfo.getTrackGroups(i).length > 0;
    }
  }

  boolean selectedAudioTracks = false;
  boolean selectedTextTracks = false;
  for (int i = 0; i < rendererCount; i++) {
    int trackType = mappedTrackInfo.getRendererType(i);
    switch (trackType) {
      case C.TRACK_TYPE_VIDEO:
        // Already done. Do nothing.
        break;
      case C.TRACK_TYPE_AUDIO:
        if (!selectedAudioTracks) {
          rendererTrackSelections[i] =
              selectAudioTrack(
                  mappedTrackInfo.getTrackGroups(i),
                  rendererFormatSupports[i],
                  rendererMixedMimeTypeAdaptationSupports[i],
                  params,
                  seenVideoRendererWithMappedTracks ? null : adaptiveTrackSelectionFactory);
          selectedAudioTracks = rendererTrackSelections[i] != null;
        }
        break;
      case C.TRACK_TYPE_TEXT:
        if (!selectedTextTracks) {
          rendererTrackSelections[i] =
              selectTextTrack(
                  mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params);
          selectedTextTracks = rendererTrackSelections[i] != null;
        }
        break;
      default:
        rendererTrackSelections[i] =
            selectOtherTrack(
                trackType, mappedTrackInfo.getTrackGroups(i), rendererFormatSupports[i], params);
        break;
    }
  }

  return rendererTrackSelections;
}
 
Example 20
Source File: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Determines whether tunneling should be enabled, replacing {@link RendererConfiguration}s in
 * {@code rendererConfigurations} with configurations that enable tunneling on the appropriate
 * renderers if so.
 *
 * @param mappedTrackInfo Mapped track information.
 * @param renderererFormatSupports The {@link Capabilities} for each mapped track, indexed by
 *     renderer, track group and track (in that order).
 * @param rendererConfigurations The renderer configurations. Configurations may be replaced with
 *     ones that enable tunneling as a result of this call.
 * @param trackSelections The renderer track selections.
 * @param tunnelingAudioSessionId The audio session id to use when tunneling, or {@link
 *     C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
 */
private static void maybeConfigureRenderersForTunneling(
    MappedTrackInfo mappedTrackInfo,
    @Capabilities int[][][] renderererFormatSupports,
    @NullableType RendererConfiguration[] rendererConfigurations,
    @NullableType TrackSelection[] trackSelections,
    int tunnelingAudioSessionId) {
  if (tunnelingAudioSessionId == C.AUDIO_SESSION_ID_UNSET) {
    return;
  }
  // Check whether we can enable tunneling. To enable tunneling we require exactly one audio and
  // one video renderer to support tunneling and have a selection.
  int tunnelingAudioRendererIndex = -1;
  int tunnelingVideoRendererIndex = -1;
  boolean enableTunneling = true;
  for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
    int rendererType = mappedTrackInfo.getRendererType(i);
    TrackSelection trackSelection = trackSelections[i];
    if ((rendererType == C.TRACK_TYPE_AUDIO || rendererType == C.TRACK_TYPE_VIDEO)
        && trackSelection != null) {
      if (rendererSupportsTunneling(
          renderererFormatSupports[i], mappedTrackInfo.getTrackGroups(i), trackSelection)) {
        if (rendererType == C.TRACK_TYPE_AUDIO) {
          if (tunnelingAudioRendererIndex != -1) {
            enableTunneling = false;
            break;
          } else {
            tunnelingAudioRendererIndex = i;
          }
        } else {
          if (tunnelingVideoRendererIndex != -1) {
            enableTunneling = false;
            break;
          } else {
            tunnelingVideoRendererIndex = i;
          }
        }
      }
    }
  }
  enableTunneling &= tunnelingAudioRendererIndex != -1 && tunnelingVideoRendererIndex != -1;
  if (enableTunneling) {
    RendererConfiguration tunnelingRendererConfiguration =
        new RendererConfiguration(tunnelingAudioSessionId);
    rendererConfigurations[tunnelingAudioRendererIndex] = tunnelingRendererConfiguration;
    rendererConfigurations[tunnelingVideoRendererIndex] = tunnelingRendererConfiguration;
  }
}