DVBCore  20.3.0
DVBCore Documentation
ap_dbdef.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
24 //---includes for this file-------------------------------------------------------------------------
25 // compiler library header files
26 #include <string.h>
27 #include <stdio.h>
28 
29 // third party header files
30 
31 // Ocean Blue Software header files
32 #include "techtype.h"
33 #include "dbgfuncs.h"
34 
35 #include "stbhwav.h"
36 #include "stbhwos.h"
37 
38 #include "stbheap.h"
39 #include "stbdpc.h"
40 #include "stbsiflt.h"
41 #include "stbsitab.h"
42 #include "stbuni.h"
43 #include "stbgc.h"
44 
45 #include "stbllist.h"
46 #include "dba.h"
47 
48 #include "ap_cfg.h"
49 #include "ap_dbacc.h"
50 #include "ap_tmr.h"
51 #include "ap_dbdef.h"
52 #include "ap_cfdat.h"
53 
54 #include "ap_cntrl.h"
55 #include "app_nvm.h"
56 
57 
58 
59 //---constant definitions for this file-------------------------------------------------------------
60 #define NID_PRIVATE_BOUNDARY 0xFF01
61 #define ONID_PRIVATE_BOUNDARY 0xFF00
62 
63 #ifdef COUNTRY_FINLAND
64 #define FINLAND_ONID 0x20F6
65 #endif
66 
67 #ifdef COUNTRY_IRELAND
68 #define IRELAND_ONID 0x2174
69 #endif
70 
71 #define PRIVATE_NETWORK_ID0 0xff01 /* See TS 101 162, section 5.6.2 */
72 
73 #define TIMER_HANDLE_BASE INVALID_TIMER_HANDLE + 1
74 #define LAST_TIMER_HANDLE 0xffffffff
75 
76 #define PRIV_DATA_SPEC_DTAG 0x5f
77 
78 #define UK_DTT_PRIVATE_DATA_CODE 0x0000233a
79 #define FREESAT_PRIVATE_DATA_CODE 0x46534154
80 
81 //#define DEBUG_DBDEF
82 
83 #ifdef DEBUG_DBDEF
84 #define DBG_DBDEF(X) STB_SPDebugWrite X
85 #else
86 #define DBG_DBDEF(X)
87 #endif
88 
89 
90 //---local typedefs, structs, enumerations for this file--------------------------------------------
91 
92 //---local (static) variable declarations for this file---------------------------------------------
93 // (internal variables declared static to make them local)
94 
95 static void *db_access_mutex;
96 
97 CREATE_LINK_LIST_HEADER(lnb_rec_list);
98 CREATE_LINK_LIST_HEADER(satellite_rec_list);
99 CREATE_LINK_LIST_HEADER(lnb_band_rec_list);
100 CREATE_LINK_LIST_HEADER(network_rec_list);
101 CREATE_LINK_LIST_HEADER(transport_rec_list);
102 CREATE_LINK_LIST_HEADER(service_rec_list);
103 CREATE_LINK_LIST_HEADER(crid_rec_list);
104 CREATE_LINK_LIST_HEADER(favlist_list);
105 CREATE_LINK_LIST_HEADER(timer_list);
106 #ifdef COMMON_INTERFACE
107 CREATE_LINK_LIST_HEADER(cicam_timer_list);
108 #endif
109 
110 static U8BIT num_paths;
111 
112 static ADB_NETWORK_REC **tuned_network = NULL;
113 
114 static U32BIT last_timer_handle;
115 
116 /* Profile related info */
117 static ADB_PROFILE_TYPE current_profile;
118 static ADB_PROFILE_TYPE pushed_profile;
119 #ifdef COMMON_INTERFACE
120 static U16BIT cicam_onet_id;
121 static U32BIT cicam_identifier;
122 static U16BIT pushed_cicam_onet_id;
123 static U32BIT pushed_cicam_identifier;
124 #endif
125 
126 static U16BIT num_analog_channels; // used for allocating the next analogue channel num/name
127 static ADB_NETWORK_REC *analog_network;
128 
129 static U8BIT *text_langs;
130 static U8BIT *audio_langs;
131 static U8BIT *second_audio_langs;
132 static U8BIT *second_text_langs;
133 
134 static const ADB_STREAM_TYPE audio_priority_table[] = {
135  ADB_AUDIO_STREAM,
136  ADB_AC3_AUDIO_STREAM,
137  ADB_EAC3_AUDIO_STREAM,
138  ADB_AAC_AUDIO_STREAM,
139  ADB_HEAAC_AUDIO_STREAM
140 };
141 
142 
143 //---local function prototypes for this file--------------------------------------------------------
144 // (internal functions declared static to make them local)
145 static void DeleteLNBRec(ADB_LNB_REC *lnb_ptr);
146 static void DeleteSatelliteRec(ADB_SATELLITE_REC *n_ptr);
147 static void DeleteNetworkRec(ADB_NETWORK_REC *n_ptr);
148 
149 #ifdef COUNTRY_UK
150 static BOOLEAN ApplyTargetRegionRules(ADB_SERVICE_REC *s1_ptr, ADB_SERVICE_REC *s2_ptr,
151  U16BIT *next_allocated_lcn, BOOLEAN *lcn_assigned);
152 static U8BIT GetTargetRegionMatchDepth(ADB_SERVICE_REC *s_ptr, U8BIT match_depth,
153  U32BIT country_code, U8BIT primary_region, U8BIT secondary_region, U16BIT tertiary_region);
154 #endif /* COUNTRY_UK */
155 
156 static BOOLEAN UserPrefsMatch(ADB_TELETEXT_TYPE ttext_type, E_SUBTITLE_TYPE user_pref);
157 
158 static U16BIT GetReqdAudioPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *audio_mode,
159  ADB_STREAM_TYPE *audio_type, U8BIT *db_lang_ids, BOOLEAN *primary_found, ADB_STREAM_REC **selected_stream);
160 static U8BIT AudioStreamPriority(ADB_STREAM_TYPE stream_type);
161 static E_STREAM_MATCH_TYPE GetReqdSubtitleParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr, U16BIT *cpage_ptr,
162  U16BIT *apage_ptr, U8BIT *db_lang_ids, BOOLEAN *primary_found, ADB_STREAM_REC **selected_stream);
163 static E_STREAM_MATCH_TYPE GetReqdTtextParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr, BOOLEAN for_subtitles,
164  U8BIT *magazine, U8BIT *page, U8BIT *db_lang_ids, BOOLEAN *primary_found, ADB_STREAM_REC **selected_stream);
165 static U16BIT GetReqdADPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *ad_mode, U8BIT *db_lang_ids,
166  ADB_STREAM_REC **selected_stream, BOOLEAN *broadcast_mix);
167 #if defined(COUNTRY_FINLAND) || defined(COUNTRY_IRELAND)
168 static U16BIT FindLargestLcnNumber(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT onet_id);
169 #endif
170 
171 static S16BIT LcnSortCompareFunc(LINK_LIST_PTR_BLK **blk_1, LINK_LIST_PTR_BLK **blk_2);
172 static S16BIT FavServiceSortCompare(LINK_LIST_PTR_BLK **blk1, LINK_LIST_PTR_BLK **blk2);
173 
174 #if 0
175 static void InsertEventInSchedule(ADB_SERVICE_REC *serv_ptr, ADB_EVENT_REC *event_ptr);
176 #endif
177 
178 static S16BIT TimerSortDateTime(LINK_LIST_PTR_BLK **timer1, LINK_LIST_PTR_BLK **timer2);
179 static S16BIT TimerSortName(LINK_LIST_PTR_BLK **timer1, LINK_LIST_PTR_BLK **timer2);
180 static BOOLEAN IsVideoStreamType(ADB_STREAM_TYPE type);
181 
182 static U8BIT* ReadLanguageCode(U8BIT *dptr, U32BIT *lang_code);
183 static U8BIT* CopyString(ADB_STRING *str_desc, BOOLEAN to_unicode);
184 
185 #ifdef DEBUG_PRINT_DATABASE
186 static void PrintLNBRec(ADB_LNB_REC *lnb_ptr);
187 static void PrintSatelliteRec(ADB_SATELLITE_REC *sat_ptr);
188 static void PrintNetworkRec(ADB_NETWORK_REC *n_ptr);
189 static void PrintTransportRec(ADB_TRANSPORT_REC *t_ptr);
190 static void PrintServiceRec(ADB_SERVICE_REC *s_ptr);
191 #endif
192 
193 
194 //--------------------------------------------------------------------------------------------------
195 // global function definitions
196 //--------------------------------------------------------------------------------------------------
197 
202 {
203  U8BIT i;
204 
205  FUNCTION_START(DBDEF_Initialise);
206 
207  /* Initialise the database */
208  DBA_Initialise();
209 
210  if (tuned_network == NULL)
211  {
212  num_paths = STB_DPGetNumPaths();
213 
214  tuned_network = (ADB_NETWORK_REC **)STB_AppGetMemory(sizeof(ADB_NETWORK_REC *) * num_paths);
215 
216  if (tuned_network != NULL)
217  {
218  for (i = 0; i < num_paths; i++)
219  {
220  tuned_network[i] = NULL;
221  }
222  }
223  }
224 
225  last_timer_handle = INVALID_TIMER_HANDLE;
226 
227  db_access_mutex = STB_OSCreateMutex();
228 
229  FUNCTION_FINISH(DBDEF_Initialise);
230 }
231 
236 {
237  FUNCTION_START(DBDEF_RequestAccess);
238  STB_OSMutexLock(db_access_mutex);
239  FUNCTION_FINISH(DBDEF_RequestAccess);
240 }
241 
246 {
247  FUNCTION_START(DBDEF_ReleaseAccess);
248  STB_OSMutexUnlock(db_access_mutex);
249  FUNCTION_FINISH(DBDEF_ReleaseAccess);
250 }
251 
259 BOOLEAN DBDEF_LoadDatabase(U8BIT *db_pathname)
260 {
261  void *dba_rec;
262  void *parent_rec;
263  ADB_LNB_REC *lnb_ptr;
264  ADB_SATELLITE_REC *sat_ptr;
265  ADB_LNB_BAND_REC *band_ptr;
266  ADB_NETWORK_REC *n_ptr;
267  ADB_TRANSPORT_REC *t_ptr;
268  ADB_SERVICE_REC *s_ptr;
269  ADB_CRID_REC *c_ptr;
270  ADB_FAVLIST_REC *fl_ptr;
271  ADB_FAVSERV_REC *fs_ptr;
272  U32BIT tmp32bit;
273  U8BIT *string;
274  U16BIT num_bytes;
275  U16BIT fl_index, fs_index;
276  ADB_TIMER_REC *timer;
277 #ifdef COMMON_INTERFACE
278  ADB_CICAM_TIMER_REC *cicam_timer;
279 #endif
280 #if 0
281  ADB_EVENT_REC *e_ptr;
282  U8BIT *data;
283  U16BIT data_len;
284  U32BIT lang_code;
285  U16BIT index;
286 #endif
287  BOOLEAN retval;
288 
289  FUNCTION_START(DBDEF_LoadDatabase);
290 
291  retval = DBA_LoadDatabase(db_pathname);
292  if (retval)
293  {
294  /* Read records from database to create DVB runtime database */
295 
296  /* Read all LNB records */
297  dba_rec = DBA_FindRecord(DBA_RECORD_LNB, NULL, NULL);
298  while (dba_rec != NULL)
299  {
300  /* Make app database LNB record */
301  lnb_ptr = STB_AppGetMemory(sizeof(ADB_LNB_REC));
302  if (lnb_ptr != NULL)
303  {
304  memset(lnb_ptr, 0, sizeof(ADB_LNB_REC));
305  STB_LLAddBlockToEnd(&lnb_rec_list, (LINK_LIST_PTR_BLK *)lnb_ptr);
306 
307  lnb_ptr->dba_rec = dba_rec;
308 
309  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_TYPE, &tmp32bit);
310  switch ((E_STB_DP_LNB_TYPE)tmp32bit)
311  {
312  case LNB_TYPE_SINGLE:
313  case LNB_TYPE_UNIVERSAL:
314  case LNB_TYPE_UNICABLE:
315  case LNB_TYPE_USER_DEFINED:
316  {
317  lnb_ptr->type = (E_STB_DP_LNB_TYPE)tmp32bit;
318  break;
319  }
320  default:
321  {
322  /* Invalid setting, so force to default! */
323  lnb_ptr->type = LNB_TYPE_SINGLE;
324  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_TYPE, (U32BIT)LNB_TYPE_SINGLE);
325  break;
326  }
327  }
328 
329  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_POWER, &tmp32bit);
330  switch ((E_STB_DP_LNB_POWER)tmp32bit)
331  {
332  case LNB_POWER_OFF:
333  case LNB_POWER_ON:
334  case LNB_POWER_AUTO:
335  lnb_ptr->power = (E_STB_DP_LNB_POWER)tmp32bit;
336  break;
337  default:
338  /* Use default setting */
339  lnb_ptr->power = LNB_POWER_AUTO;
340  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_POWER, (U32BIT)LNB_POWER_AUTO);
341  break;
342  }
343 
344  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_22K, &tmp32bit);
345  lnb_ptr->is_22k = (tmp32bit ? TRUE : FALSE);
346  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_12V, &tmp32bit);
347  lnb_ptr->is_12v = (tmp32bit ? TRUE : FALSE);
348  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_PULSEPOSN, &tmp32bit);
349  lnb_ptr->is_pulse_posn = (tmp32bit ? TRUE : FALSE);
350  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISPOSN, &tmp32bit);
351  lnb_ptr->is_diseqc_posn = (tmp32bit ? TRUE : FALSE);
352 
353  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISTONE, &tmp32bit);
354  switch ((E_STB_DP_DISEQC_TONE)tmp32bit)
355  {
356  case DISEQC_TONE_OFF:
357  case DISEQC_TONE_A:
358  case DISEQC_TONE_B:
359  {
360  lnb_ptr->diseqc_tone = (E_STB_DP_DISEQC_TONE)tmp32bit;
361  break;
362  }
363  default:
364  {
365  /* Invalid setting, so force to default! */
366  lnb_ptr->diseqc_tone = DISEQC_TONE_OFF;
367  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_DISTONE,
368  (U32BIT)lnb_ptr->diseqc_tone);
369  break;
370  }
371  }
372 
373  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISCSWITCH, &tmp32bit);
374  switch ((E_STB_DP_DISEQC_CSWITCH)tmp32bit)
375  {
376  case DISEQC_CSWITCH_OFF:
377  case DISEQC_CSWITCH_A:
378  case DISEQC_CSWITCH_B:
379  case DISEQC_CSWITCH_C:
380  case DISEQC_CSWITCH_D:
381  {
382  lnb_ptr->c_switch = (E_STB_DP_DISEQC_CSWITCH)tmp32bit;
383  break;
384  }
385  default:
386  {
387  /* Invalid setting, so force to default! */
388  lnb_ptr->c_switch = DISEQC_CSWITCH_OFF;
389  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_DISCSWITCH,
390  (U32BIT)lnb_ptr->c_switch);
391  break;
392  }
393  }
394 
395  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISUSWITCH, &tmp32bit);
396  if (tmp32bit <= 16L)
397  {
398  lnb_ptr->u_switch = (U8BIT)tmp32bit;
399  }
400  else
401  {
402  /* Invalid setting, so force to default! */
403  lnb_ptr->u_switch = 0;
404  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_DISUSWITCH,
405  (U32BIT)lnb_ptr->u_switch);
406  }
407 
408  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISSMATV, &tmp32bit);
409  lnb_ptr->is_smatv = (tmp32bit ? TRUE : FALSE);
410  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_DISREPEAT, &tmp32bit);
411  if (tmp32bit <= 3L)
412  {
413  lnb_ptr->diseqc_repeats = (U8BIT)tmp32bit;
414  }
415  else
416  {
417  /* Invalid setting, so force to default! */
418  lnb_ptr->diseqc_repeats = 0;
419  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_DISREPEAT,
420  (U32BIT)lnb_ptr->diseqc_repeats);
421  }
422 
423  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_UNICABLEFREQ, &tmp32bit);
424  lnb_ptr->unicable_if = tmp32bit;
425  DBA_GetFieldValue(dba_rec, DBA_FIELD_LNB_UNICABLECHAN, &tmp32bit);
426  if (tmp32bit <= 7L)
427  {
428  lnb_ptr->unicable_chan = (U8BIT)tmp32bit;
429  }
430  else
431  {
432  lnb_ptr->unicable_chan = 0;
433  }
434 
435  if (DBA_GetFieldString(dba_rec, DBA_FIELD_LNB_NAME, &string, &num_bytes) &&
436  (num_bytes > 0))
437  {
438  lnb_ptr->name = DBDEF_MakeString(0, string, num_bytes);
439  }
440  }
441 
442  dba_rec = DBA_FindRecord(DBA_RECORD_LNB, NULL, dba_rec);
443  }
444 
445  /* Read all LNB band records */
446  dba_rec = DBA_FindRecord(DBA_RECORD_LNB_BAND, NULL, NULL);
447  while (dba_rec != NULL)
448  {
449  band_ptr = STB_AppGetMemory(sizeof(ADB_LNB_BAND_REC));
450  if (band_ptr != NULL)
451  {
452  memset(band_ptr, 0, sizeof(ADB_LNB_BAND_REC));
453 
454  parent_rec = DBA_GetRecordParent(dba_rec);
455  if (parent_rec != NULL)
456  {
457  /* Find LNB record matching parent LNB for this satellite */
458  lnb_ptr = (ADB_LNB_REC *)STB_LLGetFirstBlock(&lnb_rec_list);
459  while (lnb_ptr != NULL)
460  {
461  if (lnb_ptr->dba_rec == parent_rec)
462  {
463  band_ptr->lnb = lnb_ptr;
464  break;
465  }
466  lnb_ptr = (ADB_LNB_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)lnb_ptr);
467  }
468 
469  if (band_ptr->lnb != NULL)
470  {
471  /* Add this LNB band to the list */
472  STB_LLAddBlockToEnd(&lnb_band_rec_list, (LINK_LIST_PTR_BLK *)band_ptr);
473 
474  band_ptr->dba_rec = dba_rec;
475 
476  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_POLARITY, &tmp32bit);
477  band_ptr->band_params.polarity = (E_STB_DP_POLARITY)tmp32bit;
478 
479  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_MIN_FREQUENCY, &tmp32bit);
480  band_ptr->band_params.min_freq = (U16BIT)tmp32bit;
481 
482  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_MAX_FREQUENCY, &tmp32bit);
483  band_ptr->band_params.max_freq = (U16BIT)tmp32bit;
484 
485  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_LOCAL_OSC_FREQUENCY, &tmp32bit);
486  band_ptr->band_params.local_oscillator_frequency = (U16BIT)tmp32bit;
487 
488  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_LNB_VOLTAGE, &tmp32bit);
489  band_ptr->band_params.lnb_voltage = (E_STB_TUNE_LNB_VOLTAGE)tmp32bit;
490 
491  DBA_GetFieldValue(dba_rec, DBA_FIELD_BAND_22_KHZ, &tmp32bit);
492  band_ptr->band_params.tone_22k = (BOOLEAN)tmp32bit;
493  }
494  else
495  {
496  STB_AppFreeMemory(band_ptr);
497  }
498  }
499  }
500  dba_rec = DBA_FindRecord(DBA_RECORD_LNB_BAND, NULL, dba_rec);
501  }
502 
503  /* Read all satellite records */
504  dba_rec = DBA_FindRecord(DBA_RECORD_SATELLITE, NULL, NULL);
505  while (dba_rec != NULL)
506  {
507  /* Make app database satellite record */
508  sat_ptr = STB_AppGetMemory(sizeof(ADB_SATELLITE_REC));
509  if (sat_ptr != NULL)
510  {
511  memset(sat_ptr, 0, sizeof(ADB_SATELLITE_REC));
512 
513  /* Find the LNB for this satellite */
514  parent_rec = DBA_GetRecordParent(dba_rec);
515  if (parent_rec != NULL)
516  {
517  /* Find LNB record matching parent LNB for this satellite */
518  lnb_ptr = (ADB_LNB_REC *)STB_LLGetFirstBlock(&lnb_rec_list);
519  while (lnb_ptr != NULL)
520  {
521  if (lnb_ptr->dba_rec == parent_rec)
522  {
523  sat_ptr->lnb = lnb_ptr;
524  break;
525  }
526  lnb_ptr = (ADB_LNB_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)lnb_ptr);
527  }
528  }
529 
530  if (sat_ptr->lnb != NULL)
531  {
532  /* Add this satellite to the list */
533  STB_LLAddBlockToEnd(&satellite_rec_list, (LINK_LIST_PTR_BLK *)sat_ptr);
534 
535  sat_ptr->dba_rec = dba_rec;
536 
537  DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes);
538  sat_ptr->name = DBDEF_MakeString(0, string, num_bytes);
539 
540  DBA_GetFieldValue(dba_rec, DBA_FIELD_SAT_DISH, &tmp32bit);
541  sat_ptr->dish_pos = (U16BIT)tmp32bit;
542 
543  DBA_GetFieldValue(dba_rec, DBA_FIELD_SAT_LONGWE, &tmp32bit);
544  sat_ptr->east_west = (U16BIT)tmp32bit;
545 
546  DBA_GetFieldValue(dba_rec, DBA_FIELD_SAT_LONGPOS, &tmp32bit);
547  if (tmp32bit <= 1800L)
548  {
549  sat_ptr->long_pos = (U16BIT)tmp32bit;
550  }
551  else
552  {
553  /* Invalid setting, so force to default! */
554  sat_ptr->long_pos = (U8BIT)0;
555  DBA_SetFieldValue(dba_rec, DBA_FIELD_SAT_LONGPOS, (U32BIT)sat_ptr->long_pos);
556  }
557  }
558  else
559  {
560  STB_AppFreeMemory(sat_ptr);
561  }
562  }
563 
564  dba_rec = DBA_FindRecord(DBA_RECORD_SATELLITE, NULL, dba_rec);
565  }
566 
567  /* Read all network records */
568  dba_rec = DBA_FindRecord(DBA_RECORD_NETWORK, NULL, NULL);
569  while (dba_rec != NULL)
570  {
571  /* Make app database network record */
572  n_ptr = STB_AppGetMemory(sizeof(ADB_NETWORK_REC));
573  if (n_ptr != NULL)
574  {
575  memset(n_ptr, 0, sizeof(ADB_NETWORK_REC));
576  STB_LLAddBlockToEnd(&network_rec_list, (LINK_LIST_PTR_BLK *)n_ptr);
577 
578  n_ptr->dba_rec = dba_rec;
579 
580  /* Network may have a parent satellite record */
581  parent_rec = DBA_GetRecordParent(dba_rec);
582  if (parent_rec != NULL)
583  {
584  /* Find satellite record matching parent satellite for this network */
585  sat_ptr = (ADB_SATELLITE_REC *)STB_LLGetFirstBlock(&satellite_rec_list);
586  while (sat_ptr != NULL)
587  {
588  if (sat_ptr->dba_rec == parent_rec)
589  {
590  n_ptr->satellite = sat_ptr;
591  break;
592  }
593  sat_ptr = (ADB_SATELLITE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)sat_ptr);
594  }
595  }
596 
597  DBA_GetFieldValue(dba_rec, DBA_FIELD_NET_ID, &tmp32bit);
598  n_ptr->net_id = tmp32bit;
599 
600  DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes);
601  n_ptr->name_str = DBDEF_MakeString(0, string, num_bytes);
602 
603  /* Initialise version change FALSE as should only be TRUE when there is a version change */
604  n_ptr->nit_version_changed = FALSE;
605 
606  /* Get the nit version */
607  DBA_GetFieldValue(dba_rec, DBA_FIELD_VERSION, &tmp32bit);
608  n_ptr->nit_version = (U8BIT)tmp32bit;
609 
610  DBA_GetFieldValue(dba_rec, DBA_FIELD_PROFILE_TYPE, &tmp32bit);
611  n_ptr->profile_type = tmp32bit;
612 
613 #ifdef COMMON_INTERFACE
614  DBA_GetFieldValue(n_ptr->dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
615  n_ptr->cicam_onet_id = tmp32bit;
616 
617  DBA_GetFieldValue(n_ptr->dba_rec, DBA_FIELD_PROFILE_CAM_ID, &tmp32bit);
618  n_ptr->cicam_identifier = tmp32bit;
619 #endif
620  }
621  dba_rec = DBA_FindRecord(DBA_RECORD_NETWORK, NULL, dba_rec);
622  }
623 
624  /* Read all terrestrial transport records */
625  analog_network = NULL;
626  dba_rec = DBA_FindRecord(DBA_RECORD_TERR_TRANSPORT, NULL, NULL);
627  while (dba_rec != NULL)
628  {
629  /* Make app database transport record */
630  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
631  if (t_ptr != NULL)
632  {
633  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
634  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
635 
636  t_ptr->dba_rec = dba_rec;
637 
638  /* Make link to parent network record */
639  parent_rec = DBA_GetRecordParent(dba_rec);
640  if (parent_rec != NULL)
641  {
642  /* Find network record matching parent network for this transport */
643  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
644  while (n_ptr != NULL)
645  {
646  if (n_ptr->dba_rec == parent_rec)
647  {
648  t_ptr->network = n_ptr;
649  break;
650  }
652  }
653  }
654 
655  // read back frequency and check if analogue or digital (top bit set for analogue)
656  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, &tmp32bit);
657  if ((tmp32bit & 0x80000000L) != 0)
658  {
659  /* Analogue terrestrial transport */
660  t_ptr->frequency = (tmp32bit & 0x7fffffffL);
661 
662  t_ptr->sig_type = SIGNAL_ANALOG;
663  t_ptr->tran_id = 0xffff;
664  t_ptr->signal_level_at_search = BAD_SIGNAL_STATUS;
665 
666  if (analog_network == NULL)
667  {
668  analog_network = t_ptr->network;
669  }
670 
671  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
672  t_ptr->u.anal.vtype = (E_STB_DP_ANALOG_VIDEO_TYPE)tmp32bit;
673 #if 0
674  DBA_GetFieldValue(dba_rec, DBA_FIELD_TTRAN_FREQ_OFFSET, &tmp32bit);
675  t_ptr->u.anal.freq_offset = (S8BIT)tmp32bit;
676 #endif
677  }
678  else
679  {
680  /* Digital terrestrial transport */
681  t_ptr->frequency = tmp32bit;
682  t_ptr->sig_type = SIGNAL_COFDM;
683 
684  DBA_GetFieldValue(dba_rec, DBA_FIELD_TTRAN_BWIDTH, &tmp32bit);
685  t_ptr->u.terr.bwidth = (E_STB_DP_TBWIDTH)tmp32bit;
686 
687  DBA_GetFieldValue(dba_rec, DBA_FIELD_TTRAN_MODE, &tmp32bit);
688  t_ptr->u.terr.tmode = (E_STB_DP_TMODE)tmp32bit;
689 
690  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
691  t_ptr->tran_id = tmp32bit;
692 
693  DBA_GetFieldValue(dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
694  t_ptr->orig_net_id = tmp32bit;
695 
696  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_STRENGTH, &tmp32bit);
697  t_ptr->signal_level_at_search = (U8BIT)tmp32bit;
698 
699  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_QUALITY, &tmp32bit);
700  t_ptr->signal_level_at_search = GET_SIGNAL_STATUS(tmp32bit, t_ptr->signal_level_at_search);
701 
702  DBA_GetFieldValue(dba_rec, DBA_FIELD_TTRAN_TERR_TYPE, &tmp32bit);
703  t_ptr->u.terr.terr_type = (E_STB_DP_TTYPE)tmp32bit;
704 
705  DBA_GetFieldValue(dba_rec, DBA_FIELD_TTRAN_PLP_ID, &tmp32bit);
706  t_ptr->u.terr.plp_id = (U8BIT)tmp32bit;
707 
708  /* Initialise tuning parameters not stored in nvm and requiring non-zero state */
709  t_ptr->u.terr.constellation = TUNE_TCONST_UNDEFINED;
710  t_ptr->u.terr.hierarchy = TUNE_THIERARCHY_UNDEFINED;
711  t_ptr->u.terr.lp_code_rate = TUNE_TCODERATE_UNDEFINED;
712  t_ptr->u.terr.hp_code_rate = TUNE_TCODERATE_UNDEFINED;
713  t_ptr->u.terr.guard_int = TUNE_TGUARDINT_UNDEFINED;
714  }
715 
716  /* Initialise version change FALSE as should only be TRUE when there is a version change */
717  t_ptr->sdt_version_changed = FALSE;
718 
719  /* Get the sdt version */
720  DBA_GetFieldValue(dba_rec, DBA_FIELD_VERSION, &tmp32bit);
721  t_ptr->sdt_version = (U8BIT)tmp32bit;
722  }
723 
724  dba_rec = DBA_FindRecord(DBA_RECORD_TERR_TRANSPORT, NULL, dba_rec);
725  }
726 
727  /* Read all cable transport records */
728  dba_rec = DBA_FindRecord(DBA_RECORD_CAB_TRANSPORT, NULL, NULL);
729  while (dba_rec != NULL)
730  {
731  // make app database transport record
732  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
733  if (t_ptr != NULL)
734  {
735  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
736  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
737 
738  t_ptr->dba_rec = dba_rec;
739 
740  /* Make link to parent network record */
741  parent_rec = DBA_GetRecordParent(dba_rec);
742  if (parent_rec != NULL)
743  {
744  /* Find network record matching parent network for this transport */
745  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
746  while (n_ptr != NULL)
747  {
748  if (n_ptr->dba_rec == parent_rec)
749  {
750  t_ptr->network = n_ptr;
751  break;
752  }
754  }
755  }
756 
757  t_ptr->sig_type = SIGNAL_QAM;
758 
759  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, &tmp32bit);
760  t_ptr->frequency = tmp32bit;
761 
762  DBA_GetFieldValue(dba_rec, DBA_FIELD_CTRAN_MODE, &tmp32bit);
763  t_ptr->u.cab.cmode = (E_STB_DP_TMODE)tmp32bit;
764 
765  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SRATE, &tmp32bit);
766  t_ptr->u.cab.symbol_rate = (U16BIT)tmp32bit;
767 
768  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
769  t_ptr->tran_id = tmp32bit;
770 
771  DBA_GetFieldValue(dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
772  t_ptr->orig_net_id = tmp32bit;
773 
774  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_STRENGTH, &tmp32bit);
775  t_ptr->signal_level_at_search = (U8BIT)tmp32bit;
776 
777  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_QUALITY, &tmp32bit);
778  t_ptr->signal_level_at_search = GET_SIGNAL_STATUS(tmp32bit, t_ptr->signal_level_at_search);
779 
780  /* Initialise version change FALSE as should only be TRUE when there is a version change */
781  t_ptr->sdt_version_changed = FALSE;
782 
783  /* Get the sdt version */
784  DBA_GetFieldValue(dba_rec, DBA_FIELD_VERSION, &tmp32bit);
785  t_ptr->sdt_version = (U8BIT)tmp32bit;
786  }
787 
788  dba_rec = DBA_FindRecord(DBA_RECORD_CAB_TRANSPORT, NULL, dba_rec);
789  }
790 
791  /* Read all satellite transport records */
792  dba_rec = DBA_FindRecord(DBA_RECORD_SAT_TRANSPORT, NULL, NULL);
793  while (dba_rec != NULL)
794  {
795  /* Make app database transport record */
796  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
797  if (t_ptr != NULL)
798  {
799  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
800  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
801 
802  t_ptr->dba_rec = dba_rec;
803 
804  /* Make link to parent network */
805  parent_rec = DBA_GetRecordParent(dba_rec);
806  if (parent_rec != NULL)
807  {
808  // find network record matching parent network for this transport
809  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
810  while (n_ptr != NULL)
811  {
812  if (n_ptr->dba_rec == parent_rec)
813  {
814  t_ptr->network = n_ptr;
815  break;
816  }
818  }
819  }
820  else
821  {
822  DBG_DBDEF("Parent rec not found");
823  }
824 
825  t_ptr->sig_type = SIGNAL_QPSK;
826 
827  /* Set the transponder id */
828  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
829  t_ptr->tran_id = (U16BIT)tmp32bit;
830 
831  DBA_GetFieldValue(dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
832  t_ptr->orig_net_id = (U16BIT)tmp32bit;
833 
834  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, &tmp32bit);
835  t_ptr->frequency = tmp32bit;
836 
837  DBA_GetFieldValue(dba_rec, DBA_FIELD_STRAN_POL, &tmp32bit);
838  switch ((E_STB_DP_POLARITY)tmp32bit)
839  {
840  case POLARITY_HORIZONTAL:
841  case POLARITY_VERTICAL:
842  case POLARITY_LEFT:
843  case POLARITY_RIGHT:
844  {
845  t_ptr->u.sat.polarity = (E_STB_DP_POLARITY)tmp32bit;
846  break;
847  }
848  default:
849  {
850  /* Invalid setting, so force to default! */
851  t_ptr->u.sat.polarity = POLARITY_HORIZONTAL;
852  DBA_SetFieldValue(dba_rec, DBA_FIELD_STRAN_POL,
853  (U32BIT)t_ptr->u.sat.polarity);
854  break;
855  }
856  }
857 
858  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SRATE, &tmp32bit);
859  t_ptr->u.sat.symbol_rate = tmp32bit;
860 
861  DBA_GetFieldValue(dba_rec, DBA_FIELD_STRAN_FEC, &tmp32bit);
862  switch ((E_STB_DP_FEC)tmp32bit)
863  {
864  case FEC_AUTOMATIC:
865  case FEC_1_2:
866  case FEC_2_3:
867  case FEC_3_4:
868  case FEC_5_6:
869  case FEC_7_8:
870  case FEC_1_4:
871  case FEC_1_3:
872  case FEC_2_5:
873  case FEC_8_9:
874  case FEC_9_10:
875  case FEC_3_5:
876  case FEC_4_5:
877  {
878  t_ptr->u.sat.fec_code = (E_STB_DP_FEC)tmp32bit;
879  break;
880  }
881  default:
882  {
883  /* Invalid setting, so force to default! */
884  t_ptr->u.sat.fec_code = FEC_AUTOMATIC;
885  DBA_SetFieldValue(dba_rec, DBA_FIELD_STRAN_FEC,
886  (U32BIT)t_ptr->u.sat.fec_code);
887  break;
888  }
889  }
890 
891  DBA_GetFieldValue(dba_rec, DBA_FIELD_STRAN_DVBS2, &tmp32bit);
892  t_ptr->u.sat.dvb_s2 = ((tmp32bit != 0) ? TRUE : FALSE);
893 
894  DBA_GetFieldValue(dba_rec, DBA_FIELD_STRAN_MODULATION, &tmp32bit);
895  t_ptr->u.sat.modulation = tmp32bit;
896 
897  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_STRENGTH, &tmp32bit);
898  t_ptr->signal_level_at_search = (U8BIT)tmp32bit;
899 
900  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRAN_SIGNAL_QUALITY, &tmp32bit);
901  t_ptr->signal_level_at_search = GET_SIGNAL_STATUS(tmp32bit, t_ptr->signal_level_at_search);
902 
903  /* Get the sdt version */
904  DBA_GetFieldValue(dba_rec, DBA_FIELD_VERSION, &tmp32bit);
905  t_ptr->sdt_version = (U8BIT)tmp32bit;
906  }
907 
908  dba_rec = DBA_FindRecord(DBA_RECORD_SAT_TRANSPORT, NULL, dba_rec);
909  }
910 
911  /* Read service records */
912  num_analog_channels = 0;
913  dba_rec = DBA_FindRecord(DBA_RECORD_SERVICE, NULL, NULL);
914  while (dba_rec != NULL)
915  {
916  /* Make app database service record */
917  s_ptr = STB_AppGetMemory(sizeof(ADB_SERVICE_REC));
918  if (s_ptr != NULL)
919  {
920  memset(s_ptr, 0, sizeof(ADB_SERVICE_REC));
921  STB_LLAddBlockToEnd(&service_rec_list, (LINK_LIST_PTR_BLK *)s_ptr);
922 
923  s_ptr->dba_rec = dba_rec;
924 
925  /* Make link to parent transport */
926  parent_rec = DBA_GetRecordParent(dba_rec);
927  if (parent_rec != NULL)
928  {
929  // find transport record matching parent transport for this service
930  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
931  while (t_ptr != NULL)
932  {
933  if (t_ptr->dba_rec == parent_rec)
934  {
935  s_ptr->transport = t_ptr;
936  break;
937  }
939  }
940  }
941 
942  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_ID, &tmp32bit);
943  s_ptr->serv_id = (U16BIT)tmp32bit;
944 
945  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_LCN, &tmp32bit);
946  s_ptr->allocated_lcn = (U16BIT)tmp32bit;
947 
948  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_REQ_LCN, &tmp32bit);
949  s_ptr->serv_lcn = (U16BIT)tmp32bit;
950 
951  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_TYPE, &tmp32bit);
952  s_ptr->serv_type = tmp32bit;
953 
954  if (s_ptr->serv_type == ADB_SERVICE_TYPE_ANALOG)
955  {
956  num_analog_channels++;
957  }
958 
959  DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes);
960  s_ptr->name_str = DBDEF_MakeString(0, string, num_bytes);
961 
962  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_FAV_GROUPS, &tmp32bit);
963  s_ptr->fav_groups = (U8BIT)tmp32bit;
964 
965  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_LOCKED, &tmp32bit);
966  s_ptr->locked = (BOOLEAN)tmp32bit;
967 
968  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_HIDDEN, &tmp32bit);
969  s_ptr->hidden = (BOOLEAN)tmp32bit;
970 
971  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_SELECTABLE, &tmp32bit);
972  s_ptr->selectable = (BOOLEAN)tmp32bit;
973 
974  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_SCHED_DISABLED, &tmp32bit);
975  s_ptr->sched_disabled = (BOOLEAN)tmp32bit;
976 
977  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_NOWNEXT_DISABLED, &tmp32bit);
978  s_ptr->now_next_disabled = (BOOLEAN)tmp32bit;
979 
980  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_FREESAT_ID, &tmp32bit);
981  s_ptr->freesat_id = (U16BIT)tmp32bit;
982 
983  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_REGION_ID, &tmp32bit);
984  s_ptr->region_id = (U16BIT)tmp32bit;
985 
986  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_LCN_EDITABLE, &tmp32bit);
987  s_ptr->lcn_editable = (BOOLEAN)tmp32bit;
988 
989  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERV_DELETED, &tmp32bit);
990  s_ptr->deleted = (BOOLEAN)tmp32bit;
991 
992  /* Mark all service records as found */
993  s_ptr->found = TRUE;
994  }
995 
996  dba_rec = DBA_FindRecord(DBA_RECORD_SERVICE, NULL, dba_rec);
997  }
998 
999  /* Read CRID records */
1000  dba_rec = DBA_FindRecord(DBA_RECORD_CRID, NULL, NULL);
1001  while (dba_rec != NULL)
1002  {
1003  /* Make app database crid record */
1004  c_ptr = STB_AppGetMemory(sizeof(ADB_CRID_REC));
1005  if (c_ptr != NULL)
1006  {
1007  memset(c_ptr, 0, sizeof(ADB_CRID_REC));
1008  STB_LLAddBlockToEnd(&crid_rec_list, (LINK_LIST_PTR_BLK *)c_ptr);
1009 
1010  c_ptr->dba_rec = dba_rec;
1011 
1012  DBA_GetFieldString(dba_rec, DBA_FIELD_TIMER_CRID, &string, &num_bytes);
1013  c_ptr->crid_str = DBDEF_MakeString(0, string, num_bytes);
1014 
1015  DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes);
1016  c_ptr->name_str = DBDEF_MakeString(0, string, num_bytes);
1017 
1018  DBA_GetFieldValue(dba_rec, DBA_FIELD_CRID_SERIES, &tmp32bit);
1019  c_ptr->series_flag = (tmp32bit != 0);
1020 
1021  DBA_GetFieldValue(dba_rec, DBA_FIELD_CRID_RECOMMENDED, &tmp32bit);
1022  c_ptr->recommended_flag = (tmp32bit != 0);
1023 
1024  DBA_GetFieldValue(dba_rec, DBA_FIELD_CRID_DO_NOT_DELETE, &tmp32bit);
1025  c_ptr->do_not_delete = (tmp32bit != 0);
1026 
1027  DBA_GetFieldValue(dba_rec, DBA_FIELD_CRID_EIT_DATE, &tmp32bit);
1028  c_ptr->eit_date = (U16BIT)tmp32bit;
1029 
1030  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_STARTTIME, &tmp32bit);
1031  c_ptr->date_time = tmp32bit;
1032 
1033  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERVICE_ID, &tmp32bit);
1034  c_ptr->serv_id = (U16BIT)tmp32bit;
1035  }
1036  dba_rec = DBA_FindRecord(DBA_RECORD_CRID, NULL, dba_rec);
1037  }
1038 
1039  /* Read favourite lists */
1040  dba_rec = DBA_FindRecord(DBA_RECORD_FAV_LIST, NULL, NULL);
1041  while (dba_rec != NULL)
1042  {
1043  /* Create an app database record for this list */
1044  fl_ptr = STB_AppGetMemory(sizeof(ADB_FAVLIST_REC));
1045  if (fl_ptr != NULL)
1046  {
1047  memset(fl_ptr, 0, sizeof(ADB_FAVLIST_REC));
1048  STB_LLAddBlockToEnd(&favlist_list, (LINK_LIST_PTR_BLK *)fl_ptr);
1049 
1050  fl_ptr->dba_rec = dba_rec;
1051 
1052  /* Init the list of services in this favourite list */
1053  STB_LLInitialiseHeader(&fl_ptr->serv_list);
1054 
1055  DBA_GetFieldValue(dba_rec, DBA_FIELD_FAVLIST_ID, &tmp32bit);
1056  fl_ptr->list_id = (U8BIT)tmp32bit;
1057 
1058  DBA_GetFieldValue(dba_rec, DBA_FIELD_FAVLIST_INDEX, &tmp32bit);
1059  fl_ptr->index = (U8BIT)tmp32bit;
1060 
1061  DBA_GetFieldValue(dba_rec, DBA_FIELD_FAVLIST_USER_DATA, &tmp32bit);
1062  fl_ptr->user_data = tmp32bit;
1063 
1064  DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes);
1065  fl_ptr->name = DBDEF_MakeString(0, string, num_bytes);
1066  }
1067 
1068  dba_rec = DBA_FindRecord(DBA_RECORD_FAV_LIST, NULL, dba_rec);
1069  }
1070 
1071  /* Read the services in all favourite lists */
1072  dba_rec = DBA_FindRecord(DBA_RECORD_FAV_SERV, NULL, NULL);
1073  while (dba_rec != NULL)
1074  {
1075  fs_ptr = STB_AppGetMemory(sizeof(ADB_FAVSERV_REC));
1076  if (fs_ptr != NULL)
1077  {
1078  memset(fs_ptr, 0, sizeof(ADB_FAVSERV_REC));
1079 
1080  /* Create the link to the actual service */
1081  parent_rec = DBA_GetRecordParent(dba_rec);
1082  if (parent_rec != NULL)
1083  {
1084  /* Find service record matching parent service */
1085  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
1086  while (s_ptr != NULL)
1087  {
1088  if (s_ptr->dba_rec == parent_rec)
1089  {
1090  fs_ptr->serv_ptr = s_ptr;
1091  break;
1092  }
1094  }
1095  }
1096 
1097  /* If the service hasn't been found then there's no point reading the remaining fields */
1098  if (fs_ptr->serv_ptr != NULL)
1099  {
1100  fs_ptr->dba_rec = dba_rec;
1101 
1102  DBA_GetFieldValue(dba_rec, DBA_FIELD_FAVLIST_ID, &tmp32bit);
1103  fs_ptr->list_id = (U8BIT)tmp32bit;
1104 
1105  DBA_GetFieldValue(dba_rec, DBA_FIELD_FAVLIST_INDEX, &tmp32bit);
1106  fs_ptr->index = (U16BIT)tmp32bit;
1107 
1108  /* Find the favourite list this service is in */
1109  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
1110  while (fl_ptr != NULL)
1111  {
1112  if (fl_ptr->list_id == fs_ptr->list_id)
1113  {
1114  /* Found the favourite list, add the service to it.
1115  * The list will be sorted into the correct order at the end */
1116  STB_LLAddBlockToEnd(&fl_ptr->serv_list, (LINK_LIST_PTR_BLK *)fs_ptr);
1117  break;
1118  }
1119 
1120  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
1121  }
1122 
1123  if (fl_ptr == NULL)
1124  {
1125  /* The favourite list the service is in wasn't found,
1126  * so no point keeping the service */
1127  STB_AppFreeMemory(fs_ptr);
1128  }
1129  }
1130  else
1131  {
1132  STB_AppFreeMemory(fs_ptr);
1133  }
1134  }
1135 
1136  dba_rec = DBA_FindRecord(DBA_RECORD_FAV_SERV, NULL, dba_rec);
1137  }
1138 
1139  /* Now sort the services in each favourite list into the correct order
1140  * as defined by the service's index.
1141  * The index of each list is also set to ensure they're consecutive */
1142  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
1143  for (fl_index = 0; fl_ptr != NULL; fl_index++)
1144  {
1145  if (fl_ptr->index != fl_index)
1146  {
1147  fl_ptr->index = fl_index;
1148  DBA_SetFieldValue(fl_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)fl_index);
1149  }
1150 
1151  STB_LLSort(&fl_ptr->serv_list, FavServiceSortCompare);
1152 
1153  /* Now set the index of the services in this list to ensure they're consecutive */
1154  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fl_ptr->serv_list);
1155  for (fs_index = 0; fs_ptr != NULL; fs_index++)
1156  {
1157  if (fs_ptr->index != fs_index)
1158  {
1159  fs_ptr->index = fs_index;
1160  DBA_SetFieldValue(fl_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)fs_index);
1161  }
1162 
1163  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
1164  }
1165 
1166  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
1167  }
1168 
1169  /* Read timers */
1170  dba_rec = DBA_FindRecord(DBA_RECORD_TIMER, NULL, NULL);
1171  while (dba_rec != NULL)
1172  {
1173  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_TYPE, &tmp32bit);
1174 
1175  if ((tmp32bit == TIMER_TYPE_ALARM) || (tmp32bit == TIMER_TYPE_SLEEP) ||
1176  (tmp32bit == TIMER_TYPE_PVR_RECORD) || (tmp32bit == TIMER_TYPE_PRIVATE))
1177  {
1178  /* Make app database service record */
1179  timer = (ADB_TIMER_REC *)STB_AppGetMemory(sizeof(ADB_TIMER_REC));
1180  if (timer != NULL)
1181  {
1182  memset(timer, 0, sizeof(ADB_TIMER_REC));
1183  STB_LLAddBlockToEnd(&timer_list, (LINK_LIST_PTR_BLK *)timer);
1184 
1185  timer->dba_rec = dba_rec;
1186  timer->type = (E_TIMER_TYPE)tmp32bit;
1187 
1188  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_HANDLE, &tmp32bit);
1189  timer->handle = tmp32bit;
1190 
1191  /* Set the base for the next timer handle so it's greater than
1192  * the biggest timer handle currently in use */
1193  if (timer->handle > last_timer_handle)
1194  {
1195  last_timer_handle = timer->handle;
1196  }
1197 
1198  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_STARTTIME, &tmp32bit);
1199  timer->start_time = tmp32bit;
1200 
1201  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_FREQUENCY, &tmp32bit);
1202  timer->frequency = (E_TIMER_FREQ)tmp32bit;
1203 
1204  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_MISSED, &tmp32bit);
1205  if (tmp32bit == 1)
1206  {
1207  timer->missed = TRUE;
1208  }
1209  else
1210  {
1211  timer->missed = FALSE;
1212  }
1213 
1214  if (DBA_GetFieldString(dba_rec, DBA_FIELD_REC_NAME, &string, &num_bytes) &&
1215  (num_bytes > 0))
1216  {
1217  memcpy(timer->name, &string[0], num_bytes);
1218  }
1219 
1220  switch (timer->type)
1221  {
1222  case TIMER_TYPE_ALARM:
1223  {
1224  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERVICE_ID, &tmp32bit);
1225  timer->u.alarm.service_id = (U16BIT)tmp32bit;
1226 
1227  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
1228  timer->u.alarm.transport_id = (U16BIT)tmp32bit;
1229 
1230  DBA_GetFieldValue(dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
1231  timer->u.alarm.orig_net_id = (U16BIT)tmp32bit;
1232 
1233  if (timer->u.alarm.service_id != ADB_INVALID_DVB_ID)
1234  {
1235  timer->u.alarm.change_service = TRUE;
1236  }
1237  else
1238  {
1239  timer->u.alarm.change_service = FALSE;
1240  }
1241 
1242  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_RAMPVOLUME, &tmp32bit);
1243  if (tmp32bit == 1)
1244  {
1245  timer->u.alarm.ramp_volume = TRUE;
1246  }
1247  else
1248  {
1249  timer->u.alarm.ramp_volume = FALSE;
1250  }
1251  break;
1252  }
1253 
1254  case TIMER_TYPE_PVR_RECORD:
1255  {
1256  /* Initialise path to INVALID_RES_ID, the correct path will be assigned when
1257  * the recording starts*/
1258  timer->u.record.path = INVALID_RES_ID;
1259 
1260  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_DURATION, &tmp32bit);
1261  timer->u.record.duration = tmp32bit;
1262 
1263  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_EVENT_TRIGGERED, &tmp32bit);
1264  if (tmp32bit == 1)
1265  {
1266  timer->u.record.event_triggered = TRUE;
1267 
1268  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_EVENTID, &tmp32bit);
1269  timer->u.record.event_id = (U16BIT)tmp32bit;
1270  }
1271  else
1272  {
1273  timer->u.record.event_triggered = FALSE;
1274  }
1275 
1276  DBA_GetFieldValue(dba_rec, DBA_FIELD_SERVICE_ID, &tmp32bit);
1277  timer->u.record.service_id = (U16BIT)tmp32bit;
1278 
1279  DBA_GetFieldValue(dba_rec, DBA_FIELD_TRANSPORT_ID, &tmp32bit);
1280  timer->u.record.transport_id = (U16BIT)tmp32bit;
1281 
1282  DBA_GetFieldValue(dba_rec, DBA_FIELD_ORIG_NET_ID, &tmp32bit);
1283  timer->u.record.orig_net_id = (U16BIT)tmp32bit;
1284 
1285  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_DISKID, &tmp32bit);
1286  timer->u.record.disk_id = (U16BIT)tmp32bit;
1287 
1288  if (DBA_GetFieldString(dba_rec, DBA_FIELD_TIMER_CRID, &string, &num_bytes) &&
1289  (num_bytes > 0))
1290  {
1291  memcpy(timer->u.record.prog_crid, &string[0], num_bytes);
1292  }
1293 
1294  DBA_GetFieldValue(dba_rec, DBA_FIELD_CRID_RECOMMENDED, &tmp32bit);
1295  if (tmp32bit == 1)
1296  {
1297  timer->u.record.recommendation = TRUE;
1298  }
1299  else
1300  {
1301  timer->u.record.recommendation = FALSE;
1302  }
1303 
1304  if (DBA_GetFieldString(dba_rec, DBA_FIELD_TIMER_OTHERCRID, &string, &num_bytes) &&
1305  (num_bytes > 0))
1306  {
1307  memcpy(timer->u.record.other_crid, &string[0], num_bytes);
1308  }
1309 
1310  if (DBA_GetFieldString(dba_rec, DBA_FIELD_TIMER_ADDITIONAL_INFO, &string, &num_bytes) &&
1311  (num_bytes > 0))
1312  {
1313  memcpy(timer->u.record.additional_info, string, num_bytes);
1314  }
1315 
1316  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_START_PADDING, &tmp32bit);
1317  timer->u.record.start_padding = tmp32bit;
1318 
1319  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_END_PADDING, &tmp32bit);
1320  timer->u.record.end_padding = tmp32bit;
1321 
1322  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_NOTIFY_TIME, &tmp32bit);
1323  timer->u.record.notify_time = (U16BIT)tmp32bit;
1324 
1325  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_DO_NOT_DELETE, &tmp32bit);
1326  if (tmp32bit == 1)
1327  {
1328  timer->u.record.do_not_delete = TRUE;
1329  }
1330  else
1331  {
1332  timer->u.record.do_not_delete = FALSE;
1333  }
1334  break;
1335  }
1336 
1337  default:
1338  break;
1339  }
1340  }
1341  }
1342 
1343  dba_rec = DBA_FindRecord(DBA_RECORD_TIMER, NULL, dba_rec);
1344  }
1345 
1346 #ifdef COMMON_INTERFACE
1347  /* Read CICAM timers */
1348  dba_rec = DBA_FindRecord(DBA_RECORD_CICAM_TIMER, NULL, NULL);
1349  while (dba_rec != NULL)
1350  {
1351  cicam_timer = (ADB_CICAM_TIMER_REC *)STB_AppGetMemory(sizeof(ADB_CICAM_TIMER_REC));
1352  DBA_GetFieldValue(dba_rec, DBA_FIELD_TIMER_HANDLE, &tmp32bit);
1353  cicam_timer->timer_handle = tmp32bit;
1354  DBA_GetFieldValue(dba_rec, DBA_FIELD_PROFILE_CAM_ID, &tmp32bit);
1355  cicam_timer->cicam_identifier = tmp32bit;
1356  STB_LLAddBlockToEnd(&cicam_timer_list, (LINK_LIST_PTR_BLK *)cicam_timer);
1357 
1358  dba_rec = DBA_FindRecord(DBA_RECORD_CICAM_TIMER, NULL, dba_rec);
1359  }
1360 #endif
1361 
1362 #if 0
1363  /* Read stored events */
1364  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
1365  while (s_ptr != NULL)
1366  {
1367  dba_rec = DBA_FindRecord(DBA_RECORD_EVENT, s_ptr->dba_rec, NULL);
1368  while (dba_rec != NULL)
1369  {
1370  e_ptr = (ADB_EVENT_REC *)STB_AppGetMemory(sizeof(ADB_EVENT_REC));
1371  if (e_ptr != NULL)
1372  {
1373  memset(e_ptr, 0, sizeof(ADB_EVENT_REC));
1374 
1375  e_ptr->dba_rec = dba_rec;
1376 
1377  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_ID, &tmp32bit);
1378  e_ptr->event_id = (U16BIT)tmp32bit;
1379 
1380  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_STARTTIME, &tmp32bit);
1381  e_ptr->start = (U32DHMS)tmp32bit;
1382 
1383  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_DURATION, &tmp32bit);
1384  e_ptr->duration = (U32DHMS)tmp32bit;
1385 
1386  DBA_GetFieldValue(dba_rec, DBA_FIELD_VERSION, &tmp32bit);
1387  e_ptr->version = (U8BIT)tmp32bit;
1388 #if 0
1389  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_AGE_RATING, &tmp32bit);
1390  e_ptr->parental_age_rating = (U8BIT)tmp32bit;
1391 
1392  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_SCRAMBLED, &tmp32bit);
1393  e_ptr->scrambled = (tmp32bit == 0 ? FALSE : TRUE);
1394 
1395  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_SUBTITLES, &tmp32bit);
1396  e_ptr->subtitles_avail = (tmp32bit == 0 ? FALSE : TRUE);
1397 
1398  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_AUDIO_DESC, &tmp32bit);
1399  e_ptr->audio_desc = (tmp32bit == 0 ? FALSE : TRUE);
1400 
1401  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_FREE_TO_AIR, &tmp32bit);
1402  e_ptr->has_fta_desc = (tmp32bit == 0 ? FALSE : TRUE);
1403 
1404  DBA_GetFieldValue(dba_rec, DBA_FIELD_EVENT_DO_NOT_SCRAMBLE, &tmp32bit);
1405  e_ptr->do_not_scramble = (tmp32bit == 0 ? FALSE : TRUE);
1406 
1407  for (index = 0; index < ACFG_NUM_DB_LANGUAGES; index++)
1408  {
1409  if ((lang_code = ACFG_ConvertLangIdToCode(index)) != 0)
1410  {
1411  if (e_ptr->name_array[index] != NULL)
1412  {
1413  if (DBA_GetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_NAME,
1414  lang_code, &string, &num_bytes))
1415  {
1416  e_ptr->name_array[index] = DBDEF_MakeString(lang_code, string, num_bytes);
1417  }
1418  }
1419 
1420  if (e_ptr->desc_array[index] != NULL)
1421  {
1422  if (DBA_GetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_DESCRIPTION,
1423  lang_code, &string, &num_bytes))
1424  {
1425  e_ptr->desc_array[index] = DBDEF_MakeString(lang_code, string, num_bytes);
1426  }
1427  }
1428 
1429  if (e_ptr->extended_info[index].event_text != NULL)
1430  {
1431  if (DBA_GetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_EXTENDED_DESC,
1432  lang_code, &string, &num_bytes))
1433  {
1434  e_ptr->extended_info[index].event_text = DBDEF_MakeString(lang_code, string, num_bytes);
1435  }
1436  }
1437 
1438  if (e_ptr->guidance[index] != NULL)
1439  {
1440  if (DBA_GetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_GUIDANCE,
1441  lang_code, &string, &num_bytes))
1442  {
1443  e_ptr->guidance[index] = DBDEF_MakeString(lang_code, string, num_bytes);
1444  }
1445  }
1446  }
1447  }
1448 
1449  if (DBA_GetFieldData(dba_rec, DBA_FIELD_EVENT_CONTENT_DATA, &data, &data_len) &&
1450  (data_len != 0))
1451  {
1452  if ((e_ptr->content_data = STB_AppGetMemory(data_len)) != NULL)
1453  {
1454  memcpy(e_ptr->content_data, data, data_len);
1455  }
1456  }
1457 #endif
1458  /* Find where the event should be added into the service's schedule */
1459  InsertEventInSchedule(s_ptr, e_ptr);
1460  }
1461 
1462  dba_rec = DBA_FindRecord(DBA_RECORD_EVENT, s_ptr->dba_rec, dba_rec);
1463  }
1464 
1466  }
1467 #endif
1468  }
1469 
1470  FUNCTION_FINISH(DBDEF_LoadDatabase);
1471 
1472  return(retval);
1473 }
1474 
1487 {
1488  LINK_LIST_PTR_BLK *tmp_ptr;
1489  LINK_LIST_PTR_BLK *next_ptr;
1490 
1491  FUNCTION_START(DBDEF_DeleteAllRecords);
1492 
1493  /* Delete service records */
1494  tmp_ptr = STB_LLGetFirstBlock(&service_rec_list);
1495  while (tmp_ptr != NULL)
1496  {
1497  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1499  tmp_ptr = next_ptr;
1500  }
1501 
1502  /* Delete transport records */
1503  tmp_ptr = STB_LLGetFirstBlock(&transport_rec_list);
1504  while (tmp_ptr != NULL)
1505  {
1506  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1508  tmp_ptr = next_ptr;
1509  }
1510 
1511  /* Delete network records */
1512  tmp_ptr = STB_LLGetFirstBlock(&network_rec_list);
1513  while (tmp_ptr != NULL)
1514  {
1515  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1516  DeleteNetworkRec((ADB_NETWORK_REC *)tmp_ptr);
1517  tmp_ptr = next_ptr;
1518  }
1519 
1520  /* Delete satellite records */
1521  tmp_ptr = STB_LLGetFirstBlock(&satellite_rec_list);
1522  while (tmp_ptr != NULL)
1523  {
1524  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1525  DeleteSatelliteRec((ADB_SATELLITE_REC *)tmp_ptr);
1526  tmp_ptr = next_ptr;
1527  }
1528 
1529  /* Delete LNB band records */
1530  tmp_ptr = STB_LLGetFirstBlock(&lnb_band_rec_list);
1531  while (tmp_ptr != NULL)
1532  {
1533  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1535  tmp_ptr = next_ptr;
1536  }
1537 
1538  /* Delete LNB records */
1539  tmp_ptr = STB_LLGetFirstBlock(&lnb_rec_list);
1540  while (tmp_ptr != NULL)
1541  {
1542  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1543  DeleteLNBRec((ADB_LNB_REC *)tmp_ptr);
1544  tmp_ptr = next_ptr;
1545  }
1546 
1547  /* Delete favourite list records */
1548  tmp_ptr = STB_LLGetFirstBlock(&favlist_list);
1549  while (tmp_ptr != NULL)
1550  {
1551  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1553  tmp_ptr = next_ptr;
1554  }
1555 
1556  /* Delete crid records */
1557  tmp_ptr = STB_LLGetFirstBlock(&crid_rec_list);
1558  while (tmp_ptr != NULL)
1559  {
1560  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1562  tmp_ptr = next_ptr;
1563  }
1564 
1565  /* Delete timer records */
1566  tmp_ptr = STB_LLGetFirstBlock(&timer_list);
1567  while (tmp_ptr != NULL)
1568  {
1569  next_ptr = STB_LLGetNextBlock(tmp_ptr);
1570  DBDEF_DeleteTimerRec((ADB_TIMER_REC *)tmp_ptr);
1571  tmp_ptr = next_ptr;
1572  }
1573 
1574  /* Clear analog details */
1575  analog_network = NULL;
1576  num_analog_channels = 0;
1577 
1578  FUNCTION_FINISH(DBDEF_DeleteAllRecords);
1579 }
1580 
1581 /*!**************************************************************************
1582  * @brief Deletes all network, transport and services records for the given tuner type
1583  * @param tuner_type tuner type
1584  * @param satellite only used when tuner_type == SIGNAL_QPSK to specify the satellite
1585  * from which services should be deleted. If tuner_type is SIGNAL_QPSK
1586  * and satellite is NULL then all DVB-S services will be deleted.
1587  ****************************************************************************/
1588 void DBDEF_DeleteRecordsForTunerType(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
1589 {
1590  ADB_SERVICE_REC *s_ptr;
1591  ADB_TRANSPORT_REC *t_ptr;
1592  ADB_NETWORK_REC *n_ptr;
1593  void *next_ptr;
1594  BOOLEAN delete_network;
1595 
1596  FUNCTION_START(DBDEF_DeleteRecordsForTunerType);
1597 
1598  /* Delete service records */
1599  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
1600  while (s_ptr != NULL)
1601  {
1602  next_ptr = STB_LLGetNextBlock(&s_ptr->ptrs);
1603 
1604  if (DBDEF_ServiceForTunerType(s_ptr, tuner_type, satellite))
1605  {
1606  DBDEF_DeleteServiceRec(s_ptr);
1607  }
1608 
1609  s_ptr = (ADB_SERVICE_REC *)next_ptr;
1610  }
1611 
1612  /* Delete transport records */
1613  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
1614  while (t_ptr != NULL)
1615  {
1616  next_ptr = STB_LLGetNextBlock(&t_ptr->ptrs);
1617 
1618  if (DBDEF_TransportForTunerType(t_ptr, tuner_type, satellite))
1619  {
1620  DBDEF_DeleteTransportRec(t_ptr);
1621  }
1622 
1623  t_ptr = (ADB_TRANSPORT_REC *)next_ptr;
1624  }
1625 
1626  /* Delete network records */
1627  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
1628  while (n_ptr != NULL)
1629  {
1630  next_ptr = STB_LLGetNextBlock(&n_ptr->ptrs);
1631 
1632  if (DBDEF_NetworkInProfile(n_ptr))
1633  {
1634  /* See if this network is still referenced by any transports */
1635  delete_network = TRUE;
1636  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
1637  while ((t_ptr != NULL) && delete_network)
1638  {
1639  if (t_ptr->network == n_ptr)
1640  {
1641  /* Transport for this network found, so it shouldn't be deleted */
1642  delete_network = FALSE;
1643  }
1644 
1645  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetNextBlock(&t_ptr->ptrs);
1646  }
1647 
1648  if (delete_network)
1649  {
1650  DeleteNetworkRec(n_ptr);
1651  }
1652  }
1653 
1654  n_ptr = (ADB_NETWORK_REC *)next_ptr;
1655  }
1656 
1657  if (tuner_type == SIGNAL_ANALOG)
1658  {
1659  analog_network = NULL;
1660  num_analog_channels = 0;
1661  }
1662 
1663  FUNCTION_FINISH(DBDEF_DeleteRecordsForTunerType);
1664 }
1665 
1666 #ifdef DEBUG_PRINT_DATABASE
1667 
1678 void DBDEF_PrintAllRecords(void)
1679 {
1680  void *list_ptr;
1681 
1682  FUNCTION_START(DBDEF_PrintAllRecords);
1683 
1684  STB_SPDebugWrite("Database entries:");
1685 
1686  // print LNB records
1687  STB_SPDebugWrite("\tLNB records:");
1688  list_ptr = DBA_FirstLnb();
1689  while (list_ptr != NULL)
1690  {
1691  STB_SPDebugWrite("\t0x%x", list_ptr);
1692  PrintLNBRec((ADB_LNB_REC *)list_ptr);
1693  list_ptr = DBA_FindNext(list_ptr);
1694  }
1695 
1696  // print satellite records
1697  STB_SPDebugWrite("\tSatellite records:");
1698  list_ptr = DBA_FirstSatellite();
1699  while (list_ptr != NULL)
1700  {
1701  STB_SPDebugWrite("\t0x%x", list_ptr);
1702  PrintSatelliteRec((ADB_SATELLITE_REC *)list_ptr);
1703  list_ptr = DBA_FindNext(list_ptr);
1704  }
1705 
1706  // print network records
1707  STB_SPDebugWrite("\tNetwork records:");
1708  list_ptr = DBA_FindFirst(DBA_REC_NETWORK);
1709  while (list_ptr != NULL)
1710  {
1711  STB_SPDebugWrite("\t0x%x", list_ptr);
1712  PrintNetworkRec((ADB_NETWORK_REC *)list_ptr);
1713  list_ptr = DBA_FindNext(list_ptr);
1714  }
1715 
1716  // print transport records
1717  STB_SPDebugWrite("\tTransport records:");
1718  list_ptr = DBA_FindFirst(DBA_REC_TRANSPORT);
1719  while (list_ptr != NULL)
1720  {
1721  STB_SPDebugWrite("\t0x%x", list_ptr);
1722  PrintTransportRec((ADB_TRANSPORT_REC *)list_ptr);
1723  list_ptr = DBA_FindNext(list_ptr);
1724  }
1725 
1726  // delete service records
1727  STB_SPDebugWrite("\tService records:");
1728  list_ptr = DBA_FindFirst(DBA_REC_SERVICE);
1729  while (list_ptr != NULL)
1730  {
1731  STB_SPDebugWrite("\t0x%x", list_ptr);
1732  PrintServiceRec((ADB_SERVICE_REC *)list_ptr);
1733  list_ptr = DBA_FindNext(list_ptr);
1734  }
1735 
1736  STB_SPDebugWrite("End of database");
1737 
1738  FUNCTION_FINISH(DBDEF_PrintAllRecords);
1739 }
1740 
1741 #endif
1742 
1755 {
1756  U8BIT i, j;
1757  ADB_FAVLIST_REC *fl_ptr;
1758  ADB_FAVSERV_REC *fs_ptr;
1759  ADB_SERVICE_REC *s2_ptr;
1760  BOOLEAN events_shared;
1761 
1762  FUNCTION_START(DBDEF_DeleteServiceRec);
1763 
1764  if (s_ptr != NULL)
1765  {
1766  /* Remove the service from all favourite lists */
1767  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
1768  while (fl_ptr != NULL)
1769  {
1770  if ((fs_ptr = DBDEF_FindServiceInFavouriteList(fl_ptr, s_ptr)) != NULL)
1771  {
1772  DBDEF_DeleteServiceFromFavouriteList(fl_ptr, fs_ptr);
1773  }
1774 
1775  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
1776  }
1777 
1778  STB_LLRemoveBlock(&s_ptr->ptrs);
1779 
1780  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
1781  {
1782  if (s_ptr->provider_array[i] != NULL)
1783  {
1784  STB_AppFreeMemory(s_ptr->provider_array[i]);
1785  }
1786  for (j = 0; j < ADB_NUM_SERV_NAME_IDS; j++)
1787  {
1788  if (s_ptr->name_array[i][j] != NULL)
1789  {
1790  STB_AppFreeMemory(s_ptr->name_array[i][j]);
1791  }
1792  }
1793  if (s_ptr->guidance[i].text != NULL)
1794  {
1795  DBDEF_ReleaseString(s_ptr->guidance[i].text);
1796  }
1797  }
1798 
1799  if (s_ptr->provider_str != NULL)
1800  {
1801  STB_AppFreeMemory(s_ptr->provider_str);
1802  }
1803 
1804  DBDEF_DeleteStreamList(s_ptr->stream_list);
1805  DBDEF_DeleteAltServList(s_ptr->alt_serv_list);
1806 
1807  /* The now, next and schedule events may be shared with another service,
1808  * so first check there isn't another service using this schedule list */
1809  events_shared = FALSE;
1810  s2_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
1811  while (s2_ptr != NULL)
1812  {
1813  if ((s2_ptr != s_ptr) &&
1814  (((s2_ptr->event_schedule != NULL) && (s2_ptr->event_schedule == s_ptr->event_schedule)) ||
1815  ((s2_ptr->now_event != NULL) && (s2_ptr->now_event == s_ptr->now_event)) ||
1816  ((s2_ptr->next_event != NULL) && (s2_ptr->next_event == s_ptr->next_event))))
1817  {
1818  events_shared = TRUE;
1819  break;
1820  }
1821 
1822  s2_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)s2_ptr);
1823  }
1824 
1825  if (!events_shared)
1826  {
1827  DBDEF_DeleteEventList(s_ptr->now_event);
1828  DBDEF_DeleteEventList(s_ptr->next_event);
1829  DBDEF_DeleteEventList(s_ptr->event_schedule);
1830  }
1831 
1832  DBDEF_DeleteRCTLinks(s_ptr->rct_link_list);
1833  DBDEF_DeleteImageIcons(s_ptr->icon_list);
1834 
1835  if (s_ptr->serv_type == ADB_SERVICE_TYPE_ANALOG)
1836  {
1837  num_analog_channels--;
1838  }
1839 #ifdef COMMON_INTERFACE
1840  if (s_ptr->serv_type == ADB_SERVICE_TYPE_VIRTUAL)
1841  {
1842  /* delete associated virtual transport rec */
1843  DBDEF_DeleteTransportRec(s_ptr->transport);
1844  }
1845 #endif
1846 
1847  DBA_DestroyRecord(s_ptr->dba_rec);
1848 
1849  STB_AppFreeMemory(s_ptr);
1850  }
1851 
1852  FUNCTION_FINISH(DBDEF_DeleteServiceRec);
1853 }
1854 
1855 /*!**************************************************************************
1856  * @brief Returns the number of stream records in the given list
1857  * @param slist list of stream recs
1858  * @return Number of stream recs
1859  ****************************************************************************/
1861 {
1862  U16BIT num;
1863 
1864  FUNCTION_START(DBDEF_NumStreamsInList);
1865 
1866  for (num = 0; slist != NULL; num++)
1867  {
1868  slist = slist->next;
1869  }
1870 
1871  FUNCTION_FINISH(DBDEF_NumStreamsInList);
1872 
1873  return(num);
1874 }
1875 
1876 /*!**************************************************************************
1877  * @brief Creates a copy of a stream list, allocating new memory as required
1878  * @param slist list of stream recs to be copied
1879  * @return copied stream list
1880  ****************************************************************************/
1882 {
1883  ADB_STREAM_REC *new_list;
1884  ADB_STREAM_REC *slptr;
1885  ADB_STREAM_REC *srec;
1886 
1887  FUNCTION_START(DBDEF_CopyStreamList);
1888 
1889  new_list = NULL;
1890 
1891  if (slist != NULL)
1892  {
1893  slptr = slist;
1894  while (slptr != NULL)
1895  {
1896  if ((srec = STB_AppGetMemory(sizeof(ADB_STREAM_REC))) != NULL)
1897  {
1898  memcpy(srec, slptr, sizeof(ADB_STREAM_REC));
1899 
1900  if (srec->num_tags > 0)
1901  {
1902  if ((srec->tag_array = STB_AppGetMemory(srec->num_tags)) != NULL)
1903  {
1904  memcpy(srec->tag_array, slptr->tag_array, srec->num_tags);
1905  }
1906  else
1907  {
1908  srec->num_tags = 0;
1909  }
1910  }
1911  else
1912  {
1913  srec->tag_array = NULL;
1914  }
1915 
1916  /* Prepend the new stream rec to the list */
1917  srec->next = new_list;
1918  new_list = srec;
1919  }
1920 
1921  slptr = slptr->next;
1922  }
1923  }
1924 
1925  FUNCTION_FINISH(DBDEF_CopyStreamList);
1926 
1927  return(new_list);
1928 }
1929 
1942 {
1943  ADB_STREAM_REC *stream_rec;
1944  ADB_STREAM_REC *next_rec;
1945 
1946  stream_rec = slist;
1947  while (stream_rec != NULL)
1948  {
1949  next_rec = stream_rec->next;
1950 
1951  if (stream_rec->tag_array != NULL)
1952  {
1953  STB_AppFreeMemory(stream_rec->tag_array);
1954  }
1955 
1956  STB_AppFreeMemory(stream_rec);
1957  stream_rec = next_rec;
1958  }
1959 }
1960 
1968 {
1969  ADB_EVENT_REC *e_ptr;
1970 
1971  FUNCTION_START(DBDEF_FindScheduleEventById);
1972 
1973  if ((s_ptr->now_event != NULL) && (s_ptr->now_event->event_id == event_id))
1974  {
1975  e_ptr = s_ptr->now_event;
1976  }
1977  else if ((s_ptr->next_event != NULL) && (s_ptr->next_event->event_id == event_id))
1978  {
1979  e_ptr = s_ptr->next_event;
1980  }
1981  else
1982  {
1983  e_ptr = s_ptr->event_schedule;
1984  while ((e_ptr != NULL) && (e_ptr->event_id != event_id))
1985  {
1986  e_ptr = e_ptr->next;
1987  }
1988  }
1989 
1990  FUNCTION_FINISH(DBDEF_FindScheduleEventById);
1991 
1992  return(e_ptr);
1993 }
1994 
2004  U32BIT private_data_specifier)
2005 {
2006  ADB_EVENT_DESC *desc_ptr;
2007  U32BIT priv_data_code;
2008 
2009  FUNCTION_START(DBDEF_FindEventDescriptor);
2010 
2011  priv_data_code = 0;
2012  desc_ptr = start_desc;
2013 
2014  while (desc_ptr != NULL)
2015  {
2016  if (private_data_specifier == 0)
2017  {
2018  if ((desc_ptr->desc_data[0] == desc_tag))
2019  {
2020  /* Found the descriptor */
2021  break;
2022  }
2023  }
2024  else
2025  {
2026  /* Descriptor to be found must be preceded by the given private data specifier,
2027  * so check for any private data specifier descriptors so the value preceding
2028  * the descriptor to be found can be checked */
2029  if (desc_ptr->desc_data[0] == PRIV_DATA_SPEC_DTAG)
2030  {
2031  priv_data_code = (desc_ptr->desc_data[2] << 24) | (desc_ptr->desc_data[3] << 16) |
2032  (desc_ptr->desc_data[4] << 8) | desc_ptr->desc_data[5];
2033  }
2034  else if ((desc_ptr->desc_data[0] == desc_tag) && (priv_data_code == private_data_specifier))
2035  {
2036  /* Found the descriptor */
2037  break;
2038  }
2039  }
2040 
2041  desc_ptr = desc_ptr->next;
2042  }
2043 
2044  FUNCTION_FINISH(DBDEF_FindEventDescriptor);
2045 
2046  return(desc_ptr);
2047 }
2048 
2056 {
2057  ADB_EVENT_DESC *event_desc, *und_event_desc;
2058  U8BIT *text_lang_ids;
2059  U32BIT lang_code, und_lang_code;
2060  U8BIT lang_id, i, und_lang_id;
2061  U8BIT *dptr;
2062  SI_STRING_DESC *temp_str;
2063  U16BIT str_len;
2064  U8BIT *name_str;
2065 
2066  FUNCTION_START(DBDEF_GetEventName);
2067 
2068  ASSERT(e_ptr != NULL);
2069 
2070  name_str = NULL;
2071 
2072  text_lang_ids = DBDEF_GetTextLang();
2073  if (text_lang_ids != NULL)
2074  {
2075  event_desc = e_ptr->desc_list_head;
2076 
2077  und_lang_id = ACFG_INVALID_DB_LANG;
2078  und_lang_code = ACFG_GetUndefinedLanguageBehaviour();
2079  if (und_lang_code != ADB_LANG_CODE_UNDEF)
2080  {
2081  /* See if this lang is in the list of valid langs */
2082  lang_id = ACFG_ConvertLangCodeToId(und_lang_code);
2083  if (lang_id != ACFG_INVALID_DB_LANG)
2084  {
2085  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2086  ((text_lang_ids[i] != ACFG_INVALID_DB_LANG)); i++)
2087  {
2088  if (lang_id == text_lang_ids[i])
2089  {
2090  und_lang_id = lang_id;
2091  break;
2092  }
2093  }
2094  }
2095  }
2096 
2097  und_event_desc = NULL;
2098  /* Search for a short event descriptor with a language code included in the text langs */
2099  while ((name_str == NULL) &&
2100  ((event_desc = DBDEF_FindEventDescriptor(event_desc, SHORT_EVENT_DTAG, 0)) != NULL))
2101  {
2102  dptr = ReadLanguageCode(&event_desc->desc_data[2], &lang_code);
2103 
2104  /* See if this lang is in the list of valid langs */
2105  lang_id = ACFG_ConvertLangCodeToId(lang_code);
2106  if (lang_id != ACFG_INVALID_DB_LANG)
2107  {
2108  for (i = 0; (i != ACFG_MAX_DB_LANG_CODES) &&
2109  (text_lang_ids[i] != ACFG_INVALID_DB_LANG) && (name_str == NULL); i++)
2110  {
2111  if (lang_id == text_lang_ids[i])
2112  {
2113  /* Required language found, read the event name */
2114  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2115  if (temp_str != NULL)
2116  {
2117  name_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, lang_code);
2118  STB_SIReleaseStringDesc(temp_str);
2119  }
2120  }
2121  }
2122  }
2123  if ((name_str == NULL) && (und_lang_id != ACFG_INVALID_DB_LANG) && (und_event_desc == NULL))
2124  {
2125  /* If this descriptor is good enough for the undefined language behaviour, save it */
2126  if ((lang_code == ADB_LANG_CODE_UNDEF) || (lang_code == ADB_LANG_CODE_QAA))
2127  {
2128  und_event_desc = event_desc;
2129  }
2130  }
2131  event_desc = event_desc->next;
2132  }
2133 
2134  if ((name_str == NULL) && (und_event_desc != NULL))
2135  {
2136  /* No string has been found, apply the undefined language behaviour */
2137  dptr = ReadLanguageCode(&und_event_desc->desc_data[2], &lang_code);
2138  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2139  if (temp_str != NULL)
2140  {
2141  name_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, und_lang_code);
2142  STB_SIReleaseStringDesc(temp_str);
2143  }
2144  }
2145  }
2146 
2147  if (name_str == NULL)
2148  {
2149  /* No text langs defined, or failed to find an event descriptor with a required lang,
2150  * so return the first event name */
2151  event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head, SHORT_EVENT_DTAG, 0);
2152  if (event_desc != NULL)
2153  {
2154  dptr = ReadLanguageCode(&event_desc->desc_data[2], &lang_code);
2155  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2156  if (temp_str != NULL)
2157  {
2158  name_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, lang_code);
2159  STB_SIReleaseStringDesc(temp_str);
2160  }
2161  }
2162  }
2163 
2164  FUNCTION_FINISH(DBDEF_GetEventName);
2165 
2166  return(name_str);
2167 }
2168 
2176 {
2177  ADB_EVENT_DESC *event_desc, *und_event_desc;
2178  U8BIT *text_lang_ids;
2179  U32BIT lang_code, und_lang_code;
2180  U8BIT lang_id, i, und_lang_id;
2181  U8BIT *dptr;
2182  SI_STRING_DESC *temp_str;
2183  U16BIT str_len;
2184  U8BIT *desc_str;
2185 
2186  FUNCTION_START(DBDEF_GetEventDescription);
2187 
2188  ASSERT(e_ptr != NULL);
2189 
2190  desc_str = NULL;
2191 
2192  text_lang_ids = DBDEF_GetTextLang();
2193  if (text_lang_ids != NULL)
2194  {
2195  /* Search for a short event descriptor with a language code included in the text langs */
2196  event_desc = e_ptr->desc_list_head;
2197 
2198  und_lang_id = ACFG_INVALID_DB_LANG;
2199  und_lang_code = ACFG_GetUndefinedLanguageBehaviour();
2200  if (und_lang_code != ADB_LANG_CODE_UNDEF)
2201  {
2202  /* See if this lang is in the list of valid langs */
2203  lang_id = ACFG_ConvertLangCodeToId(und_lang_code);
2204  if (lang_id != ACFG_INVALID_DB_LANG)
2205  {
2206  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2207  ((text_lang_ids[i] != ACFG_INVALID_DB_LANG)); i++)
2208  {
2209  if (lang_id == text_lang_ids[i])
2210  {
2211  und_lang_id = lang_id;
2212  break;
2213  }
2214  }
2215  }
2216  }
2217 
2218  und_event_desc = NULL;
2219  while ((desc_str == NULL) &&
2220  ((event_desc = DBDEF_FindEventDescriptor(event_desc, SHORT_EVENT_DTAG, 0)) != NULL))
2221  {
2222  dptr = ReadLanguageCode(&event_desc->desc_data[2], &lang_code);
2223 
2224  /* See if this lang is in the list of valid langs */
2225  lang_id = ACFG_ConvertLangCodeToId(lang_code);
2226  if (lang_id != ACFG_INVALID_DB_LANG)
2227  {
2228  /* Skip the event name */
2229  dptr += dptr[0] + 1;
2230 
2231  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2232  (text_lang_ids[i] != ACFG_INVALID_DB_LANG) && (desc_str == NULL); i++)
2233  {
2234  if (lang_id == text_lang_ids[i])
2235  {
2236  /* Required language found, read the event description */
2237  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2238  if (temp_str != NULL)
2239  {
2240  desc_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, lang_code);
2241  STB_SIReleaseStringDesc(temp_str);
2242  }
2243  }
2244  }
2245  }
2246  if ((desc_str == NULL) && (und_lang_id != ACFG_INVALID_DB_LANG) && (und_event_desc == NULL))
2247  {
2248  /* If this descriptor is good enough for the undefined language behaviour, save it */
2249  if ((lang_code == ADB_LANG_CODE_UNDEF) || (lang_code == ADB_LANG_CODE_QAA))
2250  {
2251  und_event_desc = event_desc;
2252  }
2253  }
2254  event_desc = event_desc->next;
2255  }
2256 
2257  if ((desc_str == NULL) && (und_event_desc != NULL))
2258  {
2259  /* No string has been found, apply the undefined language behaviour */
2260  dptr = ReadLanguageCode(&und_event_desc->desc_data[2], &lang_code);
2261  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2262  if (temp_str != NULL)
2263  {
2264  desc_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, und_lang_code);
2265  STB_SIReleaseStringDesc(temp_str);
2266  }
2267  }
2268  }
2269 
2270  if (desc_str == NULL)
2271  {
2272  /* No text langs defined, or failed to find an event descriptor with a required lang,
2273  * so return the first event name */
2274  event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head, SHORT_EVENT_DTAG, 0);
2275  if (event_desc != NULL)
2276  {
2277  dptr = ReadLanguageCode(&event_desc->desc_data[2], &lang_code);
2278 
2279  /* Skip the event name */
2280  dptr += dptr[0] + 1;
2281 
2282  dptr = STB_SIReadString(dptr[0], dptr + 1, &temp_str);
2283  if (temp_str != NULL)
2284  {
2285  desc_str = STB_ConvertStringToUTF8(temp_str->str_ptr, &str_len, FALSE, lang_code);
2286  STB_SIReleaseStringDesc(temp_str);
2287  }
2288  }
2289  }
2290 
2291  FUNCTION_FINISH(DBDEF_GetEventDescription);
2292 
2293  return(desc_str);
2294 }
2295 
2303 {
2304  ADB_EVENT_DESC *event_desc, *und_event_desc;
2305  ADB_EVENT_DESC *selected_event_desc;
2306  U8BIT *text_lang_ids;
2307  U32BIT lang_code;
2308  U32BIT selected_lang_code, und_lang_code;
2309  U8BIT lang_id, i, und_lang_id;
2310  U8BIT *dptr;
2311  U8BIT *end_ptr;
2312  U8BIT desc_num;
2314  U16BIT str_len;
2315  U8BIT *temp_str;
2316  U8BIT *temp2_str;
2317  U8BIT *desc_str;
2318 
2319  FUNCTION_START(DBDEF_GetEventExtendedDescription);
2320 
2321  ASSERT(e_ptr != NULL);
2322 
2323  desc_str = NULL;
2324 
2325  selected_event_desc = NULL;
2326 
2327  text_lang_ids = DBDEF_GetTextLang();
2328  if (text_lang_ids != NULL)
2329  {
2330  event_desc = e_ptr->desc_list_head;
2331 
2332  und_lang_id = ACFG_INVALID_DB_LANG;
2333  und_lang_code = ACFG_GetUndefinedLanguageBehaviour();
2334  if (und_lang_code != ADB_LANG_CODE_UNDEF)
2335  {
2336  /* See if this lang is in the list of valid langs */
2337  lang_id = ACFG_ConvertLangCodeToId(und_lang_code);
2338  if (lang_id != ACFG_INVALID_DB_LANG)
2339  {
2340  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2341  ((text_lang_ids[i] != ACFG_INVALID_DB_LANG)); i++)
2342  {
2343  if (lang_id == text_lang_ids[i])
2344  {
2345  und_lang_id = lang_id;
2346  break;
2347  }
2348  }
2349  }
2350  }
2351 
2352  und_event_desc = NULL;
2353  /* Search for an extended event descriptor with a language code
2354  * included in the text langs and a descriptor number of 0 */
2355  while ((selected_event_desc == NULL) &&
2356  ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL))
2357  {
2358  /* Check the descriptor number is 0 */
2359  if ((event_desc->desc_data[2] >> 4) == 0)
2360  {
2361  dptr = ReadLanguageCode(&event_desc->desc_data[3], &lang_code);
2362 
2363  /* See if this lang is in the list of valid langs */
2364  lang_id = ACFG_ConvertLangCodeToId(lang_code);
2365  if (lang_id != ACFG_INVALID_DB_LANG)
2366  {
2367  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2368  (text_lang_ids[i] != ACFG_INVALID_DB_LANG) && (selected_event_desc == NULL); i++)
2369  {
2370  if (lang_id == text_lang_ids[i])
2371  {
2372  /* Required language found, read the event description */
2373  selected_event_desc = event_desc;
2374  }
2375  }
2376  }
2377  if ((selected_event_desc == NULL) && (und_lang_id != ACFG_INVALID_DB_LANG) &&
2378  (und_event_desc == NULL))
2379  {
2380  /* If this descriptor is good enough for the undefined language behaviour,
2381  save it */
2382  if ((lang_code == ADB_LANG_CODE_UNDEF) || (lang_code == ADB_LANG_CODE_QAA))
2383  {
2384  und_event_desc = event_desc;
2385  }
2386  }
2387  }
2388  event_desc = event_desc->next;
2389  }
2390  if ((selected_event_desc == NULL) && (und_event_desc != NULL))
2391  {
2392  selected_event_desc = und_event_desc;
2393  }
2394  }
2395 
2396  if (selected_event_desc == NULL)
2397  {
2398  /* No text langs defined, or failed to find an event descriptor with a required lang,
2399  * so use the first extended event descriptor with a descriptor number of 0 */
2400  event_desc = e_ptr->desc_list_head;
2401  while ((selected_event_desc == NULL) &&
2402  ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL))
2403  {
2404  /* Check the descriptor number is 0 */
2405  if ((event_desc->desc_data[2] >> 4) == 0)
2406  {
2407  selected_event_desc = event_desc;
2408  }
2409 
2410  event_desc = event_desc->next;
2411  }
2412  }
2413 
2414  if (selected_event_desc != NULL)
2415  {
2416  /* Read all extended event descriptors with consecutive descriptor numbers and the
2417  * same language, to build up the extended descriptor string */
2418  ReadLanguageCode(&selected_event_desc->desc_data[3], &selected_lang_code);
2419  desc_num = 0;
2420 
2421  event_desc = selected_event_desc;
2422  while (event_desc != NULL)
2423  {
2424  end_ptr = &event_desc->desc_data[2] + event_desc->desc_data[1];
2425 
2426  /* Skip past the items to the non-itemised text */
2427  dptr = &event_desc->desc_data[6] + event_desc->desc_data[6] + 1;
2428 
2429  /* Check the lengths used are valid. Some have been found that are defined such
2430  * that the end of the text extends beyond the end of the descriptor! */
2431  if (dptr + dptr[0] < end_ptr)
2432  {
2433  /* Read the description string */
2434  temp_str = NULL;
2435 
2436  dptr = STB_SIReadString(dptr[0], dptr + 1, &si_string);
2437  if (si_string != NULL)
2438  {
2439  temp_str = STB_ConvertStringToUTF8(si_string->str_ptr, &str_len, FALSE,
2440  selected_lang_code);
2441  STB_SIReleaseStringDesc(si_string);
2442  }
2443 
2444  if ((temp_str != NULL) && (desc_str != NULL))
2445  {
2446  temp2_str = STB_ConcatUnicodeStrings(desc_str, temp_str);
2447  STB_ReleaseUnicodeString(desc_str);
2448  STB_ReleaseUnicodeString(temp_str);
2449  desc_str = temp2_str;
2450  }
2451  else if ((temp_str != NULL) && (desc_str == NULL))
2452  {
2453  desc_str = temp_str;
2454  }
2455 
2456  /* If this is the last descriptor then the string is complete */
2457  if ((event_desc->desc_data[2] & 0x0f) == desc_num)
2458  {
2459  /* No more descriptors need to be read */
2460  event_desc = NULL;
2461  }
2462  else
2463  {
2464  /* Find the next extended event descriptor for this language */
2465  desc_num++;
2466 
2467  event_desc = event_desc->next;
2468  while ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL)
2469  {
2470  if ((event_desc->desc_data[2] >> 4) == desc_num)
2471  {
2472  ReadLanguageCode(&event_desc->desc_data[3], &lang_code);
2473  if (lang_code == selected_lang_code)
2474  {
2475  /* Next descriptor found */
2476  break;
2477  }
2478  }
2479 
2480  event_desc = event_desc->next;
2481  }
2482  }
2483  }
2484  else
2485  {
2486  /* Invalid descriptor, so can't append any more */
2487  event_desc = NULL;
2488  }
2489  }
2490  }
2491 
2492  FUNCTION_FINISH(DBDEF_GetEventExtendedDescription);
2493 
2494  return(desc_str);
2495 }
2496 
2504 {
2505  ADB_EVENT_DESC *event_desc, *und_event_desc;
2506  ADB_EVENT_DESC *selected_event_desc;
2507  U8BIT *text_lang_ids;
2508  U32BIT lang_code;
2509  U32BIT selected_lang_code, und_lang_code;
2510  U8BIT lang_id, i, und_lang_id;
2511  U8BIT *end_ptr;
2512  U8BIT desc_num;
2513  U16BIT str_len;
2514  U8BIT *item_dptr;
2515  U8BIT *item_end_ptr;
2516  U8BIT length_of_items;
2517  U16BIT index;
2518  ADB_EVENT_ITEMIZED_INFO *event_itemized_info;
2519 
2520  FUNCTION_START(ADB_GetEventItemizedDescription);
2521 
2522  ASSERT(e_ptr != NULL);
2523 
2524  event_itemized_info = NULL;
2525  index = 0;
2526  selected_event_desc = NULL;
2527 
2528  text_lang_ids = DBDEF_GetTextLang();
2529  if (text_lang_ids != NULL)
2530  {
2531  event_desc = e_ptr->desc_list_head;
2532 
2533  und_lang_id = ACFG_INVALID_DB_LANG;
2534  und_lang_code = ACFG_GetUndefinedLanguageBehaviour();
2535  if (und_lang_code != ADB_LANG_CODE_UNDEF)
2536  {
2537  /* See if this lang is in the list of valid langs */
2538  lang_id = ACFG_ConvertLangCodeToId(und_lang_code);
2539  if (lang_id != ACFG_INVALID_DB_LANG)
2540  {
2541  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2542  ((text_lang_ids[i] != ACFG_INVALID_DB_LANG)); i++)
2543  {
2544  if (lang_id == text_lang_ids[i])
2545  {
2546  und_lang_id = lang_id;
2547  break;
2548  }
2549  }
2550  }
2551  }
2552  und_event_desc = NULL;
2553 
2554  /* Search for an extended event descriptor with a language code
2555  * included in the text langs and a descriptor number of 0 */
2556  while ((selected_event_desc == NULL) &&
2557  ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL))
2558  {
2559  /* Check the descriptor number is 0 */
2560  if ((event_desc->desc_data[2] >> 4) == 0)
2561  {
2562  ReadLanguageCode(&event_desc->desc_data[3], &lang_code);
2563 
2564  /* See if this lang is in the list of valid langs */
2565  lang_id = ACFG_ConvertLangCodeToId(lang_code);
2566  if (lang_id != ACFG_INVALID_DB_LANG)
2567  {
2568  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2569  (text_lang_ids[i] != ACFG_INVALID_DB_LANG) && (selected_event_desc == NULL); i++)
2570  {
2571  if (lang_id == text_lang_ids[i])
2572  {
2573  /* Required language found, read the event description */
2574  selected_event_desc = event_desc;
2575  }
2576  }
2577  }
2578  if ((selected_event_desc == NULL) && (und_lang_id != ACFG_INVALID_DB_LANG) &&
2579  (und_event_desc == NULL))
2580  {
2581  /* If this descriptor is good enough for the undefined language behaviour,
2582  save it */
2583  if ((lang_code == ADB_LANG_CODE_UNDEF) || (lang_code == ADB_LANG_CODE_QAA))
2584  {
2585  und_event_desc = event_desc;
2586  }
2587  }
2588  }
2589  event_desc = event_desc->next;
2590  }
2591  if ((selected_event_desc == NULL) && (und_event_desc != NULL))
2592  {
2593  selected_event_desc = und_event_desc;
2594  }
2595  }
2596 
2597  if (selected_event_desc == NULL)
2598  {
2599  /* No text langs defined, or failed to find an event descriptor with a required lang,
2600  * so use the first extended event descriptor with a descriptor number of 0 */
2601  event_desc = e_ptr->desc_list_head;
2602  while ((selected_event_desc == NULL) &&
2603  ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL))
2604  {
2605  /* Check the descriptor number is 0 */
2606  if ((event_desc->desc_data[2] >> 4) == 0)
2607  {
2608  selected_event_desc = event_desc;
2609  }
2610  event_desc = event_desc->next;
2611  }
2612  }
2613 
2614  if (selected_event_desc != NULL)
2615  {
2616  /* Read all extended event descriptors with consecutive descriptor numbers and the
2617  * same language, to build up the extended descriptor string */
2618  ReadLanguageCode(&selected_event_desc->desc_data[3], &selected_lang_code);
2619  desc_num = 0;
2620 
2621  event_desc = selected_event_desc;
2622  while (event_desc != NULL)
2623  {
2624  end_ptr = &event_desc->desc_data[2] + event_desc->desc_data[1];
2625 
2626  /* Get the length and address of items from event descriptor */
2627  item_dptr = &event_desc->desc_data[6];
2628  length_of_items = event_desc->desc_data[6];
2629  item_end_ptr = item_dptr + length_of_items;
2630 
2631  /* Get the item descripton data and item data from event descriptor*/
2632  /* Check the lengths used are valid.*/
2633  if ((length_of_items != 0) && (item_dptr != NULL) && (item_end_ptr < end_ptr))
2634  {
2635  SI_STRING_DESC *item_string;
2636  U8BIT *temp_item_str;
2637 
2638  item_dptr++;
2639  while(item_dptr < item_end_ptr)
2640  {
2641  if (index == 0 )
2642  {
2643  event_itemized_info = STB_AppGetMemory(sizeof(ADB_EVENT_ITEMIZED_INFO));
2644  }
2645  else
2646  {
2647  event_itemized_info = STB_AppResizeMemory(event_itemized_info,
2648  (index + 1) * sizeof(ADB_EVENT_ITEMIZED_INFO));
2649  }
2650 
2651  if (event_itemized_info != NULL)
2652  {
2653  item_dptr = STB_SIReadString(item_dptr[0], item_dptr + 1, &item_string);
2654 
2655  if (item_string != NULL)
2656  {
2657  temp_item_str = STB_ConvertStringToUTF8(item_string->str_ptr,
2658  &str_len,
2659  FALSE,
2660  selected_lang_code);
2661  event_itemized_info[index].item_description = temp_item_str;
2662  STB_SIReleaseStringDesc(item_string);
2663  }
2664 
2665  item_dptr = STB_SIReadString(item_dptr[0], item_dptr + 1, &item_string);
2666  if (item_string != NULL)
2667  {
2668  temp_item_str = STB_ConvertStringToUTF8(item_string->str_ptr,
2669  &str_len,
2670  FALSE,
2671  selected_lang_code);
2672  event_itemized_info[index].item = temp_item_str;
2673  STB_SIReleaseStringDesc(item_string);
2674  }
2675  index++;
2676  }
2677  }
2678 
2679  // If this is the last descriptor then the string is complete
2680  if ((event_desc->desc_data[2] & 0x0f) == desc_num)
2681  {
2682  //No more descriptors need to be read
2683  event_desc = NULL;
2684  }
2685  else
2686  {
2687  //Find the next extended event descriptor for this language
2688  desc_num++;
2689 
2690  event_desc = event_desc->next;
2691  while ((event_desc = DBDEF_FindEventDescriptor(event_desc, EXTENDED_EVENT_DTAG, 0)) != NULL)
2692  {
2693  if ((event_desc->desc_data[2] >> 4) == desc_num)
2694  {
2695  ReadLanguageCode(&event_desc->desc_data[3], &lang_code);
2696  if (lang_code == selected_lang_code)
2697  {
2698  //Next descriptor found
2699  break;
2700  }
2701  }
2702  event_desc = event_desc->next;
2703  }
2704  }
2705  }
2706  else
2707  {
2708  /* Invalid descriptor, so can't append any more */
2709  event_desc = NULL;
2710  }
2711  }//while (event_desc != NULL)
2712  }
2713 
2714  *num_items_ptr = index;
2715 
2716  FUNCTION_FINISH(DBDEF_GetEventItemizedDescription);
2717 
2718  return(event_itemized_info);
2719 }
2720 
2732 U8BIT* DBDEF_GetEventGuidance(ADB_EVENT_REC *e_ptr, ADB_SERVICE_REC *s_ptr, U8BIT *type, U8BIT *mode)
2733 {
2734  ADB_EVENT_DESC *event_desc;
2735  U32BIT country_code;
2736  U8BIT *dptr;
2737  U8BIT dlen;
2738  U8BIT *text_lang_ids;
2739  U32BIT lang_code;
2740  U8BIT lang_id;
2742  U16BIT str_len;
2743  U8BIT *text_str;
2744  ADB_TRANSPORT_REC *t_ptr;
2745  U16BIT i;
2746 
2747  FUNCTION_START(DBDEF_GetEventGuidance);
2748 
2749  text_str = NULL;
2750 
2751  if (e_ptr != NULL)
2752  {
2753  /* UK DTT guidance descriptor */
2754  country_code = ACFG_GetCountry();
2755  if ((country_code == COUNTRY_CODE_UK) && ((t_ptr = s_ptr->transport) != NULL))
2756  {
2757  if (t_ptr->sig_type == SIGNAL_COFDM)
2758  {
2759  text_lang_ids = DBDEF_GetTextLang();
2760  if (text_lang_ids != NULL)
2761  {
2762  /* Search for a guidance descriptor with a language code included in the text langs */
2763  event_desc = e_ptr->desc_list_head;
2764 
2765  while ((text_str == NULL) &&
2766  ((event_desc = DBDEF_FindEventDescriptor(event_desc, USER_DEFINED_DTAG_0x89,
2767  UK_DTT_PRIVATE_DATA_CODE)) != NULL))
2768  {
2769  dlen = event_desc->desc_data[1];
2770  dptr = &event_desc->desc_data[2];
2771 
2772  *type = *dptr & 0x03;
2773  if ((*type == 0) || (*type == 1))
2774  {
2775  dptr++;
2776  dlen--;
2777 
2778  if (*type == 1)
2779  {
2780  /* Mode is a 1-bit value */
2781  *mode = *dptr & 0x01;
2782  dptr++;
2783  dlen--;
2784  }
2785  else
2786  {
2787  *mode = 0;
2788  }
2789 
2790  dptr = ReadLanguageCode(dptr, &lang_code);
2791  dlen -= 3;
2792 
2793  lang_id = ACFG_ConvertLangCodeToId(lang_code);
2794  if (lang_id != ACFG_INVALID_DB_LANG)
2795  {
2796  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
2797  (text_lang_ids[i] != ACFG_INVALID_DB_LANG) && (text_str == NULL); i++)
2798  {
2799  if (lang_id == text_lang_ids[i])
2800  {
2801  STB_SIReadString(dlen, dptr, &si_string);
2802  if (si_string != NULL)
2803  {
2804  text_str = STB_ConvertStringToUTF8(si_string->str_ptr, &str_len,
2805  FALSE, lang_code);
2806  STB_SIReleaseStringDesc(si_string);
2807  }
2808  }
2809  }
2810  }
2811  }
2812 
2813  event_desc = event_desc->next;
2814  }
2815  }
2816 
2817  if (text_str == NULL)
2818  {
2819  /* No text langs defined, or failed to find a guidance descriptor with a desired
2820  * lang, so just return the first one available */
2821  if ((event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head,
2822  USER_DEFINED_DTAG_0x89, UK_DTT_PRIVATE_DATA_CODE)) != NULL)
2823  {
2824  dlen = event_desc->desc_data[1];
2825  dptr = &event_desc->desc_data[2];
2826 
2827  *type = *dptr & 0x03;
2828  if ((*type == 0) || (*type == 1))
2829  {
2830  dptr++;
2831  dlen--;
2832 
2833  if (*type == 1)
2834  {
2835  /* Mode is a 1-bit value */
2836  *mode = *dptr & 0x01;
2837  dptr++;
2838  dlen--;
2839  }
2840  else
2841  {
2842  *mode = 0;
2843  }
2844 
2845  dptr = ReadLanguageCode(dptr, &lang_code);
2846  dlen -= 3;
2847 
2848  STB_SIReadString(dlen, dptr, &si_string);
2849  if (si_string != NULL)
2850  {
2851  text_str = STB_ConvertStringToUTF8(si_string->str_ptr, &str_len,
2852  FALSE, lang_code);
2853  STB_SIReleaseStringDesc(si_string);
2854  }
2855  }
2856  }
2857  }
2858  }
2859  }
2860  }
2861  if (text_str == NULL)
2862  {
2863  /* No event guidance, so see if the service has guidance defined */
2864  text_str = DBDEF_GetServiceGuidanceData(s_ptr, type, mode);
2865  }
2866  FUNCTION_FINISH(DBDEF_GetEventGuidance);
2867 
2868  return(text_str);
2869 }
2870 
2879 U8BIT* DBDEF_GetServiceGuidanceData(ADB_SERVICE_REC *s_ptr, U8BIT *type, U8BIT *mode)
2880 {
2881  U8BIT *text_str;
2882  U8BIT *lang_ids;
2883  U16BIT i;
2884 
2885  FUNCTION_START(DBDEF_GetServiceGuidance);
2886 
2887  text_str = NULL;
2888 
2889  if (s_ptr != NULL)
2890  {
2891  if ((lang_ids = DBDEF_GetTextLang()) != NULL)
2892  {
2893  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) && (lang_ids[i] != ACFG_INVALID_DB_LANG) &&
2894  (text_str == NULL); i++)
2895  {
2896  if ((s_ptr->guidance[lang_ids[i]].text != NULL) &&
2897  ((s_ptr->guidance[lang_ids[i]].type == 0) || (s_ptr->guidance[lang_ids[i]].type == 1)))
2898  {
2899  *type = s_ptr->guidance[lang_ids[i]].type;
2900  *mode = s_ptr->guidance[lang_ids[i]].mode;
2901  text_str = CopyString(s_ptr->guidance[lang_ids[i]].text, TRUE);
2902  }
2903  }
2904  }
2905  }
2906 
2907  FUNCTION_FINISH(DBDEF_GetServiceGuidanceData);
2908 
2909  return(text_str);
2910 }
2911 
2919 {
2920  U8BIT *text_str;
2921  U8BIT gtype;
2922  U8BIT gmode;
2923 
2924  FUNCTION_START(DBDEF_GetServiceGuidance);
2925 
2926  text_str = DBDEF_GetServiceGuidanceData(s_ptr, &gtype, &gmode);
2927 
2928  FUNCTION_FINISH(DBDEF_GetServiceGuidance);
2929 
2930  return(text_str);
2931 }
2932 
2939 {
2940  ADB_EVENT_DESC *event_desc;
2941  U32BIT country_code;
2942  U32BIT lang_code;
2943  U8BIT dlen;
2944  U8BIT *dptr;
2945  U8BIT age;
2946 
2947  FUNCTION_START(DBDEF_GetEventParentalAge);
2948 
2949  age = 0;
2950 
2951  if ((event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head, PARENTAL_RATING_DTAG, 0)) != NULL)
2952  {
2953  dlen = event_desc->desc_data[1];
2954  if (dlen >= 4)
2955  {
2956  country_code = ACFG_GetCountry();
2957 
2958  dptr = &event_desc->desc_data[2];
2959  while (dlen >= 4)
2960  {
2961  dptr = ReadLanguageCode(dptr, &lang_code);
2962  if (lang_code == country_code)
2963  {
2964  age = *dptr;
2965  break;
2966  }
2967 
2968  dptr++;
2969  dlen -= 4;
2970  }
2971  }
2972  }
2973 
2974  FUNCTION_FINISH(DBDEF_GetEventParentalAge);
2975 
2976  return(age);
2977 }
2978 
2985 {
2986  ADB_EVENT_DESC *event_desc;
2987  U8BIT stream_content;
2988  U8BIT component_type;
2989  BOOLEAN audio_desc;
2990 
2991  FUNCTION_START(DBDEF_GetEventAudioDescriptionFlag);
2992 
2993  audio_desc = FALSE;
2994 
2995  if (e_ptr != NULL)
2996  {
2997  event_desc = e_ptr->desc_list_head;
2998 
2999  while ((event_desc = DBDEF_FindEventDescriptor(event_desc, COMPONENT_DTAG, 0)) != NULL)
3000  {
3001  stream_content = event_desc->desc_data[2] & 0x0f;
3002  component_type = event_desc->desc_data[3];
3003 
3004  if ((stream_content == 0x02) &&
3005  ((component_type == 0x40) || (component_type == 0x42) ||
3006  (component_type == 0x47) || (component_type == 0x48)))
3007  {
3008  audio_desc = TRUE;
3009  break;
3010  }
3011  else if ((stream_content == 0x06) &&
3012  ((component_type == 0x40) || (component_type == 0x42) ||
3013  (component_type == 0x44) || (component_type == 0x46) ||
3014  ((component_type >= 0x47) && (component_type <= 0x4a))))
3015  {
3016  audio_desc = TRUE;
3017  break;
3018  }
3019 
3020  event_desc = event_desc->next;
3021  }
3022  }
3023 
3024  FUNCTION_FINISH(DBDEF_GetEventAudioDescriptionFlag);
3025 
3026  return(audio_desc);
3027 }
3028 
3042 BOOLEAN DBDEF_GetEventHDLinkageInfo(ADB_EVENT_REC *e_ptr, BOOLEAN verify_event, BOOLEAN only_simulcast,
3043  ADB_SERVICE_REC **hd_serv_ptr, ADB_EVENT_REC **hd_event_ptr)
3044 {
3045  ADB_EVENT_DESC *event_desc;
3046  ADB_EVENT_DESC *desc_ptr;
3047  BOOLEAN event_found;
3048  U8BIT link_type;
3049  U8BIT *dptr;
3050  U16BIT onet_id;
3051  U16BIT trans_id;
3052  U16BIT serv_id;
3053  ADB_SERVICE_REC *s_ptr = NULL;
3054  U16BIT event_id;
3055  U8BIT target_id_type;
3056  U16BIT target_onet_id;
3057  U16BIT target_trans_id;
3058  U16BIT target_serv_id;
3059  ADB_EVENT_REC *target_event;
3060  U8BIT *end_ptr;
3061  U8BIT *info_ptr;
3062  U8BIT dlen;
3063 
3064  FUNCTION_START(DBDEF_GetEventHDLinkageInfo);
3065 
3066  event_found = FALSE;
3067 
3068  if (hd_serv_ptr != NULL)
3069  {
3070  *hd_serv_ptr = NULL;
3071  }
3072 
3073  if (hd_event_ptr != NULL)
3074  {
3075  *hd_event_ptr = NULL;
3076  }
3077 
3078  if (e_ptr != NULL)
3079  {
3080  /* There may be multiple links so find the first one that points to a valid service
3081  * with a valid event */
3082  event_desc = e_ptr->desc_list_head;
3083 
3084  while (!event_found &&
3085  ((event_desc = DBDEF_FindEventDescriptor(event_desc, LINKAGE_DTAG, 0)) != NULL))
3086  {
3087  /* Just interested in event or extended event linkage descriptors */
3088  link_type = event_desc->desc_data[8];
3089 
3090  if ((link_type == 0x0D) || (link_type == 0x0E))
3091  {
3092  dptr = &event_desc->desc_data[2];
3093 
3094  trans_id = (dptr[0] << 8) | dptr[1];
3095  onet_id = (dptr[2] << 8) | dptr[3];
3096  serv_id = (dptr[4] << 8) | dptr[5];
3097 
3098  if (link_type == 0x0D)
3099  {
3100  /* Event linkage, check the linked service is known */
3101  s_ptr = DBDEF_FindServiceRecByIds(NULL, ADB_INVALID_DVB_ID, onet_id, trans_id, serv_id);
3102  if (s_ptr != NULL)
3103  {
3104  if (verify_event)
3105  {
3106  /* Event linkage */
3107  event_id = (dptr[7] << 8) | dptr[8];
3108 
3109  target_event = DBDEF_FindScheduleEventById(s_ptr, event_id);
3110  if (target_event != NULL)
3111  {
3112  if ((only_simulcast && ((dptr[9] & 0x40) != 0)) || !only_simulcast)
3113  {
3114  event_found = TRUE;
3115 
3116  if (hd_serv_ptr != NULL)
3117  {
3118  *hd_serv_ptr = s_ptr;
3119  }
3120  if (hd_event_ptr != NULL)
3121  {
3122  *hd_event_ptr = target_event;
3123  }
3124  }
3125  }
3126  }
3127  else
3128  {
3129  if ((only_simulcast && ((dptr[9] & 0x40) != 0)) || !only_simulcast)
3130  {
3131  event_found = TRUE;
3132 
3133  if (hd_serv_ptr != NULL)
3134  {
3135  *hd_serv_ptr = s_ptr;
3136  }
3137  }
3138  }
3139  }
3140  }
3141  else
3142  {
3143  /* Extended event linkage contains a number of linked events, so need
3144  * to check each one to find the first one that's valid */
3145  end_ptr = &dptr[8] + dptr[7];
3146  dptr += 8;
3147 
3148  while (!event_found && (dptr < end_ptr))
3149  {
3150  /* Work out the length of the data included in this
3151  * extended info block. Minimum length is 3 bytes */
3152  dlen = 3;
3153 
3154  target_id_type = (dptr[2] & 0x0c) >> 2;
3155 
3156  if (target_id_type == 3)
3157  {
3158  /* Length of user defined ID */
3159  dlen += 2;
3160  }
3161  else
3162  {
3163  if (target_id_type == 1)
3164  {
3165  /* Length of transport stream ID */
3166  dlen += 2;
3167  }
3168  if ((dptr[2] & 0x02) != 0)
3169  {
3170  /* Info includes the target original network ID */
3171  dlen += 2;
3172  }
3173  if ((dptr[2] & 0x01) != 0)
3174  {
3175  /* Info includes the target service ID */
3176  dlen += 2;
3177  }
3178  }
3179 
3180  /* Check link_type to see if this is a link to an HD event */
3181  if (((dptr[2] & 0x30) >> 4) == 1)
3182  {
3183  if ((only_simulcast && ((dptr[2] & 0x40) != 0)) || !only_simulcast)
3184  {
3185  event_id = (dptr[0] << 8) | dptr[1];
3186 
3187  /* Use target_id_type and additional flags to determine how to
3188  * find the target service */
3189  if (target_id_type == 3)
3190  {
3191  /* The user defined type is profiled by the DTG for use on UK DTT,
3192  * so check whether this instance of the descriptor is preceded
3193  * by the UK DTT private data specifier */
3194  if (ACFG_GetCountry() == COUNTRY_CODE_UK)
3195  {
3196  desc_ptr = e_ptr->desc_list_head;
3197 
3198  while (((desc_ptr = DBDEF_FindEventDescriptor(desc_ptr, LINKAGE_DTAG,
3199  UK_DTT_PRIVATE_DATA_CODE)) != NULL) && (desc_ptr != event_desc))
3200  {
3201  desc_ptr = desc_ptr->next;
3202  }
3203 
3204  if (desc_ptr != NULL)
3205  {
3206  /* This is a UK extended event descriptor in which the user
3207  * defined value defines the LCN of the service linked to */
3208  target_serv_id = (dptr[3] << 8) | dptr[4];
3209  s_ptr = DBDEF_FindServiceRecByLcn(target_serv_id, NULL, TRUE);
3210  }
3211  }
3212  }
3213  else
3214  {
3215  info_ptr = &dptr[3];
3216 
3217  target_onet_id = onet_id;
3218  target_trans_id = trans_id;
3219  target_serv_id = serv_id;
3220 
3221  if (target_id_type == 1)
3222  {
3223  /* Read the target transport ID */
3224  target_trans_id = (info_ptr[0] << 8) | info_ptr[1];
3225  info_ptr += 2;
3226  }
3227  if ((dptr[2] & 0x02) != 0)
3228  {
3229  /* Info includes the target original network ID */
3230  target_onet_id = (info_ptr[0] << 8) | info_ptr[1];
3231  info_ptr += 2;
3232  }
3233  if ((dptr[2] & 0x01) != 0)
3234  {
3235  /* Info includes the target service ID */
3236  target_serv_id = (info_ptr[0] << 8) | info_ptr[1];
3237  }
3238 
3239  s_ptr = DBDEF_FindServiceRecByIds(NULL, ADB_INVALID_DVB_ID,
3240  target_onet_id, target_trans_id, target_serv_id);
3241  }
3242 
3243  if (s_ptr != NULL)
3244  {
3245  if (verify_event)
3246  {
3247  /* Now check the target service to see if the event exists */
3248  target_event = DBDEF_FindScheduleEventById(s_ptr, event_id);
3249  if (target_event != NULL)
3250  {
3251  event_found = TRUE;
3252 
3253  if (hd_serv_ptr != NULL)
3254  {
3255  *hd_serv_ptr = s_ptr;
3256  }
3257  if (hd_event_ptr != NULL)
3258  {
3259  *hd_event_ptr = target_event;
3260  }
3261  }
3262  }
3263  else
3264  {
3265  event_found = TRUE;
3266 
3267  if (*hd_serv_ptr != NULL)
3268  {
3269  *hd_serv_ptr = s_ptr;
3270  }
3271  }
3272  }
3273  }
3274  }
3275 
3276  dptr += dlen;
3277  }
3278  }
3279  }
3280 
3281  event_desc = event_desc->next;
3282  }
3283  }
3284 
3285  FUNCTION_FINISH(DBDEF_GetEventHDLinkageInfo);
3286 
3287  return(event_found);
3288 }
3289 
3299 {
3300  ADB_EVENT_DESC *event_desc;
3301  U8BIT num_components;
3302  U8BIT index;
3303  U32BIT size;
3304 
3305  FUNCTION_START(DBDEF_GetEventComponentList);
3306 
3307  num_components = 0;
3308 
3309  if (e_ptr != NULL)
3310  {
3311  /* Count the number of components */
3312  event_desc = e_ptr->desc_list_head;
3313  while (event_desc != NULL)
3314  {
3315  event_desc = DBDEF_FindEventDescriptor(event_desc, COMPONENT_DTAG, 0);
3316  if (event_desc != NULL)
3317  {
3318  num_components++;
3319  event_desc = event_desc->next;
3320  }
3321  }
3322 
3323  if (num_components != 0)
3324  {
3325  size = num_components * sizeof(ADB_EVENT_COMPONENT_INFO);
3326  *component_list = STB_AppGetMemory(size);
3327  if (*component_list != NULL)
3328  {
3329  /* Copy the component info into the array to be returned */
3330  event_desc = e_ptr->desc_list_head;
3331  index = 0;
3332  while (event_desc != NULL)
3333  {
3334  event_desc = DBDEF_FindEventDescriptor(event_desc, COMPONENT_DTAG, 0);
3335  if (event_desc != NULL)
3336  {
3337  (*component_list)[index].stream_content = event_desc->desc_data[2] & 0x0f;
3338  (*component_list)[index].component_type = event_desc->desc_data[3];
3339  (*component_list)[index].component_tag = event_desc->desc_data[4];
3340  memcpy((*component_list)[index].language_code, &event_desc->desc_data[5], 3);
3341  index++;
3342  event_desc = event_desc->next;
3343  }
3344  }
3345  }
3346  else
3347  {
3348  num_components = 0;
3349  }
3350  }
3351  }
3352 
3353  FUNCTION_FINISH(DBDEF_GetEventComponentList);
3354 
3355  return(num_components);
3356 }
3357 
3364 {
3365  ADB_EVENT_DESC *event_desc;
3366  U8BIT component_type;
3367  BOOLEAN available;
3368 
3369  FUNCTION_START(DBDEF_GetEventSubtitlesAvailFlag);
3370 
3371  available = FALSE;
3372 
3373  if (e_ptr != NULL)
3374  {
3375  event_desc = e_ptr->desc_list_head;
3376 
3377  while ((event_desc = DBDEF_FindEventDescriptor(event_desc, COMPONENT_DTAG, 0)) != NULL)
3378  {
3379  if ((event_desc->desc_data[2] & 0x0f) == 0x03)
3380  {
3381  component_type = event_desc->desc_data[3];
3382 
3383  if (((0x10 <= component_type) && (component_type <= 0x14)) ||
3384  ((0x20 <= component_type) && (component_type <= 0x24)))
3385  {
3386  available = TRUE;
3387  break;
3388  }
3389  }
3390 
3391  event_desc = event_desc->next;
3392  }
3393  }
3394 
3395  FUNCTION_FINISH(DBDEF_GetEventSubtitlesAvailFlag);
3396 
3397  return(available);
3398 }
3399 
3406 U8BIT* DBDEF_GetEventContentData(ADB_EVENT_REC *e_ptr, U8BIT *p_len)
3407 {
3408  ADB_EVENT_DESC *event_desc;
3409  U8BIT *retval;
3410  U8BIT len;
3411 
3412  FUNCTION_START(DBDEF_GetEventContentData);
3413 
3414  retval = NULL;
3415 
3416  if (e_ptr != NULL)
3417  {
3418  if ((event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head, CONTENT_DTAG, 0)) != NULL)
3419  {
3420  len = event_desc->desc_data[1];
3421  if (len != 0)
3422  {
3423  retval = &event_desc->desc_data[2];
3424  *p_len = len;
3425  }
3426  }
3427  }
3428 
3429  FUNCTION_FINISH(DBDEF_GetEventContentData);
3430 
3431  return(retval);
3432 }
3433 
3440 ADB_EVENT_CONTENT DBDEF_GetEventGenre(ADB_EVENT_REC *e_ptr, ADB_SERVICE_REC *s_ptr)
3441 {
3442  ADB_TRANSPORT_REC *t_ptr;
3443  ADB_EVENT_DESC *event_desc;
3444  U8BIT content_value;
3445  U32BIT country_code;
3446  ADB_EVENT_CONTENT genre;
3447  U8BIT *conversion_array;
3448 
3449  FUNCTION_START(DBDEF_GetEventGenre);
3450 
3451  genre = ADB_EVENT_CONTENT_UNCLASSIFIED;
3452 
3453  if (e_ptr != NULL)
3454  {
3455  if ((event_desc = DBDEF_FindEventDescriptor(e_ptr->desc_list_head, CONTENT_DTAG, 0)) != NULL)
3456  {
3457  if (event_desc->desc_data[1] != 0)
3458  {
3459  /* Only level_1 from the first content descriptor is currently used */
3460  country_code = ACFG_GetCountry();
3461  conversion_array = ACFG_GetEventContentTypes(country_code);
3462 
3463  content_value = event_desc->desc_data[2] >> 4;
3464  genre = (ADB_EVENT_CONTENT)conversion_array[content_value];
3465 
3466  if (content_value == 0x0f)
3467  {
3468  if ((country_code == COUNTRY_CODE_UK) && ((t_ptr = s_ptr->transport) != NULL))
3469  {
3470  /* Special case processing for UK: 0xF is defined as DRAMA
3471  * only if one of the UK private data specifiers is present,
3472  * otherwise it should be unclassified */
3473  if (t_ptr->sig_type == SIGNAL_COFDM)
3474  {
3475  /* Search for the content descriptor again with the UK DTT
3476  * private data specifier */
3477  if (DBDEF_FindEventDescriptor(e_ptr->desc_list_head, CONTENT_DTAG,
3478  UK_DTT_PRIVATE_DATA_CODE) == NULL)
3479  {
3480  /* The content should be unclassified */
3481  genre = ADB_EVENT_CONTENT_UNCLASSIFIED;
3482  }
3483  }
3484  else if (t_ptr->sig_type == SIGNAL_QPSK)
3485  {
3486  /* Search for the content descriptor again with the UK Freesat
3487  * private data specifier */
3488  if (DBDEF_FindEventDescriptor(e_ptr->desc_list_head, CONTENT_DTAG,
3489  FREESAT_PRIVATE_DATA_CODE) == NULL)
3490  {
3491  /* The content should be unclassified */
3492  genre = ADB_EVENT_CONTENT_UNCLASSIFIED;
3493  }
3494  }
3495  }
3496  }
3497  }
3498  }
3499  }
3500 
3501  FUNCTION_FINISH(DBDEF_GetEventGenre);
3502 
3503  return(genre);
3504 }
3505 
3515 U8BIT* DBDEF_GetEventCrid(ADB_SERVICE_REC *serv_ptr, ADB_EVENT_REC *e_ptr, U8BIT crid_type, U8BIT index)
3516 {
3517  ADB_EVENT_DESC *event_desc;
3518  U8BIT crids_found;
3519  U8BIT *dptr;
3520  U8BIT *end_ptr;
3521  U8BIT type;
3523  U8BIT *crid_str;
3524 
3525  FUNCTION_START(DBDEF_GetEventCrid);
3526 
3527  /* Each event can have multiple content identifier descriptors, so need to search for
3528  * the index'th one of the given type */
3529  crid_str = NULL;
3530  crids_found = 0;
3531  event_desc = e_ptr->desc_list_head;
3532 
3533  while ((crid_str == NULL) &&
3534  ((event_desc = DBDEF_FindEventDescriptor(event_desc, CONT_ID_DESC_DTAG, 0)) != NULL))
3535  {
3536  dptr = &event_desc->desc_data[2];
3537  end_ptr = dptr + event_desc->desc_data[1];
3538 
3539  while ((crid_str == NULL) && (dptr < end_ptr))
3540  {
3541  /* Currently only support location 0 */
3542  if ((dptr[0] & CRID_LOCATION_MASK) == CRID_LOCATION_0)
3543  {
3544  type = (dptr[0] & CRID_TYPE_MASK) >> CRID_TYPE_SHIFT;
3545 
3546  if (type == crid_type)
3547  {
3548  if ((type == UK_PROGRAMME_CRID) || (type == TVA_PROGRAMME_CRID) ||
3549  (index == crids_found))
3550  {
3551  STB_SIReadString(dptr[1], dptr + 2, &si_string);
3552  if (si_string != NULL)
3553  {
3554  crid_str = DBDEF_GetFullCrid(serv_ptr, si_string->str_ptr);
3555  }
3556  }
3557 
3558  crids_found++;
3559  }
3560 
3561  dptr += dptr[1] + 2;
3562  }
3563  else if ((dptr[0] & CRID_LOCATION_MASK) == CRID_LOCATION_1)
3564  {
3565  dptr += 3;
3566  }
3567  else
3568  {
3569  dptr += 2;
3570  }
3571  }
3572 
3573  event_desc = event_desc->next;
3574  }
3575 
3576  FUNCTION_FINISH(DBDEF_GetEventCrid);
3577 
3578  return(crid_str);
3579 }
3580 
3587 U8BIT DBDEF_NumberOfCridsOfType(ADB_EVENT_REC *e_ptr, U8BIT crid_type)
3588 {
3589  ADB_EVENT_DESC *event_desc;
3590  U8BIT crids_found;
3591  U8BIT *dptr;
3592  U8BIT *end_ptr;
3593  U8BIT type;
3594 
3595  FUNCTION_START(DBDEF_NumberOfCridsOfType);
3596 
3597  crids_found = 0;
3598 
3599  if (e_ptr != NULL)
3600  {
3601  /* Each event can have multiple content identifier descriptors */
3602  event_desc = e_ptr->desc_list_head;
3603 
3604  while ((event_desc = DBDEF_FindEventDescriptor(event_desc, CONT_ID_DESC_DTAG, 0)) != NULL)
3605  {
3606  dptr = &event_desc->desc_data[2];
3607  end_ptr = dptr + event_desc->desc_data[1];
3608 
3609  while (dptr < end_ptr)
3610  {
3611  /* Currently only support location 0 */
3612  if ((dptr[0] & CRID_LOCATION_MASK) == CRID_LOCATION_0)
3613  {
3614  type = (dptr[0] & CRID_TYPE_MASK) >> CRID_TYPE_SHIFT;
3615 
3616  if (type == crid_type)
3617  {
3618  crids_found++;
3619  }
3620 
3621  dptr += dptr[1] + 2;
3622  }
3623  else if ((dptr[0] & CRID_LOCATION_MASK) == CRID_LOCATION_1)
3624  {
3625  dptr += 3;
3626  }
3627  else
3628  {
3629  dptr += 2;
3630  }
3631  }
3632 
3633  event_desc = event_desc->next;
3634  }
3635  }
3636 
3637  FUNCTION_FINISH(DBDEF_NumberOfCridsOfType);
3638 
3639  return(crids_found);
3640 }
3641 
3649 U8BIT* DBDEF_GetFullCrid(ADB_SERVICE_REC *serv_ptr, U8BIT *event_str)
3650 {
3651  U8BIT *authority_str;
3652  U8BIT *crid_str = NULL;
3653  U16BIT str_len;
3654 
3655  FUNCTION_START(DBDEF_GetFullCrid);
3656 
3657  if ((serv_ptr != NULL) && (event_str != NULL))
3658  {
3659  if (*event_str == '/')
3660  {
3661  /* The CRID doesn't include the authority so get it from the service */
3662  authority_str = DBDEF_GetServiceDefaultAuthority(serv_ptr);
3663 
3664  if (authority_str != NULL)
3665  {
3666  str_len = strlen((char *)authority_str) + strlen((char *)event_str) + 1;
3667  crid_str = STB_AppGetMemory(str_len);
3668  if (crid_str != NULL)
3669  {
3670  strncpy((char *)crid_str, (char *)authority_str, str_len);
3671  strncat((char *)crid_str, (char *)event_str, str_len);
3672  }
3673 
3674  STB_AppFreeMemory(authority_str);
3675  }
3676  }
3677  else
3678  {
3679  /* The CRID includes the authority as well */
3680  str_len = strlen((char *)event_str) + 1;
3681  crid_str = STB_AppGetMemory(str_len);
3682  if (crid_str != NULL)
3683  {
3684  strncpy((char *)crid_str, (char *)event_str, str_len);
3685  }
3686  }
3687  }
3688 
3689  FUNCTION_FINISH(DBDEF_GetFullCrid);
3690 
3691  return(crid_str);
3692 }
3693 
3701 {
3702  ADB_TRANSPORT_REC *t_ptr;
3703  ADB_NETWORK_REC *n_ptr;
3704  U8BIT *crid_str;
3705 
3706  FUNCTION_START(DBDEF_GetServiceDefaultAuthority);
3707 
3708  crid_str = NULL;
3709 
3710  if (s_ptr != NULL)
3711  {
3712  /* The search order for the default authority CRID is defined as service,
3713  * transport and finally network */
3714  if (s_ptr->def_authority != NULL)
3715  {
3716  crid_str = CopyString(s_ptr->def_authority, FALSE);
3717  }
3718  else
3719  {
3720  /* No default authority defined in the service so try the transport */
3721  t_ptr = s_ptr->transport;
3722 
3723  if (t_ptr != NULL)
3724  {
3725  if (t_ptr->def_authority != NULL)
3726  {
3727  crid_str = CopyString(t_ptr->def_authority, FALSE);
3728  }
3729  else
3730  {
3731  /* No default authority defined in the transport so try the network */
3732  n_ptr = t_ptr->network;
3733  if (n_ptr != NULL)
3734  {
3735  if (n_ptr->def_authority != NULL)
3736  {
3737  crid_str = CopyString(n_ptr->def_authority, FALSE);
3738  }
3739  }
3740  }
3741  }
3742  }
3743  }
3744 
3745  FUNCTION_FINISH(DBDEF_GetServiceDefaultAuthority);
3746 
3747  return(crid_str);
3748 }
3749 
3755 {
3756  ADB_EVENT_REC *e_ptr;
3757  ADB_EVENT_REC *next_ptr;
3758  ADB_EVENT_DESC *next;
3759 
3760  FUNCTION_START(DBDEF_DeleteEventList);
3761 
3762  e_ptr = elist;
3763  while (e_ptr != NULL)
3764  {
3765  next_ptr = e_ptr->next;
3766 
3767  while (e_ptr->desc_list_head != NULL)
3768  {
3769  next = e_ptr->desc_list_head->next;
3770  STB_AppFreeMemory(e_ptr->desc_list_head);
3771  e_ptr->desc_list_head = next;
3772  }
3773 
3774  e_ptr->desc_list_tail = NULL;
3775 
3776  DBA_DestroyRecord(e_ptr->dba_rec);
3777 
3778  STB_AppFreeMemory(e_ptr);
3779 
3780  e_ptr = next_ptr;
3781  }
3782 
3783  FUNCTION_FINISH(DBDEF_DeleteEventList);
3784 }
3785 
3798 {
3799  ADB_ALT_SERV_REC *alt_serv_rec;
3800  ADB_ALT_SERV_REC *next_rec;
3801 
3802  alt_serv_rec = aslist;
3803  while (alt_serv_rec != NULL)
3804  {
3805  next_rec = alt_serv_rec->next;
3806  STB_AppFreeMemory(alt_serv_rec);
3807  alt_serv_rec = next_rec;
3808  }
3809 }
3810 
3811 /*!**************************************************************************
3812  * @brief Frees the given list of RCT links
3813  * @param links links to be freed
3814  ****************************************************************************/
3816 {
3817  ADB_RCT_LINK_INFO *l_ptr;
3818  ADB_RCT_LINK_INFO *next_ptr;
3819  U8BIT i;
3820 
3821  FUNCTION_START(ADB_ReleaseRCTLinks);
3822 
3823  for (l_ptr = links; l_ptr != NULL; l_ptr = next_ptr)
3824  {
3825  next_ptr = l_ptr->next;
3826 
3827  if (l_ptr->uri_string != NULL)
3828  {
3829  STB_AppFreeMemory(l_ptr->uri_string);
3830  }
3831 
3832  DBDEF_ReleaseString(l_ptr->event_name);
3833 
3834  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
3835  {
3836  DBDEF_ReleaseString(l_ptr->promo_text[i]);
3837  }
3838 
3839  STB_AppFreeMemory(l_ptr);
3840  }
3841 
3842  FUNCTION_FINISH(ADB_ReleaseRCTLinks);
3843 }
3844 
3845 /*!**************************************************************************
3846  * @brief Frees given list of image icons and any associated memory
3847  * @param icon_list icon list to be freed
3848  ****************************************************************************/
3850 {
3851  ADB_IMAGE_ICON *icon_ptr;
3852  ADB_IMAGE_ICON *next_ptr;
3853 
3854  FUNCTION_START(DBDEF_DeleteImageIcons);
3855 
3856  for (icon_ptr = icon_list; icon_ptr != NULL; icon_ptr = next_ptr)
3857  {
3858  next_ptr = icon_ptr->next;
3859 
3860  if (icon_ptr->destroy_func != NULL)
3861  {
3862  STB_SPDebugWrite("destroy file=%s", icon_ptr->icon_url);
3863  icon_ptr->destroy_func( icon_ptr->dsm_handle );
3864  }
3865 
3866  if (icon_ptr->icon_url != NULL)
3867  {
3868  STB_AppFreeMemory(icon_ptr->icon_url);
3869  }
3870 
3871  if (icon_ptr->icon_data != NULL)
3872  {
3873  STB_AppFreeMemory(icon_ptr->icon_data);
3874  }
3875 
3876  STB_AppFreeMemory(icon_ptr);
3877  }
3878 
3879  FUNCTION_FINISH(DBDEF_DeleteImageIcons);
3880 }
3881 
3890 ADB_STRING* DBDEF_MakeString(U32BIT lang_code, U8BIT *str_ptr, U16BIT nbytes)
3891 {
3892  ADB_STRING *string;
3893 
3894  FUNCTION_START(DBDEF_MakeString);
3895 
3896  if ((str_ptr == NULL) || (nbytes == 0))
3897  {
3898  string = NULL;
3899  }
3900  else
3901  {
3902  string = STB_AppGetMemory(sizeof(ADB_STRING) + nbytes);
3903  if (string != NULL)
3904  {
3905  string->lang_code = lang_code;
3906  string->nbytes = nbytes;
3907  string->str_ptr = ((U8BIT *)string) + sizeof(ADB_STRING);
3908  memcpy(string->str_ptr, str_ptr, nbytes);
3909  }
3910  }
3911 
3912  FUNCTION_FINISH(DBDEF_MakeString);
3913 
3914  return(string);
3915 }
3916 
3923 {
3924  ADB_STRING *string;
3925 
3926  FUNCTION_START(DBDEF_CopyString);
3927 
3928  string = NULL;
3929 
3930  if (src_str != NULL)
3931  {
3932  string = DBDEF_MakeString(src_str->lang_code, src_str->str_ptr, src_str->nbytes);
3933  }
3934 
3935  FUNCTION_FINISH(DBDEF_CopyString);
3936 
3937  return(string);
3938 }
3939 
3949 {
3950  U32BIT nbytes;
3951  ADB_STRING *string;
3952 
3953  FUNCTION_START(DBDEF_ConcatSIString);
3954 
3955  /* Any trailing '\0's need to be excluded from the copy to the new string */
3956  nbytes = str1->nbytes;
3957  while (str1->str_ptr[nbytes - 1] == '\0')
3958  {
3959  nbytes--;
3960  }
3961 
3962  /* Create the new string and copy the data from both strings into it */
3963  string = STB_AppGetMemory(sizeof(ADB_STRING) + nbytes + str2->nbytes);
3964  if (string != NULL)
3965  {
3966  string->lang_code = str1->lang_code;
3967  string->nbytes = nbytes + str2->nbytes;
3968  string->str_ptr = ((U8BIT *)string) + sizeof(ADB_STRING);
3969 
3970  memcpy(string->str_ptr, str1->str_ptr, nbytes);
3971  memcpy(string->str_ptr + nbytes, str2->str_ptr, str2->nbytes);
3972  }
3973 
3974  FUNCTION_FINISH(DBDEF_ConcatSIString);
3975 
3976  return(string);
3977 }
3978 
3984 {
3985  FUNCTION_START(DBDEF_ReleaseString);
3986 
3987  if (string != NULL)
3988  {
3989  STB_AppFreeMemory(string);
3990  }
3991 
3992  FUNCTION_FINISH(DBDEF_ReleaseString);
3993 }
3994 
3999 U16BIT DBDEF_GetNumLNBs(void)
4000 {
4001  FUNCTION_START(DBDEF_GetNumLNBs);
4002  FUNCTION_FINISH(DBDEF_GetNumLNBs);
4003  return(STB_LLGetNumBlocks(&lnb_rec_list));
4004 }
4005 
4012 ADB_LNB_REC* DBDEF_AddLNB(E_STB_DP_LNB_TYPE type, ADB_STRING *name)
4013 {
4014  ADB_LNB_REC *lnb_ptr;
4015  void *dba_rec;
4016 
4017  FUNCTION_START(DBDEF_AddLNB);
4018 
4019  lnb_ptr = STB_AppGetMemory(sizeof(ADB_LNB_REC));
4020  if (lnb_ptr != NULL)
4021  {
4022  memset(lnb_ptr, 0, sizeof(ADB_LNB_REC));
4023 
4024  /* Add database record */
4025  dba_rec = DBA_CreateRecord(DBA_RECORD_LNB, NULL);
4026  if (dba_rec != NULL)
4027  {
4028  lnb_ptr->dba_rec = dba_rec;
4029 
4030  /* Fill in details in record */
4031  lnb_ptr->type = type;
4032  DBA_SetFieldValue(dba_rec, DBA_FIELD_LNB_TYPE, (U32BIT)lnb_ptr->type);
4033 
4034  if (name != NULL)
4035  {
4036  lnb_ptr->name = name;
4037  DBA_SetFieldString(dba_rec, DBA_FIELD_LNB_NAME, name->str_ptr, name->nbytes);
4038  }
4039 
4040  STB_LLAddBlockToEnd(&lnb_rec_list, (LINK_LIST_PTR_BLK *)lnb_ptr);
4041  }
4042  else
4043  {
4044  STB_AppFreeMemory(lnb_ptr);
4045  lnb_ptr = NULL;
4046  }
4047  }
4048 
4049  FUNCTION_FINISH(DBDEF_AddLNB);
4050 
4051  return(lnb_ptr);
4052 }
4053 
4060 BOOLEAN DBDEF_SetLNBPower(ADB_LNB_REC *lnb, E_STB_DP_LNB_POWER power)
4061 {
4062  BOOLEAN retval;
4063 
4064  FUNCTION_START(DBDEF_SetLNBPower);
4065 
4066  retval = FALSE;
4067 
4068  if (lnb != NULL)
4069  {
4070  lnb->power = power;
4071  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_POWER, (U32BIT)power);
4072  }
4073 
4074  FUNCTION_FINISH(DBDEF_SetLNBPower);
4075 
4076  return(retval);
4077 }
4078 
4085 BOOLEAN DBDEF_SetLNB22k(ADB_LNB_REC *lnb, BOOLEAN is_22k)
4086 {
4087  BOOLEAN retval;
4088 
4089  FUNCTION_START(DBDEF_SetLNB22k);
4090 
4091  retval = FALSE;
4092 
4093  if (lnb != NULL)
4094  {
4095  lnb->is_22k = is_22k;
4096  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_22K, (U32BIT)is_22k);
4097  }
4098 
4099  FUNCTION_FINISH(DBDEF_SetLNB22k);
4100 
4101  return(retval);
4102 }
4103 
4110 BOOLEAN DBDEF_SetLNB12V(ADB_LNB_REC *lnb, BOOLEAN is_12v)
4111 {
4112  BOOLEAN retval;
4113 
4114  FUNCTION_START(DBDEF_SetLNB12V);
4115 
4116  retval = FALSE;
4117 
4118  if (lnb != NULL)
4119  {
4120  lnb->is_12v = is_12v;
4121  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_12V, (U32BIT)is_12v);
4122  }
4123 
4124  FUNCTION_FINISH(DBDEF_SetLNB12V);
4125 
4126  return(retval);
4127 }
4128 
4135 BOOLEAN DBDEF_SetLNBPulsePosition(ADB_LNB_REC *lnb, BOOLEAN is_pulse_posn)
4136 {
4137  BOOLEAN retval;
4138 
4139  FUNCTION_START(DBDEF_SetLNBPulsePosition);
4140 
4141  retval = FALSE;
4142 
4143  if (lnb != NULL)
4144  {
4145  lnb->is_pulse_posn = is_pulse_posn;
4146  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_PULSEPOSN, (U32BIT)is_pulse_posn);
4147  }
4148 
4149  FUNCTION_FINISH(DBDEF_SetLNBPulsePosition);
4150 
4151  return(retval);
4152 }
4153 
4160 BOOLEAN DBDEF_SetLNBDiSEqCPosition(ADB_LNB_REC *lnb, BOOLEAN is_diseqc_posn)
4161 {
4162  BOOLEAN retval;
4163 
4164  FUNCTION_START(DBDEF_SetLNBDiSEqcPosition);
4165 
4166  retval = FALSE;
4167 
4168  if (lnb != NULL)
4169  {
4170  lnb->is_diseqc_posn = is_diseqc_posn;
4171  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISPOSN, (U32BIT)is_diseqc_posn);
4172  }
4173 
4174  FUNCTION_FINISH(DBDEF_SetLNBDiSEqcPosition);
4175 
4176  return(retval);
4177 }
4178 
4185 BOOLEAN DBDEF_SetLNBDiSEqCTone(ADB_LNB_REC *lnb, E_STB_DP_DISEQC_TONE diseqc_tone)
4186 {
4187  BOOLEAN retval;
4188 
4189  FUNCTION_START(DBDEF_SetLNBDiSEqCTone);
4190 
4191  retval = FALSE;
4192 
4193  if (lnb != NULL)
4194  {
4195  lnb->diseqc_tone = diseqc_tone;
4196  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISTONE, (U32BIT)diseqc_tone);
4197  }
4198 
4199  FUNCTION_FINISH(DBDEF_SetLNBDiSEqCTone);
4200 
4201  return(retval);
4202 }
4203 
4210 BOOLEAN DBDEF_SetLNBCSwitch(ADB_LNB_REC *lnb, E_STB_DP_DISEQC_CSWITCH cswitch)
4211 {
4212  BOOLEAN retval;
4213 
4214  FUNCTION_START(DBDEF_SetLNBCSwitch);
4215 
4216  retval = FALSE;
4217 
4218  if (lnb != NULL)
4219  {
4220  lnb->c_switch = cswitch;
4221  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISCSWITCH, (U32BIT)cswitch);
4222  }
4223 
4224  FUNCTION_FINISH(DBDEF_SetLNBCSwitch);
4225 
4226  return(retval);
4227 }
4228 
4235 BOOLEAN DBDEF_SetLNBUSwitch(ADB_LNB_REC *lnb, U8BIT uswitch)
4236 {
4237  BOOLEAN retval;
4238 
4239  FUNCTION_START(DBDEF_SetLNBUSwitch);
4240 
4241  retval = FALSE;
4242 
4243  if (lnb != NULL)
4244  {
4245  lnb->u_switch = uswitch;
4246  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISUSWITCH, (U32BIT)uswitch);
4247  }
4248 
4249  FUNCTION_FINISH(DBDEF_SetLNBUSwitch);
4250 
4251  return(retval);
4252 }
4253 
4260 BOOLEAN DBDEF_SetLNBSmatv(ADB_LNB_REC *lnb, BOOLEAN is_smatv)
4261 {
4262  BOOLEAN retval;
4263 
4264  FUNCTION_START(DBDEF_SetLNBSmatv);
4265 
4266  retval = FALSE;
4267 
4268  if (lnb != NULL)
4269  {
4270  lnb->is_smatv = is_smatv;
4271  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISSMATV, (U32BIT)is_smatv);
4272  }
4273 
4274  FUNCTION_FINISH(DBDEF_SetLNBSmatv);
4275 
4276  return(retval);
4277 }
4278 
4285 BOOLEAN DBDEF_SetLNBRepeats(ADB_LNB_REC *lnb, U8BIT repeats)
4286 {
4287  BOOLEAN retval;
4288 
4289  FUNCTION_START(DBDEF_SetLNBRepeats);
4290 
4291  retval = FALSE;
4292 
4293  if (lnb != NULL)
4294  {
4295  lnb->diseqc_repeats = repeats;
4296  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_DISREPEAT, (U32BIT)repeats);
4297  }
4298 
4299  FUNCTION_FINISH(DBDEF_SetLNBRepeats);
4300 
4301  return(retval);
4302 }
4303 
4311 BOOLEAN DBDEF_SetLNBUnicable(ADB_LNB_REC *lnb, U32BIT inter_freq, U8BIT chan)
4312 {
4313  BOOLEAN retval;
4314 
4315  FUNCTION_START(DBDEF_SetLNBUnicable);
4316 
4317  retval = FALSE;
4318 
4319  if (lnb != NULL)
4320  {
4321  lnb->unicable_if = inter_freq;
4322  DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_UNICABLEFREQ, inter_freq);
4323  lnb->unicable_chan = chan;
4324  retval = DBA_SetFieldValue(lnb->dba_rec, DBA_FIELD_LNB_UNICABLECHAN, (U32BIT)chan);
4325  }
4326 
4327  FUNCTION_FINISH(DBDEF_SetLNBUnicable);
4328 
4329  return(retval);
4330 }
4331 
4339 {
4340  ADB_LNB_REC *ret_ptr;
4341 
4342  FUNCTION_START(DBDEF_GetNextLNBRec);
4343 
4344  if (lnb_ptr == NULL)
4345  {
4346  ret_ptr = (ADB_LNB_REC *)STB_LLGetFirstBlock(&lnb_rec_list);
4347  }
4348  else
4349  {
4350  ret_ptr = (ADB_LNB_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)lnb_ptr);
4351  }
4352 
4353  FUNCTION_FINISH(DBDEF_GetNextLNBRec);
4354 
4355  return(ret_ptr);
4356 }
4357 
4363 {
4364  FUNCTION_START(DBDEF_GetNumSatellites);
4365  FUNCTION_FINISH(DBDEF_GetNumSatellites);
4366  return(STB_LLGetNumBlocks(&satellite_rec_list));
4367 }
4368 
4378 ADB_SATELLITE_REC* DBDEF_AddSatelliteRec(ADB_STRING *name_str, U16BIT dish_pos, U16BIT long_pos,
4379  BOOLEAN east_west, ADB_LNB_REC *associated_lnb)
4380 {
4381  ADB_LNB_REC *lnb_ptr;
4382  ADB_SATELLITE_REC *sat_ptr;
4383  void *dba_rec;
4384 
4385  FUNCTION_START(DBDEF_AddSatelliteRec);
4386 
4387  sat_ptr = NULL;
4388 
4389  if (associated_lnb != NULL)
4390  {
4391  // validate associated LNB by checking if is already in database
4392  lnb_ptr = (ADB_LNB_REC *)STB_LLGetFirstBlock(&lnb_rec_list);
4393  while (lnb_ptr != NULL)
4394  {
4395  if (lnb_ptr == associated_lnb)
4396  {
4397  break;
4398  }
4399  lnb_ptr = (ADB_LNB_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)lnb_ptr);
4400  }
4401 
4402  if (lnb_ptr != NULL)
4403  {
4404  sat_ptr = STB_AppGetMemory(sizeof(ADB_SATELLITE_REC));
4405  if (sat_ptr != NULL)
4406  {
4407  memset(sat_ptr, 0, sizeof(ADB_SATELLITE_REC));
4408 
4409  sat_ptr->lnb = lnb_ptr;
4410 
4411  /* Add nvm record */
4412  dba_rec = DBA_CreateRecord(DBA_RECORD_SATELLITE, lnb_ptr->dba_rec);
4413  if (dba_rec != NULL)
4414  {
4415  sat_ptr->dba_rec = dba_rec;
4416 
4417  if (name_str != NULL)
4418  {
4419  sat_ptr->name = name_str;
4420  DBA_SetFieldString(dba_rec, DBA_FIELD_REC_NAME, name_str->str_ptr,
4421  name_str->nbytes);
4422  }
4423 
4424  sat_ptr->dish_pos = dish_pos;
4425  DBA_SetFieldValue(dba_rec, DBA_FIELD_SAT_DISH, sat_ptr->dish_pos);
4426 
4427  if (long_pos <= 1800)
4428  {
4429  sat_ptr->long_pos = long_pos;
4430  }
4431  else
4432  {
4433  sat_ptr->long_pos = 0;
4434  }
4435  DBA_SetFieldValue(dba_rec, DBA_FIELD_SAT_LONGPOS, sat_ptr->long_pos);
4436 
4437  if (east_west)
4438  {
4439  sat_ptr->east_west = 1;
4440  }
4441  else
4442  {
4443  sat_ptr->east_west = 0;
4444  }
4445  DBA_SetFieldValue(dba_rec, DBA_FIELD_SAT_LONGWE, sat_ptr->east_west);
4446 
4447  STB_LLAddBlockToEnd(&satellite_rec_list, (LINK_LIST_PTR_BLK *)sat_ptr);
4448  }
4449  else
4450  {
4451  STB_AppFreeMemory(sat_ptr);
4452  sat_ptr = NULL;
4453  }
4454  }
4455  }
4456  }
4457 
4458  FUNCTION_FINISH(DBDEF_AddSatelliteRec);
4459 
4460  return(sat_ptr);
4461 }
4462 
4470 {
4471  ADB_SATELLITE_REC *ret_ptr;
4472 
4473  FUNCTION_START(DBDEF_GetNextSatelliteRec);
4474 
4475  if (sat_ptr == NULL)
4476  {
4477  ret_ptr = (ADB_SATELLITE_REC *)STB_LLGetFirstBlock(&satellite_rec_list);
4478  }
4479  else
4480  {
4481  ret_ptr = (ADB_SATELLITE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)sat_ptr);
4482  }
4483 
4484  FUNCTION_FINISH(DBDEF_GetNextSatelliteRec);
4485 
4486  return(ret_ptr);
4487 }
4488 
4494 {
4495  FUNCTION_START(DBDEF_GetNumLNBBands);
4496  FUNCTION_FINISH(DBDEF_GetNumLNBBands);
4497  return(STB_LLGetNumBlocks(&lnb_band_rec_list));
4498 }
4499 
4507 {
4508  ADB_LNB_REC *lnb_ptr;
4509  ADB_LNB_BAND_REC *band_ptr;
4510  void *dba_rec;
4511 
4512  FUNCTION_START(DBDEF_AddLNBBandRec);
4513 
4514  band_ptr = NULL;
4515 
4516  if (associated_lnb != NULL)
4517  {
4518  // validate associated LNB by checking if is already in database
4519  lnb_ptr = (ADB_LNB_REC *)STB_LLGetFirstBlock(&lnb_rec_list);
4520  while (lnb_ptr != NULL)
4521  {
4522  if (lnb_ptr == associated_lnb)
4523  {
4524  break;
4525  }
4526  lnb_ptr = (ADB_LNB_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)lnb_ptr);
4527  }
4528 
4529  if (lnb_ptr != NULL)
4530  {
4531  band_ptr = STB_AppGetMemory(sizeof(ADB_LNB_BAND_REC));
4532  if (band_ptr != NULL)
4533  {
4534  memset(band_ptr, 0, sizeof(ADB_LNB_BAND_REC));
4535 
4536  band_ptr->lnb = lnb_ptr;
4537 
4538  /* Add nvm record */
4539  dba_rec = DBA_CreateRecord(DBA_RECORD_LNB_BAND, lnb_ptr->dba_rec);
4540  if (dba_rec != NULL)
4541  {
4542  band_ptr->dba_rec = dba_rec;
4543 
4544  band_ptr->band_params.polarity = band_parameters->polarity;
4545  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_POLARITY, band_ptr->band_params.polarity);
4546 
4547  band_ptr->band_params.min_freq = band_parameters->min_freq;
4548  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_MIN_FREQUENCY, band_ptr->band_params.min_freq);
4549 
4550  band_ptr->band_params.max_freq = band_parameters->max_freq;
4551  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_MAX_FREQUENCY, band_ptr->band_params.max_freq);
4552 
4553  band_ptr->band_params.local_oscillator_frequency =
4554  band_parameters->local_oscillator_frequency;
4555  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_LOCAL_OSC_FREQUENCY,
4556  band_ptr->band_params.local_oscillator_frequency);
4557 
4558  band_ptr->band_params.lnb_voltage = band_parameters->lnb_voltage;
4559  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_LNB_VOLTAGE,
4560  band_ptr->band_params.lnb_voltage);
4561 
4562  band_ptr->band_params.tone_22k = band_parameters->tone_22k;
4563  DBA_SetFieldValue(dba_rec, DBA_FIELD_BAND_22_KHZ, band_ptr->band_params.tone_22k);
4564 
4565  STB_LLAddBlockToEnd(&lnb_band_rec_list, (LINK_LIST_PTR_BLK *)band_ptr);
4566  }
4567  else
4568  {
4569  STB_AppFreeMemory(band_ptr);
4570  band_ptr = NULL;
4571  }
4572  }
4573  }
4574  }
4575 
4576  FUNCTION_FINISH(DBDEF_AddLNBBandRec);
4577 
4578  return band_ptr;
4579 }
4580 
4588 {
4589  ADB_LNB_BAND_REC *ret_ptr;
4590 
4591  FUNCTION_START(DBDEF_GetNextLNBBandRec);
4592 
4593  if (band_ptr == NULL)
4594  {
4595  ret_ptr = (ADB_LNB_BAND_REC *)STB_LLGetFirstBlock(&lnb_band_rec_list);
4596  }
4597  else
4598  {
4599  ret_ptr = (ADB_LNB_BAND_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)band_ptr);
4600  }
4601 
4602  FUNCTION_FINISH(DBDEF_GetNextLNBBandRec);
4603 
4604  return(ret_ptr);
4605 }
4606 
4612 {
4613  FUNCTION_START(DBDEF_DeleteLNBBandRec);
4614 
4615  if (band_ptr != NULL)
4616  {
4617  STB_LLRemoveBlock(&band_ptr->ptrs);
4618 
4619  DBA_DestroyRecord(band_ptr->dba_rec);
4620 
4621  STB_AppFreeMemory(band_ptr);
4622  }
4623 
4624  FUNCTION_FINISH(DBDEF_DeleteLNBBandRec);
4625 }
4626 
4632 {
4633  FUNCTION_START(DBDEF_GetNumNetworks);
4634  FUNCTION_FINISH(DBDEF_GetNumNetworks);
4635  return(STB_LLGetNumBlocks(&network_rec_list));
4636 }
4637 
4645 {
4646  ADB_NETWORK_REC *n_ptr;
4647  void *dba_rec;
4648 
4649  FUNCTION_START(DBDEF_AddNetworkRec);
4650 
4651  n_ptr = STB_AppGetMemory(sizeof(ADB_NETWORK_REC));
4652  if (n_ptr != NULL)
4653  {
4654  memset(n_ptr, 0, sizeof(ADB_NETWORK_REC));
4655 
4656  /* Create database record */
4657  if (satellite != NULL)
4658  {
4659  n_ptr->satellite = satellite;
4660  dba_rec = DBA_CreateRecord(DBA_RECORD_NETWORK, satellite->dba_rec);
4661  }
4662  else
4663  {
4664  dba_rec = DBA_CreateRecord(DBA_RECORD_NETWORK, NULL);
4665  }
4666 
4667  if (dba_rec != NULL)
4668  {
4669  n_ptr->dba_rec = dba_rec;
4670 
4671  /* Fill in record details */
4672  n_ptr->net_id = net_id;
4673  DBA_SetFieldValue(dba_rec, DBA_FIELD_NET_ID, net_id);
4674 
4675  n_ptr->profile_type = ADB_PROFILE_TYPE_BROADCAST;
4676  DBA_SetFieldValue(dba_rec, DBA_FIELD_PROFILE_TYPE, (U32BIT)n_ptr->profile_type);
4677 
4678  STB_LLAddBlockToEnd(&network_rec_list, (LINK_LIST_PTR_BLK *)n_ptr);
4679  }
4680  else
4681  {
4682  STB_AppFreeMemory(n_ptr);
4683  n_ptr = NULL;
4684  }
4685  }
4686 
4687  FUNCTION_FINISH(DBDEF_AddNetworkRec);
4688 
4689  return(n_ptr);
4690 }
4691 
4697 {
4698  FUNCTION_START(DBDEF_DeleteNetworkRec);
4699  DeleteNetworkRec(n_ptr);
4700  FUNCTION_FINISH(DBDEF_DeleteNetworkRec);
4701 }
4702 
4708 void DBDEF_SetNetworkName(ADB_NETWORK_REC *n_ptr, U8BIT *name)
4709 {
4710  BOOLEAN changed;
4711  U16BIT new_name_len;
4712 
4713  FUNCTION_START(DBDEF_SetNetworkName);
4714 
4715  changed = TRUE;
4716  new_name_len = 0;
4717 
4718  if (name != NULL)
4719  {
4720  new_name_len = STB_GetNumBytesInString(name);
4721  }
4722 
4723  if (n_ptr->name_str != NULL)
4724  {
4725  if (new_name_len == n_ptr->name_str->nbytes)
4726  {
4727  /* String lengths are the same, check the bytes */
4728  if (memcmp(name, n_ptr->name_str->str_ptr, new_name_len) == 0)
4729  {
4730  /* Names are the same */
4731  changed = FALSE;
4732  }
4733  }
4734  }
4735 
4736  if (changed)
4737  {
4738  /* Free the current name */
4739  if (n_ptr->name_str != NULL)
4740  {
4741  DBDEF_ReleaseString(n_ptr->name_str);
4742  n_ptr->name_str = NULL;
4743  }
4744 
4745  if (name != NULL)
4746  {
4747  n_ptr->name_str = DBDEF_MakeString(0, name, new_name_len);
4748  }
4749 
4750  if (n_ptr->name_str != NULL)
4751  {
4752  DBA_SetFieldString(n_ptr->dba_rec, DBA_FIELD_REC_NAME, n_ptr->name_str->str_ptr,
4753  n_ptr->name_str->nbytes);
4754  }
4755  else
4756  {
4757  DBA_SetFieldString(n_ptr->dba_rec, DBA_FIELD_REC_NAME, NULL, 0);
4758  }
4759 
4760  DBA_SaveRecord(n_ptr->dba_rec);
4761  }
4762 
4763  FUNCTION_FINISH(DBDEF_SetNetworkName);
4764 }
4765 
4773 {
4774  ADB_NETWORK_REC *n_ptr;
4775 
4776  FUNCTION_START(DBDEF_FindNetworkRec);
4777 
4778  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
4779  while (n_ptr != NULL)
4780  {
4781  if ((n_ptr->net_id == net_id) && DBDEF_NetworkInProfile(n_ptr) &&
4782  ((satellite == NULL) || (n_ptr->satellite == satellite)))
4783  {
4784  break;
4785  }
4787  }
4788 
4789  FUNCTION_FINISH(DBDEF_FindNetworkRec);
4790 
4791  return(n_ptr);
4792 }
4793 
4801 {
4802  ADB_NETWORK_REC *net_ptr;
4803 
4804  FUNCTION_START(DBDEF_GetNextNetworkRec);
4805 
4806  if (n_ptr == NULL)
4807  {
4808  net_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
4809  }
4810  else
4811  {
4812  net_ptr = (ADB_NETWORK_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)n_ptr);
4813  }
4814 
4815  while ((net_ptr != NULL) && !DBDEF_NetworkInProfile(net_ptr))
4816  {
4817  net_ptr = (ADB_NETWORK_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)net_ptr);
4818  }
4819 
4820  FUNCTION_FINISH(DBDEF_GetNextNetworkRec);
4821 
4822  return(net_ptr);
4823 }
4824 
4830 {
4831  FUNCTION_START(DBDEF_GetNumTransports);
4832  FUNCTION_FINISH(DBDEF_GetNumTransports);
4833  return(STB_LLGetNumBlocks(&transport_rec_list));
4834 }
4835 
4843 {
4844  ADB_TRANSPORT_REC *trans_ptr;
4845 
4846  FUNCTION_START(DBDEF_GetNextTransportRec);
4847 
4848  if (t_ptr == NULL)
4849  {
4850  trans_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
4851  }
4852  else
4853  {
4854  trans_ptr = (ADB_TRANSPORT_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)t_ptr);
4855  }
4856 
4857  while ((trans_ptr != NULL) && !DBDEF_TransportInProfile(trans_ptr))
4858  {
4859  trans_ptr = (ADB_TRANSPORT_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)trans_ptr);
4860  }
4861 
4862  FUNCTION_FINISH(DBDEF_GetNextTransportRec);
4863 
4864  return(trans_ptr);
4865 }
4866 
4875  ADB_NETWORK_REC *network)
4876 {
4877  ADB_TRANSPORT_REC *t_ptr;
4878  void *dba_rec;
4879  void *dba_network;
4880 
4881  FUNCTION_START(DBDEF_AddTerrestrialTransportRec);
4882 
4883  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
4884  if (t_ptr != NULL)
4885  {
4886  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
4887 
4888  t_ptr->network = network;
4889 
4890  /* Check if top bit is set - if so this is an analog frequency */
4891  if ((freq_hz & 0x80000000L) != 0)
4892  {
4893  /* Analog */
4894  t_ptr->sig_type = SIGNAL_ANALOG;
4895  t_ptr->frequency = (freq_hz & 0x7fffffffL);
4896  }
4897  else
4898  {
4899  t_ptr->sig_type = SIGNAL_COFDM;
4900  t_ptr->frequency = freq_hz;
4901 
4902  t_ptr->u.terr.plp_id = plp_id;
4903 
4904  /* Initialise tuning parameters requiring non-zero state */
4905  t_ptr->u.terr.constellation = TUNE_TCONST_UNDEFINED;
4906  t_ptr->u.terr.hierarchy = TUNE_THIERARCHY_UNDEFINED;
4907  t_ptr->u.terr.lp_code_rate = TUNE_TCODERATE_UNDEFINED;
4908  t_ptr->u.terr.hp_code_rate = TUNE_TCODERATE_UNDEFINED;
4909  t_ptr->u.terr.guard_int = TUNE_TGUARDINT_UNDEFINED;
4910  }
4911 
4912  if (network != NULL)
4913  {
4914  dba_network = network->dba_rec;
4915  }
4916  else
4917  {
4918  dba_network = NULL;
4919  }
4920 
4921  /* Add database record */
4922  dba_rec = DBA_CreateRecord(DBA_RECORD_TERR_TRANSPORT, dba_network);
4923  if (dba_rec != NULL)
4924  {
4925  t_ptr->dba_rec = dba_rec;
4926 
4927  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, freq_hz); // incl top bit set for analog
4928  DBA_SetFieldValue(dba_rec, DBA_FIELD_TTRAN_PLP_ID, plp_id);
4929 
4930  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
4931 
4932  DBA_SaveRecord(t_ptr->dba_rec);
4933  }
4934  else
4935  {
4936  STB_AppFreeMemory(t_ptr);
4937  t_ptr = NULL;
4938  }
4939  }
4940 
4941  FUNCTION_FINISH(DBDEF_AddTerrestrialTransportRec);
4942 
4943  return(t_ptr);
4944 }
4945 
4953 {
4954  ADB_TRANSPORT_REC *t_ptr;
4955 
4956  FUNCTION_START(DBDEF_FindTerrestrialTransportRec);
4957 
4958  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
4959  while (t_ptr != NULL)
4960  {
4961  if ((t_ptr->sig_type == SIGNAL_COFDM) &&
4962  (t_ptr->frequency == freq_hz) &&
4963  (t_ptr->u.terr.plp_id == plp_id))
4964  {
4965  break;
4966  }
4967  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetNextBlock(&t_ptr->ptrs);
4968  }
4969 
4970  FUNCTION_FINISH(DBDEF_FindTerrestrialTransportRec);
4971 
4972  return(t_ptr);
4973 }
4974 
4982 ADB_TRANSPORT_REC* DBDEF_AddCableTransportRec(U32BIT freq_hz, U32BIT symbol_rate, ADB_NETWORK_REC *network)
4983 {
4984  ADB_TRANSPORT_REC *t_ptr;
4985  void *dba_rec;
4986  void *dba_network;
4987 
4988  FUNCTION_START(DBDEF_AddCableTransportRec);
4989 
4990  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
4991  if (t_ptr != NULL)
4992  {
4993  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
4994 
4995  t_ptr->network = network;
4996  t_ptr->sig_type = SIGNAL_QAM;
4997  t_ptr->frequency = freq_hz;
4998  t_ptr->u.cab.symbol_rate = symbol_rate;
4999 
5000  if (network != NULL)
5001  {
5002  dba_network = network->dba_rec;
5003  }
5004  else
5005  {
5006  dba_network = NULL;
5007  }
5008 
5009  /* Add database record */
5010  dba_rec = DBA_CreateRecord(DBA_RECORD_CAB_TRANSPORT, dba_network);
5011  if (dba_rec != NULL)
5012  {
5013  t_ptr->dba_rec = dba_rec;
5014 
5015  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, freq_hz);
5016  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_SRATE, symbol_rate);
5017 
5018  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
5019 
5020  DBA_SaveRecord(t_ptr->dba_rec);
5021  }
5022  else
5023  {
5024  STB_AppFreeMemory(t_ptr);
5025  t_ptr = NULL;
5026  }
5027  }
5028 
5029  FUNCTION_FINISH(DBDEF_AddCableTransportRec);
5030 
5031  return(t_ptr);
5032 }
5033 
5040 ADB_TRANSPORT_REC* DBDEF_FindCableTransportRec(U32BIT freq_hz, U32BIT symbol_rate)
5041 {
5042  ADB_TRANSPORT_REC *t_ptr;
5043 
5044  FUNCTION_START(DBDEF_FindCableTransportRec);
5045 
5046  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
5047  while (t_ptr != NULL)
5048  {
5049  if ((t_ptr->sig_type == SIGNAL_QAM) && (t_ptr->frequency == freq_hz) &&
5050  (symbol_rate == SYMBOL_RATE_AUTO ||
5051  (t_ptr->u.cab.symbol_rate == SYMBOL_RATE_AUTO) ||
5052  (t_ptr->u.cab.symbol_rate == symbol_rate)))
5053  {
5054  break;
5055  }
5057  }
5058 
5059  FUNCTION_FINISH(DBDEF_FindCableTransportRec);
5060 
5061  return(t_ptr);
5062 }
5063 
5064 void DBDEF_SetCableTransportSymbolRate(ADB_TRANSPORT_REC *t_ptr, U16BIT symbol_rate)
5065 {
5066  FUNCTION_START(DBDEF_SetCableTransportSymbolRate);
5067 
5068  if (t_ptr->u.cab.symbol_rate != symbol_rate)
5069  {
5070  t_ptr->u.cab.symbol_rate = symbol_rate;
5071  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRAN_SRATE, t_ptr->u.cab.symbol_rate);
5072  DBA_SaveRecord(t_ptr->dba_rec);
5073  }
5074 
5075  FUNCTION_FINISH(DBDEF_SetCableTransportSymbolRate);
5076 }
5077 
5078 void DBDEF_SetCableTransportMode(ADB_TRANSPORT_REC *t_ptr, E_STB_DP_CMODE cmode)
5079 {
5080  FUNCTION_START(DBDEF_SetCableTransportMode);
5081 
5082  if (t_ptr->u.cab.cmode != cmode)
5083  {
5084  t_ptr->u.cab.cmode = cmode;
5085  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_CTRAN_MODE, t_ptr->u.cab.cmode);
5086  DBA_SaveRecord(t_ptr->dba_rec);
5087  }
5088 
5089  FUNCTION_FINISH(DBDEF_SetCableTransportMode);
5090 }
5091 
5102 ADB_TRANSPORT_REC* DBDEF_AddSatTransportRec(U32BIT freq_hz, U16BIT symbol_rate,
5103  E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation,
5104  ADB_NETWORK_REC *network)
5105 {
5106  ADB_TRANSPORT_REC *t_ptr;
5107  void *dba_rec;
5108  void *dba_network;
5109 
5110  FUNCTION_START(DBDEF_AddSatTransportRec);
5111 
5112  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
5113  if (t_ptr != NULL)
5114  {
5115  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
5116 
5117  t_ptr->network = network;
5118  t_ptr->sig_type = SIGNAL_QPSK;
5119  t_ptr->frequency = freq_hz;
5120  t_ptr->u.sat.symbol_rate = symbol_rate;
5121  t_ptr->u.sat.polarity = polarity;
5122  t_ptr->u.sat.dvb_s2 = dvb_s2;
5123  t_ptr->u.sat.modulation = modulation;
5124 
5125  if (network != NULL)
5126  {
5127  dba_network = network->dba_rec;
5128  }
5129  else
5130  {
5131  dba_network = NULL;
5132  }
5133 
5134  /* Add database record */
5135  dba_rec = DBA_CreateRecord(DBA_RECORD_SAT_TRANSPORT, dba_network);
5136  if (dba_rec != NULL)
5137  {
5138  t_ptr->dba_rec = dba_rec;
5139 
5140  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, freq_hz);
5141  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_SRATE, symbol_rate);
5142  DBA_SetFieldValue(dba_rec, DBA_FIELD_STRAN_POL, polarity);
5143  DBA_SetFieldValue(dba_rec, DBA_FIELD_STRAN_DVBS2, dvb_s2);
5144  DBA_SetFieldValue(dba_rec, DBA_FIELD_STRAN_MODULATION, modulation);
5145 
5146  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
5147 
5148  DBA_SaveRecord(t_ptr->dba_rec);
5149  }
5150  else
5151  {
5152  STB_AppFreeMemory(t_ptr);
5153  t_ptr = NULL;
5154  }
5155  }
5156 
5157  FUNCTION_FINISH(DBDEF_AddSatTransportRec);
5158 
5159  return(t_ptr);
5160 }
5161 
5170 ADB_TRANSPORT_REC* DBDEF_FindSatTransportRec(U32BIT freq_hz, U16BIT symbol_rate,
5171  E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation, void *satellite)
5172 {
5173  ADB_TRANSPORT_REC *t_ptr;
5174 
5175  FUNCTION_START(DBDEF_FindSatTransportRec);
5176 
5177  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
5178  while (t_ptr != NULL)
5179  {
5180  if (t_ptr->sig_type == SIGNAL_QPSK)
5181  {
5182  if ((t_ptr->frequency == freq_hz) && (t_ptr->u.sat.symbol_rate == symbol_rate) &&
5183  (t_ptr->u.sat.polarity == polarity) && (t_ptr->u.sat.dvb_s2 == dvb_s2) &&
5184  (t_ptr->u.sat.modulation == modulation))
5185  {
5186  if ((satellite == NULL) ||
5187  ((t_ptr->network != NULL) &&
5188  (t_ptr->network->satellite != NULL) &&
5189  (t_ptr->network->satellite == satellite)))
5190  {
5191  break;
5192  }
5193  }
5194  }
5196  }
5197 
5198  FUNCTION_FINISH(DBDEF_FindSatTransportRec);
5199 
5200  return(t_ptr);
5201 }
5202 
5203 #ifdef COMMON_INTERFACE
5204 
5209 ADB_TRANSPORT_REC* DBDEF_AddVirtualTransportRec(ADB_NETWORK_REC *network)
5210 {
5211  ADB_TRANSPORT_REC *t_ptr;
5212  void *dba_rec;
5213  void *dba_network;
5214 
5215  FUNCTION_START(DBDEF_AddVirtualTransportRec);
5216 
5217  t_ptr = STB_AppGetMemory(sizeof(ADB_TRANSPORT_REC));
5218  if (t_ptr != NULL)
5219  {
5220  memset(t_ptr, 0, sizeof(ADB_TRANSPORT_REC));
5221 
5222  t_ptr->network = network;
5223 
5224  t_ptr->sig_type = SIGNAL_NONE;
5225 
5226  if (network != NULL)
5227  {
5228  dba_network = network->dba_rec;
5229  }
5230  else
5231  {
5232  dba_network = NULL;
5233  }
5234 
5235  /* Add database record */
5236  dba_rec = DBA_CreateRecord(DBA_RECORD_TERR_TRANSPORT, dba_network);
5237  if (dba_rec != NULL)
5238  {
5239  t_ptr->dba_rec = dba_rec;
5240 
5241  DBA_SetFieldValue(dba_rec, DBA_FIELD_TRAN_FREQ, 0);
5242  DBA_SetFieldValue(dba_rec, DBA_FIELD_TTRAN_PLP_ID, 0);
5243 
5244  STB_LLAddBlockToEnd(&transport_rec_list, (LINK_LIST_PTR_BLK *)t_ptr);
5245 
5246  DBA_SaveRecord(t_ptr->dba_rec);
5247  }
5248  else
5249  {
5250  STB_AppFreeMemory(t_ptr);
5251  t_ptr = NULL;
5252  }
5253  }
5254 
5255  FUNCTION_FINISH(DBDEF_AddVirtualTransportRec);
5256 
5257  return(t_ptr);
5258 }
5259 #endif /*COMMON_INTERFACE*/
5260 
5272  U16BIT symbol_rate, E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation,
5273  ADB_NETWORK_REC *network)
5274 {
5275  FUNCTION_START(DBDEF_SetSatTransportTuningParams);
5276 
5277  if (t_ptr != NULL)
5278  {
5279  if ((network != NULL) && (t_ptr->network != network))
5280  {
5281  t_ptr->network = network;
5282  DBA_SetRecordParent(t_ptr->dba_rec, network->dba_rec);
5283  }
5284 
5285  t_ptr->frequency = freq_hz;
5286  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRAN_FREQ, freq_hz);
5287 
5288  t_ptr->u.sat.symbol_rate = symbol_rate;
5289  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRAN_SRATE, symbol_rate);
5290 
5291  t_ptr->u.sat.polarity = polarity;
5292  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_STRAN_POL, polarity);
5293 
5294  t_ptr->u.sat.dvb_s2 = dvb_s2;
5295  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_STRAN_DVBS2, dvb_s2);
5296 
5297  t_ptr->u.sat.modulation = modulation;
5298  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_STRAN_MODULATION, modulation);
5299 
5300  DBA_SaveRecord(t_ptr->dba_rec);
5301  }
5302 
5303  FUNCTION_FINISH(DBDEF_SetSatTransportTuningParams);
5304 }
5305 
5315  U32BIT onet_id, U32BIT tran_id)
5316 {
5317  ADB_TRANSPORT_REC *t_ptr;
5318  ADB_NETWORK_REC *n_ptr;
5319 
5320  FUNCTION_START(DBDEF_FindTransportRecByIds);
5321 
5322  if (transp == NULL)
5323  {
5324  t_ptr = (ADB_TRANSPORT_REC *)STB_LLGetFirstBlock(&transport_rec_list);
5325  }
5326  else
5327  {
5329  }
5330 
5331  while (t_ptr != NULL)
5332  {
5333  if (DBDEF_TransportInProfile(t_ptr))
5334  {
5335  if (((tran_id == ADB_INVALID_DVB_ID) || (t_ptr->tran_id == tran_id)) &&
5336  ((onet_id == ADB_INVALID_DVB_ID) || (t_ptr->orig_net_id == onet_id)))
5337  {
5338  n_ptr = t_ptr->network;
5339 
5340  if ((net_id == ADB_INVALID_DVB_ID) || (n_ptr == NULL))
5341  {
5342  /* Found it */
5343  break;
5344  }
5345  else if (n_ptr != NULL)
5346  {
5347  if (n_ptr->net_id == net_id)
5348  {
5349  /* Found it */
5350  break;
5351  }
5352  }
5353  }
5354  }
5356  }
5357 
5358  FUNCTION_FINISH(DBDEF_FindTransportRecByIds);
5359 
5360  return(t_ptr);
5361 }
5362 
5369 {
5370  FUNCTION_START(DBDEF_SetTransportTransportId);
5371 
5372  if (t_ptr->tran_id != tran_id)
5373  {
5374  t_ptr->tran_id = tran_id;
5375  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRANSPORT_ID, t_ptr->tran_id);
5376  DBA_SaveRecord(t_ptr->dba_rec);
5377  }
5378 
5379  FUNCTION_FINISH(DBDEF_SetTransportTransportId);
5380 }
5381 
5387 void DBDEF_SetTransportOrigNetworkId(ADB_TRANSPORT_REC *t_ptr, U16BIT orig_net_id)
5388 {
5389  FUNCTION_START(DBDEF_SetTransportOrigNetworkId);
5390 
5391  if (t_ptr->orig_net_id != orig_net_id)
5392  {
5393  t_ptr->orig_net_id = orig_net_id;
5394  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_ORIG_NET_ID, t_ptr->orig_net_id);
5395  DBA_SaveRecord(t_ptr->dba_rec);
5396  }
5397 
5398  FUNCTION_FINISH(DBDEF_SetTransportOrigNetworkId);
5399 }
5400 
5408 void DBDEF_GetTransportAdditionalFrequencies(ADB_TRANSPORT_REC *t_ptr, U8BIT *num_freqs, U32BIT **freqs)
5409 {
5411 
5412  if (t_ptr != NULL)
5413  {
5414  *num_freqs = t_ptr->num_additional_frequencies;
5415  *freqs = t_ptr->additional_frequencies;
5416  }
5417  else
5418  {
5419  *num_freqs = 0;
5420  *freqs = NULL;
5421  }
5422 
5423  FUNCTION_FINISH(DBDEF_GetTransportAdditionalFrequencies);
5424 }
5425 
5432 {
5433  LINK_LIST_PTR_BLK *s_ptr;
5434  LINK_LIST_PTR_BLK *next_s_ptr;
5435 
5436  FUNCTION_START(DBDEF_DeleteTransportRec);
5437 
5438  /* Delete any service records that have this transport as their parent */
5439  s_ptr = STB_LLGetFirstBlock(&service_rec_list);
5440  while (s_ptr != NULL)
5441  {
5442  next_s_ptr = STB_LLGetNextBlock(s_ptr);
5443 
5444  if (((ADB_SERVICE_REC *)s_ptr)->transport == t_ptr)
5445  {
5447  }
5448 
5449  s_ptr = next_s_ptr;
5450  }
5451 
5452  STB_LLRemoveBlock(&t_ptr->ptrs);
5453 
5455 
5456  DBA_DestroyRecord(t_ptr->dba_rec);
5457 
5458  if (t_ptr->additional_frequencies != NULL)
5459  {
5460  STB_AppFreeMemory(t_ptr->additional_frequencies);
5461  }
5462 
5463  STB_AppFreeMemory(t_ptr);
5464 
5465  FUNCTION_FINISH(DBDEF_DeleteTransportRec);
5466 }
5467 
5480 {
5481  ADB_PMT_VERSION_REC *pmt_ver_rec;
5482  void *tmp_ptr;
5483 
5484  FUNCTION_START(DBDEF_ClearTableVersionHistory);
5485 
5486  if (t_ptr != NULL)
5487  {
5488  // free pmt version list
5489  pmt_ver_rec = t_ptr->pmt_version_list;
5490  while (pmt_ver_rec != NULL)
5491  {
5492  tmp_ptr = (void *)pmt_ver_rec;
5493  pmt_ver_rec = pmt_ver_rec->next;
5494  STB_AppFreeMemory(tmp_ptr);
5495  }
5496  t_ptr->pmt_version_list = NULL;
5497  }
5498 
5499  FUNCTION_FINISH(DBDEF_ClearTableVersionHistory);
5500 }
5501 
5507 {
5508  U16BIT num_services;
5509  ADB_SERVICE_REC *serv_ptr;
5510 
5511  FUNCTION_START(DBDEF_GetNumServices);
5512 
5513  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
5514  for (num_services = 0; serv_ptr != NULL; )
5515  {
5516  if (!serv_ptr->deleted)
5517  {
5518  num_services++;
5519  }
5520 
5521  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)serv_ptr);
5522  }
5523 
5524  FUNCTION_FINISH(DBDEF_GetNumServices);
5525 
5526  return(num_services);
5527 }
5528 
5536 {
5537  ADB_SERVICE_REC *serv_ptr;
5538 
5539  FUNCTION_START(DBDEF_GetNextServiceRec);
5540 
5541  if (s_ptr == NULL)
5542  {
5543  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
5544  }
5545  else
5546  {
5547  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)s_ptr);
5548  }
5549 
5550  while ((serv_ptr != NULL) && serv_ptr->deleted)
5551  {
5552  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)serv_ptr);
5553  }
5554 
5555  FUNCTION_FINISH(DBDEF_GetNextServiceRec);
5556 
5557  return(serv_ptr);
5558 }
5559 
5567 {
5568  ADB_SERVICE_REC *serv_ptr;
5569 
5570  FUNCTION_START(DBDEF_GetPrevServiceRec);
5571 
5572  if (s_ptr == NULL)
5573  {
5574  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetLastBlock(&service_rec_list);
5575  }
5576  else
5577  {
5578  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetPrevBlock((LINK_LIST_PTR_BLK *)s_ptr);
5579  }
5580 
5581  while ((serv_ptr != NULL) && serv_ptr->deleted)
5582  {
5583  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetPrevBlock((LINK_LIST_PTR_BLK *)serv_ptr);
5584  }
5585 
5586  FUNCTION_FINISH(DBDEF_GetPrevServiceRec);
5587 
5588  return(serv_ptr);
5589 }
5590 
5599 {
5600  ADB_SERVICE_REC *s_ptr;
5601  void *trans_dba_rec;
5602  void *serv_dba_rec;
5603 
5604  FUNCTION_START(DBDEF_AddServiceRec);
5605 
5606  s_ptr = STB_AppGetMemory(sizeof(ADB_SERVICE_REC));
5607  if (s_ptr != NULL)
5608  {
5609  memset(s_ptr, 0, sizeof(ADB_SERVICE_REC));
5610  s_ptr->reqd_audio_pid = 0x1FFF;
5611 
5612  trans_dba_rec = NULL;
5613  if (t_ptr != NULL)
5614  {
5615  trans_dba_rec = t_ptr->dba_rec;
5616  }
5617 
5618  /* Add service record to database */
5619  serv_dba_rec = DBA_CreateRecord(DBA_RECORD_SERVICE, trans_dba_rec);
5620  if (serv_dba_rec != NULL)
5621  {
5622  s_ptr->dba_rec = serv_dba_rec;
5623  s_ptr->transport = t_ptr;
5624 
5625  s_ptr->serv_id = serv_id;
5626  DBA_SetFieldValue(serv_dba_rec, DBA_FIELD_SERV_ID, (U32BIT)serv_id);
5627 
5628  s_ptr->freesat_id = INVALID_FREESAT_SERV_ID;
5629  DBA_SetFieldValue(serv_dba_rec, DBA_FIELD_SERV_FREESAT_ID, (U32BIT)s_ptr->freesat_id);
5630 
5631  s_ptr->lcn_editable = TRUE;
5632  DBA_SetFieldValue(serv_dba_rec, DBA_FIELD_SERV_LCN_EDITABLE, (U32BIT)s_ptr->lcn_editable);
5633 
5634  /* Default all services to being visible and selectable */
5635  s_ptr->hidden = FALSE;
5636  DBA_SetFieldValue(serv_dba_rec, DBA_FIELD_SERV_HIDDEN, s_ptr->hidden);
5637 
5638  s_ptr->selectable = TRUE;
5639  DBA_SetFieldValue(serv_dba_rec, DBA_FIELD_SERV_SELECTABLE, s_ptr->selectable);
5640 
5641  STB_LLAddBlockToEnd(&service_rec_list, (LINK_LIST_PTR_BLK *)s_ptr);
5642  }
5643  else
5644  {
5645  /* Not enough NVM or RAM to store this service */
5646  STB_AppFreeMemory(s_ptr);
5647  s_ptr = NULL;
5648  }
5649  }
5650 
5651  FUNCTION_FINISH(DBDEF_AddServiceRec);
5652 
5653  return(s_ptr);
5654 }
5655 
5664 {
5665  ADB_SERVICE_REC *s_ptr;
5666  U8BIT i, j;
5667 
5668  FUNCTION_START(DBDEF_CopyServiceRec);
5669 
5670  s_ptr = DBDEF_AddServiceRec(orig_serv->serv_id, orig_serv->transport);
5671  if (s_ptr != NULL)
5672  {
5673  s_ptr->serv_type = orig_serv->serv_type;
5674  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_TYPE, s_ptr->serv_type);
5675 
5676  if (s_ptr->serv_type == ADB_SERVICE_TYPE_ANALOG)
5677  {
5678  num_analog_channels++;
5679  }
5680 
5681  s_ptr->serv_lcn = orig_serv->serv_lcn;
5682  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_REQ_LCN, s_ptr->serv_lcn);
5683 
5684  s_ptr->allocated_lcn = orig_serv->allocated_lcn;
5685  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_LCN, s_ptr->allocated_lcn);
5686 
5687  if ((s_ptr->name_str = DBDEF_CopyString(orig_serv->name_str)) != NULL)
5688  {
5689  DBA_SetFieldString(s_ptr->dba_rec, DBA_FIELD_REC_NAME, s_ptr->name_str->str_ptr,
5690  s_ptr->name_str->nbytes);
5691  }
5692 
5693  s_ptr->fav_groups = orig_serv->fav_groups;
5694  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_FAV_GROUPS, s_ptr->fav_groups);
5695 
5696  s_ptr->locked = orig_serv->locked;
5697  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_LOCKED, s_ptr->locked);
5698 
5699  s_ptr->hidden = orig_serv->hidden;
5700  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_HIDDEN, s_ptr->hidden);
5701 
5702  s_ptr->selectable = orig_serv->selectable;
5703  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_SELECTABLE, s_ptr->selectable);
5704 
5705  s_ptr->lcn_editable = orig_serv->lcn_editable;
5706  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_LCN_EDITABLE, s_ptr->lcn_editable);
5707 
5708  s_ptr->sched_disabled = orig_serv->sched_disabled;
5709  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_SCHED_DISABLED, s_ptr->sched_disabled);
5710 
5711  s_ptr->now_next_disabled = orig_serv->now_next_disabled;
5712  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_NOWNEXT_DISABLED, s_ptr->now_next_disabled);
5713 
5714  s_ptr->freesat_id = orig_serv->freesat_id;
5715  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_FREESAT_ID, s_ptr->freesat_id);
5716 
5717  s_ptr->region_id = orig_serv->region_id;
5718  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_REGION_ID, s_ptr->region_id);
5719 
5720  s_ptr->deleted = orig_serv->deleted;
5721  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_DELETED, s_ptr->deleted);
5722 
5723  s_ptr->provider_str = DBDEF_CopyString(orig_serv->provider_str);
5724  s_ptr->short_name_str = DBDEF_CopyString(orig_serv->short_name_str);
5725 
5726  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
5727  {
5728  for (j = 0; j < ADB_NUM_SERV_NAME_IDS; j++)
5729  {
5730  s_ptr->name_array[i][j] = DBDEF_CopyString(orig_serv->name_array[i][j]);
5731  }
5732 
5733  s_ptr->short_name_array[i] = DBDEF_CopyString(orig_serv->short_name_array[i]);
5734  s_ptr->provider_array[i] = DBDEF_CopyString(orig_serv->provider_array[i]);
5735  s_ptr->guidance[i].text = DBDEF_CopyString(orig_serv->guidance[i].text);
5736  s_ptr->guidance[i].type = orig_serv->guidance[i].type;
5737  s_ptr->guidance[i].mode = orig_serv->guidance[i].mode;
5738  }
5739 
5740  s_ptr->scrambled = orig_serv->scrambled;
5741 
5742  s_ptr->eit_now_next_avail = orig_serv->eit_now_next_avail;
5743  s_ptr->eit_sched_avail = orig_serv->eit_sched_avail;
5744 
5745  s_ptr->running_status = orig_serv->running_status;
5746  s_ptr->not_running = orig_serv->not_running;
5747  s_ptr->unavailable = orig_serv->unavailable;
5748  s_ptr->has_fta_desc = orig_serv->has_fta_desc;
5749  s_ptr->do_not_scramble = orig_serv->do_not_scramble;
5750 
5751  s_ptr->def_authority = DBDEF_CopyString(orig_serv->def_authority);
5752 
5753  s_ptr->stream_list = DBDEF_CopyStreamList(orig_serv->stream_list);
5754 
5755  s_ptr->pcr_pid = orig_serv->pcr_pid;
5756  s_ptr->video_pid = orig_serv->video_pid;
5757  s_ptr->audio_pid = orig_serv->audio_pid;
5758  s_ptr->ad_pid = orig_serv->ad_pid;
5759  s_ptr->ttext_pid = orig_serv->ttext_pid;
5760  s_ptr->ttext_mag = orig_serv->ttext_mag;
5761  s_ptr->ttext_page = orig_serv->ttext_page;
5762  s_ptr->subtitle_pid = orig_serv->subtitle_pid;
5763  s_ptr->subtitle_cpage = orig_serv->subtitle_cpage;
5764  s_ptr->subtitle_apage = orig_serv->subtitle_apage;
5765  s_ptr->video_type = orig_serv->video_type;
5766  s_ptr->audio_type = orig_serv->audio_type;
5767 
5768  DBA_SaveRecord(s_ptr->dba_rec);
5769  }
5770 
5771  FUNCTION_FINISH(DBDEF_CopyServiceRec);
5772 
5773  return(s_ptr);
5774 }
5775 
5783 BOOLEAN DBDEF_SetServiceName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
5784 {
5785  BOOLEAN changed;
5786  U16BIT new_name_len;
5787 
5788  FUNCTION_START(DBDEF_SetServiceName);
5789 
5790  changed = TRUE;
5791  new_name_len = 0;
5792 
5793  if (name != NULL)
5794  {
5795  new_name_len = STB_GetNumBytesInString(name);
5796  }
5797 
5798  if (s_ptr->name_str != NULL)
5799  {
5800  if (new_name_len == s_ptr->name_str->nbytes)
5801  {
5802  /* String lengths are the same, check the bytes */
5803  if (memcmp(name, s_ptr->name_str->str_ptr, new_name_len) == 0)
5804  {
5805  /* Names are the same */
5806  changed = FALSE;
5807  }
5808  }
5809  }
5810 
5811  if (changed)
5812  {
5813  /* Free the current name */
5814  if (s_ptr->name_str != NULL)
5815  {
5816  DBDEF_ReleaseString(s_ptr->name_str);
5817  s_ptr->name_str = NULL;
5818  }
5819 
5820  if (name != NULL)
5821  {
5822  s_ptr->name_str = DBDEF_MakeString(0, name, new_name_len);
5823  }
5824 
5825  if (s_ptr->name_str != NULL)
5826  {
5827  DBA_SetFieldString(s_ptr->dba_rec, DBA_FIELD_REC_NAME, s_ptr->name_str->str_ptr,
5828  s_ptr->name_str->nbytes);
5829  }
5830  else
5831  {
5832  DBA_SetFieldString(s_ptr->dba_rec, DBA_FIELD_REC_NAME, NULL, 0);
5833  }
5834 
5835  DBA_SaveRecord(s_ptr->dba_rec);
5836  }
5837 
5838  FUNCTION_FINISH(DBDEF_SetServiceName);
5839 
5840  return(changed);
5841 }
5842 
5850 BOOLEAN DBDEF_SetServiceShortName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
5851 {
5852  BOOLEAN changed;
5853  U16BIT new_name_len;
5854 
5855  FUNCTION_START(DBDEF_SetServiceShortName);
5856 
5857  changed = TRUE;
5858  new_name_len = 0;
5859 
5860  if (name != NULL)
5861  {
5862  new_name_len = STB_GetNumBytesInString(name);
5863  }
5864 
5865  if (s_ptr->short_name_str != NULL)
5866  {
5867  if (new_name_len == s_ptr->short_name_str->nbytes)
5868  {
5869  /* String lengths are the same, check the bytes */
5870  if (memcmp(name, s_ptr->short_name_str->str_ptr, new_name_len) == 0)
5871  {
5872  /* Names are the same */
5873  changed = FALSE;
5874  }
5875  }
5876  }
5877  else if (name == NULL)
5878  {
5879  /* Names are both NULL */
5880  changed = FALSE;
5881  }
5882 
5883  if (changed)
5884  {
5885  /* Free the current name */
5886  if (s_ptr->short_name_str != NULL)
5887  {
5888  DBDEF_ReleaseString(s_ptr->short_name_str);
5889  s_ptr->short_name_str = NULL;
5890  }
5891 
5892  if (name != NULL)
5893  {
5894  s_ptr->short_name_str = DBDEF_MakeString(0, name, new_name_len);
5895  }
5896  }
5897 
5898  FUNCTION_FINISH(DBDEF_SetServiceShortName);
5899 
5900  return(changed);
5901 }
5902 
5910 BOOLEAN DBDEF_SetServiceProviderName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
5911 {
5912  BOOLEAN changed;
5913  U16BIT new_name_len;
5914 
5915  FUNCTION_START(DBDEF_SetServiceProviderName);
5916 
5917  changed = TRUE;
5918  new_name_len = 0;
5919 
5920  if (name != NULL)
5921  {
5922  new_name_len = STB_GetNumBytesInString(name);
5923  }
5924 
5925  if (s_ptr->provider_str != NULL)
5926  {
5927  if (new_name_len == s_ptr->provider_str->nbytes)
5928  {
5929  /* String lengths are the same, check the bytes */
5930  if (memcmp(name, s_ptr->provider_str->str_ptr, new_name_len) == 0)
5931  {
5932  /* Names are the same */
5933  changed = FALSE;
5934  }
5935  }
5936  }
5937  else if (name == NULL)
5938  {
5939  /* Names are both NULL */
5940  changed = FALSE;
5941  }
5942 
5943  if (changed)
5944  {
5945  /* Free the current name */
5946  if (s_ptr->provider_str != NULL)
5947  {
5948  DBDEF_ReleaseString(s_ptr->provider_str);
5949  s_ptr->provider_str = NULL;
5950  }
5951 
5952  if (name != NULL)
5953  {
5954  s_ptr->provider_str = DBDEF_MakeString(0, name, new_name_len);
5955  }
5956  }
5957 
5958  FUNCTION_FINISH(DBDEF_SetServiceProviderName);
5959 
5960  return(changed);
5961 }
5962 
5969 BOOLEAN DBDEF_SetServiceType(ADB_SERVICE_REC *s_ptr, ADB_SERVICE_TYPE serv_type)
5970 {
5971  BOOLEAN changed;
5972 
5973  FUNCTION_START(DBDEF_SetServiceType);
5974 
5975  changed = FALSE;
5976 
5977  if (s_ptr->serv_type != serv_type)
5978  {
5979  s_ptr->serv_type = serv_type;
5980  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_TYPE, s_ptr->serv_type);
5981  DBA_SaveRecord(s_ptr->dba_rec);
5982  changed = TRUE;
5983  }
5984 
5985  FUNCTION_FINISH(DBDEF_SetServiceType);
5986 
5987  return(changed);
5988 }
5989 
5995 {
5996 #if 0
5997  ADB_EVENT_REC *e_ptr;
5998  U16BIT i;
5999 #endif
6000 
6001  FUNCTION_START(DBDEF_SaveServiceEventSchedule);
6002 
6003 #if 0
6004  /* Create a database record for each event and save the current values for the record */
6005  e_ptr = s_ptr->event_schedule;
6006  while (e_ptr != NULL)
6007  {
6008  if (e_ptr->dba_rec == NULL)
6009  {
6010  e_ptr->dba_rec = DBA_CreateRecord(DBA_RECORD_EVENT, s_ptr->dba_rec);
6011  }
6012 
6013  if (e_ptr->dba_rec != NULL)
6014  {
6015  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_ID, e_ptr->event_id);
6016  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_STARTTIME, e_ptr->start);
6017  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_DURATION, e_ptr->duration);
6018  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_VERSION, e_ptr->version);
6019 #if 0
6020  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_AGE_RATING, e_ptr->parental_age_rating);
6021  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_SCRAMBLED, e_ptr->scrambled);
6022  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_SUBTITLES, e_ptr->subtitles_avail);
6023  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_AUDIO_DESC, e_ptr->audio_desc);
6024  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_FREE_TO_AIR, e_ptr->has_fta_desc);
6025  DBA_SetFieldValue(e_ptr->dba_rec, DBA_FIELD_EVENT_DO_NOT_SCRAMBLE, e_ptr->do_not_scramble);
6026 
6027  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
6028  {
6029  if (e_ptr->name_array[i] != NULL)
6030  {
6031  DBA_SetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_NAME,
6032  e_ptr->name_array[i]->lang_code, e_ptr->name_array[i]->str_ptr,
6033  e_ptr->name_array[i]->nbytes);
6034  }
6035 
6036  if (e_ptr->desc_array[i] != NULL)
6037  {
6038  DBA_SetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_DESCRIPTION,
6039  e_ptr->desc_array[i]->lang_code, e_ptr->desc_array[i]->str_ptr,
6040  e_ptr->desc_array[i]->nbytes);
6041  }
6042 
6043  if (e_ptr->extended_info[i].event_text != NULL)
6044  {
6045  DBA_SetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_EXTENDED_DESC,
6046  e_ptr->extended_info[i].event_text->lang_code,
6047  e_ptr->extended_info[i].event_text->str_ptr,
6048  e_ptr->extended_info[i].event_text->nbytes);
6049  }
6050 
6051  if (e_ptr->guidance[i] != NULL)
6052  {
6053  DBA_SetFieldLangString(e_ptr->dba_rec, DBA_FIELD_EVENT_GUIDANCE,
6054  e_ptr->guidance[i]->lang_code, e_ptr->guidance[i]->str_ptr,
6055  e_ptr->guidance[i]->nbytes);
6056  }
6057  }
6058 
6059  if ((e_ptr->content_data != NULL) && (e_ptr->content_len > 0))
6060  {
6061  DBA_SetFieldData(e_ptr->dba_rec, DBA_FIELD_EVENT_CONTENT_DATA, e_ptr->content_data,
6062  e_ptr->content_len);
6063  }
6064 #endif
6065  DBA_SaveRecord(e_ptr->dba_rec);
6066  }
6067 
6068  e_ptr = e_ptr->next;
6069  }
6070 #else
6071  USE_UNWANTED_PARAM(s_ptr);
6072 #endif
6073 
6074  FUNCTION_FINISH(DBDEF_SaveServiceEventSchedule);
6075 }
6076 
6084 {
6085  ADB_SERVICE_REC *serv_ptr;
6086 
6087  FUNCTION_START(DBDEF_GetNextServiceOnTransport);
6088 
6089  if (s_ptr == NULL)
6090  {
6091  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6092  }
6093  else
6094  {
6095  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)s_ptr);
6096  }
6097 
6098  /* Look for service with required transport */
6099  while (serv_ptr != NULL)
6100  {
6101  if ((serv_ptr->transport == t_ptr) && !serv_ptr->deleted)
6102  {
6103  break;
6104  }
6105  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)serv_ptr);
6106  }
6107 
6108  FUNCTION_FINISH(DBDEF_GetNextServiceOnTransport);
6109 
6110  return(serv_ptr);
6111 }
6112 
6120 {
6121  ADB_SERVICE_REC *s_ptr;
6122 
6123  FUNCTION_START(DBDEF_FindServiceRec);
6124 
6125  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6126  while (s_ptr != NULL)
6127  {
6128  if ((s_ptr->serv_id == serv_id) && (s_ptr->transport == t_ptr))
6129  {
6130  break;
6131  }
6132 
6134  }
6135 
6136  FUNCTION_FINISH(DBDEF_FindServiceRec);
6137 
6138  return(s_ptr);
6139 }
6140 
6150 ADB_SERVICE_REC* DBDEF_FindServiceRecByIds(ADB_SERVICE_REC *servp, U32BIT net_id, U32BIT onet_id,
6151  U32BIT tran_id, U32BIT serv_id)
6152 {
6153  ADB_SERVICE_REC *s_ptr;
6154  ADB_TRANSPORT_REC *t_ptr;
6155  ADB_NETWORK_REC *n_ptr;
6156 
6157  FUNCTION_START(DBDEF_FindServiceRecByIds);
6158 
6159  if (servp == NULL)
6160  {
6161  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6162  }
6163  else
6164  {
6166  }
6167 
6168  while (s_ptr != NULL)
6169  {
6170  if ((serv_id == ADB_INVALID_DVB_ID) || (s_ptr->serv_id == serv_id))
6171  {
6172  t_ptr = s_ptr->transport;
6173  if (t_ptr != NULL)
6174  {
6175  if (DBDEF_TransportInProfile(t_ptr))
6176  {
6177  if (((tran_id == ADB_INVALID_DVB_ID) || (t_ptr->tran_id == tran_id)) &&
6178  ((onet_id == ADB_INVALID_DVB_ID) || (t_ptr->orig_net_id == onet_id)))
6179  {
6180  if (net_id == ADB_INVALID_DVB_ID)
6181  {
6182  /* Don't care about the network ID, so use this service rec */
6183  break;
6184  }
6185  else
6186  {
6187  n_ptr = t_ptr->network;
6188  if (n_ptr != NULL)
6189  {
6190  if (n_ptr->net_id == net_id)
6191  {
6192  /* Found it */
6193  break;
6194  }
6195  }
6196  }
6197  }
6198  }
6199  }
6200  }
6201 
6203  }
6204 
6205  FUNCTION_FINISH(DBDEF_FindServiceRecByIds);
6206 
6207  return(s_ptr);
6208 }
6209 
6218 ADB_SERVICE_REC* DBDEF_FindServiceRecByLcn(U16BIT lcn, ADB_TRANSPORT_REC *t_ptr, BOOLEAN allocated_lcn)
6219 {
6220  ADB_SERVICE_REC *s_ptr;
6221 
6222  FUNCTION_START(DBDEF_FindServiceRecByLcn);
6223 
6224  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6225  while (s_ptr != NULL)
6226  {
6227  if ((allocated_lcn && (s_ptr->allocated_lcn == lcn)) ||
6228  (!allocated_lcn && (s_ptr->serv_lcn == lcn)))
6229  {
6230  if (DBDEF_ServiceInProfile(s_ptr))
6231  {
6232  if ((t_ptr == NULL) || (t_ptr == s_ptr->transport))
6233  {
6234  break;
6235  }
6236  }
6237  }
6239  }
6240 
6241  FUNCTION_FINISH(DBDEF_FindServiceRecByLcn);
6242 
6243  return(s_ptr);
6244 }
6245 
6253 {
6254  ADB_SERVICE_REC *s_ptr;
6255 
6256  FUNCTION_START(DBDEF_FindServiceRecByFreesatId);
6257 
6258  if (servp == NULL)
6259  {
6260  s_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6261  }
6262  else
6263  {
6265  }
6266 
6267  while (s_ptr != NULL)
6268  {
6269  if (s_ptr->freesat_id == freesat_id)
6270  {
6271  break;
6272  }
6273 
6275  }
6276 
6277  FUNCTION_FINISH(DBDEF_FindServiceRecByFreesatId);
6278 
6279  return(s_ptr);
6280 }
6281 
6298 U16BIT DBDEF_GetReqdAudioPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *audio_mode, ADB_STREAM_TYPE *audio_type)
6299 {
6300  U8BIT *db_lang_ids;
6301  U16BIT a_pid;
6302  BOOLEAN found_primary;
6303  ADB_STREAM_REC *selected_stream;
6304 
6305  FUNCTION_START(DBDEF_GetReqdAudioPid);
6306 
6307  found_primary = FALSE;
6308 
6309  /* Get the first primary language */
6310  db_lang_ids = DBDEF_GetAudioLang();
6311  a_pid = GetReqdAudioPid(s_ptr, audio_mode, audio_type, db_lang_ids, &found_primary, &selected_stream);
6312 
6313  /* Check for a secondary language if the first is not found and secondary is valid */
6314  if (found_primary)
6315  {
6316  selected_stream->in_use = TRUE;
6317  }
6318  else
6319  {
6320  if ((db_lang_ids = DBDEF_GetSecondaryAudioLang()) != NULL)
6321  {
6322  a_pid = GetReqdAudioPid(s_ptr, audio_mode, audio_type, db_lang_ids, &found_primary, &selected_stream);
6323  if (selected_stream != NULL)
6324  {
6325  selected_stream->in_use = TRUE;
6326  }
6327  }
6328  }
6329 
6330  FUNCTION_FINISH(DBDEF_GetReqdAudioPid);
6331 
6332  return(a_pid);
6333 }
6334 
6352 U16BIT DBDEF_GetReqdADPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *ad_mode, ADB_STREAM_TYPE *ad_type, BOOLEAN *broadcast_mix)
6353 {
6354  U16BIT ad_pid;
6355  U8BIT *db_lang_ids;
6356  ADB_STREAM_REC *selected_stream;
6357 
6358  FUNCTION_START(DBDEF_GetReqdADPid);
6359 
6360  /* Get the first primary language */
6361  db_lang_ids = DBDEF_GetAudioLang();
6362  ad_pid = GetReqdADPid(s_ptr, ad_mode, db_lang_ids, &selected_stream, broadcast_mix);
6363  if (selected_stream != NULL)
6364  {
6365  selected_stream->in_use = TRUE;
6366  *ad_type = selected_stream->type;
6367  }
6368  else
6369  {
6370  /* Check for a secondary language */
6371  if ((db_lang_ids = DBDEF_GetSecondaryAudioLang()) != NULL)
6372  {
6373  ad_pid = GetReqdADPid(s_ptr, ad_mode, db_lang_ids, &selected_stream, broadcast_mix);
6374  if (selected_stream != NULL)
6375  {
6376  selected_stream->in_use = TRUE;
6377  *ad_type = selected_stream->type;
6378  }
6379  }
6380  }
6381 
6382  FUNCTION_FINISH(DBDEF_GetReqdADPid);
6383 
6384  return(ad_pid);
6385 }
6386 
6404 E_STREAM_MATCH_TYPE DBDEF_GetReqdTtextPid(ADB_SERVICE_REC *s_ptr, BOOLEAN for_subtitles, U16BIT *pid_ptr,
6405  U8BIT *magazine, U8BIT *page)
6406 {
6407  U8BIT *db_lang_ids;
6408  BOOLEAN found_primary;
6409  E_STREAM_MATCH_TYPE match_type;
6410  ADB_STREAM_REC *selected_stream;
6411 
6412  FUNCTION_START(DBDEF_GetReqdTtextPid);
6413 
6414  found_primary = FALSE;
6415 
6416  db_lang_ids = DBDEF_GetTextLang();
6417 
6418  match_type = GetReqdTtextParams(s_ptr, pid_ptr, for_subtitles, magazine, page, db_lang_ids,
6419  &found_primary, &selected_stream);
6420 
6421  if (found_primary)
6422  {
6423  selected_stream->in_use = TRUE;
6424  }
6425  else
6426  {
6427  /* Check for a secondary language */
6428  if ((db_lang_ids = DBDEF_GetSecondaryTextLang()) != NULL)
6429  {
6430  match_type = GetReqdTtextParams(s_ptr, pid_ptr, for_subtitles, magazine, page, db_lang_ids,
6431  &found_primary, &selected_stream);
6432  if (selected_stream != NULL)
6433  {
6434  selected_stream->in_use = TRUE;
6435  }
6436  }
6437  }
6438 
6439  if ((match_type == STREAM_MATCH_NOT_ZERO) && ACFG_IsNordigCountry())
6440  {
6441  /* set match_type to STREAM_MATCH_NONE as Nordig test will not show the non-zero DVB subtitle pid
6442  if it doesn't match with the subtitle lang */
6443  match_type = STREAM_MATCH_NONE;
6444  if (selected_stream != NULL)
6445  {
6446  selected_stream->in_use = FALSE;
6447  }
6448  }
6449 
6450  FUNCTION_FINISH(DBDEF_GetReqdTtextPid);
6451 
6452  return(match_type);
6453 }
6454 
6472 E_STREAM_MATCH_TYPE DBDEF_GetReqdSubtitleParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr,
6473  U16BIT *cpage_ptr, U16BIT *apage_ptr)
6474 {
6475  U8BIT *db_lang_ids;
6476  BOOLEAN found_primary;
6477  E_STREAM_MATCH_TYPE match_type;
6478  ADB_STREAM_REC *selected_stream;
6479 
6480  FUNCTION_START(DBDEF_GetReqdSubtitleParams);
6481 
6482  found_primary = FALSE;
6483 
6484  db_lang_ids = DBDEF_GetTextLang();
6485  match_type = GetReqdSubtitleParams(s_ptr, pid_ptr, cpage_ptr, apage_ptr, db_lang_ids,
6486  &found_primary, &selected_stream);
6487 
6488  if (found_primary)
6489  {
6490  /* Mark the selected stream as in use */
6491  selected_stream->in_use = TRUE;
6492  }
6493  else
6494  {
6495  /* Check for a secondary language */
6496  if ((db_lang_ids = DBDEF_GetSecondaryTextLang()) != NULL)
6497  {
6498  match_type = GetReqdSubtitleParams(s_ptr, pid_ptr, cpage_ptr, apage_ptr, db_lang_ids,
6499  &found_primary, &selected_stream);
6500  if (selected_stream != NULL)
6501  {
6502  selected_stream->in_use = TRUE;
6503  }
6504  }
6505  }
6506 
6507  if ((match_type == STREAM_MATCH_NOT_ZERO) && ACFG_IsNordigCountry())
6508  {
6509  /* set match_type to STREAM_MATCH_NONE as Nordig test will not show the non-zero DVB subtitle pid
6510  if it doesn't match with the subtitle lang */
6511  match_type = STREAM_MATCH_NONE;
6512  if (selected_stream != NULL)
6513  {
6514  selected_stream->in_use = FALSE;
6515  }
6516  }
6517 
6518  FUNCTION_FINISH(DBDEF_GetReqdSubtitleParams);
6519 
6520  return(match_type);
6521 }
6522 
6523 /*!**************************************************************************
6524  * @brief Returns the video pid and type that should be used for the given service
6525  * from the list of video streams available. The "best one" is based on HD
6526  * being better than SD and uses the priorities from the Nordig spec.
6527  * @param s_ptr service
6528  * @param video_type pointer used to return the type of the video selected
6529  * @return Selected video PID
6530  ****************************************************************************/
6531 U16BIT DBDEF_GetReqdVideoPid(ADB_SERVICE_REC *s_ptr, ADB_STREAM_TYPE *video_type)
6532 {
6533  U16BIT video_pid;
6534  ADB_STREAM_REC *stream_rec;
6535  ADB_STREAM_REC *best_stream;
6536 
6537  FUNCTION_START(DBDEF_GetReqdVideoPid);
6538 
6539  video_pid = 0;
6540  *video_type = ADB_VIDEO_STREAM;
6541 
6542  if (s_ptr != NULL)
6543  {
6544  best_stream = NULL;
6545 
6546  stream_rec = s_ptr->stream_list;
6547  while (stream_rec != NULL)
6548  {
6549  if (IsVideoStreamType(stream_rec->type))
6550  {
6551  /* Reset the in_use flag in case the selection changes */
6552  stream_rec->in_use = FALSE;
6553 
6554  if ((best_stream == NULL || stream_rec->type > best_stream->type))
6555  {
6556  /* Don't know how to differentiate between H265 UHD, H265 HD, H265 SD, H264 HD and H264 SD at the moment,
6557  * so always select this stream because it will be better than an MPEG2 stream */
6558  best_stream = stream_rec;
6559  }
6560  }
6561 
6562  stream_rec = stream_rec->next;
6563  }
6564 
6565  if (best_stream != NULL)
6566  {
6567  video_pid = best_stream->pid;
6568  *video_type = best_stream->type;
6569  best_stream->in_use = TRUE;
6570  }
6571  }
6572 
6573  FUNCTION_FINISH(DBDEF_GetReqdVideoPid);
6574 
6575  return(video_pid);
6576 }
6577 
6586 ADB_STRING* DBDEF_GetServiceName(ADB_SERVICE_REC *s_ptr, BOOLEAN short_name, BOOLEAN pref_name)
6587 {
6588  ADB_EVENT_DESC *event_desc;
6589  ADB_STRING *name_str;
6590  U8BIT *lang_ids;
6591  U8BIT pref_name_id;
6592  U8BIT i;
6593 
6594  FUNCTION_START(DBDEF_GetServiceName);
6595 
6596  name_str = NULL;
6597 
6598  if (s_ptr != NULL)
6599  {
6600  if (pref_name)
6601  {
6602  pref_name_id = 0;
6603 
6604  if (ACFG_GetCountry() == COUNTRY_CODE_AUSTRALIA)
6605  {
6606  /* Check to see if there's a preferred name ID descriptor included in the
6607  * now event. Although this is a user defined descriptor, it isn't protected
6608  * by a private data specifier */
6609  if ((s_ptr->now_event != NULL) &&
6610  ((event_desc = DBDEF_FindEventDescriptor(s_ptr->now_event->desc_list_head,
6611  USER_DEFINED_DTAG_0x85, 0)) != NULL))
6612  {
6613  if (event_desc->desc_data[1] == 1)
6614  {
6615  pref_name_id = event_desc->desc_data[2];
6616  }
6617  }
6618  }
6619 
6620  // find required language and preferred name id
6621  lang_ids = DBDEF_GetTextLang();
6622 
6623  if (lang_ids != NULL)
6624  {
6625  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
6626  (lang_ids[i] != ACFG_INVALID_DB_LANG) && (name_str == NULL); i++)
6627  {
6628  name_str = s_ptr->name_array[lang_ids[i]][pref_name_id];
6629  }
6630 
6631  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
6632  (lang_ids[i] != ACFG_INVALID_DB_LANG) && (name_str == NULL); i++)
6633  {
6634  name_str = s_ptr->name_array[lang_ids[i]][0];
6635  }
6636  }
6637  }
6638 
6639  if (name_str == NULL)
6640  {
6641  if (short_name)
6642  {
6643  if (s_ptr->short_name_str != NULL)
6644  {
6645  name_str = s_ptr->short_name_str;
6646  }
6647 
6648  if (name_str == NULL)
6649  {
6650  /* Try to find a multilingual short name */
6651  lang_ids = DBDEF_GetTextLang();
6652 
6653  if (lang_ids != NULL)
6654  {
6655  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
6656  (lang_ids[i] != ACFG_INVALID_DB_LANG) && (name_str == NULL); i++)
6657  {
6658  name_str = s_ptr->short_name_array[lang_ids[i]];
6659  }
6660  }
6661  }
6662  }
6663 
6664  if (name_str == NULL)
6665  {
6666  /* Default to the full service name */
6667  name_str = s_ptr->name_str;
6668  }
6669  }
6670  }
6671 
6672  FUNCTION_FINISH(DBDEF_GetServiceName);
6673 
6674  return(name_str);
6675 }
6676 
6683 {
6684  ADB_STRING *name_str;
6685  U8BIT *lang_ids;
6686  U8BIT i;
6687 
6688  FUNCTION_START(DBDEF_GetServiceProviderName);
6689 
6690  name_str = NULL;
6691 
6692  if (s_ptr != NULL)
6693  {
6694  lang_ids = DBDEF_GetTextLang();
6695 
6696  if (lang_ids != NULL)
6697  {
6698  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) &&
6699  (lang_ids[i] != ACFG_INVALID_DB_LANG) && (name_str == NULL); i++)
6700  {
6701  name_str = s_ptr->provider_array[lang_ids[i]];
6702  }
6703  }
6704 
6705  if (name_str == NULL)
6706  {
6707  name_str = s_ptr->provider_str;
6708  }
6709  }
6710 
6711  FUNCTION_FINISH(DBDEF_GetServiceProviderName);
6712 
6713  return(name_str);
6714 }
6715 
6721 void DBDEF_SetServiceDeletedFlag(ADB_SERVICE_REC *s_ptr, BOOLEAN deleted)
6722 {
6723  FUNCTION_START(DBDEF_SetServiceDeletedFlag);
6724 
6725  s_ptr->deleted = deleted;
6726  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_DELETED, s_ptr->deleted);
6727 
6728  FUNCTION_FINISH(DBDEF_SetServiceDeletedFlag);
6729 }
6730 
6737 U16BIT DBDEF_GetNumDeletedServices(E_STB_DP_SIGNAL_TYPE tuner_type)
6738 {
6739  U16BIT num_services;
6740  ADB_SERVICE_REC *serv_ptr;
6741 
6742  FUNCTION_START(DBDEF_GetNumDeletedServices);
6743 
6744  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6745  for (num_services = 0; serv_ptr != NULL; )
6746  {
6747  if ((tuner_type == SIGNAL_NONE) ||
6748  ((serv_ptr->transport != NULL) && (serv_ptr->transport->sig_type == tuner_type)))
6749  {
6750  if (serv_ptr->deleted)
6751  {
6752  num_services++;
6753  }
6754  }
6755 
6756  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)serv_ptr);
6757  }
6758 
6759  FUNCTION_FINISH(DBDEF_GetNumDeletedServices);
6760 
6761  return(num_services);
6762 }
6763 
6772 U16BIT DBDEF_GetDeletedServiceList(E_STB_DP_SIGNAL_TYPE tuner_type, void ***slist_ptr)
6773 {
6774  U16BIT num_services;
6775  ADB_SERVICE_REC *serv_ptr;
6776 
6777  FUNCTION_START(DBDEF_GetDeletedServiceList);
6778 
6779  *slist_ptr = NULL;
6780 
6781  if ((num_services = DBDEF_GetNumDeletedServices(tuner_type)) != 0)
6782  {
6783  *slist_ptr = STB_AppGetMemory(num_services * sizeof(void *));
6784  if (*slist_ptr != NULL)
6785  {
6786  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetFirstBlock(&service_rec_list);
6787  for (num_services = 0; serv_ptr != NULL; )
6788  {
6789  if ((tuner_type == SIGNAL_NONE) ||
6790  ((serv_ptr->transport != NULL) && (serv_ptr->transport->sig_type == tuner_type)))
6791  {
6792  if (serv_ptr->deleted)
6793  {
6794  (*slist_ptr)[num_services] = serv_ptr;
6795  num_services++;
6796  }
6797  }
6798 
6799  serv_ptr = (ADB_SERVICE_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)serv_ptr);
6800  }
6801  }
6802  else
6803  {
6804  num_services = 0;
6805  }
6806  }
6807 
6808  FUNCTION_FINISH(DBDEF_GetDeletedServiceList);
6809 
6810  return(num_services);
6811 }
6812 
6826 {
6827  BOOLEAN retval;
6828  ADB_TRANSPORT_REC *t_ptr;
6829  ADB_SERVICE_REC *s_ptr;
6830  U32BIT freq_hz;
6831  U8BIT temp_buff[10];
6832  U16BIT chan_num;
6833  U8BIT name_len;
6834 
6835  FUNCTION_START(DBDEF_AddAnalogService);
6836 
6837  retval = FALSE;
6838 
6839  // if analogue network does not exist create it
6840  if (analog_network == NULL)
6841  {
6842  /* Add a new private network for use by the analog services */
6843  analog_network = DBDEF_FindOrAddPrivateNetwork(NULL);
6844  }
6845 
6846  if (analog_network != NULL)
6847  {
6848  /* Add transport to network - top bit set defines analog transport */
6849  freq_hz = STB_DPGetFrequency(0);
6850  t_ptr = DBDEF_AddTerrestrialTransportRec((freq_hz | 0x80000000L), 0, analog_network);
6851  if (t_ptr != NULL)
6852  {
6853  /* Setup rest of transport record */
6854  t_ptr->sig_type = SIGNAL_ANALOG;
6855  t_ptr->u.anal.freq_offset = STB_DPGetAnalogFreqOff(0);
6856  t_ptr->u.anal.vtype = STB_DPGetAnalogVideoType(0);
6857  t_ptr->tran_id = 0xffff;
6858  t_ptr->signal_level_at_search = BAD_SIGNAL_STATUS;
6859 
6860  // now add the new analogue service
6861  s_ptr = DBDEF_AddServiceRec(0, t_ptr);
6862  if (s_ptr != NULL)
6863  {
6864  s_ptr->serv_type = ADB_SERVICE_TYPE_ANALOG;
6865  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_TYPE, s_ptr->serv_type);
6866 
6867  // allocate channel number and name
6868  num_analog_channels++;
6869  chan_num = 900 + num_analog_channels;
6870  s_ptr->allocated_lcn = chan_num;
6871  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_LCN, s_ptr->allocated_lcn);
6872 
6873  name_len = snprintf((char *)temp_buff, 10, "%02d", num_analog_channels);
6874  s_ptr->name_str = DBDEF_MakeString(0, temp_buff, (name_len + 1));
6875  DBA_SetFieldString(s_ptr->dba_rec, DBA_FIELD_REC_NAME, s_ptr->name_str->str_ptr,
6876  s_ptr->name_str->nbytes);
6877 
6878  DBA_SaveRecord(s_ptr->dba_rec);
6879 
6880  // indicate success
6881  retval = TRUE;
6882  }
6883  }
6884  }
6885 
6886  FUNCTION_FINISH(DBDEF_AddAnalogService);
6887  return(retval);
6888 }
6889 
6903 void DBDEF_SetAnalogServiceName(ADB_SERVICE_REC *s_ptr, U8BIT *new_name, U8BIT new_len)
6904 {
6905  S32BIT tmp_s32bit;
6906  BOOLEAN changed;
6907 
6908  FUNCTION_START(DBDEF_SetAnalogServiceName);
6909 
6910  if (s_ptr != NULL)
6911  {
6912  // check if changed
6913  changed = TRUE;
6914  if ((s_ptr->name_str != NULL) && (new_name != NULL))
6915  {
6916  if (s_ptr->name_str->nbytes == new_len)
6917  {
6918  tmp_s32bit = memcmp(s_ptr->name_str->str_ptr, new_name, new_len);
6919  if (tmp_s32bit == 0)
6920  {
6921  changed = FALSE;
6922  }
6923  }
6924  }
6925  if (changed == TRUE)
6926  {
6927  // release old name
6928  if (s_ptr->name_str != NULL)
6929  {
6930  STB_AppFreeMemory(s_ptr->name_str);
6931  s_ptr->name_str = NULL;
6932  }
6933  // add new name
6934  if (new_name != NULL)
6935  {
6936  s_ptr->name_str = DBDEF_MakeString(0, new_name, new_len);
6937  DBA_SetFieldString(s_ptr->dba_rec, DBA_FIELD_REC_NAME, s_ptr->name_str->str_ptr,
6938  s_ptr->name_str->nbytes);
6939  DBA_SaveRecord(s_ptr->dba_rec);
6940  }
6941  }
6942  }
6943 
6944  FUNCTION_FINISH(DBDEF_SetAnalogServiceName);
6945 }
6946 
6959 void DBDEF_SetServicePmtPid(ADB_SERVICE_REC *s_ptr, U16BIT pmt_pid)
6960 {
6961  FUNCTION_START(DBDEF_SetServicePmtPid);
6962  if (s_ptr != NULL)
6963  {
6964  s_ptr->pmt_pid = pmt_pid;
6965  }
6966  FUNCTION_FINISH(DBDEF_SetServicePmtPid);
6967 }
6968 
6981 {
6982  U16BIT pmt_pid = 0;
6983 
6984  FUNCTION_START(DBDEF_GetServicePmtPid);
6985 
6986  if (s_ptr != NULL)
6987  {
6988  pmt_pid = s_ptr->pmt_pid;
6989  }
6990 
6991  FUNCTION_FINISH(DBDEF_GetServicePmtPid);
6992 
6993  return pmt_pid;
6994 }
6995 
7001 void DBDEF_SetServiceFavGroups(ADB_SERVICE_REC *s_ptr, U8BIT groups)
7002 {
7003  FUNCTION_START(DBDEF_SetServiceFavGroups);
7004 
7005  if (s_ptr != NULL)
7006  {
7007  s_ptr->fav_groups = groups;
7008  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_FAV_GROUPS, s_ptr->fav_groups);
7009  }
7010 
7011  FUNCTION_FINISH(DBDEF_SetServiceFavGroups);
7012 }
7013 
7018 {
7019  FUNCTION_START(DBDEF_SortServicesByLcn);
7020  STB_LLSort(&service_rec_list, LcnSortCompareFunc);
7021  FUNCTION_FINISH(DBDEF_SortServicesByLcn);
7022 }
7023 
7038 BOOLEAN DBDEF_AllocateLcns(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN assign_lcns)
7039 {
7040  U32BIT country_code;
7041  AllocLcnFunc func_ptr;
7042  BOOLEAN duplicate_lcn_found;
7043  ADB_SERVICE_REC *s_ptr;
7044 
7045  FUNCTION_START(DBDEF_AllocateLcns);
7046 
7047  /* Call the appropriate function for the country and type of tuner */
7048  country_code = ACFG_GetCountry();
7049 
7050  switch (tuner_type)
7051  {
7052  case SIGNAL_COFDM:
7053  func_ptr = ACFG_GetTerrestrialLcnFunction(country_code);
7054  break;
7055 
7056  case SIGNAL_QAM:
7057  func_ptr = ACFG_GetCableLcnFunction(country_code);
7058  break;
7059 
7060  case SIGNAL_QPSK:
7061  func_ptr = ACFG_GetSatelliteLcnFunction(country_code);
7062  break;
7063 
7064  default:
7065  func_ptr = NULL;
7066  break;
7067  }
7068 
7069  if (func_ptr != NULL)
7070  {
7071  duplicate_lcn_found = func_ptr(tuner_type);
7072 
7073  if (assign_lcns)
7074  {
7075  /* Now go through all services looking for allocated LCNs that have changed */
7076  s_ptr = DBDEF_GetNextServiceRec(NULL);
7077  while (s_ptr != NULL)
7078  {
7079  if (s_ptr->allocated_lcn != s_ptr->old_allocated_lcn)
7080  {
7081  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_LCN, s_ptr->allocated_lcn);
7082  DBA_SaveRecord(s_ptr->dba_rec);
7083  }
7084  s_ptr = DBDEF_GetNextServiceRec(s_ptr);
7085  }
7086  }
7087  else
7088  {
7089  /* Clear the LCN assigned to each service */
7090  s_ptr = DBDEF_GetNextServiceRec(NULL);
7091  while (s_ptr != NULL)
7092  {
7093  s_ptr->allocated_lcn = 0;
7094  s_ptr = DBDEF_GetNextServiceRec(s_ptr);
7095  }
7096  }
7097  }
7098  else
7099  {
7100  duplicate_lcn_found = FALSE;
7101  }
7102 
7103  FUNCTION_FINISH(DBDEF_AllocateLcns);
7104 
7105  return(duplicate_lcn_found);
7106 }
7107 
7108 BOOLEAN DBDEF_AllocateLcnsDefault(E_STB_DP_SIGNAL_TYPE tuner_type)
7109 {
7110  ADB_SERVICE_REC *s1_ptr;
7111  ADB_SERVICE_REC *s2_ptr;
7112  ADB_TRANSPORT_REC *t_ptr;
7113  U16BIT first_unallocated_lcn;
7114  U16BIT next_allocated_lcn;
7115  U16BIT last_allocated_lcn;
7116  U16BIT s1_strength;
7117  U16BIT s2_strength;
7118  BOOLEAN duplicate_lcn_found;
7119 
7120  FUNCTION_START(DBDEF_AllocateLcnsDefault);
7121 
7122  // determine next available special number and save last allocated number
7123  first_unallocated_lcn = ACFG_GetFirstUnallocatedLcn(ACFG_GetCountry(), tuner_type);
7124  next_allocated_lcn = first_unallocated_lcn;
7125  last_allocated_lcn = ACFG_GetLastUnallocatedLcn(ACFG_GetCountry(), tuner_type);
7126 
7127  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7128  while (s1_ptr != NULL)
7129  {
7130  s1_ptr->old_allocated_lcn = s1_ptr->allocated_lcn;
7131  if ((s1_ptr->allocated_lcn >= next_allocated_lcn) && (s1_ptr->allocated_lcn < last_allocated_lcn))
7132  {
7133  next_allocated_lcn = s1_ptr->allocated_lcn + 1;
7134  }
7135  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7136  }
7137 
7138  duplicate_lcn_found = FALSE;
7139 
7140  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7141  while (s1_ptr != NULL)
7142  {
7143  // if allocated_lcn has not already been set
7144  if (s1_ptr->serv_lcn == 0)
7145  {
7146  /* Only allocate an lcn if one hasn't already been allocated */
7147  if (s1_ptr->allocated_lcn == 0)
7148  {
7149  // invalid lcn - allocate one
7150  s1_ptr->allocated_lcn = next_allocated_lcn;
7151  next_allocated_lcn++;
7152  }
7153  }
7154  else if ((s1_ptr->allocated_lcn == 0) || (s1_ptr->allocated_lcn >= first_unallocated_lcn))
7155  {
7156  // valid lcn supplied - check for duplicates....
7157 
7158  //initialise allocated lcn for this service to the broadcast value - it may be changed
7159  // later
7160  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7161 
7162  // find strength of this service
7163  s1_strength = 0;
7164 
7165  t_ptr = s1_ptr->transport;
7166  if (t_ptr != NULL)
7167  {
7168  s1_strength = t_ptr->signal_level_at_search;
7169  }
7170 
7171  // for all services in the list check for the same lcn number.
7172  // If a duplicate is found check the comparative strengths of the signal. The strongest
7173  // keeps the proper number, the weakest has a number allocated from the range defined
7174  // for this country onwards.
7175  s2_ptr = DBDEF_GetNextServiceRec(NULL);
7176  while (s2_ptr != NULL)
7177  {
7178  if ((s1_ptr->serv_lcn == s2_ptr->serv_lcn) && (s1_ptr != s2_ptr))
7179  {
7180  duplicate_lcn_found = TRUE;
7181 
7182  /* Decide which service should be assigned its desired LCN based on signal strength */
7183  s2_strength = 0;
7184  t_ptr = s2_ptr->transport;
7185  if (t_ptr != NULL)
7186  {
7187  s2_strength = t_ptr->signal_level_at_search;
7188  }
7189 
7190  if (s1_strength < s2_strength)
7191  {
7192  // s1 is weaker - change s1 lcn and break out of this loop, no need to look at
7193  // more s2 services
7194  s1_ptr->allocated_lcn = next_allocated_lcn;
7195  next_allocated_lcn++;
7196  break;
7197  }
7198  else
7199  {
7200  // s1 is stronger, but has s2 already been allocated the proper lcn
7201  if (s2_ptr->allocated_lcn == s2_ptr->serv_lcn)
7202  {
7203  if (s2_ptr->unavailable == FALSE)
7204  {
7205  // s2 has the lcn - for the moment leave it there and give s1 an allocated
7206  // lcn. Later we will check whether to transfer the lcn and the favourites
7207  // etc
7208  s1_ptr->allocated_lcn = next_allocated_lcn;
7209  next_allocated_lcn++;
7210  break;
7211  }
7212  else
7213  {
7214  // s2 is unavailable so make it relinquish its lcn and allocate it a new
7215  // one
7216  s2_ptr->allocated_lcn = next_allocated_lcn;
7217  next_allocated_lcn++;
7218  }
7219  }
7220  }
7221  }
7222  s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7223  }
7224  }
7225  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7226  }
7227 
7228  FUNCTION_FINISH(DBDEF_AllocateLcnsDefault);
7229 
7230  return(duplicate_lcn_found);
7231 }
7232 
7233 #ifdef COUNTRY_UK
7234 BOOLEAN DBDEF_AllocateLcnsUK(E_STB_DP_SIGNAL_TYPE tuner_type)
7235 {
7236  ADB_SERVICE_REC *s1_ptr, *next_s1_ptr;
7237  ADB_SERVICE_REC *s2_ptr, *next_s2_ptr;
7238  ADB_TRANSPORT_REC *t_ptr;
7239  U16BIT next_allocated_lcn;
7240  U16BIT first_unallocated_lcn, reqd_lcn;
7241  U16BIT s1_strength;
7242  U16BIT s2_strength;
7243  BOOLEAN duplicate_lcn_found;
7244  BOOLEAN lcn_assigned, visible;
7245  S16BIT onid1, onid2;
7246 
7247  FUNCTION_START(DBDEF_AllocateLcnsUK);
7248 
7249  /* Get the first and next LCN to be allocated to a service that isn't assigned one */
7250  first_unallocated_lcn = ACFG_GetFirstUnallocatedLcn(ACFG_GetCountry(), tuner_type);
7251  next_allocated_lcn = first_unallocated_lcn;
7252  duplicate_lcn_found = FALSE;
7253 
7254  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7255  while (s1_ptr != NULL)
7256  {
7257  next_s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7258  // if allocated_lcn has not already been set
7259  if (s1_ptr->serv_lcn == 0)
7260  {
7261  /* Only allocate an lcn if one hasn't already been allocated, or the service is using
7262  * an LCN in the unallocated range */
7263  if ((s1_ptr->allocated_lcn == 0) || (s1_ptr->allocated_lcn >= first_unallocated_lcn))
7264  {
7265  s1_ptr->allocated_lcn = next_allocated_lcn;
7266  next_allocated_lcn++;
7267  }
7268  }
7269  else if ((s1_ptr->allocated_lcn == 0) || (s1_ptr->allocated_lcn >= first_unallocated_lcn))
7270  {
7271  // valid lcn supplied - check for duplicates....
7272 
7273  //initialise allocated lcn for this service to the broadcast value - it may be changed
7274  // later
7275  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7276 
7277  // find strength of this service
7278  s1_strength = 0;
7279 
7280  t_ptr = s1_ptr->transport;
7281  if (t_ptr != NULL)
7282  {
7283  s1_strength = t_ptr->signal_level_at_search;
7284  }
7285 
7286  // for all services in the list check for the same lcn number.
7287  // If a duplicate is found check the comparative strengths of the signal. The strongest
7288  // keeps the proper number, the weakest has a number allocated from the range defined
7289  // for this country onwards.
7290  s2_ptr = DBDEF_GetNextServiceRec(NULL);
7291  while (s2_ptr != NULL)
7292  {
7293  next_s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7294  if ((s1_ptr->serv_lcn == s2_ptr->serv_lcn) && (s1_ptr != s2_ptr))
7295  {
7296  duplicate_lcn_found = TRUE;
7297  lcn_assigned = FALSE;
7298 
7299  if (tuner_type == SIGNAL_COFDM)
7300  {
7301  if (!ApplyTargetRegionRules(s1_ptr, s2_ptr, &next_allocated_lcn, &lcn_assigned))
7302  {
7303  break;
7304  }
7305 
7306  if (lcn_assigned == TRUE)
7307  {
7308  onid1 = -1;
7309  onid2 = -1;
7310  if (s1_ptr->transport != NULL)
7311  {
7312  onid1 = s1_ptr->transport->orig_net_id;
7313  }
7314  if (s2_ptr->transport != NULL)
7315  {
7316  onid2 = s2_ptr->transport->orig_net_id;
7317  }
7318 
7319  if ((s1_ptr->serv_id == s2_ptr->serv_id) && (onid1 == onid2) && (onid1 != -1))
7320  {
7321  /* Services are identical, delete the service outside the user's region */
7322  if (s1_ptr->allocated_lcn >= first_unallocated_lcn)
7323  {
7324  DBDEF_DeleteServiceRec(s1_ptr);
7325  }
7326  else if (s2_ptr->allocated_lcn >= first_unallocated_lcn)
7327  {
7328  if (s2_ptr == next_s1_ptr)
7329  {
7330  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
7331  }
7332  DBDEF_DeleteServiceRec(s2_ptr);
7333  }
7334  }
7335  }
7336  }
7337 
7338  if (!lcn_assigned)
7339  {
7340  /* Decide which service should be assigned its desired LCN based on signal strength */
7341  s2_strength = 0;
7342  t_ptr = s2_ptr->transport;
7343  if (t_ptr != NULL)
7344  {
7345  s2_strength = t_ptr->signal_level_at_search;
7346  }
7347 
7348  if (s1_strength < s2_strength)
7349  {
7350  // s1 is weaker - change s1 lcn and break out of this loop, no need to look at
7351  // more s2 services
7352  s1_ptr->allocated_lcn = next_allocated_lcn;
7353  next_allocated_lcn++;
7354  break;
7355  }
7356  else
7357  {
7358  // s1 is stronger, but has s2 already been allocated the proper lcn
7359  if (s2_ptr->allocated_lcn == s2_ptr->serv_lcn)
7360  {
7361  if (s2_ptr->unavailable == FALSE)
7362  {
7363  // s2 has the lcn - for the moment leave it there and give s1 an allocated
7364  // lcn. Later we will check whether to transfer the lcn and the favourites
7365  // etc
7366  s1_ptr->allocated_lcn = next_allocated_lcn;
7367  next_allocated_lcn++;
7368  break;
7369  }
7370  else
7371  {
7372  // s2 is unavailable so make it relinquish its lcn and allocate it a new
7373  // one
7374  s2_ptr->allocated_lcn = next_allocated_lcn;
7375  next_allocated_lcn++;
7376  }
7377  }
7378  }
7379  }
7380  }
7381  s2_ptr = next_s2_ptr;
7382  }
7383  }
7384  s1_ptr = next_s1_ptr;
7385  }
7386 
7387  /* Now apply the HD LCN descriptor, if present and applicable */
7388  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7389  while (s1_ptr != NULL)
7390  {
7391  if ((s1_ptr->allocated_lcn < first_unallocated_lcn) && (s1_ptr->hd_lcn_desc != NULL))
7392  {
7393  reqd_lcn = s1_ptr->hd_lcn_desc->serv_lcn;
7394  if (reqd_lcn != s1_ptr->serv_lcn)
7395  {
7396  s2_ptr = DBDEF_GetNextServiceRec(NULL);
7397  while (s2_ptr != NULL)
7398  {
7399  if (reqd_lcn == s2_ptr->serv_lcn)
7400  {
7401  /* This service is being replaced in the LCN lineup. Give this service
7402  * the LCN originally assigned to the one replacing it. */
7403  s2_ptr->old_allocated_lcn = s2_ptr->allocated_lcn;
7404  s2_ptr->allocated_lcn = s1_ptr->allocated_lcn;
7405  break;
7406  }
7407  s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7408  }
7409 
7410  s1_ptr->old_allocated_lcn = s1_ptr->allocated_lcn;
7411  s1_ptr->allocated_lcn = reqd_lcn;
7412  }
7413 
7414  /* See if the service's attributes should be changed */
7415  visible = !s1_ptr->hidden;
7416  if (s1_ptr->hd_lcn_desc->visible != visible)
7417  {
7418  if (s1_ptr->hd_lcn_desc->visible)
7419  {
7420  s1_ptr->hidden = FALSE;
7421  DBA_SetFieldValue(s1_ptr->dba_rec, DBA_FIELD_SERV_HIDDEN, FALSE);
7422  }
7423  else
7424  {
7425  s1_ptr->hidden = TRUE;
7426  DBA_SetFieldValue(s1_ptr->dba_rec, DBA_FIELD_SERV_HIDDEN, TRUE);
7427  }
7428  }
7429 
7430  /* The description for the HD simulcast LCN descriptor in the DBook states that
7431  * whether the service is visible or hidden it is always selectable */
7432  s1_ptr->selectable = TRUE;
7433  DBA_SetFieldValue(s1_ptr->dba_rec, DBA_FIELD_SERV_SELECTABLE, TRUE);
7434 
7435  DBA_SaveRecord(s1_ptr->dba_rec);
7436  }
7437  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7438  }
7439 
7440  FUNCTION_FINISH(DBDEF_AllocateLcnsUK);
7441 
7442  return(duplicate_lcn_found);
7443 }
7444 
7445 #endif /* COUNTRY_UK */
7446 
7447 #ifdef COUNTRY_FINLAND
7448 BOOLEAN DBDEF_AllocateLcnsFinland(E_STB_DP_SIGNAL_TYPE tuner_type)
7449 {
7450  ADB_SERVICE_REC *s1_ptr;
7451  ADB_SERVICE_REC *s2_ptr;
7452  ADB_TRANSPORT_REC *t_ptr;
7453  U16BIT next_allocated_lcn;
7454  U16BIT last_allocated_lcn;
7455  U16BIT s1_strength;
7456  U16BIT s2_strength;
7457  BOOLEAN duplicate_lcn_found;
7458  BOOLEAN lcn_assigned;
7459 
7460  FUNCTION_START(DBDEF_AllocateLcnsFinland);
7461 
7462  /* to find the first special lcn number, for Nordig, it sets to the number after the largest lcn of
7463  the services transmitted by its own country's orignal network */
7464  next_allocated_lcn = FindLargestLcnNumber(tuner_type, FINLAND_ONID) + 1;
7465  last_allocated_lcn = ACFG_GetLastUnallocatedLcn(ACFG_GetCountry(), tuner_type);
7466 
7467  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7468  while (s1_ptr != NULL)
7469  {
7470  s1_ptr->old_allocated_lcn = s1_ptr->allocated_lcn;
7471 
7472  /* if the channels got from other original network which is outside the country, reset the lcn
7473  so that the lcn will not keep increasing on manual tune or update */
7474  if (s1_ptr->transport->orig_net_id != FINLAND_ONID)
7475  {
7476  s1_ptr->allocated_lcn = 0;
7477  }
7478  if ((s1_ptr->allocated_lcn >= next_allocated_lcn) && (s1_ptr->allocated_lcn < last_allocated_lcn))
7479  {
7480  next_allocated_lcn = s1_ptr->allocated_lcn + 1;
7481  }
7482  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7483  }
7484 
7485  duplicate_lcn_found = FALSE;
7486 
7487  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7488  while (s1_ptr != NULL)
7489  {
7490  // if allocated_lcn has not already been set
7491  if (s1_ptr->serv_lcn == 0)
7492  {
7493  /* Allocate the next available LCN to the service */
7494  s1_ptr->allocated_lcn = next_allocated_lcn;
7495  next_allocated_lcn++;
7496  }
7497  else if (s1_ptr->allocated_lcn == 0)
7498  {
7499  // valid lcn supplied - check for duplicates....
7500 
7501  //initialise allocated lcn for this service to the broadcast value - it may be changed
7502  // later
7503  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7504 
7505  // find strength of this service
7506  s1_strength = 0;
7507  t_ptr = s1_ptr->transport;
7508 
7509  if (t_ptr != NULL)
7510  {
7511  if (tuner_type == SIGNAL_COFDM)
7512  {
7513  /* If the orginal network id is not for Finland when the country was set to Finland
7514  * it means that the service we got is from another country's network.
7515  * Set the lcn of the service to next allocated lcn */
7516  if (t_ptr->orig_net_id != FINLAND_ONID)
7517  {
7518  s1_ptr->allocated_lcn = next_allocated_lcn;
7519  next_allocated_lcn++;
7520  }
7521  }
7522 
7523  s1_strength = t_ptr->signal_level_at_search;
7524  }
7525 
7526  // for all services in the list check for the same lcn number.
7527  // If a duplicate is found check the comparative strengths of the signal. The strongest
7528  // keeps the proper number, the weakest has a number allocated from the range defined
7529  // for this country onwards.
7530  s2_ptr = DBDEF_GetNextServiceRec(NULL);
7531  while (s2_ptr != NULL)
7532  {
7533  if ((s1_ptr->serv_lcn == s2_ptr->serv_lcn) && (s1_ptr != s2_ptr))
7534  {
7535  /* Two services from different networks are allowed to have the same LCN */
7536  if ((s1_ptr->transport->orig_net_id) == (s2_ptr->transport->orig_net_id))
7537  {
7538  duplicate_lcn_found = TRUE;
7539  lcn_assigned = FALSE;
7540 
7541  /* Check for a HD service on service 2 */
7542  /* for Nordig, if the lcn number of two services are identical and the service type is different,
7543  then each service should get its signaled lcn. */
7544  switch (s2_ptr->serv_type)
7545  {
7546  case ADB_SERVICE_TYPE_AVC_SD_TV:
7547  case ADB_SERVICE_TYPE_HD_TV:
7548  case ADB_SERVICE_TYPE_MPEG2_HD:
7549  case ADB_SERVICE_TYPE_UHD_TV:
7550  {
7551  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7552  /* If there is and service 1 is an SD then allocate service 1 at next allocated lcn */
7553  if (s1_ptr->serv_type == ADB_SERVICE_TYPE_TV)
7554  {
7555  s1_ptr->allocated_lcn = next_allocated_lcn;
7556  next_allocated_lcn++;
7557  lcn_assigned = TRUE;
7558  }
7559  else if ((s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_RADIO) ||
7560  (s1_ptr->serv_type == ADB_SERVICE_TYPE_RADIO) ||
7561  (s1_ptr->serv_type == ADB_SERVICE_TYPE_DATA))
7562  {
7563  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7564  lcn_assigned = TRUE;
7565  }
7566  break;
7567  }
7568  case ADB_SERVICE_TYPE_AVC_RADIO:
7569  {
7570  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7571  if (s1_ptr->serv_type == ADB_SERVICE_TYPE_RADIO)
7572  {
7573  s1_ptr->allocated_lcn = next_allocated_lcn;
7574  next_allocated_lcn++;
7575  lcn_assigned = TRUE;
7576  }
7577  else if (s1_ptr->serv_type == ADB_SERVICE_TYPE_DATA)
7578  {
7579  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7580  lcn_assigned = TRUE;
7581  }
7582  break;
7583  }
7584  case ADB_SERVICE_TYPE_TV:
7585  {
7586  if ((s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_RADIO) ||
7587  (s1_ptr->serv_type == ADB_SERVICE_TYPE_RADIO) ||
7588  (s1_ptr->serv_type == ADB_SERVICE_TYPE_DATA))
7589  {
7590  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7591  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7592  lcn_assigned = TRUE;
7593  }
7594  else if ((s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_SD_TV) ||
7595  (s1_ptr->serv_type == ADB_SERVICE_TYPE_HD_TV) ||
7596  (s1_ptr->serv_type == ADB_SERVICE_TYPE_MPEG2_HD) ||
7597  (s1_ptr->serv_type == ADB_SERVICE_TYPE_UHD_TV))
7598  {
7599  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7600  s2_ptr->allocated_lcn = next_allocated_lcn;
7601  next_allocated_lcn++;
7602  lcn_assigned = TRUE;
7603  }
7604  break;
7605  }
7606  case ADB_SERVICE_TYPE_RADIO:
7607  {
7608  if ((s1_ptr->serv_type == ADB_SERVICE_TYPE_TV) ||
7609  (s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_SD_TV) ||
7610  (s1_ptr->serv_type == ADB_SERVICE_TYPE_HD_TV) ||
7611  (s1_ptr->serv_type == ADB_SERVICE_TYPE_DATA) ||
7612  (s1_ptr->serv_type == ADB_SERVICE_TYPE_MPEG2_HD) ||
7613  (s1_ptr->serv_type == ADB_SERVICE_TYPE_UHD_TV))
7614  {
7615  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7616  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7617  lcn_assigned = TRUE;
7618  }
7619  else if (s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_RADIO)
7620  {
7621  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7622  s2_ptr->allocated_lcn = next_allocated_lcn;
7623  next_allocated_lcn++;
7624  lcn_assigned = TRUE;
7625  }
7626  break;
7627  }
7628  default:
7629  {
7630  if (s1_ptr->serv_type != ADB_SERVICE_TYPE_DATA)
7631  {
7632  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7633  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7634  lcn_assigned = TRUE;
7635  }
7636  break;
7637  }
7638  }
7639 
7640  if (!lcn_assigned)
7641  {
7642  /* Decide which service should be assigned its desired LCN based on signal strength */
7643  s2_strength = 0;
7644  t_ptr = s2_ptr->transport;
7645  if (t_ptr != NULL)
7646  {
7647  s2_strength = t_ptr->signal_level_at_search;
7648  }
7649 
7650  if (s1_strength < s2_strength)
7651  {
7652  // s1 is weaker - change s1 lcn and break out of this loop, no need to look at
7653  // more s2 services
7654  s1_ptr->allocated_lcn = next_allocated_lcn;
7655  next_allocated_lcn++;
7656  break;
7657  }
7658  else
7659  {
7660  // s1 is stronger, but has s2 already been allocated the proper lcn
7661  if (s2_ptr->allocated_lcn == s2_ptr->serv_lcn)
7662  {
7663  if (s2_ptr->unavailable == FALSE)
7664  {
7665  // s2 has the lcn - for the moment leave it there and give s1 an allocated
7666  // lcn. Later we will check whether to transfer the lcn and the favourites
7667  // etc
7668  s1_ptr->allocated_lcn = next_allocated_lcn;
7669  next_allocated_lcn++;
7670  break;
7671  }
7672  else
7673  {
7674  // s2 is unavailable so make it relinquish its lcn and allocate it a new
7675  // one
7676  s2_ptr->allocated_lcn = next_allocated_lcn;
7677  next_allocated_lcn++;
7678  }
7679  }
7680  }
7681  }
7682  }
7683  }
7684  s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7685  }
7686  }
7687 
7688  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7689  }
7690 
7691  FUNCTION_FINISH(DBDEF_AllocateLcnsFinland);
7692 
7693  return(duplicate_lcn_found);
7694 }
7695 
7696 #endif /* COUNTRY_FINLAND */
7697 
7698 #ifdef COUNTRY_IRELAND
7699 BOOLEAN DBDEF_AllocateLcnsIreland(E_STB_DP_SIGNAL_TYPE tuner_type)
7700 {
7701  ADB_SERVICE_REC *s1_ptr;
7702  ADB_SERVICE_REC *s2_ptr;
7703  ADB_TRANSPORT_REC *t_ptr;
7704  U16BIT next_allocated_lcn;
7705  U16BIT last_allocated_lcn;
7706  U16BIT s1_strength;
7707  U16BIT s2_strength;
7708  BOOLEAN duplicate_lcn_found;
7709  BOOLEAN lcn_assigned;
7710 
7711  FUNCTION_START(DBDEF_AllocateLcnsIreland);
7712 
7713  /* Find the current largest LCN assigned to services on the Irish network, which will then be
7714  * used as the first LCN to assign to services without an LCN or are on a different network */
7715  next_allocated_lcn = FindLargestLcnNumber(tuner_type, IRELAND_ONID) + 1;
7716  last_allocated_lcn = ACFG_GetLastUnallocatedLcn(ACFG_GetCountry(), tuner_type);
7717 
7718  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7719  while (s1_ptr != NULL)
7720  {
7721  if ((s1_ptr->transport != NULL) && (s1_ptr->transport->sig_type == tuner_type))
7722  {
7723  s1_ptr->old_allocated_lcn = s1_ptr->allocated_lcn;
7724 
7725  /* If the service isn't from the Irish network then reset its allocated LCN
7726  * so it can be reassigned */
7727  if (s1_ptr->transport->orig_net_id != IRELAND_ONID)
7728  {
7729  s1_ptr->allocated_lcn = 0;
7730  }
7731 
7732  if ((s1_ptr->allocated_lcn >= next_allocated_lcn) && (s1_ptr->allocated_lcn < last_allocated_lcn))
7733  {
7734  next_allocated_lcn = s1_ptr->allocated_lcn + 1;
7735  }
7736  }
7737 
7738  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7739  }
7740 
7741  /* The Irish services must be assigned their requested LCNs, with services from other networks,
7742  * which in this case will be the UK, being assigned LCNs above the largest used Irish LCN, so
7743  * all Irish services are assigned LCNs first. */
7744  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7745  while (s1_ptr != NULL)
7746  {
7747  t_ptr = s1_ptr->transport;
7748  if ((t_ptr != NULL) && (t_ptr->sig_type == tuner_type))
7749  {
7750  if ((s1_ptr->allocated_lcn == 0) && (s1_ptr->selectable || !s1_ptr->hidden))
7751  {
7752  s1_strength = 0;
7753 
7754  if (t_ptr->orig_net_id == IRELAND_ONID)
7755  {
7756  /* Set the LCN it wants, but this may be changed */
7757  if (s1_ptr->serv_lcn != 0)
7758  {
7759  s1_ptr->allocated_lcn = s1_ptr->serv_lcn;
7760  }
7761  else
7762  {
7763  s1_ptr->allocated_lcn = next_allocated_lcn;
7764  next_allocated_lcn++;
7765  }
7766 
7767  s1_strength = t_ptr->signal_level_at_search;
7768 
7769  /* Check for duplicate LCNs for Irish services, and if one is found then the assigned
7770  * LCN is based on the service type followed by the signal strength of the two services */
7771  s2_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7772  while (s2_ptr != NULL)
7773  {
7774  t_ptr = s2_ptr->transport;
7775 
7776  if ((t_ptr != NULL) && (t_ptr->sig_type == tuner_type))
7777  {
7778  if ((s1_ptr->serv_lcn == s2_ptr->serv_lcn) &&
7779  (t_ptr->orig_net_id == IRELAND_ONID) &&
7780  (s1_ptr->transport->orig_net_id) == (t_ptr->orig_net_id))
7781  {
7782  duplicate_lcn_found = TRUE;
7783  lcn_assigned = FALSE;
7784 
7785  /* For LCN clashes, advanced codec services take priority over SD quality services */
7786  switch (s2_ptr->serv_type)
7787  {
7788  case ADB_SERVICE_TYPE_AVC_SD_TV:
7789  case ADB_SERVICE_TYPE_HD_TV:
7790  case ADB_SERVICE_TYPE_MPEG2_HD:
7791  case ADB_SERVICE_TYPE_UHD_TV:
7792  {
7793  /* If the first service is also an advanced codec service then the
7794  * service that gets the LCN will be based on signal strength */
7795  if ((s1_ptr->serv_type != ADB_SERVICE_TYPE_AVC_SD_TV) &&
7796  (s1_ptr->serv_type != ADB_SERVICE_TYPE_HD_TV) &&
7797  (s1_ptr->serv_type != ADB_SERVICE_TYPE_MPEG2_HD) &&
7798  (s1_ptr->serv_type != ADB_SERVICE_TYPE_UHD_TV))
7799  {
7800  /* Advanced codec service takes the LCN,
7801  * so assign a new one to the first service */
7802  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7803  s1_ptr->allocated_lcn = next_allocated_lcn;
7804  next_allocated_lcn++;
7805  lcn_assigned = TRUE;
7806  }
7807  break;
7808  }
7809  case ADB_SERVICE_TYPE_AVC_RADIO:
7810  {
7811  if (s1_ptr->serv_type != ADB_SERVICE_TYPE_AVC_RADIO)
7812  {
7813  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7814  s1_ptr->allocated_lcn = next_allocated_lcn;
7815  next_allocated_lcn++;
7816  lcn_assigned = TRUE;
7817  }
7818  break;
7819  }
7820  case ADB_SERVICE_TYPE_TV:
7821  {
7822  if ((s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_SD_TV) ||
7823  (s1_ptr->serv_type == ADB_SERVICE_TYPE_HD_TV) ||
7824  (s1_ptr->serv_type == ADB_SERVICE_TYPE_MPEG2_HD) ||
7825  (s1_ptr->serv_type == ADB_SERVICE_TYPE_UHD_TV))
7826  {
7827  /* First service keeps the LCN because it's an advanced codec service */
7828  s2_ptr->allocated_lcn = next_allocated_lcn;
7829  next_allocated_lcn++;
7830  lcn_assigned = TRUE;
7831  }
7832  break;
7833  }
7834  case ADB_SERVICE_TYPE_RADIO:
7835  {
7836  if (s1_ptr->serv_type == ADB_SERVICE_TYPE_AVC_RADIO)
7837  {
7838  /* First service keeps the LCN because it's an advanced codec service */
7839  s2_ptr->allocated_lcn = next_allocated_lcn;
7840  next_allocated_lcn++;
7841  lcn_assigned = TRUE;
7842  }
7843  break;
7844  }
7845  default:
7846  {
7847  break;
7848  }
7849  }
7850 
7851  if (!lcn_assigned)
7852  {
7853  /* Decide which service should be assigned its desired LCN based on signal strength */
7854  s2_strength = t_ptr->signal_level_at_search;
7855 
7856  if (s1_strength < s2_strength)
7857  {
7858  /* s1 is weaker so assign the LCN to s2 */
7859  s2_ptr->allocated_lcn = s2_ptr->serv_lcn;
7860  s1_ptr->allocated_lcn = next_allocated_lcn;
7861  next_allocated_lcn++;
7862  }
7863  else
7864  {
7865  /* s1 is stronger so assign an LCN to s2 */
7866  s2_ptr->allocated_lcn = next_allocated_lcn;
7867  next_allocated_lcn++;
7868  }
7869  }
7870  }
7871  }
7872 
7873  s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7874  }
7875  }
7876  }
7877  }
7878 
7879  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7880  }
7881 
7882  /* The next allocated LCN will be the next one to be used, but this will now be used as an
7883  * offset, so set it to the highest assigned LCN, which is one less than the current value */
7884  if (next_allocated_lcn != 0)
7885  {
7886  next_allocated_lcn--;
7887  }
7888 
7889  /* Now assigned LCNs to all non-Irish services. It is recommended to keep the relative LCN
7890  * order of services on other networks, so all services that have requested an LCN are assigned
7891  * first, followed by all those that haven't, which ensures that these services end up at the
7892  * end of the list */
7893  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7894  while (s1_ptr != NULL)
7895  {
7896  t_ptr = s1_ptr->transport;
7897  if ((t_ptr != NULL) && (t_ptr->sig_type == tuner_type))
7898  {
7899  if ((s1_ptr->serv_lcn != 0) && (s1_ptr->allocated_lcn == 0))
7900  {
7901  if (t_ptr->orig_net_id != IRELAND_ONID)
7902  {
7903  /* Check that this LCN hasn't already been assigned to a service */
7904  if (DBDEF_FindServiceRecByLcn(s1_ptr->serv_lcn + next_allocated_lcn, NULL, TRUE) == NULL)
7905  {
7906  s1_ptr->allocated_lcn = s1_ptr->serv_lcn + next_allocated_lcn;
7907 
7908  s1_strength = t_ptr->signal_level_at_search;
7909 
7910  /* Check for duplicate LCNs and if one is found then check the signal strength of the two
7911  * services. The strongest keeps the LCN and the weakest is allocated another LCN */
7912  s2_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7913  while (s2_ptr != NULL)
7914  {
7915  if ((s2_ptr->serv_lcn != 0) && (s1_ptr->serv_lcn == s2_ptr->serv_lcn) &&
7916  (s2_ptr->selectable || !s2_ptr->hidden) &&
7917  (s2_ptr->transport != NULL) &&
7918  (s1_ptr->transport->orig_net_id) == (s2_ptr->transport->orig_net_id))
7919  {
7920  duplicate_lcn_found = TRUE;
7921 
7922  /* Decide which service should be assigned its desired LCN based on signal strength */
7923  s2_strength = s2_ptr->transport->signal_level_at_search;
7924 
7925  if (s1_strength < s2_strength)
7926  {
7927  /* s2 has a stronger signal so assign it the LCN and clear the LCN from s1
7928  * so it will be assigned an LCN later */
7929  s2_ptr->allocated_lcn = s1_ptr->allocated_lcn;
7930  s1_ptr->allocated_lcn = 0;
7931  }
7932  }
7933 
7934  s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
7935  }
7936  }
7937  }
7938  }
7939  }
7940 
7941  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7942  }
7943 
7944  /* Find the largest allocated LCN, which will be used for all remaining services */
7945  next_allocated_lcn = 0;
7946 
7947  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7948  while (s1_ptr != NULL)
7949  {
7950  if ((s1_ptr->transport != NULL) && (s1_ptr->transport->sig_type == tuner_type))
7951  {
7952  if (s1_ptr->allocated_lcn >= next_allocated_lcn)
7953  {
7954  next_allocated_lcn = s1_ptr->allocated_lcn + 1;
7955  }
7956  }
7957 
7958  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7959  }
7960 
7961  /* Now assign LCNs to all services that haven't already been assigned one */
7962  s1_ptr = DBDEF_GetNextServiceRec(NULL);
7963  while (s1_ptr != NULL)
7964  {
7965  if ((s1_ptr->transport != NULL) && (s1_ptr->transport->sig_type == tuner_type))
7966  {
7967  /* If allocated_lcn has not already been set */
7968  if ((s1_ptr->allocated_lcn == 0) && (s1_ptr->selectable || !s1_ptr->hidden))
7969  {
7970  /* Allocate the next available LCN to the service */
7971  s1_ptr->allocated_lcn = next_allocated_lcn;
7972  next_allocated_lcn++;
7973  }
7974  }
7975 
7976  s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
7977  }
7978 
7979  FUNCTION_FINISH(DBDEF_AllocateLcnsIreland);
7980 
7981  return(duplicate_lcn_found);
7982 }
7983 #endif /* COUNTRY_IRELAND */
7984 
7996 void DBDEF_SetTunedNetwork(U8BIT path, ADB_NETWORK_REC *n_ptr)
7997 {
7998  FUNCTION_START(DBDEF_SetTunedNetwork);
7999  ASSERT(path < num_paths);
8000  tuned_network[path] = n_ptr;
8001  FUNCTION_FINISH(DBDEF_SetTunedNetwork);
8002 }
8003 
8016 {
8017  FUNCTION_START(DBDEF_GetTunedNetwork);
8018  ASSERT(path < num_paths);
8019  FUNCTION_FINISH(DBDEF_GetTunedNetwork);
8020  return(tuned_network[path]);
8021 }
8022 
8035 {
8036  FUNCTION_START(DBDEF_SetTunedTransport);
8037  ASSERT(path < num_paths);
8038  STB_DPSetTunedTransport(path, t_ptr);
8039  FUNCTION_FINISH(DBDEF_SetTunedTransport);
8040 }
8041 
8054 {
8055  FUNCTION_START(DBDEF_GetTunedTransport);
8056  ASSERT(path < num_paths);
8057  FUNCTION_FINISH(DBDEF_GetTunedTransport);
8058  return(STB_DPGetTunedTransport(path));
8059 }
8060 
8061 /*!**************************************************************************
8062  * @brief Sets the currently tuned service
8063  * @param path decode path
8064  * @param s_ptr service tuned to
8065  ****************************************************************************/
8066 void DBDEF_SetTunedService(U8BIT path, ADB_SERVICE_REC *s_ptr)
8067 {
8068  FUNCTION_START(DBDEF_SetTunedService);
8069 
8070  ASSERT(path < num_paths);
8071  if (path < num_paths)
8072  {
8073  STB_DPSetTunedService(path, s_ptr);
8074  }
8075 
8076  FUNCTION_FINISH(DBDEF_SetTunedService);
8077 }
8078 
8079 /*!**************************************************************************
8080  * @brief Returns the currently tuned service on the given path
8081  * @param path decode path
8082  * @return service pointer
8083  ****************************************************************************/
8085 {
8086  void *s_ptr;
8087 
8088  FUNCTION_START(DBDEF_GetTunedService);
8089 
8090  ASSERT(path < num_paths);
8091 
8092  s_ptr = NULL;
8093 
8094  if (path < num_paths)
8095  {
8096  s_ptr = STB_DPGetTunedService(path);
8097  }
8098 
8099  FUNCTION_FINISH(DBDEF_GetTunedService);
8100 
8101  return(s_ptr);
8102 }
8103 
8115 void DBDEF_SetTextLang(U8BIT *lang_ids)
8116 {
8117  FUNCTION_START(DBDEF_SetTextLang);
8118  text_langs = lang_ids;
8119  FUNCTION_FINISH(DBDEF_SetTextLang);
8120 }
8121 
8133 U8BIT* DBDEF_GetTextLang(void)
8134 {
8135  FUNCTION_START(DBDEF_GetTextLang);
8136  FUNCTION_FINISH(DBDEF_GetTextLang);
8137  return(text_langs);
8138 }
8139 
8151 void DBDEF_SetSecondaryTextLang(U8BIT *lang_ids)
8152 {
8153  FUNCTION_START(DBDEF_SetSecondaryTextLang);
8154  second_text_langs = lang_ids;
8155  FUNCTION_FINISH(DBDEF_SetSecondaryTextLang);
8156 }
8157 
8170 {
8171  FUNCTION_START(DBDEF_GetSecondaryTextLang);
8172  FUNCTION_FINISH(DBDEF_GetSecondaryTextLang);
8173  return(second_text_langs);
8174 }
8175 
8187 void DBDEF_SetAudioLang(U8BIT *lang_ids)
8188 {
8189  FUNCTION_START(DBDEF_SetAudioLang);
8190  audio_langs = lang_ids;
8191  FUNCTION_FINISH(DBDEF_SetAudioLang);
8192 }
8193 
8205 void DBDEF_SetSecondaryAudioLang(U8BIT *lang_ids)
8206 {
8207  FUNCTION_START(DBDEF_SetSecondaryAudioLang);
8208  second_audio_langs = lang_ids;
8209  FUNCTION_FINISH(DBDEF_SetSecondaryAudioLang);
8210 }
8211 
8224 {
8225  FUNCTION_START(DBDEF_GetAudioLang);
8226  FUNCTION_FINISH(DBDEF_GetAudioLang);
8227  return(audio_langs);
8228 }
8229 
8242 {
8243  FUNCTION_START(DBDEF_GetSecondaryAudioLang);
8244  FUNCTION_FINISH(DBDEF_GetSecondaryAudioLang);
8245  return(second_audio_langs);
8246 }
8247 
8256 void DBDEF_TidyDatabaseAfterSearch(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite,
8257  BOOLEAN search_completed, BOOLEAN manual)
8258 {
8259  U32BIT country_code;
8260  DBTidyFunc func_ptr;
8261  ADB_SERVICE_REC *s_ptr;
8262  ADB_SERVICE_REC *next_s_ptr;
8263  ADB_TRANSPORT_REC *t_ptr;
8264 
8265  FUNCTION_START(DBDEF_TidyDatabaseAfterSearch);
8266 
8267  /* Call the appropriate function for the country and type of tuner */
8268  country_code = ACFG_GetCountry();
8269 
8270  switch (tuner_type)
8271  {
8272  case SIGNAL_COFDM:
8273  func_ptr = ACFG_GetTerrestrialDBTidyFunction(country_code);
8274  break;
8275 
8276  case SIGNAL_QAM:
8277  func_ptr = ACFG_GetCableDBTidyFunction(country_code);
8278  break;
8279 
8280  case SIGNAL_QPSK:
8281  func_ptr = ACFG_GetSatelliteDBTidyFunction(country_code);
8282  break;
8283 
8284  default:
8285  func_ptr = NULL;
8286  break;
8287  }
8288 
8289  if (func_ptr != NULL)
8290  {
8291  func_ptr(tuner_type, search_completed, manual);
8292  }
8293 
8294  /* Remove any services that were added (e.g. as a result of processing a BAT), but
8295  * weren't actually found due to the transport not being found or weren't in an SDT */
8296  s_ptr = DBDEF_GetNextServiceRec(NULL);
8297  while (s_ptr != NULL)
8298  {
8299  next_s_ptr = DBDEF_GetNextServiceRec(s_ptr);
8300 
8301  if (!s_ptr->found)
8302  {
8303  DBDEF_DeleteServiceRec(s_ptr);
8304  }
8305 
8306  s_ptr = next_s_ptr;
8307  }
8308 
8309  DBDEF_RemoveEmptyTransports(tuner_type, satellite);
8310 
8311  if (!search_completed)
8312  {
8313  /* Mark all transports as available */
8314  t_ptr = DBDEF_GetNextTransportRec(NULL);
8315  while (t_ptr != NULL)
8316  {
8317  t_ptr->available = TRUE;
8318  t_ptr = DBDEF_GetNextTransportRec(t_ptr);
8319  }
8320  }
8321 
8322  FUNCTION_FINISH(DBDEF_TidyDatabaseAfterSearch);
8323 }
8324 
8332 void DBDEF_TidyDatabaseNordig(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
8333 {
8334  ADB_SERVICE_REC *s1_ptr;
8335  ADB_SERVICE_REC *s2_ptr;
8336  ADB_SERVICE_REC *next1_ptr;
8337  ADB_SERVICE_REC *next2_ptr;
8338  ADB_TRANSPORT_REC *t1_ptr;
8339  ADB_TRANSPORT_REC *t2_ptr;
8340  BOOLEAN serv_removed;
8341 
8342  FUNCTION_START(DBDEF_TidyDatabaseNordig);
8343  USE_UNWANTED_PARAM(tuner_type);
8344 
8345  s1_ptr = DBDEF_GetNextServiceRec(NULL);
8346  while (s1_ptr != NULL)
8347  {
8348  serv_removed = FALSE;
8349  next1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
8350  if ((s1_ptr->transport != NULL) && (s1_ptr->transport->network != NULL))
8351  {
8352  if (DBDEF_NetworkInProfile(s1_ptr->transport->network) &&
8353  ((s1_ptr->transport->network->net_id >= NID_PRIVATE_BOUNDARY) ||
8354  (s1_ptr->transport->orig_net_id >= ONID_PRIVATE_BOUNDARY)))
8355  {
8356  DBDEF_DeleteServiceRec(s1_ptr);
8357  serv_removed = TRUE;
8358  }
8359  }
8360 
8361  if (!serv_removed && s1_ptr->unavailable)
8362  {
8363  DBDEF_DeleteServiceRec(s1_ptr);
8364  serv_removed = TRUE;
8365  }
8366 
8367  /* Remove services contained by the transport which haven't been found during the search */
8368  if (!serv_removed && !manual && (s1_ptr->transport != NULL) &&
8369  (s1_ptr->transport->available == FALSE))
8370  {
8371  DBDEF_DeleteServiceRec(s1_ptr);
8372  }
8373 
8374  s1_ptr = next1_ptr;
8375  }
8376 
8377  /* Remove deuplicate services if they are not matching lcns */
8378  s1_ptr = DBDEF_GetNextServiceRec(NULL);
8379  while (s1_ptr != NULL)
8380  {
8381  t1_ptr = s1_ptr->transport;
8382  next1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
8383  if ((t1_ptr != NULL) && DBDEF_TransportInProfile(t1_ptr))
8384  {
8385  s2_ptr = DBDEF_GetNextServiceRec(NULL);
8386  while (s2_ptr != NULL)
8387  {
8388  next2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
8389  if ((s1_ptr != s2_ptr) && (s1_ptr->serv_id == s2_ptr->serv_id))
8390  {
8391  t2_ptr = s2_ptr->transport;
8392  if ((t2_ptr != NULL) && DBDEF_TransportInProfile(t2_ptr))
8393  {
8394  if ((t1_ptr->orig_net_id == t2_ptr->orig_net_id) &&
8395  (t1_ptr->tran_id == t2_ptr->tran_id))
8396  {
8397  if (manual == TRUE)
8398  {
8399  if (s1_ptr->new_service == TRUE)
8400  {
8401  if (s2_ptr == next1_ptr)
8402  {
8403  next1_ptr = DBDEF_GetNextServiceRec(next1_ptr);
8404  }
8405  DBDEF_DeleteServiceRec(s2_ptr);
8406  }
8407  else if (s2_ptr->new_service == TRUE)
8408  {
8409  DBDEF_DeleteServiceRec(s1_ptr);
8410  break;
8411  }
8412  }
8413  else
8414  {
8415  /* Services are the same; choose the strongest one */
8416  if (t1_ptr->signal_level_at_search >= t2_ptr->signal_level_at_search)
8417  {
8418  if (s2_ptr->serv_lcn == s1_ptr->serv_lcn)
8419  {
8420  if (s2_ptr == next1_ptr)
8421  {
8422  next1_ptr = DBDEF_GetNextServiceRec(next1_ptr);
8423  }
8424  /* Delete the second service */
8425  DBDEF_DeleteServiceRec(s2_ptr);
8426  }
8427  }
8428  else
8429  {
8430  if (s2_ptr->serv_lcn == s1_ptr->serv_lcn)
8431  {
8432  /* Delete the first service */
8433  DBDEF_DeleteServiceRec(s1_ptr);
8434  }
8435  break;
8436  }
8437  }
8438  }
8439  }
8440  }
8441  s2_ptr = next2_ptr;
8442  }
8443  }
8444  s1_ptr = next1_ptr;
8445  }
8446 
8447  if (search_completed)
8448  {
8449  /* Remove any transports that haven't been found during the search */
8450  t1_ptr = DBDEF_GetNextTransportRec(NULL);
8451  while (t1_ptr != NULL)
8452  {
8453  t2_ptr = DBDEF_GetNextTransportRec(t1_ptr);
8454 
8455  if (!t1_ptr->available)
8456  {
8457  DBDEF_DeleteTransportRec(t1_ptr);
8458  }
8459 
8460  t1_ptr = t2_ptr;
8461  }
8462  }
8463 
8464  FUNCTION_FINISH(DBDEF_TidyDatabaseNordig);
8465 }
8466 
8474 void DBDEF_TidyDatabaseUK(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
8475 {
8476  ADB_SERVICE_REC *s1_ptr;
8477  ADB_SERVICE_REC *next_s1_ptr;
8478  ADB_SERVICE_REC *s2_ptr;
8479  ADB_SERVICE_REC *next_s2_ptr;
8480  ADB_TRANSPORT_REC *t1_ptr;
8481  ADB_TRANSPORT_REC *t2_ptr;
8482 
8483  FUNCTION_START(DBDEF_TidyDatabaseUK);
8484  USE_UNWANTED_PARAM(tuner_type);
8485  USE_UNWANTED_PARAM(search_completed);
8486 
8487  s1_ptr = DBDEF_GetNextServiceRec(NULL);
8488  while (s1_ptr != NULL)
8489  {
8490  next_s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
8491  t1_ptr = s1_ptr->transport;
8492  if ((t1_ptr != NULL) && DBDEF_TransportInProfile(t1_ptr))
8493  {
8494  s2_ptr = DBDEF_GetNextServiceRec(NULL);
8495  while (s2_ptr != NULL)
8496  {
8497  next_s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
8498  if ((s1_ptr != s2_ptr) && (s1_ptr->serv_id == s2_ptr->serv_id))
8499  {
8500  t2_ptr = s2_ptr->transport;
8501  if ((t2_ptr != NULL) && DBDEF_TransportInProfile(t2_ptr))
8502  {
8503  if (t1_ptr->orig_net_id == t2_ptr->orig_net_id)
8504  {
8505  if (manual == TRUE)
8506  {
8507  if (s1_ptr->new_service == TRUE)
8508  {
8509  if (s2_ptr == next_s1_ptr)
8510  {
8511  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8512  }
8513  DBDEF_DeleteServiceRec(s2_ptr);
8514  }
8515  else if (s2_ptr->new_service == TRUE)
8516  {
8517  DBDEF_DeleteServiceRec(s1_ptr);
8518  s1_ptr = NULL;
8519  break;
8520  }
8521  }
8522  else
8523  {
8524  /* Services are the same; choose the strongest one */
8525  if (t1_ptr->signal_level_at_search >= t2_ptr->signal_level_at_search)
8526  {
8527  /* Delete the second service */
8528  if (s2_ptr == next_s1_ptr)
8529  {
8530  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8531  }
8532  DBDEF_DeleteServiceRec(s2_ptr);
8533  }
8534  else
8535  {
8536  /* Delete the first service */
8537  DBDEF_DeleteServiceRec(s1_ptr);
8538  s1_ptr = NULL;
8539  break;
8540  }
8541  }
8542  }
8543  }
8544  }
8545 
8546  s2_ptr = next_s2_ptr;
8547  }
8548  }
8549  s1_ptr = next_s1_ptr;
8550  }
8551 
8552  FUNCTION_FINISH(DBDEF_TidyDatabaseUK);
8553 }
8554 
8562 void DBDEF_TidyDatabaseSatUK(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
8563 {
8564  ADB_SERVICE_REC *s1_ptr;
8565  ADB_SERVICE_REC *next_s1_ptr;
8566  ADB_SERVICE_REC *s2_ptr;
8567  ADB_SERVICE_REC *next_s2_ptr;
8568  ADB_TRANSPORT_REC *t1_ptr;
8569  ADB_TRANSPORT_REC *t2_ptr;
8570 
8571  FUNCTION_START(DBDEF_TidyDatabaseSatUK);
8572  USE_UNWANTED_PARAM(tuner_type);
8573  USE_UNWANTED_PARAM(search_completed);
8574 
8575  s1_ptr = DBDEF_GetNextServiceRec(NULL);
8576  while (s1_ptr != NULL)
8577  {
8578  next_s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
8579  t1_ptr = s1_ptr->transport;
8580  if ((t1_ptr != NULL) && DBDEF_TransportInProfile(t1_ptr))
8581  {
8582  s2_ptr = DBDEF_GetNextServiceRec(NULL);
8583  while (s2_ptr != NULL)
8584  {
8585  next_s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
8586 
8587  /* Freesat allows identical services, so only want to delete a service if neither
8588  * of them are Freesat services */
8589  if ((s1_ptr != s2_ptr) && (s1_ptr->serv_id == s2_ptr->serv_id) &&
8590  (s1_ptr->freesat_id == INVALID_FREESAT_SERV_ID) &&
8591  (s2_ptr->freesat_id == INVALID_FREESAT_SERV_ID))
8592  {
8593  t2_ptr = s2_ptr->transport;
8594  if ((t2_ptr != NULL) && DBDEF_TransportInProfile(t2_ptr))
8595  {
8596  if ((t1_ptr->orig_net_id == t2_ptr->orig_net_id) &&
8597  (t1_ptr->tran_id == t2_ptr->tran_id))
8598  {
8599  if (manual)
8600  {
8601  if (s1_ptr->new_service)
8602  {
8603  if (s2_ptr == next_s1_ptr)
8604  {
8605  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8606  }
8607  DBDEF_DeleteServiceRec(s2_ptr);
8608  }
8609  else if (s2_ptr->new_service)
8610  {
8611  DBDEF_DeleteServiceRec(s1_ptr);
8612  s1_ptr = NULL;
8613  break;
8614  }
8615  }
8616  else
8617  {
8618  /* Services are the same; choose the strongest one */
8619  if (t1_ptr->signal_level_at_search >= t2_ptr->signal_level_at_search)
8620  {
8621  /* Delete the second service */
8622  if (s2_ptr == next_s1_ptr)
8623  {
8624  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8625  }
8626  DBDEF_DeleteServiceRec(s2_ptr);
8627  }
8628  else
8629  {
8630  /* Delete the first service */
8631  DBDEF_DeleteServiceRec(s1_ptr);
8632  s1_ptr = NULL;
8633  break;
8634  }
8635  }
8636  }
8637  }
8638  }
8639 
8640  s2_ptr = next_s2_ptr;
8641  }
8642  }
8643  s1_ptr = next_s1_ptr;
8644  }
8645 
8646  FUNCTION_FINISH(DBDEF_TidyDatabaseSatUK);
8647 }
8648 
8656 void DBDEF_TidyDatabaseDefault(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
8657 {
8658  ADB_SERVICE_REC *s1_ptr;
8659  ADB_SERVICE_REC *next_s1_ptr;
8660  ADB_SERVICE_REC *s2_ptr;
8661  ADB_SERVICE_REC *next_s2_ptr;
8662  ADB_TRANSPORT_REC *t1_ptr;
8663  ADB_TRANSPORT_REC *t2_ptr;
8664 
8665  FUNCTION_START(DBDEF_TidyDatabaseDefault);
8666  USE_UNWANTED_PARAM(tuner_type);
8667  USE_UNWANTED_PARAM(search_completed);
8668 
8669  s1_ptr = DBDEF_GetNextServiceRec(NULL);
8670  while (s1_ptr != NULL)
8671  {
8672  next_s1_ptr = DBDEF_GetNextServiceRec(s1_ptr);
8673  t1_ptr = s1_ptr->transport;
8674  if ((t1_ptr != NULL) && DBDEF_TransportInProfile(t1_ptr))
8675  {
8676  s2_ptr = DBDEF_GetNextServiceRec(NULL);
8677  while (s2_ptr != NULL)
8678  {
8679  next_s2_ptr = DBDEF_GetNextServiceRec(s2_ptr);
8680  if ((s1_ptr != s2_ptr) && (s1_ptr->serv_id == s2_ptr->serv_id))
8681  {
8682  t2_ptr = s2_ptr->transport;
8683  if ((t2_ptr != NULL) && DBDEF_TransportInProfile(t2_ptr))
8684  {
8685  if ((t1_ptr->orig_net_id == t2_ptr->orig_net_id) &&
8686  (t1_ptr->tran_id == t2_ptr->tran_id))
8687  {
8688  if (manual)
8689  {
8690  if (s1_ptr->new_service)
8691  {
8692  if (s2_ptr == next_s1_ptr)
8693  {
8694  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8695  }
8696  DBDEF_DeleteServiceRec(s2_ptr);
8697  }
8698  else if (s2_ptr->new_service)
8699  {
8700  DBDEF_DeleteServiceRec(s1_ptr);
8701  s1_ptr = NULL;
8702  break;
8703  }
8704  }
8705  else
8706  {
8707  /* Services are the same; choose the strongest one */
8708  if (t1_ptr->signal_level_at_search >= t2_ptr->signal_level_at_search)
8709  {
8710  /* Delete the second service */
8711  if (s2_ptr == next_s1_ptr)
8712  {
8713  next_s1_ptr = DBDEF_GetNextServiceRec(next_s1_ptr);
8714  }
8715  DBDEF_DeleteServiceRec(s2_ptr);
8716  }
8717  else
8718  {
8719  /* Delete the first service */
8720  DBDEF_DeleteServiceRec(s1_ptr);
8721  s1_ptr = NULL;
8722  break;
8723  }
8724  }
8725  }
8726  }
8727  }
8728 
8729  s2_ptr = next_s2_ptr;
8730  }
8731  }
8732  s1_ptr = next_s1_ptr;
8733  }
8734 
8735  FUNCTION_FINISH(DBDEF_TidyDatabaseDefault);
8736 }
8737 
8745 void DBDEF_RemoveEmptyTransports(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
8746 {
8747  ADB_TRANSPORT_REC *t_ptr, *next;
8748  ADB_SERVICE_REC *s_ptr;
8749  BOOLEAN transport_empty;
8750 
8751  FUNCTION_START(DBDEF_RemoveEmptyTransports);
8752 
8753  t_ptr = DBDEF_GetNextTransportRec(NULL);
8754  while (t_ptr != NULL)
8755  {
8756  transport_empty = TRUE;
8757  next = DBDEF_GetNextTransportRec(t_ptr);
8758 
8759  if (DBDEF_TransportForTunerType(t_ptr, tuner_type, satellite))
8760  {
8761  /* Check whether any services still reference this transport */
8762  s_ptr = DBDEF_GetNextServiceRec(NULL);
8763  while ((s_ptr != NULL) && transport_empty)
8764  {
8765  if (s_ptr->transport == t_ptr)
8766  {
8767  /* Found a service whose parent is this transport */
8768  transport_empty = FALSE;
8769  }
8770  s_ptr = DBDEF_GetNextServiceRec(s_ptr);
8771  }
8772 
8773  if (transport_empty)
8774  {
8775  /* No services refer to this transport, so it can be deleted */
8776  DBDEF_DeleteTransportRec(t_ptr);
8777  }
8778  }
8779 
8780  t_ptr = next;
8781  }
8782 
8783  FUNCTION_FINISH(DBDEF_RemoveEmptyTransports);
8784 }
8785 
8793 ADB_CRID_REC* DBDEF_AddCridRecord(U8BIT *crid, BOOLEAN series, BOOLEAN recommended)
8794 {
8795  ADB_CRID_REC *c_ptr;
8796  U16BIT crid_len;
8797  void *dba_rec;
8798 
8799  FUNCTION_START(DBDEF_AddCridRecord);
8800 
8801  c_ptr = STB_AppGetMemory(sizeof(ADB_CRID_REC));
8802  if (c_ptr != NULL)
8803  {
8804  memset(c_ptr, 0, sizeof(ADB_CRID_REC));
8805 
8806  crid_len = STB_GetNumBytesInString(crid);
8807  c_ptr->crid_str = DBDEF_MakeString(0, crid, crid_len);
8808  c_ptr->series_flag = series;
8809  c_ptr->recommended_flag = recommended;
8810 
8811  STB_LLAddBlockToEnd(&crid_rec_list, (LINK_LIST_PTR_BLK *)c_ptr);
8812 
8813  /* Add database record */
8814  dba_rec = DBA_CreateRecord(DBA_RECORD_CRID, NULL);
8815  if (dba_rec != NULL)
8816  {
8817  c_ptr->dba_rec = dba_rec;
8818 
8819  // fill in details in record
8820  DBA_SetFieldString(dba_rec, DBA_FIELD_TIMER_CRID, crid, crid_len);
8821  DBA_SetFieldValue(dba_rec, DBA_FIELD_CRID_SERIES, (U32BIT)series);
8822  DBA_SetFieldValue(dba_rec, DBA_FIELD_CRID_RECOMMENDED, (U32BIT)recommended);
8823 
8824  /* Set the current date as the last time the record was seen in the EIT */
8825  c_ptr->eit_date = STB_GCGetGMTDate();
8826  DBA_SetFieldValue(dba_rec, DBA_FIELD_CRID_EIT_DATE, c_ptr->eit_date);
8827  }
8828  else
8829  {
8830  STB_AppFreeMemory(c_ptr);
8831  c_ptr = NULL;
8832  }
8833  }
8834 
8835  FUNCTION_FINISH(DBDEF_AddCridRecord);
8836 
8837  return(c_ptr);
8838 }
8839 
8845 void DBDEF_SetCridDateTime(ADB_CRID_REC *c_ptr, U32DHMS date_time)
8846 {
8847  FUNCTION_START(DBDEF_SetCridDateTime);
8848 
8849  if (DBDEF_IsValidCridRecord(c_ptr))
8850  {
8851  c_ptr->date_time = date_time;
8852  DBA_SetFieldValue(c_ptr->dba_rec, DBA_FIELD_TIMER_STARTTIME, date_time);
8853  }
8854 
8855  FUNCTION_FINISH(DBDEF_SetCridDateTime);
8856 }
8857 
8863 void DBDEF_SetCridService(ADB_CRID_REC *c_ptr, U16BIT serv_id)
8864 {
8865  FUNCTION_START(DBDEF_SetCridService);
8866 
8867  if (DBDEF_IsValidCridRecord(c_ptr))
8868  {
8869  c_ptr->serv_id = serv_id;
8870  DBA_SetFieldValue(c_ptr->dba_rec, DBA_FIELD_SERVICE_ID, (U32BIT)serv_id);
8871  }
8872 
8873  FUNCTION_FINISH(DBDEF_SetCridService);
8874 }
8875 
8881 void DBDEF_SetCridProgrammeName(ADB_CRID_REC *c_ptr, U8BIT *prog_name)
8882 {
8883  U16BIT name_len;
8884 
8885  FUNCTION_START(DBDEF_SetCridProgrammeName);
8886 
8887  if (DBDEF_IsValidCridRecord(c_ptr))
8888  {
8889  name_len = STB_GetNumBytesInString(prog_name);
8890  c_ptr->name_str = DBDEF_MakeString(0, prog_name, name_len);
8891 
8892  DBA_SetFieldString(c_ptr->dba_rec, DBA_FIELD_REC_NAME, prog_name, name_len);
8893  }
8894 
8895  FUNCTION_FINISH(DBDEF_SetCridProgrammeName);
8896 }
8897 
8903 void DBDEF_SetCridDoNotDelete(ADB_CRID_REC *c_ptr, BOOLEAN do_not_delete)
8904 {
8905  FUNCTION_START(DBDEF_SetCridDoNotDelete);
8906 
8907  if (DBDEF_IsValidCridRecord(c_ptr))
8908  {
8909  c_ptr->do_not_delete = do_not_delete;
8910  DBA_SetFieldValue(c_ptr->dba_rec, DBA_FIELD_CRID_DO_NOT_DELETE, (U32BIT)do_not_delete);
8911  }
8912 
8913  FUNCTION_FINISH(DBDEF_SetCridDoNotDelete);
8914 }
8915 
8921 {
8922  FUNCTION_START(DBDEF_UpdateCridEitDate);
8923 
8924  ASSERT(c_ptr != NULL);
8925 
8926  if (DBDEF_IsValidCridRecord(c_ptr))
8927  {
8928  c_ptr->eit_date = STB_GCGetGMTDate();
8929  DBA_SetFieldValue(c_ptr->dba_rec, DBA_FIELD_CRID_EIT_DATE, c_ptr->eit_date);
8930  }
8931 
8932  FUNCTION_FINISH(DBDEF_UpdateCridEitDate);
8933 }
8934 
8940 {
8941  FUNCTION_START(DBDEF_DeleteCridRecord);
8942 
8943  if (DBDEF_IsValidCridRecord(c_ptr))
8944  {
8946 
8947  if (c_ptr->name_str != NULL)
8948  {
8949  STB_AppFreeMemory(c_ptr->name_str);
8950  }
8951 
8952  if (c_ptr->crid_str != NULL)
8953  {
8954  STB_AppFreeMemory(c_ptr->crid_str);
8955  }
8956 
8957  DBA_DestroyRecord(c_ptr->dba_rec);
8958 
8959  STB_AppFreeMemory(c_ptr);
8960  }
8961 
8962  FUNCTION_FINISH(DBDEF_DeleteCridRecord);
8963 }
8964 
8970 {
8971  FUNCTION_START(DBDEF_GetNumCridRecords);
8972  FUNCTION_FINISH(DBDEF_GetNumCridRecords);
8973  return(STB_LLGetNumBlocks(&crid_rec_list));
8974 }
8975 
8983 {
8984  ADB_CRID_REC *ret_ptr;
8985 
8986  FUNCTION_START(DBDEF_GetNextCridRecord);
8987 
8988  if (c_ptr == NULL)
8989  {
8990  ret_ptr = (ADB_CRID_REC *)STB_LLGetFirstBlock(&crid_rec_list);
8991  }
8992  else
8993  {
8994  ret_ptr = (ADB_CRID_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)c_ptr);
8995  }
8996 
8997  FUNCTION_FINISH(DBDEF_GetNextCridRecord);
8998 
8999  return(ret_ptr);
9000 }
9001 
9008 {
9009  BOOLEAN valid;
9010  void *next;
9011 
9012  FUNCTION_START(DBDEF_IsValidCridRecord);
9013 
9014  valid = FALSE;
9015 
9016  if (c_ptr != NULL)
9017  {
9018  next = STB_LLGetFirstBlock(&crid_rec_list);
9019  while ((next != NULL) && !valid)
9020  {
9021  if (next == c_ptr)
9022  {
9023  valid = TRUE;
9024  }
9025  else
9026  {
9027  next = STB_LLGetNextBlock(next);
9028  }
9029  }
9030  }
9031 
9032  FUNCTION_FINISH(DBDEF_IsValidCridRecord);
9033 
9034  return(valid);
9035 }
9036 
9042 {
9043  FUNCTION_START(DBDEF_GetNumFavouriteLists);
9044  FUNCTION_FINISH(DBDEF_GetNumFavouriteLists);
9045  return(STB_LLGetNumBlocks(&favlist_list));
9046 }
9047 
9061 ADB_FAVLIST_REC* DBDEF_AddFavouriteList(U8BIT list_id, U8BIT *name, U32BIT user_data, S16BIT index)
9062 {
9063  BOOLEAN id_used;
9064  ADB_FAVLIST_REC *fl_ptr;
9065  ADB_FAVLIST_REC *fav_list;
9066  void *dba_rec;
9067  U16BIT name_len;
9068 
9069  FUNCTION_START(DBDEF_AddFavouriteList);
9070 
9071  fav_list = NULL;
9072 
9073  if (list_id == 0)
9074  {
9075  /* Find an available id for the new list. 0 is an invalid list id */
9076  for (list_id = 1; list_id != 0; list_id++)
9077  {
9078  id_used = FALSE;
9079 
9080  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9081  while ((fl_ptr != NULL) && !id_used)
9082  {
9083  if (fl_ptr->list_id == list_id)
9084  {
9085  /* This id is used, try another one */
9086  id_used = TRUE;
9087  }
9088  else
9089  {
9090  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9091  }
9092  }
9093 
9094  if (!id_used)
9095  {
9096  /* Usable id has been found */
9097  break;
9098  }
9099  }
9100  }
9101  else
9102  {
9103  /* Check the id isn't already being used */
9104  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9105  while (fl_ptr != NULL)
9106  {
9107  if (fl_ptr->list_id == list_id)
9108  {
9109  /* This id is used */
9110  break;
9111  }
9112 
9113  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9114  }
9115 
9116  if (fl_ptr != NULL)
9117  {
9118  /* The given list id can't be used */
9119  list_id = 0;
9120  }
9121  }
9122 
9123  if (list_id != 0)
9124  {
9125  /* Id available, create a new fav list */
9126  if ((fav_list = STB_AppGetMemory(sizeof(ADB_FAVLIST_REC))) != NULL)
9127  {
9128  memset(fav_list, 0, sizeof(ADB_FAVLIST_REC));
9129 
9130  dba_rec = DBA_CreateRecord(DBA_RECORD_FAV_LIST, NULL);
9131  if (dba_rec != NULL)
9132  {
9133  fav_list->dba_rec = dba_rec;
9134 
9135  fav_list->list_id = list_id;
9136  DBA_SetFieldValue(dba_rec, DBA_FIELD_FAVLIST_ID, (U32BIT)list_id);
9137 
9138  fav_list->user_data = user_data;
9139  DBA_SetFieldValue(dba_rec, DBA_FIELD_FAVLIST_USER_DATA, user_data);
9140 
9141  if (name == NULL)
9142  {
9143  fav_list->name = NULL;
9144  DBA_SetFieldString(dba_rec, DBA_FIELD_REC_NAME, NULL, 0);
9145  }
9146  else
9147  {
9148  name_len = STB_GetNumBytesInString(name);
9149  fav_list->name = DBDEF_MakeString(0, name, name_len);
9150  DBA_SetFieldString(dba_rec, DBA_FIELD_REC_NAME, name, name_len);
9151  }
9152 
9153  STB_LLInitialiseHeader(&fav_list->serv_list);
9154 
9155  if (index == 0)
9156  {
9157  /* Add to start of list */
9158  STB_LLAddBlockToStart(&favlist_list, (LINK_LIST_PTR_BLK *)fav_list);
9159  }
9160  else if ((index < 0) || (index >= STB_LLGetNumBlocks(&favlist_list)))
9161  {
9162  /* Add to end of list */
9163  STB_LLAddBlockToEnd(&favlist_list, (LINK_LIST_PTR_BLK *)fav_list);
9164  }
9165  else
9166  {
9167  /* Inserting new list at a given position */
9168  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9169  while (fl_ptr != NULL)
9170  {
9171  if (fl_ptr->index >= index)
9172  {
9173  /* Need to insert before this item */
9175  break;
9176  }
9177  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9178  }
9179  }
9180 
9181  /* Reassign index of each list according to the new order */
9182  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9183  for (index = 0; fl_ptr != NULL; index++)
9184  {
9185  if (fl_ptr->index != index)
9186  {
9187  fl_ptr->index = index;
9188  DBA_SetFieldValue(fl_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9189  }
9190 
9191  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9192  }
9193  }
9194  else
9195  {
9196  STB_AppFreeMemory(fav_list);
9197  fav_list = NULL;
9198  }
9199  }
9200  }
9201 
9202  FUNCTION_FINISH(DBDEF_AddFavouriteList);
9203 
9204  return(fav_list);
9205 }
9206 
9213 {
9214  ADB_FAVLIST_REC *next;
9215 
9216  FUNCTION_START(DBDEF_GetNextFavouriteList);
9217 
9218  if (fav_list == NULL)
9219  {
9220  next = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9221  }
9222  else
9223  {
9224  next = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fav_list);
9225  }
9226 
9227  FUNCTION_FINISH(DBDEF_GetNextFavouriteList);
9228 
9229  return(next);
9230 }
9231 
9238 {
9239  ADB_FAVLIST_REC *fl_ptr;
9240 
9241  FUNCTION_START(DBDEF_FindFavouriteList);
9242 
9243  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9244  while (fl_ptr != NULL)
9245  {
9246  if (fl_ptr->list_id == list_id)
9247  {
9248  break;
9249  }
9250  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9251  }
9252 
9253  FUNCTION_FINISH(DBDEF_FindFavouriteList);
9254 
9255  return(fl_ptr);
9256 }
9257 
9263 void DBDEF_SetFavouriteListUserData(ADB_FAVLIST_REC *fav_list, U32BIT user_data)
9264 {
9265  FUNCTION_START(DBDEF_SetFavouriteListUserData);
9266 
9267  if (fav_list != NULL)
9268  {
9269  fav_list->user_data = user_data;
9270  DBA_SetFieldValue(fav_list->dba_rec, DBA_FIELD_FAVLIST_USER_DATA, user_data);
9271  }
9272 
9273  FUNCTION_FINISH(DBDEF_SetFavouriteListUserData);
9274 }
9275 
9283 void DBDEF_MoveFavouriteListTo(ADB_FAVLIST_REC *fav_list, S16BIT index)
9284 {
9285  ADB_FAVLIST_REC *fl_ptr;
9286 
9287  FUNCTION_START(DBDEF_MoveFavouriteListTo);
9288 
9289  if (fav_list->index != index)
9290  {
9291  /* Remove the block from it's current position in the list */
9292  STB_LLRemoveBlock((LINK_LIST_PTR_BLK *)fav_list);
9293 
9294  if (index == 0)
9295  {
9296  STB_LLAddBlockToStart(&favlist_list, (LINK_LIST_PTR_BLK *)fav_list);
9297  }
9298  else if ((index < 0) || (index >= STB_LLGetNumBlocks(&favlist_list)))
9299  {
9300  STB_LLAddBlockToEnd(&favlist_list, (LINK_LIST_PTR_BLK *)fav_list);
9301  }
9302  else
9303  {
9304  /* Find position to insert the list */
9305  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9306  while (fl_ptr != NULL)
9307  {
9308  if (fl_ptr->index >= index)
9309  {
9310  /* Need to insert before this item */
9312  break;
9313  }
9314  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9315  }
9316  }
9317 
9318  /* Reassign index of each list according to the new order */
9319  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9320  for (index = 0; fl_ptr != NULL; index++)
9321  {
9322  if (fl_ptr->index != index)
9323  {
9324  fl_ptr->index = index;
9325  DBA_SetFieldValue(fl_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9326  }
9327 
9328  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9329  }
9330  }
9331 
9332  FUNCTION_FINISH(DBDEF_MoveFavouriteListTo);
9333 }
9334 
9340 {
9341  ADB_FAVSERV_REC *fs_ptr;
9342  ADB_FAVLIST_REC *fl_ptr;
9343  U16BIT index;
9344 
9345  FUNCTION_START(DBDEF_DeleteFavouriteList);
9346 
9347  if (fav_list != NULL)
9348  {
9349  STB_LLRemoveBlock((LINK_LIST_PTR_BLK *)fav_list);
9350 
9351  /* Delete all services from this favourite list */
9352  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9353  while (fs_ptr != NULL)
9354  {
9355  DBDEF_DeleteServiceFromFavouriteList(fav_list, fs_ptr);
9356  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9357  }
9358 
9359  if (fav_list->name != NULL)
9360  {
9361  STB_AppFreeMemory(fav_list->name);
9362  }
9363 
9364  DBA_DestroyRecord(fav_list->dba_rec);
9365 
9366  STB_AppFreeMemory(fav_list);
9367 
9368  /* Reassign list indexes to reflect updated positions */
9369  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetFirstBlock(&favlist_list);
9370  for (index = 0; fl_ptr != NULL; index++)
9371  {
9372  if (fl_ptr->index != index)
9373  {
9374  fl_ptr->index = index;
9375  DBA_SetFieldValue(fl_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9376  }
9377  fl_ptr = (ADB_FAVLIST_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fl_ptr);
9378  }
9379  }
9380 
9381  FUNCTION_FINISH(DBDEF_DeleteFavouriteList);
9382 }
9383 
9390 {
9391  FUNCTION_START(DBDEF_GetNumServicesInFavouriteList);
9392  FUNCTION_FINISH(DBDEF_GetNumServicesInFavouriteList);
9393  return(STB_LLGetNumBlocks(&fav_list->serv_list));
9394 }
9395 
9405  ADB_SERVICE_REC *serv_ptr, S16BIT index)
9406 {
9407  ADB_FAVSERV_REC *fs_ptr;
9408  ADB_FAVSERV_REC *fav_serv;
9409  void *dba_rec;
9410 
9411  FUNCTION_START(DBDEF_AddServiceToFavouriteList);
9412 
9413  fav_serv = NULL;
9414 
9415  /* Check that the service isn't already in the list */
9416  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9417  while (fs_ptr != NULL)
9418  {
9419  if (fs_ptr->serv_ptr == serv_ptr)
9420  {
9421  /* Service already in this list */
9422  break;
9423  }
9424  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
9425  }
9426 
9427  if (fs_ptr == NULL)
9428  {
9429  /* Service not in list, add it */
9430  if ((fav_serv = STB_AppGetMemory(sizeof(ADB_FAVSERV_REC))) != NULL)
9431  {
9432  memset(fav_serv, 0, sizeof(ADB_FAVSERV_REC));
9433 
9434  dba_rec = DBA_CreateRecord(DBA_RECORD_FAV_SERV, serv_ptr->dba_rec);
9435  if (dba_rec != NULL)
9436  {
9437  fav_serv->dba_rec = dba_rec;
9438  fav_serv->serv_ptr = serv_ptr;
9439 
9440  fav_serv->list_id = fav_list->list_id;
9441  DBA_SetFieldValue(dba_rec, DBA_FIELD_FAVLIST_ID, (U32BIT)fav_serv->list_id);
9442 
9443  if (index == 0)
9444  {
9445  /* Add to start of list */
9446  STB_LLAddBlockToStart(&fav_list->serv_list, (LINK_LIST_PTR_BLK *)fav_serv);
9447  }
9448  else if ((index < 0) || (index >= STB_LLGetNumBlocks(&fav_list->serv_list)))
9449  {
9450  /* Add to end of list */
9451  STB_LLAddBlockToEnd(&fav_list->serv_list, (LINK_LIST_PTR_BLK *)fav_serv);
9452  }
9453  else
9454  {
9455  /* Insert into given position */
9456  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9457  while (fs_ptr != NULL)
9458  {
9459  if (fs_ptr->index >= index)
9460  {
9461  /* Insert before this item */
9463  break;
9464  }
9465  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
9466  }
9467  }
9468 
9469  /* Reassign index of each service according to the new order */
9470  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9471  for (index = 0; fs_ptr != NULL; index++)
9472  {
9473  if (fs_ptr->index != index)
9474  {
9475  fs_ptr->index = index;
9476  DBA_SetFieldValue(fs_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9477  }
9478 
9479  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
9480  }
9481  }
9482  else
9483  {
9484  STB_AppFreeMemory(fav_serv);
9485  fav_serv = NULL;
9486  }
9487  }
9488  }
9489 
9490  FUNCTION_FINISH(DBDEF_AddServiceToFavouriteList);
9491 
9492  return(fav_serv);
9493 }
9494 
9502 {
9503  ADB_FAVSERV_REC *fav_serv;
9504 
9505  FUNCTION_START(DBDEF_FindServiceInFavouriteList);
9506 
9507  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9508  while (fav_serv != NULL)
9509  {
9510  if (fav_serv->serv_ptr == serv_ptr)
9511  {
9512  break;
9513  }
9514 
9515  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fav_serv);
9516  }
9517 
9518  FUNCTION_FINISH(DBDEF_FindServiceInFavouriteList);
9519 
9520  return(fav_serv);
9521 }
9522 
9530  ADB_FAVSERV_REC *fav_serv)
9531 {
9532  FUNCTION_START(DBDEF_GetNextServiceFromFavouriteList);
9533 
9534  if (fav_serv == NULL)
9535  {
9536  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9537  }
9538  else
9539  {
9540  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fav_serv);
9541  }
9542 
9543  FUNCTION_FINISH(DBDEF_GetNextServiceFromFavouriteList);
9544 
9545  return(fav_serv);
9546 }
9547 
9555  ADB_FAVSERV_REC *fav_serv)
9556 {
9557  FUNCTION_START(DBDEF_GetPrevServiceFromFavouriteList);
9558 
9559  if (fav_serv == NULL)
9560  {
9561  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetLastBlock(&fav_list->serv_list);
9562  }
9563  else
9564  {
9565  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetPrevBlock((LINK_LIST_PTR_BLK *)fav_serv);
9566  }
9567 
9568  FUNCTION_FINISH(DBDEF_GetPrevServiceFromFavouriteList);
9569 
9570  return(fav_serv);
9571 }
9572 
9582  S16BIT index)
9583 {
9584  ADB_FAVSERV_REC *fs_ptr;
9585 
9586  FUNCTION_START(DBDEF_MoveFavouriteListServiceTo);
9587 
9588  if (fav_serv->index != index)
9589  {
9590  /* Remove the block from it's current position in the list */
9591  STB_LLRemoveBlock((LINK_LIST_PTR_BLK *)fav_serv);
9592 
9593  if (index == 0)
9594  {
9595  STB_LLAddBlockToStart(&fav_list->serv_list, (LINK_LIST_PTR_BLK *)fav_serv);
9596  }
9597  else if ((index < 0) || (index >= STB_LLGetNumBlocks(&fav_list->serv_list)))
9598  {
9599  STB_LLAddBlockToEnd(&fav_list->serv_list, (LINK_LIST_PTR_BLK *)fav_serv);
9600  }
9601  else
9602  {
9603  /* Find position to insert the list */
9604  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9605  while (fs_ptr != NULL)
9606  {
9607  if (fs_ptr->index >= index)
9608  {
9609  /* Need to insert before this item */
9611  break;
9612  }
9613  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
9614  }
9615  }
9616 
9617  /* Reassign index of each service according to the new order */
9618  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9619  for (index = 0; fs_ptr != NULL; index++)
9620  {
9621  if (fs_ptr->index != index)
9622  {
9623  fs_ptr->index = index;
9624  DBA_SetFieldValue(fs_ptr->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9625  }
9626 
9627  fs_ptr = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fs_ptr);
9628  }
9629  }
9630 
9631  FUNCTION_FINISH(DBDEF_MoveFavouriteListServiceTo);
9632 }
9633 
9640 {
9641  U16BIT index;
9642 
9643  FUNCTION_START(DBDEF_DeleteServiceFromFavouriteList);
9644 
9645  if ((fav_list != NULL) && (fav_serv != NULL))
9646  {
9647  STB_LLRemoveBlock((LINK_LIST_PTR_BLK *)fav_serv);
9648 
9649  DBA_DestroyRecord(fav_serv->dba_rec);
9650 
9651  STB_AppFreeMemory(fav_serv);
9652 
9653  /* Reassign list indexes for all the services remaining in the list */
9654  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9655  for (index = 0; fav_serv != NULL; index++)
9656  {
9657  if (fav_serv->index != index)
9658  {
9659  fav_serv->index = index;
9660  DBA_SetFieldValue(fav_serv->dba_rec, DBA_FIELD_FAVLIST_INDEX, (U32BIT)index);
9661  }
9662  fav_serv = (ADB_FAVSERV_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)fav_serv);
9663  }
9664  }
9665 
9666  FUNCTION_FINISH(DBDEF_DeleteServiceFromFavouriteList);
9667 }
9668 
9674 {
9675  ADB_FAVSERV_REC *serv;
9676  ADB_FAVSERV_REC *next;
9677 
9679 
9680  if (fav_list != NULL)
9681  {
9682  serv = (ADB_FAVSERV_REC *)STB_LLGetFirstBlock(&fav_list->serv_list);
9683  while (serv != NULL)
9684  {
9686 
9688 
9689  DBA_DestroyRecord(serv->dba_rec);
9690 
9691  STB_AppFreeMemory(serv);
9692 
9693  serv = next;
9694  }
9695  }
9696 
9698 }
9699 
9707 {
9708  BOOLEAN changed;
9709  U16BIT new_name_len;
9710 
9711  FUNCTION_START(DBDEF_SetFavouriteListName);
9712 
9713  changed = TRUE;
9714  new_name_len = 0;
9715 
9716  if (name != NULL)
9717  {
9718  new_name_len = STB_GetNumBytesInString(name);
9719  }
9720 
9721  if (f_ptr->name != NULL)
9722  {
9723  if (new_name_len == f_ptr->name->nbytes)
9724  {
9725  /* String lengths are the same, check the bytes */
9726  if (memcmp(name, f_ptr->name->str_ptr, new_name_len) == 0)
9727  {
9728  /* Names are the same */
9729  changed = FALSE;
9730  }
9731  }
9732  }
9733 
9734  if (changed)
9735  {
9736  /* Free the current name */
9737  if (f_ptr->name != NULL)
9738  {
9739  DBDEF_ReleaseString(f_ptr->name);
9740  f_ptr->name = NULL;
9741  }
9742 
9743  if (name != NULL)
9744  {
9745  f_ptr->name = DBDEF_MakeString(0, name, new_name_len);
9746  }
9747 
9748  if (f_ptr->name != NULL)
9749  {
9750  DBA_SetFieldString(f_ptr->dba_rec, DBA_FIELD_REC_NAME, f_ptr->name->str_ptr,
9751  f_ptr->name->nbytes);
9752  }
9753  else
9754  {
9755  DBA_SetFieldString(f_ptr->dba_rec, DBA_FIELD_REC_NAME, NULL, 0);
9756  }
9757 
9758  DBA_SaveRecord(f_ptr->dba_rec);
9759  }
9760 
9761  FUNCTION_FINISH(DBDEF_SetFavouriteListName);
9762 }
9763 
9764 
9775 BOOLEAN DBDEF_ServiceForTunerType(ADB_SERVICE_REC *s_ptr, E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
9776 {
9777  BOOLEAN retval;
9778 
9779  FUNCTION_START(DBDEF_ServiceForTunerType);
9780 
9781  if ((s_ptr != NULL) && (s_ptr->transport != NULL))
9782  {
9783  retval = DBDEF_TransportForTunerType(s_ptr->transport, tuner_type, satellite);
9784  }
9785  else
9786  {
9787  retval = FALSE;
9788  }
9789 
9790  FUNCTION_FINISH(DBDEF_ServiceForTunerType);
9791 
9792  return(retval);
9793 }
9794 
9805 BOOLEAN DBDEF_TransportForTunerType(ADB_TRANSPORT_REC *t_ptr, E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
9806 {
9807  BOOLEAN retval;
9808 
9809  FUNCTION_START(DBDEF_TransportForTunerType);
9810 
9811  if ((t_ptr != NULL) && (t_ptr->sig_type == tuner_type) &&
9812  ((satellite == NULL) || (tuner_type != SIGNAL_QPSK) ||
9813  ((tuner_type == SIGNAL_QPSK) && (t_ptr->network != NULL) &&
9814  (t_ptr->network->satellite == satellite))))
9815  {
9816  retval = TRUE;
9817  }
9818  else
9819  {
9820  retval = FALSE;
9821  }
9822 
9823  FUNCTION_FINISH(DBDEF_TransportForTunerType);
9824 
9825  return(retval);
9826 }
9827 
9833 ADB_TIMER_REC* DBDEF_AddTimerRec(BOOLEAN store_in_nvm)
9834 {
9835  ADB_TIMER_REC *timer;
9836  void *dba_rec;
9837  U32BIT handle;
9838 
9839  FUNCTION_START(DBDEF_AddTimerRec);
9840 
9841  timer = (ADB_TIMER_REC *)STB_AppGetMemory(sizeof(ADB_TIMER_REC));
9842  if (timer != NULL)
9843  {
9844  memset(timer, 0, sizeof(ADB_TIMER_REC));
9845 
9846  /* Find next unused handle */
9847  handle = last_timer_handle + 1;
9848  if (handle == LAST_TIMER_HANDLE)
9849  {
9850  handle = TIMER_HANDLE_BASE;
9851  }
9852 
9853  while (DBDEF_FindTimerRec(handle) != NULL)
9854  {
9855  handle++;
9856  if (handle == LAST_TIMER_HANDLE)
9857  {
9858  handle = TIMER_HANDLE_BASE;
9859  }
9860  }
9861 
9862  last_timer_handle = handle;
9863 
9864  timer->handle = handle;
9865 
9866  if (store_in_nvm)
9867  {
9868  /* Create the database record */
9869  dba_rec = DBA_CreateRecord(DBA_RECORD_TIMER, NULL);
9870  if (dba_rec != NULL)
9871  {
9872  timer->dba_rec = dba_rec;
9873 
9874  DBA_SetFieldValue(dba_rec, DBA_FIELD_TIMER_HANDLE, timer->handle);
9875  }
9876  else
9877  {
9878  STB_AppFreeMemory(timer);
9879  timer = NULL;
9880  }
9881  }
9882 
9883  if (timer != NULL)
9884  {
9885  STB_LLAddBlockToEnd(&timer_list, (LINK_LIST_PTR_BLK *)timer);
9886  }
9887  }
9888 
9889  FUNCTION_FINISH(DBDEF_AddTimerRec);
9890 
9891  return(timer);
9892 }
9893 
9900 {
9901  ADB_TIMER_REC *timer;
9902 
9903  FUNCTION_START(DBDEF_FindTimerRec);
9904 
9905  timer = DBDEF_GetNextTimerRec(NULL);
9906  while ((timer != NULL) && (timer->handle != handle))
9907  {
9908  timer = DBDEF_GetNextTimerRec(timer);
9909  }
9910 
9911  FUNCTION_FINISH(DBDEF_FindTimerRec);
9912 
9913  return(timer);
9914 }
9915 
9923 {
9924  ADB_TIMER_REC *ret_ptr;
9925 
9926  FUNCTION_START(DBDEF_GetNextTimerRec);
9927 
9928  if (timer_ptr == NULL)
9929  {
9930  ret_ptr = (ADB_TIMER_REC *)STB_LLGetFirstBlock(&timer_list);
9931  }
9932  else
9933  {
9934  ret_ptr = (ADB_TIMER_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)timer_ptr);
9935  }
9936 
9937  FUNCTION_FINISH(DBDEF_GetNextTimerRec);
9938 
9939  return(ret_ptr);
9940 }
9941 
9946 void DBDEF_SortTimers(BOOLEAN date_time_order)
9947 {
9948  FUNCTION_START(DBDEF_SortTimers);
9949 
9950  if (date_time_order)
9951  {
9952  STB_LLSort(&timer_list, TimerSortDateTime);
9953  }
9954  else
9955  {
9956  STB_LLSort(&timer_list, TimerSortName);
9957  }
9958 
9959  FUNCTION_FINISH(DBDEF_SortTimers);
9960 }
9961 
9967 {
9968  FUNCTION_START(DBDEF_DeleteTimerRec);
9969 
9970  if (timer != NULL)
9971  {
9973 
9974  if (timer->dba_rec != NULL)
9975  {
9976  DBA_DestroyRecord(timer->dba_rec);
9977  }
9978 
9979  STB_AppFreeMemory(timer);
9980  }
9981 
9982  FUNCTION_FINISH(DBDEF_DeleteTimerRec);
9983 }
9984 
9989 {
9990  U16BIT num_profiles;
9991  ADB_NETWORK_REC *n_ptr;
9992  BOOLEAN broadcast_found;
9993 
9994  FUNCTION_START(DBDEF_GetNumProfiles);
9995 
9996  num_profiles = 0;
9997  broadcast_found = FALSE;
9998 
9999  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
10000  while (n_ptr != NULL)
10001  {
10002  if (n_ptr->profile_type == ADB_PROFILE_TYPE_BROADCAST)
10003  {
10004  /* Only count the broadcast profile once */
10005  if (!broadcast_found)
10006  {
10007  num_profiles++;
10008  broadcast_found = TRUE;
10009  }
10010  }
10011  else
10012  {
10013  num_profiles++;
10014  }
10015 
10017  }
10018 
10019  FUNCTION_FINISH(DBDEF_GetNumProfiles);
10020 
10021  return(num_profiles);
10022 }
10023 
10031 U16BIT DBDEF_GetProfileList(void ***profile_list, U16BIT *active_profile)
10032 {
10033  U16BIT num_profiles;
10034  ADB_NETWORK_REC *n_ptr;
10035  BOOLEAN broadcast_found;
10036 
10037  FUNCTION_START(DBDEF_GetProfileList);
10038 
10039  num_profiles = DBDEF_GetNumProfiles();
10040  if (num_profiles > 0)
10041  {
10042  *profile_list = (void **)STB_AppGetMemory(num_profiles * sizeof(void *));
10043  if (*profile_list != NULL)
10044  {
10045  broadcast_found = FALSE;
10046  num_profiles = 0;
10047 
10048  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
10049  while (n_ptr != NULL)
10050  {
10051  if (n_ptr->profile_type == ADB_PROFILE_TYPE_BROADCAST)
10052  {
10053  /* Only count the broadcast profile once */
10054  if (!broadcast_found)
10055  {
10056  (*profile_list)[num_profiles] = (void *)n_ptr;
10057 
10058  if (current_profile == ADB_PROFILE_TYPE_BROADCAST)
10059  {
10060  /* Return as the current profile */
10061  *active_profile = num_profiles;
10062  }
10063 
10064  num_profiles++;
10065  broadcast_found = TRUE;
10066  }
10067  }
10068  else
10069  {
10070  (*profile_list)[num_profiles] = (void *)n_ptr;
10071 
10072  #ifdef COMMON_INTERFACE
10073  if ((current_profile == n_ptr->profile_type) &&
10074  (cicam_onet_id == n_ptr->cicam_onet_id) &&
10075  (cicam_identifier == n_ptr->cicam_identifier))
10076  {
10077  /* Return as the current profile */
10078  *active_profile = num_profiles;
10079  }
10080  #endif /*COMMON_INTERFACE*/
10081 
10082  num_profiles++;
10083  }
10084 
10086  }
10087  }
10088  else
10089  {
10090  num_profiles = 0;
10091  }
10092  }
10093 
10094  FUNCTION_FINISH(DBDEF_GetProfileList);
10095 
10096  return(num_profiles);
10097 }
10098 
10104 void DBDEF_ReleaseProfileList(void **profile_list, U16BIT num_profiles)
10105 {
10106  FUNCTION_START(DBDEF_ReleaseProfileList);
10107  USE_UNWANTED_PARAM(num_profiles);
10108 
10109  if (profile_list != NULL)
10110  {
10111  STB_AppFreeMemory(profile_list);
10112  }
10113 
10114  FUNCTION_FINISH(DBDEF_ReleaseProfileList);
10115 }
10116 
10123 {
10124  BOOLEAN retval;
10125  ADB_NETWORK_REC *n_ptr;
10126 
10127  FUNCTION_START(DBDEF_IsActiveProfile);
10128 
10129  retval = FALSE;
10130 
10131  n_ptr = (ADB_NETWORK_REC *)STB_LLGetFirstBlock(&network_rec_list);
10132  while (n_ptr != NULL)
10133  {
10134  if (n_ptr == profile)
10135  {
10136  if (n_ptr->profile_type == current_profile)
10137  {
10138  if ((current_profile == ADB_PROFILE_TYPE_BROADCAST)
10139  #ifdef COMMON_INTERFACE
10140  || ((current_profile == ADB_PROFILE_TYPE_CIPLUS) &&
10141  (n_ptr->cicam_onet_id == cicam_onet_id) && (n_ptr->cicam_identifier == cicam_identifier))
10142  #endif /*COMMON_INTERFACE*/
10143  )
10144  {
10145  retval = TRUE;
10146  }
10147  }
10148  break;
10149  }
10150 
10152  }
10153 
10154  FUNCTION_FINISH(DBDEF_IsActiveProfile);
10155 
10156  return(retval);
10157 }
10158 
10163 ADB_PROFILE_TYPE DBDEF_GetCurrentProfileType(void)
10164 {
10165  FUNCTION_START(DBDEF_GetCurrentProfileType);
10166  FUNCTION_FINISH(DBDEF_GetCurrentProfileType);
10167  return(current_profile);
10168 }
10169 
10175 {
10176  FUNCTION_START(DBDEF_SelectBroadcastProfile);
10177  current_profile = ADB_PROFILE_TYPE_BROADCAST;
10178  FUNCTION_FINISH(DBDEF_SelectBroadcastProfile);
10179 }
10180 
10187 {
10188  FUNCTION_START(DBDEF_PushBroadcastProfile);
10189 
10190  pushed_profile = current_profile;
10191 #ifdef COMMON_INTERFACE
10192  if (current_profile == ADB_PROFILE_TYPE_CIPLUS)
10193  {
10194  pushed_cicam_onet_id = cicam_onet_id;
10195  pushed_cicam_identifier = cicam_identifier;
10196  }
10197 #endif
10198  current_profile = ADB_PROFILE_TYPE_BROADCAST;
10199 
10200  FUNCTION_FINISH(DBDEF_PushBroadcastProfile);
10201 }
10202 
10203 #ifdef COMMON_INTERFACE
10204 
10211 void DBDEF_PushCIPlusProfile(U16BIT onet_id, U32BIT cicam_id)
10212 {
10213  FUNCTION_START(DBDEF_SelectCIPlusProfile);
10214 
10215  /* Save the current profile type */
10216  pushed_profile = current_profile;
10217 
10218  if (current_profile == ADB_PROFILE_TYPE_CIPLUS)
10219  {
10220  pushed_cicam_onet_id = cicam_onet_id;
10221  pushed_cicam_identifier = cicam_identifier;
10222  }
10223 
10224  current_profile = ADB_PROFILE_TYPE_CIPLUS;
10225  cicam_onet_id = onet_id;
10226  cicam_identifier = cicam_id;
10227 
10228  FUNCTION_FINISH(DBDEF_SelectCIPlusProfile);
10229 }
10230 
10237 void DBDEF_SelectCIPlusProfile(U16BIT onet_id, U32BIT cicam_id)
10238 {
10239  FUNCTION_START(DBDEF_SelectCIPlusProfile);
10240 
10241  current_profile = ADB_PROFILE_TYPE_CIPLUS;
10242  cicam_onet_id = onet_id;
10243  cicam_identifier = cicam_id;
10244 
10245  FUNCTION_FINISH(DBDEF_SelectCIPlusProfile);
10246 }
10247 
10248 #endif
10249 
10254 {
10255  FUNCTION_START(DBDEF_PopProfile);
10256 
10257  current_profile = pushed_profile;
10258 
10259 #ifdef COMMON_INTERFACE
10260  if (pushed_profile == ADB_PROFILE_TYPE_CIPLUS)
10261  {
10262  cicam_onet_id = pushed_cicam_onet_id;
10263  cicam_identifier = pushed_cicam_identifier;
10264  }
10265 #endif
10266 
10267  FUNCTION_FINISH(DBDEF_PopProfile);
10268 }
10269 
10277 {
10278  BOOLEAN retval;
10279 
10280  FUNCTION_START(DBDEF_ServiceInProfile);
10281 
10282  retval = TRUE;
10283 
10284  if ((s_ptr->transport != NULL) && (s_ptr->transport->network != NULL))
10285  {
10286  if (s_ptr->transport->network->profile_type != current_profile)
10287  {
10288  retval = FALSE;
10289  }
10290 #ifdef COMMON_INTERFACE
10291  else if ((current_profile == ADB_PROFILE_TYPE_CIPLUS) &&
10292  ((s_ptr->transport->network->cicam_onet_id != cicam_onet_id) ||
10293  (s_ptr->transport->network->cicam_identifier != cicam_identifier)))
10294  {
10295  /* Profile is CI+, but for a different CAM */
10296  retval = FALSE;
10297  }
10298 #endif
10299  }
10300 
10301  FUNCTION_FINISH(DBDEF_ServiceInProfile);
10302 
10303  return(retval);
10304 }
10305 
10313 {
10314  BOOLEAN retval;
10315 
10316  FUNCTION_START(DBDEF_TransportInProfile);
10317 
10318  retval = TRUE;
10319 
10320  if (t_ptr->network != NULL)
10321  {
10322  if (t_ptr->network->profile_type != current_profile)
10323  {
10324  retval = FALSE;
10325  }
10326 #ifdef COMMON_INTERFACE
10327  else if ((current_profile == ADB_PROFILE_TYPE_CIPLUS) &&
10328  ((t_ptr->network->cicam_onet_id != cicam_onet_id) ||
10329  (t_ptr->network->cicam_identifier != cicam_identifier)))
10330  {
10331  /* Profile is CI+, but for a different CAM */
10332  retval = FALSE;
10333  }
10334 #endif
10335  }
10336 
10337  FUNCTION_FINISH(DBDEF_TransportInProfile);
10338 
10339  return(retval);
10340 }
10341 
10349 {
10350  BOOLEAN retval;
10351 
10352  FUNCTION_START(DBDEF_NetworkInProfile);
10353 
10354  retval = TRUE;
10355 
10356  if (n_ptr->profile_type != current_profile)
10357  {
10358  retval = FALSE;
10359  }
10360 #ifdef COMMON_INTERFACE
10361  else if ((current_profile == ADB_PROFILE_TYPE_CIPLUS) &&
10362  ((n_ptr->cicam_onet_id != cicam_onet_id) ||
10363  (n_ptr->cicam_identifier != cicam_identifier)))
10364  {
10365  /* Profile is CI+, but for a different CAM */
10366  retval = FALSE;
10367  }
10368 #endif
10369 
10370  FUNCTION_FINISH(DBDEF_NetworkInProfile);
10371 
10372  return(retval);
10373 }
10374 
10375 #ifdef COMMON_INTERFACE
10376 /*!**************************************************************************
10377  * @brief Finds the CI+ profile network record
10378  * @param cicam_onet_id CI+ private network id
10379  * @param cicam_identifier CI+ CAM identifier
10380  * @return Pointer to the network record or NULL if not found
10381  ****************************************************************************/
10382 ADB_NETWORK_REC* DBDEF_FindNetworkForCIPlusProfile(U16BIT cicam_onet_id, U32BIT cicam_identifier)
10383 {
10384  ADB_NETWORK_REC *n_ptr;
10385 
10386  FUNCTION_START(DBDEF_FindNetworkForCIPlusProfile);
10387 
10388  n_ptr = DBDEF_GetNextNetworkRec(NULL);
10389  while (n_ptr != NULL)
10390  {
10391  if ((n_ptr->profile_type == ADB_PROFILE_TYPE_CIPLUS) && (n_ptr->cicam_onet_id == cicam_onet_id) &&
10392  (n_ptr->cicam_identifier == cicam_identifier))
10393  {
10394  break;
10395  }
10396 
10397  n_ptr = DBDEF_GetNextNetworkRec(n_ptr);
10398  }
10399 
10400  FUNCTION_FINISH(DBDEF_FindNetworkForCIPlusProfile);
10401 
10402  return(n_ptr);
10403 }
10404 
10405 /*!**************************************************************************
10406  * @brief Finds the CI+ profile network record for the given module.
10407  * The module must be present for the record to be found
10408  * @param module CI+ operator module
10409  * @return Pointer to the network record or NULL if not found
10410  ****************************************************************************/
10411 ADB_NETWORK_REC* DBDEF_FindNetworkForCIPlusModule(U32BIT module)
10412 {
10413  ADB_NETWORK_REC *n_ptr;
10414 
10415  FUNCTION_START(DBDEF_FindNetworkForCIPlusModule);
10416 
10417  n_ptr = DBDEF_GetNextNetworkRec(NULL);
10418  while (n_ptr != NULL)
10419  {
10420  if ((n_ptr->profile_type == ADB_PROFILE_TYPE_CIPLUS) && n_ptr->module_present &&
10421  (n_ptr->module == module))
10422  {
10423  break;
10424  }
10425 
10426  n_ptr = DBDEF_GetNextNetworkRec(n_ptr);
10427  }
10428 
10429  FUNCTION_FINISH(DBDEF_FindNetworkForCIPlusModule);
10430 
10431  return(n_ptr);
10432 }
10433 
10438 ADB_NETWORK_REC *DBDEF_GetCurrentCIPlusProfile(void)
10439 {
10440  ADB_NETWORK_REC *n_ptr = NULL;
10441 
10442  FUNCTION_START(DBDEF_GetCurrentCIPlusProfile);
10443 
10444  if (current_profile == ADB_PROFILE_TYPE_CIPLUS)
10445  {
10446  n_ptr = DBDEF_FindNetworkForCIPlusProfile(cicam_onet_id, cicam_identifier);
10447  }
10448 
10449  FUNCTION_FINISH(DBDEF_GetCurrentCIPlusProfile);
10450 
10451  return n_ptr;
10452 }
10453 
10460 ADB_CICAM_TIMER_REC* DBDEF_AddCicamTimer(U32BIT cicam_id, U32BIT timer_handle)
10461 {
10462  ADB_CICAM_TIMER_REC *t;
10463  void *dba_rec;
10464 
10465  FUNCTION_START(DBDEF_AddCicamTimer);
10466 
10467  DBA_LockDatabase();
10468  dba_rec = DBA_CreateRecord(DBA_RECORD_CICAM_TIMER, NULL);
10469  if (dba_rec != NULL)
10470  {
10471  t = (ADB_CICAM_TIMER_REC *)STB_AppGetMemory(sizeof(ADB_CICAM_TIMER_REC));
10472  if (t != NULL)
10473  {
10474  t->dba_rec = dba_rec;
10475  t->cicam_identifier = cicam_id;
10476  DBA_SetFieldValue(dba_rec, DBA_FIELD_TIMER_HANDLE, t->cicam_identifier);
10477  t->timer_handle = timer_handle;
10478  DBA_SetFieldValue(dba_rec, DBA_FIELD_PROFILE_CAM_ID, t->timer_handle);
10479 
10480  STB_LLAddBlockToEnd(&cicam_timer_list, (LINK_LIST_PTR_BLK *)t);
10481  DBA_SaveRecord(dba_rec);
10482  DBA_SaveDatabase();
10483  }
10484  else
10485  {
10486  DBA_DestroyRecord(dba_rec);
10487  }
10488  }
10489  else
10490  {
10491  t = NULL;
10492  }
10494 
10495  FUNCTION_FINISH(DBDEF_AddCicamTimer);
10496 
10497  return t;
10498 }
10499 
10504 void DBDEF_DeleteCicamTimerRec(ADB_CICAM_TIMER_REC *cicam_timer_ptr)
10505 {
10506  FUNCTION_START(DBDEF_DeleteCicamTimerRec);
10507 
10508  STB_LLRemoveBlock(&cicam_timer_ptr->ptrs);
10509  DBA_LockDatabase();
10510  DBA_DestroyRecord(cicam_timer_ptr->dba_rec);
10511  DBA_SaveDatabase();
10513  STB_AppFreeMemory(cicam_timer_ptr);
10514 
10515  FUNCTION_FINISH(DBDEF_DeleteCicamTimerRec);
10516 }
10517 
10524 ADB_CICAM_TIMER_REC* DBDEF_GetNextCicamTimerRec(ADB_CICAM_TIMER_REC *cicam_timer_ptr)
10525 {
10526  ADB_CICAM_TIMER_REC *t_ptr;
10527 
10528  FUNCTION_START(DBDEF_GetNextCicamTimerRec);
10529 
10530  if (cicam_timer_ptr == NULL)
10531  {
10532  t_ptr = (ADB_CICAM_TIMER_REC *)STB_LLGetFirstBlock(&cicam_timer_list);
10533  }
10534  else
10535  {
10536  t_ptr = (ADB_CICAM_TIMER_REC *)STB_LLGetNextBlock((LINK_LIST_PTR_BLK *)cicam_timer_ptr);
10537  }
10538 
10539  FUNCTION_FINISH(DBDEF_GetNextCicamTimerRec);
10540 
10541  return(t_ptr);
10542 }
10543 
10549 ADB_CICAM_TIMER_REC* DBDEF_FindCicamTimer(U32BIT cicam_id)
10550 {
10551  ADB_CICAM_TIMER_REC *t;
10552 
10553  FUNCTION_START(DBDEF_FindCicamTimer);
10554 
10555  t = DBDEF_GetNextCicamTimerRec(NULL);
10556  while (t != NULL)
10557  {
10558  if (t->cicam_identifier == cicam_id)
10559  {
10560  break;
10561  }
10562  t = DBDEF_GetNextCicamTimerRec(t);
10563  }
10564 
10565  FUNCTION_FINISH(DBDEF_FindCicamTimer)
10566 
10567  return t;
10568 }
10569 
10575 ADB_CICAM_TIMER_REC* DBDEF_FindCicamTimerByHandle(U32BIT handle)
10576 {
10577  ADB_CICAM_TIMER_REC *t;
10578 
10579  FUNCTION_START(DBDEF_FindCicamTimerByHandle);
10580 
10581  t = DBDEF_GetNextCicamTimerRec(NULL);
10582  while (t != NULL)
10583  {
10584  if (t->timer_handle == handle)
10585  {
10586  break;
10587  }
10588  t = DBDEF_GetNextCicamTimerRec(t);
10589  }
10590 
10591  FUNCTION_FINISH(DBDEF_FindCicamTimerByHandle)
10592 
10593  return t;
10594 }
10595 
10596 #endif /*COMMON_INTERFACE*/
10597 
10604 {
10605  ADB_NETWORK_REC *n_ptr;
10606  U16BIT net_id;
10607 
10608  FUNCTION_START(DBDEF_FindOrAddPrivateNetwork);
10609 
10610  n_ptr = NULL;
10611  net_id = PRIVATE_NETWORK_ID0;
10612 
10613  /* Check to see if there's a private network for the given satellite */
10614  while ((n_ptr = DBDEF_FindNetworkRec(net_id, NULL)) != NULL)
10615  {
10616  if (n_ptr->satellite == satellite)
10617  {
10618  /* Found a private network for the given satellite */
10619  break;
10620  }
10621 
10622  /* Try the next private network id */
10623  net_id++;
10624  }
10625 
10626  if (n_ptr == NULL)
10627  {
10628  /* No network found so need to add one */
10629  if ((n_ptr = DBDEF_AddNetworkRec(net_id, satellite)) != NULL)
10630  {
10631  DBA_SaveRecord(n_ptr->dba_rec);
10632  }
10633  }
10634 
10635  FUNCTION_FINISH(DBDEF_FindOrAddPrivateNetwork);
10636 
10637  return(n_ptr);
10638 }
10639 
10640 //--------------------------------------------------------------------------------------------------
10641 // local function definitions
10642 //--------------------------------------------------------------------------------------------------
10643 
10644 /*!**************************************************************************
10645  * @brief Deletes an LNB record from the RAM database
10646  * @param lnb_ptr pointer to record to be deleted
10647  ****************************************************************************/
10648 static void DeleteLNBRec(ADB_LNB_REC *lnb_ptr)
10649 {
10650  FUNCTION_START(DeleteLNBRec);
10651 
10652  STB_LLRemoveBlock(&lnb_ptr->ptrs);
10653 
10654  if (lnb_ptr->name != NULL)
10655  {
10656  DBDEF_ReleaseString(lnb_ptr->name);
10657  }
10658 
10659  DBA_DestroyRecord(lnb_ptr->dba_rec);
10660 
10661  STB_AppFreeMemory(lnb_ptr);
10662 
10663  FUNCTION_FINISH(DeleteLNBRec);
10664 }
10665 
10666 /*!**************************************************************************
10667  * @brief Deletes a satellite record from the RAM database
10668  * @param sat_ptr pointer to record to be deleted
10669  ****************************************************************************/
10670 static void DeleteSatelliteRec(ADB_SATELLITE_REC *sat_ptr)
10671 {
10672  ADB_BAT_VERSION_REC *ver_rec;
10673 
10674  FUNCTION_START(DeleteSatelliteRec);
10675 
10676  STB_LLRemoveBlock(&sat_ptr->ptrs);
10677 
10678  if (sat_ptr->name != NULL)
10679  {
10680  DBDEF_ReleaseString(sat_ptr->name);
10681  }
10682 
10683  if (sat_ptr->def_authority != NULL)
10684  {
10685  DBDEF_ReleaseString(sat_ptr->def_authority);
10686  }
10687 
10688  ver_rec = sat_ptr->bat_version_list;
10689  while (ver_rec != NULL)
10690  {
10691  sat_ptr->bat_version_list = ver_rec->next;
10692  STB_AppFreeMemory(ver_rec);
10693  ver_rec = sat_ptr->bat_version_list;
10694  }
10695 
10696  DBA_DestroyRecord(sat_ptr->dba_rec);
10697 
10698  STB_AppFreeMemory(sat_ptr);
10699 
10700  FUNCTION_FINISH(DeleteSatelliteRec);
10701 }
10702 
10714 static void DeleteNetworkRec(ADB_NETWORK_REC *n_ptr)
10715 {
10716  U8BIT i;
10717 
10718  FUNCTION_START(DeleteNetworkRec);
10719 
10720  STB_LLRemoveBlock(&n_ptr->ptrs);
10721 
10722  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
10723  {
10724  if (n_ptr->name_array[i] != NULL)
10725  {
10726  STB_AppFreeMemory(n_ptr->name_array[i]);
10727  }
10728  }
10729 
10730  if (n_ptr->name_str != NULL)
10731  {
10732  STB_AppFreeMemory(n_ptr->name_str);
10733  }
10734 
10735  DBA_DestroyRecord(n_ptr->dba_rec);
10736 
10737  STB_AppFreeMemory(n_ptr);
10738 
10739  FUNCTION_FINISH(DeleteNetworkRec);
10740 }
10741 
10742 #ifdef DEBUG_PRINT_DATABASE
10743 /*!**************************************************************************
10744  * @brief Print details of the spcified LNB record
10745  * @param lnb_ptr pointer to LNB record
10746  ****************************************************************************/
10747 static void PrintLNBRec(ADB_LNB_REC *lnb_ptr)
10748 {
10749  static const char *diseqc_cswitch[] = { "Off", "1", "2", "3", "4" };
10750  static const char *diseqc_tone_burst[] = { "Off", "A", "B" };
10751 
10752  FUNCTION_START(PrintLNBRec);
10753 
10754  STB_SPDebugWrite("\t\tType: %s", (lnb_ptr->type == LNB_TYPE_SINGLE ? "Single" : "Universal"));
10755  STB_SPDebugWrite("\t\tFreq lo: %d", lnb_ptr->freq_low);
10756  if (lnb_ptr->type == LNB_TYPE_UNIVERSAL)
10757  {
10758  STB_SPDebugWrite("\t\tFreq hi: %d", lnb_ptr->freq_high);
10759  }
10760 
10761  if (lnb_ptr->is_pulse_posn)
10762  {
10763  STB_SPDebugWrite("\t\tLNB motor: pulse");
10764  }
10765  else
10766  {
10767  if (lnb_ptr->is_diseqc_posn)
10768  {
10769  STB_SPDebugWrite("\t\tLNB motor: DiSEqC 1.2");
10770  }
10771  else
10772  {
10773  STB_SPDebugWrite("\t\tLNB motor: none");
10774  }
10775  }
10776 
10777  STB_SPDebugWrite("\t\tDiSEqC 1.0 (c-switch): %s", diseqc_cswitch[lnb_ptr->c_switch]);
10778  if (lnb_ptr->u_switch)
10779  {
10780  STB_SPDebugWrite("\t\tDiSEqC 1.1 (u-switch): %d", lnb_ptr->u_switch);
10781  }
10782  else
10783  {
10784  STB_SPDebugWrite("\t\tDiSEqC 1.1 (u-switch): None");
10785  }
10786 
10787  STB_SPDebugWrite("\t\tDiSEqC repeats: %d", lnb_ptr->diseqc_repeats);
10788  STB_SPDebugWrite("\t\tDiSEqC tone burst: %s", diseqc_tone_burst[lnb_ptr->diseqc_tone]);
10789  STB_SPDebugWrite("\t\t12v: %d", (lnb_ptr->is_12v ? "On" : "Off"));
10790  if (lnb_ptr->type == LNB_TYPE_SINGLE)
10791  {
10792  STB_SPDebugWrite("\t\t22k: %d", (lnb_ptr->is_22k ? "On" : "Off"));
10793  }
10794 
10795  STB_SPDebugWrite("\t\tSMATV %d", (lnb_ptr->is_smatv ? "On" : "Off"));
10796 
10797  FUNCTION_FINISH(PrintLNBRec);
10798 }
10799 
10800 /*!**************************************************************************
10801  * @brief Print details of the spcified satellite record
10802  * @param sat_ptr pointer to satellite record
10803  ****************************************************************************/
10804 static void PrintSatelliteRec(ADB_SATELLITE_REC *sat_ptr)
10805 {
10806  S16BIT long_pos;
10807  char ewc;
10808  FUNCTION_START(PrintSatelliteRec);
10809 
10810  if (sat_ptr->name.str_ptr != NULL)
10811  {
10812  STB_SPDebugWrite("\t\tSatellite name: \"%s\"", sat_ptr->name.str_ptr);
10813  }
10814  long_pos = sat_ptr->long_pos;
10815  if (long_pos < 0)
10816  {
10817  long_pos *= -1;
10818  ewc = 'W';
10819  }
10820  else
10821  {
10822  ewc = 'E';
10823  }
10824  STB_SPDebugWrite("\t\tPosition: %d.%01d %c", long_pos / 10, long_pos % 10, ewc );
10825 
10826  FUNCTION_FINISH(PrintSatelliteRec);
10827 }
10828 
10840 static void PrintNetworkRec(ADB_NETWORK_REC *n_ptr)
10841 {
10842  U8BIT i;
10843 
10844  FUNCTION_START(PrintNetworkRec);
10845 
10846  STB_SPDebugWrite("\t\tNetwork id: %d", n_ptr->net_id);
10847 
10848  if (n_ptr->name_str != NULL)
10849  {
10850  STB_SPDebugWrite("\t\tNetwork name: \"%s\"", n_ptr->name_str->str_ptr);
10851  }
10852 
10853  STB_SPDebugWrite("\t\tDB rec: 0x%x", n_ptr->stb_db_rec);
10854 #if 0
10855  if (n_ptr->stb_db_rec != NULL)
10856  {
10857  STB_PrintRecord(n_ptr->stb_db_rec);
10858  }
10859 #endif
10860 
10861  for (i = 0; i < ACFG_NUM_DB_LANGUAGES; i++)
10862  {
10863  if ((n_ptr->name_array[i] != NULL) &&
10864  (n_ptr->name_array[i]->nbytes > 0))
10865  {
10866  STB_SPDebugWrite("\t\tName %d: %s", i, n_ptr->name_array[i]->str_ptr);
10867  }
10868  }
10869 
10870  STB_SPDebugWrite("\t\tProfile type: %u", n_ptr->profile_type);
10871 
10872  STB_SPDebugWrite("\t\tSatellite 0x%x", n_ptr->satellite);
10873 
10874  FUNCTION_FINISH(PrintNetworkRec);
10875 }
10876 
10877 #endif /* DEBUG_PRINT_DATABASE */
10878 
10879 #ifdef DEBUG_PRINT_DATABASE
10880 
10891 static void PrintTransportRec(ADB_TRANSPORT_REC *t_ptr)
10892 {
10893  FUNCTION_START(PrintTransportRec);
10894 
10895  if (t_ptr->name_str != NULL)
10896  {
10897  STB_SPDebugWrite("\t\tTransport name: \"%s\"", ACTL_GetRfNameFromFreq(t_ptr->sig_type, t_ptr->freq_hz));
10898  }
10899 
10900  STB_SPDebugWrite("\t\tTransport id: %d", t_ptr->tran_id);
10901  STB_SPDebugWrite("\t\tOriginal network id: %d", t_ptr->orig_net_id);
10902  STB_SPDebugWrite("\t\tParent network: 0x%x", t_ptr->network);
10903 
10904  STB_SPDebugWrite("\t\tDB rec: 0x%x", t_ptr->stb_db_rec);
10905 #if 0
10906  if (t_ptr->stb_db_rec != NULL)
10907  {
10908  STB_PrintRecord(t_ptr->stb_db_rec);
10909  }
10910 #endif
10911 
10912  STB_SPDebugWrite("\t\tFreq: %dHz", t_ptr->freq_hz);
10913  STB_SPDebugWrite("\t\tPAT version: %d", t_ptr->pat_version);
10914  STB_SPDebugWrite("\t\tSDT version: %d", t_ptr->sdt_version);
10915  STB_SPDebugWrite("\t\tPMT version list: 0x%x", t_ptr->pmt_version_list);
10916 // STB_SPDebugWrite("\t\tEIT version list: 0x%x", t_ptr->eit_version_list);
10917 
10918  FUNCTION_FINISH(PrintTransportRec);
10919 }
10920 
10921 #endif
10922 
10923 #ifdef DEBUG_PRINT_DATABASE
10924 
10935 static void PrintServiceRec(ADB_SERVICE_REC *s_ptr)
10936 {
10937  FUNCTION_START(PrintServiceRec);
10938 
10939  if (s_ptr->name_str != NULL)
10940  {
10941  STB_SPDebugWrite("\t\tService name: \"%s\"", s_ptr->name_str->str_ptr);
10942  }
10943 
10944  STB_SPDebugWrite("\t\tService id: %d", s_ptr->serv_id);
10945 
10946  if (s_ptr->provider_str != NULL)
10947  {
10948  STB_SPDebugWrite("\t\tProvider: \"%s\"", s_ptr->provider_str->str_ptr);
10949  }
10950 
10951  STB_SPDebugWrite("\t\tDB rec: 0x%x", s_ptr->stb_db_rec);
10952 #if 0
10953  if (s_ptr->stb_db_rec != NULL)
10954  {
10955  STB_PrintRecord(s_ptr->stb_db_rec);
10956  }
10957 #endif
10958 
10959  STB_SPDebugWrite("\t\tService LCN: %d", s_ptr->serv_lcn);
10960  STB_SPDebugWrite("\t\tAllocated LCN: %d", s_ptr->allocated_lcn);
10961  STB_SPDebugWrite("\t\tScrambled: %s", (s_ptr->scrambled ? "Yes" : "No"));
10962  STB_SPDebugWrite("\t\tParent transport: 0x%x", s_ptr->transport);
10963  STB_SPDebugWrite("\t\tNow/next available: %s", (s_ptr->eit_now_next_avail ? "Yes" : "No"));
10964  STB_SPDebugWrite("\t\tSchedule available: %s", (s_ptr->eit_sched_avail ? "Yes" : "No"));
10965  STB_SPDebugWrite("\t\tDeleted: %u", s_ptr->deleted);
10966 
10967  STB_SPDebugWrite("\t\tPCR PID: %d", s_ptr->pcr_pid);
10968  STB_SPDebugWrite("\t\tVideo PID: %d", s_ptr->video_pid);
10969  STB_SPDebugWrite("\t\tAudio PID: %d", s_ptr->audio_pid);
10970  STB_SPDebugWrite("\t\tSubtitle PID: %d", s_ptr->subtitle_pid);
10971  STB_SPDebugWrite("\t\tTeletext PID: %d", s_ptr->ttext_pid);
10972  STB_SPDebugWrite("\t\tTeletext lang code: 0x%x", s_ptr->reqd_ttext_lang_code);
10973 
10974  STB_SPDebugWrite("\t\tRunning status: %u", s_ptr->running_status);
10975  STB_SPDebugWrite("\t\tService running: %s", (s_ptr->not_running ? "No" : "Yes"));
10976 
10977  FUNCTION_FINISH(PrintServiceRec);
10978 }
10979 
10980 #endif
10981 
10982 /*!**************************************************************************
10983  * @brief Gets a required audio pid
10984  * @param s_ptr service record ptr
10985  * @param audio_mode pointer to the returned channel setting (mono, stereo, left, right)
10986  * @param audio_type pointer to the type of audio
10987  * @param db_lang_ids Language ids to be matching
10988  * @param primary_found If it found the required language
10989  * @return U16BIT - Found Pid
10990  ****************************************************************************/
10991 static U16BIT GetReqdAudioPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *audio_mode,
10992  ADB_STREAM_TYPE *audio_type, U8BIT *db_lang_ids, BOOLEAN *primary_found, ADB_STREAM_REC **selected_stream)
10993 {
10994  U16BIT audio_pid;
10995  ADB_STREAM_REC *stream_rec;
10996  ADB_STREAM_REC *nzero_pid_stream;
10997  ADB_STREAM_REC *lang_code_match_stream;
10998  ADB_STREAM_REC *qaa_match_stream;
10999  ADB_STREAM_REC *audio_type_match_stream;
11000  ADB_STREAM_REC *default_match_stream;
11001  ADB_STREAM_REC *exact_match_stream;
11002  U32BIT def_lang_code;
11003  ADB_AUDIO_TYPE def_audio_type;
11004  BOOLEAN prefer_hd_stream;
11005  U8BIT stream_priority;
11006  U8BIT def_stream_priority;
11007  U8BIT lang_stream_priority;
11008  U8BIT qaa_stream_priority;
11009  U8BIT type_stream_priority;
11010  U8BIT nzero_stream_priority;
11011  U8BIT lang_lang_priority;
11012  U8BIT def_lang_priority;
11013  U8BIT i;
11014 
11015  FUNCTION_START(GetReqdAudioPid);
11016 
11017  audio_pid = 0;
11018  *audio_mode = AUDIO_STEREO;
11019  *audio_type = ADB_AUDIO_STREAM;
11020  *primary_found = FALSE;
11021  *selected_stream = NULL;
11022 
11023  if (s_ptr != NULL)
11024  {
11025  nzero_pid_stream = NULL;
11026  lang_code_match_stream = NULL;
11027  qaa_match_stream = NULL;
11028  audio_type_match_stream = NULL;
11029  default_match_stream = NULL;
11030  exact_match_stream = NULL;
11031  def_stream_priority = 0;
11032  lang_stream_priority = 0;
11033  qaa_stream_priority = 0;
11034  type_stream_priority = 0;
11035  nzero_stream_priority = 0;
11036  lang_lang_priority = ACFG_MAX_DB_LANG_CODES;
11037  def_lang_priority = ACFG_MAX_DB_LANG_CODES;
11038 
11039  def_audio_type = (ADB_AUDIO_TYPE)APP_NvmRead(AUDIO_TYPE_NVM);
11040  prefer_hd_stream = APP_NvmRead(PREFER_HD_AUDIO_NVM);
11041 
11042  stream_rec = s_ptr->stream_list;
11043  while (stream_rec != NULL)
11044  {
11045  if ((stream_rec->type == ADB_AUDIO_STREAM) ||
11046  (stream_rec->type == ADB_AAC_AUDIO_STREAM) ||
11047  (stream_rec->type == ADB_HEAAC_AUDIO_STREAM) ||
11048  (stream_rec->type == ADB_AC3_AUDIO_STREAM) ||
11049  (stream_rec->type == ADB_EAC3_AUDIO_STREAM)
11050  )
11051  {
11052  // ensure in use flag is cleared
11053  stream_rec->in_use = FALSE;
11054 
11055  if (stream_rec->pid != 0)
11056  {
11057  // if the audio has been required by PID and it matches, consider this an exact match
11058  if ((s_ptr->reqd_audio_pid < 0x1FFF) && (s_ptr->reqd_audio_pid == stream_rec->pid))
11059  {
11060  exact_match_stream = stream_rec;
11061  *primary_found = TRUE;
11062  }
11063  // is this audio stream an exact match for the reqd audio settings?
11064  else if ((s_ptr->reqd_audio_valid == TRUE) &&
11065  (exact_match_stream == NULL) &&
11066  (stream_rec->data.audio.lang_code == s_ptr->reqd_audio_lang_code) &&
11067  (stream_rec->data.audio.type == s_ptr->reqd_audio_type) &&
11068  (stream_rec->type == s_ptr->reqd_stream_type))
11069  {
11070  // yes - found it!
11071  exact_match_stream = stream_rec;
11072  *primary_found = TRUE;
11073  }
11074  else
11075  {
11076  stream_priority = AudioStreamPriority(stream_rec->type);
11077 
11078  if (db_lang_ids != NULL)
11079  {
11080  // if not an exact match, check if this stream matches the default lang and type
11081  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) && (db_lang_ids[i] != ACFG_INVALID_DB_LANG); i++)
11082  {
11083  def_lang_code = ACFG_ConvertLangIdToCode(db_lang_ids[i]);
11084 
11085  if ((def_lang_code == stream_rec->data.audio.lang_code) &&
11086  ((def_audio_type == ADB_AUDIO_TYPE_UNDEFINED) ||
11087  (def_audio_type == ADB_AUDIO_TYPE_CLEAN_EFFECTS)) &&
11088  (def_audio_type == stream_rec->data.audio.type))
11089  {
11090  if ((default_match_stream == NULL) || (i < def_lang_priority))
11091  {
11092  /* No stream selected yet so use this one */
11093  default_match_stream = stream_rec;
11094  def_stream_priority = stream_priority;
11095  def_lang_priority = i;
11096  *primary_found = TRUE;
11097  }
11098  else
11099  {
11100  /* Check whether this stream uses a better encoding
11101  * than the currently selected one */
11102  if (!prefer_hd_stream)
11103  {
11104  /* The minimum match needs to be found if the output is PCM */
11105  if (stream_priority < def_stream_priority)
11106  {
11107  /* This stream is a better match so use it instead */
11108  default_match_stream = stream_rec;
11109  def_stream_priority = stream_priority;
11110  }
11111  else if (stream_priority == def_stream_priority)
11112  {
11113  /* Both streams use the same codec so a non-multichannel one
11114  * should be selected, if available */
11115  if ((default_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11116  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11117  {
11118  /* This stream is a better match so use it instead */
11119  default_match_stream = stream_rec;
11120  def_stream_priority = stream_priority;
11121  }
11122  }
11123  }
11124  else
11125  {
11126  if (stream_priority > def_stream_priority)
11127  {
11128  /* This stream has better audio encoding so select it instead */
11129  default_match_stream = stream_rec;
11130  def_stream_priority = stream_priority;
11131  }
11132  else if (stream_priority == def_stream_priority)
11133  {
11134  /* Both streams use the same codec so a multichannel one
11135  * should be selected, if available */
11136  if ((default_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
11137  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
11138  {
11139  /* This stream is a better match so use it instead */
11140  default_match_stream = stream_rec;
11141  def_stream_priority = stream_priority;
11142  }
11143  }
11144  }
11145  }
11146  }
11147 
11148  /* Does it match the default language, but not if it's an AD stream?
11149  * In the D-Book, "und" is defined as being assumed to be English, in
11150  * which case it should be chosen above "qaa". */
11151  if (((def_lang_code == stream_rec->data.audio.lang_code) ||
11152  (stream_rec->data.audio.lang_code == ADB_LANG_CODE_UNDEF)) &&
11153  (stream_rec->data.audio.type != ADB_AUDIO_TYPE_FOR_VISUALLY_IMPAIRED))
11154  {
11155  if ((lang_code_match_stream == NULL) || (i < lang_lang_priority))
11156  {
11157  /* No stream selected yet so use this one */
11158  lang_code_match_stream = stream_rec;
11159  lang_stream_priority = stream_priority;
11160  lang_lang_priority = i;
11161  }
11162  else
11163  {
11164  /* Check whether this stream uses a better encoding
11165  * than the currently selected one */
11166  if (!prefer_hd_stream)
11167  {
11168  /* The minimum match needs to be found if the output is PCM */
11169  if (stream_priority < lang_stream_priority)
11170  {
11171  /* This stream is a better match so use it instead */
11172  lang_code_match_stream = stream_rec;
11173  lang_stream_priority = stream_priority;
11174  }
11175  else if (stream_priority == lang_stream_priority)
11176  {
11177  /* Both streams use the same codec so a non-multichannel one
11178  * should be selected, if available */
11179  if ((lang_code_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11180  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11181  {
11182  /* This stream is a better match so use it instead */
11183  lang_code_match_stream = stream_rec;
11184  lang_stream_priority = stream_priority;
11185  }
11186  }
11187  }
11188  else
11189  {
11190  if (stream_priority > lang_stream_priority)
11191  {
11192  /* This stream has better audio encoding so select it instead */
11193  lang_code_match_stream = stream_rec;
11194  lang_stream_priority = stream_priority;
11195  }
11196  else if (stream_priority == lang_stream_priority)
11197  {
11198  /* Both streams use the same codec so a multichannel one
11199  * should be selected, if available */
11200  if ((lang_code_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
11201  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
11202  {
11203  /* This stream is a better match so use it instead */
11204  lang_code_match_stream = stream_rec;
11205  lang_stream_priority = stream_priority;
11206  }
11207  }
11208  }
11209  }
11210  }
11211 
11212  /* Is it the Original Language Soundtrack? */
11213  if ((stream_rec->data.audio.lang_code == ADB_LANG_CODE_QAA) &&
11214  (stream_rec->data.audio.type != ADB_AUDIO_TYPE_FOR_VISUALLY_IMPAIRED))
11215  {
11216  if (qaa_match_stream == NULL)
11217  {
11218  qaa_match_stream = stream_rec;
11219  qaa_stream_priority = stream_priority;
11220  }
11221  else
11222  {
11223  /* Check whether this stream uses a better encoding
11224  * than the currently selected one */
11225  if (!prefer_hd_stream)
11226  {
11227  /* The minimum match needs to be found if the output is PCM */
11228  if (stream_priority < qaa_stream_priority)
11229  {
11230  /* This stream is a better match so use it instead */
11231  qaa_match_stream = stream_rec;
11232  qaa_stream_priority = stream_priority;
11233  }
11234  else if (stream_priority == qaa_stream_priority)
11235  {
11236  /* Both streams use the same codec so a non-multichannel one
11237  * should be selected, if available */
11238  if ((qaa_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11239  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11240  {
11241  /* This stream is a better match so use it instead */
11242  qaa_match_stream = stream_rec;
11243  qaa_stream_priority = stream_priority;
11244  }
11245  }
11246  }
11247  else
11248  {
11249  if (stream_priority > qaa_stream_priority)
11250  {
11251  /* This stream has better audio encoding so select it instead */
11252  qaa_match_stream = stream_rec;
11253  qaa_stream_priority = stream_priority;
11254  }
11255  else if (stream_priority == qaa_stream_priority)
11256  {
11257  /* Both streams use the same codec so a multichannel one
11258  * should be selected, if available */
11259  if ((qaa_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
11260  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
11261  {
11262  /* This stream is a better match so use it instead */
11263  qaa_match_stream = stream_rec;
11264  qaa_stream_priority = stream_priority;
11265  }
11266  }
11267  }
11268  }
11269  }
11270  }
11271  }
11272 
11273  // does it match the default type only
11274  if (((def_audio_type == ADB_AUDIO_TYPE_UNDEFINED) ||
11275  (def_audio_type == ADB_AUDIO_TYPE_CLEAN_EFFECTS)) &&
11276  (def_audio_type == stream_rec->data.audio.type))
11277  {
11278  if (audio_type_match_stream == NULL)
11279  {
11280  audio_type_match_stream = stream_rec;
11281  type_stream_priority = stream_priority;
11282  }
11283  else
11284  {
11285  /* Check whether this stream uses a better encoding
11286  * than the currently selected one */
11287  if (!prefer_hd_stream)
11288  {
11289  /* The minimum match needs to be found if the output is PCM */
11290  if (stream_priority < type_stream_priority)
11291  {
11292  /* This stream is a better match so use it instead */
11293  audio_type_match_stream = stream_rec;
11294  type_stream_priority = stream_priority;
11295  }
11296  else if (stream_priority == type_stream_priority)
11297  {
11298  /* Both streams use the same codec so a non-multichannel one
11299  * should be selected, if available */
11300  if ((audio_type_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11301  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11302  {
11303  /* This stream is a better match so use it instead */
11304  audio_type_match_stream = stream_rec;
11305  type_stream_priority = stream_priority;
11306  }
11307  }
11308  }
11309  else
11310  {
11311  if (stream_priority > type_stream_priority)
11312  {
11313  /* This stream has better audio encoding so select it instead */
11314  audio_type_match_stream = stream_rec;
11315  type_stream_priority = stream_priority;
11316  }
11317  else if (stream_priority == type_stream_priority)
11318  {
11319  /* Both streams use the same codec so a multichannel one
11320  * should be selected, if available */
11321  if ((audio_type_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
11322  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
11323  {
11324  /* This stream is a better match so use it instead */
11325  audio_type_match_stream = stream_rec;
11326  type_stream_priority = stream_priority;
11327  }
11328  }
11329  }
11330  }
11331  }
11332 
11333  // is this the first non-zero pid
11334  if (nzero_pid_stream == NULL)
11335  {
11336  nzero_pid_stream = stream_rec;
11337  nzero_stream_priority = stream_priority;
11338  }
11339  else
11340  {
11341  /* Check whether this stream uses a better encoding
11342  * than the currently selected one */
11343  if (!prefer_hd_stream)
11344  {
11345  /* The minimum match needs to be found if the output is PCM */
11346  if (stream_priority < nzero_stream_priority)
11347  {
11348  /* This stream is a better match so use it instead */
11349  nzero_pid_stream = stream_rec;
11350  nzero_stream_priority = stream_priority;
11351  }
11352  else if (stream_priority == nzero_stream_priority)
11353  {
11354  /* Both streams use the same codec so a non-multichannel one
11355  * should be selected, if available */
11356  if ((nzero_pid_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11357  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11358  {
11359  /* This stream is a better match so use it instead */
11360  nzero_pid_stream = stream_rec;
11361  nzero_stream_priority = stream_priority;
11362  }
11363  }
11364  }
11365  else
11366  {
11367  if (stream_priority > nzero_stream_priority)
11368  {
11369  /* This stream has better audio encoding so select it instead */
11370  nzero_pid_stream = stream_rec;
11371  nzero_stream_priority = stream_priority;
11372  }
11373  else if (stream_priority == nzero_stream_priority)
11374  {
11375  /* Both streams use the same codec so a multichannel one
11376  * should be selected, if available */
11377  if ((nzero_pid_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
11378  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
11379  {
11380  /* This stream is a better match so use it instead */
11381  nzero_pid_stream = stream_rec;
11382  nzero_stream_priority = stream_priority;
11383  }
11384  }
11385  }
11386  }
11387  }
11388  }
11389  }
11390  stream_rec = stream_rec->next;
11391  }
11392 
11393  // choose the stream which provides the best match to the requirements
11394  stream_rec = exact_match_stream;
11395  if (stream_rec == NULL)
11396  {
11397  stream_rec = default_match_stream;
11398  if (stream_rec == NULL)
11399  {
11400  stream_rec = lang_code_match_stream;
11401  if (stream_rec == NULL)
11402  {
11403  stream_rec = qaa_match_stream;
11404  if (stream_rec == NULL)
11405  {
11406  stream_rec = audio_type_match_stream;
11407  if (stream_rec == NULL)
11408  {
11409  stream_rec = nzero_pid_stream;
11410  }
11411  }
11412  }
11413  }
11414  }
11415 
11416  // if a stream has been found mark it in use
11417  if (stream_rec != NULL)
11418  {
11419  audio_pid = stream_rec->pid;
11420  *audio_mode = stream_rec->data.audio.mode;
11421  *audio_type = stream_rec->type;
11422  *selected_stream = stream_rec;
11423  }
11424  }
11425 
11426  FUNCTION_FINISH(GetReqdAudioPid);
11427 
11428  return(audio_pid);
11429 }
11430 
11431 /*!**************************************************************************
11432  * @brief Return the audio priority of the given stream type based on a fixed table
11433  * @param stream_type audio stream type
11434  * @return priority value - higher is better
11435  ****************************************************************************/
11436 static U8BIT AudioStreamPriority(ADB_STREAM_TYPE stream_type)
11437 {
11438  S8BIT priority;
11439  U16BIT num_entries;
11440  U8BIT i;
11441 
11442  FUNCTION_START(AudioStreamPriority);
11443 
11444  priority = 0;
11445  num_entries = sizeof(audio_priority_table) / sizeof(audio_priority_table[0]);
11446 
11447  for (i = 0; i < num_entries; i++)
11448  {
11449  if (stream_type == audio_priority_table[i])
11450  {
11451  priority = i;
11452  break;
11453  }
11454  }
11455 
11456  FUNCTION_FINISH(AudioStreamPriority);
11457 
11458  return(priority);
11459 }
11460 
11461 /*!**************************************************************************
11462  * @brief Gets a required subtitle pid
11463  * @param s_ptr service record ptr
11464  * @param pid_ptr - pointer for the return of the pid
11465  * @param cpage_ptr pointer for the return of the composition page
11466  * @param apage_ptr pointer for the return of the ancilliary page
11467  * @param db_lang_ids Language ids to be matching
11468  * @param primary_found If it found the required language
11469  * @return U16BIT - Found Pid
11470  ****************************************************************************/
11471 static E_STREAM_MATCH_TYPE GetReqdSubtitleParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr,
11472  U16BIT *cpage_ptr, U16BIT *apage_ptr, U8BIT *db_lang_ids, BOOLEAN *primary_found,
11473  ADB_STREAM_REC **selected_stream)
11474 {
11475  E_STREAM_MATCH_TYPE match_type;
11476  ADB_STREAM_REC *stream_rec;
11477  ADB_STREAM_REC *nzero_pid_stream;
11478  ADB_STREAM_REC *undef_match_stream;
11479  ADB_STREAM_REC *default_match_stream;
11480  ADB_STREAM_REC *aspect_match_stream;
11481  ADB_STREAM_REC *exact_match_stream;
11482  U32BIT def_lang_code;
11483  E_STB_AV_ASPECT_RATIO aspect_ratio;
11484  U8BIT i;
11485  E_SUBTITLE_TYPE subtitle_type;
11486 
11487  FUNCTION_START(GetReqdSubtitleParams);
11488 
11489  *primary_found = FALSE;
11490  *selected_stream = NULL;
11491 
11492  if (s_ptr != NULL)
11493  {
11494  nzero_pid_stream = NULL;
11495  undef_match_stream = NULL;
11496  default_match_stream = NULL;
11497  aspect_match_stream = NULL;
11498  exact_match_stream = NULL;
11499 
11500  aspect_ratio = (E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM);
11501  subtitle_type = (E_SUBTITLE_TYPE)APP_NvmRead(SUBTITLE_TYPE_NVM);
11502 
11503  stream_rec = s_ptr->stream_list;
11504  while (stream_rec != NULL)
11505  {
11506  if (stream_rec->type == ADB_SUBTITLE_STREAM)
11507  {
11508  // ensure in use flag is cleared
11509  stream_rec->in_use = FALSE;
11510 
11511  if (stream_rec->pid != 0)
11512  {
11513  // is this stream an exact match for the reqd settings?
11514  if ((s_ptr->reqd_subtitle_valid == TRUE) &&
11515  (exact_match_stream == NULL) &&
11516  (stream_rec->data.subtitle.lang_code == s_ptr->reqd_subtitle_lang_code) &&
11517  (stream_rec->data.subtitle.type == s_ptr->reqd_subtitle_type))
11518  {
11519  // yes - found it!
11520  exact_match_stream = stream_rec;
11521  *primary_found = TRUE;
11522  }
11523  else
11524  {
11525  if (db_lang_ids != NULL)
11526  {
11527  /* Not an exact match so check whether this stream matches the
11528  * default lang and aspect ratio */
11529  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) && (db_lang_ids[i] != ACFG_INVALID_DB_LANG); i++)
11530  {
11531  def_lang_code = ACFG_ConvertLangIdToCode(db_lang_ids[i]);
11532 
11533  if (subtitle_type == SUBTITLE_NORMAL)
11534  {
11535  if ((aspect_match_stream == NULL) &&
11536  (def_lang_code == stream_rec->data.subtitle.lang_code) &&
11537  (((aspect_ratio == ASPECT_RATIO_4_3) &&
11538  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_4_3)) ||
11539  ((aspect_ratio == ASPECT_RATIO_16_9) &&
11540  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_16_9))))
11541  {
11542  aspect_match_stream = stream_rec;
11543  *primary_found = TRUE;
11544  }
11545  }
11546  else
11547  {
11548  if ((aspect_match_stream == NULL) &&
11549  (def_lang_code == stream_rec->data.subtitle.lang_code) &&
11550  (((aspect_ratio == ASPECT_RATIO_4_3) &&
11551  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_4_3)) ||
11552  ((aspect_ratio == ASPECT_RATIO_16_9) &&
11553  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_16_9))))
11554  {
11555  aspect_match_stream = stream_rec;
11556  *primary_found = TRUE;
11557  }
11558  }
11559 
11560  // if not an exact match, check if this stream matches the default lang
11561  if (subtitle_type == SUBTITLE_NORMAL)
11562  {
11563  if ((default_match_stream == NULL) &&
11564  (def_lang_code == stream_rec->data.subtitle.lang_code) &&
11565  ((stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB) ||
11566  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_4_3) ||
11567  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_16_9) ||
11568  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HD)))
11569  {
11570  default_match_stream = stream_rec;
11571  *primary_found = TRUE;
11572  }
11573  }
11574  else
11575  {
11576  /* If both DVB and HoH subtitle present, it will select HoH subtitle
11577  * as it matches with the user setting, if there is only DVB subtitle
11578  * available, we still need to show the DVB subtitle even though the
11579  * user setting is HoH */
11580  if ((default_match_stream == NULL) && (def_lang_code == stream_rec->data.subtitle.lang_code) &&
11581  ((stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB) ||
11582  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_4_3) ||
11583  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_16_9) ||
11584  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HD)))
11585  {
11586  default_match_stream = stream_rec;
11587  *primary_found = TRUE;
11588  }
11589  if ((def_lang_code == stream_rec->data.subtitle.lang_code) &&
11590  ((stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING) ||
11591  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_4_3) ||
11592  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_16_9) ||
11593  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_HD)))
11594  {
11595  default_match_stream = stream_rec;
11596  *primary_found = TRUE;
11597  }
11598  }
11599  }
11600  }
11601 
11602  // does it match the default type only
11603  if ((undef_match_stream == NULL) &&
11604  ((stream_rec->data.subtitle.lang_code == ADB_LANG_CODE_UNDEF) ||
11605  (stream_rec->data.subtitle.lang_code == ADB_LANG_CODE_QAA)))
11606  {
11607  undef_match_stream = stream_rec;
11608  }
11609 
11610  // is this the first non-zero pid
11611  if (nzero_pid_stream == NULL)
11612  {
11613  nzero_pid_stream = stream_rec;
11614  }
11615  }
11616  }
11617  }
11618  stream_rec = stream_rec->next;
11619  }
11620 
11621  // choose the stream which provides the best match to the requirements
11622  stream_rec = exact_match_stream;
11623  match_type = STREAM_MATCH_EXACT;
11624  if (stream_rec == NULL)
11625  {
11626  stream_rec = aspect_match_stream;
11627 
11628  match_type = STREAM_MATCH_ASPECT;
11629  if (stream_rec == NULL)
11630  {
11631  stream_rec = default_match_stream;
11632  match_type = STREAM_MATCH_LANG;
11633  if (stream_rec == NULL)
11634  {
11635  stream_rec = undef_match_stream;
11636  match_type = STREAM_MATCH_TYPE;
11637  if (stream_rec == NULL)
11638  {
11639  stream_rec = nzero_pid_stream;
11640  match_type = STREAM_MATCH_NOT_ZERO;
11641 
11642  if ((stream_rec != NULL) && ACFG_IsNordigCountry())
11643  {
11644  /* match_type should be set to STREAM_MATCH_NONE if HoH(Hard of Hearing) was
11645  * disabled in order to disable the HoH subtitle even if there is an HoH
11646  * subtitle present */
11647  if ((subtitle_type == SUBTITLE_NORMAL) &&
11648  ((stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING) ||
11649  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_4_3) ||
11650  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_16_9)))
11651  {
11652  /* set stream_rec to NULL in order to set match_type = STREAM_MATCH_NONE as Nordig spec wouldn't show
11653  subtitle if above case not matched */
11654  stream_rec = NULL;
11655  }
11656  }
11657  }
11658  }
11659  }
11660  }
11661 
11662  // if a stream has been found, return details
11663  if ((stream_rec != NULL) &&
11664  ((stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB) ||
11665  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_4_3) ||
11666  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_16_9) ||
11667  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_221_1) ||
11668  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HD) ||
11669  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING) ||
11670  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_4_3) ||
11671  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_16_9) ||
11672  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_221_1) ||
11673  (stream_rec->data.subtitle.type == ADB_SUBTITLE_TYPE_DVB_HARD_HEARING_HD)))
11674  {
11675  *pid_ptr = stream_rec->pid;
11676  *cpage_ptr = stream_rec->data.subtitle.composition_page;
11677  *apage_ptr = stream_rec->data.subtitle.ancillary_page;
11678  *selected_stream = stream_rec;
11679  }
11680  else
11681  {
11682  *pid_ptr = 0;
11683  *cpage_ptr = 0;
11684  *apage_ptr = 0;
11685  match_type = STREAM_MATCH_NONE;
11686  }
11687  }
11688  else
11689  {
11690  *pid_ptr = 0;
11691  *cpage_ptr = 0;
11692  *apage_ptr = 0;
11693  match_type = STREAM_MATCH_NONE;
11694  }
11695 
11696  FUNCTION_FINISH(GetReqdSubtitleParams);
11697 
11698  return(match_type);
11699 }
11700 
11721 static E_STREAM_MATCH_TYPE GetReqdTtextParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr, BOOLEAN for_subtitles,
11722  U8BIT *magazine, U8BIT *page, U8BIT *db_lang_ids, BOOLEAN *primary_found, ADB_STREAM_REC **selected_stream)
11723 {
11724  E_STREAM_MATCH_TYPE match_type;
11725  ADB_STREAM_REC *stream_rec;
11726  ADB_STREAM_REC *nzero_pid_stream;
11727  ADB_STREAM_REC *default_match_stream;
11728  ADB_STREAM_REC *exact_match_stream;
11729  ADB_STREAM_REC *normal_subt_nzero_pid_stream;
11730  ADB_STREAM_REC *normal_subt_default_match_stream;
11731  U32BIT def_lang_code;
11732  U8BIT i;
11733  E_SUBTITLE_TYPE subtitle_type;
11734 
11735  FUNCTION_START(GetReqdTtextParams);
11736 
11737  match_type = STREAM_MATCH_NONE;
11738  *primary_found = FALSE;
11739  *selected_stream = NULL;
11740 
11741  subtitle_type = (E_SUBTITLE_TYPE)APP_NvmRead(SUBTITLE_TYPE_NVM);
11742 
11743  if (s_ptr != NULL)
11744  {
11745  nzero_pid_stream = NULL;
11746  default_match_stream = NULL;
11747  exact_match_stream = NULL;
11748  normal_subt_nzero_pid_stream = NULL;
11749  normal_subt_default_match_stream = NULL;
11750 
11751  stream_rec = s_ptr->stream_list;
11752  while (stream_rec != NULL)
11753  {
11754  if (stream_rec->type == ADB_TTEXT_STREAM)
11755  {
11756  // ensure in use flag is cleared
11757  stream_rec->in_use = FALSE;
11758 
11759  if (stream_rec->pid != 0)
11760  {
11761  // is this stream an exact match for the reqd settings?
11762  if ((s_ptr->reqd_ttext_valid == TRUE) && (exact_match_stream == NULL) &&
11763  (stream_rec->data.ttext.lang_code == s_ptr->reqd_ttext_lang_code) &&
11764  (stream_rec->data.ttext.type == s_ptr->reqd_ttext_type))
11765  {
11766  // yes - found it!
11767  exact_match_stream = stream_rec;
11768  *primary_found = TRUE;
11769  }
11770  else
11771  {
11772  if (db_lang_ids != NULL)
11773  {
11774  // if not an exact match, check if this stream matches the default lang
11775  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) && (db_lang_ids[i] != ACFG_INVALID_DB_LANG); i++)
11776  {
11777  def_lang_code = ACFG_ConvertLangIdToCode(db_lang_ids[i]);
11778 
11779  if ((default_match_stream == NULL) &&
11780  (def_lang_code == stream_rec->data.ttext.lang_code) &&
11781  ((for_subtitles && (UserPrefsMatch(stream_rec->data.ttext.type, subtitle_type) == TRUE)) ||
11782  (!for_subtitles && (stream_rec->data.ttext.type != ADB_TELETEXT_TYPE_SUBTITLE) &&
11783  (stream_rec->data.ttext.type != ADB_TELETEXT_TYPE_SUBTITLE_HARD_HEARING) &&
11784  (stream_rec->data.ttext.type == ADB_TELETEXT_TYPE_INITIAL))))
11785  {
11786  default_match_stream = stream_rec;
11787  *primary_found = TRUE;
11788  }
11789  else if ((normal_subt_default_match_stream == NULL) &&
11790  (def_lang_code == stream_rec->data.ttext.lang_code) &&
11791  (for_subtitles && (stream_rec->data.ttext.type == ADB_TELETEXT_TYPE_SUBTITLE) &&
11792  (subtitle_type == SUBTITLE_HARD_OF_HEARING)))
11793  {
11794  normal_subt_default_match_stream = stream_rec;
11795  *primary_found = TRUE;
11796  }
11797  }
11798  }
11799 
11800  // is this the first non-zero pid
11801  if ((nzero_pid_stream == NULL) &&
11802  ((for_subtitles && (UserPrefsMatch(stream_rec->data.ttext.type, subtitle_type) == TRUE)) ||
11803  (!for_subtitles && (stream_rec->data.ttext.type != ADB_TELETEXT_TYPE_SUBTITLE))))
11804  {
11805  nzero_pid_stream = stream_rec;
11806  }
11807  else if ((normal_subt_nzero_pid_stream == NULL) &&
11808  (for_subtitles && (stream_rec->data.ttext.type == ADB_TELETEXT_TYPE_SUBTITLE) &&
11809  (subtitle_type == SUBTITLE_HARD_OF_HEARING)))
11810  {
11811  normal_subt_nzero_pid_stream = stream_rec;
11812  }
11813  }
11814  }
11815  }
11816  stream_rec = stream_rec->next;
11817  }
11818 
11819  // choose the stream which provides the best match to the requirements
11820  stream_rec = exact_match_stream;
11821  match_type = STREAM_MATCH_EXACT;
11822  if (stream_rec == NULL)
11823  {
11824  stream_rec = default_match_stream;
11825  match_type = STREAM_MATCH_LANG;
11826  if (stream_rec == NULL)
11827  {
11828  stream_rec = normal_subt_default_match_stream;
11829  match_type = STREAM_MATCH_LANG;
11830  if (stream_rec == NULL)
11831  {
11832  stream_rec = nzero_pid_stream;
11833  match_type = STREAM_MATCH_NOT_ZERO;
11834  if (stream_rec == NULL)
11835  {
11836  stream_rec = normal_subt_nzero_pid_stream;
11837  match_type = STREAM_MATCH_NOT_ZERO;
11838 
11839  if ((stream_rec != NULL) && ACFG_IsNordigCountry())
11840  {
11841  /* set stream_rec to NULL in order to set match_type = STREAM_MATCH_NONE as
11842  * Nordig spec wouldn't show teletext if the above case is not matched */
11843  stream_rec = NULL;
11844  }
11845  }
11846  else if (ACFG_IsNordigCountry())
11847  {
11848  /* set stream_rec to NULL in order to set match_type = STREAM_MATCH_NONE as
11849  * Nordig spec wouldn't show teletext if the above cae is not matched */
11850  stream_rec = NULL;
11851  }
11852  }
11853  }
11854  }
11855 
11856  // if a stream has been found mark it in use and return details
11857  if (stream_rec != NULL)
11858  {
11859  *pid_ptr = stream_rec->pid;
11860  *magazine = stream_rec->data.ttext.magazine;
11861  *page = stream_rec->data.ttext.page;
11862  *selected_stream = stream_rec;
11863  }
11864  else
11865  {
11866  *pid_ptr = 0;
11867  *magazine = 0;
11868  *page = 0;
11869  }
11870  }
11871  else
11872  {
11873  *pid_ptr = 0;
11874  *magazine = 0;
11875  *page = 0;
11876  }
11877 
11878  FUNCTION_FINISH(GetReqdTtextParams);
11879 
11880  return(match_type);
11881 }
11882 
11892 static U16BIT GetReqdADPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *ad_mode, U8BIT *db_lang_ids,
11893  ADB_STREAM_REC **selected_stream, BOOLEAN *broadcast_mix)
11894 {
11895  U16BIT ad_pid;
11896  ADB_STREAM_REC *stream_rec;
11897  ADB_STREAM_REC *lang_code_match_stream;
11898  ADB_STREAM_REC *exact_match_stream;
11899  ADB_STREAM_REC *nar_match_stream;
11900  U32BIT def_lang_code;
11901  BOOLEAN prefer_hd_stream;
11902  U8BIT stream_priority;
11903  U8BIT lang_stream_priority;
11904  U8BIT nar_stream_priority;
11905  U8BIT i;
11906 
11907  FUNCTION_START(GetReqdADPid);
11908 
11909  ad_pid = 0;
11910  *ad_mode = AUDIO_MONO;
11911  *selected_stream = NULL;
11912  *broadcast_mix = FALSE;
11913 
11914  if (s_ptr != NULL)
11915  {
11916  lang_code_match_stream = NULL;
11917  exact_match_stream = NULL;
11918  nar_match_stream = NULL;
11919 
11920  prefer_hd_stream = APP_NvmRead(PREFER_HD_AUDIO_NVM);
11921  db_lang_ids = DBDEF_GetAudioLang();
11922 
11923  stream_rec = s_ptr->stream_list;
11924  while (stream_rec != NULL)
11925  {
11926  if ((stream_rec->type == ADB_AUDIO_STREAM) ||
11927  (stream_rec->type == ADB_AAC_AUDIO_STREAM) ||
11928  (stream_rec->type == ADB_HEAAC_AUDIO_STREAM) ||
11929  (stream_rec->type == ADB_AC3_AUDIO_STREAM) ||
11930  (stream_rec->type == ADB_EAC3_AUDIO_STREAM)
11931  )
11932  {
11933  // ensure in use flag is cleared
11934  stream_rec->in_use = FALSE;
11935 
11936  if (stream_rec->pid != 0)
11937  {
11938  // is this audio stream an exact match for the reqd audio settings?
11939  if ((s_ptr->reqd_audio_valid == TRUE) &&
11940  (exact_match_stream == NULL) &&
11941  (stream_rec->data.audio.lang_code == s_ptr->reqd_audio_lang_code) &&
11942  (stream_rec->data.audio.type == ADB_AUDIO_TYPE_FOR_VISUALLY_IMPAIRED))
11943  {
11944  // yes - found it!
11945  exact_match_stream = stream_rec;
11946  }
11947  else
11948  {
11949  stream_priority = AudioStreamPriority(stream_rec->type);
11950  if (db_lang_ids != NULL)
11951  {
11952  /* If not an exact match, does it match the default language */
11953  for (i = 0; (i < ACFG_MAX_DB_LANG_CODES) && (db_lang_ids[i] != ACFG_INVALID_DB_LANG); i++)
11954  {
11955  def_lang_code = ACFG_ConvertLangIdToCode(db_lang_ids[i]);
11956 
11957  if (((def_lang_code == stream_rec->data.audio.lang_code) ||
11958  (stream_rec->data.audio.lang_code == ADB_LANG_CODE_UNDEF)) &&
11959  (stream_rec->data.audio.type == ADB_AUDIO_TYPE_FOR_VISUALLY_IMPAIRED))
11960  {
11961  if (lang_code_match_stream == NULL)
11962  {
11963  /* No stream selected yet so use this one */
11964  lang_code_match_stream = stream_rec;
11965  lang_stream_priority = stream_priority;
11966  }
11967  else
11968  {
11969  /* Check whether this stream uses a better encoding
11970  * than the currently selected one */
11971  if (!prefer_hd_stream)
11972  {
11973  /* The minimum match needs to be found if the output is PCM */
11974  if (stream_priority < lang_stream_priority)
11975  {
11976  /* This stream is a better match so use it instead */
11977  lang_code_match_stream = stream_rec;
11978  lang_stream_priority = stream_priority;
11979  }
11980  else if (stream_priority == lang_stream_priority)
11981  {
11982  /* Both streams use the same codec so a non-multichannel one
11983  * should be selected, if available */
11984  if ((lang_code_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
11985  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
11986  {
11987  /* This stream is a better match so use it instead */
11988  lang_code_match_stream = stream_rec;
11989  lang_stream_priority = stream_priority;
11990  }
11991  }
11992  }
11993  else
11994  {
11995  if (stream_priority > lang_stream_priority)
11996  {
11997  /* This stream has better audio encoding so select it instead */
11998  lang_code_match_stream = stream_rec;
11999  lang_stream_priority = stream_priority;
12000  }
12001  else if (stream_priority == lang_stream_priority)
12002  {
12003  /* Both streams use the same codec so a multichannel one
12004  * should be selected, if available */
12005  if ((lang_code_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
12006  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
12007  {
12008  /* This stream is a better match so use it instead */
12009  lang_code_match_stream = stream_rec;
12010  lang_stream_priority = stream_priority;
12011  }
12012  }
12013  }
12014  }
12015  }
12016  }
12017  }
12018 
12019  if (stream_rec->data.audio.lang_code == ADB_LANG_CODE_NAR)
12020  {
12021  if (nar_match_stream == NULL)
12022  {
12023  nar_match_stream = stream_rec;
12024  nar_stream_priority = stream_priority;
12025  }
12026  else
12027  {
12028  /* Check whether this stream uses a better encoding
12029  * than the currently selected one */
12030  if (!prefer_hd_stream)
12031  {
12032  /* The minimum match needs to be found if the output is PCM */
12033  if (stream_priority < nar_stream_priority)
12034  {
12035  /* This stream is a better match so use it instead */
12036  nar_match_stream = stream_rec;
12037  nar_stream_priority = stream_priority;
12038  }
12039  else if (stream_priority == nar_stream_priority)
12040  {
12041  /* Both streams use the same codec so a non-multichannel one
12042  * should be selected, if available */
12043  if ((nar_match_stream->data.audio.mode == AUDIO_MULTICHANNEL) &&
12044  (stream_rec->data.audio.mode != AUDIO_MULTICHANNEL))
12045  {
12046  /* This stream is a better match so use it instead */
12047  nar_match_stream = stream_rec;
12048  nar_stream_priority = stream_priority;
12049  }
12050  }
12051  }
12052  else
12053  {
12054  if (stream_priority > nar_stream_priority)
12055  {
12056  /* This stream has better audio encoding so select it instead */
12057  nar_match_stream = stream_rec;
12058  nar_stream_priority = stream_priority;
12059  }
12060  else if (stream_priority == nar_stream_priority)
12061  {
12062  /* Both streams use the same codec so a multichannel one
12063  * should be selected, if available */
12064  if ((nar_match_stream->data.audio.mode != AUDIO_MULTICHANNEL) &&
12065  (stream_rec->data.audio.mode == AUDIO_MULTICHANNEL))
12066  {
12067  /* This stream is a better match so use it instead */
12068  nar_match_stream = stream_rec;
12069  nar_stream_priority = stream_priority;
12070  }
12071  }
12072  }
12073  }
12074  }
12075  }
12076  }
12077  }
12078  stream_rec = stream_rec->next;
12079  }
12080 
12081  // choose the stream which provides the best match to the requirements
12082  stream_rec = exact_match_stream;
12083  if (stream_rec == NULL)
12084  {
12085  stream_rec = lang_code_match_stream;
12086  if (stream_rec == NULL)
12087  {
12088  stream_rec = nar_match_stream;
12089  if (stream_rec != NULL)
12090  {
12091  *broadcast_mix = TRUE;
12092  }
12093  }
12094  }
12095 
12096  // if a stream has been found mark it in use
12097  if (stream_rec != NULL)
12098  {
12099  ad_pid = stream_rec->pid;
12100  *ad_mode = stream_rec->data.audio.mode;
12101  *selected_stream = stream_rec;
12102  }
12103  }
12104 
12105  FUNCTION_FINISH(GetReqdADPid);
12106 
12107  return(ad_pid);
12108 }
12109 
12110 #if defined(COUNTRY_FINLAND) || defined(COUNTRY_IRELAND)
12111 /*!**************************************************************************
12112  * @brief Returns the largest LCN from all the available services
12113  * @param tuner_type only use services found on this tuner type.
12114  * Use SIGNAL_NONE for all services
12115  * @param onet_id the original network ID to be matched when checking.
12116  * Use ADB_INVALID_DVB_ID for all services
12117  * @return Largest LCN
12118  ****************************************************************************/
12119 static U16BIT FindLargestLcnNumber(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT onet_id)
12120 {
12121  ADB_SERVICE_REC *s_ptr;
12122  ADB_TRANSPORT_REC *t_ptr;
12123  U16BIT largest_lcn = 0;
12124 
12125  FUNCTION_START(FindLargestLcnNumber);
12126 
12127  s_ptr = DBDEF_GetNextServiceRec(NULL);
12128  while (s_ptr != NULL)
12129  {
12130  /* Can only check the service's signal type and orig net id if it has a transport */
12131  t_ptr = s_ptr->transport;
12132  if ((tuner_type == SIGNAL_NONE) || (onet_id == ADB_INVALID_DVB_ID) || (t_ptr != NULL))
12133  {
12134  if ((tuner_type == SIGNAL_NONE) || (t_ptr->sig_type == tuner_type))
12135  {
12136  if ((onet_id == ADB_INVALID_DVB_ID) || (onet_id == t_ptr->orig_net_id))
12137  {
12138  if (s_ptr->serv_lcn > largest_lcn)
12139  {
12140  largest_lcn = s_ptr->serv_lcn;
12141  }
12142  }
12143  }
12144  }
12145 
12146  s_ptr = DBDEF_GetNextServiceRec(s_ptr);
12147  }
12148 
12149  FUNCTION_FINISH(FindLargestLcnNumber);
12150 
12151  return largest_lcn;
12152 }
12153 
12154 #endif
12155 
12156 #ifdef COUNTRY_UK
12157 /*!**************************************************************************
12158  * @brief Implements the rules that should be applied when target regions are available
12159  * and 2 services require the same LCN.
12160  * @param s1_ptr pointer to service whose LCN is being set
12161  * @param s2_ptr pointer to service that requires the same LCN
12162  * @param next_allocated_lcn pointer to value of next LCN that should be assigned
12163  * in the 800+ range. The value is incremented for returning.
12164  * @param lcn_assigned returned value indicating whether an LCN has been assigned to either service
12165  * @return TRUE if searching should continue.
12166  ****************************************************************************/
12167 static BOOLEAN ApplyTargetRegionRules(ADB_SERVICE_REC *s1_ptr, ADB_SERVICE_REC *s2_ptr,
12168  U16BIT *next_allocated_lcn, BOOLEAN *lcn_assigned)
12169 {
12170  BOOLEAN continue_search;
12171  U8BIT device_region_depth;
12172  U8BIT s1_region_depth, s2_region_depth;
12173  U32BIT device_country_code;
12174  U8BIT device_primary_region;
12175  U8BIT device_secondary_region;
12176  U16BIT device_tertiary_region;
12177 
12178  FUNCTION_START(ApplyTargetRegionRules);
12179 
12180  continue_search = TRUE;
12181  *lcn_assigned = FALSE;
12182 
12183  device_region_depth = (U8BIT)APP_NvmRead(TARGET_REGION_DEPTH_NVM);
12184  if (device_region_depth > 0)
12185  {
12186  device_primary_region = 0;
12187  device_secondary_region = 0;
12188  device_tertiary_region = 0;
12189 
12190  device_country_code = (U32BIT)APP_NvmRead(TARGET_REGION_COUNTRY_NVM);
12191 
12192  if (device_region_depth > 1)
12193  {
12194  device_primary_region = (U8BIT)APP_NvmRead(TARGET_REGION_PRIMARY_NVM);
12195  if (device_region_depth > 2)
12196  {
12197  device_secondary_region = (U8BIT)APP_NvmRead(TARGET_REGION_SECONDARY_NVM);
12198  if (device_region_depth > 3)
12199  {
12200  device_tertiary_region = (U8BIT)APP_NvmRead(TARGET_REGION_TERTIARY_NVM);
12201  }
12202  }
12203  }
12204 
12205  /* Now find the service that best matches the target region depth defined for the device */
12206  s1_region_depth = GetTargetRegionMatchDepth(s1_ptr, device_region_depth, device_country_code,
12207  device_primary_region, device_secondary_region, device_tertiary_region);
12208 
12209  s2_region_depth = GetTargetRegionMatchDepth(s2_ptr, device_region_depth, device_country_code,
12210  device_primary_region, device_secondary_region, device_tertiary_region);
12211 
12212  if (s1_region_depth < s2_region_depth)
12213  {
12214  /* First service doesn't get the LCN it wants, so give it the next available LCN */
12215  s1_ptr->allocated_lcn = *next_allocated_lcn;
12216  (*next_allocated_lcn)++;
12217  *lcn_assigned = TRUE;
12218  continue_search = FALSE;
12219  }
12220  else if (s1_region_depth > s2_region_depth)
12221  {
12222  /* s1 should get the LCN it wants */
12223  if (s2_ptr->allocated_lcn == s2_ptr->serv_lcn)
12224  {
12225  if (s2_ptr->unavailable == FALSE)
12226  {
12227  /* s2 has the lcn - for the moment leave it there and give s1 an allocated lcn.
12228  * Later we will check whether to transfer the lcn and the favourites */
12229  s1_ptr->allocated_lcn = *next_allocated_lcn;
12230  (*next_allocated_lcn)++;
12231  continue_search = FALSE;
12232  }
12233  else
12234  {
12235  /* s2 is unavailable so make it relinquish its lcn and allocate it a new one */
12236  s2_ptr->allocated_lcn = *next_allocated_lcn;
12237  (*next_allocated_lcn)++;
12238  }
12239  }
12240 
12241  *lcn_assigned = TRUE;
12242  }
12243  }
12244 
12245  FUNCTION_FINISH(ApplyTargetRegionRules);
12246 
12247  return(continue_search);
12248 }
12249 
12250 /*!**************************************************************************
12251  * @brief Returns the number of target regions that match the given service.
12252  * @param s_ptr pointer to service to be checked
12253  * @param match_depth number of codes given that are valid and available for checking.
12254  * 1 = only match country code
12255  * 2 = match to primary region level
12256  * 3 = match to secondary region level
12257  * 4 = match to tertiary region level
12258  * @param country_code - region codes to be matched against
12259  * @param primary_region
12260  * @param secondary_region
12261  * @param tertiary_region
12262  * @return The number of matches
12263  ****************************************************************************/
12264 static U8BIT GetTargetRegionMatchDepth(ADB_SERVICE_REC *s_ptr, U8BIT match_depth,
12265  U32BIT country_code, U8BIT primary_region, U8BIT secondary_region, U16BIT tertiary_region)
12266 {
12267  SI_TARGET_REGION_DESC *tptr;
12268  SI_TARGET_REGION *rptr;
12269  U8BIT best_depth;
12270 
12271  tptr = s_ptr->target_region_list;
12272  if (tptr == NULL)
12273  {
12274  if ((s_ptr->transport != NULL) &&
12275  (s_ptr->transport->sig_type == SIGNAL_COFDM))
12276  {
12277  tptr = s_ptr->transport->u.terr.target_region_list;
12278  if (tptr == NULL)
12279  {
12280  if (s_ptr->transport->network != NULL)
12281  {
12282  tptr = s_ptr->transport->network->target_region_list;
12283  }
12284  }
12285  }
12286  }
12287 
12288  best_depth = 0;
12289 
12290  while (tptr != NULL)
12291  {
12292  if (tptr->country_code == country_code)
12293  {
12294  if (best_depth < 1)
12295  {
12296  best_depth = 1;
12297  }
12298 
12299  if (match_depth > 1)
12300  {
12301  rptr = tptr->region_list;
12302  while (rptr != NULL)
12303  {
12304  if ((rptr->region_depth >= 1) && (rptr->primary_region_code == primary_region))
12305  {
12306  if (best_depth < 2)
12307  {
12308  best_depth = 2;
12309  }
12310 
12311  if (match_depth > 2)
12312  {
12313  if ((rptr->region_depth >= 2) && (rptr->secondary_region_code == secondary_region))
12314  {
12315  if (best_depth < 3)
12316  {
12317  best_depth = 3;
12318  }
12319 
12320  if (match_depth > 3)
12321  {
12322  if ((rptr->region_depth >= 3) && (rptr->tertiary_region_code == tertiary_region))
12323  {
12324  if (best_depth < 4)
12325  {
12326  best_depth = 4;
12327  }
12328  }
12329  }
12330  }
12331  }
12332  }
12333 
12334  rptr = rptr->next;
12335  }
12336  }
12337  }
12338 
12339  tptr = tptr->next;
12340  }
12341 
12342  return(best_depth);
12343 }
12344 
12345 #endif /* COUNTRY_UK */
12346 
12347 /*!**************************************************************************
12348  * @brief Checks the teletext subtitle type against the subtitle type
12349  * user preference
12350  * @param ADB_TELETEXT_TYPE ttext_type teletex type in the stream
12351  * @param E_SUBTITLE_TYPE user_pref user preference
12352  * @return TRUE if the teletext type is compatible with the user preference
12353  ****************************************************************************/
12354 static BOOLEAN UserPrefsMatch(ADB_TELETEXT_TYPE ttext_type, E_SUBTITLE_TYPE user_pref)
12355 {
12356  BOOLEAN retval = FALSE;
12357 
12358  if (((ttext_type == ADB_TELETEXT_TYPE_SUBTITLE) && (user_pref == SUBTITLE_NORMAL)) ||
12359  ((ttext_type == ADB_TELETEXT_TYPE_SUBTITLE_HARD_HEARING) && (user_pref == SUBTITLE_HARD_OF_HEARING)))
12360  {
12361  retval = TRUE;
12362  }
12363 
12364  return retval;
12365 }
12366 
12373 static S16BIT LcnSortCompareFunc(LINK_LIST_PTR_BLK **blk_1, LINK_LIST_PTR_BLK **blk_2)
12374 {
12375  S16BIT ret_val;
12376  ADB_SERVICE_REC *s1_ptr;
12377  ADB_SERVICE_REC *s2_ptr;
12378  S16BIT lcn_1;
12379  S16BIT lcn_2;
12380 
12381  FUNCTION_START(LcnSortCompareFunc);
12382 
12383  ASSERT(blk_1 != NULL);
12384  ASSERT(blk_2 != NULL);
12385 
12386  s1_ptr = (ADB_SERVICE_REC *)*blk_1;
12387  s2_ptr = (ADB_SERVICE_REC *)*blk_2;
12388  ret_val = 0;
12389  if ((s1_ptr != NULL) && (s2_ptr != NULL))
12390  {
12391  lcn_1 = (S16BIT)s1_ptr->allocated_lcn;
12392  lcn_2 = (S16BIT)s2_ptr->allocated_lcn;
12393  ret_val = lcn_1 - lcn_2;
12394  }
12395 
12396  FUNCTION_FINISH(LcnSortCompareFunc);
12397 
12398  return(ret_val);
12399 }
12400 
12408 static S16BIT FavServiceSortCompare(LINK_LIST_PTR_BLK **blk1, LINK_LIST_PTR_BLK **blk2)
12409 {
12410  S16BIT retval;
12411  ADB_FAVSERV_REC *fs1;
12412  ADB_FAVSERV_REC *fs2;
12413 
12414  FUNCTION_START(FavServiceSortCompare);
12415 
12416  retval = 0;
12417 
12418  fs1 = (ADB_FAVSERV_REC *)*blk1;
12419  fs2 = (ADB_FAVSERV_REC *)*blk2;
12420 
12421  if ((fs1 != NULL) && (fs2 != NULL))
12422  {
12423  if (fs1->index < fs2->index)
12424  {
12425  retval = -1;
12426  }
12427  else if (fs1->index > fs2->index)
12428  {
12429  retval = 1;
12430  }
12431  }
12432 
12433  FUNCTION_FINISH(FavServiceSortCompare);
12434 
12435  return(retval);
12436 }
12437 
12438 #if 0
12439 
12444 static void InsertEventInSchedule(ADB_SERVICE_REC *serv_ptr, ADB_EVENT_REC *event_ptr)
12445 {
12446  ADB_EVENT_REC *e_ptr;
12447  ADB_EVENT_REC **add_ptr;
12448  U32DHMS end_date_time;
12449 
12450  FUNCTION_START(InsertEventInSchedule);
12451 
12452  /* Skip any events that end before the one being added starts */
12453  add_ptr = &(serv_ptr->event_schedule);
12454 
12455  if (serv_ptr->event_schedule != NULL)
12456  {
12457  e_ptr = serv_ptr->event_schedule;
12458  end_date_time = STB_GCCalculateDHMS(e_ptr->start, e_ptr->duration, CALC_ADD);
12459 
12460  while ((e_ptr != NULL) && (end_date_time < event_ptr->start))
12461  {
12462  add_ptr = &(e_ptr->next);
12463  if ((e_ptr = e_ptr->next) != NULL)
12464  {
12465  end_date_time = STB_GCCalculateDHMS(e_ptr->start, e_ptr->duration, CALC_ADD);
12466  }
12467  }
12468  }
12469 
12470  event_ptr->next = *add_ptr;
12471  *add_ptr = event_ptr;
12472 
12473  serv_ptr->num_events_in_schedule++;
12474 
12475  FUNCTION_FINISH(InsertEventInSchedule);
12476 }
12477 #endif
12478 
12486 static S16BIT TimerSortDateTime(LINK_LIST_PTR_BLK **timer1, LINK_LIST_PTR_BLK **timer2)
12487 {
12488  S16BIT retval;
12489  ADB_TIMER_REC *t1_ptr;
12490  ADB_TIMER_REC *t2_ptr;
12491 
12492  FUNCTION_START(TimerSortDateTime);
12493 
12494  ASSERT(timer1 != NULL);
12495  ASSERT(timer2 != NULL);
12496 
12497  t1_ptr = (ADB_TIMER_REC *)*timer1;
12498  t2_ptr = (ADB_TIMER_REC *)*timer2;
12499  retval = 0;
12500 
12501  if ((t1_ptr != NULL) && (t2_ptr != NULL))
12502  {
12503  if (t1_ptr->start_time > t2_ptr->start_time)
12504  {
12505  retval = 1;
12506  }
12507  else
12508  {
12509  if (t1_ptr->start_time < t2_ptr->start_time)
12510  {
12511  retval = -1;
12512  }
12513  else
12514  {
12515  /* Items are equal */
12516  retval = 0;
12517  }
12518  }
12519  }
12520 
12521  FUNCTION_FINISH(TimerSortDateTime);
12522 
12523  return(retval);
12524 }
12525 
12533 static S16BIT TimerSortName(LINK_LIST_PTR_BLK **timer1, LINK_LIST_PTR_BLK **timer2)
12534 {
12535  S16BIT retval;
12536  ADB_TIMER_REC *t1_ptr;
12537  ADB_TIMER_REC *t2_ptr;
12538  U8BIT *name1;
12539  U8BIT *name2;
12540  BOOLEAN reverse;
12541  U16BIT num_chars;
12542 
12543  FUNCTION_START(TimerSortName);
12544 
12545  ASSERT(timer1 != NULL);
12546  ASSERT(timer2 != NULL);
12547 
12548  t1_ptr = (ADB_TIMER_REC *)*timer1;
12549  t2_ptr = (ADB_TIMER_REC *)*timer2;
12550  retval = 0;
12551 
12552  if ((t1_ptr != NULL) && (t2_ptr != NULL))
12553  {
12554  name1 = STB_ConvertStringToUnicode(t1_ptr->name, &reverse, &num_chars, FALSE, 0);
12555  if (name1 != NULL)
12556  {
12557  name2 = STB_ConvertStringToUnicode(t2_ptr->name, &reverse, &num_chars, FALSE, 0);
12558  if (name2 != NULL)
12559  {
12560  retval = STB_CompareUnicodeStrings(name1, name2, TRUE, TRUE);
12561 
12562  STB_ReleaseUnicodeString(name2);
12563  }
12564 
12565  STB_ReleaseUnicodeString(name1);
12566  }
12567  }
12568 
12569  FUNCTION_FINISH(TimerSortName);
12570 
12571  return(retval);
12572 }
12573 
12579 static BOOLEAN IsVideoStreamType(ADB_STREAM_TYPE type)
12580 {
12581  BOOLEAN is_video;
12582 
12583  FUNCTION_START(IsVideoStreamType);
12584 
12585  if ((type == ADB_VIDEO_STREAM) || (type == ADB_H264_VIDEO_STREAM) ||
12586  (type == ADB_H265_VIDEO_STREAM))
12587  {
12588  is_video = TRUE;
12589  }
12590  else
12591  {
12592  is_video = FALSE;
12593  }
12594 
12595  FUNCTION_FINISH(IsVideoStreamType);
12596 
12597  return is_video;
12598 }
12599 
12600 static U8BIT* ReadLanguageCode(U8BIT *dptr, U32BIT *lang_code)
12601 {
12602  U32BIT lcode;
12603  U8BIT i;
12604  U8BIT code_char;
12605 
12606  FUNCTION_START(ReadLanguageCode);
12607 
12608  lcode = 0;
12609  for (i = 0; i < 3; i++)
12610  {
12611  code_char = *dptr;
12612  dptr++;
12613  if ((code_char >= 'A') && (code_char <= 'Z'))
12614  {
12615  code_char += 0x20; // convert to lower case
12616  }
12617  lcode = (lcode << 8) | code_char;
12618  }
12619  *lang_code = lcode;
12620 
12621  FUNCTION_FINISH(ReadLanguageCode);
12622 
12623  return(dptr);
12624 }
12625 
12626 static U8BIT* CopyString(ADB_STRING *str_desc, BOOLEAN to_unicode)
12627 {
12628  U16BIT str_len;
12629  U8BIT *copied_string;
12630 
12631  FUNCTION_START(CopyString);
12632 
12633  copied_string = NULL;
12634  if (str_desc != NULL)
12635  {
12636  if (to_unicode)
12637  {
12638  copied_string = STB_ConvertStringToUTF8(str_desc->str_ptr, &str_len, FALSE,
12639  str_desc->lang_code);
12640  }
12641  else
12642  {
12643  str_len = (U16BIT)str_desc->nbytes;
12644  copied_string = (U8BIT *)STB_AppGetMemory(str_len);
12645  if (copied_string != NULL)
12646  {
12647  memcpy(copied_string, str_desc->str_ptr, str_len);
12648  }
12649  }
12650  }
12651 
12652  FUNCTION_FINISH(CopyString);
12653 
12654  return(copied_string);
12655 }
12656 
ADB_LNB_BAND_REC * DBDEF_GetNextLNBBandRec(ADB_LNB_BAND_REC *band_ptr)
Returns the next LNB band record after the one given. If the argument is NULL then the first record i...
Definition: ap_dbdef.c:4587
U8BIT DBDEF_GetEventComponentList(ADB_EVENT_REC *e_ptr, ADB_EVENT_COMPONENT_INFO **component_list)
Retrieves a list of components associated with the specified event, as described by component descrip...
Definition: ap_dbdef.c:3298
U16BIT DBDEF_GetReqdAudioPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *audio_mode, ADB_STREAM_TYPE *audio_type)
Gets the appropriate audio pid - looks first for the pid matching exactly the required audio settings...
Definition: ap_dbdef.c:6298
U8BIT * DBDEF_GetServiceGuidanceData(ADB_SERVICE_REC *s_ptr, U8BIT *type, U8BIT *mode)
Returns the guidance text for the service, as a UTF-8 string. The returned string should be freed usi...
Definition: ap_dbdef.c:2879
U8BIT DBDEF_GetEventParentalAge(ADB_EVENT_REC *e_ptr)
Returns the parental age value for the given event.
Definition: ap_dbdef.c:2938
void DBDEF_SetTunedTransport(U8BIT path, ADB_TRANSPORT_REC *t_ptr)
sets the currently tuned transport
Definition: ap_dbdef.c:8034
U8BIT * STB_ConvertStringToUnicode(U8BIT *string, BOOLEAN *reverse_dir, U16BIT *nchar, BOOLEAN strip_DVB_cntrl_char, U32BIT lang_code)
Converts the specified DVB coded string into a unicode string, counting the number of characters and ...
Definition: stbuni.c:1069
void * DBA_CreateRecord(U32BIT record_id, void *parent)
Creates a new record of the given type, adding it to the database as a child of the given parent reco...
Definition: dba_nvm.c:940
void DBDEF_DeleteCridRecord(ADB_CRID_REC *c_ptr)
Deletes the given CRID record from the database.
Definition: ap_dbdef.c:8939
void STB_DPSetTunedTransport(U8BIT path, void *transport)
Saves the given transport with the specified decode path.
Definition: stbdpc.c:1518
U32DHMS STB_GCCalculateDHMS(U32DHMS dhms, U32DHMS period, E_STB_GC_CALCTYPE calc)
Calculates the date/time when the period is added/subtracted to/from dhms.
Definition: stbgc.c:2136
void STB_LLAddBlockToEnd(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the end of the linked list identified by the list...
Definition: stbllist.c:325
U32BIT ACFG_GetUndefinedLanguageBehaviour(void)
Gets the language code set by ACFG_SetUndefinedLanguageBehaviour, or &#39;und&#39; if that function has not b...
Definition: ap_cfg.c:2061
void DBDEF_RemoveEmptyTransports(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
Delete all transport records that don&#39;t have any services.
Definition: ap_dbdef.c:8745
AllocLcnFunc ACFG_GetTerrestrialLcnFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to assign LCNs following a DVB-T/T2 scan for the given co...
Definition: ap_cfg.c:1768
void DBDEF_DeleteEventList(ADB_EVENT_REC *elist)
Deletes all events in the given list.
Definition: ap_dbdef.c:3754
U16BIT DBDEF_GetNumServicesInFavouriteList(ADB_FAVLIST_REC *fav_list)
Returns the number of services in the given favourite list.
Definition: ap_dbdef.c:9389
U16BIT DBDEF_GetReqdADPid(ADB_SERVICE_REC *s_ptr, E_STB_DP_AUDIO_MODE *ad_mode, ADB_STREAM_TYPE *ad_type, BOOLEAN *broadcast_mix)
Gets the appropriate audio description pid - looks first for the pid matching exactly the required au...
Definition: ap_dbdef.c:6352
U8BIT * DBDEF_GetTextLang(void)
returns array of current text langs
Definition: ap_dbdef.c:8133
void * STB_DPGetTunedService(U8BIT path)
Returns the service saved with the given decode path.
Definition: stbdpc.c:1582
void DBDEF_SetSecondaryTextLang(U8BIT *lang_ids)
sets secondary text lang
Definition: ap_dbdef.c:8151
ADB_FAVSERV_REC * DBDEF_FindServiceInFavouriteList(ADB_FAVLIST_REC *fav_list, void *serv_ptr)
Returns the ADB_FAVSERV_REC from the given favourite list for the given service.
Definition: ap_dbdef.c:9501
U16BIT ACFG_GetLastUnallocatedLcn(U32BIT country_code, E_STB_DP_SIGNAL_TYPE tuner_type)
Returns the last LCN that should be used when assigning LCNs to services that don&#39;t appear in an LCN ...
Definition: ap_cfg.c:1195
U16BIT DBDEF_GetNumSatellites(void)
Returns the number of satellite records in the database.
Definition: ap_dbdef.c:4362
BOOLEAN DBDEF_SetLNB22k(ADB_LNB_REC *lnb, BOOLEAN is_22k)
Sets the LNB 22k setting.
Definition: ap_dbdef.c:4085
BOOLEAN DBA_SaveDatabase(void)
Saves any changes made to the working database to non-volatile storage. If saving to a file...
Definition: dba_nvm.c:667
ADB_SERVICE_REC * DBDEF_FindServiceRecByLcn(U16BIT lcn, ADB_TRANSPORT_REC *t_ptr, BOOLEAN allocated_lcn)
Find the service with the given LCN, and optionally on the given transport.
Definition: ap_dbdef.c:6218
ADB_TRANSPORT_REC * DBDEF_FindSatTransportRec(U32BIT freq_hz, U16BIT symbol_rate, E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation, void *satellite)
Find the satellite transport record in the database matching the given params.
Definition: ap_dbdef.c:5170
void DBDEF_TidyDatabaseNordig(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
Iterates through all the services following a search search to see whether any need to be deleted bas...
Definition: ap_dbdef.c:8332
Application configuration.
ADB_FAVSERV_REC * DBDEF_AddServiceToFavouriteList(ADB_FAVLIST_REC *fav_list, ADB_SERVICE_REC *serv_ptr, S16BIT index)
Adds a new service to the given favourite list at the given position.
Definition: ap_dbdef.c:9404
ADB_EVENT_ITEMIZED_INFO * ADB_GetEventItemizedDescription(void *event_ptr, U16BIT *num_items_ptr)
Returns the items of extended event descriptor as item descriptor and item itself.
Definition: ap_dbacc.c:8874
U16BIT DBDEF_GetNumCridRecords(void)
Returns the number of CRID records in the database.
Definition: ap_dbdef.c:8969
Application database control.
LINK_LIST_PTR_BLK * STB_LLGetPrevBlock(LINK_LIST_PTR_BLK *blk)
Returns a pointer to the previous block in the linked list, or NULL if at the start of the list...
Definition: stbllist.c:600
U16BIT DBDEF_GetDeletedServiceList(E_STB_DP_SIGNAL_TYPE tuner_type, void ***slist_ptr)
Definition: ap_dbdef.c:6772
Header file - macros and function prototypes for public use.
BOOLEAN DBDEF_IsActiveProfile(ADB_NETWORK_REC *profile)
Is the given profile the currently active profile?
Definition: ap_dbdef.c:10122
U8BIT * ACTL_GetRfNameFromFreq(E_STB_DP_SIGNAL_TYPE tuner_type, U32BIT freq_hz)
Returns the rf name appropriate to the frequency specified.
Definition: ap_cntrl.c:1308
Header file for NVM data handling functions.
BOOLEAN DBDEF_SetServiceType(ADB_SERVICE_REC *s_ptr, ADB_SERVICE_TYPE serv_type)
Sets the service type for the given service record.
Definition: ap_dbdef.c:5969
ADB_TRANSPORT_REC * DBDEF_FindTerrestrialTransportRec(U32BIT freq_hz, U8BIT plp_id)
Find the terrestrial transport record in the database matching the given params.
Definition: ap_dbdef.c:4952
BOOLEAN DBDEF_SetLNBCSwitch(ADB_LNB_REC *lnb, E_STB_DP_DISEQC_CSWITCH cswitch)
Sets the LNB committed switch setting.
Definition: ap_dbdef.c:4210
void DBDEF_SetCridProgrammeName(ADB_CRID_REC *c_ptr, U8BIT *prog_name)
Sets the programme name field of the given CRID record.
Definition: ap_dbdef.c:8881
BOOLEAN DBA_SetFieldLangString(void *record, U32BIT field_id, U32BIT lang_code, U8BIT *string, U16BIT num_bytes)
Set the string value of a record&#39;s field. The function will fail if the record doesn&#39;t exist...
Definition: dba_nvm.c:1291
void DBDEF_SetTunedService(U8BIT path, ADB_SERVICE_REC *s_ptr)
Sets the currently tuned service.
Definition: ap_dbdef.c:8066
void * STB_AppGetMemory(U32BIT bytes)
Attempts to allocate memory from the application heap.
Definition: stbheap.c:651
ADB_SERVICE_REC * DBDEF_FindServiceRecByIds(ADB_SERVICE_REC *servp, U32BIT net_id, U32BIT onet_id, U32BIT tran_id, U32BIT serv_id)
Search for a service with the given IDs.
Definition: ap_dbdef.c:6150
void DBDEF_SetTransportTransportId(ADB_TRANSPORT_REC *t_ptr, U16BIT tran_id)
Sets the transport ID of the given transport.
Definition: ap_dbdef.c:5368
S8BIT STB_DPGetAnalogFreqOff(U8BIT path)
Reads the analogue frequency offset value from decode path store.
Definition: stbdpc.c:6906
void DBA_SaveRecord(void *record)
Forces a record to be saved to non-volatile storage. Depending on the implementation, this function may not do anything if the data is updated to non-volatile storage as any records and/or fields are created or updated.
Definition: dba_nvm.c:1157
void DBDEF_DeleteTimerRec(ADB_TIMER_REC *timer)
Deletes the given timer from the database.
Definition: ap_dbdef.c:9966
DBTidyFunc ACFG_GetSatelliteDBTidyFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to tidy up the database following a DVB-S/S2 scan for the...
Definition: ap_cfg.c:1968
U8BIT * DBDEF_GetEventGuidance(ADB_EVENT_REC *e_ptr, ADB_SERVICE_REC *s_ptr, U8BIT *type, U8BIT *mode)
Returns the guidance text for an event, either from the event itself or the event&#39;s service...
Definition: ap_dbdef.c:2732
void DBDEF_TidyDatabaseSatUK(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
Iterates through all the services following a search search to see whether any need to be deleted bas...
Definition: ap_dbdef.c:8562
void DBDEF_SetAudioLang(U8BIT *lang_ids)
sets current audio lang
Definition: ap_dbdef.c:8187
Structure representing the component information as found in the EIT component_descriptor.
Definition: ap_dbacc.h:238
void DBDEF_PopProfile(void)
Restores a previously pushed profile.
Definition: ap_dbdef.c:10253
BOOLEAN DBDEF_SetServiceName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
Set or change the name of a service.
Definition: ap_dbdef.c:5783
ADB_TRANSPORT_REC * DBDEF_AddSatTransportRec(U32BIT freq_hz, U16BIT symbol_rate, E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation, ADB_NETWORK_REC *network)
Adds a satellite transport record with the given frequency, symbol rate and polarity.
Definition: ap_dbdef.c:5102
BOOLEAN DBA_GetFieldData(void *record, U32BIT field_id, U8BIT **data, U16BIT *num_bytes)
Gets the data of a record&#39;s field. The function will fail if the record doesn&#39;t exist, the record doesn&#39;t include the given field, or the field isn&#39;t a data field. The pointer to the data returned will be to the data held by the database, so the data must not be changed.
Definition: dba_nvm.c:1488
U16BIT STB_LLGetNumBlocks(LINK_LIST_HEADER *hdr)
Counts and returns the number of blocks in a linked list.
Definition: stbllist.c:736
ADB_FAVLIST_REC * DBDEF_AddFavouriteList(U8BIT list_id, U8BIT *name, U32BIT user_data, S16BIT index)
Creates a new favourite list and adds it to the list of favourite lists. Creation of the new list wil...
Definition: ap_dbdef.c:9061
ADB_STREAM_REC * DBDEF_CopyStreamList(ADB_STREAM_REC *slist)
Creates a copy of a stream list, allocating new memory as required.
Definition: ap_dbdef.c:1881
ADB_CRID_REC * DBDEF_GetNextCridRecord(ADB_CRID_REC *c_ptr)
Returns the next CRID record after the one specified. If the record specified is NULL then the first ...
Definition: ap_dbdef.c:8982
U8BIT * STB_ConvertStringToUTF8(U8BIT *string, U16BIT *nchar, BOOLEAN strip_DVB_cntrl_char, U32BIT lang_code)
Converts the given DVB coded string into a UTF-8 unicode string. The returned string will be preceded...
Definition: stbuni.c:1508
Header file - Function prototypes for A/V control.
void DBDEF_ReleaseString(ADB_STRING *string)
Releases an ADB_STRING.
Definition: ap_dbdef.c:3983
BOOLEAN DBA_LoadDatabase(U8BIT *pathname)
Reads a database from non-volatile storage, creating any structures in memory that will be required t...
Definition: dba_nvm.c:541
BOOLEAN DBDEF_SetLNBUnicable(ADB_LNB_REC *lnb, U32BIT inter_freq, U8BIT chan)
Sets the LNB Unicable settings.
Definition: ap_dbdef.c:4311
ADB_EVENT_ITEMIZED_INFO * DBDEF_GetEventItemizedDescription(ADB_EVENT_REC *e_ptr, U16BIT *num_items_ptr)
Returns the items of extended event descriptor as item descriptor and item itself.
Definition: ap_dbdef.c:2503
void DBDEF_ReleaseProfileList(void **profile_list, U16BIT num_profiles)
Frees a profile list returned by DBDEF_GetProfileList.
Definition: ap_dbdef.c:10104
ADB_TRANSPORT_REC * DBDEF_AddTerrestrialTransportRec(U32BIT freq_hz, U8BIT plp_id, ADB_NETWORK_REC *network)
Adds a terrestrial transport record with the given frequency and PLP id.
Definition: ap_dbdef.c:4874
U16BIT DBDEF_GetNumFavouriteLists(void)
Returns the number of favourite lists.
Definition: ap_dbdef.c:9041
U32BIT APP_NvmRead(E_NVM_ITEMS nvm_item)
Returns the current value for the given DVB setting.
Definition: app_nvm.c:562
BOOLEAN DBDEF_SetLNBRepeats(ADB_LNB_REC *lnb, U8BIT repeats)
Sets the LNB message repeat setting in the range 0 to 3.
Definition: ap_dbdef.c:4285
void DBDEF_SelectBroadcastProfile(void)
Sets the broadcast profile type for for all network, transport and service record accesses...
Definition: ap_dbdef.c:10174
void STB_SIReleaseStringDesc(SI_STRING_DESC *desc)
Frees the memory used by the descriptor specified.
Definition: stbsitab.c:12040
ADB_NETWORK_REC * DBDEF_AddNetworkRec(U16BIT net_id, ADB_SATELLITE_REC *satellite)
Adds a new network record to the database with the given network ID.
Definition: ap_dbdef.c:4644
Application timer functions and defines.
BOOLEAN DBA_GetFieldLangString(void *record, U32BIT field_id, U32BIT lang_code, U8BIT **string, U16BIT *num_bytes)
Gets the string value of a record&#39;s field. The function will fail if the record doesn&#39;t exist...
Definition: dba_nvm.c:1460
ADB_SERVICE_REC * DBDEF_GetTunedService(U8BIT path)
Returns the currently tuned service on the given path.
Definition: ap_dbdef.c:8084
void STB_OSMutexUnlock(void *mutex)
Unlock a mutex (a.k.a. &#39;leave&#39;, &#39;signal&#39; or &#39;release&#39;)
U32BIT ACFG_ConvertLangIdToCode(U8BIT lang_id)
Returns the language code for the given language id.
Definition: ap_cfg.c:957
LINK_LIST_PTR_BLK * STB_LLGetLastBlock(LINK_LIST_HEADER *hdr)
Returns a pointer to the last block in the linked list, identified by hdr.
Definition: stbllist.c:665
BOOLEAN DBDEF_TransportInProfile(ADB_TRANSPORT_REC *t_ptr)
Checks whether the given transport is valid for the current profile. There may be multiple CI+ profil...
Definition: ap_dbdef.c:10312
ADB_LNB_REC * DBDEF_GetNextLNBRec(ADB_LNB_REC *lnb_ptr)
Returns the next LNB record after the one given. If the argument is NULL then the first record is ret...
Definition: ap_dbdef.c:4338
BOOLEAN DBDEF_SetLNB12V(ADB_LNB_REC *lnb, BOOLEAN is_12v)
Sets the LNB 12V setting.
Definition: ap_dbdef.c:4110
AllocLcnFunc ACFG_GetSatelliteLcnFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to assign LCNs following a DVB-S/S2 scan for the given co...
Definition: ap_cfg.c:1864
void DBDEF_DeleteImageIcons(ADB_IMAGE_ICON *icon_list)
Frees given list of image icons and any associated memory.
Definition: ap_dbdef.c:3849
void DBDEF_DeleteServiceRec(ADB_SERVICE_REC *s_ptr)
Deletes specified service record.
Definition: ap_dbdef.c:1754
ADB_FAVLIST_REC * DBDEF_FindFavouriteList(U8BIT list_id)
Return the favourite list with the given list id.
Definition: ap_dbdef.c:9237
void DBDEF_SetSatTransportTuningParams(ADB_TRANSPORT_REC *t_ptr, U32BIT freq_hz, U16BIT symbol_rate, E_STB_DP_POLARITY polarity, BOOLEAN dvb_s2, E_STB_DP_MODULATION modulation, ADB_NETWORK_REC *network)
Sets the tuning parameters for an existing satellite transport.
Definition: ap_dbdef.c:5271
ADB_LNB_REC * DBDEF_AddLNB(E_STB_DP_LNB_TYPE type, ADB_STRING *name)
Add an LNB record to the database.
Definition: ap_dbdef.c:4012
void DBDEF_TidyDatabaseAfterSearch(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite, BOOLEAN search_completed, BOOLEAN manual)
Calls any country and tuner type specific function to tidy up the database following a search...
Definition: ap_dbdef.c:8256
void DBDEF_SetAnalogServiceName(ADB_SERVICE_REC *s_ptr, U8BIT *new_name, U8BIT new_len)
Updates analog service names - ASSUMES NORMAL ASCII CODED.
Definition: ap_dbdef.c:6903
ADB_FAVSERV_REC * DBDEF_GetPrevServiceFromFavouriteList(ADB_FAVLIST_REC *fav_list, ADB_FAVSERV_REC *fav_serv)
Returns the previous favourite list service record.
Definition: ap_dbdef.c:9554
U8BIT * DBDEF_GetEventDescription(ADB_EVENT_REC *e_ptr)
Returns the short event description text of the event as a UTF-8 string. The returned string should b...
Definition: ap_dbdef.c:2175
BOOLEAN DBDEF_SetLNBDiSEqCTone(ADB_LNB_REC *lnb, E_STB_DP_DISEQC_TONE diseqc_tone)
Sets the LNB DiSEqC tone setting.
Definition: ap_dbdef.c:4185
void * STB_AppResizeMemory(void *ptr, U32BIT new_num_bytes)
Re-allocates a given memory area to the new size, ensuring data contained within the original memory ...
Definition: stbheap.c:891
BOOLEAN DBDEF_GetEventAudioDescriptionFlag(ADB_EVENT_REC *e_ptr)
Returns whether audio description is signalled as being available for the given event.
Definition: ap_dbdef.c:2984
ADB_STRING * DBDEF_GetServiceProviderName(ADB_SERVICE_REC *s_ptr)
Returns a pointer to the service provider name.
Definition: ap_dbdef.c:6682
ADB_STRING * DBDEF_MakeString(U32BIT lang_code, U8BIT *str_ptr, U16BIT nbytes)
Creates an ADB_STRING, copying the given data into it. If the string passed in is NULL or the number ...
Definition: ap_dbdef.c:3890
U8BIT STB_DPGetNumPaths(void)
Returns the maximum number of decode paths.
Definition: stbdpc.c:532
U16BIT DBDEF_GetNumServices(void)
Returns the total number of services.
Definition: ap_dbdef.c:5506
E_STB_DP_ANALOG_VIDEO_TYPE STB_DPGetAnalogVideoType(U8BIT path)
Reads the analogue video type value from decode path store.
Definition: stbdpc.c:6841
ADB_EVENT_CONTENT DBDEF_GetEventGenre(ADB_EVENT_REC *e_ptr, ADB_SERVICE_REC *s_ptr)
Returns the genre of an event.
Definition: ap_dbdef.c:3440
DBTidyFunc ACFG_GetCableDBTidyFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to tidy up the database following a DVB-C scan for the gi...
Definition: ap_cfg.c:1940
ADB_SERVICE_REC * DBDEF_GetPrevServiceRec(ADB_SERVICE_REC *s_ptr)
Returns the service before the one given. If NULL is passed then the last service in the list is retu...
Definition: ap_dbdef.c:5566
void DBDEF_GetTransportAdditionalFrequencies(ADB_TRANSPORT_REC *t_ptr, U8BIT *num_freqs, U32BIT **freqs)
Returns the additional frequencies associated with a transport. The returned array should not be modi...
Definition: ap_dbdef.c:5408
ADB_TRANSPORT_REC * DBDEF_GetNextTransportRec(ADB_TRANSPORT_REC *t_ptr)
Returns the transport following the one given. If the argument is NULL then the first transport will ...
Definition: ap_dbdef.c:4842
S8BIT STB_CompareUnicodeStrings(U8BIT *string1_ptr, U8BIT *string2_ptr, BOOLEAN exact_match, BOOLEAN ignore_case)
Compares the contents of the two given unicode strings and returns the status (as per strcmp) ...
Definition: stbuni.c:910
U16BIT DBDEF_GetNumLNBs(void)
Returns the number of LNB records in the database.
Definition: ap_dbdef.c:3999
U16BIT DBDEF_GetNumProfiles(void)
Returns the number of network profiles.
Definition: ap_dbdef.c:9988
ADB_LNB_BAND_REC * DBDEF_AddLNBBandRec(S_STB_DP_LNB_BAND *band_parameters, ADB_LNB_REC *associated_lnb)
Add an LNB band record to the database.
Definition: ap_dbdef.c:4506
ADB_PROFILE_TYPE DBDEF_GetCurrentProfileType(void)
Returns the current profile type.
Definition: ap_dbdef.c:10163
ADB_SERVICE_REC * DBDEF_FindServiceRec(U16BIT serv_id, ADB_TRANSPORT_REC *t_ptr)
Search for the service with the given service ID on the given transport.
Definition: ap_dbdef.c:6119
void DBDEF_SetNetworkName(ADB_NETWORK_REC *n_ptr, U8BIT *name)
Set or change the name of the given network.
Definition: ap_dbdef.c:4708
BOOLEAN DBA_GetFieldString(void *record, U32BIT field_id, U8BIT **string, U16BIT *num_bytes)
Gets the string value of a record&#39;s field. The function will fail if the record doesn&#39;t exist...
Definition: dba_nvm.c:1400
void DBDEF_SaveServiceEventSchedule(ADB_SERVICE_REC *s_ptr)
Saves the event schedule of a service to the service database.
Definition: ap_dbdef.c:5994
BOOLEAN DBDEF_ServiceForTunerType(ADB_SERVICE_REC *s_ptr, E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
Checks whether the given service is a terrestrial, cable or satellite service, and optionally check w...
Definition: ap_dbdef.c:9775
BOOLEAN DBDEF_AddAnalogService(void)
Adds an analogue service, transport and, if necessary, network to the database based on the current t...
Definition: ap_dbdef.c:6825
U8BIT * DBDEF_GetEventContentData(ADB_EVENT_REC *e_ptr, U8BIT *p_len)
Returns the level 1 and 2 values for all content identifiers for the given event. ...
Definition: ap_dbdef.c:3406
void STB_ReleaseUnicodeString(U8BIT *string)
Releases the specified unicode string, freeing associated heap resources.
Definition: stbuni.c:1955
U8BIT * DBDEF_GetServiceDefaultAuthority(ADB_SERVICE_REC *s_ptr)
Returns a copy of the default authority CRID string for the given service. This string will be return...
Definition: ap_dbdef.c:3700
void DBDEF_ReleaseAccess(void)
Releases access to the app&#39;s database.
Definition: ap_dbdef.c:245
void DBDEF_TidyDatabaseUK(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
Iterates through all the services following a search search to see whether any need to be deleted bas...
Definition: ap_dbdef.c:8474
U16BIT DBDEF_GetNumDeletedServices(E_STB_DP_SIGNAL_TYPE tuner_type)
Returns the number of services that are marked as deleted for the given tuner type.
Definition: ap_dbdef.c:6737
void DBDEF_SetTransportOrigNetworkId(ADB_TRANSPORT_REC *t_ptr, U16BIT orig_net_id)
Sets the original network ID of the given transport.
Definition: ap_dbdef.c:5387
BOOLEAN DBA_Initialise(void)
Performs any initialisation required prior to the database being loaded.
Definition: dba_nvm.c:482
BOOLEAN ACFG_IsNordigCountry(void)
Returns whether the current country requires Nordig compliance for SI.
Definition: ap_cfg.c:1656
BOOLEAN DBA_SetFieldString(void *record, U32BIT field_id, U8BIT *string, U16BIT num_bytes)
Set the string value of a record&#39;s field. The function will fail if the record doesn&#39;t exist...
Definition: dba_nvm.c:1227
void DBDEF_UpdateCridEitDate(ADB_CRID_REC *c_ptr)
Updates the stored EIT date of this CRID with the current GMT date.
Definition: ap_dbdef.c:8920
void STB_SPDebugWrite(const char *format,...)
Write debug string to serial/debug port. <CR><LF> characters will be automatically added to the end o...
Debug functions header file.
void STB_LLRemoveBlock(LINK_LIST_PTR_BLK *blk)
Removes the block identified by the blk pointer from its linked list.
Definition: stbllist.c:488
Header file - Function prototypes for linked lists.
Header file - macros and function prototypes for public use.
U8BIT * STB_ConcatUnicodeStrings(U8BIT *string1_ptr, U8BIT *string2_ptr)
Appends the contents of string2_ptr to string1_ptr and returns a pointer to the newly created string...
Definition: stbuni.c:618
void DBDEF_SetTextLang(U8BIT *lang_ids)
sets current text lang
Definition: ap_dbdef.c:8115
void STB_OSMutexLock(void *mutex)
Lock a mutex (a.k.a. &#39;enter&#39;, &#39;wait&#39; or &#39;get&#39;).
Header file - macros and function prototypes for public use.
ADB_SERVICE_REC * DBDEF_CopyServiceRec(ADB_SERVICE_REC *orig_serv)
Creates a copy of the given service, copying the service&#39;s attributes, e.g. service name...
Definition: ap_dbdef.c:5663
void DBDEF_SetCridDoNotDelete(ADB_CRID_REC *c_ptr, BOOLEAN do_not_delete)
Sets the do not delete flag in the crid record.
Definition: ap_dbdef.c:8903
ADB_TRANSPORT_REC * DBDEF_AddCableTransportRec(U32BIT freq_hz, U32BIT symbol_rate, ADB_NETWORK_REC *network)
Adds a cable transport record with the given frequency and symbol rate.
Definition: ap_dbdef.c:4982
LINK_LIST_PTR_BLK * STB_LLGetNextBlock(LINK_LIST_PTR_BLK *blk)
Returns a pointer to the next block in the linked list, or NULL if at the end of the list...
Definition: stbllist.c:566
U8BIT ACFG_ConvertLangCodeToId(U32BIT lang_code)
Returns the language id for the given language code.
Definition: ap_cfg.c:931
Database access defines, structures and public functions.
U32BIT STB_DPGetFrequency(U8BIT path)
Reads the frequency value from decode path store.
Definition: stbdpc.c:6092
ADB_SERVICE_REC * DBDEF_GetNextServiceRec(ADB_SERVICE_REC *s_ptr)
Returns the service after the one given. If NULL is passed then the first service in the list is retu...
Definition: ap_dbdef.c:5535
ADB_TRANSPORT_REC * DBDEF_FindCableTransportRec(U32BIT freq_hz, U32BIT symbol_rate)
Find the cable transport record in the database matching the given params.
Definition: ap_dbdef.c:5040
void * DBA_FindRecord(U32BIT record_id, void *parent, void *last_rec)
Finds the next record, of the given type, that comes after last_rec. last_rec must be the same type o...
Definition: dba_nvm.c:1055
ADB_FAVLIST_REC * DBDEF_GetNextFavouriteList(ADB_FAVLIST_REC *fav_list)
Returns the favourite list following the given item.
Definition: ap_dbdef.c:9212
U8BIT * STB_SIReadString(U8BIT nbytes, U8BIT *dptr, SI_STRING_DESC **str_ptr)
Copies a string from a descriptor for the specified length. Converts the number of bytes specified in...
Definition: stbsitab.c:10947
Application configuration data.
void ADB_ReleaseRCTLinks(void *links)
Frees the given list of RCT links.
Definition: ap_dbacc.c:6317
void DBDEF_SetFavouriteListUserData(ADB_FAVLIST_REC *fav_list, U32BIT user_data)
Saves the given user data with a favourite list.
Definition: ap_dbdef.c:9263
U16BIT DBDEF_GetNumNetworks(void)
Returns the number of networks in ther service database.
Definition: ap_dbdef.c:4631
U8BIT * DBDEF_GetSecondaryAudioLang(void)
returns current secondary audio lang
Definition: ap_dbdef.c:8241
ADB_STRING * DBDEF_GetServiceName(ADB_SERVICE_REC *s_ptr, BOOLEAN short_name, BOOLEAN pref_name)
Returns a pointer to the service name, taking into account perferred names and short names...
Definition: ap_dbdef.c:6586
void DBDEF_SetServiceFavGroups(ADB_SERVICE_REC *s_ptr, U8BIT groups)
Sets the favourite groups for a service.
Definition: ap_dbdef.c:7001
ADB_SERVICE_REC * DBDEF_AddServiceRec(U16BIT serv_id, ADB_TRANSPORT_REC *t_ptr)
Adds a new service record to the service database with the given service ID and parent transport...
Definition: ap_dbdef.c:5598
Header for STB unicode string handling routines.
void DBDEF_DeleteStreamList(ADB_STREAM_REC *slist)
Deletes all records in a service stream list.
Definition: ap_dbdef.c:1941
DBTidyFunc ACFG_GetTerrestrialDBTidyFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to tidy up the database following a DVB-T/T2 scan for the...
Definition: ap_cfg.c:1912
void DBDEF_SetTunedNetwork(U8BIT path, ADB_NETWORK_REC *n_ptr)
sets the currently tuned network
Definition: ap_dbdef.c:7996
void STB_DPSetTunedService(U8BIT path, void *service)
Saves the given service with the specified decode path.
Definition: stbdpc.c:1563
void DBDEF_RequestAccess(void)
Requests access to the app&#39;s database.
Definition: ap_dbdef.c:235
BOOLEAN DBDEF_NetworkInProfile(ADB_NETWORK_REC *n_ptr)
Checks whether the given network is valid for the current profile. There may be multiple CI+ profiles...
Definition: ap_dbdef.c:10348
LINK_LIST_PTR_BLK * STB_LLGetFirstBlock(LINK_LIST_HEADER *hdr)
Returns a pointer to the first block in the linked list, identified by hdr.
Definition: stbllist.c:633
BOOLEAN DBDEF_SetServiceProviderName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
Set or change the name of a service&#39;s provider.
Definition: ap_dbdef.c:5910
U8BIT * DBDEF_GetEventName(ADB_EVENT_REC *e_ptr)
Returns the name of the event as a UTF-8 string in the currently selected language. The returned string should be freed using STB_ReleaseUnicodeString.
Definition: ap_dbdef.c:2055
ADB_NETWORK_REC * DBDEF_FindNetworkRec(U16BIT net_id, ADB_SATELLITE_REC *satellite)
Finds the network with the given network ID.
Definition: ap_dbdef.c:4772
void * STB_DPGetTunedTransport(U8BIT path)
Returns the transport saved with the given decode path.
Definition: stbdpc.c:1537
BOOLEAN DBDEF_LoadDatabase(U8BIT *db_pathname)
Loads the service database from non-volatile storage and creates the RAM version of this data that wi...
Definition: ap_dbdef.c:259
void DBDEF_DeleteFavouriteList(ADB_FAVLIST_REC *fav_list)
Deletes the given favourite list.
Definition: ap_dbdef.c:9339
void DBDEF_PushBroadcastProfile(void)
Saves the current profile and any related data so that it can restored using DBDEF_PopProfile(), and sets the broadcast profile type for for all network, transport and service record accesses.
Definition: ap_dbdef.c:10186
void DBDEF_DeleteTransportRec(ADB_TRANSPORT_REC *t_ptr)
Deletes the given transport from the service database, deleting any service records that it&#39;s the par...
Definition: ap_dbdef.c:5431
ADB_STRING * DBDEF_CopyString(ADB_STRING *src_str)
Creates a copy of the given ADB_STRING.
Definition: ap_dbdef.c:3922
BOOLEAN DBDEF_IsValidCridRecord(ADB_CRID_REC *c_ptr)
Checks whether the given crid record is in the list of valid crid records.
Definition: ap_dbdef.c:9007
U32BIT ACFG_GetCountry(void)
Returns the country code the DVB is configured for.
Definition: ap_cfg.c:150
ADB_FAVSERV_REC * DBDEF_GetNextServiceFromFavouriteList(ADB_FAVLIST_REC *fav_list, ADB_FAVSERV_REC *fav_serv)
Returns the next favourite list service record.
Definition: ap_dbdef.c:9529
BOOLEAN DBDEF_SetLNBSmatv(ADB_LNB_REC *lnb, BOOLEAN is_smatv)
Sets the LNB SMATV setting.
Definition: ap_dbdef.c:4260
U32BIT STB_GetNumBytesInString(U8BIT *string_ptr)
Determines the no of bytes of the given string.
Definition: stbuni.c:311
U8BIT DBDEF_NumberOfCridsOfType(ADB_EVENT_REC *e_ptr, U8BIT crid_type)
Returns the number of CRIDs of the given type for the event.
Definition: ap_dbdef.c:3587
BOOLEAN DBDEF_ServiceInProfile(ADB_SERVICE_REC *s_ptr)
Checks whether the given service is valid for the current profile. There may be multiple CI+ profiles...
Definition: ap_dbdef.c:10276
U16BIT DBDEF_GetReqdVideoPid(ADB_SERVICE_REC *s_ptr, ADB_STREAM_TYPE *video_type)
Returns the video pid and type that should be used for the given service from the list of video strea...
Definition: ap_dbdef.c:6531
ADB_SERVICE_REC * DBDEF_GetNextServiceOnTransport(ADB_SERVICE_REC *s_ptr, ADB_TRANSPORT_REC *t_ptr)
Find the next service following the given service that&#39;s on the given transport.
Definition: ap_dbdef.c:6083
Application stb layer control.
void DBDEF_DeleteNetworkRec(ADB_NETWORK_REC *n_ptr)
Deletes specified network record.
Definition: ap_dbdef.c:4696
U8BIT * DBDEF_GetSecondaryTextLang(void)
returns array of secondary text langs
Definition: ap_dbdef.c:8169
ADB_SERVICE_REC * DBDEF_FindServiceRecByFreesatId(ADB_SERVICE_REC *servp, U16BIT freesat_id)
Search for a service with the given Freesat ID.
Definition: ap_dbdef.c:6252
void DBDEF_DeleteServiceFromFavouriteList(ADB_FAVLIST_REC *fav_list, ADB_FAVSERV_REC *fav_serv)
Delete the given service from the given favourite list.
Definition: ap_dbdef.c:9639
void DBDEF_DeleteAllServicesFromFavouriteList(ADB_FAVLIST_REC *fav_list)
Delete the all services from the given favourite list.
Definition: ap_dbdef.c:9673
Header file - Function prototypes for operating system.
System Wide Global Technical Data Type Definitions.
BOOLEAN DBA_SetFieldValue(void *record, U32BIT field_id, U32BIT value)
Set the value of a record&#39;s field. The function will fail if the record doesn&#39;t exist, the record doesn&#39;t include the given field, or the field is a string value.
Definition: dba_nvm.c:1175
void DBDEF_DeleteAllRecords(void)
Deletes all records in the database.
Definition: ap_dbdef.c:1486
U16BIT DBDEF_GetServicePmtPid(ADB_SERVICE_REC *s_ptr)
gets the PMT PID associated with the service
Definition: ap_dbdef.c:6980
ADB_SATELLITE_REC * DBDEF_GetNextSatelliteRec(ADB_SATELLITE_REC *sat_ptr)
Returns the next satellite record after the one given. If the argument is NULL then the first record ...
Definition: ap_dbdef.c:4469
ADB_SATELLITE_REC * DBDEF_AddSatelliteRec(ADB_STRING *name_str, U16BIT dish_pos, U16BIT long_pos, BOOLEAN east_west, ADB_LNB_REC *associated_lnb)
Add a satellite record to the database.
Definition: ap_dbdef.c:4378
ADB_NETWORK_REC * DBDEF_GetTunedNetwork(U8BIT path)
gets the currently tuned network
Definition: ap_dbdef.c:8015
void STB_AppFreeMemory(void *addr)
Releases previously allocated application heap memory.
Definition: stbheap.c:781
void DBDEF_SetServicePmtPid(ADB_SERVICE_REC *s_ptr, U16BIT pmt_pid)
Updates the pmt pid.
Definition: ap_dbdef.c:6959
U8BIT * DBDEF_GetAudioLang(void)
returns current audio lang
Definition: ap_dbdef.c:8223
BOOLEAN DBDEF_GetEventHDLinkageInfo(ADB_EVENT_REC *e_ptr, BOOLEAN verify_event, BOOLEAN only_simulcast, ADB_SERVICE_REC **hd_serv_ptr, ADB_EVENT_REC **hd_event_ptr)
Returns whether there&#39;s an HD event linked to the SD event and returns the info for it...
Definition: ap_dbdef.c:3042
void DBDEF_DeleteRecordsForTunerType(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
Deletes all network, transport and services records for the given tuner type.
Definition: ap_dbdef.c:1588
ADB_TRANSPORT_REC * DBDEF_GetTunedTransport(U8BIT path)
gets the currently tuned transport
Definition: ap_dbdef.c:8053
void DBDEF_SetServiceDeletedFlag(ADB_SERVICE_REC *s_ptr, BOOLEAN deleted)
Marks whether a service is deleted or not.
Definition: ap_dbdef.c:6721
BOOLEAN DBDEF_SetLNBUSwitch(ADB_LNB_REC *lnb, U8BIT uswitch)
Sets the LNB uncommitted switch setting.
Definition: ap_dbdef.c:4235
U8BIT * DBDEF_GetServiceGuidance(ADB_SERVICE_REC *s_ptr)
Returns the guidance text for the service, as a UTF-8 string. The returned string should be freed usi...
Definition: ap_dbdef.c:2918
BOOLEAN DBDEF_SetServiceShortName(ADB_SERVICE_REC *s_ptr, U8BIT *name)
Set or change the short name of a service.
Definition: ap_dbdef.c:5850
ADB_NETWORK_REC * DBDEF_FindOrAddPrivateNetwork(void *satellite)
Find or add a private network, assigning an unused private network ID.
Definition: ap_dbdef.c:10603
ADB_EVENT_DESC * DBDEF_FindEventDescriptor(ADB_EVENT_DESC *start_desc, U8BIT desc_tag, U32BIT private_data_specifier)
Searches a descriptor list for the first descriptor with the given descriptor tag.
Definition: ap_dbdef.c:2003
U16BIT DBDEF_GetNumTransports(void)
Returns the number of transports in ther service database.
Definition: ap_dbdef.c:4829
U8BIT * DBDEF_GetFullCrid(ADB_SERVICE_REC *serv_ptr, U8BIT *event_str)
Returns the full CRID for the given CRID string The returned string should be freed using STB_AppFree...
Definition: ap_dbdef.c:3649
BOOLEAN DBA_SetFieldData(void *record, U32BIT field_id, U8BIT *data, U16BIT num_bytes)
Set a variable amount of data of a record&#39;s field. The function will fail if the record doesn&#39;t exist...
Definition: dba_nvm.c:1318
AllocLcnFunc ACFG_GetCableLcnFunction(U32BIT country_code)
Returns a pointer to a function that&#39;s used to assign LCNs following a DVB-C scan for the given count...
Definition: ap_cfg.c:1816
void STB_LLAddBlockBefore(LINK_LIST_PTR_BLK *blk, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the linked list before the block identified by th...
Definition: stbllist.c:403
void DBDEF_SetSecondaryAudioLang(U8BIT *lang_ids)
sets the secondary audio lang
Definition: ap_dbdef.c:8205
U8BIT * DBDEF_GetEventExtendedDescription(ADB_EVENT_REC *e_ptr)
Returns the extended event description text of the event as a UTF-8 string. The returned string shoul...
Definition: ap_dbdef.c:2302
U8BIT * DBDEF_GetEventCrid(ADB_SERVICE_REC *serv_ptr, ADB_EVENT_REC *e_ptr, U8BIT crid_type, U8BIT index)
Returns the full CRID of the type given for the given event.
Definition: ap_dbdef.c:3515
U16BIT DBDEF_GetNumLNBBands(void)
Returns the number of LNB band records in the database.
Definition: ap_dbdef.c:4493
Header file - Function prototypes for heap memory.
void DBA_DestroyRecord(void *record)
Destroys the given record, removing it from the database and freeing any memory associated with it...
Definition: dba_nvm.c:1013
void * STB_OSCreateMutex(void)
Create a mutex.
E_STREAM_MATCH_TYPE DBDEF_GetReqdSubtitleParams(ADB_SERVICE_REC *s_ptr, U16BIT *pid_ptr, U16BIT *cpage_ptr, U16BIT *apage_ptr)
Gets the appropriate subtitle pid and page ids - looks first for the params matching exactly the requ...
Definition: ap_dbdef.c:6472
void DBDEF_SetFavouriteListName(ADB_FAVLIST_REC *f_ptr, U8BIT *name)
Set or change the name of the given favourite list.
Definition: ap_dbdef.c:9706
void DBDEF_TidyDatabaseDefault(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN search_completed, BOOLEAN manual)
Iterates through all the services following a search search to see whether any need to be deleted bas...
Definition: ap_dbdef.c:8656
ADB_STRING * DBDEF_ConcatSIString(ADB_STRING *str1, SI_STRING_DESC *str2)
Concatenates an SI_STRING_DESC string to the end of an ADB_STRING string, removing any terminating &#39;\...
Definition: ap_dbdef.c:3948
U8BIT * ACFG_GetEventContentTypes(U32BIT country_code)
Returns the event content types for the given country. This defines how the content type value broadc...
Definition: ap_cfg.c:1529
void DBDEF_SetCridService(ADB_CRID_REC *c_ptr, U16BIT serv_id)
Sets the service ID in the crid record.
Definition: ap_dbdef.c:8863
void DBDEF_MoveFavouriteListTo(ADB_FAVLIST_REC *fav_list, S16BIT index)
Changes the order of the favourite lists by moving the given list to the given position.
Definition: ap_dbdef.c:9283
BOOLEAN DBDEF_GetEventSubtitlesAvailFlag(ADB_EVENT_REC *e_ptr)
Returns whether DVB subtitles are signalled as being available for the given event.
Definition: ap_dbdef.c:3363
void DBDEF_SortTimers(BOOLEAN date_time_order)
Sorts timer list into date/time or alphabetical order.
Definition: ap_dbdef.c:9946
U16BIT ACFG_GetFirstUnallocatedLcn(U32BIT country_code, E_STB_DP_SIGNAL_TYPE tuner_type)
Returns the first LCN that should be used when assigning LCNs to services that don&#39;t appear in an LCN...
Definition: ap_cfg.c:1156
BOOLEAN DBDEF_SetLNBPulsePosition(ADB_LNB_REC *lnb, BOOLEAN is_pulse_posn)
Sets the LNB pulse position setting.
Definition: ap_dbdef.c:4135
BOOLEAN DBDEF_TransportForTunerType(ADB_TRANSPORT_REC *t_ptr, E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
Checks whether the given transport is a terrestrial, cable or satellite transport, and optionally check whether it&#39;s on a particular satellite.
Definition: ap_dbdef.c:9805
ADB_TRANSPORT_REC * DBDEF_FindTransportRecByIds(ADB_TRANSPORT_REC *transp, U32BIT net_id, U32BIT onet_id, U32BIT tran_id)
Find a transport record matching the given set of IDs, starting from the given transport.
Definition: ap_dbdef.c:5314
BOOLEAN DBDEF_AllocateLcns(E_STB_DP_SIGNAL_TYPE tuner_type, BOOLEAN assign_lcns)
allocates lcns - expects allocated lcn for all services to be 0
Definition: ap_dbdef.c:7038
BOOLEAN DBDEF_SetLNBPower(ADB_LNB_REC *lnb, E_STB_DP_LNB_POWER power)
Sets the LNB power setting.
Definition: ap_dbdef.c:4060
void DBA_LockDatabase(void)
Locks the database to prevent access from other threads or processes.
Definition: dba_nvm.c:866
U16BIT STB_GCGetGMTDate(void)
Reads the current GMT date code.
Definition: stbgc.c:1207
ADB_CRID_REC * DBDEF_AddCridRecord(U8BIT *crid, BOOLEAN series, BOOLEAN recommended)
Creates a CRID record and adds it to the database.
Definition: ap_dbdef.c:8793
void DBDEF_Initialise(void)
Initialises the database, preparing for it to be accessed.
Definition: ap_dbdef.c:201
void DBA_UnlockDatabase(void)
Unlocks the database to allow other threads or processes to access it.
Definition: dba_nvm.c:876
ADB_TIMER_REC * DBDEF_GetNextTimerRec(ADB_TIMER_REC *timer_ptr)
Returns the next timer record after the one given. If the argument is NULL then the first record is r...
Definition: ap_dbdef.c:9922
BOOLEAN DBA_GetFieldValue(void *record, U32BIT field_id, U32BIT *value)
Gets the value of a record&#39;s field. The function will fail if the record doesn&#39;t exist, the record doesn&#39;t include the given field, or the field is a string value.
Definition: dba_nvm.c:1341
E_STREAM_MATCH_TYPE DBDEF_GetReqdTtextPid(ADB_SERVICE_REC *s_ptr, BOOLEAN for_subtitles, U16BIT *pid_ptr, U8BIT *magazine, U8BIT *page)
Gets the appropriate teletext pid - looks first for the params matching exactly the required teletext...
Definition: ap_dbdef.c:6404
void DBDEF_ClearTableVersionHistory(ADB_TRANSPORT_REC *t_ptr)
Clears the version histories stored in the transport records.
Definition: ap_dbdef.c:5479
void STB_LLInitialiseHeader(LINK_LIST_HEADER *hdr)
Initialise the header variables of the linked list.
Definition: stbllist.c:119
void DBA_SetRecordParent(void *record, void *parent)
Set of change the parent of the given record.
Definition: dba_nvm.c:1080
ADB_TIMER_REC * DBDEF_AddTimerRec(BOOLEAN store_in_nvm)
Creates a new timer record in the database, assigning it a unique handle.
Definition: ap_dbdef.c:9833
void DBDEF_MoveFavouriteListServiceTo(ADB_FAVLIST_REC *fav_list, ADB_FAVSERV_REC *fav_serv, S16BIT index)
Changes the order of the services in the favourite list by moving the given service to the given posi...
Definition: ap_dbdef.c:9581
void DBDEF_SetCridDateTime(ADB_CRID_REC *c_ptr, U32DHMS date_time)
Sets the date and time fields in the crid record.
Definition: ap_dbdef.c:8845
void STB_LLAddBlockToStart(LINK_LIST_HEADER *hdr, LINK_LIST_PTR_BLK *new_blk)
Adds the block identified by the new_blk pointer to the start of the linked list identified by the li...
Definition: stbllist.c:364
void DBDEF_DeleteLNBBandRec(ADB_LNB_BAND_REC *band_ptr)
Deletes an LNB band record from the database.
Definition: ap_dbdef.c:4611
ADB_EVENT_REC * DBDEF_FindScheduleEventById(ADB_SERVICE_REC *s_ptr, U16BIT event_id)
Find an event for a service from its event_id.
Definition: ap_dbdef.c:1967
U16BIT DBDEF_NumStreamsInList(ADB_STREAM_REC *slist)
Returns the number of stream records in the given list.
Definition: ap_dbdef.c:1860
void DBDEF_DeleteAltServList(ADB_ALT_SERV_REC *aslist)
Deletes all records in a service alternate service list.
Definition: ap_dbdef.c:3797
Application database access functions.
BOOLEAN DBDEF_SetLNBDiSEqCPosition(ADB_LNB_REC *lnb, BOOLEAN is_diseqc_posn)
Sets the LNB DiSEqC position setting.
Definition: ap_dbdef.c:4160
BOOLEAN STB_LLSort(LINK_LIST_HEADER *ll_hdr, S16BIT(*cmp_func)(LINK_LIST_PTR_BLK **, LINK_LIST_PTR_BLK **))
Sorts the blocks of a link list object in ascending or descending order NOTE: The order in which the ...
Definition: stbllist.c:161
ADB_NETWORK_REC * DBDEF_GetNextNetworkRec(ADB_NETWORK_REC *n_ptr)
Returns the network following the one given. If the argument is NULL then the first network will be r...
Definition: ap_dbdef.c:4800
U16BIT DBDEF_GetProfileList(void ***profile_list, U16BIT *active_profile)
Gets a list of the available network profiles.
Definition: ap_dbdef.c:10031
ADB_TIMER_REC * DBDEF_FindTimerRec(U32BIT handle)
Returns the timer record with the given timer handle.
Definition: ap_dbdef.c:9899
Header file - macros and function prototypes for public use.
void * DBA_GetRecordParent(void *record)
Returns the handle to the parent of the given record.
Definition: dba_nvm.c:1129
void DBDEF_SortServicesByLcn(void)
Sort the full service list into ascending logical channel number order.
Definition: ap_dbdef.c:7017
void DBDEF_DeleteRCTLinks(ADB_RCT_LINK_INFO *links)
Frees the given list of RCT links.
Definition: ap_dbdef.c:3815