mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
for #250, add mpegts over udp stream caster class.
This commit is contained in:
parent
7f02bfa3a4
commit
6463d22a14
8 changed files with 148 additions and 29 deletions
3
trunk/configure
vendored
3
trunk/configure
vendored
|
@ -390,7 +390,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
|||
"srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
|
||||
"srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
|
||||
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
|
||||
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic")
|
||||
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic"
|
||||
"srs_app_mpegts_udp")
|
||||
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
|
||||
APP_OBJS="${MODULE_OBJS[@]}"
|
||||
fi
|
||||
|
|
|
@ -102,6 +102,8 @@ file
|
|||
../../src/app/srs_app_kbps.cpp,
|
||||
../../src/app/srs_app_log.hpp,
|
||||
../../src/app/srs_app_log.cpp,
|
||||
../../src/app/srs_app_mpegts_udp.hpp,
|
||||
../../src/app/srs_app_mpegts_udp.cpp,
|
||||
../../src/app/srs_app_recv_thread.hpp,
|
||||
../../src/app/srs_app_recv_thread.cpp,
|
||||
../../src/app/srs_app_refer.hpp,
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
<ClInclude Include="..\..\src\app\srs_app_json.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_kbps.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_log.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_mpegts_udp.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_pithy_print.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_recv_thread.hpp" />
|
||||
<ClInclude Include="..\..\src\app\srs_app_refer.hpp" />
|
||||
|
@ -158,6 +159,7 @@
|
|||
<ClCompile Include="..\..\src\app\srs_app_json.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_kbps.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_log.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_mpegts_udp.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_pithy_print.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_recv_thread.cpp" />
|
||||
<ClCompile Include="..\..\src\app\srs_app_refer.cpp" />
|
||||
|
|
|
@ -223,6 +223,9 @@
|
|||
<ClCompile Include="..\..\src\protocol\srs_rtmp_utility.cpp">
|
||||
<Filter>srs</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\app\srs_app_mpegts_udp.cpp">
|
||||
<Filter>srs</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\app\srs_app_bandwidth.hpp">
|
||||
|
@ -408,6 +411,9 @@
|
|||
<ClInclude Include="..\..\src\protocol\srs_rtmp_utility.hpp">
|
||||
<Filter>srs</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\app\srs_app_mpegts_udp.hpp">
|
||||
<Filter>srs</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="research">
|
||||
|
|
57
trunk/src/app/srs_app_mpegts_udp.cpp
Normal file
57
trunk/src/app/srs_app_mpegts_udp.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_app_mpegts_udp.hpp>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c)
|
||||
{
|
||||
}
|
||||
|
||||
SrsMpegtsOverUdp::~SrsMpegtsOverUdp()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
std::string peer_ip = inet_ntoa(from->sin_addr);
|
||||
int peer_port = ntohs(from->sin_port);
|
||||
|
||||
srs_info("udp: got %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf);
|
||||
// TODO: FIXME: implements it.
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
62
trunk/src/app/srs_app_mpegts_udp.hpp
Normal file
62
trunk/src/app/srs_app_mpegts_udp.hpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_APP_MPEGTS_UDP_HPP
|
||||
#define SRS_APP_MPEGTS_UDP_HPP
|
||||
|
||||
/*
|
||||
#include <srs_app_mpegts_udp.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
class sockaddr_in;
|
||||
|
||||
class SrsConfDirective;
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
/**
|
||||
* the mpegts over udp stream caster.
|
||||
*/
|
||||
class SrsMpegtsOverUdp
|
||||
{
|
||||
public:
|
||||
SrsMpegtsOverUdp(SrsConfDirective* c);
|
||||
virtual ~SrsMpegtsOverUdp();
|
||||
public:
|
||||
/**
|
||||
* when udp listener got a udp packet, notice server to process it.
|
||||
* @param type, the client type, used to create concrete connection,
|
||||
* for instance RTMP connection to serve client.
|
||||
* @param from, the udp packet from address.
|
||||
* @param buf, the udp packet bytes, user should copy if need to use.
|
||||
* @param nb_buf, the size of udp packet bytes.
|
||||
* @remark user should never use the buf, for it's a shared memory bytes.
|
||||
*/
|
||||
virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -44,6 +44,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_app_source.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
#include <srs_app_heartbeat.hpp>
|
||||
#include <srs_app_mpegts_udp.hpp>
|
||||
|
||||
// signal defines.
|
||||
#define SIGNAL_RELOAD SIGHUP
|
||||
|
@ -226,14 +227,18 @@ int SrsListener::cycle()
|
|||
return ret;
|
||||
}
|
||||
|
||||
SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type) : SrsListener(server, type)
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
|
||||
{
|
||||
nb_buf = SRS_UDP_MAX_PACKET_SIZE;
|
||||
buf = new char[nb_buf];
|
||||
caster = new SrsMpegtsOverUdp(c);
|
||||
}
|
||||
|
||||
SrsUdpListener::~SrsUdpListener()
|
||||
{
|
||||
srs_freep(caster);
|
||||
srs_freep(buf);
|
||||
}
|
||||
|
||||
int SrsUdpListener::listen(int port)
|
||||
|
@ -313,7 +318,7 @@ int SrsUdpListener::cycle()
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((ret = _server->on_udp_packet(_type, &from, buf, nread)) != ERROR_SUCCESS) {
|
||||
if ((ret = caster->on_udp_packet(&from, buf, nread)) != ERROR_SUCCESS) {
|
||||
srs_warn("handle udp packet failed. ret=%d", ret);
|
||||
continue;
|
||||
}
|
||||
|
@ -328,6 +333,7 @@ int SrsUdpListener::cycle()
|
|||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
SrsSignalManager* SrsSignalManager::instance = NULL;
|
||||
|
||||
|
@ -1015,7 +1021,7 @@ int SrsServer::listen_stream_caster()
|
|||
|
||||
std::string caster = _srs_config->get_stream_caster_engine(stream_caster);
|
||||
if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) {
|
||||
listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp);
|
||||
listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp, stream_caster);
|
||||
} else {
|
||||
ret = ERROR_STREAM_CASTER_ENGINE;
|
||||
srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret);
|
||||
|
@ -1141,19 +1147,6 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_udp_packet(SrsListenerType type, sockaddr_in* from, char* buf, int nb_buf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
std::string peer_ip = inet_ntoa(from->sin_addr);
|
||||
int peer_port = ntohs(from->sin_port);
|
||||
|
||||
// TODO: FIXME: implements it.
|
||||
srs_warn("udp: drop %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_listen()
|
||||
{
|
||||
return listen();
|
||||
|
|
|
@ -44,7 +44,10 @@ class SrsHttpServer;
|
|||
class SrsIngester;
|
||||
class SrsHttpHeartbeat;
|
||||
class SrsKbps;
|
||||
class sockaddr_in;
|
||||
class SrsConfDirective;
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
class SrsMpegtsOverUdp;
|
||||
#endif
|
||||
|
||||
// listener type for server to identify the connection,
|
||||
// that is, use different type to process the connection.
|
||||
|
@ -84,6 +87,7 @@ public:
|
|||
virtual int cycle();
|
||||
};
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
/**
|
||||
* the udp listener, for udp server.
|
||||
*/
|
||||
|
@ -92,8 +96,9 @@ class SrsUdpListener : public SrsListener
|
|||
private:
|
||||
char* buf;
|
||||
int nb_buf;
|
||||
SrsMpegtsOverUdp* caster;
|
||||
public:
|
||||
SrsUdpListener(SrsServer* server, SrsListenerType type);
|
||||
SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
||||
virtual ~SrsUdpListener();
|
||||
public:
|
||||
virtual int listen(int port);
|
||||
|
@ -101,6 +106,7 @@ public:
|
|||
public:
|
||||
virtual int cycle();
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* convert signal to io,
|
||||
|
@ -256,16 +262,6 @@ public:
|
|||
* @param client_stfd, the client fd in st boxed, the underlayer fd.
|
||||
*/
|
||||
virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd);
|
||||
/**
|
||||
* when udp listener got a udp packet, notice server to process it.
|
||||
* @param type, the client type, used to create concrete connection,
|
||||
* for instance RTMP connection to serve client.
|
||||
* @param from, the udp packet from address.
|
||||
* @param buf, the udp packet bytes, user should copy if need to use.
|
||||
* @param nb_buf, the size of udp packet bytes.
|
||||
* @remark user should never use the buf, for it's a shared memory bytes.
|
||||
*/
|
||||
virtual int on_udp_packet(SrsListenerType type, sockaddr_in* from, char* buf, int nb_buf);
|
||||
// interface ISrsThreadHandler.
|
||||
public:
|
||||
virtual int on_reload_listen();
|
||||
|
|
Loading…
Reference in a new issue