DTVRecorder Class Reference

#include <dtvrecorder.h>

Inheritance diagram for DTVRecorder:

RecorderBase DBox2Recorder DVBRecorder FirewireRecorder HDHRRecorder IPTVRecorder

List of all members.


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 24 of file dtvrecorder.h.


Public Member Functions

 DTVRecorder (TVRec *rec)
 ~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" and "pkt_buf_size" options.
virtual void StopRecording (void)
 StopRecording() signals to the StartRecording() function that it should stop recording and exit cleanly.
bool IsRecording (void)
 Tells whether the StartRecorder() loop is running.
bool IsErrored (void)
 Tells us whether an unrecoverable error has been encountered.
long long GetKeyframePosition (long long desired)
 Returns closest keyframe position before the desired frame.
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 StartRecording() 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 (MPEGStreamData *)
virtual MPEGStreamDataGetStreamData (void)
virtual void Reset ()
 Reset the recorder to the startup state.

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 ()
 This save the current frame to the position maps and handles ringbuffer switching.
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.
bool FindOtherKeyframes (const TSPacket *tspacket)
 Non-Audio/Video data.

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
bool _pes_synced
bool _seen_sps
H264::KeyframeSequencer _h264_kf_seq
bool _request_recording
 True if API call has requested a recording be [re]started.
bool _wait_for_keyframe_option
 Wait for the a GOP/SEQ-start before sending data.
bool _has_written_other_keyframe
bool _recording
 True iff recording is actually being performed.
bool _error
 True iff irrecoverable recording error detected.
unsigned char * _buffer
int _buffer_size
bool _buffer_packets
vector< unsigned char > _payload_buffer
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.

Constructor & Destructor Documentation

DTVRecorder::DTVRecorder ( TVRec rec  ) 

Definition at line 33 of file dtvrecorder.cpp.

DTVRecorder::~DTVRecorder (  ) 

Definition at line 62 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, audiodevice, videodevice, vbidevice, tvformat (ntsc,ntsc-jp,pal-m), vbiformat ("none","pal teletext","ntsc").

Reimplemented from RecorderBase.

Reimplemented in DBox2Recorder.

Definition at line 66 of file dtvrecorder.cpp.

Referenced by DVBRecorder::SetOption(), HDHRRecorder::SetOptionsFromProfile(), and DVBRecorder::SetOptionsFromProfile().

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

handles the "wait_for_seqstart" and "pkt_buf_size" options.

Reimplemented from RecorderBase.

Reimplemented in DBox2Recorder, and DVBRecorder.

Definition at line 77 of file dtvrecorder.cpp.

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

StopRecording() signals to the StartRecording() function that it should stop recording and exit cleanly.

This function should block until StartRecording() has finished up.

Implements RecorderBase.

Reimplemented in DVBRecorder, and IPTVRecorder.

Definition at line 33 of file dtvrecorder.h.

Referenced by HDHRRecorder::TeardownAll().

bool DTVRecorder::IsRecording ( void   )  [inline, virtual]

Tells whether the StartRecorder() loop is running.

Implements RecorderBase.

Definition at line 34 of file dtvrecorder.h.

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

Tells us whether an unrecoverable error has been encountered.

Implements RecorderBase.

Definition at line 35 of file dtvrecorder.h.

long long DTVRecorder::GetKeyframePosition ( long long  desired  )  [virtual]

Returns closest keyframe position before the desired frame.

This returns -1 if a keyframe position can not be found for a frame. This could be true if the keyframe has not yet been seen by the recorder(unlikely), or if a keyframe map does not exist or is not up to date. The latter can happen because the video is an external video, because the database is corrupted, or because this is a live recording and it is being read by a remote frontend faster than the keyframes can be saved to the database.

Returns:
Closest prior keyframe, or -1 if there is no prior known keyframe.

Implements RecorderBase.

Definition at line 132 of file dtvrecorder.cpp.

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.

Definition at line 38 of file dtvrecorder.h.

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.

Definition at line 40 of file dtvrecorder.h.

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

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

Implements RecorderBase.

Definition at line 41 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.

Definition at line 42 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.

Definition at line 374 of file dtvrecorder.cpp.

virtual void DTVRecorder::SetStreamData ( MPEGStreamData  )  [inline, virtual]

Reimplemented in DVBRecorder, FirewireRecorder, HDHRRecorder, and IPTVRecorder.

Definition at line 45 of file dtvrecorder.h.

Referenced by TVRec::SetupDTVSignalMonitor(), and TVRec::TuningNewRecorder().

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

void DTVRecorder::Reset (  )  [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.

Definition at line 169 of file dtvrecorder.cpp.

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.

Definition at line 107 of file dtvrecorder.cpp.

Referenced by IPTVRecorder::StartRecording(), HDHRRecorder::StartRecording(), FirewireRecorder::StartRecording(), DVBRecorder::StartRecording(), and DBox2Recorder::StartRecording().

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

Implements RecorderBase.

Reimplemented in DVBRecorder.

Definition at line 143 of file dtvrecorder.cpp.

Referenced by Reset(), and DVBRecorder::ResetForNewFile().

void DTVRecorder::HandleKeyframe ( void   )  [protected]

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

Definition at line 401 of file dtvrecorder.cpp.

Referenced by FindAudioKeyframes(), FindMPEG2Keyframes(), and FindOtherKeyframes().

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 234 of file dtvrecorder.cpp.

Referenced by DBox2Recorder::processStream(), IPTVRecorder::ProcessTSPacket(), HDHRRecorder::ProcessTSPacket(), FirewireRecorder::ProcessTSPacket(), and DVBRecorder::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 431 of file dtvrecorder.cpp.

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

void DTVRecorder::HandleH264Keyframe ( void   )  [protected]

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

Definition at line 556 of file dtvrecorder.cpp.

Referenced by FindH264Keyframes().

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 351 of file dtvrecorder.cpp.

Referenced by DVBRecorder::ProcessTSPacket().


Member Data Documentation

int DTVRecorder::_stream_fd [protected]

QString DTVRecorder::_recording_type [protected]

Definition at line 74 of file dtvrecorder.h.

Referenced by SetOption().

QTime DTVRecorder::_audio_timer [protected]

Definition at line 77 of file dtvrecorder.h.

Referenced by FindAudioKeyframes().

Definition at line 78 of file dtvrecorder.h.

Referenced by FindH264Keyframes(), FindMPEG2Keyframes(), and Reset().

unsigned long long DTVRecorder::_last_gop_seen [protected]

Definition at line 80 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), and ResetForNewFile().

unsigned long long DTVRecorder::_last_seq_seen [protected]

Definition at line 81 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes(), and ResetForNewFile().

unsigned long long DTVRecorder::_last_keyframe_seen [protected]

Definition at line 85 of file dtvrecorder.h.

Referenced by FindH264Keyframes(), and ResetForNewFile().

Definition at line 87 of file dtvrecorder.h.

Referenced by FindH264Keyframes(), HandleH264Keyframe(), and ResetForNewFile().

Definition at line 94 of file dtvrecorder.h.

Referenced by FindOtherKeyframes(), and ResetForNewFile().

unsigned char* DTVRecorder::_buffer [protected]

Definition at line 103 of file dtvrecorder.h.

Referenced by DVBRecorder::DVBRecorder(), SetOption(), and DVBRecorder::TeardownAll().

int DTVRecorder::_buffer_size [protected]

Definition at line 104 of file dtvrecorder.h.

Referenced by DVBRecorder::DVBRecorder(), and SetOption().

vector<unsigned char> DTVRecorder::_payload_buffer [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 118 of file dtvrecorder.h.

Referenced by FindMPEG2Keyframes().


The documentation for this class was generated from the following files:

Generated on Sat Dec 18 05:16:01 2010 for MythTV by  doxygen 1.5.5