private void InitCam1() { panel1.Controls.Clear(); _wp1 = new CameraPanel(panel1); _wp1.Dock = DockStyle.Fill; panel1.Controls.Add(_wp1); }
public async Task StartStreamingAsync(CameraPanel panel, object preview) { if (CurrentState == ScenarioState.Idle) { await this.ChangeScenarioStateAsync(ScenarioState.Streaming, panel, preview as CaptureElement); } }
private void InitCam3() { panel3.Controls.Clear(); _wp3 = new CameraPanel(panel3); _wp3.Dock = DockStyle.Fill; panel3.Controls.Add(_wp3); }
void ObjectPing(GameObject obj) { if (objectRevealTimer.CurrentObjectList == (int)VisibilityState.RevealingObjects) { obj.SetActive(true); float currentDelay = objectRevealTimer.objectLists[objectRevealTimer.CurrentObjectList].objectTaskDelay; if (currentDelay < maxRevealDelay) { objectRevealTimer.SetListRevealDelay(objectRevealTimer.CurrentObjectList, Mathf.Clamp(currentDelay * blocksRevealDelayGrowth, 0.0f, maxRevealDelay)); } } else if (objectRevealTimer.CurrentObjectList == (int)VisibilityState.RevealingCameras) { obj.SetActive(true); CameraPanel camPanel = obj.GetComponentInChildren <CameraPanel>(); if (camPanel != null) { camPanel.PostActivate(); } } else if (objectRevealTimer.CurrentObjectList == (int)VisibilityState.RevealingPanel) { if (UDLRCameraController.Instance != null) { UDLRCameraController.Instance.panelController.enabled = true; } } }
private bool MouseScreenCheck() { CameraPanel viewPanel = GetComponent <CameraPanel>(); if (viewPanel != null) { RectTransform rectTransform = viewPanel.m_ParentPanel.GetComponent <RectTransform>(); if (rectTransform != null) { if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, null)) { return(true); } } } // Old method left for reference // This used the entire screen. The new method above uses only the actual view panel // if ( Input.mousePosition.x >= 0 && Input.mousePosition.y >= 0 ) // { //#if UNITY_EDITOR // if ( Input.mousePosition.x < Handles.GetMainGameViewSize().x - 1 && Input.mousePosition.y < Handles.GetMainGameViewSize().y - 1 ) //#else // if ( Input.mousePosition.x < Screen.width - 1 && Input.mousePosition.y < Screen.height - 1 ) //#endif // { // return true; // } // } return(false); }
public Task StartStreamingAsync(CameraPanel panel, object preview) { this.textureView = preview as TextureView; this.TryStart(); CurrentState = ScenarioState.Streaming; return(Task.FromResult <object>(null)); }
public Task StartStreamingAsync(CameraPanel panel, object preview) { this.contentLayer = preview as AVCaptureVideoPreviewLayer; this.TryStart(); CurrentState = ScenarioState.Streaming; return(Task.FromResult <object>(null)); }
void OnEnable() { CameraPorts cameraports = CameraPanel.Load(); List <int> portSettings = new List <int>(); portSettings.Add(cameraports.camera1); portSettings.Add(cameraports.camera2); portSettings.Add(cameraports.camera3); portSettings.Add(cameraports.camera4); portSettings.Add(cameraports.idMiniROV); //Debug.Log("El id está en la posicion: "+portSettings.Count); GameObject parent = GameObject.Find("CameraManager"); for (int i = 0; i < parent.transform.childCount; i++) { if (this.gameObject.name == ("VideoStream" + (i + 1))) { port = portSettings[i].ToString(); int mjpegCamera = portSettings[portSettings.Count - 1]; if (i == mjpegCamera) { pipeline = "udpsrc port=" + port + " ! application/x-rtp,encoding-name=JPEG,payload=26 ! rtpjpegdepay ! jpegdec ! appsink name=videoSink"; } else { pipeline = "udpsrc port=" + port + " ! application/x-rtp ! rtph264depay ! avdec_h264 ! videoconvert ! appsink name=videoSink"; } } } m_Texture = gameObject.GetComponent <GstCustomTexture>(); m_Texture.Initialize(); //StartCoroutine(Dalay()); System.Threading.Thread.Sleep(100); //pipeline = "udpsrc port="+port+" ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink name=videoSink"; m_Texture.SetPipeline(pipeline); // pipeline+" ! video/x-raw,format=I420 ! videoconvert ! appsink name=videoSink" //StartCoroutine(Dalay()); System.Threading.Thread.Sleep(100); m_Texture.Player.CreateStream(); //StartCoroutine(Dalay()); System.Threading.Thread.Sleep(100); m_Texture.Player.Play(); m_Texture.OnFrameBlitted += OnFrameBlitted; _img = new GstImageInfo(); _img.Create(1, 1, GstImageInfo.EPixelFormat.EPixel_R8G8B8); BlittedImage = new Texture2D(1, 1); BlittedImage.filterMode = FilterMode.Bilinear; BlittedImage.anisoLevel = 0; BlittedImage.wrapMode = TextureWrapMode.Clamp; if (TargetMaterial != null) { TargetMaterial.mainTexture = BlittedImage; } }
void InitUI() { geoUI = new GeoUI(); Transform canvasBack = GameObject.Find("/UI/CanvasBack").transform; Transform canvasFront = GameObject.Find("/UI/CanvasFront").transform; NavPanel navPanel = canvasBack.Find("NavPanel").GetComponent <NavPanel>(); navPanel.OnShadeButtonClick = HandleClickShadeButton; navPanel.OnLockButtonClick = HandleClickLockButton; navPanel.OnDisplayButtonClick = HandleClickDisplayButton; navPanel.OnCoordinateButtonClick = HandleClickCoordinateButton; navPanel.OnGridButtonClick = HandleClickGridButton; navPanel.OnSnapButtonClick = HandleClickSnapButton; geometryBehaviour.OnElementDisplayChange = HandleElementDisplayChange; navPanel.Init(); ToolPanel toolPanel = canvasBack.Find("ToolPanel").GetComponent <ToolPanel>(); toolPanel.Init(); toolPanel.OnClickTool = HandleClickTool; StatePanel statePanel = canvasBack.Find("StatePanel").GetComponent <StatePanel>(); statePanel.Init(); InputPanel inputPanel = canvasBack.Find("InputPanel").GetComponent <InputPanel>(); inputPanel.Init(); ElementPanel elementPanel = canvasFront.Find("ElementPanel").GetComponent <ElementPanel>(); elementPanel.Init(); ActivePanel activePanel = canvasFront.Find("ActivePanel").GetComponent <ActivePanel>(); activePanel.Init(); CameraPanel cameraPanel = canvasFront.Find("CameraPanel").GetComponent <CameraPanel>(); cameraPanel.OnCenterButtonClick = HandleClickCenterButton; cameraPanel.OnZoomInButtonClick = HandleClickZoomInButton; cameraPanel.OnZoomOutButtonClick = HandleClickZoomOutButton; cameraPanel.OnUpButtonClick = HandleClickUpButton; cameraPanel.OnDownButtonClick = HandleClickDownButton; cameraPanel.Init(); cameraPanel.SetCenterButtonActive(false); geoUI.navPanel = navPanel; geoUI.toolPanel = toolPanel; geoUI.statePanel = statePanel; geoUI.inputPanel = inputPanel; geoUI.elementPanel = elementPanel; geoUI.activePanel = activePanel; geoUI.cameraPanel = cameraPanel; }
private async Task NotifyCameraPanelAsync() { // Avoids to notify if the camera panel is the same. if (streamingService.CameraPanel != lastCameraPanel) { var message = streamingService.CameraPanel == CameraPanel.Front ? AppResources.FrontCameraReady : AppResources.BackCameraReady; StatusMessage = message; await SpeechHelper.TrySpeechAsync(message); lastCameraPanel = streamingService.CameraPanel; } }
private Windows.Devices.Enumeration.Panel ConvertCameraPanelToDevicePanel(CameraPanel panel) { switch (panel) { case CameraPanel.Front: return(Windows.Devices.Enumeration.Panel.Front); case CameraPanel.Back: case CameraPanel.Unknown: default: return(Windows.Devices.Enumeration.Panel.Back); } }
public Task SwapCameraAsync() { if (session != null) { var currentCameraInput = session.Inputs[0]; AVCaptureDevice newCamera; if (currentCameraInput.GetPosition() == AVCaptureDevicePosition.Back) { newCamera = AVCaptureDevice .DevicesWithMediaType(AVMediaType.Video) .FirstOrDefault(d => d.Position == AVCaptureDevicePosition.Front); } else { newCamera = AVCaptureDevice .DevicesWithMediaType(AVMediaType.Video) .FirstOrDefault(d => d.Position == AVCaptureDevicePosition.Back); } if (newCamera != null) { session.BeginConfiguration(); session.RemoveInput(currentCameraInput); NSError error = null; var newInput = new AVCaptureDeviceInput(newCamera, out error); if (error == null) { session.AddInput(newInput); CameraPanel = currentCameraInput.GetPosition() == AVCaptureDevicePosition.Back ? CameraPanel.Front : CameraPanel.Back; } else { //rollback session.RemoveInput(currentCameraInput); } session.CommitConfiguration(); } } return(Task.FromResult <object>(null)); }
public static CamAnimator GetSelectedCameraAnimator() { if (Instance == null) { return(null); } foreach (CamAnimator cam in Instance.cameraAnimators) { if (cam != null) { CameraPanel panel = cam.CameraPanel; if (panel.camPosition == Instance.selectedPosition) { return(cam); } } } Assert.IsTrue(false /* Found no selected camera! */); return(Instance.cameraAnimators[0]); }
/// <summary> /// Manages the scenario's internal state. Invokes the internal methods and updates the UI according to the /// passed in state value. Handles failures and resets the state if necessary. /// </summary> /// <param name="newState">State to switch to</param> private async Task ChangeScenarioStateAsync(ScenarioState newState, CameraPanel panel = CameraPanel.Back, CaptureElement preview = null) { switch (newState) { case ScenarioState.Idle: this.ShutdownWebCam(); break; case ScenarioState.Streaming: preview = this.preview ?? preview; if (!await this.StartWebcamStreamingAsync(panel, preview)) { await this.ChangeScenarioStateAsync(ScenarioState.Idle); break; } break; } this.CurrentState = newState; }
public static void CamearPanelChaneg( DependencyObject obj, DependencyPropertyChangedEventArgs e) { if (!(obj is Grid)) { return; } Grid grid = obj as Grid; CameraPanel oldTV = e.OldValue as CameraPanel; CameraPanel newTV = e.NewValue as CameraPanel; // 只有布局的,绘制布局 // 两者都有的,判断布局是否有变化 // 只有视频源信息的,替换视频源 if (newTV.LayoutInfo != null && newTV.Cameras == null) { CreateGrid(grid, newTV.LayoutInfo); } else if (newTV.LayoutInfo != null && newTV.Cameras != null) { if (oldTV.LayoutInfo != null && oldTV.LayoutInfo.Id == newTV.LayoutInfo.Id) { // 替换视频源 foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); if (panelItem.Flag == 1) { SetBorderChildByVLC(border, panelItem); } else if (panelItem.Flag == 0) { if (border.Child is WindowsFormsHost windowsForms) { if (windowsForms.Child is VlcControl vlcControl) { vlcControl.Stop(); } } border.Child = new Image { Source = imageSource, Width = 125, Height = 161 }; } } } else { CreateGrid(grid, newTV.LayoutInfo); foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); SetBorderChildByVLC(border, panelItem); } } } else if (newTV.Cameras != null) { if (grid.Children.Count > 0) { // 替换视频源 foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); if (panelItem.Flag == 1) { SetBorderChildByVLC(border, panelItem); } else if (panelItem.Flag == 0) { if (border.Child is WindowsFormsHost windowsForms) { if (windowsForms.Child is VlcControl vlcControl) { vlcControl.Stop(); } } border.Child = new Image { Source = imageSource, Width = 125, Height = 161 }; } } } } }
public void SwitchCameraVertical(UIPanel.MovementDirection direction) { Assert.IsTrue(direction == UIPanel.MovementDirection.Up || direction == UIPanel.MovementDirection.Down); selectedPosition = CameraPanel.SwitchPositionVertical(selectedPosition); panelController.PositionPanel(selectedPosition, direction); }
public void SwitchCameraHorizontal(UIPanel.MovementDirection direction) { Assert.IsTrue(direction == UIPanel.MovementDirection.Left || direction == UIPanel.MovementDirection.Right); selectedPosition = CameraPanel.SwitchPositionHorizontal(selectedPosition); panelController.PositionPanel(selectedPosition, direction); }
/// <summary> /// 播放命令操作 /// </summary> /// <param name="tvConfig"></param> public void PlayOnTV(TvConfig tvConfig) { // 处理数据对象,转换为封装的 Camera 等对象 CameraPanel cameraPanel = new CameraPanel { LayoutInfo = tvConfig.LayoutInfo }; if (tvConfig.MonitorInfo != null) { List <int> indexs = tvConfig.MonitorInfo.Select(t => t.Index).Distinct().ToList(); foreach (int index in indexs) { List <MonitorInfo> monitors = tvConfig.MonitorInfo.Where(t => t.Index == index).ToList(); CameraPanelItem panelItem = new CameraPanelItem { Index = index, RtspStrs = new List <string>(), RtmpStrs = new List <string>() }; if (monitors.Count > 1) { CameraGroup cameraGroup = new CameraGroup { Interval = monitors[0].TimeInterval }; foreach (var monitor in monitors) { DVR dvr = new DVR() { IP = monitor.Ip, Port = monitor.AdminPort, UserName = monitor.User, Password = monitor.PassWord, Id = monitor.Id }; Camera camera = new Camera { StreamType = monitor.StreamType, DVR = dvr, Number = monitor.Channel }; cameraGroup.Items.Add(camera); panelItem.RtspStrs.Add(monitor.Rtsp); panelItem.RtmpStrs.Add(monitor.Rtmp); } panelItem.CameraGroup = cameraGroup; panelItem.Flag = monitors[0].Flag; panelItem.PlayType = PlayContentType.Group; } else { MonitorInfo monitor = monitors[0]; DVR dvr = new DVR() { IP = monitor.Ip, Port = monitor.AdminPort, UserName = monitor.User, Password = monitor.PassWord, Id = monitor.Id }; Camera camera = new Camera() { DVR = dvr, StreamType = monitor.StreamType, Number = monitor.Channel }; panelItem.RtspStrs.Add(monitor.Rtsp); panelItem.RtmpStrs.Add(monitor.Rtmp); panelItem.Camera = camera; panelItem.Flag = monitor.Flag; panelItem.PlayType = PlayContentType.One; } cameraPanel.Cameras.Add(panelItem); } } gridVideo.SetValue(GridHelpers.CamearPanelProperty, cameraPanel); }
/// <summary> /// 播放命令操作 /// </summary> /// <param name="tvConfig"></param> public void PlayOnTV(TvConfig tvConfig) { // 当布局变化时视频信息会变,清楚全部的 CameraPanelItem 信息 if (tvConfig.LayoutInfo != null) { this.cameras = new Dictionary <int, CameraPanelItem>(); } // 处理数据对象,转换为封装的 Camera 等对象 CameraPanel cameraPanel = new CameraPanel { LayoutInfo = tvConfig.LayoutInfo }; if (tvConfig.MonitorInfo != null) { List <int> indexs = tvConfig.MonitorInfo.Select(t => t.Index).Distinct().ToList(); foreach (int index in indexs) { List <MonitorInfo> monitors = tvConfig.MonitorInfo.Where(t => t.Index == index).ToList(); CameraPanelItem panelItem = new CameraPanelItem { Index = index }; if (monitors.Count > 1) { CameraGroup cameraGroup = new CameraGroup { Interval = monitors[0].TimeInterval }; foreach (var monitor in monitors) { DVR dvr = new DVR() { IP = monitor.Ip, Port = monitor.AdminPort, UserName = monitor.User, Password = monitor.PassWord, Id = monitor.Id }; Camera camera = new Camera { StreamType = monitor.StreamType, DVR = dvr, Number = monitor.Channel }; cameraGroup.Items.Add(camera); } panelItem.CameraGroup = cameraGroup; panelItem.Flag = monitors[0].Flag; panelItem.PlayType = PlayContentType.Group; } else { MonitorInfo monitor = monitors[0]; DVR dvr = new DVR() { IP = monitor.Ip, Port = monitor.AdminPort, UserName = monitor.User, Password = monitor.PassWord, Id = monitor.Id }; Camera camera = new Camera() { DVR = dvr, StreamType = monitor.StreamType, Number = monitor.Channel }; panelItem.Camera = camera; panelItem.Flag = monitor.Flag; panelItem.PlayType = PlayContentType.One; if (monitor.Ip == null && monitor.User == null) { panelItem.Flag = 0; } } cameraPanel.Cameras.Add(panelItem); if (this.cameras.ContainsKey(index)) { this.cameras.Remove(index); } this.cameras.Add(index, panelItem); } // 登录各个设备,为后面播放, // 这里再返回赋值,因为每次都需要登录信息,否则失败 foreach (var item2 in cameraPanel.Cameras) { if (item2.Camera != null) { item2.Camera.DVR.Connection(false); } else if (item2.CameraGroup != null) { foreach (var item in item2.CameraGroup.Items) { item.DVR.Connection(false); } } } } this.gridVideo.SetValue(GridHelpers.CamearPanelProperty, cameraPanel); }
void SwitchPanelHorizontal() { currentSelection = (ButtonSelection)CameraPanel.SwitchPositionHorizontal((CameraPanel.DisplayPosition)currentSelection); }
public static void CamearPanelChaneg( DependencyObject obj, DependencyPropertyChangedEventArgs e) { if (!(obj is Grid)) { return; } Grid grid = obj as Grid; CameraPanel oldTV = e.OldValue as CameraPanel; CameraPanel newTV = e.NewValue as CameraPanel; // 只有布局的,绘制布局 // 两者都有的,判断布局是否有变化 // 只有视频源信息的,替换视频源 if (newTV.LayoutInfo != null && newTV.Cameras == null) { CreateGrid(grid, newTV.LayoutInfo); } else if (newTV.LayoutInfo != null && newTV.Cameras != null) { if (oldTV.LayoutInfo != null && oldTV.LayoutInfo.Id == newTV.LayoutInfo.Id) { // 替换视频源 foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); if (panelItem.Flag == 1) { SetCameraOnBorder(border, panelItem); } else if (panelItem.Flag == 0) { if (border.DataContext is CameraPanelItem oldItem) { oldItem.GetPlayView().Stop(); } if (showLogo) { border.Child = new Image { Source = imageSource, Width = 125, Height = 161 }; } else { border.Child = null; } } } } else { CreateGrid(grid, newTV.LayoutInfo); foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); SetCameraOnBorder(border, panelItem); } } } else if (newTV.Cameras != null) { if (grid.Children.Count > 0) { // 替换视频源 foreach (var panelItem in newTV.Cameras) { Border border = GetBorderByTag(grid.Children, panelItem.Index); if (panelItem.Flag == 1) { SetCameraOnBorder(border, panelItem); } else { if (border.DataContext is CameraPanelItem oldItem) { oldItem.GetPlayView().Stop(); } if (showLogo) { border.Child = new Image { Source = imageSource, Width = 125, Height = 161 }; } else { border.Child = null; } } } } } }
/// <summary> /// Initializes a new MediaCapture instance and starts the Preview streaming to the CamPreview UI element. /// </summary> /// <returns>Async Task object returning true if initialization and streaming were successful and false if an exception occurred.</returns> private async Task <bool> StartWebcamStreamingAsync(CameraPanel panel, CaptureElement preview) { if (preview == null) { return(false); } var successful = true; try { this.preview = preview; this.preview.Visibility = Visibility.Collapsed; // For this scenario, we only need Video (not microphone) so specify this in the initializer. // NOTE: the appxmanifest only declares "webcam" under capabilities and if this is changed to include // microphone (default constructor) you must add "microphone" to the manifest or initialization will fail. // Attempt to get the back camera if one is available, but use any camera device if not var cameraDevice = await this.FindCameraDeviceByPanelAsync(this.ConvertCameraPanelToDevicePanel(panel)); var settings = new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video, VideoDeviceId = cameraDevice.Id }; this.mediaCapture = new MediaCapture(); await this.mediaCapture.InitializeAsync(settings); this.mediaCapture.Failed += this.MediaCapture_CameraStreamFailed; // Cache the media properties as we'll need them later. var deviceController = this.mediaCapture.VideoDeviceController; this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; // Figure out where the camera is located if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown) { // No information on the location of the camera, assume it's an external camera, not integrated on the device externalCamera = true; } else { // Camera is fixed on the device externalCamera = false; } // Only mirror the preview if the camera is on the front panel mirroringPreview = (cameraDevice.EnclosureLocation?.Panel == Windows.Devices.Enumeration.Panel.Front); CameraPanel = this.ConvertDevicePanelToCameraPanel(cameraDevice.EnclosureLocation?.Panel ?? Windows.Devices.Enumeration.Panel.Unknown); await this.StartPreviewAsync(); // Ensure the Semaphore is in the signalled state. this.frameProcessingSemaphore.Release(); } catch (UnauthorizedAccessException) { // If the user has disabled their webcam this exception is thrown; provide a descriptive message to inform the user of this fact. successful = false; } catch (Exception ex) { var msg = ex.Message; successful = false; } return(successful); }
void SwitchPanelVertical() { currentSelection = (ButtonSelection)CameraPanel.SwitchPositionVertical((CameraPanel.DisplayPosition)currentSelection); }