• 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 
18 package android.media.filterfw.samples;
19 
20 import android.app.Activity;
21 import android.os.Bundle;
22 import android.os.Environment;
23 import android.view.View;
24 import android.view.View.OnClickListener;
25 import android.view.SurfaceView;
26 import android.view.KeyEvent;
27 import android.widget.Button;
28 import android.filterfw.GraphEnvironment;
29 import android.filterfw.core.GraphRunner;
30 import android.filterpacks.videosink.MediaEncoderFilter;
31 import android.graphics.Bitmap;
32 import android.graphics.BitmapFactory;
33 import android.content.Intent;
34 
35 public class CameraEffectsRecordingSample extends Activity {
36 
37     private Button mRunButton;
38     private SurfaceView mCameraView;
39 
40     private GraphRunner mRunner;
41     private int mCameraId = 0;
42     private String mOutFileName =  Environment.getExternalStorageDirectory().toString() +
43         "/CameraEffectsRecordingSample.mp4";
44 
onCreate(Bundle savedInstanceState)45     public void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47         setContentView(R.layout.main);
48         mRunButton = findViewById(R.id.runbutton);
49         mCameraView = findViewById(R.id.cameraview);
50         mRunButton.setOnClickListener(mRunButtonClick);
51 
52         Intent intent = getIntent();
53         if (intent.hasExtra("OUTPUT_FILENAME")) {
54             mOutFileName = intent.getStringExtra("OUTPUT_FILENAME");
55         }
56         // Set up the references and load the filter graph
57         createGraph();
58     }
59 
60     @Override
onKeyDown(int keyCode, KeyEvent event)61     public boolean onKeyDown(int keyCode, KeyEvent event) {
62         switch (keyCode) {
63             case KeyEvent.KEYCODE_CAMERA:
64                 mRunButton.performClick();
65                 return true;
66         }
67         return super.onKeyDown(keyCode, event);
68     }
69 
createGraph()70     private void createGraph() {
71         Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.android);
72         GraphEnvironment graphEnvironment = new GraphEnvironment();
73         graphEnvironment.createGLEnvironment();
74         graphEnvironment.addReferences("cameraView", mCameraView);
75         graphEnvironment.addReferences("cameraId", mCameraId);
76         graphEnvironment.addReferences("outputFileName", mOutFileName);
77         int graphId = graphEnvironment.loadGraph(this, R.raw.cameraeffectsrecordingsample);
78         mRunner = graphEnvironment.getRunner(graphId, GraphEnvironment.MODE_ASYNCHRONOUS);
79     }
80 
onPause()81     protected void onPause() {
82         super.onPause();
83         if (mRunner.isRunning()) {
84             mRunner.stop();
85             mRunButton.setText("Record");
86         }
87     }
88 
89     private OnClickListener mRunButtonClick = new OnClickListener() {
90         @Override
91         public void onClick(View v) {
92             if (mRunner.isRunning()) {
93                 mRunner.stop();
94                 mRunButton.setText("Record");
95             } else {
96                 mRunner.run();
97                 mRunButton.setText("Stop");
98             }
99         }
100     };
101 }
102