Exemplo n.º 1
0
def send_seek_event(data):
    format = gst.FORMAT_TIME

    (position, fmt) = data.pipeline.query_position(format)
    if (not position):
        print >> sys.stderr, ("Unable to retrieve current position.")
        return

    seek_event = None
    #Create the seek event
    #http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gstreamer-GstEvent.html#gst-event-new-seek
    if (data.rate > 0.0):
        seek_event = gst.event_new_seek(
            data.rate, gst.FORMAT_TIME,
            (gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE), gst.SEEK_TYPE_SET,
            position, gst.SEEK_TYPE_SET, -1)
    else:
        seek_event = gst.event_new_seek(
            data.rate, gst.FORMAT_TIME,
            (gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE), gst.SEEK_TYPE_SET,
            0, gst.SEEK_TYPE_SET, position)
    if (not data.video_sink):
        data.video_sink = data.pipeline.get_property("video_sink")
    data.video_sink.send_event(seek_event)
    print("Current rate: {0.rate}".format(data))
def send_seek_event(data):
    format = gst.FORMAT_TIME
    (position, fmt) = data.pipeline.query_position(format)
    if not position:
        print >>sys.stderr, ("Unable to retrieve current position.")
        return

    seek_event = None
    # Create the seek event
    # http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gstreamer-GstEvent.html#gst-event-new-seek
    if data.rate > 0.0:
        seek_event = gst.event_new_seek(
            data.rate,
            gst.FORMAT_TIME,
            (gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE),
            gst.SEEK_TYPE_SET,
            position,
            gst.SEEK_TYPE_SET,
            -1,
        )
    else:
        seek_event = gst.event_new_seek(
            data.rate,
            gst.FORMAT_TIME,
            (gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE),
            gst.SEEK_TYPE_SET,
            0,
            gst.SEEK_TYPE_SET,
            position,
        )
    if not data.video_sink:
        data.video_sink = data.pipeline.get_property("video_sink")
    data.video_sink.send_event(seek_event)
    print("Current rate: {0.rate}".format(data))
Exemplo n.º 3
0
    def set_position(self, posicion):
        if not self.progressbar:
            return

        if self.duracion < posicion:
            return

        if self.duracion == 0 or posicion == 0:
            return

        posicion = self.duracion * posicion / 100

        # http://pygstdocs.berlios.de/pygst-reference/gst-constants.html
        #self.player.set_state(gst.STATE_PAUSED)
        # http://nullege.com/codes/show/
        #   src@d@b@dbr-HEAD@trunk@[email protected]/72/gst.SEEK_TYPE_SET
        #self.player.seek(
        #    1.0,
        #    gst.FORMAT_TIME,
        #    gst.SEEK_FLAG_FLUSH,
        #    gst.SEEK_TYPE_SET,
        #    posicion,
        #    gst.SEEK_TYPE_SET,
        #    self.duracion)

        # http://nullege.com/codes/show/
        #   src@c@o@congabonga-HEAD@congaplayer@congalib@[email protected]/
        #   104/gst.SEEK_FLAG_ACCURATE
        event = gst.event_new_seek(
            1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, posicion * 1000000000, gst.SEEK_TYPE_NONE,
            self.duracion * 1000000000)

        self.player.send_event(event)
Exemplo n.º 4
0
    def _add_audiosink(self, audio_sink, buffer_position):
        '''Sets up the new audiosink and syncs it'''

        self.add(audio_sink)
        audio_sink.sync_state_with_parent()
        gst.element_link_many(self._elements[-1], audio_sink)

        if buffer_position is not None:

            # buffer position is the output from get_position. If set, we
            # seek to that position.

            # TODO: this actually seems to skip ahead a tiny bit. why?

            # Note! this is super important in paused mode too, because when
            #       we switch the sinks around the new sink never goes into
            #       the paused state because there's no buffer. This forces
            #       a resync of the buffer, so things still work.

            seek_event = gst.event_new_seek(1.0, gst.FORMAT_DEFAULT,
                                            gst.SEEK_FLAG_FLUSH,
                                            gst.SEEK_TYPE_SET,
                                            buffer_position[0],
                                            gst.SEEK_TYPE_NONE, 0)

            self.send_event(seek_event)

        self.audio_sink = audio_sink
Exemplo n.º 5
0
  def setposition(self,trackid,t):
    """
    t in microseconds
    """
    if trackid != self.playlist.current:
        logging.warning( "setposition trackid is not current trackid")

    try:
      logging.info("set position")
      pos_int = self.player.query_duration(gst.FORMAT_TIME, None)[0]
      tnano=t*1000

      if tnano >= 0 and tnano <= pos_int : 
        logging.debug("set position to: %s; len: %s" % (str(t),str(pos_int)))

        #if wait: self.playbin.get_state(timeout=50*gst.MSECOND)
        event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                gst.SEEK_FLAG_FLUSH|gst.SEEK_FLAG_ACCURATE,
                gst.SEEK_TYPE_SET, tnano, gst.SEEK_TYPE_NONE, 0)
        res = self.player.send_event(event)
        if res:
          self.player.set_new_stream_time(0L)
        #if wait: self.playbin.get_state(timeout=50*gst.MSECOND)

        # this cause a doble seek with playbin2
        #self.player.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, t)

    except:
        logging.error( "in setposition")
Exemplo n.º 6
0
	def _seek_step(self, step):
		self.seeklock.acquire()
		new_pos = self.position+step*self.stepnanoseconds
		restrict = False
		duration = self.keyseeksinkpad.query_peer_duration(gst.FORMAT_TIME, None)[0]
		if new_pos < 0:
			print "Restrict!"
			new_pos = 0
			self.restrict = True
		elif new_pos >= duration:
			print "Restrict!"
			new_pos = duration-1
			self.restrict = True
		seek_event = gst.event_new_seek(self.rate, self.format, gst.SEEK_FLAG_KEY_UNIT | gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, new_pos, gst.SEEK_TYPE_NONE,0)
		# print "Doing keyseek to time %i" % (new_pos)
		res = self.keyseeksinkpad.push_event(seek_event)
		if not res:
			print "Seek for keyframe failed"
			self.backward_seek = False
			self.forward_seek = False
			self.step = 0
			self.gui_wait.release()
		else:
			# print "Step %i succeeded" % step
			self.step = step
		self.seeklock.release()
Exemplo n.º 7
0
 def seek(self, pos):
     pos = long(pos * 1000000000);
     event = gst.event_new_seek(gst.FORMAT_TIME |
                                gst.SEEK_METHOD_SET |
                                gst.SEEK_FLAG_FLUSH, pos);
     self.audio_sink.send_event(event);
     self.pipeline.set_state(gst.STATE_PLAYING);
Exemplo n.º 8
0
    def _add_audiosink(self, audio_sink, buffer_position):
        '''Sets up the new audiosink and syncs it'''
        
        self.add(audio_sink)
        audio_sink.sync_state_with_parent()
        gst.element_link_many(self._elements[-1], audio_sink)

        if buffer_position is not None:
            
            # buffer position is the output from get_position. If set, we
            # seek to that position.
            
            # TODO: this actually seems to skip ahead a tiny bit. why?
            
            # Note! this is super important in paused mode too, because when
            #       we switch the sinks around the new sink never goes into
            #       the paused state because there's no buffer. This forces
            #       a resync of the buffer, so things still work.
            
            seek_event = gst.event_new_seek(1.0, gst.FORMAT_DEFAULT,
                gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
                buffer_position[0],
                gst.SEEK_TYPE_NONE, 0)
            
            self.send_event(seek_event)
        
        self.audio_sink = audio_sink        
Exemplo n.º 9
0
    def setposition(self, trackid, t):
        """
    t in microseconds
    """
        if trackid != self.playlist.current:
            logging.warning("setposition trackid is not current trackid")

        try:
            logging.info("set position")
            pos_int = self.player.query_duration(gst.FORMAT_TIME, None)[0]
            tnano = t * 1000

            if tnano >= 0 and tnano <= pos_int:
                logging.debug("set position to: %s; len: %s" %
                              (str(t), str(pos_int)))

                #if wait: self.playbin.get_state(timeout=50*gst.MSECOND)
                event = gst.event_new_seek(
                    1.0, gst.FORMAT_TIME,
                    gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                    gst.SEEK_TYPE_SET, tnano, gst.SEEK_TYPE_NONE, 0)
                res = self.player.send_event(event)
                if res:
                    self.player.set_new_stream_time(0)
                #if wait: self.playbin.get_state(timeout=50*gst.MSECOND)

                # this cause a doble seek with playbin2
                #self.player.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, t)

        except:
            logging.error("in setposition")
Exemplo n.º 10
0
 def _seek_step(self, step):
     self.seeklock.acquire()
     new_pos = self.position + step * self.stepnanoseconds
     restrict = False
     duration = self.keyseeksinkpad.query_peer_duration(
         gst.FORMAT_TIME, None)[0]
     if new_pos < 0:
         print "Restrict!"
         new_pos = 0
         self.restrict = True
     elif new_pos >= duration:
         print "Restrict!"
         new_pos = duration - 1
         self.restrict = True
     seek_event = gst.event_new_seek(
         self.rate, self.format,
         gst.SEEK_FLAG_KEY_UNIT | gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
         new_pos, gst.SEEK_TYPE_NONE, 0)
     # print "Doing keyseek to time %i" % (new_pos)
     res = self.keyseeksinkpad.push_event(seek_event)
     if not res:
         print "Seek for keyframe failed"
         self.backward_seek = False
         self.forward_seek = False
         self.step = 0
         self.gui_wait.release()
     else:
         # print "Step %i succeeded" % step
         self.step = step
     self.seeklock.release()
Exemplo n.º 11
0
    def set_position(self, posicion):
        if not self.progressbar:
            return
        if self.duracion < posicion:
            return
        if self.duracion == 0 or posicion == 0:
            return
        posicion = self.duracion * posicion / 100

        # http://pygstdocs.berlios.de/pygst-reference/gst-constants.html
        #self.player.set_state(gst.STATE_PAUSED)
        # http://nullege.com/codes/show/
        #   src@d@b@dbr-HEAD@trunk@[email protected]/72/gst.SEEK_TYPE_SET
        #self.player.seek(
        #    1.0,
        #    gst.FORMAT_TIME,
        #    gst.SEEK_FLAG_FLUSH,
        #    gst.SEEK_TYPE_SET,
        #    posicion,
        #    gst.SEEK_TYPE_SET,
        #    self.duracion)
        # http://nullege.com/codes/show/
        #   src@c@o@congabonga-HEAD@congaplayer@congalib@[email protected]/
        #   104/gst.SEEK_FLAG_ACCURATE

        event = gst.event_new_seek(
            1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, posicion * 1000000000,
            gst.SEEK_TYPE_NONE, self.duracion * 1000000000)
        self.player.send_event(event)
    def _do_seek(self, pad, flush, first=False):
        start, stop =  self.cue_points[0]
        del self.cue_points[0]

        self.info("Preparing segment:  start=%s stop=%s" %
            (gst.TIME_ARGS(start), gst.TIME_ARGS(stop)))

        flags = gst.SEEK_FLAG_ACCURATE
        if flush:
            flags = flags | gst.SEEK_FLAG_FLUSH
        if len(self.cue_points) != 0:
            flags = flags | gst.SEEK_FLAG_SEGMENT

        if start <= self.DEFAULT_SEEK_GUARD:
            seek_start = 0
        else:
            seek_start = start - self.seek_guard

        self.info("Sending seek event:  start=%s stop=%s" %
            (gst.TIME_ARGS(seek_start), gst.TIME_ARGS(stop)))
        # After a segment-done event, the seek must be non-flushing in order to
        # process properly all the remaining buffers of the current segment. The
        # start of the new segment will really happen when we'll receive a
        # new-segment event with update=False.
        self._next_segment = self._make_segment(start, stop)
        event = gst.event_new_seek(1.0, gst.FORMAT_TIME, flags,
            gst.SEEK_TYPE_SET, seek_start + self._file_start,
            gst.SEEK_TYPE_SET, stop + self._file_start)

        reactor.callInThread(pad.push_event, event)

        if first:
            self._cur_segment[self.video_sinkpad] = self._next_segment
            self._cur_segment[self.audio_sinkpad] = self._next_segment
            self._need_seek = False
Exemplo n.º 13
0
 def _seek(self, seconds):
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, from_seconds(seconds), gst.SEEK_TYPE_NONE, 0)
     result = self.playbin.send_event(event)
     if not result:
         logging.error("seek failed")
Exemplo n.º 14
0
    def seek(self, location):
        print "seek to %ld on element %s" % (location, self.player.get_name())
        event = gst.event_new_seek(gst.FORMAT_TIME |
                                   gst.SEEK_METHOD_SET |
                                   gst.SEEK_FLAG_FLUSH, location)

        self.player.send_event(event)
        self.player.set_state(gst.STATE_PLAYING)
Exemplo n.º 15
0
    def seek(self, location):
        print "seek to %ld on element %s" % (location, self.player.get_name())
        event = gst.event_new_seek(
            gst.FORMAT_TIME | gst.SEEK_METHOD_SET | gst.SEEK_FLAG_FLUSH,
            location)

        self.player.send_event(event)
        self.player.set_state(gst.STATE_PLAYING)
Exemplo n.º 16
0
 def _seek(self, seconds):
     event = gst.event_new_seek(1.0,
                                gst.FORMAT_TIME,
                                gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                                gst.SEEK_TYPE_SET, from_seconds(seconds),
                                gst.SEEK_TYPE_NONE, 0)
     result = self.playbin.send_event(event)
     if not result:
         logging.error("seek failed")
Exemplo n.º 17
0
    def paused(self):
        sink = self.pipeline.get_by_name('sink')

        length = self._getSampleLength()
        if length is None:
            return

        if self._sampleLength < 0:
            self._sampleLength = length - self._sampleStart
            logger.debug('sampleLength is queried as %d samples',
                self._sampleLength)
        else:
            logger.debug('sampleLength is known, and is %d samples' %
                self._sampleLength)

        self._sampleEnd = self._sampleStart + self._sampleLength - 1
        logger.debug('sampleEnd is sample %d' % self._sampleEnd)

        logger.debug('event')


        if self._sampleStart == 0 and self._sampleEnd + 1 == length:
            logger.debug('No need to seek, crcing full file')
        else:
            # the segment end only is respected since -good 0.10.14.1
            event = gst.event_new_seek(1.0, gst.FORMAT_DEFAULT,
                gst.SEEK_FLAG_FLUSH,
                gst.SEEK_TYPE_SET, self._sampleStart,
                gst.SEEK_TYPE_SET, self._sampleEnd + 1) # half-inclusive
            logger.debug('CRCing %r from frame %d to frame %d (excluded)' % (
                self._path,
                self._sampleStart / common.SAMPLES_PER_FRAME,
                (self._sampleEnd + 1) / common.SAMPLES_PER_FRAME))
            # FIXME: sending it with sampleEnd set screws up the seek, we
            # don't get # everything for flac; fixed in recent -good
            result = sink.send_event(event)
            logger.debug('event sent, result %r', result)
            if not result:
                msg = 'Failed to select samples with GStreamer seek event'
                logger.critical(msg)
                raise Exception(msg)
        sink.connect('new-buffer', self._new_buffer_cb)
        sink.connect('eos', self._eos_cb)

        logger.debug('scheduling setting to play')
        # since set_state returns non-False, adding it as timeout_add
        # will repeatedly call it, and block the main loop; so
        #   gobject.timeout_add(0L, self.pipeline.set_state, gst.STATE_PLAYING)
        # would not work.

        def play():
            self.pipeline.set_state(gst.STATE_PLAYING)
            return False
        self.schedule(0, play)

        #self.pipeline.set_state(gst.STATE_PLAYING)
        logger.debug('scheduled setting to play')
Exemplo n.º 18
0
    def paused(self):
        sink = self.pipeline.get_by_name('sink')

        length = self._getSampleLength()
        if length is None:
            return

        if self._sampleLength < 0:
            self._sampleLength = length - self._sampleStart
            self.debug('sampleLength is queried as %d samples',
                       self._sampleLength)
        else:
            self.debug('sampleLength is known, and is %d samples' %
                       self._sampleLength)

        self._sampleEnd = self._sampleStart + self._sampleLength - 1
        self.debug('sampleEnd is sample %d' % self._sampleEnd)

        self.debug('event')

        if self._sampleStart == 0 and self._sampleEnd + 1 == length:
            self.debug('No need to seek, crcing full file')
        else:
            # the segment end only is respected since -good 0.10.14.1
            event = gst.event_new_seek(1.0, gst.FORMAT_DEFAULT,
                                       gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
                                       self._sampleStart, gst.SEEK_TYPE_SET,
                                       self._sampleEnd + 1)  # half-inclusive
            self.debug(
                'CRCing %r from frame %d to frame %d (excluded)' %
                (self._path, self._sampleStart / common.SAMPLES_PER_FRAME,
                 (self._sampleEnd + 1) / common.SAMPLES_PER_FRAME))
            # FIXME: sending it with sampleEnd set screws up the seek, we
            # don't get # everything for flac; fixed in recent -good
            result = sink.send_event(event)
            self.debug('event sent, result %r', result)
            if not result:
                self.error(
                    'Failed to select samples with GStreamer seek event')
        sink.connect('new-buffer', self._new_buffer_cb)
        sink.connect('eos', self._eos_cb)

        self.debug('scheduling setting to play')

        # since set_state returns non-False, adding it as timeout_add
        # will repeatedly call it, and block the main loop; so
        #   gobject.timeout_add(0L, self.pipeline.set_state, gst.STATE_PLAYING)
        # would not work.

        def play():
            self.pipeline.set_state(gst.STATE_PLAYING)
            return False

        self.schedule(0, play)

        #self.pipeline.set_state(gst.STATE_PLAYING)
        self.debug('scheduled setting to play')
Exemplo n.º 19
0
 def seek(self, seek=None):
     if seek is None:
         return True
     # 转换成纳秒
     seek = int(seek * 1000 * 1000 * 1000)
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, seek, gst.SEEK_TYPE_NONE, 0)
     return self.player.send_event(event)
Exemplo n.º 20
0
 def seek(self, time):
     event = gst.event_new_seek(1.0,\
                                gst.FORMAT_TIME,\
                                gst.SEEK_FLAG_FLUSH|gst.SEEK_FLAG_ACCURATE,\
                                gst.SEEK_TYPE_SET,\
                                time,\
                                gst.SEEK_TYPE_NONE, 0)
     res = self.player.send_event(event)
     if res:
         self.player.set_new_stream_time(0L)
Exemplo n.º 21
0
    def seek_end(self):
        event = gst.event_new_seek(
            1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_END, -1, gst.SEEK_TYPE_NONE, 0)

        res = self.pipeline.send_event(event)
        if res:
            gst.info("setting new stream time to 0")
        else:
            gst.error("seek to end failed")
Exemplo n.º 22
0
 def seek(self, seek=None):
     if seek is None:
         return True
     # 转换成纳秒
     seek = int(seek * 1000*1000*1000)
     event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
         gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, seek,
         gst.SEEK_TYPE_NONE, 0)
     return self.player.send_event(event)
Exemplo n.º 23
0
    def seek_end(self):
        event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_END, -1,
            gst.SEEK_TYPE_NONE, 0)

        res = self.pipeline.send_event(event)
        if res:
            gst.info("setting new stream time to 0")
        else:
            gst.error("seek to end failed")
Exemplo n.º 24
0
    def seek(self, position):
        if position == 0:
            location = 0
        else:
            duration = self._player.query_duration(gst.FORMAT_TIME, None)[0]
            location = duration * (position / 100)

        event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)
        res = self._player.send_event(event)
        if res:
            self._player.set_new_stream_time(0L)
Exemplo n.º 25
0
    def do_src_event(self, event):
        if event.type == gst.EVENT_SEEK:
            rate, format, flags, cur_type, cur, stop_type, stop = \
                    event.parse_seek()
            if cur_type == gst.SEEK_TYPE_SET and cur >= self.track.duration:
                cur = self.track.duration - 1 * gst.NSECOND
                new_event = gst.event_new_seek(rate, format, flags, cur_type, cur,
                        stop_type, stop)
                event = new_event

        return gst.BaseTransform.do_src_event(self, event)
Exemplo n.º 26
0
    def do_src_event(self, event):
        if event.type == gst.EVENT_SEEK:
            rate, format, flags, cur_type, cur, stop_type, stop = \
                    event.parse_seek()
            if cur_type == gst.SEEK_TYPE_SET and cur >= self.track.duration:
                cur = self.track.duration - 1 * gst.NSECOND
                new_event = gst.event_new_seek(rate, format, flags, cur_type, cur,
                        stop_type, stop)
                event = new_event

        return gst.BaseTransform.do_src_event(self, event)
Exemplo n.º 27
0
 def seek(self, location):
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)
     if self._playbin.send_event(event):
         mesk_log.debug('Seeking to location %r' % location)
         self._playbin.set_new_stream_time(0L)
         return True
     else:
         mesk_log.error('Seeking to location %r failed' % location)
         return False
Exemplo n.º 28
0
 def snapshot(self, t):
     """Set movie time to a specific time.
     """
     p = long(t * gst.MSECOND)
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, p, gst.SEEK_TYPE_NONE, 0)
     self.player.set_state(gst.STATE_PAUSED)
     res = self.player.send_event(event)
     if not res:
         print "snapshotter: error when sending event"
     return True
Exemplo n.º 29
0
    def seek(self, location):
        gst.debug("seeking to %r" % location)
        event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, location,
            gst.SEEK_TYPE_NONE, 0)

        res = self.player.send_event(event)
        if res:
            gst.info("setting new stream time to 0")
            self.player.set_new_stream_time(0L)
        else:
            gst.error("seek to %r failed" % location)
Exemplo n.º 30
0
 def set_position(self, posicion):
     if not self.progressbar:
         return
     if self.duracion < posicion:
         return
     if self.duracion == 0 or posicion == 0:
         return
     posicion = self.duracion * posicion / 100
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, posicion * 1000000000, gst.SEEK_TYPE_NONE,
         self.duracion * 1000000000)
     self.player.send_event(event)
Exemplo n.º 31
0
 def snapshot(self, t):
     """Set movie time to a specific time.
     """
     p = long(t * gst.MSECOND)
     event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                                gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                                gst.SEEK_TYPE_SET, p,
                                gst.SEEK_TYPE_NONE, 0)
     self.player.set_state(gst.STATE_PAUSED)
     res=self.player.send_event(event)
     if not res:
         print "Error when sending event"
     return True
Exemplo n.º 32
0
    def seek(self, position):
        if position == 0:
            location = 0
        else:
            duration = self._player.query_duration(gst.FORMAT_TIME, None)[0]
            location = duration * (position / 100)

        event = gst.event_new_seek(
            1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)
        res = self._player.send_event(event)
        if res:
            self._player.set_new_stream_time(0L)
Exemplo n.º 33
0
 def set_media_position(self, position):
     if not self.check_uri():
         return
     if self.current_status() == self.UndefinedStatus:
         self.player.set_state(gst.STATE_PAUSED)
     p = long(self.position2value(position) * gst.MSECOND)
     event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                                gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                                gst.SEEK_TYPE_SET, p,
                                gst.SEEK_TYPE_NONE, 0)
     res = self.player.send_event(event)
     if not res:
         raise InternalException
Exemplo n.º 34
0
 def seek(self, location):
     """
     @param location: time to seek to, in nanoseconds
     """
     gst.debug("seeking to %r" % location)
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)
     res = self.player.send_event(event)
     if res:
         gst.info("setting new stream time to 0")
         self.player.set_new_stream_time(0L)
     else:
         gst.error("seek to %r failed" % location)
 def set_position(self, posicion):
     if not self.progressbar:
         return
     if self.duracion < posicion:
         return
     if self.duracion == 0 or posicion == 0:
         return
     posicion = self.duracion * posicion / 100
     event = gst.event_new_seek(
         1.0, gst.FORMAT_TIME,
         gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, posicion * 1000000000,
         gst.SEEK_TYPE_NONE, self.duracion * 1000000000)
     self.player.send_event(event)
Exemplo n.º 36
0
    def seek(self, location):
        try:
            self.log.info('Seeking to {0}'.format(location))
            event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, 
                                        gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)

            res = self._player.send_event(event)
            if res:
                self.log.info('setting stream time to 0')
                self._player.set_new_stream_time(0L)
            else:
                self.log.error('error seeking to {0}'.format(location))

        except Exception, err:
            self.log.error('Error: ' + str(err))
Exemplo n.º 37
0
 def seek(self, location):
     """
     @param location: time to seek to, in nanoseconds
     """
     # gst.debug("seeking to %r" % location)
     event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
         gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
         gst.SEEK_TYPE_SET, location,
         gst.SEEK_TYPE_NONE, 0)
     res = self._pipeline.send_event(event)
     if res:
         # gst.info("setting new stream time to 0")
         self._pipeline.set_new_stream_time(0L)
     else:
         gst.error("seek to %r failed" % location)
Exemplo n.º 38
0
	def seek(self, location, bypos):
		location = (location + self.query_pos()[0] if bypos else location)

		try:
			event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
				gst.SEEK_FLAG_FLUSH,
				gst.SEEK_TYPE_SET, location,
				gst.SEEK_TYPE_NONE, 0)
		except:
			return False

		res = self.player.send_event(event)
		if res:
			self.player.set_new_stream_time(0L)
			return True
		return False
Exemplo n.º 39
0
    def seek(self, value):
        """
            seek to the given position in the current stream
        """
        if self._settle_flag == 1:
            event.add_callback(self._seek_delayed, "stream_settled", self)
            self._seek_event.clear()
            self._seek_event.wait()

        value = int(gst.SECOND * value)
        seekevent = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                                       gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
                                       value, gst.SEEK_TYPE_NONE, 0)

        self.vol.send_event(seekevent)
        # update this in case we're paused
        self.last_position = value
Exemplo n.º 40
0
    def seek(self, value):
        """
            seek to the given position in the current stream
        """
        value = int(gst.SECOND * value)
        event.log_event('seek', self, value)
        seekevent = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH,
            gst.SEEK_TYPE_SET, value, gst.SEEK_TYPE_NONE, 0)

        res = self.playbin.send_event(seekevent)
        if res:
            self.playbin.set_new_stream_time(0L)
        else:
            logger.debug("Couldn't send seek event")

        self.last_seek_pos = value
Exemplo n.º 41
0
    def seek(self, value):
        """
            seek to the given position in the current stream
        """
        new_position = int(gst.SECOND * value)
        seek_event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                                        gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
                                        new_position, gst.SEEK_TYPE_NONE, 0)

        res = self._pipe.send_event(seek_event)
        if res:
            self._pipe.set_new_stream_time(0L)
            # update this in case we're paused
            self._last_position = new_position
            event.log_event('playback_seeked', self, value)
        else:
            logger.debug("Couldn't send seek event")
Exemplo n.º 42
0
    def seek(self, value):
        """
            seek to the given position in the current stream
        """
        if self._settle_flag == 1:
            event.add_callback(self._seek_delayed, "stream_settled", self)
            self._seek_event.clear()
            self._seek_event.wait()

        value = int(gst.SECOND * value)
        seekevent = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH,gst.SEEK_TYPE_SET, value,
            gst.SEEK_TYPE_NONE, 0)

        self.vol.send_event(seekevent)
        # update this in case we're paused
        self.last_position = value
Exemplo n.º 43
0
    def seek(self, value):
        """
            seek to the given position in the current stream
        """
        new_position = int(gst.SECOND * value)
        seek_event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
            new_position,
            gst.SEEK_TYPE_NONE, 0)

        res = self._pipe.send_event(seek_event)
        if res:
            self._pipe.set_new_stream_time(0L)
            # update this in case we're paused
            self._last_position = new_position  
            event.log_event('playback_seeked', self, value)
        else:
            logger.debug("Couldn't send seek event")
Exemplo n.º 44
0
    def fast_forward(self):
        """
            Here we will fast forward the stream for as many times
            as this is called
        """
        if self.rate < 8.0:
            self.rate = self.rate*2.0
            event = gst.event_new_seek(self.rate, gst.FORMAT_TIME,
                gst.SEEK_FLAG_FLUSH,
                gst.SEEK_TYPE_SET, self.query_position()[0],
                gst.SEEK_TYPE_NONE, 0)

            res = self.player.send_event(event)
            if res:
                gst.info("fast forwarding at rate: %f" % self.rate)
                self.player.set_new_stream_time(0L)
            else:
                gst.error("change rate to %f failed" % self.rate)
        return
Exemplo n.º 45
0
    def slow_motion(self):
        """
            Here we will slow motion the stream for as many times
            as this is called
        """
        self.rate = self.rate/2.0
        event = gst.event_new_seek(self.rate, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH,
            gst.SEEK_TYPE_SET, self.query_position()[0],
            gst.SEEK_TYPE_NONE, 0)

        res = self.player.send_event(event)
        if res:
            gst.info("slowing playback to rate: %f" % self.rate)
            self.player.set_new_stream_time(0L)
        else:
            gst.error("change rate to %f failed" % self.rate)

        return
Exemplo n.º 46
0
    def play(self):
        """
            Change the stream state to playing or simply
            change its playing rate to normal rate
        """
        if self.rate != 1.0:
            self.rate = 1.0
            event = gst.event_new_seek(self.rate, gst.FORMAT_TIME,
                gst.SEEK_FLAG_FLUSH,
                gst.SEEK_TYPE_SET, self.query_position()[0],
                gst.SEEK_TYPE_NONE, 0)

            res = self.player.send_event(event)
            if res:
                gst.info("slowing playback to rate: %f" % self.rate)
                self.player.set_new_stream_time(0L)
            else:
                gst.error("change rate to %f failed" % self.rate)           
        else:
            gst.info("playing player")
            self.player.set_state(gst.STATE_PLAYING)
            self.playing = True
        return
Exemplo n.º 47
0
    def seek(self, location):
        """
        @param location:    simple number = time to seek to, in seconds
                            +nL = relative seek forward n seconds
                            -nL = relative seek backwards n seconds
        """

        _,state,_ = self.player.get_state()
        if state != gst.STATE_PAUSED:
            self.player.set_state(gst.STATE_PAUSED)
        l = long(location)*1000000000
        p = self.query_position()

        #print p['raw']['position'], l

        if location[0] == '+':
            l =  long(p[u'raw'][u'position']) + (long(location[1:])*1000000000)
            l = min( l, long(p[u'raw'][u'duration']))
        elif location[0] == '-':
            if location == '-0':
                l = 0L
            else:
                l = long(p[u'raw'][u'position']) - (long(location[1:])*1000000000)
                l = max( l, 0L)


        self.debug("seeking to %r" % l)
        """
        self.player.seek( 1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, l,
            gst.SEEK_TYPE_NONE, 0)

        """
        event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT,
            gst.SEEK_TYPE_SET, l,
            gst.SEEK_TYPE_NONE, 0)

        res = self.player.send_event(event)
        if res:
            pass
            #print "setting new stream time to 0"
            #self.player.set_new_stream_time(0L)
        elif location != '-0':
            print "seek to %r failed" % location

        if location == '-0':
            content_type, _ = self.mimetype.split("/")
            try:
                self.update_LC.stop()
            except:
                pass
            if self.player.get_name() != 'player':
                self.player.set_state(gst.STATE_NULL)
                self.player_clean = False
            elif content_type != "image":
                self.player.set_state(gst.STATE_READY)
            self.update()
        else:
            self.player.set_state(state)
            if state == gst.STATE_PAUSED:
                self.update()
Exemplo n.º 48
0
    def do_POST(self):
        length = int(self.headers.getheader('content-length'))        
        params = parse_qs(self.rfile.read(length))

        if self.path == "/inputs/add":
          if "url" not in params or "channel" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            newsource = params['url'][0]
            channel = int( params['channel'][0] )
            if newsource[:9] == "device://":
                for i in range(0, nbchannels):
                  if newsource == mixer.uri[i]:
                    #cannot add a camera two times, would crash
                    self.send_response(400, 'Bad request')
                    self.send_header('Content-type', 'html')
                    self.end_headers()
                    return
            if ( channel < 0 or channel >= nbchannels ):
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return

            #check if the source exists
            if newsource[:7] == "file://":
               if (not os.path.exists(newsource[7:]) ): 
                 self.send_response(400, 'Bad request')
                 self.send_header('Content-type', 'html')
                 self.end_headers()
                 return

            #determine the size of the source
            if newsource[:7] == "file://":
             mixer.uri[channel]=newsource
             self.send_response(200, 'OK')
             self.send_header('Content-type', 'html')
             self.end_headers()

             if os.path.exists('/usr/bin/ffprobe'):
               cmd = "/usr/bin/ffprobe -show_streams \"%s\" 2>&1 | grep width" % ( mixer.uri[channel][7:] )
               fwidth = commands.getoutput(cmd)
               widths = fwidth.split('=')
               #print "Video width %s" % widths[1];
               mixer.owidth[channel]=int(widths[1]) 
               cmd = "ffprobe -show_streams \"%s\" 2>&1 | grep height" % ( mixer.uri[channel][7:] )
               fheight = commands.getoutput(cmd)
               heights = fheight.split('=')
               #print "Video height %s" % heights[1];
               mixer.oheight[channel]=int(heights[1])
               cmd = "ffprobe -show_streams \"%s\" 2>&1 | grep audio" % ( mixer.uri[channel][7:] )
               audio = commands.getoutput(cmd)
               if audio == "codec_type=audio":
                  mixer.noaudio[channel]=False
               else:
                  mixer.noaudio[channel]=True
             else:
               print "warning : cannot detect video size ( is ffmpeg installed ?)"

            if newsource[:9] == "device://":
             if os.path.exists('/usr/bin/v4l-info'):
               cmd = "/usr/bin/v4l-info %s 2>/dev/null | grep fmt.pix.width | awk '{print $3}'" % ( newsource[9:] )
               width = commands.getoutput(cmd)
               cmd = "/usr/bin/v4l-info %s 2>/dev/null | grep fmt.pix.height | awk '{print $3}'" % ( newsource[9:] )
               height = commands.getoutput(cmd)
               if width != '':
                 self.send_response(200, 'OK')
                 self.send_header('Content-type', 'html')
                 self.end_headers()
                 mixer.uri[channel]=newsource
                 mixer.owidth[channel]=int(width) 
                 mixer.oheight[channel]=int(height)
               else:
                 self.send_response(400, 'Bad request')
                 self.send_header('Content-type', 'html')
                 self.end_headers()
                 return
             else:
               print "warning : cannot detect camera size ( is v4l-conf installed ?)"
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return

            if newsource[:7] == "rtsp://" or newsource[:7] == "rtmp://":
             mixer.uri[channel]=newsource
             if os.path.exists('/usr/bin/mplayer'):
               process = subprocess.Popen(['/usr/bin/mplayer','-endpos', '1', '-vo', 'null', '-ao', 'null', newsource], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
               streamis=False
               pv = re.compile('VO:')
               pa = re.compile('AO:')
               mixer.noaudio[channel]=True
               for line in process.stdout:
                  if pv.match( line ):
                    sizes=line.split(' '); 
                    wihe=sizes[2].split('x'); 
                    mixer.owidth[channel]=int(wihe[0]) 
                    mixer.oheight[channel]=int(wihe[1])
                    self.send_response(200, 'OK')
                    self.send_header('Content-type', 'html')
                    self.end_headers()
                    streamis=True
                  if pa.match( line ):
                    mixer.noaudio[channel]=False
               if not streamis:
                    self.send_response(200, 'OK')
                    self.send_header('Content-type', 'html')
                    self.end_headers()
             else:
               print "warning : cannot detect stream size ( is mplayer installed ?)"
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return

            if newsource[:7] == "http://":
             if os.path.exists('/usr/bin/mplayer'):
               process = subprocess.Popen(['/usr/bin/mplayer','-endpos', '1', '-vo', 'null', '-ao', 'null', newsource], shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
               streamis=False
               pv = re.compile('VO:')
               pa = re.compile('AO:')
               mixer.noaudio[channel]=True
               for line in process.stdout:
                  if pv.match( line ):
                    sizes=line.split(' '); 
                    wihe=sizes[2].split('x'); 
                    mixer.uri[channel]=newsource
                    mixer.owidth[channel]=int(wihe[0]) 
                    mixer.oheight[channel]=int(wihe[1])
                    self.send_response(200, 'OK')
                    self.send_header('Content-type', 'html')
                    self.end_headers()
                    streamis=True
                  if pv.match( line ):
                    mixer.noaudio[channel]=False
               if not streamis:
                    self.send_response(400, 'Bad request')
                    self.send_header('Content-type', 'html')
                    self.end_headers()
                    return
             else:
               print "warning : cannot detect remote video size ( is mplayer installed ?)"
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return

            #check if the image exists
            if newsource[:8] == "still://":
               if (not os.path.exists(newsource[8:]) ): 
                 self.send_response(400, 'Bad request')
                 self.send_header('Content-type', 'html')
                 self.end_headers()
                 return

            #determine the size of the source
            if newsource[:8] == "still://":
             mixer.uri[channel]=newsource
             self.send_response(200, 'OK')
             self.send_header('Content-type', 'html')
             self.end_headers()

             if os.path.exists('/usr/bin/ffprobe'):
               cmd = "/usr/bin/ffprobe -show_streams %s 2>&1 | grep width" % ( mixer.uri[channel][8:] )
               fwidth = commands.getoutput(cmd)
               widths = fwidth.split('=')
               #print "Video width %s" % widths[1];
               mixer.owidth[channel]=int(widths[1]) 
               cmd = "ffprobe -show_streams %s 2>&1 | grep height" % ( mixer.uri[channel][8:] )
               fheight = commands.getoutput(cmd)
               heights = fheight.split('=')
               #print "Video height %s" % heights[1];
               mixer.oheight[channel]=int(heights[1])
             else:
               print "warning : cannot detect video size ( is ffmpeg installed ?)"

            mixer.launch_pipe()
	    #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/inputs/delete":
          if "channel" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            if ( channel < 0 or channel >= nbchannels ):
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            mixer.uri[channel]=""
            mixer.launch_pipe()
	    #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/inputs/hide":
          if "channel" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            if ( channel < 0 or channel >= nbchannels ):
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.alpha=0.0

        elif self.path == "/inputs/show":
          if "channel" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            if ( channel < 0 or channel >= nbchannels ):
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.alpha=1.0

        elif self.path == "/inputs/alpha":
          if "channel" not in params or "alpha" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            alpha = float( params['alpha'][0] )
            if ( channel < 0 or channel >= nbchannels or alpha<0 or alpha>1.0 ):
               self.send_response(400, 'Bad request')
               self.send_header('Content-type', 'html')
               self.end_headers()
               return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.alpha=alpha

        elif self.path == "/inputs/move":
          if "channel" not in params or "posx" not in params or "posy" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            posx = int( params['posx'][0] )
            posy = int( params['posy'][0] )
            if posx < 0 or posy < 0 or channel < 0 or channel >= nbchannels:
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            mixer.xpos[channel]=posx
            mixer.ypos[channel]=posy
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.xpos=posx
                   pads[j].props.ypos=posy

        elif self.path == "/inputs/zorder":
          if "channel" not in params or "zorder" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            zorder = int( params['zorder'][0] )
            if channel < 0 or channel >= nbchannels or zorder<0:
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            mixer.zorder[channel]=zorder
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.zorder=zorder

        elif self.path == "/inputs/resize":
          if "channel" not in params or "width" not in params or "height" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            width = int( params['width'][0] )
            height = int( params['height'][0] )
            if width < 0 or height < 0 or channel < 0 or channel >= nbchannels:
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            mixer.owidth[channel]=width
            mixer.oheight[channel]=height
            pads=list(mixer.player.get_by_name("mix").sink_pads())
            for j in range(0, len(pads)):
                if pads[j].props.ename == "channel%d" % ( channel+1 ):
                   pads[j].props.width=width
                   pads[j].props.height=height

        elif self.path == "/seek":
          if "seconds" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            seconds = int( params['seconds'][0] )
            if seconds < 0:
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return

            # request is ok
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()

            event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                    gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                    gst.SEEK_TYPE_SET, seconds,
                    gst.SEEK_TYPE_NONE, 0)

            # try the seek
            res = mixer.player.send_event(event)
            if res:
               mixer.player.set_new_stream_time(0L)
	       mixer.player.set_state(gst.STATE_PLAYING)

        elif self.path == "/inputs/load":
          if "channel" not in params or "url" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            url = params['url'][0]
            if channel < 0 or channel >= nbchannels or ( mixer.uri[channel][:7] != "file://" and mixer.uri[channel][:8] != "still://" ):
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return

            # try to load the file for still or video ( but video will fail )
            kfilesrc=mixer.player.get_by_name("kfilesrc%d"%(channel+1))
            if mixer.uri[channel][:7] == "file://" and url[:7] == "file://":
               mixer.uri[channel]=url
               self.send_response(200, 'OK')
               self.send_header('Content-type', 'html')
               self.end_headers()

	       mixer.player.set_state(gst.STATE_PAUSED)
               event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                    gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                    gst.SEEK_TYPE_SET, 0,
                    gst.SEEK_TYPE_SET, 0)

               res = mixer.player.send_event(event)
               if res:
                   mixer.player.set_new_stream_time(0L)
               kfilesrc.set_property( "location", url[7:] )
	       mixer.player.set_state(gst.STATE_PLAYING)

               return

            if mixer.uri[channel][:8] == "still://" and url[:8] == "still://":
               mixer.uri[channel]=url
               self.send_response(200, 'OK')
               self.send_header('Content-type', 'html')
               self.end_headers()

	       mixer.player.set_state(gst.STATE_PAUSED)
               event = gst.event_new_seek(1.0, gst.FORMAT_TIME,
                    gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
                    gst.SEEK_TYPE_SET, 0,
                    gst.SEEK_TYPE_SET, 0)

               res = mixer.player.send_event(event)
               if res:
                   mixer.player.set_new_stream_time(0L)
               kfilesrc.set_property( "location", url[8:] )
	       mixer.player.set_state(gst.STATE_PLAYING)

               return

            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()

        elif self.path == "/inputs/detect":
          if "channel" not in params or "imagedir" not in params or "minscore" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          else:
            channel = int( params['channel'][0] )
            imagedir = params['imagedir'][0]
            minscore = int( params['minscore'][0] )
            if channel < 0 or channel >= nbchannels or minscore < 0:
              self.send_response(400, 'Bad request')
              self.send_header('Content-type', 'html')
              self.end_headers()
              return
            mixer.imagedir[channel]=imagedir
            mixer.minscore[channel]=minscore
            self.send_response(200, 'OK')
            self.send_header('Content-type', 'html')
            self.end_headers()
            mixer.launch_pipe()
	    #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/outputs/record":
          if "file" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          mixer.recfile=params['file'][0]
          self.send_response(200, 'OK')
          self.send_header('Content-type', 'html')
          self.end_headers()
          mixer.launch_pipe()
	  #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/outputs/stream":
          if "hostname" not in params or "audioport" not in params or "videoport" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          self.send_response(200, 'OK')
          self.send_header('Content-type', 'html')
          self.end_headers()
          mixer.hostname=params['hostname'][0]
          mixer.audioport=int(params['audioport'][0])
          mixer.videoport=int(params['videoport'][0])
          mixer.launch_pipe()
	  #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/outputs/icestream":
          if "hostname" not in params or "port" not in params or "mountpoint" not in params or "password" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          self.send_response(200, 'OK')
          self.send_header('Content-type', 'html')
          self.end_headers()
          mixer.icehost=params['hostname'][0]
          mixer.iceport=int(params['port'][0])
          mixer.icemount=params['mountpoint'][0]
          mixer.icepass=params['password'][0]
          mixer.launch_pipe()
	  #mixer.player.set_state(gst.STATE_PAUSED)

        elif self.path == "/outputs/state":
          if "state" not in params:
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
            return
          state=params['state'][0]
          if state != "start" and state != "stop":
            self.send_response(400, 'Bad request')
            self.send_header('Content-type', 'html')
            self.end_headers()
          self.send_response(200, 'OK')
          self.send_header('Content-type', 'html')
          self.end_headers()
          if state == "start":
             mixer.launch_pipe()
          if state == "stop":
	     mixer.player.set_state(gst.STATE_NULL)

        else:
          self.send_response(404, 'Not Found')
          self.send_header('Content-type', 'html')
          self.end_headers()
    def seek(self, location):
        """
        @param location:    simple number = time to seek to, in seconds
                            +nL = relative seek forward n seconds
                            -nL = relative seek backwards n seconds
        """

        _, state, _ = self.player.get_state()
        if state != gst.STATE_PAUSED:
            self.player.set_state(gst.STATE_PAUSED)
        l = long(location) * 1000000000
        p = self.query_position()

        #print p['raw']['position'], l

        if location[0] == '+':
            l = long(
                p[u'raw'][u'position']) + (long(location[1:]) * 1000000000)
            l = min(l, long(p[u'raw'][u'duration']))
        elif location[0] == '-':
            if location == '-0':
                l = 0L
            else:
                l = long(
                    p[u'raw'][u'position']) - (long(location[1:]) * 1000000000)
                l = max(l, 0L)

        self.debug("seeking to %r" % l)
        """
        self.player.seek( 1.0, gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
            gst.SEEK_TYPE_SET, l,
            gst.SEEK_TYPE_NONE, 0)

        """
        event = gst.event_new_seek(
            1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_KEY_UNIT,
            gst.SEEK_TYPE_SET, l, gst.SEEK_TYPE_NONE, 0)

        res = self.player.send_event(event)
        if res:
            pass
            #print "setting new stream time to 0"
            #self.player.set_new_stream_time(0L)
        elif location != '-0':
            print "seek to %r failed" % location

        if location == '-0':
            content_type, _ = self.mimetype.split("/")
            try:
                self.update_LC.stop()
            except:
                pass
            if self.player.get_name() != 'player':
                self.player.set_state(gst.STATE_NULL)
                self.player_clean = False
            elif content_type != "image":
                self.player.set_state(gst.STATE_READY)
            self.update()
        else:
            self.player.set_state(state)
            if state == gst.STATE_PAUSED:
                self.update()
Exemplo n.º 50
0
            # wavparse 0.10.14 returns in bytes
            if qformat == gst.FORMAT_BYTES:
                self.debug('query returned in BYTES format')
                length /= 4
            self.debug('total length: %r', length)
            self._frameLength = length - self._frameStart
            self.debug('audio frame length is %r', self._frameLength)
        else:
            self.debug('frameLength known, is %d' % self._frameLength)
        self._frameEnd = self._frameStart + self._frameLength - 1

        self.debug('event')

        # the segment end only is respected since -good 0.10.14.1
        event = gst.event_new_seek(
            1.0, gst.FORMAT_DEFAULT, gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET,
            self._frameStart, gst.SEEK_TYPE_SET,
            self._frameEnd + 1)  # half-inclusive interval
        self.debug('CRCing %r from sector %d to sector %d' %
                   (self._path, self._frameStart / common.SAMPLES_PER_FRAME,
                    (self._frameEnd + 1) / common.SAMPLES_PER_FRAME))
        # FIXME: sending it with frameEnd set screws up the seek, we don't get
        # everything for flac; fixed in recent -good
        result = sink.send_event(event)
        self.debug('event sent, result %r', result)
        sink.connect('new-buffer', self._new_buffer_cb)
        sink.connect('eos', self._eos_cb)

        self.debug('scheduling setting to play')

        # since set_state returns non-False, adding it as timeout_add
        # will repeatedly call it, and block the main loop; so
Exemplo n.º 51
0
	def seek(self, location):
		event = gst.event_new_seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, location, gst.SEEK_TYPE_NONE, 0)
		res = self.getPlayer().send_event(event)
		if res:
			self.getPlayer().set_new_stream_time(0L)
Exemplo n.º 52
0
            return True
        if s.has_field('gerror'):
            logger.error("MSG %s", msg.structure['debug'])

    def on_eos(bus, msg):
        mainloop.quit()

    bus = pipe.get_bus()
    bus.add_signal_watch()
    bus.connect('message::eos', on_eos)
    bus.connect('message', on_msg)

    logger.info("PLAYING")
    pipe.set_state(gst.STATE_PLAYING)

    # Increase playing rate
    if params['rate']:
        event = gst.event_new_seek(
            int(params['rate']), gst.FORMAT_TIME,
            gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, 0,
            gst.SEEK_TYPE_NONE, 0)
        res = pipe.send_event(event)

    try:
        mainloop.run()
    except:
        pass

    pipe.set_state(gst.STATE_NULL)
    pipe.get_state(gst.CLOCK_TIME_NONE)
Exemplo n.º 53
0
    def _handle_item(self):
        self.qlock.acquire()
        while self.running and not self.item_waiting:
            self.cond_del.wait()
        if self.running:
            if self.stored_buf != None:
                # print "Got Buffer with timestamp %i and forward_seek %r and backward_seek %r at position %i and segment position %i" % (self.stored_buf.timestamp,self.forward_seek,self.backward_seek,self.position, self.seg_position)
                if self.restrict or (
                        self.forward_seek and
                    (self.stored_buf.timestamp > self.position)) or (
                        self.backward_seek and
                        (self.stored_buf.timestamp < self.position)):
                    self.position = self.stored_buf.timestamp
                    self.forward_seek = False
                    self.backward_seek = False
                    self.step = 0
                    self.restrict = False
                    seek_event = gst.event_new_seek(
                        self.rate, self.format,
                        gst.SEEK_FLAG_ACCURATE | gst.SEEK_FLAG_FLUSH,
                        gst.SEEK_TYPE_SET, self.position, gst.SEEK_TYPE_NONE,
                        0)
                    res = self.secondsinkpad.push_event(seek_event)
                    if not res:
                        print "Secondary-seek failed"
                    self._push_segment()
                    self.gui_wait.release()
                    self.buf_result = self.keyseeksrcpad.push(self.stored_buf)
                    self.item_waiting = False
                    self.stored_buf = None
                    self.cond_add.notify()
                    self.qlock.release()
                elif self.forward_seek:
                    self.buf_result = gst.FLOW_OK
                    self.item_waiting = False
                    self.stored_buf = None
                    self.cond_add.notify()
                    self.qlock.release()
                    self._seek_step(self.step + 1)
                elif self.backward_seek:
                    self.buf_result = gst.FLOW_OK
                    self.item_waiting = False
                    self.stored_buf = None
                    self.cond_add.notify()
                    self.qlock.release()
                    self._seek_step(self.step - 1)
                else:
                    self.position = self.stored_buf.timestamp
                    # print "Pushing buffer with pts %i" % self.stored_buf.timestamp
                    self.buf_result = self.keyseeksrcpad.push(self.stored_buf)
                    # print "Result: %r" % self.buf_result
                    self.item_waiting = False
                    self.stored_buf = None
                    self.cond_add.notify()
                    self.qlock.release()
            else:
                if self.stored_event.type == gst.EVENT_NEWSEGMENT:
                    self.update, self.rate, self.format, self.start, self.stop, self.seg_position = self.stored_event.parse_new_segment(
                    )
                    # print "Received Segment with update=%r, rate=%r, format=%i, start=%i, stop=%i, position=%i" % (self.update,self.rate,self.format,self.start,self.stop,self.seg_position)
                    if (not self.forward_seek) and (not self.backward_seek):
                        # print "Forwarding segment"
                        self.event_result = self.keyseeksrcpad.push_event(
                            self.stored_event)
                    else:
                        self.event_result = True
                elif self.stored_event.type == gst.EVENT_EOS:
                    # print "Forwarding EOS"
                    self.event_result = self.keyseeksrcpad.push_event(
                        self.stored_event)
                    self.running = False
                    self.cond_add.notify_all()
                    self.cond_del.notify_all()
                    self.keyseeksrcpad.pause_task()

                else:
                    # print "Forwarding event %r" % self.stored_event.type
                    self.event_result = self.keyseeksrcpad.push_event(
                        self.stored_event)
                self.stored_event = None
                self.item_waiting = False
                self.cond_add.notify()
                self.qlock.release()
        else:
            self.qlock.release()
Exemplo n.º 54
0
            self.debug('total sample length of file: %r', length)
            self._sampleLength = length - self._sampleStart
            self.debug('sampleLength is queried as %d samples',
                self._sampleLength)
        else:
            self.debug('sampleLength is known, and is %d samples' %
                self._sampleLength)
        self._sampleEnd = self._sampleStart + self._sampleLength - 1
        self.debug('sampleEnd is sample %d' % self._sampleEnd)

        self.debug('event')


        # the segment end only is respected since -good 0.10.14.1
        event = gst.event_new_seek(1.0, gst.FORMAT_DEFAULT,
            gst.SEEK_FLAG_FLUSH,
            gst.SEEK_TYPE_SET, self._sampleStart,
            gst.SEEK_TYPE_SET, self._sampleEnd + 1) # half-inclusive interval
        self.debug('CRCing %r from sector %d to sector %d' % (
            self._path,
            self._sampleStart / common.SAMPLES_PER_FRAME,
            (self._sampleEnd + 1) / common.SAMPLES_PER_FRAME))
        # FIXME: sending it with sampleEnd set screws up the seek, we don't get
        # everything for flac; fixed in recent -good
        result = sink.send_event(event)
        self.debug('event sent, result %r', result)
        if not result:
            self.error('Failed to select samples with GStreamer seek event')
        sink.connect('new-buffer', self._new_buffer_cb)
        sink.connect('eos', self._eos_cb)

        self.debug('scheduling setting to play')
Exemplo n.º 55
0
	def _handle_item(self):
		self.qlock.acquire()
		while self.running and not self.item_waiting:
			self.cond_del.wait()
		if self.running:
			if self.stored_buf != None:
				# print "Got Buffer with timestamp %i and forward_seek %r and backward_seek %r at position %i and segment position %i" % (self.stored_buf.timestamp,self.forward_seek,self.backward_seek,self.position, self.seg_position)
				if self.restrict or (self.forward_seek and (self.stored_buf.timestamp > self.position)) or (self.backward_seek and (self.stored_buf.timestamp < self.position)):
					self.position = self.stored_buf.timestamp
					self.forward_seek = False
					self.backward_seek = False
					self.step = 0
					self.restrict = False
					seek_event = gst.event_new_seek(self.rate, self.format, gst.SEEK_FLAG_ACCURATE | gst.SEEK_FLAG_FLUSH, gst.SEEK_TYPE_SET, self.position, gst.SEEK_TYPE_NONE,0)
					res = self.secondsinkpad.push_event(seek_event)
					if not res:
						print "Secondary-seek failed"
					self._push_segment()
					self.gui_wait.release()
					self.buf_result = self.keyseeksrcpad.push(self.stored_buf)
					self.item_waiting = False
					self.stored_buf = None
					self.cond_add.notify()
					self.qlock.release()
				elif self.forward_seek:
					self.buf_result = gst.FLOW_OK
					self.item_waiting = False
					self.stored_buf = None
					self.cond_add.notify()
					self.qlock.release()
					self._seek_step(self.step+1)
				elif self.backward_seek:
					self.buf_result = gst.FLOW_OK
					self.item_waiting = False
					self.stored_buf = None
					self.cond_add.notify()
					self.qlock.release()
					self._seek_step(self.step-1)
				else:
					self.position = self.stored_buf.timestamp
					# print "Pushing buffer with pts %i" % self.stored_buf.timestamp
					self.buf_result = self.keyseeksrcpad.push(self.stored_buf)
					# print "Result: %r" % self.buf_result
					self.item_waiting = False
					self.stored_buf = None
					self.cond_add.notify()
					self.qlock.release()
			else:
				if self.stored_event.type == gst.EVENT_NEWSEGMENT:
					self.update, self.rate, self.format, self.start, self.stop, self.seg_position = self.stored_event.parse_new_segment()
					# print "Received Segment with update=%r, rate=%r, format=%i, start=%i, stop=%i, position=%i" % (self.update,self.rate,self.format,self.start,self.stop,self.seg_position)
					if (not self.forward_seek) and (not self.backward_seek):
						# print "Forwarding segment"
						self.event_result = self.keyseeksrcpad.push_event(self.stored_event)
					else:
						self.event_result = True
				elif self.stored_event.type == gst.EVENT_EOS:
					# print "Forwarding EOS"
					self.event_result = self.keyseeksrcpad.push_event(self.stored_event)
					self.running = False
					self.cond_add.notify_all()
					self.cond_del.notify_all()
					self.keyseeksrcpad.pause_task()

				else:
					# print "Forwarding event %r" % self.stored_event.type
					self.event_result = self.keyseeksrcpad.push_event(self.stored_event)
				self.stored_event = None
				self.item_waiting = False
				self.cond_add.notify()
				self.qlock.release()
		else:
			self.qlock.release()