mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add stream caster for post flv over http.
This commit is contained in:
parent
4d18073dab
commit
f0c24eeacc
10 changed files with 203 additions and 3 deletions
48
trunk/src/app/srs_app_caster_flv.cpp
Normal file
48
trunk/src/app/srs_app_caster_flv.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
||||
|
||||
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_caster_flv.hpp>
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_kernel_error.hpp>
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_app_config.hpp>
|
||||
#include <srs_app_pithy_print.hpp>
|
||||
|
||||
SrsAppCasterFlv::SrsAppCasterFlv(SrsConfDirective* c)
|
||||
{
|
||||
}
|
||||
|
||||
SrsAppCasterFlv::~SrsAppCasterFlv()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsAppCasterFlv::on_tcp_client(st_netfd_t stfd)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
52
trunk/src/app/srs_app_caster_flv.hpp
Normal file
52
trunk/src/app/srs_app_caster_flv.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
|
||||
|
||||
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_CASTER_FLV_HPP
|
||||
#define SRS_APP_CASTER_FLV_HPP
|
||||
|
||||
/*
|
||||
#include <srs_app_caster_flv.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
class SrsConfDirective;
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_app_listener.hpp>
|
||||
|
||||
class SrsAppCasterFlv : public ISrsTcpHandler
|
||||
{
|
||||
public:
|
||||
SrsAppCasterFlv(SrsConfDirective* c);
|
||||
virtual ~SrsAppCasterFlv();
|
||||
// ISrsTcpHandler
|
||||
public:
|
||||
virtual int on_tcp_client(st_netfd_t stfd);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -100,6 +100,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp"
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp"
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_FLV "flv"
|
||||
|
||||
#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ using namespace std;
|
|||
#include <srs_app_mpegts_udp.hpp>
|
||||
#include <srs_app_rtsp.hpp>
|
||||
#include <srs_app_statistic.hpp>
|
||||
#include <srs_app_caster_flv.hpp>
|
||||
|
||||
// signal defines.
|
||||
#define SIGNAL_RELOAD SIGHUP
|
||||
|
@ -206,7 +207,7 @@ int SrsRtspListener::listen(string ip, int port)
|
|||
listener = new SrsTcpListener(this, ip, port);
|
||||
|
||||
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
||||
srs_error("udp caster listen failed. ret=%d", ret);
|
||||
srs_error("rtsp caster listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -231,6 +232,64 @@ int SrsRtspListener::on_tcp_client(st_netfd_t stfd)
|
|||
return ret;
|
||||
}
|
||||
|
||||
SrsHttpFlvListener::SrsHttpFlvListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
|
||||
{
|
||||
listener = NULL;
|
||||
|
||||
// the caller already ensure the type is ok,
|
||||
// we just assert here for unknown stream caster.
|
||||
srs_assert(_type == SrsListenerRtsp);
|
||||
if (_type == SrsListenerRtsp) {
|
||||
caster = new SrsAppCasterFlv(c);
|
||||
}
|
||||
}
|
||||
|
||||
SrsHttpFlvListener::~SrsHttpFlvListener()
|
||||
{
|
||||
srs_freep(caster);
|
||||
srs_freep(listener);
|
||||
}
|
||||
|
||||
int SrsHttpFlvListener::listen(string ip, int port)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// the caller already ensure the type is ok,
|
||||
// we just assert here for unknown stream caster.
|
||||
srs_assert(_type == SrsListenerRtsp);
|
||||
|
||||
_ip = ip;
|
||||
_port = port;
|
||||
|
||||
srs_freep(listener);
|
||||
listener = new SrsTcpListener(this, ip, port);
|
||||
|
||||
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
||||
srs_error("flv caster listen failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_info("listen thread cid=%d, current_cid=%d, "
|
||||
"listen at port=%d, type=%d, fd=%d started success, ep=%s:%d",
|
||||
pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port);
|
||||
|
||||
srs_trace("%s listen at tcp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpFlvListener::on_tcp_client(st_netfd_t stfd)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if ((ret = caster->on_tcp_client(stfd)) != ERROR_SUCCESS) {
|
||||
srs_warn("accept client error. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SrsUdpCasterListener::SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
|
||||
{
|
||||
_type = type;
|
||||
|
@ -1003,6 +1062,8 @@ int SrsServer::listen_stream_caster()
|
|||
listener = new SrsUdpCasterListener(this, SrsListenerMpegTsOverUdp, stream_caster);
|
||||
} else if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_RTSP) {
|
||||
listener = new SrsRtspListener(this, SrsListenerRtsp, stream_caster);
|
||||
} else if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_FLV) {
|
||||
listener = new SrsHttpFlvListener(this, SrsListenerFlv, stream_caster);
|
||||
} else {
|
||||
ret = ERROR_STREAM_CASTER_ENGINE;
|
||||
srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret);
|
||||
|
|
|
@ -66,6 +66,8 @@ enum SrsListenerType
|
|||
SrsListenerMpegTsOverUdp = 3,
|
||||
// TCP stream, RTSP stream.
|
||||
SrsListenerRtsp = 4,
|
||||
// HTTP stream, FLV over HTTP POST.
|
||||
SrsListenerFlv = 5,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -123,6 +125,24 @@ public:
|
|||
virtual int on_tcp_client(st_netfd_t stfd);
|
||||
};
|
||||
|
||||
/**
|
||||
* the tcp listener, for http flv server.
|
||||
*/
|
||||
class SrsHttpFlvListener : virtual public SrsListener, virtual public ISrsTcpHandler
|
||||
{
|
||||
private:
|
||||
SrsTcpListener* listener;
|
||||
ISrsTcpHandler* caster;
|
||||
public:
|
||||
SrsHttpFlvListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
||||
virtual ~SrsHttpFlvListener();
|
||||
public:
|
||||
virtual int listen(std::string ip, int port);
|
||||
// ISrsTcpHandler
|
||||
public:
|
||||
virtual int on_tcp_client(st_netfd_t stfd);
|
||||
};
|
||||
|
||||
/**
|
||||
* the udp listener, for udp server.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue