• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.camera.mediaeffects.tests.functional;
18 
19 import android.media.filterfw.samples.CameraEffectsRecordingSample;
20 import android.app.Activity;
21 import android.app.Instrumentation;
22 import android.content.Intent;
23 import android.test.ActivityInstrumentationTestCase2;
24 import android.test.suitebuilder.annotation.LargeTest;
25 import android.view.KeyEvent;
26 import android.util.Log;
27 import android.content.Intent;
28 import android.os.Environment;
29 import android.media.MediaMetadataRetriever;
30 import android.net.Uri;
31 import java.io.File;
32 
33 public class EffectsVideoCapture extends ActivityInstrumentationTestCase2
34                                                <CameraEffectsRecordingSample> {
35     private static final String TAG = "EffectsVideoCaptureTest";
36     private static final long WAIT_FOR_PREVIEW = 4 * 1000; // 4 seconds
37 
EffectsVideoCapture()38     public EffectsVideoCapture() {
39         super(CameraEffectsRecordingSample.class);
40     }
41 
captureVideos(String reportTag, Instrumentation inst)42     private void captureVideos(String reportTag, Instrumentation inst) throws Exception{
43         int total_num_of_videos = 1;
44         int video_duration = 4 * 1000; // 4 seconds
45 
46         Log.v(TAG, reportTag);
47         for (int i = 0; i < total_num_of_videos; i++) {
48             Thread.sleep(WAIT_FOR_PREVIEW);
49             // record a video
50             inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
51             Thread.sleep(video_duration);
52             inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
53         }
54     }
55 
56     @LargeTest
testBackEffectsVideoCapture()57     public void testBackEffectsVideoCapture() throws Exception {
58         Instrumentation inst = getInstrumentation();
59 
60         Intent intent = new Intent();
61         intent.setClass(getInstrumentation().getTargetContext(),
62                 CameraEffectsRecordingSample.class);
63         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
64         intent.putExtra("OUTPUT_FILENAME", Environment.getExternalStorageDirectory().toString()
65                 + "/CameraEffectsRecordingTest.mp4");
66         Activity act = inst.startActivitySync(intent);
67         captureVideos("Back Camera Video Capture\n", inst);
68         act.finish();
69 
70         // Verification
71         File file = new File(Environment.getExternalStorageDirectory(),
72                 "CameraEffectsRecordingTest.mp4");
73         Uri uri = Uri.fromFile(file);
74         verify(getActivity(), uri);
75     }
76 
77     // Verify result code, result data, and the duration.
verify(CameraEffectsRecordingSample activity, Uri uri)78     private void verify(CameraEffectsRecordingSample activity, Uri uri) throws Exception {
79         assertNotNull(uri);
80         // Verify the video file
81         MediaMetadataRetriever retriever = new MediaMetadataRetriever();
82         retriever.setDataSource(activity, uri);
83         String duration = retriever.extractMetadata(
84                 MediaMetadataRetriever.METADATA_KEY_DURATION);
85         assertNotNull(duration);
86         int durationValue = Integer.parseInt(duration);
87         Log.v(TAG, "Video duration is " + durationValue);
88         assertTrue(durationValue > 0);
89     }
90 }
91