Ports are used internally only, so this does not change API.
Change-Id: I60a274ddd30bbb1f82d1b12980b6b95a07cb65ce
import java.lang.reflect.Field;
-public class FieldPort extends TargetPort {
+public class FieldPort extends InputPort {
protected Field mField;
protected boolean mHasFrame;
private int mInputCount = -1;
private int mOutputCount = -1;
- private HashMap<String, TargetPort> mInputPorts;
- private HashMap<String, SourcePort> mOutputPorts;
+ private HashMap<String, InputPort> mInputPorts;
+ private HashMap<String, OutputPort> mOutputPorts;
private HashSet<Frame> mFramesToRelease;
private HashMap<String, Frame> mFramesToSet;
}
public final FrameFormat getInputFormat(String portName) {
- TargetPort inputPort = getInputPort(portName);
+ InputPort inputPort = getInputPort(portName);
return inputPort.getSourceFormat();
}
public final int getNumberOfConnectedInputs() {
int c = 0;
- for (TargetPort inputPort : mInputPorts.values()) {
+ for (InputPort inputPort : mInputPorts.values()) {
if (inputPort.isConnected()) {
++c;
}
public final int getNumberOfConnectedOutputs() {
int c = 0;
- for (SourcePort outputPort : mOutputPorts.values()) {
+ for (OutputPort outputPort : mOutputPorts.values()) {
if (outputPort.isConnected()) {
++c;
}
return mInputPorts == null ? 0 : mOutputPorts.size();
}
- public final TargetPort getInputPort(String portName) {
- TargetPort result = mInputPorts.get(portName);
+ public final InputPort getInputPort(String portName) {
+ InputPort result = mInputPorts.get(portName);
if (result == null) {
throw new IllegalArgumentException("Unknown input port '" + portName + "' on filter "
+ this + "!");
return result;
}
- public final SourcePort getOutputPort(String portName) {
- SourcePort result = mOutputPorts.get(portName);
+ public final OutputPort getOutputPort(String portName) {
+ OutputPort result = mOutputPorts.get(portName);
if (result == null) {
throw new IllegalArgumentException("Unknown output port '" + portName + "' on filter "
+ this + "!");
* @param formatMask a format mask, which filters the allowable input types
*/
protected void addMaskedInputPort(String name, FrameFormat formatMask) {
- TargetPort port = new InputPort(this, name);
+ InputPort port = new StreamPort(this, name);
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + port);
mInputPorts.put(name, port);
port.setPortFormat(formatMask);
field.setAccessible(true);
// Create port for this input
- TargetPort fieldPort = isFinal
+ InputPort fieldPort = isFinal
? new FinalPort(this, name, field, hasDefault)
: new FieldPort(this, name, field, hasDefault);
field.setAccessible(true);
// Create port for this input
- TargetPort programPort = new ProgramPort(this, name, varName, field, hasDefault);
+ InputPort programPort = new ProgramPort(this, name, varName, field, hasDefault);
// Create format for this input
if (mLogVerbose) Log.v(TAG, "Filter " + this + " adding " + programPort);
}
// Core internal methods ///////////////////////////////////////////////////////////////////////
- final Collection<TargetPort> getInputPorts() {
+ final Collection<InputPort> getInputPorts() {
return mInputPorts.values();
}
- final Collection<SourcePort> getOutputPorts() {
+ final Collection<OutputPort> getOutputPorts() {
return mOutputPorts.values();
}
final void openOutputs() {
if (mLogVerbose) Log.v(TAG, "Opening all output ports on " + this + "!");
- for (SourcePort outputPort : mOutputPorts.values()) {
+ for (OutputPort outputPort : mOutputPorts.values()) {
if (!outputPort.isOpen()) {
outputPort.open();
}
// Filter internal methods /////////////////////////////////////////////////////////////////////
private final void initFinalPorts(KeyValueMap values) {
- mInputPorts = new HashMap<String, TargetPort>();
- mOutputPorts = new HashMap<String, SourcePort>();
+ mInputPorts = new HashMap<String, InputPort>();
+ mOutputPorts = new HashMap<String, OutputPort>();
addAndSetFinalPorts(values);
}
}
private final void transferInputFrames(FilterContext context) {
- for (TargetPort inputPort : mInputPorts.values()) {
+ for (InputPort inputPort : mInputPorts.values()) {
inputPort.transfer(context);
}
}
private final void closePorts() {
if (mLogVerbose) Log.v(TAG, "Closing all ports on " + this + "!");
- for (TargetPort inputPort : mInputPorts.values()) {
+ for (InputPort inputPort : mInputPorts.values()) {
inputPort.close();
}
- for (SourcePort outputPort : mOutputPorts.values()) {
+ for (OutputPort outputPort : mOutputPorts.values()) {
outputPort.close();
}
}
private final boolean filterMustClose() {
- for (TargetPort inputPort : mInputPorts.values()) {
+ for (InputPort inputPort : mInputPorts.values()) {
if (inputPort.filterMustClose()) {
if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + inputPort);
return true;
}
}
- for (SourcePort outputPort : mOutputPorts.values()) {
+ for (OutputPort outputPort : mOutputPorts.values()) {
if (outputPort.filterMustClose()) {
if (mLogVerbose) Log.v(TAG, "Filter " + this + " must close due to port " + outputPort);
return true;
private boolean mFilterIsSetup = false;
private FrameHolderPort[] mResultHolders;
- private class FrameHolderPort extends InputPort {
+ private class FrameHolderPort extends StreamPort {
public FrameHolderPort() {
super(null, "holder");
}
private void connectFilterOutputs() {
int i = 0;
mResultHolders = new FrameHolderPort[mFilter.getNumberOfOutputs()];
- for (SourcePort outputPort : mFilter.getOutputPorts()) {
+ for (OutputPort outputPort : mFilter.getOutputPorts()) {
mResultHolders[i] = new FrameHolderPort();
outputPort.connectTo(mResultHolders[i]);
++i;
private HashSet<Filter> mFilters = new HashSet<Filter>();
private HashMap<String, Filter> mNameMap = new HashMap<String, Filter>();
- private HashMap<SourcePort, LinkedList<TargetPort>> mPreconnections = new
- HashMap<SourcePort, LinkedList<TargetPort>>();
+ private HashMap<OutputPort, LinkedList<InputPort>> mPreconnections = new
+ HashMap<OutputPort, LinkedList<InputPort>>();
public static final int AUTOBRANCH_OFF = 0;
public static final int AUTOBRANCH_SYNCED = 1;
throw new RuntimeException("Attempting to connect filter not in graph!");
}
- SourcePort outPort = source.getOutputPort(outputName);
- TargetPort inPort = target.getInputPort(inputName);
+ OutputPort outPort = source.getOutputPort(outputName);
+ InputPort inPort = target.getInputPort(inputName);
if (outPort == null) {
throw new RuntimeException("Unknown output port '" + outputName + "' on Filter " +
source + "!");
}
// Check if all dependencies have been processed
- for (TargetPort port : filter.getInputPorts()) {
+ for (InputPort port : filter.getInputPorts()) {
Filter dependency = port.getSourceFilter();
if (dependency != null && !processed.contains(dependency)) {
return false;
runTypeCheckOn(filter, strict);
// Push connected filters onto stack
- for (SourcePort port : filter.getOutputPorts()) {
+ for (OutputPort port : filter.getOutputPorts()) {
Filter target = port.getTargetFilter();
if (target != null && readyForProcessing(target, processedFilters)) {
filterStack.push(target);
}
private void updateOutputs(Filter filter) {
- for (SourcePort outputPort : filter.getOutputPorts()) {
- TargetPort inputPort = outputPort.getBasePort();
+ for (OutputPort outputPort : filter.getOutputPorts()) {
+ InputPort inputPort = outputPort.getBasePort();
if (inputPort != null) {
FrameFormat inputFormat = inputPort.getSourceFormat();
FrameFormat outputFormat = filter.getOutputFormat(outputPort.getName(),
}
private void runTypeCheckOn(Filter filter, boolean strict) {
- for (TargetPort inputPort : filter.getInputPorts()) {
+ for (InputPort inputPort : filter.getInputPorts()) {
if (mLogVerbose) Log.v(TAG, "Type checking port " + inputPort);
FrameFormat sourceFormat = inputPort.getSourceFormat();
FrameFormat targetFormat = inputPort.getPortFormat();
LinkedList<Filter> addedFilters = new LinkedList<Filter>();
for (Filter filter : mFilters) {
int id = 0;
- for (SourcePort port : filter.getOutputPorts()) {
+ for (OutputPort port : filter.getOutputPorts()) {
if (!port.isConnected()) {
if (mLogVerbose) Log.v(TAG, "Autoconnecting unconnected " + port + " to Null filter.");
NullFilter nullFilter = new NullFilter(filter.getName() + "ToNull" + id);
mNameMap.remove(filter.getName());
}
- private void preconnect(SourcePort outPort, TargetPort inPort) {
- LinkedList<TargetPort> targets;
+ private void preconnect(OutputPort outPort, InputPort inPort) {
+ LinkedList<InputPort> targets;
targets = mPreconnections.get(outPort);
if (targets == null) {
- targets = new LinkedList<TargetPort>();
+ targets = new LinkedList<InputPort>();
mPreconnections.put(outPort, targets);
}
targets.add(inPort);
private void connectPorts() {
int branchId = 1;
- for (Entry<SourcePort, LinkedList<TargetPort>> connection : mPreconnections.entrySet()) {
- SourcePort sourcePort = connection.getKey();
- LinkedList<TargetPort> targetPorts = connection.getValue();
- if (targetPorts.size() == 1) {
- sourcePort.connectTo(targetPorts.get(0));
+ for (Entry<OutputPort, LinkedList<InputPort>> connection : mPreconnections.entrySet()) {
+ OutputPort outputPort = connection.getKey();
+ LinkedList<InputPort> inputPorts = connection.getValue();
+ if (inputPorts.size() == 1) {
+ outputPort.connectTo(inputPorts.get(0));
} else if (mAutoBranchMode == AUTOBRANCH_OFF) {
- throw new RuntimeException("Attempting to connect " + sourcePort + " to multiple "
+ throw new RuntimeException("Attempting to connect " + outputPort + " to multiple "
+ "filter ports! Enable auto-branching to allow this.");
} else {
- if (mLogVerbose) Log.v(TAG, "Creating branch for " + sourcePort + "!");
+ if (mLogVerbose) Log.v(TAG, "Creating branch for " + outputPort + "!");
FrameBranch branch = null;
if (mAutoBranchMode == AUTOBRANCH_SYNCED) {
branch = new FrameBranch("branch" + branchId++);
throw new RuntimeException("TODO: Unsynced branches not implemented yet!");
}
KeyValueMap branchParams = new KeyValueMap();
- branch.initWithAssignmentList("outputs", targetPorts.size());
+ branch.initWithAssignmentList("outputs", inputPorts.size());
addFilter(branch);
- sourcePort.connectTo(branch.getInputPort("in"));
- Iterator<TargetPort> targetPortIter = targetPorts.iterator();
- for (SourcePort branchOutPort : ((Filter)branch).getOutputPorts()) {
- branchOutPort.connectTo(targetPortIter.next());
+ outputPort.connectTo(branch.getInputPort("in"));
+ Iterator<InputPort> inputPortIter = inputPorts.iterator();
+ for (OutputPort branchOutPort : ((Filter)branch).getOutputPorts()) {
+ branchOutPort.connectTo(inputPortIter.next());
}
}
}
package android.filterfw.core;
-public class InputPort extends TargetPort {
+public abstract class InputPort extends FilterPort {
- private Frame mFrame;
- private boolean mPersistent;
+ protected OutputPort mSourcePort;
public InputPort(Filter filter, String name) {
super(filter, name);
}
- @Override
- public void clear() {
- if (mFrame != null) {
- mFrame.release();
- mFrame = null;
+ public void setSourcePort(OutputPort source) {
+ if (mSourcePort != null) {
+ throw new RuntimeException(this + " already connected to " + mSourcePort + "!");
}
+ mSourcePort = source;
}
- @Override
- public void setFrame(Frame frame) {
- assignFrame(frame, true);
+ public boolean isConnected() {
+ return mSourcePort != null;
}
- @Override
- public void pushFrame(Frame frame) {
- assignFrame(frame, false);
+ public void open() {
+ super.open();
+ if (mSourcePort != null && !mSourcePort.isOpen()) {
+ mSourcePort.open();
+ }
}
- private void assignFrame(Frame frame, boolean persistent) {
- assertPortIsOpen();
- if (persistent) {
- if (mFrame != null) {
- mFrame.release();
- }
- } else if (mFrame != null) {
- throw new RuntimeException(
- "Attempting to push more than one frame on port: " + this + "!");
+ public void close() {
+ if (mSourcePort != null && mSourcePort.isOpen()) {
+ mSourcePort.close();
}
- mFrame = frame.retain();
- mFrame.markReadOnly();
- mPersistent = persistent;
+ super.close();
}
- @Override
- public Frame pullFrame() {
- // Make sure we have a frame
- if (mFrame == null) {
- throw new RuntimeException("No frame available to pull on port: " + this + "!");
- }
+ public OutputPort getSourcePort() {
+ return mSourcePort;
+ }
- // Return a retained result
- Frame result = mFrame;
- if (mPersistent) {
- mFrame.retain();
- } else {
- mFrame = null;
- }
- return result;
+ public Filter getSourceFilter() {
+ return mSourcePort == null ? null : mSourcePort.getFilter();
+ }
+
+ public FrameFormat getSourceFormat() {
+ return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
+ }
+
+ public boolean filterMustClose() {
+ return !isOpen() && isBlocking() && !hasFrame();
}
- @Override
- public boolean hasFrame() {
- return mFrame != null;
+ public boolean isReady() {
+ return hasFrame() || !isBlocking();
}
- @Override
- public String toString() {
- return "input " + super.toString();
+ public void transfer(FilterContext context) {
}
}
package android.filterfw.core;
-public class OutputPort extends SourcePort {
+public class OutputPort extends FilterPort {
+
+ protected InputPort mTargetPort;
+ protected InputPort mBasePort;
public OutputPort(Filter filter, String name) {
super(filter, name);
}
+ public void connectTo(InputPort target) {
+ if (mTargetPort != null) {
+ throw new RuntimeException(this + " already connected to " + mTargetPort + "!");
+ }
+ mTargetPort = target;
+ mTargetPort.setSourcePort(this);
+ }
+
+ public boolean isConnected() {
+ return mTargetPort != null;
+ }
+
+ public void open() {
+ super.open();
+ if (mTargetPort != null && !mTargetPort.isOpen()) {
+ mTargetPort.open();
+ }
+ }
+
+ public void close() {
+ super.close();
+ if (mTargetPort != null && mTargetPort.isOpen()) {
+ mTargetPort.close();
+ }
+ }
+
+ public InputPort getTargetPort() {
+ return mTargetPort;
+ }
+
+ public Filter getTargetFilter() {
+ return mTargetPort == null ? null : mTargetPort.getFilter();
+ }
+
+ public void setBasePort(InputPort basePort) {
+ mBasePort = basePort;
+ }
+
+ public InputPort getBasePort() {
+ return mBasePort;
+ }
+
+ public boolean filterMustClose() {
+ return !isOpen() && isBlocking();
+ }
+
+ public boolean isReady() {
+ return (isOpen() && !hasFrame()) || !isBlocking();
+ }
+
@Override
public void clear() {
if (mTargetPort != null) {
+++ /dev/null
-/*
- * 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.filterfw.core;
-
-public abstract class SourcePort extends FilterPort {
-
- protected TargetPort mTargetPort;
- protected TargetPort mBasePort;
-
- public SourcePort(Filter filter, String name) {
- super(filter, name);
- }
-
- public void connectTo(TargetPort target) {
- if (mTargetPort != null) {
- throw new RuntimeException(this + " already connected to " + mTargetPort + "!");
- }
- mTargetPort = target;
- mTargetPort.setSourcePort(this);
- }
-
- public boolean isConnected() {
- return mTargetPort != null;
- }
-
- public void open() {
- super.open();
- if (mTargetPort != null && !mTargetPort.isOpen()) {
- mTargetPort.open();
- }
- }
-
- public void close() {
- super.close();
- if (mTargetPort != null && mTargetPort.isOpen()) {
- mTargetPort.close();
- }
- }
-
- public TargetPort getTargetPort() {
- return mTargetPort;
- }
-
- public Filter getTargetFilter() {
- return mTargetPort == null ? null : mTargetPort.getFilter();
- }
-
- public void setBasePort(TargetPort basePort) {
- mBasePort = basePort;
- }
-
- public TargetPort getBasePort() {
- return mBasePort;
- }
-
- public boolean filterMustClose() {
- return !isOpen() && isBlocking();
- }
-
- public boolean isReady() {
- return (isOpen() && !hasFrame()) || !isBlocking();
- }
-
-}
--- /dev/null
+/*
+ * 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.filterfw.core;
+
+public class StreamPort extends InputPort {
+
+ private Frame mFrame;
+ private boolean mPersistent;
+
+ public StreamPort(Filter filter, String name) {
+ super(filter, name);
+ }
+
+ @Override
+ public void clear() {
+ if (mFrame != null) {
+ mFrame.release();
+ mFrame = null;
+ }
+ }
+
+ @Override
+ public void setFrame(Frame frame) {
+ assignFrame(frame, true);
+ }
+
+ @Override
+ public void pushFrame(Frame frame) {
+ assignFrame(frame, false);
+ }
+
+ private void assignFrame(Frame frame, boolean persistent) {
+ assertPortIsOpen();
+ if (persistent) {
+ if (mFrame != null) {
+ mFrame.release();
+ }
+ } else if (mFrame != null) {
+ throw new RuntimeException(
+ "Attempting to push more than one frame on port: " + this + "!");
+ }
+ mFrame = frame.retain();
+ mFrame.markReadOnly();
+ mPersistent = persistent;
+ }
+
+ @Override
+ public Frame pullFrame() {
+ // Make sure we have a frame
+ if (mFrame == null) {
+ throw new RuntimeException("No frame available to pull on port: " + this + "!");
+ }
+
+ // Return a retained result
+ Frame result = mFrame;
+ if (mPersistent) {
+ mFrame.retain();
+ } else {
+ mFrame = null;
+ }
+ return result;
+ }
+
+ @Override
+ public boolean hasFrame() {
+ return mFrame != null;
+ }
+
+ @Override
+ public String toString() {
+ return "input " + super.toString();
+ }
+}
+++ /dev/null
-/*
- * 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.filterfw.core;
-
-public abstract class TargetPort extends FilterPort {
-
- protected SourcePort mSourcePort;
-
- public TargetPort(Filter filter, String name) {
- super(filter, name);
- }
-
- public void setSourcePort(SourcePort source) {
- if (mSourcePort != null) {
- throw new RuntimeException(this + " already connected to " + mSourcePort + "!");
- }
- mSourcePort = source;
- }
-
- public boolean isConnected() {
- return mSourcePort != null;
- }
-
- public void open() {
- super.open();
- if (mSourcePort != null && !mSourcePort.isOpen()) {
- mSourcePort.open();
- }
- }
-
- public void close() {
- if (mSourcePort != null && mSourcePort.isOpen()) {
- mSourcePort.close();
- }
- super.close();
- }
-
- public SourcePort getSourcePort() {
- return mSourcePort;
- }
-
- public Filter getSourceFilter() {
- return mSourcePort == null ? null : mSourcePort.getFilter();
- }
-
- public FrameFormat getSourceFormat() {
- return mSourcePort != null ? mSourcePort.getPortFormat() : getPortFormat();
- }
-
- public boolean filterMustClose() {
- return !isOpen() && isBlocking() && !hasFrame();
- }
-
- public boolean isReady() {
- return hasFrame() || !isBlocking();
- }
-
- public void transfer(FilterContext context) {
- }
-}