revert to previous version, add timeout though

This commit is contained in:
j 2009-06-24 14:15:56 -04:00
parent 3fdef4796f
commit acac26dad4
1 changed files with 21 additions and 25 deletions

View File

@ -45,22 +45,16 @@ class Video(gst.Pipeline):
self.sbin.connect('pad-added', self._sbinPadAddedCb)
self.set_state(gst.STATE_PAUSED)
self.get_state()
self.width = self.sink.width
self.height = self.sink.height
self.framerate = self.sink.framerate
self.getDuration()
self.frames = int((float(self.duration) / gst.SECOND) * float(self.framerate))
def _sbinPadAddedCb(self, unused_sbin, pad):
self.log("pad : %s" % pad)
pad.set_blocked_async (True, self._pad_blocked_cb)
def _pad_blocked_cb(self, pad, blocked):
if blocked:
#duration
if self.duration < 0:
q = gst.query_new_duration(gst.FORMAT_TIME)
if pad.query(q):
format, self.duration = q.parse_duration()
pad.link(self.csp.get_pad("sink"))
pad.set_blocked_async (False, self._pad_blocked_cb)
pad.link(self.csp.get_pad("sink"))
def _frameCb(self, unused_thsink, frame, timestamp):
self.log("image:%s, timestamp:%s" % (frame, gst.TIME_ARGS(timestamp)))
@ -79,6 +73,15 @@ class Video(gst.Pipeline):
# still some more thumbnails to process
gobject.idle_add(self._getFrame, self.queue.pop(0))
def getDuration(self):
if self.duration < 0:
pads = self.sink.sink_pads()
q = gst.query_new_duration(gst.FORMAT_TIME)
for pad in pads:
if pad.get_peer() and pad.get_peer().query(q):
format, self.duration = q.parse_duration()
return self.duration
def getFrame(self, timestamp, callback):
"""
Queue a frame request for the given timestamp,
@ -87,12 +90,12 @@ class Video(gst.Pipeline):
"""
self.log("timestamp %s" % gst.TIME_ARGS(timestamp))
#if self.duration < 0:
# self.getDuration()
if self.duration < 0:
self.getDuration()
#if timestamp > self.duration:
# self.log("timestamp %s > duration %s" % (timestamp, self.duration))
# return False
if timestamp > self.duration:
self.log("timestamp %s > duration %s" % (timestamp, self.duration))
return False
self.callback[timestamp] = callback
@ -108,11 +111,6 @@ class Video(gst.Pipeline):
def _getFrame(self, timestamp):
if not self._ready:
return
if timestamp > self.duration:
if self.mainloop:
self.mainloop.quit()
return
self.log("timestamp : %s" % gst.TIME_ARGS(timestamp))
self.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
gst.SEEK_TYPE_SET, timestamp,
@ -125,7 +123,6 @@ class Video(gst.Pipeline):
def callback(frame, timestamp):
self._frames[timestamp] = frame
self.mainloop.quit()
self._quit = False
def quit():
if self._quit:
self.mainloop.quit()
@ -136,7 +133,6 @@ class Video(gst.Pipeline):
gobject.timeout_add(1000, quit)
if self.getFrame(timestamp, callback):
self.mainloop.run()
frame = self._frames[timestamp]
del self._frames[timestamp]
return frame