DVBCore  22.11.0
Open Source DVB Engine
Classes | Macros | Typedefs | Functions
rtp_queue.c File Reference

DVB-IPTV RTP queue manager. More...

#include <string.h>
#include "techtype.h"
#include "dbgfuncs.h"
#include "stbhwos.h"
#include "stbheap.h"
#include "rtp.h"
#include "rtp_queue.h"

Classes

struct  s_rtp_packet
 
struct  S_RTP_QUEUE
 
struct  s_rtcp_stats
 
struct  s_fec_packet
 
struct  s_fec_stream
 
struct  S_SEQ_ARRAY
 

Macros

#define MEDIA_ARRAY_BITS   11
 
#define MEDIA_ARRAY_SIZE   (1 << MEDIA_ARRAY_BITS)
 
#define FEC_ARRAY_SIZE   (1 << 7) /* TS 102 034 says unit should cater for FEC L <= 40, so size is > 3*L */
 
#define MEDIA_INDEX_MASK   (MEDIA_ARRAY_SIZE - 1)
 
#define FEC_INDEX_MASK   (FEC_ARRAY_SIZE - 1)
 
#define MIN_PACKET_COUNT   32
 
#define BLK_PACKET_COUNT   64
 
#define INVALID_BLOCK   0xFFFF
 
#define INVALID_FEC   0xFF
 
#define PAYLOAD_MPEG2_TS   33
 
#define PAYLOAD_FEC_PKT   96
 
#define RTCP_PT_SENDER_REPORT   200
 
#define RTCP_PT_RECEIVER_REPORT   201
 
#define RTCP_PT_SOURCE_DESCRIPTION   202
 
#define RTCP_PT_GOODBYE   203
 
#define READ_U32BIT(x)   (U32BIT)(((x)[0] << 24) + ((x)[1] << 16) + ((x)[2] << 8) + ((x)[3])); x += 4
 
#define FEC_LAYER_NONE   0
 
#define FEC_LAYER_BASE_1D   1
 
#define FEC_LAYER_BASE_2D   2
 
#define TIMESTAMP_TICS_PER_MSEC   90
 
#define QDBG(x)
 
#define QERR(x)
 

Typedefs

typedef struct s_rtp_packet S_RTP_PACKET
 
typedef struct s_rtcp_stats S_RTCP_STATS
 
typedef struct s_fec_packet S_FEC_PACKET
 
typedef struct s_fec_stream S_FEC_STREAM
 

Functions

void * RTPCreateSequencingArray (U32BIT fec_layer)
 Creates sequencing array for holding RTP packets as they arrive from the network. The sequence number for each RTP packet is used to find the position for the packet in this sequence queue. Therefore, RTP packets in this queue will be in the order that they were sent from the server. FEC processing will be used while the RTP packets remain in this queue. More...
 
void RTPDestroySequencingArray (void *handle)
 Destroy sequencing array created by RTPCreateSequencingArray, freeing all RTP packets still in the queue. More...
 
void * RTPCreatePlayoutQueue (U32BIT low_threshold, U32BIT high_threshold)
 Creates a queue for holding RTP packets. The queue has low and high thresholds and no packets can be removed from it initially until the time period is greater than or equal to the high threshold. If the queue time difference drops below the low threshold then removing packets from the queue will be paused until the level has returned to the high threshold value again. More...
 
void RTPDeletePlayoutQueue (void *queue_handle)
 Deletes a queue created by RTPCreatePlayoutQueue, freeing all RTP packets still on the queue. More...
 
void RTPConnectSeqArrayToPlayoutQueue (void *seq_array_hdl, void *queue_hdl)
 Connect sequencing array to a playout queue created by RTPCreatePlayoutQueue This will allow sequencing array to add to the playout queue. More...
 
void * RTPAllocateMedia (U8BIT **buffer, U16BIT data_size)
 Allocates an RTP packet structure including the buffer for the RTP packet. More...
 
void * RTPAllocateFEC (U8BIT **buffer, U16BIT buff_size)
 Allocates an FEC packet including the buffer for the RTP packet. More...
 
void RTPFreePkt (void *handle)
 Free an RTP packet allocated with RTPAllocateMedia or RTPAllocateFEC. More...
 
void RTPParseCntl (void *seq_array_hdl, U8BIT *buffer, U16BIT nbytes)
 Parse RTCP packet - Sender Report, Source Description or Goodbye packet. More...
 
BOOLEAN RTPInsertMedia (void *seq_array_hdl, void *rtp_packet_hdl, U16BIT buffer_bytes)
 Inserts the RTP data packet to the sequencing array as long as the packet has matching SSRC. The packet is inserted in the array in position according bottom 11 bits of sequence number. More...
 
BOOLEAN RTPInsertFec (void *seq_array_hdl, void *fec_packet_hdl, U16BIT buffer_len, BOOLEAN second_stream)
 Inserts the RTP packet to the sequencing array as long as the packet has matching SSRC. The packet is inserted in the array in position according bottom 11 bits of sequence number. More...
 
void * RTPRemoveQueueItem (void *queue_handle, S_ITEM_INFO *info)
 Removes next queue item, but the item isn't freed. The queue item is returned with info for buffer pointer, buffer size, timestamp and received clock time This function blocks until the minimum amount of data is present in the queue's buffer. More...
 
void RTPUnpauseQueue (void *queue_handle)
 Unpauses the queue even if the number of time difference is less than the low threshold. Note that if a call is made to RTPRemoveQueueItem after this function is called and the time difference is less than the low threshold then the queue will be paused again. More...
 

Detailed Description

DVB-IPTV RTP queue manager.

Date
July 2020

Function Documentation

void* RTPAllocateFEC ( U8BIT **  buffer,
U16BIT  buff_size 
)

Allocates an FEC packet including the buffer for the RTP packet.

Parameters
bufferWill contain the pointer to the buffer for RTP packet
data_sizeSize of RTP stream data packet (including RTP header)
Returns
Handle for the allocated FEC packet, NULL on failure
void* RTPAllocateMedia ( U8BIT **  buffer,
U16BIT  data_size 
)

Allocates an RTP packet structure including the buffer for the RTP packet.

Parameters
bufferWill contain the pointer to the buffer
data_sizeSize of RTP stream data packet (including RTP header)
Returns
Handle for the allocated data packet, NULL on failure
void RTPConnectSeqArrayToPlayoutQueue ( void *  seq_array_hdl,
void *  queue_hdl 
)

Connect sequencing array to a playout queue created by RTPCreatePlayoutQueue This will allow sequencing array to add to the playout queue.

Parameters
seq_array_hdlHandle of the sequencing array (from RTPCreateSequencingArray)
queue_hdlHandle of the queue returned by RTPCreatePlayoutQueue
void* RTPCreatePlayoutQueue ( U32BIT  low_threshold,
U32BIT  high_threshold 
)

Creates a queue for holding RTP packets. The queue has low and high thresholds and no packets can be removed from it initially until the time period is greater than or equal to the high threshold. If the queue time difference drops below the low threshold then removing packets from the queue will be paused until the level has returned to the high threshold value again.

Creates a queue for holding RTP packets. The queue has low and high thresholds and no packets can be removed from it initially until the time period is greater than or equal to the high threshold. If the queue time difference drops below the low threshold then removing packets from the queue will be paused until the level has returned to the high threshold value again. If the number of buffered bytes goes above the max buffer size, then the packet won't be added. If max_size is 0 then the queue size isn't limited and RTP packets will always be added.

Parameters
low_thresholdThreshold value that pauses removing items from the queue.
high_thresholdThreshold value that will cause the queue to be unpaused.
Returns
Queue handle, or NULL if queue can't be created
void* RTPCreateSequencingArray ( U32BIT  fec_layer)

Creates sequencing array for holding RTP packets as they arrive from the network. The sequence number for each RTP packet is used to find the position for the packet in this sequence queue. Therefore, RTP packets in this queue will be in the order that they were sent from the server. FEC processing will be used while the RTP packets remain in this queue.

Creates a sequence queue for holding RTP packets as they arrive from the network. The sequence number for each RTP packet is used to find the position for the packet in this sequence queue. Therefore, RTP packets in this queue will be in the order that they were sent from the server. FEC processing will be used while the RTP packets remain in this queue.

Returns
Queue handle, or NULL if queue can't be created
void RTPDeletePlayoutQueue ( void *  queue_handle)

Deletes a queue created by RTPCreatePlayoutQueue, freeing all RTP packets still on the queue.

Parameters
queue_handleHandle of the queue returned by RTPCreatePlayoutQueue
void RTPDestroySequencingArray ( void *  handle)

Destroy sequencing array created by RTPCreateSequencingArray, freeing all RTP packets still in the queue.

Destroys sequence queue created by RTPCreateSequencingArray, freeing all RTP packets still in the queue.

Parameters
handleHandle of the sequence queue
void RTPFreePkt ( void *  handle)

Free an RTP packet allocated with RTPAllocateMedia or RTPAllocateFEC.

Parameters
handleHandle of the packet to be freed
BOOLEAN RTPInsertFec ( void *  seq_array_hdl,
void *  fec_packet_hdl,
U16BIT  buffer_len,
BOOLEAN  second_stream 
)

Inserts the RTP packet to the sequencing array as long as the packet has matching SSRC. The packet is inserted in the array in position according bottom 11 bits of sequence number.

Parameters
seq_array_hdlHandle of the sequencing array
fec_packet_hdlHandle of the RTP packet
buffer_lenNumber of bytes in the buffer.
second_streamTRUE if this is packet from the second stream
Returns
TRUE if item is added to the array, FALSE otherwise
BOOLEAN RTPInsertMedia ( void *  seq_array_hdl,
void *  rtp_packet_hdl,
U16BIT  buffer_bytes 
)

Inserts the RTP data packet to the sequencing array as long as the packet has matching SSRC. The packet is inserted in the array in position according bottom 11 bits of sequence number.

Insert RTP media packet to the sequencing array as long as the packet has matching SSRC. The packet is inserted in the array in position according bottom 11 bits of sequence number.

Parameters
seq_array_hdlHandle of the sequencing array
rtp_packet_hdlHandle of the RTP packet
buffer_bytesNumber of bytes in the packet buffer.
Returns
TRUE if item is added to the array, FALSE otherwise
void RTPParseCntl ( void *  seq_array_hdl,
U8BIT *  buffer,
U16BIT  nbytes 
)

Parse RTCP packet - Sender Report, Source Description or Goodbye packet.

Parameters
seq_array_hdlHandle of the sequencing array
bufferPointer to the RTCP packet data
nbytesNumber of bytes in the packet buffer.
void* RTPRemoveQueueItem ( void *  queue_handle,
S_ITEM_INFO info 
)

Removes next queue item, but the item isn't freed. The queue item is returned with info for buffer pointer, buffer size, timestamp and received clock time This function blocks until the minimum amount of data is present in the queue's buffer.

Parameters
queue_handleHandle of the queue
infoPointer to packet info (with buffer, buffer size, timestamp and received clock time)
Returns
Handle of the queue item, or NULL if the queue is empty
void RTPUnpauseQueue ( void *  queue_handle)

Unpauses the queue even if the number of time difference is less than the low threshold. Note that if a call is made to RTPRemoveQueueItem after this function is called and the time difference is less than the low threshold then the queue will be paused again.

Parameters
queue_handleHandle of the queue to be unpaused