コード例 #1
0
ファイル: Recorder.cs プロジェクト: socialpercon/Captura
        void Dispose(bool TerminateRecord, bool TerminateWrite)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            _audioProvider?.Stop();
            _audioProvider?.Dispose();

            if (_videoWriter != null)
            {
                _cancellationTokenSource.Cancel();

                _continueCapturing.Set();

                if (TerminateRecord)
                {
                    _recordTask.Wait();
                }

                _videoWriter.Dispose();

                _continueCapturing.Dispose();
            }
            else
            {
                _audioWriter.Dispose();
            }

            _imageProvider?.Dispose();
        }
コード例 #2
0
ファイル: Recorder.cs プロジェクト: tablesmit/Screna
        /// <summary>
        /// Frees all resources used by this instance.
        /// </summary>
        public void Dispose()
        {
            ThrowIfDisposed();

            _audioProvider?.Stop();
            _audioProvider?.Dispose();

            if (_videoWriter != null)
            {
                _frames.CompleteAdding();

                _continueCapturing.Set();

                _recordTask.Wait();
                _writeTask.Wait();

                _videoWriter.Dispose();
                _frames.Dispose();

                _continueCapturing.Close();
            }
            else
            {
                _audioWriter.Dispose();
            }

            _imageProvider?.Dispose();

            _disposed = true;
        }
コード例 #3
0
        private void Dispose(bool terminateRecord)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (_audioProvider != null)
            {
                _audioProvider.DataAvailable -= AudioProvider_DataAvailable;
                _audioProvider.Stop();
                _audioProvider.Dispose();
                _audioProvider = null;
            }

            if (_videoWriter != null)
            {
                _cancellationTokenSource.Cancel();

                // Resume record loop if paused so it can exit
                _continueCapturing.Set();

                if (terminateRecord)
                {
                    _recordTask.Wait();
                }

                try
                {
                    if (_task != null && !_task.IsCompleted)
                    {
                        _task.GetAwaiter().GetResult();
                    }
                }
                catch
                {
                    // Ignored in dispose
                }

                _videoWriter.Dispose();
                _videoWriter = null;

                _continueCapturing.Dispose();
            }
            else
            {
                _audioWriter.Dispose();
                _audioWriter = null;
            }

            _imageProvider?.Dispose();
            _imageProvider = null;
        }
コード例 #4
0
        public void Dispose()
        {
            _continueEvent.Set();
            _stopEvent.Set();

            _loopTask.Wait();

            _buffer = null;

            _audioWriter.Dispose();
            _audioWriter = null;

            _audioProvider.Dispose();
            _audioProvider = null;
        }
コード例 #5
0
        void Dispose(bool TerminateRecord, bool TerminateWrite)
        {
            try
            {
                ThrowIfDisposed();

                _audioProvider?.Stop();
                _audioProvider?.Dispose();

                if (_videoWriter != null)
                {
                    _frames.CompleteAdding();

                    _continueCapturing.Set();

                    if (TerminateRecord)
                    {
                        _recordTask.Wait();
                    }

                    if (TerminateWrite)
                    {
                        _writeTask.Wait();
                    }

                    _videoWriter.Dispose();
                    _frames.Dispose();

                    _continueCapturing.Close();
                }
                else
                {
                    _audioWriter.Dispose();
                }

                _imageProvider?.Dispose();

                _disposed = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #6
0
ファイル: Recorder.cs プロジェクト: thasophearak/Captura
        void Dispose(bool TerminateRecord, bool TerminateWrite)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            _audioProvider?.Stop();
            _audioProvider?.Dispose();

            if (_videoWriter != null)
            {
                _frames.CompleteAdding();

                _continueCapturing.Set();

                if (TerminateRecord)
                {
                    _recordTask.Wait();
                }

                if (TerminateWrite)
                {
                    _writeTask.Wait();
                }

                _videoWriter.Dispose();
                _frames.Dispose();

                _continueCapturing.Dispose();
            }
            else
            {
                _audioWriter.Dispose();
            }

            _imageProvider?.Dispose();
        }
コード例 #7
0
        /// <summary>
        /// Writes all the Data in the decoder to a file
        /// </summary>
        /// <param name="Writer">Audio File Writer to write to</param>
        /// <param name="Offset">+ve for forward, -ve for backward</param>
        public void Write(IAudioFileWriter Writer, int Offset = 0)
        {
            long InitialPosition = Position;

            Position += Offset;

            int BlockLength = (int)Seconds2Bytes(2);

            byte[] Buffer = new byte[BlockLength];

            var gch = GCHandle.Alloc(Buffer, GCHandleType.Pinned);

            while (HasData)
            {
                Bass.ChannelGetData(Handle, gch.AddrOfPinnedObject(), BlockLength);
                Writer.Write(Buffer, BlockLength);
            }

            gch.Free();

            Writer.Dispose();

            Position = InitialPosition;
        }
コード例 #8
0
 /// <summary>
 /// Override this method with the code to stop recording.
 /// </summary>
 protected override void OnStop()
 {
     _audioProvider?.Dispose();
     _writer?.Dispose();
 }