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) {};
20  ~MpegRecorder() override { TeardownAll(); }
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 &/*filters*/) 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_supportsSlicedVbi {false};
88 
89  // State
90  mutable QMutex m_startStopEncodingLock {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_lowMpeg4AvgBitrate { 4500};
111  unsigned int m_lowMpeg4PeakBitrate { 6000};
112  unsigned int m_mediumMpeg4AvgBitrate { 9000};
113  unsigned int m_mediumMpeg4PeakBitrate {13500};
114  unsigned int m_highMpeg4AvgBitrate {13500};
115  unsigned int m_highMpeg4PeakBitrate {20200};
116 
117  // Input file descriptors
118  int m_chanfd {-1};
119  int m_readfd {-1};
120 
121  static const int kAudRateL1[];
122  static const int kAudRateL2[];
123  static const int kAudRateL3[];
124  static const char *kStreamType[];
125  static const char *kAspectRatio[];
126  static const unsigned int kBuildBufferMaxSize;
127 
128  // Buffer device reads
130 };
131 
132 #endif
static const int kAudRateL3[]
Definition: mpegrecorder.h:123
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
uint GetFilteredAudioSampleRate(void) const
uint GetFilteredAudioLayer(void) const
void Reset(void) override
Reset the recorder to the startup state.
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
unsigned int m_mediumMpeg4AvgBitrate
Definition: mpegrecorder.h:112
QString m_driver
Definition: mpegrecorder.h:85
void TeardownAll(void)
bool m_clearTimeOnPause
Definition: mpegrecorder.h:93
DeviceReadBuffer * m_deviceReadBuffer
Definition: mpegrecorder.h:129
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 m_language
0 is Main Lang; 1 is SAP Lang; 2 is Dual
Definition: mpegrecorder.h:109
static const int kAudRateL1[]
Definition: mpegrecorder.h:121
void SetOption(const QString &opt, int value) override
handles the "wait_for_seqstart" option.
bool SetVBIOptions(int chanfd)
bool PauseAndWait(int timeout=100) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
static const char * kStreamType[]
Definition: mpegrecorder.h:124
MpegRecorder(TVRec *rec)
Definition: mpegrecorder.h:18
Abstract base class for Video4Linux based recorders.
Definition: v4lrecorder.h:24
QWaitCondition m_pauseWait
Definition: recorderbase.h:329
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:846
unsigned int m_lowMpeg4AvgBitrate
Definition: mpegrecorder.h:110
bool HandleResolutionChanges(void)
~MpegRecorder() override
Definition: mpegrecorder.h:20
bool m_deviceIsMpegFile
Definition: mpegrecorder.h:80
bool Open(void)
unsigned int m_mediumMpeg4PeakBitrate
Definition: mpegrecorder.h:113
uint GetFilteredStreamType(void) const
void StopEncoding(void)
static const char * kAspectRatio[]
Definition: mpegrecorder.h:125
unsigned int uint
Definition: compat.h:140
bool m_supportsSlicedVbi
Definition: mpegrecorder.h:87
unsigned int m_lowMpeg4PeakBitrate
Definition: mpegrecorder.h:111
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:334
bool OpenV4L2DeviceAsInput(void)
int GetVideoFd(void) override
Returns file descriptor of recorder device.
Definition: mpegrecorder.h:43
bool SetVideoCaptureFormat(int chanfd)
unsigned int m_highMpeg4PeakBitrate
Definition: mpegrecorder.h:115
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)
static const int kAudRateL2[]
Definition: mpegrecorder.h:122
static const unsigned int kBuildBufferMaxSize
Definition: mpegrecorder.h:126
unsigned int m_highMpeg4AvgBitrate
Definition: mpegrecorder.h:114
Buffers reads from device files.
bool SetRecordingVolume(int chanfd)
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
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.
QMutex m_startStopEncodingLock
Definition: mpegrecorder.h:90