public StreamingCamera(PublishedCamera camera) { if (camera == null) { throw new ArgumentNullException("camera"); } Camera = camera; _keepCameraAliveTimer = new System.Threading.Timer(KeepCameraAlive, null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(4)); }
public void UnpublishCamera(string hostUri, PublishedCamera camera, EventHandler <AsyncWorkerCallbackEventArgs <bool> > callback) { try { AsyncWorkerHandle <bool> handle = AsyncWorkerHelper.DoWork <bool>( delegate(object sender, DoWorkEventArgs e) { e.Result = UnpublishCameraSync(hostUri, camera); }, null, callback); } catch (Exception ex) { ExceptionHandler.Handle(ex); } }
internal static PublishedCameraData Translate(PublishedCamera camera) { PublishedCameraData data = new PublishedCameraData() { CameraId = camera.Id, Destinations = new List <PublishDestinationData>() }; foreach (var item in camera.Destinations) { data.Destinations.Add(new PublishDestinationData() { Address = item.Address, Port = item.Port }); } return(data); }
public void UnpublishCamera(string cameraId, PublishedDestination destination) { lock (_syncRoot) { if (destination == null) { throw new ArgumentNullException("destination"); } PublishedCamera camera = _cameras.Find(c => c.Profile.CameraId == cameraId && c.Destination.Port == destination.Port); if (camera != null) { Locator.Get <IStreamingManager>().StopCameraStreaming(camera); Locator.Get <IPublishedCameraRepository>().Remove(camera.Id); _cameras.Remove(camera); } } }
public PublishedCamera PublishCamera(PublishedCameraProfile profile, PublishedDestination destination) { lock (_syncRoot) { if (profile == null) { throw new ArgumentNullException("profile"); } if (destination == null) { throw new ArgumentNullException("destination"); } PublishedCamera camera = _cameras.Find(c => c.Profile.CameraId == profile.CameraId && c.Destination == destination); if (camera == null) { camera = new PublishedCamera(profile, destination); Locator.Get <IStreamingManager>().StartCameraStreaming(camera); _cameras.Add(camera); DA::PublishedCamera entity = new DA::PublishedCamera() { Id = camera.Id, Profile = new DA::PublishedCameraProfile() { CameraId = profile.CameraId, CameraName = profile.CameraName, CameraThumbnail = profile.CameraThumbnail, DeviceServiceHostName = profile.DeviceServiceHostName, DeviceServiceUri = profile.DeviceServiceUri, }, Destination = new DA::Destination() { Port = camera.Destination.Port, }, }; Locator.Get <IPublishedCameraRepository>().Save(entity); } return(camera); } }
public void StopCameraStreaming(PublishedCamera camera) { if (camera == null) { throw new ArgumentNullException("camera"); } lock (_syncRoot) { if (_cameras.Count(c => c.Id == camera.Id) == 0) { return; } StreamingCamera streamingCamera = _cameras.Find(c => c.Id == camera.Id); streamingCamera.Stop(); _cameras.Remove(streamingCamera); } }
public void StartCameraStreaming(PublishedCamera camera) { if (camera == null) { throw new ArgumentNullException("camera"); } lock (_syncRoot) { if (_cameras.Count(c => c.Id == camera.Id) > 0) { return; } StreamingCamera streamingCamera = new StreamingCamera(camera); streamingCamera.Start(); _cameras.Add(streamingCamera); } }
private static bool UnpublishCameraSync(string hostUri, PublishedCamera camera) { MediaService service = GetMediaPublisherServiceSync(hostUri); if (service != null) { UnpublishCameraRequest request = new UnpublishCameraRequest() { CameraId = camera.Profile.CameraId, Destination = new PublishedDestinationData() { Port = camera.Destination.Port, }, }; UnpublishCameraResponse response = ServiceProvider .GetService <IMediaPublisherService>(service.HostName, service.Uri.ToString()) .UnpublishCamera(request); } return(true); }
public PublishedCameraManager Restore() { lock (_syncRoot) { List <DA::PublishedCamera> entities = Locator.Get <IPublishedCameraRepository>().FindAll().ToList(); foreach (var entity in entities) { PublishedCamera camera = new PublishedCamera( new PublishedCameraProfile(entity.Profile.CameraId, entity.Profile.CameraName) { CameraThumbnail = entity.Profile.CameraThumbnail, DeviceServiceHostName = entity.Profile.DeviceServiceHostName, DeviceServiceUri = entity.Profile.DeviceServiceUri, }, new PublishedDestination(entity.Destination.Port)); _cameras.Add(camera); Locator.Get <IStreamingManager>().StartCameraStreaming(camera); } return(this); } }
private static List <PublishedCamera> GetPublishedCamerasSync() { List <MediaService> services = GetMediaPublisherServicesSync(); List <PublishedCamera> cameras = new List <PublishedCamera>(); foreach (var service in services) { GetPublishedCamerasRequest request = new GetPublishedCamerasRequest(); GetPublishedCamerasResponse response = ServiceProvider .GetService <IMediaPublisherService>(service.HostName, service.Uri.ToString()) .GetPublishedCameras(request); if (response.PublishedCameras != null) { foreach (var item in response.PublishedCameras) { PublishedCamera camera = new PublishedCamera( new PublishedCameraProfile(item.Profile.CameraId, item.Profile.CameraName) { CameraThumbnail = item.Profile.CameraThumbnail, DeviceServiceHostName = item.Profile.DeviceServiceHostName, DeviceServiceUri = item.Profile.DeviceServiceUri, }, new PublishedDestination(item.Destination.Port)) { PublishServiceHostName = service.HostName, PublishServiceUri = service.Uri.ToString(), }; cameras.Add(camera); } } } return(cameras); }
public PublishedCamera PublishCamera(PublishedCameraProfile profile, PublishedDestination destination) { lock (_syncRoot) { if (profile == null) throw new ArgumentNullException("profile"); if (destination == null) throw new ArgumentNullException("destination"); PublishedCamera camera = _cameras.Find(c => c.Profile.CameraId == profile.CameraId && c.Destination == destination); if (camera == null) { camera = new PublishedCamera(profile, destination); Locator.Get<IStreamingManager>().StartCameraStreaming(camera); _cameras.Add(camera); DA::PublishedCamera entity = new DA::PublishedCamera() { Id = camera.Id, Profile = new DA::PublishedCameraProfile() { CameraId = profile.CameraId, CameraName = profile.CameraName, CameraThumbnail = profile.CameraThumbnail, DeviceServiceHostName = profile.DeviceServiceHostName, DeviceServiceUri = profile.DeviceServiceUri, }, Destination = new DA::Destination() { Port = camera.Destination.Port, }, }; Locator.Get<IPublishedCameraRepository>().Save(entity); } return camera; } }
public PublishedCameraManager Restore() { lock (_syncRoot) { List<DA::PublishedCamera> entities = Locator.Get<IPublishedCameraRepository>().FindAll().ToList(); foreach (var entity in entities) { PublishedCamera camera = new PublishedCamera( new PublishedCameraProfile(entity.Profile.CameraId, entity.Profile.CameraName) { CameraThumbnail = entity.Profile.CameraThumbnail, DeviceServiceHostName = entity.Profile.DeviceServiceHostName, DeviceServiceUri = entity.Profile.DeviceServiceUri, }, new PublishedDestination(entity.Destination.Port)); _cameras.Add(camera); Locator.Get<IStreamingManager>().StartCameraStreaming(camera); } return this; } }