/// <summary> /// Create the image sampler. /// </summary> private void ImageSampler() { // Get the capture sampler. if (_imageCapture == null) { _imageCapture = new ImageCapture(_capture.CaptureImageSample); } // Set the method that is used for sampling. _imageCapture.ImageCaptureThreadContext.Execute(a => a.StartContinuous(u => GetImageData(u), _imageType)); }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. /// If disposing equals true, the method has been called directly /// or indirectly by a user's code. Managed and unmanaged resources /// can be disposed. /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// </summary> protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._disposed) { // Note disposing has been done. _disposed = true; // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. if (_capture != null) { _capture.Dispose(); } if (_imageCapture != null) { _imageCapture.Dispose(); } if (_soundCapture != null) { _soundCapture.Dispose(); } } // Call the appropriate methods to clean up // unmanaged resources here. _lockObject = null; _capture = null; _imageCapture = null; _soundCapture = null; try { _block.Audio = null; _block.Video = null; } catch { } } }
/// <summary> /// Stop the capture process. /// </summary> public void Stop() { try { // If capturing. if (_capture.Capturing) { // Stop the capture. _capture.Stop(); if (_imageCapture != null) { _imageCapture.Stop(); } if (_soundCapture != null) { _soundCapture.Stop(); } // If not paused then stop the capture. if (!_isPaused) { if (_imageCapture != null) { _imageCapture.Dispose(); } if (_soundCapture != null) { _soundCapture.Dispose(); } _imageCapture = null; _soundCapture = null; // Un pause. _isPaused = false; // If in live streaming mode then // there is no need to set the duration. if (!_isLiveStreaming) { // Read the header and set the duration of the video and audio. VideoAudioHeader headers = _mux.ReadHeader(); VideoHeader videoHeader = (headers.Video.HasValue ? headers.Video.Value : new VideoHeader()); AudioHeader audioHeader = (headers.Audio.HasValue ? headers.Audio.Value : new AudioHeader()); // Get the video and audio duration. double videoDuration = _mux.VideoDuration; double audioDuration = _mux.AudioDuration; // Select what needs to be captured. switch (_active) { case MediaActiveType.Video | MediaActiveType.Audio: // Video and audio capture. videoHeader.Duration = videoDuration; audioHeader.Duration = audioDuration; break; case MediaActiveType.Video: // Video capture. videoHeader.Duration = videoDuration; break; case MediaActiveType.Audio: // Audio capture. audioHeader.Duration = audioDuration; break; } // Write the header. headers.Video = videoHeader; headers.Audio = audioHeader; _mux.WriteHeader(headers); } } } } catch { } }
/// <summary> /// Start the capture process. /// </summary> public void Start() { try { // If not capturing. if (!_capture.Capturing) { // If headers have not been written. if (!_hasHeaders) { // If in live streaming mode then // there is no need to set the duration. if (!_isLiveStreaming) { // Write the header initially. _hasHeaders = true; VideoHeader videoHeader = new VideoHeader(); AudioHeader audioHeader = new AudioHeader(); VideoAudioHeader headers = new VideoAudioHeader(); // Select what needs to be captured. switch (_active) { case MediaActiveType.Video | MediaActiveType.Audio: // Video and audio capture. videoHeader.ContainsVideo = true; videoHeader.Duration = 0.0; videoHeader.FrameRate = VideoFrameRate; videoHeader.FrameSizeHeight = VideoFrameSize.Height; videoHeader.FrameSizeWidth = VideoFrameSize.Width; videoHeader.ImageType = _imageType; videoHeader.CompressionAlgorithm = _compressionAlgorithm; audioHeader.ContainsAudio = true; audioHeader.Channels = AudioChannels; audioHeader.Duration = 0.0; audioHeader.SampleSize = AudioSampleSize; audioHeader.SamplingRate = AudioSamplingRate; audioHeader.SoundType = _soundType; audioHeader.CompressionAlgorithm = _compressionAlgorithm; break; case MediaActiveType.Video: // Video capture. videoHeader.ContainsVideo = true; videoHeader.Duration = 0.0; videoHeader.FrameRate = VideoFrameRate; videoHeader.FrameSizeHeight = VideoFrameSize.Height; videoHeader.FrameSizeWidth = VideoFrameSize.Width; videoHeader.ImageType = _imageType; videoHeader.CompressionAlgorithm = _compressionAlgorithm; break; case MediaActiveType.Audio: // Audio capture. audioHeader.ContainsAudio = true; audioHeader.Channels = AudioChannels; audioHeader.Duration = 0.0; audioHeader.SampleSize = AudioSampleSize; audioHeader.SamplingRate = AudioSamplingRate; audioHeader.SoundType = _soundType; audioHeader.CompressionAlgorithm = _compressionAlgorithm; break; } // Add the header. headers.MediaFormat = Nequeo.Media.Streaming.MediaFormat; headers.Video = videoHeader; headers.Audio = audioHeader; _mux.WriteHeader(headers); } } // Build the graph. if (!_capture.Cued) { _capture.Cue(); } // Select what needs to be captured. switch (_active) { case MediaActiveType.Video | MediaActiveType.Audio: // Video and audio capture. // Start sample capture. _capture.StartSnapshotImageSound(); // Create the samplers. ImageSampler(); SoundSampler(); break; case MediaActiveType.Video: // Video capture. // Start sample capture. _capture.StartSnapshotImage(); // Create the samplers. ImageSampler(); break; case MediaActiveType.Audio: // Audio capture. // Start sample capture. _capture.StartSnapshotSound(); // Create the samplers. SoundSampler(); break; } } } catch (Exception) { try { // If the engine has been created. if (_capture != null) { _capture.Stop(); } if (_imageCapture != null) { _imageCapture.Stop(); _imageCapture.Dispose(); } if (_soundCapture != null) { _soundCapture.Stop(); _soundCapture.Dispose(); } _imageCapture = null; _soundCapture = null; } catch { } } // Un pause. _isPaused = false; }