Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-11-12 10:05:42 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
bc1b5f4bbfafd75b50153f1e9360b705eb663665
bc1b5f4b
1 parent
4f21e92a
for bug #194, disable the srs fd poll.
显示空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
10 行增加
和
179 行删除
trunk/src/app/srs_app_poll.cpp
trunk/src/app/srs_app_poll.hpp
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_server.cpp
trunk/src/app/srs_app_poll.cpp
查看文件 @
bc1b5f4
...
...
@@ -26,152 +26,31 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
// the interval in us to refresh the poll for all fds.
// for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
#define SRS_POLL_CYCLE_INTERVAL 10 * 1000 * 1000
SrsPoll
::
SrsPoll
()
{
_pds
=
NULL
;
pthread
=
new
SrsThread
(
this
,
0
,
false
);
}
SrsPoll
::~
SrsPoll
()
{
srs_freep
(
_pds
);
srs_freep
(
pthread
);
fds
.
clear
();
}
int
SrsPoll
::
start
()
{
return
pthread
->
start
();
}
int
SrsPoll
::
cycle
()
{
int
ret
=
ERROR_SUCCESS
;
if
(
fds
.
size
()
==
0
)
{
st_usleep
(
SRS_CONSTS_RTMP_PULSE_TIMEOUT_US
);
return
ret
;
}
int
nb_pds
=
(
int
)
fds
.
size
();
// TODO: FIXME: use more efficient way for the poll.
srs_freep
(
_pds
);
_pds
=
new
pollfd
[
nb_pds
];
if
(
true
)
{
int
index
=
0
;
std
::
map
<
int
,
SrsPollFD
*>::
iterator
it
;
for
(
it
=
fds
.
begin
();
it
!=
fds
.
end
();
++
it
)
{
int
fd
=
it
->
first
;
pollfd
&
pfd
=
_pds
[
index
++
];
pfd
.
fd
=
fd
;
pfd
.
events
=
POLLIN
;
pfd
.
revents
=
0
;
}
srs_assert
(
index
==
(
int
)
fds
.
size
());
}
// Upon successful completion, a non-negative value is returned.
// A positive value indicates the total number of OS file descriptors in pds that have events.
// A value of 0 indicates that the call timed out.
if
(
st_poll
(
_pds
,
nb_pds
,
SRS_POLL_CYCLE_INTERVAL
)
<
0
)
{
srs_warn
(
"ignore st_poll failed, size=%d"
,
nb_pds
);
return
ret
;
}
for
(
int
i
=
0
;
i
<
nb_pds
;
i
++
)
{
if
(
!
(
_pds
[
i
].
revents
&
POLLIN
))
{
continue
;
}
int
fd
=
_pds
[
i
].
fd
;
if
(
fds
.
find
(
fd
)
==
fds
.
end
())
{
continue
;
}
SrsPollFD
*
owner
=
fds
[
fd
];
owner
->
set_active
(
true
);
}
return
ret
;
}
int
SrsPoll
::
add
(
st_netfd_t
stfd
,
SrsPollFD
*
owner
)
{
int
ret
=
ERROR_SUCCESS
;
int
fd
=
st_netfd_fileno
(
stfd
);
if
(
fds
.
find
(
fd
)
!=
fds
.
end
())
{
ret
=
ERROR_RTMP_POLL_FD_DUPLICATED
;
srs_error
(
"fd exists, fd=%d, ret=%d"
,
fd
,
ret
);
return
ret
;
}
fds
[
fd
]
=
owner
;
return
ret
;
}
void
SrsPoll
::
remove
(
st_netfd_t
stfd
,
SrsPollFD
*
owner
)
{
std
::
map
<
int
,
SrsPollFD
*>::
iterator
it
;
int
fd
=
st_netfd_fileno
(
stfd
);
if
((
it
=
fds
.
find
(
fd
))
!=
fds
.
end
())
{
fds
.
erase
(
it
);
}
}
SrsPoll
*
SrsPoll
::
_instance
=
new
SrsPoll
();
SrsPoll
*
SrsPoll
::
instance
()
{
return
_instance
;
}
SrsPollFD
::
SrsPollFD
()
{
_stfd
=
NULL
;
_active
=
false
;
}
SrsPoll
FD
::~
SrsPollFD
()
SrsPoll
::~
SrsPoll
()
{
if
(
_stfd
)
{
SrsPoll
*
poll
=
SrsPoll
::
instance
();
poll
->
remove
(
_stfd
,
this
);
}
}
int
SrsPoll
FD
::
initialize
(
st_netfd_t
stfd
)
int
SrsPoll
::
initialize
(
st_netfd_t
stfd
)
{
int
ret
=
ERROR_SUCCESS
;
_stfd
=
stfd
;
SrsPoll
*
poll
=
SrsPoll
::
instance
();
if
((
ret
=
poll
->
add
(
stfd
,
this
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"add fd to poll failed. ret=%d"
,
ret
);
return
ret
;
}
return
ret
;
}
bool
SrsPoll
FD
::
active
()
bool
SrsPoll
::
active
()
{
return
_active
;
}
void
SrsPoll
FD
::
set_active
(
bool
v
)
void
SrsPoll
::
set_active
(
bool
v
)
{
_active
=
v
;
}
...
...
trunk/src/app/srs_app_poll.hpp
查看文件 @
bc1b5f4
...
...
@@ -35,59 +35,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#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
;
pollfd
*
_pds
;
std
::
map
<
int
,
SrsPollFD
*>
fds
;
public
:
SrsPoll
();
virtual
~
SrsPoll
();
public
:
/**
* start the poll thread.
*/
virtual
int
start
();
/**
* start an cycle thread.
*/
virtual
int
cycle
();
public
:
/**
* add the fd to poll.
*/
virtual
int
add
(
st_netfd_t
stfd
,
SrsPollFD
*
owner
);
/**
* remove the fd to poll, ignore any error.
*/
virtual
void
remove
(
st_netfd_t
stfd
,
SrsPollFD
*
owner
);
// singleton
private:
static
SrsPoll
*
_instance
;
public
:
static
SrsPoll
*
instance
();
};
/**
* the poll fd to check whether the specified fd is active.
* we start new thread to covert the fd status to async.
* for performance issue, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
*/
class
SrsPoll
FD
class
SrsPoll
{
private
:
st_netfd_t
_stfd
;
// whether current fd is active.
bool
_active
;
public
:
SrsPollFD
();
virtual
~
SrsPollFD
();
SrsPoll
();
virtual
~
SrsPoll
();
public
:
/**
* initialize the poll.
...
...
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
bc1b5f4
...
...
@@ -518,7 +518,7 @@ int SrsRtmpConn::playing(SrsSource* source)
srs_verbose
(
"consumer created success."
);
// use poll fd to manage the connection, read when active.
SrsPoll
FD
poll_fd
;
SrsPoll
poll_fd
;
if
((
ret
=
poll_fd
.
initialize
(
stfd
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
trunk/src/app/srs_app_server.cpp
查看文件 @
bc1b5f4
...
...
@@ -44,7 +44,6 @@ 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
...
...
@@ -665,14 +664,6 @@ 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
);
...
...
请
注册
或
登录
后发表评论