Search in sources :

Example 1 with TrackSelectionOverrides

use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.

the class TrackSelectionOverridesTest method setOverrideForType_onSameType_replacesOverride.

@Test
public void setOverrideForType_onSameType_replacesOverride() {
    TrackSelectionOverride override1 = new TrackSelectionOverride(newTrackGroupWithIds(1));
    TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(2));
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().setOverrideForType(override1).setOverrideForType(override2).build();
    assertThat(trackSelectionOverrides.asList()).containsExactly(override2);
    assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 2 with TrackSelectionOverrides

use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.

the class TrackSelectionOverridesTest method addOverride_onSameGroup_replacesOverride.

@Test
public void addOverride_onSameGroup_replacesOverride() {
    TrackGroup trackGroup = newTrackGroupWithIds(1, 2, 3);
    TrackSelectionOverride override1 = new TrackSelectionOverride(trackGroup, /* trackIndices= */
    ImmutableList.of(0));
    TrackSelectionOverride override2 = new TrackSelectionOverride(trackGroup, /* trackIndices= */
    ImmutableList.of(1));
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).build();
    assertThat(trackSelectionOverrides.asList()).containsExactly(override2);
    assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 3 with TrackSelectionOverrides

use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.

the class TrackSelectionParametersTest method parametersSet_fromDefault_isAsExpected.

@Test
public void parametersSet_fromDefault_isAsExpected() {
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().build()))).addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().setId(4).build(), new Format.Builder().setId(5).build()), /* trackIndices= */
    ImmutableList.of(1))).build();
    TrackSelectionParameters parameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxVideoSize(/* maxVideoWidth= */
    0, /* maxVideoHeight= */
    1).setMaxVideoFrameRate(2).setMaxVideoBitrate(3).setMinVideoSize(/* minVideoWidth= */
    4, /* minVideoHeight= */
    5).setMinVideoFrameRate(6).setMinVideoBitrate(7).setViewportSize(/* viewportWidth= */
    8, /* viewportHeight= */
    9, /* viewportOrientationMayChange= */
    true).setPreferredVideoMimeTypes(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).setPreferredAudioLanguages("zh", "jp").setPreferredAudioRoleFlags(C.ROLE_FLAG_COMMENTARY).setMaxAudioChannelCount(10).setMaxAudioBitrate(11).setPreferredAudioMimeTypes(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).setPreferredTextLanguages("de", "en").setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION).setSelectUndeterminedTextLanguage(true).setForceLowestBitrate(false).setForceHighestSupportedBitrate(true).setTrackSelectionOverrides(trackSelectionOverrides).setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT)).build();
    // Video
    assertThat(parameters.maxVideoWidth).isEqualTo(0);
    assertThat(parameters.maxVideoHeight).isEqualTo(1);
    assertThat(parameters.maxVideoFrameRate).isEqualTo(2);
    assertThat(parameters.maxVideoBitrate).isEqualTo(3);
    assertThat(parameters.minVideoWidth).isEqualTo(4);
    assertThat(parameters.minVideoHeight).isEqualTo(5);
    assertThat(parameters.minVideoFrameRate).isEqualTo(6);
    assertThat(parameters.minVideoBitrate).isEqualTo(7);
    assertThat(parameters.viewportWidth).isEqualTo(8);
    assertThat(parameters.viewportHeight).isEqualTo(9);
    assertThat(parameters.viewportOrientationMayChange).isTrue();
    assertThat(parameters.preferredVideoMimeTypes).containsExactly(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).inOrder();
    // Audio
    assertThat(parameters.preferredAudioLanguages).containsExactly("zh", "jp").inOrder();
    assertThat(parameters.preferredAudioRoleFlags).isEqualTo(C.ROLE_FLAG_COMMENTARY);
    assertThat(parameters.maxAudioChannelCount).isEqualTo(10);
    assertThat(parameters.maxAudioBitrate).isEqualTo(11);
    assertThat(parameters.preferredAudioMimeTypes).containsExactly(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).inOrder();
    // Text
    assertThat(parameters.preferredTextLanguages).containsExactly("de", "en").inOrder();
    assertThat(parameters.preferredTextRoleFlags).isEqualTo(C.ROLE_FLAG_CAPTION);
    assertThat(parameters.selectUndeterminedTextLanguage).isTrue();
    // General
    assertThat(parameters.forceLowestBitrate).isFalse();
    assertThat(parameters.forceHighestSupportedBitrate).isTrue();
    assertThat(parameters.trackSelectionOverrides).isEqualTo(trackSelectionOverrides);
    assertThat(parameters.disabledTrackTypes).containsExactly(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 4 with TrackSelectionOverrides

use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project jellyfin-androidtv by jellyfin.

the class VideoManager method stopPlayback.

public void stopPlayback() {
    if (nativeMode && mExoPlayer != null) {
        mExoPlayer.stop();
        disableSubs();
        TrackSelectionOverrides overrides = mExoPlayer.getTrackSelectionParameters().trackSelectionOverrides.buildUpon().clearOverridesOfType(C.TRACK_TYPE_AUDIO).build();
        mExoPlayer.setTrackSelectionParameters(mExoPlayer.getTrackSelectionParameters().buildUpon().setTrackSelectionOverrides(overrides).build());
    } else if (mVlcPlayer != null) {
        mVlcPlayer.stop();
    }
    stopProgressLoop();
}
Also used : TrackSelectionOverrides(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides)

Example 5 with TrackSelectionOverrides

use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project jellyfin-androidtv by jellyfin.

the class VideoManager method setExoPlayerTrack.

public boolean setExoPlayerTrack(int index, @Nullable MediaStreamType streamType, @Nullable List<MediaStream> allStreams) {
    if (!nativeMode || !isInitialized() || allStreams == null || streamType != MediaStreamType.Subtitle && streamType != MediaStreamType.Audio)
        return false;
    int chosenTrackType = streamType == MediaStreamType.Subtitle ? C.TRACK_TYPE_TEXT : C.TRACK_TYPE_AUDIO;
    MediaStream candidate = allStreams.get(index);
    if (candidate.getIsExternal() || candidate.getType() != streamType)
        return false;
    int exoTrackID = offsetStreamIndex(index, false, allStreams);
    if (exoTrackID < 0)
        return false;
    // print the streams for debugging
    for (MediaStream stream : allStreams) {
        Timber.d("MediaStream track %s type %s label %s codec %s isExternal %s", stream.getIndex(), stream.getType(), stream.getTitle(), stream.getCodec(), stream.getIsExternal());
    }
    // design choices for exoplayer track selection overrides:
    // * build upon the prior parameters so we can mix overrides of different track types without erasing priors
    // 
    // * for subtitles (not currently used) - use setDisabledTrackTypes to disable or enable exoplayer handing subtitles
    // if we want most formats to be handled by the external subtitle handler (which has adjustable size, background), we leave sub track selection disabled
    // if we decide to use exoplayer to render a specific subtitle format, allow subtitle track selection and restrict selection to the chosen group
    TracksInfo exoTracks = mExoPlayer.getCurrentTracksInfo();
    TrackGroup matchedGroup = null;
    for (TracksInfo.TrackGroupInfo groupInfo : exoTracks.getTrackGroupInfos()) {
        // Group level information.
        @C.TrackType int trackType = groupInfo.getTrackType();
        TrackGroup group = groupInfo.getTrackGroup();
        for (int i = 0; i < group.length; i++) {
            // Individual track information.
            boolean isSupported = groupInfo.isTrackSupported(i);
            boolean isSelected = groupInfo.isTrackSelected(i);
            Format trackFormat = group.getFormat(i);
            Timber.d("track %s group %s/%s trackType %s label %s mime %s isSelected %s isSupported %s", trackFormat.id, i + 1, group.length, trackType, trackFormat.label, trackFormat.sampleMimeType, isSelected, isSupported);
            if (trackType != chosenTrackType || trackFormat.id == null)
                continue;
            int id;
            try {
                id = Integer.parseInt(trackFormat.id);
                if (id != exoTrackID)
                    continue;
            } catch (NumberFormatException e) {
                Timber.d("failed to parse track ID [%s]", trackFormat.id);
                continue;
            }
            if (groupInfo.isTrackSelected(i) || !groupInfo.isTrackSupported(i)) {
                Timber.d("track is %s", groupInfo.isTrackSelected(i) ? "already selected" : "not compatible");
                return false;
            }
            Timber.d("matched exoplayer track %s to mediaStream track %s", trackFormat.id, index);
            matchedGroup = group;
        }
    }
    if (matchedGroup == null)
        return false;
    try {
        TrackSelectionOverrides overrides = mExoPlayer.getTrackSelectionParameters().trackSelectionOverrides.buildUpon().setOverrideForType(new TrackSelectionOverrides.TrackSelectionOverride(matchedGroup)).build();
        TrackSelectionParameters.Builder mExoPlayerSelectionParams = mExoPlayer.getTrackSelectionParameters().buildUpon();
        if (streamType == MediaStreamType.Subtitle)
            mExoPlayerSelectionParams.setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_NONE));
        mExoPlayerSelectionParams.setTrackSelectionOverrides(overrides);
        mExoPlayer.setTrackSelectionParameters(mExoPlayerSelectionParams.build());
    } catch (Exception e) {
        Timber.d("Error setting track selection");
        return false;
    }
    return true;
}
Also used : TracksInfo(com.google.android.exoplayer2.TracksInfo) PlaybackException(com.google.android.exoplayer2.PlaybackException) TrackSelectionOverrides(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides) PixelFormat(android.graphics.PixelFormat) Format(com.google.android.exoplayer2.Format) MediaStream(org.jellyfin.apiclient.model.entities.MediaStream) TrackSelectionParameters(com.google.android.exoplayer2.trackselection.TrackSelectionParameters) TrackGroup(com.google.android.exoplayer2.source.TrackGroup)

Aggregations

TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)8 Test (org.junit.Test)7 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)4 TrackSelectionOverrides (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides)3 TracksInfo (com.google.android.exoplayer2.TracksInfo)2 SuppressLint (android.annotation.SuppressLint)1 PixelFormat (android.graphics.PixelFormat)1 Format (com.google.android.exoplayer2.Format)1 PlaybackException (com.google.android.exoplayer2.PlaybackException)1 TrackGroupInfo (com.google.android.exoplayer2.TracksInfo.TrackGroupInfo)1 TrackSelectionParameters (com.google.android.exoplayer2.trackselection.TrackSelectionParameters)1 ArrayList (java.util.ArrayList)1 MediaStream (org.jellyfin.apiclient.model.entities.MediaStream)1