/// <summary> /// Get the resolution of the latest recorded image /// </summary> static void GetRes() { var jpegSource = new JPEGVideoSource(_camera); jpegSource.Init(); jpegSource.Height = 0; jpegSource.Width = 0; Console.WriteLine("Asking for the last recorded image from camera {0} ", _camera.Name); var jpegData = jpegSource.GetEnd(); if (jpegData == null) { Console.WriteLine("No recorded image from " + _camera.Name); } else { Console.WriteLine("The resolution of the last recorded image " + "from camera {0} is ({1},{2})" + Environment.NewLine, _camera.Name, jpegData.Width, jpegData.Height); } }
private void JPEGFetchThread() { bool errorRecovery = false; while (!_stop) { if (_performCloseVideoSource) { if (_jpegVideoSource != null) { _jpegVideoSource.Close(); _jpegVideoSource = null; } _performCloseVideoSource = false; } if (_newlySelectedItem != null) { _selectedItem = _newlySelectedItem; _jpegVideoSource = new JPEGVideoSource(_selectedItem); if (checkBoxAspect.Checked) { // Keeping aspect ratio can only work when the Media Toolkit knows the actual displayed area _jpegVideoSource.Width = pictureBox.Width; _jpegVideoSource.Height = pictureBox.Height; _jpegVideoSource.SetKeepAspectRatio(checkBoxAspect.Checked, checkBoxFill.Checked); // Must be done before Init } try { _jpegVideoSource.Init(); JPEGData jpegData = _currentShownTime == DateTime.MinValue ? _jpegVideoSource.GetBegin() : _jpegVideoSource.GetAtOrBefore(_currentShownTime) as JPEGData; if (jpegData != null) { _requestInProgress = true; ShowJPEG(jpegData); } else { ShowError(""); // Clear any error messages } _newlySelectedItem = null; errorRecovery = false; } catch (Exception ex) { if (ex is CommunicationMIPException) { ShowError("Connection lost to server ..."); } else { ShowError(ex.Message); } errorRecovery = true; _jpegVideoSource = null; _newlySelectedItem = _selectedItem; // Redo the Initialization } } if (errorRecovery) { Thread.Sleep(3000); continue; } if (_setNewResolution && _jpegVideoSource != null && _requestInProgress == false) { try { _jpegVideoSource.Width = _newWidth; _jpegVideoSource.Height = _newHeight; _jpegVideoSource.SetWidthHeight(); _setNewResolution = false; JPEGData jpegData; jpegData = _jpegVideoSource.GetAtOrBefore(_currentShownTime) as JPEGData; if (jpegData != null) { _requestInProgress = true; _currentShownTime = DateTime.MinValue; ShowJPEG(jpegData); } } catch (Exception ex) { if (ex is CommunicationMIPException) { ShowError("Connection lost to recorder..."); } else { ShowError(ex.Message); } errorRecovery = true; _jpegVideoSource = null; _newlySelectedItem = _selectedItem; // Redo the Initialization } } if (_requestInProgress == false && _jpegVideoSource != null && _nextCommand != MyPlayCommand.None) { JPEGData jpegData = null; try { switch (_nextCommand) { case MyPlayCommand.Start: jpegData = _jpegVideoSource.GetBegin(); break; case MyPlayCommand.NextFrame: jpegData = _jpegVideoSource.GetNext() as JPEGData; break; case MyPlayCommand.NextSequence: jpegData = _jpegVideoSource.GetNextSequence(); break; case MyPlayCommand.PrevFrame: jpegData = _jpegVideoSource.GetPrevious(); break; case MyPlayCommand.PrevSequence: jpegData = _jpegVideoSource.GetPreviousSequence(); break; case MyPlayCommand.End: jpegData = _jpegVideoSource.GetEnd(); break; } } catch (Exception ex) { if (ex is CommunicationMIPException) { ShowError("Connection lost to recorder..."); } else { ShowError(ex.Message); } errorRecovery = true; _jpegVideoSource = null; _newlySelectedItem = _selectedItem; // Redo the Initialization } if (jpegData != null) { _requestInProgress = true; ShowJPEG(jpegData); } _nextCommand = MyPlayCommand.None; } if (_nextToFetchTime != DateTime.MinValue && _requestInProgress == false && _jpegVideoSource != null) { bool willResultInSameFrame = false; // Lets validate if we are just asking for the same frame if (_currentTimeInformation != null) { if (_currentTimeInformation.PreviousTime < _nextToFetchTime && _currentTimeInformation.NextTime > _nextToFetchTime) { willResultInSameFrame = true; } } if (willResultInSameFrame) { Debug.WriteLine("Now Fetch ignored: " + _nextToFetchTime.ToLongTimeString() + " - nextToFetch=" + _nextToFetchTime.ToLongTimeString()); // Same frame -> Ignore request _requestInProgress = false; _nextToFetchTime = DateTime.MinValue; } else { Debug.WriteLine("Now Fetch: " + _nextToFetchTime.ToLongTimeString()); DateTime time = _nextToFetchTime; _nextToFetchTime = DateTime.MinValue; try { DateTime localTime = time.Kind == DateTimeKind.Local ? time : time.ToLocalTime(); DateTime utcTime = time.Kind == DateTimeKind.Local ? time.ToUniversalTime() : time; BeginInvoke( new MethodInvoker(delegate() { textBoxAsked.Text = localTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); })); JPEGData jpegData; jpegData = _jpegVideoSource.GetAtOrBefore(utcTime) as JPEGData; if (jpegData == null && _mode == PlaybackPlayModeData.Stop) { jpegData = _jpegVideoSource.GetNearest(utcTime) as JPEGData; } if (_mode == PlaybackPlayModeData.Reverse) { while (jpegData != null && jpegData.DateTime > utcTime) { jpegData = _jpegVideoSource.GetPrevious(); } } else if (_mode == PlaybackPlayModeData.Forward) { if (jpegData != null && jpegData.DateTime < utcTime) { jpegData = _jpegVideoSource.Get(utcTime) as JPEGData; } } if (jpegData != null) { _requestInProgress = true; ShowJPEG(jpegData); } } catch (Exception ex) { if (ex is CommunicationMIPException) { ShowError("Connection lost to server ..."); } else { ShowError(ex.Message); } errorRecovery = true; _jpegVideoSource = null; _newlySelectedItem = _selectedItem; // Redo the Initialization } } } Thread.Sleep(5); } _fetchThread = null; }