void FirewireRecorder::run(void) { LOG(VB_RECORD, LOG_INFO, LOC + "run"); if (!Open()) { _error = "Failed to open firewire device"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); return; } _continuity_error_count = 0; { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } StartStreaming(); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (!IsRecordingRequested()) break; { // sleep 1 seconds unless StopRecording() or Unpause() is called, // just to avoid running this too often. QMutexLocker locker(&pauseLock); if (!request_recording || request_pause) continue; unpauseWait.wait(&pauseLock, 1000); } } StopStreaming(); FinishRecording(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); }
void IPTVRecorder::run(void) { LOG(VB_RECORD, LOG_INFO, LOC + "run() -- begin"); if (!Open()) { _error = "Failed to open IPTV stream"; return; } // Start up... { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (!IsRecordingRequested()) break; if (!_channel->GetFeeder()->IsOpen()) { usleep(5000); continue; } // Go into main RTSP loop, feeding data to AddData _channel->GetFeeder()->Run(); } // Finish up... FinishRecording(); Close(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); LOG(VB_RECORD, LOG_INFO, LOC + "run() -- end"); }
void IPTVRecorder::StartRecording(void) { VERBOSE(VB_RECORD, LOC + "StartRecording() -- begin"); if (!Open()) { _error = true; return; } // Start up... _recording = true; _request_recording = true; while (_request_recording) { if (PauseAndWait()) continue; if (!_channel->GetFeeder()->IsOpen()) { usleep(5000); continue; } // Go into main RTSP loop, feeding data to AddData _channel->GetFeeder()->Run(); } // Finish up... FinishRecording(); Close(); VERBOSE(VB_RECORD, LOC + "StartRecording() -- end"); _recording = false; _cond_recording.wakeAll(); }
void DVBRecorder::run(void) { if (!Open()) { _error = "Failed to open DVB device"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); return; } { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } // Listen for time table on DVB standard streams if (_channel && (_channel->GetSIStandard() == "dvb")) _stream_data->AddListeningPID(DVB_TDT_PID); // Make sure the first things in the file are a PAT & PMT bool tmp = _wait_for_keyframe_option; _wait_for_keyframe_option = false; HandleSingleProgramPAT(_stream_data->PATSingleProgram()); HandleSingleProgramPMT(_stream_data->PMTSingleProgram()); _wait_for_keyframe_option = tmp; _stream_data->AddAVListener(this); _stream_data->AddWritingListener(this); _stream_handler->AddListener(_stream_data, false, true); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; { // sleep 100 milliseconds unless StopRecording() or Unpause() // is called, just to avoid running this too often. QMutexLocker locker(&pauseLock); if (!request_recording || request_pause) continue; unpauseWait.wait(&pauseLock, 100); } if (!_input_pmt) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Recording will not commence until a PMT is set."); usleep(5000); continue; } if (!_stream_handler->IsRunning()) { _error = "Stream handler died unexpectedly."; LOG(VB_GENERAL, LOG_ERR, LOC + _error); } } _stream_handler->RemoveListener(_stream_data); _stream_data->RemoveWritingListener(this); _stream_data->RemoveAVListener(this); Close(); FinishRecording(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); }
void ASIRecorder::run(void) { if (!Open()) { _error = "Failed to open device"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); return; } if (!_stream_data) { _error = "MPEGStreamData pointer has not been set"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); Close(); return; } { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } if (m_channel->HasGeneratedPAT()) { const ProgramAssociationTable *pat = m_channel->GetGeneratedPAT(); const ProgramMapTable *pmt = m_channel->GetGeneratedPMT(); _stream_data->Reset(pat->ProgramNumber(0)); _stream_data->HandleTables(MPEG_PAT_PID, *pat); _stream_data->HandleTables(pat->ProgramPID(0), *pmt); } // Listen for time table on DVB standard streams if (m_channel && (m_channel->GetSIStandard() == "dvb")) _stream_data->AddListeningPID(DVB_TDT_PID); StartNewFile(); _stream_data->AddAVListener(this); _stream_data->AddWritingListener(this); m_stream_handler->AddListener( _stream_data, false, true, (_record_mpts) ? ringBuffer->GetFilename() : QString()); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; { // sleep 100 milliseconds unless StopRecording() or Unpause() // is called, just to avoid running this too often. QMutexLocker locker(&pauseLock); if (!request_recording || request_pause) continue; unpauseWait.wait(&pauseLock, 100); } if (!_input_pmt) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Recording will not commence until a PMT is set."); usleep(5000); continue; } if (!m_stream_handler->IsRunning()) { _error = "Stream handler died unexpectedly."; LOG(VB_GENERAL, LOG_ERR, LOC + _error); } } m_stream_handler->RemoveListener(_stream_data); _stream_data->RemoveWritingListener(this); _stream_data->RemoveAVListener(this); Close(); FinishRecording(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); }
void HDHRRecorder::StartRecording(void) { LOG(VB_RECORD, LOG_INFO, LOC + "StartRecording -- begin"); /* Create video socket. */ if (!Open()) { _error = "Failed to open HDHRRecorder device"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); return; } _continuity_error_count = 0; { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } // Make sure the first things in the file are a PAT & PMT bool tmp = _wait_for_keyframe_option; _wait_for_keyframe_option = false; HandleSingleProgramPAT(_stream_data->PATSingleProgram()); HandleSingleProgramPMT(_stream_data->PMTSingleProgram()); _wait_for_keyframe_option = tmp; _stream_data->AddAVListener(this); _stream_data->AddWritingListener(this); _stream_handler->AddListener(_stream_data); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (!IsRecordingRequested()) break; { // sleep 100 milliseconds unless StopRecording() or Unpause() // is called, just to avoid running this too often. QMutexLocker locker(&pauseLock); if (!request_recording || request_pause) continue; unpauseWait.wait(&pauseLock, 100); } if (!_input_pmt) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Recording will not commence until a PMT is set."); usleep(5000); continue; } if (!_stream_handler->IsRunning()) { _error = "Stream handler died unexpectedly."; LOG(VB_GENERAL, LOG_ERR, LOC + _error); } } LOG(VB_RECORD, LOG_INFO, LOC + "StartRecording -- ending..."); _stream_handler->RemoveListener(_stream_data); _stream_data->RemoveWritingListener(this); _stream_data->RemoveAVListener(this); Close(); FinishRecording(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); LOG(VB_RECORD, LOG_INFO, LOC + "StartRecording -- end"); }
void V4L2encRecorder::run(void) { LOG(VB_RECORD, LOG_INFO, LOC + "run() -- begin"); bool failing, failed; bool is_TS = false; if (!m_stream_data) { m_error = "MPEGStreamData pointer has not been set"; LOG(VB_GENERAL, LOG_ERR, LOC + "run() -- " + m_error); Close(); return; } m_stream_handler->Configure(); { QMutexLocker locker(&m_pauseLock); m_request_recording = true; m_recording = true; m_recordingWait.wakeAll(); } if (m_channel->HasGeneratedPAT()) { const ProgramAssociationTable *pat = m_channel->GetGeneratedPAT(); const ProgramMapTable *pmt = m_channel->GetGeneratedPMT(); m_stream_data->Reset(pat->ProgramNumber(0)); m_stream_data->HandleTables(MPEG_PAT_PID, *pat); m_stream_data->HandleTables(pat->ProgramPID(0), *pmt); LOG(VB_GENERAL, LOG_INFO, LOC + "PMT set"); // debugging } StartNewFile(); is_TS = (m_stream_handler->GetStreamType() == V4L2_MPEG_STREAM_TYPE_MPEG2_TS); if (is_TS) { LOG(VB_RECORD, LOG_INFO, LOC + "mpeg2ts"); m_stream_data->AddAVListener(this); m_stream_data->AddWritingListener(this); } else { LOG(VB_RECORD, LOG_INFO, LOC + "program stream (non mpeg2ts)"); m_stream_data->AddPSStreamListener(this); } m_stream_handler->AddListener(m_stream_data, false, true); StartEncoding(); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (is_TS && !m_input_pmt) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Recording will not commence until a PMT is set."); std::this_thread::sleep_for(std::chrono::milliseconds(5)); continue; } if (!m_stream_handler->Status(failed, failing)) { if (failed) { m_error = "Stream handler died unexpectedly."; LOG(VB_GENERAL, LOG_ERR, LOC + "run() -- " + m_error); } else if (failing) { SetRecordingStatus(RecStatus::Failing, __FILE__, __LINE__); } } } LOG(VB_RECORD, LOG_INFO, LOC + "Shutting down"); StopEncoding(); m_stream_handler->RemoveListener(m_stream_data); if (m_stream_handler->GetStreamType() == V4L2_MPEG_STREAM_TYPE_MPEG2_TS) { m_stream_data->RemoveWritingListener(this); m_stream_data->RemoveAVListener(this); } else m_stream_data->RemovePSStreamListener(this); Close(); FinishRecording(); QMutexLocker locker(&m_pauseLock); m_recording = false; m_recordingWait.wakeAll(); LOG(VB_RECORD, LOG_INFO, LOC + "run() -- end"); }
void V4LRecorder::RunVBIDevice(void) { if (vbi_fd < 0) return; unsigned char *buf = NULL, *ptr = NULL, *ptr_end = NULL; if (ntsc_vbi_width) { uint sz = ntsc_vbi_width * ntsc_vbi_line_count * 2; buf = ptr = new unsigned char[sz]; ptr_end = buf + sz; } while (IsHelperRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (!IsHelperRequested() || IsErrored()) break; struct timeval tv; fd_set rdset; tv.tv_sec = 0; tv.tv_usec = 5000; FD_ZERO(&rdset); FD_SET(vbi_fd, &rdset); int nr = select(vbi_fd + 1, &rdset, 0, 0, &tv); if (nr < 0) LOG(VB_GENERAL, LOG_ERR, LOC + "vbi select failed" + ENO); if (nr <= 0) { if (nr==0) LOG(VB_GENERAL, LOG_DEBUG, LOC + "vbi select timed out"); continue; // either failed or timed out.. } if (VBIMode::PAL_TT == vbimode) { pal_vbi_cb->foundteletextpage = false; vbi_handler(pal_vbi_tt, pal_vbi_tt->fd); if (pal_vbi_cb->foundteletextpage) { // decode VBI as teletext subtitles FormatTT(pal_vbi_cb); } } else if (VBIMode::NTSC_CC == vbimode) { int ret = read(vbi_fd, ptr, ptr_end - ptr); ptr = (ret > 0) ? ptr + ret : ptr; if ((ptr_end - ptr) == 0) { unsigned char *line21_field1 = buf + ((21 - ntsc_vbi_start_line) * ntsc_vbi_width); unsigned char *line21_field2 = buf + ((ntsc_vbi_line_count + 21 - ntsc_vbi_start_line) * ntsc_vbi_width); bool cc1 = vbi608->ExtractCC12(line21_field1, ntsc_vbi_width); bool cc2 = vbi608->ExtractCC34(line21_field2, ntsc_vbi_width); if (cc1 || cc2) { int code1 = vbi608->GetCode1(); int code2 = vbi608->GetCode2(); code1 = (0xFFFF==code1) ? -1 : code1; code2 = (0xFFFF==code2) ? -1 : code2; FormatCC(code1, code2); } ptr = buf; } else if (ret < 0) { LOG(VB_GENERAL, LOG_ERR, LOC + "Reading VBI data" + ENO); } } } if (buf) delete [] buf; }
void HDHRRecorder::run(void) { LOG(VB_RECORD, LOG_INFO, LOC + "run -- begin"); /* Create video socket. */ if (!Open()) { _error = "Failed to open HDHRRecorder device"; LOG(VB_GENERAL, LOG_ERR, LOC + _error); return; } { QMutexLocker locker(&pauseLock); request_recording = true; recording = true; recordingWait.wakeAll(); } StartNewFile(); _stream_data->AddAVListener(this); _stream_data->AddWritingListener(this); _stream_handler->AddListener(_stream_data); while (IsRecordingRequested() && !IsErrored()) { if (PauseAndWait()) continue; if (!IsRecordingRequested()) break; { // sleep 100 milliseconds unless StopRecording() or Unpause() // is called, just to avoid running this too often. QMutexLocker locker(&pauseLock); if (!request_recording || request_pause) continue; unpauseWait.wait(&pauseLock, 100); } if (!_input_pmt) { LOG(VB_GENERAL, LOG_WARNING, LOC + "Recording will not commence until a PMT is set."); usleep(5000); continue; } if (!_stream_handler->IsRunning()) { _error = "Stream handler died unexpectedly."; LOG(VB_GENERAL, LOG_ERR, LOC + _error); } } LOG(VB_RECORD, LOG_INFO, LOC + "run -- ending..."); _stream_handler->RemoveListener(_stream_data); _stream_data->RemoveWritingListener(this); _stream_data->RemoveAVListener(this); Close(); FinishRecording(); QMutexLocker locker(&pauseLock); recording = false; recordingWait.wakeAll(); LOG(VB_RECORD, LOG_INFO, LOC + "run -- end"); }