Esempio n. 1
0
    def _switch_data_type(self):
        self.isStream = not self.isStream
        if not self.isStream:
            self.isWhite = not self.isWhite

        logger.debug('switched to stream: %s and white: %s' % (self.isStream, self.isWhite,))

        # recall us again, over and over again dude
        return True
Esempio n. 2
0
    def OnDynamicPad(self, dbin, pad):
        logger.debug("OnDynamicPad Called! %s %s" % (dbin.get_name(), pad,))
        caps = pad.query_caps(None)

        logger.debug(' with capabilities: %s' % caps.to_string())

        if caps.to_string().startswith('audio'):
            pad.link(self.convert.get_static_pad('sink'))
        elif caps.to_string().startswith('video'):
            pad.link(self.videosink.get_static_pad('sink'))
Esempio n. 3
0
    def push_data(self, source):
        bff = self.copy_from_data() if self.isStream else self.build_white_black_stream(320, 240, 2)

        if bff is None:
            return True

        result  = source.emit('push-buffer', bff)
        logger.debug('pushed %s' % bff)

        if result != Gst.FlowReturn.OK:
            logger.debug('error on on_need_data: %s' % result)
            g_main_loop.quit()

        return True
Esempio n. 4
0
    def build_white_black_stream(self, width, height, depth):
        logger.debug('white: %s' % self.isWhite)
        # http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-data-spoof.html#section-spoof-appsrc
        size = width * height * depth
        bffer = Gst.Buffer.new_allocate(None, size, None)

        bffer.memset(0, 0x00 if self.isWhite else 0xff, size)

        bffer.pts = self.timestamp
        bffer.duration = Gst.util_uint64_scale_int(1, Gst.SECOND, 30)

        # NOTE: if you remove this line below the stream after the first
        # switch doesn't re-switch and the stream appears lagging
        self.timestamp += bffer.duration

        return bffer
Esempio n. 5
0
 def on_need_data(self, source, *args):
     logger.debug('on_need_dat')
     if not self.source_id:
         self.source_id = GObject.idle_add(self.push_data, source)
Esempio n. 6
0
 def on_new_buffer(self, appsink):
     with self.lock:
         bffer = appsink.emit('pull-sample')
         self.data = bffer
     # logger.info('. %s' % buffer.get_caps().to_string())
     logger.debug('pulled %s' % self.data)
Esempio n. 7
0
 def on_enough_data(self, *args):
     logger.debug('enough data')
     if self.source_id:
         GObject.source_remove(self.source_id)
         self.source_id = None
Esempio n. 8
0
        self.timestamp += bffer.duration

        return bffer

    def push_data(self, source):
        bff = self.copy_from_data() if self.isStream else self.build_white_black_stream(320, 240, 2)

        if bff is None:
            return True

        result  = source.emit('push-buffer', bff)
        logger.debug('pushed %s' % bff)

        if result != Gst.FlowReturn.OK:
            logger.debug('error on on_need_data: %s' % result)
            g_main_loop.quit()

        return True

    def on_enough_data(self, *args):
        logger.debug('enough data')
        if self.source_id:
            GObject.source_remove(self.source_id)
            self.source_id = None

if __name__ == '__main__':
    start=Main()
    logger.debug('start')
    g_main_loop.run()