winlin

add bandwidth workflow

@@ -131,6 +131,35 @@ Stream Architecture: @@ -131,6 +131,35 @@ Stream Architecture:
131 | ...) | +-> DVR --------------+-> FILE | 131 | ...) | +-> DVR --------------+-> FILE |
132 +-----------+-------------------------+----------------+ 132 +-----------+-------------------------+----------------+
133 </pre> 133 </pre>
  134 +Bandwidth Test Workflow:
  135 +<pre>
  136 + +------------+ +----------+
  137 + | Client | | Server |
  138 + +-----+------+ +-----+----+
  139 + | |
  140 + | connect vhost------> | if vhost enable bandwidth,
  141 + | <-----result(success) | do bandwidth check.
  142 + | |
  143 + | <----call(start play) | onSrsBandCheckStartPlayBytes
  144 + | result(playing)-----> | onSrsBandCheckStartingPlayBytes
  145 + | <-------data(playing) | onSrsBandCheckStartingPlayBytes
  146 + | <-----call(stop play) | onSrsBandCheckStopPlayBytes
  147 + | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes
  148 + | |
  149 + | <-call(start publish) | onSrsBandCheckStartPublishBytes
  150 + | result(publishing)--> | onSrsBandCheckStartingPublishBytes
  151 + | data(publishing)----> | onSrsBandCheckStartingPublishBytes
  152 + | <--call(stop publish) | onSrsBandCheckStopPublishBytes
  153 + | result(stopped)(1)--> | onSrsBandCheckStoppedPublishBytes
  154 + | |
  155 + | <--------------report |
  156 + | final(2)------------> | finalClientPacket
  157 + | <END> |
  158 +1. when flash client, server ignore the publish stopped result,
  159 + and directly send the report to flash client.
  160 +2. flash client only. when got report, flash client should send out
  161 + a final packet and close the connection immediately.
  162 +</pre>
134 163
135 ### System Requirements 164 ### System Requirements
136 Supported operating systems and hardware: 165 Supported operating systems and hardware:
1 -/*  
2 -The MIT License (MIT)  
3 -  
4 -Copyright (c) 2013 wenjiegit  
5 -  
6 -Permission is hereby granted, free of charge, to any person obtaining a copy of  
7 -this software and associated documentation files (the "Software"), to deal in  
8 -the Software without restriction, including without limitation the rights to  
9 -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of  
10 -the Software, and to permit persons to whom the Software is furnished to do so,  
11 -subject to the following conditions:  
12 -  
13 -The above copyright notice and this permission notice shall be included in all  
14 -copies or substantial portions of the Software.  
15 -  
16 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
17 -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS  
18 -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR  
19 -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER  
20 -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN  
21 -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
22 -*/  
23 -  
24 -#ifndef SRS_CORE_BANDWIDTH_HPP  
25 -#define SRS_CORE_BANDWIDTH_HPP  
26 -  
27 -/*  
28 -#include <srs_core_bandwidth.hpp>  
29 -*/  
30 -#include <srs_core.hpp>  
31 -  
32 -class SrsRequest;  
33 -class SrsRtmp;  
34 -  
35 -/**  
36 -* bandwidth test agent which provides the interfaces for bandwidth check.  
37 -* 1. if vhost disabled bandwidth check, ignore.  
38 -* 2. otherwise, check the key, error if verify failed.  
39 -* 3. check the interval limit, error if bandwidth in the interval window.  
40 -* 4. check the bandwidth under the max kbps.  
41 -* 5. send the bandwidth data to client.  
42 -* bandwidth workflow:  
43 -* +------------+ +----------+  
44 -* | Client | | Server |  
45 -* +-----+------+ +-----+----+  
46 -* | |  
47 -* | connect vhost------> | if vhost enable bandwidth,  
48 -* | <-----result(success) | do bandwidth check.  
49 -* | |  
50 -* | <----call(start play) | onSrsBandCheckStartPlayBytes  
51 -* | result(playing)-----> | onSrsBandCheckStartingPlayBytes  
52 -* | <-------data(playing) | onSrsBandCheckStartingPlayBytes  
53 -* | <-----call(stop play) | onSrsBandCheckStopPlayBytes  
54 -* | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes  
55 -* | |  
56 -* | <-call(start publish) | onSrsBandCheckStartPublishBytes  
57 -* | result(publishing)--> | onSrsBandCheckStartingPublishBytes  
58 -* | data(publishing)----> | onSrsBandCheckStartingPublishBytes  
59 -* | <--call(stop publish) | onSrsBandCheckStopPublishBytes  
60 -* | result(stopped)-----> | onSrsBandCheckStoppedPublishBytes(1)  
61 -* | |  
62 -* | <--------------report |  
63 -* | final---------------> | finalClientPacket(2)  
64 -* | <END> |  
65 -* 1. when flash client, server ignore the publish stopped result,  
66 -* and directly send the report to flash client.  
67 -* 2. flash client only. when got report, flash client should send out  
68 -* a final packet and close the connection immediately.  
69 -*/  
70 -class SrsBandwidth  
71 -{  
72 -private:  
73 - SrsRequest* req;  
74 - SrsRtmp* rtmp;  
75 -public:  
76 - SrsBandwidth();  
77 - virtual ~SrsBandwidth();  
78 -public:  
79 - /**  
80 - * do the bandwidth test.  
81 - */  
82 - virtual int bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rtmp);  
83 -private:  
84 - virtual int get_local_ip(st_netfd_t stfd, char *&local_ip);  
85 - /**  
86 - * used to process band width check from client.  
87 - */  
88 - virtual int do_bandwidth_check();  
89 - virtual int check_play(int duration_ms, int interval_ms, int& actual_duration_ms, int& play_bytes, int max_play_kbps);  
90 - virtual int check_publish(int duration_ms, int interval_ms, int& actual_duration_ms, int& publish_bytes, int max_pub_kbps);  
91 -};  
92 - 1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013 wenjiegit
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_CORE_BANDWIDTH_HPP
  25 +#define SRS_CORE_BANDWIDTH_HPP
  26 +
  27 +/*
  28 +#include <srs_core_bandwidth.hpp>
  29 +*/
  30 +#include <srs_core.hpp>
  31 +
  32 +class SrsRequest;
  33 +class SrsRtmp;
  34 +
  35 +/**
  36 +* bandwidth test agent which provides the interfaces for bandwidth check.
  37 +* 1. if vhost disabled bandwidth check, ignore.
  38 +* 2. otherwise, check the key, error if verify failed.
  39 +* 3. check the interval limit, error if bandwidth in the interval window.
  40 +* 4. check the bandwidth under the max kbps.
  41 +* 5. send the bandwidth data to client.
  42 +* bandwidth workflow:
  43 +* +------------+ +----------+
  44 +* | Client | | Server |
  45 +* +-----+------+ +-----+----+
  46 +* | |
  47 +* | connect vhost------> | if vhost enable bandwidth,
  48 +* | <-----result(success) | do bandwidth check.
  49 +* | |
  50 +* | <----call(start play) | onSrsBandCheckStartPlayBytes
  51 +* | result(playing)-----> | onSrsBandCheckStartingPlayBytes
  52 +* | <-------data(playing) | onSrsBandCheckStartingPlayBytes
  53 +* | <-----call(stop play) | onSrsBandCheckStopPlayBytes
  54 +* | result(stopped)-----> | onSrsBandCheckStoppedPlayBytes
  55 +* | |
  56 +* | <-call(start publish) | onSrsBandCheckStartPublishBytes
  57 +* | result(publishing)--> | onSrsBandCheckStartingPublishBytes
  58 +* | data(publishing)----> | onSrsBandCheckStartingPublishBytes
  59 +* | <--call(stop publish) | onSrsBandCheckStopPublishBytes
  60 +* | result(stopped)(1)--> | onSrsBandCheckStoppedPublishBytes
  61 +* | |
  62 +* | <--------------report |
  63 +* | final(2)------------> | finalClientPacket
  64 +* | <END> |
  65 +* 1. when flash client, server ignore the publish stopped result,
  66 +* and directly send the report to flash client.
  67 +* 2. flash client only. when got report, flash client should send out
  68 +* a final packet and close the connection immediately.
  69 +*/
  70 +class SrsBandwidth
  71 +{
  72 +private:
  73 + SrsRequest* req;
  74 + SrsRtmp* rtmp;
  75 +public:
  76 + SrsBandwidth();
  77 + virtual ~SrsBandwidth();
  78 +public:
  79 + /**
  80 + * do the bandwidth test.
  81 + */
  82 + virtual int bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rtmp);
  83 +private:
  84 + virtual int get_local_ip(st_netfd_t stfd, char *&local_ip);
  85 + /**
  86 + * used to process band width check from client.
  87 + */
  88 + virtual int do_bandwidth_check();
  89 + virtual int check_play(int duration_ms, int interval_ms, int& actual_duration_ms, int& play_bytes, int max_play_kbps);
  90 + virtual int check_publish(int duration_ms, int interval_ms, int& actual_duration_ms, int& publish_bytes, int max_pub_kbps);
  91 +};
  92 +
93 #endif 93 #endif