AVPKit
IPacket.cpp
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 #include "IPacket.h"
21 #include "Global.h"
22 #include "Packet.h"
23 
24 namespace com { namespace avpkit { namespace core
25 {
26  using namespace com::avpkit::ferry;
27 
28  IPacket :: IPacket()
29  {
30  }
31 
32  IPacket :: ~IPacket()
33  {
34  }
35 
36  IPacket*
38  {
39  Global::init();
40  return Packet::make();
41  }
42 
43  IPacket*
45  {
46  Global::init();
47  if (!buffer)
48  throw std::invalid_argument("no buffer");
49 
50  return Packet::make(buffer);
51  }
52 
53  IPacket*
54  IPacket :: make(IPacket* packet, bool copyData)
55  {
56  Global::init();
57  return Packet::make(dynamic_cast<Packet*>(packet), copyData);
58  }
59 
60  IPacket*
61  IPacket :: make(int32_t size)
62  {
63  Global::init();
64  IPacket* retval = make();
65  if (retval) {
66  if (retval->allocateNewPayload(size) < 0)
67  VS_REF_RELEASE(retval);
68  }
69  return retval;
70  }
71 
72 }}}
static void init()
Internal Only.
Definition: Global.cpp:157
Represents an encoded piece of data that can be placed in an IContainer for a given IStream of data.
Definition: IPacket.h:50
static IPacket * make()
Allocate a new packet.
Definition: IPacket.cpp:37
virtual int32_t allocateNewPayload(int32_t payloadSize)=0
Discard the current payload and allocate a new payload.
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
This library contains routines used by AVPKit libraries for "ferry"ing Java objects to and from nativ...
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...