GstRtp.RTPBuffer

Fields

Name

Type

Access

Description

buffer

Gst.Buffer

r/w

pointer to RTP buffer

data

[object]

r/w

array of data

map

[Gst.MapInfo]

r/w

array of Gst.MapInfo

size

[int]

r/w

array of size

state

int

r/w

internal state

Methods

class

allocate_data (buffer, payload_len, pad_len, csrc_count)

class

calc_header_len (csrc_count)

class

calc_packet_len (payload_len, pad_len, csrc_count)

class

calc_payload_len (packet_len, pad_len, csrc_count)

class

compare_seqnum (seqnum1, seqnum2)

class

default_clock_rate (payload_type)

class

ext_timestamp (exttimestamp, timestamp)

class

get_extension_onebyte_header_from_bytes (bytes, bit_pattern, id, nth)

class

new_allocate (payload_len, pad_len, csrc_count)

class

new_allocate_len (packet_len, pad_len, csrc_count)

class

new_copy_data (data)

class

new_take_data (data)

add_extension_onebyte_header (id, data)

add_extension_twobytes_header (appbits, id, data)

get_csrc (idx)

get_csrc_count ()

get_extension ()

get_extension_data ()

get_extension_onebyte_header (id, nth)

get_extension_twobytes_header (id, nth)

get_header_len ()

get_marker ()

get_packet_len ()

get_padding ()

get_payload ()

get_payload_buffer ()

get_payload_len ()

get_payload_subbuffer (offset, len)

get_payload_type ()

get_seq ()

get_ssrc ()

get_timestamp ()

get_version ()

pad_to (len)

remove_extension_data ()

set_csrc (idx, csrc)

set_extension (extension)

set_extension_data (bits, length)

set_marker (marker)

set_packet_len (len)

set_padding (padding)

set_payload_type (payload_type)

set_seq (seq)

set_ssrc (ssrc)

set_timestamp (timestamp)

set_version (version)

unmap ()

Details

class GstRtp.RTPBuffer

The GstRtp.RTPBuffer helper functions makes it easy to parse and create regular Gst.Buffer objects that contain RTP payloads. These buffers are typically of ‘application/x-rtp’ Gst.Caps.

classmethod allocate_data(buffer, payload_len, pad_len, csrc_count)
Parameters:
  • buffer (Gst.Buffer) – a Gst.Buffer

  • payload_len (int) – the length of the payload

  • pad_len (int) – the amount of padding

  • csrc_count (int) – the number of CSRC entries

Allocate enough data in buffer to hold an RTP packet with csrc_count CSRCs, a payload length of payload_len and padding of pad_len. buffer must be writable and all previous memory in buffer will be freed. If pad_len is >0, the padding bit will be set. All other RTP header fields will be set to 0/False.

classmethod calc_header_len(csrc_count)
Parameters:

csrc_count (int) – the number of CSRC entries

Returns:

The length of an RTP header with csrc_count CSRC entries.

Return type:

int

Calculate the header length of an RTP packet with csrc_count CSRC entries. An RTP packet can have at most 15 CSRC entries.

classmethod calc_packet_len(payload_len, pad_len, csrc_count)
Parameters:
  • payload_len (int) – the length of the payload

  • pad_len (int) – the amount of padding

  • csrc_count (int) – the number of CSRC entries

Returns:

The total length of an RTP header with given parameters.

Return type:

int

Calculate the total length of an RTP packet with a payload size of payload_len, a padding of pad_len and a csrc_count CSRC entries.

classmethod calc_payload_len(packet_len, pad_len, csrc_count)
Parameters:
  • packet_len (int) – the length of the total RTP packet

  • pad_len (int) – the amount of padding

  • csrc_count (int) – the number of CSRC entries

Returns:

The length of the payload of an RTP packet with given parameters.

Return type:

int

Calculate the length of the payload of an RTP packet with size packet_len, a padding of pad_len and a csrc_count CSRC entries.

classmethod compare_seqnum(seqnum1, seqnum2)
Parameters:
  • seqnum1 (int) – a sequence number

  • seqnum2 (int) – a sequence number

Returns:

a negative value if seqnum1 is bigger than seqnum2, 0 if they are equal or a positive value if seqnum1 is smaller than segnum2.

Return type:

int

Compare two sequence numbers, taking care of wraparounds. This function returns the difference between seqnum1 and seqnum2.

classmethod default_clock_rate(payload_type)
Parameters:

payload_type (int) – the static payload type

Returns:

the default clock rate or -1 if the payload type is not static or the clock-rate is undefined.

Return type:

int

Get the default clock-rate for the static payload type payload_type.

classmethod ext_timestamp(exttimestamp, timestamp)
Parameters:
  • exttimestamp (int) – a previous extended timestamp

  • timestamp (int) – a new timestamp

Returns:

The extended timestamp of timestamp or 0 if the result can’t go anywhere backwards.

exttimestamp:

a previous extended timestamp

Return type:

(int, exttimestamp: int)

Update the exttimestamp field with the extended timestamp of timestamp For the first call of the method, exttimestamp should point to a location with a value of -1.

This function is able to handle both forward and backward timestamps taking into account:

  • timestamp wraparound making sure that the returned value is properly increased.

  • timestamp unwraparound making sure that the returned value is properly decreased.

classmethod get_extension_onebyte_header_from_bytes(bytes, bit_pattern, id, nth)
Parameters:
  • bytes (GLib.Bytes) – GLib.Bytes

  • bit_pattern (int) – The bit-pattern. Anything but 0xBEDE is rejected.

  • id (int) – The ID of the header extension to be read (between 1 and 14).

  • nth (int) – Read the nth extension packet with the requested ID

Returns:

True if bytes had the requested header extension

data:

location for data

Return type:

(bool, data: bytes)

Similar to GstRtp.RTPBuffer.get_extension_onebyte_header, but working on the GLib.Bytes you get from GstRtp.RTPBuffer.get_extension_data. Parses RFC 5285 style header extensions with a one byte header. It will return the nth extension with the requested id.

New in version 1.18.

classmethod new_allocate(payload_len, pad_len, csrc_count)
Parameters:
  • payload_len (int) – the length of the payload

  • pad_len (int) – the amount of padding

  • csrc_count (int) – the number of CSRC entries

Returns:

A newly allocated buffer that can hold an RTP packet with given parameters.

Return type:

Gst.Buffer

Allocate a new Gst.Buffer with enough data to hold an RTP packet with csrc_count CSRCs, a payload length of payload_len and padding of pad_len. All other RTP header fields will be set to 0/False.

classmethod new_allocate_len(packet_len, pad_len, csrc_count)
Parameters:
  • packet_len (int) – the total length of the packet

  • pad_len (int) – the amount of padding

  • csrc_count (int) – the number of CSRC entries

Returns:

A newly allocated buffer that can hold an RTP packet of packet_len.

Return type:

Gst.Buffer

Create a new Gst.Buffer that can hold an RTP packet that is exactly packet_len long. The length of the payload depends on pad_len and csrc_count and can be calculated with GstRtp.RTPBuffer.calc_payload_len(). All RTP header fields will be set to 0/False.

classmethod new_copy_data(data)
Parameters:

data (bytes) – data for the new buffer

Returns:

A newly allocated buffer with a copy of data and of size len.

Return type:

Gst.Buffer

Create a new buffer and set the data to a copy of len bytes of data and the size to len. The data will be freed when the buffer is freed.

classmethod new_take_data(data)
Parameters:

data (bytes) – data for the new buffer

Returns:

A newly allocated buffer with data and of size len.

Return type:

Gst.Buffer

Create a new buffer and set the data and size of the buffer to data and len respectively. data will be freed when the buffer is unreffed, so this function transfers ownership of data to the new buffer.

add_extension_onebyte_header(id, data)
Parameters:
  • id (int) – The ID of the header extension (between 1 and 14).

  • data (bytes) – location for data

Returns:

True if header extension could be added

Return type:

bool

Adds a RFC 5285 header extension with a one byte header to the end of the RTP header. If there is already a RFC 5285 header extension with a one byte header, the new extension will be appended. It will not work if there is already a header extension that does not follow the mechanism described in RFC 5285 or if there is a header extension with a two bytes header as described in RFC 5285. In that case, use GstRtp.RTPBuffer.add_extension_twobytes_header()

add_extension_twobytes_header(appbits, id, data)
Parameters:
  • appbits (int) – Application specific bits

  • id (int) – The ID of the header extension

  • data (bytes) – location for data

Returns:

True if header extension could be added

Return type:

bool

Adds a RFC 5285 header extension with a two bytes header to the end of the RTP header. If there is already a RFC 5285 header extension with a two bytes header, the new extension will be appended. It will not work if there is already a header extension that does not follow the mechanism described in RFC 5285 or if there is a header extension with a one byte header as described in RFC 5285. In that case, use GstRtp.RTPBuffer.add_extension_onebyte_header()

get_csrc(idx)
Parameters:

idx (int) – the index of the CSRC to get

Returns:

the CSRC at index idx in host order.

Return type:

int

Get the CSRC at index idx in buffer.

get_csrc_count()
Returns:

the CSRC count of buffer.

Return type:

int

Get the CSRC count of the RTP packet in buffer.

get_extension()
Returns:

True if buffer has the extension bit set.

Return type:

bool

Check if the extension bit is set on the RTP packet in buffer.

get_extension_data()
Returns:

A new GLib.Bytes if an extension header was present and None otherwise.

bits:

location for header bits

Return type:

(GLib.Bytes or None, bits: int)

Similar to GstRtp.RTPBuffer.get_extension_data, but more suitable for language bindings usage. bits will contain the extension 16 bits of custom data and the extension data (not including the extension header) is placed in a new GLib.Bytes structure.

If self did not contain an extension, this function will return None, with bits unchanged. If there is an extension header but no extension data then an empty GLib.Bytes will be returned.

New in version 1.2.

get_extension_onebyte_header(id, nth)
Parameters:
  • id (int) – The ID of the header extension to be read (between 1 and 14).

  • nth (int) – Read the nth extension packet with the requested ID

Returns:

True if buffer had the requested header extension

data:

location for data

Return type:

(bool, data: bytes)

Parses RFC 5285 style header extensions with a one byte header. It will return the nth extension with the requested id.

get_extension_twobytes_header(id, nth)
Parameters:
  • id (int) – The ID of the header extension to be read (between 1 and 14).

  • nth (int) – Read the nth extension packet with the requested ID

Returns:

True if buffer had the requested header extension

appbits:

Application specific bits

data:

location for data

Return type:

(bool, appbits: int, data: bytes)

Parses RFC 5285 style header extensions with a two bytes header. It will return the nth extension with the requested id.

get_header_len()
Returns:

The total length of the header in buffer.

Return type:

int

Return the total length of the header in buffer. This include the length of the fixed header, the CSRC list and the extension header.

get_marker()
Returns:

True if buffer has the marker bit set.

Return type:

bool

Check if the marker bit is set on the RTP packet in buffer.

get_packet_len()
Returns:

The total length of the packet in buffer.

Return type:

int

Return the total length of the packet in buffer.

get_padding()
Returns:

True if buffer has the padding bit set.

Return type:

bool

Check if the padding bit is set on the RTP packet in buffer.

get_payload()
Returns:

A new GLib.Bytes containing the payload data in self.

Return type:

GLib.Bytes or None

Similar to GstRtp.RTPBuffer.get_payload, but more suitable for language bindings usage. The return value is a pointer to a GLib.Bytes structure containing the payload data in self.

New in version 1.2.

get_payload_buffer()
Returns:

A new buffer with the data of the payload.

Return type:

Gst.Buffer

Create a buffer of the payload of the RTP packet in buffer. This function will internally create a subbuffer of buffer so that a memcpy can be avoided.

get_payload_len()
Returns:

The length of the payload in buffer.

Return type:

int

Get the length of the payload of the RTP packet in buffer.

get_payload_subbuffer(offset, len)
Parameters:
  • offset (int) – the offset in the payload

  • len (int) – the length in the payload

Returns:

A new buffer with the specified data of the payload.

Return type:

Gst.Buffer

Create a subbuffer of the payload of the RTP packet in buffer. offset bytes are skipped in the payload and the subbuffer will be of size len. If len is -1 the total payload starting from offset is subbuffered.

get_payload_type()
Returns:

The payload type.

Return type:

int

Get the payload type of the RTP packet in buffer.

get_seq()
Returns:

The sequence number in host order.

Return type:

int

Get the sequence number of the RTP packet in buffer.

get_ssrc()
Returns:

the SSRC of buffer in host order.

Return type:

int

Get the SSRC of the RTP packet in buffer.

get_timestamp()
Returns:

The timestamp in host order.

Return type:

int

Get the timestamp of the RTP packet in buffer.

get_version()
Returns:

The version of buffer.

Return type:

int

Get the version number of the RTP packet in buffer.

pad_to(len)
Parameters:

len (int) – the new amount of padding

Set the amount of padding in the RTP packet in buffer to len. If len is 0, the padding is removed.

NOTE: This function does not work correctly.

remove_extension_data()

Unsets the extension bit of the RTP buffer and removes the extension header and data.

If the RTP buffer has no header extension data, the action has no effect. The RTP buffer must be mapped READWRITE only once and the underlying Gst.Buffer must be writable.

New in version 1.20.

set_csrc(idx, csrc)
Parameters:
  • idx (int) – the CSRC index to set

  • csrc (int) – the CSRC in host order to set at idx

Modify the CSRC at index idx in buffer to csrc.

set_extension(extension)
Parameters:

extension (bool) – the new extension

Set the extension bit on the RTP packet in buffer to extension.

set_extension_data(bits, length)
Parameters:
  • bits (int) – the bits specific for the extension

  • length (int) – the length that counts the number of 32-bit words in the extension, excluding the extension header ( therefore zero is a valid length)

Returns:

True if done.

Return type:

bool

Set the extension bit of the rtp buffer and fill in the bits and length of the extension header. If the existing extension data is not large enough, it will be made larger.

Will also shorten the extension data from 1.20.

set_marker(marker)
Parameters:

marker (bool) – the new marker

Set the marker bit on the RTP packet in buffer to marker.

set_packet_len(len)
Parameters:

len (int) – the new packet length

Set the total self size to len. The data in the buffer will be made larger if needed. Any padding will be removed from the packet.

set_padding(padding)
Parameters:

padding (bool) – the new padding

Set the padding bit on the RTP packet in buffer to padding.

set_payload_type(payload_type)
Parameters:

payload_type (int) – the new type

Set the payload type of the RTP packet in buffer to payload_type.

set_seq(seq)
Parameters:

seq (int) – the new sequence number

Set the sequence number of the RTP packet in buffer to seq.

set_ssrc(ssrc)
Parameters:

ssrc (int) – the new SSRC

Set the SSRC on the RTP packet in buffer to ssrc.

set_timestamp(timestamp)
Parameters:

timestamp (int) – the new timestamp

Set the timestamp of the RTP packet in buffer to timestamp.

set_version(version)
Parameters:

version (int) – the new version

Set the version of the RTP packet in buffer to version.

unmap()

Unmap self previously mapped with GstRtp.RTPBuffer.map().