2002-10-03 22:11:37 +00:00
|
|
|
#!/usr/bin/env python
|
2002-03-24 11:40:06 +00:00
|
|
|
#
|
|
|
|
# gst-python
|
|
|
|
# Copyright (C) 2002 David I. Lehn
|
|
|
|
#
|
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Library General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Library General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
#
|
2002-12-17 17:40:42 +00:00
|
|
|
# Author: David I. Lehn <dlehn@users.sourceforge.net>
|
2002-03-24 11:40:06 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2004-02-24 18:40:21 +00:00
|
|
|
import gst
|
2002-03-24 11:40:06 +00:00
|
|
|
import gtk
|
2002-11-07 07:32:19 +00:00
|
|
|
gtk.threads_init()
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
class DVDPlayer(object):
|
2002-03-24 11:40:06 +00:00
|
|
|
def idle(self, pipeline):
|
2002-11-07 07:32:19 +00:00
|
|
|
#gtk.threads_enter()
|
2002-03-24 11:40:06 +00:00
|
|
|
pipeline.iterate()
|
2002-11-07 07:32:19 +00:00
|
|
|
#gtk.threads_leave()
|
2002-03-24 11:40:06 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
def eof(self, sender):
|
|
|
|
print 'EOS, quiting'
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def mpegparse_newpad(self, parser, pad, pipeline):
|
2002-11-07 07:32:19 +00:00
|
|
|
#gtk.threads_enter()
|
2002-03-24 11:40:06 +00:00
|
|
|
print '***** a new pad %s was created' % pad.get_name()
|
|
|
|
if pad.get_name()[:6] == 'video_':
|
2003-01-10 00:18:33 +00:00
|
|
|
pad.link(self.v_queue.get_pad('sink'))
|
2004-02-24 18:40:21 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PAUSED)
|
2002-03-24 11:40:06 +00:00
|
|
|
self.pipeline.add(self.v_thread)
|
2004-02-24 18:40:21 +00:00
|
|
|
#self.v_thread.set_state(gst.STATE_PLAYING)
|
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2002-03-24 11:40:06 +00:00
|
|
|
elif pad.get_name() == 'private_stream_1.0':
|
2003-01-10 00:18:33 +00:00
|
|
|
pad.link(self.a_queue.get_pad('sink'))
|
2004-02-24 18:40:21 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PAUSED)
|
2002-03-24 11:40:06 +00:00
|
|
|
self.pipeline.add(self.a_thread)
|
2004-02-24 18:40:21 +00:00
|
|
|
#self.a_thread.set_state(gst.STATE_PLAYING);
|
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2002-03-24 11:40:06 +00:00
|
|
|
else:
|
|
|
|
print 'unknown pad: %s' % pad.get_name()
|
2002-11-07 07:32:19 +00:00
|
|
|
#gtk.threads_leave()
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
def mpegparse_have_size(self, videosink, width, height):
|
2002-11-07 07:32:19 +00:00
|
|
|
gtk.threads_enter()
|
2002-03-24 11:40:06 +00:00
|
|
|
self.gtk_socket.set_usize(width,height)
|
|
|
|
self.appwindow.show_all()
|
2002-11-07 07:32:19 +00:00
|
|
|
gtk.threads_leave()
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
def main(self, location, title, chapter, angle):
|
|
|
|
self.location = location
|
|
|
|
self.title = title
|
|
|
|
self.chapter = chapter
|
|
|
|
self.angle = angle
|
|
|
|
|
2002-03-24 11:40:06 +00:00
|
|
|
#gst_init(&argc,&argv);
|
|
|
|
#gnome_init('MPEG2 Video player','0.0.1',argc,argv);
|
|
|
|
|
|
|
|
ret = self.build()
|
|
|
|
if ret:
|
|
|
|
return ret
|
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
return self.run()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
print 'setting to PLAYING state'
|
|
|
|
|
2002-11-07 07:32:19 +00:00
|
|
|
gtk.threads_enter()
|
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_PLAYING)
|
2002-06-17 02:01:54 +00:00
|
|
|
|
|
|
|
gtk.idle_add(self.idle,self.pipeline)
|
|
|
|
|
|
|
|
gtk.main()
|
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.pipeline.set_state(gst.STATE_NULL)
|
2002-06-17 02:01:54 +00:00
|
|
|
|
2002-11-07 07:32:19 +00:00
|
|
|
gtk.threads_leave()
|
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
return 0
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
def build_video_thread(self):
|
|
|
|
# ***** pre-construct the video thread *****
|
2004-02-24 18:40:21 +00:00
|
|
|
self.v_thread = gst.Thread('v_thread')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.v_queue = gst.Element('queue','v_queue')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.v_decode = gst.Element('mpeg2dec','decode_video')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.color = gst.Element('colorspace','color')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.efx = gst.Element('identity','identity')
|
|
|
|
#self.efx = gst.Element('edgeTV','EdgeTV')
|
|
|
|
#self.efx = gst.Element('agingTV','AgingTV')
|
2002-06-17 02:01:54 +00:00
|
|
|
#effectv: diceTV: DiceTV
|
|
|
|
#effectv: warpTV: WarpTV
|
|
|
|
#effectv: shagadelicTV: ShagadelicTV
|
|
|
|
#effectv: vertigoTV: VertigoTV
|
2004-02-24 18:40:21 +00:00
|
|
|
#self.efx = gst.Element('revTV','RevTV')
|
|
|
|
#self.efx = gst.Element('quarkTV','QuarkTV')
|
2002-06-17 02:01:54 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.color2 = gst.Element('colorspace','color2')
|
2002-06-17 02:01:54 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.show = gst.Element('xvideosink','show')
|
2003-10-04 23:02:48 +00:00
|
|
|
#self.show = Element('sdlvideosink','show')
|
|
|
|
#self.show = Element('fakesink','fakesinkv')
|
2002-06-17 02:01:54 +00:00
|
|
|
#self.show.set_property('silent', 0)
|
|
|
|
#self.show.set_property('sync', 1)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
#self.deinterlace = gst.Element('deinterlace','deinterlace')
|
|
|
|
self.deinterlace = gst.Element('identity','deinterlace')
|
2002-06-17 02:01:54 +00:00
|
|
|
|
|
|
|
last = None
|
|
|
|
for e in (self.v_queue, self.v_decode, self.color, self.efx, self.color2, self.deinterlace, self.show):
|
2002-03-24 11:40:06 +00:00
|
|
|
self.v_thread.add(e)
|
2002-06-17 02:01:54 +00:00
|
|
|
if last:
|
2003-01-10 00:18:33 +00:00
|
|
|
last.link(e)
|
2002-06-17 02:01:54 +00:00
|
|
|
last = e
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
#self.v_queue.link(self.v_decode)
|
|
|
|
#self.v_decode.link(self.color)
|
|
|
|
#self.color.link(self.efx)
|
|
|
|
#self.efx.link(self.color2)
|
|
|
|
#self.color2.link(self.show)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
def build_audio_thread(self):
|
|
|
|
# ***** pre-construct the audio thread *****
|
2004-02-24 18:40:21 +00:00
|
|
|
self.a_thread = gst.Thread('a_thread')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.a_queue = gst.Element('queue','a_queue')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.a_decode = gst.Element('a52dec','decode_audio')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.osssink = gst.Element('osssink','osssink')
|
2003-10-04 23:02:48 +00:00
|
|
|
#self.osssink = Element('fakesink','fakesinka')
|
2002-06-17 02:01:54 +00:00
|
|
|
#self.osssink.set_property('silent', 0)
|
|
|
|
#self.osssink.set_property('sync', 0)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
for e in (self.a_queue, self.a_decode, self.osssink):
|
|
|
|
self.a_thread.add(e)
|
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
self.a_queue.link(self.a_decode)
|
|
|
|
self.a_decode.link(self.osssink)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
def build(self):
|
|
|
|
# ***** construct the main pipeline *****
|
2004-02-24 18:40:21 +00:00
|
|
|
self.pipeline = gst.Pipeline('pipeline')
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.src = gst.Element('dvdreadsrc','src');
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
self.src.connect('deep_notify',self.dnprint)
|
2002-03-24 11:40:06 +00:00
|
|
|
self.src.set_property('location', self.location)
|
|
|
|
self.src.set_property('title', self.title)
|
|
|
|
self.src.set_property('chapter', self.chapter)
|
|
|
|
self.src.set_property('angle', self.angle)
|
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
self.parse = gst.Element('mpegdemux','parse')
|
2002-06-17 02:01:54 +00:00
|
|
|
self.parse.set_property('sync', 0)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
self.pipeline.add(self.src)
|
|
|
|
self.pipeline.add(self.parse)
|
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
self.src.link(self.parse)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
|
|
|
# pre-construct the audio/video threads
|
|
|
|
self.build_video_thread()
|
|
|
|
self.build_audio_thread()
|
|
|
|
|
|
|
|
# ***** construct the GUI *****
|
|
|
|
#self.appwindow = gnome_app_new('DVD Player','DVD Player')
|
|
|
|
|
|
|
|
#self.gtk_socket = gtk_socket_new ()
|
|
|
|
#gtk_socket.show()
|
|
|
|
|
|
|
|
#gnome_app_set_contents(GNOME_APP(appwindow),
|
|
|
|
#GTK_WIDGET(gtk_socket));
|
|
|
|
|
|
|
|
#gtk_widget_realize (gtk_socket);
|
|
|
|
#gtk_socket_steal (GTK_SOCKET (gtk_socket),
|
|
|
|
#gst_util_get_int_arg (GTK_OBJECT(show), 'xid'));
|
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
self.parse.connect('new_pad',self.mpegparse_newpad, self.pipeline)
|
|
|
|
self.src.connect('eos',self.eof)
|
|
|
|
#show.connect('have_size',self.mpegparse_have_size, self.pipeline)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2003-01-10 00:18:33 +00:00
|
|
|
#self.pipeline.connect('error',self.pipeline_error)
|
|
|
|
#self.pipeline.connect('deep_notify',self.dnprint)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
return 0
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
def pipeline_error(self, sender, obj, error):
|
|
|
|
print "(%s) ERROR: %s: %s" % (self, obj.name(), error)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
def dnprint(self, sender, obj, param):
|
|
|
|
str = obj.get_property(param.name)
|
|
|
|
print '%s: %s = %s' % (sender.get_name(), param.name, str)
|
2002-03-24 11:40:06 +00:00
|
|
|
|
2004-02-24 18:40:21 +00:00
|
|
|
def main(args):
|
|
|
|
if len(sys.argv) < 5:
|
|
|
|
print 'usage: %s dvdlocation title chapter angle' % sys.argv[0]
|
|
|
|
return -1
|
|
|
|
|
|
|
|
location = sys.argv[1]
|
|
|
|
title = int(sys.argv[2])
|
|
|
|
chapter = int(sys.argv[3])
|
|
|
|
angle = int(sys.argv[4])
|
|
|
|
|
2002-06-17 02:01:54 +00:00
|
|
|
player = DVDPlayer()
|
2004-02-24 18:40:21 +00:00
|
|
|
return player.main(location, title, chapter, angle)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|