diff options
author | MaZderMind <github@mazdermind.de> | 2015-06-18 13:47:05 +0200 |
---|---|---|
committer | MaZderMind <github@mazdermind.de> | 2015-06-18 13:47:05 +0200 |
commit | 2e7194ad7916bef47a8e322353a3cdbd27953697 (patch) | |
tree | aa76599f3d3d5c5d75b4f22c92a84b5e63a0be5e | |
parent | cbc4f78dc9ad35a5b3ae81139cb6d8ffe054cdee (diff) |
minimalistic start of a level-meter
-rw-r--r-- | voctogui/lib/ui.py | 9 | ||||
-rw-r--r-- | voctogui/lib/videodisplay.py | 54 | ||||
-rw-r--r-- | voctogui/ui/voctogui.ui | 44 |
3 files changed, 74 insertions, 33 deletions
diff --git a/voctogui/lib/ui.py b/voctogui/lib/ui.py index 54a56a1..e3e2db0 100644 --- a/voctogui/lib/ui.py +++ b/voctogui/lib/ui.py @@ -26,8 +26,8 @@ class Ui(UiBuilder): def configure_video_main(self): video = self.find_widget_recursive(self.win, 'video_main') - self.video_main_player = VideoDisplay(11000, video) - pass + audiolevel = self.find_widget_recursive(self.win, 'audiolevel_main') + self.video_main_player = VideoDisplay(11000, video, audiolevel, playaudio=True) def configure_video_previews(self): sources = ['cam1', 'cam2', 'grabber'] @@ -35,12 +35,15 @@ class Ui(UiBuilder): for idx, source in enumerate(sources): preview = self.get_check_widget('widget_preview', clone=True) + video = self.find_widget_recursive(preview, 'video') + + # video.set_size_request(160, 90) + box.pack_start(preview, fill=False, expand=False, padding=0) # http://stackoverflow.com/questions/3489520/python-gtk-widget-name self.find_widget_recursive(preview, 'label').set_label(source) - video = self.find_widget_recursive(preview, 'video') player = VideoDisplay(13000 + idx, video) self.preview_players[source] = player diff --git a/voctogui/lib/videodisplay.py b/voctogui/lib/videodisplay.py index 6537b78..b98daf1 100644 --- a/voctogui/lib/videodisplay.py +++ b/voctogui/lib/videodisplay.py @@ -4,23 +4,40 @@ from gi.repository import Gst, Gtk class VideoDisplay: """ Displays a Voctomix-Video-Stream into a GtkWidget """ - def __init__(self, port, widget): + def __init__(self, port, videowidget, audiolevelwidget=None, playaudio=False): self.log = logging.getLogger('VideoDisplay[%u]' % port) pipeline = """ videotestsrc ! timeoverlay ! video/x-raw,width=1920,height=1080 ! - xvimagesink + xvimagesink name=v """.format( port=port ) - self.log.info('launching gstreamer-pipeline for widget %s "%s":\n%s', widget.get_name(), Gtk.Buildable.get_name(widget), pipeline) + + if audiolevelwidget or playaudio: + pipeline += """ + audiotestsrc wave=blue-noise ! + audio/x-raw ! + level name=lvl interval=50000000 ! + """ + + if playaudio: + pipeline += """ + alsasink + """ + else: + pipeline += """ + fakesink + """ + + self.log.info('launching gstreamer-pipeline for widget %s "%s":\n%s', videowidget.get_name(), Gtk.Buildable.get_name(videowidget), pipeline) self.pipeline = Gst.parse_launch(pipeline) - widget.realize() - self.xid = widget.get_property('window').get_xid() + videowidget.realize() + self.xid = videowidget.get_property('window').get_xid() bus = self.pipeline.get_bus() bus.add_signal_watch() @@ -29,6 +46,12 @@ class VideoDisplay: bus.connect('message::error', self.on_error) bus.connect("sync-message::element", self.on_syncmsg) + if audiolevelwidget: + self.levelrms = [0, 0] + self.audiolevelwidget = audiolevelwidget + self.audiolevelwidget.connect('draw', self.on_level_draw) + bus.connect("message::element", self.on_level) + def run(self): self.pipeline.set_state(Gst.State.PLAYING) @@ -38,4 +61,23 @@ class VideoDisplay: msg.src.set_window_handle(self.xid) def on_error(self, bus, msg): - self.log.error('on_error():', msg.parse_error()) + self.log.error('on_error():', msg.parse_error()) + + def on_level_draw(self, widget, cr): + cr.set_source_rgb(1, 1, 1) + cr.set_line_width(10) + + cr.move_to(15, 0) + cr.line_to(15, self.levelrms[0]*-20) + cr.stroke() + + def on_level(self, bus, msg): + if msg.src.name != 'lvl': + return + + if msg.type != Gst.MessageType.ELEMENT: + return + + self.levelpeaks = msg.get_structure().get_value('peak') + self.levelrms = msg.get_structure().get_value('rms') + self.audiolevelwidget.queue_draw() diff --git a/voctogui/ui/voctogui.ui b/voctogui/ui/voctogui.ui index c4cf068..ca7dd32 100644 --- a/voctogui/ui/voctogui.ui +++ b/voctogui/ui/voctogui.ui @@ -160,7 +160,6 @@ <property name="can_focus">False</property> <child> <object class="GtkBox" id="box_left"> - <property name="width_request">320</property> <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> @@ -224,31 +223,16 @@ </packing> </child> <child> - <object class="GtkBox" id="box_video_mail"> + <object class="GtkDrawingArea" id="video_main"> + <property name="width_request">800</property> + <property name="height_request">450</property> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkDrawingArea" id="video_main"> - <property name="width_request">800</property> - <property name="height_request">450</property> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="double_buffered">False</property> - <property name="margin_left">5</property> - <property name="margin_right">5</property> - <property name="margin_top">5</property> - <property name="margin_bottom">5</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <placeholder/> - </child> + <property name="double_buffered">False</property> + <property name="margin_left">5</property> + <property name="margin_right">5</property> + <property name="margin_top">5</property> + <property name="margin_bottom">5</property> </object> <packing> <property name="expand">True</property> @@ -256,6 +240,18 @@ <property name="position">1</property> </packing> </child> + <child> + <object class="GtkDrawingArea" id="audiolevel_main"> + <property name="width_request">30</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> </object> <packing> <property name="expand">True</property> |