FileDocCategorySizeDatePackage
ThroughputFilter.javaAPI DocAndroid 5.1 API3166Thu Mar 12 22:22:30 GMT 2015android.filterpacks.performance

ThroughputFilter

public class ThroughputFilter extends android.filterfw.core.Filter
hide

Fields Summary
private int
mPeriod
private long
mLastTime
private int
mTotalFrameCount
private int
mPeriodFrameCount
private android.filterfw.core.FrameFormat
mOutputFormat
Constructors Summary
public ThroughputFilter(String name)


       
        super(name);
    
Methods Summary
public android.filterfw.core.FrameFormatgetOutputFormat(java.lang.String portName, android.filterfw.core.FrameFormat inputFormat)

        return inputFormat;
    
public voidopen(android.filterfw.core.FilterContext env)

        mTotalFrameCount = 0;
        mPeriodFrameCount = 0;
        mLastTime = 0;
    
public voidprocess(android.filterfw.core.FilterContext context)

        // Pass through input frame
        Frame input = pullInput("frame");
        pushOutput("frame", input);

        // Update stats
        ++mTotalFrameCount;
        ++mPeriodFrameCount;

        // Check clock
        if (mLastTime == 0) {
            mLastTime = SystemClock.elapsedRealtime();
        }
        long curTime = SystemClock.elapsedRealtime();

        // Output throughput info if time period is up
        if ((curTime - mLastTime) >= (mPeriod * 1000)) {
            FrameFormat inputFormat = input.getFormat();
            int pixelCount = inputFormat.getWidth() * inputFormat.getHeight();
            Throughput throughput = new Throughput(mTotalFrameCount,
                                                   mPeriodFrameCount,
                                                   mPeriod,
                                                   pixelCount);
            Frame throughputFrame = context.getFrameManager().newFrame(mOutputFormat);
            throughputFrame.setObjectValue(throughput);
            pushOutput("throughput", throughputFrame);
            mLastTime = curTime;
            mPeriodFrameCount = 0;
        }
    
public voidsetupPorts()

        // Add input ports
        addInputPort("frame");

        // Add output ports
        mOutputFormat = ObjectFormat.fromClass(Throughput.class, FrameFormat.TARGET_SIMPLE);
        addOutputBasedOnInput("frame", "frame");
        addOutputPort("throughput", mOutputFormat);