예제 #1
0
        private static AVProLiveCameraDeviceMode GetClosestMode(AVProLiveCameraDevice device, List <Vector2> resolutions, bool maintainApectRatio, float frameRate, bool anyPixelFormat, AVProLiveCameraPlugin.VideoFrameFormat pixelFormat)
        {
            AVProLiveCameraDeviceMode result = null;

            for (int i = 0; i < resolutions.Count; i++)
            {
                result = device.GetClosestMode(Mathf.FloorToInt(resolutions[i].x), Mathf.FloorToInt(resolutions[i].y), maintainApectRatio, frameRate, anyPixelFormat, pixelFormat);
                if (result != null)
                {
                    break;
                }
            }
            return(result);
        }
예제 #2
0
        public void SelectDeviceAndMode()
        {
            _device     = null;
            _mode       = null;
            _videoInput = -1;

            _device = SelectDevice();
            if (_device != null)
            {
                _mode       = SelectMode();
                _videoInput = SelectVideoInputIndex();
            }
            else
            {
                Debug.LogWarning("[AVProLiveCamera] Could not find the device.");
            }
        }
예제 #3
0
        private void EnumModes()
        {
            int numModes = AVProLiveCameraPlugin.GetNumModes(_deviceIndex);

            for (int i = 0; i < numModes; i++)
            {
                int    width, height;
                float  fps;
                string format;
                if (AVProLiveCameraPlugin.GetModeInfo(_deviceIndex, i, out width, out height, out fps, out format))
                {
                    AVProLiveCameraDeviceMode mode = new AVProLiveCameraDeviceMode(this, i, width, height, fps, format.ToString());
                    _modes.Add(mode);
                }
            }
            SortModes();
        }
예제 #4
0
        public bool Start(int modeIndex = -1, int videoInputIndex = -1)
        {
            AVProLiveCameraDeviceMode mode = null;

            if (modeIndex >= 0)
            {
                if (modeIndex < _modes.Count)
                {
                    mode = _modes[modeIndex];
                }
                else
                {
                    Debug.LogError("[AVProLiveCamera] Mode index out of range, using default resolution");
                }
            }

            return(Start(mode, videoInputIndex));
        }
예제 #5
0
        public AVProLiveCameraDeviceMode GetHighestResolutionMode(float minimumFrameRate)
        {
            AVProLiveCameraDeviceMode result = null;

            float highestRes = 0f;

            for (int i = 0; i < NumModes; i++)
            {
                AVProLiveCameraDeviceMode mode = GetMode(i);

                if (mode.FPS >= minimumFrameRate && (mode.Width * mode.Height > highestRes))
                {
                    result     = mode;
                    highestRes = mode.Width * mode.Height;
                }
            }

            return(result);
        }
예제 #6
0
        public void SelectDeviceAndMode()
        {
            _device     = null;
            _mode       = null;
            _videoInput = -1;

            _device = SelectDevice();
            if (_device != null)
            {
                VitaCaptureU.PSVitaConnected = true;
                _mode       = SelectMode();
                _videoInput = SelectVideoInputIndex();
            }
            else
            {
                Debug.LogWarning("[AVProLiveCamera] Could not find the device.");
                VitaCaptureU.PSVitaConnected = false;
            }
        }
예제 #7
0
        private AVProLiveCameraDeviceMode SelectMode()
        {
            AVProLiveCameraDeviceMode result = null;

            switch (_modeSelection)
            {
            default:
            case SelectModeBy.Default:
                result = null;
                break;

            case SelectModeBy.Resolution:
                if (_desiredResolutions.Count > 0)
                {
                    result = GetClosestMode(_device, _desiredResolutions, _maintainAspectRatio, _desiredFrameRate, _desiredFormatAny, _desiredFormat);
                    if (result == null)
                    {
                        Debug.LogWarning("[AVProLiveCamera] Could not find desired mode, using default mode.");
                    }
                }
                break;

            case SelectModeBy.Index:
                if (_desiredModeIndex >= 0)
                {
                    result = _device.GetMode(_desiredModeIndex);
                    if (result == null)
                    {
                        Debug.LogWarning("[AVProLiveCamera] Could not find desired mode, using default mode.");
                    }
                }
                break;
            }

            return(result);
        }
예제 #8
0
        void Reset()
        {
            _videoInput        = -1;
            _mode              = null;
            _device            = null;
            _flipX             = _flipY = false;
            _allowTransparency = false;

            _deviceSelection     = SelectDeviceBy.Default;
            _modeSelection       = SelectModeBy.Default;
            _videoInputSelection = SelectDeviceBy.Default;
            _desiredDeviceNames  = new List <string>(4);
            _desiredResolutions  = new List <Vector2>(2);
            _desiredVideoInputs  = new List <AVProLiveCameraPlugin.VideoInput>(4);
            _desiredDeviceNames.Add("Logitech BRIO");
            _desiredDeviceNames.Add("XSplit VCam");
            _desiredDeviceNames.Add("Logitech HD Pro Webcam C922");
            _desiredDeviceNames.Add("Logitech HD Pro Webcam C920");
            _desiredDeviceNames.Add("Decklink Video Capture");
            _desiredDeviceNames.Add("Logitech Webcam Pro 9000");
            _desiredResolutions.Add(new Vector2(1920, 1080));
            _desiredResolutions.Add(new Vector2(1280, 720));
            _desiredResolutions.Add(new Vector2(640, 360));
            _desiredResolutions.Add(new Vector2(640, 480));
            _desiredVideoInputs.Add(AVProLiveCameraPlugin.VideoInput.Video_Serial_Digital);
            _desiredVideoInputs.Add(AVProLiveCameraPlugin.VideoInput.Video_SVideo);
            _desiredVideoInputIndex    = 0;
            _maintainAspectRatio       = false;
            _desiredTransparencyFormat = false;
            _desiredAnyResolution      = true;
            _desiredFrameRate          = 0f;
            _desiredFormatAny          = true;
            _desiredFormat             = AVProLiveCameraPlugin.VideoFrameFormat.YUV_422_HDYC;
            _desiredModeIndex          = -1;
            _desiredDeviceIndex        = 0;
        }
예제 #9
0
        public AVProLiveCameraDeviceMode GetClosestMode(int width, int height, bool maintainAspectRatio, float frameRate, bool anyPixelFormat, AVProLiveCameraPlugin.VideoFrameFormat pixelFormat)
        {
            AVProLiveCameraDeviceMode result = null;

            if (width <= 0 || height <= 0)
            {
                return(result);
            }

            List <AVProLiveCameraDeviceMode> bestModes = new List <AVProLiveCameraDeviceMode>();

            // Try to find exact match to resolution
            {
                for (int i = 0; i < NumModes; i++)
                {
                    AVProLiveCameraDeviceMode mode = GetMode(i);

                    if (mode.Width == width && mode.Height == height)
                    {
                        bestModes.Add(mode);
                    }
                }
            }

            // If we haven't found an exact match, find by closest area
            if (bestModes.Count == 0)
            {
                float aspect = (float)width * (float)height;
                int   area   = width * height;
                float lowestAreaDifference = float.MaxValue;
                for (int i = 0; i < NumModes; i++)
                {
                    AVProLiveCameraDeviceMode mode = GetMode(i);

                    // Maintain aspect ratio or not
                    float modeAspect = (float)mode.Width / (float)mode.Height;
                    bool  consider   = true;
                    if (maintainAspectRatio && !Mathf.Approximately(modeAspect, aspect))
                    {
                        consider = false;
                    }

                    if (consider)
                    {
                        int modeArea       = mode.Width * mode.Height;
                        int areaDifference = Mathf.Abs(area - modeArea);
                        if (areaDifference < lowestAreaDifference)
                        {
                            result = mode;
                            lowestAreaDifference = areaDifference;
                        }
                    }
                }

                // Now that we know the closest resolution, collect all modes with that resolution
                if (result != null)
                {
                    for (int i = 0; i < NumModes; i++)
                    {
                        AVProLiveCameraDeviceMode mode = GetMode(i);
                        if (mode.Width == result.Width && mode.Height == result.Height)
                        {
                            bestModes.Add(mode);
                        }
                    }
                    result = null;
                }
            }


            // Pick best based on pixel format or frame rate
            if (bestModes.Count > 0)
            {
                if (bestModes.Count == 1)
                {
                    result = bestModes[0];
                }
                else
                {
                    bool findHighestFrameRate = (frameRate <= 0f);
                    if (findHighestFrameRate)
                    {
                        float highestFps = 0f;
                        for (int i = 0; i < bestModes.Count; i++)
                        {
                            AVProLiveCameraDeviceMode mode = bestModes[i];
                            if (mode.FPS > highestFps)
                            {
                                highestFps = mode.FPS;
                            }
                        }
                        // Remove modes that didn't have the higest fps
                        for (int i = 0; i < bestModes.Count; i++)
                        {
                            AVProLiveCameraDeviceMode mode = bestModes[i];
                            if (mode.FPS < highestFps)
                            {
                                bestModes.RemoveAt(i);
                                i = -1;
                            }
                        }
                    }
                    else
                    {
                        float lowestDelta = 1000f;
                        float closestFps  = 0f;
                        // Find the closest FPS
                        for (int i = 0; i < bestModes.Count; i++)
                        {
                            AVProLiveCameraDeviceMode mode = bestModes[i];
                            float d = Mathf.Abs(mode.FPS - frameRate);
                            if (d < lowestDelta)
                            {
                                closestFps  = mode.FPS;
                                lowestDelta = d;
                            }
                        }
                        // Remove modes that have a different frameRate
                        for (int i = 0; i < bestModes.Count; i++)
                        {
                            AVProLiveCameraDeviceMode mode = bestModes[i];
                            if (mode.FPS != closestFps)
                            {
                                bestModes.RemoveAt(i);
                                i = -1;
                            }
                        }
                    }

                    if (result == null)
                    {
                        if (bestModes.Count == 0)
                        {
                            result = null;
                        }
                        else if (bestModes.Count == 1)
                        {
                            result = bestModes[0];
                        }
                        else
                        {
                            if (anyPixelFormat)
                            {
                                string[] bestFormats = { "YUV_UYVY_HDYC", "YUV_UYVY", "YUV_YVYU", "YUV_YUY2", "ARGB32", "RGB32", "RGB24", "MJPG", "UNKNOWN" };
                                int      bestScore   = 100;
                                for (int i = 0; i < bestModes.Count; i++)
                                {
                                    int index = System.Array.IndexOf <string>(bestFormats, bestModes[i].Format);
                                    if (index >= 0 && index < bestScore)
                                    {
                                        result    = bestModes[i];
                                        bestScore = index;
                                    }
                                }
                            }
                            else
                            {
                                for (int i = 0; i < bestModes.Count; i++)
                                {
                                    if (CompareMode(bestModes[i].Format, pixelFormat))
                                    {
                                        result = bestModes[i];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (result != null)
            {
                //Debug.Log(string.Format("Selected mode {0}: {1}x{2} {3} {4}", result.Index, result.Width , result.Height, result.FPS, result.Format));
            }

            return(result);
        }
예제 #10
0
        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);
        }