DeviceReadBuffer Class Reference

Buffers reads from device files. More...

#include <DeviceReadBuffer.h>

Inheritance diagram for DeviceReadBuffer:
MThread

List of all members.

Public Member Functions

 DeviceReadBuffer (DeviceReaderCB *callback, bool use_poll=true, bool error_exit_on_poll_timeout=true)
 ~DeviceReadBuffer ()
bool Setup (const QString &streamName, int streamfd, uint readQuanta=sizeof(TSPacket), uint deviceBufferSize=0)
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.

Private Member Functions

virtual void run (void)
 Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
void SetPaused (bool)
void IncrWritePointer (uint len)
void IncrReadPointer (uint len)
bool HandlePausing (void)
bool Poll (void) const
void WakePoll (void) const
uint WaitForUnused (uint bytes_needed) const
uint WaitForUsed (uint bytes_needed, uint max_wait) const
bool IsPauseRequested (void) const
bool IsOpen (void) const
void ClosePipes (void) const
uint GetUnused (void) const
uint GetUsed (void) const
uint GetContiguousUnused (void) const
bool CheckForErrors (ssize_t read_len, size_t requested_len, uint &err_cnt)
void ReportStats (void)

Private Attributes

QString videodevice
int _stream_fd
int wake_pipe [2]
long wake_pipe_flags [2]
DeviceReaderCBreaderCB
QMutex lock
volatile bool dorun
bool eof
bool error
bool request_pause
bool paused
bool using_poll
bool poll_timeout_is_error
uint max_poll_wait
size_t size
size_t used
size_t read_quanta
size_t dev_read_size
size_t min_read
unsigned char * buffer
unsigned char * readPtr
unsigned char * writePtr
unsigned char * endPtr
QWaitCondition dataWait
QWaitCondition runWait
QWaitCondition pauseWait
QWaitCondition unpauseWait
size_t max_used
size_t avg_used
size_t avg_cnt
MythTimer lastReport

Detailed Description

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 33 of file DeviceReadBuffer.h.


Constructor & Destructor Documentation

DeviceReadBuffer::DeviceReadBuffer ( DeviceReaderCB callback,
bool  use_poll = true,
bool  error_exit_on_poll_timeout = true 
)

Definition at line 21 of file DeviceReadBuffer.cpp.

DeviceReadBuffer::~DeviceReadBuffer (  ) 

Definition at line 63 of file DeviceReadBuffer.cpp.


Member Function Documentation

bool DeviceReadBuffer::Setup ( const QString &  streamName,
int  streamfd,
uint  readQuanta = sizeof(TSPacket),
uint  deviceBufferSize = 0 
)
void DeviceReadBuffer::Start ( void   ) 
void DeviceReadBuffer::Reset ( const QString &  streamName,
int  streamfd 
)

Definition at line 154 of file DeviceReadBuffer.cpp.

Referenced by HandlePausing(), and MpegRecorder::StartEncoding().

void DeviceReadBuffer::Stop ( void   ) 
void DeviceReadBuffer::SetRequestPause ( bool  request  ) 

Definition at line 183 of file DeviceReadBuffer.cpp.

bool DeviceReadBuffer::IsPaused ( void   )  const

Definition at line 231 of file DeviceReadBuffer.cpp.

Referenced by HandlePausing().

bool DeviceReadBuffer::WaitForUnpause ( unsigned long  timeout  ) 

Definition at line 247 of file DeviceReadBuffer.cpp.

bool DeviceReadBuffer::WaitForPaused ( unsigned long  timeout  ) 

Definition at line 237 of file DeviceReadBuffer.cpp.

bool DeviceReadBuffer::IsErrored ( void   )  const
bool DeviceReadBuffer::IsEOF ( void   )  const
bool DeviceReadBuffer::IsRunning ( void   )  const
uint DeviceReadBuffer::Read ( unsigned char *  buf,
uint  count 
)

Try to Read count bytes from into buffer.

Parameters:
buf Buffer to put data in
count Number of bytes to attempt to read
Returns:
number of bytes actually read

Definition at line 613 of file DeviceReadBuffer.cpp.

Referenced by MpegRecorder::run(), ASIStreamHandler::run(), and DVBStreamHandler::RunTS().

void DeviceReadBuffer::run ( void   )  [private, virtual]

Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.

Note:
If you override this method you must call RunProlog before you do any work and RunEpilog before you exit the run method.

Reimplemented from MThread.

Definition at line 320 of file DeviceReadBuffer.cpp.

void DeviceReadBuffer::SetPaused ( bool  val  )  [private]

Definition at line 190 of file DeviceReadBuffer.cpp.

Referenced by HandlePausing().

void DeviceReadBuffer::IncrWritePointer ( uint  len  )  [private]

Definition at line 299 of file DeviceReadBuffer.cpp.

Referenced by run().

void DeviceReadBuffer::IncrReadPointer ( uint  len  )  [private]

Definition at line 312 of file DeviceReadBuffer.cpp.

Referenced by Read().

bool DeviceReadBuffer::HandlePausing ( void   )  [private]

Definition at line 392 of file DeviceReadBuffer.cpp.

Referenced by run().

bool DeviceReadBuffer::Poll ( void   )  const [private]

Definition at line 412 of file DeviceReadBuffer.cpp.

Referenced by run().

void DeviceReadBuffer::WakePoll ( void   )  const [private]

Definition at line 201 of file DeviceReadBuffer.cpp.

Referenced by SetRequestPause(), Start(), and Stop().

uint DeviceReadBuffer::WaitForUnused ( uint  bytes_needed  )  const [private]
Parameters:
needed Number of bytes we want to write
Returns:
bytes available for writing

Definition at line 655 of file DeviceReadBuffer.cpp.

Referenced by run().

uint DeviceReadBuffer::WaitForUsed ( uint  bytes_needed,
uint  max_wait 
) const [private]
Parameters:
needed Number of bytes we want to read
max_wait Number of milliseconds to wait for the needed data
Returns:
bytes available for reading

Definition at line 681 of file DeviceReadBuffer.cpp.

Referenced by Read().

bool DeviceReadBuffer::IsPauseRequested ( void   )  const [private]

Definition at line 257 of file DeviceReadBuffer.cpp.

Referenced by HandlePausing(), Poll(), and WaitForUnused().

bool DeviceReadBuffer::IsOpen ( void   )  const [inline, private]

Definition at line 75 of file DeviceReadBuffer.h.

Referenced by Poll(), run(), and WaitForUnused().

void DeviceReadBuffer::ClosePipes ( void   )  const [private]

Definition at line 218 of file DeviceReadBuffer.cpp.

Referenced by run(), and WakePoll().

uint DeviceReadBuffer::GetUnused ( void   )  const [private]

Definition at line 281 of file DeviceReadBuffer.cpp.

Referenced by WaitForUnused().

uint DeviceReadBuffer::GetUsed ( void   )  const [private]

Definition at line 287 of file DeviceReadBuffer.cpp.

uint DeviceReadBuffer::GetContiguousUnused ( void   )  const [private]

Definition at line 293 of file DeviceReadBuffer.cpp.

bool DeviceReadBuffer::CheckForErrors ( ssize_t  read_len,
size_t  requested_len,
uint err_cnt 
) [private]

Definition at line 532 of file DeviceReadBuffer.cpp.

Referenced by run().

void DeviceReadBuffer::ReportStats ( void   )  [private]

Definition at line 698 of file DeviceReadBuffer.cpp.

Referenced by Read().


Member Data Documentation

QString DeviceReadBuffer::videodevice [private]

Definition at line 84 of file DeviceReadBuffer.h.

Referenced by HandlePausing(), Reset(), and Setup().

Definition at line 85 of file DeviceReadBuffer.h.

Referenced by CheckForErrors(), HandlePausing(), IsOpen(), Poll(), Reset(), run(), and Setup().

int DeviceReadBuffer::wake_pipe[2] [mutable, private]

Definition at line 86 of file DeviceReadBuffer.h.

Referenced by ClosePipes(), DeviceReadBuffer(), Poll(), run(), and WakePoll().

long DeviceReadBuffer::wake_pipe_flags[2] [mutable, private]

Definition at line 87 of file DeviceReadBuffer.h.

Referenced by ClosePipes(), DeviceReadBuffer(), Poll(), and run().

Definition at line 89 of file DeviceReadBuffer.h.

Referenced by HandlePausing(), and Poll().

QMutex DeviceReadBuffer::lock [mutable, private]
volatile bool DeviceReadBuffer::dorun [private]

Definition at line 93 of file DeviceReadBuffer.h.

Referenced by Poll(), run(), Start(), Stop(), and WaitForUnused().

Definition at line 94 of file DeviceReadBuffer.h.

Referenced by CheckForErrors(), IsEOF(), run(), Setup(), Start(), and WaitForUsed().

bool DeviceReadBuffer::error [mutable, private]

Definition at line 95 of file DeviceReadBuffer.h.

Referenced by CheckForErrors(), IsErrored(), Poll(), Reset(), run(), Setup(), Start(), and WaitForUsed().

Definition at line 96 of file DeviceReadBuffer.h.

Referenced by IsPauseRequested(), SetRequestPause(), Setup(), and WaitForUsed().

Definition at line 97 of file DeviceReadBuffer.h.

Referenced by IsPaused(), SetPaused(), Setup(), WaitForPaused(), and WaitForUnpause().

Definition at line 98 of file DeviceReadBuffer.h.

Referenced by DeviceReadBuffer(), run(), and Setup().

Definition at line 99 of file DeviceReadBuffer.h.

Referenced by Poll().

Definition at line 100 of file DeviceReadBuffer.h.

Referenced by Poll().

size_t DeviceReadBuffer::size [private]

Definition at line 102 of file DeviceReadBuffer.h.

Referenced by GetUnused(), ReportStats(), and Setup().

size_t DeviceReadBuffer::used [private]

Definition at line 104 of file DeviceReadBuffer.h.

Referenced by run(), Setup(), and WaitForUnused().

Definition at line 105 of file DeviceReadBuffer.h.

Referenced by run(), and Setup().

size_t DeviceReadBuffer::min_read [private]

Definition at line 106 of file DeviceReadBuffer.h.

Referenced by Read(), and Setup().

unsigned char* DeviceReadBuffer::buffer [private]
unsigned char* DeviceReadBuffer::readPtr [private]

Definition at line 108 of file DeviceReadBuffer.h.

Referenced by IncrReadPointer(), Read(), Reset(), and Setup().

unsigned char* DeviceReadBuffer::writePtr [private]

Definition at line 109 of file DeviceReadBuffer.h.

Referenced by GetContiguousUnused(), IncrWritePointer(), Reset(), run(), and Setup().

unsigned char* DeviceReadBuffer::endPtr [private]
QWaitCondition DeviceReadBuffer::dataWait [mutable, private]

Definition at line 112 of file DeviceReadBuffer.h.

Referenced by IncrWritePointer(), run(), and WaitForUsed().

QWaitCondition DeviceReadBuffer::runWait [private]

Definition at line 113 of file DeviceReadBuffer.h.

Referenced by run(), and Start().

QWaitCondition DeviceReadBuffer::pauseWait [private]

Definition at line 114 of file DeviceReadBuffer.h.

Referenced by run(), SetPaused(), and WaitForPaused().

QWaitCondition DeviceReadBuffer::unpauseWait [private]

Definition at line 115 of file DeviceReadBuffer.h.

Referenced by run(), SetPaused(), and WaitForUnpause().

size_t DeviceReadBuffer::max_used [private]

Definition at line 118 of file DeviceReadBuffer.h.

Referenced by IncrWritePointer(), ReportStats(), and Setup().

size_t DeviceReadBuffer::avg_used [private]

Definition at line 119 of file DeviceReadBuffer.h.

Referenced by IncrWritePointer(), ReportStats(), and Setup().

size_t DeviceReadBuffer::avg_cnt [private]

Definition at line 120 of file DeviceReadBuffer.h.

Referenced by IncrWritePointer(), ReportStats(), and Setup().

Definition at line 121 of file DeviceReadBuffer.h.

Referenced by ReportStats(), and Setup().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Thu May 24 06:41:57 2012 for MythTV by  doxygen 1.6.3