public bool Open(Uri.Locator name) { bool result = false; if (name.Scheme == "sensoray") { int device = 0; int stream = 0; if (name.Authority.NotNull() && name.Authority.Endpoint.Host.NotNull() && name.Authority.Endpoint.Host.Head.NotEmpty()) { if (name.Authority.Endpoint.Host.Tail.NotNull() && name.Authority.Endpoint.Host.Tail.Head.NotEmpty()) { if (!(int.TryParse(name.Authority.Endpoint.Host.Head, out device))) { device = 0; } if (!(int.TryParse(name.Authority.Endpoint.Host.Tail.Head, out stream))) { stream = 0; } } else if (!(int.TryParse(name.Authority.Endpoint.Host.Head, out stream))) { stream = 0; } } string system = name.Query["system"]; this.videoSystem = name.Query.GetEnumeration <VideoSystem>("system", VideoSystem.Pal); this.device = Device.Open(device, this.videoSystem); this.device.Deinterlace = name.Query.NotFalse("deinterlace"); this.size = (Geometry2D.Integer.Size)name.Query["size"]; if (this.size.IsNull() || this.size.Area <= 0) { this.size = this.device.NativeSize; } this.stream = this.device[stream]; string record = null; if ((record = name.Query["record"]).NotEmpty()) { result = this.stream.Start(this.size, name.Query.GetEnumeration <Encoding>("encoding", Encoding.H264), name.Query.Get("bitrate", 2500), record); } else { result = this.stream.Start(this.size, image => this.Send(0, DateTime.Now, TimeSpan.FromSeconds(this.videoSystem == VideoSystem.Ntsc ? 1 / 30.0f : 1 / 25.0f), image.Convert <Raster.Yuv422>(), null)); string video = null; if (result && (video = name.Query["video"]).NotEmpty()) { this.recordStream = this.device[(stream + 1) % 2]; this.recordStream.Start(this.size, name.Query.GetEnumeration <Encoding>("encoding", Encoding.H264), name.Query.Get("bitrate", 2500), new Uri.Locator("file", video)); } } this.Status = result ? Status.Playing : Status.Closed; } return(result); }
public void Close() { if (this.stream.NotNull()) { this.stream.Stop(); this.stream = null; } if (this.recordStream.NotNull()) { this.recordStream.Stop(); this.recordStream = null; } }