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-12-05 14:38:43 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
dde05c63155b705e6337e9a633886432cec32f2c
dde05c63
1 parent
4c1d5c0d
for bug #251, refine the send use cond wait.
隐藏空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
71 行增加
和
7 行删除
trunk/src/app/srs_app_rtmp_conn.cpp
trunk/src/app/srs_app_source.cpp
trunk/src/app/srs_app_source.hpp
trunk/src/core/srs_core.hpp
trunk/src/core/srs_core_performance.hpp
trunk/src/app/srs_app_rtmp_conn.cpp
查看文件 @
dde05c6
...
...
@@ -598,6 +598,10 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd)
// collect elapse for pithy print.
pithy_print
.
elapse
();
// wait for message to incoming.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/251
consumer
->
wait
(
SRS_PERF_MW_MIN_MSGS
,
mw_sleep
);
// get messages from consumer.
// each msg in msgs.msgs must be free, for the SrsMessageArray never free them.
int
count
=
0
;
...
...
@@ -606,12 +610,9 @@ int SrsRtmpConn::do_playing(SrsSource* source, SrsQueueRecvThread* trd)
return
ret
;
}
// no message to send, sleep a while.
if
(
count
<=
0
)
{
srs_verbose
(
"sleep for no messages to send"
);
st_usleep
(
mw_sleep
*
1000
);
}
srs_info
(
"got %d msgs, mw=%d"
,
count
,
mw_sleep
);
// we use wait to get messages, so the count must be positive.
srs_assert
(
count
>
0
);
srs_info
(
"got %d msgs, min=%d, mw=%d"
,
count
,
SRS_PERF_MW_MIN_MSGS
,
mw_sleep
);
// reportable
if
(
pithy_print
.
can_print
())
{
...
...
trunk/src/app/srs_app_source.cpp
查看文件 @
dde05c6
...
...
@@ -166,6 +166,16 @@ SrsMessageQueue::~SrsMessageQueue()
clear
();
}
int
SrsMessageQueue
::
count
()
{
return
(
int
)
msgs
.
size
();
}
int
SrsMessageQueue
::
duration
()
{
return
(
int
)(
av_end_time
-
av_start_time
);
}
void
SrsMessageQueue
::
set_queue_size
(
double
queue_size
)
{
queue_size_ms
=
(
int
)(
queue_size
*
1000
);
...
...
@@ -290,6 +300,11 @@ SrsConsumer::SrsConsumer(SrsSource* _source)
jitter
=
new
SrsRtmpJitter
();
queue
=
new
SrsMessageQueue
();
should_update_source_id
=
false
;
mw_wait
=
st_cond_new
();
mw_min_msgs
=
0
;
mw_duration
=
0
;
mw_waiting
=
false
;
}
SrsConsumer
::~
SrsConsumer
()
...
...
@@ -297,6 +312,7 @@ SrsConsumer::~SrsConsumer()
source
->
on_consumer_destroy
(
this
);
srs_freep
(
jitter
);
srs_freep
(
queue
);
st_cond_destroy
(
mw_wait
);
}
void
SrsConsumer
::
set_queue_size
(
double
queue_size
)
...
...
@@ -329,6 +345,12 @@ int SrsConsumer::enqueue(SrsSharedPtrMessage* msg, bool atc, int tba, int tbv, S
return
ret
;
}
// fire the mw when msgs is enough.
if
(
mw_waiting
&&
queue
->
count
()
>
mw_min_msgs
&&
queue
->
duration
()
>
mw_duration
)
{
st_cond_signal
(
mw_wait
);
mw_waiting
=
false
;
}
return
ret
;
}
...
...
@@ -349,6 +371,22 @@ int SrsConsumer::dump_packets(int max_count, SrsMessage** pmsgs, int& count)
return
queue
->
dump_packets
(
max_count
,
pmsgs
,
count
);
}
void
SrsConsumer
::
wait
(
int
nb_msgs
,
int
duration
)
{
mw_min_msgs
=
nb_msgs
;
mw_duration
=
duration
;
// already ok, donot wait.
if
(
queue
->
count
()
>
mw_min_msgs
&&
queue
->
duration
()
>
mw_duration
)
{
return
;
}
// the enqueue will notify this cond.
mw_waiting
=
true
;
st_cond_wait
(
mw_wait
);
}
int
SrsConsumer
::
on_play_client_pause
(
bool
is_pause
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_source.hpp
查看文件 @
dde05c6
...
...
@@ -116,6 +116,14 @@ public:
virtual
~
SrsMessageQueue
();
public
:
/**
* get the count of queue.
*/
virtual
int
count
();
/**
* get duration of queue.
*/
virtual
int
duration
();
/**
* set the queue size
* @param queue_size the queue size in seconds.
*/
...
...
@@ -154,6 +162,12 @@ private:
bool
paused
;
// when source id changed, notice all consumers
bool
should_update_source_id
;
// the cond wait for mw.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/251
st_cond_t
mw_wait
;
bool
mw_waiting
;
int
mw_min_msgs
;
int
mw_duration
;
public
:
SrsConsumer
(
SrsSource
*
_source
);
virtual
~
SrsConsumer
();
...
...
@@ -189,6 +203,12 @@ public:
*/
virtual
int
dump_packets
(
int
max_count
,
SrsMessage
**
pmsgs
,
int
&
count
);
/**
* wait for messages incomming, atleast nb_msgs and in duration.
* @param nb_msgs the messages count to wait.
* @param duration the messgae duration to wait.
*/
virtual
void
wait
(
int
nb_msgs
,
int
duration
);
/**
* when client send the pause message.
*/
virtual
int
on_play_client_pause
(
bool
is_pause
);
...
...
trunk/src/core/srs_core.hpp
查看文件 @
dde05c6
...
...
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_REVISION 5
5
#define VERSION_REVISION 5
6
// server info.
#define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server"
...
...
trunk/src/core/srs_core_performance.hpp
查看文件 @
dde05c6
...
...
@@ -93,6 +93,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* @remark, recomment to 156.
*/
#define SRS_PERF_MW_MSGS 156
/**
* how many msgs atleast to send.
* @remark, recomment to 8.
*/
#define SRS_PERF_MW_MIN_MSGS 8
/**
* how many chunk stream to cache, [0, N].
...
...
请
注册
或
登录
后发表评论