-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
108 lines (87 loc) · 3.41 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygtk
import gtk
import gobject
import pygst
import gst
class Main:
def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title('Test Player')
window.set_default_size(200, 200)
window.connect('destroy', gtk.main_quit, 'WM destroy')
vbox = gtk.VBox()
window.add(vbox)
self.button = gtk.Button('Add')
self.button.connect('clicked', self.add_player)
vbox.add(self.button)
self.button = gtk.Button('Remove')
self.button.connect('clicked', self.remove_player)
vbox.add(self.button)
window.show_all()
self.player = gst.Pipeline('player')
source = gst.element_factory_make('filesrc', 'test-source')
source.set_property('location', '/home/jfanaian/Desktop/output.ogg')
decoder = gst.element_factory_make('decodebin')
decoder.connect('pad-added', self.on_pad_added)
self.video_sink = gst.element_factory_make('tee', 'video-output')
self.audio_sink = gst.element_factory_make('tee', 'audio-output')
self.player.add(source, decoder, self.video_sink, self.audio_sink)
gst.element_link_many(source, decoder)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect('message', self.on_message)
self.player.set_state(gst.STATE_READY)
def add_player(self, w):
video_pad = self.player.get_by_name('video-output').get_request_pad('src%d')
queue = gst.element_factory_make('queue')
video_out = gst.element_factory_make('autovideosink')
self.player.add(queue, video_out)
gst.element_link_many(queue, video_out)
video_pad.link(queue.get_static_pad('sink'))
queue.set_state(gst.STATE_PLAYING)
video_out.set_state(gst.STATE_PLAYING)
if (self.player.get_state()[1] != gst.STATE_PLAYING):
self.player.set_state(gst.STATE_PLAYING)
def remove_player(self, w):
pass
def on_message(self, bus, message):
t = message.type
if t == gst.MESSAGE_EOS:
self.player.set_state(gst.STATE_NULL)
elif t == gst.MESSAGE_ERROR:
self.player.set_state(gst.STATE_NULL)
err, debug = message.parse_error()
print 'Error: %s' % err, debug
def on_pad_added(self, element, pad):
try:
sink = self.video_sink.get_static_pad('sink')
pad.link(sink)
except gst.LinkError:
sink = self.audio_sink.get_static_pad('sink')
pad.link(sink)
#class TestSrc(gst.Bin):
#'''
#'''
#__gsttemplates__ = (
#gst.PadTemplate(
#'src%d',
#gst.PAD_SRC,
#gst.PAD_SOMETIMES,
#gst.caps_new_any(),
#)
#)
#def __init__(self, *args, **kwargs):
#gst.BaseSrc.__init__(self, *args, **kwargs)
#self.source = gst.element_factory_make('filesrc')
#self.source.set_property('location', '/home/jfanaian/Desktop/output.ogg')
#self.queue = gst.element_factory_make('queue')
#self.decoder = gst.element_factory_make('decodebin')
#self.decoder.connect('pad-added', self.on_pad_added)
#self.add(self.source, self.queue, self.decoder)
#def on_pad_added(self, element, pad):
#pass
#gobject.type_register(TestSrc)
#gst.element_register(TestSrc, 'testsrc')
Main()
gtk.gdk.threads_init()
gtk.main()