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  std::chrono::milliseconds 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  std::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 
77 using CC608WriteFn = void (*) (void *, unsigned char *, int, std::chrono::milliseconds, int);
78 
80 {
81  public:
82  explicit CC608Reader(MythPlayer *parent);
83  ~CC608Reader() override;
84 
85  void SetTTPageNum(int page) { m_ccPageNum = page; }
86  void SetEnabled(bool enable) { m_enabled = enable; }
87  void FlushTxtBuffers(void);
88  CC608Buffer *GetOutputText(bool &changed, int &streamIdx);
89  CC608Buffer* GetOutputText(bool &changed);
90  void SetMode(int mode);
91  void ClearBuffers(bool input, bool output, int outputStreamIdx = -1);
92  void AddTextData(unsigned char *buf, int len,
93  std::chrono::milliseconds timecode, char type) override; // CC608Input
94  void TranscodeWriteText(CC608WriteFn func, void * ptr);
95 
96  private:
97  int Update(unsigned char *inpos);
98  void Update608Text(std::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  std::array<TextContainer,MAXTBUFFER+1> m_inputBuffers {};
113  int m_ccMode {CC_CC1};
114  int m_ccPageNum {0x888};
115  // Output buffers
116  std::array<CC608StateTracker,MAXOUTBUFFERS> m_state;
117 };
118 
119 #endif // CC608READER_H
CC608Buffer::m_lock
QMutex m_lock
Definition: cc608reader.h:50
CC608Text
Definition: cc608reader.h:18
CC608Reader::m_inputBufLock
QMutex m_inputBufLock
Definition: cc608reader.h:110
mythtvexp.h
cc
Definition: cc.h:9
CC608Buffer::m_buffers
std::vector< CC608Text * > m_buffers
Definition: cc608reader.h:51
CC608Reader::SetTTPageNum
void SetTTPageNum(int page)
Definition: cc608reader.h:85
CC608Input
Definition: cc608decoder.h:30
MythPlayer
Definition: mythplayer.h:86
CC608WriteFn
void(*)(void *, unsigned char *, int, std::chrono::milliseconds, int) CC608WriteFn
Definition: cc608reader.h:77
CC608Text::m_x
int m_x
Definition: cc608reader.h:25
cc608decoder.h
CC608Buffer::Clear
void Clear(void)
Definition: cc608reader.h:41
CC608Buffer
Definition: cc608reader.h:37
CC608StateTracker::m_outputRow
int m_outputRow
Definition: cc608reader.h:70
CC608Reader::m_state
std::array< CC608StateTracker, MAXOUTBUFFERS > m_state
Definition: cc608reader.h:116
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
CC608Input::AddTextData
virtual void AddTextData(unsigned char *buf, int len, std::chrono::milliseconds timecode, char type)=0
TextContainer
Definition: cc608reader.h:29
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
CC_CC1
#define CC_CC1
Definition: format.h:202
CC608Text::CC608Text
CC608Text(QString T, int X, int Y)
Definition: cc608reader.h:21
CC608StateTracker::Clear
void Clear(void)
Definition: cc608reader.h:59
TextContainer::len
int len
Definition: cc608reader.h:32
std
Definition: mythchrono.h:23
TextContainer::timecode
std::chrono::milliseconds timecode
Definition: cc608reader.h:31
CC608StateTracker
Definition: cc608reader.h:54
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:86
CC608Text::m_text
QString m_text
Definition: cc608reader.h:24
CC608Reader
Definition: cc608reader.h:79
CC608StateTracker::m_outputCol
int m_outputCol
Definition: cc608reader.h:69
output
#define output
Definition: synaesthesia.cpp:220
TextContainer::buffer
unsigned char * buffer
Definition: cc608reader.h:33
CC608Text::m_y
int m_y
Definition: cc608reader.h:26