1.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/gstreamer.py Thu Apr 19 15:13:48 2007 +0100
1.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gstreamer.py Thu Apr 19 15:41:49 2007 +0100
1.3 @@ -42,6 +42,7 @@
1.4
1.5 def __init__(self, params):
1.6 server.Transcoder.__init__(self, params)
1.7 + gobject.threads_init ()
1.8 # set gstreamer basic options
1.9 self.connection = None
1.10 self.addr = None
1.11 @@ -56,7 +57,7 @@
1.12 self.log.info("Opening Uri:" + uri)
1.13 src = gst.element_make_from_uri(gst.URI_SRC, uri, "src")
1.14 decode = gst.element_factory_make("decodebin", "decode")
1.15 - mux = gst.element_factory_make("avimux", "mux")
1.16 + mux = gst.element_factory_make("ffmux_mpeg", "mux")
1.17 sink = gst.element_factory_make("fdsink", "sink")
1.18
1.19 return [src, decode, mux, sink]
1.20 @@ -67,10 +68,13 @@
1.21 vqueue = gst.element_factory_make("queue", "vqueue")
1.22 colorspace = gst.element_factory_make("ffmpegcolorspace", "")
1.23 vrate = gst.element_factory_make("videorate", "vrate")
1.24 - vencode = gst.element_factory_make("ffenc_mpeg4", "vencode")
1.25 + #vencode = gst.element_factory_make("ffenc_mpeg4", "vencode")
1.26 + vencode = gst.element_factory_make("ffenc_mpeg1video", "vencode")
1.27 vqueue_src = gst.element_factory_make("queue", "vqueue_src")
1.28
1.29 vencode.set_property("bitrate", 200)
1.30 + vencode.set_property ("pass", 2)
1.31 + vencode.set_property ("quantizer", 5)
1.32
1.33 if None in [vbin, vqueue, vrate, vencode, vqueue_src]:
1.34 self.log.info("Fail to create video encode elements.")
1.35 @@ -122,22 +126,42 @@
1.36 def _setup_audio_encode(self, abin):
1.37 aqueue = gst.element_factory_make("queue", "aqueue")
1.38 aconvert = gst.element_factory_make("audioconvert", "aconvert")
1.39 - arate = gst.element_factory_make("audioresample", "arate")
1.40 - aencode = gst.element_factory_make("queue", "aencode")
1.41 + #aencode = gst.element_factory_make("queue", "aencode")
1.42 + #aencode = gst.element_factory_make("ffenc_mp2", "aencode")
1.43 + aencode = gst.element_factory_make("lame", "aencode")
1.44 aqueue_src = gst.element_factory_make("queue", "aqueue_src")
1.45 -
1.46 - if None in [abin, aqueue, arate, aencode, aqueue_src]:
1.47 +
1.48 + if None in [abin, aqueue, aencode, aqueue_src]:
1.49 self.log.info("Fail to create video encode elements.")
1.50 return False
1.51
1.52 - abin.add(aqueue, aconvert, arate, aencode, aqueue_src)
1.53 + #aencode.set_property ("bitrate", 32)
1.54 + #aencode.set_property ("vbr-quality", 2)
1.55
1.56 - if not gst.element_link_many(aqueue, aconvert, arate, aencode, aqueue_src):
1.57 + abin.add(aqueue, aconvert, aencode, aqueue_src)
1.58 +
1.59 + self.log.info ("Link queue -> aconvert")
1.60 + if not aqueue.link (aconvert):
1.61 + self.log.info("Fail to link queue video")
1.62 + return False
1.63 +
1.64 + self.log.info ("Link aconvert -> aencode")
1.65 + if not aconvert.link (aencode):
1.66 self.log.info("Fail to link video elements")
1.67 return False
1.68
1.69 - abin.add_pad(gst.GhostPad("sink", aqueue.get_pad("sink")))
1.70 - abin.add_pad(gst.GhostPad("src", aqueue_src.get_pad("src")))
1.71 + self.log.info ("Link aencode -> aqueue_src")
1.72 + if not aencode.link (aqueue_src):
1.73 + self.log.info("Fail to link aencode -> aqueue_src")
1.74 + return False
1.75 +
1.76 + self.log.info ("Link:OK")
1.77 +
1.78 + ghost_sink = gst.GhostPad("sink", aqueue.get_pad("sink"))
1.79 + ghost_src = gst.GhostPad("src", aqueue_src.get_pad("src"))
1.80 + #ghost_src.set_caps (gst.caps_from_string ("audio/mpeg,mpegversion=(int)1,layer=(int)3,rate=(int)32000"))
1.81 + abin.add_pad(ghost_sink)
1.82 + abin.add_pad(ghost_src)
1.83
1.84 return True
1.85 # _setup_audio_encode()
1.86 @@ -208,6 +232,7 @@
1.87 def __on_bus_message(self, bus, message, stream_data):
1.88
1.89 t = message.type
1.90 + self.log.info ("__on_bus_message")
1.91
1.92 if t == gst.MESSAGE_STATE_CHANGED:
1.93 oldstate = -1
1.94 @@ -230,14 +255,18 @@
1.95
1.96 elif t == gst.MESSAGE_EOS:
1.97 self.log.info("Pipe finished")
1.98 - stream_data.Loop.quit()
1.99 - self.quit = True
1.100 + if stream_data.Ready:
1.101 + self.stop()
1.102 + else:
1.103 + stream_data.Loop.quit()
1.104
1.105 elif t == gst.MESSAGE_ERROR:
1.106 err, debug = message.parse_error()
1.107 self.log.error("Error: %s %s" %(err, debug))
1.108 - stream_data.Loop.quit()
1.109 - stream_data.Ready = False
1.110 + if stream_data.Ready:
1.111 + self.stop()
1.112 + else:
1.113 + stream_data.Loop.quit()
1.114
1.115 return True
1.116 # __on_bus_message()
1.117 @@ -270,7 +299,8 @@
1.118 def start(self, outfd):
1.119 params_first = self.params_first
1.120
1.121 - self.setup(params_first("uri", ""), params_first("mux", "avi"),
1.122 + uri = '%s://%s' % (params_first("uri_prefix", ""), params_first("uri_path", ""))
1.123 + self.setup(uri, params_first("mux", "avi"),
1.124 params_first("vcodec", "ffenc_h263p"), params_first("vbitrate", 256000),
1.125 params_first("fps", 25), params_first("acodec", "faac"),
1.126 params_first("abitrate", 192000), params_first("width", 320),
1.127 @@ -282,12 +312,7 @@
1.128 self.stream_data.Pipe.set_state(gst.STATE_PLAYING)
1.129
1.130 # keep playing until EOS
1.131 - self.log.info("QUIT: %s" % self.quit)
1.132 -
1.133 - i = 0
1.134 - loop = gobject.MainLoop()
1.135 - loop.run()
1.136 -
1.137 + self.stream_data.Loop.run()
1.138 self.log.info("quit loop")
1.139
1.140 return True
1.141 @@ -298,8 +323,9 @@
1.142
1.143 if self.stream_data:
1.144 self.stream_data.Pipe.set_state(gst.STATE_NULL)
1.145 - self.quit = True
1.146
1.147 + self.stream_data.Ready = False
1.148 + self.stream_data.Loop.quit ()
1.149 del self.stream_data
1.150 self.stream_data = None
1.151 # stop