ext/ogg/gstogmparse.c: don't pass random values to ogmparse convert function.
[platform/upstream/gstreamer.git] / tools / gst-launch-ext-m.m
1 #!/usr/bin/perl -w
2 use strict;
3
4 # launch a gst-launch pipeline for the supplied media file
5 # use the extension to determine the gst-launch pipeline
6 # make use of default output sinks
7
8 my (%pipes, %cfg);
9
10 sub extension
11 {
12   my $path = shift;
13   my $ext;
14
15   # get only the bit after the last period.  We don't deal with
16   # .tar.gz extensions do we ?
17   if ($path =~ /\./)
18   {
19     $ext = $path;
20     $ext =~ s/^.*\.//;
21   }
22   else { $ext = ""; }
23
24   return $ext;
25 }
26
27 sub read_config
28 {
29   my $command = shift;
30
31   my $config_file = $ENV{HOME}."/.gst";
32   if (-e $config_file)
33   {
34     open CONFIG, $config_file;
35     while (<CONFIG>)
36     {
37       chomp;
38       s/#.*//;
39       s/\s+$//;
40       next unless length;
41       my ($var, $value) = split (/\s*=\s*/, $_, 2);
42       $cfg{$var} = $value;
43     }
44     if (!($cfg{AUDIOSINK}))
45     {
46       print "Please add an AUDIOSINK to $config_file !\n";
47     }
48     if (!($cfg{VIDEOSINK}))
49     {
50       print "Please add a VIDEOSINK to $config_file !\n";
51     }
52   }
53   else
54   {
55     print "No configuration file $config_file found.  You might want to create one.\n";
56     print "This is not an error, just a friendly reminder... Check the man page.\n\n";
57   }
58   if (!defined $cfg{AUDIOSINK})  { $cfg{AUDIOSINK} = "osssink"; }
59   if (!defined $cfg{VIDEOSINK})  { $cfg{VIDEOSINK} = "ffmpegcolorspace ! xvimagesink"; }
60   if (!defined $cfg{CVS_PATH})   { $cfg{CVS_PATH} =  $ENV{HOME}."/gst/cvs"; }
61
62   if ($command =~ /(.+)\/gst-launch-ext-@GST_MAJORMINOR@$/)
63   { $cfg{COMMAND_PATH} = "$1"; }
64   else
65   { $cfg{COMMAND_PATH} = ""; }
66 }
67
68 sub playfile($$)
69 {
70     my ($file, $ext) = @_;
71     my $command;
72     my $pipe;
73     my $path = "\$PATH:".$cfg{CVS_PATH}."/gstreamer/tools";
74
75     if ($cfg{COMMAND_PATH} ne "") {
76       $path = $cfg{COMMAND_PATH}.":$path";
77     }
78
79     $ext = lc $ext;
80
81     if ($cfg{VISUALIZER} && ($pipe = $pipes{"vis." . $ext}))
82     {
83         $command = "gst-launch-@GST_MAJORMINOR@ filesrc location=\"$file\" ! $pipe";
84         print "Running command-line\n$command\n\n";
85         system ("PATH=$path $command");
86     }
87     elsif ($pipe = $pipes{$ext})
88     {
89         $command = "gst-launch-@GST_MAJORMINOR@ filesrc location=\"$file\" ! $pipe";
90         print "Running command-line\n$command\n\n";
91         system ("PATH=$path $command");
92     }
93     else
94     {
95         print "No suitable pipe found for extension $ext.\n";
96     }
97 }
98
99 ### main
100
101 read_config ($0);
102
103 %pipes = ( 
104   "ac3", "a52dec ! $cfg{AUDIOSINK}",
105   "au", "auparse ! $cfg{AUDIOSINK}",
106   "avi", "decodebin name=d { d. ! queue ! $cfg{VIDEOSINK} } { d. ! queue ! audioconvert ! audioscale ! $cfg{AUDIOSINK} }",
107   "asf", "decodebin name=d ! { d. ! queue ! $cfg{VIDEOSINK} } { d. ! queue ! audioconvert ! audioscale ! $cfg{AUDIOSINK} }",
108   "flac", "flacdec ! $cfg{AUDIOSINK}",
109   "fli", "flxdec ! colorspace ! $cfg{VIDEOSINK}",
110   "m1v", "mpeg2dec ! $cfg{VIDEOSINK}",
111   "m2v", "mpeg2dec ! $cfg{VIDEOSINK}",
112   "m4a", "qtdemux .audio_00 ! { queue ! faad ! $cfg{AUDIOSINK} }",
113   "aac", "faad ! $cfg{AUDIOSINK}",
114   "mod", "modplug !  $cfg{AUDIOSINK}",
115   "mpc", "musepackdec ! $cfg{AUDIOSINK}",
116   "mp2", "mad ! $cfg{AUDIOSINK}",
117   "mp3", "mad ! $cfg{AUDIOSINK}",
118   "mp4", "decodebin name=d { d. ! queue ! ffmpegcolorspace ! videoscale ! $cfg{VIDEOSINK} } { d. ! queue ! audioconvert ! audioscale ! $cfg{AUDIOSINK} }",
119   "mpeg", "mpegdemux name=d { d.audio_00 ! queue ! mad ! audioconvert ! audioscale ! $cfg{AUDIOSINK} } { d.video_00 ! queue ! mpeg2dec ! $cfg{VIDEOSINK} }",
120   "mpg", "mpegdemux name=demux { demux.video_00 ! queue ! mpeg2dec ! ffmpegcolorspace ! $cfg{VIDEOSINK} } { demux.audio_00 ! queue ! mad ! $cfg{AUDIOSINK} }",
121   "ogg", "oggdemux ! vorbisdec ! audioconvert ! $cfg{AUDIOSINK}",
122   "sid", "siddec ! $cfg{AUDIOSINK}",
123   "swf", "swfdec name=swfdec ! { queue ! colorspace ! $cfg{VIDEOSINK} }  { swfdec. ! queue ! $cfg{AUDIOSINK} }",
124   "vob", "mpegdemux name=d { d.video_00 ! queue ! mpeg2dec ! $cfg{VIDEOSINK} } { d.audio_00 ! queue ! a52dec ! audioconvert ! audioscale ! $cfg{AUDIOSINK} }",
125   "wav", "wavparse ! $cfg{AUDIOSINK}",
126   "wm", "asfdemux name=demux ! { queue ! spider ! $cfg{VIDEOSINK} } { demux. ! queue ! spider ! $cfg{AUDIOSINK} }",
127 ### a wma file can use wmav1 or wmav2 codec so we must use spider to decode it  
128   "wma", "asfdemux name=demux ! spider ! $cfg{AUDIOSINK}",
129   "wmv", "asfdemux name=demux ! { queue ! spider ! $cfg{VIDEOSINK} } { demux. ! queue ! spider ! $cfg{AUDIOSINK} }",
130   "mkv", "matroskademux name=demux ! { queue ! spider ! $cfg{VIDEOSINK} } { demux. ! queue ! spider ! $cfg{AUDIOSINK} }",
131   "mka", "matroskademux ! spider ! $cfg{AUDIOSINK}",
132   "mov", "decodebin name=d { d. ! queue ! ffmpegcolorspace ! videoscale ! $cfg{VIDEOSINK} } { d. ! queue ! audioconvert ! audioscale ! $cfg{AUDIOSINK} }",
133 );
134
135 if ($cfg{VISUALIZER}) {
136   %pipes = (
137     %pipes,
138     "vis.mp3", "mad ! tee name=tee silent=true ! queue leaky=1 ! { $cfg{VISUALIZER} ! ffmpegcolorspace ! $cfg{VIDEOSINK} } tee. ! $cfg{AUDIOSINK}",
139     "vis.ogg", "vorbisdec ! tee name=tee silent=true ! queue leaky=1 ! { $cfg{VISUALIZER} ! ffmpegcolorspace ! $cfg{VIDEOSINK} } tee. ! $cfg{AUDIOSINK}",
140     "vis.wav", "wavparse ! tee name=tee silent=true ! queue leaky=1 ! { $cfg{VISUALIZER} ! ffmpegcolorspace ! $cfg{VIDEOSINK} } tee. ! $cfg{AUDIOSINK}",
141   );
142 }              
143
144 if ($#ARGV == -1) {
145     print STDERR "Usage: gst-launch-ext-@GST_MAJORMINOR@ filename[s]\n";
146     exit 1;
147 }
148
149 my $file;
150 while ($file = shift @ARGV) {
151     my $ext = extension ($file);
152     if (!$ext) { 
153       print "file $file doesn't have an extension !\n";
154       exit;
155     }
156     if ($ext eq 'm3u')
157     {
158         open (PLAYLIST, '<', $file);
159         my $file2;
160         while ($file2 = <PLAYLIST>) {
161             chomp $file2;
162             my $ext2 = extension ($file2);
163             playfile($file2, $ext2);
164         }
165         close PLAYLIST;
166     } else {
167         playfile($file, $ext);
168     }
169 }