com.xuggle.xuggler

Class 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

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 Xuggler 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.xuggle.xuggler.IMediaData DEFAULT_TIME_STAMP_FORMAT

Fields inherited from class com.xuggle.ferry.RefCounted swigCMemOwn

Constructor Summary protected IPacket(long cPtr, boolean cMemoryOwn)

Internal Only. protected IPacket(long cPtr, boolean cMemoryOwn, AtomicLong ref)

Internal Only.

Method Summary int allocateNewPayload(int payloadSize)

Discard the current payload and allocate a new payload. IPacket copyReference()

Create a new IPacket object that is actually referring to the exact same underlying native object. boolean equals(Object obj)

Compares two values, returning true if the underlying objects in native code are the same object. long getConvergenceDuration()

Time difference in IStream.getTimeBase() units from the presentation time stamp of this packet to the point at which the output from the decoder has converged independent from the availability of previous frames. static long getCPtr(IPacket obj)

Internal Only. long getDts()

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

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

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

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

Internal Only. long getPosition()

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

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

Get the size in bytes of the payload currently in this packet. int getStreamIndex()

Get the container-specific index for the stream this packet is part of. int hashCode()

Get a hashable value for this object. boolean isComplete()

Is this packet complete. boolean isKeyPacket()

Does this packet contain Key data? i.e. static IPacket make()

Allocate a new packet. static IPacket make(IBuffer buffer)

Allocate a new packet that wraps an existing IBuffer. static IPacket make(int size)

Allocate a new packet. static IPacket make(IPacket packet, boolean copyData)

Allocate a new packet wrapping the existing contents of a passed in packet. void reset()

Clear out any data in this packet, but leaves the buffer available for reuse. 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. void setConvergenceDuration(long duration)

Set the convergence duration. void setDts(long aDts)

Set a new Decompression Time Stamp (DTS) for this packet. void setDuration(long duration)

Set the duration. void setFlags(int flags)

Set any internal flags. void setKeyPacket(boolean keyPacket)

Set if this is a key packet. void setPosition(long position)

Set the position. void setPts(long aPts)

Set a new Presentation Time Stamp (PTS) for this packet. void setStreamIndex(int streamIndex)

Set the stream index for this packet. String toString()

info about this packet

Methods inherited from class com.xuggle.xuggler.IMediaData delete, get, get, get, get, get, get, get, getByteBuffer, getByteBuffer, getCPtr, getData_internal, getData, getDataCached, getFormattedTimeStamp, getFormattedTimeStamp, getTimeBase, getTimeStamp, isKey, put, put, put, put, put, put, put, setData_internal, setData, setTimeBase, setTimeStamp

Methods inherited from class com.xuggle.ferry.RefCounted acquire, getCPtr, getCurrentRefCount, getJavaRefCount, release

Methods inherited from class java.lang.Object clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructor Detail

IPacket

protected IPacket(long cPtr, boolean cMemoryOwn)

Internal Only.

IPacket

protected IPacket(long cPtr, boolean cMemoryOwn, AtomicLong ref)

Internal Only.

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: getMyCPtr in class IMediaData 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: copyReference in class IMediaData Returns: the new Java object.

equals

public boolean equals(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: equals in class IMediaData Returns: True if the underlying native object is the same. False otherwise.

hashCode

public int hashCode()

Get a hashable value for this object. Overrides: hashCode in class IMediaData Returns: the hashable value.

toString

public String toString()

info about this packet Overrides: toString in class 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 IMediaData.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 IMediaData.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: getSize in class IMediaData 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 IMediaData.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()

getConvergenceDuration

public long getConvergenceDuration()

Time difference in IStream.getTimeBase() units from the presentation time stamp of this packet to the point at which the output from the decoder has converged independent from the availability of previous frames. That is, the frames are virtually identical no matter if decoding started from the very first frame or from this keyframe. Is Global.NO_PTS if unknown. This field is not the display duration of the current packet. The purpose of this field is to allow seeking in streams that have no keyframes in the conventional sense. It corresponds to the recovery point SEI in H.264 and match_time_delta in NUT. It is also subtitles are correctly displayed after seeking. If you didn't follow that, try drinking one to two glasses of Absinthe. It won't help, but it'll be more fun. Returns: the convergence duration

setConvergenceDuration

public void setConvergenceDuration(long duration)

Set the convergence duration. Parameters: duration - the new duration

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)