Commit cb9a64da by olly Committed by Oliver Woodman

Merge ID3 parsing improvements from GitHub.

- Parse APIC and TextInformation frames.
- In MPEG-TS, don't mind if packets contain end padding.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124079930
parent 444d2156
......@@ -30,9 +30,11 @@ import com.google.android.exoplayer.TrackGroupArray;
import com.google.android.exoplayer.drm.DrmSessionManager;
import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
import com.google.android.exoplayer.drm.UnsupportedDrmException;
import com.google.android.exoplayer.metadata.id3.ApicFrame;
import com.google.android.exoplayer.metadata.id3.GeobFrame;
import com.google.android.exoplayer.metadata.id3.Id3Frame;
import com.google.android.exoplayer.metadata.id3.PrivFrame;
import com.google.android.exoplayer.metadata.id3.TextInformationFrame;
import com.google.android.exoplayer.metadata.id3.TxxxFrame;
import com.google.android.exoplayer.text.CaptionStyleCompat;
import com.google.android.exoplayer.text.Cue;
......@@ -533,6 +535,14 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
GeobFrame geobFrame = (GeobFrame) id3Frame;
Log.i(TAG, String.format("ID3 TimedMetadata %s: mimeType=%s, filename=%s, description=%s",
geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
} else if (id3Frame instanceof ApicFrame) {
ApicFrame apicFrame = (ApicFrame) id3Frame;
Log.i(TAG, String.format("ID3 TimedMetadata %s: mimeType=%s, description=%s",
apicFrame.id, apicFrame.mimeType, apicFrame.description));
} else if (id3Frame instanceof TextInformationFrame) {
TextInformationFrame textInformationFrame = (TextInformationFrame) id3Frame;
Log.i(TAG, String.format("ID3 TimedMetadata %s: description=%s", textInformationFrame.id,
textInformationFrame.description));
} else {
Log.i(TAG, String.format("ID3 TimedMetadata %s", id3Frame.id));
}
......
......@@ -15,6 +15,9 @@
*/
package com.google.android.exoplayer.metadata.id3;
import com.google.android.exoplayer.ParserException;
import android.test.MoreAsserts;
import junit.framework.TestCase;
import java.util.List;
......@@ -24,21 +27,42 @@ import java.util.List;
*/
public class Id3ParserTest extends TestCase {
public void testParseTxxxFrames() {
byte[] rawId3 = new byte[] {73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31,
0, 0, 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};
public void testParseTxxxFrame() throws ParserException {
byte[] rawId3 = new byte[] {73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31, 0, 0,
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};
Id3Parser parser = new Id3Parser();
List<Id3Frame> id3Frames = parser.parse(rawId3, rawId3.length);
assertEquals(1, id3Frames.size());
TxxxFrame txxxFrame = (TxxxFrame) id3Frames.get(0);
assertEquals("", txxxFrame.description);
assertEquals("mdialog_VINDICO1527664_start", txxxFrame.value);
}
public void testParseApicFrame() throws ParserException {
byte[] rawId3 = new byte[] {73, 68, 51, 4, 0, 0, 0, 0, 0, 45, 65, 80, 73, 67, 0, 0, 0, 35, 0, 0,
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};
Id3Parser parser = new Id3Parser();
List<Id3Frame> id3Frames = parser.parse(rawId3, rawId3.length);
assertEquals(1, id3Frames.size());
ApicFrame apicFrame = (ApicFrame) id3Frames.get(0);
assertEquals("image/jpeg", apicFrame.mimeType);
assertEquals(16, apicFrame.pictureType);
assertEquals("Hello World", apicFrame.description);
assertEquals(10, apicFrame.pictureData.length);
MoreAsserts.assertEquals(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, apicFrame.pictureData);
}
public void testParseTextInformationFrame() throws ParserException {
byte[] rawId3 = new byte[] {73, 68, 51, 4, 0, 0, 0, 0, 0, 23, 84, 73, 84, 50, 0, 0, 0, 13, 0, 0,
3, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 0};
Id3Parser parser = new Id3Parser();
try {
List<Id3Frame> id3Frames = parser.parse(rawId3, rawId3.length);
assertNotNull(id3Frames);
assertEquals(1, id3Frames.size());
TxxxFrame txxxFrame = (TxxxFrame) id3Frames.get(0);
assertEquals("", txxxFrame.description);
assertEquals("mdialog_VINDICO1527664_start", txxxFrame.value);
} catch (Exception exception) {
fail(exception.getMessage());
}
List<Id3Frame> id3Frames = parser.parse(rawId3, rawId3.length);
assertEquals(1, id3Frames.size());
TextInformationFrame textInformationFrame = (TextInformationFrame) id3Frames.get(0);
assertEquals("TIT2", textInformationFrame.id);
assertEquals("Hello World", textInformationFrame.description);
}
}
......@@ -79,8 +79,9 @@ import com.google.android.exoplayer.util.ParsableByteArray;
}
}
// Write data to the output.
output.sampleData(data, bytesAvailable);
sampleBytesRead += bytesAvailable;
int bytesToWrite = Math.min(bytesAvailable, sampleSize - sampleBytesRead);
output.sampleData(data, bytesToWrite);
sampleBytesRead += bytesToWrite;
}
@Override
......
......@@ -15,7 +15,7 @@
*/
package com.google.android.exoplayer.metadata;
import java.io.IOException;
import com.google.android.exoplayer.ParserException;
/**
* Parses objects of type <T> from binary data.
......@@ -38,8 +38,8 @@ public interface MetadataParser<T> {
* @param data The raw binary data from which to parse the metadata.
* @param size The size of the input data.
* @return @return A parsed metadata object of type <T>.
* @throws IOException If a problem occurred parsing the data.
* @throws ParserException If a problem occurred parsing the data.
*/
T parse(byte[] data, int size) throws IOException;
T parse(byte[] data, int size) throws ParserException;
}
/*
* Copyright (C) 2014 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.exoplayer.metadata.id3;
/**
* APIC (Attached Picture) ID3 frame.
*/
public final class ApicFrame extends Id3Frame {
public static final String ID = "APIC";
public final String mimeType;
public final String description;
public final int pictureType;
public final byte[] pictureData;
public ApicFrame(String mimeType, String description, int pictureType, byte[] pictureData) {
super(ID);
this.mimeType = mimeType;
this.description = description;
this.pictureType = pictureType;
this.pictureData = pictureData;
}
}
/*
* Copyright (C) 2014 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.exoplayer.metadata.id3;
/**
* Text information ("T000" - "TZZZ", excluding "TXXX") ID3 frame.
*/
public final class TextInformationFrame extends Id3Frame {
public final String description;
public TextInformationFrame(String id, String description) {
super(id);
this.description = description;
}
}
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