• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 
17 package android.videocodec.cts;
18 
19 import android.media.MediaFormat;
20 import android.mediav2.common.cts.EncoderConfigParams;
21 import android.mediav2.common.cts.RawResource;
22 
23 import androidx.annotation.NonNull;
24 
25 import java.util.HashMap;
26 import java.util.Map;
27 
28 /**
29  * Class containing encoder input resources.
30  */
31 public class VideoEncoderInput {
32     private static final String MEDIA_DIR = WorkDir.getMediaDirString();
33     public static final HashMap<String, RawResource> RES_YUV_MAP = new HashMap<>();
34 
35     public static class CompressedResource {
36         final String mMediaType;
37         final String mResFile;
38 
CompressedResource(String mediaType, String resFile)39         CompressedResource(String mediaType, String resFile) {
40             mMediaType = mediaType;
41             mResFile = resFile;
42         }
43 
44         @NonNull
45         @Override
toString()46         public String toString() {
47             return "CompressedResource{" + "res file ='" + mResFile + '\'' + '}';
48         }
49 
uniqueLabel()50         public String uniqueLabel() {
51             return mMediaType + mResFile;
52         }
53     }
54 
55     public static final CompressedResource BIRTHDAY_FULLHD_LANDSCAPE =
56             new CompressedResource(MediaFormat.MIMETYPE_VIDEO_AVC, MEDIA_DIR
57                     + "AVICON-MOBILE-BirthdayHalfway-SI17-CRUW03-L-420-8bit-SDR-1080p-30fps.mp4");
58     public static final CompressedResource SELFIEGROUP_FULLHD_PORTRAIT =
59             new CompressedResource(MediaFormat.MIMETYPE_VIDEO_AVC, MEDIA_DIR
60                     + "AVICON-MOBILE-SelfieGroupGarden-SF15-CF01-P-420-8bit-SDR-1080p-30fps.mp4");
61     public static final CompressedResource RIVER_HD_LANDSCAPE =
62             new CompressedResource(MediaFormat.MIMETYPE_VIDEO_AVC, MEDIA_DIR
63                     + "AVICON-MOBILE-River-SO03-CRW01-L-420-8bit-SDR-720p-30fps.mp4");
64 
manhattanDistance(int w1, int h1, int w2, int h2)65     private static int manhattanDistance(int w1, int h1, int w2, int h2) {
66         return Math.abs(w1 - w2) + Math.abs(h1 - h2);
67     }
68 
getRawResource(EncoderConfigParams cfg)69     public static RawResource getRawResource(EncoderConfigParams cfg) {
70         String key = null;
71         int closestDistance = Integer.MAX_VALUE;
72         for (Map.Entry<String, RawResource> element : RES_YUV_MAP.entrySet()) {
73             if (element.getValue() == null) continue;
74             int distance = manhattanDistance(cfg.mWidth, cfg.mHeight, element.getValue().mWidth,
75                     element.getValue().mHeight);
76             if (distance < closestDistance) {
77                 closestDistance = distance;
78                 key = element.getKey();
79             }
80         }
81         return RES_YUV_MAP.get(key);
82     }
83 
getRawResource(CompressedResource cRes)84     public static RawResource getRawResource(CompressedResource cRes) {
85         return RES_YUV_MAP.get(cRes.uniqueLabel());
86     }
87 }
88