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