Package com.wowza.wms.amf
Class AMFPacket
- Object
-
- com.wowza.wms.amf.AMFPacket
-
public class AMFPacket extends Object
AMFPacket: data container for data being transferred to and from the server from the Flash client. AMFPacket is also used to store data read/written to/from an flv file.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addData(byte[] data, int offset, int size)
Add data to the packetint
addDataEx(byte[] srcData, int srcOffset, int destOffset, int srcBytes)
Add data to the packetstatic int
calcTotalPacketSize(int packetSize, int headerSize, int chunkSize, int amfNumber, boolean isLongTimecode)
Calculate the total packet size for given packet parametersAMFPacket
clone()
AMFPacket
clone(boolean doCopy)
boolean
containsExtraDataKey(String key)
Return true if extra data contains the keystatic AMFPacket
deserializePacket(byte[] buffer)
java.util.Map<String,IAMFPacketExtraData>
extraDataClone()
Deep copy the extra data and return as a Mapstatic java.util.Map<String,IAMFPacketExtraData>
extraDataClone(java.util.Map<String,IAMFPacketExtraData> extraData)
long
getAbsTimecode()
Get absolute timecode (milliseconds)byte[]
getData()
Get data as byte[]java.nio.ByteBuffer
getDataBuffer()
Get data as ByteBufferIAMFPacketExtraData
getExtraData(String key)
Get extra data valuejava.util.Set<String>
getExtraDataKeys()
Get a set of the extra data keysint
getFirstByte()
Get first byte of data (used to peek into packet)Object
getLock()
Get lock (mostly used for extra data access)int
getMissing()
Get the number of bytes remaining unfilled in the packetint
getSecondByte()
Get second byte of data (used to peek into packet)long
getSeq()
Get packet sequence number.int
getSize()
Get packet sizeint
getSrc()
Get stream id (0 if not stream data)long
getTimecode()
Get timecode (milliseconds) relative to the previous packet.int
getType()
Get content type IVHost.CONTENTTYPE_*boolean
isAudio()
Is this an audio packet IVHost.CONTENTTYPE_AUDIOboolean
isExtraData()
Returns true if this packet contains any extra databoolean
isVideo()
Is this an audio packet IVHost.CONTENTTYPE_VIDEOString
prettyPrint()
void
putAllExtraData(java.util.Map<String,IAMFPacketExtraData> entries)
Add extra data key value pairsIAMFPacketExtraData
putExtraData(String key, IAMFPacketExtraData value)
Add extra data valuebyte[]
serializePacket()
void
setAbsTimecode(long absTimecode)
Set absolute timecode (milliseconds)void
setDataBuffer(byte[] data)
Set the data buffer to a byte arrayvoid
setDataBuffer(java.nio.ByteBuffer data)
Set the data for this packetvoid
setSeq(long seq)
Set packet sequence.void
setSize(int size)
Set packet sizevoid
setSrc(int src)
Set stream id (0 if not stream data)void
setTimecode(long timecode)
Set timecode (milliseconds) relative,void
setTimecodes(long timecode, long absTimecode)
Set both relative and absolute timecode in one call (milliseconds)void
setType(int type)
Set content type IVHost.CONTENTTYPE_*String
toString()
Return object as formatted stringvoid
truncatePacket(int newSize)
-
-
-
Constructor Detail
-
AMFPacket
public AMFPacket()
Create new empty packet
-
AMFPacket
public AMFPacket(int type, int src, int size)
Create new packet with given values- Parameters:
type
- packet content type: IVHost.CONTENTTYPE_*src
- stream idsize
- packet size (bytes)
-
AMFPacket
public AMFPacket(int type, int src, byte[] data)
Create new packet with given values- Parameters:
type
- packet content type: IVHost.CONTENTTYPE_*src
- stream iddata
- data buffer
-
-
Method Detail
-
clone
public AMFPacket clone()
- Overrides:
clone
in classObject
-
clone
public AMFPacket clone(boolean doCopy)
-
getSize
public int getSize()
Get packet size- Returns:
- packet size
-
setSize
public void setSize(int size)
Set packet size- Parameters:
size
- packet size
-
truncatePacket
public void truncatePacket(int newSize)
-
getMissing
public int getMissing()
Get the number of bytes remaining unfilled in the packet- Returns:
- number of bytes unfilled in packet
-
setDataBuffer
public void setDataBuffer(java.nio.ByteBuffer data)
Set the data for this packet- Parameters:
data
- byte buffer that holds packet data
-
setDataBuffer
public void setDataBuffer(byte[] data)
Set the data buffer to a byte array- Parameters:
data
- data buffer byte array
-
addData
public int addData(byte[] data, int offset, int size)
Add data to the packet- Parameters:
data
- byte buffer with dataoffset
- offset in byte buffersize
- size of data- Returns:
- number of bytes unfilled in packet
-
getType
public int getType()
Get content type IVHost.CONTENTTYPE_*- Returns:
- content type
-
setType
public void setType(int type)
Set content type IVHost.CONTENTTYPE_*- Parameters:
type
- content type
-
getSrc
public int getSrc()
Get stream id (0 if not stream data)- Returns:
- stream id
-
setSrc
public void setSrc(int src)
Set stream id (0 if not stream data)- Parameters:
src
- stream id
-
toString
public String toString()
Return object as formatted string- Overrides:
toString
in classObject
-
getTimecode
public long getTimecode()
Get timecode (milliseconds) relative to the previous packet.- Returns:
- timecode (milliseconds)
-
setTimecodes
public void setTimecodes(long timecode, long absTimecode)
Set both relative and absolute timecode in one call (milliseconds)Note this time is relative to the previous packet.
- Parameters:
timecode
- relative timecode (milliseconds)absTimecode
- absolute timecode (milliseconds)
-
setTimecode
public void setTimecode(long timecode)
Set timecode (milliseconds) relative,Note this time is relative to the previous packet.
- Parameters:
timecode
- timecode (milliseconds)
-
getAbsTimecode
public long getAbsTimecode()
Get absolute timecode (milliseconds)- Returns:
- absolute timecode
-
setAbsTimecode
public void setAbsTimecode(long absTimecode)
Set absolute timecode (milliseconds)- Parameters:
absTimecode
- absolute timecode
-
getSeq
public long getSeq()
Get packet sequence number. Used for live streams to keep track of packet ordering.- Returns:
- packet sequence
-
setSeq
public void setSeq(long seq)
Set packet sequence. Used for live streams to keep track of packet ordering.- Parameters:
seq
- packet sequence
-
isAudio
public boolean isAudio()
Is this an audio packet IVHost.CONTENTTYPE_AUDIO- Returns:
- true if audio packet
-
isVideo
public boolean isVideo()
Is this an audio packet IVHost.CONTENTTYPE_VIDEO- Returns:
- true if video packet
-
getDataBuffer
public java.nio.ByteBuffer getDataBuffer()
Get data as ByteBuffer- Returns:
- data as ByteBuffer
-
getData
public byte[] getData()
Get data as byte[]- Returns:
- data as byte[] null if no data
-
getFirstByte
public int getFirstByte()
Get first byte of data (used to peek into packet)- Returns:
- first byte of data in packet
-
getSecondByte
public int getSecondByte()
Get second byte of data (used to peek into packet)- Returns:
- second byte of data in packet
-
calcTotalPacketSize
public static int calcTotalPacketSize(int packetSize, int headerSize, int chunkSize, int amfNumber, boolean isLongTimecode)
Calculate the total packet size for given packet parameters- Parameters:
packetSize
- data sizeheaderSize
- header sizechunkSize
- chunk sizeamfNumber
- amf numberisLongTimecode
- is long timecode- Returns:
- total bytes
-
addDataEx
public int addDataEx(byte[] srcData, int srcOffset, int destOffset, int srcBytes)
Add data to the packet- Parameters:
srcData
- - source byte buffer with datasrcOffset
- - start copying from source buffer at this offsetdestOffset
- - copy into destination buffer from this offsetsrcBytes
- - size of data to copy- Returns:
- number of bytes unfilled in packet
-
serializePacket
public byte[] serializePacket()
-
deserializePacket
public static AMFPacket deserializePacket(byte[] buffer)
-
getLock
public Object getLock()
Get lock (mostly used for extra data access)- Returns:
- lock
-
putExtraData
public IAMFPacketExtraData putExtraData(String key, IAMFPacketExtraData value)
Add extra data value- Parameters:
key
- keyvalue
- extra data- Returns:
- extra data currently at that key
-
putAllExtraData
public void putAllExtraData(java.util.Map<String,IAMFPacketExtraData> entries)
Add extra data key value pairs- Parameters:
entries
- extra data key value pairs
-
getExtraData
public IAMFPacketExtraData getExtraData(String key)
Get extra data value- Parameters:
key
- key- Returns:
- extra data value
-
getExtraDataKeys
public java.util.Set<String> getExtraDataKeys()
Get a set of the extra data keys- Returns:
- extra data keys
-
containsExtraDataKey
public boolean containsExtraDataKey(String key)
Return true if extra data contains the key- Parameters:
key
- key- Returns:
- true if extra data contains the key
-
isExtraData
public boolean isExtraData()
Returns true if this packet contains any extra data- Returns:
- true if this packet contains any extra data
-
extraDataClone
public static java.util.Map<String,IAMFPacketExtraData> extraDataClone(java.util.Map<String,IAMFPacketExtraData> extraData)
-
extraDataClone
public java.util.Map<String,IAMFPacketExtraData> extraDataClone()
Deep copy the extra data and return as a Map- Returns:
- deep copy of extra data
-
prettyPrint
public String prettyPrint()
-
-