MythTV  master
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
StreamingRingBuffer Class Reference

#include <streamingringbuffer.h>

Inheritance diagram for StreamingRingBuffer:
Inheritance graph
[legend]
Collaboration diagram for StreamingRingBuffer:
Collaboration graph
[legend]

Public Member Functions

 StreamingRingBuffer (const QString &lfilename)
 
 ~StreamingRingBuffer () override
 
bool IsOpen (void) const override
 Returns true if open for either reading or writing. More...
 
long long GetReadPosition (void) const override
 Returns how far into the file we have read. More...
 
bool OpenFile (const QString &lfilename, uint retry_ms=kDefaultOpenTimeout) override
 Opens a network stream for reading. More...
 
bool IsStreamed (void) override
 
bool IsSeekingAllowed (void) override
 
bool IsBookmarkAllowed (void) override
 
- Public Member Functions inherited from RingBuffer
 ~RingBuffer () override=0
 Deletes. More...
 
void SetWriteBufferSize (int newSize)
 
void SetWriteBufferMinWriteSize (int newMinSize)
 Calls ThreadedFileWriter::SetWriteBufferMinWriteSize(int) More...
 
void SetOldFile (bool is_old)
 Tell RingBuffer if this is an old file or not. More...
 
void UpdateRawBitrate (uint raw_bitrate)
 Set the raw bit rate, to allow RingBuffer adjust effective bitrate. More...
 
void UpdatePlaySpeed (float play_speed)
 Set the play speed, to allow RingBuffer adjust effective bitrate. More...
 
void EnableBitrateMonitor (bool enable)
 
void SetBufferSizeFactors (bool estbitrate, bool matroska)
 Tells RingBuffer that the raw bitrate may be innacurate and the underlying container is matroska, both of which may require a larger buffer size. More...
 
void SetWaitForWrite (void)
 
QString GetSafeFilename (void)
 
QString GetFilename (void) const
 Returns name of file used by this RingBuffer. More...
 
QString GetSubtitleFilename (void) const
 
QString GetLastError (void) const
 
bool GetCommsError (void) const
 
void ResetCommsError (void)
 
bool GetStopReads (void) const
 Returns value of stopreads. More...
 
bool isPaused (void) const
 Returns false iff read-ahead is not running and read-ahead is not paused. More...
 
QString GetDecoderRate (void)
 
QString GetStorageRate (void)
 
QString GetAvailableBuffer (void)
 
uint GetBufferSize (void)
 
long long GetWritePosition (void) const
 Returns how far into a ThreadedFileWriter file we have written. More...
 
long long GetRealFileSize (void) const
 Returns the size of the file we are reading/writing, or -1 if the query fails. More...
 
bool IsNearEnd (double fps, uint vvf) const
 
virtual int BestBufferSize (void)
 
RingBufferType GetType () const
 
int GetReadBufAvail () const
 Returns number of bytes available for reading from buffer. More...
 
bool SetReadInternalMode (bool mode)
 
bool IsReadInternalMode (void)
 
bool IsDisc (void) const
 
bool IsDVD (void) const
 
bool IsBD (void) const
 
const DVDRingBufferDVD (void) const
 
const BDRingBufferBD (void) const
 
DVDRingBufferDVD (void)
 
BDRingBufferBD (void)
 
virtual bool StartFromBeginning (void)
 
virtual void IgnoreWaitStates (bool)
 
virtual bool IsInMenu (void) const
 
virtual bool IsInStillFrame (void) const
 
virtual bool IsInDiscMenuOrStillFrame (void) const
 
virtual bool HandleAction (const QStringList &, int64_t)
 
virtual bool ReOpen (const QString &="")
 
int Read (void *buf, int count)
 This is the public method for reading from a file, it calls the appropriate read method if the file is remote or buffered, or a BD/DVD. More...
 
int Peek (void *buf, int count)
 
void Reset (bool full=false, bool toAdjust=false, bool resetInternal=false)
 Resets the read-ahead thread and our position in the file. More...
 
long long Seek (long long pos, int whence, bool has_lock=false)
 Seeks to a particular position in the file. More...
 
void Pause (void)
 Pauses the read-ahead thread. More...
 
void Unpause (void)
 Unpauses the read-ahead thread. More...
 
void WaitForPause (void)
 Waits for Pause(void) to take effect. More...
 
void Start (void)
 Starts the read-ahead thread. More...
 
void StopReads (void)
 ???? More...
 
void StartReads (void)
 ???? More...
 
bool LiveMode (void) const
 Returns true if this RingBuffer has been assigned a LiveTVChain. More...
 
void SetLiveMode (LiveTVChain *chain)
 Assigns a LiveTVChain to this RingBuffer. More...
 
void IgnoreLiveEOF (bool ignore)
 Tells RingBuffer whether to ignore the end-of-file. More...
 
int Write (const void *buf, uint count)
 Writes buffer to ThreadedFileWriter::Write(const void*,uint) More...
 
bool IsIOBound (void) const
 
void WriterFlush (void)
 Calls ThreadedFileWriter::Flush(void) More...
 
void Sync (void)
 Calls ThreadedFileWriter::Sync(void) More...
 
long long WriterSeek (long long pos, int whence, bool has_lock=false)
 Calls ThreadedFileWriter::Seek(long long,int). More...
 
bool WriterSetBlocking (bool lock=true)
 Calls ThreadedFileWriter::SetBlocking(bool) More...
 
long long SetAdjustFilesize (void)
 

Protected Member Functions

int safe_read (void *data, uint sz) override
 
long long GetRealFileSizeInternal (void) const override
 
long long SeekInternal (long long pos, int whence) override
 
- Protected Member Functions inherited from RingBuffer
 RingBuffer (RingBufferType rbtype)
 
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 CreateReadAheadBuffer (void)
 
void CalcReadAheadThresh (void)
 Calculates m_fillMin, m_fillThreshold, and m_readBlockSize from the estimated effective bitrate of the stream. More...
 
bool PauseAndWait (void)
 
int ReadPriv (void *buf, int count, bool peek)
 When possible reads from the read-ahead buffer, otherwise reads directly from the device. More...
 
int ReadDirect (void *buf, int count, bool peek)
 
bool WaitForReadsAllowed (void)
 
int WaitForAvail (int count, int timeout)
 
int ReadBufFree (void) const
 Returns number of bytes available for reading into buffer. More...
 
int ReadBufAvail (void) const
 Returns number of bytes available for reading from buffer. More...
 
void ResetReadAhead (long long newinternal)
 Restart the read-ahead thread at the 'newinternal' position. More...
 
void KillReadAheadThread (void)
 Stops the read-ahead thread, and waits for it to stop. More...
 
uint64_t UpdateDecoderRate (uint64_t latest=0)
 
uint64_t UpdateStorageRate (uint64_t latest=0)
 
- 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
 
MThreadoperator= (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 (unsigned long time=ULONG_MAX)
 Wait for the MThread to exit, with a maximum timeout. More...
 

Private Attributes

URLContext * m_context {nullptr}
 
bool m_streamed {true}
 
bool m_allowSeeks {false}
 

Additional Inherited Members

- Static Public Member Functions inherited from RingBuffer
static RingBufferCreate (const QString &xfilename, bool write, bool usereadahead=true, int timeout_ms=kDefaultOpenTimeout, bool stream_only=false)
 Creates a RingBuffer instance. More...
 
static QString BitrateToString (uint64_t rate, bool hz=false)
 
static void AVFormatInitNetwork (void)
 
- Static Public Attributes inherited from RingBuffer
static const int kDefaultOpenTimeout = 2000
 
static const int kLiveTVOpenTimeout = 10000
 
static QMutex s_subExtLock
 
static QStringList s_subExt
 
static QStringList s_subExtNoCheck
 
- Static Protected Member Functions inherited from MThread
static void setTerminationEnabled (bool enabled=true)
 
static void sleep (unsigned long time)
 
static void msleep (unsigned long time)
 
static void usleep (unsigned long 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 RingBuffer
RingBufferType m_type
 
QReadWriteLock m_posLock
 
long long m_readPos {0}
 
long long m_writePos {0}
 
long long m_internalReadPos {0}
 
long long m_ignoreReadPos {-1}
 
QReadWriteLock m_rbrLock
 
int m_rbrPos {0}
 
QReadWriteLock m_rbwLock
 
int m_rbwPos {0}
 
volatile bool m_stopReads {false}
 
QString m_safeFilename
 
QReadWriteLock m_rwLock
 
QString m_filename
 
QString m_subtitleFilename
 
QString m_lastError
 
ThreadedFileWriterm_tfw {nullptr}
 
int m_fd2 {-1}
 
bool m_writeMode {false}
 
RemoteFilem_remotefile {nullptr}
 
uint m_bufferSize {BUFFER_SIZE_MINIMUM}
 
bool m_lowBuffers {false}
 
bool m_fileIsMatroska {false}
 
bool m_unknownBitrate {false}
 
bool m_startReadAhead {false}
 
char * m_readAheadBuffer {nullptr}
 
bool m_readAheadRunning {false}
 
bool m_reallyRunning {false}
 
bool m_requestPause {false}
 
bool m_paused {false}
 
bool m_ateof {false}
 
bool m_waitForWrite {false}
 
bool m_beingWritten {false}
 
bool m_readsAllowed {false}
 
bool m_readsDesired {false}
 
volatile bool m_recentSeek {true}
 
bool m_setSwitchToNext {false}
 
uint m_rawBitrate {8000}
 
float m_playSpeed {1.0F}
 
int m_fillThreshold {65536}
 
int m_fillMin {-1}
 
int m_readBlockSize {CHUNK}
 
int m_wantToRead {0}
 
int m_numFailures {0}
 
bool m_commsError {false}
 
bool m_oldfile {false}
 
LiveTVChainm_liveTVChain {nullptr}
 
bool m_ignoreLiveEOF {false}
 
long long m_readAdjust {0}
 
int m_readOffset {0}
 
bool m_readInternalMode {false}
 
bool m_bitrateMonitorEnabled {false}
 
QMutex m_decoderReadLock
 
QMap< qint64, uint64_t > m_decoderReads
 
QMutex m_storageReadLock
 
QMap< qint64, uint64_t > m_storageReads
 
QWaitCondition m_generalWait
 Condition to signal that the read ahead thread is running. More...
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 
- Static Protected Attributes inherited from MThread
static const int kDefaultStartTimeout
 

Detailed Description

Definition at line 11 of file streamingringbuffer.h.

Constructor & Destructor Documentation

◆ StreamingRingBuffer()

StreamingRingBuffer::StreamingRingBuffer ( const QString &  lfilename)
explicit

Definition at line 9 of file streamingringbuffer.cpp.

◆ ~StreamingRingBuffer()

StreamingRingBuffer::~StreamingRingBuffer ( )
override

Definition at line 16 of file streamingringbuffer.cpp.

Member Function Documentation

◆ IsOpen()

bool StreamingRingBuffer::IsOpen ( void  ) const
overridevirtual

Returns true if open for either reading or writing.

Implements RingBuffer.

Definition at line 26 of file streamingringbuffer.cpp.

◆ GetReadPosition()

long long StreamingRingBuffer::GetReadPosition ( void  ) const
overridevirtual

Returns how far into the file we have read.

Implements RingBuffer.

Definition at line 34 of file streamingringbuffer.cpp.

◆ OpenFile()

bool StreamingRingBuffer::OpenFile ( const QString &  lfilename,
uint  retry_ms = kDefaultOpenTimeout 
)
overridevirtual

Opens a network stream for reading.

Parameters
lfilenameUrl of the stream to read.
retry_msIgnored. This value is part of the API inherited from the parent class.
Returns
Returns true if the stream was opened.

Implements RingBuffer.

Definition at line 47 of file streamingringbuffer.cpp.

Referenced by StreamingRingBuffer().

◆ IsStreamed()

bool StreamingRingBuffer::IsStreamed ( void  )
inlineoverridevirtual

Reimplemented from RingBuffer.

Definition at line 22 of file streamingringbuffer.h.

◆ IsSeekingAllowed()

bool StreamingRingBuffer::IsSeekingAllowed ( void  )
inlineoverridevirtual

Reimplemented from RingBuffer.

Definition at line 23 of file streamingringbuffer.h.

◆ IsBookmarkAllowed()

bool StreamingRingBuffer::IsBookmarkAllowed ( void  )
inlineoverridevirtual

Reimplemented from RingBuffer.

Definition at line 24 of file streamingringbuffer.h.

◆ safe_read()

int StreamingRingBuffer::safe_read ( void *  data,
uint  sz 
)
overrideprotectedvirtual

Implements RingBuffer.

Definition at line 107 of file streamingringbuffer.cpp.

◆ GetRealFileSizeInternal()

long long StreamingRingBuffer::GetRealFileSizeInternal ( void  ) const
overrideprotectedvirtual

Reimplemented from RingBuffer.

Definition at line 133 of file streamingringbuffer.cpp.

◆ SeekInternal()

long long StreamingRingBuffer::SeekInternal ( long long  pos,
int  whence 
)
overrideprotectedvirtual

Implements RingBuffer.

Definition at line 90 of file streamingringbuffer.cpp.

Member Data Documentation

◆ m_context

URLContext* StreamingRingBuffer::m_context {nullptr}
private

◆ m_streamed

bool StreamingRingBuffer::m_streamed {true}
private

Definition at line 33 of file streamingringbuffer.h.

Referenced by IsStreamed(), and OpenFile().

◆ m_allowSeeks

bool StreamingRingBuffer::m_allowSeeks {false}
private

Definition at line 34 of file streamingringbuffer.h.

Referenced by IsSeekingAllowed(), and OpenFile().


The documentation for this class was generated from the following files: