2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android
.media
.effect
.effects
;
19 import android
.filterfw
.core
.Filter
;
20 import android
.filterfw
.core
.OneShotScheduler
;
21 import android
.media
.effect
.EffectContext
;
22 import android
.media
.effect
.FilterGraphEffect
;
23 import android
.media
.effect
.EffectUpdateListener
;
25 import android
.filterpacks
.videoproc
.BackDropperFilter
;
26 import android
.filterpacks
.videoproc
.BackDropperFilter
.LearningDoneListener
;
29 * Background replacement Effect.
31 * Replaces the background of the input video stream with a selected video
32 * Learns the background when it first starts up;
33 * needs unobstructed view of background when this happens.
36 * source: A URI for the background video
37 * Listener: Called when learning period is complete
41 public class BackDropperEffect
extends FilterGraphEffect
{
42 private static final String mGraphDefinition
=
43 "@import android.filterpacks.base;\n" +
44 "@import android.filterpacks.videoproc;\n" +
45 "@import android.filterpacks.videosrc;\n" +
47 "@filter GLTextureSource foreground {\n" +
48 " texId = 0;\n" + // Will be set by base class
51 " repeatFrame = true;\n" +
54 "@filter MediaSource background {\n" +
55 " sourceUrl = \"no_file_specified\";\n" +
56 " waitForNewFrame = false;\n" +
57 " sourceIsUrl = true;\n" +
60 "@filter BackDropperFilter replacer {\n" +
61 " autowbToggle = 1;\n" +
64 "@filter GLTextureTarget output {\n" +
68 "@connect foreground[frame] => replacer[video];\n" +
69 "@connect background[video] => replacer[background];\n" +
70 "@connect replacer[video] => output[frame];\n";
72 private EffectUpdateListener mEffectListener
= null;
74 private LearningDoneListener mLearningListener
= new LearningDoneListener() {
75 public void onLearningDone(BackDropperFilter filter
) {
76 if (mEffectListener
!= null) {
77 mEffectListener
.onEffectUpdated(BackDropperEffect
.this, null);
82 public BackDropperEffect(EffectContext context
, String name
) {
83 super(context
, name
, mGraphDefinition
, "foreground", "output", OneShotScheduler
.class);
85 Filter replacer
= mGraph
.getFilter("replacer");
86 replacer
.setInputValue("learningDoneListener", mLearningListener
);
90 public void setParameter(String parameterKey
, Object value
) {
91 if (parameterKey
.equals("source")) {
92 Filter background
= mGraph
.getFilter("background");
93 background
.setInputValue("sourceUrl", value
);
94 } else if (parameterKey
.equals("context")) {
95 Filter background
= mGraph
.getFilter("background");
96 background
.setInputValue("context", value
);
101 public void setUpdateListener(EffectUpdateListener listener
) {
102 mEffectListener
= listener
;