Class IPacket
- java.lang.Object
-
- com.avpkit.ferry.RefCounted
-
- com.avpkit.core.IMediaData
-
- com.avpkit.core.IPacket
-
public class IPacket extends IMediaData
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 {IPacket}s
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}.
-
-
Field Summary
-
Fields inherited from class com.avpkit.core.IMediaData
DEFAULT_TIME_STAMP_FORMAT
-
Fields inherited from class com.avpkit.ferry.RefCounted
swigCMemOwn
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intallocateNewPayload(int payloadSize)Discard the current payload and allocate a new payload.IPacketcopyReference()Create a new IPacket object that is actually referring to the exact same underlying native object.booleanequals(java.lang.Object obj)Compares two values, returning true if the underlying objects in native code are the same object.static longgetCPtr(IPacket obj)Internal Only.longgetDts()Get the Decompression Time Stamp (DTS) for this packet.longgetDuration()Return the duration of this packet, in units of {#getTimeBase()}intgetFlags()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.intgetMaxSize()Get the maximum size (in bytes) of payload this packet can hold.longgetMyCPtr()Internal Only.longgetPosition()Return the position (in bytes) of this packet in the stream.longgetPts()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.
intgetSize()Get the size in bytes of the payload currently in this packet.intgetStreamIndex()Get the container-specific index for the stream this packet is
part of.inthashCode()Get a hashable value for this object.booleanisComplete()Is this packet complete.booleanisKeyPacket()Does this packet contain Key data? i.e.static IPacketmake()Allocate a new packet.static IPacketmake(int size)Allocate a new packet.static IPacketmake(IPacket packet, boolean copyData)Allocate a new packet wrapping the existing contents of
a passed in packet.static IPacketmake(IBuffer buffer)Allocate a new packet that wraps an existing IBuffer.
voidreset()Clear out any data in this packet, but leaves
the buffer available for reuse.voidsetComplete(boolean complete, int size)Set if this packet is complete, and what the total size of the data should be assumed to be.
voidsetDts(long aDts)Set a new Decompression Time Stamp (DTS) for this packet.voidsetDuration(long duration)Set the duration.voidsetFlags(int flags)Set any internal flags.
voidsetKeyPacket(boolean keyPacket)Set if this is a key packet.
voidsetPosition(long position)Set the position.voidsetPts(long aPts)Set a new Presentation Time Stamp (PTS) for this packet.
voidsetStreamIndex(int streamIndex)Set the stream index for this packet.
java.lang.StringtoString()info about this packet-
Methods inherited from class com.avpkit.core.IMediaData
delete, get, get, get, get, get, get, get, getByteBuffer, getByteBuffer, getCPtr, getData, getData_internal, getDataCached, getFormattedTimeStamp, getFormattedTimeStamp, getTimeBase, getTimeStamp, isKey, put, put, put, put, put, put, put, setData, setData_internal, setTimeBase, setTimeStamp
-
Methods inherited from class com.avpkit.ferry.RefCounted
acquire, getCPtr, getCurrentRefCount, getJavaRefCount, release
-
-
-
-
Method Detail
-
getCPtr
public static long getCPtr(IPacket obj)
Internal Only. Not part of public API. Get the raw value of the native object that obj is proxying for.- Parameters:
obj- The java proxy object for a native object.- Returns:
- The raw pointer obj is proxying for.
-
getMyCPtr
public long getMyCPtr()
Internal Only. Not part of public API. Get the raw value of the native object that we're proxying for.- Overrides:
getMyCPtrin classIMediaData- Returns:
- The raw pointer we're proxying for.
-
copyReference
public IPacket copyReference()
Create a new IPacket object that is actually referring to the exact same underlying native object.- Overrides:
copyReferencein classIMediaData- Returns:
- the new Java object.
-
equals
public boolean equals(java.lang.Object obj)
Compares two values, returning true if the underlying objects in native code are the same object. That means you can have two different Java objects, but when you do a comparison, you'll find out they are the EXACT same object.- Overrides:
equalsin classIMediaData- Returns:
- True if the underlying native object is the same. False otherwise.
-
hashCode
public int hashCode()
Get a hashable value for this object.- Overrides:
hashCodein classIMediaData- Returns:
- the hashable value.
-
toString
public java.lang.String toString()
info about this packet- Overrides:
toStringin classjava.lang.Object- Returns:
- information about this packet
-
reset
public void reset()
Clear out any data in this packet, but leaves
the buffer available for reuse.
-
isComplete
public boolean isComplete()
Is this packet complete.- Returns:
- Is this packet full and therefore has valid information.
-
getPts
public long getPts()
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.
-
setPts
public void setPts(long aPts)
Set a new Presentation Time Stamp (PTS) for this packet.
- Parameters:
aPts- a new PTS for this packet.
- See Also:
getPts()
-
getDts
public long getDts()
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).
-
setDts
public void setDts(long aDts)
Set a new Decompression Time Stamp (DTS) for this packet.- Parameters:
aDts- a new DTS for this packet.- See Also:
getDts()
-
getSize
public int getSize()
Get the size in bytes of the payload currently in this packet.- Overrides:
getSizein classIMediaData- Returns:
- Size (in bytes) of payload currently in packet.
-
getMaxSize
public int getMaxSize()
Get the maximum size (in bytes) of payload this packet can hold.- Returns:
- Get maximum size (in bytes) of payload this packet can hold.
-
getStreamIndex
public int getStreamIndex()
Get the container-specific index for the stream this packet is
part of.- Returns:
- Stream in container that this packet has data for.
-
getFlags
public int getFlags()
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.
-
isKeyPacket
public boolean isKeyPacket()
Does this packet contain Key data? i.e. data that needs no other
frames or samples to decode.- Returns:
- true if key; false otherwise.
-
getDuration
public long getDuration()
Return the duration of this packet, in units of {#getTimeBase()}- Returns:
- Duration of this packet, in same time-base as the PTS.
-
getPosition
public long getPosition()
Return the position (in bytes) of this packet in the stream.- Returns:
- The position of this packet in the stream, or -1 if
unknown.
-
allocateNewPayload
public int allocateNewPayload(int payloadSize)
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:
payloadSize- The (minimum) payloadSize of this packet in bytes.
- Returns:
- >= 0 if successful. < 0 if error.
-
make
public static IPacket make()
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.
-
make
public static IPacket make(IBuffer buffer)
Allocate a new packet that wraps an existing IBuffer.
- Parameters:
buffer- The IBuffer to wrap.- Returns:
- a new packet or null on error.
-
setKeyPacket
public void setKeyPacket(boolean keyPacket)
Set if this is a key packet.
- Parameters:
keyPacket- true for yes, false for no.
-
setFlags
public void setFlags(int flags)
Set any internal flags.
- Parameters:
flags- Flags to set
-
setComplete
public void setComplete(boolean complete, int size)
Set if this packet is complete, and what the total size of the data should be assumed to be.
- Parameters:
complete- True for complete, false for not.size- Size of data in packet.
-
setStreamIndex
public void setStreamIndex(int streamIndex)
Set the stream index for this packet.
- Parameters:
streamIndex- The stream index, as determined from the {IContainer} this packet will be written to.
-
setDuration
public void setDuration(long duration)
Set the duration.- Parameters:
duration- new duration- See Also:
getDuration()
-
setPosition
public void setPosition(long position)
Set the position.- Parameters:
position- new position- See Also:
getPosition()
-
make
public static IPacket make(IPacket packet, boolean copyData)
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:
packet- Packet to reuse buffer from and to
copy settings from.copyData- if 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.
-
make
public static IPacket make(int size)
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:
size- The maximum size, in bytes, of data you
want to put in this packet.
- Returns:
- a new packet, or null on error.
-
-