merge from release branch
[platform/upstream/gstreamer.git] / tools / gst-launch-ext
1 #!/usr/bin/perl -w
2
3 # launch a gst-launch pipeline for the supplied media file
4 # use the extension to determine the gst-launch pipeline
5 # make use of default output sinks
6
7 ### packages
8
9 use File::Basename;
10
11 my (%pipes, %cfg);
12
13 sub extension
14 {
15   my $path = shift;
16   my $ext = (fileparse ($path, '\..*?'))[2];
17   $ext =~ s/^\.//;
18   return $ext;
19 }
20
21 sub read_config
22 {
23   my $config_file = `echo -n ~`."/.gst";
24   if (-e $config_file)
25   {
26     open CONFIG, $config_file;
27     while (<CONFIG>)
28     {
29       chomp;
30       s/#.*//;
31       s/\s+$//;
32       next unless length;
33       my ($var, $value) = split (/\s*=\s*/, $_, 2);
34       $cfg{$var} = $value;
35     }
36     if (!($cfg{AUDIOSINK}))
37     {
38       print "Please add an AUDIOSINK to $config_file !\n";
39     }
40     if (!($cfg{VIDEOSINK}))
41     {
42       print "Please add a VIDEOSINK to $config_file !\n";
43     }
44   }
45   else
46   {
47     print "No configuration file $config_file found.  You might want to create one.\n";
48   }
49   if (!defined $cfg{AUDIOSINK})  { $cfg{AUDIOSINK} = "osssink"; }
50   if (!defined $cfg{VIDEOSINK})  { $cfg{VIDEOSINK} = "xvideosink"; }
51   if (!defined $cfg{CVS_PATH})   { $cfg{CVS_PATH} =  `echo -n ~`."/gst/cvs"; }
52 }
53
54 sub playfile($$)
55 {
56     my ($file, $ext) = @_;
57     $ext = lc $ext;
58
59     my $pipe;
60     if ($cfg{VISUALIZER} && ($pipe = $pipes{"vis." . $ext}))
61     {
62         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
63         print "Running $command\n";
64         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
65     }
66     elsif ($pipe = $pipes{$ext})
67     {
68         $command = "gst-launch filesrc location=\"$file\" ! $pipe";
69         print "Running $command\n";
70         system ("PATH=\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools $command");
71     }
72     else
73     {
74         print "No suitable pipe found for extension $ext.\n";
75     }
76 }
77
78 ### main
79
80 read_config ();
81
82 ###  "ac3", "ac3parse ! $cfg{AUDIOSINK}",
83 %pipes = ( 
84   "au", "auparse ! $cfg{AUDIOSINK}",
85   "avi", "avidemux video_%02d! { queue ! windec ! $cfg{VIDEOSINK} } avidemux0.audio_%02d! { queue ! mad ! $cfg{AUDIOSINK} }",
86   "fli", "flxdec ! colorspace ! $cfg{VIDEOSINK}",
87   "mod", "modplug !  $cfg{AUDIOSINK}",
88   "mp3", "mad ! $cfg{AUDIOSINK}",
89   "mpg", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} } mpegdemux0.audio_%02d! { queue ! mad ! $cfg{AUDIOSINK} }",
90   "ogg", "vorbisdec ! $cfg{AUDIOSINK}",
91   "sid", "siddec ! $cfg{AUDIOSINK}",
92   "vob", "mpegdemux video_%02d! { queue ! mpeg2dec ! $cfg{VIDEOSINK} }  mpegdemux0.private_stream_1_%02d! { queue ! a52dec ! $cfg{AUDIOSINK} }",
93 );
94
95 if ($cfg{VISUALIZER}) {
96   %pipes = (
97     %pipes,
98     "vis.mp3", "mad ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
99     "vis.ogg", "vorbisdec ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
100     "vis.wav", "wavparse ! tee silent=true 'tee1.src0!' queue leaky=1 ! { $cfg{VISUALIZER} ! colorspace ! $cfg{VIDEOSINK} } 'tee1.src1!' $cfg{AUDIOSINK}",
101   );
102 }              
103
104 if ($#ARGV == -1) {
105     print STDERR "Usage: gst-launch-ext filename[s]\n";
106     exit 1;
107 }
108
109 my $file;
110 while ($file = shift @ARGV) {
111     my $ext = extension ($file);
112     if ($ext eq 'm3u')
113     {
114         open (PLAYLIST, '<', $file);
115         my $file2;
116         while ($file2 = <PLAYLIST>) {
117             chomp $file2;
118             my $ext2 = extension ($file2);
119             playfile($file2, $ext2);
120         }
121         close PLAYLIST;
122     } else {
123         playfile($file, $ext);
124     }
125 }