1#!/usr/bin/env perl
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
10#
11# This software is licensed as described in the file COPYING, which
12# you should have received as part of this distribution. The terms
13# are also available at http://curl.haxx.se/docs/copyright.html.
14#
15# You may opt to use, copy, modify, merge, publish, distribute and/or sell
16# copies of the Software, and permit persons to whom the Software is
17# furnished to do so, under the terms of the COPYING file.
18#
19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20# KIND, either express or implied.
21#
22#***************************************************************************
23
24BEGIN {
25    @INC=(@INC, $ENV{'srcdir'}, '.');
26}
27
28use strict;
29use warnings;
30
31use serverhelp qw(
32    server_pidfilename
33    server_logfilename
34    );
35
36my $verbose = 0;     # set to 1 for debugging
37my $port = 8990;     # just a default
38my $ipvnum = 4;      # default IP version of rtsp server
39my $idnum = 1;       # dafault rtsp server instance number
40my $proto = 'rtsp';  # protocol the rtsp server speaks
41my $pidfile;         # rtsp server pid file
42my $logfile;         # rtsp server log file
43my $srcdir;
44
45my $flags  = "";
46my $path   = '.';
47my $logdir = $path .'/log';
48
49while(@ARGV) {
50    if($ARGV[0] eq '--pidfile') {
51        if($ARGV[1]) {
52            $pidfile = $ARGV[1];
53            shift @ARGV;
54        }
55    }
56    elsif($ARGV[0] eq '--logfile') {
57        if($ARGV[1]) {
58            $logfile = $ARGV[1];
59            shift @ARGV;
60        }
61    }
62    elsif($ARGV[0] eq '--srcdir') {
63        if($ARGV[1]) {
64            $srcdir = $ARGV[1];
65            shift @ARGV;
66        }
67    }
68    elsif($ARGV[0] eq '--ipv4') {
69        $ipvnum = 4;
70    }
71    elsif($ARGV[0] eq '--ipv6') {
72        $ipvnum = 6;
73    }
74    elsif($ARGV[0] eq '--port') {
75        if($ARGV[1] =~ /^(\d+)$/) {
76            $port = $1;
77            shift @ARGV;
78        }
79    }
80    elsif($ARGV[0] eq '--id') {
81        if($ARGV[1] =~ /^(\d+)$/) {
82            $idnum = $1 if($1 > 0);
83            shift @ARGV;
84        }
85    }
86    elsif($ARGV[0] eq '--verbose') {
87        $verbose = 1;
88    }
89    else {
90        print STDERR "\nWarning: rtspserver.pl unknown parameter: $ARGV[0]\n";
91    }
92    shift @ARGV;
93}
94
95if(!$srcdir) {
96    $srcdir = $ENV{'srcdir'} || '.';
97}
98if(!$pidfile) {
99    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
100}
101if(!$logfile) {
102    $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
103}
104
105$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
106$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
107
108exec("server/rtspd $flags");
109