示例#1
0
    public bool Start(int modeIndex = -1, int videoInputIndex = -1)
    {
        if (AVProLiveCameraPlugin.StartDevice(_deviceIndex, modeIndex, videoInputIndex))
        {
            Debug.Log("[AVProLiveCamera] Started device using mode index " + modeIndex);

            // Get format mode properties
            int width  = AVProLiveCameraPlugin.GetWidth(_deviceIndex);
            int height = AVProLiveCameraPlugin.GetHeight(_deviceIndex);
            AVProLiveCameraPlugin.VideoFrameFormat format = (AVProLiveCameraPlugin.VideoFrameFormat)AVProLiveCameraPlugin.GetFormat(_deviceIndex);
            _width            = width;
            _height           = height;
            _format           = format.ToString();
            _deviceFormat     = AVProLiveCameraPlugin.GetDeviceFormat(_deviceIndex);
            _frameRate        = AVProLiveCameraPlugin.GetFrameRate(_deviceIndex);
            _frameDurationHNS = AVProLiveCameraPlugin.GetFrameDurationHNS(_deviceIndex);

            // Validate properties
            if (width <= 0 || width > MaxVideoResolution || height <= 0 || height > MaxVideoResolution)
            {
                Debug.LogWarning("[AVProLiveCamera] invalid width or height");
                Close();
                return(false);
            }

            // Create format converter
            _isTopDown = AVProLiveCameraPlugin.IsFrameTopDown(_deviceIndex);
            if (!_formatConverter.Build(width, height, format, _flipX, _isTopDown != _flipY, Deinterlace))
            {
                Debug.LogWarning("[AVProLiveCamera] unable to convert camera format");
                Close();
                return(false);
            }

            // Run camera
            IsActive             = true;
            IsRunning            = false;
            IsPicture            = false;
            IsPaused             = true;
            _lastModeIndex       = modeIndex;
            _lastVideoInputIndex = videoInputIndex;
            Play();

            return(IsRunning);
        }

        Debug.LogWarning("[AVProLiveCamera] unable to start camera");
        Close();
        return(false);
    }