private void RecieveDataCallback(IntPtr buf, int bufsize, bool isheaderdata) { var bytes = new byte[bufsize]; Marshal.Copy(buf, bytes, 0, bufsize); var dir = string.Format("{0}\\RecordFiles", Directory.GetCurrentDirectory()); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (isheaderdata) { if (writer != null) { writer.Close(); writer = null; } _path = string.Format("{0}\\recordFile{1}.mkv", dir, _count); writer = new BinaryWriter(File.Open(_path, FileMode.Append)); _count++; } if (_path != string.Empty) { writer.Write(bytes); } _fileSize += bufsize; if (_fileSize > 104857600) { RtspRecorder.WriteHeader(_rtspPath); _fileSize = 0; } }
public void StartRecord(string rtsp) { _rtspPath = rtsp; _recieveDataCallback += RecieveDataCallback; _errorCallback += ErrorCallback; RtspRecorder.StartCallbackRecord(_rtspPath, 10000, _recieveDataCallback, null, _errorCallback); }
private void RecordStreamButton_OnClick(object sender, RoutedEventArgs e) { _rtspPath = PathRecordTextBox.Text; _recieveDataCallback += RecieveDataCallback; _errorCallback += ErrorCallback; RtspRecorder.StartCallbackRecord(_rtspPath, 0, _recieveDataCallback, null, _errorCallback); //RtspRecorder.StartFileRecord(_rtspPath, "D:\\TestVideo\\Record\\test.mkv", 15000, _errorCallback); }
public void InternalContolTest() { var fileName = GetFileName(nameof(InternalContolTest)); var recorder = new RtspRecorder(rtsp, fileName); ThreadPool.QueueUserWorkItem(_ => recorder.Start()); Thread.Sleep(5000); recorder.Stop(); Assert.True(File.Exists(fileName)); }
private void StopRecordStreamButton_OnClick(object sender, RoutedEventArgs e) { RtspRecorder.Stop(_rtspPath); if (writer != null) { writer.Close(); if (fsStream != null) { fsStream.Close(); } } }
private void RecieveDataCallback(IntPtr buf, int bufSize, bool isHeaderData) { var bytes = new byte[bufSize]; Marshal.Copy(buf, bytes, 0, bufSize); var dir = string.Format("{0}\\RecordFiles", Directory.GetCurrentDirectory()); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (isHeaderData) { if (writer != null) { writer.Close(); if (fsStream != null) { fsStream.Close(); } } _path = string.Format("{0}\\recordFile{1}.mkv", dir, _count); fsStream = new FileStream(_path, FileMode.Append); writer = new BinaryWriter(fsStream, Encoding.UTF8); _count++; _isHeaderCall = false; } if (_path != string.Empty) { writer.Write(bytes); } _fileSize += bufSize; if (_fileSize > 10000000 && !_isHeaderCall) { RtspRecorder.WriteHeader(_rtspPath); _isHeaderCall = true; _fileSize = 0; } }
public void ExternalControlTest() { const string key = "cameraTest"; var fileName = GetFileName(nameof(ExternalControlTest)); var recorder = new RtspRecorder(rtsp, fileName, addr => MemoryCache.Default[key]?.ToString() == addr, (s, e) => { //OnException (s as RtspRecorder).Stop(); MemoryCache.Default[key] = string.Empty; } ); MemoryCache.Default[key] = rtsp; ThreadPool.QueueUserWorkItem(state => recorder.Start()); Thread.Sleep(5000); MemoryCache.Default[key] = string.Empty; Assert.True(File.Exists(fileName)); }
public void StopRecord(string rtsp) { RtspRecorder.Stop(rtsp); }