From a739b2c55538f736eed2f65ede851703e68e6b15 Mon Sep 17 00:00:00 2001
From: winlin <winlin@vip.126.com>
Date: Wed, 11 Mar 2015 15:54:31 +0800
Subject: [PATCH] fix the bug for fork ffmpeg in mac, the local variable is
 unvailable.

---
 trunk/research/librtmp/srs_ingest_flv.c  | 30 +++++++++++++++---------
 trunk/research/librtmp/srs_ingest_rtmp.c | 26 +++++++++++---------
 trunk/src/app/srs_app_ffmpeg.cpp         |  4 ++--
 3 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/trunk/research/librtmp/srs_ingest_flv.c b/trunk/research/librtmp/srs_ingest_flv.c
index 4136b1eb1..7d8ce132c 100644
--- a/trunk/research/librtmp/srs_ingest_flv.c
+++ b/trunk/research/librtmp/srs_ingest_flv.c
@@ -76,17 +76,25 @@ int main(int argc, char** argv)
         exit(-1);
     }
     
-    // parse options in FFMPEG format.
-    while ((opt = getopt(argc, argv, "i:y:")) != -1) {
-        switch (opt) {
-            case 'i':
-                in_flv_file = optarg;
-                break;
-            case 'y':
-                out_rtmp_url = optarg;
-                break;
-            default:
-                break;
+    for (opt = 0; opt < argc; opt++) {
+        srs_human_trace("argv[%d]=%s", opt, argv[opt]);
+    }
+    
+    // fill the options for mac
+    for (opt = 0; opt < argc - 1; opt++) {
+        // ignore all options except -i and -y.
+        char* p = argv[opt];
+        
+        // only accept -x
+        if (p[0] != '-' || p[1] == 0 || p[2] != 0) {
+            continue;
+        }
+        
+        // parse according the option name.
+        switch (p[1]) {
+            case 'i': in_flv_file = argv[opt + 1]; break;
+            case 'y': out_rtmp_url = argv[opt + 1]; break;
+            default: break;
         }
     }
     
diff --git a/trunk/research/librtmp/srs_ingest_rtmp.c b/trunk/research/librtmp/srs_ingest_rtmp.c
index b9607cb40..d4c8606cd 100644
--- a/trunk/research/librtmp/srs_ingest_rtmp.c
+++ b/trunk/research/librtmp/srs_ingest_rtmp.c
@@ -61,17 +61,21 @@ int main(int argc, char** argv)
         exit(-1);
     }
     
-    // parse options in FFMPEG format.
-    while ((opt = getopt(argc, argv, "i:y:")) != -1) {
-        switch (opt) {
-            case 'i':
-                in_rtmp_url = optarg;
-                break;
-            case 'y':
-                out_rtmp_url = optarg;
-                break;
-            default:
-                break;
+    // fill the options for mac
+    for (opt = 0; opt < argc - 1; opt++) {
+        // ignore all options except -i and -y.
+        char* p = argv[opt];
+        
+        // only accept -x
+        if (p[0] != '-' || p[1] == 0 || p[2] != 0) {
+            continue;
+        }
+        
+        // parse according the option name.
+        switch (p[1]) {
+            case 'i': in_rtmp_url = argv[opt + 1]; break;
+            case 'y': out_rtmp_url = argv[opt + 1]; break;
+            default: break;
         }
     }
     
diff --git a/trunk/src/app/srs_app_ffmpeg.cpp b/trunk/src/app/srs_app_ffmpeg.cpp
index 473fbdfb5..16badcea7 100644
--- a/trunk/src/app/srs_app_ffmpeg.cpp
+++ b/trunk/src/app/srs_app_ffmpeg.cpp
@@ -432,8 +432,8 @@ int SrsFFMPEG::start()
         // memory leak in child process, it's ok.
         char** charpv_params = new char*[params.size() + 1];
         for (int i = 0; i < (int)params.size(); i++) {
-            std::string p = params[i];
-            charpv_params[i] = (char*)p.c_str();
+            std::string& p = params[i];
+            charpv_params[i] = (char*)p.data();
         }
         // EOF: NULL
         charpv_params[params.size()] = NULL;