AVPKit
Buffer.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 BUFFER_H_
21 #define BUFFER_H_
22 
23 #include <com/avpkit/ferry/IBuffer.h>
24 
25 namespace com { namespace avpkit { namespace ferry
26 {
27 
28  class Buffer : public IBuffer
29  {
30  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(Buffer);
31  public:
32 
33  virtual void* getBytes(int32_t offset, int32_t length);
34  virtual int32_t getBufferSize();
35 
39  static VS_API_FERRY Buffer* make(RefCounted* requestor,
40  int32_t bufferSize);
41 
47  static VS_API_FERRY Buffer* make(RefCounted* requestor, void * bufToWrap, int32_t bufferSize,
48  FreeFunc freeFunc, void * closure);
49 
50  virtual Type getType();
51  virtual void setType(Type);
52  virtual int32_t getSize();
53 
54  static Buffer*
56  Type type, int32_t numElements, bool zero);
57 
58  static int32_t getTypeSize(Type type);
59  protected:
60  Buffer();
61  virtual ~Buffer();
62  private:
63  void* mBuffer;
64  FreeFunc mFreeFunc;
65  void* mClosure;
66  int32_t mBufferSize;
67  bool mInternallyAllocated;
68  Type mType;
69  static uint8_t mTypeSize[];
70  };
71 
72 }}}
73 
74 #endif /*BUFFER_H_*/
virtual void setType(Type)
Reset the buffer type to a new type.
Definition: Buffer.cpp:141
virtual void * getBytes(int32_t offset, int32_t length)
Returns up to length bytes, starting at offset in the underlying buffer we're managing.
Definition: Buffer.cpp:71
virtual Type getType()
Get the type this buffer was created as.
Definition: Buffer.cpp:135
virtual int32_t getBufferSize()
Get the current maximum number of bytes that can be safely placed in this buffer.
Definition: Buffer.cpp:85
virtual int32_t getSize()
Returns the size, in units of getType() of this buffer.
Definition: Buffer.cpp:175
static VS_API_FERRY Buffer * make(RefCounted *requestor, int32_t bufferSize)
Allocate a new buffer of at least bufferSize.
Definition: Buffer.cpp:91
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
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...