00001
00002
00003 #ifndef _STREAM_HANDLER_H_
00004 #define _STREAM_HANDLER_H_
00005
00006 #include <vector>
00007 using namespace std;
00008
00009 #include <QWaitCondition>
00010 #include <QString>
00011 #include <QMutex>
00012 #include <QMap>
00013
00014 #include "DeviceReadBuffer.h"
00015 #include "mpegstreamdata.h"
00016 #include "mthread.h"
00017 #include "mythmiscutil.h"
00018
00019
00020
00021 class PIDInfo
00022 {
00023 public:
00024 PIDInfo() :
00025 _pid(0xffffffff), filter_fd(-1), streamType(0), pesType(-1) {;}
00026 PIDInfo(uint pid) :
00027 _pid(pid), filter_fd(-1), streamType(0), pesType(-1) {;}
00028 PIDInfo(uint pid, uint stream_type, int pes_type) :
00029 _pid(pid), filter_fd(-1),
00030 streamType(stream_type), pesType(pes_type) {;}
00031
00032 virtual bool Open(const QString &dev, bool use_section_reader)
00033 { return false; }
00034 virtual bool Close(const QString &dev) { return false; }
00035 bool IsOpen(void) const { return filter_fd >= 0; }
00036
00037 uint _pid;
00038 int filter_fd;
00039 uint streamType;
00040 int pesType;
00041 };
00042
00043
00044
00045 typedef QMap<uint,PIDInfo*> PIDInfoMap;
00046
00047
00048
00049
00050 class StreamHandler : protected MThread, public DeviceReaderCB
00051 {
00052 public:
00053 virtual void AddListener(MPEGStreamData *data,
00054 bool allow_section_reader = false,
00055 bool needs_drb = false,
00056 QString output_file = QString());
00057 virtual void RemoveListener(MPEGStreamData *data);
00058 bool IsRunning(void) const;
00059
00060 protected:
00061 StreamHandler(const QString &device);
00062 ~StreamHandler();
00063
00064 void Start(void);
00065 void Stop(void);
00066
00067 void SetRunning(bool running,
00068 bool using_buffering,
00069 bool using_section_reader);
00070
00071 bool AddPIDFilter(PIDInfo *info);
00072 bool RemovePIDFilter(uint pid);
00073 bool RemoveAllPIDFilters(void);
00074
00075 void UpdateListeningForEIT(void);
00076 bool UpdateFiltersFromStreamData(void);
00077 virtual bool UpdateFilters(void) { return true; }
00078 virtual void CycleFiltersByPriority() {}
00079
00080 PIDPriority GetPIDPriority(uint pid) const;
00081
00082
00083 virtual void ReaderPaused(int fd) { (void) fd; }
00084 virtual void PriorityEvent(int fd) { (void) fd; }
00085
00086 virtual PIDInfo *CreatePIDInfo(uint pid, uint stream_type, int pes_type)
00087 { return new PIDInfo(pid, stream_type, pes_type); }
00088
00089 protected:
00091 virtual void AddNamedOutputFile(const QString &filename) {}
00093 virtual void RemoveNamedOutputFile(const QString &filename) {}
00097 virtual void SetRunningDesired(bool desired) { _running_desired = desired; }
00098
00099 protected:
00100 QString _device;
00101 bool _needs_buffering;
00102 bool _allow_section_reader;
00103
00104 mutable QMutex _start_stop_lock;
00105 volatile bool _running_desired;
00106 volatile bool _error;
00107 bool _running;
00108 bool _using_buffering;
00109 bool _using_section_reader;
00110 QWaitCondition _running_state_changed;
00111
00112 mutable QMutex _pid_lock;
00113 vector<uint> _eit_pids;
00114 PIDInfoMap _pid_info;
00115 uint _open_pid_filters;
00116 MythTimer _cycle_timer;
00117
00118 typedef QMap<MPEGStreamData*,QString> StreamDataList;
00119 mutable QMutex _listener_lock;
00120 StreamDataList _stream_data_list;
00121 };
00122
00123 #endif // _STREAM_HANDLER_H_