mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +00:00
for bug #194, use play fd poll, create the singleton poll
This commit is contained in:
parent
efc85ed6df
commit
133cc62b51
6 changed files with 182 additions and 1 deletions
3
trunk/configure
vendored
3
trunk/configure
vendored
|
@ -388,7 +388,8 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
|||
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
|
||||
"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_avc_aac")
|
||||
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_avc_aac"
|
||||
"srs_app_poll")
|
||||
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
|
||||
APP_OBJS="${MODULE_OBJS[@]}"
|
||||
fi
|
||||
|
|
75
trunk/src/app/srs_app_poll.cpp
Normal file
75
trunk/src/app/srs_app_poll.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 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_poll.hpp>
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
||||
SrsPoll::SrsPoll()
|
||||
{
|
||||
pthread = new SrsThread(this, 0, false);
|
||||
}
|
||||
|
||||
SrsPoll::~SrsPoll()
|
||||
{
|
||||
srs_freep(pthread);
|
||||
fds.clear();
|
||||
}
|
||||
|
||||
int SrsPoll::start()
|
||||
{
|
||||
return pthread->start();
|
||||
}
|
||||
|
||||
int SrsPoll::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
// TODO: FIXME: implements it.
|
||||
return ret;
|
||||
}
|
||||
|
||||
SrsPoll* SrsPoll::_instance = new SrsPoll();
|
||||
|
||||
SrsPoll* SrsPoll::instance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
SrsPollFD::SrsPollFD()
|
||||
{
|
||||
_stfd = NULL;
|
||||
}
|
||||
|
||||
SrsPollFD::~SrsPollFD()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsPollFD::initialize(st_netfd_t stfd)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
_stfd = stfd;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
88
trunk/src/app/srs_app_poll.hpp
Normal file
88
trunk/src/app/srs_app_poll.hpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2014 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_POLL_HPP
|
||||
#define SRS_APP_POLL_HPP
|
||||
|
||||
/*
|
||||
#include <srs_app_poll.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <srs_app_st.hpp>
|
||||
#include <srs_app_thread.hpp>
|
||||
|
||||
class SrsPollFD;
|
||||
|
||||
/**
|
||||
* the poll for all play clients to finger the active fd out.
|
||||
* for performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
|
||||
* the poll is shared by all SrsPollFD, and we start an isolate thread to finger the active fds.
|
||||
*/
|
||||
class SrsPoll : public ISrsThreadHandler
|
||||
{
|
||||
private:
|
||||
SrsThread* pthread;
|
||||
std::map<st_netfd_t, SrsPollFD*> fds;
|
||||
public:
|
||||
SrsPoll();
|
||||
virtual ~SrsPoll();
|
||||
public:
|
||||
/**
|
||||
* start the poll thread.
|
||||
*/
|
||||
virtual int start();
|
||||
/**
|
||||
* start an cycle thread.
|
||||
*/
|
||||
virtual int cycle();
|
||||
// singleton
|
||||
private:
|
||||
static SrsPoll* _instance;
|
||||
public:
|
||||
static SrsPoll* instance();
|
||||
};
|
||||
|
||||
/**
|
||||
* the poll fd to check whether the specified fd is active.
|
||||
*/
|
||||
class SrsPollFD
|
||||
{
|
||||
private:
|
||||
st_netfd_t _stfd;
|
||||
public:
|
||||
SrsPollFD();
|
||||
virtual ~SrsPollFD();
|
||||
public:
|
||||
/**
|
||||
* initialize the poll.
|
||||
* @param stfd the fd to poll.
|
||||
*/
|
||||
virtual int initialize(st_netfd_t stfd);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -48,6 +48,7 @@ using namespace std;
|
|||
#include <srs_app_utility.hpp>
|
||||
#include <srs_protocol_msg_array.hpp>
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
#include <srs_app_poll.hpp>
|
||||
|
||||
// when stream is busy, for example, streaming is already
|
||||
// publishing, when a new client to request to publish,
|
||||
|
@ -525,6 +526,11 @@ int SrsRtmpConn::playing(SrsSource* source)
|
|||
bool user_specified_duration_to_stop = (req->duration > 0);
|
||||
int64_t starttime = -1;
|
||||
|
||||
SrsPollFD poll;
|
||||
if ((ret = poll.initialize(stfd)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
// collect elapse for pithy print.
|
||||
pithy_print.elapse();
|
||||
|
|
|
@ -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_poll.hpp>
|
||||
|
||||
// signal defines.
|
||||
#define SIGNAL_RELOAD SIGHUP
|
||||
|
@ -664,6 +665,14 @@ int SrsServer::do_cycle()
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// start the poll for play clients.
|
||||
// performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
|
||||
SrsPoll* poll = SrsPoll::instance();
|
||||
if ((ret = poll->start()) != ERROR_SUCCESS) {
|
||||
srs_error("start poll failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// find the max loop
|
||||
int max = srs_max(0, SRS_SYS_TIME_RESOLUTION_MS_TIMES);
|
||||
|
||||
|
|
|
@ -92,6 +92,8 @@ file
|
|||
..\app\srs_app_kbps.cpp,
|
||||
..\app\srs_app_log.hpp,
|
||||
..\app\srs_app_log.cpp,
|
||||
..\app\srs_app_poll.hpp,
|
||||
..\app\srs_app_poll.cpp,
|
||||
..\app\srs_app_refer.hpp,
|
||||
..\app\srs_app_refer.cpp,
|
||||
..\app\srs_app_reload.hpp,
|
||||
|
|
Loading…
Reference in a new issue