AVPKit
com::avpkit::ferry::Buffer Class Reference
Inheritance diagram for com::avpkit::ferry::Buffer:
Collaboration diagram for com::avpkit::ferry::Buffer:

Public Member Functions

virtual void * getBytes (int32_t offset, int32_t length)
 Returns up to length bytes, starting at offset in the underlying buffer we're managing. More...
 
virtual int32_t getBufferSize ()
 Get the current maximum number of bytes that can be safely placed in this buffer. More...
 
virtual Type getType ()
 Get the type this buffer was created as. More...
 
virtual void setType (Type)
 Reset the buffer type to a new type. More...
 
virtual int32_t getSize ()
 Returns the size, in units of getType() of this buffer. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static VS_API_FERRY Buffermake (RefCounted *requestor, int32_t bufferSize)
 Allocate a new buffer of at least bufferSize.
 
static VS_API_FERRY Buffermake (RefCounted *requestor, void *bufToWrap, int32_t bufferSize, FreeFunc freeFunc, void *closure)
 Create an iBuffer that wraps the given buffer, and calls FreeFunc(buffer, closure) on it when we believe it's safe to destruct it.
 
static Buffermake (com::avpkit::ferry::RefCounted *requestor, Type type, int32_t numElements, bool zero)
 
static int32_t getTypeSize (Type type)
 
- Static Public Member Functions inherited from com::avpkit::ferry::IBuffer
static IBuffermake (RefCounted *requestor, void *bufToWrap, int32_t bufferSize, FreeFunc freeFunc, void *closure)
 Allocate a new buffer by wrapping a native buffer. More...
 
static IBuffermake (com::avpkit::ferry::RefCounted *requestor, int32_t bufferSize)
 Allocate a new buffer of at least bufferSize. More...
 
static int32_t getTypeSize (Type type)
 Returns the size, in bytes, of elements of given Type. More...
 
static IBuffermake (com::avpkit::ferry::RefCounted *requestor, Type type, int32_t numElements, bool zero)
 Allocate a new buffer of at least bufferSize. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::ferry::IBuffer
enum  Type {
  IBUFFER_UINT8 , IBUFFER_SINT8 , IBUFFER_UINT16 , IBUFFER_SINT16 ,
  IBUFFER_UINT32 , IBUFFER_SINT32 , IBUFFER_UINT64 , IBUFFER_SINT64 ,
  IBUFFER_FLT32 , IBUFFER_DBL64 , IBUFFER_NB
}
 
typedef void(* FreeFunc) (void *mem, void *closure)
 
- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

Definition at line 28 of file Buffer.h.

Member Function Documentation

◆ getBufferSize()

int32_t com::avpkit::ferry::Buffer::getBufferSize ( )
virtual

Get the current maximum number of bytes that can be safely placed in this buffer.

Returns
Maximum number of bytes this buffer can manage.

Implements com::avpkit::ferry::IBuffer.

Definition at line 85 of file Buffer.cpp.

86  {
87  return mBufferSize;
88  }

◆ getBytes()

void * com::avpkit::ferry::Buffer::getBytes ( int32_t  offset,
int32_t  length 
)
virtual

Returns up to length bytes, starting at offset in the underlying buffer we're managing.

Note that with this method you are accessing the direct memory, so be careful.

Parameters
offsetThe offset (in bytes) into the buffer managed by this IBuffer
lengthThe requested length (in bytes) you want to access. The buffer returned may actually be longer than length.
Returns
A pointer to the direct buffer, or 0 if the offset or length would not fit within the buffer we're managing.

Implements com::avpkit::ferry::IBuffer.

Definition at line 71 of file Buffer.cpp.

72  {
73  void* retval = 0;
74 
75  if (length == 0)
76  length = mBufferSize - offset;
77 
78  if ((length > 0) && (length + offset <= mBufferSize))
79  retval = ((unsigned char*) mBuffer)+offset;
80 
81  return retval;
82  }

◆ getSize()

int32_t com::avpkit::ferry::Buffer::getSize ( )
virtual

Returns the size, in units of getType() of this buffer.

Returns
number of items of type getType() that will fit in this buffer.

Implements com::avpkit::ferry::IBuffer.

Definition at line 175 of file Buffer.cpp.

176  {
177  if (mType < 0 || mType >= IBUFFER_NB)
178  return 0;
179  return getBufferSize()/mTypeSize[(int32_t)mType];
180  }
virtual int32_t getBufferSize()
Get the current maximum number of bytes that can be safely placed in this buffer.
Definition: Buffer.cpp:85

◆ getType()

IBuffer::Type com::avpkit::ferry::Buffer::getType ( )
virtual

Get the type this buffer was created as.

A type is really just a hint. Like objects, IBuffer objects can be cast to and from any type.

Returns
the type

Implements com::avpkit::ferry::IBuffer.

Definition at line 135 of file Buffer.cpp.

136  {
137  return mType;
138  }

◆ setType()

void com::avpkit::ferry::Buffer::setType ( Type  type)
virtual

Reset the buffer type to a new type.

This method does not do any data conversion, it just changes the reported type (so changing from Type#IBUFFER_UINT8 to Type#IBUFFER_SINT16 is really just a "cast" operation).

Parameters
typethe type to set to.

Implements com::avpkit::ferry::IBuffer.

Definition at line 141 of file Buffer.cpp.

142  {
143  mType = type;
144  }

The documentation for this class was generated from the following files: