def _configure_camera(self, sensor_mode, framerate, resolution, clock_mode, old_sensor_mode=0):
    "\n        An internal method for setting a new camera mode, framerate,\n        resolution, and/or clock_mode.\n\n        This method is used by the setters of the :attr:`resolution`,\n        :attr:`framerate`, and :attr:`sensor_mode` properties. It assumes the\n        camera is currently disabled. The *old_mode* and *new_mode* arguments\n        are required to ensure correct operation on older firmwares\n        (specifically that we don't try to set the sensor mode when both old\n        and new modes are 0 or automatic).\n        "
    old_cc = mmal.MMAL_PARAMETER_CAMERA_CONFIG_T.from_buffer_copy(self._camera_config)
    old_ports = [(port.framesize, port.framerate, port.params[mmal.MMAL_PARAMETER_FPS_RANGE]) for port in self._camera.outputs]
    if ((old_sensor_mode != 0) or (sensor_mode != 0)):
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG] = sensor_mode
    if (not self._camera.control.enabled):
        self._camera.control.enable(self._control_callback)
        preview_resolution = resolution
    elif (self._camera.outputs[self.CAMERA_PREVIEW_PORT].framesize == self._camera.outputs[self.CAMERA_VIDEO_PORT].framesize):
        preview_resolution = resolution
    else:
        preview_resolution = self._camera.outputs[self.CAMERA_PREVIEW_PORT].framesize
    try:
        try:
            (fps_low, fps_high) = framerate
        except TypeError:
            fps_low = fps_high = framerate
        else:
            framerate = 0
        fps_range = mmal.MMAL_PARAMETER_FPS_RANGE_T(mmal.MMAL_PARAMETER_HEADER_T(mmal.MMAL_PARAMETER_FPS_RANGE, ct.sizeof(mmal.MMAL_PARAMETER_FPS_RANGE_T)), fps_low=mo.to_rational(fps_low), fps_high=mo.to_rational(fps_high))
        cc = self._camera_config
        cc.max_stills_w = resolution.width
        cc.max_stills_h = resolution.height
        cc.stills_yuv422 = 0
        cc.one_shot_stills = 1
        cc.max_preview_video_w = resolution.width
        cc.max_preview_video_h = resolution.height
        cc.num_preview_video_frames = max(3, (fps_high // 10))
        cc.stills_capture_circular_buffer_height = 0
        cc.fast_preview_resume = 0
        cc.use_stc_timestamp = clock_mode
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = cc
        if ((preview_resolution.width > resolution.width) or (preview_resolution.height > resolution.height)):
            preview_resolution = resolution
        for port in self._camera.outputs:
            port.params[mmal.MMAL_PARAMETER_FPS_RANGE] = fps_range
            if (port.index == self.CAMERA_PREVIEW_PORT):
                port.framesize = preview_resolution
            else:
                port.framesize = resolution
            port.framerate = framerate
            port.commit()
    except:
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = old_cc
        self._camera_config = old_cc
        for (port, (res, fps, fps_range)) in zip(self._camera.outputs, old_ports):
            port.framesize = res
            port.framerate = fps
            port.params[mmal.MMAL_PARAMETER_FPS_RANGE] = fps_range
            port.commit()
        raise
An internal method for setting a new camera mode, framerate,
resolution, and/or clock_mode.

This method is used by the setters of the :attr:`resolution`,
:attr:`framerate`, and :attr:`sensor_mode` properties. It assumes the
camera is currently disabled. The *old_mode* and *new_mode* arguments
are required to ensure correct operation on older firmwares
(specifically that we don't try to set the sensor mode when both old
and new modes are 0 or automatic).
def _configure_camera(self, sensor_mode, framerate, resolution, clock_mode, old_sensor_mode=0):
    "\n        An internal method for setting a new camera mode, framerate,\n        resolution, and/or clock_mode.\n\n        This method is used by the setters of the :attr:`resolution`,\n        :attr:`framerate`, and :attr:`sensor_mode` properties. It assumes the\n        camera is currently disabled. The *old_mode* and *new_mode* arguments\n        are required to ensure correct operation on older firmwares\n        (specifically that we don't try to set the sensor mode when both old\n        and new modes are 0 or automatic).\n        "
    old_cc = mmal.MMAL_PARAMETER_CAMERA_CONFIG_T.from_buffer_copy(self._camera_config)
    old_ports = [(port.framesize, port.framerate, port.params[mmal.MMAL_PARAMETER_FPS_RANGE]) for port in self._camera.outputs]
    if ((old_sensor_mode != 0) or (sensor_mode != 0)):
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG] = sensor_mode
    if (not self._camera.control.enabled):
        self._camera.control.enable(self._control_callback)
        preview_resolution = resolution
    elif (self._camera.outputs[self.CAMERA_PREVIEW_PORT].framesize == self._camera.outputs[self.CAMERA_VIDEO_PORT].framesize):
        preview_resolution = resolution
    else:
        preview_resolution = self._camera.outputs[self.CAMERA_PREVIEW_PORT].framesize
    try:
        try:
            (fps_low, fps_high) = framerate
        except TypeError:
            fps_low = fps_high = framerate
        else:
            framerate = 0
        fps_range = mmal.MMAL_PARAMETER_FPS_RANGE_T(mmal.MMAL_PARAMETER_HEADER_T(mmal.MMAL_PARAMETER_FPS_RANGE, ct.sizeof(mmal.MMAL_PARAMETER_FPS_RANGE_T)), fps_low=mo.to_rational(fps_low), fps_high=mo.to_rational(fps_high))
        cc = self._camera_config
        cc.max_stills_w = resolution.width
        cc.max_stills_h = resolution.height
        cc.stills_yuv422 = 0
        cc.one_shot_stills = 1
        cc.max_preview_video_w = resolution.width
        cc.max_preview_video_h = resolution.height
        cc.num_preview_video_frames = max(3, (fps_high // 10))
        cc.stills_capture_circular_buffer_height = 0
        cc.fast_preview_resume = 0
        cc.use_stc_timestamp = clock_mode
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = cc
        if ((preview_resolution.width > resolution.width) or (preview_resolution.height > resolution.height)):
            preview_resolution = resolution
        for port in self._camera.outputs:
            port.params[mmal.MMAL_PARAMETER_FPS_RANGE] = fps_range
            if (port.index == self.CAMERA_PREVIEW_PORT):
                port.framesize = preview_resolution
            else:
                port.framesize = resolution
            port.framerate = framerate
            port.commit()
    except:
        self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = old_cc
        self._camera_config = old_cc
        for (port, (res, fps, fps_range)) in zip(self._camera.outputs, old_ports):
            port.framesize = res
            port.framerate = fps
            port.params[mmal.MMAL_PARAMETER_FPS_RANGE] = fps_range
            port.commit()
        raise