FrameFetch.java revision 30ab3fc173709a491c9e2e103f53fb7c0d1b96b7
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
18package android.filterpacks.base;
19
20import android.filterfw.core.Filter;
21import android.filterfw.core.FilterEnvironment;
22import android.filterfw.core.FilterParameter;
23import android.filterfw.core.Frame;
24import android.filterfw.core.FrameFormat;
25
26import android.util.Log;
27
28public class FrameFetch extends Filter {
29
30    @FilterParameter(name = "key", isOptional = false)
31    private String mKey;
32
33    @FilterParameter(name = "format", isOptional = true)
34    private FrameFormat mFormat;
35
36    @FilterParameter(name = "repeatFrame", isOptional = true)
37    private boolean mRepeatFrame = false;
38
39    public FrameFetch(String name) {
40        super(name);
41    }
42
43    public String[] getInputNames() {
44        return null;
45    }
46
47    public String[] getOutputNames() {
48        return new String[] { "frame" };
49    }
50
51    public boolean setInputFormat(int index, FrameFormat format) {
52        return false;
53    }
54
55    public FrameFormat getFormatForOutput(int index) {
56        if (mFormat != null) {
57            return mFormat;
58        } else {
59            return new FrameFormat(FrameFormat.TYPE_UNSPECIFIED, FrameFormat.TARGET_UNSPECIFIED);
60        }
61    }
62
63    public int process(FilterEnvironment env) {
64        Frame output = env.fetchFrame(mKey);
65        Log.i("FrameFetch", "Got frame " + output + " for key: " + mKey + "!");
66        if (output != null) {
67            putOutput(0, output);
68            return mRepeatFrame ? Filter.STATUS_WAIT_FOR_FREE_OUTPUTS : Filter.STATUS_FINISHED;
69        } else {
70            return Filter.STATUS_SLEEP | Filter.STATUS_WAIT_FOR_FREE_OUTPUTS;
71        }
72    }
73
74}
75