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=122743786
This commit is contained in:
parent
83b43a6fe6
commit
7465db2a22
@ -22,6 +22,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -60,52 +61,53 @@ public final class Id3Parser implements MetadataParser<List<Id3Frame>> {
|
||||
|
||||
// Skip frame flags.
|
||||
id3Data.skipBytes(2);
|
||||
// Check Frame ID == TXXX.
|
||||
|
||||
if (frameId0 == 'T' && frameId1 == 'X' && frameId2 == 'X' && frameId3 == 'X') {
|
||||
int encoding = id3Data.readUnsignedByte();
|
||||
String charset = getCharsetName(encoding);
|
||||
byte[] frame = new byte[frameSize - 1];
|
||||
id3Data.readBytes(frame, 0, frameSize - 1);
|
||||
|
||||
int firstZeroIndex = indexOfEOS(frame, 0, encoding);
|
||||
String description = new String(frame, 0, firstZeroIndex, charset);
|
||||
int valueStartIndex = firstZeroIndex + delimiterLength(encoding);
|
||||
int descriptionEndIndex = indexOfEOS(frame, 0, encoding);
|
||||
String description = new String(frame, 0, descriptionEndIndex, charset);
|
||||
|
||||
int valueStartIndex = descriptionEndIndex + delimiterLength(encoding);
|
||||
int valueEndIndex = indexOfEOS(frame, valueStartIndex, encoding);
|
||||
String value = new String(frame, valueStartIndex, valueEndIndex - valueStartIndex, charset);
|
||||
|
||||
id3Frames.add(new TxxxFrame(description, value));
|
||||
} else if (frameId0 == 'P' && frameId1 == 'R' && frameId2 == 'I' && frameId3 == 'V') {
|
||||
// Check frame ID == PRIV
|
||||
byte[] frame = new byte[frameSize];
|
||||
id3Data.readBytes(frame, 0, frameSize);
|
||||
|
||||
int firstZeroIndex = indexOf(frame, 0, (byte) 0);
|
||||
String owner = new String(frame, 0, firstZeroIndex, "ISO-8859-1");
|
||||
byte[] privateData = new byte[frameSize - firstZeroIndex - 1];
|
||||
System.arraycopy(frame, firstZeroIndex + 1, privateData, 0, frameSize - firstZeroIndex - 1);
|
||||
int ownerEndIndex = indexOf(frame, 0, (byte) 0);
|
||||
String owner = new String(frame, 0, ownerEndIndex, "ISO-8859-1");
|
||||
|
||||
byte[] privateData = Arrays.copyOfRange(frame, ownerEndIndex + 1, frame.length);
|
||||
|
||||
id3Frames.add(new PrivFrame(owner, privateData));
|
||||
} else if (frameId0 == 'G' && frameId1 == 'E' && frameId2 == 'O' && frameId3 == 'B') {
|
||||
// Check frame ID == GEOB
|
||||
int encoding = id3Data.readUnsignedByte();
|
||||
String charset = getCharsetName(encoding);
|
||||
byte[] frame = new byte[frameSize - 1];
|
||||
id3Data.readBytes(frame, 0, frameSize - 1);
|
||||
|
||||
int firstZeroIndex = indexOf(frame, 0, (byte) 0);
|
||||
String mimeType = new String(frame, 0, firstZeroIndex, "ISO-8859-1");
|
||||
int filenameStartIndex = firstZeroIndex + 1;
|
||||
int mimeTypeEndIndex = indexOf(frame, 0, (byte) 0);
|
||||
String mimeType = new String(frame, 0, mimeTypeEndIndex, "ISO-8859-1");
|
||||
|
||||
int filenameStartIndex = mimeTypeEndIndex + 1;
|
||||
int filenameEndIndex = indexOfEOS(frame, filenameStartIndex, encoding);
|
||||
String filename = new String(frame, filenameStartIndex,
|
||||
filenameEndIndex - filenameStartIndex, charset);
|
||||
|
||||
int descriptionStartIndex = filenameEndIndex + delimiterLength(encoding);
|
||||
int descriptionEndIndex = indexOfEOS(frame, descriptionStartIndex, encoding);
|
||||
String description = new String(frame, descriptionStartIndex,
|
||||
descriptionEndIndex - descriptionStartIndex, charset);
|
||||
|
||||
int objectDataSize = frameSize - 1 /* encoding byte */ - descriptionEndIndex
|
||||
- delimiterLength(encoding);
|
||||
byte[] objectData = new byte[objectDataSize];
|
||||
System.arraycopy(frame, descriptionEndIndex + delimiterLength(encoding), objectData, 0,
|
||||
objectDataSize);
|
||||
int objectDataStartIndex = descriptionEndIndex + delimiterLength(encoding);
|
||||
byte[] objectData = Arrays.copyOfRange(frame, objectDataStartIndex, frame.length);
|
||||
|
||||
id3Frames.add(new GeobFrame(mimeType, filename, description, objectData));
|
||||
} else {
|
||||
String type = String.format(Locale.US, "%c%c%c%c", frameId0, frameId1, frameId2, frameId3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user