Add RTP packet dispatcher and Media object to Media Stream

Deprecate the old sender/receiver architecture from vanilla uvgRTP
and start using RTP packet dispatcher for incoming frames and Media
object for outgoing frames.
This commit is contained in:
Aaro Altonen 2020-08-04 08:53:27 +03:00
parent 9cc21ebf35
commit 6b812cddc8
2 changed files with 47 additions and 46 deletions

View File

@ -3,6 +3,8 @@
#include <unordered_map>
#include <memory>
#include "media.hh"
#include "pkt_dispatch.hh"
#include "rtcp.hh"
#include "socket.hh"
#include "srtp.hh"
@ -206,5 +208,11 @@ namespace uvg_rtp {
/* media stream type */
enum mstream_type type_;
/* RTP packet dispatcher for the receiver */
uvg_rtp::pkt_dispatcher *pkt_dispatcher_;
/* Media object associated with this media stream. */
uvg_rtp::formats::media *media_;
};
};

View File

@ -5,6 +5,8 @@
#include "media_stream.hh"
#include "random.hh"
#include "formats/hevc.hh"
#define INVALID_TS UINT64_MAX
#define RECV_ONLY_FLAGS (RCE_UNIDIRECTIONAL | RCE_UNIDIR_RECEIVER)
@ -20,7 +22,9 @@ uvg_rtp::media_stream::media_stream(std::string addr, int src_port, int dst_port
rtcp_(nullptr),
ctx_config_(),
media_config_(nullptr),
initialized_(false)
initialized_(false),
pkt_dispatcher_(nullptr),
media_(nullptr)
{
fmt_ = fmt;
addr_ = addr;
@ -51,6 +55,8 @@ uvg_rtp::media_stream::~media_stream()
delete rtcp_;
delete rtp_;
delete srtp_;
delete pkt_dispatcher_;
delete media_;
}
rtp_error_t uvg_rtp::media_stream::init_connection()
@ -96,42 +102,40 @@ rtp_error_t uvg_rtp::media_stream::init()
return RTP_GENERIC_ERROR;
}
if (!(rtp_ = new uvg_rtp::rtp(fmt_)))
if (!(pkt_dispatcher_ = new uvg_rtp::pkt_dispatcher(socket_)))
return RTP_MEMORY_ERROR;
if (!RECV_ONLY(ctx_config_.flags)) {
if (!(sender_ = new uvg_rtp::sender(socket_, ctx_config_, fmt_, rtp_))) {
delete rtp_;
return RTP_MEMORY_ERROR;
}
if ((ret = sender_->init()) != RTP_OK) {
delete rtp_;
delete sender_;
return RTP_MEMORY_ERROR;
}
if (!(rtp_ = new uvg_rtp::rtp(fmt_))) {
delete pkt_dispatcher_;
return RTP_MEMORY_ERROR;
}
if (!SEND_ONLY(ctx_config_.flags)) {
if (!(receiver_ = new uvg_rtp::receiver(socket_, ctx_config_, fmt_, rtp_))) {
delete rtp_;
delete sender_;
return RTP_MEMORY_ERROR;
}
pkt_dispatcher_->install_handler(rtp_->packet_handler);
if ((ret = receiver_->start()) != RTP_OK) {
if (sender_) {
sender_->destroy();
delete sender_;
}
delete rtp_;
delete receiver_;
return RTP_MEMORY_ERROR;
}
switch (fmt_) {
case RTP_FORMAT_HEVC:
media_ = new uvg_rtp::formats::hevc(&socket_, rtp_, ctx_config_.flags);
break;
case RTP_FORMAT_OPUS:
case RTP_FORMAT_GENERIC:
media_ = new uvg_rtp::formats::media(&socket_, rtp_, ctx_config_.flags);
break;
default:
LOG_ERROR("Unknown payload format %u\n", fmt_);
}
if (!media_) {
delete rtp_;
delete pkt_dispatcher_;
return RTP_MEMORY_ERROR;
}
pkt_dispatcher_->install_handler(media_->packet_handler);
initialized_ = true;
return ret;
return pkt_dispatcher_->start();
}
#ifdef __RTP_CRYPTO__
@ -157,6 +161,8 @@ rtp_error_t uvg_rtp::media_stream::init(uvg_rtp::zrtp *zrtp)
return ret;
}
/* TODO: install zrtp packet handler */
if ((srtp_ = new uvg_rtp::srtp()) == nullptr)
return RTP_MEMORY_ERROR;
@ -283,12 +289,7 @@ uvg_rtp::frame::rtp_frame *uvg_rtp::media_stream::pull_frame()
return nullptr;
}
if (!receiver_) {
rtp_errno = RTP_NOT_SUPPORTED;
return nullptr;
}
return receiver_->pull_frame();
return pkt_dispatcher_->pull_frame();
}
uvg_rtp::frame::rtp_frame *uvg_rtp::media_stream::pull_frame(size_t timeout)
@ -299,12 +300,7 @@ uvg_rtp::frame::rtp_frame *uvg_rtp::media_stream::pull_frame(size_t timeout)
return nullptr;
}
if (!receiver_) {
rtp_errno = RTP_NOT_SUPPORTED;
return nullptr;
}
return receiver_->pull_frame(timeout);
return pkt_dispatcher_->pull_frame(timeout);
}
rtp_error_t uvg_rtp::media_stream::install_receive_hook(void *arg, void (*hook)(void *, uvg_rtp::frame::rtp_frame *))
@ -314,13 +310,10 @@ rtp_error_t uvg_rtp::media_stream::install_receive_hook(void *arg, void (*hook)(
return RTP_NOT_INITIALIZED;
}
if (!receiver_)
return RTP_NOT_SUPPORTED;
if (!hook)
return RTP_INVALID_VALUE;
receiver_->install_recv_hook(arg, hook);
pkt_dispatcher_->install_receive_hook(arg, hook);
return RTP_OK;
}