19bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#!/usr/bin/env perl
29bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#***************************************************************************
39bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#                                  _   _ ____  _
49bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#  Project                     ___| | | |  _ \| |
59bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#                             / __| | | | |_) | |
69bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#                            | (__| |_| |  _ <| |___
79bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#                             \___|\___/|_| \_\_____|
89bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#
99bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
109bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#
119bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# This software is licensed as described in the file COPYING, which
129bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# you should have received as part of this distribution. The terms
13d15eaac64ca1a7244824d660ea84e8815a23d058Alex Deymo# are also available at https://curl.haxx.se/docs/copyright.html.
149bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#
159bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# You may opt to use, copy, modify, merge, publish, distribute and/or sell
169bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# copies of the Software, and permit persons to whom the Software is
179bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# furnished to do so, under the terms of the COPYING file.
189bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#
199bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
209bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels# KIND, either express or implied.
219bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#
229bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels#***************************************************************************
239bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
249bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas EckelsBEGIN {
25e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
26e6cd738ed3716c02557fb3a47515244e949ade39Bertrand SIMONNET    push(@INC, ".");
279bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}
289bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
299bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse strict;
309bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse warnings;
319bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
329bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsuse serverhelp qw(
339bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    server_pidfilename
349bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    server_logfilename
359bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    );
369bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
379bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $verbose = 0;     # set to 1 for debugging
389bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $port = 8990;     # just a default
399bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $ipvnum = 4;      # default IP version of rtsp server
409bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $idnum = 1;       # dafault rtsp server instance number
419bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $proto = 'rtsp';  # protocol the rtsp server speaks
429bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $pidfile;         # rtsp server pid file
439bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $logfile;         # rtsp server log file
449bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $srcdir;
459bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
469bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $flags  = "";
479bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $path   = '.';
489bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsmy $logdir = $path .'/log';
499bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
509bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelswhile(@ARGV) {
519bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    if($ARGV[0] eq '--pidfile') {
529bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        if($ARGV[1]) {
539bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            $pidfile = $ARGV[1];
549bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            shift @ARGV;
559bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        }
569bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
579bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--logfile') {
589bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        if($ARGV[1]) {
599bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            $logfile = $ARGV[1];
609bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            shift @ARGV;
619bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        }
629bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
639bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--srcdir') {
649bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        if($ARGV[1]) {
659bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            $srcdir = $ARGV[1];
669bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            shift @ARGV;
679bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        }
689bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
699bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--ipv4') {
709bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        $ipvnum = 4;
719bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
729bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--ipv6') {
739bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        $ipvnum = 6;
749bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
759bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--port') {
769bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        if($ARGV[1] =~ /^(\d+)$/) {
779bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            $port = $1;
789bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            shift @ARGV;
799bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        }
809bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
819bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--id') {
829bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        if($ARGV[1] =~ /^(\d+)$/) {
839bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            $idnum = $1 if($1 > 0);
849bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels            shift @ARGV;
859bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        }
869bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
879bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    elsif($ARGV[0] eq '--verbose') {
889bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        $verbose = 1;
899bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
909bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    else {
919bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels        print STDERR "\nWarning: rtspserver.pl unknown parameter: $ARGV[0]\n";
929bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    }
939bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    shift @ARGV;
949bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}
959bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
969bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$srcdir) {
979bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    $srcdir = $ENV{'srcdir'} || '.';
989bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}
999bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$pidfile) {
1009bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    $pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
1019bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}
1029bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsif(!$logfile) {
1039bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels    $logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
1049bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels}
1059bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
1069bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1079bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels$flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1089bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckels
1099bd90e6e25f1e55f50201c87a1b5837de7e5b64aLucas Eckelsexec("server/rtspd $flags");
110