mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Fix SSA and SRT to display an in-progress cue when enabling subtitles
Issue: androidx/media#2309 PiperOrigin-RevId: 751424941
This commit is contained in:
parent
35303c94a1
commit
170098b400
@ -40,6 +40,8 @@
|
|||||||
* Improve codec performance checks for software video codecs. This may
|
* Improve codec performance checks for software video codecs. This may
|
||||||
lead to some additional tracks being marked as `EXCEEDS_CAPABILITIES`.
|
lead to some additional tracks being marked as `EXCEEDS_CAPABILITIES`.
|
||||||
* Text:
|
* Text:
|
||||||
|
* Fix SSA and SubRip to display an in-progress cue when enabling subtitles
|
||||||
|
([#2309](https://github.com/androidx/media/issues/2309)).
|
||||||
* Metadata:
|
* Metadata:
|
||||||
* Image:
|
* Image:
|
||||||
* DataSource:
|
* DataSource:
|
||||||
|
@ -259,7 +259,7 @@ public class SubtitleExtractor implements Extractor {
|
|||||||
cuesWithTiming.startTimeUs,
|
cuesWithTiming.startTimeUs,
|
||||||
cueEncoder.encode(cuesWithTiming.cues, cuesWithTiming.durationUs));
|
cueEncoder.encode(cuesWithTiming.cues, cuesWithTiming.durationUs));
|
||||||
samples.add(sample);
|
samples.add(sample);
|
||||||
if (seekTimeUs == C.TIME_UNSET || cuesWithTiming.startTimeUs >= seekTimeUs) {
|
if (seekTimeUs == C.TIME_UNSET || cuesWithTiming.endTimeUs >= seekTimeUs) {
|
||||||
writeToOutput(sample);
|
writeToOutput(sample);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -167,13 +167,14 @@ public final class SsaParser implements SubtitleParser {
|
|||||||
}
|
}
|
||||||
long startTimeUs = startTimesUs.get(i);
|
long startTimeUs = startTimesUs.get(i);
|
||||||
// It's safe to inspect element i+1, because we already exited the loop above if i=size()-1.
|
// It's safe to inspect element i+1, because we already exited the loop above if i=size()-1.
|
||||||
long durationUs = startTimesUs.get(i + 1) - startTimesUs.get(i);
|
long endTimeUs = startTimesUs.get(i + 1);
|
||||||
if (outputOptions.startTimeUs == C.TIME_UNSET || startTimeUs >= outputOptions.startTimeUs) {
|
CuesWithTiming cuesWithTiming =
|
||||||
output.accept(new CuesWithTiming(cuesForThisStartTime, startTimeUs, durationUs));
|
new CuesWithTiming(
|
||||||
|
cuesForThisStartTime, startTimeUs, /* durationUs= */ endTimeUs - startTimeUs);
|
||||||
|
if (outputOptions.startTimeUs == C.TIME_UNSET || endTimeUs >= outputOptions.startTimeUs) {
|
||||||
|
output.accept(cuesWithTiming);
|
||||||
} else if (cuesWithTimingBeforeRequestedStartTimeUs != null) {
|
} else if (cuesWithTimingBeforeRequestedStartTimeUs != null) {
|
||||||
cuesWithTimingBeforeRequestedStartTimeUs.add(
|
cuesWithTimingBeforeRequestedStartTimeUs.add(cuesWithTiming);
|
||||||
new CuesWithTiming(cuesForThisStartTime, startTimeUs, durationUs));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cuesWithTimingBeforeRequestedStartTimeUs != null) {
|
if (cuesWithTimingBeforeRequestedStartTimeUs != null) {
|
||||||
|
@ -166,7 +166,7 @@ public final class SubripParser implements SubtitleParser {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputOptions.startTimeUs == C.TIME_UNSET || startTimeUs >= outputOptions.startTimeUs) {
|
if (outputOptions.startTimeUs == C.TIME_UNSET || endTimeUs >= outputOptions.startTimeUs) {
|
||||||
output.accept(
|
output.accept(
|
||||||
new CuesWithTiming(
|
new CuesWithTiming(
|
||||||
ImmutableList.of(buildCue(text, alignmentTag)),
|
ImmutableList.of(buildCue(text, alignmentTag)),
|
||||||
|
@ -129,7 +129,8 @@ public final class SsaParserTest {
|
|||||||
SsaParser parser = new SsaParser();
|
SsaParser parser = new SsaParser();
|
||||||
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL);
|
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL);
|
||||||
List<CuesWithTiming> cues = new ArrayList<>();
|
List<CuesWithTiming> cues = new ArrayList<>();
|
||||||
parser.parse(bytes, OutputOptions.onlyCuesAfter(/* startTimeUs= */ 1_000_000), cues::add);
|
// Choose a start time halfway through the second cue, and expect it to be included.
|
||||||
|
parser.parse(bytes, OutputOptions.onlyCuesAfter(/* startTimeUs= */ 3_000_000), cues::add);
|
||||||
|
|
||||||
assertThat(cues).hasSize(2);
|
assertThat(cues).hasSize(2);
|
||||||
assertTypicalCue2(cues.get(0));
|
assertTypicalCue2(cues.get(0));
|
||||||
@ -141,9 +142,10 @@ public final class SsaParserTest {
|
|||||||
SsaParser parser = new SsaParser();
|
SsaParser parser = new SsaParser();
|
||||||
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL);
|
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL);
|
||||||
List<CuesWithTiming> cues = new ArrayList<>();
|
List<CuesWithTiming> cues = new ArrayList<>();
|
||||||
|
// Choose a start time halfway through the second cue, and expect it to be considered 'after'.
|
||||||
parser.parse(
|
parser.parse(
|
||||||
bytes,
|
bytes,
|
||||||
OutputOptions.cuesAfterThenRemainingCuesBefore(/* startTimeUs= */ 1_000_000),
|
OutputOptions.cuesAfterThenRemainingCuesBefore(/* startTimeUs= */ 3_000_000),
|
||||||
cues::add);
|
cues::add);
|
||||||
|
|
||||||
assertThat(cues).hasSize(3);
|
assertThat(cues).hasSize(3);
|
||||||
|
@ -105,7 +105,8 @@ public final class SubripParserTest {
|
|||||||
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL_FILE);
|
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL_FILE);
|
||||||
|
|
||||||
List<CuesWithTiming> cues = new ArrayList<>();
|
List<CuesWithTiming> cues = new ArrayList<>();
|
||||||
parser.parse(bytes, OutputOptions.onlyCuesAfter(/* startTimeUs= */ 1_000_000), cues::add);
|
// Choose a start time halfway through the second cue, and expect it to be included.
|
||||||
|
parser.parse(bytes, OutputOptions.onlyCuesAfter(/* startTimeUs= */ 3_000_000), cues::add);
|
||||||
|
|
||||||
assertThat(cues).hasSize(2);
|
assertThat(cues).hasSize(2);
|
||||||
assertTypicalCue2(cues.get(0));
|
assertTypicalCue2(cues.get(0));
|
||||||
@ -118,9 +119,10 @@ public final class SubripParserTest {
|
|||||||
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL_FILE);
|
byte[] bytes = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), TYPICAL_FILE);
|
||||||
|
|
||||||
List<CuesWithTiming> cues = new ArrayList<>();
|
List<CuesWithTiming> cues = new ArrayList<>();
|
||||||
|
// Choose a start time halfway through the second cue, and expect it to be considered 'after'.
|
||||||
parser.parse(
|
parser.parse(
|
||||||
bytes,
|
bytes,
|
||||||
OutputOptions.cuesAfterThenRemainingCuesBefore(/* startTimeUs= */ 1_000_000),
|
OutputOptions.cuesAfterThenRemainingCuesBefore(/* startTimeUs= */ 3_000_000),
|
||||||
cues::add);
|
cues::add);
|
||||||
|
|
||||||
assertThat(cues).hasSize(3);
|
assertThat(cues).hasSize(3);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user