正在显示
1 个修改的文件
包含
93 行增加
和
92 行删除
trunk/src/core/srs_core_bandwidth.hpp
100755 → 100644
| 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 | - | 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 | +* | ||
| 66 | +* 1. when flash client, server ignore the publish stopped result, | ||
| 67 | +* and directly send the report to flash client. | ||
| 68 | +* 2. flash client only. when got report, flash client should send out | ||
| 69 | +* a final packet and close the connection immediately. | ||
| 70 | +*/ | ||
| 71 | +class SrsBandwidth | ||
| 72 | +{ | ||
| 73 | +private: | ||
| 74 | + SrsRequest* req; | ||
| 75 | + SrsRtmp* rtmp; | ||
| 76 | +public: | ||
| 77 | + SrsBandwidth(); | ||
| 78 | + virtual ~SrsBandwidth(); | ||
| 79 | +public: | ||
| 80 | + /** | ||
| 81 | + * do the bandwidth test. | ||
| 82 | + */ | ||
| 83 | + virtual int bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmp* _rtmp); | ||
| 84 | +private: | ||
| 85 | + virtual int get_local_ip(st_netfd_t stfd, char *&local_ip); | ||
| 86 | + /** | ||
| 87 | + * used to process band width check from client. | ||
| 88 | + */ | ||
| 89 | + virtual int do_bandwidth_check(); | ||
| 90 | + virtual int check_play(int duration_ms, int interval_ms, int& actual_duration_ms, int& play_bytes, int max_play_kbps); | ||
| 91 | + virtual int check_publish(int duration_ms, int interval_ms, int& actual_duration_ms, int& publish_bytes, int max_pub_kbps); | ||
| 92 | +}; | ||
| 93 | + | ||
| 93 | #endif | 94 | #endif |
-
请 注册 或 登录 后发表评论