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.

  • Constructor Details

    • 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 id
      size - 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 id
      data - data buffer
  • Method Details

    • clone

      public AMFPacket clone()
      Overrides:
      clone in class Object
    • 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(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 data
      offset - offset in byte buffer
      size - 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 class Object
    • 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 ByteBuffer getDataBuffer()
      Get data as ByteBuffer
      Returns:
      data as ByteBuffer
    • getData

      public byte[] getData()
      The packet's bytes. NOT necessarily a bounded view of them: when the packet is backed by a ByteBuffer this returns that buffer's whole backing array, which can be longer than the packet, and it ignores arrayOffset() entirely - so for a sliced buffer the packet's bytes would not even start at index 0. Callers must therefore treat getSize() as the authoritative length, not the array length. Packets built through the constructors allocate an exact array so the two agree, and no caller in this tree currently passes a sliced buffer to setDataBuffer, which is why the offset case has never bitten. It is left as-is deliberately: with ~459 call sites, some of which mutate the returned array in place and depend on it being the live buffer, returning a bounded copy here would silently change behaviour for all of them. Bound at the call site.
    • 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 size
      headerSize - header size
      chunkSize - chunk size
      amfNumber - amf number
      isLongTimecode - 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 data
      srcOffset - - start copying from source buffer at this offset
      destOffset - - copy into destination buffer from this offset
      srcBytes - - 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 - key
      value - extra data
      Returns:
      extra data currently at that key
    • putAllExtraData

      public void putAllExtraData(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 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 Map<String,IAMFPacketExtraData> extraDataClone(Map<String,IAMFPacketExtraData> extraData)
    • extraDataClone

      public Map<String,IAMFPacketExtraData> extraDataClone()
      Deep copy the extra data and return as a Map
      Returns:
      deep copy of extra data
    • prettyPrint

      public String prettyPrint()