From ff87318b95ec8282ed17e2782724c5fa51f1b61f Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 23 Apr 2017 20:55:51 +0800 Subject: [PATCH] Fix #851, HTTP API support number of video frames for FPS. 2.0.240 --- README.md | 2 ++ trunk/src/app/srs_app_recv_thread.cpp | 10 ++++++++++ trunk/src/app/srs_app_recv_thread.hpp | 3 +++ trunk/src/app/srs_app_rtmp_conn.cpp | 9 +++++++++ trunk/src/app/srs_app_statistic.cpp | 14 ++++++++++++++ trunk/src/app/srs_app_statistic.hpp | 6 ++++++ trunk/src/core/srs_core.hpp | 2 +- 7 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98ed21a477..8c1f6aad73 100755 --- a/README.md +++ b/README.md @@ -337,6 +337,7 @@ Remark: ## History +* v2.0, 2017-04-23, Fix [#851][bug #851], HTTP API support number of video frames for FPS. 2.0.240 * v2.0, 2017-04-18, [2.0 release1(2.0.239)][r2.0r1] released. 86515 lines. * v2.0, 2017-04-18, Fix [#848][bug #848], crash at HTTP fast buffer grow. 2.0.239 * v2.0, 2017-04-15, Fix [#844][bug #844], support Haivision encoder. 2.0.238 @@ -1291,6 +1292,7 @@ Winlin [bug #846]: https://github.com/ossrs/srs/issues/846 [bug #844]: https://github.com/ossrs/srs/issues/844 [bug #848]: https://github.com/ossrs/srs/issues/848 +[bug #851]: https://github.com/ossrs/srs/issues/851 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 117de8bf5b..a61f41f603 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -257,6 +257,7 @@ SrsPublishRecvThread::SrsPublishRecvThread( recv_error_code = ERROR_SUCCESS; _nb_msgs = 0; + video_frames = 0; error = st_cond_new(); ncid = cid = 0; @@ -298,6 +299,11 @@ int64_t SrsPublishRecvThread::nb_msgs() return _nb_msgs; } +uint64_t SrsPublishRecvThread::nb_video_frames() +{ + return video_frames; +} + int SrsPublishRecvThread::error_code() { return recv_error_code; @@ -378,6 +384,10 @@ int SrsPublishRecvThread::handle(SrsCommonMessage* msg) _nb_msgs++; + if (msg->header.is_video()) { + video_frames++; + } + // log to show the time of recv thread. srs_verbose("recv thread now=%"PRId64"us, got msg time=%"PRId64"ms, size=%d", srs_update_system_time_ms(), msg->header.timestamp, msg->size); diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 388c884de7..a9b001b17b 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -154,6 +154,8 @@ class SrsPublishRecvThread : virtual public ISrsMessageHandler SrsRequest* req; // the msgs already got. int64_t _nb_msgs; + // The video frames we got. + uint64_t video_frames; // for mr(merged read), // @see https://github.com/ossrs/srs/issues/241 bool mr; @@ -186,6 +188,7 @@ class SrsPublishRecvThread : virtual public ISrsMessageHandler */ virtual int wait(int timeout_ms); virtual int64_t nb_msgs(); + virtual uint64_t nb_video_frames(); virtual int error_code(); virtual void set_cid(int v); virtual int get_cid(); diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index a256ed3d18..aa57842c37 100755 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -906,6 +906,7 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) } int64_t nb_msgs = 0; + uint64_t nb_frames = 0; while (!disposed) { pprint->elapse(); @@ -941,6 +942,14 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd) break; } nb_msgs = trd->nb_msgs(); + + // Update the stat for video fps. + // @remark https://github.com/ossrs/srs/issues/851 + SrsStatistic* stat = SrsStatistic::instance(); + if ((ret = stat->on_video_frames(req, (int)(trd->nb_video_frames() - nb_frames))) != ERROR_SUCCESS) { + return ret; + } + nb_frames = trd->nb_video_frames(); // reportable if (pprint->can_print()) { diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index fa58e6260f..813e89e426 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -111,6 +111,7 @@ SrsStatisticStream::SrsStatisticStream() kbps->set_io(NULL, NULL); nb_clients = 0; + nb_frames = 0; } SrsStatisticStream::~SrsStatisticStream() @@ -129,6 +130,7 @@ int SrsStatisticStream::dumps(stringstream& ss) << SRS_JFIELD_STR("app", app) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("live_ms", srs_get_system_time_ms()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT + << SRS_JFIELD_ORG("frames", nb_frames) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT << SRS_JFIELD_OBJ("kbps") @@ -327,6 +329,18 @@ int SrsStatistic::on_audio_info(SrsRequest* req, return ret; } +int SrsStatistic::on_video_frames(SrsRequest* req, int nb_frames) +{ + int ret = ERROR_SUCCESS; + + SrsStatisticVhost* vhost = create_vhost(req); + SrsStatisticStream* stream = create_stream(vhost, req); + + stream->nb_frames += nb_frames; + + return ret; +} + void SrsStatistic::on_stream_publish(SrsRequest* req, int cid) { SrsStatisticVhost* vhost = create_vhost(req); diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 2c2610bc37..ebc9fd2014 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -70,6 +70,7 @@ struct SrsStatisticStream bool active; int connection_cid; int nb_clients; + uint64_t nb_frames; public: /** * stream total kbps. @@ -172,6 +173,11 @@ class SrsStatistic SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type, SrsAacObjectType aac_object ); + /** + * When got videos, update the frames. + * We only stat the total number of video frames. + */ + virtual int on_video_frames(SrsRequest* req, int nb_frames); /** * when publish stream. * @param req the request object of publish connection. diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 7eff59bc98..765c01b7ac 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 239 +#define VERSION_REVISION 240 // generated by configure, only macros. #include