def add_layer(scenario, action): timeline = get_pipeline(scenario).props.timeline if len(timeline.get_layers()) == 0: GstValidate.print_action(action, "Adding first layer\n") timeline.append_layer() else: GstValidate.print_action(action, "Not adding layer, should be done by pitivi itself\n") return True
def zoom(scenario, action): timeline = get_pipeline(scenario).props.timeline GstValidate.print_action(action, action.type.replace('-', ' ') + "\n") {"zoom-fit": timeline.ui.set_best_zoom_ratio, "zoom-out": Zoomable.zoomOut, "zoom-in": Zoomable.zoomIn}[action.type]() return True
def zoom(scenario, action): timeline = scenario.pipeline.props.timeline.ui GstValidate.print_action(action, action.type.replace('-', ' ') + "\n") {"zoom-fit": timeline.parent.zoomFit, "zoom-out": timelineUtils.Zoomable.zoomOut, "zoom-in": timelineUtils.Zoomable.zoomIn}[action.type]() return True
def init(): global has_validate try: from gi.repository import GstValidate GstValidate.init() has_validate = GES.validate_register_action_types() GstValidate.register_action_type( "stop", "pitivi", stop, None, "Pitivi override for the stop action", GstValidate.ActionTypeFlags.NONE) except ImportError: has_validate = False
def init(): global has_validate try: from gi.repository import GstValidate GstValidate.init() has_validate = GES.validate_register_action_types() GstValidate.register_action_type("stop", "pitivi", stop, None, "Pitivi override for the stop action", GstValidate.ActionTypeFlags.NONE) except ImportError: has_validate = False
def set_state_func(scenario, action): wanted_state = action.structure["state"] if wanted_state is None: wanted_state = action.structure.get_name() if wanted_state == "play": wanted_state = "playing" elif wanted_state == "pause": wanted_state = "paused" if wanted_state == "paused": if scenario.__dict__.get("started", None) is None: return 1 return GstValidate.execute_action( GstValidate.get_action_type(action.type).overriden_type, action)
def setEditingMode(timeline, scenario, action): if not hasattr(scenario, "last_mode"): scenario.last_mode = None try: res, mode = GstValidate.utils_enum_from_str(GES.EditMode, action.structure["edit-mode"]) if not res: mode = GES.EditMode.EDIT_NORMAL else: mode = GES.EditMode(mode) except KeyError: mode = GES.EditMode.EDIT_NORMAL if mode == GES.EditMode.EDIT_RIPPLE: timeline.ui.get_parent().do_key_press_event(Event(Gdk.EventType.KEY_PRESS, keyval=Gdk.KEY_Shift_L)) if scenario.last_mode == GES.EditMode.EDIT_ROLL: timeline.ui.get_parent().do_key_release_event(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Control_L)) elif mode == GES.EditMode.EDIT_ROLL: timeline.ui.do_key_press_event(Event(Gdk.EventType.KEY_PRESS, keyval=Gdk.KEY_Control_L)) if scenario.last_mode == GES.EditMode.EDIT_RIPPLE: timeline.ui.do_key_release_event(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Shift_L)) else: cleanEditModes(timeline, scenario) scenario.last_mode = mode
def setEditingMode(timeline, scenario, action): try: mode = scenario.last_mode mode except AttributeError: scenario.last_mode = None try: res, mode = GstValidate.utils_enum_from_str(GES.EditMode, action.structure["edit-mode"]) if not res: mode = GES.EditMode.EDIT_NORMAL else: mode = GES.EditMode(mode) except KeyError: mode = GES.EditMode.EDIT_NORMAL if mode == GES.EditMode.EDIT_RIPPLE: timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_PRESS, keyval=Gdk.KEY_Shift_L)) if scenario.last_mode == GES.EditMode.EDIT_ROLL: timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Control_L)) elif mode == GES.EditMode.EDIT_ROLL: timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_PRESS, keyval=Gdk.KEY_Control_L)) if scenario.last_mode == GES.EditMode.EDIT_RIPPLE: timeline.ui.sendFakeEvent(Event(Gdk.EventType.KEY_RELEASE, keyval=Gdk.KEY_Shift_L)) else: cleanEditModes(timeline, scenario) scenario.last_mode = mode
def set_state(scenario, action): wanted_state = action.structure["state"] if wanted_state is None: wanted_state = action.structure.get_name() if wanted_state == "play": wanted_state = "playing" elif wanted_state == "pause": wanted_state = "paused" if wanted_state == "paused": if scenario.__dict__.get("started", None) is None: return 1 return GstValidate.execute_action(GstValidate.get_action_type(action.type).overriden_type, action)
def seek(scenario, action): res, wanted_position = GstValidate.utils_get_clocktime(action.structure, "start") get_pipeline(scenario).simple_seek(wanted_position) get_pipeline(scenario).connect("position", positionChangedCb, scenario, action, wanted_position) return GstValidate.ActionReturn.ASYNC
def remove_clip(scenario, action): try: next_action = scenario.get_actions()[1] except KeyError: next_action = None if next_action and next_action.type == "add-clip": if next_action.structure["element-name"] == action.structure["element-name"]: scenario.no_next_add_element = True GstValidate.print_action(action, "Just moving %s between layers, not removing it\n" % action.structure["element-name"]) return True action_type = GstValidate.get_action_type(action.type) return GstValidate.execute_action(action_type.overriden_type, action)
def stop(scenario, action): global monitor if monitor: monitor.checkWrongWindow() if action.structure.get_boolean("force")[0]: GstValidate.execute_action(GstValidate.get_action_type(action.type).overriden_type, action) timeline = get_pipeline(scenario).props.timeline project = timeline.get_asset() if project: project.setModificationState(False) GstValidate.print_action(action, "Force quiting, ignoring any" " changes in the project\n") timeline.ui.app.shutdown() return 1 GstValidate.print_action(action, "STOP: not doing anything in pitivi\n") return 1
def seek_func(scenario, action): res, wanted_position = GstValidate.utils_get_clocktime( action.structure, "start") assert res scenario.get_pipeline().simple_seek(wanted_position) scenario.get_pipeline().connect("position", position_changed_cb, scenario, action, wanted_position) return GstValidate.ActionReturn.ASYNC
def Parametter(name, desc, mandatory=False, possible_variables=None, types=None): p = GstValidate.ActionParameter() p.description = desc p.mandatory = mandatory p.name = name p.possible_variables = possible_variables p.types = types return p
def get_edge(structure): try: res, edge = GstValidate.utils_enum_from_str(GES.Edge, structure["edge"]) if not res: edge = GES.Edge.EDGE_NONE else: edge = GES.Edge(edge) except KeyError: edge = GES.Edge.EDGE_NONE return edge
def create_action_parameter(name, desc, mandatory=False, possible_variables=None, types=None): parameter = GstValidate.ActionParameter() parameter.description = desc parameter.mandatory = mandatory parameter.name = name parameter.possible_variables = possible_variables parameter.types = types return parameter
def init(): Gst.init(None) GstValidate.init() args = parse_options() if not args.scenario: args.scenario = os.environ.get('GST_VALIDATE_SCENARIO', None) # if we have both manual scenario creation and env, then the scenario # is executed twice... if 'GST_VALIDATE_SCENARIO' in os.environ: del os.environ['GST_VALIDATE_SCENARIO'] if not args.scenario: raise ValueError("No scenario file provided") if not args.server: raise ValueError("No server location provided") if not args.peer_id: raise ValueError("No peer id provided") if not args.html_source: raise ValueError("No HTML page provided") if not args.browser: raise ValueError("No Browser provided") return args
def init(): global has_validate try: from gi.repository import GstValidate GstValidate.init() has_validate = GES.validate_register_action_types() GstValidate.register_action_type("stop", "pitivi", stop, None, "Pitivi override for the stop action", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("seek", "pitivi", seek, None, "Pitivi override for the seek action", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("pause", "pitivi", set_state, None, "Pitivi override for the pause action", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("play", "pitivi", set_state, None, "Pitivi override for the pause action", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("set-state", "pitivi", set_state, None, "Pitivi override for the set-state action", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("edit-container", "pitivi", editContainer, None, "Start dragging a clip in the timeline", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("split-clip", "pitivi", split_clip, None, "Split a clip", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("add-layer", "pitivi", add_layer, None, "Add layer", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("remove-clip", "pitivi", remove_clip, None, "Remove clip", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type("select-clips", "pitivi", select_clips, [Parametter("clip-name", "The name of the clip to select", True, None, "str")], "Select clips", GstValidate.ActionTypeFlags.NONE) for z in ["zoom-fit", "zoom-out", "zoom-in"]: GstValidate.register_action_type(z, "pitivi", zoom, None, z, GstValidate.ActionTypeFlags.NO_EXECUTION_NOT_FATAL) GstValidate.register_action_type('set-zoom-level', "pitivi", setZoomLevel, None, z, GstValidate.ActionTypeFlags.NO_EXECUTION_NOT_FATAL) Gst.info("Adding pitivi::wrong-window-creation") GstValidate.Issue.register(GstValidate.Issue.new( GLib.quark_from_string("pitivi::wrong-window-creation"), "A new window for the sink has wrongly been created", "All sink should display their images in an embedded " "widget and thus not create a new window", GstValidate.ReportLevel.CRITICAL)) return True except ImportError: has_validate = False return False
def editContainer(scenario, action): timeline = get_pipeline(scenario).props.timeline container = timeline.get_element(action.structure["container-name"]) if container is None: for layer in timeline.get_layers(): for clip in layer.get_clips(): Gst.info("Exisiting clip: %s" % clip.get_name()) scenario.report_simple(GLib.quark_from_string("scenario::execution-error"), "Could not find container: %s" % action.structure["container-name"]) return 1 res, position = GstValidate.action_get_clocktime(scenario, action, "position") layer_prio = action.structure["new-layer-priority"] if res is False: return 0 edge = get_edge(action.structure) container_ui = container.ui setEditingMode(timeline, scenario, action) y = 21 - container_ui.translate_coordinates(timeline.ui, 0, 0)[1] if container.get_layer().get_priority() != layer_prio and layer_prio != -1: try: layer = timeline.get_layers()[layer_prio] Gst.info("Y is: %s Realized?? %s Priori: %s layer prio: %s" % (layer.ui.get_allocation().y, container_ui.get_realized(), container.get_layer().get_priority(), layer_prio)) y = layer.ui.get_allocation().y - container_ui.translate_coordinates(timeline.ui, 0, 0)[1] if y < 0: y += 21 elif y > 0: y -= 21 except IndexError: if layer_prio == -1: y = -5 else: layer = timeline.get_layers()[-1] alloc = layer.ui.get_allocation() y = alloc.y + alloc.height + 10 - container_ui.translate_coordinates(timeline.ui, 0, 0)[1] if not hasattr(scenario, "last_edge"): scenario.last_edge = edge if not hasattr(scenario, "dragging") or scenario.dragging is False \ or scenario.last_edge != edge: event_widget = container.ui if isinstance(container, GES.SourceClip): if edge == GES.Edge.EDGE_START: event_widget = container.ui.leftHandle elif edge == GES.Edge.EDGE_END: event_widget = container.ui.rightHandle scenario.dragging = True event = Event(Gdk.EventType.BUTTON_PRESS, button=1, y=y) with mock.patch.object(Gtk, "get_event_widget") as get_event_widget: get_event_widget.return_value = event_widget timeline.ui._button_press_event_cb(event_widget, event) event = Event(Gdk.EventType.MOTION_NOTIFY, button=1, x=Zoomable.nsToPixelAccurate(position) - container_ui.translate_coordinates(timeline.ui.layout.layers_vbox, 0, 0)[0], y=y, state=Gdk.ModifierType.BUTTON1_MASK) with mock.patch.object(Gtk, "get_event_widget") as get_event_widget: get_event_widget.return_value = container.ui timeline.ui._motion_notify_event_cb(None, event) GstValidate.print_action(action, "Editing %s to %s in %s mode, edge: %s " "with new layer prio: %d\n" % (action.structure["container-name"], Gst.TIME_ARGS(position), scenario.last_mode, edge, layer_prio)) _releaseButtonIfNeeded(scenario, action, timeline, container, edge, layer_prio, position, y) scenario.last_edge = edge return 1
def register_action_types(observer): if not isinstance(observer, ActionObserver): raise TypeError GstValidate.register_action_type( Actions.CREATE_OFFER.value, "webrtc", observer._action, None, "Instruct a create-offer to commence", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type(Actions.CREATE_ANSWER.value, "webrtc", observer._action, None, "Create answer", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.WAIT_FOR_NEGOTIATION_STATE.value, "webrtc", observer._action, None, "Wait for a specific negotiation state to be reached", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type(Actions.ADD_STREAM.value, "webrtc", observer._action, None, "Add a stream to the webrtcbin", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.ADD_DATA_CHANNEL.value, "webrtc", observer._action, None, "Add a data channel to the webrtcbin", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.SEND_DATA_CHANNEL_STRING.value, "webrtc", observer._action, None, "Send a message using a data channel", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.WAIT_FOR_DATA_CHANNEL_STATE.value, "webrtc", observer._action, None, "Wait for data channel to reach state", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type(Actions.CLOSE_DATA_CHANNEL.value, "webrtc", observer._action, None, "Close a data channel", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type(Actions.WAIT_FOR_DATA_CHANNEL.value, "webrtc", observer._action, None, "Wait for a data channel to appear", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.WAIT_FOR_DATA_CHANNEL_STRING.value, "webrtc", observer._action, None, "Wait for a data channel to receive a message", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type( Actions.WAIT_FOR_NEGOTIATION_NEEDED.value, "webrtc", observer._action, None, "Wait for a the on-negotiation-needed signal to fire", GstValidate.ActionTypeFlags.NONE) GstValidate.register_action_type(Actions.SET_WEBRTC_OPTIONS.value, "webrtc", observer._action, None, "Set some webrtc options", GstValidate.ActionTypeFlags.NONE)