From 1f1776a0d8aa4f4d03ea6ca631a1dcf390ababf8 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 9 Jun 2015 14:38:05 +0800 Subject: [PATCH 1/3] fix the export project bug. wakeup connection when dispose server. --- trunk/auto/generate-srs-librtmp-single.sh | 4 +-- trunk/src/app/srs_app_rtmp_conn.cpp | 13 +++++++++ trunk/src/app/srs_app_rtmp_conn.hpp | 5 ++++ trunk/src/app/srs_app_source.cpp | 26 +++++++++++------ trunk/src/app/srs_app_source.hpp | 34 ++++++++++++++++++----- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/trunk/auto/generate-srs-librtmp-single.sh b/trunk/auto/generate-srs-librtmp-single.sh index ce03b8f33..390e438ca 100755 --- a/trunk/auto/generate-srs-librtmp-single.sh +++ b/trunk/auto/generate-srs-librtmp-single.sh @@ -80,7 +80,7 @@ function build_module_hpp() } SRS_LIBRTMP_OBJS="${CORE_OBJS[@]}" && build_module_hpp SRS_LIBRTMP_OBJS="${KERNEL_OBJS[@]}" && build_module_hpp -SRS_LIBRTMP_OBJS="${RTMP_OBJS[@]}" && build_module_hpp +SRS_LIBRTMP_OBJS="${PROTOCOL_OBJS[@]}" && build_module_hpp SRS_LIBRTMP_OBJS="${LIBS_OBJS[@]}" && build_module_hpp # module to cpp files. function build_module_cpp() @@ -99,7 +99,7 @@ function build_module_cpp() } SRS_LIBRTMP_OBJS="${CORE_OBJS[@]}" && build_module_cpp SRS_LIBRTMP_OBJS="${KERNEL_OBJS[@]}" && build_module_cpp -SRS_LIBRTMP_OBJS="${RTMP_OBJS[@]}" && build_module_cpp +SRS_LIBRTMP_OBJS="${PROTOCOL_OBJS[@]}" && build_module_cpp SRS_LIBRTMP_OBJS="${LIBS_OBJS[@]}" && build_module_cpp # create example.cpp diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index a72dcfc9e..b2c73307e 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -88,6 +88,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c) duration = 0; kbps = new SrsKbps(); kbps->set_io(skt, skt); + wakable = NULL; mw_sleep = SRS_PERF_MW_SLEEP; mw_enabled = false; @@ -110,6 +111,16 @@ SrsRtmpConn::~SrsRtmpConn() srs_freep(kbps); } +void SrsRtmpConn::dispose() +{ + SrsConnection::dispose(); + + // wakeup the handler which need to notice. + if (wakable) { + wakable->wakeup(); + } +} + // TODO: return detail message when error for client. int SrsRtmpConn::do_cycle() { @@ -597,7 +608,9 @@ int SrsRtmpConn::playing(SrsSource* source) } // delivery messages for clients playing stream. + wakable = consumer; ret = do_playing(source, consumer, &trd); + wakable = NULL; // stop isolate recv thread trd.stop(); diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index 39aad6e0e..96db60ac7 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -53,6 +53,7 @@ class SrsSharedPtrMessage; class SrsQueueRecvThread; class SrsPublishRecvThread; class SrsSecurity; +class ISrsWakable; /** * the client provides the main logic control for RTMP clients. @@ -70,6 +71,8 @@ private: SrsRefer* refer; SrsBandwidth* bandwidth; SrsSecurity* security; + // the wakable handler, maybe NULL. + ISrsWakable* wakable; // elapse duration in ms // for live play duration, for instance, rtmpdump to record. // @see https://github.com/simple-rtmp-server/srs/issues/47 @@ -85,6 +88,8 @@ private: public: SrsRtmpConn(SrsServer* svr, st_netfd_t c); virtual ~SrsRtmpConn(); +public: + virtual void dispose(); protected: virtual int do_cycle(); // interface ISrsReloadHandler diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 32b9cae39..caea50ec8 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -423,6 +423,14 @@ void SrsMessageQueue::clear() av_start_time = av_end_time = -1; } +ISrsWakable::ISrsWakable() +{ +} + +ISrsWakable::~ISrsWakable() +{ +} + SrsConsumer::SrsConsumer(SrsSource* _source) { source = _source; @@ -551,14 +559,6 @@ void SrsConsumer::wait(int nb_msgs, int duration) // use cond block wait for high performance mode. st_cond_wait(mw_wait); } - -void SrsConsumer::wakeup() -{ - if (mw_waiting) { - st_cond_signal(mw_wait); - mw_waiting = false; - } -} #endif int SrsConsumer::on_play_client_pause(bool is_pause) @@ -571,6 +571,16 @@ int SrsConsumer::on_play_client_pause(bool is_pause) return ret; } +void SrsConsumer::wakeup() +{ +#ifdef SRS_PERF_QUEUE_COND_WAIT + if (mw_waiting) { + st_cond_signal(mw_wait); + mw_waiting = false; + } +#endif +} + SrsGopCache::SrsGopCache() { cached_video_count = 0; diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 95eda44ea..b72caaa6a 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -196,10 +196,28 @@ private: virtual void clear(); }; +/** + * the wakable used for some object + * which is waiting on cond. + */ +class ISrsWakable +{ +public: + ISrsWakable(); + virtual ~ISrsWakable(); +public: + /** + * when the consumer(for player) got msg from recv thread, + * it must be processed for maybe it's a close msg, so the cond + * wait must be wakeup. + */ + virtual void wakeup() = 0; +}; + /** * the consumer for SrsSource, that is a play client. */ -class SrsConsumer +class SrsConsumer : public ISrsWakable { private: SrsRtmpJitter* jitter; @@ -257,17 +275,19 @@ public: * @param duration the messgae duration to wait. */ virtual void wait(int nb_msgs, int duration); - /** - * when the consumer(for player) got msg from recv thread, - * it must be processed for maybe it's a close msg, so the cond - * wait must be wakeup. - */ - virtual void wakeup(); #endif /** * when client send the pause message. */ virtual int on_play_client_pause(bool is_pause); +// ISrsWakable +public: + /** + * when the consumer(for player) got msg from recv thread, + * it must be processed for maybe it's a close msg, so the cond + * wait must be wakeup. + */ + virtual void wakeup(); }; /** From 8e8c8108fc6f4e8e09179c32e4f88488d7a3a116 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 9 Jun 2015 21:04:30 +0800 Subject: [PATCH 2/3] refine the time jitter code. --- trunk/src/app/srs_app_source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index caea50ec8..b30bf9c3f 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -92,7 +92,7 @@ int SrsRtmpJitter::correct(SrsSharedPtrMessage* msg, int tba, int tbv, SrsRtmpJi if (ag == SrsRtmpJitterAlgorithmZERO) { // for the first time, last_pkt_correct_time is zero. // while when timestamp overflow, the timestamp become smaller, reset the last_pkt_correct_time. - if (last_pkt_correct_time <= 0 || last_pkt_correct_time > msg->timestamp) { + if (last_pkt_correct_time <= 0 || msg->timestamp < last_pkt_correct_time) { last_pkt_correct_time = msg->timestamp; } msg->timestamp -= last_pkt_correct_time; From 6941f2c072b35ff46b8c91264f9afa5b1469d074 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 10 Jun 2015 13:53:13 +0800 Subject: [PATCH 3/3] fix #424, fix aggregate timestamp bug. 2.0.174 --- README.md | 1 + trunk/src/app/srs_app_source.cpp | 3 ++- trunk/src/core/srs_core.hpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 527c0e86f..f28abfd31 100755 --- a/README.md +++ b/README.md @@ -344,6 +344,7 @@ Remark: ### SRS 2.0 history +* v2.0, 2015-06-10, fix [#424](https://github.com/simple-rtmp-server/srs/issues/424) fix aggregate timestamp bug. 2.0.174 * v2.0, 2015-06-06, fix [#421](https://github.com/simple-rtmp-server/srs/issues/421) drop video for unkown RTMP header. * v2.0, 2015-06-05, fix [#420](https://github.com/simple-rtmp-server/srs/issues/420) remove ts for hls ram mode. * v2.0, 2015-05-30, fix [#209](https://github.com/simple-rtmp-server/srs/issues/209) cleanup hls when stop and timeout. 2.0.173. diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index b30bf9c3f..343056522 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1922,7 +1922,8 @@ int SrsSource::on_aggregate(SrsCommonMessage* msg) timestamp &= 0x7FFFFFFF; // adjust abs timestamp in aggregate msg. - if (delta < 0) { + // only -1 means uninitialized delta. + if (delta == -1) { delta = (int)msg->header.timestamp - (int)timestamp; } timestamp += delta; diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index cb1e34055..3985cdcd7 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -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 173 +#define VERSION_REVISION 174 // server info. #define RTMP_SIG_SRS_KEY "SRS"