Merge "CTS-like Test for Face Effects recording support" into ics-mr1
diff --git a/mca/samples/Android.mk b/mca/samples/Android.mk
new file mode 100644
index 0000000..b1ce91e
--- /dev/null
+++ b/mca/samples/Android.mk
@@ -0,0 +1,21 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Build all native libraries
+#
+include $(call all-subdir-makefiles)
+
+
diff --git a/mca/samples/CameraEffectsRecordingSample/Android.mk b/mca/samples/CameraEffectsRecordingSample/Android.mk
new file mode 100644
index 0000000..d3c4336
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/Android.mk
@@ -0,0 +1,34 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Build activity
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := CameraEffectsRecordingSample
+
+LOCAL_PROGUARD_ENABLED := disabled
+
+include $(BUILD_PACKAGE)
+
+# ============================================================
+
+# Also build all of the sub-targets under this one: the shared library.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/mca/samples/CameraEffectsRecordingSample/AndroidManifest.xml b/mca/samples/CameraEffectsRecordingSample/AndroidManifest.xml
new file mode 100644
index 0000000..a65129d
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/AndroidManifest.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ android:versionCode="1"
+ android:versionName="1.0" package="android.media.filterfw.samples">
+ <uses-sdk android:minSdkVersion="3" />
+ <uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-feature android:name="android.hardware.camera" />
+ <uses-feature android:name="android.hardware.camera.autofocus" />
+ <application android:label="@string/app_name"
+ android:debuggable="true">
+ <activity android:name=".CameraEffectsRecordingSample"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/mca/samples/CameraEffectsRecordingSample/java/android/media/filterfw/samples/CameraEffectsRecordingSample.java b/mca/samples/CameraEffectsRecordingSample/java/android/media/filterfw/samples/CameraEffectsRecordingSample.java
new file mode 100644
index 0000000..c0c3034
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/java/android/media/filterfw/samples/CameraEffectsRecordingSample.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.media.filterfw.samples;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Environment;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.SurfaceView;
+import android.view.KeyEvent;
+import android.widget.Button;
+import android.filterfw.GraphEnvironment;
+import android.filterfw.core.GraphRunner;
+import android.filterpacks.videosink.MediaEncoderFilter;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.content.Intent;
+
+public class CameraEffectsRecordingSample extends Activity {
+
+ private Button mRunButton;
+ private SurfaceView mCameraView;
+
+ private GraphRunner mRunner;
+ private int mCameraId = 0;
+ private String mOutFileName = Environment.getExternalStorageDirectory().toString() +
+ "/CameraEffectsRecordingSample.mp4";
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ mRunButton = (Button) findViewById(R.id.runbutton);
+ mCameraView = (SurfaceView) findViewById(R.id.cameraview);
+ mRunButton.setOnClickListener(mRunButtonClick);
+
+ Intent intent = getIntent();
+ if (intent.hasExtra("OUTPUT_FILENAME")) {
+ mOutFileName = intent.getStringExtra("OUTPUT_FILENAME");
+ }
+ // Set up the references and load the filter graph
+ createGraph();
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_CAMERA:
+ mRunButton.performClick();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ private void createGraph() {
+ Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android);
+ GraphEnvironment graphEnvironment = new GraphEnvironment();
+ graphEnvironment.createGLEnvironment();
+ graphEnvironment.addReferences("cameraView", mCameraView);
+ graphEnvironment.addReferences("cameraId", mCameraId);
+ graphEnvironment.addReferences("outputFileName", mOutFileName);
+ int graphId = graphEnvironment.loadGraph(this, R.raw.cameraeffectsrecordingsample);
+ mRunner = graphEnvironment.getRunner(graphId, GraphEnvironment.MODE_ASYNCHRONOUS);
+ }
+
+ protected void onPause() {
+ super.onPause();
+ if (mRunner.isRunning()) {
+ mRunner.stop();
+ mRunButton.setText("Record");
+ }
+ }
+
+ private OnClickListener mRunButtonClick = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mRunner.isRunning()) {
+ mRunner.stop();
+ mRunButton.setText("Record");
+ } else {
+ mRunner.run();
+ mRunButton.setText("Stop");
+ }
+ }
+ };
+}
diff --git a/mca/samples/CameraEffectsRecordingSample/res/drawable/android.jpg b/mca/samples/CameraEffectsRecordingSample/res/drawable/android.jpg
new file mode 100644
index 0000000..7c26a8d
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/res/drawable/android.jpg
Binary files differ
diff --git a/mca/samples/CameraEffectsRecordingSample/res/layout/main.xml b/mca/samples/CameraEffectsRecordingSample/res/layout/main.xml
new file mode 100644
index 0000000..0cc07ce
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/res/layout/main.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <Button
+ android:id="@+id/runbutton"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="Record" />
+ <android.filterfw.core.FilterSurfaceView
+ android:id="@+id/cameraview"
+ android:layout_height="fill_parent"
+ android:layout_width="fill_parent"
+ android:layout_weight="1" />
+</LinearLayout>
diff --git a/mca/samples/CameraEffectsRecordingSample/res/raw/cameraeffectsrecordingsample.graph b/mca/samples/CameraEffectsRecordingSample/res/raw/cameraeffectsrecordingsample.graph
new file mode 100644
index 0000000..f3ed667
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/res/raw/cameraeffectsrecordingsample.graph
@@ -0,0 +1,57 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// A simple graph that displays the raw camera stream.
+
+@setting autoBranch = "synced";
+
+// Imports ---------------------------------------------------
+@import android.filterpacks.videosrc;
+@import android.filterpacks.ui;
+@import android.filterpacks.videosink;
+@import android.filterpacks.base;
+
+// Externals -------------------------------------------------
+@external cameraView;
+@external outputFileName;
+@external cameraId;
+
+@set widthLoc = 320;
+@set heightLoc = 240;
+
+// Filters ---------------------------------------------------
+@filter CameraSource camera {
+ id = $cameraId;
+ width = $widthLoc;
+ height = $heightLoc;
+ waitForNewFrame = false;
+}
+
+@filter MediaEncoderFilter mediaEncoder {
+ width = $widthLoc;
+ height = $heightLoc;
+ outputFile = $outputFileName;
+}
+
+@filter SurfaceRenderFilter renderer {
+ surfaceView = $cameraView;
+}
+
+
+// Connections -----------------------------------------------
+// Camera->Preview, Camera->Encoder
+// Render camera output on to a surface
+@connect camera[video] => renderer[frame];
+// Also pass it to an encoder
+@connect camera[video] => mediaEncoder[videoframe];
diff --git a/mca/samples/CameraEffectsRecordingSample/res/values/strings.xml b/mca/samples/CameraEffectsRecordingSample/res/values/strings.xml
new file mode 100644
index 0000000..6491043
--- /dev/null
+++ b/mca/samples/CameraEffectsRecordingSample/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ -->
+<resources>
+ <string name="app_name">CameraEffectsRecordingSample</string>
+</resources>
diff --git a/mca/tests/Android.mk b/mca/tests/Android.mk
new file mode 100644
index 0000000..2abd7f6
--- /dev/null
+++ b/mca/tests/Android.mk
@@ -0,0 +1,18 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# We only want this apk build for tests.
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+# Include all test java files.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CameraEffectsTests
+
+LOCAL_INSTRUMENTATION_FOR := CameraEffectsRecordingSample
+
+include $(BUILD_PACKAGE)
+
+
diff --git a/mca/tests/AndroidManifest.xml b/mca/tests/AndroidManifest.xml
new file mode 100644
index 0000000..5133640
--- /dev/null
+++ b/mca/tests/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="android.camera.mediaeffects.tests">
+
+ <uses-permission android:name="android.permission.INJECT_EVENTS" />
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="android.media.filterfw.samples"
+ android:label="Tests for Camera Effects Recording."/>
+</manifest>
diff --git a/mca/tests/src/android/camera/mediaeffects/tests/functional/EffectsVideoCapture.java b/mca/tests/src/android/camera/mediaeffects/tests/functional/EffectsVideoCapture.java
new file mode 100644
index 0000000..474b00f
--- /dev/null
+++ b/mca/tests/src/android/camera/mediaeffects/tests/functional/EffectsVideoCapture.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.camera.mediaeffects.tests.functional;
+
+import android.media.filterfw.samples.CameraEffectsRecordingSample;
+import android.app.Activity;
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.view.KeyEvent;
+import android.util.Log;
+import android.content.Intent;
+import android.os.Environment;
+import android.media.MediaMetadataRetriever;
+import android.net.Uri;
+import java.io.File;
+
+public class EffectsVideoCapture extends ActivityInstrumentationTestCase2
+ <CameraEffectsRecordingSample> {
+ private static final String TAG = "EffectsVideoCaptureTest";
+ private static final long WAIT_FOR_PREVIEW = 4 * 1000; // 4 seconds
+
+ public EffectsVideoCapture() {
+ super(CameraEffectsRecordingSample.class);
+ }
+
+ private void captureVideos(String reportTag, Instrumentation inst) throws Exception{
+ int total_num_of_videos = 1;
+ int video_duration = 4 * 1000; // 4 seconds
+
+ Log.v(TAG, reportTag);
+ for (int i = 0; i < total_num_of_videos; i++) {
+ Thread.sleep(WAIT_FOR_PREVIEW);
+ // record a video
+ inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
+ Thread.sleep(video_duration);
+ inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
+ }
+ }
+
+ @LargeTest
+ public void testBackEffectsVideoCapture() throws Exception {
+ Instrumentation inst = getInstrumentation();
+
+ Intent intent = new Intent();
+ intent.setClass(getInstrumentation().getTargetContext(),
+ CameraEffectsRecordingSample.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra("OUTPUT_FILENAME", Environment.getExternalStorageDirectory().toString()
+ + "/CameraEffectsRecordingTest.mp4");
+ Activity act = inst.startActivitySync(intent);
+ captureVideos("Back Camera Video Capture\n", inst);
+ act.finish();
+
+ // Verification
+ File file = new File(Environment.getExternalStorageDirectory(),
+ "CameraEffectsRecordingTest.mp4");
+ Uri uri = Uri.fromFile(file);
+ verify(getActivity(), uri);
+ }
+
+ // Verify result code, result data, and the duration.
+ private void verify(CameraEffectsRecordingSample activity, Uri uri) throws Exception {
+ assertNotNull(uri);
+ // Verify the video file
+ MediaMetadataRetriever retriever = new MediaMetadataRetriever();
+ retriever.setDataSource(activity, uri);
+ String duration = retriever.extractMetadata(
+ MediaMetadataRetriever.METADATA_KEY_DURATION);
+ assertNotNull(duration);
+ int durationValue = Integer.parseInt(duration);
+ Log.v(TAG, "Video duration is " + durationValue);
+ assertTrue(durationValue > 0);
+ }
+}