winlin

change copyright from 2013 to 2013-2014.

正在显示 57 个修改的文件 包含 1120 行增加1120 行删除
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 ''' 2 '''
3 The MIT License (MIT) 3 The MIT License (MIT)
4 4
5 -Copyright (c) 2013 winlin 5 +Copyright (c) 2013-2014 winlin
6 6
7 Permission is hereby granted, free of charge, to any person obtaining a copy of 7 Permission is hereby granted, free of charge, to any person obtaining a copy of
8 this software and associated documentation files (the "Software"), to deal in 8 this software and associated documentation files (the "Software"), to deal in
@@ -463,7 +463,7 @@ if __name__ != "__main__": @@ -463,7 +463,7 @@ if __name__ != "__main__":
463 463
464 # check the user options 464 # check the user options
465 if len(sys.argv) <= 1: 465 if len(sys.argv) <= 1:
466 - print "SRS api callback server, Copyright (c) 2013 winlin" 466 + print "SRS api callback server, Copyright (c) 2013-2014 winlin"
467 print "Usage: python %s <port>"%(sys.argv[0]) 467 print "Usage: python %s <port>"%(sys.argv[0])
468 print " port: the port to listen at." 468 print " port: the port to listen at."
469 print "For example:" 469 print "For example:"
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
@@ -78,7 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -78,7 +78,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78 #define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" 78 #define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin"
79 #define RTMP_SIG_SRS_EMAIL "winterserver@126.com" 79 #define RTMP_SIG_SRS_EMAIL "winterserver@126.com"
80 #define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)" 80 #define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)"
81 -#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013 winlin" 81 +#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013-2014 winlin"
82 #define RTMP_SIG_SRS_CONTRIBUTOR "winlin,wenjiegit" 82 #define RTMP_SIG_SRS_CONTRIBUTOR "winlin,wenjiegit"
83 83
84 // compare 84 // compare
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 wenjiegit 4 +Copyright (c) 2013-2014 wenjiegit
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 wenjiegit 4 +Copyright (c) 2013-2014 wenjiegit
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
@@ -736,7 +736,7 @@ int SrsConfig::parse_argv(int& i, char** argv) @@ -736,7 +736,7 @@ int SrsConfig::parse_argv(int& i, char** argv)
736 void SrsConfig::print_help(char** argv) 736 void SrsConfig::print_help(char** argv)
737 { 737 {
738 printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION 738 printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION
739 - " Copyright (c) 2013 winlin\n" 739 + " Copyright (c) 2013-2014 winlin\n"
740 "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n" 740 "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n"
741 "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n" 741 "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n"
742 "Usage: %s [-h?vV] [-c <filename>]\n" 742 "Usage: %s [-h?vV] [-c <filename>]\n"
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 -/*  
2 -The MIT License (MIT)  
3 -  
4 -Copyright (c) 2013 winlin  
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_RTMP_HPP  
25 -#define SRS_CORE_RTMP_HPP  
26 -  
27 -/*  
28 -#include <srs_core_rtmp.hpp>  
29 -*/  
30 -  
31 -#include <srs_core.hpp>  
32 -  
33 -#include <string>  
34 -  
35 -class SrsProtocol;  
36 -class ISrsMessage;  
37 -class SrsCommonMessage;  
38 -class SrsCreateStreamPacket;  
39 -class SrsFMLEStartPacket;  
40 -class SrsPublishPacket;  
41 -class SrsSharedPtrMessage;  
42 -class SrsOnMetaDataPacket;  
43 -  
44 -/**  
45 -* the original request from client.  
46 -*/  
47 -struct SrsRequest  
48 -{  
49 - /**  
50 - * tcUrl: rtmp://request_vhost:port/app/stream  
51 - * support pass vhost in query string, such as:  
52 - * rtmp://ip:port/app?vhost=request_vhost/stream  
53 - * rtmp://ip:port/app...vhost...request_vhost/stream  
54 - */  
55 - std::string tcUrl;  
56 - std::string pageUrl;  
57 - std::string swfUrl;  
58 - double objectEncoding;  
59 -  
60 - std::string schema;  
61 - std::string vhost;  
62 - std::string port;  
63 - std::string app;  
64 - std::string stream;  
65 -  
66 - SrsRequest();  
67 - virtual ~SrsRequest();  
68 -  
69 - /**  
70 - * deep copy the request, for source to use it to support reload,  
71 - * for when initialize the source, the request is valid,  
72 - * when reload it, the request maybe invalid, so need to copy it.  
73 - */  
74 - virtual SrsRequest* copy();  
75 -  
76 - /**  
77 - * disconvery vhost/app from tcUrl.  
78 - */  
79 - virtual int discovery_app();  
80 - virtual std::string get_stream_url();  
81 - virtual void strip();  
82 -private:  
83 - std::string& trim(std::string& str, std::string chs);  
84 -};  
85 -  
86 -/**  
87 -* the response to client.  
88 -*/  
89 -struct SrsResponse  
90 -{  
91 - int stream_id;  
92 -  
93 - SrsResponse();  
94 - virtual ~SrsResponse();  
95 -};  
96 -  
97 -/**  
98 -* the rtmp client type.  
99 -*/  
100 -enum SrsClientType  
101 -{  
102 - SrsClientUnknown,  
103 - SrsClientPlay,  
104 - SrsClientFMLEPublish,  
105 - SrsClientFlashPublish,  
106 -};  
107 -  
108 -/**  
109 -* implements the client role protocol.  
110 -*/  
111 -class SrsRtmpClient  
112 -{  
113 -protected:  
114 - SrsProtocol* protocol;  
115 - st_netfd_t stfd;  
116 -public:  
117 - SrsRtmpClient(st_netfd_t _stfd);  
118 - virtual ~SrsRtmpClient();  
119 -public:  
120 - virtual void set_recv_timeout(int64_t timeout_us);  
121 - virtual void set_send_timeout(int64_t timeout_us);  
122 - virtual int64_t get_recv_bytes();  
123 - virtual int64_t get_send_bytes();  
124 - virtual int get_recv_kbps();  
125 - virtual int get_send_kbps();  
126 - virtual int recv_message(SrsCommonMessage** pmsg);  
127 - virtual int send_message(ISrsMessage* msg);  
128 -public:  
129 - virtual int handshake();  
130 - virtual int connect_app(std::string app, std::string tc_url);  
131 - virtual int create_stream(int& stream_id);  
132 - virtual int play(std::string stream, int stream_id);  
133 - virtual int publish(std::string stream, int stream_id);  
134 -};  
135 -  
136 -/**  
137 -* the rtmp provices rtmp-command-protocol services,  
138 -* a high level protocol, media stream oriented services,  
139 -* such as connect to vhost/app, play stream, get audio/video data.  
140 -*/  
141 -class SrsRtmp  
142 -{  
143 -private:  
144 - SrsProtocol* protocol;  
145 - st_netfd_t stfd;  
146 -public:  
147 - SrsRtmp(st_netfd_t client_stfd);  
148 - virtual ~SrsRtmp();  
149 -public:  
150 - virtual SrsProtocol* get_protocol();  
151 - virtual void set_recv_timeout(int64_t timeout_us);  
152 - virtual int64_t get_recv_timeout();  
153 - virtual void set_send_timeout(int64_t timeout_us);  
154 - virtual int64_t get_send_timeout();  
155 - virtual int64_t get_recv_bytes();  
156 - virtual int64_t get_send_bytes();  
157 - virtual int get_recv_kbps();  
158 - virtual int get_send_kbps();  
159 - virtual int recv_message(SrsCommonMessage** pmsg);  
160 - virtual int send_message(ISrsMessage* msg);  
161 -public:  
162 - virtual int handshake();  
163 - virtual int connect_app(SrsRequest* req);  
164 - virtual int set_window_ack_size(int ack_size);  
165 - /**  
166 - * @type: The sender can mark this message hard (0), soft (1), or dynamic (2)  
167 - * using the Limit type field.  
168 - */  
169 - virtual int set_peer_bandwidth(int bandwidth, int type);  
170 - /**  
171 - * @param server_ip the ip of server.  
172 - */  
173 - virtual int response_connect_app(SrsRequest* req, const char* server_ip = NULL);  
174 - virtual void response_connect_reject(SrsRequest* req, const char* desc);  
175 - virtual int on_bw_done();  
176 - /**  
177 - * recv some message to identify the client.  
178 - * @stream_id, client will createStream to play or publish by flash,  
179 - * the stream_id used to response the createStream request.  
180 - * @type, output the client type.  
181 - */  
182 - virtual int identify_client(int stream_id, SrsClientType& type, std::string& stream_name);  
183 - /**  
184 - * set the chunk size when client type identified.  
185 - */  
186 - virtual int set_chunk_size(int chunk_size);  
187 - /**  
188 - * when client type is play, response with packets:  
189 - * StreamBegin,  
190 - * onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,  
191 - * |RtmpSampleAccess(false, false),  
192 - * onStatus(NetStream.Data.Start).  
193 - */  
194 - virtual int start_play(int stream_id);  
195 - /**  
196 - * when client(type is play) send pause message,  
197 - * if is_pause, response the following packets:  
198 - * onStatus(NetStream.Pause.Notify)  
199 - * StreamEOF  
200 - * if not is_pause, response the following packets:  
201 - * onStatus(NetStream.Unpause.Notify)  
202 - * StreamBegin  
203 - */  
204 - virtual int on_play_client_pause(int stream_id, bool is_pause);  
205 - /**  
206 - * when client type is publish, response with packets:  
207 - * releaseStream response  
208 - * FCPublish  
209 - * FCPublish response  
210 - * createStream response  
211 - * onFCPublish(NetStream.Publish.Start)  
212 - * onStatus(NetStream.Publish.Start)  
213 - */  
214 - virtual int start_fmle_publish(int stream_id);  
215 - /**  
216 - * process the FMLE unpublish event.  
217 - * @unpublish_tid the unpublish request transaction id.  
218 - */  
219 - virtual int fmle_unpublish(int stream_id, double unpublish_tid);  
220 - /**  
221 - * when client type is publish, response with packets:  
222 - * onStatus(NetStream.Publish.Start)  
223 - */  
224 - virtual int start_flash_publish(int stream_id);  
225 -private:  
226 - virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsClientType& type, std::string& stream_name);  
227 - virtual int identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsClientType& type, std::string& stream_name);  
228 - virtual int identify_flash_publish_client(SrsPublishPacket* req, SrsClientType& type, std::string& stream_name);  
229 -};  
230 - 1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 winlin
  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_RTMP_HPP
  25 +#define SRS_CORE_RTMP_HPP
  26 +
  27 +/*
  28 +#include <srs_core_rtmp.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +#include <string>
  34 +
  35 +class SrsProtocol;
  36 +class ISrsMessage;
  37 +class SrsCommonMessage;
  38 +class SrsCreateStreamPacket;
  39 +class SrsFMLEStartPacket;
  40 +class SrsPublishPacket;
  41 +class SrsSharedPtrMessage;
  42 +class SrsOnMetaDataPacket;
  43 +
  44 +/**
  45 +* the original request from client.
  46 +*/
  47 +struct SrsRequest
  48 +{
  49 + /**
  50 + * tcUrl: rtmp://request_vhost:port/app/stream
  51 + * support pass vhost in query string, such as:
  52 + * rtmp://ip:port/app?vhost=request_vhost/stream
  53 + * rtmp://ip:port/app...vhost...request_vhost/stream
  54 + */
  55 + std::string tcUrl;
  56 + std::string pageUrl;
  57 + std::string swfUrl;
  58 + double objectEncoding;
  59 +
  60 + std::string schema;
  61 + std::string vhost;
  62 + std::string port;
  63 + std::string app;
  64 + std::string stream;
  65 +
  66 + SrsRequest();
  67 + virtual ~SrsRequest();
  68 +
  69 + /**
  70 + * deep copy the request, for source to use it to support reload,
  71 + * for when initialize the source, the request is valid,
  72 + * when reload it, the request maybe invalid, so need to copy it.
  73 + */
  74 + virtual SrsRequest* copy();
  75 +
  76 + /**
  77 + * disconvery vhost/app from tcUrl.
  78 + */
  79 + virtual int discovery_app();
  80 + virtual std::string get_stream_url();
  81 + virtual void strip();
  82 +private:
  83 + std::string& trim(std::string& str, std::string chs);
  84 +};
  85 +
  86 +/**
  87 +* the response to client.
  88 +*/
  89 +struct SrsResponse
  90 +{
  91 + int stream_id;
  92 +
  93 + SrsResponse();
  94 + virtual ~SrsResponse();
  95 +};
  96 +
  97 +/**
  98 +* the rtmp client type.
  99 +*/
  100 +enum SrsClientType
  101 +{
  102 + SrsClientUnknown,
  103 + SrsClientPlay,
  104 + SrsClientFMLEPublish,
  105 + SrsClientFlashPublish,
  106 +};
  107 +
  108 +/**
  109 +* implements the client role protocol.
  110 +*/
  111 +class SrsRtmpClient
  112 +{
  113 +protected:
  114 + SrsProtocol* protocol;
  115 + st_netfd_t stfd;
  116 +public:
  117 + SrsRtmpClient(st_netfd_t _stfd);
  118 + virtual ~SrsRtmpClient();
  119 +public:
  120 + virtual void set_recv_timeout(int64_t timeout_us);
  121 + virtual void set_send_timeout(int64_t timeout_us);
  122 + virtual int64_t get_recv_bytes();
  123 + virtual int64_t get_send_bytes();
  124 + virtual int get_recv_kbps();
  125 + virtual int get_send_kbps();
  126 + virtual int recv_message(SrsCommonMessage** pmsg);
  127 + virtual int send_message(ISrsMessage* msg);
  128 +public:
  129 + virtual int handshake();
  130 + virtual int connect_app(std::string app, std::string tc_url);
  131 + virtual int create_stream(int& stream_id);
  132 + virtual int play(std::string stream, int stream_id);
  133 + virtual int publish(std::string stream, int stream_id);
  134 +};
  135 +
  136 +/**
  137 +* the rtmp provices rtmp-command-protocol services,
  138 +* a high level protocol, media stream oriented services,
  139 +* such as connect to vhost/app, play stream, get audio/video data.
  140 +*/
  141 +class SrsRtmp
  142 +{
  143 +private:
  144 + SrsProtocol* protocol;
  145 + st_netfd_t stfd;
  146 +public:
  147 + SrsRtmp(st_netfd_t client_stfd);
  148 + virtual ~SrsRtmp();
  149 +public:
  150 + virtual SrsProtocol* get_protocol();
  151 + virtual void set_recv_timeout(int64_t timeout_us);
  152 + virtual int64_t get_recv_timeout();
  153 + virtual void set_send_timeout(int64_t timeout_us);
  154 + virtual int64_t get_send_timeout();
  155 + virtual int64_t get_recv_bytes();
  156 + virtual int64_t get_send_bytes();
  157 + virtual int get_recv_kbps();
  158 + virtual int get_send_kbps();
  159 + virtual int recv_message(SrsCommonMessage** pmsg);
  160 + virtual int send_message(ISrsMessage* msg);
  161 +public:
  162 + virtual int handshake();
  163 + virtual int connect_app(SrsRequest* req);
  164 + virtual int set_window_ack_size(int ack_size);
  165 + /**
  166 + * @type: The sender can mark this message hard (0), soft (1), or dynamic (2)
  167 + * using the Limit type field.
  168 + */
  169 + virtual int set_peer_bandwidth(int bandwidth, int type);
  170 + /**
  171 + * @param server_ip the ip of server.
  172 + */
  173 + virtual int response_connect_app(SrsRequest* req, const char* server_ip = NULL);
  174 + virtual void response_connect_reject(SrsRequest* req, const char* desc);
  175 + virtual int on_bw_done();
  176 + /**
  177 + * recv some message to identify the client.
  178 + * @stream_id, client will createStream to play or publish by flash,
  179 + * the stream_id used to response the createStream request.
  180 + * @type, output the client type.
  181 + */
  182 + virtual int identify_client(int stream_id, SrsClientType& type, std::string& stream_name);
  183 + /**
  184 + * set the chunk size when client type identified.
  185 + */
  186 + virtual int set_chunk_size(int chunk_size);
  187 + /**
  188 + * when client type is play, response with packets:
  189 + * StreamBegin,
  190 + * onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,
  191 + * |RtmpSampleAccess(false, false),
  192 + * onStatus(NetStream.Data.Start).
  193 + */
  194 + virtual int start_play(int stream_id);
  195 + /**
  196 + * when client(type is play) send pause message,
  197 + * if is_pause, response the following packets:
  198 + * onStatus(NetStream.Pause.Notify)
  199 + * StreamEOF
  200 + * if not is_pause, response the following packets:
  201 + * onStatus(NetStream.Unpause.Notify)
  202 + * StreamBegin
  203 + */
  204 + virtual int on_play_client_pause(int stream_id, bool is_pause);
  205 + /**
  206 + * when client type is publish, response with packets:
  207 + * releaseStream response
  208 + * FCPublish
  209 + * FCPublish response
  210 + * createStream response
  211 + * onFCPublish(NetStream.Publish.Start)
  212 + * onStatus(NetStream.Publish.Start)
  213 + */
  214 + virtual int start_fmle_publish(int stream_id);
  215 + /**
  216 + * process the FMLE unpublish event.
  217 + * @unpublish_tid the unpublish request transaction id.
  218 + */
  219 + virtual int fmle_unpublish(int stream_id, double unpublish_tid);
  220 + /**
  221 + * when client type is publish, response with packets:
  222 + * onStatus(NetStream.Publish.Start)
  223 + */
  224 + virtual int start_flash_publish(int stream_id);
  225 +private:
  226 + virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsClientType& type, std::string& stream_name);
  227 + virtual int identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsClientType& type, std::string& stream_name);
  228 + virtual int identify_flash_publish_client(SrsPublishPacket* req, SrsClientType& type, std::string& stream_name);
  229 +};
  230 +
231 #endif 231 #endif
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in
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 -#include <sys/socket.h>  
25 -#include <netinet/in.h>  
26 -#include <arpa/inet.h>  
27 -#include <sstream>  
28 -#include <getopt.h>  
29 -#include <stdlib.h>  
30 -  
31 -#include <srs_core_rtmp.hpp>  
32 -#include <srs_core_protocol.hpp>  
33 -#include <srs_core_error.hpp>  
34 -#include <srs_core_amf0.hpp>  
35 -#include <srs_core_autofree.hpp>  
36 -#include <srs_core_stream.hpp>  
37 -  
38 -#include <st.h>  
39 -  
40 -// server play control  
41 -#define SRS_BW_CHECK_START_PLAY "onSrsBandCheckStartPlayBytes"  
42 -#define SRS_BW_CHECK_STARTING_PLAY "onSrsBandCheckStartingPlayBytes"  
43 -#define SRS_BW_CHECK_STOP_PLAY "onSrsBandCheckStopPlayBytes"  
44 -#define SRS_BW_CHECK_STOPPED_PLAY "onSrsBandCheckStoppedPlayBytes"  
45 -  
46 -// server publish control  
47 -#define SRS_BW_CHECK_START_PUBLISH "onSrsBandCheckStartPublishBytes"  
48 -#define SRS_BW_CHECK_STARTING_PUBLISH "onSrsBandCheckStartingPublishBytes"  
49 -#define SRS_BW_CHECK_STOP_PUBLISH "onSrsBandCheckStopPublishBytes"  
50 -#define SRS_BW_CHECK_STOPPED_PUBLISH "onSrsBandCheckStoppedPublishBytes"  
51 -  
52 -// EOF control.  
53 -#define SRS_BW_CHECK_FINISHED "onSrsBandCheckFinished"  
54 -#define SRS_BW_CHECK_FLASH_FINAL "finalClientPacket"  
55 -  
56 -// client only  
57 -#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying"  
58 -#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing"  
59 -  
60 -/**  
61 -* @brief class of Linux version band check client  
62 -* check play and publish speed.  
63 -*/  
64 -class SrsBandCheckClient : public SrsRtmpClient  
65 -{  
66 -public:  
67 - SrsBandCheckClient(st_netfd_t _stfd);  
68 - ~SrsBandCheckClient();  
69 -  
70 -public:  
71 - /**  
72 - * @brief test play  
73 - *  
74 - */  
75 - int check_play();  
76 - /**  
77 - * @brief test publish  
78 - *  
79 - */  
80 - int check_publish();  
81 -  
82 -private:  
83 - /**  
84 - * @brief just return success.  
85 - */  
86 - int create_stream(int& stream_id);  
87 - /**  
88 - * @brief just return success.  
89 - */  
90 - int play(std::string stream, int stream_id);  
91 - /**  
92 - * @brief just return success.  
93 - */  
94 - int publish(std::string stream, int stream_id);  
95 -  
96 -private:  
97 - int expect_start_play();  
98 - int send_starting_play();  
99 - int expect_stop_play();  
100 - int send_stopped_play();  
101 - int expect_start_pub();  
102 - int send_starting_pub();  
103 - int send_pub_data();  
104 - int expect_stop_pub();  
105 - /**  
106 - * @brief expect result.  
107 - * because the core module has no method to decode this packet  
108 - * so we must get the internal data and decode it here.  
109 - */  
110 - int expect_finished();  
111 - int send_stopped_pub();  
112 - /**  
113 - * @brief notify server the check procedure is over.  
114 - */  
115 - int send_final();  
116 -};  
117 -  
118 -/**  
119 -* @brief class of band check  
120 -* used to check band width with a client @param bandCheck_Client  
121 -*/  
122 -class SrsBandCheck  
123 -{  
124 -public:  
125 - SrsBandCheck();  
126 - ~SrsBandCheck();  
127 -  
128 -public:  
129 - /**  
130 - * @brief band check method  
131 - *  
132 - * connect to server------>rtmp handshake------>rtmp connect------>play------>publish  
133 - * @retval ERROR_SUCCESS when success.  
134 - */  
135 - int check(const std::string& app, const std::string& tcUrl);  
136 -  
137 - /**  
138 - * @brief set the address and port of test server  
139 - *  
140 - * @param server server address, domain or ip  
141 - * @param server listened port ,default is 1935  
142 - */  
143 - void set_server(const std::string& server, int port = 1935);  
144 -  
145 -private:  
146 - int connect_server();  
147 -  
148 -private:  
149 - SrsBandCheckClient* bandCheck_Client;  
150 - std::string server_address;  
151 - int server_port;  
152 -};  
153 -  
154 -/**  
155 -* @brief init st lib  
156 -*/  
157 -static int init_st();  
158 -static void print_help(char** argv);  
159 -static void print_version();  
160 -  
161 -/**  
162 -* @brief get user option  
163 -* @internal ip Mandatory arguments  
164 -* @internal key Mandatory arguments  
165 -* @internal port default 1935  
166 -* @internal vhost default bandcheck.srs.com  
167 -*/  
168 -static int get_opt(int argc ,char* argv[]);  
169 -  
170 -/**  
171 -* global var.  
172 -*/  
173 -static struct option long_options[] =  
174 -{  
175 - {"ip", required_argument, 0, 'i'},  
176 - {"port", optional_argument, 0, 'p'},  
177 - {"key", required_argument, 0, 'k'},  
178 - {"vhost", optional_argument, 0, 'v'},  
179 - {"help", no_argument, 0, 'h'},  
180 - {"version", no_argument, 0, 'V'},  
181 -};  
182 -  
183 -static const char* short_options = "i:p::k:v::hV";  
184 -  
185 -static std::string g_ip;  
186 -static int g_port = 1935;  
187 -static std::string g_key;  
188 -static std::string g_vhost = "bandcheck.srs.com";  
189 -  
190 -#define BUILD_VERSION "srs band check 0.1"  
191 -  
192 -int main(int argc ,char* argv[])  
193 -{  
194 - int ret = ERROR_SUCCESS;  
195 -  
196 - if (argc <= 1) {  
197 - print_help(argv);  
198 - exit(1);  
199 - }  
200 -  
201 - if ((ret = get_opt(argc, argv)) != ERROR_SUCCESS) {  
202 - return -1;  
203 - }  
204 -  
205 - // check param  
206 - if (g_ip.empty()) {  
207 - printf("ip address should not be empty.\n");  
208 - return -1;  
209 - }  
210 -  
211 - if (g_key.empty()) {  
212 - printf("test key should not be empty.\n");  
213 - return -1;  
214 - }  
215 -  
216 - if ((ret = init_st()) != ERROR_SUCCESS) {  
217 - srs_error("band check init failed. ret=%d", ret);  
218 - return ret;  
219 - }  
220 -  
221 - std::string app = "app?key=" + g_key + "&vhost=" + g_vhost;  
222 -  
223 - char tcUrl_buffer[1024] = {0};  
224 - sprintf(tcUrl_buffer, "rtmp://%s:%d/%s", g_ip.c_str(), g_port, app.c_str());  
225 - std::string tcUrl = tcUrl_buffer;  
226 -  
227 - SrsBandCheck band_check;  
228 - band_check.set_server(g_ip, g_port);  
229 - if ((ret = band_check.check(app, tcUrl)) != ERROR_SUCCESS) {  
230 - srs_error("band check failed. address=%s ret=%d", "xx.com", ret);  
231 - return -1;  
232 - }  
233 -  
234 - return 0;  
235 -}  
236 -  
237 -SrsBandCheckClient::SrsBandCheckClient(st_netfd_t _stfd)  
238 - : SrsRtmpClient(_stfd)  
239 -{  
240 -}  
241 -  
242 -SrsBandCheckClient::~SrsBandCheckClient()  
243 -{  
244 -}  
245 -  
246 -int SrsBandCheckClient::check_play()  
247 -{  
248 - int ret = ERROR_SUCCESS;  
249 -  
250 - if ((ret = expect_start_play()) != ERROR_SUCCESS) {  
251 - srs_error("expect_start_play failed. ret=%d", ret);  
252 - return ret;  
253 - }  
254 -  
255 - if ((ret = send_starting_play()) != ERROR_SUCCESS) {  
256 - srs_error("send starting play failed. ret=%d", ret);  
257 - return ret;  
258 - }  
259 -  
260 - if ((ret = expect_stop_play()) != ERROR_SUCCESS) {  
261 - srs_error("expect stop play failed. ret=%d", ret);  
262 - return ret;  
263 - }  
264 -  
265 - if ((ret = send_stopped_play()) != ERROR_SUCCESS) {  
266 - srs_error("send stopped play failed. ret=%d", ret);  
267 - return ret;  
268 - }  
269 -  
270 - return ret;  
271 -}  
272 -  
273 -int SrsBandCheckClient::check_publish()  
274 -{  
275 - int ret = ERROR_SUCCESS;  
276 -  
277 - if ((ret = expect_start_pub()) != ERROR_SUCCESS) {  
278 - srs_error("expect start pub failed. ret=%d", ret);  
279 - return ret;  
280 - }  
281 -  
282 - if ((ret = send_starting_pub())!= ERROR_SUCCESS) {  
283 - srs_error("send starting pub failed. ret=%d", ret);  
284 - return ret;  
285 - }  
286 -  
287 - if ((ret = send_pub_data()) != ERROR_SUCCESS) {  
288 - srs_error("publish data failed. ret=%d", ret);  
289 - return ret;  
290 - }  
291 -  
292 - if ((ret = send_stopped_pub()) != ERROR_SUCCESS) {  
293 - srs_error("send stopped pub failed. ret=%d", ret);  
294 - return ret;  
295 - }  
296 -  
297 - if ((ret = expect_finished()) != ERROR_SUCCESS) {  
298 - srs_error("expect finished msg failed. ret=%d", ret);  
299 - return ret;  
300 - }  
301 -  
302 - if ((ret = send_final()) != ERROR_SUCCESS) {  
303 - srs_error("send final msg failed. ret=%d", ret);  
304 - return ret;  
305 - }  
306 -  
307 - return ret;  
308 -}  
309 -  
310 -int SrsBandCheckClient::create_stream(int &stream_id)  
311 -{  
312 - return ERROR_SUCCESS;  
313 -}  
314 -  
315 -int SrsBandCheckClient::play(std::string stream, int stream_id)  
316 -{  
317 - return ERROR_SUCCESS;  
318 -}  
319 -  
320 -int SrsBandCheckClient::publish(std::string stream, int stream_id)  
321 -{  
322 - return ERROR_SUCCESS;  
323 -}  
324 -  
325 -int SrsBandCheckClient::expect_start_play()  
326 -{  
327 - int ret = ERROR_SUCCESS;  
328 -  
329 - // expect connect _result  
330 - SrsCommonMessage* msg = NULL;  
331 - SrsBandwidthPacket* pkt = NULL;  
332 - if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {  
333 - srs_error("expect bandcheck start play message failed. ret=%d", ret);  
334 - return ret;  
335 - }  
336 - SrsAutoFree(SrsCommonMessage, msg, false);  
337 - srs_info("get bandcheck start play message");  
338 -  
339 - if (pkt->command_name != SRS_BW_CHECK_START_PLAY) {  
340 - srs_error("pkt error. expect=%s, actual=%s", SRS_BW_CHECK_START_PLAY, pkt->command_name.c_str());  
341 - return -1;  
342 - }  
343 -  
344 - return ret;  
345 -}  
346 -  
347 -int SrsBandCheckClient::send_starting_play()  
348 -{  
349 - int ret = ERROR_SUCCESS;  
350 -  
351 - SrsCommonMessage* msg = new SrsCommonMessage;  
352 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
353 - pkt->command_name = SRS_BW_CHECK_STARTING_PLAY;  
354 - msg->set_packet(pkt, 0);  
355 -  
356 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
357 - srs_error("send starting play msg failed. ret=%d", ret);  
358 - return ret;  
359 - }  
360 -  
361 - return ret;  
362 -}  
363 -  
364 -int SrsBandCheckClient::expect_stop_play()  
365 -{  
366 - int ret = ERROR_SUCCESS;  
367 -  
368 - while (true) {  
369 - SrsCommonMessage* msg = NULL;  
370 - SrsBandwidthPacket* pkt = NULL;  
371 - if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {  
372 - srs_error("expect stop play message failed. ret=%d", ret);  
373 - return ret;  
374 - }  
375 - SrsAutoFree(SrsCommonMessage, msg, false);  
376 - srs_info("get bandcheck stop play message");  
377 -  
378 - if (pkt->command_name == SRS_BW_CHECK_STOP_PLAY) {  
379 - break;  
380 - }  
381 - }  
382 -  
383 - return ret;  
384 -}  
385 -  
386 -int SrsBandCheckClient::send_stopped_play()  
387 -{  
388 - int ret = ERROR_SUCCESS;  
389 -  
390 - SrsCommonMessage* msg = new SrsCommonMessage;  
391 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
392 - pkt->command_name = SRS_BW_CHECK_STOPPED_PLAY;  
393 - msg->set_packet(pkt, 0);  
394 -  
395 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
396 - srs_error("send stopped play msg failed. ret=%d", ret);  
397 - return ret;  
398 - }  
399 -  
400 - return ret;  
401 -}  
402 -  
403 -int SrsBandCheckClient::expect_start_pub()  
404 -{  
405 - int ret = ERROR_SUCCESS;  
406 -  
407 - while (true) {  
408 - SrsCommonMessage* msg = NULL;  
409 - SrsBandwidthPacket* pkt = NULL;  
410 - if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {  
411 - srs_error("expect start pub message failed. ret=%d", ret);  
412 - return ret;  
413 - }  
414 - SrsAutoFree(SrsCommonMessage, msg, false);  
415 - srs_info("get bandcheck start pub message");  
416 -  
417 - if (pkt->command_name == SRS_BW_CHECK_START_PUBLISH) {  
418 - break;  
419 - }  
420 - }  
421 -  
422 - return ret;  
423 -}  
424 -  
425 -int SrsBandCheckClient::send_starting_pub()  
426 -{  
427 - int ret = ERROR_SUCCESS;  
428 -  
429 - SrsCommonMessage* msg = new SrsCommonMessage;  
430 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
431 - pkt->command_name = SRS_BW_CHECK_STARTING_PUBLISH;  
432 - msg->set_packet(pkt, 0);  
433 -  
434 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
435 - srs_error("send starting play msg failed. ret=%d", ret);  
436 - return ret;  
437 - }  
438 - srs_info("send starting play msg success.");  
439 -  
440 - return ret;  
441 -}  
442 -  
443 -int SrsBandCheckClient::send_pub_data()  
444 -{  
445 - int ret = ERROR_SUCCESS;  
446 -  
447 - int data_count = 100;  
448 - while (true) {  
449 - SrsCommonMessage* msg = new SrsCommonMessage;  
450 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
451 - pkt->command_name = SRS_BW_CHECK_PUBLISHING;  
452 - msg->set_packet(pkt, 0);  
453 -  
454 - for (int i = 0; i < data_count; ++i) {  
455 - std::stringstream seq;  
456 - seq << i;  
457 - std::string play_data = "SrS band check data from client's publishing......";  
458 - pkt->data->set(seq.str(), new SrsAmf0String(play_data.c_str()));  
459 - }  
460 - data_count += 100;  
461 -  
462 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
463 - srs_error("send publish message failed.ret=%d", ret);  
464 - return ret;  
465 - }  
466 -  
467 - if ((ret = expect_stop_pub()) == ERROR_SUCCESS) {  
468 - break;  
469 - }  
470 - }  
471 -  
472 - return ret;  
473 -}  
474 -  
475 -int SrsBandCheckClient::expect_stop_pub()  
476 -{  
477 - int ret = ERROR_SUCCESS;  
478 -  
479 - while (true) {  
480 - if ((ret = st_netfd_poll(stfd, POLLIN, 1000)) == ERROR_SUCCESS) {  
481 - SrsCommonMessage* msg = 0;  
482 - if ((ret = recv_message(&msg)) != ERROR_SUCCESS)  
483 - {  
484 - srs_error("recv message failed while expect stop pub. ret=%d", ret);  
485 - return ret;  
486 - }  
487 -  
488 - if ((ret = msg->decode_packet(protocol)) != ERROR_SUCCESS) {  
489 - srs_error("decode packet error while expect stop pub. ret=%d", ret);  
490 - return ret;  
491 - }  
492 -  
493 - SrsBandwidthPacket* pkt = dynamic_cast<SrsBandwidthPacket*>(msg->get_packet());  
494 - if (pkt && pkt->command_name == SRS_BW_CHECK_STOP_PUBLISH) {  
495 -  
496 - return ret;  
497 - }  
498 - } else {  
499 - break;  
500 - }  
501 - }  
502 -  
503 - return ret;  
504 -}  
505 -  
506 -int SrsBandCheckClient::expect_finished()  
507 -{  
508 - int ret = ERROR_SUCCESS;  
509 -  
510 - while (true) {  
511 - SrsCommonMessage* msg = NULL;  
512 - SrsBandwidthPacket* pkt = NULL;  
513 - if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {  
514 - srs_error("expect finished message failed. ret=%d", ret);  
515 - return ret;  
516 - }  
517 - SrsAutoFree(SrsCommonMessage, msg, false);  
518 - srs_info("get bandcheck finished message");  
519 -  
520 - if (pkt->command_name == SRS_BW_CHECK_FINISHED) {  
521 - SrsStream *stream = new SrsStream;  
522 - SrsAutoFree(SrsStream, stream, false);  
523 -  
524 - if ((ret = stream->initialize((char*)msg->payload, msg->size)) != ERROR_SUCCESS) {  
525 - srs_error("initialize stream error. ret=%d", ret);  
526 - return ret;  
527 - }  
528 -  
529 - std::string command_name;  
530 - if ((ret = srs_amf0_read_string(stream, command_name)) != ERROR_SUCCESS) {  
531 - srs_error("amfo read string error. ret=%d", ret);  
532 - return ret;  
533 - }  
534 -  
535 - double action_id;  
536 - if ((ret = srs_amf0_read_number(stream, action_id)) != ERROR_SUCCESS) {  
537 - srs_error("amfo read number error. ret=%d", ret);  
538 - return ret;  
539 - }  
540 -  
541 - if ((ret = srs_amf0_read_null(stream)) != ERROR_SUCCESS) {  
542 - srs_error("amfo read number error. ret=%d", ret);  
543 - return ret;  
544 - }  
545 -  
546 - SrsAmf0Object* object;  
547 - if ((ret = srs_amf0_read_object(stream, object)) != ERROR_SUCCESS) {  
548 - srs_error("amfo read object error. ret=%d", ret);  
549 - return ret;  
550 - }  
551 -  
552 - int64_t start_time = 0;  
553 - int64_t end_time = 0;  
554 -  
555 - SrsAmf0Any* start_time_any = object->get_property("start_time");  
556 - if (start_time_any && start_time_any->is_number()) {  
557 - SrsAmf0Number* start_time_number = dynamic_cast<SrsAmf0Number*> (start_time_any);  
558 - if (start_time_number) {  
559 - start_time = start_time_number->value;  
560 - }  
561 - }  
562 -  
563 - SrsAmf0Any* end_time_any = object->get_property("end_time");  
564 - if (end_time_any && end_time_any->is_number()) {  
565 - SrsAmf0Number* end_time_number = dynamic_cast<SrsAmf0Number*> (end_time_any);  
566 - if (end_time_number) {  
567 - end_time = end_time_number->value;  
568 - }  
569 - }  
570 -  
571 - int play_kbps = 0;  
572 - int pub_kbps = 0;  
573 - SrsAmf0Any* play_kbp_any = object->get_property("play_kbps");  
574 - if (play_kbp_any && play_kbp_any->is_number()) {  
575 - SrsAmf0Number* play_kbps_number = dynamic_cast<SrsAmf0Number*> (play_kbp_any);  
576 - if (play_kbps_number) {  
577 - play_kbps = play_kbps_number->value;  
578 - }  
579 - }  
580 -  
581 - SrsAmf0Any* pub_kbp_any = object->get_property("publish_kbps");  
582 - if (pub_kbp_any && pub_kbp_any->is_number()) {  
583 - SrsAmf0Number* pub_kbps_number = dynamic_cast<SrsAmf0Number*> (pub_kbp_any);  
584 - if (pub_kbps_number) {  
585 - pub_kbps = pub_kbps_number->value;  
586 - }  
587 - }  
588 -  
589 - float time_elapsed;  
590 - if (end_time - start_time > 0) {  
591 - time_elapsed = (end_time - start_time) / 1000.00;  
592 - }  
593 -  
594 - srs_trace("result: play %d kbps, publish %d kbps, check time %.4f S\n"  
595 - , play_kbps, pub_kbps, time_elapsed);  
596 -  
597 - break;  
598 - }  
599 - }  
600 -  
601 - return ret;  
602 -}  
603 -  
604 -int SrsBandCheckClient::send_stopped_pub()  
605 -{  
606 - int ret = ERROR_SUCCESS;  
607 -  
608 - SrsCommonMessage* msg = new SrsCommonMessage;  
609 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
610 - pkt->command_name = SRS_BW_CHECK_STOPPED_PUBLISH;  
611 - msg->set_packet(pkt, 0);  
612 -  
613 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
614 - srs_error("send stopped pub msg failed. ret=%d", ret);  
615 - return ret;  
616 - }  
617 - srs_info("send stopped pub msg success.");  
618 -  
619 - return ret;  
620 -}  
621 -  
622 -int SrsBandCheckClient::send_final()  
623 -{  
624 - int ret = ERROR_SUCCESS;  
625 -  
626 - SrsCommonMessage* msg = new SrsCommonMessage;  
627 - SrsBandwidthPacket* pkt = new SrsBandwidthPacket;  
628 - pkt->command_name = SRS_BW_CHECK_FLASH_FINAL;  
629 - msg->set_packet(pkt, 0);  
630 -  
631 - if ((ret = send_message(msg)) != ERROR_SUCCESS) {  
632 - srs_error("send final msg failed. ret=%d", ret);  
633 - return ret;  
634 - }  
635 - srs_info("send final msg success.");  
636 -  
637 - return ret;  
638 -}  
639 -  
640 -SrsBandCheck::SrsBandCheck()  
641 - : bandCheck_Client(0)  
642 -{  
643 -}  
644 -  
645 -SrsBandCheck::~SrsBandCheck()  
646 -{  
647 - if (bandCheck_Client) {  
648 - srs_freep(bandCheck_Client);  
649 - }  
650 -}  
651 -  
652 -int SrsBandCheck::check(const std::string &app, const std::string &tcUrl)  
653 -{  
654 - int ret = ERROR_SUCCESS;  
655 -  
656 - if ((ret = connect_server()) != ERROR_SUCCESS) {  
657 - srs_error("connect to server failed. ret = %d", ret);  
658 - return ret;  
659 - }  
660 -  
661 - if ((ret = bandCheck_Client->handshake()) != ERROR_SUCCESS) {  
662 - srs_error("handshake failed. ret = %d", ret);  
663 - return ret;  
664 - }  
665 -  
666 - if ((ret = bandCheck_Client->connect_app(app, tcUrl)) != ERROR_SUCCESS) {  
667 - srs_error("handshake failed. ret = %d", ret);  
668 - return ret;  
669 - }  
670 -  
671 - if ((ret = bandCheck_Client->check_play()) != ERROR_SUCCESS) {  
672 - srs_error("band check play failed.");  
673 - return ret;  
674 - }  
675 -  
676 - if ((ret = bandCheck_Client->check_publish()) != ERROR_SUCCESS) {  
677 - srs_error("band check publish failed.");  
678 - return ret;  
679 - }  
680 -  
681 - return ret;  
682 -}  
683 -  
684 -void SrsBandCheck::set_server(const std::string &server, int port)  
685 -{  
686 - server_address = server;  
687 - server_port = port;  
688 -}  
689 -  
690 -int SrsBandCheck::connect_server()  
691 -{  
692 - int ret = ERROR_SUCCESS;  
693 -  
694 - int sock = socket(AF_INET, SOCK_STREAM, 0);  
695 - if(sock == -1){  
696 - ret = ERROR_SOCKET_CREATE;  
697 - srs_error("create socket error. ret=%d", ret);  
698 - return ret;  
699 - }  
700 -  
701 - st_netfd_t stfd = st_netfd_open_socket(sock);  
702 - if(stfd == NULL){  
703 - ret = ERROR_ST_OPEN_SOCKET;  
704 - srs_error("st_netfd_open_socket failed. ret=%d", ret);  
705 - return ret;  
706 - }  
707 -  
708 - bandCheck_Client = new SrsBandCheckClient(stfd);  
709 -  
710 - // connect to server.  
711 - std::string ip = srs_dns_resolve(server_address);  
712 - if (ip.empty()) {  
713 - ret = ERROR_SYSTEM_IP_INVALID;  
714 - srs_error("dns resolve server error, ip empty. ret=%d", ret);  
715 - return ret;  
716 - }  
717 -  
718 - sockaddr_in addr;  
719 - addr.sin_family = AF_INET;  
720 - addr.sin_port = htons(server_port);  
721 - addr.sin_addr.s_addr = inet_addr(ip.c_str());  
722 -  
723 - if (st_connect(stfd, (const struct sockaddr*)&addr, sizeof(sockaddr_in), ST_UTIME_NO_TIMEOUT) == -1){  
724 - ret = ERROR_ST_CONNECT;  
725 - srs_error("connect to server error. ip=%s, port=%d, ret=%d", ip.c_str(), server_port, ret);  
726 - return ret;  
727 - }  
728 - srs_trace("connect to server success. server=%s, ip=%s, port=%d", server_address.c_str(), ip.c_str(), server_port);  
729 -  
730 - return ret;  
731 -}  
732 -  
733 -int init_st()  
734 -{  
735 - int ret = ERROR_SUCCESS;  
736 -  
737 - if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {  
738 - ret = ERROR_ST_SET_EPOLL;  
739 - srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);  
740 - return ret;  
741 - }  
742 -  
743 - if(st_init() != 0){  
744 - ret = ERROR_ST_INITIALIZE;  
745 - srs_error("st_init failed. ret=%d", ret);  
746 - return ret;  
747 - }  
748 -  
749 - return ret;  
750 -}  
751 -  
752 -void print_help(char** argv)  
753 -{  
754 - printf(  
755 - "Usage: %s [OPTION]...\n"  
756 - "test band width from client to rtmp server.\n"  
757 - "Mandatory arguments to long options are mandatory for short options too.\n"  
758 - " -i, --ip the ip or domain that to test\n"  
759 - " -p, --port the port that server listen \n"  
760 - " -k, --key the key used to test \n"  
761 - " -v, --vhost the vhost used to test \n"  
762 - " -V, --version output version information and exit \n"  
763 - " -h, --help display this help and exit \n"  
764 - "\n"  
765 - "For example:\n"  
766 - " %s -i 192.168.1.248 -p 1935 -v bandcheck.srs.com -k 35c9b402c12a7246868752e2878f7e0e"  
767 - "\n\n"  
768 - "Exit status:\n"  
769 - "0 if OK,\n"  
770 - "other if error occured, and the detail should be printed.\n"  
771 - "\n\n"  
772 - "srs home page: <http://blog.chinaunix.net/uid/25006789.html>\n",  
773 - argv[0], argv[0]);  
774 -}  
775 -  
776 -void print_version()  
777 -{  
778 - const char *version = ""  
779 - "srs_bandcheck "BUILD_VERSION"\n"  
780 - "Copyright (C) 2013 wenjiegit.\n"  
781 - "License MIT\n"  
782 - "This is free software: you are free to change and redistribute it.\n"  
783 - "There is NO WARRANTY, to the extent permitted by law.\n"  
784 - "\n"  
785 - "Written by wenjie.\n";  
786 -  
787 - printf("%s", version);  
788 -}  
789 -  
790 -int get_opt(int argc, char *argv[])  
791 -{  
792 - int ret = ERROR_SUCCESS;  
793 -  
794 - int c;  
795 - while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) {  
796 - switch (c) {  
797 - case 'i':  
798 - if (optarg) {  
799 - g_ip = optarg;  
800 - }  
801 - break;  
802 - case 'p':  
803 - if (optarg) {  
804 - g_port = atoi(optarg);  
805 - }  
806 - break;  
807 - case 'k':  
808 - if (optarg) {  
809 - g_key = optarg;  
810 - }  
811 - break;  
812 - case 'v':  
813 - if (optarg) {  
814 - g_vhost = optarg;  
815 - }  
816 - break;  
817 - case 'V':  
818 - print_version();  
819 - exit(0);  
820 - break;  
821 - case 'h':  
822 - print_help(argv);  
823 - exit(0);  
824 - break;  
825 - default:  
826 - printf("see --help or -h\n");  
827 - ret = -1;  
828 - }  
829 - }  
830 -  
831 - return ret;  
832 -} 1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2014 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 +#include <sys/socket.h>
  25 +#include <netinet/in.h>
  26 +#include <arpa/inet.h>
  27 +#include <sstream>
  28 +#include <getopt.h>
  29 +#include <stdlib.h>
  30 +
  31 +#include <srs_core_rtmp.hpp>
  32 +#include <srs_core_protocol.hpp>
  33 +#include <srs_core_error.hpp>
  34 +#include <srs_core_amf0.hpp>
  35 +#include <srs_core_autofree.hpp>
  36 +#include <srs_core_stream.hpp>
  37 +
  38 +#include <st.h>
  39 +
  40 +// server play control
  41 +#define SRS_BW_CHECK_START_PLAY "onSrsBandCheckStartPlayBytes"
  42 +#define SRS_BW_CHECK_STARTING_PLAY "onSrsBandCheckStartingPlayBytes"
  43 +#define SRS_BW_CHECK_STOP_PLAY "onSrsBandCheckStopPlayBytes"
  44 +#define SRS_BW_CHECK_STOPPED_PLAY "onSrsBandCheckStoppedPlayBytes"
  45 +
  46 +// server publish control
  47 +#define SRS_BW_CHECK_START_PUBLISH "onSrsBandCheckStartPublishBytes"
  48 +#define SRS_BW_CHECK_STARTING_PUBLISH "onSrsBandCheckStartingPublishBytes"
  49 +#define SRS_BW_CHECK_STOP_PUBLISH "onSrsBandCheckStopPublishBytes"
  50 +#define SRS_BW_CHECK_STOPPED_PUBLISH "onSrsBandCheckStoppedPublishBytes"
  51 +
  52 +// EOF control.
  53 +#define SRS_BW_CHECK_FINISHED "onSrsBandCheckFinished"
  54 +#define SRS_BW_CHECK_FLASH_FINAL "finalClientPacket"
  55 +
  56 +// client only
  57 +#define SRS_BW_CHECK_PLAYING "onSrsBandCheckPlaying"
  58 +#define SRS_BW_CHECK_PUBLISHING "onSrsBandCheckPublishing"
  59 +
  60 +/**
  61 +* @brief class of Linux version band check client
  62 +* check play and publish speed.
  63 +*/
  64 +class SrsBandCheckClient : public SrsRtmpClient
  65 +{
  66 +public:
  67 + SrsBandCheckClient(st_netfd_t _stfd);
  68 + ~SrsBandCheckClient();
  69 +
  70 +public:
  71 + /**
  72 + * @brief test play
  73 + *
  74 + */
  75 + int check_play();
  76 + /**
  77 + * @brief test publish
  78 + *
  79 + */
  80 + int check_publish();
  81 +
  82 +private:
  83 + /**
  84 + * @brief just return success.
  85 + */
  86 + int create_stream(int& stream_id);
  87 + /**
  88 + * @brief just return success.
  89 + */
  90 + int play(std::string stream, int stream_id);
  91 + /**
  92 + * @brief just return success.
  93 + */
  94 + int publish(std::string stream, int stream_id);
  95 +
  96 +private:
  97 + int expect_start_play();
  98 + int send_starting_play();
  99 + int expect_stop_play();
  100 + int send_stopped_play();
  101 + int expect_start_pub();
  102 + int send_starting_pub();
  103 + int send_pub_data();
  104 + int expect_stop_pub();
  105 + /**
  106 + * @brief expect result.
  107 + * because the core module has no method to decode this packet
  108 + * so we must get the internal data and decode it here.
  109 + */
  110 + int expect_finished();
  111 + int send_stopped_pub();
  112 + /**
  113 + * @brief notify server the check procedure is over.
  114 + */
  115 + int send_final();
  116 +};
  117 +
  118 +/**
  119 +* @brief class of band check
  120 +* used to check band width with a client @param bandCheck_Client
  121 +*/
  122 +class SrsBandCheck
  123 +{
  124 +public:
  125 + SrsBandCheck();
  126 + ~SrsBandCheck();
  127 +
  128 +public:
  129 + /**
  130 + * @brief band check method
  131 + *
  132 + * connect to server------>rtmp handshake------>rtmp connect------>play------>publish
  133 + * @retval ERROR_SUCCESS when success.
  134 + */
  135 + int check(const std::string& app, const std::string& tcUrl);
  136 +
  137 + /**
  138 + * @brief set the address and port of test server
  139 + *
  140 + * @param server server address, domain or ip
  141 + * @param server listened port ,default is 1935
  142 + */
  143 + void set_server(const std::string& server, int port = 1935);
  144 +
  145 +private:
  146 + int connect_server();
  147 +
  148 +private:
  149 + SrsBandCheckClient* bandCheck_Client;
  150 + std::string server_address;
  151 + int server_port;
  152 +};
  153 +
  154 +/**
  155 +* @brief init st lib
  156 +*/
  157 +static int init_st();
  158 +static void print_help(char** argv);
  159 +static void print_version();
  160 +
  161 +/**
  162 +* @brief get user option
  163 +* @internal ip Mandatory arguments
  164 +* @internal key Mandatory arguments
  165 +* @internal port default 1935
  166 +* @internal vhost default bandcheck.srs.com
  167 +*/
  168 +static int get_opt(int argc ,char* argv[]);
  169 +
  170 +/**
  171 +* global var.
  172 +*/
  173 +static struct option long_options[] =
  174 +{
  175 + {"ip", required_argument, 0, 'i'},
  176 + {"port", optional_argument, 0, 'p'},
  177 + {"key", required_argument, 0, 'k'},
  178 + {"vhost", optional_argument, 0, 'v'},
  179 + {"help", no_argument, 0, 'h'},
  180 + {"version", no_argument, 0, 'V'},
  181 +};
  182 +
  183 +static const char* short_options = "i:p::k:v::hV";
  184 +
  185 +static std::string g_ip;
  186 +static int g_port = 1935;
  187 +static std::string g_key;
  188 +static std::string g_vhost = "bandcheck.srs.com";
  189 +
  190 +#define BUILD_VERSION "srs band check 0.1"
  191 +
  192 +int main(int argc ,char* argv[])
  193 +{
  194 + int ret = ERROR_SUCCESS;
  195 +
  196 + if (argc <= 1) {
  197 + print_help(argv);
  198 + exit(1);
  199 + }
  200 +
  201 + if ((ret = get_opt(argc, argv)) != ERROR_SUCCESS) {
  202 + return -1;
  203 + }
  204 +
  205 + // check param
  206 + if (g_ip.empty()) {
  207 + printf("ip address should not be empty.\n");
  208 + return -1;
  209 + }
  210 +
  211 + if (g_key.empty()) {
  212 + printf("test key should not be empty.\n");
  213 + return -1;
  214 + }
  215 +
  216 + if ((ret = init_st()) != ERROR_SUCCESS) {
  217 + srs_error("band check init failed. ret=%d", ret);
  218 + return ret;
  219 + }
  220 +
  221 + std::string app = "app?key=" + g_key + "&vhost=" + g_vhost;
  222 +
  223 + char tcUrl_buffer[1024] = {0};
  224 + sprintf(tcUrl_buffer, "rtmp://%s:%d/%s", g_ip.c_str(), g_port, app.c_str());
  225 + std::string tcUrl = tcUrl_buffer;
  226 +
  227 + SrsBandCheck band_check;
  228 + band_check.set_server(g_ip, g_port);
  229 + if ((ret = band_check.check(app, tcUrl)) != ERROR_SUCCESS) {
  230 + srs_error("band check failed. address=%s ret=%d", "xx.com", ret);
  231 + return -1;
  232 + }
  233 +
  234 + return 0;
  235 +}
  236 +
  237 +SrsBandCheckClient::SrsBandCheckClient(st_netfd_t _stfd)
  238 + : SrsRtmpClient(_stfd)
  239 +{
  240 +}
  241 +
  242 +SrsBandCheckClient::~SrsBandCheckClient()
  243 +{
  244 +}
  245 +
  246 +int SrsBandCheckClient::check_play()
  247 +{
  248 + int ret = ERROR_SUCCESS;
  249 +
  250 + if ((ret = expect_start_play()) != ERROR_SUCCESS) {
  251 + srs_error("expect_start_play failed. ret=%d", ret);
  252 + return ret;
  253 + }
  254 +
  255 + if ((ret = send_starting_play()) != ERROR_SUCCESS) {
  256 + srs_error("send starting play failed. ret=%d", ret);
  257 + return ret;
  258 + }
  259 +
  260 + if ((ret = expect_stop_play()) != ERROR_SUCCESS) {
  261 + srs_error("expect stop play failed. ret=%d", ret);
  262 + return ret;
  263 + }
  264 +
  265 + if ((ret = send_stopped_play()) != ERROR_SUCCESS) {
  266 + srs_error("send stopped play failed. ret=%d", ret);
  267 + return ret;
  268 + }
  269 +
  270 + return ret;
  271 +}
  272 +
  273 +int SrsBandCheckClient::check_publish()
  274 +{
  275 + int ret = ERROR_SUCCESS;
  276 +
  277 + if ((ret = expect_start_pub()) != ERROR_SUCCESS) {
  278 + srs_error("expect start pub failed. ret=%d", ret);
  279 + return ret;
  280 + }
  281 +
  282 + if ((ret = send_starting_pub())!= ERROR_SUCCESS) {
  283 + srs_error("send starting pub failed. ret=%d", ret);
  284 + return ret;
  285 + }
  286 +
  287 + if ((ret = send_pub_data()) != ERROR_SUCCESS) {
  288 + srs_error("publish data failed. ret=%d", ret);
  289 + return ret;
  290 + }
  291 +
  292 + if ((ret = send_stopped_pub()) != ERROR_SUCCESS) {
  293 + srs_error("send stopped pub failed. ret=%d", ret);
  294 + return ret;
  295 + }
  296 +
  297 + if ((ret = expect_finished()) != ERROR_SUCCESS) {
  298 + srs_error("expect finished msg failed. ret=%d", ret);
  299 + return ret;
  300 + }
  301 +
  302 + if ((ret = send_final()) != ERROR_SUCCESS) {
  303 + srs_error("send final msg failed. ret=%d", ret);
  304 + return ret;
  305 + }
  306 +
  307 + return ret;
  308 +}
  309 +
  310 +int SrsBandCheckClient::create_stream(int &stream_id)
  311 +{
  312 + return ERROR_SUCCESS;
  313 +}
  314 +
  315 +int SrsBandCheckClient::play(std::string stream, int stream_id)
  316 +{
  317 + return ERROR_SUCCESS;
  318 +}
  319 +
  320 +int SrsBandCheckClient::publish(std::string stream, int stream_id)
  321 +{
  322 + return ERROR_SUCCESS;
  323 +}
  324 +
  325 +int SrsBandCheckClient::expect_start_play()
  326 +{
  327 + int ret = ERROR_SUCCESS;
  328 +
  329 + // expect connect _result
  330 + SrsCommonMessage* msg = NULL;
  331 + SrsBandwidthPacket* pkt = NULL;
  332 + if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
  333 + srs_error("expect bandcheck start play message failed. ret=%d", ret);
  334 + return ret;
  335 + }
  336 + SrsAutoFree(SrsCommonMessage, msg, false);
  337 + srs_info("get bandcheck start play message");
  338 +
  339 + if (pkt->command_name != SRS_BW_CHECK_START_PLAY) {
  340 + srs_error("pkt error. expect=%s, actual=%s", SRS_BW_CHECK_START_PLAY, pkt->command_name.c_str());
  341 + return -1;
  342 + }
  343 +
  344 + return ret;
  345 +}
  346 +
  347 +int SrsBandCheckClient::send_starting_play()
  348 +{
  349 + int ret = ERROR_SUCCESS;
  350 +
  351 + SrsCommonMessage* msg = new SrsCommonMessage;
  352 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  353 + pkt->command_name = SRS_BW_CHECK_STARTING_PLAY;
  354 + msg->set_packet(pkt, 0);
  355 +
  356 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  357 + srs_error("send starting play msg failed. ret=%d", ret);
  358 + return ret;
  359 + }
  360 +
  361 + return ret;
  362 +}
  363 +
  364 +int SrsBandCheckClient::expect_stop_play()
  365 +{
  366 + int ret = ERROR_SUCCESS;
  367 +
  368 + while (true) {
  369 + SrsCommonMessage* msg = NULL;
  370 + SrsBandwidthPacket* pkt = NULL;
  371 + if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
  372 + srs_error("expect stop play message failed. ret=%d", ret);
  373 + return ret;
  374 + }
  375 + SrsAutoFree(SrsCommonMessage, msg, false);
  376 + srs_info("get bandcheck stop play message");
  377 +
  378 + if (pkt->command_name == SRS_BW_CHECK_STOP_PLAY) {
  379 + break;
  380 + }
  381 + }
  382 +
  383 + return ret;
  384 +}
  385 +
  386 +int SrsBandCheckClient::send_stopped_play()
  387 +{
  388 + int ret = ERROR_SUCCESS;
  389 +
  390 + SrsCommonMessage* msg = new SrsCommonMessage;
  391 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  392 + pkt->command_name = SRS_BW_CHECK_STOPPED_PLAY;
  393 + msg->set_packet(pkt, 0);
  394 +
  395 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  396 + srs_error("send stopped play msg failed. ret=%d", ret);
  397 + return ret;
  398 + }
  399 +
  400 + return ret;
  401 +}
  402 +
  403 +int SrsBandCheckClient::expect_start_pub()
  404 +{
  405 + int ret = ERROR_SUCCESS;
  406 +
  407 + while (true) {
  408 + SrsCommonMessage* msg = NULL;
  409 + SrsBandwidthPacket* pkt = NULL;
  410 + if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
  411 + srs_error("expect start pub message failed. ret=%d", ret);
  412 + return ret;
  413 + }
  414 + SrsAutoFree(SrsCommonMessage, msg, false);
  415 + srs_info("get bandcheck start pub message");
  416 +
  417 + if (pkt->command_name == SRS_BW_CHECK_START_PUBLISH) {
  418 + break;
  419 + }
  420 + }
  421 +
  422 + return ret;
  423 +}
  424 +
  425 +int SrsBandCheckClient::send_starting_pub()
  426 +{
  427 + int ret = ERROR_SUCCESS;
  428 +
  429 + SrsCommonMessage* msg = new SrsCommonMessage;
  430 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  431 + pkt->command_name = SRS_BW_CHECK_STARTING_PUBLISH;
  432 + msg->set_packet(pkt, 0);
  433 +
  434 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  435 + srs_error("send starting play msg failed. ret=%d", ret);
  436 + return ret;
  437 + }
  438 + srs_info("send starting play msg success.");
  439 +
  440 + return ret;
  441 +}
  442 +
  443 +int SrsBandCheckClient::send_pub_data()
  444 +{
  445 + int ret = ERROR_SUCCESS;
  446 +
  447 + int data_count = 100;
  448 + while (true) {
  449 + SrsCommonMessage* msg = new SrsCommonMessage;
  450 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  451 + pkt->command_name = SRS_BW_CHECK_PUBLISHING;
  452 + msg->set_packet(pkt, 0);
  453 +
  454 + for (int i = 0; i < data_count; ++i) {
  455 + std::stringstream seq;
  456 + seq << i;
  457 + std::string play_data = "SrS band check data from client's publishing......";
  458 + pkt->data->set(seq.str(), new SrsAmf0String(play_data.c_str()));
  459 + }
  460 + data_count += 100;
  461 +
  462 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  463 + srs_error("send publish message failed.ret=%d", ret);
  464 + return ret;
  465 + }
  466 +
  467 + if ((ret = expect_stop_pub()) == ERROR_SUCCESS) {
  468 + break;
  469 + }
  470 + }
  471 +
  472 + return ret;
  473 +}
  474 +
  475 +int SrsBandCheckClient::expect_stop_pub()
  476 +{
  477 + int ret = ERROR_SUCCESS;
  478 +
  479 + while (true) {
  480 + if ((ret = st_netfd_poll(stfd, POLLIN, 1000)) == ERROR_SUCCESS) {
  481 + SrsCommonMessage* msg = 0;
  482 + if ((ret = recv_message(&msg)) != ERROR_SUCCESS)
  483 + {
  484 + srs_error("recv message failed while expect stop pub. ret=%d", ret);
  485 + return ret;
  486 + }
  487 +
  488 + if ((ret = msg->decode_packet(protocol)) != ERROR_SUCCESS) {
  489 + srs_error("decode packet error while expect stop pub. ret=%d", ret);
  490 + return ret;
  491 + }
  492 +
  493 + SrsBandwidthPacket* pkt = dynamic_cast<SrsBandwidthPacket*>(msg->get_packet());
  494 + if (pkt && pkt->command_name == SRS_BW_CHECK_STOP_PUBLISH) {
  495 +
  496 + return ret;
  497 + }
  498 + } else {
  499 + break;
  500 + }
  501 + }
  502 +
  503 + return ret;
  504 +}
  505 +
  506 +int SrsBandCheckClient::expect_finished()
  507 +{
  508 + int ret = ERROR_SUCCESS;
  509 +
  510 + while (true) {
  511 + SrsCommonMessage* msg = NULL;
  512 + SrsBandwidthPacket* pkt = NULL;
  513 + if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
  514 + srs_error("expect finished message failed. ret=%d", ret);
  515 + return ret;
  516 + }
  517 + SrsAutoFree(SrsCommonMessage, msg, false);
  518 + srs_info("get bandcheck finished message");
  519 +
  520 + if (pkt->command_name == SRS_BW_CHECK_FINISHED) {
  521 + SrsStream *stream = new SrsStream;
  522 + SrsAutoFree(SrsStream, stream, false);
  523 +
  524 + if ((ret = stream->initialize((char*)msg->payload, msg->size)) != ERROR_SUCCESS) {
  525 + srs_error("initialize stream error. ret=%d", ret);
  526 + return ret;
  527 + }
  528 +
  529 + std::string command_name;
  530 + if ((ret = srs_amf0_read_string(stream, command_name)) != ERROR_SUCCESS) {
  531 + srs_error("amfo read string error. ret=%d", ret);
  532 + return ret;
  533 + }
  534 +
  535 + double action_id;
  536 + if ((ret = srs_amf0_read_number(stream, action_id)) != ERROR_SUCCESS) {
  537 + srs_error("amfo read number error. ret=%d", ret);
  538 + return ret;
  539 + }
  540 +
  541 + if ((ret = srs_amf0_read_null(stream)) != ERROR_SUCCESS) {
  542 + srs_error("amfo read number error. ret=%d", ret);
  543 + return ret;
  544 + }
  545 +
  546 + SrsAmf0Object* object;
  547 + if ((ret = srs_amf0_read_object(stream, object)) != ERROR_SUCCESS) {
  548 + srs_error("amfo read object error. ret=%d", ret);
  549 + return ret;
  550 + }
  551 +
  552 + int64_t start_time = 0;
  553 + int64_t end_time = 0;
  554 +
  555 + SrsAmf0Any* start_time_any = object->get_property("start_time");
  556 + if (start_time_any && start_time_any->is_number()) {
  557 + SrsAmf0Number* start_time_number = dynamic_cast<SrsAmf0Number*> (start_time_any);
  558 + if (start_time_number) {
  559 + start_time = start_time_number->value;
  560 + }
  561 + }
  562 +
  563 + SrsAmf0Any* end_time_any = object->get_property("end_time");
  564 + if (end_time_any && end_time_any->is_number()) {
  565 + SrsAmf0Number* end_time_number = dynamic_cast<SrsAmf0Number*> (end_time_any);
  566 + if (end_time_number) {
  567 + end_time = end_time_number->value;
  568 + }
  569 + }
  570 +
  571 + int play_kbps = 0;
  572 + int pub_kbps = 0;
  573 + SrsAmf0Any* play_kbp_any = object->get_property("play_kbps");
  574 + if (play_kbp_any && play_kbp_any->is_number()) {
  575 + SrsAmf0Number* play_kbps_number = dynamic_cast<SrsAmf0Number*> (play_kbp_any);
  576 + if (play_kbps_number) {
  577 + play_kbps = play_kbps_number->value;
  578 + }
  579 + }
  580 +
  581 + SrsAmf0Any* pub_kbp_any = object->get_property("publish_kbps");
  582 + if (pub_kbp_any && pub_kbp_any->is_number()) {
  583 + SrsAmf0Number* pub_kbps_number = dynamic_cast<SrsAmf0Number*> (pub_kbp_any);
  584 + if (pub_kbps_number) {
  585 + pub_kbps = pub_kbps_number->value;
  586 + }
  587 + }
  588 +
  589 + float time_elapsed;
  590 + if (end_time - start_time > 0) {
  591 + time_elapsed = (end_time - start_time) / 1000.00;
  592 + }
  593 +
  594 + srs_trace("result: play %d kbps, publish %d kbps, check time %.4f S\n"
  595 + , play_kbps, pub_kbps, time_elapsed);
  596 +
  597 + break;
  598 + }
  599 + }
  600 +
  601 + return ret;
  602 +}
  603 +
  604 +int SrsBandCheckClient::send_stopped_pub()
  605 +{
  606 + int ret = ERROR_SUCCESS;
  607 +
  608 + SrsCommonMessage* msg = new SrsCommonMessage;
  609 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  610 + pkt->command_name = SRS_BW_CHECK_STOPPED_PUBLISH;
  611 + msg->set_packet(pkt, 0);
  612 +
  613 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  614 + srs_error("send stopped pub msg failed. ret=%d", ret);
  615 + return ret;
  616 + }
  617 + srs_info("send stopped pub msg success.");
  618 +
  619 + return ret;
  620 +}
  621 +
  622 +int SrsBandCheckClient::send_final()
  623 +{
  624 + int ret = ERROR_SUCCESS;
  625 +
  626 + SrsCommonMessage* msg = new SrsCommonMessage;
  627 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket;
  628 + pkt->command_name = SRS_BW_CHECK_FLASH_FINAL;
  629 + msg->set_packet(pkt, 0);
  630 +
  631 + if ((ret = send_message(msg)) != ERROR_SUCCESS) {
  632 + srs_error("send final msg failed. ret=%d", ret);
  633 + return ret;
  634 + }
  635 + srs_info("send final msg success.");
  636 +
  637 + return ret;
  638 +}
  639 +
  640 +SrsBandCheck::SrsBandCheck()
  641 + : bandCheck_Client(0)
  642 +{
  643 +}
  644 +
  645 +SrsBandCheck::~SrsBandCheck()
  646 +{
  647 + if (bandCheck_Client) {
  648 + srs_freep(bandCheck_Client);
  649 + }
  650 +}
  651 +
  652 +int SrsBandCheck::check(const std::string &app, const std::string &tcUrl)
  653 +{
  654 + int ret = ERROR_SUCCESS;
  655 +
  656 + if ((ret = connect_server()) != ERROR_SUCCESS) {
  657 + srs_error("connect to server failed. ret = %d", ret);
  658 + return ret;
  659 + }
  660 +
  661 + if ((ret = bandCheck_Client->handshake()) != ERROR_SUCCESS) {
  662 + srs_error("handshake failed. ret = %d", ret);
  663 + return ret;
  664 + }
  665 +
  666 + if ((ret = bandCheck_Client->connect_app(app, tcUrl)) != ERROR_SUCCESS) {
  667 + srs_error("handshake failed. ret = %d", ret);
  668 + return ret;
  669 + }
  670 +
  671 + if ((ret = bandCheck_Client->check_play()) != ERROR_SUCCESS) {
  672 + srs_error("band check play failed.");
  673 + return ret;
  674 + }
  675 +
  676 + if ((ret = bandCheck_Client->check_publish()) != ERROR_SUCCESS) {
  677 + srs_error("band check publish failed.");
  678 + return ret;
  679 + }
  680 +
  681 + return ret;
  682 +}
  683 +
  684 +void SrsBandCheck::set_server(const std::string &server, int port)
  685 +{
  686 + server_address = server;
  687 + server_port = port;
  688 +}
  689 +
  690 +int SrsBandCheck::connect_server()
  691 +{
  692 + int ret = ERROR_SUCCESS;
  693 +
  694 + int sock = socket(AF_INET, SOCK_STREAM, 0);
  695 + if(sock == -1){
  696 + ret = ERROR_SOCKET_CREATE;
  697 + srs_error("create socket error. ret=%d", ret);
  698 + return ret;
  699 + }
  700 +
  701 + st_netfd_t stfd = st_netfd_open_socket(sock);
  702 + if(stfd == NULL){
  703 + ret = ERROR_ST_OPEN_SOCKET;
  704 + srs_error("st_netfd_open_socket failed. ret=%d", ret);
  705 + return ret;
  706 + }
  707 +
  708 + bandCheck_Client = new SrsBandCheckClient(stfd);
  709 +
  710 + // connect to server.
  711 + std::string ip = srs_dns_resolve(server_address);
  712 + if (ip.empty()) {
  713 + ret = ERROR_SYSTEM_IP_INVALID;
  714 + srs_error("dns resolve server error, ip empty. ret=%d", ret);
  715 + return ret;
  716 + }
  717 +
  718 + sockaddr_in addr;
  719 + addr.sin_family = AF_INET;
  720 + addr.sin_port = htons(server_port);
  721 + addr.sin_addr.s_addr = inet_addr(ip.c_str());
  722 +
  723 + if (st_connect(stfd, (const struct sockaddr*)&addr, sizeof(sockaddr_in), ST_UTIME_NO_TIMEOUT) == -1){
  724 + ret = ERROR_ST_CONNECT;
  725 + srs_error("connect to server error. ip=%s, port=%d, ret=%d", ip.c_str(), server_port, ret);
  726 + return ret;
  727 + }
  728 + srs_trace("connect to server success. server=%s, ip=%s, port=%d", server_address.c_str(), ip.c_str(), server_port);
  729 +
  730 + return ret;
  731 +}
  732 +
  733 +int init_st()
  734 +{
  735 + int ret = ERROR_SUCCESS;
  736 +
  737 + if (st_set_eventsys(ST_EVENTSYS_ALT) == -1) {
  738 + ret = ERROR_ST_SET_EPOLL;
  739 + srs_error("st_set_eventsys use linux epoll failed. ret=%d", ret);
  740 + return ret;
  741 + }
  742 +
  743 + if(st_init() != 0){
  744 + ret = ERROR_ST_INITIALIZE;
  745 + srs_error("st_init failed. ret=%d", ret);
  746 + return ret;
  747 + }
  748 +
  749 + return ret;
  750 +}
  751 +
  752 +void print_help(char** argv)
  753 +{
  754 + printf(
  755 + "Usage: %s [OPTION]...\n"
  756 + "test band width from client to rtmp server.\n"
  757 + "Mandatory arguments to long options are mandatory for short options too.\n"
  758 + " -i, --ip the ip or domain that to test\n"
  759 + " -p, --port the port that server listen \n"
  760 + " -k, --key the key used to test \n"
  761 + " -v, --vhost the vhost used to test \n"
  762 + " -V, --version output version information and exit \n"
  763 + " -h, --help display this help and exit \n"
  764 + "\n"
  765 + "For example:\n"
  766 + " %s -i 192.168.1.248 -p 1935 -v bandcheck.srs.com -k 35c9b402c12a7246868752e2878f7e0e"
  767 + "\n\n"
  768 + "Exit status:\n"
  769 + "0 if OK,\n"
  770 + "other if error occured, and the detail should be printed.\n"
  771 + "\n\n"
  772 + "srs home page: <http://blog.chinaunix.net/uid/25006789.html>\n",
  773 + argv[0], argv[0]);
  774 +}
  775 +
  776 +void print_version()
  777 +{
  778 + const char *version = ""
  779 + "srs_bandcheck "BUILD_VERSION"\n"
  780 + "Copyright (c) 2013-2014 wenjiegit.\n"
  781 + "License MIT\n"
  782 + "This is free software: you are free to change and redistribute it.\n"
  783 + "There is NO WARRANTY, to the extent permitted by law.\n"
  784 + "\n"
  785 + "Written by wenjie.\n";
  786 +
  787 + printf("%s", version);
  788 +}
  789 +
  790 +int get_opt(int argc, char *argv[])
  791 +{
  792 + int ret = ERROR_SUCCESS;
  793 +
  794 + int c;
  795 + while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) {
  796 + switch (c) {
  797 + case 'i':
  798 + if (optarg) {
  799 + g_ip = optarg;
  800 + }
  801 + break;
  802 + case 'p':
  803 + if (optarg) {
  804 + g_port = atoi(optarg);
  805 + }
  806 + break;
  807 + case 'k':
  808 + if (optarg) {
  809 + g_key = optarg;
  810 + }
  811 + break;
  812 + case 'v':
  813 + if (optarg) {
  814 + g_vhost = optarg;
  815 + }
  816 + break;
  817 + case 'V':
  818 + print_version();
  819 + exit(0);
  820 + break;
  821 + case 'h':
  822 + print_help(argv);
  823 + exit(0);
  824 + break;
  825 + default:
  826 + printf("see --help or -h\n");
  827 + ret = -1;
  828 + }
  829 + }
  830 +
  831 + return ret;
  832 +}
1 /* 1 /*
2 The MIT License (MIT) 2 The MIT License (MIT)
3 3
4 -Copyright (c) 2013 winlin 4 +Copyright (c) 2013-2014 winlin
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of 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 7 this software and associated documentation files (the "Software"), to deal in