1 /* 2 * Copyright (C) 2022 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.mediav2.cts; 18 19 import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Flexible; 20 import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUVP010; 21 22 import android.graphics.ImageFormat; 23 import android.media.AudioFormat; 24 import android.mediav2.common.cts.EncoderConfigParams; 25 import android.mediav2.common.cts.RawResource; 26 27 /** 28 * Class containing encoder input resources. 29 */ 30 public class EncoderInput { 31 private static final String MEDIA_DIR = WorkDir.getMediaDirString(); 32 33 // files are in WorkDir.getMediaDirString(); 34 private static final RawResource INPUT_VIDEO_FILE = 35 new RawResource.Builder() 36 .setFileName(MEDIA_DIR + "bbb_cif_yuv420p_30fps.yuv", false) 37 .setDimension(352, 288) 38 .setBytesPerSample(1) 39 .setColorFormat(ImageFormat.YUV_420_888) 40 .build(); 41 private static final RawResource INPUT_VIDEO_FILE_HBD = 42 new RawResource.Builder() 43 .setFileName(MEDIA_DIR + "cosmat_cif_24fps_yuv420p16le.yuv", false) 44 .setDimension(352, 288) 45 .setBytesPerSample(2) 46 .setColorFormat(ImageFormat.YCBCR_P010) 47 .build(); 48 49 /* Note: The mSampleRate and mChannelCount fields of RawResource are not used by the tests 50 the way mWidth and mHeight are used. mWidth and mHeight is used by fillImage() to select a 51 portion of the frame or duplicate the frame as tiles depending on testWidth and testHeight. 52 Ideally mSampleRate and mChannelCount information should be used to resample and perform 53 channel-conversion basing on testSampleRate and testChannelCount. Instead the test considers 54 the resource file to be of testSampleRate and testChannelCount. */ 55 private static final RawResource INPUT_AUDIO_FILE = 56 new RawResource.Builder() 57 .setFileName(MEDIA_DIR + "bbb_2ch_44kHz_s16le.raw", true) 58 .setSampleRate(44100) 59 .setChannelCount(2) 60 .setBytesPerSample(2) 61 .setAudioEncoding(AudioFormat.ENCODING_PCM_16BIT) 62 .build(); 63 private static final RawResource INPUT_AUDIO_FILE_HBD = 64 new RawResource.Builder() 65 .setFileName(MEDIA_DIR + "audio/sd_2ch_48kHz_f32le.raw", true) 66 .setSampleRate(48000) 67 .setChannelCount(2) 68 .setBytesPerSample(4) 69 .setAudioEncoding(AudioFormat.ENCODING_PCM_FLOAT) 70 .build(); 71 getRawResource(EncoderConfigParams cfg)72 public static RawResource getRawResource(EncoderConfigParams cfg) { 73 if (cfg.mIsAudio) { 74 if (cfg.mPcmEncoding == AudioFormat.ENCODING_PCM_FLOAT) { 75 return INPUT_AUDIO_FILE_HBD; 76 } else if (cfg.mPcmEncoding == AudioFormat.ENCODING_PCM_16BIT) { 77 return INPUT_AUDIO_FILE; 78 } 79 } else { 80 if (cfg.mColorFormat == COLOR_FormatYUV420Flexible) { 81 return INPUT_VIDEO_FILE; 82 } else if (cfg.mColorFormat == COLOR_FormatYUVP010) { 83 return INPUT_VIDEO_FILE_HBD; 84 } 85 } 86 return null; 87 } 88 } 89