add api to get url

pull/296/head
mpromonet 2 years ago
parent 6209874075
commit 4542647b72

@ -48,43 +48,6 @@ class V4l2RTSPServer {
delete scheduler;
}
int addSession(const std::string & sessionName, ServerMediaSubsession* subSession)
{
std::list<ServerMediaSubsession*> subSessionList;
if (subSession) {
subSessionList.push_back(subSession);
}
return this->addSession(sessionName, subSessionList);
}
int addSession(const std::string & sessionName, const std::list<ServerMediaSubsession*> & subSession)
{
int nbSubsession = 0;
if (subSession.empty() == false)
{
ServerMediaSession* sms = ServerMediaSession::createNew(*m_env, sessionName.c_str());
if (sms != NULL)
{
std::list<ServerMediaSubsession*>::const_iterator subIt;
for (subIt = subSession.begin(); subIt != subSession.end(); ++subIt)
{
sms->addSubsession(*subIt);
nbSubsession++;
}
m_rtspServer->addServerMediaSession(sms);
char* url = m_rtspServer->rtspURL(sms);
if (url != NULL)
{
LOG(NOTICE) << "Play this stream using the URL \"" << url << "\"";
delete[] url;
}
}
}
return nbSubsession;
}
bool available() {
return ((m_env != NULL) && (m_rtspServer != NULL));
}
@ -129,7 +92,7 @@ class V4l2RTSPServer {
// -----------------------------------------
// Add unicast Session
// -----------------------------------------
int AddUnicastSession(const std::string& url, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
ServerMediaSession* AddUnicastSession(const std::string& url, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
// Create Unicast Session
std::list<ServerMediaSubsession*> subSession;
if (videoReplicator)
@ -146,13 +109,13 @@ class V4l2RTSPServer {
// -----------------------------------------
// Add HLS & MPEG# Session
// -----------------------------------------
int AddHlsSession(const std::string& url, int hlsSegment, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
ServerMediaSession* AddHlsSession(const std::string& url, int hlsSegment, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
std::list<ServerMediaSubsession*> subSession;
if (videoReplicator)
{
subSession.push_back(TSServerMediaSubsession::createNew(*this->env(), videoReplicator, audioReplicator, hlsSegment));
}
int nbSource = this->addSession(url, subSession);
ServerMediaSession* sms = this->addSession(url, subSession);
struct in_addr ip;
#if LIVEMEDIA_LIBRARY_VERSION_INT < 1611878400
@ -163,14 +126,14 @@ class V4l2RTSPServer {
LOG(NOTICE) << "HLS http://" << inet_ntoa(ip) << ":" << m_rtspPort << "/" << url << ".m3u8";
LOG(NOTICE) << "MPEG-DASH http://" << inet_ntoa(ip) << ":" << m_rtspPort << "/" << url << ".mpd";
return nbSource;
return sms;
}
// -----------------------------------------
// Add multicats Session
// -----------------------------------------
int AddMulticastSession(const std::string& url, in_addr destinationAddress, unsigned short & rtpPortNum, unsigned short & rtcpPortNum, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
ServerMediaSession* AddMulticastSession(const std::string& url, in_addr destinationAddress, unsigned short & rtpPortNum, unsigned short & rtcpPortNum, StreamReplicator* videoReplicator, StreamReplicator* audioReplicator) {
LOG(NOTICE) << "RTP address " << inet_ntoa(destinationAddress) << ":" << rtpPortNum;
LOG(NOTICE) << "RTCP address " << inet_ntoa(destinationAddress) << ":" << rtcpPortNum;
@ -195,6 +158,21 @@ class V4l2RTSPServer {
return this->addSession(url, subSession);
}
// -----------------------------------------
// get rtsp url
// -----------------------------------------
std::string getRtspUrl(ServerMediaSession* sms) {
std::string url;
char* rtspurl = m_rtspServer->rtspURL(sms);
if (rtspurl != NULL)
{
url = rtspurl;
delete[] rtspurl;
}
return url;
}
protected:
UserAuthenticationDatabase* createUserAuthenticationDatabase(const std::list<std::string> & userPasswordList, const char* realm)
{
@ -218,6 +196,42 @@ class V4l2RTSPServer {
return auth;
}
ServerMediaSession* addSession(const std::string & sessionName, ServerMediaSubsession* subSession)
{
std::list<ServerMediaSubsession*> subSessionList;
if (subSession) {
subSessionList.push_back(subSession);
}
return this->addSession(sessionName, subSessionList);
}
ServerMediaSession* addSession(const std::string & sessionName, const std::list<ServerMediaSubsession*> & subSession)
{
ServerMediaSession* sms = NULL;
if (subSession.empty() == false)
{
sms = ServerMediaSession::createNew(*m_env, sessionName.c_str());
if (sms != NULL)
{
std::list<ServerMediaSubsession*>::const_iterator subIt;
for (subIt = subSession.begin(); subIt != subSession.end(); ++subIt)
{
sms->addSubsession(*subIt);
}
m_rtspServer->addServerMediaSession(sms);
char* url = m_rtspServer->rtspURL(sms);
if (url != NULL)
{
LOG(NOTICE) << "Play this stream using the URL \"" << url << "\"";
delete[] url;
}
}
}
return sms;
}
protected:
char m_stop;
UsageEnvironment* m_env;

@ -355,17 +355,26 @@ int main(int argc, char** argv)
// Create Multicast Session
if (multicast)
{
nbSource += rtspServer.AddMulticastSession(baseUrl+murl, destinationAddress, rtpPortNum, rtcpPortNum, videoReplicator, audioReplicator);
ServerMediaSession* sms = rtspServer.AddMulticastSession(baseUrl+murl, destinationAddress, rtpPortNum, rtcpPortNum, videoReplicator, audioReplicator);
if (sms) {
nbSource += sms->numSubsessions();
}
}
// Create HLS Session
if (hlsSegment > 0)
{
nbSource += rtspServer.AddHlsSession(baseUrl+tsurl, hlsSegment, videoReplicator, audioReplicator);
ServerMediaSession* sms = rtspServer.AddHlsSession(baseUrl+tsurl, hlsSegment, videoReplicator, audioReplicator);
if (sms) {
nbSource += sms->numSubsessions();
}
}
// Create Unicast Session
nbSource += rtspServer.AddUnicastSession(baseUrl+url, videoReplicator, audioReplicator);
ServerMediaSession* sms = rtspServer.AddUnicastSession(baseUrl+url, videoReplicator, audioReplicator);
if (sms) {
nbSource += sms->numSubsessions();
}
}
if (nbSource>0)

Loading…
Cancel
Save