diff options
author | James Dong <jdong@google.com> | 2010-02-16 14:38:23 -0800 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-02-22 11:32:02 -0800 |
commit | 1b7babd2cce5bb10adac7b061cf7ba065d480edb (patch) | |
tree | 5d2b0456f6f91882859fbb3819c0c98d25abb114 /media/tests | |
parent | 9a56aaf12b462a064e81e02386eca8a1e77fe737 (diff) | |
download | frameworks_base-1b7babd2cce5bb10adac7b061cf7ba065d480edb.zip frameworks_base-1b7babd2cce5bb10adac7b061cf7ba065d480edb.tar.gz frameworks_base-1b7babd2cce5bb10adac7b061cf7ba065d480edb.tar.bz2 |
Use Java API from xml configuration in the test application
Diffstat (limited to 'media/tests')
3 files changed, 101 insertions, 126 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java index 717f7ba..d7cf069 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java @@ -1,28 +1,35 @@ package com.android.mediaframeworktest; import android.media.MediaRecorder; +import android.media.EncoderCapabilities; +import android.media.EncoderCapabilities.VideoEncoderCap; +import android.media.EncoderCapabilities.AudioEncoderCap; +import android.media.DecoderCapabilities; +import android.media.DecoderCapabilities.VideoDecoder; +import android.media.DecoderCapabilities.AudioDecoder; + import android.os.SystemProperties; +import java.util.List; import java.util.HashMap; -public class MediaProfileReader { +public class MediaProfileReader +{ + private static final List<VideoDecoder> videoDecoders = DecoderCapabilities.getVideoDecoders(); + private static final List<AudioDecoder> audioDecoders = DecoderCapabilities.getAudioDecoders(); + private static final List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders(); + private static final List<AudioEncoderCap> audioEncoders = EncoderCapabilities.getAudioEncoders(); + private static final HashMap<Integer, String> encoderMap = new HashMap<Integer, String>(); - public static final HashMap<String, Integer> - OUTPUT_FORMAT_TABLE = new HashMap<String, Integer>(); - public static String MEDIA_ENC_VID = "ro.media.enc.vid."; - public static String MEDIA_AUD_VID = "ro.media.enc.aud."; - public static String[] VIDEO_ENCODER_PROPERTY = {".width", ".height", ".bps", ".fps",}; - public static String[] AUDIO_ENCODER_PROPERTY = {".bps", ".hz", ".ch",}; + static { + initEncoderMap(); + }; - public static String getVideoCodecProperty() { - String s; - s = SystemProperties.get("ro.media.enc.vid.codec"); - return s; + public static List<VideoEncoderCap> getVideoEncoders() { + return videoEncoders; } - public static String getAudioCodecProperty() { - String s; - s = SystemProperties.get("ro.media.enc.aud.codec"); - return s; + public static List<AudioEncoderCap> getAudioEncoders() { + return audioEncoders; } public static String getDeviceType() { @@ -33,78 +40,56 @@ public class MediaProfileReader { } public static boolean getWMAEnable() { - // push all the property into one big table - int wmaEnable = 1; - wmaEnable = SystemProperties.getInt("ro.media.dec.aud.wma.enabled", - wmaEnable); - if (wmaEnable == 1) { - return true; - } else { - return false; + for (AudioDecoder decoder: audioDecoders) { + if (decoder == AudioDecoder.AUDIO_DECODER_WMA) { + return true; + } } + return false; } public static boolean getWMVEnable(){ - int wmvEnable = 1; - wmvEnable = SystemProperties.getInt("ro.media.dec.vid.wmv.enabled", - wmvEnable); - if (wmvEnable == 1) { - return true; - } else { - return false; + for (VideoDecoder decoder: videoDecoders) { + if (decoder == VideoDecoder.VIDEO_DECODER_WMV) { + return true; + } } + return false; } - public static void createVideoProfileTable() { - // push all the property into one big table - String encoderType = getVideoCodecProperty(); - if (encoderType.length() != 0) { - String encoder[] = encoderType.split(","); - for (int i = 0; i < encoder.length; i++) { - for (int j = 0; j < VIDEO_ENCODER_PROPERTY.length; j++) { - String propertyName = MEDIA_ENC_VID + encoder[i] + VIDEO_ENCODER_PROPERTY[j]; - String prop = SystemProperties.get(propertyName); - // push to the table - String propRange[] = prop.split(","); - OUTPUT_FORMAT_TABLE.put((encoder[i] + VIDEO_ENCODER_PROPERTY[j] + "_low"), - Integer.parseInt(propRange[0])); - OUTPUT_FORMAT_TABLE.put((encoder[i] + VIDEO_ENCODER_PROPERTY[j] + "_high"), - Integer.parseInt(propRange[1])); - } - - } + public static String getVideoCodecName(int videoEncoder) { + if (videoEncoder != MediaRecorder.VideoEncoder.H263 && + videoEncoder != MediaRecorder.VideoEncoder.H264 && + videoEncoder != MediaRecorder.VideoEncoder.MPEG_4_SP) { + throw new IllegalArgumentException("Unsupported video encoder " + videoEncoder); } + return encoderMap.get(videoEncoder); } - public static void createAudioProfileTable() { - // push all the property into one big table - String audioType = getAudioCodecProperty(); - String encoder[] = audioType.split(","); - if (audioType.length() != 0) { - for (int i = 0; i < encoder.length; i++) { - for (int j = 0; j < AUDIO_ENCODER_PROPERTY.length; j++) { - String propertyName = MEDIA_AUD_VID + encoder[i] + AUDIO_ENCODER_PROPERTY[j]; - String prop = SystemProperties.get(propertyName); - // push to the table - String propRange[] = prop.split(","); - OUTPUT_FORMAT_TABLE.put((encoder[i] + AUDIO_ENCODER_PROPERTY[j] + "_low"), - Integer.parseInt(propRange[0])); - OUTPUT_FORMAT_TABLE.put((encoder[i] + AUDIO_ENCODER_PROPERTY[j] + "_high"), - Integer.parseInt(propRange[1])); - } - } + public static String getAudioCodecName(int audioEncoder) { + if (audioEncoder != MediaRecorder.AudioEncoder.AMR_NB && + audioEncoder != MediaRecorder.AudioEncoder.AMR_WB && + audioEncoder != MediaRecorder.AudioEncoder.AAC && + audioEncoder != MediaRecorder.AudioEncoder.AAC_PLUS && + audioEncoder != MediaRecorder.AudioEncoder.EAAC_PLUS) { + throw new IllegalArgumentException("Unsupported audio encodeer " + audioEncoder); } + return encoderMap.get(audioEncoder); } - public static void createEncoderTable(){ - OUTPUT_FORMAT_TABLE.put("h263", MediaRecorder.VideoEncoder.H263); - OUTPUT_FORMAT_TABLE.put("h264", MediaRecorder.VideoEncoder.H264); - OUTPUT_FORMAT_TABLE.put("m4v", MediaRecorder.VideoEncoder.MPEG_4_SP); - OUTPUT_FORMAT_TABLE.put("amrnb", MediaRecorder.AudioEncoder.AMR_NB); - OUTPUT_FORMAT_TABLE.put("amrwb", MediaRecorder.AudioEncoder.AMR_WB); - OUTPUT_FORMAT_TABLE.put("aac", MediaRecorder.AudioEncoder.AAC); - OUTPUT_FORMAT_TABLE.put("aacplus", MediaRecorder.AudioEncoder.AAC_PLUS); - OUTPUT_FORMAT_TABLE.put("eaacplus", - MediaRecorder.AudioEncoder.EAAC_PLUS); + private MediaProfileReader() {} // Don't call me + + private static void initEncoderMap() { + // video encoders + encoderMap.put(MediaRecorder.VideoEncoder.H263, "h263"); + encoderMap.put(MediaRecorder.VideoEncoder.H264, "h264"); + encoderMap.put(MediaRecorder.VideoEncoder.MPEG_4_SP, "m4v"); + + // audio encoders + encoderMap.put(MediaRecorder.AudioEncoder.AMR_NB, "amrnb"); + encoderMap.put(MediaRecorder.AudioEncoder.AMR_WB, "amrwb"); + encoderMap.put(MediaRecorder.AudioEncoder.AAC, "aac"); + encoderMap.put(MediaRecorder.AudioEncoder.AAC_PLUS, "aacplus"); + encoderMap.put(MediaRecorder.AudioEncoder.EAAC_PLUS, "eaacplus"); } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java index fdc5970..39caccd 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java @@ -25,6 +25,9 @@ import android.content.Context; import android.hardware.Camera; import android.media.MediaPlayer; import android.media.MediaRecorder; +import android.media.EncoderCapabilities; +import android.media.EncoderCapabilities.VideoEncoderCap; +import android.media.EncoderCapabilities.AudioEncoderCap; import android.test.ActivityInstrumentationTestCase; import android.util.Log; import android.view.SurfaceHolder; @@ -33,6 +36,7 @@ import com.android.mediaframeworktest.MediaProfileReader; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; +import java.util.List; /** @@ -99,31 +103,29 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram } } - private boolean recordVideoWithPara(String encoder, String audio, String quality){ + private boolean recordVideoWithPara(VideoEncoderCap videoCap, AudioEncoderCap audioCap, boolean highQuality){ boolean recordSuccess = false; - int videoEncoder = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(encoder); - int audioEncoder = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(audio); - int videoWidth = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(encoder + ".width_" + quality); - int videoHeight = - MediaProfileReader.OUTPUT_FORMAT_TABLE.get(encoder + ".height_" + quality); - int videoFps = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(encoder + ".fps_" + quality); - int videoBitrate = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(encoder + ".bps_" + quality); - int audioBitrate = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(audio + ".bps_" + quality); - int audioChannels = MediaProfileReader.OUTPUT_FORMAT_TABLE.get(audio + ".ch_" + quality); - int audioSamplingRate = - MediaProfileReader.OUTPUT_FORMAT_TABLE.get(audio + ".hz_" + quality); + int videoEncoder = videoCap.mCodec; + int audioEncoder = audioCap.mCodec; + int videoWidth = highQuality? videoCap.mMaxFrameWidth: videoCap.mMinFrameWidth; + int videoHeight = highQuality? videoCap.mMaxFrameHeight: videoCap.mMinFrameHeight; + int videoFps = highQuality? videoCap.mMaxFrameRate: videoCap.mMinFrameRate; + int videoBitrate = highQuality? videoCap.mMaxBitRate: videoCap.mMinBitRate; + int audioBitrate = highQuality? audioCap.mMaxBitRate: audioCap.mMinBitRate; + int audioChannels = highQuality? audioCap.mMaxChannels: audioCap.mMinChannels ; + int audioSamplingRate = highQuality? audioCap.mMaxSampleRate: audioCap.mMinSampleRate; if (videoFps < MIN_VIDEO_FPS) { videoFps = MIN_VIDEO_FPS; } mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); - String filename = ("/sdcard/" + encoder + "_" + audio + "_" + quality + ".3gp"); + String filename = ("/sdcard/" + videoEncoder + "_" + audioEncoder + "_" + highQuality + ".3gp"); try { Log.v(TAG, "video encoder :" + videoEncoder); Log.v(TAG, "audio encoder :" + audioEncoder); - Log.v(TAG, "quality : " + quality); - Log.v(TAG, "encoder : " + encoder); - Log.v(TAG, "audio : " + audio); + Log.v(TAG, "quality : " + (highQuality?"high": "low")); + Log.v(TAG, "encoder : " + MediaProfileReader.getVideoCodecName(videoEncoder)); + Log.v(TAG, "audio : " + MediaProfileReader.getAudioCodecName(audioEncoder)); Log.v(TAG, "videoWidth : " + videoWidth); Log.v(TAG, "videoHeight : " + videoHeight); Log.v(TAG, "videoFPS : " + videoFps); @@ -434,35 +436,26 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram boolean recordSuccess = false; String deviceType = MediaProfileReader.getDeviceType(); Log.v(TAG, "deviceType = " + deviceType); - // Test cases are device specified - MediaProfileReader.createVideoProfileTable(); - MediaProfileReader.createAudioProfileTable(); - MediaProfileReader.createEncoderTable(); - String encoderType = MediaProfileReader.getVideoCodecProperty(); - String audioType = MediaProfileReader.getAudioCodecProperty(); - if ((encoderType.length() != 0) || (audioType.length() != 0)) { - String audio[] = audioType.split(","); - String encoder[] = encoderType.split(","); - for (int k = 0; k < 2; k++) { - for (int i = 0; i < encoder.length; i++) { - for (int j = 0; j < audio.length; j++) { - if (k == 0) { - recordSuccess = recordVideoWithPara(encoder[i], audio[j], "high"); - } else { - recordSuccess = recordVideoWithPara(encoder[i], audio[j], "low"); - } - if (!recordSuccess) { - Log.v(TAG, "testDeviceSpecificCodec failed"); - Log.v(TAG, "Encoder = " + encoder[i] + "Audio Encoder = " + audio[j]); - noOfFailure++; - } - // assertTrue((encoder[i] + audio[j]), recordSuccess); + List<VideoEncoderCap> videoEncoders = MediaProfileReader.getVideoEncoders(); + List<AudioEncoderCap> audioEncoders = MediaProfileReader.getAudioEncoders(); + for (int k = 0; k < 2; k++) { + for (VideoEncoderCap videoEncoder: videoEncoders) { + for (AudioEncoderCap audioEncoder: audioEncoders) { + if (k == 0) { + recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, true); + } else { + recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, false); + } + if (!recordSuccess) { + Log.v(TAG, "testDeviceSpecificCodec failed"); + Log.v(TAG, "Encoder = " + videoEncoder.mCodec + "Audio Encoder = " + audioEncoder.mCodec); + noOfFailure++; } } } - if (noOfFailure != 0) { - assertTrue("testDeviceSpecificCodec", false); - } + } + if (noOfFailure != 0) { + assertTrue("testDeviceSpecificCodec", false); } } } diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java index 8750098..4c259f1 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaMetadataRetrieverTest.java @@ -39,9 +39,8 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase { public static void testAlbumArt() throws Exception { Log.v(TAG, "testAlbumArt starts."); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - MediaProfileReader reader = new MediaProfileReader(); - boolean supportWMA = reader.getWMAEnable(); - boolean supportWMV = reader.getWMVEnable(); + boolean supportWMA = MediaProfileReader.getWMAEnable(); + boolean supportWMV = MediaProfileReader.getWMVEnable(); retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); for (int i = 0, n = MediaNames.ALBUMART_TEST_FILES.length; i < n; ++i) { try { @@ -74,9 +73,8 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase { @LargeTest public static void testThumbnailCapture() throws Exception { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); - MediaProfileReader reader = new MediaProfileReader(); - boolean supportWMA = reader.getWMAEnable(); - boolean supportWMV = reader.getWMVEnable(); + boolean supportWMA = MediaProfileReader.getWMAEnable(); + boolean supportWMV = MediaProfileReader.getWMVEnable(); Log.v(TAG, "Thumbnail processing starts"); long startedAt = System.currentTimeMillis(); for(int i = 0, n = MediaNames.THUMBNAIL_CAPTURE_TEST_FILES.length; i < n; ++i) { @@ -110,9 +108,8 @@ public class MediaMetadataRetrieverTest extends AndroidTestCase { @LargeTest public static void testMetadataRetrieval() throws Exception { - MediaProfileReader reader = new MediaProfileReader(); - boolean supportWMA = reader.getWMAEnable(); - boolean supportWMV = reader.getWMVEnable(); + boolean supportWMA = MediaProfileReader.getWMAEnable(); + boolean supportWMV = MediaProfileReader.getWMVEnable(); MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setMode(MediaMetadataRetriever.MODE_GET_METADATA_ONLY); for(int i = 0, n = MediaNames.METADATA_RETRIEVAL_TEST_FILES.length; i < n; ++i) { |