winlin

donot install tools when ffmpeg is not open, 0.9.108

@@ -70,39 +70,41 @@ function Ubuntu_prepare() @@ -70,39 +70,41 @@ function Ubuntu_prepare()
70 echo "install patch success" 70 echo "install patch success"
71 fi 71 fi
72 72
73 - autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then  
74 - echo "install autoconf"  
75 - require_sudoer "sudo apt-get install -y --force-yes autoconf"  
76 - sudo apt-get install -y --force-yes autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
77 - echo "install autoconf success"  
78 - fi  
79 -  
80 - libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then  
81 - echo "install libtool"  
82 - require_sudoer "sudo apt-get install -y --force-yes libtool"  
83 - sudo apt-get install -y --force-yes libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
84 - echo "install libtool success"  
85 - fi  
86 -  
87 - if [[ ! -f /usr/include/pcre.h ]]; then  
88 - echo "install libpcre3-dev"  
89 - require_sudoer "sudo apt-get install -y --force-yes libpcre3-dev"  
90 - sudo apt-get install -y --force-yes libpcre3-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
91 - echo "install libpcre3-dev success"  
92 - fi  
93 -  
94 - if [[ ! -f /usr/include/zlib.h ]]; then  
95 - echo "install zlib1g-dev"  
96 - require_sudoer "sudo apt-get install -y --force-yes zlib1g-dev"  
97 - sudo apt-get install -y --force-yes zlib1g-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
98 - echo "install zlib1g-dev success"  
99 - fi  
100 -  
101 - if [[ ! -d /usr/include/freetype2 ]]; then  
102 - echo "install libfreetype6-dev"  
103 - require_sudoer "sudo apt-get install -y --force-yes libfreetype6-dev"  
104 - sudo apt-get install -y --force-yes libfreetype6-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
105 - echo "install libfreetype6-dev success" 73 + if [ $SRS_FFMPEG_TOOL = YES ]; then
  74 + autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  75 + echo "install autoconf"
  76 + require_sudoer "sudo apt-get install -y --force-yes autoconf"
  77 + sudo apt-get install -y --force-yes autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  78 + echo "install autoconf success"
  79 + fi
  80 +
  81 + libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  82 + echo "install libtool"
  83 + require_sudoer "sudo apt-get install -y --force-yes libtool"
  84 + sudo apt-get install -y --force-yes libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  85 + echo "install libtool success"
  86 + fi
  87 +
  88 + if [[ ! -f /usr/include/pcre.h ]]; then
  89 + echo "install libpcre3-dev"
  90 + require_sudoer "sudo apt-get install -y --force-yes libpcre3-dev"
  91 + sudo apt-get install -y --force-yes libpcre3-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  92 + echo "install libpcre3-dev success"
  93 + fi
  94 +
  95 + if [[ ! -f /usr/include/zlib.h ]]; then
  96 + echo "install zlib1g-dev"
  97 + require_sudoer "sudo apt-get install -y --force-yes zlib1g-dev"
  98 + sudo apt-get install -y --force-yes zlib1g-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  99 + echo "install zlib1g-dev success"
  100 + fi
  101 +
  102 + if [[ ! -d /usr/include/freetype2 ]]; then
  103 + echo "install libfreetype6-dev"
  104 + require_sudoer "sudo apt-get install -y --force-yes libfreetype6-dev"
  105 + sudo apt-get install -y --force-yes libfreetype6-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  106 + echo "install libfreetype6-dev success"
  107 + fi
106 fi 108 fi
107 109
108 # for arm, install the cross build tool chain. 110 # for arm, install the cross build tool chain.
@@ -168,46 +170,48 @@ function Centos_prepare() @@ -168,46 +170,48 @@ function Centos_prepare()
168 echo "install patch success" 170 echo "install patch success"
169 fi 171 fi
170 172
171 - automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then  
172 - echo "install automake"  
173 - require_sudoer "sudo yum install -y automake"  
174 - sudo yum install -y automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
175 - echo "install automake success"  
176 - fi  
177 -  
178 - autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then  
179 - echo "install autoconf"  
180 - require_sudoer "sudo yum install -y autoconf"  
181 - sudo yum install -y autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
182 - echo "install autoconf success"  
183 - fi  
184 -  
185 - libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then  
186 - echo "install libtool"  
187 - require_sudoer "sudo yum install -y libtool"  
188 - sudo yum install -y libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
189 - echo "install libtool success"  
190 - fi  
191 -  
192 - if [[ ! -f /usr/include/pcre.h ]]; then  
193 - echo "install pcre-devel"  
194 - require_sudoer "sudo yum install -y pcre-devel"  
195 - sudo yum install -y pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
196 - echo "install pcre-devel success"  
197 - fi  
198 -  
199 - if [[ ! -f /usr/include/zlib.h ]]; then  
200 - echo "install zlib-devel"  
201 - require_sudoer "sudo yum install -y zlib-devel"  
202 - sudo yum install -y zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
203 - echo "install zlib-devel success"  
204 - fi  
205 -  
206 - if [[ ! -d /usr/include/freetype2 ]]; then  
207 - echo "install freetype-devel"  
208 - require_sudoer "sudo yum install -y freetype-devel"  
209 - sudo yum install -y freetype-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi  
210 - echo "install freetype-devel success" 173 + if [ $SRS_FFMPEG_TOOL = YES ]; then
  174 + automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  175 + echo "install automake"
  176 + require_sudoer "sudo yum install -y automake"
  177 + sudo yum install -y automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  178 + echo "install automake success"
  179 + fi
  180 +
  181 + autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  182 + echo "install autoconf"
  183 + require_sudoer "sudo yum install -y autoconf"
  184 + sudo yum install -y autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  185 + echo "install autoconf success"
  186 + fi
  187 +
  188 + libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
  189 + echo "install libtool"
  190 + require_sudoer "sudo yum install -y libtool"
  191 + sudo yum install -y libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  192 + echo "install libtool success"
  193 + fi
  194 +
  195 + if [[ ! -f /usr/include/pcre.h ]]; then
  196 + echo "install pcre-devel"
  197 + require_sudoer "sudo yum install -y pcre-devel"
  198 + sudo yum install -y pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  199 + echo "install pcre-devel success"
  200 + fi
  201 +
  202 + if [[ ! -f /usr/include/zlib.h ]]; then
  203 + echo "install zlib-devel"
  204 + require_sudoer "sudo yum install -y zlib-devel"
  205 + sudo yum install -y zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  206 + echo "install zlib-devel success"
  207 + fi
  208 +
  209 + if [[ ! -d /usr/include/freetype2 ]]; then
  210 + echo "install freetype-devel"
  211 + require_sudoer "sudo yum install -y freetype-devel"
  212 + sudo yum install -y freetype-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
  213 + echo "install freetype-devel success"
  214 + fi
211 fi 215 fi
212 216
213 # for arm, install the cross build tool chain. 217 # for arm, install the cross build tool chain.
@@ -43,13 +43,18 @@ void close_flv_file(int flv_fd); @@ -43,13 +43,18 @@ void close_flv_file(int flv_fd);
43 int flv_open_ic(int flv_fd); 43 int flv_open_ic(int flv_fd);
44 int flv_read_packet(int flv_fd, int* type, u_int32_t* timestamp, char** data, int* size); 44 int flv_read_packet(int flv_fd, int* type, u_int32_t* timestamp, char** data, int* size);
45 45
  46 +#define RE_PULSE_MS 300
46 int64_t re_create(); 47 int64_t re_create();
47 -int64_t re_update(int64_t re, u_int32_t time); 48 +void re_update(int64_t re, u_int32_t time);
48 49
  50 +int64_t tools_main_entrance_startup_time;
49 int main(int argc, char** argv) 51 int main(int argc, char** argv)
50 { 52 {
51 int ret = 0; 53 int ret = 0;
52 54
  55 + // main function
  56 + tools_main_entrance_startup_time = srs_get_time_ms();
  57 +
53 // user option parse index. 58 // user option parse index.
54 int opt = 0; 59 int opt = 0;
55 // user options. 60 // user options.
@@ -118,8 +123,6 @@ int proxy(int flv_fd, srs_rtmp_t ortmp) @@ -118,8 +123,6 @@ int proxy(int flv_fd, srs_rtmp_t ortmp)
118 int type, size; 123 int type, size;
119 u_int32_t timestamp = 0; 124 u_int32_t timestamp = 0;
120 char* data = NULL; 125 char* data = NULL;
121 - // re  
122 - int64_t re = re_create();  
123 126
124 if ((ret = flv_open_ic(flv_fd)) != 0) { 127 if ((ret = flv_open_ic(flv_fd)) != 0) {
125 return ret; 128 return ret;
@@ -128,6 +131,9 @@ int proxy(int flv_fd, srs_rtmp_t ortmp) @@ -128,6 +131,9 @@ int proxy(int flv_fd, srs_rtmp_t ortmp)
128 return ret; 131 return ret;
129 } 132 }
130 133
  134 + // re
  135 + int64_t re = re_create();
  136 +
131 trace("start ingest flv to RTMP stream"); 137 trace("start ingest flv to RTMP stream");
132 for (;;) { 138 for (;;) {
133 if ((ret = flv_read_packet(flv_fd, &type, &timestamp, &data, &size)) != 0) { 139 if ((ret = flv_read_packet(flv_fd, &type, &timestamp, &data, &size)) != 0) {
@@ -144,7 +150,7 @@ int proxy(int flv_fd, srs_rtmp_t ortmp) @@ -144,7 +150,7 @@ int proxy(int flv_fd, srs_rtmp_t ortmp)
144 verbose("ortmp sent packet: type=%s, time=%d, size=%d", 150 verbose("ortmp sent packet: type=%s, time=%d, size=%d",
145 srs_type2string(type), timestamp, size); 151 srs_type2string(type), timestamp, size);
146 152
147 - re = re_update(re, timestamp); 153 + re_update(re, timestamp);
148 } 154 }
149 155
150 return ret; 156 return ret;
@@ -177,17 +183,35 @@ int connect_oc(srs_rtmp_t ortmp) @@ -177,17 +183,35 @@ int connect_oc(srs_rtmp_t ortmp)
177 183
178 int64_t re_create() 184 int64_t re_create()
179 { 185 {
180 - return 0;  
181 -}  
182 -int64_t re_update(int64_t re, u_int32_t time)  
183 -{  
184 - if (time - re > 500) {  
185 - usleep((time - re) * 1000);  
186 - return time; 186 + // if not very precise, we can directly use this as re.
  187 + int64_t re = srs_get_time_ms();
  188 +
  189 + // use the starttime to get the deviation
  190 + int64_t deviation = re - tools_main_entrance_startup_time;
  191 + trace("deviation is %d ms, pulse is %d ms", (int)(deviation), (int)(RE_PULSE_MS));
  192 +
  193 + // so, we adjust time to max(0, deviation - pulse/4)
  194 + // because the last pulse, we never sleep, so we use pulse/4,
  195 + // for example, when EOF at the 120ms of last pulse,
  196 + // these bytes is additional data and to fill the deviation.
  197 + int adjust = (int)(deviation - (RE_PULSE_MS / 4));
  198 + if (adjust > 0) {
  199 + trace("adjust re time, sub %d ms", adjust);
  200 + re -= adjust;
  201 + } else {
  202 + trace("no need to adjust re time");
187 } 203 }
188 204
189 return re; 205 return re;
190 } 206 }
  207 +void re_update(int64_t re, u_int32_t time)
  208 +{
  209 + int64_t now = srs_get_time_ms();
  210 + int64_t diff = time - (now -re);
  211 + if (diff > RE_PULSE_MS) {
  212 + usleep(diff * 1000);
  213 + }
  214 +}
191 215
192 int open_flv_file(char* in_flv_file) 216 int open_flv_file(char* in_flv_file)
193 { 217 {
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "107" 34 +#define VERSION_REVISION "108"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -35,6 +35,7 @@ using namespace std; @@ -35,6 +35,7 @@ using namespace std;
35 #include <srs_protocol_utility.hpp> 35 #include <srs_protocol_utility.hpp>
36 #include <srs_core_autofree.hpp> 36 #include <srs_core_autofree.hpp>
37 #include <srs_protocol_rtmp_stack.hpp> 37 #include <srs_protocol_rtmp_stack.hpp>
  38 +#include <srs_kernel_utility.hpp>
38 39
39 // if user want to define log, define the folowing macro. 40 // if user want to define log, define the folowing macro.
40 #ifndef SRS_RTMP_USER_DEFINED_LOG 41 #ifndef SRS_RTMP_USER_DEFINED_LOG
@@ -399,6 +400,12 @@ int srs_version_revision() @@ -399,6 +400,12 @@ int srs_version_revision()
399 return ::atoi(VERSION_REVISION); 400 return ::atoi(VERSION_REVISION);
400 } 401 }
401 402
  403 +int64_t srs_get_time_ms()
  404 +{
  405 + srs_update_system_time_ms();
  406 + return srs_get_system_time_ms();
  407 +}
  408 +
402 #ifdef __cplusplus 409 #ifdef __cplusplus
403 } 410 }
404 #endif 411 #endif
@@ -154,6 +154,11 @@ int srs_version_major(); @@ -154,6 +154,11 @@ int srs_version_major();
154 int srs_version_minor(); 154 int srs_version_minor();
155 int srs_version_revision(); 155 int srs_version_revision();
156 156
  157 +/**
  158 +* utilities
  159 +*/
  160 +extern int64_t srs_get_time_ms();
  161 +
157 #ifdef __cplusplus 162 #ifdef __cplusplus
158 } 163 }
159 #endif 164 #endif