Skip to content

Commit

Permalink
examples: Update examples to use the new RCE send/recv only flags
Browse files Browse the repository at this point in the history
  • Loading branch information
jrsnen committed Sep 6, 2022
1 parent f92e349 commit ce876bc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 36 deletions.
14 changes: 5 additions & 9 deletions examples/receiving_hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
*
Expand Down
18 changes: 6 additions & 12 deletions examples/receiving_poll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions examples/sending.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down
20 changes: 9 additions & 11 deletions examples/sending_generic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
*
Expand All @@ -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)
{
Expand Down

0 comments on commit ce876bc

Please sign in to comment.