FileDocCategorySizeDatePackage
NativeBuffer.javaAPI DocAndroid 5.1 API3589Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

NativeBuffer

public class NativeBuffer extends Object
hide

Fields Summary
private long
mDataPointer
private int
mSize
private android.filterfw.core.Frame
mAttachedFrame
private boolean
mOwnsData
private int
mRefCount
Constructors Summary
public NativeBuffer()


      
    
public NativeBuffer(int count)

        allocate(count * getElementSize());
        mOwnsData = true;
    
Methods Summary
private native booleanallocate(int size)

protected voidassertReadable()

        if (mDataPointer == 0 || mSize == 0
        || (mAttachedFrame != null && !mAttachedFrame.hasNativeAllocation())) {
            throw new NullPointerException("Attempting to read from null data frame!");
        }
    
protected voidassertWritable()

        if (isReadOnly()) {
            throw new RuntimeException("Attempting to modify read-only native (structured) data!");
        }
    
voidattachToFrame(android.filterfw.core.Frame frame)

        System.loadLibrary("filterfw");
    
        // We do not auto-retain. We expect the user to call retain() if they want to hold on to
        // the frame.
        mAttachedFrame = frame;
    
public intcount()

        return (mDataPointer != 0) ? mSize / getElementSize() : 0;
    
private native booleandeallocate(boolean ownsData)

public intgetElementSize()

        return 1;
    
public booleanisReadOnly()

        return (mAttachedFrame != null) ? mAttachedFrame.isReadOnly() : false;
    
public android.filterfw.core.NativeBuffermutableCopy()

        NativeBuffer result = null;
        try {
            Class myClass = getClass();
            result = (NativeBuffer)myClass.newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Unable to allocate a copy of " + getClass() + "! Make " +
                                       "sure the class has a default constructor!");
        }
        if (mSize > 0 && !nativeCopyTo(result)) {
            throw new RuntimeException("Failed to copy NativeBuffer to mutable instance!");
        }
        return result;
    
private native booleannativeCopyTo(android.filterfw.core.NativeBuffer buffer)

public android.filterfw.core.NativeBufferrelease()

        // Decrement refcount
        boolean doDealloc = false;
        if (mAttachedFrame != null) {
            doDealloc = (mAttachedFrame.release() == null);
        } else if (mOwnsData) {
            --mRefCount;
            doDealloc = (mRefCount == 0);
        }

        // Deallocate if necessary
        if (doDealloc) {
            deallocate(mOwnsData);
            return null;
        } else {
            return this;
        }
    
public android.filterfw.core.NativeBufferretain()

        if (mAttachedFrame != null) {
            mAttachedFrame.retain();
        } else if (mOwnsData) {
            ++mRefCount;
        }
        return this;
    
public intsize()

        return mSize;