Commit bc4dc591 by andrewlewis Committed by Oliver Woodman

Fix some style nits in ID3 chapter support.

Issue: #2316

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=144815010
parent 877c7f4e
...@@ -19,9 +19,9 @@ import android.os.Parcel; ...@@ -19,9 +19,9 @@ import android.os.Parcel;
import junit.framework.TestCase; import junit.framework.TestCase;
/** /**
* Test for {@link ChapterTOCFrame}. * Test for {@link ChapterTocFrame}.
*/ */
public final class ChapterTOCFrameTest extends TestCase { public final class ChapterTocFrameTest extends TestCase {
public void testParcelable() { public void testParcelable() {
String[] children = new String[] {"child0", "child1"}; String[] children = new String[] {"child0", "child1"};
...@@ -29,15 +29,15 @@ public final class ChapterTOCFrameTest extends TestCase { ...@@ -29,15 +29,15 @@ public final class ChapterTOCFrameTest extends TestCase {
new TextInformationFrame("TIT2", null, "title"), new TextInformationFrame("TIT2", null, "title"),
new UrlLinkFrame("WXXX", "description", "url") new UrlLinkFrame("WXXX", "description", "url")
}; };
ChapterTOCFrame chapterTOCFrameToParcel = new ChapterTOCFrame("id", false, true, children, ChapterTocFrame chapterTocFrameToParcel = new ChapterTocFrame("id", false, true, children,
subFrames); subFrames);
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
chapterTOCFrameToParcel.writeToParcel(parcel, 0); chapterTocFrameToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0); parcel.setDataPosition(0);
ChapterTOCFrame chapterTOCFrameFromParcel = ChapterTOCFrame.CREATOR.createFromParcel(parcel); ChapterTocFrame chapterTocFrameFromParcel = ChapterTocFrame.CREATOR.createFromParcel(parcel);
assertEquals(chapterTOCFrameToParcel, chapterTOCFrameFromParcel); assertEquals(chapterTocFrameToParcel, chapterTocFrameFromParcel);
parcel.recycle(); parcel.recycle();
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.metadata.id3; package com.google.android.exoplayer2.metadata.id3;
import android.os.Parcel; import android.os.Parcel;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.Arrays; import java.util.Arrays;
...@@ -27,18 +28,24 @@ public final class ChapterFrame extends Id3Frame { ...@@ -27,18 +28,24 @@ public final class ChapterFrame extends Id3Frame {
public static final String ID = "CHAP"; public static final String ID = "CHAP";
public final String chapterId; public final String chapterId;
public final int startTime; public final int startTimeMs;
public final int endTime; public final int endTimeMs;
public final int startOffset; /**
public final int endOffset; * The byte offset of the start of the chapter, or {@link C#POSITION_UNSET} if not set.
*/
public final long startOffset;
/**
* The byte offset of the end of the chapter, or {@link C#POSITION_UNSET} if not set.
*/
public final long endOffset;
private final Id3Frame[] subFrames; private final Id3Frame[] subFrames;
public ChapterFrame(String chapterId, int startTime, int endTime, int startOffset, int endOffset, public ChapterFrame(String chapterId, int startTimeMs, int endTimeMs, long startOffset,
Id3Frame[] subFrames) { long endOffset, Id3Frame[] subFrames) {
super(ID); super(ID);
this.chapterId = chapterId; this.chapterId = chapterId;
this.startTime = startTime; this.startTimeMs = startTimeMs;
this.endTime = endTime; this.endTimeMs = endTimeMs;
this.startOffset = startOffset; this.startOffset = startOffset;
this.endOffset = endOffset; this.endOffset = endOffset;
this.subFrames = subFrames; this.subFrames = subFrames;
...@@ -47,10 +54,10 @@ public final class ChapterFrame extends Id3Frame { ...@@ -47,10 +54,10 @@ public final class ChapterFrame extends Id3Frame {
/* package */ ChapterFrame(Parcel in) { /* package */ ChapterFrame(Parcel in) {
super(ID); super(ID);
this.chapterId = in.readString(); this.chapterId = in.readString();
this.startTime = in.readInt(); this.startTimeMs = in.readInt();
this.endTime = in.readInt(); this.endTimeMs = in.readInt();
this.startOffset = in.readInt(); this.startOffset = in.readLong();
this.endOffset = in.readInt(); this.endOffset = in.readLong();
int subFrameCount = in.readInt(); int subFrameCount = in.readInt();
subFrames = new Id3Frame[subFrameCount]; subFrames = new Id3Frame[subFrameCount];
for (int i = 0; i < subFrameCount; i++) { for (int i = 0; i < subFrameCount; i++) {
...@@ -58,6 +65,20 @@ public final class ChapterFrame extends Id3Frame { ...@@ -58,6 +65,20 @@ public final class ChapterFrame extends Id3Frame {
} }
} }
/**
* Returns the number of sub-frames.
*/
public int getSubFrameCount() {
return subFrames.length;
}
/**
* Returns the sub-frame at {@code index}.
*/
public Id3Frame getSubFrame(int index) {
return subFrames[index];
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
...@@ -67,8 +88,8 @@ public final class ChapterFrame extends Id3Frame { ...@@ -67,8 +88,8 @@ public final class ChapterFrame extends Id3Frame {
return false; return false;
} }
ChapterFrame other = (ChapterFrame) obj; ChapterFrame other = (ChapterFrame) obj;
return startTime == other.startTime return startTimeMs == other.startTimeMs
&& endTime == other.endTime && endTimeMs == other.endTimeMs
&& startOffset == other.startOffset && startOffset == other.startOffset
&& endOffset == other.endOffset && endOffset == other.endOffset
&& Util.areEqual(chapterId, other.chapterId) && Util.areEqual(chapterId, other.chapterId)
...@@ -78,10 +99,10 @@ public final class ChapterFrame extends Id3Frame { ...@@ -78,10 +99,10 @@ public final class ChapterFrame extends Id3Frame {
@Override @Override
public int hashCode() { public int hashCode() {
int result = 17; int result = 17;
result = 31 * result + startTime; result = 31 * result + startTimeMs;
result = 31 * result + endTime; result = 31 * result + endTimeMs;
result = 31 * result + startOffset; result = 31 * result + (int) startOffset;
result = 31 * result + endOffset; result = 31 * result + (int) endOffset;
result = 31 * result + (chapterId != null ? chapterId.hashCode() : 0); result = 31 * result + (chapterId != null ? chapterId.hashCode() : 0);
return result; return result;
} }
...@@ -89,13 +110,13 @@ public final class ChapterFrame extends Id3Frame { ...@@ -89,13 +110,13 @@ public final class ChapterFrame extends Id3Frame {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(chapterId); dest.writeString(chapterId);
dest.writeInt(startTime); dest.writeInt(startTimeMs);
dest.writeInt(endTime); dest.writeInt(endTimeMs);
dest.writeInt(startOffset); dest.writeLong(startOffset);
dest.writeInt(endOffset); dest.writeLong(endOffset);
dest.writeInt(subFrames.length); dest.writeInt(subFrames.length);
for (int i = 0; i < subFrames.length; i++) { for (Id3Frame subFrame : subFrames) {
dest.writeParcelable(subFrames[i], 0); dest.writeParcelable(subFrame, 0);
} }
} }
......
...@@ -16,15 +16,13 @@ ...@@ -16,15 +16,13 @@
package com.google.android.exoplayer2.metadata.id3; package com.google.android.exoplayer2.metadata.id3;
import android.os.Parcel; import android.os.Parcel;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.Arrays; import java.util.Arrays;
/** /**
* Chapter table of contents ID3 frame. * Chapter table of contents ID3 frame.
*/ */
public final class ChapterTOCFrame extends Id3Frame { public final class ChapterTocFrame extends Id3Frame {
public static final String ID = "CTOC"; public static final String ID = "CTOC";
...@@ -32,9 +30,9 @@ public final class ChapterTOCFrame extends Id3Frame { ...@@ -32,9 +30,9 @@ public final class ChapterTOCFrame extends Id3Frame {
public final boolean isRoot; public final boolean isRoot;
public final boolean isOrdered; public final boolean isOrdered;
public final String[] children; public final String[] children;
public final Id3Frame[] subFrames; private final Id3Frame[] subFrames;
public ChapterTOCFrame(String elementId, boolean isRoot, boolean isOrdered, String[] children, public ChapterTocFrame(String elementId, boolean isRoot, boolean isOrdered, String[] children,
Id3Frame[] subFrames) { Id3Frame[] subFrames) {
super(ID); super(ID);
this.elementId = elementId; this.elementId = elementId;
...@@ -44,7 +42,7 @@ public final class ChapterTOCFrame extends Id3Frame { ...@@ -44,7 +42,7 @@ public final class ChapterTOCFrame extends Id3Frame {
this.subFrames = subFrames; this.subFrames = subFrames;
} }
/* package */ ChapterTOCFrame(Parcel in) { /* package */ ChapterTocFrame(Parcel in) {
super(ID); super(ID);
this.elementId = in.readString(); this.elementId = in.readString();
this.isRoot = in.readByte() != 0; this.isRoot = in.readByte() != 0;
...@@ -57,6 +55,20 @@ public final class ChapterTOCFrame extends Id3Frame { ...@@ -57,6 +55,20 @@ public final class ChapterTOCFrame extends Id3Frame {
} }
} }
/**
* Returns the number of sub-frames.
*/
public int getSubFrameCount() {
return subFrames.length;
}
/**
* Returns the sub-frame at {@code index}.
*/
public Id3Frame getSubFrame(int index) {
return subFrames[index];
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) { if (this == obj) {
...@@ -65,7 +77,7 @@ public final class ChapterTOCFrame extends Id3Frame { ...@@ -65,7 +77,7 @@ public final class ChapterTOCFrame extends Id3Frame {
if (obj == null || getClass() != obj.getClass()) { if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
ChapterTOCFrame other = (ChapterTOCFrame) obj; ChapterTocFrame other = (ChapterTocFrame) obj;
return isRoot == other.isRoot return isRoot == other.isRoot
&& isOrdered == other.isOrdered && isOrdered == other.isOrdered
&& Util.areEqual(elementId, other.elementId) && Util.areEqual(elementId, other.elementId)
...@@ -94,16 +106,16 @@ public final class ChapterTOCFrame extends Id3Frame { ...@@ -94,16 +106,16 @@ public final class ChapterTOCFrame extends Id3Frame {
} }
} }
public static final Creator<ChapterTOCFrame> CREATOR = new Creator<ChapterTOCFrame>() { public static final Creator<ChapterTocFrame> CREATOR = new Creator<ChapterTocFrame>() {
@Override @Override
public ChapterTOCFrame createFromParcel(Parcel in) { public ChapterTocFrame createFromParcel(Parcel in) {
return new ChapterTOCFrame(in); return new ChapterTocFrame(in);
} }
@Override @Override
public ChapterTOCFrame[] newArray(int size) { public ChapterTocFrame[] newArray(int size) {
return new ChapterTOCFrame[size]; return new ChapterTocFrame[size];
} }
}; };
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.metadata.id3; package com.google.android.exoplayer2.metadata.id3;
import android.util.Log; import android.util.Log;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataDecoder; import com.google.android.exoplayer2.metadata.MetadataDecoder;
import com.google.android.exoplayer2.metadata.MetadataInputBuffer; import com.google.android.exoplayer2.metadata.MetadataInputBuffer;
...@@ -368,8 +369,8 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -368,8 +369,8 @@ public final class Id3Decoder implements MetadataDecoder {
return new TextInformationFrame(id, null, value); return new TextInformationFrame(id, null, value);
} }
private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, private static UrlLinkFrame decodeWxxxFrame(ParsableByteArray id3Data, int frameSize)
int frameSize) throws UnsupportedEncodingException { throws UnsupportedEncodingException {
int encoding = id3Data.readUnsignedByte(); int encoding = id3Data.readUnsignedByte();
String charset = getCharsetName(encoding); String charset = getCharsetName(encoding);
...@@ -523,8 +524,14 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -523,8 +524,14 @@ public final class Id3Decoder implements MetadataDecoder {
int startTime = id3Data.readInt(); int startTime = id3Data.readInt();
int endTime = id3Data.readInt(); int endTime = id3Data.readInt();
int startOffset = id3Data.readInt(); long startOffset = id3Data.readUnsignedInt();
int endOffset = id3Data.readInt(); if (startOffset == 0xFFFFFFFFL) {
startOffset = C.POSITION_UNSET;
}
long endOffset = id3Data.readUnsignedInt();
if (endOffset == 0xFFFFFFFFL) {
endOffset = C.POSITION_UNSET;
}
ArrayList<Id3Frame> subFrames = new ArrayList<>(); ArrayList<Id3Frame> subFrames = new ArrayList<>();
int limit = framePosition + frameSize; int limit = framePosition + frameSize;
...@@ -541,7 +548,7 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -541,7 +548,7 @@ public final class Id3Decoder implements MetadataDecoder {
return new ChapterFrame(chapterId, startTime, endTime, startOffset, endOffset, subFrameArray); return new ChapterFrame(chapterId, startTime, endTime, startOffset, endOffset, subFrameArray);
} }
private static ChapterTOCFrame decodeChapterTOCFrame(ParsableByteArray id3Data, int frameSize, private static ChapterTocFrame decodeChapterTOCFrame(ParsableByteArray id3Data, int frameSize,
int majorVersion, boolean unsignedIntFrameSizeHack, int frameHeaderSize) int majorVersion, boolean unsignedIntFrameSizeHack, int frameHeaderSize)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
int framePosition = id3Data.getPosition(); int framePosition = id3Data.getPosition();
...@@ -575,7 +582,7 @@ public final class Id3Decoder implements MetadataDecoder { ...@@ -575,7 +582,7 @@ public final class Id3Decoder implements MetadataDecoder {
Id3Frame[] subFrameArray = new Id3Frame[subFrames.size()]; Id3Frame[] subFrameArray = new Id3Frame[subFrames.size()];
subFrames.toArray(subFrameArray); subFrames.toArray(subFrameArray);
return new ChapterTOCFrame(elementId, isRoot, isOrdered, children, subFrameArray); return new ChapterTocFrame(elementId, isRoot, isOrdered, children, subFrameArray);
} }
private static BinaryFrame decodeBinaryFrame(ParsableByteArray id3Data, int frameSize, private static BinaryFrame decodeBinaryFrame(ParsableByteArray id3Data, int frameSize,
......
...@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.metadata.id3; ...@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.metadata.id3;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment