MythTV
master
|
Buffers reads from device files. More...
#include <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 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) |
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 | |
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.
|
explicit |
Definition at line 21 of file DeviceReadBuffer.cpp.
|
override |
Definition at line 39 of file DeviceReadBuffer.cpp.
bool DeviceReadBuffer::Setup | ( | const QString & | streamName, |
int | streamfd, | ||
uint | readQuanta = sizeof(TSPacket) , |
||
uint | deviceBufferSize = 0 , |
||
uint | deviceBufferCount = 1 |
||
) |
Definition at line 49 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), and DVBStreamHandler::RunTS().
void DeviceReadBuffer::Start | ( | void | ) |
Definition at line 106 of file DeviceReadBuffer.cpp.
Referenced by DVBStreamHandler::RunTS(), V4L2encStreamHandler::StartEncoding(), and MpegRecorder::StartEncoding().
void DeviceReadBuffer::Reset | ( | const QString & | streamName, |
int | streamfd | ||
) |
Definition at line 134 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing(), and MpegRecorder::StartEncoding().
void DeviceReadBuffer::Stop | ( | void | ) |
Definition at line 149 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Close(), V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), ASIStreamHandler::run(), ASIStreamHandler::SetRunningDesired(), MpegRecorder::StopEncoding(), MpegRecorder::TeardownAll(), and ~DeviceReadBuffer().
void DeviceReadBuffer::SetRequestPause | ( | bool | request | ) |
Definition at line 163 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), V4L2encStreamHandler::StartEncoding(), MpegRecorder::StartEncoding(), V4L2encStreamHandler::StopEncoding(), and MpegRecorder::StopEncoding().
bool DeviceReadBuffer::IsPaused | ( | void | ) | const |
Definition at line 210 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing().
bool DeviceReadBuffer::WaitForUnpause | ( | unsigned long | timeout | ) |
Definition at line 226 of file DeviceReadBuffer.cpp.
bool DeviceReadBuffer::WaitForPaused | ( | unsigned long | timeout | ) |
Definition at line 216 of file DeviceReadBuffer.cpp.
bool DeviceReadBuffer::IsErrored | ( | void | ) | const |
Definition at line 242 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
bool DeviceReadBuffer::IsEOF | ( | void | ) | const |
Definition at line 248 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
bool DeviceReadBuffer::IsRunning | ( | void | ) | const |
Definition at line 254 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::Open(), MpegRecorder::OpenV4L2DeviceAsInput(), V4L2encStreamHandler::StopEncoding(), MpegRecorder::StopEncoding(), and MpegRecorder::TeardownAll().
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 616 of file DeviceReadBuffer.cpp.
Referenced by MpegRecorder::run(), V4L2encStreamHandler::run(), and DVBStreamHandler::RunTS().
uint DeviceReadBuffer::GetUsed | ( | void | ) | const |
Definition at line 266 of file DeviceReadBuffer.cpp.
Referenced by V4L2encStreamHandler::AvailCount().
|
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 303 of file DeviceReadBuffer.cpp.
|
private |
Definition at line 170 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing().
|
private |
Definition at line 278 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 292 of file DeviceReadBuffer.cpp.
Referenced by Read().
|
private |
Definition at line 389 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 409 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 181 of file DeviceReadBuffer.cpp.
Referenced by SetRequestPause(), Start(), and Stop().
needed | Number of bytes we want to write |
Definition at line 658 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 684 of file DeviceReadBuffer.cpp.
Referenced by Read().
|
private |
Definition at line 236 of file DeviceReadBuffer.cpp.
Referenced by HandlePausing(), Poll(), and WaitForUnused().
|
inlineprivate |
Definition at line 79 of file DeviceReadBuffer.h.
Referenced by Poll(), run(), and WaitForUnused().
|
private |
Definition at line 197 of file DeviceReadBuffer.cpp.
Referenced by run(), and WakePoll().
|
private |
Definition at line 260 of file DeviceReadBuffer.cpp.
Referenced by WaitForUnused().
|
private |
Definition at line 272 of file DeviceReadBuffer.cpp.
|
private |
Definition at line 535 of file DeviceReadBuffer.cpp.
Referenced by run().
|
private |
Definition at line 701 of file DeviceReadBuffer.cpp.
Referenced by Read().
|
private |
Definition at line 87 of file DeviceReadBuffer.h.
Referenced by HandlePausing(), Reset(), and Setup().
|
private |
Definition at line 88 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), HandlePausing(), IsOpen(), Poll(), Reset(), run(), and Setup().
|
mutableprivate |
Definition at line 89 of file DeviceReadBuffer.h.
Referenced by ClosePipes(), Poll(), run(), and WakePoll().
|
mutableprivate |
Definition at line 90 of file DeviceReadBuffer.h.
Referenced by ClosePipes(), Poll(), and run().
|
private |
Definition at line 92 of file DeviceReadBuffer.h.
Referenced by HandlePausing(), and Poll().
|
mutableprivate |
Definition at line 95 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().
Definition at line 96 of file DeviceReadBuffer.h.
Referenced by Poll(), run(), Start(), Stop(), and WaitForUnused().
Definition at line 97 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), IsEOF(), run(), Setup(), Start(), and WaitForUsed().
Definition at line 98 of file DeviceReadBuffer.h.
Referenced by CheckForErrors(), IsErrored(), Poll(), Reset(), run(), Setup(), Start(), and WaitForUsed().
Definition at line 99 of file DeviceReadBuffer.h.
Referenced by IsPauseRequested(), SetRequestPause(), Setup(), and WaitForUsed().
Definition at line 100 of file DeviceReadBuffer.h.
Referenced by IsPaused(), SetPaused(), Setup(), WaitForPaused(), and WaitForUnpause().
Definition at line 101 of file DeviceReadBuffer.h.
Referenced by DeviceReadBuffer(), run(), and Setup().
Definition at line 102 of file DeviceReadBuffer.h.
Referenced by Poll().
|
private |
Definition at line 103 of file DeviceReadBuffer.h.
Referenced by Poll().
|
private |
Definition at line 105 of file DeviceReadBuffer.h.
Referenced by GetUnused(), ReportStats(), and Setup().
|
private |
Definition at line 106 of file DeviceReadBuffer.h.
Referenced by GetUnused(), GetUsed(), IncrReadPointer(), IncrWritePointer(), Reset(), Setup(), and WaitForUsed().
|
private |
Definition at line 107 of file DeviceReadBuffer.h.
Referenced by run(), Setup(), and WaitForUnused().
|
private |
Definition at line 108 of file DeviceReadBuffer.h.
|
private |
Definition at line 109 of file DeviceReadBuffer.h.
|
private |
Definition at line 110 of file DeviceReadBuffer.h.
|
private |
Definition at line 111 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), IncrWritePointer(), Reset(), run(), Setup(), and ~DeviceReadBuffer().
|
private |
Definition at line 112 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), Read(), Reset(), and Setup().
|
private |
Definition at line 113 of file DeviceReadBuffer.h.
Referenced by GetContiguousUnused(), IncrWritePointer(), Reset(), run(), and Setup().
|
private |
Definition at line 114 of file DeviceReadBuffer.h.
Referenced by GetContiguousUnused(), IncrReadPointer(), IncrWritePointer(), Read(), run(), and Setup().
|
mutableprivate |
Definition at line 116 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), run(), and WaitForUsed().
|
private |
Definition at line 117 of file DeviceReadBuffer.h.
|
private |
Definition at line 118 of file DeviceReadBuffer.h.
Referenced by run(), SetPaused(), and WaitForPaused().
|
private |
Definition at line 119 of file DeviceReadBuffer.h.
Referenced by run(), SetPaused(), and WaitForUnpause().
|
private |
Definition at line 122 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
|
private |
Definition at line 123 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
|
private |
Definition at line 124 of file DeviceReadBuffer.h.
Referenced by IncrWritePointer(), ReportStats(), and Setup().
|
private |
Definition at line 125 of file DeviceReadBuffer.h.
Referenced by IncrReadPointer(), ReportStats(), and Setup().
|
private |
Definition at line 126 of file DeviceReadBuffer.h.
Referenced by ReportStats(), and Setup().
|
private |
Definition at line 127 of file DeviceReadBuffer.h.
Referenced by ReportStats(), and Setup().