Skip to content

Commit 9cfff0b

Browse files
committed
Merge cleaned version of #1234.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117224172
1 parent 99606f6 commit 9cfff0b

File tree

9 files changed

+131
-74
lines changed

9 files changed

+131
-74
lines changed

demo/src/main/java/com/google/android/exoplayer/demo/PlayerActivity.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
import com.google.android.exoplayer.demo.player.SmoothStreamingSourceBuilder;
3131
import com.google.android.exoplayer.demo.ui.TrackSelectionHelper;
3232
import com.google.android.exoplayer.drm.UnsupportedDrmException;
33-
import com.google.android.exoplayer.metadata.GeobMetadata;
34-
import com.google.android.exoplayer.metadata.PrivMetadata;
35-
import com.google.android.exoplayer.metadata.TxxxMetadata;
33+
import com.google.android.exoplayer.metadata.id3.GeobFrame;
34+
import com.google.android.exoplayer.metadata.id3.Id3Frame;
35+
import com.google.android.exoplayer.metadata.id3.PrivFrame;
36+
import com.google.android.exoplayer.metadata.id3.TxxxFrame;
3637
import com.google.android.exoplayer.text.CaptionStyleCompat;
3738
import com.google.android.exoplayer.text.Cue;
3839
import com.google.android.exoplayer.text.SubtitleLayout;
@@ -67,7 +68,6 @@
6768
import java.net.CookieManager;
6869
import java.net.CookiePolicy;
6970
import java.util.List;
70-
import java.util.Map;
7171

7272
/**
7373
* An activity that plays media using {@link DemoPlayer}.
@@ -447,23 +447,21 @@ public void onCues(List<Cue> cues) {
447447
// DemoPlayer.MetadataListener implementation
448448

449449
@Override
450-
public void onId3Metadata(Map<String, Object> metadata) {
451-
for (Map.Entry<String, Object> entry : metadata.entrySet()) {
452-
if (TxxxMetadata.TYPE.equals(entry.getKey())) {
453-
TxxxMetadata txxxMetadata = (TxxxMetadata) entry.getValue();
454-
Log.i(TAG, String.format("ID3 TimedMetadata %s: description=%s, value=%s",
455-
TxxxMetadata.TYPE, txxxMetadata.description, txxxMetadata.value));
456-
} else if (PrivMetadata.TYPE.equals(entry.getKey())) {
457-
PrivMetadata privMetadata = (PrivMetadata) entry.getValue();
458-
Log.i(TAG, String.format("ID3 TimedMetadata %s: owner=%s",
459-
PrivMetadata.TYPE, privMetadata.owner));
460-
} else if (GeobMetadata.TYPE.equals(entry.getKey())) {
461-
GeobMetadata geobMetadata = (GeobMetadata) entry.getValue();
450+
public void onId3Metadata(List<Id3Frame> id3Frames) {
451+
for (Id3Frame id3Frame : id3Frames) {
452+
if (id3Frame instanceof TxxxFrame) {
453+
TxxxFrame txxxFrame = (TxxxFrame) id3Frame;
454+
Log.i(TAG, String.format("ID3 TimedMetadata %s: description=%s, value=%s", txxxFrame.id,
455+
txxxFrame.description, txxxFrame.value));
456+
} else if (id3Frame instanceof PrivFrame) {
457+
PrivFrame privFrame = (PrivFrame) id3Frame;
458+
Log.i(TAG, String.format("ID3 TimedMetadata %s: owner=%s", privFrame.id, privFrame.owner));
459+
} else if (id3Frame instanceof GeobFrame) {
460+
GeobFrame geobFrame = (GeobFrame) id3Frame;
462461
Log.i(TAG, String.format("ID3 TimedMetadata %s: mimeType=%s, filename=%s, description=%s",
463-
GeobMetadata.TYPE, geobMetadata.mimeType, geobMetadata.filename,
464-
geobMetadata.description));
462+
geobFrame.id, geobFrame.mimeType, geobFrame.filename, geobFrame.description));
465463
} else {
466-
Log.i(TAG, String.format("ID3 TimedMetadata %s", entry.getKey()));
464+
Log.i(TAG, String.format("ID3 TimedMetadata %s", id3Frame.id));
467465
}
468466
}
469467
}

demo/src/main/java/com/google/android/exoplayer/demo/player/DemoPlayer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434
import com.google.android.exoplayer.dash.DashChunkSource;
3535
import com.google.android.exoplayer.drm.StreamingDrmSessionManager;
3636
import com.google.android.exoplayer.hls.HlsSampleSource;
37-
import com.google.android.exoplayer.metadata.Id3Parser;
3837
import com.google.android.exoplayer.metadata.MetadataTrackRenderer;
3938
import com.google.android.exoplayer.metadata.MetadataTrackRenderer.MetadataRenderer;
39+
import com.google.android.exoplayer.metadata.id3.Id3Frame;
40+
import com.google.android.exoplayer.metadata.id3.Id3Parser;
4041
import com.google.android.exoplayer.text.Cue;
4142
import com.google.android.exoplayer.text.TextRenderer;
4243
import com.google.android.exoplayer.text.TextTrackRenderer;
@@ -54,7 +55,6 @@
5455

5556
import java.io.IOException;
5657
import java.util.List;
57-
import java.util.Map;
5858
import java.util.concurrent.CopyOnWriteArrayList;
5959

6060
/**
@@ -66,7 +66,7 @@ public class DemoPlayer implements ExoPlayer.Listener, DefaultTrackSelector.Even
6666
ChunkSampleSource.EventListener, HlsSampleSource.EventListener,
6767
DefaultBandwidthMeter.EventListener, MediaCodecVideoTrackRenderer.EventListener,
6868
MediaCodecAudioTrackRenderer.EventListener, StreamingDrmSessionManager.EventListener,
69-
DashChunkSource.EventListener, TextRenderer, MetadataRenderer<Map<String, Object>>,
69+
DashChunkSource.EventListener, TextRenderer, MetadataRenderer<List<Id3Frame>>,
7070
DebugTextViewHelper.Provider {
7171

7272
/**
@@ -140,7 +140,7 @@ public interface CaptionListener {
140140
* A listener for receiving ID3 metadata parsed from the media stream.
141141
*/
142142
public interface Id3MetadataListener {
143-
void onId3Metadata(Map<String, Object> metadata);
143+
void onId3Metadata(List<Id3Frame> id3Frames);
144144
}
145145

146146
// Constants pulled into this class for convenience.
@@ -187,8 +187,8 @@ public DemoPlayer(Context context, SourceBuilder sourceBuilder) {
187187
true, mainHandler, this, AudioCapabilities.getCapabilities(context),
188188
AudioManager.STREAM_MUSIC);
189189
TrackRenderer textRenderer = new TextTrackRenderer(this, mainHandler.getLooper());
190-
MetadataTrackRenderer<Map<String, Object>> id3Renderer = new MetadataTrackRenderer<>(
191-
new Id3Parser(), this, mainHandler.getLooper());
190+
MetadataTrackRenderer<List<Id3Frame>> id3Renderer = new MetadataTrackRenderer<>(new Id3Parser(),
191+
this, mainHandler.getLooper());
192192
TrackRenderer[] renderers = new TrackRenderer[] {videoRenderer, audioRenderer, textRenderer,
193193
id3Renderer};
194194

@@ -434,9 +434,9 @@ public void onCues(List<Cue> cues) {
434434
}
435435

436436
@Override
437-
public void onMetadata(Map<String, Object> metadata) {
437+
public void onMetadata(List<Id3Frame> id3Frames) {
438438
if (id3MetadataListener != null && trackInfo.getTrackSelection(TYPE_METADATA) != null) {
439-
id3MetadataListener.onId3Metadata(metadata);
439+
id3MetadataListener.onId3Metadata(id3Frames);
440440
}
441441
}
442442

library/src/androidTest/java/com/google/android/exoplayer/metadata/Id3ParserTest.java renamed to library/src/androidTest/java/com/google/android/exoplayer/metadata/id3/Id3ParserTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,29 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.google.android.exoplayer.metadata;
16+
package com.google.android.exoplayer.metadata.id3;
1717

1818
import junit.framework.TestCase;
1919

20-
import java.util.Map;
20+
import java.util.List;
2121

2222
/**
2323
* Test for {@link Id3Parser}
2424
*/
2525
public class Id3ParserTest extends TestCase {
2626

2727
public void testParseTxxxFrames() {
28-
byte[] rawId3 = new byte[] { 73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31,
28+
byte[] rawId3 = new byte[] {73, 68, 51, 4, 0, 0, 0, 0, 0, 41, 84, 88, 88, 88, 0, 0, 0, 31,
2929
0, 0, 3, 0, 109, 100, 105, 97, 108, 111, 103, 95, 86, 73, 78, 68, 73, 67, 79, 49, 53, 50,
30-
55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0 };
31-
30+
55, 54, 54, 52, 95, 115, 116, 97, 114, 116, 0};
3231
Id3Parser parser = new Id3Parser();
3332
try {
34-
Map<String, Object> metadata = parser.parse(rawId3, rawId3.length);
35-
assertNotNull(metadata);
36-
assertEquals(1, metadata.size());
37-
TxxxMetadata txxx = (TxxxMetadata) metadata.get(TxxxMetadata.TYPE);
38-
assertNotNull(txxx);
39-
assertEquals("", txxx.description);
40-
assertEquals("mdialog_VINDICO1527664_start", txxx.value);
33+
List<Id3Frame> id3Frames = parser.parse(rawId3, rawId3.length);
34+
assertNotNull(id3Frames);
35+
assertEquals(1, id3Frames.size());
36+
TxxxFrame txxxFrame = (TxxxFrame) id3Frames.get(0);
37+
assertEquals("", txxxFrame.description);
38+
assertEquals("mdialog_VINDICO1527664_start", txxxFrame.value);
4139
} catch (Exception exception) {
4240
fail(exception.getMessage());
4341
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.android.exoplayer.metadata.id3;
17+
18+
/**
19+
* Binary ID3 frame.
20+
*/
21+
public final class BinaryFrame extends Id3Frame {
22+
23+
public final byte[] data;
24+
25+
public BinaryFrame(String type, byte[] data) {
26+
super(type);
27+
this.data = data;
28+
}
29+
30+
}

library/src/main/java/com/google/android/exoplayer/metadata/GeobMetadata.java renamed to library/src/main/java/com/google/android/exoplayer/metadata/id3/GeobFrame.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.google.android.exoplayer.metadata;
16+
package com.google.android.exoplayer.metadata.id3;
1717

1818
/**
19-
* A metadata that contains parsed ID3 GEOB (General Encapsulated Object) frame data associated
20-
* with time indices.
19+
* GEOB (General Encapsulated Object) ID3 frame.
2120
*/
22-
public final class GeobMetadata {
21+
public final class GeobFrame extends Id3Frame {
2322

24-
public static final String TYPE = "GEOB";
23+
public static final String ID = "GEOB";
2524

2625
public final String mimeType;
2726
public final String filename;
2827
public final String description;
2928
public final byte[] data;
3029

31-
public GeobMetadata(String mimeType, String filename, String description, byte[] data) {
30+
public GeobFrame(String mimeType, String filename, String description, byte[] data) {
31+
super(ID);
3232
this.mimeType = mimeType;
3333
this.filename = filename;
3434
this.description = description;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.android.exoplayer.metadata.id3;
17+
18+
/**
19+
* Base class for ID3 frames.
20+
*/
21+
public abstract class Id3Frame {
22+
23+
/**
24+
* The frame ID.
25+
*/
26+
public final String id;
27+
28+
public Id3Frame(String id) {
29+
this.id = id;
30+
}
31+
32+
}

library/src/main/java/com/google/android/exoplayer/metadata/Id3Parser.java renamed to library/src/main/java/com/google/android/exoplayer/metadata/id3/Id3Parser.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.google.android.exoplayer.metadata;
16+
package com.google.android.exoplayer.metadata.id3;
1717

1818
import com.google.android.exoplayer.ParserException;
19+
import com.google.android.exoplayer.metadata.MetadataParser;
1920
import com.google.android.exoplayer.util.MimeTypes;
2021
import com.google.android.exoplayer.util.ParsableByteArray;
2122

2223
import java.io.UnsupportedEncodingException;
24+
import java.util.ArrayList;
2325
import java.util.Collections;
24-
import java.util.HashMap;
26+
import java.util.List;
2527
import java.util.Locale;
26-
import java.util.Map;
2728

2829
/**
2930
* Extracts individual TXXX text frames from raw ID3 data.
3031
*/
31-
public final class Id3Parser implements MetadataParser<Map<String, Object>> {
32+
public final class Id3Parser implements MetadataParser<List<Id3Frame>> {
3233

3334
private static final int ID3_TEXT_ENCODING_ISO_8859_1 = 0;
3435
private static final int ID3_TEXT_ENCODING_UTF_16 = 1;
@@ -41,9 +42,9 @@ public boolean canParse(String mimeType) {
4142
}
4243

4344
@Override
44-
public Map<String, Object> parse(byte[] data, int size)
45-
throws UnsupportedEncodingException, ParserException {
46-
Map<String, Object> metadata = new HashMap<>();
45+
public List<Id3Frame> parse(byte[] data, int size) throws UnsupportedEncodingException,
46+
ParserException {
47+
List<Id3Frame> id3Frames = new ArrayList<>();
4748
ParsableByteArray id3Data = new ParsableByteArray(data, size);
4849
int id3Size = parseId3Header(id3Data);
4950

@@ -70,9 +71,8 @@ public Map<String, Object> parse(byte[] data, int size)
7071
String description = new String(frame, 0, firstZeroIndex, charset);
7172
int valueStartIndex = firstZeroIndex + delimiterLength(encoding);
7273
int valueEndIndex = indexOfEOS(frame, valueStartIndex, encoding);
73-
String value = new String(frame, valueStartIndex, valueEndIndex - valueStartIndex,
74-
charset);
75-
metadata.put(TxxxMetadata.TYPE, new TxxxMetadata(description, value));
74+
String value = new String(frame, valueStartIndex, valueEndIndex - valueStartIndex, charset);
75+
id3Frames.add(new TxxxFrame(description, value));
7676
} else if (frameId0 == 'P' && frameId1 == 'R' && frameId2 == 'I' && frameId3 == 'V') {
7777
// Check frame ID == PRIV
7878
byte[] frame = new byte[frameSize];
@@ -82,7 +82,7 @@ public Map<String, Object> parse(byte[] data, int size)
8282
String owner = new String(frame, 0, firstZeroIndex, "ISO-8859-1");
8383
byte[] privateData = new byte[frameSize - firstZeroIndex - 1];
8484
System.arraycopy(frame, firstZeroIndex + 1, privateData, 0, frameSize - firstZeroIndex - 1);
85-
metadata.put(PrivMetadata.TYPE, new PrivMetadata(owner, privateData));
85+
id3Frames.add(new PrivFrame(owner, privateData));
8686
} else if (frameId0 == 'G' && frameId1 == 'E' && frameId2 == 'O' && frameId3 == 'B') {
8787
// Check frame ID == GEOB
8888
int encoding = id3Data.readUnsignedByte();
@@ -106,19 +106,18 @@ public Map<String, Object> parse(byte[] data, int size)
106106
byte[] objectData = new byte[objectDataSize];
107107
System.arraycopy(frame, descriptionEndIndex + delimiterLength(encoding), objectData, 0,
108108
objectDataSize);
109-
metadata.put(GeobMetadata.TYPE, new GeobMetadata(mimeType, filename,
110-
description, objectData));
109+
id3Frames.add(new GeobFrame(mimeType, filename, description, objectData));
111110
} else {
112111
String type = String.format(Locale.US, "%c%c%c%c", frameId0, frameId1, frameId2, frameId3);
113112
byte[] frame = new byte[frameSize];
114113
id3Data.readBytes(frame, 0, frameSize);
115-
metadata.put(type, frame);
114+
id3Frames.add(new BinaryFrame(type, frame));
116115
}
117116

118117
id3Size -= frameSize + 10 /* header size */;
119118
}
120119

121-
return Collections.unmodifiableMap(metadata);
120+
return Collections.unmodifiableList(id3Frames);
122121
}
123122

124123
private static int indexOf(byte[] data, int fromIndex, byte key) {
@@ -150,8 +149,8 @@ private static int indexOfEOS(byte[] data, int fromIndex, int encodingByte) {
150149
}
151150

152151
private static int delimiterLength(int encodingByte) {
153-
return (encodingByte == ID3_TEXT_ENCODING_ISO_8859_1
154-
|| encodingByte == ID3_TEXT_ENCODING_UTF_8) ? 1 : 2;
152+
return (encodingByte == ID3_TEXT_ENCODING_ISO_8859_1 || encodingByte == ID3_TEXT_ENCODING_UTF_8)
153+
? 1 : 2;
155154
}
156155

157156
/**

library/src/main/java/com/google/android/exoplayer/metadata/PrivMetadata.java renamed to library/src/main/java/com/google/android/exoplayer/metadata/id3/PrivFrame.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package com.google.android.exoplayer.metadata;
16+
package com.google.android.exoplayer.metadata.id3;
1717

1818
/**
19-
* A metadata that contains parsed ID3 PRIV (Private) frame data associated
20-
* with time indices.
19+
* PRIV (Private) ID3 frame.
2120
*/
22-
public final class PrivMetadata {
21+
public final class PrivFrame extends Id3Frame {
2322

24-
public static final String TYPE = "PRIV";
23+
public static final String ID = "PRIV";
2524

2625
public final String owner;
2726
public final byte[] privateData;
2827

29-
public PrivMetadata(String owner, byte[] privateData) {
28+
public PrivFrame(String owner, byte[] privateData) {
29+
super(ID);
3030
this.owner = owner;
3131
this.privateData = privateData;
3232
}

0 commit comments

Comments
 (0)