MythTV  master
v4l2encstreamhandler.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 
3 #ifndef _V4L2encStreamhandler_H_
4 #define _V4L2encStreamhandler_H_
5 
6 #include <cstdint>
7 #include <vector>
8 using namespace std;
9 
10 #include <QString>
11 #include <QAtomicInt>
12 #include <QMutex>
13 #include <QMap>
14 
15 #include "streamhandler.h"
16 #include "v4l2util.h"
17 
18 class DTVSignalMonitor;
19 class V4L2encChannel;
20 
22 {
23  friend class V4L2encRecorder;
24  friend class V4L2encSignalMonitor;
25 
26  enum constants {PACKET_SIZE = 188 * 32768};
27 
28  public:
29  static V4L2encStreamHandler *Get(const QString &devname, int audioinput,
30  int inputid);
31  static void Return(V4L2encStreamHandler * & ref, int inputid);
32 
33  public:
34  V4L2encStreamHandler(const QString & device, int audio_input, int inputid);
35  ~V4L2encStreamHandler(void) override;
36 
37  void run(void) override; // MThread
38 #if 0
39  void PriorityEvent(int fd) override; // DeviceReaderCB
40 #endif
41 
42  bool Configure(void);
43 
44  QString Driver(void) const { return m_v4l2.DriverName(); }
45  int GetStreamType(void);
46  bool IsOpen(void) const { return m_fd >= 0 && m_v4l2.IsOpen(); }
47 
48  bool HasTuner(void) const { return m_v4l2.HasTuner(); }
49  bool HasAudio(void) const { return m_v4l2.HasAudioSupport(); }
50  bool HasSlicedVBI(void) const { return m_v4l2.HasSlicedVBI(); }
51 
52  bool HasPictureAttributes(void) const { return m_hasPictureAttributes; }
53 // bool HasCap(uint32_t mask) const { return (mask & m_caps); }
54 
55  int AvailCount(void) const { return m_drb ? m_drb->GetUsed() : 0; }
56  bool StartEncoding(void);
57  bool StopEncoding(void);
58  void RestartEncoding(void);
59 
60  QString ErrorString(void) const { return m_error; }
61 
62  protected:
63  bool Status(bool &failed, bool &failing);
64 
65  static QString RequestDescription(int request);
66 
67  bool SetOption(const QString &opt, int value);
68  bool SetOption(const QString &opt, const QString &value);
69 
70  bool SetControl(int request, int value);
71  bool SetVideoCaptureFormat(void);
72  bool SetLanguageMode(void);
73  bool SetRecordingVolume(void);
74 
75  bool HasLock(void);
76  int GetSignalStrength(void);
77  bool GetResolution(int& width, int&height) const
78  { return m_v4l2.GetResolution(width, height); }
79 
80  void SetBitrate(int bitrate, int maxbitrate, int bitratemode,
81  const QString & reason);
82  bool SetBitrateForResolution(void);
83 
84  private:
85  bool Open(void);
86  void Close(void);
87 // int Read(unsigned char *buf, uint count);
88  bool ConfigureVBI(void);
89 
90  bool m_failing {false};
91  QString m_error;
92 
93  bool m_hasTuner {false};
94  bool m_hasPictureAttributes {false};
95 
96  // for implementing Get & Return
97  static QMutex s_handlers_lock;
98  static QMap<QString, V4L2encStreamHandler*> s_handlers;
99  static QMap<QString, uint> s_handlers_refcnt;
100 
101  int m_bufferSize {1000 * (int)TSPacket::kSize};
102 
103  // Encoding info
104  int m_desiredStreamType {-1};
105  int m_streamType {-1};
106  int m_aspectRatio {-1};
107  int m_bitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
108  int m_bitrate {-1};
109  int m_maxBitrate {-1};
110  int m_audioCodec {-1};
111  int m_audioLayer {V4L2_MPEG_AUDIO_ENCODING_LAYER_1};
112  int m_audioSampleRate {-1};
113  int m_audioBitrateL1 {-1};
114  int m_audioBitrateL2 {-1};
115  int m_audioBitrateL3 {-1};
116  int m_audioVolume {-1};
117  int m_langMode {-1};
118  uint m_lowBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
119  uint m_lowBitrate {UINT_MAX};
120  uint m_lowPeakBitrate {UINT_MAX};
121  uint m_mediumBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
122  uint m_mediumBitrate {UINT_MAX};
123  uint m_mediumPeakBitrate {UINT_MAX};
124  uint m_highBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
125  uint m_highBitrate {UINT_MAX};
126  uint m_highPeakBitrate {UINT_MAX};
127 
128  static const int kAudioRateL1[];
129  static const int kAudioRateL2[];
130  static const int kAudioRateL3[];
131  static const char *kStreamTypes[];
132 
133  int m_fd {-1};
134  int m_audioInput {-1};
135 
136  uint m_width {UINT_MAX};
137  uint m_height {UINT_MAX};
138  uint m_signalStrength {UINT_MAX};
139 
141  DeviceReadBuffer *m_drb {nullptr};
142 
143  // VBI
144  QString m_vbiDevice;
145 
146  QAtomicInt m_streamingCnt {0};
147  QMutex m_streamLock;
148 
149  bool m_pauseEncodingAllowed {true};
150 };
151 
152 #endif // _V4L2encSTREAMHANDLER_H_
This is a specialization of DTVRecorder used to handle streams from V4L2 recorders.
static QMap< QString, uint > s_handlers_refcnt
bool GetResolution(int &width, int &height) const
bool GetResolution(int &width, int &height) const
bool HasAudio(void) const
static QMap< QString, V4L2encStreamHandler * > s_handlers
bool IsOpen(void) const
Definition: v4l2util.h:29
QString Driver(void) const
bool HasTuner(void) const
int GetSignalStrength(void)
Definition: signalmonitor.h:73
bool HasSlicedVBI(void) const
bool HasPictureAttributes(void) const
QString ErrorString(void) const
unsigned int uint
Definition: compat.h:140
This class is intended to detect the presence of needed tables.
static const unsigned int kSize
Definition: tspacket.h:220
SignalMonitorValue m_signalStrength
bool HasAudioSupport(void) const
bool HasTuner(void) const
int AvailCount(void) const
#define PACKET_SIZE
Definition: lirc_client.c:1751
void run(void) override
Basic signal monitoring loop.
Buffers reads from device files.
bool HasSlicedVBI(void) const
QString DriverName(void) const
Definition: v4l2util.h:48