def __init__(self, name): Device.__init__(self, name) self.ControlPanelClass = DskControlPanel self.file = ObservableVariable() self.file.changed.connect(self.file_changed) self.alpha = ObservableVariable(0) self.alpha.changed.connect(self.alpha_changed) # While input convert doesn't seem explicitly necessary, it seems to # give better performance. Not sure why. self.inputconvert = self.add_element('videoconvert') self.mixer = self.add_element('videomixer') self.outputconvert = self.add_element('videoconvert') self.add_input_video_port_on(self.inputconvert) self.inputconvert.link(self.mixer) self.mixer.link(self.outputconvert) self.add_output_video_port_on(self.outputconvert) self.mixer.get_static_pad('sink_0').set_property('zorder', 0) self.alpha.set_value(1.0)
def __init__(self, name): Device.__init__(self, name) self.ControlPanelClass = AudioTestGenControlPanel self.freqs = ObservableVariable([1000, 1000]) self.freqs.changed.connect(self.change_freqs) caps = Gst.caps_from_string(self.SINGLE_CHANNEL_AUDIO_CAPS) self.src0 = Gst.ElementFactory.make('audiotestsrc', None) self.bin.add(self.src0) self.src0.set_property('is-live', True) self.src1 = Gst.ElementFactory.make('audiotestsrc', None) self.bin.add(self.src1) self.src1.set_property('is-live', True) self.interleave = Gst.ElementFactory.make('interleave', None) self.bin.add(self.interleave) self.src0.link_filtered(self.interleave, caps) self.src1.link_filtered(self.interleave, caps) self.add_output_audio_port_on(self.interleave, "src") self.change_freqs(self.freqs.get_value())
def __init__(self, name, pattern=0): Device.__init__(self, name) self.ControlPanelClass = VideoTestGenControlPanel self.pattern = ObservableVariable(pattern) self.pattern.changed.connect(self.change_pattern) self.src = Gst.ElementFactory.make('videotestsrc', None) self.bin.add(self.src) self.src.set_property('pattern', self.pattern.get_value()) self.convert = Gst.ElementFactory.make('videoconvert', None) self.bin.add(self.convert) self.text_overlay = Gst.ElementFactory.make('textoverlay', None) self.bin.add(self.text_overlay) self.text_overlay.set_property("text", self.name) self.text_overlay.set_property("shaded-background", True) self.caps_filter = Gst.ElementFactory.make('capsfilter', None) self.bin.add(self.caps_filter) caps = Gst.caps_from_string(Device.DEFAULT_VIDEO_CAPS) self.caps_filter.set_property('caps', caps) self.src.link(self.text_overlay) self.text_overlay.link(self.convert) self.convert.link(self.caps_filter) self.add_output_video_port_on(self.caps_filter, "src")
class Dsk(Device): suggested_name = "dsk" suggested_readable_name = "DSK" def __init__(self, name): Device.__init__(self, name) self.ControlPanelClass = DskControlPanel self.file = ObservableVariable() self.file.changed.connect(self.file_changed) self.alpha = ObservableVariable(0) self.alpha.changed.connect(self.alpha_changed) # While input convert doesn't seem explicitly necessary, it seems to # give better performance. Not sure why. self.inputconvert = self.add_element('videoconvert') self.mixer = self.add_element('videomixer') self.outputconvert = self.add_element('videoconvert') self.add_input_video_port_on(self.inputconvert) self.inputconvert.link(self.mixer) self.mixer.link(self.outputconvert) self.add_output_video_port_on(self.outputconvert) self.mixer.get_static_pad('sink_0').set_property('zorder', 0) self.alpha.set_value(1.0) def file_changed(self, new_file): print "Setting file:", new_file self.filesrc = self.add_element('filesrc') self.gdkdec = self.add_element('gdkpixbufdec') self.convert = self.add_element('videoconvert') self.freeze = self.add_element('imagefreeze') self.caps = self.add_element('capsfilter') caps = Gst.caps_from_string(self.DEFAULT_VIDEO_CAPS) self.caps.set_property('caps', caps) self.filesrc.set_property('location', new_file) self.filesrc.link(self.gdkdec) self.gdkdec.link(self.convert) self.convert.link(self.freeze) self.freeze.link(self.caps) videomixer_pad = self.mixer.get_request_pad("sink_%u") self.caps.get_static_pad('src').link(videomixer_pad) self.filesrc.set_state(Gst.State.PLAYING) self.gdkdec.set_state(Gst.State.PLAYING) self.convert.set_state(Gst.State.PLAYING) self.freeze.set_state(Gst.State.PLAYING) self.caps.set_state(Gst.State.PLAYING) videomixer_pad.set_property('zorder', 1) def alpha_changed(self, alpha): pass
class Monitor(Device): suggested_name = "monitor" suggested_readable_name = "Monitor" def __init__(self, name, size, location): Device.__init__(self, name) self.ControlPanelClass = MonitorControlPanel self.size = ObservableVariable(size) self.size.changed.connect(self.change_size) self.location = ObservableVariable(location) self.location.changed.connect(self.change_location) self.convert = Gst.ElementFactory.make('videoconvert', None) self.bin.add(self.convert) self.scale = Gst.ElementFactory.make('videoscale', None) self.bin.add(self.scale) self.sink = Gst.ElementFactory.make('xvimagesink', None) self.bin.add(self.sink) caps = Gst.caps_from_string(Device.DEFAULT_VIDEO_CAPS) self.convert.link_filtered(self.scale, caps) self.scale.link(self.sink) self.add_input_video_port_on(self.convert) def get_sink(self): return self.sink def set_window_id(self, id): self.get_sink().set_window_handle(id) def change_size(self): self.display.set_size(*self.size.get_value()) def change_location(self): self.display.set_location(*self.location.get_value()) def prepare_for_removal(self): super(Monitor, self).prepare_for_removal() if self.display: self.display.close()
def __init__(self, name, size, location): Device.__init__(self, name) self.ControlPanelClass = MonitorControlPanel self.size = ObservableVariable(size) self.size.changed.connect(self.change_size) self.location = ObservableVariable(location) self.location.changed.connect(self.change_location) self.convert = Gst.ElementFactory.make('videoconvert', None) self.bin.add(self.convert) self.scale = Gst.ElementFactory.make('videoscale', None) self.bin.add(self.scale) self.sink = Gst.ElementFactory.make('xvimagesink', None) self.bin.add(self.sink) caps = Gst.caps_from_string(Device.DEFAULT_VIDEO_CAPS) self.convert.link_filtered(self.scale, caps) self.scale.link(self.sink) self.add_input_video_port_on(self.convert)
def __init__(self, name): Device.__init__(self, name) self.ControlPanelClass = UstreamProviderControlPanel self.url_and_key = ObservableVariable([None, None]) self.url_and_key.changed.connect(self.change_url_and_key) self.video_input_queue = Gst.ElementFactory.make('queue', None) self.bin.add(self.video_input_queue) self.videoconvert = Gst.ElementFactory.make('videoconvert', None) self.bin.add(self.videoconvert) self.videoencoder = Gst.ElementFactory.make('x264enc', None) self.bin.add(self.videoencoder) self.videoencoder.set_property('bitrate', 4000) self.videoencoder.set_property('bframes', 0) self.videoparse = Gst.ElementFactory.make('h264parse', None) self.bin.add(self.videoparse) self.videoparse_queue = Gst.ElementFactory.make('queue', None) self.bin.add(self.videoparse_queue) self.flvmux = Gst.ElementFactory.make('flvmux', None) self.bin.add(self.flvmux) self.flvmux.set_property('streamable', True) self.flvmux_queue = Gst.ElementFactory.make('queue', None) self.bin.add(self.flvmux_queue) self.rtmpsink = Gst.ElementFactory.make('fakesink', None) self.bin.add(self.rtmpsink) # Link elements self.video_input_queue.link(self.videoconvert) self.videoconvert.link(self.videoencoder) self.videoencoder.link(self.videoparse) videoparse_caps = Gst.caps_from_string( 'video/x-h264,level=(string)4.1,profile=main') self.videoparse.link_filtered(self.videoparse_queue, videoparse_caps) self.videoparse_queue.link(self.flvmux) self.flvmux.link(self.flvmux_queue) self.flvmux_queue.link(self.rtmpsink) # Add ports self.add_input_video_port_on(self.video_input_queue, "sink")
def __init__(self, name): Device.__init__(self, name) #self.ControlPanelClass = DeckControlPanel self.file_uri = ObservableVariable() self.file_uri.changed.connect(self.file_uri_changed) self.default_video = self.add_element('videotestsrc') self.default_video.set_property('pattern', 2) self.video_selector = self.add_element('input-selector') self.default_video.link(self.video_selector) self.default_audio = self.add_element('audiotestsrc') self.default_audio.set_property('wave', 4) self.audio_selector = self.add_element('input-selector') caps = Gst.caps_from_string(self.DEFAULT_AUDIO_CAPS) self.default_audio.link_filtered(self.audio_selector, caps) self.add_output_video_port_on(self.video_selector, 'src', 'video_out') self.add_output_audio_port_on(self.audio_selector, 'src', 'audio_out')
def __init__(self, name, inputs): Device.__init__(self, name) self.ControlPanelClass = SwitcherControlPanel self.program_active_id = ObservableVariable(0) self.preview_active_id = ObservableVariable(0) self.opacity = ObservableVariable(1.0) # Create elements that exist for all instances of the switcher self.prog_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prog_mixer) self.prev_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prev_mixer) # Add outputs for static mixer pads self.add_output_video_port_on(self.prog_mixer, "src", "prog_out") self.add_output_video_port_on(self.prev_mixer, "src", "prev_out") for input_id in range(inputs): # Create tee and create input tee = Gst.ElementFactory.make('tee', None) self.bin.add(tee) name = "in" + str(input_id + 1) self.add_input_video_port_on(tee, name, name) #pad = Gst.GhostPad.new(name, tee.get_static_pad("sink")) #self.bin.add_pad(pad) # Create queues queue1 = Gst.ElementFactory.make('queue', None) self.bin.add(queue1) queue2 = Gst.ElementFactory.make('queue', None) self.bin.add(queue2) # Link tee to queues pad = tee.get_request_pad("src_%u") toPad = queue1.get_static_pad("sink") pad.link(toPad) pad = tee.get_request_pad("src_%u") toPad = queue2.get_static_pad("sink") pad.link(toPad) # Link queues to videomixers pad = queue1.get_static_pad("src") toPad = self.prog_mixer.get_request_pad("sink_%u") pad.link(toPad) pad = queue2.get_static_pad("src") toPad = self.prev_mixer.get_request_pad("sink_%u") pad.link(toPad) if inputs >= 2: self.set_bus_input("preview", 1) self.set_bus_input("program", 0) else: self.set_bus_input("preview", 0) self.set_bus_input("program", 0) self.add_action("take", self.take, "Swap program and preview or set program") self.add_action("preview", self.preview, "Set preview") self.add_action("fade", self.fade, "Set fade position")
class Switcher(Device): suggested_name = "switcher" suggested_readable_name = "Switcher" def __init__(self, name, inputs): Device.__init__(self, name) self.ControlPanelClass = SwitcherControlPanel self.program_active_id = ObservableVariable(0) self.preview_active_id = ObservableVariable(0) self.opacity = ObservableVariable(1.0) # Create elements that exist for all instances of the switcher self.prog_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prog_mixer) self.prev_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prev_mixer) # Add outputs for static mixer pads self.add_output_video_port_on(self.prog_mixer, "src", "prog_out") self.add_output_video_port_on(self.prev_mixer, "src", "prev_out") for input_id in range(inputs): # Create tee and create input tee = Gst.ElementFactory.make('tee', None) self.bin.add(tee) name = "in" + str(input_id + 1) self.add_input_video_port_on(tee, name, name) #pad = Gst.GhostPad.new(name, tee.get_static_pad("sink")) #self.bin.add_pad(pad) # Create queues queue1 = Gst.ElementFactory.make('queue', None) self.bin.add(queue1) queue2 = Gst.ElementFactory.make('queue', None) self.bin.add(queue2) # Link tee to queues pad = tee.get_request_pad("src_%u") toPad = queue1.get_static_pad("sink") pad.link(toPad) pad = tee.get_request_pad("src_%u") toPad = queue2.get_static_pad("sink") pad.link(toPad) # Link queues to videomixers pad = queue1.get_static_pad("src") toPad = self.prog_mixer.get_request_pad("sink_%u") pad.link(toPad) pad = queue2.get_static_pad("src") toPad = self.prev_mixer.get_request_pad("sink_%u") pad.link(toPad) if inputs >= 2: self.set_bus_input("preview", 1) self.set_bus_input("program", 0) else: self.set_bus_input("preview", 0) self.set_bus_input("program", 0) self.add_action("take", self.take, "Swap program and preview or set program") self.add_action("preview", self.preview, "Set preview") self.add_action("fade", self.fade, "Set fade position") def set_bus_input(self, bus, input_id): print "Setting bus input: " + bus + ", " + str(input_id) high_pad_name = "sink_" + str(input_id) if bus == "program": mixer = self.prog_mixer low_pad_name = "sink_" + str(self.preview_active_id.get_value()) prev_high_pad_name = "sink_" + str(self.program_active_id.get_value()) elif bus == "preview": mixer = self.prev_mixer low_pad_name = "sink_" + str(self.program_active_id.get_value()) prev_high_pad_name = "sink_" + str(self.preview_active_id.get_value()) else: return # Arrange input z-orders pad = mixer.get_static_pad(high_pad_name) pad.set_property('zorder', 2) pad = mixer.get_static_pad(low_pad_name) pad.set_property('zorder', 1) # Iterate over all sink pads and set below it = mixer.iterate_sink_pads() while True: status, pad = it.next() if status != Gst.IteratorResult.OK: break if (pad.get_name() != high_pad_name and pad.get_name() != low_pad_name): pad.set_property("zorder", 0) pad.set_property("alpha", 1.0) # Update if bus == "program": self.program_active_id.set_value(input_id) elif bus == "preview": self.preview_active_id.set_value(input_id) self.set_opacity(self.opacity.get_value()) #self.debug_mixer(mixer) def debug_mixer(self, mixer): it = mixer.iterate_sink_pads() while True: status, pad = it.next() if status != Gst.IteratorResult.OK: break pad_info = "Pad: " + pad.get_name() pad_info = pad_info + " (zorder: " + str(pad.get_property("zorder")) pad_info = pad_info + ", alpha: " + str(pad.get_property('alpha')) + ")" print pad_info def take(self, program_id=None): if program_id is None: current_prog_id = self.program_active_id.get_value() current_prev_id = self.preview_active_id.get_value() self.set_bus_input("preview", current_prog_id) self.set_bus_input("program", current_prev_id) else: self.set_bus_input("program", int(program_id)) def preview(self, preview_id): self.set_bus_input("preview", int(preview_id)) def set_opacity(self, opacity): self.opacity.set_value(opacity) pad = self.prog_mixer.get_static_pad("sink_" + str(self.program_active_id.get_value())) if self.program_active_id.get_value() != self.preview_active_id.get_value(): pad.set_property("alpha", opacity) else: pad.set_property("alpha", 1.0) def fade(self, opacity): self.set_opacity(float(opacity))
class Switcher(Device): suggested_name = "switcher" suggested_readable_name = "Switcher" def __init__(self, name, inputs): Device.__init__(self, name) self.ControlPanelClass = SwitcherControlPanel self.program_active_id = ObservableVariable(0) self.preview_active_id = ObservableVariable(0) self.opacity = ObservableVariable(1.0) # Create elements that exist for all instances of the switcher self.prog_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prog_mixer) self.prev_mixer = Gst.ElementFactory.make('videomixer', None) self.bin.add(self.prev_mixer) # Add outputs for static mixer pads self.add_output_video_port_on(self.prog_mixer, "src", "prog_out") self.add_output_video_port_on(self.prev_mixer, "src", "prev_out") for input_id in range(inputs): # Create tee and create input tee = Gst.ElementFactory.make('tee', None) self.bin.add(tee) name = "in" + str(input_id + 1) self.add_input_video_port_on(tee, name, name) #pad = Gst.GhostPad.new(name, tee.get_static_pad("sink")) #self.bin.add_pad(pad) # Create queues queue1 = Gst.ElementFactory.make('queue', None) self.bin.add(queue1) queue2 = Gst.ElementFactory.make('queue', None) self.bin.add(queue2) # Link tee to queues pad = tee.get_request_pad("src_%u") toPad = queue1.get_static_pad("sink") pad.link(toPad) pad = tee.get_request_pad("src_%u") toPad = queue2.get_static_pad("sink") pad.link(toPad) # Link queues to videomixers pad = queue1.get_static_pad("src") toPad = self.prog_mixer.get_request_pad("sink_%u") pad.link(toPad) pad = queue2.get_static_pad("src") toPad = self.prev_mixer.get_request_pad("sink_%u") pad.link(toPad) if inputs >= 2: self.set_bus_input("preview", 1) self.set_bus_input("program", 0) else: self.set_bus_input("preview", 0) self.set_bus_input("program", 0) self.add_action("take", self.take, "Swap program and preview or set program") self.add_action("preview", self.preview, "Set preview") self.add_action("fade", self.fade, "Set fade position") def set_bus_input(self, bus, input_id): print "Setting bus input: " + bus + ", " + str(input_id) high_pad_name = "sink_" + str(input_id) if bus == "program": mixer = self.prog_mixer low_pad_name = "sink_" + str(self.preview_active_id.get_value()) prev_high_pad_name = "sink_" + str( self.program_active_id.get_value()) elif bus == "preview": mixer = self.prev_mixer low_pad_name = "sink_" + str(self.program_active_id.get_value()) prev_high_pad_name = "sink_" + str( self.preview_active_id.get_value()) else: return # Arrange input z-orders pad = mixer.get_static_pad(high_pad_name) pad.set_property('zorder', 2) pad = mixer.get_static_pad(low_pad_name) pad.set_property('zorder', 1) # Iterate over all sink pads and set below it = mixer.iterate_sink_pads() while True: status, pad = it.next() if status != Gst.IteratorResult.OK: break if (pad.get_name() != high_pad_name and pad.get_name() != low_pad_name): pad.set_property("zorder", 0) pad.set_property("alpha", 1.0) # Update if bus == "program": self.program_active_id.set_value(input_id) elif bus == "preview": self.preview_active_id.set_value(input_id) self.set_opacity(self.opacity.get_value()) #self.debug_mixer(mixer) def debug_mixer(self, mixer): it = mixer.iterate_sink_pads() while True: status, pad = it.next() if status != Gst.IteratorResult.OK: break pad_info = "Pad: " + pad.get_name() pad_info = pad_info + " (zorder: " + str( pad.get_property("zorder")) pad_info = pad_info + ", alpha: " + str( pad.get_property('alpha')) + ")" print pad_info def take(self, program_id=None): if program_id is None: current_prog_id = self.program_active_id.get_value() current_prev_id = self.preview_active_id.get_value() self.set_bus_input("preview", current_prog_id) self.set_bus_input("program", current_prev_id) else: self.set_bus_input("program", int(program_id)) def preview(self, preview_id): self.set_bus_input("preview", int(preview_id)) def set_opacity(self, opacity): self.opacity.set_value(opacity) pad = self.prog_mixer.get_static_pad( "sink_" + str(self.program_active_id.get_value())) if self.program_active_id.get_value( ) != self.preview_active_id.get_value(): pad.set_property("alpha", opacity) else: pad.set_property("alpha", 1.0) def fade(self, opacity): self.set_opacity(float(opacity))