2626import android .hardware .Camera .PreviewCallback ;
2727import android .media .MediaPlayer ;
2828import android .media .MediaRecorder ;
29+ import android .media .EncoderCapabilities .VideoEncoderCap ;
2930import android .os .ConditionVariable ;
3031import android .os .Looper ;
3132import android .os .SystemClock ;
3536import android .util .Log ;
3637import android .view .SurfaceHolder ;
3738
39+ import java .util .List ;
3840import java .io .FileDescriptor ;
3941import java .io .FileInputStream ;
4042import java .io .FileOutputStream ;
4850import android .media .MediaMetadataRetriever ;
4951import com .android .mediaframeworktest .MediaProfileReader ;
5052
51- import android .hardware .Camera .PreviewCallback ;
52-
5353/**
5454 * Junit / Instrumentation - performance measurement for media player and
5555 * recorder
56+ *
57+ * FIXME:
58+ * Add tests on H264 video encoder
5659 */
5760public class MediaPlayerPerformance extends ActivityInstrumentationTestCase2 <MediaFrameworkTest > {
5861
@@ -81,6 +84,8 @@ public class MediaPlayerPerformance extends ActivityInstrumentationTestCase2<Med
8184 private static int DECODER_LIMIT = 150 ;
8285 private static int CAMERA_LIMIT = 80 ;
8386
87+ private static List <VideoEncoderCap > videoEncoders = MediaProfileReader .getVideoEncoders ();
88+
8489 Camera mCamera ;
8590
8691 public MediaPlayerPerformance () {
@@ -360,6 +365,16 @@ public void testH264VideoPlaybackMemoryUsage() throws Exception {
360365 assertTrue ("H264 playback memory test" , memoryResult );
361366 }
362367
368+ private int getMaxFrameRateForVideoEncoder (int codec ) {
369+ int frameRate = -1 ;
370+ for (VideoEncoderCap cap : videoEncoders ) {
371+ if (cap .mCodec == MediaRecorder .VideoEncoder .H263 ) {
372+ frameRate = cap .mMaxFrameRate ;
373+ }
374+ }
375+ return frameRate ;
376+ }
377+
363378 // Test case 4: Capture the memory usage after every 20 video only recorded
364379 @ LargeTest
365380 public void testH263RecordVideoOnlyMemoryUsage () throws Exception {
@@ -369,8 +384,10 @@ public void testH263RecordVideoOnlyMemoryUsage() throws Exception {
369384 File videoH263RecordOnlyMemoryOut = new File (MEDIA_MEMORY_OUTPUT );
370385 Writer output = new BufferedWriter (new FileWriter (videoH263RecordOnlyMemoryOut , true ));
371386 output .write ("H263 video record only\n " );
387+ int frameRate = getMaxFrameRateForVideoEncoder (MediaRecorder .VideoEncoder .H263 );
388+ assertTrue ("H263 video recording frame rate" , frameRate != -1 );
372389 for (int i = 0 ; i < NUM_STRESS_LOOP ; i ++) {
373- assertTrue (stressVideoRecord (20 , 352 , 288 , MediaRecorder .VideoEncoder .H263 ,
390+ assertTrue (stressVideoRecord (frameRate , 352 , 288 , MediaRecorder .VideoEncoder .H263 ,
374391 MediaRecorder .OutputFormat .MPEG_4 , MediaNames .RECORDED_VIDEO_3GP , true ));
375392 getMemoryWriteToLog (output , i );
376393 }
@@ -389,8 +406,10 @@ public void testMpeg4RecordVideoOnlyMemoryUsage() throws Exception {
389406 File videoMp4RecordOnlyMemoryOut = new File (MEDIA_MEMORY_OUTPUT );
390407 Writer output = new BufferedWriter (new FileWriter (videoMp4RecordOnlyMemoryOut , true ));
391408 output .write ("MPEG4 video record only\n " );
409+ int frameRate = getMaxFrameRateForVideoEncoder (MediaRecorder .VideoEncoder .MPEG_4_SP );
410+ assertTrue ("MPEG4 video recording frame rate" , frameRate != -1 );
392411 for (int i = 0 ; i < NUM_STRESS_LOOP ; i ++) {
393- assertTrue (stressVideoRecord (20 , 352 , 288 , MediaRecorder .VideoEncoder .MPEG_4_SP ,
412+ assertTrue (stressVideoRecord (frameRate , 352 , 288 , MediaRecorder .VideoEncoder .MPEG_4_SP ,
394413 MediaRecorder .OutputFormat .MPEG_4 , MediaNames .RECORDED_VIDEO_3GP , true ));
395414 getMemoryWriteToLog (output , i );
396415 }
@@ -409,9 +428,11 @@ public void testRecordVideoAudioMemoryUsage() throws Exception {
409428
410429 File videoRecordAudioMemoryOut = new File (MEDIA_MEMORY_OUTPUT );
411430 Writer output = new BufferedWriter (new FileWriter (videoRecordAudioMemoryOut , true ));
431+ int frameRate = getMaxFrameRateForVideoEncoder (MediaRecorder .VideoEncoder .H263 );
432+ assertTrue ("H263 video recording frame rate" , frameRate != -1 );
412433 output .write ("Audio and h263 video record\n " );
413434 for (int i = 0 ; i < NUM_STRESS_LOOP ; i ++) {
414- assertTrue (stressVideoRecord (20 , 352 , 288 , MediaRecorder .VideoEncoder .H263 ,
435+ assertTrue (stressVideoRecord (frameRate , 352 , 288 , MediaRecorder .VideoEncoder .H263 ,
415436 MediaRecorder .OutputFormat .MPEG_4 , MediaNames .RECORDED_VIDEO_3GP , false ));
416437 getMemoryWriteToLog (output , i );
417438 }
0 commit comments