~ubuntu-branches/ubuntu/saucy/gnash/saucy-proposed

« back to all changes in this revision

Viewing changes to utilities/rtmpget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sindhudweep Narayan Sarkar
  • Date: 2009-10-07 00:06:10 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091007000610-mj9rwqe774gizn1j
Tags: 0.8.6-0ubuntu1
new upstream release 0.8.6 (LP: #435897)

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
        { 'a', "app",           Arg_parser::yes  },
132
132
        { 'p', "path",          Arg_parser::yes  },
133
133
        { 'f', "filename",      Arg_parser::yes  },
134
 
        { 't', "tcurl",     Arg_parser::yes  },
135
 
        { 's', "swfurl",    Arg_parser::yes  },
 
134
        { 't', "tcurl",         Arg_parser::yes  },
 
135
        { 's', "swfurl",        Arg_parser::yes  },
136
136
        { 'u', "url",           Arg_parser::yes  },
137
137
        { 'n', "netdebug",      Arg_parser::no  }
138
138
        };
152
152
        dbglogfile.setVerbosity(rcfile.verbosityLevel());
153
153
    }    
154
154
 
 
155
#if 0
155
156
    string app; // the application name
156
157
    string path; // the path to the file on the server
157
158
    string tcUrl; // the tcUrl field
158
159
    string swfUrl; // the swfUrl field
159
160
    string filename; // the filename to play
160
 
 
 
161
#endif
 
162
    
161
163
    // Handle command line arguments
162
164
    for( int i = 0; i < parser.arguments(); ++i ) {
163
165
        const int code = parser.code(i);
216
218
        return EXIT_FAILURE;
217
219
    }
218
220
 
219
 
    RTMPClient client;    
220
 
    short port = 0;
221
 
    string protocol;        // the network protocol, rtmp or http
222
 
    string query;       // any queries for the host
223
 
    string pageUrl;     // the pageUrl field
224
 
    string hostname;        // the hostname of the server
225
 
    
226
 
    URL url( infiles[0] );
227
 
    string portstr;
228
 
    
229
221
    // Trap ^C (SIGINT) so we can kill all the threads
230
222
    act.sa_handler = cntrlc_handler;
231
223
    sigaction (SIGINT, &act, NULL);
232
224
 
233
 
    protocol = url.protocol();
234
 
    hostname = url.hostname();
235
 
    log_debug("hostname: %s", hostname);
236
 
    portstr = url.port();
237
 
    query = url.querystring();
238
 
 
239
 
    if ( portstr.empty() )
240
 
    {
241
 
        if ((protocol == "http") || (protocol == "rtmpt")) {
242
 
            port = RTMPT_PORT;
243
 
        }
244
 
        if (protocol == "rtmp") {
245
 
            port = RTMP_PORT;
246
 
        }
247
 
    }
248
 
    else
249
 
    {
250
 
        port = strtol(portstr.c_str(), NULL, 0) & 0xffff;
251
 
    }
252
 
 
253
 
 
254
 
    if ( path.empty() )
255
 
    {
256
 
        path = url.path();
257
 
    }
258
 
 
259
 
    if ( filename.empty() )
260
 
    {
261
 
        string::size_type end = path.rfind('/');
262
 
        if (end != string::npos) {
263
 
            filename = path.substr(end + 1);
264
 
        }
265
 
    }
266
 
 
267
 
 
268
 
    if (tcUrl.empty()) {
269
 
        tcUrl = protocol + "://" + hostname;
270
 
        if (!portstr.empty()) {
271
 
            tcUrl += ":" + portstr;
272
 
        }
273
 
        if (!query.empty()) {
274
 
            tcUrl += "/" + query;
275
 
        } else {
276
 
            tcUrl += "/" + path;
277
 
        }
278
 
    }
279
 
    
280
 
    if (app.empty())
281
 
    {
282
 
 
283
 
        // Get the application name
284
 
        // rtmp://localhost/application/resource
285
 
        //                  ^^^^^^^^^^^ <-- appname is this
286
 
        //
287
 
        app = path;
288
 
        if ( ! filename.empty() )
289
 
        {
290
 
                string::size_type end = app.rfind(filename);
291
 
                if (end != string::npos) {
292
 
                    app = app.substr(0, end);
293
 
                }
294
 
        }
295
 
 
296
 
        // drop slashes
297
 
        string::size_type end = app.find_first_not_of('/');
298
 
        if (end != string::npos) {
299
 
            app = app.substr(end);
300
 
        }
301
 
        end = app.find_last_not_of('/');
302
 
        if (end != string::npos) {
303
 
            app = app.substr(0, end+1);
304
 
        }
305
 
        
306
 
        if (!query.empty()) {
307
 
            app = path;
308
 
            app += "?" + query;
309
 
        }
310
 
    }
311
 
 
312
 
    if (swfUrl.empty()) {
313
 
        swfUrl = "mediaplayer.swf";
314
 
    }
315
 
    if (pageUrl.empty()) {
316
 
        pageUrl = "http://gnashdev.org";
317
 
    }
318
 
    
319
 
    log_debug("URL is %s", url);
320
 
    log_debug("Protocol is %s", protocol);
321
 
    log_debug("Host is %s", hostname);
322
 
    log_debug("Port is %s", port);
323
 
    log_debug("Path is %s", path);
324
 
    log_debug("Filename is %s", filename);
325
 
    log_debug("App is %s", app);
326
 
    log_debug("Query is %s", query);
327
 
    log_debug("tcUrl is %s", tcUrl);
328
 
    log_debug("swfUrl is %s", swfUrl);
329
 
    log_debug("pageUrl is %s", pageUrl);
330
 
 
 
225
    RTMPClient client;
331
226
    client.toggleDebug(netdebug);
332
227
    if (client.createClient(hostname, port) == false) {
333
228
        log_error("Can't connect to RTMP server %s", hostname);
334
229
        exit(-1);
335
230
    }
336
231
    
337
 
    if ( ! client.handShakeRequest() )
338
 
    {
 
232
    if (! client.handShakeRequest()) {
339
233
        log_error("RTMP handshake request failed");
340
234
        exit(EXIT_FAILURE);
341
235
    }
342
236
    
343
 
    if ( ! client.clientFinish() )
344
 
    {
 
237
    if (! client.clientFinish()) {
345
238
        log_error("RTMP handshake completion failed");
346
239
        exit(EXIT_FAILURE);
347
240
    }
351
244
    // RTMP::rtmp_head_t *rthead = 0;
352
245
    // int ret = 0;
353
246
    log_debug("Sending NetConnection Connect message,");
354
 
    BufferSharedPtr buf2 = client.encodeConnect(app.c_str(), swfUrl.c_str(), tcUrl.c_str(), 615, 124, 1, pageUrl.c_str());
 
247
#if 0
 
248
    BufferSharedPtr buf2 = client.encodeConnect(app.c_str(), swfUrl.c_str(), tcUrl.c_str(), RTMPClient::DEFAULT_AUDIO_SET,
 
249
                      RTMPClient::DEFAULT_VIDEO_SET,
 
250
                      RTMPClient::SEEK, pageUrl.c_str());
 
251
#else
 
252
    BufferSharedPtr buf2 = client.encodeConnect(infiles[0]);    
 
253
#endif
355
254
//    BufferSharedPtr buf2 = client.encodeConnect("video/2006/sekt/gate06/tablan_valentin", "mediaplayer.swf", "rtmp://velblod.videolectures.net/video/2006/sekt/gate06/tablan_valentin", 615, 124, 1, "http://gnashdev.org");
356
255
//    BufferSharedPtr buf2 = client.encodeConnect("oflaDemo", "http://192.168.1.70/software/gnash/tests/ofla_demo.swf", "rtmp://localhost/oflaDemo/stream", 615, 124, 1, "http://192.168.1.70/software/gnash/tests/index.html");
357
256
    //buf2->resize(buf2->size() - 6); // FIXME: encodeConnect returns the wrong size for the buffer!