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
17package androidx.media.filterpacks.base;
18
19import androidx.media.filterfw.*;
20
21// TODO: Rename back to ValueSource? Seems to make more sense even if we use it as a Variable
22// in some contexts.
23public final class VariableSource extends Filter {
24
25    private Object mValue = null;
26    private OutputPort mOutputPort = null;
27
28    public VariableSource(MffContext context, String name) {
29        super(context, name);
30    }
31
32    public synchronized void setValue(Object value) {
33        mValue = value;
34    }
35
36    public synchronized Object getValue() {
37        return mValue;
38    }
39
40    @Override
41    public Signature getSignature() {
42        return new Signature()
43            .addOutputPort("value", Signature.PORT_REQUIRED, FrameType.single())
44            .disallowOtherPorts();
45    }
46
47    @Override
48    protected void onPrepare() {
49        mOutputPort = getConnectedOutputPort("value");
50    }
51
52    @Override
53    protected synchronized void onProcess() {
54        FrameValue frame = mOutputPort.fetchAvailableFrame(null).asFrameValue();
55        frame.setValue(mValue);
56        mOutputPort.pushFrame(frame);
57    }
58
59}
60
61