Skip to content

Commit

Permalink
Merge pull request #226 from Atlas42/ttl-multicast
Browse files Browse the repository at this point in the history
Multicast TTL configuration flag added
  • Loading branch information
jrsnen authored Sep 11, 2024
2 parents 74249a8 + 5c9c08b commit 08c153f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ stream->configure_ctx(RCC_PKT_MAX_DELAY, 150);
| RCC_POLL_TIMEOUT | Set the timeout value for polling the socket. | 100 ms | Receiver|
| RCC_SSRC | Set the SSSRC value for this media stream. | random uint32 | Sender|
| RCC_REMOTE_SSRC | Set the remote SSRC value that this media stream should receive packets from. | random uint32 | Receiver|
| RCC_MULTICAST_TTL | Set the sender packets IP TTL (Time to Live) for multicast. Must be in range [1, 255]. | system default | Sender |

### RTP frame flags

Expand Down Expand Up @@ -173,7 +174,7 @@ The default behavior of uvgRTP video reception when there is packet loss is to g

## Trouble receiving burst of packets?

The default configuration of uvgRTP should be able to handle most basic scenarios up to 4K60p without any frame loss. If you are however 1) using a higher resolution, 2) higher fps value, 3) using a low power machine to receive the RTP stream, or 4) you are experiencing frame loss, you might consider setting or increasing the following parameters:
The default configuration of uvgRTP should be able to handle most basic scenarios up to 4K60p without any frame loss. If you are however 1) using a higher resolution, 2) higher fps value, 3) using a low power machine to receive the RTP stream, or 4) you are experiencing frame loss, you might consider setting or increasing the following parameters:
* RCC_UDP_RCV_BUF_SIZE: You can try increasing this to 40 or 80 MB if it helps receiving frames
* RCC_UDP_SND_BUF_SIZE_ You can try increasing this to 40 or 80 MB if it helps sending frames
* RCC_RING_BUFFER_SIZE: You can try increasing this to 8 or 16 MB if it helps receiving frames
Expand Down
1 change: 1 addition & 0 deletions include/uvgrtp/media_stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ namespace uvgrtp {
// Values are initialized to -2, which means value not set
int snd_buf_size_;
int rcv_buf_size_;
int multicast_ttl_;
};
}

Expand Down
6 changes: 6 additions & 0 deletions include/uvgrtp/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ enum RTP_CTX_CONFIGURATION_FLAGS {
*/
RCC_POLL_TIMEOUT = 13,

/** Set the sender packets IP TTL (Time to Live) for multicast
*
* Must be in range [1, 255]. Keep the system default if not set.
*/
RCC_MULTICAST_TTL = 15,

/// \cond DO_NOT_DOCUMENT
RCC_LAST
/// \endcond
Expand Down
15 changes: 14 additions & 1 deletion src/media_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ uvgrtp::media_stream::media_stream(std::string cname, std::string remote_addr,
ssrc_(std::make_shared<std::atomic<std::uint32_t>>(uvgrtp::random::generate_32())),
remote_ssrc_(std::make_shared<std::atomic<std::uint32_t>>(ssrc_.get()->load() + 1)),
snd_buf_size_(-1),
rcv_buf_size_(-1)
rcv_buf_size_(-1),
multicast_ttl_(-1)
{
}

Expand Down Expand Up @@ -936,6 +937,15 @@ rtp_error_t uvgrtp::media_stream::configure_ctx(int rcc_flag, ssize_t value)
*remote_ssrc_ = (uint32_t)value;
break;
}
case RCC_MULTICAST_TTL: {
if (value <= 0 || value > 255)
return RTP_INVALID_VALUE;

int multicast_ttl = (int)value;
multicast_ttl_ = multicast_ttl;
ret = socket_->setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, (const char*)&multicast_ttl, sizeof(int));
break;
}
default:
return RTP_INVALID_VALUE;
}
Expand Down Expand Up @@ -993,6 +1003,9 @@ int uvgrtp::media_stream::get_configuration_value(int rcc_flag)
case RCC_POLL_TIMEOUT: {
return reception_flow_->get_poll_timeout_ms();
}
case RCC_MULTICAST_TTL: {
return multicast_ttl_;
}
default:
ret = -1;
}
Expand Down
2 changes: 2 additions & 0 deletions test/test_2_rtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ TEST(RTPTests, rtp_configuration)

sender->configure_ctx(RCC_FPS_NUMERATOR, 100);
sender->configure_ctx(RCC_FPS_DENOMINATOR, 1);

sender->configure_ctx(RCC_MULTICAST_TTL, 1);
}

if (receiver)
Expand Down

0 comments on commit 08c153f

Please sign in to comment.