1 /* 2 * Copyright (C) 2013 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 package androidx.media.filterfw; 17 18 /** 19 * A {@link Filter} that consumes frames and allows to register a listener to observe when 20 * a new frame has been consumed. 21 */ 22 class FrameTargetFilter extends Filter { 23 24 interface Listener { 25 /** 26 * Called each time this filter receives a new frame. The implementer of this method is 27 * responsible for releasing the frame. 28 */ 29 void onFramePushed(String filterName, Frame frame); 30 } 31 32 private Listener mListener; 33 34 FrameTargetFilter(MffContext context, String name) { 35 super(context, name); 36 } 37 38 @Override 39 public Signature getSignature() { 40 return new Signature() 41 .addInputPort("input", Signature.PORT_REQUIRED, FrameType.any()) 42 .disallowOtherPorts(); 43 } 44 45 public synchronized void setListener(Listener listener) { 46 mListener = listener; 47 } 48 49 @Override 50 protected synchronized void onProcess() { 51 Frame frame = getConnectedInputPort("input").pullFrame(); 52 if (mListener != null) { 53 frame.retain(); 54 mListener.onFramePushed(getName(), frame); 55 } 56 } 57 58 } 59