winlin

donot install tools when ffmpeg is not open, 0.9.108

@@ -70,6 +70,7 @@ function Ubuntu_prepare() @@ -70,6 +70,7 @@ function Ubuntu_prepare()
70 echo "install patch success" 70 echo "install patch success"
71 fi 71 fi
72 72
  73 + if [ $SRS_FFMPEG_TOOL = YES ]; then
73 autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then 74 autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
74 echo "install autoconf" 75 echo "install autoconf"
75 require_sudoer "sudo apt-get install -y --force-yes autoconf" 76 require_sudoer "sudo apt-get install -y --force-yes autoconf"
@@ -104,6 +105,7 @@ function Ubuntu_prepare() @@ -104,6 +105,7 @@ function Ubuntu_prepare()
104 sudo apt-get install -y --force-yes libfreetype6-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi 105 sudo apt-get install -y --force-yes libfreetype6-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
105 echo "install libfreetype6-dev success" 106 echo "install libfreetype6-dev success"
106 fi 107 fi
  108 + fi
107 109
108 # for arm, install the cross build tool chain. 110 # for arm, install the cross build tool chain.
109 if [ $SRS_ARM_UBUNTU12 = YES ]; then 111 if [ $SRS_ARM_UBUNTU12 = YES ]; then
@@ -168,6 +170,7 @@ function Centos_prepare() @@ -168,6 +170,7 @@ function Centos_prepare()
168 echo "install patch success" 170 echo "install patch success"
169 fi 171 fi
170 172
  173 + if [ $SRS_FFMPEG_TOOL = YES ]; then
171 automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then 174 automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
172 echo "install automake" 175 echo "install automake"
173 require_sudoer "sudo yum install -y automake" 176 require_sudoer "sudo yum install -y automake"
@@ -209,6 +212,7 @@ function Centos_prepare() @@ -209,6 +212,7 @@ function Centos_prepare()
209 sudo yum install -y freetype-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi 212 sudo yum install -y freetype-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
210 echo "install freetype-devel success" 213 echo "install freetype-devel success"
211 fi 214 fi
  215 + fi
212 216
213 # for arm, install the cross build tool chain. 217 # for arm, install the cross build tool chain.
214 if [ $SRS_EMBEDED_CPU = YES ]; then 218 if [ $SRS_EMBEDED_CPU = YES ]; then
@@ -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