Added a playback script, to exercise the endurance of gst-ducati
[glsdk/gst-plugin-ducati.git] / tools / playback.py
1 #! /usr/bin/python
2 import gobject
3 gobject.threads_init()
4 import gst
5 import sys
6 from argparse import ArgumentParser
7 import time
9 class Playlist(object):
10     def run(self):
11         parser = ArgumentParser()
12         parser.add_argument('--skip-after', type=int, default=0)
13         parser.add_argument('-d', dest='vs',action='store_const', const='dri2videosink', default='dri2videosink')
14         parser.add_argument('-k', dest='vs', action='store_const',  const='kmssink', default='')
15         parser.add_argument('-p', dest='vs',action='store_const', const='pvrvideosink', default='')
16         parser.add_argument('uris', nargs='+')
17         args = parser.parse_args()
18         
19         self.uris = args.uris
20         self.skip_after = args.skip_after
21         self.playbin = playbin = gst.element_factory_make("playbin2")
22         self.sink = gst.element_factory_make(args.vs)
23         self.playbin.set_property('video-sink', self.sink)
24         bus = playbin.get_bus()
25         bus.add_signal_watch()
26         bus.connect('message::eos', self.eos)
27         bus.connect('message::error', self.error)
29         self.current_index = -1
30         self.next()
32         self.loop = gobject.MainLoop()
33         self.loop.run()
34         playbin.set_state(gst.STATE_NULL)
36     def eos(self, bus, message):
37         print 'EOS'
38         self.next()
40     def error(self, bus, message):
41         gerror, debug = message.parse_error()
42         print 'ERROR', gerror.message, debug
43         self.next()
45     def next(self):
46         if self.current_index >= 0:
47             print '*** STOPPING ', self.uris[self.current_index]
48         playbin = self.playbin
49         playbin.set_state(gst.STATE_NULL)
50         self.current_index += 1
51         if self.current_index == len(self.uris):
52             self.loop.quit()
53             return
54         time.sleep(2)
56         playbin.props.uri = self.uris[self.current_index]
57         print '*** STARTING ', self.uris[self.current_index]
58         playbin.set_state(gst.STATE_PLAYING)
59         if self.skip_after:
60             gobject.timeout_add_seconds(self.skip_after, self.next)
61         
64 if __name__ == '__main__':
65     Playlist().run()