1/* 2 * Copyright 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// Takes in an array, returns the size of the array 17 18package androidx.media.filterfw.samples.simplecamera; 19 20import android.util.Log; 21import androidx.media.filterfw.Filter; 22import androidx.media.filterfw.FrameType; 23import androidx.media.filterfw.FrameValue; 24import androidx.media.filterfw.MffContext; 25import androidx.media.filterfw.OutputPort; 26import androidx.media.filterfw.Signature; 27 28import java.lang.reflect.Array; 29import java.util.Arrays; 30 31public class FloatArrayToStrFilter extends Filter { 32 33 private static final String TAG = "FloatArrayToStrFilter"; 34 private static boolean mLogVerbose = Log.isLoggable(TAG, Log.VERBOSE); 35 36 /** 37 * @param context 38 * @param name 39 */ 40 public FloatArrayToStrFilter(MffContext context, String name) { 41 super(context, name); 42 } 43 44 @Override 45 public Signature getSignature() { 46 FrameType floatType = FrameType.array(float.class); 47 48 return new Signature() 49 .addInputPort("array", Signature.PORT_REQUIRED, floatType) 50 .addOutputPort("string", Signature.PORT_REQUIRED, FrameType.single(String.class)) 51 .disallowOtherPorts(); 52 } 53 54 /** 55 * @see androidx.media.filterfw.Filter#onProcess() 56 */ 57 @Override 58 protected void onProcess() { 59 FrameValue arrayFrame = getConnectedInputPort("array").pullFrame().asFrameValues(); 60 float[] array = (float[]) arrayFrame.getValue(); 61 String outstr = Arrays.toString(array); 62 63 OutputPort outPort = getConnectedOutputPort("string"); 64 FrameValue stringFrame = outPort.fetchAvailableFrame(null).asFrameValue(); 65 stringFrame.setValue(outstr); 66 outPort.pushFrame(stringFrame); 67 68 } 69} 70