Skip to content

Commit

Permalink
DASH: Set MIME, width and height for image adaptation sets
Browse files Browse the repository at this point in the history
Issue: #9500
PiperOrigin-RevId: 401091261
  • Loading branch information
ojw28 committed Oct 6, 2021
1 parent 03ff5b6 commit 585b0bd
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
* RTSP:
* Support RFC4566 SDP attribute field grammar
([#9430](https://github.com/google/ExoPlayer/issues/9430)).
* DASH:
* Populate `Format.sampleMimeType`, `width` and `height` for image
`AdaptationSet` elements
([#9500](https://github.com/google/ExoPlayer/issues/9500)).
* Remove deprecated symbols:
* Remove `Renderer.VIDEO_SCALING_MODE_*` constants. Use identically named
constants in `C` instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public static boolean isText(@Nullable String mimeType) {
|| APPLICATION_DVBSUBS.equals(mimeType);
}

/** Returns whether the given string is an image MIME type. */
public static boolean isImage(@Nullable String mimeType) {
return BASE_TYPE_IMAGE.equals(getTopLevelType(mimeType));
}

/**
* Returns true if it is known that all samples in a stream of the given MIME type and codec are
* guaranteed to be sync samples (i.e., {@link C#BUFFER_FLAG_KEY_FRAME} is guaranteed to be set on
Expand Down Expand Up @@ -505,6 +510,8 @@ public static String getMimeTypeFromMp4ObjectType(int objectType) {
return C.TRACK_TYPE_VIDEO;
} else if (isText(mimeType)) {
return C.TRACK_TYPE_TEXT;
} else if (isImage(mimeType)) {
return C.TRACK_TYPE_IMAGE;
} else if (APPLICATION_ID3.equals(mimeType)
|| APPLICATION_EMSG.equals(mimeType)
|| APPLICATION_SCTE35.equals(mimeType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -114,6 +115,36 @@ public void isText_returnsCorrectResult() {
assertThat(MimeTypes.isText("application/custom")).isFalse();
}

@Test
public void isImage_returnsCorrectResult() {
assertThat(MimeTypes.isImage(MimeTypes.IMAGE_JPEG)).isTrue();
assertThat(MimeTypes.isImage("image/custom")).isTrue();

assertThat(MimeTypes.isImage(MimeTypes.VIDEO_MP4)).isFalse();
assertThat(MimeTypes.isImage("application/custom")).isFalse();
}

@Test
public void getTrackType_returnsCorrectResult() {
assertThat(MimeTypes.getTrackType(MimeTypes.VIDEO_H264)).isEqualTo(C.TRACK_TYPE_VIDEO);
assertThat(MimeTypes.getTrackType("video/custom")).isEqualTo(C.TRACK_TYPE_VIDEO);

assertThat(MimeTypes.getTrackType(MimeTypes.AUDIO_AAC)).isEqualTo(C.TRACK_TYPE_AUDIO);
assertThat(MimeTypes.getTrackType("audio/custom")).isEqualTo(C.TRACK_TYPE_AUDIO);

assertThat(MimeTypes.getTrackType(MimeTypes.TEXT_SSA)).isEqualTo(C.TRACK_TYPE_TEXT);
assertThat(MimeTypes.getTrackType("text/custom")).isEqualTo(C.TRACK_TYPE_TEXT);

assertThat(MimeTypes.getTrackType(MimeTypes.IMAGE_JPEG)).isEqualTo(C.TRACK_TYPE_IMAGE);
assertThat(MimeTypes.getTrackType("image/custom")).isEqualTo(C.TRACK_TYPE_IMAGE);

assertThat(MimeTypes.getTrackType(MimeTypes.APPLICATION_CEA608)).isEqualTo(C.TRACK_TYPE_TEXT);
assertThat(MimeTypes.getTrackType(MimeTypes.APPLICATION_EMSG)).isEqualTo(C.TRACK_TYPE_METADATA);
assertThat(MimeTypes.getTrackType(MimeTypes.APPLICATION_CAMERA_MOTION))
.isEqualTo(C.TRACK_TYPE_CAMERA_MOTION);
assertThat(MimeTypes.getTrackType("application/custom")).isEqualTo(C.TRACK_TYPE_UNKNOWN);
}

@Test
public void getMediaMimeType_fromValidCodecs_returnsCorrectMimeType() {
assertThat(MimeTypes.getMediaMimeType("avc1")).isEqualTo(MimeTypes.VIDEO_H264);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ protected Format buildFormat(
accessibilityChannel = parseCea708AccessibilityChannel(accessibilityDescriptors);
}
formatBuilder.setAccessibilityChannel(accessibilityChannel);
} else if (MimeTypes.isImage(sampleMimeType)) {
formatBuilder.setWidth(width).setHeight(height);
}

return formatBuilder.build();
Expand Down Expand Up @@ -1635,6 +1637,9 @@ private static String getSampleMimeType(
}
// All other text types are raw formats.
return containerMimeType;
} else if (MimeTypes.isImage(containerMimeType)) {
// Image types are raw formats.
return containerMimeType;
} else if (MimeTypes.APPLICATION_MP4.equals(containerMimeType)) {
@Nullable String mimeType = MimeTypes.getMediaMimeType(codecs);
return MimeTypes.TEXT_VTT.equals(mimeType) ? MimeTypes.APPLICATION_MP4VTT : mimeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class DashManifestParserTest {
"media/mpd/sample_mpd_unknown_mime_type";
private static final String SAMPLE_MPD_SEGMENT_TEMPLATE = "media/mpd/sample_mpd_segment_template";
private static final String SAMPLE_MPD_EVENT_STREAM = "media/mpd/sample_mpd_event_stream";
private static final String SAMPLE_MPD_IMAGES = "media/mpd/sample_mpd_images";
private static final String SAMPLE_MPD_LABELS = "media/mpd/sample_mpd_labels";
private static final String SAMPLE_MPD_ASSET_IDENTIFIER = "media/mpd/sample_mpd_asset_identifier";
private static final String SAMPLE_MPD_TEXT = "media/mpd/sample_mpd_text";
Expand Down Expand Up @@ -192,6 +193,23 @@ public void parseMediaPresentationDescription_programInformation() throws IOExce
assertThat(manifest.programInformation).isEqualTo(expectedProgramInformation);
}

@Test
public void parseMediaPresentationDescription_images() throws IOException {
DashManifestParser parser = new DashManifestParser();
DashManifest manifest =
parser.parse(
Uri.parse("https://example.com/test.mpd"),
TestUtil.getInputStream(
ApplicationProvider.getApplicationContext(), SAMPLE_MPD_IMAGES));

AdaptationSet adaptationSet = manifest.getPeriod(0).adaptationSets.get(0);
Format format = adaptationSet.representations.get(0).format;

assertThat(format.sampleMimeType).isEqualTo("image/jpeg");
assertThat(format.width).isEqualTo(320);
assertThat(format.height).isEqualTo(180);
}

@Test
public void parseMediaPresentationDescription_labels() throws IOException {
DashManifestParser parser = new DashManifestParser();
Expand Down
11 changes: 11 additions & 0 deletions testdata/src/test/assets/media/mpd/sample_mpd_images
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD type="static" duration="1s" mediaPresentationDuration="PT1000S">
<Period>
<AdaptationSet id="3" mimeType="image/jpeg" contentType="image">
<SegmentTemplate media="$RepresentationID$/tile_$Number$.jpg" duration="100" startNumber="1"/>
<Representation bandwidth="1234" id="images_320x180" width="320" height="180">
<EssentialProperty schemeIdUri="http://dashif.org/thumbnail_tile" value="title"/>
</Representation>
</AdaptationSet>
</Period>
</MPD>

0 comments on commit 585b0bd

Please sign in to comment.