|
MythTV master
|
Buffers reads from device files. More...
#include <libmythtv/recorders/DeviceReadBuffer.h>
Public Member Functions | |
| DeviceReadBuffer (DeviceReaderCB *cb, bool use_poll=true, bool error_exit_on_poll_timeout=true) | |
| ~DeviceReadBuffer () override | |
| bool | Setup (const QString &streamName, int streamfd, uint readQuanta=sizeof(TSPacket), uint deviceBufferSize=0, uint deviceBufferCount=1) |
| void | Start (void) |
| void | Reset (const QString &streamName, int streamfd) |
| void | Stop (void) |
| void | SetRequestPause (bool request) |
| bool | IsPaused (void) const |
| bool | WaitForUnpause (unsigned long timeout) |
| bool | WaitForPaused (unsigned long timeout) |
| bool | IsErrored (void) const |
| bool | IsEOF (void) const |
| bool | IsRunning (void) const |
| uint | Read (unsigned char *buf, uint count) |
| Try to Read count bytes from into buffer. More... | |
| uint | GetUsed (void) const |
Private Types | |
| using | pipe_fd_array = std::array< int, 2 > |
| using | pipe_flag_array = std::array< long, 2 > |
Private Member Functions | |
| void | run (void) override |
| Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead. More... | |
| void | SetPaused (bool val) |
| void | IncrWritePointer (uint len) |
| void | IncrReadPointer (uint len) |
| bool | HandlePausing (void) |
| bool | Poll (void) const |
| void | WakePoll (void) const |
| uint | WaitForUnused (uint needed) const |
| uint | WaitForUsed (uint needed, std::chrono::milliseconds max_wait) const |
| bool | IsPauseRequested (void) const |
| bool | IsOpen (void) const |
| void | ClosePipes (void) const |
| uint | GetUnused (void) const |
| uint | GetContiguousUnused (void) const |
| bool | CheckForErrors (ssize_t read_len, size_t requested_len, uint &errcnt) |
| void | ReportStats (void) |
Static Private Member Functions | |
| static void | setup_pipe (pipe_fd_array &mypipe, pipe_flag_array &myflags) |
Private Attributes | |
| QString | m_videoDevice |
| int | m_streamFd {-1} |
| pipe_fd_array | m_wakePipe {-1,-1} |
| pipe_flag_array | m_wakePipeFlags {0,0} |
| DeviceReaderCB * | m_readerCB {nullptr} |
| QMutex | m_lock |
| volatile bool | m_doRun {false} |
| bool | m_eof {false} |
| bool | m_error {false} |
| bool | m_requestPause {false} |
| bool | m_paused {false} |
| bool | m_usingPoll {true} |
| bool | m_pollTimeoutIsError {true} |
| std::chrono::milliseconds | m_maxPollWait {2500ms} |
| size_t | m_size {0} |
| size_t | m_used {0} |
| size_t | m_readQuanta {0} |
| size_t | m_devBufferCount {1} |
| size_t | m_devReadSize {0} |
| size_t | m_readThreshold {0} |
| unsigned char * | m_buffer {nullptr} |
| unsigned char * | m_readPtr {nullptr} |
| unsigned char * | m_writePtr {nullptr} |
| unsigned char * | m_endPtr {nullptr} |
| QWaitCondition | m_dataWait |
| QWaitCondition | m_runWait |
| QWaitCondition | m_pauseWait |
| QWaitCondition | m_unpauseWait |
| size_t | m_maxUsed {0} |
| size_t | m_avgUsed {0} |
| size_t | m_avgBufWriteCnt {0} |
| size_t | m_avgBufReadCnt {0} |
| size_t | m_avgBufSleepCnt {0} |
| MythTimer | m_lastReport |
Additional Inherited Members | |
Protected Member Functions inherited from MThread | |
| virtual void | run (void) |
| Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead. More... | |
| int | exec (void) |
| Enters the qt event loop. call exit or quit to exit thread. More... | |
| MThread (const QString &objectName) | |
| Standard constructor. More... | |
| MThread (const QString &objectName, QRunnable *runnable) | |
| Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More... | |
| virtual | ~MThread () |
| MThread (const MThread &)=delete | |
| MThread & | operator= (const MThread &)=delete |
| void | RunProlog (void) |
| Sets up a thread, call this if you reimplement run(). More... | |
| void | RunEpilog (void) |
| Cleans up a thread's resources, call this if you reimplement run(). More... | |
| QThread * | qthread (void) |
| Returns the thread, this will always return the same pointer no matter how often you restart the thread. More... | |
| void | setObjectName (const QString &name) |
| QString | objectName (void) const |
| void | setPriority (QThread::Priority priority) |
| QThread::Priority | priority (void) const |
| bool | isFinished (void) const |
| bool | isRunning (void) const |
| void | setStackSize (uint stackSize) |
| uint | stackSize (void) const |
| void | exit (int retcode=0) |
| Use this to exit from the thread if you are using a Qt event loop. More... | |
| void | start (QThread::Priority p=QThread::InheritPriority) |
| Tell MThread to start running the thread in the near future. More... | |
| void | terminate (void) |
| Kill a thread unsafely. More... | |
| void | quit (void) |
| calls exit(0) More... | |
| bool | wait (std::chrono::milliseconds time=std::chrono::milliseconds::max()) |
| Wait for the MThread to exit, with a maximum timeout. More... | |
Static Protected Member Functions inherited from MThread | |
| static void | setTerminationEnabled (bool enabled=true) |
| static void | usleep (std::chrono::microseconds time) |
| template<typename R , typename P > | |
| static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > | usleep (std::chrono::duration< R, P > time) |
| static void | ThreadSetup (const QString &name) |
| This is to be called on startup in those few threads that haven't been ported to MThread. More... | |
| static void | ThreadCleanup (void) |
| This is to be called on exit in those few threads that haven't been ported to MThread. More... | |
| static void | Cleanup (void) |
| This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More... | |
| static void | GetAllThreadNames (QStringList &list) |
| static void | GetAllRunningThreadNames (QStringList &list) |
Protected Attributes inherited from MThread | |
| MThreadInternal * | m_thread {nullptr} |
| QRunnable * | m_runnable {nullptr} |
| bool | m_prologExecuted {true} |
| bool | m_epilogExecuted {true} |
Buffers reads from device files.
This allows us to read the device regularly even in the presence of long blocking conditions on writing to disk or accessing the database.
Definition at line 35 of file DeviceReadBuffer.h.
|
private |
Definition at line 87 of file DeviceReadBuffer.h.
|
private |
Definition at line 88 of file DeviceReadBuffer.h.
|
explicit |
Definition at line 64 of file DeviceReadBuffer.cpp.
|
override |
Definition at line 82 of file DeviceReadBuffer.cpp.
|
private |
Definition at line 578 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 240 of file DeviceReadBuffer.cpp.
Referenced by run(), and WakePoll().
|
private |
Definition at line 315 of file DeviceReadBuffer.cpp.
|
private |
Definition at line 303 of file DeviceReadBuffer.cpp.
Referenced by WaitForUnused().
| uint DeviceReadBuffer::GetUsed | ( | void | ) | const |
Definition at line 309 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::AvailCount().
|
private |
Definition at line 432 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 335 of file DeviceReadBuffer.cpp.
Referenced by Read().
|
private |
Definition at line 321 of file DeviceReadBuffer.cpp.
Referenced by run().
| bool DeviceReadBuffer::IsEOF | ( | void | ) | const |
Definition at line 291 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
| bool DeviceReadBuffer::IsErrored | ( | void | ) | const |
Definition at line 285 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
|
inlineprivate |
Definition at line 79 of file DeviceReadBuffer.h.
Referenced by Poll(), run(), and WaitForUnused().
| bool DeviceReadBuffer::IsPaused | ( | void | ) | const |
Definition at line 253 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing().
|
private |
Definition at line 279 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing(), Poll(), and WaitForUnused().
| bool DeviceReadBuffer::IsRunning | ( | void | ) | const |
Definition at line 297 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), MpegRecorder::StopEncoding(), V4L2encStreamHandler::StopEncoding(), and MpegRecorder::TeardownAll().
|
private |
Definition at line 452 of file DeviceReadBuffer.cpp.
Referenced by run().
Try to Read count bytes from into buffer.
| buf | Buffer to put data in |
| count | Number of bytes to attempt to read |
Definition at line 659 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
|
private |
Definition at line 744 of file DeviceReadBuffer.cpp.
Referenced by Read().
| void DeviceReadBuffer::Reset | ( | const QString & | streamName, |
| int | streamfd | ||
| ) |
Definition at line 177 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing(), and MpegRecorder::StartEncoding().
|
overrideprivatevirtual |
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Reimplemented from MThread.
Definition at line 346 of file DeviceReadBuffer.cpp.
|
private |
Definition at line 213 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing().
| void DeviceReadBuffer::SetRequestPause | ( | bool | request | ) |
Definition at line 206 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), MpegRecorder::StartEncoding(), V4L2encStreamHandler::StartEncoding(), MpegRecorder::StopEncoding(), and V4L2encStreamHandler::StopEncoding().
| bool DeviceReadBuffer::Setup | ( | const QString & | streamName, |
| int | streamfd, | ||
| uint | readQuanta = sizeof(TSPacket), |
||
| uint | deviceBufferSize = 0, |
||
| uint | deviceBufferCount = 1 |
||
| ) |
Definition at line 92 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), and DVBStreamHandler::RunTS().
|
staticprivate |
Definition at line 22 of file DeviceReadBuffer.cpp.
Referenced by run().
| void DeviceReadBuffer::Start | ( | void | ) |
Definition at line 149 of file DeviceReadBuffer.cpp.
Referenced by DVBStreamHandler::RunTS(), MpegRecorder::StartEncoding(), and V4L2encStreamHandler::StartEncoding().
| void DeviceReadBuffer::Stop | ( | void | ) |
Definition at line 192 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Close(), V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), ASIStreamHandler::run(), ASIStreamHandler::SetRunningDesired(), MpegRecorder::StopEncoding(), MpegRecorder::TeardownAll(), and ~DeviceReadBuffer().
| bool DeviceReadBuffer::WaitForPaused | ( | unsigned long | timeout | ) |
Definition at line 259 of file DeviceReadBuffer.cpp.
| bool DeviceReadBuffer::WaitForUnpause | ( | unsigned long | timeout | ) |
Definition at line 269 of file DeviceReadBuffer.cpp.
| needed | Number of bytes we want to write |
Definition at line 701 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
| needed | Number of bytes we want to read |
| max_wait | Number of milliseconds to wait for the needed data |
Definition at line 727 of file DeviceReadBuffer.cpp.
Referenced by Read().
|
private |
Definition at line 224 of file DeviceReadBuffer.cpp.
Referenced by SetRequestPause(), Start(), and Stop().
|
private |
Definition at line 129 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), ReportStats(), and Setup().
|
private |
Definition at line 130 of file DeviceReadBuffer.h.
Referenced by ReportStats(), and Setup().
|
private |
Definition at line 128 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
|
private |
Definition at line 127 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
|
private |
Definition at line 115 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), IncrWritePointer(), Reset(), run(), Setup(), and ~DeviceReadBuffer().
|
mutableprivate |
Definition at line 120 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), run(), and WaitForUsed().
|
private |
Definition at line 112 of file DeviceReadBuffer.h.
|
private |
Definition at line 113 of file DeviceReadBuffer.h.
Definition at line 100 of file DeviceReadBuffer.h.
Referenced by Poll(), run(), Start(), Stop(), and WaitForUnused().
|
private |
Definition at line 118 of file DeviceReadBuffer.h.
Referenced by GetContiguousUnused(), IncrReadPointer(), IncrWritePointer(), Read(), run(), and Setup().
Definition at line 101 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), IsEOF(), run(), Setup(), Start(), and WaitForUsed().
Definition at line 102 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), IsErrored(), Poll(), Reset(), run(), Setup(), Start(), and WaitForUsed().
|
private |
Definition at line 131 of file DeviceReadBuffer.h.
Referenced by ReportStats(), and Setup().
|
mutableprivate |
Definition at line 99 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), GetContiguousUnused(), GetUnused(), GetUsed(), IncrReadPointer(), IncrWritePointer(), IsEOF(), IsErrored(), IsPaused(), IsPauseRequested(), IsRunning(), Poll(), ReportStats(), Reset(), run(), SetPaused(), SetRequestPause(), Setup(), Start(), Stop(), WaitForPaused(), WaitForUnpause(), and WaitForUsed().
|
private |
Definition at line 107 of file DeviceReadBuffer.h.
Referenced by Poll().
|
private |
Definition at line 126 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
Definition at line 104 of file DeviceReadBuffer.h.
Referenced by IsPaused(), SetPaused(), Setup(), WaitForPaused(), and WaitForUnpause().
|
private |
Definition at line 122 of file DeviceReadBuffer.h.
Referenced by run(), SetPaused(), and WaitForPaused().
Definition at line 106 of file DeviceReadBuffer.h.
Referenced by Poll().
|
private |
Definition at line 96 of file DeviceReadBuffer.h.
Referenced by HandlePausing(), and Poll().
|
private |
Definition at line 116 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), Read(), Reset(), and Setup().
|
private |
Definition at line 111 of file DeviceReadBuffer.h.
Referenced by run(), Setup(), and WaitForUnused().
|
private |
Definition at line 114 of file DeviceReadBuffer.h.
Definition at line 103 of file DeviceReadBuffer.h.
Referenced by IsPauseRequested(), SetRequestPause(), Setup(), and WaitForUsed().
|
private |
Definition at line 121 of file DeviceReadBuffer.h.
|
private |
Definition at line 109 of file DeviceReadBuffer.h.
Referenced by GetUnused(), ReportStats(), and Setup().
|
private |
Definition at line 92 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), HandlePausing(), IsOpen(), Poll(), Reset(), run(), and Setup().
|
private |
Definition at line 123 of file DeviceReadBuffer.h.
Referenced by run(), SetPaused(), and WaitForUnpause().
|
private |
Definition at line 110 of file DeviceReadBuffer.h.
Referenced by GetUnused(), GetUsed(), IncrReadPointer(), IncrWritePointer(), Reset(), Setup(), and WaitForUsed().
Definition at line 105 of file DeviceReadBuffer.h.
Referenced by DeviceReadBuffer(), run(), and Setup().
|
private |
Definition at line 91 of file DeviceReadBuffer.h.
Referenced by HandlePausing(), Reset(), and Setup().
|
mutableprivate |
Definition at line 93 of file DeviceReadBuffer.h.
Referenced by ClosePipes(), Poll(), run(), and WakePoll().
|
mutableprivate |
Definition at line 94 of file DeviceReadBuffer.h.
Referenced by ClosePipes(), Poll(), and run().
|
private |
Definition at line 117 of file DeviceReadBuffer.h.
Referenced by GetContiguousUnused(), IncrWritePointer(), Reset(), run(), and Setup().