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);
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_desired_stream_type {-1};
105  int m_stream_type {-1};
106  int m_aspect_ratio {-1};
107  int m_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
108  int m_bitrate {-1};
109  int m_max_bitrate {-1};
110  int m_audio_codec {-1};
111  int m_audio_layer {V4L2_MPEG_AUDIO_ENCODING_LAYER_1};
112  int m_audio_samplerate {-1};
113  int m_audio_bitrateL1 {-1};
114  int m_audio_bitrateL2 {-1};
115  int m_audio_bitrateL3 {-1};
116  int m_audio_volume {-1};
117  int m_lang_mode {-1};
118  uint m_low_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
119  uint m_low_bitrate {(uint)-1};
120  uint m_low_peak_bitrate {(uint)-1};
121  uint m_medium_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
122  uint m_medium_bitrate {(uint)-1};
123  uint m_medium_peak_bitrate {(uint)-1};
124  uint m_high_bitrate_mode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
125  uint m_high_bitrate {(uint)-1};
126  uint m_high_peak_bitrate {(uint)-1};
127 
128  static const int s_audio_rateL1[];
129  static const int s_audio_rateL2[];
130  static const int s_audio_rateL3[];
131  static const char *s_stream_types[];
132  static const char *s_aspect_ratios[];
133 
134  int m_fd {-1};
136 
139  bool m_has_lock {false};
140  uint m_signal_strength {(uint)-1};
141 
143  DeviceReadBuffer *m_drb {nullptr};
144 
145  // VBI
146  QString m_vbi_device;
147 
148  QAtomicInt m_streaming_cnt {0};
150 
151  bool m_pause_encoding_allowed {true};
152 };
153 
154 #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
unsigned int uint
Definition: compat.h:140
QString Driver(void) const
bool HasTuner(void) const
bool HasSlicedVBI(void) const
bool HasPictureAttributes(void) const
QString ErrorString(void) const
This class is intended to detect the presence of needed tables.
static const unsigned int kSize
Definition: tspacket.h:220
bool HasAudioSupport(void) const
bool HasTuner(void) const
int AvailCount(void) const
#define PACKET_SIZE
Definition: lirc_client.c:1754
void run(void) override
Basic signal monitoring loop.
Buffers reads from device files.
bool HasSlicedVBI(void) const
QString DriverName(void) const
Definition: v4l2util.h:45