Drawing from multiple threads
- From: Matteo Landi <landimatte gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Drawing from multiple threads
- Date: Mon, 26 Jul 2010 18:15:46 +0200
Hi all,
these days I'm trying create a very simple spectrum analyzer using gtk
and gstreamer.
Basically there is a method invoked from the outside (gstreamer
thread) notifying me about the presence of a new audio buffer.
Inside this method, I create a new thread which: compute the fft of
the signal, create a Surface, draw the results on it and at the end
queues a redraw of the widget.
Let's see some snippet of code:
class MyWindow():
def __init__(self):
...
darea = DrawingArea()
darea.connect('configure', self.configure_cb)
darea.connect('expose', self.expose_cb)
...
def configure_cb():
self.surface = ..
def expose_cb():
# copy self.surface
def new_audio_buffer_helper(self, buffer):
Thread(target=self.new_audio_buffer, args=(buffer,))
def new_audio_buffer(self, buffer):
fft = ..
surface = ..
# drawing actions
gobject.idle_add(self.refresh, surface)
def refresh(self, surface):
self.surface = surface
self.queue_draw()
Is this the right way to code in this scenario? Should I protect the
private variable 'surface' even though only the main thread access to
it? Should I need to skip any redrawing actions in order to prevent
potential delay between audio and video?
Thanks in advance.
--
Matteo Landi
http://www.matteolandi.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]