Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ android {
// Vendored media3 1.9.0 Matroska extractor with Dolby Vision P7 sample hooks
// (see dvmkv/package-info.java for the re-vendoring procedure on media3 bumps).
java.srcDir("src/main/dvmkv-java")
// Vendored media3 1.9.0 TS extractor that keeps every DVB subtitle stream in HLS
// (see iptvts/package-info.java for the re-vendoring procedure on media3 bumps).
java.srcDir("src/main/iptvts-java")
res.srcDir("src/main/res-player")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.arflix.tv.ui.screens.tv.live

import androidx.activity.ComponentActivity
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Subtitles
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.isFocused
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.unit.dp
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.arflix.tv.R
import com.arflix.tv.ui.theme.ArflixTvTheme
import com.arflix.tv.util.DeviceType
import com.arflix.tv.util.LocalDeviceType
import org.junit.Assert.assertFalse
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LiveTrackControlsDeviceTest {
@get:Rule val compose = createAndroidComposeRule<ComponentActivity>()
private val strings get() = InstrumentationRegistry.getInstrumentation().targetContext

private fun show(content: @Composable () -> Unit) {
compose.setContent {
CompositionLocalProvider(LocalDeviceType provides DeviceType.TV) {
ArflixTvTheme { Box(Modifier.fillMaxSize().background(Color.Black)) { content() } }
}
}
}

@Test fun aSelectedTrackBelowTheFirstScreenIsScrolledToAndFocused() {
val options = (0..24).map { LiveTrackOption("lang$it", "Language $it", selected = it == 20) }
show {
LiveTrackPickerOverlay(
title = "Subtitles", icon = Icons.Filled.Subtitles, channelName = "Channel",
options = options, onDismiss = {}, onPick = {},
)
}
// Without scrolling first, the request for the unplaced row failed and nothing was focused.
compose.waitUntil(5_000) { compose.onAllNodes(isFocused()).fetchSemanticsNodes().isNotEmpty() }
val focused = compose.onAllNodes(isFocused()).fetchSemanticsNodes().single().boundsInRoot
val selectedLabel = compose.onNodeWithText("Language 20").assertIsDisplayed()
.fetchSemanticsNode().boundsInRoot
val overlap = focused.intersect(selectedLabel)
assertFalse("Focus is not on the selected row", overlap.width <= 0f || overlap.height <= 0f)
}

@Test fun controlsDoNotOverlapOnANarrowScreenWithEveryButtonShown() =
assertNoOverlappingControls(widthDp = 480)

@Test fun controlsDoNotOverlapOnATvScreenWithEveryButtonShown() =
assertNoOverlappingControls(widthDp = 960)

private fun assertNoOverlappingControls(widthDp: Int) {
show {
Box(Modifier.width(widthDp.dp).fillMaxHeight()) {
FullscreenHud(
channel = null, nowNext = null, pokeSignal = 0,
isCatchupMode = true, playbackDurationMs = 3_600_000L,
onGuideClick = {}, onOpenVariants = {}, onSubtitlesClick = {}, onAudioClick = {},
onPlayPauseClick = {}, onRewindClick = {}, onFastForwardClick = {},
onPreviousCatchupClick = {}, onNextCatchupClick = {}, onReplayClick = {}, onGoLiveClick = {},
showControls = true,
)
}
}
compose.waitForIdle()
val controls: List<Pair<String, SemanticsNodeInteraction>> =
listOf(R.string.live_audio, R.string.live_subtitles, R.string.live_label_choose_source,
R.string.live_btn_guide, R.string.live_badge_live)
.map { strings.getString(it) }
.map { it to compose.onNodeWithText(it) } +
listOf(R.string.live_cd_previous_channel, R.string.live_cd_rewind, R.string.live_cd_pause,
R.string.live_cd_fast_forward, R.string.live_cd_next_channel, R.string.live_cd_replay)
.map { strings.getString(it) }
.map { it to compose.onNodeWithContentDescription(it) }
val bounds: List<Pair<String, Rect>> = controls.map { (name, node) -> name to node.fetchSemanticsNode().boundsInRoot }
for (i in bounds.indices) {
for (j in i + 1 until bounds.size) {
val (a, ra) = bounds[i]
val (b, rb) = bounds[j]
val overlap = ra.intersect(rb)
assertFalse("\"$a\" $ra overlaps \"$b\" $rb at ${widthDp}dp", overlap.width > 0f && overlap.height > 0f)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arflix.tv.player.iptvts;

import static java.lang.Math.min;

import androidx.media3.common.C;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.TimestampAdjuster;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.BinarySearchSeeker;
import androidx.media3.extractor.ExtractorInput;
import java.io.IOException;
import androidx.media3.extractor.ts.TsUtil;

/**
* A seeker that supports seeking within TS stream using binary search.
*
* <p>This seeker uses the first and last PCR values within the stream, as well as the stream
* duration to interpolate the PCR value of the seeking position. Then it performs binary search
* within the stream to find a packets whose PCR value is within {@link #SEEK_TOLERANCE_US} from the
* target PCR.
*/
/* package */ final class TsBinarySearchSeeker extends BinarySearchSeeker {

private static final long SEEK_TOLERANCE_US = 100_000;
private static final int MINIMUM_SEARCH_RANGE_BYTES = 5 * TsExtractor.TS_PACKET_SIZE;

public TsBinarySearchSeeker(
TimestampAdjuster pcrTimestampAdjuster,
long streamDurationUs,
long inputLength,
int pcrPid,
int timestampSearchBytes) {
super(
new DefaultSeekTimestampConverter(),
new TsPcrSeeker(pcrPid, pcrTimestampAdjuster, timestampSearchBytes),
streamDurationUs,
/* floorTimePosition= */ 0,
/* ceilingTimePosition= */ streamDurationUs + 1,
/* floorBytePosition= */ 0,
/* ceilingBytePosition= */ inputLength,
/* approxBytesPerFrame= */ TsExtractor.TS_PACKET_SIZE,
MINIMUM_SEARCH_RANGE_BYTES);
}

/**
* A {@link TimestampSeeker} implementation that looks for a given PCR timestamp at a given
* position in a TS stream.
*
* <p>Given a PCR timestamp, and a position within a TS stream, this seeker will peek up to {@link
* #timestampSearchBytes} from that stream position, look for all packets with PID equal to
* PCR_PID, and then compare the PCR timestamps (if available) of these packets to the target
* timestamp.
*/
private static final class TsPcrSeeker implements TimestampSeeker {

private final TimestampAdjuster pcrTimestampAdjuster;
private final ParsableByteArray packetBuffer;
private final int pcrPid;
private final int timestampSearchBytes;

public TsPcrSeeker(
int pcrPid, TimestampAdjuster pcrTimestampAdjuster, int timestampSearchBytes) {
this.pcrPid = pcrPid;
this.pcrTimestampAdjuster = pcrTimestampAdjuster;
this.timestampSearchBytes = timestampSearchBytes;
packetBuffer = new ParsableByteArray();
}

@Override
public TimestampSearchResult searchForTimestamp(ExtractorInput input, long targetTimestamp)
throws IOException {
long inputPosition = input.getPosition();
int bytesToSearch = (int) min(timestampSearchBytes, input.getLength() - inputPosition);

packetBuffer.reset(bytesToSearch);
input.peekFully(packetBuffer.getData(), /* offset= */ 0, bytesToSearch);

return searchForPcrValueInBuffer(packetBuffer, targetTimestamp, inputPosition);
}

private TimestampSearchResult searchForPcrValueInBuffer(
ParsableByteArray packetBuffer, long targetPcrTimeUs, long bufferStartOffset) {
int limit = packetBuffer.limit();

long startOfLastPacketPosition = C.INDEX_UNSET;
long endOfLastPacketPosition = C.INDEX_UNSET;
long lastPcrTimeUsInRange = C.TIME_UNSET;

while (packetBuffer.bytesLeft() >= TsExtractor.TS_PACKET_SIZE) {
int startOfPacket =
TsUtil.findSyncBytePosition(packetBuffer.getData(), packetBuffer.getPosition(), limit);
int endOfPacket = startOfPacket + TsExtractor.TS_PACKET_SIZE;
if (endOfPacket > limit) {
break;
}
long pcrValue = TsUtil.readPcrFromPacket(packetBuffer, startOfPacket, pcrPid);
if (pcrValue != C.TIME_UNSET) {
long pcrTimeUs = pcrTimestampAdjuster.adjustTsTimestamp(pcrValue);
if (pcrTimeUs > targetPcrTimeUs) {
if (lastPcrTimeUsInRange == C.TIME_UNSET) {
// First PCR timestamp is already over target.
return TimestampSearchResult.overestimatedResult(pcrTimeUs, bufferStartOffset);
} else {
// Last PCR timestamp < target timestamp < this timestamp.
return TimestampSearchResult.targetFoundResult(
bufferStartOffset + startOfLastPacketPosition);
}
} else if (pcrTimeUs + SEEK_TOLERANCE_US > targetPcrTimeUs) {
long startOfPacketInStream = bufferStartOffset + startOfPacket;
return TimestampSearchResult.targetFoundResult(startOfPacketInStream);
}

lastPcrTimeUsInRange = pcrTimeUs;
startOfLastPacketPosition = startOfPacket;
}
packetBuffer.setPosition(endOfPacket);
endOfLastPacketPosition = endOfPacket;
}

if (lastPcrTimeUsInRange != C.TIME_UNSET) {
long endOfLastPacketPositionInStream = bufferStartOffset + endOfLastPacketPosition;
return TimestampSearchResult.underestimatedResult(
lastPcrTimeUsInRange, endOfLastPacketPositionInStream);
} else {
return TimestampSearchResult.NO_TIMESTAMP_IN_RANGE_RESULT;
}
}

@Override
public void onSeekFinished() {
packetBuffer.reset(Util.EMPTY_BYTE_ARRAY);
}
}
}
Loading
Loading