00001 // -*- Mode: c++ -*- 00009 #ifndef DTVRECORDER_H 00010 #define DTVRECORDER_H 00011 00012 #include <vector> 00013 using namespace std; 00014 00015 #include <qdatetime.h> 00016 00017 #include "recorderbase.h" 00018 #include "h264utils.h" 00019 00020 class MPEGStreamData; 00021 class TSPacket; 00022 class QTime; 00023 00024 class DTVRecorder: public RecorderBase 00025 { 00026 public: 00027 DTVRecorder(TVRec *rec); 00028 ~DTVRecorder(); 00029 00030 virtual void SetOption(const QString &opt, const QString &value); 00031 virtual void SetOption(const QString &name, int value); 00032 00033 virtual void StopRecording(void) { _request_recording = false; } 00034 bool IsRecording(void) { return _recording; } 00035 bool IsErrored(void) { return _error; } 00036 00037 long long GetKeyframePosition(long long desired); 00038 long long GetFramesWritten(void) { return _frames_written_count; } 00039 00040 void SetVideoFilters(QString &/*filters*/) {;} 00041 void Initialize(void) {;} 00042 int GetVideoFd(void) { return _stream_fd; } 00043 00044 virtual void SetNextRecording(const ProgramInfo*, RingBuffer*); 00045 virtual void SetStreamData(MPEGStreamData*) {} 00046 virtual MPEGStreamData *GetStreamData(void) { return NULL; } 00047 00048 virtual void Reset(); 00049 00050 protected: 00051 void FinishRecording(void); 00052 void ResetForNewFile(void); 00053 00054 void HandleKeyframe(); 00055 00056 void BufferedWrite(const TSPacket &tspacket); 00057 00058 // MPEG "audio only" support 00059 bool FindAudioKeyframes(const TSPacket *tspacket); 00060 00061 // MPEG2 support 00062 bool FindMPEG2Keyframes(const TSPacket* tspacket); 00063 00064 // MPEG4 AVC / H.264 support 00065 bool FindH264Keyframes(const TSPacket* tspacket); 00066 void HandleH264Keyframe(void); 00067 00068 // For handling other (non audio/video) packets 00069 bool FindOtherKeyframes(const TSPacket *tspacket); 00070 00071 // file handle for stream 00072 int _stream_fd; 00073 00074 QString _recording_type; 00075 00076 // used for scanning pes headers for keyframes 00077 QTime _audio_timer; 00078 uint32_t _start_code; 00079 int _first_keyframe; 00080 unsigned long long _last_gop_seen; 00081 unsigned long long _last_seq_seen; 00082 unsigned long long _last_keyframe_seen; 00083 00084 // H.264 support 00085 bool _pes_synced; 00086 bool _seen_sps; 00087 H264::KeyframeSequencer _h264_kf_seq; 00088 00090 bool _request_recording; 00092 bool _wait_for_keyframe_option; 00093 00094 bool _has_written_other_keyframe; 00095 00096 // state tracking variables 00098 bool _recording; 00100 bool _error; 00101 00102 // packet buffer 00103 unsigned char* _buffer; 00104 int _buffer_size; 00105 00106 // keyframe finding buffer 00107 bool _buffer_packets; 00108 vector<unsigned char> _payload_buffer; 00109 00110 // statistics 00111 unsigned long long _frames_seen_count; 00112 unsigned long long _frames_written_count; 00113 00114 // constants 00118 static const uint kMaxKeyFrameDistance; 00119 }; 00120 00121 #endif // DTVRECORDER_H
1.5.5