예제 #1
0
파일: engine.py 프로젝트: brunoabud/ic
    def _init_input(self, plugin_id):
        try:
            video_source = get_component("video_source")
            app = get_app()
            # Check if the plugin_id is valid
            new_plugin = self._get_plugin(plugin_id)
            if not new_plugin.plugin_type == PLUGIN_TYPE_VIDEO_INPUT:
                raise TypeError("Wrong Plugin Type {}".format(new_plugin.plugin_type))

            # Close the current input plugin if there is one
            if self.input_plugin is not None:
                current_id = self.input_plugin["plugin_id"]
                current_plugin = get_plugin(current_id)

                #Call the plugin close method
                try:
                    current_plugin.instance.close_plugin()
                except:
                    log.error("Error when closing the plugin", exc_info=True)
                #Release the gui interface
                try:
                    current_plugin.gui_interface.release()
                    current_plugin.gui_interface = None
                except:
                    log.error("Error when releasing the gui interface", exc_info=True)
                #Clean the input plugin info
                self.input_plugin = None
                #Close the VideoSource bridge
                video_source.close_bridge()
                #Post the message signaling that the video input was closed
                app.post_message("video_input_closed", {"plugin_id": current_id}, -1)

            #Get a input bridge to the video source object
            video_source_bridge = video_source.get_input_bridge()
            #Object that provides gui access to the plugin
            interface = GUI_Interface(plugin_id)
            #Init the plugin
            try:
                ret = new_plugin.instance.init_plugin(gui_interface=interface, video_source_bridge=video_source_bridge)
                if ret:
                    #Init the VideoSource bridge
                    video_source.init_bridge(new_plugin)
                    new_plugin.gui_interface = interface
                    self.input_plugin=  {"plugin_id": plugin_id}
                    app.post_message("video_input_changed", {"plugin_id": plugin_id}, -1)
                else:
                    interface.release()
                    raise PluginInitError("init_plugin returned False")
            except:
                log.error("Error when initialiazing input plugin", exc_info=True)
                #raise PluginInitError("Plugin init. raised exception")
                interface.release()
                video_source.close_bridge()

        except:
            log.error("Could not init input plugin", exc_info=True)
예제 #2
0
파일: engine.py 프로젝트: brunoabud/ic
    def _init_analysis(self, plugin_id):
        try:
            # Get the plugin object
            plugin = self._get_plugin(plugin_id)

            # Close the current analysis plugin
            if self.analysis_plugin:
                current_id     = self.analysis_plugin["plugin_id"]
                current_plugin = self._get_plugin(current_id)

                # Release the plugin
                try:
                    current_plugin.instance.release()
                except:
                    log.debug("Error when releasing plugin", exc_info=True)

                # Release the plugin interface
                try:
                    current_plugin.gui_interface.release()
                except:
                    log.error("Error when releasing plugin GUI interface", exc_info=True)

                self.analysis_plugin = None

            # Create a GUI interface and initialize the plugin
            gui_interface = GUI_Interface(plugin_id)
            # Parse de info XML to look for Filter Pages
            info_path = os.path.join(plugin.root_path, "info.xml")
            doc = minidom.parse(info_path)
            # Retrieve all FilterPage Elements
            pages = {}
            for element in doc.getElementsByTagName("FilterPage"):
                in_, out, name = [element.getAttribute(n) for n in ["in", "out", "name"]]
                pages[name] = {
                    "in"     : in_,
                    "out"    : out,
                    "filters": [] ,
                    "name"   : name
                    }

                for f in [n for n in element.childNodes if
                n.nodeType == Node.ELEMENT_NODE and n.localName == "Filter"]:
                    pages[name]["filters"].append(f.getAttribute("name"))

            # Create a Filter Page for each page, and try to load the default
            # filter plugins that each page requires.
            rack_interface = {}

            for page in pages.values():
                rack = get_component("filter_rack")
                p = rack.add_page(page["name"], page["in"], page["out"])
                rack_interface[page["name"]] = p

                # Try to load each filter plugin and add it to the rack
                for f in page["filters"]:
                    try:
                        log.debug("Loading filter {} for page {}".format(
                        f, page["name"]))
                        pid, filter_plugin = load_plugin(f)
                        log.debug("Loaded pid {}".format(pid))
                        p.add(pid)
                        
                    except:
                        log.error("Filter '{}' required by Plugin could not be loaded".format(f),
                        exc_info=True)
            try:
                if plugin.instance.init_plugin(gui_interface=gui_interface, rack_interface=rack_interface):
                    plugin.gui_interface = gui_interface
                    plugin.rack_interface = rack_interface
                    self.analysis_plugin = {"plugin_id": plugin_id}
                    # Check if there is a media opened to inform the analysis plugin
                    video_source = get_component("video_source")
                    try:
                        plugin.instance.on_media_opened(video_source.source_state())
                    except sys.modules["ic.video_source"].SourceClosedError:
                        pass
                    except:
                        raise
                else:
                    raise PluginInitError()
            except:
                gui_interface.release()
                raise
        except:
            log.error("Could not init analysis plugin", exc_info=True)