AVPKit
com::avpkit::core::IPacket Class Referenceabstract

Represents an encoded piece of data that can be placed in an IContainer for a given IStream of data. More...

#include <IPacket.h>

Inheritance diagram for com::avpkit::core::IPacket:
Collaboration diagram for com::avpkit::core::IPacket:

Public Member Functions

virtual void reset ()=0
 Clear out any data in this packet, but leaves the buffer available for reuse.
 
virtual bool isComplete ()=0
 Is this packet complete. More...
 
virtual int64_t getPts ()=0
 Get the Presentation Time Stamp (PTS) for this packet. More...
 
virtual void setPts (int64_t aPts)=0
 Set a new Presentation Time Stamp (PTS) for this packet. More...
 
virtual int64_t getDts ()=0
 Get the Decompression Time Stamp (DTS) for this packet. More...
 
virtual void setDts (int64_t aDts)=0
 Set a new Decompression Time Stamp (DTS) for this packet. More...
 
virtual int32_t getSize ()=0
 Get the size in bytes of the payload currently in this packet. More...
 
virtual int32_t getMaxSize ()=0
 Get the maximum size (in bytes) of payload this packet can hold. More...
 
virtual int32_t getStreamIndex ()=0
 Get the container-specific index for the stream this packet is part of. More...
 
virtual int32_t getFlags ()=0
 Get any flags set on this packet, as a 4-byte binary-ORed bit-mask. More...
 
virtual bool isKeyPacket ()=0
 Does this packet contain Key data? i.e. More...
 
virtual int64_t getDuration ()=0
 Return the duration of this packet, in units of getTimeBase(). More...
 
virtual int64_t getPosition ()=0
 Return the position (in bytes) of this packet in the stream. More...
 
virtual int32_t allocateNewPayload (int32_t payloadSize)=0
 Discard the current payload and allocate a new payload. More...
 
virtual void setKeyPacket (bool keyPacket)=0
 Set if this is a key packet. More...
 
virtual void setFlags (int32_t flags)=0
 Set any internal flags. More...
 
virtual void setComplete (bool complete, int32_t size)=0
 Set if this packet is complete, and what the total size of the data should be assumed to be. More...
 
virtual void setStreamIndex (int32_t streamIndex)=0
 Set the stream index for this packet. More...
 
virtual void setDuration (int64_t duration)=0
 Set the duration. More...
 
virtual void setPosition (int64_t position)=0
 Set the position. More...
 
- Public Member Functions inherited from com::avpkit::core::IMediaData
virtual int64_t getTimeStamp ()=0
 Get the time stamp of this object in getTimeBase() units. More...
 
virtual void setTimeStamp (int64_t aTimeStamp)=0
 Set the time stamp for this object in getTimeBase() units. More...
 
virtual IRationalgetTimeBase ()=0
 Get the time base that time stamps of this object are represented in. More...
 
virtual void setTimeBase (IRational *aBase)=0
 Set the time base that time stamps of this object are represented in. More...
 
virtual com::avpkit::ferry::IBuffergetData ()=0
 Get any underlying raw data available for this object. More...
 
virtual bool isKey ()=0
 Is this object a key object? i.e. More...
 
virtual void setData (com::avpkit::ferry::IBuffer *buffer)=0
 Sets the underlying buffer used by this object. 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 IPacketmake ()
 Allocate a new packet. More...
 
static IPacketmake (com::avpkit::ferry::IBuffer *buffer)
 Allocate a new packet that wraps an existing IBuffer. More...
 
static IPacketmake (IPacket *packet, bool copyData)
 Allocate a new packet wrapping the existing contents of a passed in packet. More...
 
static IPacketmake (int32_t size)
 Allocate a new packet. 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

Represents an encoded piece of data that can be placed in an IContainer for a given IStream of data.

You read this object out of IContainer objects when decoding, and pass to an IStreamCoder object to decode.

You pass this object to a IStreamCoder to encode data, and then pass to an IContainer object to write to a data source.

Lastly, the units of timestamps in an IPacket are determined by the IContainer it came from (or is going to). For example, FLV IPackets are always in milliseconds (1/1000 of a second). You cannot assume these timestamps are in any given timeunit without getting an IStream object and finding out what Time Base that stream operates in.

For convenience, the AVPKit API always uses Microseconds for raw data (IVideoPicture and IAudioSamples objects), and will convert to the right time stamp unit when decoding or encoding data (with an IStreamCoder) from or to an IContainer.

Definition at line 49 of file IPacket.h.

Member Function Documentation

◆ allocateNewPayload()

virtual int32_t com::avpkit::core::IPacket::allocateNewPayload ( int32_t  payloadSize)
pure virtual

Discard the current payload and allocate a new payload.

Note that if any people have access to the old payload using getData(), the memory will continue to be available to them until they release their hold of the IBuffer.

When requesting a packet size, the system may allocate a larger payloadSize.

Parameters
payloadSizeThe (minimum) payloadSize of this packet in bytes.
Returns
>= 0 if successful. < 0 if error.

Implemented in com::avpkit::core::Packet.

Referenced by make().

◆ getDts()

virtual int64_t com::avpkit::core::IPacket::getDts ( )
pure virtual

Get the Decompression Time Stamp (DTS) for this packet.

This is the time at which the payload for this packet should be decompressed, in units of getTimeBase(), relative to the start of stream.

Some media codecs can require packets from the "future" to be decompressed before earliest packets as an additional way to compress data. In general you don't need to worry about this, but if you're curious start reading about the difference between I-Frames, P-Frames and B-Frames (or Bi-Directional Frames). B-Frames can use information from future frames when compressed.

Returns
Get the Decompression Timestamp (i.e. when this was read relative to the start of reading packets).

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ getDuration()

virtual int64_t com::avpkit::core::IPacket::getDuration ( )
pure virtual

Return the duration of this packet, in units of getTimeBase().

Returns
Duration of this packet, in same time-base as the PTS.

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ getFlags()

virtual int32_t com::avpkit::core::IPacket::getFlags ( )
pure virtual

Get any flags set on this packet, as a 4-byte binary-ORed bit-mask.

This is access to raw FFMPEG flags, but it is easier to use the is* methods below.

Returns
Any flags on the packet.

Implemented in com::avpkit::core::Packet.

◆ getMaxSize()

virtual int32_t com::avpkit::core::IPacket::getMaxSize ( )
pure virtual

Get the maximum size (in bytes) of payload this packet can hold.

Returns
Get maximum size (in bytes) of payload this packet can hold.

Implemented in com::avpkit::core::Packet.

◆ getPosition()

virtual int64_t com::avpkit::core::IPacket::getPosition ( )
pure virtual

Return the position (in bytes) of this packet in the stream.

Returns
The position of this packet in the stream, or -1 if unknown.

Implemented in com::avpkit::core::Packet.

◆ getPts()

virtual int64_t com::avpkit::core::IPacket::getPts ( )
pure virtual

Get the Presentation Time Stamp (PTS) for this packet.

This is the time at which the payload for this packet should be presented to the user, in units of getTimeBase(), relative to the start of stream.

Returns
Get the Presentation Timestamp for this packet.

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ getSize()

virtual int32_t com::avpkit::core::IPacket::getSize ( )
pure virtual

Get the size in bytes of the payload currently in this packet.

Returns
Size (in bytes) of payload currently in packet.

Implements com::avpkit::core::IMediaData.

Implemented in com::avpkit::core::Packet.

◆ getStreamIndex()

virtual int32_t com::avpkit::core::IPacket::getStreamIndex ( )
pure virtual

Get the container-specific index for the stream this packet is part of.

Returns
Stream in container that this packet has data for.

Implemented in com::avpkit::core::Packet.

◆ isComplete()

virtual bool com::avpkit::core::IPacket::isComplete ( )
pure virtual

Is this packet complete.

Returns
Is this packet full and therefore has valid information.

Implemented in com::avpkit::core::Packet.

◆ isKeyPacket()

virtual bool com::avpkit::core::IPacket::isKeyPacket ( )
pure virtual

Does this packet contain Key data? i.e.

data that needs no other frames or samples to decode.

Returns
true if key; false otherwise.

Implemented in com::avpkit::core::Packet.

◆ make() [1/4]

IPacket * com::avpkit::core::IPacket::make ( )
static

Allocate a new packet.

Note that any buffers this packet needs will be lazily allocated (i.e. we won't actually grab all the memory until we need it).

Returns
a new packet, or null on error.

Definition at line 37 of file IPacket.cpp.

38  {
39  Global::init();
40  return Packet::make();
41  }
static void init()
Internal Only.
Definition: Global.cpp:157
static IPacket * make()
Allocate a new packet.
Definition: IPacket.cpp:37

References com::avpkit::core::Global::init().

Referenced by make().

◆ make() [2/4]

IPacket * com::avpkit::core::IPacket::make ( com::avpkit::ferry::IBuffer buffer)
static

Allocate a new packet that wraps an existing IBuffer.

Parameters
bufferThe IBuffer to wrap.
Returns
a new packet or null on error.

Definition at line 44 of file IPacket.cpp.

45  {
46  Global::init();
47  if (!buffer)
48  throw std::invalid_argument("no buffer");
49 
50  return Packet::make(buffer);
51  }

References com::avpkit::core::Global::init(), and make().

◆ make() [3/4]

IPacket * com::avpkit::core::IPacket::make ( int32_t  size)
static

Allocate a new packet.

Note that any buffers this packet needs will be lazily allocated (i.e. we won't actually grab all the memory until we need it).

Parameters
sizeThe maximum size, in bytes, of data you want to put in this packet.
Returns
a new packet, or null on error.

Definition at line 61 of file IPacket.cpp.

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  }

References allocateNewPayload(), and com::avpkit::core::Global::init().

◆ make() [4/4]

IPacket * com::avpkit::core::IPacket::make ( IPacket packet,
bool  copyData 
)
static

Allocate a new packet wrapping the existing contents of a passed in packet.

Callers can then modify getPts(), getDts() and other get/set methods without modifying the original packet.

Parameters
packetPacket to reuse buffer from and to copy settings from.
copyDataif true copy data from packet into our own buffer. If false, share the same data buffer that packet uses
Returns
a new packet or null on error.

Definition at line 54 of file IPacket.cpp.

55  {
56  Global::init();
57  return Packet::make(dynamic_cast<Packet*>(packet), copyData);
58  }

References com::avpkit::core::Global::init(), and make().

◆ setComplete()

virtual void com::avpkit::core::IPacket::setComplete ( bool  complete,
int32_t  size 
)
pure virtual

Set if this packet is complete, and what the total size of the data should be assumed to be.

Parameters
completeTrue for complete, false for not.
sizeSize of data in packet.

Implemented in com::avpkit::core::Packet.

◆ setDts()

virtual void com::avpkit::core::IPacket::setDts ( int64_t  aDts)
pure virtual

Set a new Decompression Time Stamp (DTS) for this packet.

Parameters
aDtsa new DTS for this packet.
See also
getDts()

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ setDuration()

virtual void com::avpkit::core::IPacket::setDuration ( int64_t  duration)
pure virtual

Set the duration.

Parameters
durationnew duration
See also
getDuration()

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ setFlags()

virtual void com::avpkit::core::IPacket::setFlags ( int32_t  flags)
pure virtual

Set any internal flags.

Parameters
flagsFlags to set

Implemented in com::avpkit::core::Packet.

◆ setKeyPacket()

virtual void com::avpkit::core::IPacket::setKeyPacket ( bool  keyPacket)
pure virtual

Set if this is a key packet.

Parameters
keyPackettrue for yes, false for no.

Implemented in com::avpkit::core::Packet.

◆ setPosition()

virtual void com::avpkit::core::IPacket::setPosition ( int64_t  position)
pure virtual

Set the position.

Parameters
positionnew position
See also
getPosition()

Implemented in com::avpkit::core::Packet.

◆ setPts()

virtual void com::avpkit::core::IPacket::setPts ( int64_t  aPts)
pure virtual

Set a new Presentation Time Stamp (PTS) for this packet.

Parameters
aPtsa new PTS for this packet.
See also
getPts()

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().

◆ setStreamIndex()

virtual void com::avpkit::core::IPacket::setStreamIndex ( int32_t  streamIndex)
pure virtual

Set the stream index for this packet.

Parameters
streamIndexThe stream index, as determined from the IContainer this packet will be written to.

Implemented in com::avpkit::core::Packet.

Referenced by com::avpkit::core::Stream::stampOutputPacket().


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