diff --git a/library/common/src/main/java/com/google/android/exoplayer2/Format.java b/library/common/src/main/java/com/google/android/exoplayer2/Format.java
index 5ad355ce2d..4e15771f9a 100644
--- a/library/common/src/main/java/com/google/android/exoplayer2/Format.java
+++ b/library/common/src/main/java/com/google/android/exoplayer2/Format.java
@@ -108,6 +108,13 @@ import java.util.UUID;
*
* - {@link #accessibilityChannel}
*
+ *
+ *
+ *
+ *
+ * - {@link #tileCountHorizontal}
+ *
- {@link #tileCountVertical}
+ *
*/
public final class Format implements Bundleable {
@@ -167,6 +174,11 @@ public final class Format implements Bundleable {
private int accessibilityChannel;
+ // Image specific
+
+ private int tileCountHorizontal;
+ private int tileCountVertical;
+
// Provided by the source.
private @C.CryptoType int cryptoType;
@@ -190,6 +202,9 @@ public final class Format implements Bundleable {
pcmEncoding = NO_VALUE;
// Text specific.
accessibilityChannel = NO_VALUE;
+ // Image specific.
+ tileCountHorizontal = NO_VALUE;
+ tileCountVertical = NO_VALUE;
// Provided by the source.
cryptoType = C.CRYPTO_TYPE_NONE;
}
@@ -234,6 +249,9 @@ public final class Format implements Bundleable {
this.encoderPadding = format.encoderPadding;
// Text specific.
this.accessibilityChannel = format.accessibilityChannel;
+ // Image specific.
+ this.tileCountHorizontal = format.tileCountHorizontal;
+ this.tileCountVertical = format.tileCountVertical;
// Provided by the source.
this.cryptoType = format.cryptoType;
}
@@ -609,6 +627,32 @@ public final class Format implements Bundleable {
return this;
}
+ // Image specific.
+
+ /**
+ * Sets {@link Format#tileCountHorizontal}. The default value is {@link #NO_VALUE}.
+ *
+ * @param tileCountHorizontal The {@link Format#accessibilityChannel}.
+ * @return The builder.
+ */
+ @CanIgnoreReturnValue
+ public Builder setTileCountHorizontal(int tileCountHorizontal) {
+ this.tileCountHorizontal = tileCountHorizontal;
+ return this;
+ }
+
+ /**
+ * Sets {@link Format#tileCountVertical}. The default value is {@link #NO_VALUE}.
+ *
+ * @param tileCountVertical The {@link Format#accessibilityChannel}.
+ * @return The builder.
+ */
+ @CanIgnoreReturnValue
+ public Builder setTileCountVertical(int tileCountVertical) {
+ this.tileCountVertical = tileCountVertical;
+ return this;
+ }
+
// Provided by source.
/**
@@ -781,6 +825,15 @@ public final class Format implements Bundleable {
/** The Accessibility channel, or {@link #NO_VALUE} if not known or applicable. */
public final int accessibilityChannel;
+ // Image specific.
+
+ /**
+ * The number of horizontal tiles in an image, or {@link #NO_VALUE} if not known or applicable.
+ */
+ public final int tileCountHorizontal;
+ /** The number of vertical tiles in an image, or {@link #NO_VALUE} if not known or applicable. */
+ public final int tileCountVertical;
+
// Provided by source.
/**
@@ -1004,6 +1057,9 @@ public final class Format implements Bundleable {
encoderPadding = builder.encoderPadding == NO_VALUE ? 0 : builder.encoderPadding;
// Text specific.
accessibilityChannel = builder.accessibilityChannel;
+ // Image specific.
+ tileCountHorizontal = builder.tileCountHorizontal;
+ tileCountVertical = builder.tileCountVertical;
// Provided by source.
if (builder.cryptoType == C.CRYPTO_TYPE_NONE && drmInitData != null) {
// Encrypted content cannot use CRYPTO_TYPE_NONE.
@@ -1250,6 +1306,9 @@ public final class Format implements Bundleable {
result = 31 * result + encoderPadding;
// Text specific.
result = 31 * result + accessibilityChannel;
+ // Image specific.
+ result = 31 * result + tileCountHorizontal;
+ result = 31 * result + tileCountVertical;
// Provided by the source.
result = 31 * result + cryptoType;
hashCode = result;
@@ -1286,6 +1345,8 @@ public final class Format implements Bundleable {
&& encoderDelay == other.encoderDelay
&& encoderPadding == other.encoderPadding
&& accessibilityChannel == other.accessibilityChannel
+ && tileCountHorizontal == other.tileCountHorizontal
+ && tileCountVertical == other.tileCountVertical
&& cryptoType == other.cryptoType
&& Float.compare(frameRate, other.frameRate) == 0
&& Float.compare(pixelWidthHeightRatio, other.pixelWidthHeightRatio) == 0
@@ -1480,6 +1541,8 @@ public final class Format implements Bundleable {
private static final String FIELD_ENCODER_PADDING = Util.intToStringMaxRadix(27);
private static final String FIELD_ACCESSIBILITY_CHANNEL = Util.intToStringMaxRadix(28);
private static final String FIELD_CRYPTO_TYPE = Util.intToStringMaxRadix(29);
+ private static final String FIELD_TILE_COUNT_HORIZONTAL = Util.intToStringMaxRadix(30);
+ private static final String FIELD_TILE_COUNT_VERTICAL = Util.intToStringMaxRadix(31);
@Override
public Bundle toBundle() {
@@ -1535,6 +1598,9 @@ public final class Format implements Bundleable {
bundle.putInt(FIELD_ENCODER_PADDING, encoderPadding);
// Text specific.
bundle.putInt(FIELD_ACCESSIBILITY_CHANNEL, accessibilityChannel);
+ // Image specific.
+ bundle.putInt(FIELD_TILE_COUNT_HORIZONTAL, tileCountHorizontal);
+ bundle.putInt(FIELD_TILE_COUNT_VERTICAL, tileCountVertical);
// Source specific.
bundle.putInt(FIELD_CRYPTO_TYPE, cryptoType);
return bundle;
@@ -1599,6 +1665,10 @@ public final class Format implements Bundleable {
// Text specific.
.setAccessibilityChannel(
bundle.getInt(FIELD_ACCESSIBILITY_CHANNEL, DEFAULT.accessibilityChannel))
+ // Image specific.
+ .setTileCountHorizontal(
+ bundle.getInt(FIELD_TILE_COUNT_HORIZONTAL, DEFAULT.tileCountHorizontal))
+ .setTileCountVertical(bundle.getInt(FIELD_TILE_COUNT_VERTICAL, DEFAULT.tileCountVertical))
// Source specific.
.setCryptoType(bundle.getInt(FIELD_CRYPTO_TYPE, DEFAULT.cryptoType));
diff --git a/library/common/src/test/java/com/google/android/exoplayer2/FormatTest.java b/library/common/src/test/java/com/google/android/exoplayer2/FormatTest.java
index 9218658568..aff55a1b06 100644
--- a/library/common/src/test/java/com/google/android/exoplayer2/FormatTest.java
+++ b/library/common/src/test/java/com/google/android/exoplayer2/FormatTest.java
@@ -115,6 +115,8 @@ public final class FormatTest {
.setEncoderPadding(1002)
.setAccessibilityChannel(2)
.setCryptoType(C.CRYPTO_TYPE_CUSTOM_BASE)
+ .setTileCountHorizontal(20)
+ .setTileCountVertical(40)
.build();
}
diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java
index 853f76b4a4..e875f6c928 100644
--- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java
+++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java
@@ -1056,9 +1056,11 @@ public final class DashMediaSource extends BaseMediaSource {
for (int i = 0; i < period.adaptationSets.size(); i++) {
AdaptationSet adaptationSet = period.adaptationSets.get(i);
List representations = adaptationSet.representations;
- // Exclude text adaptation sets from duration calculations, if we have at least one audio
- // or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
- if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
+ // Exclude other adaptation sets from duration calculations, if we have at least one audio or
+ // video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029.
+ boolean adaptationSetIsNotAudioVideo =
+ adaptationSet.type != C.TRACK_TYPE_AUDIO && adaptationSet.type != C.TRACK_TYPE_VIDEO;
+ if ((haveAudioVideoAdaptationSets && adaptationSetIsNotAudioVideo)
|| representations.isEmpty()) {
continue;
}
@@ -1088,9 +1090,11 @@ public final class DashMediaSource extends BaseMediaSource {
for (int i = 0; i < period.adaptationSets.size(); i++) {
AdaptationSet adaptationSet = period.adaptationSets.get(i);
List representations = adaptationSet.representations;
- // Exclude text adaptation sets from duration calculations, if we have at least one audio
- // or video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
- if ((haveAudioVideoAdaptationSets && adaptationSet.type == C.TRACK_TYPE_TEXT)
+ // Exclude other adaptation sets from duration calculations, if we have at least one audio or
+ // video adaptation set. See: https://github.com/google/ExoPlayer/issues/4029
+ boolean adaptationSetIsNotAudioVideo =
+ adaptationSet.type != C.TRACK_TYPE_AUDIO && adaptationSet.type != C.TRACK_TYPE_VIDEO;
+ if ((haveAudioVideoAdaptationSets && adaptationSetIsNotAudioVideo)
|| representations.isEmpty()) {
continue;
}
diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java
index 997e0e2ff7..9235f8c830 100644
--- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java
+++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParser.java
@@ -555,7 +555,9 @@ public class DashManifestParser extends DefaultHandler
? C.TRACK_TYPE_VIDEO
: MimeTypes.BASE_TYPE_TEXT.equals(contentType)
? C.TRACK_TYPE_TEXT
- : C.TRACK_TYPE_UNKNOWN;
+ : MimeTypes.BASE_TYPE_IMAGE.equals(contentType)
+ ? C.TRACK_TYPE_IMAGE
+ : C.TRACK_TYPE_UNKNOWN;
}
/**
@@ -808,6 +810,7 @@ public class DashManifestParser extends DefaultHandler
roleFlags |= parseRoleFlagsFromAccessibilityDescriptors(accessibilityDescriptors);
roleFlags |= parseRoleFlagsFromProperties(essentialProperties);
roleFlags |= parseRoleFlagsFromProperties(supplementalProperties);
+ @Nullable Pair tileCounts = parseTileCountFromProperties(essentialProperties);
Format.Builder formatBuilder =
new Format.Builder()
@@ -818,7 +821,9 @@ public class DashManifestParser extends DefaultHandler
.setPeakBitrate(bitrate)
.setSelectionFlags(selectionFlags)
.setRoleFlags(roleFlags)
- .setLanguage(language);
+ .setLanguage(language)
+ .setTileCountHorizontal(tileCounts != null ? tileCounts.first : Format.NO_VALUE)
+ .setTileCountVertical(tileCounts != null ? tileCounts.second : Format.NO_VALUE);
if (MimeTypes.isVideo(sampleMimeType)) {
formatBuilder.setWidth(width).setHeight(height).setFrameRate(frameRate);
@@ -1627,6 +1632,41 @@ public class DashManifestParser extends DefaultHandler
return attributeValue.split(",");
}
+ // Thumbnail tile information parsing
+
+ /**
+ * Parses given descriptors for thumbnail tile information.
+ *
+ * @param essentialProperties List of descriptors that contain thumbnail tile information.
+ * @return A pair of Integer values, where the first is the count of horizontal tiles and the
+ * second is the count of vertical tiles, or null if no thumbnail tile information is found.
+ */
+ @Nullable
+ protected Pair parseTileCountFromProperties(
+ List essentialProperties) {
+ for (int i = 0; i < essentialProperties.size(); i++) {
+ Descriptor descriptor = essentialProperties.get(i);
+ if ((Ascii.equalsIgnoreCase("http://dashif.org/thumbnail_tile", descriptor.schemeIdUri)
+ || Ascii.equalsIgnoreCase(
+ "http://dashif.org/guidelines/thumbnail_tile", descriptor.schemeIdUri))
+ && descriptor.value != null) {
+ String size = descriptor.value;
+ String[] sizeSplit = Util.split(size, "x");
+ if (sizeSplit.length != 2) {
+ continue;
+ }
+ try {
+ int tileCountHorizontal = Integer.parseInt(sizeSplit[0]);
+ int tileCountVertical = Integer.parseInt(sizeSplit[1]);
+ return Pair.create(tileCountHorizontal, tileCountVertical);
+ } catch (NumberFormatException e) {
+ // Ignore property if it's malformed.
+ }
+ }
+ }
+ return null;
+ }
+
// Utility methods.
/**
diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java
index 854ae54d63..ac7ae3e4ad 100644
--- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java
+++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/manifest/DashManifestParserTest.java
@@ -252,11 +252,19 @@ public class DashManifestParserTest {
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_IMAGES));
AdaptationSet adaptationSet = manifest.getPeriod(0).adaptationSets.get(0);
- Format format = adaptationSet.representations.get(0).format;
+ Format format0 = adaptationSet.representations.get(0).format;
+ Format format1 = adaptationSet.representations.get(1).format;
- assertThat(format.sampleMimeType).isEqualTo("image/jpeg");
- assertThat(format.width).isEqualTo(320);
- assertThat(format.height).isEqualTo(180);
+ assertThat(format0.sampleMimeType).isEqualTo("image/jpeg");
+ assertThat(format0.width).isEqualTo(320);
+ assertThat(format0.height).isEqualTo(180);
+ assertThat(format0.tileCountHorizontal).isEqualTo(12);
+ assertThat(format0.tileCountVertical).isEqualTo(16);
+ assertThat(format1.sampleMimeType).isEqualTo("image/jpeg");
+ assertThat(format1.width).isEqualTo(640);
+ assertThat(format1.height).isEqualTo(360);
+ assertThat(format1.tileCountHorizontal).isEqualTo(2);
+ assertThat(format1.tileCountVertical).isEqualTo(4);
}
@Test
diff --git a/testdata/src/test/assets/media/mpd/sample_mpd_images b/testdata/src/test/assets/media/mpd/sample_mpd_images
index 981a29a23a..7d0779e957 100644
--- a/testdata/src/test/assets/media/mpd/sample_mpd_images
+++ b/testdata/src/test/assets/media/mpd/sample_mpd_images
@@ -4,7 +4,10 @@
-
+
+
+
+