00001
00002
00003 #ifndef _DVBSTREAMHANDLER_H_
00004 #define _DVBSTREAMHANDLER_H_
00005
00006 #include <vector>
00007 using namespace std;
00008
00009 #include <qmap.h>
00010 #include <qmutex.h>
00011
00012 #include "util.h"
00013 #include "DeviceReadBuffer.h"
00014 #include "mpegstreamdata.h"
00015
00016 class QString;
00017 class DVBStreamHandler;
00018 class DTVSignalMonitor;
00019 class DVBChannel;
00020 class DeviceReadBuffer;
00021
00022 typedef QMap<uint,int> FilterMap;
00023
00024
00025
00026 class PIDInfo
00027 {
00028 public:
00029 PIDInfo() :
00030 _pid(0xffffffff), filter_fd(-1), streamType(0), pesType(-1) {;}
00031 PIDInfo(uint pid) :
00032 _pid(pid), filter_fd(-1), streamType(0), pesType(-1) {;}
00033 PIDInfo(uint pid, uint stream_type, uint pes_type) :
00034 _pid(pid), filter_fd(-1),
00035 streamType(stream_type), pesType(pes_type) {;}
00036
00037 bool Open(uint dvb_dev_num, bool use_section_reader);
00038 bool Close(uint dvb_dev_num);
00039 bool IsOpen(void) const { return filter_fd >= 0; }
00040
00041 uint _pid;
00042 int filter_fd;
00043 uint streamType;
00044 int pesType;
00045 };
00046 typedef QMap<uint,PIDInfo*> PIDInfoMap;
00047
00048 class DVBStreamHandler : public ReaderPausedCB
00049 {
00050 friend void *run_dvb_stream_handler_thunk(void *param);
00051
00052 public:
00053 static DVBStreamHandler *Get(uint dvb_device_number);
00054 static void Return(DVBStreamHandler * & ref);
00055
00056 void AddListener(MPEGStreamData *data,
00057 bool allow_section_reader,
00058 bool needs_buffering);
00059 void RemoveListener(MPEGStreamData *data);
00060
00061 void RetuneMonitor(void);
00062
00063 bool IsRunning(void) const { return _running; }
00064 bool IsRetuneAllowed(void) const { return _allow_retune; }
00065
00066 void SetRetuneAllowed(bool allow,
00067 DTVSignalMonitor *sigmon,
00068 DVBChannel *dvbchan);
00069
00070
00071 virtual void ReaderPaused(int fd) { (void) fd; }
00072
00073 private:
00074 DVBStreamHandler(uint);
00075 ~DVBStreamHandler();
00076
00077 void Start(void);
00078 void Stop(void);
00079
00080 void Run(void);
00081 void RunTS(void);
00082 void RunSR(void);
00083
00084 void UpdateListeningForEIT(void);
00085 bool UpdateFiltersFromStreamData(void);
00086 bool AddPIDFilter(PIDInfo *info);
00087 bool RemovePIDFilter(uint pid);
00088 bool RemoveAllPIDFilters(void);
00089 void CycleFiltersByPriority(void);
00090
00091 void SetRunning(bool);
00092
00093 PIDPriority GetPIDPriority(uint pid) const;
00094 bool SupportsTSMonitoring(void);
00095
00096 private:
00097 uint _dvb_dev_num;
00098 QString _dvr_dev_path;
00099 bool _allow_section_reader;
00100 bool _needs_buffering;
00101 bool _allow_retune;
00102
00103 mutable QMutex _start_stop_lock;
00104 bool _running;
00105 QWaitCondition _running_state_changed;
00106 pthread_t _reader_thread;
00107 bool _using_section_reader;
00108 DeviceReadBuffer *_device_read_buffer;
00109 DTVSignalMonitor *_sigmon;
00110 DVBChannel *_dvbchannel;
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 mutable QMutex _listener_lock;
00119 vector<MPEGStreamData*> _stream_data_list;
00120
00121
00122 static QMutex _rec_supports_ts_monitoring_lock;
00123 static QMap<uint,bool> _rec_supports_ts_monitoring;
00124
00125
00126 static QMutex _handlers_lock;
00127 static QMap<uint,DVBStreamHandler*> _handlers;
00128 static QMap<uint,uint> _handlers_refcnt;
00129 };
00130
00131 #endif // _DVBSTREAMHANDLER_H_