Minor style tweaks

This commit is contained in:
Oliver Woodman 2017-08-17 23:13:12 +01:00 committed by Oliver Woodman
parent 51dac5838d
commit 47e3b4dc3e
5 changed files with 69 additions and 28 deletions

View File

@ -0,0 +1,10 @@
1
00:00:00,000 --> 00:00:01,234
This is the first subtitle.
2
00:00:02,345 --> 00:00:03,456
This is the second subtitle.
Second subtitle with second line.
3

View File

@ -31,6 +31,7 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
private static final String TYPICAL_MISSING_TIMECODE = "subrip/typical_missing_timecode"; private static final String TYPICAL_MISSING_TIMECODE = "subrip/typical_missing_timecode";
private static final String TYPICAL_MISSING_SEQUENCE = "subrip/typical_missing_sequence"; private static final String TYPICAL_MISSING_SEQUENCE = "subrip/typical_missing_sequence";
private static final String TYPICAL_NEGATIVE_TIMESTAMPS = "subrip/typical_negative_timestamps"; private static final String TYPICAL_NEGATIVE_TIMESTAMPS = "subrip/typical_negative_timestamps";
private static final String TYPICAL_UNEXPECTED_END = "subrip/typical_unexpected_end";
private static final String NO_END_TIMECODES_FILE = "subrip/no_end_timecodes"; private static final String NO_END_TIMECODES_FILE = "subrip/no_end_timecodes";
public void testDecodeEmpty() throws IOException { public void testDecodeEmpty() throws IOException {
@ -107,6 +108,17 @@ public final class SubripDecoderTest extends InstrumentationTestCase {
assertTypicalCue3(subtitle, 0); assertTypicalCue3(subtitle, 0);
} }
public void testDecodeTypicalUnexpectedEnd() throws IOException {
// Parsing should succeed, parsing the first and second cues only.
SubripDecoder decoder = new SubripDecoder();
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_UNEXPECTED_END);
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
assertEquals(4, subtitle.getEventTimeCount());
assertTypicalCue1(subtitle, 0);
assertTypicalCue2(subtitle, 2);
}
public void testDecodeNoEndTimecodes() throws IOException { public void testDecodeNoEndTimecodes() throws IOException {
SubripDecoder decoder = new SubripDecoder(); SubripDecoder decoder = new SubripDecoder();
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE); byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);

View File

@ -116,9 +116,32 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener); optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener);
} }
/** Releases the helper. Should be called when the helper is no longer required. */ /**
public void release() { * @see DefaultDrmSessionManager#getPropertyByteArray
handlerThread.quit(); */
public synchronized byte[] getPropertyByteArray(String key) {
return drmSessionManager.getPropertyByteArray(key);
}
/**
* @see DefaultDrmSessionManager#setPropertyByteArray
*/
public synchronized void setPropertyByteArray(String key, byte[] value) {
drmSessionManager.setPropertyByteArray(key, value);
}
/**
* @see DefaultDrmSessionManager#getPropertyString
*/
public synchronized String getPropertyString(String key) {
return drmSessionManager.getPropertyString(key);
}
/**
* @see DefaultDrmSessionManager#setPropertyString
*/
public synchronized void setPropertyString(String key, String value) {
drmSessionManager.setPropertyString(key, value);
} }
/** /**
@ -185,21 +208,12 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
} }
return licenseDurationRemainingSec; return licenseDurationRemainingSec;
} }
public byte[] getPropertyByteArray(String key) {
return drmSessionManager.getPropertyByteArray(key);
}
public void setPropertyByteArray(String key, byte[] value) { /**
drmSessionManager.setPropertyByteArray(key, value); * Releases the helper. Should be called when the helper is no longer required.
} */
public void release() {
public String getPropertyString(String key) { handlerThread.quit();
return drmSessionManager.getPropertyString(key);
}
public void setPropertyString(String key, String value) {
drmSessionManager.setPropertyString(key, value);
} }
private byte[] blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId, private byte[] blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,

View File

@ -995,9 +995,10 @@ import java.util.List;
int objectTypeIndication = parent.readUnsignedByte(); int objectTypeIndication = parent.readUnsignedByte();
String mimeType; String mimeType;
switch (objectTypeIndication) { switch (objectTypeIndication) {
case 0x6B: case 0x60:
mimeType = MimeTypes.AUDIO_MPEG; case 0x61:
return Pair.create(mimeType, null); mimeType = MimeTypes.VIDEO_MPEG2;
break;
case 0x20: case 0x20:
mimeType = MimeTypes.VIDEO_MP4V; mimeType = MimeTypes.VIDEO_MP4V;
break; break;
@ -1007,6 +1008,9 @@ import java.util.List;
case 0x23: case 0x23:
mimeType = MimeTypes.VIDEO_H265; mimeType = MimeTypes.VIDEO_H265;
break; break;
case 0x6B:
mimeType = MimeTypes.AUDIO_MPEG;
return Pair.create(mimeType, null);
case 0x40: case 0x40:
case 0x66: case 0x66:
case 0x67: case 0x67:
@ -1027,10 +1031,6 @@ import java.util.List;
case 0xAB: case 0xAB:
mimeType = MimeTypes.AUDIO_DTS_HD; mimeType = MimeTypes.AUDIO_DTS_HD;
return Pair.create(mimeType, null); return Pair.create(mimeType, null);
case 0x60: /* Visual 13818-2 Simple Profile */
case 0x61: /* Visual 13818-2 Main Profile */
mimeType = MimeTypes.VIDEO_MPEG2;
break;
default: default:
mimeType = null; mimeType = null;
break; break;
@ -1038,8 +1038,8 @@ import java.util.List;
parent.skipBytes(12); parent.skipBytes(12);
// Start of the AudioSpecificConfig. // Start of the DecoderSpecificInfo.
parent.skipBytes(1); // AudioSpecificConfig tag parent.skipBytes(1); // DecoderSpecificInfo tag
int initializationDataSize = parseExpandableClassSize(parent); int initializationDataSize = parseExpandableClassSize(parent);
byte[] initializationData = new byte[initializationDataSize]; byte[] initializationData = new byte[initializationDataSize];
parent.readBytes(initializationData, 0, initializationDataSize); parent.readBytes(initializationData, 0, initializationDataSize);

View File

@ -69,8 +69,13 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
// Read and parse the timing line. // Read and parse the timing line.
boolean haveEndTimecode = false; boolean haveEndTimecode = false;
currentLine = subripData.readLine(); currentLine = subripData.readLine();
Matcher matcher = currentLine == null ? null : SUBRIP_TIMING_LINE.matcher(currentLine); if (currentLine == null) {
if (matcher != null && matcher.matches()) { Log.w(TAG, "Unexpected end");
break;
}
Matcher matcher = SUBRIP_TIMING_LINE.matcher(currentLine);
if (matcher.matches()) {
cueTimesUs.add(parseTimecode(matcher, 1)); cueTimesUs.add(parseTimecode(matcher, 1));
if (!TextUtils.isEmpty(matcher.group(6))) { if (!TextUtils.isEmpty(matcher.group(6))) {
haveEndTimecode = true; haveEndTimecode = true;