From ce876bc58910309c8715781824eaaf485d5b297d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Tue, 6 Sep 2022 10:46:50 +0300 Subject: [PATCH] examples: Update examples to use the new RCE send/recv only flags --- examples/receiving_hook.cc | 14 +++++--------- examples/receiving_poll.cc | 18 ++++++------------ examples/sending.cc | 6 ++---- examples/sending_generic.cc | 20 +++++++++----------- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/examples/receiving_hook.cc b/examples/receiving_hook.cc index c848a003..c973a5e1 100644 --- a/examples/receiving_hook.cc +++ b/examples/receiving_hook.cc @@ -23,11 +23,10 @@ // parameters for this test. You can change these to suit your network environment constexpr uint16_t LOCAL_PORT = 8890; -constexpr char REMOTE_ADDRESS[] = "127.0.0.1"; -constexpr uint16_t REMOTE_PORT = 8888; +constexpr char LOCAL_ADDRESS[] = "127.0.0.1"; // This example runs for 5 seconds -constexpr auto RECEIVE_TIME_S = std::chrono::seconds(3); +constexpr auto RECEIVE_TIME_S = std::chrono::seconds(10); void rtp_receive_hook(void *arg, uvgrtp::frame::rtp_frame *frame); void cleanup(uvgrtp::context& ctx, uvgrtp::session *sess, uvgrtp::media_stream *receiver); @@ -37,12 +36,9 @@ int main(void) std::cout << "Starting uvgRTP RTP receive hook example" << std::endl; uvgrtp::context ctx; - /* There remote address and port are needed if the . - uvgRTP API is */ - - uvgrtp::session *sess = ctx.create_session(REMOTE_ADDRESS); - int flags = RTP_NO_FLAGS; - uvgrtp::media_stream *receiver = sess->create_stream(LOCAL_PORT, REMOTE_PORT, RTP_FORMAT_H265, flags); + uvgrtp::session *sess = ctx.create_session(LOCAL_ADDRESS); + int flags = RCE_RECEIVE_ONLY; + uvgrtp::media_stream *receiver = sess->create_stream(LOCAL_PORT, RTP_FORMAT_H265, flags); /* Receive hook can be installed and uvgRTP will call this hook when an RTP frame is received * diff --git a/examples/receiving_poll.cc b/examples/receiving_poll.cc index e4605839..4a1d2c25 100644 --- a/examples/receiving_poll.cc +++ b/examples/receiving_poll.cc @@ -21,11 +21,10 @@ // parameters of this example. You may change these to reflect you network environment constexpr uint16_t LOCAL_PORT = 8890; -constexpr char REMOTE_ADDRESS[] = "127.0.0.1"; -constexpr uint16_t REMOTE_PORT = 8888; +constexpr char LOCAL_ADDRESS[] = "127.0.0.1"; // How long this example will run -constexpr auto RECEIVE_TIME_MS = std::chrono::milliseconds(3000); +constexpr auto RECEIVE_TIME_MS = std::chrono::milliseconds(10000); constexpr int RECEIVER_WAIT_TIME_MS = 100; void process_frame(uvgrtp::frame::rtp_frame *frame); @@ -35,18 +34,13 @@ int main(void) std::cout << "Starting uvgRTP RTP receive hook example" << std::endl; uvgrtp::context ctx; - uvgrtp::session *sess = ctx.create_session(REMOTE_ADDRESS); - int flags = RCE_NO_FLAGS; + uvgrtp::session *sess = ctx.create_session(LOCAL_ADDRESS); + int flags = RCE_RECEIVE_ONLY; - uvgrtp::media_stream *receiver = sess->create_stream(LOCAL_PORT, REMOTE_PORT, - RTP_FORMAT_H265, flags); - - // TODO: Explain how to stop poll in middle of the wait + uvgrtp::media_stream *receiver = sess->create_stream(LOCAL_PORT, RTP_FORMAT_H265, flags); if (receiver) { - uvgrtp::frame::rtp_frame *frame = nullptr; - std::cout << "Start receiving frames for " << RECEIVE_TIME_MS.count() << " ms" << std::endl; auto start = std::chrono::steady_clock::now(); @@ -56,7 +50,7 @@ int main(void) * within that time limit, pull_frame() returns a nullptr * * The parameter tells how long time a frame is waited in milliseconds */ - frame = receiver->pull_frame(RECEIVER_WAIT_TIME_MS); + uvgrtp::frame::rtp_frame* frame = receiver->pull_frame(RECEIVER_WAIT_TIME_MS); if (frame) process_frame(frame); diff --git a/examples/sending.cc b/examples/sending.cc index df369027..82fc9653 100644 --- a/examples/sending.cc +++ b/examples/sending.cc @@ -10,7 +10,6 @@ /* parameters of this example. You may change these to reflect * you network environment. */ -constexpr uint16_t LOCAL_PORT = 8888; constexpr char REMOTE_ADDRESS[] = "127.0.0.1"; constexpr uint16_t REMOTE_PORT = 8890; @@ -42,9 +41,8 @@ int main(void) * * In this example, we have one media stream with the remote participant: H265 */ - int flags = RTP_NO_FLAGS; - uvgrtp::media_stream *hevc = sess->create_stream(LOCAL_PORT, REMOTE_PORT, - RTP_FORMAT_H265, flags); + int flags = RCE_SEND_ONLY; + uvgrtp::media_stream *hevc = sess->create_stream(REMOTE_PORT, RTP_FORMAT_H265, flags); if (hevc) { diff --git a/examples/sending_generic.cc b/examples/sending_generic.cc index 74709254..d6173d47 100644 --- a/examples/sending_generic.cc +++ b/examples/sending_generic.cc @@ -15,11 +15,8 @@ // network parameters of the example -constexpr char LOCAL_INTERFACE[] = "127.0.0.1"; -constexpr uint16_t LOCAL_PORT = 8888; - constexpr char REMOTE_ADDRESS[] = "127.0.0.1"; -constexpr uint16_t REMOTE_PORT = 8890; +constexpr uint16_t REMOTE_PORT = 8888; // demonstration parameters of the example constexpr uint32_t PAYLOAD_MAXLEN = (0xffff - 0x1000); @@ -35,8 +32,8 @@ int main(void) // See sending example for more details uvgrtp::context ctx; - uvgrtp::session *local_session = ctx.create_session(REMOTE_ADDRESS); - uvgrtp::session *remote_session = ctx.create_session(LOCAL_INTERFACE); + uvgrtp::session *local_session = ctx.create_session(REMOTE_ADDRESS); // REMOTE_ADDRESS will be intereted as remote address due to RCE_SEND_ONLY + uvgrtp::session *remote_session = ctx.create_session(REMOTE_ADDRESS); // REMOTE_ADDRESS will be interpreted as local address due to RCE_RECEIVE_ONLY /* To enable interoperability between RTP libraries, uvgRTP won't fragment generic frames by default. * @@ -50,11 +47,12 @@ int main(void) * * See sending.cc for more details about create_stream() */ - int flags = RCE_FRAGMENT_GENERIC; - uvgrtp::media_stream *send = local_session->create_stream(LOCAL_PORT, REMOTE_PORT, - RTP_FORMAT_GENERIC, flags); - uvgrtp::media_stream *recv = remote_session->create_stream(REMOTE_PORT, LOCAL_PORT, - RTP_FORMAT_GENERIC, flags); + int send_flags = RCE_FRAGMENT_GENERIC | RCE_SEND_ONLY; + int receive_flags = RCE_FRAGMENT_GENERIC | RCE_RECEIVE_ONLY; + + // set only one port, this one port is interpreted based on rce flags + uvgrtp::media_stream *send = local_session->create_stream(REMOTE_PORT, RTP_FORMAT_GENERIC, send_flags); + uvgrtp::media_stream *recv = remote_session->create_stream(REMOTE_PORT, RTP_FORMAT_GENERIC, receive_flags); if (!recv || recv->install_receive_hook(nullptr, rtp_receive_hook) != RTP_OK) {