DTVRecorder Class Reference

This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC, DVB and ATSC streams. More...

#include <dtvrecorder.h>

Inheritance diagram for DTVRecorder:
RecorderBase MPEGStreamListener MPEGSingleProgramStreamListener DVBMainStreamListener ATSCMainStreamListener TSPacketListener TSPacketListenerAV ASIRecorder CetonRecorder DVBRecorder FirewireRecorder HDHRRecorder ImportRecorder IPTVRecorder V4LRecorder

List of all members.

Public Member Functions

 DTVRecorder (TVRec *rec)
virtual ~DTVRecorder ()
virtual void SetOption (const QString &opt, const QString &value)
 Set an specific option.
virtual void SetOption (const QString &name, int value)
 handles the "wait_for_seqstart" option.
virtual void SetOptionsFromProfile (RecordingProfile *profile, const QString &videodev, const QString &, const QString &)
 Sets basic recorder options.
bool IsErrored (void)
 Tells us whether an unrecoverable error has been encountered.
long long GetFramesWritten (void)
 Returns number of frames written to disk.
void SetVideoFilters (QString &)
 Tells recorder which filters to use.
void Initialize (void)
 This is called between SetOptionsFromProfile() and run() to initialize any devices, etc.
int GetVideoFd (void)
 Returns file descriptor of recorder device.
virtual void SetNextRecording (const ProgramInfo *, RingBuffer *)
 Sets next recording info, to be applied as soon as practical.
virtual void SetStreamData (void)
void SetStreamData (MPEGStreamData *sd)
MPEGStreamDataGetStreamData (void) const
virtual void Reset (void)
 Reset the recorder to the startup state.
virtual void ClearStatistics (void)
virtual RecordingQualityGetRecordingQuality (void) const
 Returns a report about the current recordings quality.
void HandlePAT (const ProgramAssociationTable *)
void HandleCAT (const ConditionalAccessTable *)
void HandlePMT (uint pid, const ProgramMapTable *)
void HandleEncryptionStatus (uint, bool)
void HandleSingleProgramPAT (ProgramAssociationTable *pat)
void HandleSingleProgramPMT (ProgramMapTable *pmt)
void HandleSTT (const SystemTimeTable *)
void HandleVCT (uint, const VirtualChannelTable *)
void HandleMGT (const MasterGuideTable *)
void HandleTDT (const TimeDateTable *)
void HandleNIT (const NetworkInformationTable *)
void HandleSDT (uint, const ServiceDescriptionTable *)
bool ProcessTSPacket (const TSPacket &tspacket)
bool ProcessVideoTSPacket (const TSPacket &tspacket)
bool ProcessAudioTSPacket (const TSPacket &tspacket)
bool ProcessAVTSPacket (const TSPacket &tspacket)
 Common code for processing either audio or video packets.

Protected Member Functions

void FinishRecording (void)
 Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesize.
void ResetForNewFile (void)
void HandleKeyframe (uint64_t frameNum, int64_t extra=0)
void HandleTimestamps (int stream_id, int64_t pts, int64_t dts)
void BufferedWrite (const TSPacket &tspacket)
bool FindAudioKeyframes (const TSPacket *tspacket)
bool FindMPEG2Keyframes (const TSPacket *tspacket)
 Locates the keyframes and saves them to the position map.
bool FindH264Keyframes (const TSPacket *tspacket)
 This searches the TS packet to identify keyframes.
void HandleH264Keyframe (void)
 This save the current frame to the position maps and handles ringbuffer switching.
void FindPSKeyFrames (const uint8_t *buffer, uint len)
bool FindOtherKeyframes (const TSPacket *tspacket)
 Non-Audio/Video data.
bool CheckCC (uint pid, uint cc)
virtual QString GetSIStandard (void) const
virtual void SetCAMPMT (const ProgramMapTable *)
virtual void UpdateCAMTimeOffset (void)

Protected Attributes

int _stream_fd
QString _recording_type
QTime _audio_timer
uint32_t _start_code
int _first_keyframe
unsigned long long _last_gop_seen
unsigned long long _last_seq_seen
unsigned long long _last_keyframe_seen
unsigned int _audio_bytes_remaining
unsigned int _video_bytes_remaining
unsigned int _other_bytes_remaining
int _progressive_sequence
int _repeat_pict
bool _pes_synced
bool _seen_sps
H264Parser m_h264_parser
bool _wait_for_keyframe_option
 Wait for the a GOP/SEQ-start before sending data.
bool _has_written_other_keyframe
QString _error
 non-empty iff irrecoverable recording error detected
MPEGStreamData_stream_data
bool _buffer_packets
vector< unsigned char > _payload_buffer
QMutex _pid_lock
ProgramAssociationTable_input_pat
 PAT on input side.
ProgramMapTable_input_pmt
 PMT on input side.
bool _has_no_av
unsigned char _stream_id [0x1fff+1]
unsigned char _pid_status [0x1fff+1]
unsigned char _continuity_counter [0x1fff+1]
vector< TSPacket_scratch
bool _use_pts
uint64_t _ts_count [256]
int64_t _ts_last [256]
int64_t _ts_first [256]
QDateTime _ts_first_dt [256]
QAtomicInt _packet_count
QAtomicInt _continuity_error_count
unsigned long long _frames_seen_count
unsigned long long _frames_written_count

Static Protected Attributes

static const uint kMaxKeyFrameDistance = 80
 If the number of regular frames detected since the last detected keyframe exceeds this value, then we begin marking random regular frames as keyframes.
static const unsigned char kPayloadStartSeen = 0x2

Detailed Description

This is a specialization of RecorderBase used to handle MPEG-2, MPEG-4, MPEG-4 AVC, DVB and ATSC streams.

See also:
DBox2Recorder, DVBRecorder, FirewireRecorder, HDHRRecoreder, IPTVRecorder

Definition at line 26 of file dtvrecorder.h.


Constructor & Destructor Documentation

DTVRecorder::DTVRecorder ( TVRec rec  ) 

Definition at line 47 of file dtvrecorder.cpp.

DTVRecorder::~DTVRecorder (  )  [virtual]

Definition at line 89 of file dtvrecorder.cpp.


Member Function Documentation

void DTVRecorder::SetOption ( const QString &  opt,
const QString &  value 
) [virtual]

Set an specific option.

Base options include: codec, videodevice, tvformat (ntsc,ntsc-jp,pal-m), vbiformat ("none","pal teletext","ntsc").

Reimplemented from RecorderBase.

Reimplemented in MpegRecorder, NuppelVideoRecorder, and V4LRecorder.

Definition at line 108 of file dtvrecorder.cpp.

Referenced by V4LRecorder::SetOption(), SetOption(), ImportRecorder::SetOptionsFromProfile(), and SetOptionsFromProfile().

void DTVRecorder::SetOption ( const QString &  name,
int  value 
) [virtual]

handles the "wait_for_seqstart" option.

Reimplemented from RecorderBase.

Reimplemented in ASIRecorder, MpegRecorder, NuppelVideoRecorder, and V4LRecorder.

Definition at line 122 of file dtvrecorder.cpp.

void DTVRecorder::SetOptionsFromProfile ( RecordingProfile profile,
const QString &  videodev,
const QString &  audiodev,
const QString &  vbidev 
) [virtual]

Sets basic recorder options.

SetOptionsFromProfile is used to tell the recorder about the recording profile as well as the devices to use.

Implements RecorderBase.

Reimplemented in ASIRecorder, FirewireRecorder, ImportRecorder, IPTVRecorder, MpegRecorder, and NuppelVideoRecorder.

Definition at line 130 of file dtvrecorder.cpp.

bool DTVRecorder::IsErrored ( void   )  [inline, virtual]
long long DTVRecorder::GetFramesWritten ( void   )  [inline, virtual]

Returns number of frames written to disk.

It is not always safe to seek up to this frame in a player because frames may not be written in display order.

Implements RecorderBase.

Reimplemented in NuppelVideoRecorder.

Definition at line 47 of file dtvrecorder.h.

Referenced by MpegRecorder::run().

void DTVRecorder::SetVideoFilters ( QString &  filters  )  [inline, virtual]

Tells recorder which filters to use.

These filters are used by frame grabber encoders to lower the bitrate while keeping quality good. They must execute quickly so that frames are not lost by the recorder.

Implements RecorderBase.

Reimplemented in MpegRecorder, and NuppelVideoRecorder.

Definition at line 49 of file dtvrecorder.h.

void DTVRecorder::Initialize ( void   )  [inline, virtual]

This is called between SetOptionsFromProfile() and run() to initialize any devices, etc.

Implements RecorderBase.

Reimplemented in MpegRecorder, and NuppelVideoRecorder.

Definition at line 50 of file dtvrecorder.h.

int DTVRecorder::GetVideoFd ( void   )  [inline, virtual]

Returns file descriptor of recorder device.

This is used by channel when only one open file descriptor is allowed on a device node. This is the case with video4linux devices and similar devices in BSD. It is not needed by newer drivers, such as those used for DVB.

Implements RecorderBase.

Reimplemented in MpegRecorder, and NuppelVideoRecorder.

Definition at line 51 of file dtvrecorder.h.

void DTVRecorder::SetNextRecording ( const ProgramInfo ,
RingBuffer  
) [virtual]

Sets next recording info, to be applied as soon as practical.

This should not lose any frames on the switchover, and should initialize the RingBuffer stream with headers as appropriate.

The switch does not have to happen immediately, but should happen soon. (i.e. it can wait for a key frame..)

This calls TVRec::RingBufferChanged() when the switch happens.

Implements RecorderBase.

Reimplemented in NuppelVideoRecorder.

Definition at line 672 of file dtvrecorder.cpp.

void DTVRecorder::SetStreamData ( void   )  [virtual]
void DTVRecorder::SetStreamData ( MPEGStreamData sd  ) 

Definition at line 233 of file dtvrecorder.cpp.

MPEGStreamData* DTVRecorder::GetStreamData ( void   )  const [inline]
void DTVRecorder::Reset ( void   )  [virtual]

Reset the recorder to the startup state.

This is used after Pause(bool), WaitForPause() and after the RingBuffer's StopReads() method has been called.

Implements RecorderBase.

Reimplemented in MpegRecorder, and NuppelVideoRecorder.

Definition at line 222 of file dtvrecorder.cpp.

void DTVRecorder::ClearStatistics ( void   )  [virtual]

Reimplemented from RecorderBase.

Definition at line 205 of file dtvrecorder.cpp.

Referenced by NuppelVideoRecorder::ResetForNewFile(), and ResetForNewFile().

RecordingQuality * DTVRecorder::GetRecordingQuality ( void   )  const [virtual]

Returns a report about the current recordings quality.

Reimplemented from RecorderBase.

Definition at line 1326 of file dtvrecorder.cpp.

void DTVRecorder::HandlePAT ( const ProgramAssociationTable _pat  )  [virtual]

Implements MPEGStreamListener.

Definition at line 1110 of file dtvrecorder.cpp.

void DTVRecorder::HandleCAT ( const ConditionalAccessTable  )  [inline, virtual]

Implements MPEGStreamListener.

Definition at line 64 of file dtvrecorder.h.

void DTVRecorder::HandlePMT ( uint  pid,
const ProgramMapTable _pmt 
) [virtual]

Implements MPEGStreamListener.

Definition at line 1146 of file dtvrecorder.cpp.

void DTVRecorder::HandleEncryptionStatus ( uint  ,
bool   
) [inline, virtual]

Implements MPEGStreamListener.

Definition at line 66 of file dtvrecorder.h.

void DTVRecorder::HandleSingleProgramPAT ( ProgramAssociationTable pat  )  [virtual]
void DTVRecorder::HandleSingleProgramPMT ( ProgramMapTable pmt  )  [virtual]
void DTVRecorder::HandleSTT ( const SystemTimeTable  )  [inline, virtual]

Implements ATSCMainStreamListener.

Definition at line 73 of file dtvrecorder.h.

void DTVRecorder::HandleVCT ( uint  ,
const VirtualChannelTable  
) [inline, virtual]

Implements ATSCMainStreamListener.

Definition at line 74 of file dtvrecorder.h.

void DTVRecorder::HandleMGT ( const MasterGuideTable  )  [inline, virtual]

Implements ATSCMainStreamListener.

Definition at line 75 of file dtvrecorder.h.

void DTVRecorder::HandleTDT ( const TimeDateTable  )  [inline, virtual]

Implements DVBMainStreamListener.

Definition at line 78 of file dtvrecorder.h.

void DTVRecorder::HandleNIT ( const NetworkInformationTable  )  [inline, virtual]

Implements DVBMainStreamListener.

Definition at line 79 of file dtvrecorder.h.

void DTVRecorder::HandleSDT ( uint  ,
const ServiceDescriptionTable  
) [inline, virtual]

Implements DVBMainStreamListener.

Definition at line 80 of file dtvrecorder.h.

bool DTVRecorder::ProcessTSPacket ( const TSPacket tspacket  )  [virtual]

Implements TSPacketListener.

Reimplemented in FirewireRecorder, IPTVRecorder, and MpegRecorder.

Definition at line 1213 of file dtvrecorder.cpp.

bool DTVRecorder::ProcessVideoTSPacket ( const TSPacket tspacket  )  [virtual]

Implements TSPacketListenerAV.

Definition at line 1253 of file dtvrecorder.cpp.

bool DTVRecorder::ProcessAudioTSPacket ( const TSPacket tspacket  )  [virtual]

Implements TSPacketListenerAV.

Definition at line 1275 of file dtvrecorder.cpp.

bool DTVRecorder::ProcessAVTSPacket ( const TSPacket tspacket  ) 

Common code for processing either audio or video packets.

Definition at line 1285 of file dtvrecorder.cpp.

Referenced by ProcessAudioTSPacket(), and ProcessVideoTSPacket().

void DTVRecorder::FinishRecording ( void   )  [protected, virtual]

Flushes the ringbuffer, and if this is not a live LiveTV recording saves the position map and filesize.

Implements RecorderBase.

Reimplemented in NuppelVideoRecorder.

Definition at line 143 of file dtvrecorder.cpp.

Referenced by MpegRecorder::run(), IPTVRecorder::run(), ImportRecorder::run(), HDHRRecorder::run(), FirewireRecorder::run(), DVBRecorder::run(), CetonRecorder::run(), and ASIRecorder::run().

void DTVRecorder::ResetForNewFile ( void   )  [protected, virtual]
void DTVRecorder::HandleKeyframe ( uint64_t  frameNum,
int64_t  extra = 0 
) [protected]
void DTVRecorder::HandleTimestamps ( int  stream_id,
int64_t  pts,
int64_t  dts 
) [protected]

Definition at line 545 of file dtvrecorder.cpp.

Referenced by FindMPEG2Keyframes().

void DTVRecorder::BufferedWrite ( const TSPacket tspacket  )  [protected]
bool DTVRecorder::FindAudioKeyframes ( const TSPacket tspacket  )  [protected]
bool DTVRecorder::FindMPEG2Keyframes ( const TSPacket tspacket  )  [protected]

Locates the keyframes and saves them to the position map.

This searches for three magic integers in the stream. The picture start code 0x00000100, the GOP code 0x000001B8, and the sequence start code 0x000001B3. The GOP code is prefered, but is only required of MPEG1 streams, the sequence start code is a decent fallback for MPEG2 streams, and if all else fails we just look for the picture start codes and call every 16th frame a keyframe.

NOTE: This does not only find keyframes but also tracks the total frames as well. At least a couple times seeking has been broken by short-circuiting the search once a keyframe stream id has been found. This may work on some channels, but will break on others so algorithmic optimizations should be done with great care.

   PES header format
   byte 0  byte 1  byte 2  byte 3      [byte 4     byte 5]
   0x00    0x00    0x01    PESStreamID  PES packet length
Returns:
Returns true if packet[s] should be output.

Definition at line 375 of file dtvrecorder.cpp.

Referenced by IPTVRecorder::ProcessTSPacket(), FirewireRecorder::ProcessTSPacket(), and ProcessVideoTSPacket().

bool DTVRecorder::FindH264Keyframes ( const TSPacket tspacket  )  [protected]

This searches the TS packet to identify keyframes.

Parameters:
TSPacket Pointer the the TS packet data.
Returns:
Returns true if a keyframe has been found.

Definition at line 739 of file dtvrecorder.cpp.

Referenced by IPTVRecorder::ProcessTSPacket(), and ProcessVideoTSPacket().

void DTVRecorder::HandleH264Keyframe ( void   )  [protected]

This save the current frame to the position maps and handles ringbuffer switching.

Definition at line 905 of file dtvrecorder.cpp.

Referenced by FindH264Keyframes().

void DTVRecorder::FindPSKeyFrames ( const uint8_t buffer,
uint  len 
) [protected]

Definition at line 924 of file dtvrecorder.cpp.

Referenced by MpegRecorder::run().

bool DTVRecorder::FindOtherKeyframes ( const TSPacket tspacket  )  [protected]

Non-Audio/Video data.

For streams which contain no audio/video, write just 1 key-frame at the start.

Definition at line 649 of file dtvrecorder.cpp.

Referenced by ProcessTSPacket().

bool DTVRecorder::CheckCC ( uint  pid,
uint  cc 
) [inline, protected]

Definition at line 194 of file dtvrecorder.h.

Referenced by ProcessAVTSPacket(), and ProcessTSPacket().

virtual QString DTVRecorder::GetSIStandard ( void   )  const [inline, protected, virtual]

Reimplemented in CetonRecorder, DVBRecorder, and HDHRRecorder.

Definition at line 119 of file dtvrecorder.h.

Referenced by HandlePMT().

virtual void DTVRecorder::SetCAMPMT ( const ProgramMapTable  )  [inline, protected, virtual]

Reimplemented in DVBRecorder.

Definition at line 120 of file dtvrecorder.h.

Referenced by HandlePMT().

virtual void DTVRecorder::UpdateCAMTimeOffset ( void   )  [inline, protected, virtual]

Reimplemented in DVBRecorder.

Definition at line 121 of file dtvrecorder.h.

Referenced by HandleSTT(), and HandleTDT().


Member Data Documentation

int DTVRecorder::_stream_fd [protected]

Definition at line 124 of file dtvrecorder.h.

Referenced by GetVideoFd().

QString DTVRecorder::_recording_type [protected]

Definition at line 126 of file dtvrecorder.h.

Referenced by MpegRecorder::run(), and SetOption().

QTime DTVRecorder::_audio_timer [protected]

Definition at line 129 of file dtvrecorder.h.

Referenced by FindAudioKeyframes().

unsigned long long DTVRecorder::_last_gop_seen [protected]

Definition at line 132 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), FindPSKeyFrames(), and ResetForNewFile().

unsigned long long DTVRecorder::_last_seq_seen [protected]

Definition at line 133 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), FindPSKeyFrames(), and ResetForNewFile().

unsigned long long DTVRecorder::_last_keyframe_seen [protected]
unsigned int DTVRecorder::_audio_bytes_remaining [protected]

Definition at line 135 of file dtvrecorder.h.

Referenced by FindPSKeyFrames(), and ResetForNewFile().

unsigned int DTVRecorder::_video_bytes_remaining [protected]

Definition at line 136 of file dtvrecorder.h.

Referenced by FindPSKeyFrames(), and ResetForNewFile().

unsigned int DTVRecorder::_other_bytes_remaining [protected]

Definition at line 137 of file dtvrecorder.h.

Referenced by FindPSKeyFrames(), and ResetForNewFile().

Definition at line 140 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), and ResetForNewFile().

int DTVRecorder::_repeat_pict [protected]

Definition at line 141 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), and ResetForNewFile().

Definition at line 144 of file dtvrecorder.h.

Referenced by FindH264Keyframes(), and ResetForNewFile().

Definition at line 151 of file dtvrecorder.h.

Referenced by FindOtherKeyframes(), and ResetForNewFile().

QString DTVRecorder::_error [protected]
vector<unsigned char> DTVRecorder::_payload_buffer [protected]
QMutex DTVRecorder::_pid_lock [mutable, protected]

Definition at line 164 of file dtvrecorder.h.

Referenced by HandlePAT(), and HandlePMT().

PAT on input side.

Definition at line 165 of file dtvrecorder.h.

Referenced by HandlePAT(), and ~DTVRecorder().

Definition at line 167 of file dtvrecorder.h.

Referenced by HandlePMT(), and ProcessTSPacket().

unsigned char DTVRecorder::_stream_id[0x1fff+1] [protected]

Definition at line 170 of file dtvrecorder.h.

Referenced by HandleSingleProgramPMT(), ProcessVideoTSPacket(), and ResetForNewFile().

unsigned char DTVRecorder::_pid_status[0x1fff+1] [protected]

Definition at line 171 of file dtvrecorder.h.

Referenced by ProcessAVTSPacket(), and ResetForNewFile().

unsigned char DTVRecorder::_continuity_counter[0x1fff+1] [protected]
vector<TSPacket> DTVRecorder::_scratch [protected]

Definition at line 173 of file dtvrecorder.h.

Referenced by HandleSingleProgramPAT(), and HandleSingleProgramPMT().

Definition at line 176 of file dtvrecorder.h.

Referenced by HandleTimestamps().

uint64_t DTVRecorder::_ts_count[256] [protected]

Definition at line 177 of file dtvrecorder.h.

Referenced by ClearStatistics(), and HandleTimestamps().

int64_t DTVRecorder::_ts_last[256] [protected]

Definition at line 178 of file dtvrecorder.h.

Referenced by ClearStatistics(), and HandleTimestamps().

int64_t DTVRecorder::_ts_first[256] [protected]

Definition at line 179 of file dtvrecorder.h.

Referenced by ClearStatistics(), and HandleTimestamps().

QDateTime DTVRecorder::_ts_first_dt[256] [protected]

Definition at line 180 of file dtvrecorder.h.

Referenced by HandleTimestamps().

QAtomicInt DTVRecorder::_packet_count [mutable, protected]
QAtomicInt DTVRecorder::_continuity_error_count [mutable, protected]
unsigned long long DTVRecorder::_frames_seen_count [protected]
unsigned long long DTVRecorder::_frames_written_count [protected]
const uint DTVRecorder::kMaxKeyFrameDistance = 80 [static, protected]

If the number of regular frames detected since the last detected keyframe exceeds this value, then we begin marking random regular frames as keyframes.

Definition at line 190 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), and FindPSKeyFrames().

const unsigned char DTVRecorder::kPayloadStartSeen = 0x2 [static, protected]

Definition at line 191 of file dtvrecorder.h.

Referenced by ProcessAVTSPacket().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Fri Feb 10 06:41:56 2012 for MythTV by  doxygen 1.6.3