MythTV  master
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
MythMediaBuffer Class Referenceabstract

#include <libmythtv/io/mythmediabuffer.h>

Inheritance diagram for MythMediaBuffer:
[legend]
Collaboration diagram for MythMediaBuffer:
[legend]

Public Member Functions

 ~MythMediaBuffer () override=0
 Deletes. More...
 
MythBufferType GetType () const
 
void SetOldFile (bool Old)
 Tell RingBuffer if this is an old file or not. More...
 
void UpdateRawBitrate (uint RawBitrate)
 Set the raw bit rate, to allow RingBuffer adjust effective bitrate. More...
 
void UpdatePlaySpeed (float PlaySpeed)
 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 inaccurate 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
 
QString GetSubtitleFilename (void) const
 
QString GetLastError (void) const
 
bool GetCommsError (void) const
 
void ResetCommsError (void)
 
bool GetStopReads (void) const
 
QString GetDecoderRate (void)
 
QString GetStorageRate (void)
 
QString GetAvailableBuffer (void)
 
uint GetBufferSize (void) const
 
bool IsNearEnd (double Framerate, uint Frames) const
 
long long GetWritePosition (void) const
 Returns how far into a ThreadedFileWriter file we have written. More...
 
long long GetRealFileSize (void) const
 
bool IsDisc (void) const
 
bool IsDVD (void) const
 
bool IsBD (void) const
 
const MythDVDBufferDVD (void) const
 
MythDVDBufferDVD (void)
 
const MythBDBufferBD (void) const
 
MythBDBufferBD (void)
 
int Read (void *Buffer, 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 *Buffer, int Count)
 
int Peek (std::vector< char > &Buffer)
 
void Reset (bool Full=false, bool ToAdjust=false, bool ResetInternal=false)
 Resets the read-ahead thread and our position in the file. More...
 
void Pause (void)
 Pauses the read-ahead thread. Calls StopReads(void). More...
 
void Unpause (void)
 Unpauses the read-ahead thread. Calls StartReads(void). More...
 
void WaitForPause (void)
 Waits for Pause(void) to take effect. More...
 
void Start (void)
 Starts the read-ahead thread. More...
 
void StopReads (void)
 
void StartReads (void)
 
long long Seek (long long Position, int Whence, bool HasLock=false)
 
long long SetAdjustFilesize (void)
 
int GetReadBufAvail (void) const
 Returns number of bytes available for reading from buffer. More...
 
bool SetReadInternalMode (bool Mode)
 
bool IsReadInternalMode (void) const
 
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 *Buffer, 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 Position, int Whence, bool HasLock=false)
 Calls ThreadedFileWriter::Seek(long long,int). More...
 
bool WriterSetBlocking (bool Lock=true)
 Calls ThreadedFileWriter::SetBlocking(bool) More...
 
virtual long long GetReadPosition (void) const =0
 
virtual bool IsOpen (void) const =0
 
virtual bool IsStreamed (void)
 
virtual bool IsSeekingAllowed (void)
 
virtual bool IsBookmarkAllowed (void)
 
virtual int BestBufferSize (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 &, mpeg::chrono::pts)
 
virtual bool OpenFile (const QString &Filename, std::chrono::milliseconds Retry=kDefaultOpenTimeout)=0
 
virtual bool ReOpen (const QString &="")
 

Static Public Member Functions

static MythMediaBufferCreate (const QString &Filename, bool Write, bool UseReadAhead=true, std::chrono::milliseconds Timeout=kDefaultOpenTimeout, bool StreamOnly=false)
 Creates a RingBuffer instance. More...
 
static QString BitrateToString (uint64_t Rate, bool Hz=false)
 
static void AVFormatInitNetwork (void)
 

Static Public Attributes

static constexpr std::chrono::milliseconds kDefaultOpenTimeout { 2s }
 
static constexpr std::chrono::milliseconds kLiveTVOpenTimeout { 10s }
 

Protected Member Functions

 MythMediaBuffer (MythBufferType Type)
 
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 *Buffer, int Count, bool Peek)
 When possible reads from the read-ahead buffer, otherwise reads directly from the device. More...
 
int ReadDirect (void *Buffer, int Count, bool Peek)
 
bool WaitForReadsAllowed (void)
 
int WaitForAvail (int Count, std::chrono::milliseconds 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)
 
virtual int SafeRead (void *Buffer, uint Size)=0
 
virtual long long GetRealFileSizeInternal (void) const
 
virtual long long SeekInternal (long long Position, int Whence)=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 (std::chrono::milliseconds time=std::chrono::milliseconds::max())
 Wait for the MThread to exit, with a maximum timeout. More...
 

Protected Attributes

MythBufferType 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 { DEFAULT_CHUNK_SIZE}
 
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< std::chrono::milliseconds, uint64_t > m_decoderReads
 
QMutex m_storageReadLock
 
QMap< std::chrono::milliseconds, 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}
 

Private Attributes

bool m_bitrateInitialized { false }
 

Friends

class MythInteractiveBuffer
 

Additional Inherited Members

- 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)
 

Detailed Description

Definition at line 59 of file mythmediabuffer.h.

Constructor & Destructor Documentation

◆ ~MythMediaBuffer()

MythMediaBuffer::~MythMediaBuffer ( )
overridepure virtual

Deletes.

Note
Classes inheriting from RingBuffer must implement a destructor that calls KillReadAheadThread(). We can not do that here because this would leave pure virtual functions without implementations during destruction.

Definition at line 219 of file mythmediabuffer.cpp.

◆ MythMediaBuffer()

MythMediaBuffer::MythMediaBuffer ( MythBufferType  Type)
explicitprotected

Definition at line 198 of file mythmediabuffer.cpp.

Member Function Documentation

◆ Create()

MythMediaBuffer * MythMediaBuffer::Create ( const QString &  Filename,
bool  Write,
bool  UseReadAhead = true,
std::chrono::milliseconds  Timeout = kDefaultOpenTimeout,
bool  StreamOnly = false 
)
static

Creates a RingBuffer instance.

You can explicitly disable the readahead thread by setting readahead to false or by just not calling Start(void).

Parameters
FilenameName of file to read or write.
WriteIf true an encapsulated writer is created
UseReadAheadIf false a call to Start(void) will not a pre-buffering thread, otherwise Start(void) will start a pre-buffering thread.
Timeoutif < 0, then we will not open the file. Otherwise it's how long to try opening the file after the first failure in milliseconds before giving up.
StreamOnlyIf true disallow DVD and Bluray (used by FileTransfer)

Definition at line 99 of file mythmediabuffer.cpp.

Referenced by CopyFile(), FlagCommercials(), TVRec::GetProgramRingBufferForLiveTV(), PreviewGenerator::GetScreenGrab(), TV::HandleStateChange(), NuppelVideoRecorder::Initialize(), MythFileOpen(), MythAVFormatWriter::OpenFile(), pid_counter(), pid_filter(), pid_printer(), RebuildSeekTable(), ImportRecorder::run(), RunCCExtract(), TV::SwitchInputs(), TVRec::SwitchRecordingRingBuffer(), VideoPerformanceTest::Test(), Transcode::TranscodeFile(), and TVRec::TuningNewRecorder().

◆ GetType()

MythBufferType MythMediaBuffer::GetType ( ) const

◆ BitrateToString()

QString MythMediaBuffer::BitrateToString ( uint64_t  Rate,
bool  Hz = false 
)
static

◆ AVFormatInitNetwork()

void MythMediaBuffer::AVFormatInitNetwork ( void  )
static

◆ SetOldFile()

void MythMediaBuffer::SetOldFile ( bool  Old)

Tell RingBuffer if this is an old file or not.

Normally the RingBuffer determines that the file is old if it has not been modified in the last minute. This allows one to override that determination externally.

If for instance you are slowly writing to the file you could call this with the value of false. If you just finished writing the file you could call it with the value true. Knowing that the file is old allows MythTV to determine that a read at the end of the file is really an end-of-file condition more quickly. But if the file is growing it can also cause the RingBuffer to report an end-of-file condition prematurely.

Definition at line 1737 of file mythmediabuffer.cpp.

Referenced by FileTransfer::SetTimeout(), and BEFileTransfer::SetTimeout().

◆ UpdateRawBitrate()

void MythMediaBuffer::UpdateRawBitrate ( uint  RawBitrate)

Set the raw bit rate, to allow RingBuffer adjust effective bitrate.

Parameters
RawBitrateStreams average number of kilobits per second when playspeed is 1.0

Definition at line 279 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::JumpToProgram(), MythPlayerUI::JumpToStream(), AvFormatDecoder::ScanStreams(), and MythPlayerUI::SwitchToProgram().

◆ UpdatePlaySpeed()

void MythMediaBuffer::UpdatePlaySpeed ( float  PlaySpeed)

Set the play speed, to allow RingBuffer adjust effective bitrate.

Parameters
play_speedSpeed to set. (1.0 for normal speed)

Definition at line 307 of file mythmediabuffer.cpp.

◆ EnableBitrateMonitor()

void MythMediaBuffer::EnableBitrateMonitor ( bool  Enable)

Definition at line 315 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::EnableBitrateMonitor().

◆ SetBufferSizeFactors()

void MythMediaBuffer::SetBufferSizeFactors ( bool  EstBitrate,
bool  Matroska 
)

Tells RingBuffer that the raw bitrate may be inaccurate and the underlying container is matroska, both of which may require a larger buffer size.

Definition at line 330 of file mythmediabuffer.cpp.

Referenced by AvFormatDecoder::ScanStreams().

◆ SetWaitForWrite()

void MythMediaBuffer::SetWaitForWrite ( void  )

Definition at line 320 of file mythmediabuffer.cpp.

Referenced by RunCCExtract().

◆ GetSafeFilename()

QString MythMediaBuffer::GetSafeFilename ( void  )

◆ GetFilename()

QString MythMediaBuffer::GetFilename ( void  ) const

◆ GetSubtitleFilename()

QString MythMediaBuffer::GetSubtitleFilename ( void  ) const

Definition at line 1758 of file mythmediabuffer.cpp.

Referenced by MythPlayerCaptionsUI::LoadExternalSubtitles().

◆ GetLastError()

QString MythMediaBuffer::GetLastError ( void  ) const

◆ GetCommsError()

bool MythMediaBuffer::GetCommsError ( void  ) const

Definition at line 1774 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::EventLoop().

◆ ResetCommsError()

void MythMediaBuffer::ResetCommsError ( void  )

Definition at line 1779 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::EventLoop().

◆ GetStopReads()

bool MythMediaBuffer::GetStopReads ( void  ) const

◆ GetDecoderRate()

QString MythMediaBuffer::GetDecoderRate ( void  )

Definition at line 1539 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::GetPlaybackData().

◆ GetStorageRate()

QString MythMediaBuffer::GetStorageRate ( void  )

Definition at line 1544 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::GetPlaybackData().

◆ GetAvailableBuffer()

QString MythMediaBuffer::GetAvailableBuffer ( void  )

Definition at line 1549 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::GetPlaybackData().

◆ GetBufferSize()

uint MythMediaBuffer::GetBufferSize ( void  ) const

Definition at line 1559 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::GetPlaybackData().

◆ IsNearEnd()

bool MythMediaBuffer::IsNearEnd ( double  Framerate,
uint  Frames 
) const

Definition at line 412 of file mythmediabuffer.cpp.

Referenced by MythPlayer::IsReallyNearEnd().

◆ GetWritePosition()

long long MythMediaBuffer::GetWritePosition ( void  ) const

◆ GetRealFileSize()

long long MythMediaBuffer::GetRealFileSize ( void  ) const

◆ IsDisc()

bool MythMediaBuffer::IsDisc ( void  ) const

◆ IsDVD()

bool MythMediaBuffer::IsDVD ( void  ) const

Definition at line 1836 of file mythmediabuffer.cpp.

Referenced by MythDVDPlayer::CalcMaxFFTime(), MythDVDPlayer::ChangeSpeed(), MythDVDPlayer::DisableCaptions(), MythDVDPlayer::DisplayDVDButton(), MythDVDPlayer::DisplayPauseFrame(), DecoderBase::DoFastForward(), MythDVDDecoder::DoFastForwardSeek(), MythDVDPlayer::DoJumpChapter(), MythDVDDecoder::DoRewindSeek(), MythDVDDecoder::DVDFindPosition(), MythDVDPlayer::EnableCaptions(), MythDVDDecoder::GetAudioLanguage(), MythDVDPlayer::GetBookmark(), MythDVDPlayer::GetChapterTimes(), MythDVDPlayer::GetCurrentChapter(), MythDVDPlayer::GetMillisecondsPlayed(), MythDVDPlayer::GetNumChapters(), MythPreviewPlayer::GetScreenGrabAtFrame(), AvFormatDecoder::GetTrackDesc(), MythDVDPlayer::GoToMenu(), TV::HandleLCDTimerEvent(), TV::HandleStateChange(), AvFormatDecoder::InitVideoCodec(), IsDisc(), AvFormatDecoder::MpegPreProcessPkt(), AvFormatDecoder::OpenFile(), TV::OSDDialogEvent(), DecoderBase::PosMapFromDb(), MythDVDDecoder::PostProcessTracks(), MythDVDPlayer::PrepareAudioSample(), TV::ProcessKeypressOrGesture(), TV::ProcessNetworkControlCommand(), AvFormatDecoder::ProcessSubtitlePacket(), AvFormatDecoder::ProcessVideoFrame(), AvFormatDecoder::ProcessVideoPacket(), ReadDirect(), AvFormatDecoder::ScanStreams(), MythDVDPlayer::SetBookmark(), TV::ShowLCDDVDInfo(), TV::ShowOSDStopWatchingRecording(), MythDVDPlayer::StillFrameCheck(), MythDVDDecoder::StreamChangeCheck(), DecoderBase::SyncPositionMap(), MythDVDDecoder::UpdateFramesPlayed(), MythDVDPlayer::VideoLoop(), and TV::VolumeChange().

◆ IsBD()

bool MythMediaBuffer::IsBD ( void  ) const

◆ DVD() [1/2]

const MythDVDBuffer * MythMediaBuffer::DVD ( void  ) const

Definition at line 1846 of file mythmediabuffer.cpp.

Referenced by TV::ActiveHandleAction(), MythDVDPlayer::CalcMaxFFTime(), MythDVDPlayer::ChangeSpeed(), MythDVDDecoder::CheckContext(), MythDVDPlayer::DisableCaptions(), MythDVDPlayer::DisplayDVDButton(), MythDVDPlayer::DisplayPauseFrame(), DecoderBase::DoFastForward(), MythDVDPlayer::DoJumpChapter(), MythDVDDecoder::DVDFindPosition(), MythDVDPlayer::EnableCaptions(), MythDVDPlayer::EventEnd(), MythDVDPlayer::EventStart(), MythDVDDecoder::GetAudioLanguage(), MythDVDDecoder::GetAudioTrackType(), MythDVDPlayer::GetBookmark(), MythDVDPlayer::GetChapterTimes(), MythDVDPlayer::GetCurrentAngle(), MythDVDPlayer::GetCurrentChapter(), MythDVDPlayer::GetMillisecondsPlayed(), MythDVDPlayer::GetNumAngles(), MythDVDPlayer::GetNumChapters(), MythDVDPlayer::GoToDVDProgram(), MythDVDPlayer::GoToMenu(), MythDVDPlayer::InitialSeek(), AvFormatDecoder::MpegPreProcessPkt(), DecoderBase::PosMapFromDb(), MythDVDDecoder::PostProcessTracks(), MythDVDPlayer::PrepareAudioSample(), MythDVDDecoder::ProcessDataPacket(), AvFormatDecoder::ProcessSubtitlePacket(), MythDVDDecoder::ProcessVideoPacket(), MythDVDDecoder::ReadPacket(), AvFormatDecoder::ScanStreams(), MythDVDPlayer::SetBookmark(), MythDVDPlayer::SetTrack(), TV::ShowLCDDVDInfo(), MythDVDPlayer::StillFrameCheck(), MythDVDDecoder::StreamChangeCheck(), MythDVDPlayer::SwitchAngle(), DecoderBase::SyncPositionMap(), MythDVDDecoder::UpdateFramesPlayed(), MythDVDPlayer::VideoLoop(), and MythDVDPlayer::VideoStart().

◆ DVD() [2/2]

MythDVDBuffer * MythMediaBuffer::DVD ( void  )

Definition at line 1856 of file mythmediabuffer.cpp.

◆ BD() [1/2]

const MythBDBuffer * MythMediaBuffer::BD ( void  ) const

◆ BD() [2/2]

MythBDBuffer * MythMediaBuffer::BD ( void  )

Definition at line 1861 of file mythmediabuffer.cpp.

◆ Read()

int MythMediaBuffer::Read ( void *  Buffer,
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.

Parameters
bufPointer to where data will be written
countNumber of bytes to read
Returns
Returns number of bytes read

Definition at line 1492 of file mythmediabuffer.cpp.

Referenced by CopyFile(), pid_counter(), pid_filter(), pid_printer(), MythAVFormatBuffer::Read(), FileTransfer::RequestBlock(), and BEFileTransfer::RequestBlock().

◆ Peek() [1/2]

int MythMediaBuffer::Peek ( void *  Buffer,
int  Count 
)
Note
Only works with readahead

Definition at line 1170 of file mythmediabuffer.cpp.

Referenced by MythPlayer::OpenFile(), Peek(), ReadDirect(), and ReadPriv().

◆ Peek() [2/2]

int MythMediaBuffer::Peek ( std::vector< char > &  Buffer)

Definition at line 1181 of file mythmediabuffer.cpp.

◆ Reset()

void MythMediaBuffer::Reset ( bool  Full = false,
bool  ToAdjust = false,
bool  ResetInternal = false 
)

Resets the read-ahead thread and our position in the file.

Definition at line 238 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::FileChanged(), MythPlayerUI::JumpToProgram(), MythInteractiveBuffer::OpenFile(), and MythPlayerUI::SwitchToProgram().

◆ Pause()

void MythMediaBuffer::Pause ( void  )

Pauses the read-ahead thread. Calls StopReads(void).

See also
Unpause(void), WaitForPause(void)

Definition at line 690 of file mythmediabuffer.cpp.

Referenced by MythInteractiveBuffer::OpenFile(), MythPlayer::PauseBuffer(), TV::StopStuff(), and TV::SwitchInputs().

◆ Unpause()

void MythMediaBuffer::Unpause ( void  )

Unpauses the read-ahead thread. Calls StartReads(void).

See also
Pause(void)

Definition at line 704 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::SwitchToProgram(), MythInteractiveBuffer::TakeBuffer(), and MythPlayer::UnpauseBuffer().

◆ WaitForPause()

void MythMediaBuffer::WaitForPause ( void  )

Waits for Pause(void) to take effect.

Definition at line 718 of file mythmediabuffer.cpp.

Referenced by TV::DoTogglePauseFinish(), MythPlayer::PauseBuffer(), TV::StopStuff(), and TV::SwitchInputs().

◆ Start()

void MythMediaBuffer::Start ( void  )

Starts the read-ahead thread.

If the RingBuffer constructor was not called with a usereadahead of true of if this was reset to false because we're dealing with a DVD the read ahead thread will not be started.

If this RingBuffer is in write-mode a warning will be printed and the read ahead thread will not be started.

If the read ahead thread is already running a warning will be printed and the read ahead thread will not be started.

Definition at line 617 of file mythmediabuffer.cpp.

Referenced by BEFileTransfer::BEFileTransfer(), MythFileOpen(), MythPlayer::OpenFile(), and MythDVDStream::SafeRead().

◆ StopReads()

void MythMediaBuffer::StopReads ( void  )

◆ StartReads()

void MythMediaBuffer::StartReads ( void  )

◆ Seek()

long long MythMediaBuffer::Seek ( long long  Position,
int  Whence,
bool  HasLock = false 
)

◆ SetAdjustFilesize()

long long MythMediaBuffer::SetAdjustFilesize ( void  )

Definition at line 1158 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::SwitchToProgram().

◆ GetReadBufAvail()

int MythMediaBuffer::GetReadBufAvail ( void  ) const

Returns number of bytes available for reading from buffer.

Definition at line 462 of file mythmediabuffer.cpp.

Referenced by AvFormatDecoder::InitByteContext().

◆ SetReadInternalMode()

bool MythMediaBuffer::SetReadInternalMode ( bool  Mode)

Definition at line 523 of file mythmediabuffer.cpp.

Referenced by MythAVFormatBuffer::SetInInit().

◆ IsReadInternalMode()

bool MythMediaBuffer::IsReadInternalMode ( void  ) const

Definition at line 548 of file mythmediabuffer.cpp.

◆ LiveMode()

bool MythMediaBuffer::LiveMode ( void  ) const

Returns true if this RingBuffer has been assigned a LiveTVChain.

See also
SetLiveMode(LiveTVChain*)

Definition at line 1804 of file mythmediabuffer.cpp.

Referenced by NuppelVideoRecorder::Initialize(), IsStreamed(), and MythPlayer::OpenFile().

◆ SetLiveMode()

void MythMediaBuffer::SetLiveMode ( LiveTVChain Chain)

Assigns a LiveTVChain to this RingBuffer.

See also
LiveMode(void)

Definition at line 1816 of file mythmediabuffer.cpp.

Referenced by TV::HandleStateChange(), and TV::SwitchInputs().

◆ IgnoreLiveEOF()

void MythMediaBuffer::IgnoreLiveEOF ( bool  Ignore)

Tells RingBuffer whether to ignore the end-of-file.

Definition at line 1824 of file mythmediabuffer.cpp.

Referenced by MythPlayerUI::JumpToProgram(), TV::PauseLiveTV(), TV::SwitchInputs(), and TV::UnpauseLiveTV().

◆ Write()

int MythMediaBuffer::Write ( const void *  Buffer,
uint  Count 
)

◆ IsIOBound()

bool MythMediaBuffer::IsIOBound ( void  ) const

◆ WriterFlush()

void MythMediaBuffer::WriterFlush ( void  )

◆ Sync()

void MythMediaBuffer::Sync ( void  )

Calls ThreadedFileWriter::Sync(void)

Definition at line 1667 of file mythmediabuffer.cpp.

◆ WriterSeek()

long long MythMediaBuffer::WriterSeek ( long long  Position,
int  Whence,
bool  HasLock = false 
)

◆ WriterSetBlocking()

bool MythMediaBuffer::WriterSetBlocking ( bool  Lock = true)

◆ GetReadPosition()

virtual long long MythMediaBuffer::GetReadPosition ( void  ) const
pure virtual

◆ IsOpen()

virtual bool MythMediaBuffer::IsOpen ( void  ) const
pure virtual

◆ IsStreamed()

virtual bool MythMediaBuffer::IsStreamed ( void  )
inlinevirtual

◆ IsSeekingAllowed()

virtual bool MythMediaBuffer::IsSeekingAllowed ( void  )
inlinevirtual

◆ IsBookmarkAllowed()

virtual bool MythMediaBuffer::IsBookmarkAllowed ( void  )
inlinevirtual

◆ BestBufferSize()

virtual int MythMediaBuffer::BestBufferSize ( void  )
inlinevirtual

Reimplemented in MythDVDBuffer.

Definition at line 137 of file mythmediabuffer.h.

Referenced by AvFormatDecoder::InitByteContext().

◆ StartFromBeginning()

virtual bool MythMediaBuffer::StartFromBeginning ( void  )
inlinevirtual

Reimplemented in MythDVDBuffer, and MythBDBuffer.

Definition at line 138 of file mythmediabuffer.h.

Referenced by AvFormatDecoder::OpenFile().

◆ IgnoreWaitStates()

virtual void MythMediaBuffer::IgnoreWaitStates ( bool  )
inlinevirtual

Reimplemented in MythDVDBuffer, and MythBDBuffer.

Definition at line 139 of file mythmediabuffer.h.

Referenced by MythDVDPlayer::InitialSeek(), AvFormatDecoder::OpenFile(), and TV::StopStuff().

◆ IsInMenu()

virtual bool MythMediaBuffer::IsInMenu ( void  ) const
inlinevirtual

◆ IsInStillFrame()

virtual bool MythMediaBuffer::IsInStillFrame ( void  ) const
inlinevirtual

◆ IsInDiscMenuOrStillFrame()

virtual bool MythMediaBuffer::IsInDiscMenuOrStillFrame ( void  ) const
inlinevirtual

◆ HandleAction()

virtual bool MythMediaBuffer::HandleAction ( const QStringList &  ,
mpeg::chrono::pts   
)
inlinevirtual

Reimplemented in MythDVDBuffer, and MythBDBuffer.

Definition at line 143 of file mythmediabuffer.h.

Referenced by TV::DiscMenuHandleAction().

◆ OpenFile()

virtual bool MythMediaBuffer::OpenFile ( const QString &  Filename,
std::chrono::milliseconds  Retry = kDefaultOpenTimeout 
)
pure virtual

◆ ReOpen()

virtual bool MythMediaBuffer::ReOpen ( const QString &  = "")
inlinevirtual

Reimplemented in MythFileBuffer.

Definition at line 145 of file mythmediabuffer.h.

Referenced by FileTransfer::ReOpen(), BEFileTransfer::ReOpen(), and MythAVFormatWriter::ReOpen().

◆ run()

void MythMediaBuffer::run ( void  )
overrideprotectedvirtual

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 825 of file mythmediabuffer.cpp.

◆ CreateReadAheadBuffer()

void MythMediaBuffer::CreateReadAheadBuffer ( void  )
protected

Definition at line 777 of file mythmediabuffer.cpp.

Referenced by run(), and SetBufferSizeFactors().

◆ CalcReadAheadThresh()

void MythMediaBuffer::CalcReadAheadThresh ( void  )
protected

Calculates m_fillMin, m_fillThreshold, and m_readBlockSize from the estimated effective bitrate of the stream.

Warning
Must be called with rwlock in write lock state.

Definition at line 367 of file mythmediabuffer.cpp.

Referenced by CreateReadAheadBuffer(), MythInteractiveBuffer::OpenFile(), MythFileBuffer::OpenFile(), MythBDBuffer::OpenFile(), MythDVDBuffer::OpenFile(), ResetReadAhead(), run(), UpdatePlaySpeed(), and UpdateRawBitrate().

◆ PauseAndWait()

bool MythMediaBuffer::PauseAndWait ( void  )
protected

Definition at line 734 of file mythmediabuffer.cpp.

Referenced by run().

◆ ReadPriv()

int MythMediaBuffer::ReadPriv ( void *  Buffer,
int  Count,
bool  Peek 
)
protected

When possible reads from the read-ahead buffer, otherwise reads directly from the device.

Parameters
BufferPointer to where data will be written
CountNumber of bytes to read
PeekIf true, don't increment read count
Returns
Returns number of bytes read

Definition at line 1326 of file mythmediabuffer.cpp.

Referenced by Peek(), and Read().

◆ ReadDirect()

int MythMediaBuffer::ReadDirect ( void *  Buffer,
int  Count,
bool  Peek 
)
protected

Definition at line 1251 of file mythmediabuffer.cpp.

Referenced by ReadPriv().

◆ WaitForReadsAllowed()

bool MythMediaBuffer::WaitForReadsAllowed ( void  )
protected

Definition at line 1186 of file mythmediabuffer.cpp.

Referenced by ReadPriv().

◆ WaitForAvail()

int MythMediaBuffer::WaitForAvail ( int  Count,
std::chrono::milliseconds  Timeout 
)
protected

Definition at line 1215 of file mythmediabuffer.cpp.

Referenced by ReadPriv().

◆ ReadBufFree()

int MythMediaBuffer::ReadBufFree ( void  ) const
protected

Returns number of bytes available for reading into buffer.

Warning
Must be called with rwlock in locked state.

Definition at line 451 of file mythmediabuffer.cpp.

Referenced by run().

◆ ReadBufAvail()

int MythMediaBuffer::ReadBufAvail ( void  ) const
protected

Returns number of bytes available for reading from buffer.

Warning
Must be called with rwlock in locked state.

Definition at line 555 of file mythmediabuffer.cpp.

Referenced by GetReadBufAvail(), GetRealFileSize(), ReadPriv(), Seek(), and WaitForAvail().

◆ ResetReadAhead()

void MythMediaBuffer::ResetReadAhead ( long long  NewInternal)
protected

Restart the read-ahead thread at the 'newinternal' position.

This is called after a Seek(long long, int) so that the read-ahead buffer doesn't contain any stale data, and so that it will read any new data from the new position in the file.

Warning
Must be called with rwlock and poslock in write lock state.
Parameters
NewInternalPosition in file to start reading data from

Definition at line 575 of file mythmediabuffer.cpp.

Referenced by Reset(), run(), MythInteractiveBuffer::SeekInternal(), MythFileBuffer::SeekInternal(), MythBDBuffer::SeekInternal(), and MythDVDBuffer::SeekInternal().

◆ KillReadAheadThread()

void MythMediaBuffer::KillReadAheadThread ( void  )
protected

◆ UpdateDecoderRate()

uint64_t MythMediaBuffer::UpdateDecoderRate ( uint64_t  Latest = 0)
protected

Definition at line 1564 of file mythmediabuffer.cpp.

Referenced by GetDecoderRate(), and Read().

◆ UpdateStorageRate()

uint64_t MythMediaBuffer::UpdateStorageRate ( uint64_t  Latest = 0)
protected

Definition at line 1595 of file mythmediabuffer.cpp.

Referenced by GetStorageRate(), ReadDirect(), and run().

◆ SafeRead()

virtual int MythMediaBuffer::SafeRead ( void *  Buffer,
uint  Size 
)
protectedpure virtual

◆ GetRealFileSizeInternal()

virtual long long MythMediaBuffer::GetRealFileSizeInternal ( void  ) const
inlineprotectedvirtual

Reimplemented in HLSRingBuffer, MythStreamingBuffer, MythFileBuffer, and MythInteractiveBuffer.

Definition at line 166 of file mythmediabuffer.h.

Referenced by GetRealFileSize().

◆ SeekInternal()

virtual long long MythMediaBuffer::SeekInternal ( long long  Position,
int  Whence 
)
protectedpure virtual

Friends And Related Function Documentation

◆ MythInteractiveBuffer

friend class MythInteractiveBuffer
friend

Definition at line 61 of file mythmediabuffer.h.

Member Data Documentation

◆ kDefaultOpenTimeout

constexpr std::chrono::milliseconds MythMediaBuffer::kDefaultOpenTimeout { 2s }
staticconstexpr

Definition at line 71 of file mythmediabuffer.h.

Referenced by MythFileOpen().

◆ kLiveTVOpenTimeout

constexpr std::chrono::milliseconds MythMediaBuffer::kLiveTVOpenTimeout { 10s }
staticconstexpr

◆ m_type

MythBufferType MythMediaBuffer::m_type
protected

Definition at line 171 of file mythmediabuffer.h.

Referenced by GetAvailableBuffer(), GetType(), IsBD(), and IsDVD().

◆ m_posLock

QReadWriteLock MythMediaBuffer::m_posLock
mutableprotected

◆ m_readPos

long long MythMediaBuffer::m_readPos { 0 }
protected

◆ m_writePos

long long MythMediaBuffer::m_writePos { 0 }
protected

Definition at line 175 of file mythmediabuffer.h.

Referenced by GetWritePosition(), MythFileBuffer::ReOpen(), Reset(), Write(), and WriterSeek().

◆ m_internalReadPos

long long MythMediaBuffer::m_internalReadPos { 0 }
protected

◆ m_ignoreReadPos

long long MythMediaBuffer::m_ignoreReadPos { -1 }
protected

◆ m_rbrLock

QReadWriteLock MythMediaBuffer::m_rbrLock
mutableprotected

◆ m_rbrPos

int MythMediaBuffer::m_rbrPos { 0 }
protected

◆ m_rbwLock

QReadWriteLock MythMediaBuffer::m_rbwLock
mutableprotected

◆ m_rbwPos

int MythMediaBuffer::m_rbwPos { 0 }
protected

◆ m_stopReads

volatile bool MythMediaBuffer::m_stopReads {false}
protected

◆ m_safeFilename

QString MythMediaBuffer::m_safeFilename
protected

◆ m_rwLock

QReadWriteLock MythMediaBuffer::m_rwLock
mutableprotected

◆ m_filename

QString MythMediaBuffer::m_filename
protected

◆ m_subtitleFilename

QString MythMediaBuffer::m_subtitleFilename
protected

Definition at line 194 of file mythmediabuffer.h.

Referenced by GetSubtitleFilename(), and MythFileBuffer::OpenFile().

◆ m_lastError

QString MythMediaBuffer::m_lastError
protected

◆ m_tfw

ThreadedFileWriter* MythMediaBuffer::m_tfw { nullptr }
protected

◆ m_fd2

int MythMediaBuffer::m_fd2 { -1 }
protected

◆ m_writeMode

bool MythMediaBuffer::m_writeMode { false }
protected

◆ m_remotefile

RemoteFile* MythMediaBuffer::m_remotefile { nullptr }
protected

◆ m_bufferSize

uint MythMediaBuffer::m_bufferSize { BUFFER_SIZE_MINIMUM }
protected

◆ m_lowBuffers

bool MythMediaBuffer::m_lowBuffers { false }
protected

Definition at line 201 of file mythmediabuffer.h.

Referenced by CalcReadAheadThresh(), and WaitForAvail().

◆ m_fileIsMatroska

bool MythMediaBuffer::m_fileIsMatroska { false }
protected

Definition at line 202 of file mythmediabuffer.h.

Referenced by CreateReadAheadBuffer(), and SetBufferSizeFactors().

◆ m_unknownBitrate

bool MythMediaBuffer::m_unknownBitrate { false }
protected

Definition at line 203 of file mythmediabuffer.h.

Referenced by CreateReadAheadBuffer(), and SetBufferSizeFactors().

◆ m_startReadAhead

bool MythMediaBuffer::m_startReadAhead { false }
protected

◆ m_readAheadBuffer

char* MythMediaBuffer::m_readAheadBuffer { nullptr }
protected

Definition at line 205 of file mythmediabuffer.h.

Referenced by CreateReadAheadBuffer(), ReadPriv(), run(), and ~MythMediaBuffer().

◆ m_readAheadRunning

bool MythMediaBuffer::m_readAheadRunning { false }
protected

◆ m_reallyRunning

bool MythMediaBuffer::m_reallyRunning { false }
protected

Definition at line 207 of file mythmediabuffer.h.

Referenced by run(), and Start().

◆ m_requestPause

bool MythMediaBuffer::m_requestPause { false }
protected

◆ m_paused

bool MythMediaBuffer::m_paused { false }
protected

Definition at line 209 of file mythmediabuffer.h.

Referenced by IsNearEnd(), PauseAndWait(), and WaitForPause().

◆ m_ateof

bool MythMediaBuffer::m_ateof { false }
protected

◆ m_waitForWrite

bool MythMediaBuffer::m_waitForWrite { false }
protected

Definition at line 211 of file mythmediabuffer.h.

Referenced by run(), and SetWaitForWrite().

◆ m_beingWritten

bool MythMediaBuffer::m_beingWritten { false }
protected

Definition at line 212 of file mythmediabuffer.h.

Referenced by run().

◆ m_readsAllowed

bool MythMediaBuffer::m_readsAllowed { false }
protected

◆ m_readsDesired

bool MythMediaBuffer::m_readsDesired { false }
protected

◆ m_recentSeek

volatile bool MythMediaBuffer::m_recentSeek { true }
protected

◆ m_setSwitchToNext

bool MythMediaBuffer::m_setSwitchToNext { false }
protected

◆ m_rawBitrate

uint MythMediaBuffer::m_rawBitrate { 8000 }
protected

◆ m_playSpeed

float MythMediaBuffer::m_playSpeed { 1.0F }
protected

Definition at line 218 of file mythmediabuffer.h.

Referenced by CalcReadAheadThresh(), IsNearEnd(), and UpdatePlaySpeed().

◆ m_fillThreshold

int MythMediaBuffer::m_fillThreshold { 65536 }
protected

Definition at line 219 of file mythmediabuffer.h.

Referenced by CalcReadAheadThresh(), and run().

◆ m_fillMin

int MythMediaBuffer::m_fillMin { -1 }
protected

◆ m_readBlockSize

int MythMediaBuffer::m_readBlockSize { DEFAULT_CHUNK_SIZE}
protected

◆ m_wantToRead

int MythMediaBuffer::m_wantToRead { 0 }
protected

Definition at line 222 of file mythmediabuffer.h.

Referenced by ReadPriv(), and WaitForAvail().

◆ m_numFailures

int MythMediaBuffer::m_numFailures { 0 }
protected

◆ m_commsError

bool MythMediaBuffer::m_commsError { false }
protected

◆ m_oldfile

bool MythMediaBuffer::m_oldfile { false }
protected

◆ m_liveTVChain

LiveTVChain* MythMediaBuffer::m_liveTVChain { nullptr }
protected

◆ m_ignoreLiveEOF

bool MythMediaBuffer::m_ignoreLiveEOF { false }
protected

Definition at line 227 of file mythmediabuffer.h.

Referenced by IgnoreLiveEOF(), and run().

◆ m_readAdjust

long long MythMediaBuffer::m_readAdjust { 0 }
protected

◆ m_readOffset

int MythMediaBuffer::m_readOffset { 0 }
protected

Definition at line 229 of file mythmediabuffer.h.

Referenced by ReadPriv(), ResetReadAhead(), Seek(), and SetReadInternalMode().

◆ m_readInternalMode

bool MythMediaBuffer::m_readInternalMode { false }
protected

◆ m_bitrateMonitorEnabled

bool MythMediaBuffer::m_bitrateMonitorEnabled { false }
protected

Definition at line 233 of file mythmediabuffer.h.

Referenced by EnableBitrateMonitor(), UpdateDecoderRate(), and UpdateStorageRate().

◆ m_decoderReadLock

QMutex MythMediaBuffer::m_decoderReadLock
protected

Definition at line 234 of file mythmediabuffer.h.

Referenced by UpdateDecoderRate().

◆ m_decoderReads

QMap<std::chrono::milliseconds, uint64_t> MythMediaBuffer::m_decoderReads
protected

Definition at line 235 of file mythmediabuffer.h.

Referenced by UpdateDecoderRate().

◆ m_storageReadLock

QMutex MythMediaBuffer::m_storageReadLock
protected

Definition at line 236 of file mythmediabuffer.h.

Referenced by UpdateStorageRate().

◆ m_storageReads

QMap<std::chrono::milliseconds, uint64_t> MythMediaBuffer::m_storageReads
protected

Definition at line 237 of file mythmediabuffer.h.

Referenced by UpdateStorageRate().

◆ m_generalWait

QWaitCondition MythMediaBuffer::m_generalWait
protected

◆ m_bitrateInitialized

bool MythMediaBuffer::m_bitrateInitialized { false }
private

Definition at line 249 of file mythmediabuffer.h.

Referenced by CalcReadAheadThresh(), and UpdateRawBitrate().


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