Пример #1
0
        private async Task Write(StorageFile file)
        {
            var stream = await file.OpenAsync(FileAccessMode.ReadWrite);

            var factory = new VideoWriteServiceFactory();
            var prop    = new VideoProperty();

            prop.BitRate = 800000;
            prop.Format  = VideoEncoding.WindowsMediaVideo;
            prop.FPS     = 25;
            prop.Height  = 480;
            prop.Width   = 640;
            prop.Output  = stream;
            var service = factory.Create(prop);

            UInt32[] data = new UInt32[prop.Height * prop.Width];
            for (int i = 0; i < data.Length; ++i)
            {
                data[i] = 0x0000FF00;
            }
            for (int i = 0; i < 20 * prop.FPS; ++i)
            {
                service.WriteFrame(data);
            }
            service.Close();
        }
Пример #2
0
 private void SetDeviceProperty(VideoProperty prop, MediaCaptureInfo.PropertyInfo propInfo, MediaCaptureConfiguration.PropertyValue <bool> value)
 {
     if (propInfo.Supported)
     {
         VideoPropertyFlags flag = (propInfo.AutoControlled && value.Auto) ? VideoPropertyFlags.Auto : VideoPropertyFlags.Manual;
         this.camera.SetProperty(prop, value.Value ? 1 : 0, flag);
     }
 }
Пример #3
0
 public void SetUp()
 {
     property         = new VideoProperty();
     property.BitRate = 12345;
     property.Format  = VideoEncoding.H264;
     property.Height  = 11111;
     property.Width   = 12345;
     property.Output  = null;
     property.FPS     = 30;
 }
Пример #4
0
        private MediaCaptureConfiguration.PropertyValue <bool> GetValueBool(VideoProperty prop, bool supported)
        {
            int flags = 0;
            int value = 0;

            MediaCaptureConfiguration.PropertyValue <bool> propValue = new MediaCaptureConfiguration.PropertyValue <bool>();
            if (supported &&
                this.camera.GetProperty(prop, ref value, ref flags))
            {
                propValue.Value = (value == 1) ? true : false;
                propValue.Auto  = (flags == (int)VideoPropertyFlags.Auto) ? true : false;
            }

            return(propValue);
        }
Пример #5
0
        private MediaCaptureConfiguration.PropertyValue <int> GetValueInt(VideoProperty prop, bool supported)
        {
            int flags = 0;
            int value = 0;

            MediaCaptureConfiguration.PropertyValue <int> propValue = new MediaCaptureConfiguration.PropertyValue <int>();
            if (supported &&
                this.camera.GetProperty(prop, ref value, ref flags))
            {
                propValue.Value = value;
                propValue.Auto  = flags == (int)VideoPropertyFlags.Auto;
            }

            return(propValue);
        }
Пример #6
0
        private MediaCaptureInfo.PropertyInfo GetInfo(VideoProperty prop)
        {
            MediaCaptureInfo.PropertyInfo info = new MediaCaptureInfo.PropertyInfo();
            int min = 0, max = 0, stepSize = 0, defValue = 0, flag = 0;

            if (this.camera.GetRange(prop, ref min, ref max, ref stepSize, ref defValue, ref flag))
            {
                info.MinValue       = min;
                info.MaxValue       = max;
                info.StepSize       = stepSize;
                info.DefaultValue   = defValue;
                info.AutoControlled = (flag == (int)VideoPropertyFlags.Auto) ? true : false;
                info.Supported      = true;
            }
            else
            {
                info.Supported = false;
            }

            return(info);
        }
Пример #7
0
        private PropertyInfo GetInfo(VideoProperty prop, MediaCaptureDevice device)
        {
            PropertyInfo info = new PropertyInfo();
            int          min = 0, max = 0, stepSize = 0, defValue = 0, flag = 0;

            if (device.GetRange(prop, ref min, ref max, ref stepSize, ref defValue, ref flag))
            {
                info.MinValue       = min;
                info.MaxValue       = max;
                info.StepSize       = stepSize;
                info.DefaultValue   = defValue;
                info.AutoControlled = ((flag & (int)VideoPropertyFlags.Auto) != 0) ? true : false;
                info.Supported      = true;
            }
            else
            {
                info.Supported = false;
            }

            return(info);
        }
Пример #8
0
        private CameraServer()
        {
            m_defaultUsbDevice = 0;
            m_lockObject       = new object();
            m_sources          = new Dictionary <string, VideoSource>();
            m_sinks            = new Dictionary <string, VideoSink>();
            m_tables           = new Dictionary <int, ITable>();
            m_publishTable     = NetworkTable.GetTable(PublishName);
            m_nextPort         = BasePort;
            m_addresses        = new List <string>();

            m_videoListener = new VideoListener((vidEvent) =>
            {
                switch (vidEvent.Kind)
                {
                case EventKind.SourceCreated:
                    {
                        // Create subtable for the camera
                        ITable table = m_publishTable.GetSubTable(vidEvent.Name);
                        lock (m_lockObject)
                        {
                            m_tables.Add(vidEvent.SourceHandle, table);
                        }
                        table.PutString("source", MakeSourceValue(vidEvent.SourceHandle));
                        table.PutString("description",
                                        NativeMethods.GetSourceDescription(vidEvent.SourceHandle));
                        table.PutBoolean("connected", NativeMethods.IsSourceConnected(vidEvent.SourceHandle));
                        table.PutStringArray("streams", GetSourceStreamValues(vidEvent.SourceHandle));
                        try
                        {
                            VideoMode mode = NativeMethods.GetSourceVideoMode(vidEvent.SourceHandle);
                            table.SetDefaultString("mode", VideoModeToString(mode));
                            table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
                        }
                        catch (VideoException)
                        {
                            // Do nothing
                        }
                        break;
                    }

                case EventKind.SourceDestroyed:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            table.PutString("source", "");
                            table.PutStringArray("streams", new string[0]);
                            table.PutStringArray("modes", new string[0]);
                        }
                        break;
                    }

                case EventKind.SourceConnected:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            // update the description too (as it may have changed)
                            table.PutString("description",
                                            NativeMethods.GetSourceDescription(vidEvent.SourceHandle));
                            table.PutBoolean("connected", true);
                        }
                        break;
                    }

                case EventKind.SourceDisconnected:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        table?.PutBoolean("connected", false);
                        break;
                    }

                case EventKind.SourceVideoModesUpdated:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
                        }
                        break;
                    }

                case EventKind.SourceVideoModeChanged:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            table.PutString("mode", VideoModeToString(vidEvent.Mode));
                        }
                        break;
                    }

                case EventKind.SourcePropertyCreated:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            PutSourcePropertyValue(table, vidEvent, true);
                        }
                        break;
                    }

                case EventKind.SourcePropertyValueUpdated:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            PutSourcePropertyValue(table, vidEvent, false);
                        }
                        break;
                    }

                case EventKind.SourcePropertyChoicesUpdated:
                    {
                        ITable table = GetSourceTable(vidEvent.SourceHandle);
                        if (table != null)
                        {
                            List <string> choices = NativeMethods.GetEnumPropertyChoices(vidEvent.PropertyHandle);
                            table.PutStringArray($"PropertyInfo/{vidEvent.Name}/choices", choices);
                        }
                        break;
                    }

                case EventKind.SinkSourceChanged:
                case EventKind.SinkCreated:
                case EventKind.SinkDestroyed:
                    {
                        UpdateStreamValues();
                        break;
                    }

                case EventKind.NetworkInterfacesChanged:
                    {
                        m_addresses = NativeMethods.GetNetworkInterfaces();
                        break;
                    }

                default:
                    break;
                }
            }, (EventKind)0x4fff, true);

            m_tableListener = NtCore.AddEntryListener($"{PublishName}/", (uid, key, value, flags) =>
            {
                string relativeKey = key.Substring(PublishName.Length + 1);

                int subKeyIndex = relativeKey.IndexOf('/');
                if (subKeyIndex == -1)
                {
                    return;
                }
                string sourceName = relativeKey.Substring(0, subKeyIndex);
                VideoSource source;
                if (!m_sources.TryGetValue(sourceName, out source))
                {
                    return;
                }

                relativeKey = relativeKey.Substring(subKeyIndex + 1);

                string propName;
                if (relativeKey == "mode")
                {
                    // reset to current mode
                    NtCore.SetEntryString(key, VideoModeToString(source.GetVideoMode()));
                    return;
                }
                else if (relativeKey.StartsWith("Property/"))
                {
                    propName = relativeKey.Substring(9);
                }
                else if (relativeKey.StartsWith("RawProperty/"))
                {
                    propName = relativeKey.Substring(12);
                }
                else
                {
                    return;
                }

                VideoProperty prop = source.GetProperty(propName);
                switch (prop.Kind)
                {
                case PropertyKind.None:
                    return;

                case PropertyKind.Boolean:
                    NtCore.SetEntryBoolean(key, prop.Get() != 0);
                    break;

                case PropertyKind.Integer:
                case PropertyKind.Enum:
                    NtCore.SetEntryDouble(key, prop.Get());
                    break;

                case PropertyKind.String:
                    NtCore.SetEntryString(key, prop.GetString());
                    break;

                default:
                    return;
                }
            }, NotifyFlags.NotifyImmediate | NotifyFlags.NotifyUpdate);
        }
Пример #9
0
		public int GetVideoProperty(VideoProperty type) {
			int raw_ret = bacon_video_widget_get_video_property(Handle, (int) type);
			int ret = raw_ret;
			return ret;
		}
Пример #10
0
		public void SetVideoProperty(VideoProperty type, int value) {
			bacon_video_widget_set_video_property(Handle, (int) type, value);
		}
Пример #11
0
 public VideoElement(string name, string extension, string path, VideoProperty property, TimeSpan duration)
     : base(name, extension, path)
 {
     Property = property;
     Duration = duration;
 }