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 "DeviceReadBuffer.h"
8#include "mpeg/tspacket.h"
9#include "v4lrecorder.h"
10
11struct AVFormatContext;
12struct AVPacket;
13
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
38 bool IsRecording(void) override // RecorderBase
39 { return m_recording; }
40
41 bool Open(void);
42 int GetVideoFd(void) override // DTVRecorder
43 { return m_chanfd; }
44
45 // TSPacketListener
46 bool ProcessTSPacket(const TSPacket &tspacket) override; // DTVRecorder
47
48 // DeviceReaderCB
49 void ReaderPaused(int /*fd*/) override // DeviceReaderCB
50 { m_pauseWait.wakeAll(); }
51 void PriorityEvent(int /*fd*/) override { } //DeviceReaderCB
52
53 protected:
54 bool PauseAndWait(std::chrono::milliseconds timeout = 100ms) override; // RecorderBase
55 void InitStreamData(void) override; // DTVRecorder
56 void FormatCC(uint code1, uint code2) override; // V4LRecorder
57
58 private:
59 void SetIntOption(RecordingProfile *profile, const QString &name);
60 void SetStrOption(RecordingProfile *profile, const QString &name);
61
62 bool OpenMpegFileAsInput(void);
63 bool OpenV4L2DeviceAsInput(void);
64 bool SetV4L2DeviceOptions(int chanfd);
65 bool SetVideoCaptureFormat(int chanfd);
66 bool SetLanguageMode(int chanfd);
67 bool SetRecordingVolume(int chanfd);
68 bool SetVBIOptions(int chanfd);
69 uint GetFilteredStreamType(void) const;
71 uint GetFilteredAudioLayer(void) const;
72 uint GetFilteredAudioBitRate(uint audio_layer) const;
73
74 bool RestartEncoding(void);
75 bool StartEncoding(void);
76 void StopEncoding(void);
77
78 void SetBitrate(int bitrate, int maxbitrate, const QString & reason);
79 bool HandleResolutionChanges(void);
80
81 bool m_deviceIsMpegFile {false};
82 int m_bufferSize {0};
83
84 // Driver info
85 QString m_card;
86 QString m_driver;
87 uint32_t m_version {0};
88 bool m_supportsSlicedVbi {false};
89
90 // State
91 mutable QRecursiveMutex m_startStopEncodingLock;
92
93 // Pausing state
94 bool m_clearTimeOnPause {false};
95
96 // Encoding info
97 int m_width {720};
98 int m_height {480};
99 int m_bitrate {4500};
100 int m_maxBitrate {6000};
103 int m_audType {2};
104 int m_audSampleRate {48000};
108 int m_audVolume {80};
110 unsigned int m_language {0};
111 unsigned int m_lowMpeg4AvgBitrate { 4500};
112 unsigned int m_lowMpeg4PeakBitrate { 6000};
113 unsigned int m_mediumMpeg4AvgBitrate { 9000};
114 unsigned int m_mediumMpeg4PeakBitrate {13500};
115 unsigned int m_highMpeg4AvgBitrate {13500};
116 unsigned int m_highMpeg4PeakBitrate {20200};
117
118 // Input file descriptors
119 int m_chanfd {-1};
120 int m_readfd {-1};
121
122 static const std::array<const int,14> kAudRateL1;
123 static const std::array<const int,14> kAudRateL2;
124 static const std::array<const int,14> kAudRateL3;
125 static const std::array<const std::string,15> kStreamType;
126 static const std::array<const std::string,4> kAspectRatio;
127 static const unsigned int kBuildBufferMaxSize;
128
129 // Buffer device reads
131};
132
133#endif
Buffers reads from device files.
QRecursiveMutex m_startStopEncodingLock
Definition: mpegrecorder.h:91
static const unsigned int kBuildBufferMaxSize
Definition: mpegrecorder.h:127
bool m_deviceIsMpegFile
Definition: mpegrecorder.h:81
void InitStreamData(void) override
unsigned int m_mediumMpeg4PeakBitrate
Definition: mpegrecorder.h:114
static const std::array< const int, 14 > kAudRateL1
Definition: mpegrecorder.h:122
void SetVideoFilters(QString &) override
Tells recorder which filters to use.
Definition: mpegrecorder.h:25
void SetOption(const QString &opt, int value) override
handles the "wait_for_seqstart" option.
void run(void) override
run() starts the recording process, and does not exit until the recording is complete.
bool m_clearTimeOnPause
Definition: mpegrecorder.h:94
unsigned int m_mediumMpeg4AvgBitrate
Definition: mpegrecorder.h:113
bool PauseAndWait(std::chrono::milliseconds timeout=100ms) override
If m_requestPause is true, sets pause and blocks up to timeout milliseconds or until unpaused,...
bool Open(void)
void ReaderPaused(int) override
Definition: mpegrecorder.h:49
bool SetV4L2DeviceOptions(int chanfd)
static const std::array< const int, 14 > kAudRateL2
Definition: mpegrecorder.h:123
void Reset(void) override
Reset the recorder to the startup state.
void SetOptionsFromProfile(RecordingProfile *profile, const QString &videodev, const QString &audiodev, const QString &vbidev) override
Sets basic recorder options.
static const std::array< const std::string, 15 > kStreamType
Definition: mpegrecorder.h:125
void TeardownAll(void)
bool ProcessTSPacket(const TSPacket &tspacket) override
void SetBitrate(int bitrate, int maxbitrate, const QString &reason)
QString m_driver
Definition: mpegrecorder.h:86
void SetStrOption(RecordingProfile *profile, const QString &name)
bool SetRecordingVolume(int chanfd)
DeviceReadBuffer * m_deviceReadBuffer
Definition: mpegrecorder.h:130
void Initialize(void) override
This is called between SetOptionsFromProfile() and run() to initialize any devices,...
Definition: mpegrecorder.h:32
uint32_t m_version
Definition: mpegrecorder.h:87
void SetIntOption(RecordingProfile *profile, const QString &name)
bool m_supportsSlicedVbi
Definition: mpegrecorder.h:88
uint GetFilteredAudioSampleRate(void) const
static const std::array< const std::string, 4 > kAspectRatio
Definition: mpegrecorder.h:126
bool RestartEncoding(void)
bool OpenMpegFileAsInput(void)
bool IsRecording(void) override
Tells whether the StartRecorder() loop is running.
Definition: mpegrecorder.h:38
unsigned int m_lowMpeg4PeakBitrate
Definition: mpegrecorder.h:112
QString m_card
Definition: mpegrecorder.h:85
bool OpenV4L2DeviceAsInput(void)
bool SetLanguageMode(int chanfd)
Set audio language mode.
uint GetFilteredAudioLayer(void) const
static const std::array< const int, 14 > kAudRateL3
Definition: mpegrecorder.h:124
~MpegRecorder() override
Definition: mpegrecorder.h:20
unsigned int m_highMpeg4PeakBitrate
Definition: mpegrecorder.h:116
bool HandleResolutionChanges(void)
unsigned int m_language
0 is Main Lang; 1 is SAP Lang; 2 is Dual
Definition: mpegrecorder.h:110
void StopEncoding(void)
void Pause(bool clear=true) override
Pause tells recorder to pause, it should not block.
unsigned int m_lowMpeg4AvgBitrate
Definition: mpegrecorder.h:111
uint GetFilteredAudioBitRate(uint audio_layer) const
bool SetVideoCaptureFormat(int chanfd)
void FormatCC(uint code1, uint code2) override
bool SetVBIOptions(int chanfd)
void PriorityEvent(int) override
Definition: mpegrecorder.h:51
uint GetFilteredStreamType(void) const
int GetVideoFd(void) override
Returns file descriptor of recorder device.
Definition: mpegrecorder.h:42
unsigned int m_highMpeg4AvgBitrate
Definition: mpegrecorder.h:115
bool StartEncoding(void)
MpegRecorder(TVRec *rec)
Definition: mpegrecorder.h:18
bool m_recording
True while recording is actually being performed.
Definition: recorderbase.h:322
QWaitCondition m_pauseWait
Definition: recorderbase.h:317
Used to access the data of a Transport Stream packet.
Definition: tspacket.h:208
This is the coordinating class of the Recorder Subsystem.
Definition: tv_rec.h:142
Abstract base class for Video4Linux based recorders.
Definition: v4lrecorder.h:16
unsigned int uint
Definition: compat.h:60
static void clear(SettingsMap &cache, SettingsMap &overrides, const QString &myKey)
Definition: mythdb.cpp:948