00001
00002
00003
00004
00005
00006
00007
00008 #ifndef DVBRECORDER_H
00009 #define DVBRECORDER_H
00010
00011
00012 #include <vector>
00013 #include <deque>
00014 using namespace std;
00015
00016
00017 #include <qmutex.h>
00018
00019 #include "dtvrecorder.h"
00020 #include "tspacket.h"
00021 #include "DeviceReadBuffer.h"
00022
00023 class DVBChannel;
00024 class MPEGStreamData;
00025 class ProgramAssociationTable;
00026 class ProgramMapTable;
00027 class TSPacket;
00028 class DVBStreamHandler;
00029
00030 typedef vector<uint> uint_vec_t;
00031
00038 class DVBRecorder :
00039 public DTVRecorder,
00040 public MPEGStreamListener,
00041 public MPEGSingleProgramStreamListener,
00042 public DVBMainStreamListener,
00043 public ATSCMainStreamListener,
00044 public TSPacketListener,
00045 public TSPacketListenerAV,
00046 private ReaderPausedCB
00047 {
00048 public:
00049 DVBRecorder(TVRec *rec, DVBChannel* dvbchannel);
00050 ~DVBRecorder();
00051
00052 void SetOption(const QString &name, int value);
00053
00054 void SetOptionsFromProfile(RecordingProfile *profile,
00055 const QString &videodev,
00056 const QString &audiodev,
00057 const QString &vbidev);
00058
00059 void StartRecording(void);
00060 void ResetForNewFile(void);
00061 void StopRecording(void);
00062
00063 bool Open(void);
00064 bool IsOpen(void) const { return _stream_fd >= 0; }
00065 void Close(void);
00066
00067 void HandlePAT(const ProgramAssociationTable*);
00068 void HandleCAT(const ConditionalAccessTable*) {}
00069 void HandlePMT(uint pid, const ProgramMapTable*);
00070 void HandleEncryptionStatus(uint , bool ) { }
00071
00072
00073 void HandleSingleProgramPAT(ProgramAssociationTable *pat);
00074 void HandleSingleProgramPMT(ProgramMapTable*);
00075
00076
00077 void HandleSTT(const SystemTimeTable*);
00078 void HandleVCT(uint , const VirtualChannelTable*) {}
00079 void HandleMGT(const MasterGuideTable*) {}
00080
00081
00082 void HandleTDT(const TimeDateTable*);
00083 void HandleNIT(const NetworkInformationTable*) {}
00084 void HandleSDT(uint , const ServiceDescriptionTable*) {}
00085
00086
00087 bool ProcessTSPacket(const TSPacket& tspacket);
00088
00089
00090 bool ProcessVideoTSPacket(const TSPacket& tspacket);
00091 bool ProcessAudioTSPacket(const TSPacket& tspacket);
00092
00093
00094 bool ProcessAVTSPacket(const TSPacket &tspacket);
00095
00096 void SetStreamData(MPEGStreamData*);
00097 MPEGStreamData* GetStreamData(void) { return _stream_data; }
00098
00099 void BufferedWrite(const TSPacket &tspacket);
00100
00101 private:
00102 void TeardownAll(void);
00103
00104 inline bool CheckCC(uint pid, uint cc);
00105
00106 void ReaderPaused(int fd);
00107 bool PauseAndWait(int timeout = 100);
00108
00109 private:
00110
00111 int _card_number_option;
00112
00113
00114 DVBChannel *dvbchannel;
00115 DVBStreamHandler *_stream_handler;
00116
00117
00118 MPEGStreamData *_stream_data;
00119 mutable QMutex _pid_lock;
00120 ProgramAssociationTable *_input_pat;
00121 ProgramMapTable *_input_pmt;
00122 bool _has_no_av;
00123
00124
00125 unsigned char _stream_id[0x1fff];
00126 unsigned char _pid_status[0x1fff];
00127 unsigned char _continuity_counter[0x1fff];
00128
00129
00130 mutable uint _continuity_error_count;
00131 mutable uint _stream_overflow_count;
00132 mutable uint _bad_packet_count;
00133
00134
00135 static const int TSPACKETS_BETWEEN_PSIP_SYNC;
00136 static const int POLL_INTERVAL;
00137 static const int POLL_WARNING_TIMEOUT;
00138
00139 static const unsigned char kPayloadStartSeen = 0x2;
00140 };
00141
00142
00143 inline bool DVBRecorder::CheckCC(uint pid, uint new_cnt)
00144 {
00145 bool ok = ((((_continuity_counter[pid] + 1) & 0xf) == new_cnt) ||
00146 (_continuity_counter[pid] == 0xFF));
00147
00148 _continuity_counter[pid] = new_cnt & 0xf;
00149
00150 return ok;
00151 }
00152
00153 #endif