RtpMultiCaster MediaTuple重构
This commit is contained in:
parent
f5a8226bbc
commit
6905b5cfe6
|
|
@ -99,10 +99,10 @@ RtpMultiCaster::~RtpMultiCaster() {
|
||||||
DebugL;
|
DebugL;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpMultiCaster::RtpMultiCaster(SocketHelper &helper, const string &local_ip, const string &vhost, const string &app, const string &stream, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port) {
|
RtpMultiCaster::RtpMultiCaster(SocketHelper &helper, const string &local_ip, const MediaTuple &tuple, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port) {
|
||||||
auto src = dynamic_pointer_cast<RtspMediaSource>(MediaSource::find(RTSP_SCHEMA, vhost, app, stream));
|
auto src = dynamic_pointer_cast<RtspMediaSource>(MediaSource::find(RTSP_SCHEMA, tuple.vhost, tuple.app, tuple.stream));
|
||||||
if (!src) {
|
if (!src) {
|
||||||
auto err = StrPrinter << "未找到媒体源:" << vhost << " " << app << " " << stream << endl;
|
auto err = StrPrinter << "未找到媒体源:" << tuple.shortUrl() << endl;
|
||||||
throw std::runtime_error(err);
|
throw std::runtime_error(err);
|
||||||
}
|
}
|
||||||
_multicast_ip = (multicast_ip) ? make_shared<uint32_t>(multicast_ip) : MultiCastAddressMaker::Instance().obtain();
|
_multicast_ip = (multicast_ip) ? make_shared<uint32_t>(multicast_ip) : MultiCastAddressMaker::Instance().obtain();
|
||||||
|
|
@ -144,7 +144,7 @@ RtpMultiCaster::RtpMultiCaster(SocketHelper &helper, const string &local_ip, con
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
string strKey = StrPrinter << local_ip << " " << vhost << " " << app << " " << stream << endl;
|
string strKey = StrPrinter << local_ip << " " << tuple.vhost << " " << tuple.app << " " << tuple.stream << endl;
|
||||||
_rtp_reader->setDetachCB([this, strKey]() {
|
_rtp_reader->setDetachCB([this, strKey]() {
|
||||||
{
|
{
|
||||||
lock_guard<recursive_mutex> lck(g_mtx);
|
lock_guard<recursive_mutex> lck(g_mtx);
|
||||||
|
|
@ -167,7 +167,7 @@ RtpMultiCaster::RtpMultiCaster(SocketHelper &helper, const string &local_ip, con
|
||||||
DebugL << MultiCastAddressMaker::toString(*_multicast_ip) << " "
|
DebugL << MultiCastAddressMaker::toString(*_multicast_ip) << " "
|
||||||
<< _udp_sock[0]->get_local_port() << " "
|
<< _udp_sock[0]->get_local_port() << " "
|
||||||
<< _udp_sock[1]->get_local_port() << " "
|
<< _udp_sock[1]->get_local_port() << " "
|
||||||
<< vhost << " " << app << " " << stream;
|
<< tuple.shortUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RtpMultiCaster::getMultiCasterPort(TrackType trackType) {
|
uint16_t RtpMultiCaster::getMultiCasterPort(TrackType trackType) {
|
||||||
|
|
@ -180,17 +180,17 @@ string RtpMultiCaster::getMultiCasterIP() {
|
||||||
return SockUtil::inet_ntoa(addr);
|
return SockUtil::inet_ntoa(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpMultiCaster::Ptr RtpMultiCaster::get(SocketHelper &helper, const string &local_ip, const string &vhost, const string &app, const string &stream, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port) {
|
RtpMultiCaster::Ptr RtpMultiCaster::get(SocketHelper &helper, const string &local_ip, const MediaTuple &tuple, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port) {
|
||||||
static auto on_create = [](SocketHelper &helper, const string &local_ip, const string &vhost, const string &app, const string &stream, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port){
|
static auto on_create = [](SocketHelper &helper, const string &local_ip, const MediaTuple &tuple, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port){
|
||||||
try {
|
try {
|
||||||
auto poller = helper.getPoller();
|
auto poller = helper.getPoller();
|
||||||
auto ret = RtpMultiCaster::Ptr(new RtpMultiCaster(helper, local_ip, vhost, app, stream, multicast_ip, video_port, audio_port), [poller](RtpMultiCaster *ptr) {
|
auto ret = RtpMultiCaster::Ptr(new RtpMultiCaster(helper, local_ip, tuple, multicast_ip, video_port, audio_port), [poller](RtpMultiCaster *ptr) {
|
||||||
poller->async([ptr]() {
|
poller->async([ptr]() {
|
||||||
delete ptr;
|
delete ptr;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
lock_guard<recursive_mutex> lck(g_mtx);
|
lock_guard<recursive_mutex> lck(g_mtx);
|
||||||
string strKey = StrPrinter << local_ip << " " << vhost << " " << app << " " << stream << endl;
|
string strKey = StrPrinter << local_ip << " " << tuple.vhost << " " << tuple.app << " " << tuple.stream << endl;
|
||||||
g_multi_caster_map.emplace(strKey, ret);
|
g_multi_caster_map.emplace(strKey, ret);
|
||||||
return ret;
|
return ret;
|
||||||
} catch (std::exception &ex) {
|
} catch (std::exception &ex) {
|
||||||
|
|
@ -199,16 +199,16 @@ RtpMultiCaster::Ptr RtpMultiCaster::get(SocketHelper &helper, const string &loca
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string strKey = StrPrinter << local_ip << " " << vhost << " " << app << " " << stream << endl;
|
string strKey = StrPrinter << local_ip << " " << tuple.vhost << " " << tuple.app << " " << tuple.stream << endl;
|
||||||
lock_guard<recursive_mutex> lck(g_mtx);
|
lock_guard<recursive_mutex> lck(g_mtx);
|
||||||
auto it = g_multi_caster_map.find(strKey);
|
auto it = g_multi_caster_map.find(strKey);
|
||||||
if (it == g_multi_caster_map.end()) {
|
if (it == g_multi_caster_map.end()) {
|
||||||
return on_create(helper, local_ip, vhost, app, stream, multicast_ip, video_port, audio_port);
|
return on_create(helper, local_ip, tuple, multicast_ip, video_port, audio_port);
|
||||||
}
|
}
|
||||||
auto ret = it->second.lock();
|
auto ret = it->second.lock();
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
g_multi_caster_map.erase(it);
|
g_multi_caster_map.erase(it);
|
||||||
return on_create(helper, local_ip, vhost, app, stream, multicast_ip, video_port, audio_port);
|
return on_create(helper, local_ip, tuple, multicast_ip, video_port, audio_port);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,14 @@ public:
|
||||||
|
|
||||||
~RtpMultiCaster();
|
~RtpMultiCaster();
|
||||||
|
|
||||||
static Ptr get(toolkit::SocketHelper &helper, const std::string &local_ip, const std::string &vhost, const std::string &app, const std::string &stream, uint32_t multicast_ip = 0, uint16_t video_port = 0, uint16_t audio_port = 0);
|
static Ptr get(toolkit::SocketHelper &helper, const std::string &local_ip, const MediaTuple &tuple, uint32_t multicast_ip = 0, uint16_t video_port = 0, uint16_t audio_port = 0);
|
||||||
void setDetachCB(void *listener,const onDetach &cb);
|
void setDetachCB(void *listener,const onDetach &cb);
|
||||||
|
|
||||||
std::string getMultiCasterIP();
|
std::string getMultiCasterIP();
|
||||||
uint16_t getMultiCasterPort(TrackType trackType);
|
uint16_t getMultiCasterPort(TrackType trackType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RtpMultiCaster(toolkit::SocketHelper &helper, const std::string &local_ip, const std::string &vhost, const std::string &app, const std::string &stream, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port);
|
RtpMultiCaster(toolkit::SocketHelper &helper, const std::string &local_ip, const MediaTuple &tuple, uint32_t multicast_ip, uint16_t video_port, uint16_t audio_port);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::recursive_mutex _mtx;
|
std::recursive_mutex _mtx;
|
||||||
|
|
|
||||||
|
|
@ -742,7 +742,7 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
|
||||||
break;
|
break;
|
||||||
case Rtsp::RTP_MULTICAST: {
|
case Rtsp::RTP_MULTICAST: {
|
||||||
if(!_multicaster){
|
if(!_multicaster){
|
||||||
_multicaster = RtpMultiCaster::get(*this, get_local_ip(), _media_info.vhost, _media_info.app, _media_info.stream, _multicast_ip, _multicast_video_port, _multicast_audio_port);
|
_multicaster = RtpMultiCaster::get(*this, get_local_ip(), _media_info, _multicast_ip, _multicast_video_port, _multicast_audio_port);
|
||||||
if (!_multicaster) {
|
if (!_multicaster) {
|
||||||
send_NotAcceptable();
|
send_NotAcceptable();
|
||||||
throw SockException(Err_shutdown, "can not get a available udp multicast socket");
|
throw SockException(Err_shutdown, "can not get a available udp multicast socket");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue