MythTV  master
cc608reader.h
Go to the documentation of this file.
1 #ifndef CC608READER_H
2 #define CC608READER_H
3 
4 #include <cstdint>
5 #include <utility>
6 
7 // Qt headers
8 #include <QMutex>
9 
10 // MythTV headers
11 #include "captions/cc608decoder.h"
12 
13 #include "mythtvexp.h"
14 
15 #define MAXTBUFFER 60
16 #define MAXOUTBUFFERS (16 + 1)
17 
18 class CC608Text
19 {
20  public:
21  CC608Text(QString T, int X, int Y) :
22  m_text(std::move(T)), m_x(X), m_y(Y) {}
23  CC608Text(const CC608Text &other) = default;
24  QString m_text;
25  int m_x;
26  int m_y;
27 };
28 
30 {
31  int timecode;
32  int len;
33  unsigned char *buffer;
34  char type;
35 };
36 
38 {
39  public:
40  ~CC608Buffer(void) { Clear(); }
41  void Clear(void)
42  {
43  m_lock.lock();
44  for (auto *cc : m_buffers)
45  delete cc;
46  m_buffers.clear();
47  m_lock.unlock();
48  }
49 
50  QMutex m_lock;
51  vector<CC608Text*> m_buffers;
52 };
53 
55 {
56  public:
57  CC608StateTracker() = default;
58 
59  void Clear(void)
60  {
61  m_outputText = "";
62  m_outputCol = 0;
63  m_outputRow = 0;
64  m_changed = true;
65  m_output.Clear();
66  }
67 
68  QString m_outputText;
69  int m_outputCol {0};
70  int m_outputRow {0};
71  bool m_changed {true};
73 };
74 
75 class MythPlayer;
76 
78 {
79  public:
80  explicit CC608Reader(MythPlayer *parent);
81  ~CC608Reader() override;
82 
83  void SetTTPageNum(int page) { m_ccPageNum = page; }
84  void SetEnabled(bool enable) { m_enabled = enable; }
85  void FlushTxtBuffers(void);
86  CC608Buffer *GetOutputText(bool &changed, int &streamIdx);
87  CC608Buffer* GetOutputText(bool &changed);
88  void SetMode(int mode);
89  void ClearBuffers(bool input, bool output, int outputStreamIdx = -1);
90  void AddTextData(unsigned char *buf, int len,
91  int64_t timecode, char type) override; // CC608Input
92  void TranscodeWriteText(void (*func)
93  (void *, unsigned char *, int, int, int),
94  void * ptr);
95 
96  private:
97  int Update(unsigned char *inpos);
98  void Update608Text(vector<CC608Text*> *ccbuf,
99  int replace = 0, int scroll = 0,
100  bool scroll_prsv = false,
101  int scroll_yoff = 0, int scroll_ymax = 15,
102  int streamIdx = CC_CC1);
103  int NumInputBuffers(bool need_to_lock = true);
104 
105  MythPlayer *m_parent {nullptr};
106  bool m_enabled {false};
107  // Input buffers
108  int m_readPosition {0};
109  int m_writePosition {0};
111  int m_maxTextSize {0};
112  TextContainer m_inputBuffers[MAXTBUFFER+1] {};
113  int m_ccMode {CC_CC1};
114  int m_ccPageNum {0x888};
115  // Output buffers
117 };
118 
119 #endif // CC608READER_H
CC608Buffer::m_lock
QMutex m_lock
Definition: cc608reader.h:50
CC608Text
Definition: cc608reader.h:19
CC608Text::CC608Text
CC608Text(const CC608Text &other)=default
CC608Input::AddTextData
virtual void AddTextData(unsigned char *buf, int len, int64_t timecode, char type)=0
CC608Reader::m_inputBufLock
QMutex m_inputBufLock
Definition: cc608reader.h:110
mythtvexp.h
cc
Definition: cc.h:10
CC608Reader::SetTTPageNum
void SetTTPageNum(int page)
Definition: cc608reader.h:83
CC608Input
Definition: cc608decoder.h:19
MythPlayer
Definition: mythplayer.h:165
CC608Text::m_x
int m_x
Definition: cc608reader.h:25
MAXOUTBUFFERS
#define MAXOUTBUFFERS
Definition: cc608reader.h:16
cc608decoder.h
CC608Buffer::Clear
void Clear(void)
Definition: cc608reader.h:41
CC608Buffer
Definition: cc608reader.h:38
CC608StateTracker::m_outputRow
int m_outputRow
Definition: cc608reader.h:70
CC608StateTracker::m_output
CC608Buffer m_output
Definition: cc608reader.h:72
CC608Buffer::~CC608Buffer
~CC608Buffer(void)
Definition: cc608reader.h:40
CC608StateTracker::m_changed
bool m_changed
Definition: cc608reader.h:71
CC608Buffer::m_buffers
vector< CC608Text * > m_buffers
Definition: cc608reader.h:51
TextContainer
Definition: cc608reader.h:30
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
CC_CC1
#define CC_CC1
Definition: format.h:198
CC608Text::CC608Text
CC608Text(QString T, int X, int Y)
Definition: cc608reader.h:21
MAXTBUFFER
#define MAXTBUFFER
Definition: cc608reader.h:15
TextContainer::timecode
int timecode
Definition: cc608reader.h:31
CC608StateTracker::Clear
void Clear(void)
Definition: cc608reader.h:59
TextContainer::len
int len
Definition: cc608reader.h:32
CC608StateTracker
Definition: cc608reader.h:55
CC608StateTracker::m_outputText
QString m_outputText
Definition: cc608reader.h:68
CC608StateTracker::CC608StateTracker
CC608StateTracker()=default
TextContainer::type
char type
Definition: cc608reader.h:34
CC608Reader::SetEnabled
void SetEnabled(bool enable)
Definition: cc608reader.h:84
CC608Text::m_text
QString m_text
Definition: cc608reader.h:24
CC608Reader
Definition: cc608reader.h:78
CC608StateTracker::m_outputCol
int m_outputCol
Definition: cc608reader.h:69
output
#define output
Definition: synaesthesia.cpp:221
TextContainer::buffer
unsigned char * buffer
Definition: cc608reader.h:33
CC608Text::m_y
int m_y
Definition: cc608reader.h:26