def _initialize_video(self):
        '''
        Initialize video if necessary.

        Note that this function must only be called by the main GTK
        thread.  Otherwise, dead-lock will occur.  Currently, this is
        ensured by calling this function in a gtk.timeout_add() call.
        '''
        if not self._video_initialized:
            if self._gui_initialized and self._video_available\
                    and self.video_enabled and self.view.window_xid\
                            and self.video_mode:
                self._video_initialized = True
                selected_mode = self.video_mode_map[self.video_mode]
                caps_str = GstVideoSourceManager.get_caps_string(selected_mode)
                if self.recording_enabled:
                    bitrate = self._bitrate
                    record_path = self._record_path
                else:
                    bitrate = None
                    record_path = None
                self.view._initialize_video(str(selected_mode['device']),
                                            str(caps_str),
                                            record_path=record_path,
                                            bitrate=bitrate)
                self.set_app_values({'transform_matrix':
                                     self.get_app_value('transform_matrix')})
                if self.recording_enabled:
                    self._recording = True
            else:
                x, y, width, height = self.view.widget.get_allocation()
                self.view._initialize_video('',
                                            'video/x-raw-yuv,width={},height={}'
                                            .format(width, height))
                self._video_initialized = True
        return True
 def get_video_device_and_caps_str(self):
     selected_mode = self.video_mode_map[self.video_settings]
     caps_str = GstVideoSourceManager.get_caps_string(selected_mode)
     return (str(selected_mode['device']), caps_str)