MythTV  master
mpegrecorder.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef MPEGRECORDER_H_
4 #define MPEGRECORDER_H_
5 
6 #include "v4lrecorder.h"
7 #include "tspacket.h"
8 #include "mpegstreamdata.h"
9 #include "DeviceReadBuffer.h"
10 
11 struct AVFormatContext;
12 struct AVPacket;
13 
14 class MpegRecorder : public V4LRecorder,
15  public DeviceReaderCB
16 {
17  public:
18  explicit MpegRecorder(TVRec*rec)
19  : V4LRecorder(rec) {};
21  void TeardownAll(void);
22 
23  void SetOption(const QString &opt, int value) override; // DTVRecorder
24  void SetOption(const QString &opt, const QString &value) override; // DTVRecorder
25  void SetVideoFilters(QString&) override {} // DTVRecorder
26 
28  const QString &videodev,
29  const QString &audiodev,
30  const QString &vbidev) override; // DTVRecorder
31 
32  void Initialize(void) override {} // DTVRecorder
33  void run(void) override; // RecorderBase
34  void Reset(void) override; // DTVRecorder
35 
36  void Pause(bool clear = true) override; // RecorderBase
37  bool PauseAndWait(int timeout = 100) override; // RecorderBase
38 
39  bool IsRecording(void) override // RecorderBase
40  { return m_recording; }
41 
42  bool Open(void);
43  int GetVideoFd(void) override // DTVRecorder
44  { return m_chanfd; }
45 
46  // TSPacketListener
47  bool ProcessTSPacket(const TSPacket &tspacket) override; // DTVRecorder
48 
49  // DeviceReaderCB
50  void ReaderPaused(int /*fd*/) override // DeviceReaderCB
51  { m_pauseWait.wakeAll(); }
52  void PriorityEvent(int /*fd*/) override { } //DeviceReaderCB
53 
54  private:
55  void InitStreamData(void) override; // DTVRecorder
56  void SetIntOption(RecordingProfile *profile, const QString &name);
57  void SetStrOption(RecordingProfile *profile, const QString &name);
58 
59  bool OpenMpegFileAsInput(void);
60  bool OpenV4L2DeviceAsInput(void);
61  bool SetV4L2DeviceOptions(int chanfd);
62  bool SetVideoCaptureFormat(int chanfd);
63  bool SetLanguageMode(int chanfd);
64  bool SetRecordingVolume(int chanfd);
65  bool SetVBIOptions(int chanfd);
66  uint GetFilteredStreamType(void) const;
67  uint GetFilteredAudioSampleRate(void) const;
68  uint GetFilteredAudioLayer(void) const;
69  uint GetFilteredAudioBitRate(uint audio_layer) const;
70 
71  bool RestartEncoding(void);
72  bool StartEncoding(void);
73  void StopEncoding(void);
74 
75  void SetBitrate(int bitrate, int maxbitrate, const QString & reason);
76  bool HandleResolutionChanges(void);
77 
78  void FormatCC(uint code1, uint code2) override; // V4LRecorder
79 
80  bool m_deviceIsMpegFile {false};
81  int m_bufferSize {0};
82 
83  // Driver info
84  QString m_card;
85  QString m_driver;
86  uint32_t m_version {0};
87  bool m_supports_sliced_vbi {false};
88 
89  // State
90  mutable QMutex m_start_stop_encoding_lock {QMutex::Recursive};
91 
92  // Pausing state
93  bool m_cleartimeonpause {false};
94 
95  // Encoding info
96  int m_width {720};
97  int m_height {480};
98  int m_bitrate {4500};
99  int m_maxbitrate {6000};
100  int m_streamtype {0};
101  int m_aspectratio {2};
102  int m_audtype {2};
103  int m_audsamplerate {48000};
104  int m_audbitratel1 {14};
105  int m_audbitratel2 {14};
106  int m_audbitratel3 {10};
107  int m_audvolume {80};
109  unsigned int m_language {0};
110  unsigned int m_low_mpeg4avgbitrate { 4500};
111  unsigned int m_low_mpeg4peakbitrate { 6000};
112  unsigned int m_medium_mpeg4avgbitrate { 9000};
113  unsigned int m_medium_mpeg4peakbitrate {13500};
114  unsigned int m_high_mpeg4avgbitrate {13500};
115  unsigned int m_high_mpeg4peakbitrate {20200};
116 
117  // Input file descriptors
118  int m_chanfd {-1};
119  int m_readfd {-1};
120 
121  static const int s_audRateL1[];
122  static const int s_audRateL2[];
123  static const int s_audRateL3[];
124  static const char *s_streamType[];
125  static const char *s_aspectRatio[];
126  static const unsigned int kBuildBufferMaxSize;
127 
128  // Buffer device reads
130 };
131 
132 #endif
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:166
QString m_card
Definition: mpegrecorder.h:84
bool ProcessTSPacket(const TSPacket &tspacket) override
static const int s_audRateL2[]
Definition: mpegrecorder.h:122
uint GetFilteredAudioSampleRate(void) const
uint GetFilteredAudioLayer(void) const
void Reset(void) override
Reset the recorder to the startup state.
unsigned int m_medium_mpeg4avgbitrate
Definition: mpegrecorder.h:112
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
QString m_driver
Definition: mpegrecorder.h:85
void TeardownAll(void)
void SetBitrate(int bitrate, int maxbitrate, const QString &reason)
bool SetV4L2DeviceOptions(int chanfd)
void Initialize(void) override
This is called between SetOptionsFromProfile() and run() to initialize any devices,...
Definition: mpegrecorder.h:32
void ReaderPaused(int) override
Definition: mpegrecorder.h:50
bool StartEncoding(void)
unsigned int uint
Definition: compat.h:140
unsigned int m_language
0 is Main Lang; 1 is SAP Lang; 2 is Dual
Definition: mpegrecorder.h:109
void SetOption(const QString &opt, int value) override
handles the "wait_for_seqstart" option.
unsigned int m_high_mpeg4avgbitrate
Definition: mpegrecorder.h:114
bool m_cleartimeonpause
Definition: mpegrecorder.h:93
bool SetVBIOptions(int chanfd)
bool PauseAndWait(int timeout=100) override
If m_request_pause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
DeviceReadBuffer * m_device_read_buffer
Definition: mpegrecorder.h:129
MpegRecorder(TVRec *rec)
Definition: mpegrecorder.h:18
Abstract base class for Video4Linux based recorders.
Definition: v4lrecorder.h:24
bool m_supports_sliced_vbi
Definition: mpegrecorder.h:87
QWaitCondition m_pauseWait
Definition: recorderbase.h:329
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:150
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:830
bool HandleResolutionChanges(void)
bool m_deviceIsMpegFile
Definition: mpegrecorder.h:80
bool Open(void)
uint GetFilteredStreamType(void) const
void StopEncoding(void)
unsigned int m_low_mpeg4avgbitrate
Definition: mpegrecorder.h:110
unsigned int m_high_mpeg4peakbitrate
Definition: mpegrecorder.h:115
static const char * s_streamType[]
Definition: mpegrecorder.h:124
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:334
const char * name
Definition: ParseText.cpp:328
bool OpenV4L2DeviceAsInput(void)
unsigned int m_low_mpeg4peakbitrate
Definition: mpegrecorder.h:111
int GetVideoFd(void) override
Returns file descriptor of recorder device.
Definition: mpegrecorder.h:43
bool SetVideoCaptureFormat(int chanfd)
void InitStreamData(void) override
void Pause(bool clear=true) override
Pause tells recorder to pause, it should not block.
void PriorityEvent(int) override
Definition: mpegrecorder.h:52
void SetVideoFilters(QString &) override
Tells recorder which filters to use.
Definition: mpegrecorder.h:25
bool SetLanguageMode(int chanfd)
Set audio language mode.
bool OpenMpegFileAsInput(void)
uint GetFilteredAudioBitRate(uint audio_layer) const
void SetIntOption(RecordingProfile *profile, const QString &name)
bool RestartEncoding(void)
unsigned int m_medium_mpeg4peakbitrate
Definition: mpegrecorder.h:113
static const unsigned int kBuildBufferMaxSize
Definition: mpegrecorder.h:126
static const char * s_aspectRatio[]
Definition: mpegrecorder.h:125
Buffers reads from device files.
bool SetRecordingVolume(int chanfd)
static const int s_audRateL3[]
Definition: mpegrecorder.h:123
QMutex m_start_stop_encoding_lock
Definition: mpegrecorder.h:90
void SetStrOption(RecordingProfile *profile, const QString &name)
bool IsRecording(void) override
Tells whether the StartRecorder() loop is running.
Definition: mpegrecorder.h:39
void FormatCC(uint code1, uint code2) override
static const int s_audRateL1[]
Definition: mpegrecorder.h:121
uint32_t m_version
Definition: mpegrecorder.h:86
void SetOptionsFromProfile(RecordingProfile *profile, const QString &videodev, const QString &audiodev, const QString &vbidev) override
Sets basic recorder options.