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(std::chrono::milliseconds timeout = 100ms) 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 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
91  mutable QMutex m_startStopEncodingLock {QMutex::Recursive};
92 #else
93  mutable QRecursiveMutex m_startStopEncodingLock;
94 #endif
95 
96  // Pausing state
97  bool m_clearTimeOnPause {false};
98 
99  // Encoding info
100  int m_width {720};
101  int m_height {480};
102  int m_bitrate {4500};
103  int m_maxBitrate {6000};
104  int m_streamType {0};
105  int m_aspectRatio {2};
106  int m_audType {2};
107  int m_audSampleRate {48000};
108  int m_audBitrateL1 {14};
109  int m_audBitrateL2 {14};
110  int m_audBitrateL3 {10};
111  int m_audVolume {80};
113  unsigned int m_language {0};
114  unsigned int m_lowMpeg4AvgBitrate { 4500};
115  unsigned int m_lowMpeg4PeakBitrate { 6000};
116  unsigned int m_mediumMpeg4AvgBitrate { 9000};
117  unsigned int m_mediumMpeg4PeakBitrate {13500};
118  unsigned int m_highMpeg4AvgBitrate {13500};
119  unsigned int m_highMpeg4PeakBitrate {20200};
120 
121  // Input file descriptors
122  int m_chanfd {-1};
123  int m_readfd {-1};
124 
125  static const std::array<const int,14> kAudRateL1;
126  static const std::array<const int,14> kAudRateL2;
127  static const std::array<const int,14> kAudRateL3;
128  static const std::array<const std::string,15> kStreamType;
129  static const std::array<const std::string,4> kAspectRatio;
130  static const unsigned int kBuildBufferMaxSize;
131 
132  // Buffer device reads
134 };
135 
136 #endif
MpegRecorder::Pause
void Pause(bool clear=true) override
Pause tells recorder to pause, it should not block.
Definition: mpegrecorder.cpp:1233
MpegRecorder::m_clearTimeOnPause
bool m_clearTimeOnPause
Definition: mpegrecorder.h:97
MpegRecorder::m_version
uint32_t m_version
Definition: mpegrecorder.h:86
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MpegRecorder::SetLanguageMode
bool SetLanguageMode(int chanfd)
Set audio language mode.
Definition: mpegrecorder.cpp:498
MpegRecorder::~MpegRecorder
~MpegRecorder() override
Definition: mpegrecorder.h:20
MpegRecorder::Reset
void Reset(void) override
Reset the recorder to the startup state.
Definition: mpegrecorder.cpp:1215
MpegRecorder::ReaderPaused
void ReaderPaused(int) override
Definition: mpegrecorder.h:50
MpegRecorder::m_deviceIsMpegFile
bool m_deviceIsMpegFile
Definition: mpegrecorder.h:80
V4LRecorder
Abstract base class for Video4Linux based recorders.
Definition: v4lrecorder.h:24
MpegRecorder::StartEncoding
bool StartEncoding(void)
Definition: mpegrecorder.cpp:1307
MpegRecorder::kAspectRatio
static const std::array< const std::string, 4 > kAspectRatio
Definition: mpegrecorder.h:129
MpegRecorder::SetIntOption
void SetIntOption(RecordingProfile *profile, const QString &name)
Definition: mpegrecorder.cpp:321
MpegRecorder::m_supportsSlicedVbi
bool m_supportsSlicedVbi
Definition: mpegrecorder.h:87
MpegRecorder::m_lowMpeg4PeakBitrate
unsigned int m_lowMpeg4PeakBitrate
Definition: mpegrecorder.h:115
MpegRecorder::PauseAndWait
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
Definition: mpegrecorder.cpp:1241
MpegRecorder::GetFilteredAudioLayer
uint GetFilteredAudioLayer(void) const
Definition: mpegrecorder.cpp:628
MpegRecorder::m_deviceReadBuffer
DeviceReadBuffer * m_deviceReadBuffer
Definition: mpegrecorder.h:133
MpegRecorder::SetOption
void SetOption(const QString &opt, int value) override
handles the "wait_for_seqstart" option.
Definition: mpegrecorder.cpp:102
MpegRecorder::OpenMpegFileAsInput
bool OpenMpegFileAsInput(void)
Definition: mpegrecorder.cpp:336
MpegRecorder::m_driver
QString m_driver
Definition: mpegrecorder.h:85
DeviceReadBuffer
Buffers reads from device files.
Definition: DeviceReadBuffer.h:34
MpegRecorder::m_highMpeg4PeakBitrate
unsigned int m_highMpeg4PeakBitrate
Definition: mpegrecorder.h:119
MpegRecorder::m_highMpeg4AvgBitrate
unsigned int m_highMpeg4AvgBitrate
Definition: mpegrecorder.h:118
DeviceReaderCB
Definition: DeviceReadBuffer.h:18
MpegRecorder::OpenV4L2DeviceAsInput
bool OpenV4L2DeviceAsInput(void)
Definition: mpegrecorder.cpp:352
MpegRecorder::run
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
Definition: mpegrecorder.cpp:905
MpegRecorder::m_height
int m_height
Definition: mpegrecorder.h:101
MpegRecorder::SetV4L2DeviceOptions
bool SetV4L2DeviceOptions(int chanfd)
Definition: mpegrecorder.cpp:731
hardwareprofile.scan.profile
profile
Definition: scan.py:99
MpegRecorder::HandleResolutionChanges
bool HandleResolutionChanges(void)
Definition: mpegrecorder.cpp:1476
v4lrecorder.h
TSPacket
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:169
MpegRecorder::SetVideoFilters
void SetVideoFilters(QString &) override
Tells recorder which filters to use.
Definition: mpegrecorder.h:25
MpegRecorder::IsRecording
bool IsRecording(void) override
Tells whether the StartRecorder() loop is running.
Definition: mpegrecorder.h:39
MpegRecorder::kStreamType
static const std::array< const std::string, 15 > kStreamType
Definition: mpegrecorder.h:128
MpegRecorder::Open
bool Open(void)
Definition: mpegrecorder.cpp:899
MpegRecorder::m_lowMpeg4AvgBitrate
unsigned int m_lowMpeg4AvgBitrate
Definition: mpegrecorder.h:114
MpegRecorder
Definition: mpegrecorder.h:14
MpegRecorder::m_bufferSize
int m_bufferSize
Definition: mpegrecorder.h:81
MpegRecorder::SetRecordingVolume
bool SetRecordingVolume(int chanfd)
Definition: mpegrecorder.cpp:542
clear
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:866
tspacket.h
MpegRecorder::m_aspectRatio
int m_aspectRatio
Definition: mpegrecorder.h:105
MpegRecorder::m_language
unsigned int m_language
0 is Main Lang; 1 is SAP Lang; 2 is Dual
Definition: mpegrecorder.h:113
MpegRecorder::TeardownAll
void TeardownAll(void)
Definition: mpegrecorder.cpp:65
MpegRecorder::m_audBitrateL3
int m_audBitrateL3
Definition: mpegrecorder.h:110
MpegRecorder::m_audVolume
int m_audVolume
Definition: mpegrecorder.h:111
uint
unsigned int uint
Definition: compat.h:140
MpegRecorder::SetVideoCaptureFormat
bool SetVideoCaptureFormat(int chanfd)
Definition: mpegrecorder.cpp:468
MpegRecorder::kAudRateL3
static const std::array< const int, 14 > kAudRateL3
Definition: mpegrecorder.h:127
MpegRecorder::GetFilteredStreamType
uint GetFilteredStreamType(void) const
Definition: mpegrecorder.cpp:574
MpegRecorder::GetFilteredAudioSampleRate
uint GetFilteredAudioSampleRate(void) const
Definition: mpegrecorder.cpp:605
mpegstreamdata.h
MpegRecorder::m_card
QString m_card
Definition: mpegrecorder.h:84
MpegRecorder::GetVideoFd
int GetVideoFd(void) override
Returns file descriptor of recorder device.
Definition: mpegrecorder.h:43
MpegRecorder::Initialize
void Initialize(void) override
This is called between SetOptionsFromProfile() and run() to initialize any devices,...
Definition: mpegrecorder.h:32
MpegRecorder::m_audBitrateL2
int m_audBitrateL2
Definition: mpegrecorder.h:109
MpegRecorder::SetOptionsFromProfile
void SetOptionsFromProfile(RecordingProfile *profile, const QString &videodev, const QString &audiodev, const QString &vbidev) override
Sets basic recorder options.
Definition: mpegrecorder.cpp:267
MpegRecorder::PriorityEvent
void PriorityEvent(int) override
Definition: mpegrecorder.h:52
MpegRecorder::FormatCC
void FormatCC(uint code1, uint code2) override
Definition: mpegrecorder.cpp:1534
RecorderBase::m_pauseWait
QWaitCondition m_pauseWait
Definition: recorderbase.h:340
MpegRecorder::MpegRecorder
MpegRecorder(TVRec *rec)
Definition: mpegrecorder.h:18
MpegRecorder::InitStreamData
void InitStreamData(void) override
Definition: mpegrecorder.cpp:1441
MpegRecorder::m_mediumMpeg4AvgBitrate
unsigned int m_mediumMpeg4AvgBitrate
Definition: mpegrecorder.h:116
MpegRecorder::m_width
int m_width
Definition: mpegrecorder.h:100
MpegRecorder::StopEncoding
void StopEncoding(void)
Definition: mpegrecorder.cpp:1399
MpegRecorder::m_maxBitrate
int m_maxBitrate
Definition: mpegrecorder.h:103
MpegRecorder::SetBitrate
void SetBitrate(int bitrate, int maxbitrate, const QString &reason)
Definition: mpegrecorder.cpp:1447
MpegRecorder::GetFilteredAudioBitRate
uint GetFilteredAudioBitRate(uint audio_layer) const
Definition: mpegrecorder.cpp:647
MpegRecorder::kBuildBufferMaxSize
static const unsigned int kBuildBufferMaxSize
Definition: mpegrecorder.h:130
MpegRecorder::m_audType
int m_audType
Definition: mpegrecorder.h:106
MpegRecorder::m_startStopEncodingLock
QRecursiveMutex m_startStopEncodingLock
Definition: mpegrecorder.h:93
MpegRecorder::kAudRateL2
static const std::array< const int, 14 > kAudRateL2
Definition: mpegrecorder.h:126
MpegRecorder::m_audSampleRate
int m_audSampleRate
Definition: mpegrecorder.h:107
TVRec
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:145
MpegRecorder::SetVBIOptions
bool SetVBIOptions(int chanfd)
Definition: mpegrecorder.cpp:824
RecorderBase::m_recording
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:345
MpegRecorder::kAudRateL1
static const std::array< const int, 14 > kAudRateL1
Definition: mpegrecorder.h:125
MpegRecorder::SetStrOption
void SetStrOption(RecordingProfile *profile, const QString &name)
Definition: mpegrecorder.cpp:329
MpegRecorder::m_readfd
int m_readfd
Definition: mpegrecorder.h:123
RecordingProfile
Definition: recordingprofile.h:39
MpegRecorder::m_audBitrateL1
int m_audBitrateL1
Definition: mpegrecorder.h:108
MpegRecorder::m_mediumMpeg4PeakBitrate
unsigned int m_mediumMpeg4PeakBitrate
Definition: mpegrecorder.h:117
DeviceReadBuffer.h
MpegRecorder::RestartEncoding
bool RestartEncoding(void)
Definition: mpegrecorder.cpp:1283
MpegRecorder::m_streamType
int m_streamType
Definition: mpegrecorder.h:104
MpegRecorder::m_chanfd
int m_chanfd
Definition: mpegrecorder.h:122
MpegRecorder::m_bitrate
int m_bitrate
Definition: mpegrecorder.h:102
MpegRecorder::ProcessTSPacket
bool ProcessTSPacket(const TSPacket &tspacket) override
Definition: mpegrecorder.cpp:1192