bitstreams: add profile/level for 10-bit streams if missing

Bug: 134493976
Test: cts-tradefed run commandAndExit cts --abi armeabi-v7a -m CtsMediaBitstreamsTestCases -t android.media.cts.bitstreams.Vp9Yuv420BitstreamsTest
Change-Id: I787e9bfbdfa5c7318cf42adfe90718e21196f088
diff --git a/hostsidetests/media/bitstreams/app/src/android/media/cts/bitstreams/app/MediaBitstreamsDeviceSideTest.java b/hostsidetests/media/bitstreams/app/src/android/media/cts/bitstreams/app/MediaBitstreamsDeviceSideTest.java
index 625839f..ae8d4a8 100644
--- a/hostsidetests/media/bitstreams/app/src/android/media/cts/bitstreams/app/MediaBitstreamsDeviceSideTest.java
+++ b/hostsidetests/media/bitstreams/app/src/android/media/cts/bitstreams/app/MediaBitstreamsDeviceSideTest.java
@@ -21,6 +21,7 @@
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.media.MediaCodec;
+import android.media.MediaCodecInfo.CodecProfileLevel;
 import android.media.MediaExtractor;
 import android.media.MediaFormat;
 import android.media.cts.bitstreams.MediaBitstreams;
@@ -83,6 +84,35 @@
         }
     }
 
+    private static void fixFormat(MediaFormat format, String path) {
+        // TODO(b/137684344): Revisit so that we can get this information from
+        //                    the bitstream or the extractor.
+        if (path.indexOf("/10bit/") < 0) {
+            return;
+        }
+        String mime = format.getString(MediaFormat.KEY_MIME);
+        int profile = -1, level = -1;
+        if (mime.equals(MediaFormat.MIMETYPE_VIDEO_VP9)) {
+            profile = CodecProfileLevel.VP9Profile2;
+            level = CodecProfileLevel.VP9Level1;
+        } else if (mime.equals(MediaFormat.MIMETYPE_VIDEO_HEVC)) {
+            profile = CodecProfileLevel.HEVCProfileMain10;
+            level = CodecProfileLevel.HEVCMainTierLevel1;
+        } else if (mime.equals(MediaFormat.MIMETYPE_VIDEO_AV1)) {
+            profile = CodecProfileLevel.AV1ProfileMain10;
+            level = CodecProfileLevel.AV1Level2;
+        } else {
+            return;
+        }
+
+        if (!format.containsKey(MediaFormat.KEY_PROFILE)) {
+            format.setInteger(MediaFormat.KEY_PROFILE, profile);
+        }
+        if (!format.containsKey(MediaFormat.KEY_LEVEL)) {
+            format.setInteger(MediaFormat.KEY_LEVEL, level);
+        }
+    }
+
     static interface ReportCallback {
         void run(OutputStream out) throws Exception;
     }
@@ -166,6 +196,7 @@
                 MediaFormat format = parseTrackFormat(formatStr);
                 String mime = format.getString(MediaFormat.KEY_MIME);
                 String[] decoders = MediaUtils.getDecoderNamesForMime(mime);
+                fixFormat(format, path);
 
                 ps.println(path);
                 ps.println(decoders.length);
@@ -225,6 +256,7 @@
             try {
                 ex.setDataSource(path);
                 MediaFormat format = ex.getTrackFormat(0);
+                fixFormat(format, path);
                 boolean[] vendors = new boolean[] {false, true};
                 for (boolean v : vendors) {
                     for (String name : MediaUtils.getDecoderNames(v, format)) {