Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Migrate to GStreamer 1.0 #407

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions src/freeseer/framework/multimedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import datetime
import logging
import os
import sys

import gobject
gobject.threads_init()
import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst, GstVideo

GObject.threads_init()
Gst.init(None)

from freeseer.framework.presentation import Presentation
from freeseer.framework.plugin import IOutput
Expand Down Expand Up @@ -58,16 +60,16 @@ def __init__(self, config, plugman, window_id=None, audio_feedback=None, cli=Fal
self.current_state = Multimedia.NULL

# Initialize Player
self.player = gst.Pipeline('player')
self.player = Gst.Pipeline()
bus = self.player.get_bus()
bus.add_signal_watch()
bus.enable_sync_message_emission()
bus.connect('message', self.on_message)
bus.connect('sync-message::element', self.on_sync_message)

# Initialize Entry Points
self.audio_tee = gst.element_factory_make('tee', 'audio_tee')
self.video_tee = gst.element_factory_make('tee', 'video_tee')
self.audio_tee = Gst.ElementFactory.make('tee', None)
self.video_tee = Gst.ElementFactory.make('tee', None)
self.player.add(self.audio_tee)
self.player.add(self.video_tee)

Expand All @@ -77,38 +79,42 @@ def __init__(self, config, plugman, window_id=None, audio_feedback=None, cli=Fal
## GST Player Functions
##
def on_message(self, bus, message):
# This mothod never seems to be run in Windows
# print "This message came from on_message"
# print t
t = message.type

if t == gst.MESSAGE_EOS:
if t == Gst.MessageType.EOS:
self.stop()

elif t == gst.MESSAGE_ERROR:
elif t == Gst.MessageType.ERROR:
err, debug = message.parse_error()
log.error(str(err) + str(debug))

elif message.structure is not None:
s = message.structure.get_name()

elif message.get_structure() is not None:
s = message.get_structure().get_name()
if s == 'level' and self.audio_feedback_event is not None:
msg = message.structure.to_string()
rms_dB = float(msg.split(',')[6].split('{')[1].rstrip('}'))

# This is an inaccurate representation of decibels into percent
# conversion, this code should be revisited.
try:
percent = (int(round(rms_dB)) + 50) * 2
except OverflowError:
percent = 0
self.audio_feedback_event(percent)
msg = message.get_structure().get_name()
#This code causes Linux to throw errors
# rms_dB = float(msg.split(',')[6].split('{')[1].rstrip('}'))

# # This is an inaccurate representation of decibels into percent
# # conversion, this code should be revisited.
# try:
# percent = (int(round(rms_dB)) + 50) * 2
# except OverflowError:
# percent = 0
# self.audio_feedback_event(percent)

def on_sync_message(self, bus, message):
if message.structure is None:
if message.get_structure() is None:
return
message_name = message.structure.get_name()
if message_name == 'prepare-xwindow-id' and self.window_id is not None:
message_name = message.get_structure().get_name()
# print "This message came from on_sync_message"
# print message_name
if message_name == 'prepare-window-handle' and self.window_id is not None:
imagesink = message.src
imagesink.set_property('force-aspect-ratio', True)
imagesink.set_xwindow_id(int(self.window_id))
imagesink.set_window_handle(int(self.window_id))
log.debug("Preview loaded into window.")

def set_window_id(self, window_id):
Expand All @@ -126,15 +132,15 @@ def record(self):
"""
Start recording.
"""
self.player.set_state(gst.STATE_PLAYING)
self.player.set_state(Gst.State.PLAYING)
self.current_state = Multimedia.RECORD
log.debug("Recording started.")

def pause(self):
"""
Pause recording.
"""
self.player.set_state(gst.STATE_PAUSED)
self.player.set_state(Gst.State.PAUSED)
self.current_state = Multimedia.PAUSE
log.debug("Gstreamer paused.")

Expand All @@ -143,7 +149,7 @@ def stop(self):
Stop recording.
"""
if self.current_state != Multimedia.NULL and self.current_state != Multimedia.STOP:
self.player.set_state(gst.STATE_NULL)
self.player.set_state(Gst.State.NULL)

self.unload_audiomixer()
self.unload_videomixer()
Expand Down Expand Up @@ -299,9 +305,9 @@ def load_output_plugins(self, plugins, record_audio, record_video, metadata):
elif type == IOutput.BOTH:
self.player.add(bin)
if record_audio:
self.audio_tee.link_pads("src%d", bin, "audiosink")
self.audio_tee.link_pads("src_%u", bin, "audiosink")
if record_video:
self.video_tee.link_pads("src%d", bin, "videosink")
self.video_tee.link_pads("src_%u", bin, "videosink")
self.output_plugins.append(bin)

return True
Expand Down Expand Up @@ -362,4 +368,4 @@ def unload_videomixer(self):
self.player.remove(plugin)

self.videomixer.unlink(self.video_tee)
self.player.remove(self.videomixer)
self.player.remove(self.videomixer)
14 changes: 7 additions & 7 deletions src/freeseer/plugins/audioinput/alsasrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
@author: Thanh Ha
'''

import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

from freeseer.framework.plugin import IAudioInput

Expand All @@ -40,14 +40,14 @@ class ALSASrc(IAudioInput):
os = ["linux", "linux2"]

def get_audioinput_bin(self):
bin = gst.Bin() # Do not pass a name so that we can load this input more than once.
bin = Gst.Bin() # Do not pass a name so that we can load this input more than once.

audiosrc = gst.element_factory_make("alsasrc", "audiosrc")
audiosrc = Gst.ElementFactory.make("alsasrc", "audiosrc")
bin.add(audiosrc)

# Setup ghost pad
pad = audiosrc.get_pad("src")
ghostpad = gst.GhostPad("audiosrc", pad)
pad = audiosrc.get_static_pad("src")
ghostpad = Gst.GhostPad.new("audiosrc", pad)
bin.add_pad(ghostpad)

return bin
14 changes: 7 additions & 7 deletions src/freeseer/plugins/audioinput/audiotestsrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
@author: Thanh Ha
'''

import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

from freeseer.framework.plugin import IAudioInput

Expand All @@ -41,14 +41,14 @@ class AudioTestSrc(IAudioInput):
os = ["linux", "linux2", "win32", "cygwin", "darwin"]

def get_audioinput_bin(self):
bin = gst.Bin() # Do not pass a name so that we can load this input more than once.
bin = Gst.Bin() # Do not pass a name so that we can load this input more than once.

audiosrc = gst.element_factory_make("audiotestsrc", "audiosrc")
audiosrc = Gst.ElementFactory.make("audiotestsrc", "audiosrc")
bin.add(audiosrc)

# Setup ghost pad
pad = audiosrc.get_pad("src")
ghostpad = gst.GhostPad("audiosrc", pad)
pad = audiosrc.get_static_pad("src")
ghostpad = Gst.GhostPad.new("audiosrc", pad)
bin.add_pad(ghostpad)

return bin
21 changes: 14 additions & 7 deletions src/freeseer/plugins/audioinput/autoaudiosrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

@author: Thanh Ha
'''
import sys

import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

from freeseer.framework.plugin import IAudioInput

Expand All @@ -41,14 +42,20 @@ class AutoAudioSrc(IAudioInput):
os = ["linux", "linux2", "win32", "cygwin", "darwin"]

def get_audioinput_bin(self):
bin = gst.Bin() # Do not pass a name so that we can load this input more than once.
bin = Gst.Bin() # Do not pass a name so that we can load this input more than once.
if sys.platform.startswith("linux"):
audiosrc = Gst.ElementFactory.make("autoaudiosrc", None)

audiosrc = gst.element_factory_make("autoaudiosrc", "audiosrc")
elif sys.platform in ["win32", "cygwin"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why you need to do this. If the plugin doesn't support windows then just remove it from the "os" list on line 41. The os variable represents what OSes this plugin supports and Freeseer will automatically filter the plugin out when someone tries to run it on an unsupported OS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in IRC my thinking was along the lines of, I knew that it didn't work currently but that it would probably be supported in an upcoming version of Gst so that it would a simple matter of just deleting the added code to allow Windows to use an audio source once the feature was implemented.

I didn't think at this point that this would be a functional product that I'd be delivering but one that could be built upon in the future.

# autoaudiosrc causes python to lock up in Windows
audiosrc = Gst.ElementFactory.make("audiotestsrc", None)


bin.add(audiosrc)

# Setup ghost pad
pad = audiosrc.get_pad("src")
ghostpad = gst.GhostPad("audiosrc", pad)
pad = audiosrc.get_static_pad("src")
ghostpad = Gst.GhostPad.new("audiosrc", pad)
bin.add_pad(ghostpad)

return bin
14 changes: 7 additions & 7 deletions src/freeseer/plugins/audioinput/jackaudiosrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import ConfigParser

# GStreamer
import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

# PyQt
from PyQt4.QtCore import SIGNAL
Expand All @@ -57,14 +57,14 @@ class JackAudioSrc(IAudioInput):
clientname = ""

def get_audioinput_bin(self):
bin = gst.Bin() # Do not pass a name so that we can load this input more than once.
bin = Gst.Bin() # Do not pass a name so that we can load this input more than once.

audiosrc = gst.element_factory_make("jackaudiosrc", "audiosrc")
audiosrc = Gst.ElementFactory.make("jackaudiosrc", "audiosrc")
bin.add(audiosrc)

# Setup ghost pad
pad = audiosrc.get_pad("src")
ghostpad = gst.GhostPad("audiosrc", pad)
pad = audiosrc.get_static_pad("src")
ghostpad = Gst.GhostPad.new("audiosrc", pad)
bin.add_pad(ghostpad)

return bin
Expand Down
16 changes: 8 additions & 8 deletions src/freeseer/plugins/audioinput/pulsesrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import logging

# GStreamer
import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

# PyQt
from PyQt4.QtCore import SIGNAL
Expand All @@ -57,17 +57,17 @@ class PulseSrc(IAudioInput):
source = ''

def get_audioinput_bin(self):
bin = gst.Bin() # Do not pass a name so that we can load this input more than once.
bin = Gst.Bin() # Do not pass a name so that we can load this input more than once.

audiosrc = gst.element_factory_make("pulsesrc", "audiosrc")
audiosrc = Gst.ElementFactory.make("pulsesrc", "audiosrc")
if self.source != '':
audiosrc.set_property('device', self.source)
log.debug('Pulseaudio source is set to %s' % str(audiosrc.get_property('device')))
bin.add(audiosrc)

# Setup ghost pad
pad = audiosrc.get_pad("src")
ghostpad = gst.GhostPad("audiosrc", pad)
pad = audiosrc.get_static_pad("src")
ghostpad = Gst.GhostPad.new("audiosrc", pad)
bin.add_pad(ghostpad)

return bin
Expand All @@ -77,7 +77,7 @@ def __get_sources(self):
Get a list of pairs in the form (name, description) for each pulseaudio source.
"""
result = []
audiosrc = gst.element_factory_make("pulsesrc", "audiosrc")
audiosrc = Gst.ElementFactory.make("pulsesrc", "audiosrc")
audiosrc.probe_property_name('device')
names = audiosrc.probe_get_values_name('device')
#should be getting actual device description, but .get_property('device-name') does not work
Expand Down
18 changes: 9 additions & 9 deletions src/freeseer/plugins/audiomixer/audiopassthrough/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import ConfigParser

# GStreamer
import pygst
pygst.require("0.10")
import gst
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GObject, Gst

# PyQt
from PyQt4.QtCore import SIGNAL
Expand All @@ -55,18 +55,18 @@ class AudioPassthrough(IAudioMixer):
widget = None

def get_audiomixer_bin(self):
bin = gst.Bin()
bin = Gst.Bin()

audiomixer = gst.element_factory_make("adder", "audiomixer")
audiomixer = Gst.ElementFactory.make("adder", "audiomixer")
bin.add(audiomixer)

# Setup ghost pad
sinkpad = audiomixer.get_pad("sink%d")
sink_ghostpad = gst.GhostPad("sink", sinkpad)
sinkpad = audiomixer.get_request_pad("sink_%u")
sink_ghostpad = Gst.GhostPad.new("sink", sinkpad)
bin.add_pad(sink_ghostpad)

srcpad = audiomixer.get_pad("src")
src_ghostpad = gst.GhostPad("src", srcpad)
srcpad = audiomixer.get_static_pad("src")
src_ghostpad = Gst.GhostPad.new("src", srcpad)
bin.add_pad(src_ghostpad)

return bin
Expand Down
Loading