winlin

fix the bug for fork ffmpeg in mac, the local variable is unvailable.

@@ -76,17 +76,25 @@ int main(int argc, char** argv) @@ -76,17 +76,25 @@ int main(int argc, char** argv)
76 exit(-1); 76 exit(-1);
77 } 77 }
78 78
79 - // parse options in FFMPEG format.  
80 - while ((opt = getopt(argc, argv, "i:y:")) != -1) {  
81 - switch (opt) {  
82 - case 'i':  
83 - in_flv_file = optarg;  
84 - break;  
85 - case 'y':  
86 - out_rtmp_url = optarg;  
87 - break;  
88 - default:  
89 - break; 79 + for (opt = 0; opt < argc; opt++) {
  80 + srs_human_trace("argv[%d]=%s", opt, argv[opt]);
  81 + }
  82 +
  83 + // fill the options for mac
  84 + for (opt = 0; opt < argc - 1; opt++) {
  85 + // ignore all options except -i and -y.
  86 + char* p = argv[opt];
  87 +
  88 + // only accept -x
  89 + if (p[0] != '-' || p[1] == 0 || p[2] != 0) {
  90 + continue;
  91 + }
  92 +
  93 + // parse according the option name.
  94 + switch (p[1]) {
  95 + case 'i': in_flv_file = argv[opt + 1]; break;
  96 + case 'y': out_rtmp_url = argv[opt + 1]; break;
  97 + default: break;
90 } 98 }
91 } 99 }
92 100
@@ -61,17 +61,21 @@ int main(int argc, char** argv) @@ -61,17 +61,21 @@ int main(int argc, char** argv)
61 exit(-1); 61 exit(-1);
62 } 62 }
63 63
64 - // parse options in FFMPEG format.  
65 - while ((opt = getopt(argc, argv, "i:y:")) != -1) {  
66 - switch (opt) {  
67 - case 'i':  
68 - in_rtmp_url = optarg;  
69 - break;  
70 - case 'y':  
71 - out_rtmp_url = optarg;  
72 - break;  
73 - default:  
74 - break; 64 + // fill the options for mac
  65 + for (opt = 0; opt < argc - 1; opt++) {
  66 + // ignore all options except -i and -y.
  67 + char* p = argv[opt];
  68 +
  69 + // only accept -x
  70 + if (p[0] != '-' || p[1] == 0 || p[2] != 0) {
  71 + continue;
  72 + }
  73 +
  74 + // parse according the option name.
  75 + switch (p[1]) {
  76 + case 'i': in_rtmp_url = argv[opt + 1]; break;
  77 + case 'y': out_rtmp_url = argv[opt + 1]; break;
  78 + default: break;
75 } 79 }
76 } 80 }
77 81
@@ -432,8 +432,8 @@ int SrsFFMPEG::start() @@ -432,8 +432,8 @@ int SrsFFMPEG::start()
432 // memory leak in child process, it's ok. 432 // memory leak in child process, it's ok.
433 char** charpv_params = new char*[params.size() + 1]; 433 char** charpv_params = new char*[params.size() + 1];
434 for (int i = 0; i < (int)params.size(); i++) { 434 for (int i = 0; i < (int)params.size(); i++) {
435 - std::string p = params[i];  
436 - charpv_params[i] = (char*)p.c_str(); 435 + std::string& p = params[i];
  436 + charpv_params[i] = (char*)p.data();
437 } 437 }
438 // EOF: NULL 438 // EOF: NULL
439 charpv_params[params.size()] = NULL; 439 charpv_params[params.size()] = NULL;