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 <string>
8#include <vector>
9
10#include <QString>
11#include <QAtomicInt>
12#include <QMutex>
13#include <QMap>
14
15#include "streamhandler.h"
16#include "v4l2util.h"
17
19class V4L2encChannel;
20
22{
23 friend class V4L2encRecorder;
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);
72 bool SetLanguageMode(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};
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
105 int m_streamType {-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};
117 int m_langMode {-1};
118 uint m_lowBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
119 uint m_lowBitrate {UINT_MAX};
121 uint m_mediumBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
124 uint m_highBitrateMode {V4L2_MPEG_VIDEO_BITRATE_MODE_VBR};
125 uint m_highBitrate {UINT_MAX};
127
128 static const std::array<const int,14> kAudioRateL1;
129 static const std::array<const int,14> kAudioRateL2;
130 static const std::array<const int,14> kAudioRateL3;
131 static const std::array<const std::string,15> 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};
139
142
143 // VBI
144 QString m_vbiDevice;
145
146 QAtomicInt m_streamingCnt {0};
148
150};
151
152#endif // V4L2encSTREAMHANDLER_H
This class is intended to detect the presence of needed tables.
Buffers reads from device files.
uint GetUsed(void) const
void PriorityEvent(int fd) override
Definition: streamhandler.h:98
static constexpr unsigned int kSize
Definition: tspacket.h:261
This is a specialization of DTVRecorder used to handle streams from V4L2 recorders.
bool SetVideoCaptureFormat(void)
bool SetOption(const QString &opt, int value)
static QString RequestDescription(int request)
static QMap< QString, V4L2encStreamHandler * > s_handlers
bool HasPictureAttributes(void) const
bool SetRecordingVolume(void)
static const std::array< const int, 14 > kAudioRateL1
V4L2encStreamHandler(const QString &device, int audio_input, int inputid)
bool Status(bool &failed, bool &failing)
int m_langMode
0 is Main Lang; 1 is SAP Lang; 2 is Dual
bool HasTuner(void) const
QString Driver(void) const
bool HasSlicedVBI(void) const
static void Return(V4L2encStreamHandler *&ref, int inputid)
QString ErrorString(void) const
bool GetResolution(int &width, int &height) const
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
static const std::array< const int, 14 > kAudioRateL2
bool SetControl(int request, int value)
int AvailCount(void) const
~V4L2encStreamHandler(void) override
static QMap< QString, uint > s_handlers_refcnt
bool HasAudio(void) const
DeviceReadBuffer * m_drb
void SetBitrate(int bitrate, int maxbitrate, int bitratemode, const QString &reason)
bool SetLanguageMode(void)
Set audio language mode.
static const std::array< const std::string, 15 > kStreamTypes
static const std::array< const int, 14 > kAudioRateL3
static V4L2encStreamHandler * Get(const QString &devname, int audioinput, int inputid)
bool HasTuner(void) const
Definition: v4l2util.cpp:689
bool GetResolution(int &width, int &height) const
Definition: v4l2util.cpp:654
QString DriverName(void) const
Definition: v4l2util.h:50
bool HasSlicedVBI(void) const
Definition: v4l2util.cpp:118
bool HasAudioSupport(void) const
Definition: v4l2util.cpp:694
bool IsOpen(void) const
Definition: v4l2util.h:31
unsigned int uint
Definition: freesurround.h:24