From c62194aea2af6a56c2fa762d644ae2a1a8058750 Mon Sep 17 00:00:00 2001 From: Aaro Altonen Date: Mon, 27 Apr 2020 14:31:59 +0300 Subject: [PATCH] Add ability to specify custom payload type --- include/media_stream.hh | 3 +++ include/rtp.hh | 2 ++ src/media_stream.cc | 5 +++++ src/rtp.cc | 9 +++++++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/media_stream.hh b/include/media_stream.hh index bf59a4d..9242479 100644 --- a/include/media_stream.hh +++ b/include/media_stream.hh @@ -121,6 +121,9 @@ namespace uvg_rtp { void set_media_config(void *config); void *get_media_config(); + /* Overwrite the payload type set during initialization */ + void set_dynamic_payload(uint8_t payload); + /* Get unique key of the media stream * Used by session to index media streams */ uint32_t get_key(); diff --git a/include/rtp.hh b/include/rtp.hh index 5d47063..5d1c3a8 100644 --- a/include/rtp.hh +++ b/include/rtp.hh @@ -19,6 +19,7 @@ namespace uvg_rtp { void set_clock_rate(size_t rate); void set_payload(rtp_format_t fmt); + void set_dynamic_payload(uint8_t payload); void fill_header(uint8_t *buffer); void update_sequence(uint8_t *buffer); @@ -28,6 +29,7 @@ namespace uvg_rtp { uint32_t ts_; uint16_t seq_; uint8_t fmt_; + uint8_t payload_; uint32_t clock_rate_; uint32_t wc_start_; diff --git a/src/media_stream.cc b/src/media_stream.cc index 5820e18..ba7ad52 100644 --- a/src/media_stream.cc +++ b/src/media_stream.cc @@ -221,3 +221,8 @@ uint32_t uvg_rtp::media_stream::get_key() { return key_; } + +void uvg_rtp::media_stream::set_dynamic_payload(uint8_t payload) +{ + rtp_->set_dynamic_payload(payload); +} diff --git a/src/rtp.cc b/src/rtp.cc index 7eb53e2..0895fb3 100644 --- a/src/rtp.cc +++ b/src/rtp.cc @@ -36,7 +36,7 @@ uint16_t uvg_rtp::rtp::get_sequence() void uvg_rtp::rtp::set_payload(rtp_format_t fmt) { - fmt_ = fmt; + payload_ = fmt_ = fmt; switch (fmt_) { case RTP_FORMAT_HEVC: @@ -54,6 +54,11 @@ void uvg_rtp::rtp::set_payload(rtp_format_t fmt) } } +void uvg_rtp::rtp::set_dynamic_payload(uint8_t payload) +{ + payload_ = payload; +} + void uvg_rtp::rtp::inc_sequence() { seq_++; @@ -86,7 +91,7 @@ void uvg_rtp::rtp::fill_header(uint8_t *buffer) } buffer[0] = 2 << 6; // RTP version - buffer[1] = (fmt_ & 0x7f) | (0 << 7); + buffer[1] = (payload_ & 0x7f) | (0 << 7); *(uint16_t *)&buffer[2] = htons(seq_); *(uint32_t *)&buffer[4] = htonl(