multiplex: all sessions share a single socketfactory
This commit is contained in:
parent
ac7023f9f3
commit
076f06c57d
|
|
@ -4,11 +4,13 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
namespace uvgrtp {
|
namespace uvgrtp {
|
||||||
|
|
||||||
class session;
|
class session;
|
||||||
|
class socketfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Provides CNAME isolation and can be used to create uvgrtp::session objects
|
* \brief Provides CNAME isolation and can be used to create uvgrtp::session objects
|
||||||
|
|
@ -61,6 +63,9 @@ namespace uvgrtp {
|
||||||
*/
|
*/
|
||||||
uvgrtp::session *create_session(std::string remote_addr, std::string local_addr);
|
uvgrtp::session *create_session(std::string remote_addr, std::string local_addr);
|
||||||
|
|
||||||
|
uvgrtp::session* create_session(std::string remote_addr, std::string local_addr, bool sfp);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Destroy RTP session and all of its media streams
|
* \brief Destroy RTP session and all of its media streams
|
||||||
*
|
*
|
||||||
|
|
@ -91,6 +96,7 @@ namespace uvgrtp {
|
||||||
|
|
||||||
/* CNAME is the same for all connections */
|
/* CNAME is the same for all connections */
|
||||||
std::string cname_;
|
std::string cname_;
|
||||||
|
std::shared_ptr<uvgrtp::socketfactory> sfp_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ namespace uvgrtp {
|
||||||
/// \cond DO_NOT_DOCUMENT
|
/// \cond DO_NOT_DOCUMENT
|
||||||
session(std::string cname, std::string addr);
|
session(std::string cname, std::string addr);
|
||||||
session(std::string cname, std::string remote_addr, std::string local_addr);
|
session(std::string cname, std::string remote_addr, std::string local_addr);
|
||||||
|
session(std::string cname, std::string remote_addr, std::string local_addr, std::shared_ptr<uvgrtp::socketfactory> sfp);
|
||||||
~session();
|
~session();
|
||||||
/// \endcond
|
/// \endcond
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#include "debug.hh"
|
#include "debug.hh"
|
||||||
#include "hostname.hh"
|
#include "hostname.hh"
|
||||||
#include "random.hh"
|
#include "random.hh"
|
||||||
|
#include "socketfactory.hh"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -37,6 +38,7 @@ uvgrtp::context::context()
|
||||||
UVG_LOG_INFO("uvgRTP version: %s", uvgrtp::get_version().c_str());
|
UVG_LOG_INFO("uvgRTP version: %s", uvgrtp::get_version().c_str());
|
||||||
|
|
||||||
cname_ = uvgrtp::context::generate_cname();
|
cname_ = uvgrtp::context::generate_cname();
|
||||||
|
sfp_ = std::make_shared<uvgrtp::socketfactory>(RCE_NO_FLAGS);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WSADATA wsd;
|
WSADATA wsd;
|
||||||
|
|
@ -78,6 +80,21 @@ uvgrtp::session *uvgrtp::context::create_session(std::string remote_addr, std::s
|
||||||
return new uvgrtp::session(get_cname(), remote_addr, local_addr);
|
return new uvgrtp::session(get_cname(), remote_addr, local_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uvgrtp::session* uvgrtp::context::create_session(std::string remote_addr, std::string local_addr, bool sfp)
|
||||||
|
{
|
||||||
|
if (remote_addr == "" && local_addr == "")
|
||||||
|
{
|
||||||
|
UVG_LOG_ERROR("Please specify at least one address for create_session");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (sfp == true) {
|
||||||
|
return new uvgrtp::session(get_cname(), remote_addr, local_addr, sfp_);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rtp_error_t uvgrtp::context::destroy_session(uvgrtp::session *session)
|
rtp_error_t uvgrtp::context::destroy_session(uvgrtp::session *session)
|
||||||
{
|
{
|
||||||
if (!session)
|
if (!session)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,19 @@ uvgrtp::session::session(std::string cname, std::string remote_addr, std::string
|
||||||
sf_->set_local_interface(local_addr);
|
sf_->set_local_interface(local_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uvgrtp::session::session(std::string cname, std::string remote_addr, std::string local_addr, std::shared_ptr<uvgrtp::socketfactory> sfp) :
|
||||||
|
#ifdef __RTP_CRYPTO__
|
||||||
|
zrtp_(new uvgrtp::zrtp()),
|
||||||
|
#endif
|
||||||
|
generic_address_(""),
|
||||||
|
remote_address_(remote_addr),
|
||||||
|
local_address_(local_addr),
|
||||||
|
cname_(cname),
|
||||||
|
sf_(sfp)
|
||||||
|
{
|
||||||
|
sf_->set_local_interface(local_addr);
|
||||||
|
}
|
||||||
|
|
||||||
uvgrtp::session::~session()
|
uvgrtp::session::~session()
|
||||||
{
|
{
|
||||||
for (auto&i : streams_) {
|
for (auto&i : streams_) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
uvgrtp::socketfactory::socketfactory(int rce_flags) :
|
uvgrtp::socketfactory::socketfactory(int rce_flags) :
|
||||||
rce_flags_(rce_flags),
|
rce_flags_(rce_flags),
|
||||||
|
|
@ -15,7 +16,8 @@ uvgrtp::socketfactory::socketfactory(int rce_flags) :
|
||||||
local_port_(),
|
local_port_(),
|
||||||
ipv6_(false),
|
ipv6_(false),
|
||||||
socket_(std::shared_ptr<uvgrtp::socket>(new uvgrtp::socket(rce_flags))),
|
socket_(std::shared_ptr<uvgrtp::socket>(new uvgrtp::socket(rce_flags))),
|
||||||
local_bound_(false)
|
local_bound_(false),
|
||||||
|
used_ports_({})
|
||||||
{}
|
{}
|
||||||
|
|
||||||
uvgrtp::socketfactory::~socketfactory()
|
uvgrtp::socketfactory::~socketfactory()
|
||||||
|
|
@ -57,20 +59,23 @@ rtp_error_t uvgrtp::socketfactory::set_local_interface(std::string local_addr)
|
||||||
|
|
||||||
rtp_error_t uvgrtp::socketfactory::bind_local_socket(uint16_t local_port)
|
rtp_error_t uvgrtp::socketfactory::bind_local_socket(uint16_t local_port)
|
||||||
{
|
{
|
||||||
rtp_error_t ret;
|
rtp_error_t ret = RTP_OK;
|
||||||
local_port_ = local_port;
|
|
||||||
|
|
||||||
|
if (std::find(used_ports_.begin(), used_ports_.end(), local_port) == used_ports_.end()) {
|
||||||
if (ipv6_) {
|
if (ipv6_) {
|
||||||
sockaddr_in6 bind_addr6 = socket_->create_ip6_sockaddr(local_address_, local_port_);
|
sockaddr_in6 bind_addr6 = socket_->create_ip6_sockaddr(local_address_, local_port);
|
||||||
ret = socket_->bind_ip6(bind_addr6);
|
ret = socket_->bind_ip6(bind_addr6);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sockaddr_in bind_addr = socket_->create_sockaddr(AF_INET, local_address_, local_port_);
|
sockaddr_in bind_addr = socket_->create_sockaddr(AF_INET, local_address_, local_port);
|
||||||
ret = socket_->bind(bind_addr);
|
ret = socket_->bind(bind_addr);
|
||||||
}
|
}
|
||||||
if (ret == RTP_OK) {
|
if (ret == RTP_OK) {
|
||||||
|
used_ports_.push_back(local_port);
|
||||||
local_bound_ = true;
|
local_bound_ = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// = local_port;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "uvgrtp/util.hh"
|
#include "uvgrtp/util.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace uvgrtp {
|
namespace uvgrtp {
|
||||||
|
|
||||||
|
|
@ -26,6 +27,7 @@ namespace uvgrtp {
|
||||||
bool ipv6_;
|
bool ipv6_;
|
||||||
std::shared_ptr<uvgrtp::socket> socket_;
|
std::shared_ptr<uvgrtp::socket> socket_;
|
||||||
bool local_bound_;
|
bool local_bound_;
|
||||||
|
std::vector<uint16_t> used_ports_;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue