正在显示
8 个修改的文件
包含
148 行增加
和
29 行删除
| @@ -390,7 +390,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | @@ -390,7 +390,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then | ||
| 390 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" | 390 | "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" |
| 391 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" | 391 | "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" |
| 392 | "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" | 392 | "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" |
| 393 | - "srs_app_recv_thread" "srs_app_security" "srs_app_statistic") | 393 | + "srs_app_recv_thread" "srs_app_security" "srs_app_statistic" |
| 394 | + "srs_app_mpegts_udp") | ||
| 394 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh | 395 | APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh |
| 395 | APP_OBJS="${MODULE_OBJS[@]}" | 396 | APP_OBJS="${MODULE_OBJS[@]}" |
| 396 | fi | 397 | fi |
| @@ -102,6 +102,8 @@ file | @@ -102,6 +102,8 @@ file | ||
| 102 | ../../src/app/srs_app_kbps.cpp, | 102 | ../../src/app/srs_app_kbps.cpp, |
| 103 | ../../src/app/srs_app_log.hpp, | 103 | ../../src/app/srs_app_log.hpp, |
| 104 | ../../src/app/srs_app_log.cpp, | 104 | ../../src/app/srs_app_log.cpp, |
| 105 | + ../../src/app/srs_app_mpegts_udp.hpp, | ||
| 106 | + ../../src/app/srs_app_mpegts_udp.cpp, | ||
| 105 | ../../src/app/srs_app_recv_thread.hpp, | 107 | ../../src/app/srs_app_recv_thread.hpp, |
| 106 | ../../src/app/srs_app_recv_thread.cpp, | 108 | ../../src/app/srs_app_recv_thread.cpp, |
| 107 | ../../src/app/srs_app_refer.hpp, | 109 | ../../src/app/srs_app_refer.hpp, |
| @@ -83,6 +83,7 @@ | @@ -83,6 +83,7 @@ | ||
| 83 | <ClInclude Include="..\..\src\app\srs_app_json.hpp" /> | 83 | <ClInclude Include="..\..\src\app\srs_app_json.hpp" /> |
| 84 | <ClInclude Include="..\..\src\app\srs_app_kbps.hpp" /> | 84 | <ClInclude Include="..\..\src\app\srs_app_kbps.hpp" /> |
| 85 | <ClInclude Include="..\..\src\app\srs_app_log.hpp" /> | 85 | <ClInclude Include="..\..\src\app\srs_app_log.hpp" /> |
| 86 | + <ClInclude Include="..\..\src\app\srs_app_mpegts_udp.hpp" /> | ||
| 86 | <ClInclude Include="..\..\src\app\srs_app_pithy_print.hpp" /> | 87 | <ClInclude Include="..\..\src\app\srs_app_pithy_print.hpp" /> |
| 87 | <ClInclude Include="..\..\src\app\srs_app_recv_thread.hpp" /> | 88 | <ClInclude Include="..\..\src\app\srs_app_recv_thread.hpp" /> |
| 88 | <ClInclude Include="..\..\src\app\srs_app_refer.hpp" /> | 89 | <ClInclude Include="..\..\src\app\srs_app_refer.hpp" /> |
| @@ -158,6 +159,7 @@ | @@ -158,6 +159,7 @@ | ||
| 158 | <ClCompile Include="..\..\src\app\srs_app_json.cpp" /> | 159 | <ClCompile Include="..\..\src\app\srs_app_json.cpp" /> |
| 159 | <ClCompile Include="..\..\src\app\srs_app_kbps.cpp" /> | 160 | <ClCompile Include="..\..\src\app\srs_app_kbps.cpp" /> |
| 160 | <ClCompile Include="..\..\src\app\srs_app_log.cpp" /> | 161 | <ClCompile Include="..\..\src\app\srs_app_log.cpp" /> |
| 162 | + <ClCompile Include="..\..\src\app\srs_app_mpegts_udp.cpp" /> | ||
| 161 | <ClCompile Include="..\..\src\app\srs_app_pithy_print.cpp" /> | 163 | <ClCompile Include="..\..\src\app\srs_app_pithy_print.cpp" /> |
| 162 | <ClCompile Include="..\..\src\app\srs_app_recv_thread.cpp" /> | 164 | <ClCompile Include="..\..\src\app\srs_app_recv_thread.cpp" /> |
| 163 | <ClCompile Include="..\..\src\app\srs_app_refer.cpp" /> | 165 | <ClCompile Include="..\..\src\app\srs_app_refer.cpp" /> |
| @@ -223,6 +223,9 @@ | @@ -223,6 +223,9 @@ | ||
| 223 | <ClCompile Include="..\..\src\protocol\srs_rtmp_utility.cpp"> | 223 | <ClCompile Include="..\..\src\protocol\srs_rtmp_utility.cpp"> |
| 224 | <Filter>srs</Filter> | 224 | <Filter>srs</Filter> |
| 225 | </ClCompile> | 225 | </ClCompile> |
| 226 | + <ClCompile Include="..\..\src\app\srs_app_mpegts_udp.cpp"> | ||
| 227 | + <Filter>srs</Filter> | ||
| 228 | + </ClCompile> | ||
| 226 | </ItemGroup> | 229 | </ItemGroup> |
| 227 | <ItemGroup> | 230 | <ItemGroup> |
| 228 | <ClInclude Include="..\..\src\app\srs_app_bandwidth.hpp"> | 231 | <ClInclude Include="..\..\src\app\srs_app_bandwidth.hpp"> |
| @@ -408,6 +411,9 @@ | @@ -408,6 +411,9 @@ | ||
| 408 | <ClInclude Include="..\..\src\protocol\srs_rtmp_utility.hpp"> | 411 | <ClInclude Include="..\..\src\protocol\srs_rtmp_utility.hpp"> |
| 409 | <Filter>srs</Filter> | 412 | <Filter>srs</Filter> |
| 410 | </ClInclude> | 413 | </ClInclude> |
| 414 | + <ClInclude Include="..\..\src\app\srs_app_mpegts_udp.hpp"> | ||
| 415 | + <Filter>srs</Filter> | ||
| 416 | + </ClInclude> | ||
| 411 | </ItemGroup> | 417 | </ItemGroup> |
| 412 | <ItemGroup> | 418 | <ItemGroup> |
| 413 | <Filter Include="research"> | 419 | <Filter Include="research"> |
trunk/src/app/srs_app_mpegts_udp.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_app_mpegts_udp.hpp> | ||
| 25 | + | ||
| 26 | +#include <sys/socket.h> | ||
| 27 | +#include <netinet/in.h> | ||
| 28 | +#include <arpa/inet.h> | ||
| 29 | + | ||
| 30 | +#include <srs_app_config.hpp> | ||
| 31 | +#include <srs_kernel_error.hpp> | ||
| 32 | +#include <srs_kernel_log.hpp> | ||
| 33 | + | ||
| 34 | +#ifdef SRS_AUTO_STREAM_CASTER | ||
| 35 | + | ||
| 36 | +SrsMpegtsOverUdp::SrsMpegtsOverUdp(SrsConfDirective* c) | ||
| 37 | +{ | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +SrsMpegtsOverUdp::~SrsMpegtsOverUdp() | ||
| 41 | +{ | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) | ||
| 45 | +{ | ||
| 46 | + int ret = ERROR_SUCCESS; | ||
| 47 | + | ||
| 48 | + std::string peer_ip = inet_ntoa(from->sin_addr); | ||
| 49 | + int peer_port = ntohs(from->sin_port); | ||
| 50 | + | ||
| 51 | + srs_info("udp: got %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); | ||
| 52 | + // TODO: FIXME: implements it. | ||
| 53 | + | ||
| 54 | + return ret; | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +#endif |
trunk/src/app/srs_app_mpegts_udp.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2015 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_APP_MPEGTS_UDP_HPP | ||
| 25 | +#define SRS_APP_MPEGTS_UDP_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_app_mpegts_udp.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +#include <srs_core.hpp> | ||
| 32 | + | ||
| 33 | +class sockaddr_in; | ||
| 34 | + | ||
| 35 | +class SrsConfDirective; | ||
| 36 | + | ||
| 37 | +#ifdef SRS_AUTO_STREAM_CASTER | ||
| 38 | + | ||
| 39 | +/** | ||
| 40 | +* the mpegts over udp stream caster. | ||
| 41 | +*/ | ||
| 42 | +class SrsMpegtsOverUdp | ||
| 43 | +{ | ||
| 44 | +public: | ||
| 45 | + SrsMpegtsOverUdp(SrsConfDirective* c); | ||
| 46 | + virtual ~SrsMpegtsOverUdp(); | ||
| 47 | +public: | ||
| 48 | + /** | ||
| 49 | + * when udp listener got a udp packet, notice server to process it. | ||
| 50 | + * @param type, the client type, used to create concrete connection, | ||
| 51 | + * for instance RTMP connection to serve client. | ||
| 52 | + * @param from, the udp packet from address. | ||
| 53 | + * @param buf, the udp packet bytes, user should copy if need to use. | ||
| 54 | + * @param nb_buf, the size of udp packet bytes. | ||
| 55 | + * @remark user should never use the buf, for it's a shared memory bytes. | ||
| 56 | + */ | ||
| 57 | + virtual int on_udp_packet(sockaddr_in* from, char* buf, int nb_buf); | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | +#endif | ||
| 61 | + | ||
| 62 | +#endif |
| @@ -44,6 +44,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -44,6 +44,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 44 | #include <srs_app_source.hpp> | 44 | #include <srs_app_source.hpp> |
| 45 | #include <srs_app_utility.hpp> | 45 | #include <srs_app_utility.hpp> |
| 46 | #include <srs_app_heartbeat.hpp> | 46 | #include <srs_app_heartbeat.hpp> |
| 47 | +#include <srs_app_mpegts_udp.hpp> | ||
| 47 | 48 | ||
| 48 | // signal defines. | 49 | // signal defines. |
| 49 | #define SIGNAL_RELOAD SIGHUP | 50 | #define SIGNAL_RELOAD SIGHUP |
| @@ -226,14 +227,18 @@ int SrsListener::cycle() | @@ -226,14 +227,18 @@ int SrsListener::cycle() | ||
| 226 | return ret; | 227 | return ret; |
| 227 | } | 228 | } |
| 228 | 229 | ||
| 229 | -SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type) : SrsListener(server, type) | 230 | +#ifdef SRS_AUTO_STREAM_CASTER |
| 231 | +SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type) | ||
| 230 | { | 232 | { |
| 231 | nb_buf = SRS_UDP_MAX_PACKET_SIZE; | 233 | nb_buf = SRS_UDP_MAX_PACKET_SIZE; |
| 232 | buf = new char[nb_buf]; | 234 | buf = new char[nb_buf]; |
| 235 | + caster = new SrsMpegtsOverUdp(c); | ||
| 233 | } | 236 | } |
| 234 | 237 | ||
| 235 | SrsUdpListener::~SrsUdpListener() | 238 | SrsUdpListener::~SrsUdpListener() |
| 236 | { | 239 | { |
| 240 | + srs_freep(caster); | ||
| 241 | + srs_freep(buf); | ||
| 237 | } | 242 | } |
| 238 | 243 | ||
| 239 | int SrsUdpListener::listen(int port) | 244 | int SrsUdpListener::listen(int port) |
| @@ -313,7 +318,7 @@ int SrsUdpListener::cycle() | @@ -313,7 +318,7 @@ int SrsUdpListener::cycle() | ||
| 313 | continue; | 318 | continue; |
| 314 | } | 319 | } |
| 315 | 320 | ||
| 316 | - if ((ret = _server->on_udp_packet(_type, &from, buf, nread)) != ERROR_SUCCESS) { | 321 | + if ((ret = caster->on_udp_packet(&from, buf, nread)) != ERROR_SUCCESS) { |
| 317 | srs_warn("handle udp packet failed. ret=%d", ret); | 322 | srs_warn("handle udp packet failed. ret=%d", ret); |
| 318 | continue; | 323 | continue; |
| 319 | } | 324 | } |
| @@ -328,6 +333,7 @@ int SrsUdpListener::cycle() | @@ -328,6 +333,7 @@ int SrsUdpListener::cycle() | ||
| 328 | 333 | ||
| 329 | return ret; | 334 | return ret; |
| 330 | } | 335 | } |
| 336 | +#endif | ||
| 331 | 337 | ||
| 332 | SrsSignalManager* SrsSignalManager::instance = NULL; | 338 | SrsSignalManager* SrsSignalManager::instance = NULL; |
| 333 | 339 | ||
| @@ -1015,7 +1021,7 @@ int SrsServer::listen_stream_caster() | @@ -1015,7 +1021,7 @@ int SrsServer::listen_stream_caster() | ||
| 1015 | 1021 | ||
| 1016 | std::string caster = _srs_config->get_stream_caster_engine(stream_caster); | 1022 | std::string caster = _srs_config->get_stream_caster_engine(stream_caster); |
| 1017 | if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) { | 1023 | if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) { |
| 1018 | - listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp); | 1024 | + listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp, stream_caster); |
| 1019 | } else { | 1025 | } else { |
| 1020 | ret = ERROR_STREAM_CASTER_ENGINE; | 1026 | ret = ERROR_STREAM_CASTER_ENGINE; |
| 1021 | srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret); | 1027 | 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) | @@ -1141,19 +1147,6 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) | ||
| 1141 | return ret; | 1147 | return ret; |
| 1142 | } | 1148 | } |
| 1143 | 1149 | ||
| 1144 | -int SrsServer::on_udp_packet(SrsListenerType type, sockaddr_in* from, char* buf, int nb_buf) | ||
| 1145 | -{ | ||
| 1146 | - int ret = ERROR_SUCCESS; | ||
| 1147 | - | ||
| 1148 | - std::string peer_ip = inet_ntoa(from->sin_addr); | ||
| 1149 | - int peer_port = ntohs(from->sin_port); | ||
| 1150 | - | ||
| 1151 | - // TODO: FIXME: implements it. | ||
| 1152 | - srs_warn("udp: drop %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); | ||
| 1153 | - | ||
| 1154 | - return ret; | ||
| 1155 | -} | ||
| 1156 | - | ||
| 1157 | int SrsServer::on_reload_listen() | 1150 | int SrsServer::on_reload_listen() |
| 1158 | { | 1151 | { |
| 1159 | return listen(); | 1152 | return listen(); |
| @@ -44,7 +44,10 @@ class SrsHttpServer; | @@ -44,7 +44,10 @@ class SrsHttpServer; | ||
| 44 | class SrsIngester; | 44 | class SrsIngester; |
| 45 | class SrsHttpHeartbeat; | 45 | class SrsHttpHeartbeat; |
| 46 | class SrsKbps; | 46 | class SrsKbps; |
| 47 | -class sockaddr_in; | 47 | +class SrsConfDirective; |
| 48 | +#ifdef SRS_AUTO_STREAM_CASTER | ||
| 49 | +class SrsMpegtsOverUdp; | ||
| 50 | +#endif | ||
| 48 | 51 | ||
| 49 | // listener type for server to identify the connection, | 52 | // listener type for server to identify the connection, |
| 50 | // that is, use different type to process the connection. | 53 | // that is, use different type to process the connection. |
| @@ -84,6 +87,7 @@ public: | @@ -84,6 +87,7 @@ public: | ||
| 84 | virtual int cycle(); | 87 | virtual int cycle(); |
| 85 | }; | 88 | }; |
| 86 | 89 | ||
| 90 | +#ifdef SRS_AUTO_STREAM_CASTER | ||
| 87 | /** | 91 | /** |
| 88 | * the udp listener, for udp server. | 92 | * the udp listener, for udp server. |
| 89 | */ | 93 | */ |
| @@ -92,8 +96,9 @@ class SrsUdpListener : public SrsListener | @@ -92,8 +96,9 @@ class SrsUdpListener : public SrsListener | ||
| 92 | private: | 96 | private: |
| 93 | char* buf; | 97 | char* buf; |
| 94 | int nb_buf; | 98 | int nb_buf; |
| 99 | + SrsMpegtsOverUdp* caster; | ||
| 95 | public: | 100 | public: |
| 96 | - SrsUdpListener(SrsServer* server, SrsListenerType type); | 101 | + SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); |
| 97 | virtual ~SrsUdpListener(); | 102 | virtual ~SrsUdpListener(); |
| 98 | public: | 103 | public: |
| 99 | virtual int listen(int port); | 104 | virtual int listen(int port); |
| @@ -101,6 +106,7 @@ public: | @@ -101,6 +106,7 @@ public: | ||
| 101 | public: | 106 | public: |
| 102 | virtual int cycle(); | 107 | virtual int cycle(); |
| 103 | }; | 108 | }; |
| 109 | +#endif | ||
| 104 | 110 | ||
| 105 | /** | 111 | /** |
| 106 | * convert signal to io, | 112 | * convert signal to io, |
| @@ -256,16 +262,6 @@ public: | @@ -256,16 +262,6 @@ public: | ||
| 256 | * @param client_stfd, the client fd in st boxed, the underlayer fd. | 262 | * @param client_stfd, the client fd in st boxed, the underlayer fd. |
| 257 | */ | 263 | */ |
| 258 | virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); | 264 | virtual int accept_client(SrsListenerType type, st_netfd_t client_stfd); |
| 259 | - /** | ||
| 260 | - * when udp listener got a udp packet, notice server to process it. | ||
| 261 | - * @param type, the client type, used to create concrete connection, | ||
| 262 | - * for instance RTMP connection to serve client. | ||
| 263 | - * @param from, the udp packet from address. | ||
| 264 | - * @param buf, the udp packet bytes, user should copy if need to use. | ||
| 265 | - * @param nb_buf, the size of udp packet bytes. | ||
| 266 | - * @remark user should never use the buf, for it's a shared memory bytes. | ||
| 267 | - */ | ||
| 268 | - virtual int on_udp_packet(SrsListenerType type, sockaddr_in* from, char* buf, int nb_buf); | ||
| 269 | // interface ISrsThreadHandler. | 265 | // interface ISrsThreadHandler. |
| 270 | public: | 266 | public: |
| 271 | virtual int on_reload_listen(); | 267 | virtual int on_reload_listen(); |
-
请 注册 或 登录 后发表评论