common: Separate setting the ring buffer size from socket buffer

Gives user more control over internals of uvgRTP.
This commit is contained in:
Joni Räsänen 2022-09-06 13:42:00 +03:00
parent 27ed56aa1c
commit 237e71d465
3 changed files with 28 additions and 18 deletions

View File

@ -71,6 +71,7 @@ int main(void)
* For example, here UDP receive buffer is increased to BUFFER_SIZE_MB
* and frame delay is set PACKET_MAX_DELAY_MS to allow frames to arrive a little late */
receive->configure_ctx(RCC_UDP_RCV_BUF_SIZE, BUFFER_SIZE_MB);
receive->configure_ctx(RCC_RING_BUFFER_SIZE, BUFFER_SIZE_MB);
receive->configure_ctx(RCC_PKT_MAX_DELAY, MAX_PACKET_INTERVAL_MS);
// install receive hook for asynchronous reception

View File

@ -301,7 +301,7 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
*
* Default value is 4 MB
*
* For video with high bitrate, it is advisable to set this
* For video with high bitrate (100+ fps 4K), it is advisable to set this
* to a high number to prevent OS from dropping packets */
RCC_UDP_RCV_BUF_SIZE = 1,
@ -309,21 +309,29 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
*
* Default value is 4 MB
*
* For video with high bitrate, it is advisable to set this
* For video with high bitrate (100+ fps 4K), it is advisable to set this
* to a high number to prevent OS from dropping packets */
RCC_UDP_SND_BUF_SIZE = 2,
/** How large is the receiver ring buffer inside uvgRTP is
*
* Default value is 4 MB
*
* For video with high bitrate (100+ fps 4K), it is advisable to set this
* to a high number to prevent uvgRTP from overwriting previous packets */
RCC_RING_BUFFER_SIZE = 3,
/** How many milliseconds is each frame waited for until it is considered lost.
*
* Default is 500 milliseconds
*
* This is valid only for fragmented frames,
* i.e. RTP_FORMAT_H26X and RTP_FORMAT_GENERIC with RCE_FRAGMENT_GENERIC (TODO) */
RCC_PKT_MAX_DELAY = 3,
RCC_PKT_MAX_DELAY = 4,
/** Overwrite uvgRTP's own payload type in RTP packets and specify your own
* dynamic payload type for all packets of an RTP stream */
RCC_DYN_PAYLOAD_TYPE = 4,
RCC_DYN_PAYLOAD_TYPE = 5,
/** Set a maximum value for the Ethernet frame size assumed by uvgRTP.
*
@ -333,7 +341,7 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
* If application wishes to use small UDP datagrams for some reason,
* it can set MTU size to, for example, 500 bytes or if it wishes
* to use jumbo frames, it can set the MTU size to 9000 bytes */
RCC_MTU_SIZE = 5,
RCC_MTU_SIZE = 6,
/** Set the enumerator of frame rate enforced by uvgRTP.
*
@ -344,7 +352,7 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
* The fps API paces the sending of the RTP packets so that receiver is under less
* strain to receive all. Setting this is not neccessary for small frame sizes,
* but even then it makes the stream smoother. The cost is at most one frame extra latency. */
RCC_FPS_ENUMERATOR = 6,
RCC_FPS_ENUMERATOR = 7,
/** Set the denominator of frame rate enforced by uvgRTP.
*
@ -354,7 +362,7 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
*
* Setting the denominator is only necessary for fractional fps values as setting the enumerator
* already enables the fps functionality. */
RCC_FPS_DENOMINATOR = 7,
RCC_FPS_DENOMINATOR = 8,
RCC_LAST
};

View File

@ -576,37 +576,38 @@ rtp_error_t uvgrtp::media_stream::configure_ctx(int rcc_flag, ssize_t value)
int buf_size = (int)value;
if ((ret = socket_->setsockopt(SOL_SOCKET, SO_SNDBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK)
return ret;
break;
}
break;
case RCC_UDP_RCV_BUF_SIZE: {
if (value <= 0)
return RTP_INVALID_VALUE;
reception_flow_->set_buffer_size(value);
int buf_size = (int)value;
if ((ret = socket_->setsockopt(SOL_SOCKET, SO_RCVBUF, (const char *)&buf_size, sizeof(int))) != RTP_OK)
return ret;
break;
}
break;
case RCC_RING_BUFFER_SIZE: {
if (value <= 0)
return RTP_INVALID_VALUE;
reception_flow_->set_buffer_size(value);
break;
}
case RCC_PKT_MAX_DELAY: {
if (value <= 0)
return RTP_INVALID_VALUE;
rtp_->set_pkt_max_delay(value);
break;
}
break;
case RCC_DYN_PAYLOAD_TYPE: {
if (value <= 0 || UINT8_MAX < value)
return RTP_INVALID_VALUE;
rtp_->set_dynamic_payload((uint8_t)value);
break;
}
break;
case RCC_MTU_SIZE: {
ssize_t hdr = ETH_HDR_SIZE + IPV4_HDR_SIZE + UDP_HDR_SIZE + RTP_HDR_SIZE;
ssize_t max_size = 0xffff - IPV4_HDR_SIZE - UDP_HDR_SIZE;
@ -627,9 +628,9 @@ rtp_error_t uvgrtp::media_stream::configure_ctx(int rcc_flag, ssize_t value)
rtp_->set_payload_size(value - hdr);
rtcp_->set_mtu_size(value - (ETH_HDR_SIZE + IPV4_HDR_SIZE + UDP_HDR_SIZE));
break;
}
break;
case RCC_FPS_ENUMERATOR: {
fps_enumerator_ = value;