Loading media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java 0 → 100644 +84 −0 Original line number Diff line number Diff line package com.android.mediaframeworktest; import android.media.MediaRecorder; import android.os.SystemProperties; import java.util.HashMap; public class MediaProfileReader { 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",}; public static String getVideoCodecProperty() { String s; s = SystemProperties.get("ro.media.enc.vid.codec"); return s; } public static String getAudioCodecProperty() { String s; s = SystemProperties.get("ro.media.enc.aud.codec"); return s; } public static String getDeviceType() { // push all the property into one big table String s; s = SystemProperties.get("ro.product.name"); return s; } public static void createVideoProfileTable() { // push all the property into one big table String encoderType = getVideoCodecProperty(); 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 void createAudioProfileTable() { // push all the property into one big table String audioType = getAudioCodecProperty(); String encoder[] = audioType.split(","); 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 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); } } media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java +98 −3 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import android.test.ActivityInstrumentationTestCase; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import com.android.mediaframeworktest.MediaProfileReader; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; Loading @@ -46,6 +46,9 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram private SurfaceHolder mSurfaceHolder = null; private MediaRecorder mRecorder; private int MIN_VIDEO_FPS = 5; Context mContext; Camera mCamera; Loading Loading @@ -96,6 +99,69 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram } } private boolean recordVideoWithPara(String encoder, String audio, String quality){ 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); if (videoFps < MIN_VIDEO_FPS) { videoFps = MIN_VIDEO_FPS; } mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); String filename = ("/sdcard/" + encoder + "_" + audio + "_" + quality + ".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, "videoWidth : " + videoWidth); Log.v(TAG, "videoHeight : " + videoHeight); Log.v(TAG, "videoFPS : " + videoFps); Log.v(TAG, "videobitrate : " + videoBitrate); Log.v(TAG, "audioBitrate : " + audioBitrate); Log.v(TAG, "audioChannel : " + audioChannels); Log.v(TAG, "AudioSampleRate : " + audioSamplingRate); MediaRecorder mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder.setOutputFile(filename); mMediaRecorder.setVideoFrameRate(videoFps); mMediaRecorder.setVideoSize(videoWidth, videoHeight); mMediaRecorder.setParameters(String.format("video-param-encoding-bitrate=%d", videoBitrate)); mMediaRecorder.setParameters(String.format("audio-param-encoding-bitrate=%d", audioBitrate)); mMediaRecorder.setParameters(String.format("audio-param-number-of-channels=%d", audioChannels)); mMediaRecorder.setParameters(String.format("audio-param-sampling-rate=%d", audioSamplingRate)); mMediaRecorder.setVideoEncoder(videoEncoder); mMediaRecorder.setAudioEncoder(audioEncoder); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mMediaRecorder.prepare(); mMediaRecorder.start(); Thread.sleep(MediaNames.RECORDED_TIME); mMediaRecorder.stop(); mMediaRecorder.release(); recordSuccess = validateVideo(filename, videoWidth, videoHeight); } catch (Exception e) { Log.v(TAG, e.toString()); return false; } return recordSuccess; } private boolean invalidRecordSetting(int frameRate, int width, int height, int videoFormat, int outFormat, String outFile, boolean videoOnly) { Loading Loading @@ -357,5 +423,34 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram assertTrue("Invalid FrameRate", isTestInvalidFrameRateSuccessful); } @LargeTest //est cases for the new codec public void testDeviceSpecificCodec() throws Exception { boolean recordSuccess = false; String deviceType = MediaProfileReader.getDeviceType(); Log.v(TAG, "deviceType = " + deviceType); if (deviceType.compareTo("voles") == 0) { // Test cases are device specified MediaProfileReader.createVideoProfileTable(); MediaProfileReader.createAudioProfileTable(); MediaProfileReader.createEncoderTable(); String encoderType = MediaProfileReader.getVideoCodecProperty(); String encoder[] = encoderType.split(","); String audioType = MediaProfileReader.getAudioCodecProperty(); String audio[] = audioType.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"); } assertTrue((encoder[i] + audio[j]), recordSuccess); } } } } } } Loading
media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaProfileReader.java 0 → 100644 +84 −0 Original line number Diff line number Diff line package com.android.mediaframeworktest; import android.media.MediaRecorder; import android.os.SystemProperties; import java.util.HashMap; public class MediaProfileReader { 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",}; public static String getVideoCodecProperty() { String s; s = SystemProperties.get("ro.media.enc.vid.codec"); return s; } public static String getAudioCodecProperty() { String s; s = SystemProperties.get("ro.media.enc.aud.codec"); return s; } public static String getDeviceType() { // push all the property into one big table String s; s = SystemProperties.get("ro.product.name"); return s; } public static void createVideoProfileTable() { // push all the property into one big table String encoderType = getVideoCodecProperty(); 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 void createAudioProfileTable() { // push all the property into one big table String audioType = getAudioCodecProperty(); String encoder[] = audioType.split(","); 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 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); } }
media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/functional/MediaRecorderTest.java +98 −3 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ import android.test.ActivityInstrumentationTestCase; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; import com.android.mediaframeworktest.MediaProfileReader; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.Suppress; Loading @@ -46,6 +46,9 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram private SurfaceHolder mSurfaceHolder = null; private MediaRecorder mRecorder; private int MIN_VIDEO_FPS = 5; Context mContext; Camera mCamera; Loading Loading @@ -96,6 +99,69 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram } } private boolean recordVideoWithPara(String encoder, String audio, String quality){ 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); if (videoFps < MIN_VIDEO_FPS) { videoFps = MIN_VIDEO_FPS; } mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder(); String filename = ("/sdcard/" + encoder + "_" + audio + "_" + quality + ".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, "videoWidth : " + videoWidth); Log.v(TAG, "videoHeight : " + videoHeight); Log.v(TAG, "videoFPS : " + videoFps); Log.v(TAG, "videobitrate : " + videoBitrate); Log.v(TAG, "audioBitrate : " + audioBitrate); Log.v(TAG, "audioChannel : " + audioChannels); Log.v(TAG, "AudioSampleRate : " + audioSamplingRate); MediaRecorder mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mMediaRecorder.setOutputFile(filename); mMediaRecorder.setVideoFrameRate(videoFps); mMediaRecorder.setVideoSize(videoWidth, videoHeight); mMediaRecorder.setParameters(String.format("video-param-encoding-bitrate=%d", videoBitrate)); mMediaRecorder.setParameters(String.format("audio-param-encoding-bitrate=%d", audioBitrate)); mMediaRecorder.setParameters(String.format("audio-param-number-of-channels=%d", audioChannels)); mMediaRecorder.setParameters(String.format("audio-param-sampling-rate=%d", audioSamplingRate)); mMediaRecorder.setVideoEncoder(videoEncoder); mMediaRecorder.setAudioEncoder(audioEncoder); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mMediaRecorder.prepare(); mMediaRecorder.start(); Thread.sleep(MediaNames.RECORDED_TIME); mMediaRecorder.stop(); mMediaRecorder.release(); recordSuccess = validateVideo(filename, videoWidth, videoHeight); } catch (Exception e) { Log.v(TAG, e.toString()); return false; } return recordSuccess; } private boolean invalidRecordSetting(int frameRate, int width, int height, int videoFormat, int outFormat, String outFile, boolean videoOnly) { Loading Loading @@ -357,5 +423,34 @@ public class MediaRecorderTest extends ActivityInstrumentationTestCase<MediaFram assertTrue("Invalid FrameRate", isTestInvalidFrameRateSuccessful); } @LargeTest //est cases for the new codec public void testDeviceSpecificCodec() throws Exception { boolean recordSuccess = false; String deviceType = MediaProfileReader.getDeviceType(); Log.v(TAG, "deviceType = " + deviceType); if (deviceType.compareTo("voles") == 0) { // Test cases are device specified MediaProfileReader.createVideoProfileTable(); MediaProfileReader.createAudioProfileTable(); MediaProfileReader.createEncoderTable(); String encoderType = MediaProfileReader.getVideoCodecProperty(); String encoder[] = encoderType.split(","); String audioType = MediaProfileReader.getAudioCodecProperty(); String audio[] = audioType.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"); } assertTrue((encoder[i] + audio[j]), recordSuccess); } } } } } }