Ticket #1164: firewire.diff
File firewire.diff, 6.1 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/firewirerecorder.cpp
15 15 // MythTV includes 16 16 #include "firewirerecorder.h" 17 17 #include "mythcontext.h" 18 #include "tspacket.h" 18 #include "mpegtables.h" 19 #include "mpegstreamdata.h" 19 20 #include "tv_rec.h" 20 21 21 22 // callback function for libiec61883 … … 44 45 return 1; 45 46 } 46 47 48 FirewireRecorder::FirewireRecorder(TVRec *rec) 49 : DTVRecorder(rec, "FirewireRecorder"), 50 fwport(-1), fwchannel(-1), fwspeed(-1), fwbandwidth(-1), 51 fwfd(-1), fwconnection(FIREWIRE_CONNECTION_P2P), 52 fwoplug(-1), fwiplug(-1), fwmodel(""), fwnode(0), 53 fwhandle(NULL), fwmpeg(NULL), isopen(false), lastpacket(0), 54 _mpeg_stream_data(NULL) 55 { 56 57 _mpeg_stream_data = new MPEGStreamData(1, true); 58 connect(_mpeg_stream_data, SIGNAL(UpdatePATSingleProgram( 59 ProgramAssociationTable*)), 60 this, SLOT(WritePAT(ProgramAssociationTable*))); 61 connect(_mpeg_stream_data, SIGNAL(UpdatePMTSingleProgram(ProgramMapTable*)), 62 this, SLOT(WritePMT(ProgramMapTable*))); 63 64 } 65 66 FirewireRecorder::~FirewireRecorder() 67 { 68 Close(); 69 if (_mpeg_stream_data) 70 delete(_mpeg_stream_data); 71 } 72 47 73 void FirewireRecorder::deleteLater(void) 48 74 { 49 75 Close(); … … 55 81 if (isopen) 56 82 return true; 57 83 84 if(!_mpeg_stream_data) 85 return false; 86 58 87 VERBOSE(VB_GENERAL,QString("Firewire: Initializing Port: %1, Node: %2, Speed: %3") 59 88 .arg(fwport) 60 89 .arg(fwnode) … … 113 142 return true; 114 143 } 115 144 145 void FirewireRecorder::SetStreamData(MPEGStreamData *stream_data) 146 { 147 if (stream_data == _mpeg_stream_data) 148 return; 149 150 MPEGStreamData *old_data = _mpeg_stream_data; 151 _mpeg_stream_data = stream_data; 152 if (old_data) 153 delete old_data; 154 } 155 116 156 void FirewireRecorder::Close(void) 117 157 { 118 158 if (!isopen) … … 189 229 _recording = false; 190 230 } 191 231 232 void FirewireRecorder::WritePAT(ProgramAssociationTable *pat) 233 { 234 if (!pat) 235 return; 236 237 int next = (pat->tsheader()->ContinuityCounter()+1)&0xf; 238 pat->tsheader()->SetContinuityCounter(next); 239 BufferedWrite(*(reinterpret_cast<TSPacket*>(pat->tsheader()))); 240 } 241 242 void FirewireRecorder::WritePMT(ProgramMapTable* pmt) 243 { 244 if (!pmt) 245 return; 246 247 int next = (pmt->tsheader()->ContinuityCounter()+1)&0xf; 248 pmt->tsheader()->SetContinuityCounter(next); 249 BufferedWrite(*(reinterpret_cast<TSPacket*>(pmt->tsheader()))); 250 } 251 192 252 void FirewireRecorder::ProcessTSPacket(const TSPacket &tspacket) 193 253 { 194 lastpacket = time(NULL); 195 _buffer_packets = !FindKeyframes(&tspacket); 196 BufferedWrite(tspacket); 254 255 bool ok = !tspacket.TransportError(); 256 if (ok && !tspacket.ScramplingControl()) 257 { 258 if (tspacket.HasAdaptationField()) 259 StreamData()->HandleAdaptationFieldControl(&tspacket); 260 if (tspacket.HasPayload()) 261 { 262 const unsigned int lpid = tspacket.PID(); 263 // Pass or reject frames based on PID, and parse info from them 264 if (lpid == StreamData()->VideoPIDSingleProgram()) 265 { 266 _buffer_packets = !FindKeyframes(&tspacket); 267 BufferedWrite(tspacket); 268 } 269 else if (StreamData()->IsAudioPID(lpid)) 270 BufferedWrite(tspacket); 271 else if (StreamData()->IsListeningPID(lpid)) 272 StreamData()->HandleTSTables(&tspacket); 273 else if (StreamData()->IsWritingPID(lpid)) 274 BufferedWrite(tspacket); 275 } 276 } 277 278 if (ok) 279 { 280 lastpacket = time(NULL); 281 _ts_stats.IncrTSPacketCount(); 282 if (0 == _ts_stats.TSPacketCount()%1000000) 283 VERBOSE(VB_RECORD, _ts_stats.toString()); 284 } 197 285 } 198 286 199 287 void FirewireRecorder::SetOptionsFromProfile(RecordingProfile *profile, -
libs/libmythtv/firewirerecorder.h
8 8 #define FIREWIRERECORDER_H_ 9 9 10 10 #include "dtvrecorder.h" 11 #include " mpeg/tspacket.h"11 #include "tsstats.h" 12 12 #include <libraw1394/raw1394.h> 13 13 #include <libiec61883/iec61883.h> 14 15 14 #include <time.h> 16 15 16 class MPEGStreamData; 17 class ProgramAssociationTable; 18 class ProgramMapTable; 19 17 20 #define FIREWIRE_TIMEOUT 15 18 21 19 22 #define FIREWIRE_CONNECTION_P2P 0 … … 29 32 */ 30 33 class FirewireRecorder : public DTVRecorder 31 34 { 35 Q_OBJECT 36 friend class MPEGStreamData; 37 friend class TSPacketProcessor; 38 32 39 public: 33 FirewireRecorder(TVRec *rec) : 34 DTVRecorder(rec, "FirewireRecorder"), 35 fwport(-1), fwchannel(-1), fwspeed(-1), fwbandwidth(-1), 36 fwfd(-1), fwconnection(FIREWIRE_CONNECTION_P2P), 37 fwoplug(-1), fwiplug(-1), fwmodel(""), fwnode(0), 38 fwhandle(NULL), fwmpeg(NULL), isopen(false), lastpacket(0) {;} 39 40 ~FirewireRecorder() { Close(); } 40 FirewireRecorder(TVRec *rec); 41 ~FirewireRecorder(); 41 42 42 43 void StartRecording(void); 43 44 bool Open(void); … … 50 51 void SetOption(const QString &name, const QString &value); 51 52 void SetOption(const QString &name, int value); 52 53 QString FirewireSpeedString(int speed); 54 void SetStreamData(MPEGStreamData*); 55 MPEGStreamData* StreamData(void) { return _mpeg_stream_data; } 53 56 54 57 bool PauseAndWait(int timeout = 100); 55 58 … … 58 61 59 62 private: 60 63 void Close(void); 64 65 private slots: 66 void WritePAT(ProgramAssociationTable*); 67 void WritePMT(ProgramMapTable*); 68 69 private: 61 70 int fwport, fwchannel, fwspeed, fwbandwidth, fwfd, fwconnection; 62 71 int fwoplug, fwiplug; 63 72 QString fwmodel; … … 66 75 iec61883_mpeg2_t fwmpeg; 67 76 bool isopen; 68 77 time_t lastpacket; 78 MPEGStreamData* _mpeg_stream_data; 79 TSStats _ts_stats; 80 69 81 }; 70 82 71 83 #endif