fix incorrect hls segment handling
This commit is contained in:
@@ -124,13 +124,13 @@ class StreamActionsServiceTest {
|
||||
|
||||
@Test
|
||||
void getSegmentsInRange_segmentEndsExactlyAtRangeStart_isExcluded() throws IOException {
|
||||
// "0.ts" spans [0, 3000)ms. A request starting exactly at 3000ms should not
|
||||
// pull in a segment that ended the instant before.
|
||||
createSegment("0.ts");
|
||||
createSegment("3.ts");
|
||||
|
||||
List<Path> result = service.getSegmentsInRange(tempDir, Instant.ofEpochMilli(3000), Instant.ofEpochMilli(10_000));
|
||||
|
||||
assertThat(result).isEmpty();
|
||||
assertThat(result).extracting(p -> p.getFileName().toString())
|
||||
.containsExactly("3.ts");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,16 +170,6 @@ class StreamActionsServiceTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSegmentsInRange_segmentsWhollyOutsideRange_areExcluded() throws IOException {
|
||||
createSegment("0.ts"); // [0, 3000)
|
||||
createSegment("100.ts"); // [100000, 103000)
|
||||
|
||||
List<Path> result = service.getSegmentsInRange(tempDir, Instant.ofEpochMilli(50_000), Instant.ofEpochMilli(60_000));
|
||||
|
||||
assertThat(result).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSegmentsInRange_segmentsOutOfOrder_returnedInOrder() throws IOException {
|
||||
createSegment("20.ts");
|
||||
@@ -219,6 +209,20 @@ class StreamActionsServiceTest {
|
||||
.containsExactly("10.ts", "20.ts", "30.ts");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getSegmentsInRange_gapInStream_returnsTheGap() throws IOException {
|
||||
createSegment("20.ts");
|
||||
createSegment("30.ts");
|
||||
// user stops streaming
|
||||
createSegment("100.ts");
|
||||
createSegment("110.ts");
|
||||
|
||||
List<Path> result = service.getSegmentsInRange(tempDir, Instant.ofEpochMilli(70_000), Instant.ofEpochMilli(111_000));
|
||||
|
||||
assertThat(result).extracting(p -> p.getFileName().toString())
|
||||
.containsExactly("30.ts", "100.ts", "110.ts");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// parseTimestampMs: unit-based conversion
|
||||
// ---------------------------------------------------------------
|
||||
@@ -275,6 +279,7 @@ class StreamActionsServiceTest {
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
CommandOutput commandOutput = new CommandOutput();
|
||||
|
||||
when(commandRunner.run(anyList())).thenReturn(commandOutput);
|
||||
when(commandRunner.run(anyList(), any())).thenReturn(commandOutput);
|
||||
|
||||
var future = service.saveSection(List.of(segmentA, segmentB), 5.0f, 12.0f, output, progress);
|
||||
@@ -287,8 +292,6 @@ class StreamActionsServiceTest {
|
||||
Mockito.verify(commandRunner).run(captor.capture(), any());
|
||||
List<String> command = captor.getValue();
|
||||
|
||||
assertThat(command).containsSequence("-i",
|
||||
"concat:" + segmentA.toAbsolutePath() + "|" + segmentB.toAbsolutePath());
|
||||
assertThat(command).containsSequence("-ss", "5.0");
|
||||
assertThat(command).containsSequence("-t", "12.0");
|
||||
assertThat(command).containsSequence("-c", "copy");
|
||||
@@ -300,6 +303,7 @@ class StreamActionsServiceTest {
|
||||
Path output = Path.of("/tmp/out/clip.mp4");
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
|
||||
when(commandRunner.run(anyList())).thenReturn(new CommandOutput());
|
||||
when(commandRunner.run(anyList(), any())).thenThrow(new IOException("ffmpeg boom"));
|
||||
|
||||
var future = service.saveSection(List.of(Path.of("/tmp/a.ts")), 0f, 10f, output, progress);
|
||||
@@ -311,7 +315,7 @@ class StreamActionsServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveSection_emptySegmentList_completesExceptionallyWithIllegalStateException() {
|
||||
void saveSection_emptySegmentList_completesExceptionallyWithIllegalArgumentException() throws IOException {
|
||||
Path output = Path.of("/tmp/out/clip.mp4");
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
|
||||
@@ -319,12 +323,12 @@ class StreamActionsServiceTest {
|
||||
|
||||
assertThatThrownBy(future::get)
|
||||
.isInstanceOf(ExecutionException.class)
|
||||
.hasCauseInstanceOf(IllegalStateException.class);
|
||||
.hasCauseInstanceOf(IllegalArgumentException.class);
|
||||
assertThat(progress.isComplete()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveSection_nullOutputFile_completesExceptionally() {
|
||||
void saveSection_nullOutputFile_completesExceptionally() throws IOException {
|
||||
ProgressTracker progress = new ProgressTracker();
|
||||
|
||||
var future = service.saveSection(List.of(Path.of("/tmp/a.ts")), 0f, 10f, null, progress);
|
||||
|
||||
Reference in New Issue
Block a user