MythTV  master
cc708reader.cpp
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2003-2005, Daniel Kristjansson
3 
4 #include <cstdlib>
5 
7 
8 #include "captions/cc708reader.h"
9 #include "decoders/decoderbase.h"
10 #include "mythplayer.h"
11 
12 #define LOC QString("CC708Reader: ")
13 #define CHECKENABLED if (!m_enabled) return
14 
16  : m_parent(owner)
17 {
18  for (uint i=0; i < k708MaxServices; i++)
19  {
20  m_bufAlloc[i] = 512;
21  m_buf[i] = (unsigned char*) malloc(m_bufAlloc[i]);
22  m_bufSize[i] = 0;
23  m_delayed[i] = false;
24 
25  m_tempStrAlloc[i] = 512;
26  m_tempStrSize[i] = 0;
27  m_tempStr[i] = (int16_t*) malloc(m_tempStrAlloc[i] * sizeof(int16_t));
28  }
29  m_cc708DelayedDeletes.fill(0);
30 }
31 
33 {
34  for (uint i=0; i < k708MaxServices; i++)
35  {
36  free(m_buf[i]);
37  free(m_tempStr[i]);
38  }
39 }
40 
42 {
43  for (uint i = 1; i < k708MaxServices; i++)
44  DeleteWindows(i, 0xff);
45 }
46 
47 void CC708Reader::SetCurrentWindow(uint service_num, int window_id)
48 {
50  LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetCurrentWindow(%1, %2)")
51  .arg(service_num).arg(window_id));
52  m_cc708services[service_num].m_currentWindow = window_id;
53 }
54 
56  uint service_num, int window_id,
57  int priority, bool visible,
58  int anchor_point, int relative_pos,
59  int anchor_vertical, int anchor_horizontal,
60  int row_count, int column_count,
61  int row_lock, int column_lock,
62  int pen_style, int window_style)
63 {
64  if (m_parent && m_parent->GetDecoder())
65  {
66  StreamInfo si(-1, 0, 0, service_num, 0, false, false);
68  }
69 
71 
72  m_cc708DelayedDeletes[service_num & 63] &= ~(1 << window_id);
73 
74  LOG(VB_VBI, LOG_DEBUG, LOC +
75  QString("DefineWindow(%1, %2,\n\t\t\t\t\t")
76  .arg(service_num).arg(window_id) +
77  QString(" prio %1, vis %2, ap %3, rp %4, av %5, ah %6")
78  .arg(priority).arg(visible).arg(anchor_point).arg(relative_pos)
79  .arg(anchor_vertical).arg(anchor_horizontal) +
80  QString("\n\t\t\t\t\t row_cnt %1, row_lck %2, "
81  "col_cnt %3, col_lck %4 ")
82  .arg(row_count).arg(row_lock)
83  .arg(column_count).arg(column_lock) +
84  QString("\n\t\t\t\t\t pen style %1, win style %2)")
85  .arg(pen_style).arg(window_style));
86 
87  GetCCWin(service_num, window_id)
88  .DefineWindow(priority, visible,
89  anchor_point, relative_pos,
90  anchor_vertical, anchor_horizontal,
91  row_count, column_count,
92  row_lock, column_lock,
93  pen_style, window_style);
94 
95  m_cc708services[service_num].m_currentWindow = window_id;
96 }
97 
98 void CC708Reader::DeleteWindows(uint service_num, int window_map)
99 {
100  CHECKENABLED;
101  LOG(VB_VBI, LOG_DEBUG, LOC + QString("DeleteWindows(%1, %2)")
102  .arg(service_num).arg(window_map, 8, 2, QChar(48)));
103 
104  for (uint i = 0; i < 8; i++)
105  if ((1 << i) & window_map)
106  GetCCWin(service_num, i).Clear();
107  m_cc708DelayedDeletes[service_num&63] |= window_map;
108 }
109 
110 void CC708Reader::DisplayWindows(uint service_num, int window_map)
111 {
112  CHECKENABLED;
113  LOG(VB_VBI, LOG_DEBUG, LOC + QString("DisplayWindows(%1, %2)")
114  .arg(service_num).arg(window_map, 8, 2, QChar(48)));
115 
116  for (uint i = 0; i < 8; i++)
117  {
118  if ((1 << i) & m_cc708DelayedDeletes[service_num & 63])
119  {
120  CC708Window &win = GetCCWin(service_num, i);
121  QMutexLocker locker(&win.m_lock);
122 
123  win.SetExists(false);
124  if (win.m_text)
125  {
126  delete [] win.m_text;
127  win.m_text = nullptr;
128  }
129  }
130  m_cc708DelayedDeletes[service_num & 63] = 0;
131  }
132 
133  for (uint i = 0; i < 8; i++)
134  {
135  if ((1 << i ) & window_map)
136  {
137  CC708Window &win = GetCCWin(service_num, i);
138  win.SetVisible(true);
139  LOG(VB_VBI, LOG_DEBUG, LOC +
140  QString("DisplayedWindow(%1, %2)").arg(service_num).arg(i));
141  }
142  }
143 }
144 
145 void CC708Reader::HideWindows(uint service_num, int window_map)
146 {
147  CHECKENABLED;
148  LOG(VB_VBI, LOG_DEBUG, LOC + QString("HideWindows(%1, %2)")
149  .arg(service_num).arg(window_map, 8, 2, QChar(48)));
150 
151  for (uint i = 0; i < 8; i++)
152  {
153  if ((1 << i) & window_map)
154  {
155  CC708Window &win = GetCCWin(service_num, i);
156  win.SetVisible(false);
157  }
158  }
159 }
160 
161 void CC708Reader::ClearWindows(uint service_num, int window_map)
162 {
163  CHECKENABLED;
164  LOG(VB_VBI, LOG_DEBUG, LOC + QString("ClearWindows(%1, %2)")
165  .arg(service_num).arg(window_map, 8, 2, QChar(48)));
166 
167  for (uint i = 0; i < 8; i++)
168  if ((1 << i) & window_map)
169  GetCCWin(service_num, i).Clear();
170 }
171 
172 void CC708Reader::ToggleWindows(uint service_num, int window_map)
173 {
174  CHECKENABLED;
175  LOG(VB_VBI, LOG_DEBUG, LOC + QString("ToggleWindows(%1, %2)")
176  .arg(service_num).arg(window_map, 8, 2, QChar(48)));
177 
178  for (uint i = 0; i < 8; i++)
179  {
180  if ((1 << i) & window_map)
181  {
182  CC708Window &win = GetCCWin(service_num, i);
183  win.SetVisible(!win.GetVisible());
184  }
185  }
186 }
187 
189  uint service_num,
190  int fill_color, int fill_opacity,
191  int border_color, int border_type,
192  int scroll_dir, int print_dir,
193  int effect_dir,
194  int display_effect, int effect_speed,
195  int justify, int word_wrap)
196 {
197  CHECKENABLED;
198  LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetWindowAttributes(%1...)")
199  .arg(service_num));
200 
201  CC708Window &win = GetCCWin(service_num);
202 
203  win.m_fill_color = fill_color & 0x3f;
204  win.m_fill_opacity = fill_opacity;
205  win.m_border_color = border_color & 0x3f;
206  win.m_border_type = border_type;
207  win.m_scroll_dir = scroll_dir;
208  win.m_print_dir = print_dir;
209  win.m_effect_dir = effect_dir;
210  win.m_display_effect = display_effect;
211  win.m_effect_speed = effect_speed;
212  win.m_justify = justify;
213  win.m_word_wrap = word_wrap;
214 }
215 
217  uint service_num, int pen_size,
218  int offset, int text_tag, int font_tag,
219  int edge_type, int underline, int italics)
220 {
221  CHECKENABLED;
222  LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetPenAttributes(%1, %2,")
223  .arg(service_num).arg(m_cc708services[service_num].m_currentWindow) +
224  QString("\n\t\t\t\t\t pen_size %1, offset %2, text_tag %3, "
225  "font_tag %4,"
226  "\n\t\t\t\t\t edge_type %5, underline %6, italics %7")
227  .arg(pen_size).arg(offset).arg(text_tag).arg(font_tag)
228  .arg(edge_type).arg(underline).arg(italics));
229 
230  GetCCWin(service_num).m_pen.SetAttributes(
231  pen_size, offset, text_tag, font_tag, edge_type, underline, italics);
232 }
233 
235  uint service_num,
236  int fg_color, int fg_opacity,
237  int bg_color, int bg_opacity,
238  int edge_color)
239 {
240  CHECKENABLED;
241  LOG(VB_VBI, LOG_DEBUG,
242  LOC + QString("SetPenColor(service=%1, fg%2.%3, bg=%4.%5, edge=%6)")
243  .arg(service_num).arg(fg_color).arg(fg_opacity)
244  .arg(bg_color).arg(bg_opacity).arg(edge_color));
245 
246  CC708CharacterAttribute &attr = GetCCWin(service_num).m_pen.m_attr;
247 
248  attr.m_fgColor = fg_color;
249  attr.m_fgOpacity = fg_opacity;
250  attr.m_bgColor = bg_color;
251  attr.m_bgOpacity = bg_opacity;
252  attr.m_edgeColor = edge_color;
253 }
254 
255 void CC708Reader::SetPenLocation(uint service_num, int row, int column)
256 {
257  CHECKENABLED;
258  LOG(VB_VBI, LOG_DEBUG, LOC + QString("SetPenLocation(%1, (c %2, r %3))")
259  .arg(service_num).arg(column).arg(row));
260  GetCCWin(service_num).SetPenLocation(row, column);
261 }
262 
263 void CC708Reader::Delay(uint service_num, int tenths_of_seconds)
264 {
265  CHECKENABLED;
266  LOG(VB_VBI, LOG_DEBUG, LOC + QString("Delay(%1, %2 seconds)")
267  .arg(service_num).arg(tenths_of_seconds * 0.1F));
268 }
269 
271 {
272  CHECKENABLED;
273  LOG(VB_VBI, LOG_DEBUG, LOC + QString("DelayCancel(%1)").arg(service_num));
274 }
275 
276 void CC708Reader::Reset(uint service_num)
277 {
278  CHECKENABLED;
279  LOG(VB_VBI, LOG_DEBUG, LOC + QString("Reset(%1)").arg(service_num));
280  DeleteWindows(service_num, 0xff);
281  DelayCancel(service_num);
282 }
283 
284 void CC708Reader::TextWrite(uint service_num,
285  int16_t* unicode_string, int16_t len)
286 {
287  CHECKENABLED;
288  QString debug = QString();
289  for (uint i = 0; i < (uint)len; i++)
290  {
291  GetCCWin(service_num).AddChar(QChar(unicode_string[i]));
292  debug += QChar(unicode_string[i]);
293  }
294  LOG(VB_VBI, LOG_DEBUG, LOC + QString("AddText to %1->%2 |%3|")
295  .arg(service_num).arg(m_cc708services[service_num].m_currentWindow).arg(debug));
296 }
CC708Window::m_text
CC708Character * m_text
Definition: cc708window.h:282
CC708Pen::m_attr
CC708CharacterAttribute m_attr
Definition: cc708window.h:173
CC708Window::m_fill_color
uint m_fill_color
Definition: cc708window.h:265
CC708Reader::SetWindowAttributes
virtual void SetWindowAttributes(uint service_num, int fill_color, int fill_opacity, int border_color, int border_type, int scroll_dir, int print_dir, int effect_dir, int display_effect, int effect_speed, int justify, int word_wrap)
Definition: cc708reader.cpp:188
CC708Reader::CC708Reader
CC708Reader(MythPlayer *owner)
Definition: cc708reader.cpp:15
CC708Reader::m_tempStrSize
std::array< int, k708MaxServices > m_tempStrSize
Definition: cc708reader.h:85
CC708Window::SetPenLocation
void SetPenLocation(uint row, uint column)
Definition: cc708window.cpp:619
CC708Pen::SetAttributes
void SetAttributes(int pen_size, int offset, int text_tag, int font_tag, int edge_type, int underline, int italics)
Definition: cc708window.h:159
CC708Window::m_lock
QRecursiveMutex m_lock
Definition: cc708window.h:317
CC708Reader::m_delayed
std::array< bool, k708MaxServices > m_delayed
Definition: cc708reader.h:81
CC708Reader::ClearBuffers
void ClearBuffers(void)
Definition: cc708reader.cpp:41
k708MaxServices
const uint k708MaxServices
Definition: cc708reader.h:14
CC708Window
Definition: cc708window.h:198
CC708CharacterAttribute::m_edgeColor
uint m_edgeColor
Definition: cc708window.h:103
CC708Reader::Delay
virtual void Delay(uint service_num, int tenths_of_seconds)
Definition: cc708reader.cpp:263
CC708Reader::DelayCancel
virtual void DelayCancel(uint service_num)
Definition: cc708reader.cpp:270
CC708Reader::SetPenColor
virtual void SetPenColor(uint service_num, int fg_color, int fg_opacity, int bg_color, int bg_opacity, int edge_color)
Definition: cc708reader.cpp:234
CC708Window::m_border_color
uint m_border_color
Definition: cc708window.h:267
CC708CharacterAttribute
Definition: cc708window.h:87
CC708Window::m_justify
uint m_justify
Definition: cc708window.h:274
CC708Reader::SetCurrentWindow
virtual void SetCurrentWindow(uint service_num, int window_id)
Definition: cc708reader.cpp:47
CC708Reader::DefineWindow
virtual void DefineWindow(uint service_num, int window_id, int priority, bool visible, int anchor_point, int relative_pos, int anchor_vertical, int anchor_horizontal, int row_count, int column_count, int row_lock, int column_lock, int pen_style, int window_style)
Definition: cc708reader.cpp:55
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
CC708CharacterAttribute::m_fgOpacity
uint m_fgOpacity
Definition: cc708window.h:100
CC708Reader::~CC708Reader
virtual ~CC708Reader()
Definition: cc708reader.cpp:32
mythplayer.h
CC708CharacterAttribute::m_bgOpacity
uint m_bgOpacity
Definition: cc708window.h:102
MythPlayer
Definition: mythplayer.h:84
CC708Reader::ClearWindows
virtual void ClearWindows(uint service_num, int window_map)
Definition: cc708reader.cpp:161
CC708Reader::TextWrite
virtual void TextWrite(uint service_num, int16_t *unicode_string, int16_t len)
Definition: cc708reader.cpp:284
CC708Window::GetVisible
bool GetVisible(void) const
Definition: cc708window.h:292
CC708Window::Clear
void Clear(void)
Definition: cc708window.cpp:260
CC708Reader::m_cc708services
std::array< CC708Service, k708MaxServices > m_cc708services
Definition: cc708reader.h:88
CC708Reader::ToggleWindows
virtual void ToggleWindows(uint service_num, int window_map)
Definition: cc708reader.cpp:172
CC708Reader::m_buf
std::array< unsigned char *, k708MaxServices > m_buf
Definition: cc708reader.h:78
mythlogging.h
StreamInfo
Definition: decoderbase.h:74
CC708Window::AddChar
void AddChar(QChar ch)
Definition: cc708window.cpp:415
CC708Reader::GetCCWin
CC708Window & GetCCWin(uint service_num, uint window_id)
Definition: cc708reader.h:29
debug
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL
CC708Window::SetExists
void SetExists(bool value)
Definition: cc708window.h:294
CC708Reader::SetPenLocation
virtual void SetPenLocation(uint service_num, int row, int column)
Definition: cc708reader.cpp:255
CC708Window::m_effect_dir
uint m_effect_dir
Definition: cc708window.h:271
kTrackTypeCC708
@ kTrackTypeCC708
Definition: decoderbase.h:33
uint
unsigned int uint
Definition: compat.h:79
CC708Window::m_fill_opacity
uint m_fill_opacity
Definition: cc708window.h:266
CC708Window::m_print_dir
uint m_print_dir
Definition: cc708window.h:270
CC708Window::m_border_type
uint m_border_type
Definition: cc708window.h:268
MythPlayer::GetDecoder
DecoderBase * GetDecoder(void)
Returns the stream decoder currently in use.
Definition: mythplayer.h:186
CC708Reader::HideWindows
virtual void HideWindows(uint service_num, int window_map)
Definition: cc708reader.cpp:145
CC708Window::m_word_wrap
uint m_word_wrap
Definition: cc708window.h:275
cc708reader.h
CC708Reader::m_parent
MythPlayer * m_parent
Definition: cc708reader.h:91
CC708Window::m_effect_speed
uint m_effect_speed
Definition: cc708window.h:273
CC708Reader::SetPenAttributes
virtual void SetPenAttributes(uint service_num, int pen_size, int offset, int text_tag, int font_tag, int edge_type, int underline, int italics)
Definition: cc708reader.cpp:216
CC708Window::m_display_effect
uint m_display_effect
Definition: cc708window.h:272
CC708Reader::Reset
virtual void Reset(uint service_num)
Definition: cc708reader.cpp:276
CC708Reader::m_bufSize
std::array< uint, k708MaxServices > m_bufSize
Definition: cc708reader.h:80
CC708Reader::m_tempStrAlloc
std::array< int, k708MaxServices > m_tempStrAlloc
Definition: cc708reader.h:84
decoderbase.h
LOC
#define LOC
Definition: cc708reader.cpp:12
CC708Window::m_scroll_dir
uint m_scroll_dir
Definition: cc708window.h:269
CC708Reader::m_cc708DelayedDeletes
std::array< int, k708MaxServices > m_cc708DelayedDeletes
Definition: cc708reader.h:89
CC708Reader::m_bufAlloc
std::array< uint, k708MaxServices > m_bufAlloc
Definition: cc708reader.h:79
CC708Window::DefineWindow
void DefineWindow(int priority, bool visible, int anchor_point, int relative_pos, int anchor_vertical, int anchor_horizontal, int row_count, int column_count, int row_lock, int column_lock, int pen_style, int window_style)
Definition: cc708window.cpp:108
CHECKENABLED
#define CHECKENABLED
Definition: cc708reader.cpp:13
CC708Reader::DisplayWindows
virtual void DisplayWindows(uint service_num, int window_map)
Definition: cc708reader.cpp:110
CC708Window::SetVisible
void SetVisible(bool value)
Definition: cc708window.h:300
CC708CharacterAttribute::m_bgColor
uint m_bgColor
Definition: cc708window.h:101
CC708Reader::m_tempStr
std::array< int16_t *, k708MaxServices > m_tempStr
Definition: cc708reader.h:83
DecoderBase::InsertTrack
virtual bool InsertTrack(uint Type, const StreamInfo &Info)
Definition: decoderbase.cpp:1021
CC708Reader::DeleteWindows
virtual void DeleteWindows(uint service_num, int window_map)
Definition: cc708reader.cpp:98
CC708CharacterAttribute::m_fgColor
uint m_fgColor
Definition: cc708window.h:99
CC708Window::m_pen
CC708Pen m_pen
Definition: cc708window.h:283