MythTV  master
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ExternalStreamHandler Class Reference

#include <ExternalStreamHandler.h>

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

Public Member Functions

 ExternalStreamHandler (const QString &path, int inputid, int majorid)
 
 ~ExternalStreamHandler (void) override
 
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 PriorityEvent (int fd) override
 
QString GetDescription (void)
 
QString UpdateDescription (void)
 
bool IsAppOpen (void)
 
bool IsTSOpen (void)
 
bool HasTuner (void) const
 
bool HasPictureAttributes (void) const
 
bool RestartStream (void)
 
void LockReplay (void)
 
void UnlockReplay (bool enable_replay=false)
 
void ReplayStream (void)
 
bool StartStreaming (void)
 
bool StopStreaming (void)
 
bool CheckForError (void)
 
void PurgeBuffer (void)
 
bool ProcessCommand (const QString &cmd, QString &result, std::chrono::milliseconds timeout=4s, uint retry_cnt=3)
 
bool ProcessVer1 (const QString &cmd, QString &result, std::chrono::milliseconds timeout, uint retry_cnt)
 
bool ProcessVer2 (const QString &command, QString &result, std::chrono::milliseconds timeout, uint retry_cnt)
 
- Public Member Functions inherited from StreamHandler
virtual void AddListener (MPEGStreamData *data, bool allow_section_reader=false, bool needs_buffering=false, const QString &output_file=QString())
 
virtual void RemoveListener (MPEGStreamData *data)
 
bool IsRunning (void) const
 
bool HasError (void) const
 
virtual bool AddNamedOutputFile (const QString &filename)
 Called with _listener_lock locked just after adding new output file. More...
 
virtual void RemoveNamedOutputFile (const QString &filename)
 Called with _listener_lock locked just before removing old output file. More...
 

Static Public Member Functions

static ExternalStreamHandlerGet (const QString &devname, int inputid, int majorid)
 
static void Return (ExternalStreamHandler *&ref, int inputid)
 

Private Types

enum  constants { MAX_API_VERSION = 2, TS_PACKET_SIZE = 188, PACKET_SIZE = TS_PACKET_SIZE * 8192, TOO_FAST_SIZE = TS_PACKET_SIZE * 32768 }
 

Private Member Functions

int StreamingCount (void) const
 
bool SetAPIVersion (void)
 
bool OpenApp (void)
 
void CloseApp (void)
 

Private Attributes

QString m_loc
 
int m_majorId
 
QMutex m_ioLock
 
ExternIOm_io {nullptr}
 
QStringList m_args
 
QString m_app
 
bool m_tsOpen {false}
 
int m_ioErrCnt {0}
 
bool m_pollMode {false}
 
int m_apiVersion {1}
 
uint m_serialNo {0}
 
bool m_hasTuner {false}
 
bool m_hasPictureAttributes {false}
 
QByteArray m_replayBuffer
 
bool m_replay {false}
 
bool m_xon {false}
 
QAtomicInt m_streamingCnt
 
QMutex m_streamLock
 
QMutex m_replayLock
 
QMutex m_processLock
 

Static Private Attributes

static QMutex s_handlersLock
 
static QMap< int, ExternalStreamHandler * > s_handlers
 
static QMap< int, uints_handlersRefCnt
 

Additional Inherited Members

- Protected Types inherited from StreamHandler
using StreamDataList = QHash< MPEGStreamData *, QString >
 
- Protected Member Functions inherited from StreamHandler
 StreamHandler (QString device, int inputid)
 
 ~StreamHandler () override
 
void Start (void)
 
void Stop (void)
 
void SetRunning (bool running, bool using_buffering, bool using_section_reader)
 
bool AddPIDFilter (PIDInfo *info)
 
bool RemovePIDFilter (uint pid)
 
bool RemoveAllPIDFilters (void)
 
void UpdateListeningForEIT (void)
 
bool UpdateFiltersFromStreamData (void)
 
virtual bool UpdateFilters (void)
 
virtual void CycleFiltersByPriority ()
 
PIDPriority GetPIDPriority (uint pid) const
 
void ReaderPaused (int fd) override
 
void PriorityEvent (int fd) override
 
virtual PIDInfoCreatePIDInfo (uint pid, uint stream_type, int pes_type)
 
void WriteMPTS (const unsigned char *buffer, uint len)
 Write out a copy of the raw MPTS. More...
 
virtual void SetRunningDesired (bool desired)
 At minimum this sets _running_desired, this may also send signals to anything that might be blocking the run() loop. More...
 
- 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 Member Functions inherited from DeviceReaderCB
virtual ~DeviceReaderCB ()=default
 
- 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 StreamHandler
QString m_device
 
int m_inputId
 
bool m_needsBuffering {false}
 
bool m_allowSectionReader {false}
 
QMutex m_addRmLock
 
QMutex m_startStopLock
 
volatile bool m_runningDesired {false}
 
volatile bool m_bError {false}
 
bool m_running {false}
 
bool m_restarting {false}
 
bool m_usingBuffering {false}
 
bool m_usingSectionReader {false}
 
QWaitCondition m_runningStateChanged
 
QRecursiveMutex m_pidLock
 
std::vector< uintm_eitPids
 
PIDInfoMap m_pidInfo
 
uint m_openPidFilters {0}
 
bool m_filtersChanged {false}
 
MythTimer m_cycleTimer
 
ThreadedFileWriterm_mptsTfw {nullptr}
 
QSet< QString > m_mptsFiles
 
QString m_mptsBaseFile
 
QMutex m_mptsLock
 
QRecursiveMutex m_listenerLock
 
StreamDataList m_streamDataList
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 

Detailed Description

Definition at line 68 of file ExternalStreamHandler.h.

Member Enumeration Documentation

◆ constants

Enumerator
MAX_API_VERSION 
TS_PACKET_SIZE 
PACKET_SIZE 
TOO_FAST_SIZE 

Definition at line 70 of file ExternalStreamHandler.h.

Constructor & Destructor Documentation

◆ ExternalStreamHandler()

ExternalStreamHandler::ExternalStreamHandler ( const QString &  path,
int  inputid,
int  majorid 
)
explicit

Definition at line 535 of file ExternalStreamHandler.cpp.

Referenced by Get().

◆ ~ExternalStreamHandler()

ExternalStreamHandler::~ExternalStreamHandler ( void  )
inlineoverride

Definition at line 83 of file ExternalStreamHandler.h.

Member Function Documentation

◆ Get()

ExternalStreamHandler * ExternalStreamHandler::Get ( const QString &  devname,
int  inputid,
int  majorid 
)
static

◆ Return()

void ExternalStreamHandler::Return ( ExternalStreamHandler *&  ref,
int  inputid 
)
static

◆ run()

void ExternalStreamHandler::run ( void  )
overridevirtual

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 569 of file ExternalStreamHandler.cpp.

◆ PriorityEvent()

void ExternalStreamHandler::PriorityEvent ( int  fd)
overridevirtual

Implements DeviceReaderCB.

Definition at line 1543 of file ExternalStreamHandler.cpp.

◆ GetDescription()

QString ExternalStreamHandler::GetDescription ( void  )
inline

Definition at line 88 of file ExternalStreamHandler.h.

Referenced by ExternalChannel::GetDescription().

◆ UpdateDescription()

QString ExternalStreamHandler::UpdateDescription ( void  )

◆ IsAppOpen()

bool ExternalStreamHandler::IsAppOpen ( void  )

◆ IsTSOpen()

bool ExternalStreamHandler::IsTSOpen ( void  )

Definition at line 1005 of file ExternalStreamHandler.cpp.

Referenced by run().

◆ HasTuner()

bool ExternalStreamHandler::HasTuner ( void  ) const
inline

◆ HasPictureAttributes()

bool ExternalStreamHandler::HasPictureAttributes ( void  ) const
inline

Definition at line 93 of file ExternalStreamHandler.h.

◆ RestartStream()

bool ExternalStreamHandler::RestartStream ( void  )

Definition at line 1057 of file ExternalStreamHandler.cpp.

Referenced by run().

◆ LockReplay()

void ExternalStreamHandler::LockReplay ( void  )
inline

Definition at line 97 of file ExternalStreamHandler.h.

◆ UnlockReplay()

void ExternalStreamHandler::UnlockReplay ( bool  enable_replay = false)
inline

Definition at line 98 of file ExternalStreamHandler.h.

◆ ReplayStream()

void ExternalStreamHandler::ReplayStream ( void  )

Definition at line 1074 of file ExternalStreamHandler.cpp.

◆ StartStreaming()

bool ExternalStreamHandler::StartStreaming ( void  )

◆ StopStreaming()

bool ExternalStreamHandler::StopStreaming ( void  )

◆ CheckForError()

bool ExternalStreamHandler::CheckForError ( void  )

Definition at line 1489 of file ExternalStreamHandler.cpp.

Referenced by run().

◆ PurgeBuffer()

void ExternalStreamHandler::PurgeBuffer ( void  )

Definition at line 1533 of file ExternalStreamHandler.cpp.

Referenced by StopStreaming().

◆ ProcessCommand()

bool ExternalStreamHandler::ProcessCommand ( const QString &  cmd,
QString &  result,
std::chrono::milliseconds  timeout = 4s,
uint  retry_cnt = 3 
)

◆ ProcessVer1()

bool ExternalStreamHandler::ProcessVer1 ( const QString &  cmd,
QString &  result,
std::chrono::milliseconds  timeout,
uint  retry_cnt 
)

Definition at line 1241 of file ExternalStreamHandler.cpp.

Referenced by ProcessCommand().

◆ ProcessVer2()

bool ExternalStreamHandler::ProcessVer2 ( const QString &  command,
QString &  result,
std::chrono::milliseconds  timeout,
uint  retry_cnt 
)

Definition at line 1347 of file ExternalStreamHandler.cpp.

Referenced by ProcessCommand().

◆ StreamingCount()

int ExternalStreamHandler::StreamingCount ( void  ) const
private

Definition at line 564 of file ExternalStreamHandler.cpp.

Referenced by RestartStream(), run(), StartStreaming(), and StopStreaming().

◆ SetAPIVersion()

bool ExternalStreamHandler::SetAPIVersion ( void  )
private

Definition at line 859 of file ExternalStreamHandler.cpp.

Referenced by OpenApp().

◆ OpenApp()

bool ExternalStreamHandler::OpenApp ( void  )
private

Definition at line 899 of file ExternalStreamHandler.cpp.

Referenced by ExternalStreamHandler().

◆ CloseApp()

void ExternalStreamHandler::CloseApp ( void  )
private

Definition at line 1019 of file ExternalStreamHandler.cpp.

Referenced by run(), and ~ExternalStreamHandler().

Member Data Documentation

◆ m_loc

QString ExternalStreamHandler::m_loc
private

Definition at line 122 of file ExternalStreamHandler.h.

Referenced by GetDescription(), and UpdateDescription().

◆ m_majorId

int ExternalStreamHandler::m_majorId
private

Definition at line 123 of file ExternalStreamHandler.h.

Referenced by Return().

◆ m_ioLock

QMutex ExternalStreamHandler::m_ioLock
private

Definition at line 124 of file ExternalStreamHandler.h.

Referenced by CheckForError(), CloseApp(), OpenApp(), ProcessVer1(), and ProcessVer2().

◆ m_io

ExternIO* ExternalStreamHandler::m_io {nullptr}
private

◆ m_args

QStringList ExternalStreamHandler::m_args
private

Definition at line 126 of file ExternalStreamHandler.h.

Referenced by CloseApp(), ExternalStreamHandler(), and OpenApp().

◆ m_app

QString ExternalStreamHandler::m_app
private

Definition at line 127 of file ExternalStreamHandler.h.

Referenced by ExternalStreamHandler(), and OpenApp().

◆ m_tsOpen

bool ExternalStreamHandler::m_tsOpen {false}
private

Definition at line 128 of file ExternalStreamHandler.h.

Referenced by IsTSOpen().

◆ m_ioErrCnt

int ExternalStreamHandler::m_ioErrCnt {0}
private

Definition at line 129 of file ExternalStreamHandler.h.

Referenced by ProcessVer1(), and ProcessVer2().

◆ m_pollMode

bool ExternalStreamHandler::m_pollMode {false}
private

Definition at line 130 of file ExternalStreamHandler.h.

Referenced by OpenApp(), ReplayStream(), run(), and StopStreaming().

◆ m_apiVersion

int ExternalStreamHandler::m_apiVersion {1}
private

◆ m_serialNo

uint ExternalStreamHandler::m_serialNo {0}
private

Definition at line 133 of file ExternalStreamHandler.h.

Referenced by ProcessVer2().

◆ m_hasTuner

bool ExternalStreamHandler::m_hasTuner {false}
private

Definition at line 134 of file ExternalStreamHandler.h.

Referenced by HasTuner(), and OpenApp().

◆ m_hasPictureAttributes

bool ExternalStreamHandler::m_hasPictureAttributes {false}
private

Definition at line 135 of file ExternalStreamHandler.h.

Referenced by HasPictureAttributes(), and OpenApp().

◆ m_replayBuffer

QByteArray ExternalStreamHandler::m_replayBuffer
private

Definition at line 137 of file ExternalStreamHandler.h.

Referenced by ReplayStream(), and run().

◆ m_replay

bool ExternalStreamHandler::m_replay {false}
private

Definition at line 138 of file ExternalStreamHandler.h.

Referenced by ReplayStream(), run(), and UnlockReplay().

◆ m_xon

bool ExternalStreamHandler::m_xon {false}
private

Definition at line 139 of file ExternalStreamHandler.h.

Referenced by ReplayStream(), run(), and StopStreaming().

◆ s_handlersLock

QMutex ExternalStreamHandler::s_handlersLock
staticprivate

Definition at line 142 of file ExternalStreamHandler.h.

Referenced by Get(), and Return().

◆ s_handlers

QMap< int, ExternalStreamHandler * > ExternalStreamHandler::s_handlers
staticprivate

Definition at line 143 of file ExternalStreamHandler.h.

Referenced by Get(), and Return().

◆ s_handlersRefCnt

QMap< int, uint > ExternalStreamHandler::s_handlersRefCnt
staticprivate

Definition at line 144 of file ExternalStreamHandler.h.

Referenced by Get(), and Return().

◆ m_streamingCnt

QAtomicInt ExternalStreamHandler::m_streamingCnt
private

Definition at line 146 of file ExternalStreamHandler.h.

Referenced by StartStreaming(), StopStreaming(), and StreamingCount().

◆ m_streamLock

QMutex ExternalStreamHandler::m_streamLock
private

Definition at line 147 of file ExternalStreamHandler.h.

Referenced by run(), StartStreaming(), and StopStreaming().

◆ m_replayLock

QMutex ExternalStreamHandler::m_replayLock
private

Definition at line 148 of file ExternalStreamHandler.h.

Referenced by LockReplay(), and UnlockReplay().

◆ m_processLock

QMutex ExternalStreamHandler::m_processLock
private

Definition at line 149 of file ExternalStreamHandler.h.

Referenced by ProcessCommand().


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