winlin

fix #145, refine ffmpeg log, check abitrate for libaacplus. 0.9.186.

@@ -207,7 +207,8 @@ Supported operating systems and hardware: @@ -207,7 +207,8 @@ Supported operating systems and hardware:
207 * 2013-10-17, Created.<br/> 207 * 2013-10-17, Created.<br/>
208 208
209 ## History 209 ## History
210 -* v1.0, 2014-08-02, fix [#143](https://github.com/winlinvip/simple-rtmp-server/issues/143), fix retrieve sys stat bug for all linux. 0.9.185. 210 +* v1.0, 2014-08-03, fix [#145](https://github.com/winlinvip/simple-rtmp-server/issues/145), refine ffmpeg log, check abitrate for libaacplus. 0.9.186.
  211 +* v1.0, 2014-08-03, fix [#143](https://github.com/winlinvip/simple-rtmp-server/issues/143), fix retrieve sys stat bug for all linux. 0.9.185.
211 * v1.0, 2014-08-02, fix [#138](https://github.com/winlinvip/simple-rtmp-server/issues/138), fix http hooks bug, regression bug. 0.9.184. 212 * v1.0, 2014-08-02, fix [#138](https://github.com/winlinvip/simple-rtmp-server/issues/138), fix http hooks bug, regression bug. 0.9.184.
212 * v1.0, 2014-08-02, fix [#142](https://github.com/winlinvip/simple-rtmp-server/issues/142), fix tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183. 213 * v1.0, 2014-08-02, fix [#142](https://github.com/winlinvip/simple-rtmp-server/issues/142), fix tcp stat slow bug, use /proc/net/sockstat instead, refer to 'ss -s'. 0.9.183.
213 * v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179. 214 * v1.0, 2014-07-31, fix [#141](https://github.com/winlinvip/simple-rtmp-server/issues/141), support tun0(vpn network device) ip retrieve. 0.9.179.
@@ -41,14 +41,15 @@ using namespace std; @@ -41,14 +41,15 @@ using namespace std;
41 41
42 #ifdef SRS_AUTO_FFMPEG 42 #ifdef SRS_AUTO_FFMPEG
43 43
44 -#define SRS_RTMP_ENCODER_COPY "copy"  
45 -#define SRS_RTMP_ENCODER_NO_VIDEO "vn"  
46 -#define SRS_RTMP_ENCODER_NO_AUDIO "an" 44 +#define SRS_RTMP_ENCODER_COPY "copy"
  45 +#define SRS_RTMP_ENCODER_NO_VIDEO "vn"
  46 +#define SRS_RTMP_ENCODER_NO_AUDIO "an"
47 // only support libx264 encoder. 47 // only support libx264 encoder.
48 -#define SRS_RTMP_ENCODER_VCODEC "libx264" 48 +#define SRS_RTMP_ENCODER_VCODEC "libx264"
49 // any aac encoder is ok which contains the aac, 49 // any aac encoder is ok which contains the aac,
50 // for example, libaacplus, aac, fdkaac 50 // for example, libaacplus, aac, fdkaac
51 -#define SRS_RTMP_ENCODER_ACODEC "aac" 51 +#define SRS_RTMP_ENCODER_ACODEC "aac"
  52 +#define SRS_RTMP_ENCODER_LIBAACPLUS "libaacplus"
52 53
53 SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin) 54 SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin)
54 { 55 {
@@ -173,6 +174,15 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) @@ -173,6 +174,15 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
173 } 174 }
174 } 175 }
175 176
  177 + // @see, https://github.com/winlinvip/simple-rtmp-server/issues/145
  178 + if (acodec == SRS_RTMP_ENCODER_LIBAACPLUS) {
  179 + if (abitrate < 16 || abitrate > 72) {
  180 + ret = ERROR_ENCODER_ABITRATE;
  181 + srs_error("invalid abitrate for aac: %d, must in [16, 72], ret=%d", abitrate, ret);
  182 + return ret;
  183 + }
  184 + }
  185 +
176 if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) { 186 if (acodec != SRS_RTMP_ENCODER_COPY && acodec != SRS_RTMP_ENCODER_NO_AUDIO) {
177 if (acodec.find(SRS_RTMP_ENCODER_ACODEC) == std::string::npos) { 187 if (acodec.find(SRS_RTMP_ENCODER_ACODEC) == std::string::npos) {
178 ret = ERROR_ENCODER_ACODEC; 188 ret = ERROR_ENCODER_ACODEC;
@@ -182,20 +192,17 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine) @@ -182,20 +192,17 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
182 } 192 }
183 if (abitrate <= 0) { 193 if (abitrate <= 0) {
184 ret = ERROR_ENCODER_ABITRATE; 194 ret = ERROR_ENCODER_ABITRATE;
185 - srs_error("invalid abitrate: %d, ret=%d",  
186 - abitrate, ret); 195 + srs_error("invalid abitrate: %d, ret=%d", abitrate, ret);
187 return ret; 196 return ret;
188 } 197 }
189 if (asample_rate <= 0) { 198 if (asample_rate <= 0) {
190 ret = ERROR_ENCODER_ASAMPLE_RATE; 199 ret = ERROR_ENCODER_ASAMPLE_RATE;
191 - srs_error("invalid sample rate: %d, ret=%d",  
192 - asample_rate, ret); 200 + srs_error("invalid sample rate: %d, ret=%d", asample_rate, ret);
193 return ret; 201 return ret;
194 } 202 }
195 if (achannels != 1 && achannels != 2) { 203 if (achannels != 1 && achannels != 2) {
196 ret = ERROR_ENCODER_ACHANNELS; 204 ret = ERROR_ENCODER_ACHANNELS;
197 - srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d",  
198 - achannels, ret); 205 + srs_error("invalid achannels, must be 1 or 2, actual %d, ret=%d", achannels, ret);
199 return ret; 206 return ret;
200 } 207 }
201 } 208 }
@@ -359,21 +366,21 @@ int SrsFFMPEG::start() @@ -359,21 +366,21 @@ int SrsFFMPEG::start()
359 params.push_back("-y"); 366 params.push_back("-y");
360 params.push_back(_output); 367 params.push_back(_output);
361 368
  369 + std::string cli;
362 if (true) { 370 if (true) {
363 - int pparam_size = 8 * 1024;  
364 - char* pparam = new char[pparam_size];  
365 - char* p = pparam;  
366 - char* last = pparam + pparam_size;  
367 for (int i = 0; i < (int)params.size(); i++) { 371 for (int i = 0; i < (int)params.size(); i++) {
368 std::string ffp = params[i]; 372 std::string ffp = params[i];
369 - snprintf(p, last - p, "%s ", ffp.c_str());  
370 - p += ffp.length() + 1; 373 + cli += ffp;
  374 + if (i < (int)params.size() - 1) {
  375 + cli += " ";
  376 + }
371 } 377 }
372 - srs_trace("start transcoder, log: %s, params: %s",  
373 - log_file.c_str(), pparam);  
374 - srs_freep(pparam); 378 + srs_trace("start ffmpeg, log: %s, params: %s", log_file.c_str(), cli.c_str());
375 } 379 }
376 380
  381 + // for log
  382 + int cid = _srs_context->get_id();
  383 +
377 // TODO: fork or vfork? 384 // TODO: fork or vfork?
378 if ((pid = fork()) < 0) { 385 if ((pid = fork()) < 0) {
379 ret = ERROR_ENCODER_FORK; 386 ret = ERROR_ENCODER_FORK;
@@ -392,6 +399,19 @@ int SrsFFMPEG::start() @@ -392,6 +399,19 @@ int SrsFFMPEG::start()
392 srs_error("open encoder file %s failed. ret=%d", log_file.c_str(), ret); 399 srs_error("open encoder file %s failed. ret=%d", log_file.c_str(), ret);
393 return ret; 400 return ret;
394 } 401 }
  402 +
  403 + // log basic info
  404 + if (true) {
  405 + char buf[4096];
  406 + int pos = 0;
  407 + pos += snprintf(buf + pos, sizeof(buf) - pos, "\n");
  408 + pos += snprintf(buf + pos, sizeof(buf) - pos, "ffmpeg cid=%d\n", cid);
  409 + pos += snprintf(buf + pos, sizeof(buf) - pos, "log=%s\n", log_file.c_str());
  410 + pos += snprintf(buf + pos, sizeof(buf) - pos, "params: %s\n", cli.c_str());
  411 + ::write(log_fd, buf, pos);
  412 + }
  413 +
  414 + // dup to stdout and stderr.
395 if (dup2(log_fd, STDOUT_FILENO) < 0) { 415 if (dup2(log_fd, STDOUT_FILENO) < 0) {
396 ret = ERROR_ENCODER_DUP2; 416 ret = ERROR_ENCODER_DUP2;
397 srs_error("dup2 encoder file failed. ret=%d", ret); 417 srs_error("dup2 encoder file failed. ret=%d", ret);
@@ -402,6 +422,7 @@ int SrsFFMPEG::start() @@ -402,6 +422,7 @@ int SrsFFMPEG::start()
402 srs_error("dup2 encoder file failed. ret=%d", ret); 422 srs_error("dup2 encoder file failed. ret=%d", ret);
403 return ret; 423 return ret;
404 } 424 }
  425 +
405 // close log fd 426 // close log fd
406 ::close(log_fd); 427 ::close(log_fd);
407 // close other fds 428 // close other fds
@@ -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 "185" 34 +#define VERSION_REVISION "186"
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"