Nullness fixes for emsg and id3 metadata classes

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=205972857
This commit is contained in:
olly 2018-07-25 04:08:18 -07:00 committed by Oliver Woodman
parent 3d55bc78f7
commit 14216ef53b
19 changed files with 84 additions and 108 deletions

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata;
import android.support.annotation.Nullable;
/**
* Decodes metadata from binary data.
*/
@ -24,9 +26,8 @@ public interface MetadataDecoder {
* Decodes a {@link Metadata} element from the provided input buffer.
*
* @param inputBuffer The input buffer to decode.
* @return The decoded metadata object.
* @throws MetadataDecoderException If a problem occurred decoding the data.
* @return The decoded metadata object, or null if the metadata could not be decoded.
*/
Metadata decode(MetadataInputBuffer inputBuffer) throws MetadataDecoderException;
@Nullable
Metadata decode(MetadataInputBuffer inputBuffer);
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (C) 2016 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.google.android.exoplayer2.metadata;
/**
* Thrown when an error occurs decoding metadata.
*/
public class MetadataDecoderException extends Exception {
/**
* @param message The detail message for this exception.
*/
public MetadataDecoderException(String message) {
super(message);
}
/**
* @param message The detail message for this exception.
* @param cause The cause of this exception.
*/
public MetadataDecoderException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -128,14 +128,10 @@ public final class MetadataRenderer extends BaseRenderer implements Callback {
} else {
buffer.subsampleOffsetUs = formatHolder.format.subsampleOffsetUs;
buffer.flip();
try {
int index = (pendingMetadataIndex + pendingMetadataCount) % MAX_PENDING_METADATA_COUNT;
pendingMetadata[index] = decoder.decode(buffer);
pendingMetadataTimestamps[index] = buffer.timeUs;
pendingMetadataCount++;
} catch (MetadataDecoderException e) {
throw ExoPlaybackException.createForRenderer(e, getIndex());
}
int index = (pendingMetadataIndex + pendingMetadataCount) % MAX_PENDING_METADATA_COUNT;
pendingMetadata[index] = decoder.decode(buffer);
pendingMetadataTimestamps[index] = buffer.timeUs;
pendingMetadataCount++;
}
}
}

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.emsg;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -81,12 +83,12 @@ public final class EventMessage implements Metadata.Entry {
}
/* package */ EventMessage(Parcel in) {
schemeIdUri = in.readString();
value = in.readString();
schemeIdUri = castNonNull(in.readString());
value = castNonNull(in.readString());
presentationTimeUs = in.readLong();
durationMs = in.readLong();
id = in.readLong();
messageData = in.createByteArray();
messageData = castNonNull(in.createByteArray());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -44,10 +46,10 @@ public final class ApicFrame extends Id3Frame {
/* package */ ApicFrame(Parcel in) {
super(ID);
mimeType = in.readString();
description = in.readString();
mimeType = castNonNull(in.readString());
description = castNonNull(in.readString());
pictureType = in.readInt();
pictureData = in.createByteArray();
pictureData = castNonNull(in.createByteArray());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -33,8 +35,8 @@ public final class BinaryFrame extends Id3Frame {
}
/* package */ BinaryFrame(Parcel in) {
super(in.readString());
data = in.createByteArray();
super(castNonNull(in.readString()));
data = castNonNull(in.createByteArray());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
@ -54,7 +56,7 @@ public final class ChapterFrame extends Id3Frame {
/* package */ ChapterFrame(Parcel in) {
super(ID);
this.chapterId = in.readString();
this.chapterId = castNonNull(in.readString());
this.startTimeMs = in.readInt();
this.endTimeMs = in.readInt();
this.startOffset = in.readLong();

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.util.Util;
@ -45,7 +47,7 @@ public final class ChapterTocFrame extends Id3Frame {
/* package */ ChapterTocFrame(Parcel in) {
super(ID);
this.elementId = in.readString();
this.elementId = castNonNull(in.readString());
this.isRoot = in.readByte() != 0;
this.isOrdered = in.readByte() != 0;
this.children = in.createStringArray();

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -40,9 +42,9 @@ public final class CommentFrame extends Id3Frame {
/* package */ CommentFrame(Parcel in) {
super(ID);
language = in.readString();
description = in.readString();
text = in.readString();
language = castNonNull(in.readString());
description = castNonNull(in.readString());
text = castNonNull(in.readString());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -43,10 +45,10 @@ public final class GeobFrame extends Id3Frame {
/* package */ GeobFrame(Parcel in) {
super(ID);
mimeType = in.readString();
filename = in.readString();
description = in.readString();
data = in.createByteArray();
mimeType = castNonNull(in.readString());
filename = castNonNull(in.readString());
description = castNonNull(in.readString());
data = castNonNull(in.createByteArray());
}
@Override

View File

@ -103,7 +103,7 @@ public final class Id3Decoder implements MetadataDecoder {
}
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) {
public @Nullable Metadata decode(MetadataInputBuffer inputBuffer) {
ByteBuffer buffer = inputBuffer.data;
return decode(buffer.array(), buffer.limit());
}
@ -113,9 +113,10 @@ public final class Id3Decoder implements MetadataDecoder {
*
* @param data The bytes to decode ID3 tags from.
* @param size Amount of bytes in {@code data} to read.
* @return A {@link Metadata} object containing the decoded ID3 tags.
* @return A {@link Metadata} object containing the decoded ID3 tags, or null if the data could
* not be decoded.
*/
public Metadata decode(byte[] data, int size) {
public @Nullable Metadata decode(byte[] data, int size) {
List<Id3Frame> id3Frames = new ArrayList<>();
ParsableByteArray id3Data = new ParsableByteArray(data, size);
@ -157,7 +158,7 @@ public final class Id3Decoder implements MetadataDecoder {
* @param data A {@link ParsableByteArray} from which the header should be read.
* @return The parsed header, or null if the ID3 tag is unsupported.
*/
private static Id3Header decodeHeader(ParsableByteArray data) {
private static @Nullable Id3Header decodeHeader(ParsableByteArray data) {
if (data.bytesLeft() < ID3_HEADER_LENGTH) {
Log.w(TAG, "Data too short to be an ID3 tag");
return null;
@ -271,7 +272,7 @@ public final class Id3Decoder implements MetadataDecoder {
}
}
private static Id3Frame decodeFrame(
private static @Nullable Id3Frame decodeFrame(
int majorVersion,
ParsableByteArray id3Data,
boolean unsignedIntFrameSizeHack,
@ -404,8 +405,8 @@ public final class Id3Decoder implements MetadataDecoder {
}
}
private static TextInformationFrame decodeTxxxFrame(ParsableByteArray id3Data, int frameSize)
throws UnsupportedEncodingException {
private static @Nullable TextInformationFrame decodeTxxxFrame(
ParsableByteArray id3Data, int frameSize) throws UnsupportedEncodingException {
if (frameSize < 1) {
// Frame is malformed.
return null;
@ -427,8 +428,8 @@ public final class Id3Decoder implements MetadataDecoder {
return new TextInformationFrame("TXXX", description, value);
}
private static TextInformationFrame decodeTextInformationFrame(ParsableByteArray id3Data,
int frameSize, String id) throws UnsupportedEncodingException {
private static @Nullable TextInformationFrame decodeTextInformationFrame(
ParsableByteArray id3Data, int frameSize, String id) throws UnsupportedEncodingException {
if (frameSize < 1) {
// Frame is malformed.
return null;
@ -446,7 +447,7 @@ public final class Id3Decoder implements MetadataDecoder {
return new TextInformationFrame(id, null, value);
}
private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)
private static @Nullable UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)
throws UnsupportedEncodingException {
if (frameSize < 1) {
// Frame is malformed.
@ -557,7 +558,7 @@ public final class Id3Decoder implements MetadataDecoder {
return new ApicFrame(mimeType, description, pictureType, pictureData);
}
private static CommentFrame decodeCommentFrame(ParsableByteArray id3Data, int frameSize)
private static @Nullable CommentFrame decodeCommentFrame(ParsableByteArray id3Data, int frameSize)
throws UnsupportedEncodingException {
if (frameSize < 4) {
// Frame is malformed.

View File

@ -16,7 +16,6 @@
package com.google.android.exoplayer2.metadata.id3;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.util.Assertions;
/**
* Base class for ID3 frames.
@ -29,7 +28,7 @@ public abstract class Id3Frame implements Metadata.Entry {
public final String id;
public Id3Frame(String id) {
this.id = Assertions.checkNotNull(id);
this.id = id;
}
@Override

View File

@ -15,9 +15,10 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
/** Internal ID3 frame that is intended for use by the player. */
@ -38,9 +39,9 @@ public final class InternalFrame extends Id3Frame {
/* package */ InternalFrame(Parcel in) {
super(ID);
domain = Assertions.checkNotNull(in.readString());
description = Assertions.checkNotNull(in.readString());
text = Assertions.checkNotNull(in.readString());
domain = castNonNull(in.readString());
description = castNonNull(in.readString());
text = castNonNull(in.readString());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -39,8 +41,8 @@ public final class PrivFrame extends Id3Frame {
/* package */ PrivFrame(Parcel in) {
super(ID);
owner = in.readString();
privateData = in.createByteArray();
owner = castNonNull(in.readString());
privateData = castNonNull(in.createByteArray());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -35,9 +37,9 @@ public final class TextInformationFrame extends Id3Frame {
}
/* package */ TextInformationFrame(Parcel in) {
super(in.readString());
super(castNonNull(in.readString()));
description = in.readString();
value = in.readString();
value = castNonNull(in.readString());
}
@Override

View File

@ -15,6 +15,8 @@
*/
package com.google.android.exoplayer2.metadata.id3;
import static org.checkerframework.checker.nullness.NullnessUtil.castNonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
@ -25,19 +27,19 @@ import com.google.android.exoplayer2.util.Util;
*/
public final class UrlLinkFrame extends Id3Frame {
public final String description;
public final @Nullable String description;
public final String url;
public UrlLinkFrame(String id, String description, String url) {
public UrlLinkFrame(String id, @Nullable String description, String url) {
super(id);
this.description = description;
this.url = url;
}
/* package */ UrlLinkFrame(Parcel in) {
super(in.readString());
super(castNonNull(in.readString()));
description = in.readString();
url = in.readString();
url = castNonNull(in.readString());
}
@Override

View File

@ -17,7 +17,6 @@ package com.google.android.exoplayer2.metadata.scte35;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoder;
import com.google.android.exoplayer2.metadata.MetadataDecoderException;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
import com.google.android.exoplayer2.util.ParsableBitArray;
import com.google.android.exoplayer2.util.ParsableByteArray;
@ -46,7 +45,7 @@ public final class SpliceInfoDecoder implements MetadataDecoder {
}
@Override
public Metadata decode(MetadataInputBuffer inputBuffer) throws MetadataDecoderException {
public Metadata decode(MetadataInputBuffer inputBuffer) {
// Internal timestamps adjustment.
if (timestampAdjuster == null
|| inputBuffer.subsampleOffsetUs != timestampAdjuster.getTimestampOffsetUs()) {

View File

@ -19,7 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoderException;
import com.google.android.exoplayer2.util.Assertions;
import java.nio.charset.Charset;
import java.util.Arrays;
@ -38,7 +37,7 @@ public final class Id3DecoderTest {
private static final int ID3_TEXT_ENCODING_UTF_8 = 3;
@Test
public void testDecodeTxxxFrame() throws MetadataDecoderException {
public void testDecodeTxxxFrame() {
byte[] rawId3 = buildSingleFrameTag("TXXX", new byte[] {3, 0, 109, 100, 105, 97, 108, 111, 103,
95, 86, 73, 78, 68, 73, 67, 79, 49, 53, 50, 55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0});
Id3Decoder decoder = new Id3Decoder();
@ -65,7 +64,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeTextInformationFrame() throws MetadataDecoderException {
public void testDecodeTextInformationFrame() {
byte[] rawId3 = buildSingleFrameTag("TIT2", new byte[] {3, 72, 101, 108, 108, 111, 32, 87, 111,
114, 108, 100, 0});
Id3Decoder decoder = new Id3Decoder();
@ -92,7 +91,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeWxxxFrame() throws MetadataDecoderException {
public void testDecodeWxxxFrame() {
byte[] rawId3 = buildSingleFrameTag("WXXX", new byte[] {ID3_TEXT_ENCODING_UTF_8, 116, 101, 115,
116, 0, 104, 116, 116, 112, 115, 58, 47, 47, 116, 101, 115, 116, 46, 99, 111, 109, 47, 97,
98, 99, 63, 100, 101, 102});
@ -120,7 +119,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeUrlLinkFrame() throws MetadataDecoderException {
public void testDecodeUrlLinkFrame() {
byte[] rawId3 = buildSingleFrameTag("WCOM", new byte[] {104, 116, 116, 112, 115, 58, 47, 47,
116, 101, 115, 116, 46, 99, 111, 109, 47, 97, 98, 99, 63, 100, 101, 102});
Id3Decoder decoder = new Id3Decoder();
@ -142,7 +141,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodePrivFrame() throws MetadataDecoderException {
public void testDecodePrivFrame() {
byte[] rawId3 = buildSingleFrameTag("PRIV", new byte[] {116, 101, 115, 116, 0, 1, 2, 3, 4});
Id3Decoder decoder = new Id3Decoder();
Metadata metadata = decoder.decode(rawId3, rawId3.length);
@ -161,7 +160,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeApicFrame() throws MetadataDecoderException {
public void testDecodeApicFrame() {
byte[] rawId3 = buildSingleFrameTag("APIC", new byte[] {3, 105, 109, 97, 103, 101, 47, 106, 112,
101, 103, 0, 16, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 0});
@ -177,7 +176,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeCommentFrame() throws MetadataDecoderException {
public void testDecodeCommentFrame() {
byte[] rawId3 = buildSingleFrameTag("COMM", new byte[] {ID3_TEXT_ENCODING_UTF_8, 101, 110, 103,
100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 0, 116, 101, 120, 116, 0});
Id3Decoder decoder = new Id3Decoder();
@ -204,7 +203,7 @@ public final class Id3DecoderTest {
}
@Test
public void testDecodeMultiFrames() throws MetadataDecoderException {
public void testDecodeMultiFrames() {
byte[] rawId3 =
buildMultiFramesTag(
new FrameSpec(

View File

@ -19,7 +19,6 @@ import static com.google.android.exoplayer2.C.TIME_UNSET;
import static com.google.common.truth.Truth.assertThat;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoderException;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
import com.google.android.exoplayer2.util.TimestampAdjuster;
import java.nio.ByteBuffer;
@ -45,7 +44,7 @@ public final class SpliceInfoDecoderTest {
}
@Test
public void testWrappedAroundTimeSignalCommand() throws MetadataDecoderException {
public void testWrappedAroundTimeSignalCommand() {
byte[] rawTimeSignalSection = new byte[] {
0, // table_id.
(byte) 0x80, // section_syntax_indicator, private_indicator, reserved, section_length(4).
@ -72,7 +71,7 @@ public final class SpliceInfoDecoderTest {
}
@Test
public void test2SpliceInsertCommands() throws MetadataDecoderException {
public void test2SpliceInsertCommands() {
byte[] rawSpliceInsertCommand1 = new byte[] {
0, // table_id.
(byte) 0x80, // section_syntax_indicator, private_indicator, reserved, section_length(4).
@ -165,8 +164,7 @@ public final class SpliceInfoDecoderTest {
assertThat(command.availsExpected).isEqualTo(2);
}
private Metadata feedInputBuffer(byte[] data, long timeUs, long subsampleOffset)
throws MetadataDecoderException{
private Metadata feedInputBuffer(byte[] data, long timeUs, long subsampleOffset) {
inputBuffer.clear();
inputBuffer.data = ByteBuffer.allocate(data.length).put(data);
inputBuffer.timeUs = timeUs;