Пример #1
0
        //-------------------------------------------------------------------
        // SetDevice
        //
        // Set up preview for a specified video capture device.
        //-------------------------------------------------------------------

        public int SetDevice(MfDevice pDevice, ref string format)
        {
            int            hr;
            IMFMediaSource pSource = null;

            lock (LockSync)
            {
                try
                {
                    // Release the current device, if any.
                    hr        = CloseDevice();
                    pActivate = pDevice.Activator;
                    object o = null;
                    if (Succeeded(hr))
                    {
                        // Create the media source for the device.
                        hr = pActivate.ActivateObject(typeof(IMFMediaSource).GUID, out o);
                    }

                    if (Succeeded(hr))
                    {
                        pSource = (IMFMediaSource)o;
                    }

                    // Get Symbolic device link
                    PwszSymbolicLink = pDevice.SymbolicName;

                    // Create the source reader.
                    if (Succeeded(hr))
                    {
                        hr = OpenMediaSource(pSource, ref PReader);
                    }

                    if (Succeeded(hr))
                    {
                        var index = GetOptimizedFormatIndex(ref format);
                        if (index >= 0)
                        {
                            hr = ConfigureSourceReader(index);
                        }
                    }

                    if (Failed(hr))
                    {
                        pSource?.Shutdown();
                        //pActivate.ShutdownObject();
                        // NOTE: The source reader shuts down the media source
                        // by default, but we might not have gotten that far.
                        CloseDevice();
                    }
                }
                finally
                {
                    SafeRelease(pSource);
                }
            }

            return(hr);
        }
Пример #2
0
        private void OnActivate(IDeviceInfo moniker)
        {
            activeDevice = moniker as MfDevice;
            var format = string.Empty;
            var hr     = camProcess.SetDevice(activeDevice, ref format);

            if (!string.IsNullOrEmpty(format))
            {
                eventAggregator.GetEvent <NoticeFormatEvent>().Publish(format);
            }
            MFError.ThrowExceptionForHR(hr);
        }
Пример #3
0
 private void OnActivate(IDeviceInfo moniker)
 {
     activeDevice = moniker as MfDevice;
     var format = string.Empty;
     var hr = camProcess.SetDevice(activeDevice, ref format);
     if (!string.IsNullOrEmpty(format))
         eventAggregator.GetEvent<NoticeFormatEvent>().Publish(format);
     MFError.ThrowExceptionForHR(hr);
 }
Пример #4
0
 public MonikerProvider()
 {
     // Query MF for the devices
     DeviceTable = MfDevice.GetCategoryDevices(CLSID.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
 }
Пример #5
0
        //-------------------------------------------------------------------
        // SetDevice
        //
        // Set up preview for a specified video capture device.
        //-------------------------------------------------------------------
        public int SetDevice(MfDevice pDevice, ref string format)
        {
            int hr;
            IMFMediaSource pSource = null;
            lock (LockSync)
            {
                try
                {
                    // Release the current device, if any.
                    hr = CloseDevice();
                    pActivate = pDevice.Activator;
                    object o = null;
                    if (Succeeded(hr))
                    {
                        // Create the media source for the device.
                        hr = pActivate.ActivateObject(typeof(IMFMediaSource).GUID, out o);
                    }

                    if (Succeeded(hr))
                    {
                        pSource = (IMFMediaSource)o;
                    }

                    // Get Symbolic device link
                    PwszSymbolicLink = pDevice.SymbolicName;

                    // Create the source reader.
                    if (Succeeded(hr))
                    {
                        hr = OpenMediaSource(pSource, ref PReader);
                    }

                    if (Succeeded(hr))
                    {
                        var index = GetOptimizedFormatIndex(ref format);
                        if (index>=0)
                            hr = ConfigureSourceReader(index);
                    }

                    if (Failed(hr))
                    {

                        pSource?.Shutdown();
                        //pActivate.ShutdownObject();
                        // NOTE: The source reader shuts down the media source
                        // by default, but we might not have gotten that far.
                        CloseDevice();
                    }
                }
                finally
                {
                    SafeRelease(pSource);
                }
            }

            return hr;
        }