summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaveen Kumar Ponnusamy <naveenkumar.p@ittiam.com>2021-08-30 10:19:04 -0700
committerKevin Rocard <krocard@google.com>2022-04-12 12:53:58 +0000
commit4da997f295e39f0e33b038f44a30c2c7653212ec (patch)
treead5e8ee8bc1ca5f002f9553b8fd05916bfe725a6
parent8ae58329ed4150e1ee20784c98ff683f15630fdb (diff)
downloadcts-4da997f295e39f0e33b038f44a30c2c7653212ec.tar.gz
transcoding: Add tests for VideoFormatResolver
Added the following tests for VideoFormatResolver - Create a HEVC source video format and verify a target format is returned. - Width set to 0 in the source format. - Missing height in the source format. - Frame rate set to 0 in the source format. - AV1 mime type set in the source format. Bug: 198164635 Test: cts-tradefed run singleCommand cts -m CtsMediaTranscodingTestCases Change-Id: If1bc01094306d216f615f1de5422916ecd5ccfca Merged-In: If1bc01094306d216f615f1de5422916ecd5ccfca
-rw-r--r--tests/tests/mediatranscoding/src/android/media/mediatranscoding/cts/MediaTranscodingManagerTest.java185
1 files changed, 171 insertions, 14 deletions
diff --git a/tests/tests/mediatranscoding/src/android/media/mediatranscoding/cts/MediaTranscodingManagerTest.java b/tests/tests/mediatranscoding/src/android/media/mediatranscoding/cts/MediaTranscodingManagerTest.java
index a88f81c9004..fd99ed06f27 100644
--- a/tests/tests/mediatranscoding/src/android/media/mediatranscoding/cts/MediaTranscodingManagerTest.java
+++ b/tests/tests/mediatranscoding/src/android/media/mediatranscoding/cts/MediaTranscodingManagerTest.java
@@ -94,6 +94,8 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
private static final int BIT_RATE = 4000000; // 4Mbps
private static final int WIDTH = 720;
private static final int HEIGHT = 480;
+ private static final int FRAME_RATE = 30;
+ private static final int INT_NOT_SET = Integer.MIN_VALUE;
// Threshold for the psnr to make sure the transcoded video is valid.
private static final int PSNR_THRESHOLD = 20;
@@ -131,9 +133,33 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
/**
* Creates a MediaFormat with the default settings.
*/
- private static MediaFormat createMediaFormat() {
- MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, WIDTH, HEIGHT);
- format.setInteger(MediaFormat.KEY_BIT_RATE, BIT_RATE);
+ private static MediaFormat createDefaultMediaFormat() {
+ return createMediaFormat(MIME_TYPE, WIDTH, HEIGHT, INT_NOT_SET /* frameRate */,
+ BIT_RATE /* bitrate */);
+ }
+
+ /**
+ * Creates a MediaFormat with custom settings.
+ */
+ private static MediaFormat createMediaFormat(String mime, int width, int height, int frameRate,
+ int bitrate) {
+ MediaFormat format = new MediaFormat();
+ // Set mime if it not null.
+ if (mime != null) {
+ format.setString(MediaFormat.KEY_MIME, mime);
+ }
+ if (width != INT_NOT_SET) {
+ format.setInteger(MediaFormat.KEY_WIDTH, width);
+ }
+ if (height != INT_NOT_SET) {
+ format.setInteger(MediaFormat.KEY_HEIGHT, height);
+ }
+ if (frameRate != INT_NOT_SET) {
+ format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate);
+ }
+ if (bitrate != INT_NOT_SET) {
+ format.setInteger(MediaFormat.KEY_BIT_RATE, bitrate);
+ }
return format;
}
@@ -189,7 +215,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, null,
- createMediaFormat())
+ createDefaultMediaFormat())
.build();
});
}
@@ -204,7 +230,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, mDestinationUri,
- createMediaFormat())
+ createDefaultMediaFormat())
.setClientPid(-1)
.build();
});
@@ -220,7 +246,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, mDestinationUri,
- createMediaFormat())
+ createDefaultMediaFormat())
.setClientUid(-1)
.build();
});
@@ -235,7 +261,8 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
}
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
- new VideoTranscodingRequest.Builder(null, mDestinationUri, createMediaFormat())
+ new VideoTranscodingRequest.Builder(null, mDestinationUri,
+ createDefaultMediaFormat())
.build();
});
}
@@ -249,7 +276,8 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
}
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
- new VideoTranscodingRequest.Builder(null, mDestinationUri, createMediaFormat())
+ new VideoTranscodingRequest.Builder(null, mDestinationUri,
+ createDefaultMediaFormat())
.build();
});
}
@@ -264,7 +292,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
assertThrows(IllegalArgumentException.class, () -> {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, null,
- createMediaFormat())
+ createDefaultMediaFormat())
.build();
});
}
@@ -292,7 +320,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
Semaphore transcodeCompleteSemaphore = new Semaphore(0);
VideoTranscodingRequest request =
- new VideoTranscodingRequest.Builder(srcUri, dstUri, createMediaFormat())
+ new VideoTranscodingRequest.Builder(srcUri, dstUri, createDefaultMediaFormat())
.build();
Executor listenerExecutor = Executors.newSingleThreadExecutor();
@@ -562,6 +590,135 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
stats.mAveragePSNR >= PSNR_THRESHOLD);
}
+ private void testVideoFormatResolverShouldTranscode(String mime, int width, int height,
+ int frameRate) {
+ ApplicationMediaCapabilities clientCaps =
+ new ApplicationMediaCapabilities.Builder().build();
+
+ MediaFormat mediaFormat = createMediaFormat(mime, width, height, frameRate, BIT_RATE);
+
+ TranscodingRequest.VideoFormatResolver
+ resolver = new TranscodingRequest.VideoFormatResolver(clientCaps,
+ mediaFormat);
+ assertTrue(resolver.shouldTranscode());
+ MediaFormat videoTrackFormat = resolver.resolveVideoFormat();
+ assertNotNull(videoTrackFormat);
+ }
+
+ public void testVideoFormatResolverValidArgs() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverShouldTranscode(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH, HEIGHT,
+ FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverAv1Mime() {
+ if (shouldSkip()) {
+ return;
+ }
+ ApplicationMediaCapabilities clientCaps =
+ new ApplicationMediaCapabilities.Builder().build();
+
+ MediaFormat mediaFormat = createMediaFormat(MediaFormat.MIMETYPE_VIDEO_AV1, WIDTH, HEIGHT,
+ FRAME_RATE, BIT_RATE);
+
+ TranscodingRequest.VideoFormatResolver
+ resolver = new TranscodingRequest.VideoFormatResolver(clientCaps,
+ mediaFormat);
+ assertFalse(resolver.shouldTranscode());
+ MediaFormat videoTrackFormat = resolver.resolveVideoFormat();
+ assertNull(videoTrackFormat);
+ }
+
+ private void testVideoFormatResolverInvalidArgs(String mime, int width, int height,
+ int frameRate) {
+ ApplicationMediaCapabilities clientCaps =
+ new ApplicationMediaCapabilities.Builder().build();
+
+ MediaFormat mediaFormat = createMediaFormat(mime, width, height, frameRate, BIT_RATE);
+
+ TranscodingRequest.VideoFormatResolver
+ resolver = new TranscodingRequest.VideoFormatResolver(clientCaps,
+ mediaFormat);
+
+ assertThrows(IllegalArgumentException.class, () -> {
+ MediaFormat videoTrackFormat = resolver.resolveVideoFormat();
+ });
+ }
+
+ public void testVideoFormatResolverZeroWidth() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, 0 /* width */,
+ HEIGHT, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverZeroHeight() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH,
+ 0 /* height */, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverZeroFrameRate() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH,
+ HEIGHT, 0 /* frameRate */);
+ }
+
+ public void testVideoFormatResolverNegativeWidth() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, -WIDTH,
+ HEIGHT, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverNegativeHeight() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH,
+ -HEIGHT, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverNegativeFrameRate() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH,
+ HEIGHT, -FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverMissingWidth() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, INT_NOT_SET /* width*/,
+ HEIGHT /* height */, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverMissingHeight() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverInvalidArgs(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH,
+ INT_NOT_SET /* height */, FRAME_RATE);
+ }
+
+ public void testVideoFormatResolverMissingFrameRate() {
+ if (shouldSkip()) {
+ return;
+ }
+ testVideoFormatResolverShouldTranscode(MediaFormat.MIMETYPE_VIDEO_HEVC, WIDTH, HEIGHT,
+ INT_NOT_SET /* frameRate */);
+ }
+
private boolean compareFormat(MediaFormat fmt1, MediaFormat fmt2) {
if (fmt1 == fmt2) return true;
if (fmt1 == null || fmt2 == null) return false;
@@ -586,7 +743,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, destinationUri,
- createMediaFormat())
+ createDefaultMediaFormat())
.build();
Executor listenerExecutor = Executors.newSingleThreadExecutor();
@@ -650,7 +807,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
.setClientPid(pid)
.setClientUid(uid)
.setPriority(MediaTranscodingManager.PRIORITY_REALTIME)
- .setVideoTrackFormat(createMediaFormat())
+ .setVideoTrackFormat(createDefaultMediaFormat())
.build();
Executor listenerExecutor = Executors.newSingleThreadExecutor();
@@ -678,7 +835,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, destinationUri,
- createMediaFormat())
+ createDefaultMediaFormat())
.build();
Executor listenerExecutor = Executors.newSingleThreadExecutor();
@@ -730,7 +887,7 @@ public class MediaTranscodingManagerTest extends AndroidTestCase {
VideoTranscodingRequest request =
new VideoTranscodingRequest.Builder(mSourceHEVCVideoUri, destinationUri,
- createMediaFormat())
+ createDefaultMediaFormat())
.build();
Executor listenerExecutor = Executors.newSingleThreadExecutor();