1 // Copyright 2012 Google Inc. All Rights Reserved. 2 3 package androidx.media.filterpacks.base; 4 5 import androidx.media.filterfw.Filter; 6 import androidx.media.filterfw.Frame; 7 import androidx.media.filterfw.FrameType; 8 import androidx.media.filterfw.MffContext; 9 import androidx.media.filterfw.Signature; 10 11 public class GraphOutputTarget extends Filter { 12 13 private Frame mFrame = null; 14 private FrameType mType = FrameType.any(); 15 16 public GraphOutputTarget(MffContext context, String name) { 17 super(context, name); 18 } 19 20 // TODO: During initialization only? 21 public void setType(FrameType type) { 22 mType = type; 23 } 24 25 public FrameType getType() { 26 return mType; 27 } 28 29 @Override 30 public Signature getSignature() { 31 return new Signature() 32 .addInputPort("frame", Signature.PORT_REQUIRED, mType) 33 .disallowOtherInputs(); 34 } 35 36 // Returns a retained frame! 37 public Frame pullFrame() { 38 Frame result = null; 39 if (mFrame != null) { 40 result = mFrame; 41 mFrame = null; 42 } 43 return result; 44 } 45 46 @Override 47 protected void onProcess() { 48 Frame frame = getConnectedInputPort("frame").pullFrame(); 49 if (mFrame != null) { 50 mFrame.release(); 51 } 52 mFrame = frame.retain(); 53 } 54 55 @Override 56 protected boolean canSchedule() { 57 return super.canSchedule() && mFrame == null; 58 } 59 60 } 61