def __init__(self, camera_num=0, stereo_mode='none', stereo_decimate=False, resolution=None, framerate=None, sensor_mode=0, led_pin=None, clock_mode='reset', framerate_range=None):
    bcm_host.bcm_host_init()
    mimetypes.add_type('application/h264', '.h264', False)
    mimetypes.add_type('application/mjpeg', '.mjpg', False)
    mimetypes.add_type('application/mjpeg', '.mjpeg', False)
    self._used_led = False
    if (GPIO and (led_pin is None)):
        try:
            led_pin = {(0, 0): 2, (0, 1): 30, (1, 0): 5, (2, 0): 5, (3, 0): 32}[(GPIO.RPI_REVISION, camera_num)]
        except KeyError:
            raise PiCameraError(('Unable to determine default GPIO LED pin for RPi revision %d and camera num %d' % (GPIO.RPI_REVISION, camera_num)))
    self._led_pin = led_pin
    self._camera = None
    self._camera_config = None
    self._camera_exception = None
    self._preview = None
    self._preview_alpha = 255
    self._preview_layer = 2
    self._preview_fullscreen = True
    self._preview_window = None
    self._splitter = None
    self._splitter_connection = None
    self._encoders_lock = threading.Lock()
    self._encoders = {}
    self._overlays = []
    self._raw_format = 'yuv'
    self._image_effect_params = None
    with mo.MMALCameraInfo() as camera_info:
        info = camera_info.control.params[mmal.MMAL_PARAMETER_CAMERA_INFO]
        self._revision = 'ov5647'
        if (camera_info.info_rev > 1):
            self._revision = info.cameras[camera_num].camera_name.decode('ascii')
        self._exif_tags = {'IFD0.Model': ('RP_%s' % self._revision), 'IFD0.Make': 'RaspberryPi'}
        if (PiCamera.MAX_RESOLUTION is PiCameraMaxResolution):
            PiCamera.MAX_RESOLUTION = mo.PiResolution(info.cameras[camera_num].max_width, info.cameras[camera_num].max_height)
    if (PiCamera.MAX_FRAMERATE is PiCameraMaxFramerate):
        if (self._revision.upper() == 'OV5647'):
            PiCamera.MAX_FRAMERATE = 90
        else:
            PiCamera.MAX_FRAMERATE = 120
    if (resolution is None):
        w = ct.c_uint32()
        h = ct.c_uint32()
        if (bcm_host.graphics_get_display_size(0, w, h) == (- 1)):
            w = 1280
            h = 720
        else:
            w = int(w.value)
            h = int(h.value)
        resolution = mo.PiResolution(w, h)
    elif (resolution is PiCameraMaxResolution):
        resolution = PiCamera.MAX_RESOLUTION
    else:
        resolution = mo.to_resolution(resolution)
    if (framerate_range is None):
        if (framerate is None):
            framerate = 30
        elif (framerate is PiCameraMaxFramerate):
            framerate = PiCamera.MAX_FRAMERATE
        else:
            framerate = mo.to_fraction(framerate)
    elif (framerate is not None):
        raise PiCameraValueError("Can't specify framerate and framerate_range")
    else:
        try:
            (low, high) = framerate_range
        except TypeError:
            raise PiCameraValueError('framerate_range must have (low, high) values')
        if (low is PiCameraMaxFramerate):
            low = PiCamera.MAX_FRAMERATE
        if (high is PiCameraMaxFramerate):
            high = PiCamera.MAX_FRAMERATE
        framerate = (mo.to_fraction(low), mo.to_fraction(high))
    try:
        stereo_mode = self.STEREO_MODES[stereo_mode]
    except KeyError:
        raise PiCameraValueError(('Invalid stereo mode: %s' % stereo_mode))
    try:
        clock_mode = self.CLOCK_MODES[clock_mode]
    except KeyError:
        raise PiCameraValueError(('Invalid clock mode: %s' % clock_mode))
    try:
        self._init_camera(camera_num, stereo_mode, stereo_decimate)
        self._configure_camera(sensor_mode, framerate, resolution, clock_mode)
        self._init_preview()
        self._init_splitter()
        self._camera.enable()
        self._init_defaults()
    except:
        self.close()
        raise
def __init__(self, camera_num=0, stereo_mode='none', stereo_decimate=False, resolution=None, framerate=None, sensor_mode=0, led_pin=None, clock_mode='reset', framerate_range=None):
    bcm_host.bcm_host_init()
    mimetypes.add_type('application/h264', '.h264', False)
    mimetypes.add_type('application/mjpeg', '.mjpg', False)
    mimetypes.add_type('application/mjpeg', '.mjpeg', False)
    self._used_led = False
    if (GPIO and (led_pin is None)):
        try:
            led_pin = {(0, 0): 2, (0, 1): 30, (1, 0): 5, (2, 0): 5, (3, 0): 32}[(GPIO.RPI_REVISION, camera_num)]
        except KeyError:
            raise PiCameraError(('Unable to determine default GPIO LED pin for RPi revision %d and camera num %d' % (GPIO.RPI_REVISION, camera_num)))
    self._led_pin = led_pin
    self._camera = None
    self._camera_config = None
    self._camera_exception = None
    self._preview = None
    self._preview_alpha = 255
    self._preview_layer = 2
    self._preview_fullscreen = True
    self._preview_window = None
    self._splitter = None
    self._splitter_connection = None
    self._encoders_lock = threading.Lock()
    self._encoders = {}
    self._overlays = []
    self._raw_format = 'yuv'
    self._image_effect_params = None
    with mo.MMALCameraInfo() as camera_info:
        info = camera_info.control.params[mmal.MMAL_PARAMETER_CAMERA_INFO]
        self._revision = 'ov5647'
        if (camera_info.info_rev > 1):
            self._revision = info.cameras[camera_num].camera_name.decode('ascii')
        self._exif_tags = {'IFD0.Model': ('RP_%s' % self._revision), 'IFD0.Make': 'RaspberryPi'}
        if (PiCamera.MAX_RESOLUTION is PiCameraMaxResolution):
            PiCamera.MAX_RESOLUTION = mo.PiResolution(info.cameras[camera_num].max_width, info.cameras[camera_num].max_height)
    if (PiCamera.MAX_FRAMERATE is PiCameraMaxFramerate):
        if (self._revision.upper() == 'OV5647'):
            PiCamera.MAX_FRAMERATE = 90
        else:
            PiCamera.MAX_FRAMERATE = 120
    if (resolution is None):
        w = ct.c_uint32()
        h = ct.c_uint32()
        if (bcm_host.graphics_get_display_size(0, w, h) == (- 1)):
            w = 1280
            h = 720
        else:
            w = int(w.value)
            h = int(h.value)
        resolution = mo.PiResolution(w, h)
    elif (resolution is PiCameraMaxResolution):
        resolution = PiCamera.MAX_RESOLUTION
    else:
        resolution = mo.to_resolution(resolution)
    if (framerate_range is None):
        if (framerate is None):
            framerate = 30
        elif (framerate is PiCameraMaxFramerate):
            framerate = PiCamera.MAX_FRAMERATE
        else:
            framerate = mo.to_fraction(framerate)
    elif (framerate is not None):
        raise PiCameraValueError("Can't specify framerate and framerate_range")
    else:
        try:
            (low, high) = framerate_range
        except TypeError:
            raise PiCameraValueError('framerate_range must have (low, high) values')
        if (low is PiCameraMaxFramerate):
            low = PiCamera.MAX_FRAMERATE
        if (high is PiCameraMaxFramerate):
            high = PiCamera.MAX_FRAMERATE
        framerate = (mo.to_fraction(low), mo.to_fraction(high))
    try:
        stereo_mode = self.STEREO_MODES[stereo_mode]
    except KeyError:
        raise PiCameraValueError(('Invalid stereo mode: %s' % stereo_mode))
    try:
        clock_mode = self.CLOCK_MODES[clock_mode]
    except KeyError:
        raise PiCameraValueError(('Invalid clock mode: %s' % clock_mode))
    try:
        self._init_camera(camera_num, stereo_mode, stereo_decimate)
        self._configure_camera(sensor_mode, framerate, resolution, clock_mode)
        self._init_preview()
        self._init_splitter()
        self._camera.enable()
        self._init_defaults()
    except:
        self.close()
        raise