AVPKit
com::avpkit::ferry::IBuffer Class Referenceabstract

Allows Java code to get data from a native buffers, and optionally modify native memory directly. More...

#include <IBuffer.h>

Inheritance diagram for com::avpkit::ferry::IBuffer:
Collaboration diagram for com::avpkit::ferry::IBuffer:

Public Types

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)
 

Public Member Functions

virtual void * getBytes (int32_t offset, int32_t length)=0
 Returns up to length bytes, starting at offset in the underlying buffer we're managing. More...
 
virtual int32_t getBufferSize ()=0
 Get the current maximum number of bytes that can be safely placed in this buffer. More...
 
virtual Type getType ()=0
 Get the type this buffer was created as. More...
 
virtual void setType (Type type)=0
 Reset the buffer type to a new type. More...
 
virtual int32_t getSize ()=0
 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 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

- 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

Allows Java code to get data from a native buffers, and optionally modify native memory directly.

When accessing from Java, you can copy in and out ranges of buffers. You can do this by-copy (which is safer but a little slower) or by-reference where you directly access underlying C++/native memory from Java. Take special care if you decide that native access is required.

When accessing from C++, you get direct access to the underlying buffer.

To make an IBuffer object that is not a AVPKit internal object, pass in null for the RefCounted parameter.

Definition at line 53 of file IBuffer.h.

Member Function Documentation

◆ getBufferSize()

virtual int32_t com::avpkit::ferry::IBuffer::getBufferSize ( )
pure virtual

◆ getBytes()

virtual void* com::avpkit::ferry::IBuffer::getBytes ( int32_t  offset,
int32_t  length 
)
pure 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.

Implemented in com::avpkit::ferry::Buffer.

Referenced by com::avpkit::core::VideoPicture::copy(), com::avpkit::core::VideoPicture::copyAVFrame(), com::avpkit::core::Container::createSDPData(), com::avpkit::core::VideoPicture::fillAVFrame(), com::avpkit::core::StreamCoder::getExtraData(), com::avpkit::core::VideoPicture::make(), and com::avpkit::core::StreamCoder::setExtraData().

◆ getSize()

virtual int32_t com::avpkit::ferry::IBuffer::getSize ( )
pure virtual

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

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

Implemented in com::avpkit::ferry::Buffer.

◆ getType()

virtual Type com::avpkit::ferry::IBuffer::getType ( )
pure 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

Implemented in com::avpkit::ferry::Buffer.

◆ getTypeSize()

int32_t com::avpkit::ferry::IBuffer::getTypeSize ( Type  type)
static

Returns the size, in bytes, of elements of given Type.

Returns
the size in bytes.

Definition at line 65 of file IBuffer.cpp.

66  {
67  return Buffer::getTypeSize(type);
68  }

◆ make() [1/3]

IBuffer * com::avpkit::ferry::IBuffer::make ( com::avpkit::ferry::RefCounted requestor,
int32_t  bufferSize 
)
static

Allocate a new buffer of at least bufferSize.

Parameters
requestorAn optional value telling the IBuffer class what object requested it. This is used for debugging memory leaks; it's a marker for the FERRY object (e.g. IPacket) that actually requested the buffer. If you're not an FERRY object, pass in null here.
bufferSizeThe minimum buffer size you're requesting in bytes; a buffer with a larger size may be returned.
Returns
A new buffer, or null on error.

Definition at line 42 of file IBuffer.cpp.

43  {
44  return Buffer::make(requestor, bufferSize);
45  }
static VS_API_FERRY Buffer * make(RefCounted *requestor, int32_t bufferSize)
Allocate a new buffer of at least bufferSize.
Definition: Buffer.cpp:91

References com::avpkit::ferry::Buffer::make().

◆ make() [2/3]

IBuffer * com::avpkit::ferry::IBuffer::make ( com::avpkit::ferry::RefCounted requestor,
Type  type,
int32_t  numElements,
bool  zero 
)
static

Allocate a new buffer of at least bufferSize.

Parameters
requestorAn optional value telling the IBuffer class what object requested it. This is used for debugging memory leaks; it's a marker for the FERRY object (e.g. IPacket) that actually requested the buffer. If you're not an FERRY object, pass in null here.
typeThe type of buffer.
numElementsThe minimum number of elements of the specified type you will put in this buffer.
zeroIf true, we will guarantee the buffer contains only zeros. If false, we will not (it is faster to not, but then the buffer will have garbage-data in it).
Returns
A new buffer, or null on error.

Definition at line 58 of file IBuffer.cpp.

60  {
61  return Buffer::make(requestor, type, numElements, zero);
62  }

References com::avpkit::ferry::Buffer::make().

◆ make() [3/3]

IBuffer * com::avpkit::ferry::IBuffer::make ( RefCounted requestor,
void *  bufToWrap,
int32_t  bufferSize,
FreeFunc  freeFunc,
void *  closure 
)
static

Allocate a new buffer by wrapping a native buffer.

To make an IBuffer object that is not a AVPKit internal object, pass in null for the requestor parameter.

Parameters
requestorAn optional value telling the IBuffer class what object requested it. This is used for debugging memory leaks; it's a marker for the FERRY object (e.g. IPacket) that actually requested the buffer. If you're not an FERRY object, pass in null here.
bufToWrapBuffer to wrap
bufferSizeThe minimum buffer size you're requesting in bytes; a buffer with a larger size may be returned.
freeFuncA function that will be called when we decide to free the buffer
closureA value that will be passed, along with this, to freeFunc
Returns
A new buffer, or null on error.

Definition at line 48 of file IBuffer.cpp.

52  {
53  return Buffer::make(requestor, bufToWrap, bufferSize, freeFunc, closure);
54  }

References com::avpkit::ferry::Buffer::make().

◆ setType()

virtual void com::avpkit::ferry::IBuffer::setType ( Type  type)
pure 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.

Implemented in com::avpkit::ferry::Buffer.


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