Beispiel #1
0
    public bool Start(int modeIndex = -1, int videoInputIndex = -1)
    {
        if (AVProLiveCameraPlugin.StartDevice(_deviceIndex, modeIndex, videoInputIndex))
        {
            // 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();
            _frameRate        = AVProLiveCameraPlugin.GetFrameRate(_deviceIndex);
            _frameDurationHNS = AVProLiveCameraPlugin.GetFrameDurationHNS(_deviceIndex);

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

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

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

            return(true);
        }

        Debug.LogWarning("[AVPro LiveCamera] unable to start camera");
        Close();
        return(false);
    }
    public bool Start(AVProLiveCameraDeviceMode mode, int videoInputIndex = -1)
    {
        // Resolve the internal mode index
        int internalModeIndex = -1;

        if (mode != null)
        {
            internalModeIndex = mode.InternalIndex;
        }

        // Start the device
        if (AVProLiveCameraPlugin.StartDevice(_deviceIndex, internalModeIndex, videoInputIndex))
        {
            int modeIndex = -1;
            if (mode != null)
            {
                for (int i = 0; i < _modes.Count; i++)
                {
                    if (_modes[i] == mode)
                    {
                        modeIndex = i;
                        break;
                    }
                }
            }
            Debug.Log("[AVProLiveCamera] Started device using mode index " + modeIndex + " (internal index " + internalModeIndex + ")");

            // 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);
    }