AVPKit
IBuffer.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef IBUFFER_H_
21 #define IBUFFER_H_
22 
23 #include <com/avpkit/ferry/Ferry.h>
24 #include <com/avpkit/ferry/RefCounted.h>
25 
26 namespace com
27 {
28 namespace avpkit
29 {
30 namespace ferry
31 {
32 
53 class VS_API_FERRY IBuffer : public com::avpkit::ferry::RefCounted
54 {
55 public:
56 #ifndef SWIG
57  typedef void
58  (*FreeFunc)(void * mem, void *closure);
59 
74  virtual void*
75  getBytes(int32_t offset, int32_t length)=0;
76 
90  static IBuffer*
91  make(RefCounted* requestor, void * bufToWrap, int32_t bufferSize,
92  FreeFunc freeFunc, void * closure);
93 
94 #endif // ! SWIG
101  virtual int32_t
103 
112  static IBuffer*
113  make(com::avpkit::ferry::RefCounted* requestor, int32_t bufferSize);
114 
115  /*
116  * Added for 3.1
117  */
118  typedef enum {
119  IBUFFER_UINT8,
120  IBUFFER_SINT8,
121  IBUFFER_UINT16,
122  IBUFFER_SINT16,
123  IBUFFER_UINT32,
124  IBUFFER_SINT32,
125  IBUFFER_UINT64,
126  IBUFFER_SINT64,
127  IBUFFER_FLT32,
128  IBUFFER_DBL64,
129  IBUFFER_NB,
130  } Type;
131 
141  virtual Type getType()=0;
142 
153  virtual void setType(Type type)=0;
154 
160  static int32_t getTypeSize(Type type);
161 
169  virtual int32_t getSize()=0;
170 
185  static IBuffer*
186  make(com::avpkit::ferry::RefCounted* requestor,
187  Type type, int32_t numElements, bool zero);
188 
189 
190 protected:
191  IBuffer();
192  virtual
193  ~IBuffer();
194 };
195 
196 }
197 }
198 }
199 
200 #endif /*IBUFFER_H_*/
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
virtual void setType(Type type)=0
Reset the buffer type to a new type.
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.
virtual int32_t getBufferSize()=0
Get the current maximum number of bytes that can be safely placed in this buffer.
virtual int32_t getSize()=0
Returns the size, in units of getType() of this buffer.
virtual Type getType()=0
Get the type this buffer was created as.
Parent of all Ferry objects – it mains reference counts in native code.
Definition: RefCounted.h:85
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...