DVBCore  20.3.0
DVBCore Documentation
ap_cntrl.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  *******************************************************************************/
25 // debug macros
26 /*#define DEBUG_TUNING*/
27 /*#define DEBUG_DECODING*/
28 /*#define DEBUG_AV_OUTPUT*/
29 //#define DEBUG_PRINTING_ENABLED
30 /*#define DEBUG_STANDBY*/
31 /*#define DEBUG_SERVICE_SEARCH*/
32 /*#define DEBUG_TOT_SEARCH*/
33 /*#define DEBUG_SSU_SEARCH*/
34 /*#define DEBUG_EIT_SEARCH*/
35 /*#define DEBUG_STARTUP_SEARCH*/
36 /*#define DEBUG_SUBTITLES*/
37 
38 /*#define DEBUG_MHEG*/
39 
40 //#define DEBUG_MEMORY_USAGE
41 
42 //---includes for this file-------------------------------------------------------------------------
43 // compiler library header files
44 #include <string.h>
45 #include <stdio.h>
46 
47 // Ocean Blue Software header files
48 #include "techtype.h"
49 #include "dbgfuncs.h"
50 
51 #include "stbhwos.h"
52 #include "stbhwini.h"
53 #include "stbhwfp.h"
54 #include "stbhwav.h"
55 #include "stbheap.h"
56 #include "stbgc.h"
57 #include "stbdpc.h"
58 #include "stbsiflt.h"
59 #include "stbsitab.h"
60 #include "stbllist.h"
61 #include "stbhwdmx.h"
62 #include "stbdpc.h"
63 #include "stbdsapi.h"
64 #include "stbpes.h"
65 #include "stbpvr.h"
66 #include "stberc.h"
67 #include "stbvtc.h"
68 
69 #ifdef INCLUDE_OTA_SSU
70 #include "stbota.h"
71 #endif
72 
73 #include "stbver.h"
74 #include "stbebutt.h"
75 
76 #ifdef INTEGRATE_HBBTV
77 #include "hbbtv_api.h"
78 #endif
79 
80 #include "app.h"
81 #include "ap_cfg.h"
82 #include "app_nvm.h"
83 #include "ap_dbacc.h"
84 #include "ap_tmr.h"
85 #include "ap_dbdef.h"
86 #include "ap_si.h"
87 #include "ap_cntrl.h"
88 #include "ap_state.h"
89 
90 #include "ap_pvr.h"
91 
92 #ifdef COMMON_INTERFACE
93 #include "ap_ci_int.h"
94 #include "stbcicc.h"
95 #include "ap_ci.h"
96 #include "ap_ciop.h"
97 #include "stbci.h"
98 #endif
99 #include "ca_glue.h"
100 #include "ap_ca.h"
101 
102 #include "dba.h"
103 
104 #ifdef DEBUG_STANDBY
105 #define DBG_STDBY(X) STB_SPDebugWrite X
106 #else
107 #define DBG_STDBY(X)
108 #endif
109 
110 #ifdef DEBUG_SSU_SEARCH
111 #define DBG_SSU(X) STB_SPDebugWrite X
112 #else
113 #define DBG_SSU(X)
114 #endif
115 
116 #ifdef DEBUG_TOT_SEARCH
117 #define TOT_DBG(X) STB_SPDebugWrite X
118 #else
119 #define TOT_DBG(X)
120 #endif
121 
122 #ifdef DEBUG_EIT_SEARCH
123 #define EIT_DBG(X) STB_SPDebugWrite X
124 #else
125 #define EIT_DBG(X)
126 #endif
127 
128 #ifdef DEBUG_SUBTITLES
129 #define SUBT_DBG(X) STB_SPDebugWrite X
130 #else
131 #define SUBT_DBG(X)
132 #endif
133 
134 #if 0
135 #ifdef FUNCTION_START
136 #undef FUNCTION_START
137 #endif
138 #define FUNCTION_START(X) STB_SPDebugWrite(">>> %s\n", # X)
139 
140 #ifdef FUNCTION_FINISH
141 #undef FUNCTION_FINISH
142 #endif
143 #define FUNCTION_FINISH(X) STB_SPDebugWrite("<<< %s\n", # X)
144 #endif
145 
146 #ifdef PVR_LOG
147 extern FILE *pvr_log;
148 extern void LogDateTime();
149 #endif
150 
151 //---constant definitions for this file-------------------------------------------------------------
152 
153 
154 //---local typedefs, structs, enumerations for this file--------------------------------------------
155 
156 typedef enum
157 {
158  EXTERNAL_EVENT,
159  INTERNAL_EVENT
160 } E_ACTL_EVENT_TYPE;
161 
162 typedef enum
163 {
164  INT_EVENT_INITIALISE,
165  INT_EVENT_ENABLE,
166  INT_EVENT_DISABLE,
167  INT_EVENT_UPDATE,
168  INT_EVENT_RF_CHAN_TUNE_REQD,
169  INT_EVENT_TPTR_TUNE_REQD,
170  INT_EVENT_USERDEFINED_TUNE_REQD,
171  INT_EVENT_TUNE_OFF,
172  INT_EVENT_RESTART_DECODING,
173  INT_EVENT_RESTART_AUDIO,
174  INT_EVENT_RESTART_SUBTITLES,
175  INT_EVENT_SCRAMBLE_CHANGE,
176  INT_EVENT_RELEASE_DECODE_LOCK,
177  INT_EVENT_STANDBY_ON,
178  INT_EVENT_STANDBY_OFF,
179  INT_EVENT_STANDBY_VCR_ACTIVE,
180  INT_EVENT_ALT_AV_ALLOWED,
181  INT_EVENT_ALT_AV_NOT_ALLOWED,
182  INT_EVENT_START_MHEG_TUNE,
183  INT_EVENT_ANALOG_TV_ON,
184  INT_EVENT_ANALOG_TV_OFF,
185  INT_EVENT_ANALOG_VIDEO_ALLOWED,
186  INT_EVENT_ANALOG_VIDEO_NOT_ALLOWED
187 } E_ACTL_INTERNAL_EVENT;
188 
189 typedef enum
190 {
191  TUNED_STATUS_NO_SIGNAL,
192  TUNED_STATUS_BAD_SIGNAL,
193  TUNED_STATUS_GOOD_SIGNAL
194 } E_ACTL_TUNED_STATUS;
195 
196 typedef enum
197 {
198  TSTATE_OFF,
199  TSTATE_TUNING,
200  TSTATE_NOT_TUNED,
201  TSTATE_TUNED,
202  TSTATE_ANALOG
203 } E_ACTL_TUNING_STATE;
204 
205 // the order of these states is important - the following code uses >= comparisons to check
206 // for a number of states in one go. Do not change without checking the code.
207 typedef enum
208 {
209  DSTATE_DISABLED,
210  DSTATE_OFF,
211  DSTATE_STARTING_BAD_SIGNAL,
212  DSTATE_STARTING,
213  DSTATE_LOCKED,
214  DSTATE_DECODING,
215  DSTATE_PAUSED_SIGNAL,
216  DSTATE_PAUSED_USER,
217  DSTATE_PAUSED_SIGNAL_AND_USER
218 } E_ACTL_DECODING_STATE;
219 
220 
221 typedef struct
222 {
223  const E_STB_AV_VIDEO_FORMAT mode;
224  U16BIT width;
225  U16BIT height;
227 
228 
229 typedef enum
230 {
231  SEARCH_TYPE_NOSEARCH,
232  SEARCH_TYPE_SERVICE_FREQ,
233  SEARCH_TYPE_SERVICE_NETWORK,
234  SEARCH_TYPE_STARTUP,
235  SEARCH_TYPE_MANUAL_FREQ,
236  SEARCH_TYPE_MANUAL_NETWORK,
237  SEARCH_TYPE_SSU,
238  SEARCH_TYPE_OTA_UPDATE,
239  SEARCH_TYPE_TOT,
240  SEARCH_TYPE_EIT_PF,
241  SEARCH_TYPE_EIT_SCHED,
242  SEARCH_TYPE_EIT_PF_SCHED
243 } E_SEARCH_TYPE;
244 
245 
246 #ifdef INCLUDE_OTA_SSU
247 typedef struct
248 {
249  BOOLEAN ota_started;
250  U8BIT ota_path;
251  void *ota_location;
252  U16BIT ota_onet_id;
253  U16BIT ota_tran_id;
254  U16BIT ota_serv_id;
255  F_SSU_VERSION_CALLBACK version_cb;
256 } S_OTA_SETTINGS;
257 #endif
258 
259 
260 //---local (static) variable declarations for this file---------------------------------------------
261 // (internal variables declared static to make them local)
262 
263 static BOOLEAN initialised = FALSE;
264 
265 #ifdef INCLUDE_OTA_SSU
266 static S_OTA_SETTINGS ota_settings;
267 #endif
268 
269 // required state
270 static U16BIT rf_chan_id_required;
271 static void **transport_required;
272 static E_STB_DP_SIGNAL_TYPE signal_type_required;
273 static BOOLEAN tuner_relock_required;
274 static void **service_required;
275 static E_APP_SI_MODE *si_required;
276 static BOOLEAN decode_lock_override_required;
277 
278 #ifdef COMMON_INTERFACE
279 static void *tuneto_live_service;
280 static void *tuneto_live_transport;
281 static E_ACTL_SI_SRCH_REQD tuneto_live_si;
282 static BOOLEAN tuneto_relock;
283 static BOOLEAN tuneto_for_recording;
284 static S_ACTL_OWNER_INFO *tuneto_owner_info;
285 static U32BIT ci_ai_module;
286 #endif
287 
288 static S_MANUAL_TUNING_PARAMS *user_tuning_params;
289 static E_ACTL_TUNING_STATE *tuning_state;
290 static E_ACTL_DECODING_STATE *decoding_state;
291 static void **cntrl_mutex;
292 
293 // status information
294 static void **current_satellite;
295 static ADB_SERVICE_REC **current_service;
296 static void **current_transport;
297 static E_APP_SI_MODE *current_si;
298 static BOOLEAN current_tuner_relock;
299 static E_ACTL_AV_MODE av_mode;
300 static BOOLEAN audio_muted;
301 static U8BIT audio_volume;
302 static U8BIT ad_volume;
303 static S8BIT volume_scaling = 0;
304 static BOOLEAN ci_ui_request;
305 static BOOLEAN *decoding_started;
306 static BOOLEAN *decoding_locked;
307 static S32BIT *now_event_id;
308 
309 static BOOLEAN dvb_subtitles;
310 static BOOLEAN subtitles_started;
311 static BOOLEAN subtitles_running;
312 static BOOLEAN subtitles_suppressed;
313 
314 static BOOLEAN external_control = FALSE;
315 static F_ServiceGetSubtitlePid GetSubtitlePidFunc = ADB_ServiceGetSubtitlePid;
316 
317 static E_ACTL_TUNED_STATUS *tuned_status;
318 static BOOLEAN audio_desc_on;
319 
320 //pause flag
321 static BOOLEAN *decode_paused_flag;
322 
323 static U8BIT standby_path = INVALID_RES_ID;
324 
325 /* Values used during searches */
326 static E_SEARCH_TYPE current_search_type = SEARCH_TYPE_NOSEARCH;
327 static E_SEARCH_TYPE required_search_type = SEARCH_TYPE_NOSEARCH;
328 static U8BIT search_path = INVALID_RES_ID;
329 static U16BIT search_list_id;
330 static E_STB_DP_SIGNAL_TYPE current_search_tuner_type = SIGNAL_NONE;
331 
332 /* Service search */
333 static E_STB_TUNE_THIERARCHY terr_hierarchy;
334 static U8BIT t2_plp_id;
335 
336 /* Startup search */
337 static U16BIT search_num_transports;
338 static void **search_transport_list = NULL;
339 
340 /* EIT search */
341 static U32BIT eit_search_end_timer = INVALID_TIMER_HANDLE;
342 static U32BIT standby_wakeup_timer = INVALID_TIMER_HANDLE;
343 #ifdef COMMON_INTERFACE
344 static U32DHMS start_standby_time;
345 #endif
346 static U16BIT standby_grace_timeout = 0;
347 static U32BIT standby_grace_timer = INVALID_TIMER_HANDLE;
348 
349 static BOOLEAN hdmi_connected = FALSE;
350 
351 // can't make this const due to VIDEO_FORMAT_AUTO
352 static S_VIDEO_FORMAT_DESC app_video_formats[] = {
353  {VIDEO_FORMAT_2160P50UHD, 3840, 2160},
354  {VIDEO_FORMAT_2160P60UHD, 3840, 2160},
355  {VIDEO_FORMAT_2160P25UHD, 3840, 2160},
356  {VIDEO_FORMAT_2160P30UHD, 3840, 2160},
357  {VIDEO_FORMAT_2160P24UHD, 3840, 2160},
358  {VIDEO_FORMAT_1080P60HD, 1920, 1080},
359  {VIDEO_FORMAT_1080P50HD, 1920, 1080},
360  {VIDEO_FORMAT_1080P30HD, 1920, 1080},
361  {VIDEO_FORMAT_1080I50HD, 1920, 1080},
362  {VIDEO_FORMAT_1080P25HD, 1920, 1080},
363  {VIDEO_FORMAT_1080IHD, 1920, 1080},
364  {VIDEO_FORMAT_720P60HD, 1280, 720},
365  {VIDEO_FORMAT_720P50HD, 1280, 720},
366  {VIDEO_FORMAT_576PHD, 720, 576},
367  {VIDEO_FORMAT_576IHD, 720, 576},
368  {VIDEO_FORMAT_ORIGINAL, 0, 0},
369  {VIDEO_FORMAT_AUTO, 0, 0}
370 };
371 
372 //---local function prototypes for this file--------------------------------------------------------
373 // (internal functions declared static to make them local)
374 
375 static U8BIT AcquireLivePath(void *s_ptr, S_ACTL_OWNER_INFO *owner_info,
376  BOOLEAN override_parental_lock, void *t_ptr, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on);
377 static U8BIT AcquireRecordingPath(void *s_ptr, S_ACTL_OWNER_INFO *owner_info);
378 #ifdef COMMON_INTERFACE
379 static S_ACTL_OWNER_INFO* CopyOwnerInfo(S_ACTL_OWNER_INFO *owner_info);
380 static void AskRelease(U8BIT path, void *s_ptr, S_ACTL_OWNER_INFO *owner_info,
381  BOOLEAN override_parental_lock, void *t_ptr, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on);
382 static void CIPowerDownReadyCallback(void);
383 #endif
384 
385 static void ControlTuning(U8BIT path, E_ACTL_EVENT_TYPE type, U32BIT event);
386 static void ControlDecoding(U8BIT path, E_ACTL_EVENT_TYPE type, U32BIT event);
387 static void ControlAvOutput(E_ACTL_EVENT_TYPE type, U32BIT event);
388 static void AVSetAudioVolumes(BOOLEAN save_to_nvm);
389 
390 static void SetupForTuning(U8BIT path, U32BIT event);
391 static void StartTune(U8BIT path, S_MANUAL_TUNING_PARAMS *tuning_params);
392 static void SetupForDecoding(U8BIT path);
393 static void StartSiProcess(U8BIT path);
394 
395 static U8BIT AcquirePathForService(void *s_ptr, BOOLEAN with_decoders, BOOLEAN for_recording,
396  S_ACTL_OWNER_INFO *owner_info);
397 
398 static void ContinueServiceSearch(U8BIT path, U32BIT event);
399 static U16BIT NextSearchId(void **tlist, U16BIT num_transports);
400 static void ReleasePath(U8BIT path);
401 static void EndSearch(U8BIT path);
402 static void ContinueTransportSearch(U8BIT path);
403 static void FinishManualSearch(U8BIT path, U32BIT event);
404 static void FinishSearch(U8BIT path);
405 static BOOLEAN StartEitSearch(void);
406 static void ContinueEitSearch(U8BIT path);
407 static BOOLEAN EitSearchNeededNow(void);
408 
409 static U16BIT GetNumSatSearchIds(void);
410 static void MapIdToSatTuneParams(U16BIT search_id, S_MANUAL_TUNING_PARAMS *tuning_params);
411 
412 static BOOLEAN EnterStandby(void **recording_service);
413 static void GetNextWakeupTime(U32DHMS *wakeup_date_time, BOOLEAN *wakeup_for_search,
414  E_STB_DP_SIGNAL_TYPE *search_tuner_type, BOOLEAN *wakeup_for_recording, U16BIT *onet_id,
415  U16BIT *trans_id, U16BIT *service_id);
416 static BOOLEAN StartSearch(E_STB_DP_SIGNAL_TYPE tuner_type);
417 static U32DHMS GetDateTimeNow(void);
418 static U32DHMS CalculateWakeupTime(U32DHMS date_time);
419 
420 #if defined(DEBUG_TUNING) || defined(DEBUG_DECODING) || defined(DEBUG_AV_OUTPUT) || defined(DEBUG_MHEG)
421 static U8BIT* GetEventDebugString(E_ACTL_EVENT_TYPE type, U32BIT event);
422 #endif
423 
424 static void FinishEitSearch(U8BIT path);
425 static BOOLEAN GetNextEitSearchTime(U32DHMS *next);
426 
427 static void UpdateTransportParameters(U8BIT path);
428 static U32BIT CreateTimer(U32DHMS date_time);
429 
430 //--------------------------------------------------------------------------------------------------
431 // global function definitions
432 //--------------------------------------------------------------------------------------------------
433 
438 {
439  U8BIT num_paths;
440  U8BIT path;
441 
442  FUNCTION_START(ACTL_InitialiseAppControl);
443 
444  if (!initialised)
445  {
446  num_paths = STB_DPGetNumPaths();
447 
448  user_tuning_params = STB_AppGetMemory(sizeof(S_MANUAL_TUNING_PARAMS) * num_paths);
449  tuning_state = STB_AppGetMemory(sizeof(E_ACTL_TUNING_STATE) * num_paths);
450  tuned_status = STB_AppGetMemory(sizeof(E_ACTL_TUNED_STATUS) * num_paths);
451  decoding_state = STB_AppGetMemory(sizeof(E_ACTL_DECODING_STATE) * num_paths);
452  decoding_started = STB_AppGetMemory(sizeof(BOOLEAN) * num_paths);
453  decoding_locked = STB_AppGetMemory(sizeof(BOOLEAN) * num_paths);
454  decode_paused_flag = STB_AppGetMemory(sizeof(BOOLEAN) * num_paths);
455  cntrl_mutex = STB_AppGetMemory(sizeof(void *) * num_paths);
456  now_event_id = STB_AppGetMemory(sizeof(S32BIT) * num_paths);
457 
458  current_satellite = STB_AppGetMemory(sizeof(void *) * num_paths);
459  current_transport = STB_AppGetMemory(sizeof(void *) * num_paths);
460  current_service = STB_AppGetMemory(sizeof(ADB_SERVICE_REC *) * num_paths);
461  current_si = STB_AppGetMemory(sizeof(E_APP_SI_MODE) * num_paths);
462 
463  transport_required = STB_AppGetMemory(sizeof(void *) * num_paths);
464  service_required = STB_AppGetMemory(sizeof(ADB_SERVICE_REC *) * num_paths);
465  si_required = STB_AppGetMemory(sizeof(E_APP_SI_MODE) * num_paths);
466 
467  dvb_subtitles = FALSE;
468  subtitles_started = FALSE;
469  subtitles_running = FALSE;
470  subtitles_suppressed = FALSE;
471 
472  // do av control first because it turns on front panel led
473  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_INITIALISE);
474 
475  for (path = 0; path < num_paths; path++)
476  {
477  cntrl_mutex[path] = STB_OSCreateMutex();
478  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_INITIALISE);
479  }
480 
481  for (path = 0; path < num_paths; path++)
482  {
483  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_INITIALISE);
484  }
485 
487 
488  ASTE_Initialise();
489 
490  GetSubtitlePidFunc = ADB_ServiceGetSubtitlePid;
491 
492  initialised = TRUE;
493  }
494 
495  FUNCTION_FINISH(ACTL_InitialiseAppControl);
496 }
497 
502 void ACTL_ActionEvent(U32BIT event, void *event_data)
503 {
504  U8BIT path;
505  U32BIT handle;
506  U32DHMS search_time;
507 #ifdef INCLUDE_OTA_SSU
508  U16BIT onet_id, tran_id, serv_id;
509  void *t_ptr;
510 #endif
511 
512  FUNCTION_START(ACTL_ActionEvent);
513 
514  path = INVALID_RES_ID;
515 
516  switch (event)
517  {
518  // tuning events
519  case STB_EVENT_TUNE_SIGNAL_DATA_BAD:
520  case STB_EVENT_TUNE_SIGNAL_DATA_OK:
521  case STB_EVENT_TUNE_LOCKED:
522  {
523  /* The path passed in these events is actually the tuner number so
524  * this needs to be converted back to the associated path, but a tuner
525  * can be associated with multiple paths so handle the event for all. */
526  if (event_data != NULL)
527  {
528  path = INVALID_RES_ID;
529  while ((path = STB_DPPathForTuner(path, *(U8BIT *)event_data)) != INVALID_RES_ID)
530  {
531  ControlTuning(path, EXTERNAL_EVENT, event);
532 
533 #ifdef INCLUDE_OTA_SSU
534  if ((current_search_type == SEARCH_TYPE_SSU) ||
535  (current_search_type == SEARCH_TYPE_OTA_UPDATE))
536  {
537  DBG_SSU(("%s: Tuner locked, OTA started = %u", __FUNCTION__, ota_settings.ota_started));
538  if (!ota_settings.ota_started && (ota_settings.ota_tran_id != ADB_INVALID_DVB_ID))
539  {
540  DBG_SSU(("%s: Tuner locked, looking for OTA image on 0x%04x/%04x/%04x",
541  __FUNCTION__, ota_settings.ota_onet_id, ota_settings.ota_tran_id,
542  ota_settings.ota_serv_id));
543 
544  if (STB_OTAStartLoader(path, ota_settings.ota_onet_id, ota_settings.ota_tran_id,
545  ota_settings.ota_serv_id, ADB_INVALID_DVB_ID, ota_settings.version_cb))
546  {
547  ota_settings.ota_started = TRUE;
548  }
549 #ifdef DEBUG_SSU_SEARCH
550  else
551  {
552  DBG_SSU(("%s: Tuner locked but failed to start OTA", __FUNCTION__));
553  }
554 #endif
555  }
556  }
557 #endif /* INCLUDE_OTA_SSU */
558  }
559  }
560 
561  if (current_search_type != SEARCH_TYPE_NOSEARCH)
562  {
563  /* Send event to allow the UI to update */
564  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
565  }
566 
567  if (((current_search_type == SEARCH_TYPE_EIT_PF) ||
568  (current_search_type == SEARCH_TYPE_EIT_SCHED) ||
569  (current_search_type == SEARCH_TYPE_EIT_PF_SCHED)) && (ACFG_GetEitUpdateTime() != 0))
570  {
571  /* All the EIT events should be collected within a certain time (depending on the country),
572  set a timer to stop the EIT search */
573  EIT_DBG(("ACTL_ActionEvent: EIT search timeout after %u mins", ACFG_GetEitUpdateTime()));
574  search_time = STB_GCCalculateDHMS(STB_GCNowDHMSGmt(),
575  DHMS_CREATE(0, 0, ACFG_GetEitUpdateTime(), 0), CALC_ADD);
576  eit_search_end_timer = CreateTimer(search_time);
577  }
578  break;
579  }
580 
581  case STB_EVENT_TUNE_NOTLOCKED:
582  {
583  /* The path passed in these events is actually the tuner number so
584  * this needs to be converted back to the associated path, but a tuner
585  * can be associated with multiple paths so handle the event for all. */
586  if (event_data != NULL)
587  {
588  path = INVALID_RES_ID;
589  while ((path = STB_DPPathForTuner(path, *(U8BIT *)event_data)) != INVALID_RES_ID)
590  {
591  switch (current_search_type)
592  {
593  case SEARCH_TYPE_SERVICE_FREQ:
594  case SEARCH_TYPE_SERVICE_NETWORK:
595  case SEARCH_TYPE_MANUAL_NETWORK:
596  ContinueServiceSearch(path, event);
597  break;
598 
599 #ifdef INCLUDE_OTA_SSU
600  case SEARCH_TYPE_SSU:
601  if (ota_settings.ota_started)
602  {
603  DBG_SSU(("%s: Tuner not locked, stopping OTA download", __FUNCTION__));
605  ota_settings.ota_started = FALSE;
606 
607  if (ota_settings.ota_path != INVALID_RES_ID)
608  {
609  DBG_SSU(("%s: Releasing path %u used for OTA", __FUNCTION__,
610  ota_settings.ota_path));
611 
612  ACTL_TuneOff(ota_settings.ota_path);
613  STB_DPReleasePath(ota_settings.ota_path, RES_OWNER_NONE);
614  ota_settings.ota_path = INVALID_RES_ID;
615  }
616  }
617  ContinueTransportSearch(path);
618  break;
619 
620  case SEARCH_TYPE_OTA_UPDATE:
621  if (ota_settings.ota_started)
622  {
623  DBG_SSU(("%s: Tuner not locked, stopping OTA download", __FUNCTION__));
625  ota_settings.ota_started = FALSE;
626 
627  if (ota_settings.ota_path != INVALID_RES_ID)
628  {
629  DBG_SSU(("%s: Releasing path %u used for OTA", __FUNCTION__,
630  ota_settings.ota_path));
631 
632  ACTL_TuneOff(ota_settings.ota_path);
633  STB_DPReleasePath(ota_settings.ota_path, RES_OWNER_NONE);
634  ota_settings.ota_path = INVALID_RES_ID;
635  }
636  }
637  current_search_type = SEARCH_TYPE_NOSEARCH;
638  break;
639 #endif /* INCLUDE_OTA_SSU */
640 
641  case SEARCH_TYPE_STARTUP:
642  case SEARCH_TYPE_TOT:
643  ContinueTransportSearch(path);
644  break;
645 
646  case SEARCH_TYPE_EIT_PF:
647  case SEARCH_TYPE_EIT_SCHED:
648  case SEARCH_TYPE_EIT_PF_SCHED:
649  if (path == search_path)
650  {
651  ContinueEitSearch(path);
652  }
653  break;
654 
655  case SEARCH_TYPE_MANUAL_FREQ:
656  FinishManualSearch(path, event);
657  ControlTuning(path, EXTERNAL_EVENT, event);
658  break;
659 
660  default:
661  ControlTuning(path, EXTERNAL_EVENT, event);
662  break;
663  }
664  }
665  }
666  break;
667  }
668 
669  case STB_EVENT_SEARCH_FAIL:
670  case STB_EVENT_SEARCH_SUCCESS:
671  {
672  switch (current_search_type)
673  {
674  case SEARCH_TYPE_SERVICE_FREQ:
675  case SEARCH_TYPE_SERVICE_NETWORK:
676  case SEARCH_TYPE_MANUAL_NETWORK:
677  if (search_path != INVALID_RES_ID)
678  {
679  ContinueServiceSearch(search_path, event);
680  }
681  break;
682 
683  case SEARCH_TYPE_TOT:
684  if (search_path != INVALID_RES_ID)
685  {
686  if (event == STB_EVENT_SEARCH_SUCCESS)
687  {
688  /* Once we have the first TOT, no need to continue */
689  FinishSearch(search_path);
690  }
691  else
692  {
693  ContinueTransportSearch(search_path);
694  }
695  }
696  break;
697 
698  case SEARCH_TYPE_STARTUP:
699  if (search_path != INVALID_RES_ID)
700  {
701  ContinueTransportSearch(search_path);
702  }
703  break;
704 
705  case SEARCH_TYPE_MANUAL_FREQ:
706  if (search_path != INVALID_RES_ID)
707  {
708  if ((signal_type_required == SIGNAL_COFDM) &&
709  (ACTL_GetTerRfChanType(search_list_id) == TERR_TYPE_DVBT2))
710  {
711  /* T2 may have multiple PLPs, so need to continue the search */
712  ContinueServiceSearch(search_path, event);
713  }
714  else
715  {
716  FinishManualSearch(search_path, event);
717  search_path = INVALID_RES_ID;
718  }
719  }
720  break;
721 
722  case SEARCH_TYPE_EIT_PF:
723  case SEARCH_TYPE_EIT_SCHED:
724  case SEARCH_TYPE_EIT_PF_SCHED:
725  if (search_path != INVALID_RES_ID)
726  {
727  /* Finished, continue on the next transport */
728  ContinueEitSearch(search_path);
729  }
730  break;
731 
732 #ifdef INCLUDE_OTA_SSU
733  case SEARCH_TYPE_SSU:
734  if (event == STB_EVENT_SEARCH_SUCCESS)
735  {
736  ota_settings.ota_location = ASI_GetNextOTALocation(ADB_GetTunedNetwork(search_path),
737  NULL, &onet_id, &tran_id, &serv_id);
738 
739  if ((ota_settings.ota_location != NULL) &&
740  ((t_ptr = ADB_GetTransportFromIds(ADB_INVALID_DVB_ID, onet_id, tran_id)) != NULL))
741  {
742  DBG_SSU(("%s(%u): Looking for OTA image on 0x%04x/%04x/%04x", __FUNCTION__,
743  search_path, onet_id, tran_id, serv_id));
744 
745  if (!ACTL_StartOTAUpdate(search_path, t_ptr, serv_id, ota_settings.version_cb))
746  {
747  DBG_SSU(("%s: Failed to start OTA, continuing with search", __FUNCTION__));
748  ContinueTransportSearch(search_path);
749  }
750  }
751  else
752  {
753  DBG_SSU(("%s: No OTA available, continuing with search", __FUNCTION__));
754  ContinueTransportSearch(search_path);
755  }
756  }
757  else
758  {
759  DBG_SSU(("%s: No OTA available, continuing with search", __FUNCTION__));
760  ContinueTransportSearch(search_path);
761  }
762  break;
763 #endif
764 
765  default:
766  break;
767  }
768  break;
769  }
770 
771 #ifdef INCLUDE_OTA_SSU
772  case STB_EVENT_OTA_SW_UPGRADE_FOUND:
773  {
774  /* Nothing to be done, just pass the event on to the app */
775  break;
776  }
777 
778  case STB_EVENT_OTA_SW_UPGRADE_NOTFOUND:
779  case STB_EVENT_OTA_SW_UPGRADE_ERROR:
780  {
781  if ((current_search_type == SEARCH_TYPE_SSU) || (current_search_type == SEARCH_TYPE_OTA_UPDATE))
782  {
783  DBG_SSU(("%s: Failed to find an OTA update", __FUNCTION__));
784  ACTL_StopOTAUpdate();
785 
786  if ((current_search_type == SEARCH_TYPE_SSU) && (search_path != INVALID_RES_ID))
787  {
788  /* Try the next OTA location on this transport */
789  ota_settings.ota_location = ASI_GetNextOTALocation(ADB_GetTunedNetwork(search_path),
790  ota_settings.ota_location, &onet_id, &tran_id, &serv_id);
791 
792  if ((ota_settings.ota_location != NULL) &&
793  ((t_ptr = ADB_GetTransportFromIds(ADB_INVALID_DVB_ID, onet_id, tran_id)) != NULL))
794  {
795  DBG_SSU(("%s(%u): Looking for OTA image on 0x%04x/%04x/%04x", __FUNCTION__,
796  search_path, onet_id, tran_id, serv_id));
797 
798  if (!ACTL_StartOTAUpdate(search_path, t_ptr, serv_id, ota_settings.version_cb))
799  {
800  DBG_SSU(("%s: Failed to start OTA, continuing with search", __FUNCTION__));
801  ContinueTransportSearch(search_path);
802  }
803  }
804  else
805  {
806  DBG_SSU(("%s: Continuing SSU search", __FUNCTION__));
807  ContinueTransportSearch(search_path);
808  }
809  }
810  }
811  break;
812  }
813 #endif
814 
815  // decoding events
816  case STB_EVENT_AUDIO_DECODE_STARTED:
817  {
818  /* The path passed in these events is the decoder number
819  * so this needs to be converted back to the associated path */
820  if (event_data != NULL)
821  {
822  path = STB_DPPathForAudioDecoder(*(U8BIT *)event_data);
823  }
824 
825  if (path != INVALID_RES_ID)
826  {
827  ControlDecoding(path, EXTERNAL_EVENT, event);
828  }
829  break;
830  }
831 
832  case STB_EVENT_VIDEO_DECODE_STARTED:
833  case STB_EVENT_DECODE_LOCKED:
834  {
835  /* The path passed in these events is the decoder number
836  * so this needs to be converted back to the associated path */
837  if (event_data != NULL)
838  {
839  path = STB_DPPathForVideoDecoder(*(U8BIT *)event_data);
840  }
841 
842  if (path != INVALID_RES_ID)
843  {
844  ControlDecoding(path, EXTERNAL_EVENT, event);
845  }
846  break;
847  }
848 
849 #ifdef COMMON_INTERFACE
850  case STB_EVENT_CI_APP_INFO:
851  {
852  ci_ai_module = *((U32BIT*)event_data);
853  break;
854  }
855 #endif
856 
857  case APP_EVENT_SERVICE_AUDIO_PID_UPDATE:
858  case APP_EVENT_SERVICE_VIDEO_PID_UPDATE:
859  case APP_EVENT_SERVICE_SUBTITLE_UPDATE:
860  case APP_EVENT_SERVICE_SCRAMBLE_CHANGE:
861  case APP_EVENT_SERVICE_RUNNING:
862  {
863  /* All these events contain the service they apply to in the event data,
864  * but this service may be valid for more than one path so they all need to be checked */
865  for (path = 0; path < STB_DPGetNumPaths(); path++)
866  {
867  if (ADB_GetTunedService(path) == event_data)
868  {
869  STB_OSMutexLock(cntrl_mutex[path]);
870 
871  /* Initialise variables for playback */
872  if ((event_data == APVR_GetPlaybackService()) && (path != INVALID_RES_ID))
873  {
874  service_required[path] = (void *)APVR_GetPlaybackService();
875  current_service[path] = service_required[path];
876  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL;
877  }
878 
879  if (STB_DPIsDecodingPath(path))
880  {
881  ControlDecoding(path, EXTERNAL_EVENT, event);
882  }
883  if (STB_DPIsRecordingPath(path) && !STB_DPIsRecording(path, &handle))
884  {
885  /* The recording can only be started if the PIDs for the service are known */
886  if ((ADB_GetServiceAudioPid(event_data) != 0) ||
887  (ADB_GetServiceVideoPid(event_data) != 0))
888  {
889  ATMR_CheckRecordStatus(TRUE, event_data);
890  }
891  else
892  {
893  /* Recording can't be started with no PIDs */
894  ATMR_RecordingFailed(path);
895  STB_DPReleasePath(path, RES_OWNER_DVB);
896 
897  /* Send event to UI to inform a recording has failed due to no data */
898  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_PVR_RECORDING_FAILED, NULL, 0);
899  }
900  }
901 
902  STB_OSMutexUnlock(cntrl_mutex[path]);
903  }
904  }
905  break;
906  }
907 
908  case APP_EVENT_SERVICE_VIDEO_CODEC_CHANGED:
909  {
910  if (!external_control)
911  {
912  path = STB_DPGetPathForService(event_data);
913  if (STB_DPIsDecodingPath(path))
914  {
916  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_DECODING);
917  }
918  }
919  break;
920  }
921 
922  case APP_EVENT_SERVICE_AUDIO_CODEC_CHANGED:
923  {
924  if (!external_control)
925  {
926  path = STB_DPGetPathForService(event_data);
927  if (STB_DPIsDecodingPath(path))
928  {
930  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_AUDIO);
931  }
932  }
933  break;
934  }
935 
936  case APP_EVENT_SERVICE_NOT_RUNNING:
937  {
938  path = *(U8BIT *)event_data;
939  if (STB_DPIsDecodingPath(path))
940  {
941  ControlDecoding(path, EXTERNAL_EVENT, event);
942  }
943  break;
944  }
945 
946  default:
947  {
948  break;
949  }
950  }
951 
952  FUNCTION_FINISH(ACTL_ActionEvent);
953 }
954 
960 BOOLEAN ACTL_HandlePrivateTimerEvent(U32BIT timer_handle)
961 {
962  BOOLEAN retval = FALSE;
963  U32DHMS wakeup;
964  U16BIT onet_id, trans_id, service_id;
965  void *s_ptr;
966 
967  FUNCTION_START(ACTL_HandlePrivateTimerEvent);
968 
969  if (ATMR_GetType(timer_handle) == TIMER_TYPE_PRIVATE)
970  {
971  if (timer_handle == standby_wakeup_timer)
972  {
973  ATMR_DeleteTimer(standby_wakeup_timer);
974  standby_wakeup_timer = INVALID_TIMER_HANDLE;
975 
976  /* Check what's to be started by this timer */
977  if (APP_NvmRead(STANDBY_STATE_NVM) == STDBY_WAKE_FOR_RECORDING)
978  {
979  /* Find the details for the first wakeup timer to be started */
980  if (ATMR_GetFirstWakeupTime(&wakeup, &onet_id, &trans_id, &service_id) != INVALID_TIMER_HANDLE)
981  {
982  if ((s_ptr = ADB_FindServiceByIds(onet_id, trans_id, service_id)) != NULL)
983  {
984  if (standby_path != INVALID_RES_ID)
985  {
986  /* Release the decode path that was acquired when entering standby */
987  STB_DPReleasePath(standby_path, RES_OWNER_NONE);
988  standby_path = INVALID_RES_ID;
989  }
990 
991  if ((standby_path = AcquirePathForService(s_ptr, FALSE, FALSE, NULL)) != INVALID_RES_ID)
992  {
993  ACTL_TuneToService(standby_path, NULL, s_ptr, FALSE, TRUE);
994  }
995  }
996  else
997  {
998  /* Couldn't find the service to be recorded so go back into standby */
1000  }
1001  }
1002  else
1003  {
1004  /* No recording timer found, go back into standby */
1006  }
1007  }
1008  else
1009  {
1010  if (!StartSearch(signal_type_required))
1011  {
1012  /* No search started so re-enter standby */
1014  }
1015  }
1016 
1017  retval = TRUE;
1018  }
1019  else if (timer_handle == standby_grace_timer)
1020  {
1021  ATMR_DeleteTimer(standby_grace_timer);
1022  standby_grace_timer = INVALID_TIMER_HANDLE;
1023 
1024  DBG_STDBY(("Standby grace time expired"));
1025 
1026  if ((BOOLEAN)APP_NvmRead(STANDBY_POWERSAVE_NVM))
1027  {
1028  /* Put box into low-power standby mode */
1029  DBG_STDBY(("Entering low power standby"));
1030  STB_HWSetStandbyState(HW_STANDBY_LOWPOWER);
1031  }
1032  else
1033  {
1034  /* Nothing is being started so go into the lowest active standby state */
1035  DBG_STDBY(("Entering passive standby"));
1036  STB_HWSetStandbyState(HW_STANDBY_PASSIVE);
1037  }
1038  }
1039  else
1040  {
1041  if (timer_handle == eit_search_end_timer)
1042  {
1043  ATMR_DeleteTimer(eit_search_end_timer);
1044  eit_search_end_timer = INVALID_TIMER_HANDLE;
1045 
1046  if ((current_search_type == SEARCH_TYPE_EIT_PF) ||
1047  (current_search_type == SEARCH_TYPE_EIT_SCHED) ||
1048  (current_search_type == SEARCH_TYPE_EIT_PF_SCHED))
1049  {
1050  if (search_path != INVALID_RES_ID)
1051  {
1052  ContinueEitSearch(search_path);
1053  }
1054  }
1055 
1056  retval = TRUE;
1057  }
1058  }
1059  }
1060 
1061  FUNCTION_FINISH(ACTL_HandlePrivateTimerEvent);
1062 
1063  return retval;
1064 }
1065 
1071 void* ACTL_GetCurrentSatellite(U8BIT path)
1072 {
1073  void *sat_ptr;
1074 
1075  FUNCTION_START(ACTL_GetCurrentSatellite);
1076 
1077  if (path != INVALID_RES_ID)
1078  {
1079  sat_ptr = current_satellite[path];
1080  }
1081  else
1082  {
1083  sat_ptr = NULL;
1084  }
1085 
1086  FUNCTION_FINISH(ACTL_GetCurrentSatellite);
1087 
1088  return(sat_ptr);
1089 }
1090 
1096 U16BIT ACTL_GetNumRfChanArrayEntries(E_STB_DP_SIGNAL_TYPE tuner_type)
1097 {
1098  ACFG_ANA_RF_CHANNEL_DATA *ana_channel_table;
1099  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
1100  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1101  U16BIT num_rf_chans;
1102  U32BIT country_code;
1103 
1104  FUNCTION_START(ACTL_GetNumRfChanArrayEntries);
1105 
1106  num_rf_chans = 0;
1107  country_code = ACFG_GetCountry();
1108 
1109  switch (tuner_type)
1110  {
1111  case SIGNAL_ANALOG:
1112  ACFG_GetAnaRfChannelTable(country_code, &ana_channel_table, &num_rf_chans);
1113  break;
1114  case SIGNAL_COFDM:
1115  ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans);
1116  break;
1117  case SIGNAL_QAM:
1118  ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans);
1119  break;
1120  default:
1121  break;
1122  }
1123 
1124  FUNCTION_FINISH(ACTL_GetNumRfChanArrayEntries);
1125  return(num_rf_chans);
1126 }
1127 
1134 U8BIT* ACTL_GetRfChanName(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
1135 {
1136  U8BIT *ret_val;
1137  ACFG_ANA_RF_CHANNEL_DATA *ana_channel_table;
1138  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
1139  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1140  U16BIT num_rf_chans;
1141  U32BIT country_code;
1142 
1143  FUNCTION_START(ACTL_GetRfChanName);
1144 
1145  ret_val = NULL;
1146  country_code = ACFG_GetCountry();
1147 
1148  switch (tuner_type)
1149  {
1150  case SIGNAL_ANALOG:
1151  if (ACFG_GetAnaRfChannelTable(country_code, &ana_channel_table, &num_rf_chans) &&
1152  (id < num_rf_chans))
1153  {
1154  ret_val = ana_channel_table[id].name;
1155  }
1156  break;
1157  case SIGNAL_COFDM:
1158  if (ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans) &&
1159  (id < num_rf_chans))
1160  {
1161  ret_val = ter_channel_table[id].name;
1162  }
1163  break;
1164  case SIGNAL_QAM:
1165  if (ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans) &&
1166  (id < num_rf_chans))
1167  {
1168  ret_val = cab_channel_table[id].name;
1169  }
1170  break;
1171  default:
1172  break;
1173  }
1174 
1175  FUNCTION_FINISH(ACTL_GetRfChanName);
1176  return(ret_val);
1177 }
1178 
1185 U16BIT ACTL_GetRfSymbolRate(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
1186 {
1187  U16BIT ret_val;
1188  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1189  U16BIT num_rf_chans;
1190  U32BIT country_code;
1191 
1192  FUNCTION_START(ACTL_GetRfSymbolRate);
1193 
1194  ret_val = 0;
1195  country_code = ACFG_GetCountry();
1196 
1197  switch (tuner_type)
1198  {
1199  case SIGNAL_QAM:
1200  if (ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans) &&
1201  (id < num_rf_chans))
1202  {
1203  ret_val = cab_channel_table[id].symbol_rate;
1204  }
1205  break;
1206 
1207  default:
1208  break;
1209  }
1210 
1211  FUNCTION_FINISH(ACTL_GetRfSymbolRate);
1212  return(ret_val);
1213 }
1214 
1221 U8BIT ACTL_GetRfModulation(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
1222 {
1223  U8BIT ret_val;
1224  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1225  U16BIT num_rf_chans;
1226  U32BIT country_code;
1227 
1228  FUNCTION_START(ACTL_GetRfModulation);
1229 
1230  ret_val = 0;
1231  country_code = ACFG_GetCountry();
1232 
1233  switch (tuner_type)
1234  {
1235  case SIGNAL_QAM:
1236  if (ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans) &&
1237  (id < num_rf_chans))
1238  {
1239  ret_val = cab_channel_table[id].mode;
1240  }
1241  break;
1242 
1243  default:
1244  break;
1245  }
1246 
1247  FUNCTION_FINISH(ACTL_GetRfModulation);
1248  return(ret_val);
1249 }
1250 
1257 U32BIT ACTL_GetRfChanFreqHz(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
1258 {
1259  U32BIT ret_val;
1260  ACFG_ANA_RF_CHANNEL_DATA *ana_channel_table;
1261  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
1262  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1263  U16BIT num_rf_chans;
1264  U32BIT country_code;
1265 
1266  FUNCTION_START(ACTL_GetRfChanFreqHz);
1267 
1268  ret_val = 0;
1269  country_code = ACFG_GetCountry();
1270 
1271  switch (tuner_type)
1272  {
1273  case SIGNAL_ANALOG:
1274  if (ACFG_GetAnaRfChannelTable(country_code, &ana_channel_table, &num_rf_chans) &&
1275  (id < num_rf_chans))
1276  {
1277  ret_val = ana_channel_table[id].freq_hz;
1278  }
1279  break;
1280  case SIGNAL_COFDM:
1281  if (ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans) &&
1282  (id < num_rf_chans))
1283  {
1284  ret_val = ter_channel_table[id].freq_hz;
1285  }
1286  break;
1287  case SIGNAL_QAM:
1288  if (ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans) &&
1289  (id < num_rf_chans))
1290  {
1291  ret_val = cab_channel_table[id].freq_hz;
1292  }
1293  break;
1294  default:
1295  break;
1296  }
1297 
1298  FUNCTION_FINISH(ACTL_GetRfChanFreqHz);
1299  return(ret_val);
1300 }
1301 
1308 U8BIT* ACTL_GetRfNameFromFreq(E_STB_DP_SIGNAL_TYPE tuner_type, U32BIT freq_hz)
1309 {
1310  U8BIT *ret_val;
1311  ACFG_ANA_RF_CHANNEL_DATA *ana_channel_table;
1312  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
1313  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1314  U16BIT i, num_rf_chans;
1315  U32BIT country_code;
1316 
1317  FUNCTION_START(ACTL_GetRfNameFromFreq);
1318 
1319  ret_val = NULL;
1320  country_code = ACFG_GetCountry();
1321 
1322  switch (tuner_type)
1323  {
1324  case SIGNAL_ANALOG:
1325  if (ACFG_GetAnaRfChannelTable(country_code, &ana_channel_table, &num_rf_chans))
1326  {
1327  for (i = 0; i < num_rf_chans; i++)
1328  {
1329  if (ana_channel_table[i].freq_hz == freq_hz)
1330  {
1331  ret_val = ana_channel_table[i].name;
1332  break;
1333  }
1334  }
1335  }
1336  break;
1337  case SIGNAL_COFDM:
1338  if (ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans))
1339  {
1340  for (i = 0; i < num_rf_chans; i++)
1341  {
1342  if (ter_channel_table[i].freq_hz == freq_hz)
1343  {
1344  ret_val = ter_channel_table[i].name;
1345  break;
1346  }
1347  }
1348  }
1349  break;
1350  case SIGNAL_QAM:
1351  if (ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans))
1352  {
1353  for (i = 0; i < num_rf_chans; i++)
1354  {
1355  if (cab_channel_table[i].freq_hz == freq_hz)
1356  {
1357  ret_val = cab_channel_table[i].name;
1358  break;
1359  }
1360  }
1361  }
1362  break;
1363  default:
1364  break;
1365  }
1366 
1367  FUNCTION_FINISH(ACTL_GetRfNameFromFreq);
1368  return(ret_val);
1369 }
1370 
1376 E_STB_DP_TTYPE ACTL_GetTerRfChanType(U16BIT id)
1377 {
1378  E_STB_DP_TTYPE ret_val;
1379  BOOLEAN success;
1380  ACFG_TER_RF_CHANNEL_DATA *rf_channel_table;
1381  U16BIT num_rf_chans;
1382 
1383  FUNCTION_START(ACTL_GetTerRfChanType);
1384 
1385  ret_val = TERR_TYPE_UNKNOWN;
1386 
1387  success = ACFG_GetTerRfChannelTable(ACFG_GetCountry(), &rf_channel_table, &num_rf_chans);
1388  if ((success == TRUE) && (id < num_rf_chans))
1389  {
1390  ret_val = rf_channel_table[id].type;
1391  }
1392 
1393  FUNCTION_FINISH(ACTL_GetTerRfChanType);
1394 
1395  return(ret_val);
1396 }
1397 
1406 BOOLEAN ACTL_TuneToRfChanArrayEntry(U8BIT path, U16BIT id, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
1407 {
1408  BOOLEAN ret_val;
1409  BOOLEAN success;
1410  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
1411  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
1412  U16BIT num_rf_chans;
1413  U32BIT country_code;
1414 
1415  FUNCTION_START(ACTL_TuneToRfChanArrayEntry);
1416 
1417  ret_val = FALSE;
1418  country_code = ACFG_GetCountry();
1419 
1420  switch (signal_type_required)
1421  {
1422  case SIGNAL_COFDM:
1423  success = ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans);
1424  break;
1425  case SIGNAL_QAM:
1426  success = ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans);
1427  break;
1428  default:
1429  num_rf_chans = 0;
1430  success = FALSE;
1431  break;
1432  }
1433 
1434  ADB_SetTunedTransport(path, NULL);
1435 
1436  if ((success == TRUE) && (id < num_rf_chans))
1437  {
1438  STB_OSMutexLock(cntrl_mutex[path]);
1439  ret_val = TRUE;
1440  rf_chan_id_required = id;
1441  transport_required[path] = NULL;
1442  tuner_relock_required = relock_on;
1443  service_required[path] = NULL;
1444  decode_lock_override_required = FALSE;
1445  switch (reqd_si)
1446  {
1447  case ACTL_SI_CHANNEL_SEARCH: {si_required[path] = APP_SI_MODE_CHANNEL_SEARCH; break; }
1448  case ACTL_SI_STARTUP_SEARCH: {si_required[path] = APP_SI_MODE_STARTUP_SEARCH; break; }
1449  case ACTL_SI_EVENT_PF_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SEARCH; break; }
1450  case ACTL_SI_EVENT_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_SCHED_SEARCH; break; }
1451  case ACTL_SI_EVENT_PF_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SCHED_SEARCH; break; }
1452  case ACTL_SI_DVB_SSU_SEARCH: {si_required[path] = APP_SI_MODE_DVB_SSU_SEARCH; break; }
1453  case ACTL_SI_USER_DEFINED: {si_required[path] = APP_SI_MODE_USER_DEFINED; break; }
1454  default: {si_required[path] = APP_SI_MODE_NO_SI; break; }
1455  }
1456  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_RF_CHAN_TUNE_REQD);
1457  STB_OSMutexUnlock(cntrl_mutex[path]);
1458  }
1459  else
1460  {
1461  ret_val = FALSE;
1462  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1463  }
1464 
1465  FUNCTION_FINISH(ACTL_TuneToRfChanArrayEntry);
1466 
1467  return(ret_val);
1468 }
1469 
1476 BOOLEAN ACTL_TuneToRfChanArrayAnalogEntry(U8BIT path, U16BIT id)
1477 {
1478  BOOLEAN ret_val;
1479  BOOLEAN success;
1480  ACFG_ANA_RF_CHANNEL_DATA *rf_channel_table;
1481  U16BIT num_rf_chans;
1482 
1483  FUNCTION_START(ACTL_TuneToRfChanArrayAnalogEntry);
1484 
1485  ret_val = FALSE;
1486  success = ACFG_GetAnaRfChannelTable(ACFG_GetCountry(), &rf_channel_table, &num_rf_chans);
1487 
1488  if ((success == TRUE) && (id < num_rf_chans))
1489  {
1490  STB_OSMutexLock(cntrl_mutex[path]);
1491  ret_val = TRUE;
1492  rf_chan_id_required = id;
1493  signal_type_required = SIGNAL_ANALOG;
1494  transport_required[path] = NULL;
1495  tuner_relock_required = FALSE;
1496  service_required[path] = NULL;
1497  decode_lock_override_required = FALSE;
1498  si_required[path] = APP_SI_MODE_NO_SI;
1499 
1500  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_RF_CHAN_TUNE_REQD);
1501  STB_OSMutexUnlock(cntrl_mutex[path]);
1502  }
1503  else
1504  {
1505  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1506  }
1507 
1508  ADB_SetTunedTransport(path, NULL);
1509 
1510  FUNCTION_FINISH(ACTL_TuneToRfChanArrayAnalogEntry);
1511  return(ret_val);
1512 }
1513 
1522 BOOLEAN ACTL_TuneToUserDefinedParams(U8BIT path, S_MANUAL_TUNING_PARAMS *tuning_params,
1523  E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
1524 {
1525  BOOLEAN ret_val;
1526 
1527  FUNCTION_START(ACTL_TuneToUserDefinedParams);
1528 
1529  ret_val = FALSE;
1530 
1531  if ((path != INVALID_RES_ID) && (tuning_params != NULL))
1532  {
1533  STB_OSMutexLock(cntrl_mutex[path]);
1534 
1535  ADB_SetTunedTransport(path, NULL);
1536 
1537  transport_required[path] = NULL;
1538  tuner_relock_required = relock_on;
1539  service_required[path] = NULL;
1540  decode_lock_override_required = FALSE;
1541 
1542  switch (reqd_si)
1543  {
1544  case ACTL_SI_CHANNEL_SEARCH: {si_required[path] = APP_SI_MODE_CHANNEL_SEARCH; break; }
1545  case ACTL_SI_CHANNEL_SEARCH_NO_NIT: {si_required[path] = APP_SI_MODE_CHANNEL_SEARCH_NO_NIT; break; }
1546  case ACTL_SI_STARTUP_SEARCH: {si_required[path] = APP_SI_MODE_STARTUP_SEARCH; break; }
1547  case ACTL_SI_EVENT_PF_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SEARCH; break; }
1548  case ACTL_SI_EVENT_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_SCHED_SEARCH; break; }
1549  case ACTL_SI_EVENT_PF_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SCHED_SEARCH; break; }
1550  case ACTL_SI_DVB_SSU_SEARCH: {si_required[path] = APP_SI_MODE_DVB_SSU_SEARCH; break; }
1551  case ACTL_SI_USER_DEFINED: {si_required[path] = APP_SI_MODE_USER_DEFINED; break; }
1552  default: {si_required[path] = APP_SI_MODE_NO_SI; break; }
1553  }
1554 
1555  signal_type_required = STB_DPGetSignalType(path);
1556 
1557  /* Save the tuning params */
1558  memcpy(&user_tuning_params[path], tuning_params, sizeof(S_MANUAL_TUNING_PARAMS));
1559 
1560  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_USERDEFINED_TUNE_REQD);
1561 
1562  STB_OSMutexUnlock(cntrl_mutex[path]);
1563 
1564  ret_val = TRUE;
1565  }
1566 
1567  FUNCTION_FINISH(ACTL_TuneToUserDefinedParams);
1568 
1569  return(ret_val);
1570 }
1571 
1584 U8BIT ACTL_TuneToTransport(U8BIT path, S_ACTL_OWNER_INFO *owner_info, void *t_ptr,
1585  E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
1586 {
1587  FUNCTION_START(ACTL_TuneToTransport);
1588 
1589  if (path == INVALID_RES_ID)
1590  {
1591  /* Try to acquire a live path */
1592  path = AcquireLivePath(NULL, owner_info, FALSE, t_ptr, reqd_si, relock_on);
1593  }
1594 
1595  if (path != INVALID_RES_ID)
1596  {
1597  STB_OSMutexLock(cntrl_mutex[path]);
1598 
1599  transport_required[path] = t_ptr;
1600  tuner_relock_required = relock_on;
1601  service_required[path] = NULL;
1602  decode_lock_override_required = FALSE;
1603 
1604  switch (reqd_si)
1605  {
1606  case ACTL_SI_CHANNEL_SEARCH: {si_required[path] = APP_SI_MODE_CHANNEL_SEARCH; break; }
1607  case ACTL_SI_CHANNEL_SEARCH_NO_NIT: {si_required[path] = APP_SI_MODE_CHANNEL_SEARCH_NO_NIT; break; }
1608  case ACTL_SI_STARTUP_SEARCH: {si_required[path] = APP_SI_MODE_STARTUP_SEARCH; break; }
1609  case ACTL_SI_TOT_SEARCH: {si_required[path] = APP_SI_MODE_TOT_SEARCH; break; }
1610  case ACTL_SI_EVENT_PF_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SEARCH; break; }
1611  case ACTL_SI_EVENT_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_SCHED_SEARCH; break; }
1612  case ACTL_SI_EVENT_PF_SCHED_SEARCH: {si_required[path] = APP_SI_MODE_EVENT_PF_SCHED_SEARCH; break; }
1613  case ACTL_SI_DVB_SSU_SEARCH: {si_required[path] = APP_SI_MODE_DVB_SSU_SEARCH; break; }
1614  case ACTL_SI_USER_DEFINED: {si_required[path] = APP_SI_MODE_USER_DEFINED; break; }
1615  default: {si_required[path] = APP_SI_MODE_NO_SI; break; }
1616  }
1617 
1618  ADB_SetTunedTransport(path, t_ptr);
1619 
1620  if (t_ptr != NULL)
1621  {
1622  signal_type_required = ADB_GetTransportSignalType(t_ptr);
1623  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TPTR_TUNE_REQD);
1624  }
1625  else
1626  {
1627  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1628  }
1629 
1630  STB_OSMutexUnlock(cntrl_mutex[path]);
1631  }
1632 
1633  FUNCTION_FINISH(ACTL_TuneToTransport);
1634 
1635  return(path);
1636 }
1637 
1651 U8BIT ACTL_TuneToService(U8BIT path, S_ACTL_OWNER_INFO *owner_info, void *s_ptr,
1652  BOOLEAN override_lock, BOOLEAN for_live)
1653 {
1654  BOOLEAN slot_acquired;
1655  U32BIT handle;
1656 #if defined(EIT_EPG_4DAY_ACT) || defined(EIT_EPG_8DAY_ACT)
1657  void **slist;
1658  U16BIT num_services;
1659  U16BIT i;
1660 #endif
1661 #if defined(INTEGRATE_HBBTV)
1662  U16BIT onet_id, ts_id, serv_id;
1663 #endif
1664 
1665  FUNCTION_START(ACTL_TuneToService);
1666 
1667 #ifdef DEBUG_TUNING
1668  STB_SPDebugWrite("ACTL_TuneToService(path=%d, owner_info=%p, service=0x%x, for_live=%u)",
1669  path, owner_info, s_ptr, for_live);
1670 #endif
1671 
1672  if (path == INVALID_RES_ID)
1673  {
1674  if (for_live)
1675  {
1676  /* Try to acquire a live path */
1677  path = AcquireLivePath(s_ptr, owner_info, override_lock, NULL, APP_SI_MODE_UPDATE, FALSE);
1678  }
1679  else
1680  {
1681  /* Try to acquire a recording path */
1682  path = AcquireRecordingPath(s_ptr, owner_info);
1683  }
1684  }
1685 
1686  if (path != INVALID_RES_ID)
1687  {
1688  STB_OSMutexLock(cntrl_mutex[path]);
1689 
1690  service_required[path] = s_ptr;
1691  transport_required[path] = ADB_GetServiceTransportPtr(s_ptr);
1692  tuner_relock_required = TRUE;
1693  decode_lock_override_required = override_lock;
1694 
1695  if (s_ptr != NULL)
1696  {
1697  if (ADB_GetServiceType(s_ptr) == ADB_SERVICE_TYPE_ANALOG)
1698  {
1699  si_required[path] = APP_SI_MODE_NO_SI;
1700  signal_type_required = SIGNAL_ANALOG;
1701 
1702  if ((APP_NvmRead(PARENTAL_LOCK_NVM) != PARENTAL_LOCK_OFF) &&
1703  (decode_lock_override_required == FALSE) &&
1704  (ADB_GetServiceLockedFlag(s_ptr) == TRUE))
1705  {
1706  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1707  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_LOCKED, NULL, 0);
1708  }
1709  else
1710  {
1711  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TPTR_TUNE_REQD);
1712  }
1713  }
1714 #ifdef COMMON_INTERFACE
1715  else if (ADB_GetServiceType(s_ptr) == ADB_SERVICE_TYPE_VIRTUAL)
1716  {
1717  /* When on Virtual Channel, CAM is not expected to receive any TS data. So tune off previous channel */
1718  service_required[path] = NULL;
1719  transport_required[path] = NULL;
1720  current_service[path] = NULL;
1721  ADB_SetTunedService(path, NULL);
1722  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1723 
1724  /* Inform CI-CAM that user has selected the 'Virtual Channel' */
1725  STB_EnterCICamChannel(ci_ai_module);
1726  }
1727 #endif
1728  else
1729  {
1730 #if defined(EIT_EPG_4DAY_ACT) || defined(EIT_EPG_8DAY_ACT)
1731  if (STB_DPIsLivePath(path) &&
1732  (current_transport[path] != NULL) &&
1733  (transport_required[path] != current_transport[path]) &&
1734  (s_ptr != current_service[path]))
1735  {
1736  /* Get the list of services on this transport so that all event data can be deleted */
1737  ADB_GetTransportServiceList(current_transport[path], &slist, &num_services);
1738 
1739  for (i = 0; i < num_services; i++)
1740  {
1741  ADB_DeleteServiceEvents(slist[i], FALSE);
1742  }
1743 
1744  ADB_ReleaseServiceList(slist, num_services);
1745  }
1746 #endif
1747 
1748  si_required[path] = APP_SI_MODE_UPDATE;
1749  slot_acquired = FALSE;
1750 
1751 #ifdef COMMON_INTERFACE
1752  if (ADB_GetServiceSDTReceived(s_ptr))
1753  {
1754  /* Check whether the SDT needs to be reacquired for this service due to the
1755  * retention limit of the CI protection descriptor expiring */
1756  if (ADB_HasCIProtectionExpired(s_ptr))
1757  {
1758  /* The SDT for this service needs to be reacquired to update
1759  * the CI protection descriptor */
1760  si_required[path] = APP_SI_MODE_CIPLUS_UPDATE;
1761  }
1762  else
1763  {
1764  /* Only acquire a CI slot if the path doesn't have one yet */
1765  if (STB_DPGetPathCISlot(path) == INVALID_RES_ID)
1766  {
1767  slot_acquired = ACI_AcquireCISlot(path, s_ptr);
1768  }
1769  }
1770  if (!slot_acquired)
1771  {
1772  /* Acquire a CA slot if needed */
1773  ACA_AcquireCADescrambler(path, s_ptr);
1774  }
1775  }
1776  else
1777  {
1778  /* The SDT needs to be acquired for the service before a CAM can be acquired */
1779  si_required[path] = APP_SI_MODE_CIPLUS_UPDATE;
1780  }
1781 #else
1782  if (!slot_acquired)
1783  {
1784  /* Acquire a CA slot if needed */
1785  ACA_AcquireCADescrambler(path, s_ptr);
1786  }
1787 #endif
1788 
1789  signal_type_required = ADB_GetTransportSignalType(transport_required[path]);
1790 
1791  /* Is tuning required? */
1792  if (ADB_GetTunedTransport(path) != transport_required[path])
1793  {
1794  current_service[path] = (ADB_SERVICE_REC *)s_ptr;
1795  ADB_SetTunedService(path, s_ptr);
1796  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TPTR_TUNE_REQD);
1797  }
1798  else
1799  {
1800  tuning_state[path] = TSTATE_TUNED;
1801  current_service[path] = (ADB_SERVICE_REC *)s_ptr;
1802  ADB_SetTunedService(path, s_ptr);
1803 
1804  /* Start SI processing */
1805  StartSiProcess(path);
1806 
1807  if (STB_DPIsDecodingPath(path))
1808  {
1809  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_DECODING);
1810 #if defined(INTEGRATE_HBBTV)
1811  if (STB_DPIsLivePath(path))
1812  {
1813  /* Inform the presentation engine that the channel change succeeded */
1814  ADB_GetServiceIds(s_ptr, &onet_id, &ts_id, &serv_id);
1815  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
1816  HBBTV_CHANNEL_CHANGE_SUCCEEDED);
1817  }
1818 #endif
1819  }
1820 
1821  if (STB_DPIsRecordingPath(path) && !STB_DPIsRecording(path, &handle))
1822  {
1823  /* The recording can only be started here if the PIDs for the service
1824  * are known, otherwise it will have to start when the PMT for the service
1825  * has been received. Only the audio PID is checked as this should be
1826  * available for both radio and TV services */
1828  {
1829  ATMR_CheckRecordStatus(TRUE, s_ptr);
1830  }
1831  }
1832  }
1833  }
1834  }
1835  else
1836  {
1837  current_service[path] = NULL;
1838  ADB_SetTunedService(path, s_ptr);
1839  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
1840  }
1841 
1842  STB_OSMutexUnlock(cntrl_mutex[path]);
1843  }
1844 
1845  FUNCTION_FINISH(ACTL_TuneToService);
1846 
1847  return(path);
1848 }
1849 
1866 BOOLEAN ACTL_TuneUsingDSD(U8BIT path, SI_DELIVERY_SYS_DESC_TYPE dsd_type,
1867  SI_DELIVERY_SYS_DESC *dsd, U16BIT service_id, E_ACTL_SI_SRCH_REQD reqd_si)
1868 {
1869  BOOLEAN retval;
1870  ADB_TRANSPORT_REC *t_ptr;
1871  ADB_SERVICE_REC *s_ptr;
1872 
1873  FUNCTION_START(ACTL_TuneUsingDSD);
1874 
1875  retval = FALSE;
1876 
1877  if (path != INVALID_RES_ID)
1878  {
1880 
1881  switch (dsd_type)
1882  {
1883  case SI_DEL_SYS_DESC_TYPE_TERR:
1884  {
1885  if ((t_ptr = DBDEF_FindTerrestrialTransportRec(dsd->terr.u.t1.freq_hz, 0)) == NULL)
1886  {
1887  t_ptr = DBDEF_AddTerrestrialTransportRec(dsd->terr.u.t1.freq_hz, 0, NULL);
1888  }
1889  break;
1890  }
1891 
1892  case SI_DEL_SYS_DESC_TYPE_CABLE:
1893  {
1894  if ((t_ptr = DBDEF_FindCableTransportRec(dsd->cable.freq_hz,
1895  dsd->cable.symbol_rate)) == NULL)
1896  {
1897  t_ptr = DBDEF_AddCableTransportRec(dsd->cable.freq_hz, dsd->cable.symbol_rate, NULL);
1898  }
1899  break;
1900  }
1901 
1902  case SI_DEL_SYS_DESC_TYPE_SAT:
1903  {
1904  if ((t_ptr = DBDEF_FindSatTransportRec(dsd->sat.freq_hz, dsd->sat.sym_rate,
1905  dsd->sat.polarity, dsd->sat.dvb_s2, dsd->sat.modulation, NULL)) == NULL)
1906  {
1907  t_ptr = DBDEF_AddSatTransportRec(dsd->sat.freq_hz, dsd->sat.sym_rate,
1908  dsd->sat.polarity, dsd->sat.dvb_s2, dsd->sat.modulation, NULL);
1909  }
1910  break;
1911  }
1912 
1913  default:
1914  {
1915  t_ptr = NULL;
1916  break;
1917  }
1918  }
1919 
1921 
1922  if (t_ptr != NULL)
1923  {
1924  if (service_id != 0)
1925  {
1927 
1928  if ((s_ptr = DBDEF_FindServiceRecByIds(NULL, ADB_INVALID_DVB_ID, t_ptr->orig_net_id,
1929  t_ptr->tran_id, service_id)) == NULL)
1930  {
1931  /* Create a service record */
1932  if ((s_ptr = DBDEF_AddServiceRec(service_id, t_ptr)) != NULL)
1933  {
1934  /* Make the service hidden and non-selectable so it isn't available to the user */
1935  s_ptr->hidden = TRUE;
1936  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_HIDDEN, s_ptr->hidden);
1937 
1938  s_ptr->selectable = FALSE;
1939  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_SELECTABLE, s_ptr->selectable);
1940 
1941  s_ptr->serv_type = ADB_SERVICE_TYPE_DSD;
1942  DBA_SetFieldValue(s_ptr->dba_rec, DBA_FIELD_SERV_TYPE, s_ptr->serv_type);
1943 
1944  ADB_SaveDatabase();
1945  }
1946  }
1947 
1949 
1950  if (s_ptr != NULL)
1951  {
1952  ACTL_TuneToService(path, NULL, s_ptr, FALSE, TRUE);
1953  retval = TRUE;
1954  }
1955  }
1956  else
1957  {
1958  ACTL_TuneToTransport(path, NULL, t_ptr, reqd_si, TRUE);
1959  retval = TRUE;
1960  }
1961  }
1962  }
1963 
1964  FUNCTION_FINISH(ACTL_TuneUsingDSD);
1965 
1966  return(retval);
1967 }
1968 
1974 BOOLEAN ACTL_IsTuned(U8BIT path)
1975 {
1976  BOOLEAN tuned;
1977 
1978  FUNCTION_START(ACTL_IsTuned);
1979 
1980  tuned = FALSE;
1981 
1982  if ((path != INVALID_RES_ID) && (tuning_state[path] == TSTATE_TUNED))
1983  {
1984  tuned = TRUE;
1985  }
1986 
1987  FUNCTION_FINISH(ACTL_IsTuned);
1988 
1989  return(tuned);
1990 }
1991 
1996 {
1997  U8BIT path;
1998 
1999  path = STB_DPGetPlaybackPath();
2000  if (path != INVALID_RES_ID)
2001  {
2002  STB_OSMutexLock(cntrl_mutex[path]);
2003 
2004  current_si[path] = APP_SI_MODE_NO_SI;
2005  si_required[path] = APP_SI_MODE_STARTUP_SEARCH;
2006  service_required[path] = NULL;
2007  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_ENABLE);
2008  StartSiProcess(path);
2009  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL; /* Pretend we have a good signal */
2010  /* The state machine inside ControlDecoding needs the followuing disable command to work properly
2011  * before to actually start decoding */
2012  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
2013 
2014  STB_OSMutexUnlock(cntrl_mutex[path]);
2015  }
2016 }
2017 
2022 void ACTL_StartPlayback(void *s_ptr)
2023 {
2024  U8BIT path;
2025  FUNCTION_START(ACTL_StartPlayback);
2026 
2027  //DBG_STR("ACTL_StartPlayback(service=0x%x)\n", s_ptr);
2028 
2029  path = STB_DPGetPlaybackPath();
2030  if (path != INVALID_RES_ID)
2031  {
2032  service_required[path] = s_ptr;
2033  transport_required[path] = NULL;
2034  if (s_ptr != NULL)
2035  {
2036  si_required[path] = APP_SI_MODE_UPDATE;
2037  signal_type_required = SIGNAL_COFDM;
2038  current_service[path] = (ADB_SERVICE_REC *)s_ptr;
2039  STB_DPStopSI(path); /* We don't need to get the SI updates */
2040  }
2041  else
2042  {
2043  current_service[path] = NULL;
2044  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
2045  }
2046  }
2047 
2048  FUNCTION_FINISH(ACTL_StartPlayback);
2049 }
2050 
2058 void ACTL_StartDecoding(U8BIT path, void *s_ptr)
2059 {
2060  FUNCTION_START(ACTL_StartDecoding);
2061 
2062  if ((path != INVALID_RES_ID) && STB_DPIsDecodingPath(path))
2063  {
2064  STB_OSMutexLock(cntrl_mutex[path]);
2065  current_service[path] = s_ptr;
2066  service_required[path] = s_ptr;
2067  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL;
2068  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_ENABLE);
2069  STB_OSMutexUnlock(cntrl_mutex[path]);
2070  }
2071 
2072  FUNCTION_FINISH(ACTL_StartDecoding);
2073 }
2074 
2079 void ACTL_TuneOff(U8BIT path)
2080 {
2081  FUNCTION_START(ACTL_TuneOff);
2082 
2083  if (path != INVALID_RES_ID)
2084  {
2085  STB_OSMutexLock(cntrl_mutex[path]);
2086  transport_required[path] = NULL;
2087  service_required[path] = NULL;
2088  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
2089  current_service[path] = NULL;
2090  current_transport[path] = NULL;
2091  current_satellite[path] = NULL;
2092  ADB_SetTunedTransport(path, NULL);
2093  ADB_SetTunedService(path, NULL);
2094  now_event_id[path] = -1;
2095  STB_OSMutexUnlock(cntrl_mutex[path]);
2096  }
2097 
2098  FUNCTION_FINISH(ACTL_TuneOff);
2099 }
2100 
2105 void ACTL_DecodeOff(U8BIT path)
2106 {
2107  FUNCTION_START(ACTL_DecodeOff);
2108 
2109  if (path != INVALID_RES_ID)
2110  {
2111  STB_OSMutexLock(cntrl_mutex[path]);
2112  service_required[path] = NULL;
2113  if (STB_DPIsDecodingPath(path))
2114  {
2115  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
2116  }
2117  STB_OSMutexUnlock(cntrl_mutex[path]);
2118  }
2119 
2120  FUNCTION_FINISH(ACTL_DecodeOff);
2121 }
2122 
2128 {
2129  U8BIT path;
2130 
2131  FUNCTION_START(ACTL_ReleaseChannelLock);
2132 
2133  path = ACTL_GetActivePath();
2134  if (path != INVALID_RES_ID)
2135  {
2136  if (signal_type_required == SIGNAL_ANALOG)
2137  {
2138  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TPTR_TUNE_REQD);
2139  }
2140  else
2141  {
2142  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RELEASE_DECODE_LOCK);
2143  }
2144  }
2145 
2146  FUNCTION_FINISH(ACTL_ReleaseChannelLock);
2147 }
2148 
2154 {
2155  U8BIT path;
2156 
2157  FUNCTION_START(ACTL_ReTuneAudio);
2158 
2159  path = ACTL_GetActivePath();
2160 
2161  if ((path != INVALID_RES_ID) && STB_DPIsDecodingPath(path))
2162  {
2163  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_AUDIO);
2164  }
2165 
2166  FUNCTION_FINISH(ACTL_ReTuneAudio);
2167 }
2168 
2174 {
2175  U8BIT path;
2176 
2177  FUNCTION_START(ACTL_ReTuneSubtitles);
2178 
2179  path = ACTL_GetActivePath();
2180  if (path != INVALID_RES_ID)
2181  {
2182  SUBT_DBG(("ACTL_ReTuneSubtitles: calling ControlDecoding with INT_EVENT_RESTART_SUBTITLES"));
2183  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_SUBTITLES);
2184  }
2185 
2186  FUNCTION_FINISH(ACTL_ReTuneSubtitles);
2187 }
2188 
2194 BOOLEAN ACTL_HasDecodingStarted(U8BIT path)
2195 {
2196  BOOLEAN started;
2197  FUNCTION_START(ACTL_HasDecodingStarted);
2198  if (path == INVALID_RES_ID)
2199  {
2200  started = FALSE;
2201  }
2202  else
2203  {
2204  started = decoding_started[path];
2205  }
2206  FUNCTION_FINISH(ACTL_HasDecodingStarted);
2207  return started;
2208 }
2209 
2215 BOOLEAN ACTL_IsDecodingLocked(U8BIT path)
2216 {
2217  BOOLEAN locked;
2218  FUNCTION_START(ACTL_IsDecodingLocked);
2219  if (path == INVALID_RES_ID)
2220  {
2221  locked = FALSE;
2222  }
2223  else
2224  {
2225  locked = decoding_locked[path];
2226  }
2227  FUNCTION_FINISH(ACTL_IsDecodingLocked);
2228  return locked;
2229 }
2230 
2235 void ACTL_SetStandbyState(BOOLEAN state)
2236 {
2237  E_ACTL_INTERNAL_EVENT event;
2238 
2239  FUNCTION_START(ACTL_SetStandbyState);
2240 
2241  if (state)
2242  {
2243  event = INT_EVENT_STANDBY_ON;
2244  ASTE_EnterStandby(FALSE);
2245  }
2246  else
2247  {
2248  event = INT_EVENT_STANDBY_OFF;
2250  }
2251 
2252  ControlAvOutput(INTERNAL_EVENT, event);
2253 
2254  FUNCTION_FINISH(ACTL_SetStandbyState);
2255 }
2256 
2261 {
2262  FUNCTION_START(ACTL_SetStandbyVCRActive);
2263 
2264  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_STANDBY_VCR_ACTIVE);
2265 
2266  FUNCTION_FINISH(ACTL_SetStandbyVCRActive);
2267 }
2268 
2269 #if 0
2270 
2281 void ACTL_AllowAltAVSources(BOOLEAN state)
2282 {
2283  E_ACTL_INTERNAL_EVENT event;
2284 
2285  FUNCTION_START(ACTL_AllowAltAVSources);
2286 
2287  if (state == TRUE)
2288  {
2289  event = INT_EVENT_ALT_AV_ALLOWED;
2290  }
2291  else
2292  {
2293  event = INT_EVENT_ALT_AV_NOT_ALLOWED;
2294  }
2295  ControlAvOutput(INTERNAL_EVENT, event);
2296 
2297  FUNCTION_FINISH(ACTL_AllowAltAVSources);
2298 }
2299 
2300 #endif
2301 
2310 void ACTL_SetVideoWindow(S16BIT win_x, S16BIT win_y, U16BIT win_width, U16BIT win_height)
2311 {
2312  S_RECTANGLE output;
2313 
2314  FUNCTION_START(ACTL_SetVideoWindow);
2315 
2316  if (win_width == 0 || win_height == 0)
2317  {
2318  STB_VTSetVideoOutput(NULL);
2319  }
2320  else
2321  {
2322  output.left = win_x;
2323  output.top = win_y;
2324  output.width = win_width;
2325  output.height = win_height;
2326  STB_VTSetVideoOutput(&output);
2327  }
2328 
2329  FUNCTION_FINISH(ACTL_SetVideoWindow);
2330 }
2331 
2336 void ACTL_SetTVAspectRatio(E_STB_AV_ASPECT_RATIO aspect_ratio)
2337 {
2338  E_STB_AV_VIDEO_FORMAT actual_mode;
2339  U16BIT width, height;
2340 
2341  FUNCTION_START(ACTL_SetTVAspectRatio);
2342 
2343  /* Save the setting */
2344  APP_NvmSave(ASPECT_RATIO_NVM, aspect_ratio, TRUE);
2345 
2346  actual_mode = ACTL_GetActualVideoMode(&width, &height);
2347 
2348  STB_AVSetTVType(0, aspect_ratio, actual_mode);
2349 
2350  FUNCTION_FINISH(ACTL_SetTVAspectRatio);
2351 }
2352 
2357 E_STB_AV_ASPECT_RATIO ACTL_GetTVAspectRatio(void)
2358 {
2359  FUNCTION_START(ACTL_GetTVAspectRatio);
2360  FUNCTION_FINISH(ACTL_GetTVAspectRatio);
2361  return((E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM));
2362 }
2363 
2370 void ACTL_SetTVAspectMode(E_STB_AV_ASPECT_MODE aspect_mode)
2371 {
2372  FUNCTION_START(ACTL_SetTVAspectMode);
2373 
2374  /* Save the setting */
2375  APP_NvmSave(ASPECT_MODE_NVM, aspect_mode, TRUE);
2376 
2377  STB_VTSetVideoAlignmentPref(aspect_mode);
2378 
2379  FUNCTION_FINISH(ACTL_SetTVAspectMode);
2380 }
2381 
2386 E_STB_AV_ASPECT_MODE ACTL_GetTVAspectMode(void)
2387 {
2388  FUNCTION_START(ACTL_GetTVAspectMode);
2389  FUNCTION_FINISH(ACTL_GetTVAspectMode);
2390  return((E_STB_AV_ASPECT_MODE)APP_NvmRead(ASPECT_MODE_NVM));
2391 }
2392 
2400 void ACTL_SetTVAspectConversion(E_STB_AV_ASPECT_RATIO aspect_ratio, E_STB_AV_ASPECT_MODE aspect_mode)
2401 {
2402  E_STB_AV_VIDEO_FORMAT actual_mode;
2403  U16BIT width, height;
2404 
2405  FUNCTION_START(ACTL_SetTVAspectConversion);
2406 
2407  /* Save the settings */
2408  APP_NvmSave(ASPECT_RATIO_NVM, aspect_ratio, FALSE);
2409  APP_NvmSave(ASPECT_MODE_NVM, aspect_mode, TRUE);
2410 
2411  actual_mode = ACTL_GetActualVideoMode(&width, &height);
2412 
2413  STB_AVSetTVType(0, aspect_ratio, actual_mode);
2414 
2415  STB_VTSetVideoAlignmentPref(aspect_mode);
2416 
2417  FUNCTION_FINISH(ACTL_SetTVAspectConversion);
2418 }
2419 
2424 E_ACTL_AV_MODE ACTL_GetAvModeStatus(void)
2425 {
2426  FUNCTION_START(ACTL_GetAvModeStatus);
2427  FUNCTION_FINISH(ACTL_GetAvModeStatus);
2428  return(av_mode);
2429 }
2430 
2431 #ifdef COMMON_INTERFACE
2432 
2440 void ACTL_TuneToCIService(U8BIT path, S_ACTL_OWNER_INFO *owner_info, void *s_ptr, E_APP_SI_MODE si_mode)
2441 {
2442  FUNCTION_START(ACTL_TuneToCIService);
2443 
2444 #ifdef DEBUG_TUNING
2445  STB_SPDebugWrite("ACTL_TuneToCIService(path=%d, owner_info=%p, service=0x%x, si_mode=%u)",
2446  path, owner_info, s_ptr, si_mode);
2447 #endif
2448 
2449  if (path == INVALID_RES_ID)
2450  {
2451  /* Try to acquire a live path */
2452  path = AcquireLivePath(s_ptr, owner_info, FALSE, NULL, si_mode, FALSE);
2453  }
2454 
2455  if (path != INVALID_RES_ID)
2456  {
2457  STB_OSMutexLock(cntrl_mutex[path]);
2458 
2459  service_required[path] = s_ptr;
2460  transport_required[path] = ADB_GetServiceTransportPtr(s_ptr);
2461  tuner_relock_required = TRUE;
2462  decode_lock_override_required = FALSE;
2463 
2464  if (s_ptr != NULL)
2465  {
2466  si_required[path] = si_mode;
2467  signal_type_required = ADB_GetTransportSignalType(transport_required[path]);
2468 
2469  /* If tuning to the current service then just start decoding, otherwise tune */
2470  if (current_service[path] != s_ptr)
2471  {
2472  current_service[path] = (ADB_SERVICE_REC *)s_ptr;
2473  ADB_SetTunedService(path, s_ptr);
2474  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TPTR_TUNE_REQD);
2475  }
2476  else
2477  {
2478  /* Start SI processing */
2479  StartSiProcess(path);
2480 
2481  if (STB_DPIsDecodingPath(path))
2482  {
2483  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_DECODING);
2484  }
2485  }
2486  }
2487  else
2488  {
2489  current_service[path] = NULL;
2490  ADB_SetTunedService(path, NULL);
2491  ControlTuning(path, INTERNAL_EVENT, INT_EVENT_TUNE_OFF);
2492  }
2493 
2494  STB_OSMutexUnlock(cntrl_mutex[path]);
2495  }
2496 
2497  FUNCTION_FINISH(ACTL_TuneToCIService);
2498 }
2499 
2507 void ACTL_ContinueCIPLUSTune(U8BIT path, BOOLEAN continue_tuning)
2508 {
2509  FUNCTION_START(ACTL_ContinueCIPLUSTune);
2510 
2511  if (continue_tuning)
2512  {
2513  if (path != INVALID_RES_ID)
2514  {
2515  if (!STB_DPIsRecordingPath(path))
2516  {
2517  STB_DPReleasePath(path, RES_OWNER_CIPLUS);
2518  path = INVALID_RES_ID;
2519  }
2520 
2521  if (tuneto_for_recording)
2522  {
2523  path = AcquireRecordingPath(tuneto_live_service, tuneto_owner_info);
2524  }
2525 
2526  if (tuneto_live_service != NULL)
2527  {
2528  ACTL_TuneToService(path, tuneto_owner_info, tuneto_live_service,
2529  decode_lock_override_required, TRUE);
2530  }
2531  else if (tuneto_live_transport != NULL)
2532  {
2533  ACTL_TuneToTransport(path, tuneto_owner_info, tuneto_live_transport,
2534  tuneto_live_si, tuneto_relock);
2535  }
2536  }
2537  }
2538 
2539  /* Reset variables now that a reply has been received */
2540  tuneto_live_service = NULL;
2541  tuneto_live_transport = NULL;
2542 
2543  if (tuneto_owner_info != NULL)
2544  {
2545  /* Release the copy of the owner info */
2546  if (tuneto_owner_info->data != NULL)
2547  {
2548  STB_AppFreeMemory(tuneto_owner_info->data);
2549  }
2550 
2551  STB_AppFreeMemory(tuneto_owner_info);
2552  tuneto_owner_info = NULL;
2553  }
2554 
2555  FUNCTION_FINISH(ACTL_ContinueCIPLUSTune);
2556 }
2557 
2558 #endif
2559 
2564 {
2565  FUNCTION_START(ACTL_EnableCiModule);
2566  #ifdef COMMON_INTERFACE
2567  STB_GCSetCIStandby(FALSE);
2568  #endif
2569  FUNCTION_FINISH(ACTL_EnableCiModule);
2570 }
2571 
2576 {
2577  FUNCTION_START(ACTL_DisableCiModule);
2578  #ifdef COMMON_INTERFACE
2579  STB_GCSetCIStandby(TRUE);
2580  #endif
2581  FUNCTION_FINISH(ACTL_DisableCiModule);
2582 }
2583 
2588 BOOLEAN ACTL_IsCiUiRequired(void)
2589 {
2590  FUNCTION_START(ACTL_IsCiUiRequired);
2591  FUNCTION_FINISH(ACTL_IsCiUiRequired);
2592  return(ci_ui_request);
2593 }
2594 
2600 BOOLEAN ACTL_GetDecodePausedState(U8BIT path)
2601 {
2602  FUNCTION_START(ACTL_GetDecodePausedState);
2603  FUNCTION_FINISH(ACTL_GetDecodePausedState);
2604  return(decode_paused_flag[path]);
2605 }
2606 
2619 void ACTL_SetAnalogChanIdString(U8BIT *str_ptr)
2620 {
2621 #if 0
2622  U16BIT string_len;
2623 
2624  FUNCTION_START(ACTL_SetAnalogChanIdString);
2625 
2626  analog_string_changed = FALSE;
2627 
2628  if (str_ptr == NULL)
2629  {
2630  // no string required - if string was valid then it has changed
2631  if (valid_analog_string == TRUE)
2632  {
2633  valid_analog_string = FALSE;
2634  analog_string_changed = TRUE;
2635  }
2636  }
2637  else
2638  {
2639  // we do want to display a string - but has it changed?
2640  if (valid_analog_string == FALSE)
2641  {
2642  analog_string_changed = TRUE;
2643  }
2644  else
2645  {
2646  if (strncmp((char *)str_ptr, (char *)analog_string_buffer, (sizeof(analog_string_buffer) - 1)) != 0)
2647  {
2648  analog_string_changed = TRUE;
2649  }
2650  }
2651 
2652  if (analog_string_changed == TRUE)
2653  {
2654  // string changed - copy into string buffer...
2655  // terminate string if larger than analog buffer
2656  string_len = strlen((char *)str_ptr);
2657  if (string_len >= sizeof(analog_string_buffer))
2658  {
2659  string_len = sizeof(analog_string_buffer) - 1;
2660  }
2661  memcpy(analog_string_buffer, str_ptr, string_len);
2662  //replace last char with null terminator
2663  analog_string_buffer[string_len] = 0;
2664  valid_analog_string = TRUE;
2665  }
2666  }
2667 
2668 
2669  if (analog_string_changed == TRUE)
2670  {
2671  ControlStatusIndication(STB_DPGetLivePath());
2672  }
2673 
2674  FUNCTION_FINISH(ACTL_SetAnalogChanIdString);
2675 #else
2676  USE_UNWANTED_PARAM(str_ptr);
2677 #endif
2678 }
2679 
2684 void ACTL_AllowAnalogVideo(BOOLEAN allow_analog_video)
2685 {
2686  E_ACTL_INTERNAL_EVENT event;
2687 
2688  FUNCTION_START(ACTL_AllowAnalogVideo);
2689 
2690  if (allow_analog_video == TRUE)
2691  {
2692  event = INT_EVENT_ANALOG_VIDEO_ALLOWED;
2693  }
2694  else
2695  {
2696  event = INT_EVENT_ANALOG_VIDEO_NOT_ALLOWED;
2697  }
2698  ControlAvOutput(INTERNAL_EVENT, event);
2699 
2700  FUNCTION_FINISH(ACTL_AllowAnalogVideo);
2701 }
2702 
2708 {
2709  FUNCTION_START(ACTL_IsAudioDescriptionOn);
2710  FUNCTION_FINISH(ACTL_IsAudioDescriptionOn);
2711  return(audio_desc_on);
2712 }
2713 
2721 BOOLEAN ACTL_StartAudioDescription(U8BIT path)
2722 {
2723  void *s_ptr;
2724  U16BIT pid;
2725  BOOLEAN broadcast_mix;
2726  E_STB_DP_AUDIO_MODE mode;
2727  ADB_STREAM_TYPE type;
2728 
2729  FUNCTION_START(ACTL_StartAudioDescription);
2730 
2731  if (path != INVALID_RES_ID)
2732  {
2733  if ((s_ptr = ADB_GetTunedService(path)) != NULL)
2734  {
2735  audio_desc_on = TRUE;
2736  STB_DPSetADEnabled(path, TRUE);
2737 
2739  pid = DBDEF_GetReqdADPid(s_ptr, &mode, &type, &broadcast_mix);
2741 
2742  if ((pid != 0) && (pid != 0xffff))
2743  {
2744  if (broadcast_mix)
2745  {
2746  /* Need to change the main audio PID */
2747  STB_DPSetAudioPID(path, pid);
2748  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_AUDIO);
2749  }
2750  else
2751  {
2752  STB_DPSetADPID(path, pid);
2753  STB_DPSetADMode(path, mode);
2755  ACTL_SetADVolume((U8BIT)APP_NvmRead(AD_VOLUME_NVM));
2756  STB_DPStartADDecoding(path);
2757  }
2758  }
2759  }
2760  }
2761 
2762  FUNCTION_FINISH(ACTL_StartAudioDescription);
2763 
2764  return(audio_desc_on);
2765 }
2766 
2772 {
2773  FUNCTION_START(ACTL_StopAudioDescription);
2774 
2775  if (path != INVALID_RES_ID)
2776  {
2777  audio_desc_on = FALSE;
2778  STB_DPSetADEnabled(path, FALSE);
2779  STB_DPStopADDecoding(path);
2780 
2781  /* If AD is broadcast mix then main audio decoding needs to be changed */
2782  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_AUDIO);
2783  }
2784 
2785  FUNCTION_FINISH(ACTL_StopAudioDescription);
2786 }
2787 
2792 void ACTL_SetADVolume(U8BIT volume)
2793 {
2794  FUNCTION_START(ACTL_SetADVolume);
2795 
2796  ad_volume = volume;
2797 
2798  AVSetAudioVolumes(TRUE);
2799 
2800  FUNCTION_FINISH(ACTL_SetADVolume);
2801 }
2802 
2810 E_STB_AV_VIDEO_FORMAT ACTL_GetActualVideoMode(U16BIT *width, U16BIT *height)
2811 {
2812  E_STB_AV_VIDEO_FORMAT current_mode;
2813  E_STB_AV_VIDEO_FORMAT *supported_modes;
2814  U8BIT num_modes, num_app_modes;
2815  U8BIT i, j;
2816  BOOLEAN valid_mode;
2817 
2818  FUNCTION_START(ACTL_GetActualVideoMode);
2819 
2820  current_mode = (E_STB_AV_VIDEO_FORMAT)APP_NvmRead(HDMI_RESOLUTION_NVM);
2821  num_modes = STB_AVGetHDMISupportedModes(&supported_modes);
2822  if (num_modes > 0)
2823  {
2824  DBGPRINT("current mode %d", current_mode);
2825  /* Check whether the user selected mode is supported */
2826  valid_mode = FALSE;
2827  /* The list of supported modes passed back by platform can include
2828  * the AUTO - HW layer will know if the TV gives 'native' mode */
2829  for (i = 0; i != num_modes; i++)
2830  {
2831  DBGPRINT("supported %d", supported_modes[i]);
2832  if (supported_modes[i] == current_mode)
2833  {
2834  valid_mode = TRUE;
2835  hdmi_connected = TRUE;
2836  break;
2837  }
2838  }
2839 
2840  /* Select the best mode that is supported. It's assumed that the app modes
2841  * are ordered from best to worst */
2842  num_app_modes = sizeof(app_video_formats) / sizeof(app_video_formats[0]);
2843 
2844  for (j = 0; j != num_app_modes; j++)
2845  {
2846  if (app_video_formats[j].mode == VIDEO_FORMAT_AUTO)
2847  {
2848  STB_AVGetHDMINativeResolution(&(app_video_formats[j].width),
2849  &(app_video_formats[j].height));
2850  }
2851  if (!valid_mode)
2852  {
2853  DBGPRINT("try mode %d", app_video_formats[j].mode);
2854  for (i = 0; i != num_modes; i++)
2855  {
2856  if (app_video_formats[j].mode == supported_modes[i])
2857  {
2858  DBGPRINT("select mode %d", supported_modes[i]);
2859  /* This is the best mode */
2860  current_mode = supported_modes[i];
2861 
2862  #ifdef DEBUG_AV_OUTPUT
2863  STB_SPDebugWrite("ACTL_GetActualVideoMode: Best HDMI res is %ux%u",
2864  app_video_formats[j].width, app_video_formats[j].height);
2865  #endif
2866  valid_mode = TRUE;
2867  break;
2868  }
2869  }
2870  }
2871  if (valid_mode && app_video_formats[j].mode == current_mode)
2872  {
2873  if (width != NULL)
2874  {
2875  *width = app_video_formats[j].width;
2876  }
2877 
2878  if (height != NULL)
2879  {
2880  *height = app_video_formats[j].height;
2881  }
2882  break;
2883  }
2884  }
2885  }
2886  else
2887  {
2888  /* Select the last app mode */
2889  num_app_modes = sizeof(app_video_formats) / sizeof(app_video_formats[0]);
2890  current_mode = app_video_formats[num_app_modes - 1].mode;
2891  *width = app_video_formats[num_app_modes - 1].width;
2892  *height = app_video_formats[num_app_modes - 1].height;
2893  }
2894 
2895  FUNCTION_FINISH(ACTL_GetActualVideoMode);
2896 
2897  return(current_mode);
2898 }
2899 
2908 void ACTL_UpdateVideoMode(E_STB_AV_ASPECT_RATIO aspect, BOOLEAN force)
2909 {
2910  E_STB_AV_VIDEO_FORMAT current_mode;
2911  E_STB_AV_VIDEO_FORMAT actual_mode;
2912  U16BIT width, height;
2913  BOOLEAN subt_displayed;
2914 
2915  FUNCTION_START(ACTL_UpdateVideoMode);
2916 
2917  current_mode = (E_STB_AV_VIDEO_FORMAT)APP_NvmRead(HDMI_RESOLUTION_NVM);
2918  actual_mode = ACTL_GetActualVideoMode(&width, &height);
2919  if (actual_mode != current_mode || force)
2920  {
2921  DBGPRINT("mode=%d actual=%d width=%d,height=%d", current_mode, actual_mode, width, height);
2922 
2923  if (current_mode != VIDEO_FORMAT_AUTO && current_mode != actual_mode && ACTL_IsHDMIConnected())
2924  {
2925  /* Override the invalid user setting with the one selected */
2926  APP_NvmSave(HDMI_RESOLUTION_NVM, actual_mode, TRUE);
2927  }
2928 
2929  /* If necessary, stop subtitles before changing tv format */
2930  subt_displayed = ACTL_AreSubtitlesDisplayed();
2931 
2933  {
2935  }
2936 
2937  STB_AVSetTVType(0, aspect, actual_mode);
2938 
2939  /* If necessary re-start subtitles */
2940  if (subt_displayed)
2941  {
2943  }
2944  }
2945  FUNCTION_FINISH(ACTL_UpdateVideoMode);
2946 }
2947 
2954 {
2955 #ifdef COMMON_INTERFACE
2956  U8BIT path;
2957 #endif
2958 
2959  FUNCTION_START(ACTL_HDMIConnected);
2960 
2961  DBGPRINT("%d", hdmi_connected);
2962 
2963  ACTL_UpdateVideoMode((E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), TRUE);
2964 
2965 #ifdef COMMON_INTERFACE
2966  if (initialised && ((path = STB_DPGetLivePath()) != INVALID_RES_ID))
2967  {
2968  /* HDMI is reconnected, URI must be re-applied (HDCP may or may not be active). */
2970  }
2971 #endif
2972 
2973  hdmi_connected = TRUE;
2974 
2975  FUNCTION_FINISH(ACTL_HDMIConnected);
2976 }
2977 
2983 {
2984  FUNCTION_START(ACTL_HDMIDisconnected);
2985  DBGPRINT("%d", hdmi_connected);
2986  hdmi_connected = FALSE;
2987  FUNCTION_FINISH(ACTL_HDMIDisconnected);
2988 }
2989 
2995 {
2996  FUNCTION_START(ACTL_IsHDMIConnected);
2997  DBGPRINT("%d", hdmi_connected);
2998  FUNCTION_FINISH(ACTL_IsHDMIConnected);
2999  return(hdmi_connected);
3000 }
3001 
3011 U16BIT ACTL_GetHDMIResolutions(E_STB_AV_VIDEO_FORMAT **video_formats, U16BIT *current_index)
3012 {
3013  E_STB_AV_VIDEO_FORMAT current_mode;
3014  E_STB_AV_VIDEO_FORMAT *supported_modes;
3015  U8BIT num_modes, num_app_modes;
3016  U16BIT num_valid_modes;
3017  U8BIT i, j;
3018 
3019  FUNCTION_START(ACTL_GetHDMIResolutionStrings);
3020 
3021  num_valid_modes = 0;
3022 
3023  current_mode = (E_STB_AV_VIDEO_FORMAT)APP_NvmRead(HDMI_RESOLUTION_NVM);
3024  num_modes = STB_AVGetHDMISupportedModes(&supported_modes);
3025 
3026  /* Find the number of modes supported by the app and stb */
3027  num_app_modes = sizeof(app_video_formats) / sizeof(app_video_formats[0]);
3028 
3029  for (j = 0; j != num_app_modes; j++)
3030  {
3031  for (i = 0; i != num_modes; i++)
3032  {
3033  if (app_video_formats[j].mode == supported_modes[i])
3034  {
3035  num_valid_modes++;
3036  break;
3037  }
3038  }
3039  }
3040 
3041  num_valid_modes++; /* Adding AUTO */
3042  *video_formats = (E_STB_AV_VIDEO_FORMAT *)STB_AppGetMemory(num_valid_modes * sizeof(E_STB_AV_VIDEO_FORMAT));
3043 
3044  num_valid_modes = 0;
3045 
3046  for (j = 0; j != num_app_modes; j++)
3047  {
3048  for (i = 0; i != num_modes; i++)
3049  {
3050  if (app_video_formats[j].mode == supported_modes[i])
3051  {
3052  (*video_formats)[num_valid_modes] = app_video_formats[j].mode;
3053 
3054  if (current_mode == supported_modes[i])
3055  {
3056  *current_index = num_valid_modes;
3057  }
3058  num_valid_modes++;
3059  break;
3060  }
3061  }
3062  }
3063 
3064  /* Add AUTO */
3065  (*video_formats)[num_valid_modes] = VIDEO_FORMAT_AUTO;
3066  if (current_mode == VIDEO_FORMAT_AUTO)
3067  {
3068  *current_index = num_valid_modes;
3069  }
3070  num_valid_modes++;
3071 
3072  FUNCTION_FINISH(ACTL_GetHDMIResolutionStrings);
3073 
3074  return(num_valid_modes);
3075 }
3076 
3084 void ACTL_SetParentalControl(BOOLEAN enabled)
3085 {
3086  U8BIT setting;
3087 
3088  FUNCTION_START(ACTL_SetParentalControl);
3089 
3090  setting = (U8BIT)APP_NvmRead(PARENTAL_LOCK_NVM);
3091 
3092  if (enabled)
3093  {
3094  if (setting != PARENTAL_LOCK_ON)
3095  {
3096  APP_NvmSave(PARENTAL_LOCK_NVM, PARENTAL_LOCK_ON, TRUE);
3097  }
3098  }
3099  else
3100  {
3101  if (setting != PARENTAL_LOCK_OFF)
3102  {
3103  APP_NvmSave(PARENTAL_LOCK_NVM, PARENTAL_LOCK_OFF, TRUE);
3104  }
3105  }
3106 
3107  FUNCTION_FINISH(ACTL_SetParentalControl);
3108 }
3109 
3116 {
3117  BOOLEAN enabled;
3118 
3119  FUNCTION_START(ACTL_ParentalControlEnabled);
3120 
3121  if (APP_NvmRead(PARENTAL_LOCK_NVM) != PARENTAL_LOCK_OFF)
3122  {
3123  enabled = TRUE;
3124  }
3125  else
3126  {
3127  enabled = FALSE;
3128  }
3129 
3130  FUNCTION_FINISH(ACTL_ParentalControlEnabled);
3131 
3132  return(enabled);
3133 }
3134 
3142 {
3143  U8BIT setting;
3144 
3145  FUNCTION_START(ACTL_SetParentalControlAge);
3146 
3147  if ((age >= 4) && (age <= 18))
3148  {
3149  setting = (U8BIT)APP_NvmRead(PARENTAL_LOCK_NVM);
3150  if (age != setting)
3151  {
3152  APP_NvmSave(PARENTAL_LOCK_NVM, age, TRUE);
3153  }
3154  }
3155 
3156  FUNCTION_FINISH(ACTL_SetParentalControlAge);
3157 }
3158 
3165 {
3166  U8BIT age;
3167 
3168  FUNCTION_START(ACTL_GetParentalControlAge);
3169 
3170  age = (U8BIT)APP_NvmRead(PARENTAL_LOCK_NVM);
3171  if ((age < 4) || (age > 18))
3172  {
3173  age = 0;
3174  }
3175 
3176  FUNCTION_FINISH(ACTL_GetParentalControlAge);
3177 
3178  return(age);
3179 }
3180 
3187 void ACTL_ApplyParentalControl(U8BIT path, void *s_ptr)
3188 {
3189  void *now_event;
3190  U8BIT parental_lock;
3191  U8BIT age;
3192  BOOLEAN restart_decoding;
3193 
3194  FUNCTION_START(ACTL_ApplyParentalControl);
3195 
3196  parental_lock = (U8BIT)APP_NvmRead(PARENTAL_LOCK_NVM);
3197  if (parental_lock == PARENTAL_LOCK_OFF)
3198  {
3199  /* No parental control, so ensure decoding isn't locked */
3200  STB_DPSetLockEnable(path, FALSE);
3201  }
3202  else
3203  {
3204  restart_decoding = FALSE;
3205 
3206  /* Check whether the current service is locked before checking whether age related parental
3207  * control should be applied */
3208  if (ADB_GetServiceLockedFlag(s_ptr))
3209  {
3210  if (!STB_DPGetLockEnable(path) && (decoding_state[path] != DSTATE_STARTING) &&
3211  (decoding_state[path] != DSTATE_DECODING))
3212  {
3213  /* Service needs to be locked */
3214  STB_DPSetLockEnable(path, TRUE);
3215 
3216  if (!STB_DPGetLockMode(path))
3217  {
3218  STB_DPSetLockMode(path, TRUE);
3219  }
3220 
3221  restart_decoding = TRUE;
3222  }
3223  }
3224  else
3225  {
3226  /* Check whether parental control applies to the programme now being broadcast,
3227  * or the service being viewed */
3228  ADB_GetNowNextEvents(s_ptr, &now_event, NULL);
3229  if (now_event != NULL)
3230  {
3231  /* If the now event hasn't changed then don't need to reapply parental control */
3232  if (ADB_GetEventId(now_event) != now_event_id[path])
3233  {
3234  now_event_id[path] = ADB_GetEventId(now_event);
3235 
3236  /* Generate age part of ETSI 300468 */
3237  age = ADB_GetEventParentalAge(now_event);
3238  if ((age >= 0x01) && (age <= 0x0f))
3239  {
3240  age += 3;
3241  }
3242 
3243  /* Parental locking needs to be applied according to the set age */
3244  if (age >= parental_lock)
3245  {
3246  /* Parental locking is enabled */
3247  STB_DPSetLockEnable(path, TRUE);
3248 
3249  /* Decoding needs to be locked */
3250  if (!STB_DPGetLockMode(path))
3251  {
3252  STB_DPSetLockMode(path, TRUE);
3253 #ifdef INTEGRATE_HBBTV
3255 #endif
3256  }
3257 
3258  restart_decoding = TRUE;
3259  }
3260  else
3261  {
3262  /* Decoding no longer needs to be locked */
3263  STB_DPSetLockEnable(path, FALSE);
3264 
3265  if (STB_DPGetLockMode(path))
3266  {
3267  STB_DPSetLockMode(path, FALSE);
3268 #ifdef INTEGRATE_HBBTV
3270 #endif
3271  restart_decoding = TRUE;
3272  }
3273  }
3274  }
3275 
3276  ADB_ReleaseEventData(now_event);
3277  }
3278  else
3279  {
3280  /* Without the now event, the service should be unlocked */
3281  STB_DPSetLockEnable(path, FALSE);
3282 
3283  if (STB_DPGetLockMode(path))
3284  {
3285  STB_DPSetLockMode(path, FALSE);
3286  restart_decoding = TRUE;
3287  }
3288  }
3289  }
3290 
3291  if (restart_decoding)
3292  {
3293  if (decoding_state[path] >= DSTATE_STARTING_BAD_SIGNAL)
3294  {
3295  /* Stop and start decoding to force the change to locked mode */
3296  STB_DPStopDecoding(path);
3297  STB_DPStartDecoding(path);
3298  }
3299  }
3300  }
3301 
3302  FUNCTION_FINISH(ACTL_ApplyParentalControl);
3303 }
3304 
3311 void ACTL_ApplyHDCP(void *s_ptr)
3312 {
3313  void *now_event;
3314  U8BIT level;
3315 
3316  FUNCTION_START(ACTL_ApplyHDCP);
3317 
3318  if (ACFG_IsNordigCountry())
3319  {
3320 #ifdef COMMON_INTERFACE
3321  /* If CI+ indicates that HDCP is required then it will have set the state of the HDMI output,
3322  * in which case nothing should be done here to override it. */
3324 #endif
3325  {
3326  /* Use the content protection level to determine whether HDCP is required or not */
3327  level = ADB_GetServiceContentProtectionLevel(s_ptr);
3328 
3329  switch (level)
3330  {
3331  case 0x03:
3332  /* Protection is mandatory regardless of the content */
3334  {
3335  /* Turn the HDMI output on */
3337  }
3338  else
3339  {
3340  /* Turn the HDMI output off */
3342  }
3343  break;
3344 
3345  case 0x02:
3346  /* Protection is mandatory for HD or above content, but not for SD (<= 576 lines).
3347  * As HDCP is currently always on, treat this the same as case 0x03 */
3348  if (ADB_GetServiceIsHd(s_ptr))
3349  {
3351  {
3352  /* Turn the HDMI output on */
3354  }
3355  else
3356  {
3357  /* Turn the HDMI output off */
3359  }
3360  }
3361  else
3362  {
3363  /* Turn the HDMI output on */
3365  }
3366  break;
3367 
3368  case 0x00:
3369  /* Protection shall be turned off! Always enable the output */
3371  break;
3372 
3373  case 0x01:
3374  default:
3375  /* Protection isn't required and can be on or off, so enable output */
3377  break;
3378  }
3379  }
3380  }
3381  else
3382  {
3383  /* Check that the programme now being broadcast is allowed to be shown on an HD output */
3384  ADB_GetNowNextEvents(s_ptr, &now_event, NULL);
3385  if (now_event != NULL)
3386  {
3387 #ifdef COMMON_INTERFACE
3388  /* If CI+ indicates that HDCP is required then it will have set the state of the HDMI output,
3389  * in which case nothing should be done here to override it. */
3391 #endif
3392  {
3393  /* Check whether the current event should only be output with
3394  * content protection enabled */
3395  if (!ADB_GetEventDoNotScramble(now_event))
3396  {
3398  {
3399  /* Turn the HDMI output off */
3401  }
3402  else
3403  {
3404  /* Turn the HDMI output on */
3406  }
3407  }
3408  else
3409  {
3410  /* Make sure the HDMI output is on */
3412  }
3413  }
3414 
3415  ADB_ReleaseEventData(now_event);
3416  }
3417  else
3418  {
3419 #ifdef COMMON_INTERFACE
3420  /* If CI+ indicates that HDCP is required then it will have set the state of the HDMI output,
3421  * in which case nothing should be done here to override it. */
3423 #endif
3424  {
3425  /* Base protection on the service */
3426  if (!ADB_GetServiceDoNotScramble(s_ptr))
3427  {
3429  {
3430  /* Turn the HDMI output off */
3432  }
3433  else
3434  {
3435  /* Turn the HDMI output on */
3437  }
3438  }
3439  else
3440  {
3441  /* Make sure the HDMI output is on */
3443  }
3444  }
3445  }
3446  }
3447 
3448  FUNCTION_FINISH(ACTL_ApplyHDCP);
3449 }
3450 
3456 BOOLEAN ACTL_SuppressSubtitles(BOOLEAN suppress)
3457 {
3458  FUNCTION_START(ACTL_SuppressSubtitles);
3459  subtitles_suppressed = suppress;
3460  if(suppress == FALSE && subtitles_running)
3461  {
3463  }
3464  FUNCTION_FINISH(ACTL_SuppressSubtitles);
3465  return(subtitles_suppressed);
3466 }
3467 
3474 BOOLEAN ACTL_StartSubtitles(void)
3475 {
3476  ADB_SUBT_INFO subt_info;
3477  U16BIT pid;
3478  U8BIT path;
3479 
3480  FUNCTION_START(ACTL_StartSubtitles);
3481 
3482  path = ACTL_GetActivePath();
3483  if (!subtitles_suppressed && path != INVALID_RES_ID)
3484  {
3485  pid = GetSubtitlePidFunc(current_service[path], &subt_info);
3486  if (pid != 0)
3487  {
3488  SUBT_DBG(("ACTL_StartSubtitles: pid=%x dvb_subtitles=%d", pid,subt_info.is_dvb_subt));
3489  dvb_subtitles = subt_info.is_dvb_subt;
3490  if (dvb_subtitles)
3491  {
3492  SUBT_DBG(("ACTL_StartSubtitles: calling STB_SUBStart(%u,%u)",subt_info.u.subt.cpage,subt_info.u.subt.apage));
3493  STB_SUBStart(path, pid, subt_info.u.subt.cpage, subt_info.u.subt.apage);
3494  STB_SUBEnable(path, TRUE);
3495  }
3496  else
3497  {
3498  //STB_EBUTT_SetCacheMethod(EBUTT_CACHING_METHOD_PREVIOUS_NEXT);
3499  STB_EBUTT_SetCacheMethod(EBUTT_CACHING_METHOD_NAVIGATION_TREE);
3500 
3501  SUBT_DBG(("ACTL_StartSubtitles: calling STB_EBUTT_Start(%u,%u)", subt_info.u.ttxt.magazine,subt_info.u.ttxt.page));
3502  STB_EBUTT_Start(ACTL_GetActivePath(), pid, subt_info.u.ttxt.magazine, subt_info.u.ttxt.page);
3503  STB_EBUTT_Show(EBUTT_CHARACTER_SET_DESIGNATION_LATIN_DEFAULT, FALSE, FALSE);
3504  }
3505  }
3506  }
3507 
3508  subtitles_running = TRUE;
3509  subtitles_started = TRUE;
3510 
3511  FUNCTION_FINISH(ACTL_StartSubtitles);
3512 
3513  return(subtitles_started);
3514 }
3515 
3520 {
3521  U8BIT path;
3522 
3523  FUNCTION_START(ACTL_PauseSubtitles);
3524 
3525  if (subtitles_started && subtitles_running)
3526  {
3527  if (dvb_subtitles)
3528  {
3529  path = ACTL_GetActivePath();
3530  SUBT_DBG(("ACTL_PauseSubtitles: calling STB_SUBEnable(FALSE)"));
3531  STB_SUBEnable(path, FALSE);
3532  }
3533  else
3534  {
3535  SUBT_DBG(("ACTL_PauseSubtitles: calling STB_EBUTT_Hide"));
3536  STB_EBUTT_Hide();
3537  }
3538  subtitles_running = FALSE;
3539  }
3540 
3541  FUNCTION_FINISH(ACTL_PauseSubtitles);
3542 }
3543 
3548 {
3549  U8BIT path;
3550 
3551  FUNCTION_START(ACTL_ResumeSubtitles);
3552 
3553  if (subtitles_started && !subtitles_running)
3554  {
3555  path = ACTL_GetActivePath();
3556 
3557  if (!subtitles_suppressed && ADB_ServiceHasSubtitles(current_service[path], &dvb_subtitles))
3558  {
3559  if (dvb_subtitles)
3560  {
3561  SUBT_DBG(("ACTL_ResumeSubtitles calling STB_SUBEnable(TRUE)"));
3562  STB_SUBEnable(path, TRUE);
3563  }
3564  else
3565  {
3566  STB_EBUTT_Show(EBUTT_CHARACTER_SET_DESIGNATION_LATIN_DEFAULT, FALSE, FALSE);
3567  }
3568  }
3569 
3570  subtitles_running = TRUE;
3571  }
3572 
3573  FUNCTION_FINISH(ACTL_ResumeSubtitles);
3574 }
3575 
3580 {
3581  U8BIT path;
3582 
3583  FUNCTION_START(ACTL_StopSubtitles);
3584 
3585  if (subtitles_started)
3586  {
3587  path = ACTL_GetActivePath();
3588 
3589  if (dvb_subtitles)
3590  {
3591  if (subtitles_running)
3592  {
3593  SUBT_DBG(("ACTL_StopSubtitles: calling STB_SUBEnable(FALSE)"));
3594  STB_SUBEnable(path, FALSE);
3595  }
3596 
3597  SUBT_DBG(("ACTL_StopSubtitles: calling STB_SUBStop"));
3598  STB_SUBStop(path);
3599  }
3600  else
3601  {
3602  SUBT_DBG(("ACTL_StopSubtitles:: calling STB_EBUTT_Hide"));
3603  STB_EBUTT_Hide();
3604  STB_EBUTT_Stop(path, TRUE);
3605  }
3606  subtitles_running = FALSE;
3607  subtitles_started = FALSE;
3608  }
3609 
3610  FUNCTION_FINISH(ACTL_StopSubtitles);
3611 }
3612 
3617 {
3618  FUNCTION_START(ACTL_AreSubtitlesDisplayed);
3619  FUNCTION_FINISH(ACTL_AreSubtitlesDisplayed);
3620  return(subtitles_running);
3621 }
3622 
3627 {
3628  FUNCTION_START(ACTL_AreSubtitlesStarted);
3629  FUNCTION_FINISH(ACTL_AreSubtitlesStarted);
3630  return(subtitles_started);
3631 }
3632 
3639 BOOLEAN ACTL_IsTrailerBookingAvailable(void *serv_ptr)
3640 {
3641  BOOLEAN available;
3642  U8BIT num_links;
3643 
3644  FUNCTION_START(ACTL_IsTrailerBookingAvailable);
3645 
3646  available = FALSE;
3647 
3648  num_links = ADB_GetServiceNumRCTLinks(serv_ptr);
3649  if (num_links > 0)
3650  {
3651  available = TRUE;
3652  }
3653 
3654  FUNCTION_FINISH(ACTL_IsTrailerBookingAvailable);
3655 
3656  return(available);
3657 }
3658 
3664 {
3665  U8BIT path;
3666 
3667  FUNCTION_START(ACTL_GetActivePath);
3668 
3669  path = STB_DPGetPlaybackPath();
3670  if (path == INVALID_RES_ID)
3671  {
3672  path = STB_DPGetLivePath();
3673  }
3674 
3675  FUNCTION_FINISH(ACTL_GetActivePath);
3676 
3677  return path;
3678 }
3679 
3687 BOOLEAN ACTL_StartServiceSearch(E_STB_DP_SIGNAL_TYPE tuner_type, E_ACTL_SEARCH_TYPE type)
3688 {
3689  BOOLEAN retval;
3690  S_MANUAL_TUNING_PARAMS tune_params;
3691 
3692  FUNCTION_START(ACTL_StartServiceSearch);
3693 
3694  retval = FALSE;
3695 
3696 #ifdef DEBUG_SERVICE_SEARCH
3697  STB_SPDebugWrite("%s(%u, %u)", __FUNCTION__, tuner_type, type);
3698 #endif
3699 
3700  /* Path to be used for the search doesn't require decoders */
3701  search_path = STB_DPAcquireTunerPath(tuner_type, NULL, NULL, RES_OWNER_DVB, DP_PRIORITY_LOW,
3702  FALSE, FALSE);
3703  if (search_path != INVALID_RES_ID)
3704  {
3705  /* Set the state in NVM */
3706  APP_NvmSave(SEARCHING_STATE_NVM, (U32BIT)TRUE, TRUE);
3707 
3709 
3710  search_list_id = 0;
3711  signal_type_required = tuner_type;
3712 
3713  switch (tuner_type)
3714  {
3715  case SIGNAL_COFDM:
3716  terr_hierarchy = TUNE_THIERARCHY_NONE;
3717  t2_plp_id = 0;
3718  STB_DPSetTerrPLP(search_path, t2_plp_id);
3719 
3720  /* Map search type for searches supported by DVB-T */
3721  switch (type)
3722  {
3723  case ACTL_FREQ_SEARCH:
3724  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3725  required_search_type = SEARCH_TYPE_SERVICE_FREQ;
3726  break;
3727 
3728  case ACTL_NETWORK_SEARCH:
3729  /* Network search starts off as a freq search until an NIT is found */
3730  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3731  required_search_type = SEARCH_TYPE_SERVICE_NETWORK;
3732  break;
3733 
3734  default:
3735  current_search_type = SEARCH_TYPE_NOSEARCH;
3736  break;
3737  }
3738 
3739  if (current_search_type != SEARCH_TYPE_NOSEARCH)
3740  {
3741  /* Start the search */
3742  retval = ACTL_TuneToRfChanArrayEntry(search_path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
3743  }
3744  break;
3745  case SIGNAL_QAM:
3746  /* Map search type for searches supported by DVB-C */
3747  switch (type)
3748  {
3749  case ACTL_FREQ_SEARCH:
3750  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3751  required_search_type = SEARCH_TYPE_SERVICE_FREQ;
3752  break;
3753 
3754  case ACTL_NETWORK_SEARCH:
3755  /* Network search starts off as a freq search until an NIT is found */
3756  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3757  required_search_type = SEARCH_TYPE_SERVICE_NETWORK;
3758  break;
3759 
3760  default:
3761  current_search_type = SEARCH_TYPE_NOSEARCH;
3762  break;
3763  }
3764 
3765  if (current_search_type != SEARCH_TYPE_NOSEARCH)
3766  {
3767  /* Start the search */
3768  retval = ACTL_TuneToRfChanArrayEntry(search_path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
3769  }
3770  break;
3771  case SIGNAL_ANALOG:
3772  /* Only support frequency search for analog */
3773  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3774  required_search_type = SEARCH_TYPE_SERVICE_FREQ;
3775 
3776  /* Start the search */
3777  retval = ACTL_TuneToRfChanArrayAnalogEntry(search_path, search_list_id);
3778  break;
3779  case SIGNAL_QPSK:
3780  /* Map search type for searches supported by DVB-S */
3781  switch (type)
3782  {
3783  case ACTL_FREQ_SEARCH:
3784  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3785  required_search_type = SEARCH_TYPE_SERVICE_FREQ;
3786  break;
3787 
3788  case ACTL_NETWORK_SEARCH:
3789  /* Network search starts off as a freq search until a NIT is found */
3790  current_search_type = SEARCH_TYPE_SERVICE_FREQ;
3791  required_search_type = SEARCH_TYPE_SERVICE_NETWORK;
3792  break;
3793 
3794  default:
3795  current_search_type = SEARCH_TYPE_NOSEARCH;
3796  break;
3797  }
3798 
3799  if (current_search_type != SEARCH_TYPE_NOSEARCH)
3800  {
3801  /* Setup the tuning params */
3802  MapIdToSatTuneParams(search_list_id, &tune_params);
3803 
3804  /* Start the search */
3805  retval = ACTL_TuneToUserDefinedParams(search_path, &tune_params, ACTL_SI_CHANNEL_SEARCH, FALSE);
3806  }
3807  break;
3808  default:
3809  signal_type_required = SIGNAL_NONE;
3810  break;
3811  }
3812 
3813  if (retval)
3814  {
3815  if (ASTE_InStandby())
3816  {
3817  DBG_STDBY(("Starting service search"));
3819 
3820  /* Save the date the search is being performed and the standby state */
3821  APP_NvmSave(LAST_CHAN_SRCH_NVM, DHMS_DATE(STB_GCNowDHMSLocal()), FALSE);
3822 
3823  DBG_STDBY(("Setting STANDBY_STATE_NVM=STDBY_UPDATE_SEARCH"));
3824  APP_NvmSave(STANDBY_STATE_NVM, STDBY_UPDATE_SEARCH, TRUE);
3825  }
3826  else
3827  {
3828  /* Send event to update the UI */
3829  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
3830  }
3831  }
3832  else
3833  {
3834  current_search_type = SEARCH_TYPE_NOSEARCH;
3835  required_search_type = SEARCH_TYPE_NOSEARCH;
3836  EndSearch(search_path);
3837  search_path = INVALID_RES_ID;
3838  }
3839  }
3840 
3841  FUNCTION_FINISH(ACTL_StartServiceSearch);
3842 
3843  return(retval);
3844 }
3845 
3853 {
3854  BOOLEAN retval;
3855  U32BIT *country_codes;
3856 
3857  FUNCTION_START(ACTL_IsTargetRegionRequired);
3858 
3859  if (ADB_GetNetworkTargetCountries(&country_codes) > 0)
3860  {
3861  STB_AppFreeMemory(country_codes);
3862  retval = TRUE;
3863  }
3864  else
3865  {
3866  retval = FALSE;
3867  }
3868 
3869  FUNCTION_FINISH(ACTL_IsTargetRegionRequired);
3870 
3871  return(retval);
3872 }
3873 
3878 {
3879  FUNCTION_START(ACTL_StopServiceSearch);
3880 
3881  EndSearch(search_path);
3882  search_path = INVALID_RES_ID;
3883 
3884  FUNCTION_FINISH(ACTL_StopServiceSearch);
3885 }
3886 
3894 {
3895  BOOLEAN retval;
3896  void **tlist;
3897  U16BIT num_transports;
3898 
3899  FUNCTION_START(ACTL_StartStartupSearch);
3900 
3901  retval = FALSE;
3902 
3903  ADB_GetTransportList(&tlist, &num_transports);
3904 
3905  if (num_transports > 0)
3906  {
3907  search_list_id = 0;
3908  search_num_transports = num_transports;
3909  current_search_type = SEARCH_TYPE_STARTUP;
3910 
3911  search_path = STB_DPAcquireTunerPath(ADB_GetTransportSignalType(tlist[search_list_id]), NULL, NULL,
3912  RES_OWNER_DVB, DP_PRIORITY_LOW, FALSE, FALSE);
3913  if (search_path != INVALID_RES_ID)
3914  {
3915  ACTL_TuneToTransport(search_path, NULL, tlist[search_list_id], ACTL_SI_STARTUP_SEARCH, FALSE);
3916  retval = TRUE;
3917  }
3918 
3919  ADB_ReleaseTransportList(tlist, num_transports);
3920  }
3921 
3922  FUNCTION_FINISH(ACTL_StartStartupSearch);
3923 
3924  return(retval);
3925 }
3926 
3927 #ifdef INCLUDE_OTA_SSU
3928 
3937 BOOLEAN ACTL_StartSSUSearch(E_STB_DP_SIGNAL_TYPE tuner_type, F_SSU_VERSION_CALLBACK version_callback)
3938 {
3939  BOOLEAN retval;
3940  void **tlist;
3941  U16BIT num_transports;
3942 
3943  FUNCTION_START(ACTL_StartSSUSearch);
3944 
3945  DBG_SSU(("ACTL_StartSSUSearch"));
3946 
3947  /* Start search */
3948  ADB_GetTransportListForTunerType(tuner_type, &tlist, &num_transports);
3949 
3950  retval = FALSE;
3951 
3952  if (num_transports > 0)
3953  {
3954  search_list_id = 0;
3955  search_num_transports = num_transports;
3956 
3957  search_path = STB_DPAcquireTunerPath(ADB_GetTransportSignalType(tlist[0]), NULL, NULL,
3958  RES_OWNER_DVB, DP_PRIORITY_LOW, FALSE, FALSE);
3959  if (search_path != INVALID_RES_ID)
3960  {
3961  /* DVB SSU upgrade system - tune to the first transport to look for the SSU info required */
3962  current_search_type = SEARCH_TYPE_SSU;
3963  current_search_tuner_type = tuner_type;
3964 
3965  ota_settings.ota_location = NULL;
3966  ota_settings.ota_onet_id = ADB_INVALID_DVB_ID;
3967  ota_settings.ota_tran_id = ADB_INVALID_DVB_ID;
3968  ota_settings.ota_serv_id = ADB_INVALID_DVB_ID;
3969  ota_settings.version_cb = version_callback;
3970 
3971  ACTL_TuneToTransport(search_path, NULL, tlist[0], ACTL_SI_DVB_SSU_SEARCH, FALSE);
3972 
3973  if (ASTE_InStandby())
3974  {
3975  DBG_SSU(("Starting OTA SSU search"));
3977 
3978  /* Save the date the search is being performed. This is set even if it doesn't start
3979  * successfully to prevent it constantly retrying */
3980  APP_NvmSave(OTA_LAST_UPDATE_SRCH_NVM, DHMS_DATE(STB_GCNowDHMSLocal()), TRUE);
3981 
3982  DBG_STDBY(("Setting STANDBY_STATE_NVM=STDBY_UPDATE_SEARCH"));
3983  APP_NvmSave(STANDBY_STATE_NVM, STDBY_UPDATE_SEARCH, FALSE);
3984  }
3985 
3986  retval = TRUE;
3987  }
3988 
3989  ADB_ReleaseTransportList(tlist, num_transports);
3990  }
3991 
3992  FUNCTION_FINISH(ACTL_StartSSUSearch);
3993 
3994  return(retval);
3995 }
3996 #endif /* INCLUDE_OTA_SSU */
3997 
4005 BOOLEAN ACTL_StartTotSearch(E_STB_DP_SIGNAL_TYPE tuner_type)
4006 {
4007  BOOLEAN retval;
4008  void **tlist;
4009  U16BIT num_transports;
4010 
4011  FUNCTION_START(ACTL_StartTotSearch);
4012 
4013  retval = FALSE;
4014 
4015  TOT_DBG(("ACTL_StartTotSearch(tuner_type=%s)",
4016  ((tuner_type == SIGNAL_COFDM) ? "DVB-T" :
4017  (tuner_type == SIGNAL_QPSK) ? "DVB-S" :
4018  (tuner_type == SIGNAL_QAM) ? "DVB-C" : "All")));
4019 
4020  ADB_GetTransportListForTunerType(tuner_type, &tlist, &num_transports);
4021 
4022  if (num_transports > 0)
4023  {
4024  search_list_id = 0;
4025  search_num_transports = num_transports;
4026  required_search_type = SEARCH_TYPE_TOT;
4027  current_search_type = SEARCH_TYPE_TOT;
4028  current_search_tuner_type = tuner_type;
4029 
4030  search_path = STB_DPAcquireTunerPath(ADB_GetTransportSignalType(tlist[search_list_id]), NULL, NULL,
4031  RES_OWNER_DVB, DP_PRIORITY_LOW, FALSE, FALSE);
4032  if (search_path != INVALID_RES_ID)
4033  {
4034  TOT_DBG(("ACTL_StartTotSearch: Tuning, num_transports=%u", search_num_transports));
4035  ACTL_TuneToTransport(search_path, NULL, tlist[search_list_id], ACTL_SI_TOT_SEARCH, FALSE);
4036  retval = TRUE;
4037  }
4038 
4039  ADB_ReleaseTransportList(tlist, num_transports);
4040  }
4041 #ifdef DEBUG_TOT_SEARCH
4042  else
4043  {
4044  TOT_DBG(("ACTL_StartTotSearch: num_transports = 0"));
4045  }
4046 #endif
4047 
4048  if (retval == FALSE)
4049  {
4050  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
4051  }
4052 
4053  FUNCTION_FINISH(ACTL_StartTotSearch);
4054 
4055  return(retval);
4056 }
4057 
4062 {
4063  FUNCTION_START(ACTL_StopTotSearch);
4064 
4065  if (search_path != INVALID_RES_ID)
4066  {
4067  FinishSearch(search_path);
4068  }
4069 #ifdef DEBUG_TOT_SEARCH
4070  else
4071  {
4072  TOT_DBG(("ACTL_StopTotSearch: invalid path"));
4073  }
4074 #endif
4075 
4076  FUNCTION_FINISH(ACTL_StopTotSearch);
4077 }
4078 
4086 BOOLEAN ACTL_StartEitSearch(E_STB_DP_SIGNAL_TYPE tuner_type, E_ACTL_EVENT_SEARCH search_type)
4087 {
4088  BOOLEAN retval;
4089  void **transport_list;
4090  U16BIT num_transports;
4091  void **network_list;
4092  U16BIT num_networks;
4093  U16BIT i, j;
4094  void *t_ptr;
4095 
4096  FUNCTION_START(ACTL_StartEitSearch);
4097 
4098  retval = FALSE;
4099 
4100  ADB_GetTransportListForTunerType(tuner_type, &transport_list, &num_transports);
4101  if ((transport_list != NULL) && (num_transports != 0))
4102  {
4103  search_num_transports = num_transports;
4104 
4105  /* Some networks may have a transport that contains full SI data, in which case other
4106  * transports on that network can be removed */
4107  ADB_GetNetworkList(&network_list, &num_networks);
4108  if ((network_list != NULL) && (num_networks != 0))
4109  {
4110  for (i = 0; i < num_networks; i++)
4111  {
4112  t_ptr = ADB_GetFullSITransport(network_list[i]);
4113  if (t_ptr != NULL)
4114  {
4115  /* This network has a transport with full SI data, so remove other transports
4116  * from the list that are in this network */
4117  for (j = 0; j < num_transports; j++)
4118  {
4119  if ((transport_list[j] != t_ptr) &&
4120  (ADB_GetTransportNetworkPtr(transport_list[j]) == network_list[i]))
4121  {
4122  /* This transport is in the network so doesn't need to be checked */
4123  transport_list[j] = NULL;
4124  search_num_transports--;
4125  }
4126  }
4127  }
4128  }
4129 
4130  ADB_ReleaseNetworkList(network_list);
4131  }
4132 
4133  if (search_num_transports != 0)
4134  {
4135  /* Allocate and copy the transports to be searched */
4136  search_transport_list = (void **)STB_AppGetMemory(search_num_transports * sizeof(void *));
4137  if (search_transport_list != NULL)
4138  {
4139  for (i = 0, j = 0; i < num_transports; i++)
4140  {
4141  if (transport_list[i] != NULL)
4142  {
4143  search_transport_list[j] = transport_list[i];
4144  j++;
4145  }
4146  }
4147 
4148  ADB_ReleaseTransportList(transport_list, num_transports);
4149 
4150  /* Now ready to start the search */
4151  EIT_DBG(("%s: Starting EIT %s search on %u transports", __FUNCTION__,
4152  ((search_type == ACTL_EVENT_SEARCH_PF) ? "p/f" :
4153  (search_type == ACTL_EVENT_SEARCH_SCHED) ? "sched" : "p/f+sched"),
4154  search_num_transports));
4155 
4156  search_list_id = 0;
4157 
4158  switch (search_type)
4159  {
4160  case ACTL_EVENT_SEARCH_PF:
4161  current_search_type = SEARCH_TYPE_EIT_PF;
4162  break;
4163  case ACTL_EVENT_SEARCH_SCHED:
4164  current_search_type = SEARCH_TYPE_EIT_SCHED;
4165  break;
4166  case ACTL_EVENT_SEARCH_PF_SCHED:
4167  current_search_type = SEARCH_TYPE_EIT_PF_SCHED;
4168  break;
4169  }
4170 
4171  retval = StartEitSearch();
4172  if (!retval)
4173  {
4174  current_search_type = SEARCH_TYPE_NOSEARCH;
4175  }
4176  }
4177  else
4178  {
4179  EIT_DBG(("%s: Failed to allocate memory for transports to be searched", __FUNCTION__));
4180  ADB_ReleaseTransportList(transport_list, num_transports);
4181  search_num_transports = 0;
4182  }
4183  }
4184  else
4185  {
4186  EIT_DBG(("%s: No transports left after removing network transports!", __FUNCTION__));
4187  ADB_ReleaseTransportList(transport_list, num_transports);
4188  }
4189  }
4190  else
4191  {
4192  EIT_DBG(("%s: Failed to find any transports for tuner type %u", __FUNCTION__, tuner_type));
4193  }
4194 
4195  FUNCTION_FINISH(ACTL_StartEitSearch);
4196 
4197  return(retval);
4198 }
4199 
4204 {
4205  FUNCTION_START(ACTL_StopEitSearch);
4206 
4207  if (search_path != INVALID_RES_ID)
4208  {
4209  ACTL_TuneOff(search_path);
4210  STB_DPReleasePath(search_path, RES_OWNER_DVB);
4211  search_path = INVALID_RES_ID;
4212  }
4213 #ifdef DEBUG_EIT_SEARCH
4214  else
4215  {
4216  EIT_DBG(("ACTL_StopEitSearch: invalid path"));
4217  }
4218 #endif
4219 
4220  FUNCTION_FINISH(ACTL_StopEitSearch);
4221 }
4222 
4229 {
4230  FUNCTION_START(ACTL_IsSearchComplete);
4231  FUNCTION_FINISH(ACTL_IsSearchComplete);
4232  return(current_search_type == SEARCH_TYPE_NOSEARCH);
4233 }
4234 
4243 {
4244  U8BIT progress;
4245  U16BIT num;
4246 #if defined(DEBUG_SERVICE_SEARCH) || defined(DEBUG_TOT_SEARCH) || defined(DEBUG_SSU_SEARCH) || \
4247  defined(DEBUG_STARTUP_SEARCH)
4248  static U8BIT last_progress = 0;
4249 #endif
4250 
4251 
4252  FUNCTION_START(ACTL_GetSearchProgress);
4253 
4254  switch (current_search_type)
4255  {
4256  case SEARCH_TYPE_SERVICE_FREQ:
4257  if (signal_type_required == SIGNAL_QPSK)
4258  {
4259  if ((num = GetNumSatSearchIds()) == 0)
4260  {
4261  progress = 0;
4262  }
4263  else
4264  {
4265  progress = (search_list_id * 100) / num;
4266  }
4267 #ifdef DEBUG_SERVICE_SEARCH
4268  if (progress != last_progress)
4269  {
4270  STB_SPDebugWrite("Progress: %u of %u, %u%%", search_list_id, num, progress);
4271  last_progress = progress;
4272  }
4273 #endif
4274  }
4275  else
4276  {
4277  if ((num = ACTL_GetNumRfChanArrayEntries(signal_type_required)) == 0)
4278  {
4279  progress = 0;
4280  }
4281  else
4282  {
4283  progress = (search_list_id * 100) / num;
4284  }
4285 #ifdef DEBUG_SERVICE_SEARCH
4286  if (progress != last_progress)
4287  {
4288  STB_SPDebugWrite("Progress: %u of %u, %u%%", search_list_id, num, progress);
4289  last_progress = progress;
4290  }
4291 #endif
4292  }
4293  break;
4294 
4295  case SEARCH_TYPE_SERVICE_NETWORK:
4296  case SEARCH_TYPE_MANUAL_NETWORK:
4297  if ((num = ADB_GetNumTransports()) == 0)
4298  {
4299  progress = 0;
4300  }
4301  else
4302  {
4303  progress = (search_list_id * 100) / num;
4304  }
4305 #ifdef DEBUG_SERVICE_SEARCH
4306  if (progress != last_progress)
4307  {
4308  STB_SPDebugWrite("Progress: %u of %u, %u%%", search_list_id, num, progress);
4309  last_progress = progress;
4310  }
4311 #endif
4312  break;
4313 
4314  case SEARCH_TYPE_TOT:
4315  case SEARCH_TYPE_STARTUP:
4316  case SEARCH_TYPE_SSU:
4317  if (search_num_transports == 0)
4318  {
4319  progress = 0;
4320  }
4321  else
4322  {
4323  progress = (search_list_id * 100) / search_num_transports;
4324  }
4325 #if defined(DEBUG_TOT_SEARCH) || defined(DEBUG_SSU_SEARCH) || defined(DEBUG_STARTUP_SEARCH)
4326  if (progress != last_progress)
4327  {
4328  STB_SPDebugWrite("Progress: %u of %u, %u%%", search_list_id, search_num_transports, progress);
4329  last_progress = progress;
4330  }
4331 #endif
4332  break;
4333 
4334  default:
4335  progress = 0;
4336  break;
4337  }
4338 
4339  FUNCTION_FINISH(ACTL_GetSearchProgress);
4340 
4341  return(progress);
4342 }
4343 
4345 {
4346  return search_path;
4347 }
4348 
4357 BOOLEAN ACTL_StartManualSearchById(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT chan_id, BOOLEAN start_search)
4358 {
4359  BOOLEAN retval;
4360  U16BIT num_chans;
4361  E_ACTL_SI_SRCH_REQD si_type;
4362 
4363  FUNCTION_START(ACTL_StartManualSearchById);
4364 
4365  retval = FALSE;
4366 
4367  num_chans = ACTL_GetNumRfChanArrayEntries(tuner_type);
4368  if (chan_id < num_chans)
4369  {
4370  if (search_path == INVALID_RES_ID)
4371  {
4372  /* Path to be used for the search doesn't require decoders */
4373  search_path = STB_DPAcquireTunerPath(tuner_type, NULL, NULL, RES_OWNER_DVB, DP_PRIORITY_LOW,
4374  FALSE, FALSE);
4375  }
4376  if (search_path != INVALID_RES_ID)
4377  {
4378  if (start_search)
4379  {
4380  si_type = ACTL_SI_CHANNEL_SEARCH;
4381  current_search_type = SEARCH_TYPE_MANUAL_FREQ;
4382  required_search_type = SEARCH_TYPE_MANUAL_FREQ;
4383  if (tuner_type == SIGNAL_COFDM)
4384  {
4385  terr_hierarchy = TUNE_THIERARCHY_NONE;
4386  t2_plp_id = 0;
4387  STB_DPSetTerrPLP(search_path, t2_plp_id);
4388  }
4389  }
4390  else
4391  {
4392  si_type = ACTL_SI_NO_SEARCH;
4393  current_search_type = SEARCH_TYPE_NOSEARCH;
4394  required_search_type = SEARCH_TYPE_NOSEARCH;
4395  }
4396 
4397  signal_type_required = tuner_type;
4398  search_list_id = chan_id;
4399 
4400  retval = ACTL_TuneToRfChanArrayEntry(search_path, chan_id, si_type, FALSE);
4401  if (!retval)
4402  {
4403  current_search_type = SEARCH_TYPE_NOSEARCH;
4404  required_search_type = SEARCH_TYPE_NOSEARCH;
4405 
4406  STB_DPReleasePath(search_path, RES_OWNER_DVB);
4407  search_path = INVALID_RES_ID;
4408  }
4409  }
4410  }
4411 
4412  FUNCTION_FINISH(ACTL_StartManualSearchById);
4413 
4414  return(retval);
4415 }
4416 
4425 BOOLEAN ACTL_StartManualSearch(E_STB_DP_SIGNAL_TYPE tuner_type,
4426  S_MANUAL_TUNING_PARAMS *tuning_params, E_ACTL_SEARCH_TYPE type)
4427 {
4428  BOOLEAN retval;
4429 
4430  FUNCTION_START(ACTL_StartManualSearch);
4431 
4432  retval = FALSE;
4433 
4434 #ifdef DEBUG_SERVICE_SEARCH
4435  STB_SPDebugWrite("%s(%u, %u)", __FUNCTION__, tuner_type, type);
4436 #endif
4437 
4438  if (tuning_params != NULL)
4439  {
4440  /* Path to be used for the search doesn't require decoders */
4441  search_path = STB_DPAcquireTunerPath(tuner_type, NULL, NULL, RES_OWNER_DVB, DP_PRIORITY_LOW,
4442  FALSE, FALSE);
4443  if (search_path != INVALID_RES_ID)
4444  {
4446 
4447  switch (tuner_type)
4448  {
4449  case SIGNAL_COFDM:
4450  terr_hierarchy = TUNE_THIERARCHY_NONE;
4451  t2_plp_id = tuning_params->u.terr.plp_id;
4452  break;
4453  case SIGNAL_QAM:
4454  break;
4455  case SIGNAL_ANALOG:
4456  break;
4457  case SIGNAL_QPSK:
4458  break;
4459  default:
4460  tuner_type = SIGNAL_NONE;
4461  break;
4462  }
4463 
4464  signal_type_required = tuner_type;
4465 
4466  if (signal_type_required != SIGNAL_NONE)
4467  {
4468  if (type == ACTL_FREQ_SEARCH)
4469  {
4470  current_search_type = SEARCH_TYPE_MANUAL_FREQ;
4471  required_search_type = SEARCH_TYPE_MANUAL_FREQ;
4472  }
4473  else
4474  {
4475  current_search_type = SEARCH_TYPE_MANUAL_NETWORK;
4476  required_search_type = SEARCH_TYPE_MANUAL_NETWORK;
4477  }
4478 
4479  /* Start the search */
4480  search_list_id = 0;
4481  retval = ACTL_TuneToUserDefinedParams(search_path, tuning_params, ACTL_SI_CHANNEL_SEARCH, FALSE);
4482 
4483  if (retval)
4484  {
4485  if (ASTE_InStandby())
4486  {
4487  DBG_STDBY(("Starting manual service search"));
4489 
4490  /* Save the date the search is being performed and the standby state */
4491  APP_NvmSave(LAST_CHAN_SRCH_NVM, DHMS_DATE(STB_GCNowDHMSLocal()), FALSE);
4492 
4493  DBG_STDBY(("Setting STANDBY_STATE_NVM=STDBY_UPDATE_SEARCH"));
4494  APP_NvmSave(STANDBY_STATE_NVM, STDBY_UPDATE_SEARCH, TRUE);
4495  }
4496  else
4497  {
4498  /* Send event to update the UI */
4499  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
4500  }
4501  }
4502  else
4503  {
4504  current_search_type = SEARCH_TYPE_NOSEARCH;
4505  required_search_type = SEARCH_TYPE_NOSEARCH;
4506  EndSearch(search_path);
4507  search_path = INVALID_RES_ID;
4508  }
4509  }
4510  }
4511  }
4512 
4513  FUNCTION_FINISH(ACTL_StartManualSearch);
4514 
4515  return(retval);
4516 }
4517 
4523 {
4524  FUNCTION_START(ACTL_FinishManualSearch);
4525 
4526  if (search_path != INVALID_RES_ID)
4527  {
4528  ACTL_TuneOff(search_path);
4529  STB_DPReleasePath(search_path, RES_OWNER_DVB);
4530  search_path = INVALID_RES_ID;
4531  }
4532 
4533 #ifdef INTEGRATE_HBBTV
4535 #endif
4536 
4537  APP_NvmSave(FIRST_BOOT_NVM, (U32BIT)FALSE, TRUE);
4538 
4539  required_search_type = SEARCH_TYPE_NOSEARCH;
4540  current_search_type = SEARCH_TYPE_NOSEARCH;
4541 
4542  /* Re-enable the CI module */
4544 
4545  if (ASTE_InStandby())
4546  {
4548  }
4549 
4550  FUNCTION_FINISH(ACTL_FinishManualSearch);
4551 }
4552 
4553 #ifdef INCLUDE_OTA_SSU
4554 
4567 BOOLEAN ACTL_StartOTAUpdate(U8BIT path, void *transport, U16BIT serv_id,
4568  F_SSU_VERSION_CALLBACK version_callback)
4569 {
4570  BOOLEAN retval;
4571  U8BIT ota_path;
4572 
4573  FUNCTION_START(ACTL_StartOTAUpdate);
4574 
4575  retval = FALSE;
4576 
4577  ota_settings.ota_started = FALSE;
4578  ota_settings.ota_path = INVALID_RES_ID;
4579 
4580  DBG_SSU(("%s(path=%u, ts=%p, serv=0x%04x, cb=%p)", __FUNCTION__, path, transport, serv_id,
4581  version_callback));
4582 
4583  if (path == INVALID_RES_ID)
4584  {
4585  path = STB_DPGetLivePath();
4586  }
4587 
4588  if ((path == INVALID_RES_ID) || (ADB_GetTunedTransport(path) != transport))
4589  {
4590  /* Need to tune to the given transport */
4591  ota_settings.ota_onet_id = ADB_GetTransportOriginalNetworkId(transport);
4592  ota_settings.ota_tran_id = ADB_GetTransportTid(transport);
4593  ota_settings.ota_serv_id = serv_id;
4594  ota_settings.version_cb = version_callback;
4595 
4596  if (current_search_type == SEARCH_TYPE_NOSEARCH)
4597  {
4598  current_search_type = SEARCH_TYPE_OTA_UPDATE;
4599  }
4600 
4601  if (path != INVALID_RES_ID)
4602  {
4603  /* The path will be retuned so stop it first */
4604  ACTL_TuneOff(path);
4605  }
4606 
4607  ota_path = ACTL_TuneToTransport(path, NULL, transport, ACTL_SI_NO_SEARCH, TRUE);
4608  if (ota_path != INVALID_RES_ID)
4609  {
4610  if (ota_path != path)
4611  {
4612  /* Only save the decode path if it's been acquired specifically for the OTA */
4613  ota_settings.ota_path = ota_path;
4614  }
4615 
4616  DBG_SSU(("%s: Tuning to transport 0x%04x/%04x, path=%u", __FUNCTION__,
4617  ADB_GetTransportOriginalNetworkId(transport), ADB_GetTransportTid(transport), ota_path));
4618 
4619  retval = TRUE;
4620  }
4621  else
4622  {
4623  DBG_SSU(("%s: Failed to tune to transport 0x%04x/%04x", __FUNCTION__,
4624  ADB_GetTransportOriginalNetworkId(transport), ADB_GetTransportTid(transport)));
4625 
4626  if (current_search_type == SEARCH_TYPE_OTA_UPDATE)
4627  {
4628  current_search_type = SEARCH_TYPE_NOSEARCH;
4629  }
4630  }
4631  }
4632  else
4633  {
4634  /* Already tuned to the correct transport so the search for the OTA can be started */
4635  if (current_search_type == SEARCH_TYPE_NOSEARCH)
4636  {
4637  current_search_type = SEARCH_TYPE_OTA_UPDATE;
4638  }
4639 
4640  retval = STB_OTAStartLoader(path, ADB_GetTransportOriginalNetworkId(transport),
4641  ADB_GetTransportTid(transport), serv_id, ADB_INVALID_DVB_ID, version_callback);
4642  if (!retval && (current_search_type == SEARCH_TYPE_OTA_UPDATE))
4643  {
4644  current_search_type = SEARCH_TYPE_NOSEARCH;
4645  }
4646 
4647  DBG_SSU(("%s: Already tuned to transport, OTA search %s", __FUNCTION__,
4648  (retval ? "started" : "failed")));
4649 
4650  ota_settings.ota_started = retval;
4651  }
4652 
4653  FUNCTION_FINISH(ACTL_StartOTAUpdate);
4654 
4655  return(retval);
4656 }
4657 
4663 void ACTL_ContinueOTAUpdate(BOOLEAN do_update)
4664 {
4665  FUNCTION_START(ACTL_ContinueOTAUpdate);
4666 
4667  DBG_SSU(("ACTL_ContinueOTAUpdate(%s)", do_update ? "TRUE" : "FALSE"));
4668 
4669  //ASI_RefuseSSU(!do_update);
4670  STB_OTAContinueDownload(do_update);
4671 
4672  FUNCTION_FINISH(ACTL_ContinueOTAUpdate);
4673 }
4674 
4678 void ACTL_StopOTAUpdate(void)
4679 {
4680  FUNCTION_START(ACTL_StopOTAUpdate);
4681 
4682  DBG_SSU(("ACTL_StopOTAUpdate"));
4683 
4685 
4686  if (current_search_type == SEARCH_TYPE_OTA_UPDATE)
4687  {
4688  current_search_type = SEARCH_TYPE_NOSEARCH;
4689  }
4690 
4691  ota_settings.ota_onet_id = ADB_INVALID_DVB_ID;
4692  ota_settings.ota_tran_id = ADB_INVALID_DVB_ID;
4693  ota_settings.ota_serv_id = ADB_INVALID_DVB_ID;
4694  ota_settings.ota_started = FALSE;
4695 
4696  FUNCTION_FINISH(ACTL_StopOTAUpdate);
4697 }
4698 #endif /* INCLUDE_OTA_SSU */
4699 
4704 void ACTL_SetMhegAVControl(BOOLEAN control)
4705 {
4706  FUNCTION_START(ACTL_SetMhegAVControl);
4707  external_control = control;
4708  FUNCTION_FINISH(ACTL_SetMhegAVControl);
4709 }
4710 
4717 {
4718  if (func == NULL)
4719  {
4720  GetSubtitlePidFunc = ADB_ServiceGetSubtitlePid;
4721  }
4722  else
4723  {
4724  GetSubtitlePidFunc = func;
4725  }
4726 }
4727 
4732 void ACTL_SetVolumeAdjustment(S8BIT scaling)
4733 {
4734  FUNCTION_START(ACTL_SetVolumeAdjustment);
4735 
4736  volume_scaling = scaling;
4737  if(volume_scaling < -100)
4738  volume_scaling = -100;
4739  if(volume_scaling > 100)
4740  volume_scaling = 100;
4741 
4742  /* update output volume, given new scaling */
4743  AVSetAudioVolumes(FALSE);
4744 
4745  FUNCTION_FINISH(ACTL_SetVolumeAdjustment);
4746 }
4747 
4752 U8BIT ACTL_GetVolume(void)
4753 {
4754  FUNCTION_START(ACTL_GetVolume);
4755  FUNCTION_FINISH(ACTL_GetVolume);
4756  return(audio_volume);
4757 }
4758 
4764 U8BIT ACTL_SetVolume(U8BIT volume)
4765 {
4766  S8BIT volume_change;
4767  U8BIT new_volume;
4768 
4769  FUNCTION_START(ACTL_SetVolume);
4770 
4771  volume_change = (S8BIT)volume - audio_volume;
4772  if (volume_change != 0)
4773  {
4774  new_volume = ACTL_ChangeVolume(volume_change);
4775  }
4776  else
4777  {
4778  new_volume = audio_volume;
4779  }
4780 
4781  FUNCTION_FINISH(ACTL_SetVolume);
4782 
4783  return(new_volume);
4784 }
4785 
4791 U8BIT ACTL_ChangeVolume(S8BIT volume_change)
4792 {
4793  FUNCTION_START(ACTL_ChangeVolume);
4794 
4795  if (volume_change != 0)
4796  {
4797  /* Increase volume */
4798  if (audio_muted)
4799  {
4800  audio_muted = FALSE;
4801  AVSetAudioVolumes(FALSE);
4802  }
4803  else
4804  {
4805  if (volume_change > 0)
4806  {
4807  audio_volume += volume_change;
4808  if (audio_volume > 100)
4809  {
4810  audio_volume = 100;
4811  }
4812  }
4813  else
4814  {
4815  if (audio_volume < -volume_change)
4816  {
4817  audio_volume = 0;
4818  }
4819  else
4820  {
4821  audio_volume += volume_change;
4822  }
4823  }
4824 
4825  AVSetAudioVolumes(TRUE);
4826  }
4827  }
4828 
4829  FUNCTION_FINISH(ACTL_ChangeVolume);
4830 
4831  return(audio_volume);
4832 }
4833 
4838 void ACTL_SetMute(BOOLEAN mute)
4839 {
4840  FUNCTION_START(ACTL_SetMute);
4841 
4842  if (mute)
4843  {
4844  audio_muted = TRUE;
4845  }
4846  else
4847  {
4848  audio_muted = FALSE;
4849  }
4850  AVSetAudioVolumes(FALSE);
4851 
4852  FUNCTION_FINISH(ACTL_SetMute);
4853 }
4854 
4859 BOOLEAN ACTL_ToggleMute(void)
4860 {
4861  FUNCTION_START(ACTL_ToggleMute);
4862 
4863  if (audio_muted)
4864  {
4865  audio_muted = FALSE;
4866  }
4867  else
4868  {
4869  audio_muted = TRUE;
4870  }
4871  AVSetAudioVolumes(FALSE);
4872 
4873  FUNCTION_FINISH(ACTL_ToggleMute);
4874 
4875  return(audio_muted);
4876 }
4877 
4882 BOOLEAN ACTL_IsMuted(void)
4883 {
4884  FUNCTION_START(ACTL_IsMuted);
4885  FUNCTION_FINISH(ACTL_IsMuted);
4886  return(audio_muted);
4887 }
4888 
4897 U8BIT ACTL_AcquirePathForService(void *s_ptr, BOOLEAN with_decoders, BOOLEAN for_recording,
4898  S_ACTL_OWNER_INFO *owner_info)
4899 {
4900  U8BIT path;
4901 
4902  FUNCTION_START(ACTL_AcquirePathForService);
4903 
4904  path = AcquirePathForService(s_ptr, with_decoders, for_recording, owner_info);
4905 
4906  FUNCTION_FINISH(ACTL_AcquirePathForService);
4907 
4908  return(path);
4909 }
4910 
4916 void ACTL_ReleaseLivePathForService(void *s_ptr, E_STB_DP_RES_OWNER owner)
4917 {
4918  U8BIT path;
4919 
4920  FUNCTION_START(ACTL_ReleaseLivePathForService);
4921 
4922  for (path = 0; path < STB_DPGetNumPaths(); path++)
4923  {
4924  if (STB_DPIsLivePath(path) && (STB_DPGetTunedService(path) == s_ptr))
4925  {
4926  ACTL_TuneOff(path);
4927  STB_DPReleasePath(path, owner);
4928  break;
4929  }
4930  }
4931 
4932  FUNCTION_FINISH(ACTL_ReleaseLivePathForService);
4933 }
4934 
4941 BOOLEAN ACTL_ReleasePath(U8BIT path)
4942 {
4943  BOOLEAN retval;
4944 
4945  FUNCTION_START(ACTL_ReleasePath);
4946 
4947 #ifdef COMMON_INTERFACE
4948  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS))
4949  {
4950  void *owner_data;
4951  U32BIT data_size;
4952  if ((owner_data = STB_DPGetOwnerData(path, &data_size)) != NULL)
4953  {
4954  retval = ACI_AskRelease(*(U32BIT *)owner_data);
4955  }
4956  else
4957  {
4958  retval = FALSE;
4959  }
4960  }
4961  else
4962 #endif
4963  {
4964  retval = STB_DPReleasePath(path, RES_OWNER_NONE);
4965  }
4966 
4967  FUNCTION_FINISH(ACTL_ReleasePath);
4968 
4969  return(retval);
4970 }
4971 
4978 BOOLEAN ACTL_AcquirePathOwnership(U8BIT path, S_ACTL_OWNER_INFO *owner_info)
4979 {
4980  BOOLEAN retval;
4981 
4982  FUNCTION_START(ACTL_AcquirePathOwnership);
4983 
4984  retval = FALSE;
4985 
4986  if (STB_DPIsOwnedBy(path, owner_info->owner))
4987  {
4988  /* Path is already owned by the module */
4989  retval = TRUE;
4990  }
4991  else if (STB_DPIsOwnedBy(path, RES_OWNER_NONE))
4992  {
4993  /* Ownership of the path can be taken, so set the owner and save any owner data */
4994  STB_DPSetOwner(path, owner_info->owner);
4995  STB_DPSetOwnerData(path, owner_info->data, owner_info->data_size);
4996  retval = TRUE;
4997  }
4998 
4999  FUNCTION_FINISH(ACTL_AcquirePathOwnership);
5000 
5001  return(retval);
5002 }
5003 
5011 BOOLEAN ACTL_ReleasePathOwnership(U8BIT path, E_STB_DP_RES_OWNER owner)
5012 {
5013  BOOLEAN retval;
5014 
5015  FUNCTION_START(ACTL_ReleasePathOwnership);
5016 
5017  retval = FALSE;
5018 
5019  if (STB_DPIsOwnedBy(path, RES_OWNER_NONE))
5020  {
5021  /* Path doesn't have an owner */
5022  retval = TRUE;
5023  }
5024  else if (STB_DPIsOwnedBy(path, owner))
5025  {
5026  /* The module does own the path so is allowed to release its ownership of it */
5027  STB_DPSetOwner(path, RES_OWNER_NONE);
5028  STB_DPSetOwnerData(path, NULL, 0);
5029  retval = TRUE;
5030  }
5031 
5032  FUNCTION_FINISH(ACTL_ReleasePathOwnership);
5033 
5034  return(retval);
5035 }
5036 
5044 BOOLEAN ACTL_CanServiceBeViewed(void *s_ptr)
5045 {
5046  void *t_ptr;
5047  BOOLEAN viewable;
5048 
5049  FUNCTION_START(ACTL_CanServiceBeViewed);
5050 
5051  viewable = FALSE;
5052 
5053  t_ptr = ADB_GetServiceTransportPtr(s_ptr);
5054  if (t_ptr != NULL)
5055  {
5056  viewable = STB_DPCanTuneTo(ADB_GetTransportSignalType(t_ptr), s_ptr, t_ptr);
5057  }
5058 
5059  FUNCTION_FINISH(ACTL_CanServiceBeViewed);
5060 
5061  return(viewable);
5062 }
5063 
5070 void ACTL_SetStandbyGracePeriod(U16BIT num_seconds)
5071 {
5072  FUNCTION_START(ACTL_SetStandbyGracePeriod);
5073  standby_grace_timeout = num_seconds;
5074  FUNCTION_FINISH(ACTL_SetStandbyGracePeriod);
5075 }
5076 
5082 {
5083  U8BIT path, num_paths;
5084  void *s_ptr;
5085  U32BIT recording_handle;
5086  U8BIT hours, mins, secs;
5087  U16BIT grace_timeout;
5088  U32DHMS enter_standby_time;
5089 
5090  FUNCTION_START(ACTL_EnterStandby);
5091 
5092  DBG_STDBY(("%s", __FUNCTION__));
5093 
5095 
5097  {
5098  /* Hide video before entering standby */
5099  STB_AVBlankVideo(0, TRUE);
5100 
5101  /* Stop timeshift before entering standby */
5102  APVR_StopPauseRecord(FALSE);
5103  }
5104 
5105  /* Turn the live path off if it isn't being used for recording */
5106  if ((path = STB_DPGetLivePath()) != INVALID_RES_ID)
5107  {
5108  /* Save the current live service LCN to nvm */
5109  if ((s_ptr = ADB_GetTunedService(path)) != NULL)
5110  {
5111  DBG_STDBY(("ACTL_EnterStandby: saving service to NVM... LCN=%d", ADB_GetServiceLcn(s_ptr)));
5112  APP_NvmSave(LIVE_SERVICE_LCN_NVM, ADB_GetServiceLcn(s_ptr), TRUE);
5113  }
5114 
5115  if (!STB_DPIsRecordingPath(path))
5116  {
5117  ACTL_TuneOff(path);
5118  }
5119 
5120  STB_DPReleasePath(path, RES_OWNER_NONE);
5121  }
5122 
5123  /* This function can be called many times without ACTL_LeaveStandby being called, such as
5124  * when a recording completes whilst in standby, so release the original path that was
5125  * acquired to monitor the SI for that recording as another one will be acquired if
5126  * another recording is due to start soon */
5127  if ((standby_path != INVALID_RES_ID) && !APVR_GetRecordingHandle(standby_path, &recording_handle))
5128  {
5129  /* Release the decode path that was acquired when entering standby */
5130  STB_DPReleasePath(standby_path, RES_OWNER_NONE);
5131  }
5132 
5133  standby_path = INVALID_RES_ID;
5134 
5135  ACTL_SetStandbyState(TRUE);
5136 
5138  {
5139  DBG_STDBY(("Recording in progress, entering active standby"));
5140  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_RECORDING, TRUE);
5141  ASTE_EnterStandby(TRUE);
5142  STB_HWSetStandbyState(HW_STANDBY_ACTIVE);
5143  }
5144  else
5145  {
5146  ASTE_EnterStandby(FALSE);
5147 
5148  /* Check whether standby should be entered; it may be time to start a background search,
5149  * or a recording may be starting soon */
5150  if (EnterStandby(&s_ptr))
5151  {
5152  /* Save database before going into standby as this may result in a power off */
5153  ADB_SaveDatabase();
5154 
5155  /* Save the EIT data, if supported by the database being used */
5157 
5158  /* Turn off all tuners and release all paths, whatever they're being used for */
5159  num_paths = STB_DPGetNumPaths();
5160 
5161  for (path = 0; path < num_paths; path++)
5162  {
5163  ACTL_TuneOff(path);
5164  }
5165 
5167 
5168 #ifdef COMMON_INTERFACE
5169  hours = standby_grace_timeout / 3600;
5170  mins = (standby_grace_timeout % 3600) / 60;
5171  secs = standby_grace_timeout % 60;
5172  start_standby_time = STB_GCCalculateDHMS(STB_GCNowDHMSGmt(),
5173  STB_GCCreateDHMS(0, hours, mins, secs), CALC_ADD);
5174 
5175  if (STB_CIStartPowerDown(CIPowerDownReadyCallback))
5176  {
5177  /* according to CI+ 1.4, must have at least 30 seconds */
5178  grace_timeout = (standby_grace_timeout > 30)? standby_grace_timeout : 30;
5179  }
5180  else
5181  {
5182  grace_timeout = standby_grace_timeout;
5183  }
5184 #else
5185  grace_timeout = standby_grace_timeout;
5186 #endif
5187  if (grace_timeout != 0)
5188  {
5189  /* Create a private timer for the standby grace period, which is defined in seconds,
5190  * and enter the active standby state until the grace period ends */
5191  hours = grace_timeout / 3600;
5192  mins = (grace_timeout % 3600) / 60;
5193  secs = grace_timeout % 60;
5194 
5195  DBG_STDBY(("Starting standby grace period of %02u:%02u:%02u", hours, mins, secs));
5196 
5197  enter_standby_time = STB_GCCalculateDHMS(STB_GCNowDHMSGmt(),
5198  STB_GCCreateDHMS(0, hours, mins, secs), CALC_ADD);
5199 
5200  standby_grace_timer = CreateTimer(enter_standby_time);
5201 
5202  STB_HWSetStandbyState(HW_STANDBY_ACTIVE);
5203  }
5204  else
5205  {
5206  if ((BOOLEAN)APP_NvmRead(STANDBY_POWERSAVE_NVM))
5207  {
5208  /* Put box into low-power standby mode */
5209  DBG_STDBY(("Entering low power standby"));
5210  STB_HWSetStandbyState(HW_STANDBY_LOWPOWER);
5211  }
5212  else
5213  {
5214  /* Nothing is being started so go into the lowest active standby state */
5215  DBG_STDBY(("Entering passive standby"));
5216  STB_HWSetStandbyState(HW_STANDBY_PASSIVE);
5217  }
5218  }
5219  }
5220  else if (s_ptr != NULL)
5221  {
5222  /* A service to be recorded has been returned, so tune to it to start monitoring the SI */
5223  if ((standby_path = AcquirePathForService(s_ptr, FALSE, FALSE, NULL)) != INVALID_RES_ID)
5224  {
5225  ACTL_TuneToService(standby_path, NULL, s_ptr, FALSE, TRUE);
5226  }
5227 
5228  /* Entering standby but just with the outputs turned off */
5229  DBG_STDBY(("Recording due to start soon, entering active standby"));
5230  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_WAKE_FOR_RECORDING, TRUE);
5231  STB_HWSetStandbyState(HW_STANDBY_ACTIVE);
5232  }
5233  else
5234  {
5235  /* A background search has been requested so just go into active standby */
5236  DBG_STDBY(("Background search due to start, entering active standby"));
5237  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_WAKE_FOR_SEARCH, TRUE);
5238  STB_HWSetStandbyState(HW_STANDBY_ACTIVE);
5239  }
5240  }
5241 
5242  FUNCTION_FINISH(ACTL_EnterStandby);
5243 }
5244 
5252 void ACTL_LeaveStandby(void *s_ptr, BOOLEAN tune_to_service)
5253 {
5254  U16BIT lcn;
5255  U16BIT num_services;
5256  void **slist;
5257  U8BIT path;
5258  U32BIT recording_handle;
5259 
5260  FUNCTION_START(ACTL_LeaveStandby);
5261 
5262  DBG_STDBY(("%s(%p, tune_to_service=%u)", __FUNCTION__, s_ptr, tune_to_service));
5263 
5265 
5266  /* May have to do something if searches are being performed when leaving standby */
5267  if (required_search_type != SEARCH_TYPE_NOSEARCH)
5268  {
5269  switch (required_search_type)
5270  {
5271  case SEARCH_TYPE_SERVICE_FREQ:
5272  case SEARCH_TYPE_SERVICE_NETWORK:
5273  /* Stop the search but save the results so far */
5275  ADB_FinaliseDatabaseAfterSearch(TRUE, signal_type_required, NULL, FALSE, FALSE, FALSE);
5276  break;
5277 
5278  case SEARCH_TYPE_EIT_PF:
5279  case SEARCH_TYPE_EIT_SCHED:
5280  case SEARCH_TYPE_EIT_PF_SCHED:
5282  break;
5283 
5284  case SEARCH_TYPE_SSU:
5285  /* The SSU search can't be stopped */
5286  break;
5287 
5288  default:
5289  break;
5290  }
5291  }
5292 
5293  STB_HWSetStandbyState(HW_STANDBY_ON);
5294 
5295  ACTL_SetStandbyState(FALSE);
5296 
5297  STB_PVRSetStandbyState(FALSE);
5298 
5299  /* The screen aspect and/or resolution may have been changed whilst DVBCore was in standby,
5300  * so read the current settings and ensure the stack knows about any changes */
5301  if (ACTL_IsHDMIConnected())
5302  {
5303  ACTL_UpdateVideoMode((E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), TRUE);
5304  }
5305 
5306  /* Volume may have been changed while in standby, so re-read the settings so they can be applied
5307  * when tuning to the first service */
5308  audio_volume = (U8BIT)APP_NvmRead(VOLUME_NVM);
5309  ad_volume = (U8BIT)APP_NvmRead(AD_VOLUME_NVM);
5310 
5311  DBG_STDBY(("Setting STANDBY_STATE_NVM=STDBY_POWER_ON"));
5312  APP_NvmSave(STANDBY_STATE_NVM, STDBY_POWER_ON, TRUE);
5313 
5315 
5316  if (standby_wakeup_timer != INVALID_TIMER_HANDLE)
5317  {
5318  ATMR_DeleteTimer(standby_wakeup_timer);
5319  standby_wakeup_timer = INVALID_TIMER_HANDLE;
5320  }
5321 
5322  if (standby_grace_timer != INVALID_TIMER_HANDLE)
5323  {
5324  ATMR_DeleteTimer(standby_grace_timer);
5325  standby_grace_timer = INVALID_TIMER_HANDLE;
5326  }
5327 
5328  /* Can only tune to a service if there isn't a search still in progress */
5329  if (required_search_type == SEARCH_TYPE_NOSEARCH)
5330  {
5331  if ((s_ptr == NULL) && tune_to_service)
5332  {
5333  /* Restore the last service that was being viewed */
5334  lcn = (U16BIT)APP_NvmRead(LIVE_SERVICE_LCN_NVM);
5335  DBG_STDBY(("ACTL_LeaveStandby: LCN in NVM=%u", lcn));
5336  if ((s_ptr = ADB_FindServiceByLcn(ADB_SERVICE_LIST_ALL, lcn, FALSE)) == NULL)
5337  {
5338  /* Use the first available TV service */
5339  ADB_GetServiceList(ADB_SERVICE_LIST_TV_DATA, &slist, &num_services);
5340  if ((slist != NULL) && (num_services > 0))
5341  {
5342  s_ptr = slist[0];
5343 #ifdef DEBUG_STANDBY
5344  if (s_ptr != NULL)
5345  {
5346  DBG_STDBY(("ACTL_LeaveStandby: LCN not found, use first TV service, serv_id %u",
5347  ADB_GetServiceId(s_ptr)));
5348  }
5349 #endif
5350 
5351  ADB_ReleaseServiceList(slist, num_services);
5352  }
5353 
5354  if (s_ptr == NULL)
5355  {
5356  /* Use the first available service, whatever it is! */
5357  ADB_GetServiceList(ADB_SERVICE_LIST_ALL, &slist, &num_services);
5358  if ((slist != NULL) && (num_services > 0))
5359  {
5360  s_ptr = slist[0];
5361 #ifdef DEBUG_STANDBY
5362  if (s_ptr != NULL)
5363  {
5364  DBG_STDBY(("ACTL_LeaveStandby: LCN not found, use first service, serv_id %u",
5365  ADB_GetServiceId(s_ptr)));
5366  }
5367 #endif
5368  ADB_ReleaseServiceList(slist, num_services);
5369  }
5370  }
5371  }
5372 #ifdef DEBUG_STANDBY
5373  else
5374  {
5375  DBG_STDBY(("ACTL_LeaveStandby: LCN %u found, serv_id %u", lcn, ADB_GetServiceId(s_ptr)));
5376  }
5377 #endif
5378  }
5379 
5380  if ((standby_path != INVALID_RES_ID) && !APVR_GetRecordingHandle(standby_path, &recording_handle))
5381  {
5382  /* Release the decode path that was acquired when entering standby */
5383  STB_DPReleasePath(standby_path, RES_OWNER_NONE);
5384  }
5385 
5386  standby_path = INVALID_RES_ID;
5387 
5388  if (s_ptr != NULL)
5389  {
5390  if (!ACTL_CanServiceBeViewed(s_ptr))
5391  {
5392  /* The service can't be viewed so use the service of the live path, if it exists */
5393  path = STB_DPGetLivePath();
5394  if (path != INVALID_RES_ID)
5395  {
5396  s_ptr = ADB_GetTunedService(path);
5397 #ifdef DEBUG_STANDBY
5398  if (s_ptr != NULL)
5399  {
5400  DBG_STDBY(("%s: can't tune to service so tuning to live service %u", __FUNCTION__,
5401  ADB_GetServiceId(s_ptr)));
5402  }
5403 #endif
5404  }
5405  else
5406  {
5407  /* There's no live path so tune to the first path that's tuned to a service */
5408  for (path = 0, s_ptr = NULL; (path < STB_DPGetNumPaths()) && (s_ptr == NULL); path++)
5409  {
5410  s_ptr = ADB_GetTunedService(path);
5411  }
5412 #ifdef DEBUG_STANDBY
5413  if (s_ptr != NULL)
5414  {
5415  DBG_STDBY(("%s: can't tune to service so tuning to service %u", __FUNCTION__,
5416  ADB_GetServiceId(s_ptr)));
5417  }
5418 #endif
5419  }
5420  }
5421 
5422  if (s_ptr != NULL)
5423  {
5424  ACTL_TuneToService(INVALID_RES_ID, NULL, s_ptr, FALSE, TRUE);
5425  }
5426 #ifdef DEBUG_STANDBY
5427  else
5428  {
5429  DBG_STDBY(("%s: No service to tune to!", __FUNCTION__));
5430  }
5431 #endif
5432  }
5433  }
5434 
5435  FUNCTION_FINISH(ACTL_LeaveStandby);
5436 }
5437 
5444 {
5445  BOOLEAN retval;
5446  U8BIT live_path;
5447  void *tuned_service;
5448 
5449  FUNCTION_START(ACTL_CheckLiveServiceChange);
5450 
5451  retval = FALSE;
5452 
5453  if (((live_path = STB_DPGetLivePath()) != INVALID_RES_ID) && (current_service[live_path] != NULL))
5454  {
5455  tuned_service = ADB_GetTunedService(live_path);
5456 
5457  if (tuned_service != current_service[live_path])
5458  {
5459  /* The live service has been changed, inform the UI */
5460  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_CHANGED, &tuned_service, sizeof(void *));
5461 
5462  /* Update the current service and transport */
5463  current_service[live_path] = tuned_service;
5464  current_transport[live_path] = ADB_GetTunedTransport(live_path);
5465 
5466  retval = TRUE;
5467  }
5468  }
5469 
5470  FUNCTION_FINISH(ACTL_CheckLiveServiceChange);
5471 
5472  return(retval);
5473 }
5474 
5482 BOOLEAN ACTL_SetActiveProfile(void *profile)
5483 {
5484  BOOLEAN retval;
5485  ADB_PROFILE_TYPE type;
5486 #ifdef COMMON_INTERFACE
5487  U16BIT cicam_onet_id;
5488  U32BIT cicam_id;
5489 #endif
5490 
5491  FUNCTION_START(ACTL_SetActiveProfile);
5492 
5493  retval = FALSE;
5494 
5495  if (profile != NULL)
5496  {
5497 #ifdef COMMON_INTERFACE
5498  if (DBDEF_GetCurrentProfileType() == ADB_PROFILE_TYPE_CIPLUS)
5499  {
5500  /* Changing from the current CI+ profile, so need to exit it */
5501  ACI_OperatorExit();
5502  }
5503 #endif
5504 
5505  type = ADB_GetProfileType(profile);
5506  if (type == ADB_PROFILE_TYPE_BROADCAST)
5507  {
5509  retval = TRUE;
5510  }
5511 #ifdef COMMON_INTERFACE
5512  else if (type == ADB_PROFILE_TYPE_CIPLUS)
5513  {
5514  if (ADB_GetProfileModulePresent(profile))
5515  {
5516  /* Send the request to enter the CI+ operator profile */
5517  if (ACI_RequestOperatorStatus(ADB_GetProfileModule(profile)))
5518  {
5519  ADB_GetProfileCAMInfo(profile, &cicam_onet_id, &cicam_id);
5520  DBDEF_SelectCIPlusProfile(cicam_onet_id, cicam_id);
5521  retval = TRUE;
5522  }
5523  }
5524  }
5525 #endif
5526  }
5527 
5528  FUNCTION_FINISH(ACTL_SetActiveProfile);
5529 
5530  return(retval);
5531 }
5532 
5540 E_ACTL_DECODE_CHANGE ACTL_SetupAudioDecoding(U8BIT path, void *s_ptr)
5541 {
5542  E_ACTL_DECODE_CHANGE change;
5543  E_STB_DP_AUDIO_MODE mode;
5544  E_STB_DP_AUDIO_CODEC codec;
5545  ADB_STREAM_TYPE type;
5546  U16BIT pid;
5547  BOOLEAN broadcast_mix;
5548 
5549  FUNCTION_START(ACTL_SetupAudioDecoding);
5550 
5551  change = ACTL_NO_CHANGE;
5554  {
5555  pid = DBDEF_GetReqdAudioPid(s_ptr, &mode, &type);
5556  }
5557  else
5558  {
5559  pid = DBDEF_GetReqdADPid(s_ptr, &mode, &type, &broadcast_mix);
5560  if (broadcast_mix)
5561  {
5562  STB_DPSetADPID(path, 0);
5563  }
5564  else
5565  {
5566  codec = ADB_GetAudioCodecFromStream(type);
5567  if (pid != STB_DPGetADPID(path) || mode != STB_DPGetADMode(path) || codec != STB_DPGetADCodec(path))
5568  {
5569  change |= ACTL_ADESC_CHANGE;
5570  }
5571  STB_DPSetADPID(path, pid);
5572  STB_DPSetADMode(path, mode);
5574  pid = DBDEF_GetReqdAudioPid(s_ptr, &mode, &type);
5575  }
5576  }
5577  //((ADB_SERVICE_REC *)s_ptr)->audio_pid = pid; /* save current audio pid */
5579 
5580  codec = ADB_GetAudioCodecFromStream(type);
5581  if (pid != STB_DPGetAudioPID(path) || mode != STB_DPGetAudioMode(path) || codec != STB_DPGetAudioCodec(path))
5582  {
5583  change |= ACTL_AUDIO_CHANGE;
5584  }
5585  STB_DPSetAudioPID(path, pid);
5586  STB_DPSetAudioMode(path, mode);
5587  STB_DPSetAudioCodec(path, codec);
5588 
5589  STB_DPSetPCRPID(path, ADB_GetServicePCRPid(s_ptr));
5590 
5591  FUNCTION_FINISH(ACTL_SetupAudioDecoding);
5592  return change;
5593 }
5594 
5595 //--------------------------------------------------------------------------------------------------
5596 // local function definitions
5597 //--------------------------------------------------------------------------------------------------
5598 
5611 #if defined(DEBUG_TUNING) || defined(DEBUG_DECODING) || defined(DEBUG_AV_OUTPUT) || defined(DEBUG_MHEG)
5612 static U8BIT* GetEventDebugString(E_ACTL_EVENT_TYPE type, U32BIT event)
5613 {
5614  U8BIT *string;
5615 
5616  if (type == INTERNAL_EVENT)
5617  {
5618  switch (event)
5619  {
5620  case INT_EVENT_INITIALISE: {string = (U8BIT *)"initialise"; break; }
5621  case INT_EVENT_ENABLE: {string = (U8BIT *)"enable"; break; }
5622  case INT_EVENT_DISABLE: {string = (U8BIT *)"disable"; break; }
5623  case INT_EVENT_UPDATE: {string = (U8BIT *)"update"; break; }
5624  case INT_EVENT_RF_CHAN_TUNE_REQD: {string = (U8BIT *)"rf tune"; break; }
5625  case INT_EVENT_TPTR_TUNE_REQD: {string = (U8BIT *)"tp tune"; break; }
5626  case INT_EVENT_USERDEFINED_TUNE_REQD: {string = (U8BIT *)"user tune"; break; }
5627  case INT_EVENT_TUNE_OFF: {string = (U8BIT *)"tune off"; break; }
5628  case INT_EVENT_RESTART_DECODING: {string = (U8BIT *)"restart decode"; break; }
5629  case INT_EVENT_RESTART_AUDIO: {string = (U8BIT *)"restart audio"; break; }
5630  case INT_EVENT_RESTART_SUBTITLES: {string = (U8BIT *)"restart subtitles"; break; }
5631  case INT_EVENT_RELEASE_DECODE_LOCK: {string = (U8BIT *)"release decode lock"; break; }
5632  case INT_EVENT_STANDBY_ON: {string = (U8BIT *)"standby on"; break; }
5633  case INT_EVENT_STANDBY_OFF: {string = (U8BIT *)"standby off"; break; }
5634  case INT_EVENT_STANDBY_VCR_ACTIVE: {string = (U8BIT *)"standby vcr active"; break; }
5635  case INT_EVENT_ALT_AV_ALLOWED: {string = (U8BIT *)"scart allowed"; break; }
5636  case INT_EVENT_ALT_AV_NOT_ALLOWED: {string = (U8BIT *)"scart not allowed"; break; }
5637  case INT_EVENT_ANALOG_TV_ON: {string = (U8BIT *)"analogue tv on"; break; }
5638  case INT_EVENT_ANALOG_TV_OFF: {string = (U8BIT *)"analogue tv off"; break; }
5639  case INT_EVENT_ANALOG_VIDEO_ALLOWED: {string = (U8BIT *)"analogue video allowed"; break; }
5640  case INT_EVENT_ANALOG_VIDEO_NOT_ALLOWED: {string = (U8BIT *)"analogue video not allowed"; break; }
5641  default: {string = (U8BIT *)"unknown internal event"; break; }
5642  }
5643  }
5644  else // i.e. external event
5645  {
5646  switch (event)
5647  {
5648  case STB_EVENT_TUNE_LOCKED: {string = (U8BIT *)"TUNE LOCKED"; break; }
5649  case STB_EVENT_TUNE_NOTLOCKED: {string = (U8BIT *)"TUNE NOT LOCKED"; break; }
5650  case STB_EVENT_TUNE_SIGNAL_DATA_BAD: {string = (U8BIT *)"SIGNAL BAD"; break; }
5651  case STB_EVENT_TUNE_SIGNAL_DATA_OK: {string = (U8BIT *)"SIGNAL OK"; break; }
5652  case STB_EVENT_AUDIO_DECODE_STARTED: {string = (U8BIT *)"AUDIO DECODE STARTED"; break; }
5653  case STB_EVENT_VIDEO_DECODE_STARTED: {string = (U8BIT *)"VIDEO DECODE STARTED"; break; }
5654  case STB_EVENT_AUDIO_DECODE_STOPPED: {string = (U8BIT *)"AUDIO DECODE STOPPED"; break; }
5655  case STB_EVENT_VIDEO_DECODE_STOPPED: {string = (U8BIT *)"VIDEO DECODE STOPPED"; break; }
5656  case STB_EVENT_DECODE_LOCKED: {string = (U8BIT *)"DECODE LOCKED"; break; }
5657 #if 0
5658  case STB_EVENT_SCART_DISCONNECTED: {string = (U8BIT *)"SCART OFF"; break; }
5659  case STB_EVENT_SCART_FORCE: {string = (U8BIT *)"SCART ON"; break; }
5660 #endif
5661  case STB_EVENT_CI_OPEN_MODULE: {string = (U8BIT *)"CI UI ON"; break; }
5662  case STB_EVENT_CI_CLOSE_MODULE: {string = (U8BIT *)"CI UI OFF"; break; }
5663  case APP_EVENT_SERVICE_NOT_RUNNING: {string = (U8BIT *)"SERV NOT RUNNING"; break; }
5664  case APP_EVENT_SERVICE_RUNNING: {string = (U8BIT *)"SERV RUNNING"; break; }
5665  case APP_EVENT_SERVICE_AUDIO_PID_UPDATE: {string = (U8BIT *)"AUDIO PID CHANGE"; break; }
5666  case APP_EVENT_SERVICE_VIDEO_PID_UPDATE: {string = (U8BIT *)"VIDEO PID CHANGE"; break; }
5667  case APP_EVENT_SERVICE_SUBTITLE_UPDATE: {string = (U8BIT *)"SUBTITLE CHANGE"; break; }
5668  case APP_EVENT_SERVICE_SCRAMBLE_CHANGE: {string = (U8BIT *)"SERV SCRAMBLE CHANGE"; break; }
5669  default: {string = (U8BIT *)"unknown external event"; break; }
5670  }
5671  }
5672  return(string);
5673 }
5674 
5675 #endif
5676 
5677 #ifdef COMMON_INTERFACE
5678 
5689 static void AskRelease(U8BIT path, void *s_ptr, S_ACTL_OWNER_INFO *owner_info,
5690  BOOLEAN override_parental_lock, void *t_ptr, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
5691 {
5692  void *owner_data;
5693  U32BIT data_size;
5694 
5695  /* Save the transport to be tuned to if the live path is eventually released */
5696  tuneto_live_service = s_ptr;
5697  decode_lock_override_required = override_parental_lock;
5698  tuneto_live_transport = t_ptr;
5699  tuneto_live_si = reqd_si;
5700  tuneto_relock = relock_on;
5701  tuneto_for_recording = FALSE;
5702  tuneto_owner_info = CopyOwnerInfo(owner_info);
5703 
5704  /* Request the path/tuner to be released */
5705  if ((owner_data = STB_DPGetOwnerData(path, &data_size)) != NULL)
5706  {
5707  ACI_AskRelease(*(U32BIT *)owner_data);
5708  }
5709  else
5710  {
5711  DBGPRINT("Need to ask for path %u to be released by CI+, but there's no owner data!", path);
5712  }
5713 }
5714 
5715 #endif /*COMMON_INTERFACE*/
5716 
5717 /*!**************************************************************************
5718  * @brief Handles the releasing and acquiring of a live path when tuning to a service or transport.
5719  * The path value returned from here may be INVALID_RES_ID if a request has to be made to
5720  * release the existing live path.
5721  * @param s_ptr - service being tuned to, can be NULL if t_ptr isn't NULL
5722  * @param owner - module that will own the path when it's acquired
5723  * @param override_parental_lock - should parental lock be overridden when tuning to a service
5724  * @param t_ptr - transport being tuned to, can be NULL if s_ptr isn't NULL
5725  * @param reqd_si - type of SI search to be started when tuning to a transport
5726  * @param relock_on - should tuner relock be applied when tuning to a transport
5727  * @return live path, if acquired, or INVALID_RES_ID if a path can't be acquired or
5728  * the existing path has been requested to be released.
5729  ****************************************************************************/
5730 static U8BIT AcquireLivePath(void *s_ptr, S_ACTL_OWNER_INFO *owner_info,
5731  BOOLEAN override_parental_lock, void *t_ptr, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
5732 {
5733  E_STB_DP_SIGNAL_TYPE signal_type;
5734  U8BIT path;
5735  E_STB_DP_RES_OWNER owner;
5736 #ifdef COMMON_INTERFACE
5737  BOOLEAN ask_release;
5738 #endif
5739 
5740  FUNCTION_START(AcquireLivePath);
5741 
5742 #ifndef COMMON_INTERFACE
5743  USE_UNWANTED_PARAM(override_parental_lock);
5744  USE_UNWANTED_PARAM(reqd_si);
5745  USE_UNWANTED_PARAM(relock_on);
5746 #endif
5747 
5748  if (owner_info != NULL)
5749  {
5750  owner = owner_info->owner;
5751  }
5752  else
5753  {
5754  owner = RES_OWNER_NONE;
5755  }
5756 
5757  if ((path = STB_DPGetLivePath()) != INVALID_RES_ID)
5758  {
5759  /* Existing live path that needs to be released */
5760  if (STB_DPIsOwnedBy(path, owner) || STB_DPIsOwnedBy(path, RES_OWNER_NONE))
5761  {
5762  /* Live path has no owner or is owned by the module wanting to tune,
5763  * so release the existing live path and acquire a new one */
5764  if (current_service[path] != NULL)
5765  {
5766  ACTL_ReleaseLivePathForService(current_service[path], owner);
5767  }
5768  else
5769  {
5770  STB_DPReleasePath(path, owner);
5771  }
5772 
5773  if (s_ptr != NULL)
5774  {
5775  path = AcquirePathForService(s_ptr, TRUE, FALSE, owner_info);
5776  }
5777  else if (t_ptr != NULL)
5778  {
5779  signal_type = ADB_GetTransportSignalType(t_ptr);
5780  path = STB_DPAcquireTunerPath(signal_type, NULL, t_ptr, owner, DP_PRIORITY_LOW, FALSE, FALSE);
5781 
5782  if ((path != INVALID_RES_ID) && (owner_info != NULL))
5783  {
5784  /* Save any owner data with the new path */
5785  STB_DPSetOwnerData(path, owner_info->data, owner_info->data_size);
5786 
5787 #ifdef COMMON_INTERFACE
5788  if (owner == RES_OWNER_CIPLUS)
5789  {
5790  /* The path needs to include the CI slot of the module making the tuning request */
5791  ACI_UseCiModuleOnPath(path, *(U32BIT *)owner_info->data);
5792  }
5793 #endif
5794  }
5795  }
5796 
5797 #ifdef COMMON_INTERFACE
5798  if ((path == INVALID_RES_ID) && (owner == RES_OWNER_CIPLUS))
5799  {
5800  ACI_TuneReply(path, *(U32BIT *)owner_info->data, CIP_TUNER_BUSY);
5801  }
5802 #endif
5803  }
5804  else
5805  {
5806  /* Live path isn't owned by the module wanting to tune, so need to ask
5807  * for the resource to be released */
5808 #ifdef COMMON_INTERFACE
5809  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS))
5810  {
5811  AskRelease(path, s_ptr, owner_info, override_parental_lock, t_ptr, reqd_si, relock_on);
5812 
5813  /* Clear the path so tuning doesn't start now */
5814  path = INVALID_RES_ID;
5815  }
5816  else
5817 #endif
5818  {
5819  STB_SPDebugWrite("[%s:%d]: Live path needs to be released but has an owner which isn't CI+\n",
5820  __FUNCTION__, __LINE__);
5821  }
5822  }
5823  }
5824  else
5825  {
5826  /* There's no current live path, so can just acquire one */
5827  if (s_ptr != NULL)
5828  {
5829  path = AcquirePathForService(s_ptr, TRUE, FALSE, owner_info);
5830  }
5831  else if (t_ptr != NULL)
5832  {
5833  /* If there is a (non-live) path in use by the requesting owner, release it like for the
5834  live path case */
5835  for (path = 0; path < STB_DPGetNumPaths(); path++)
5836  {
5837  if (STB_DPIsOwnedBy(path, owner) || STB_DPIsOwnedBy(path, RES_OWNER_NONE))
5838  {
5839  STB_DPReleasePath(path, owner);
5840  break;
5841  }
5842  }
5843 
5844  signal_type = ADB_GetTransportSignalType(t_ptr);
5845  path = STB_DPAcquireTunerPath(signal_type, NULL, t_ptr, owner, DP_PRIORITY_LOW, FALSE, FALSE);
5846 
5847  if ((path != INVALID_RES_ID) && (owner_info != NULL))
5848  {
5849  /* Save any owner data with the new path */
5850  STB_DPSetOwnerData(path, owner_info->data, owner_info->data_size);
5851 
5852 #ifdef COMMON_INTERFACE
5853  if (owner == RES_OWNER_CIPLUS)
5854  {
5855  /* The path needs to include the CI slot of the module making the tuning request */
5856  ACI_UseCiModuleOnPath(path, *(U32BIT *)owner_info->data);
5857  }
5858 #endif
5859  }
5860  }
5861 
5862 #ifdef COMMON_INTERFACE
5863  if (path == INVALID_RES_ID)
5864  {
5865  ask_release = FALSE;
5866  for (path = 0; path < STB_DPGetNumPaths(); path++)
5867  {
5868  /* Live path isn't owned by the module wanting to tune, so need to ask
5869  * for the resource to be released */
5870  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS))
5871  {
5872  ask_release = TRUE;
5873  AskRelease(path, s_ptr, owner_info, override_parental_lock, t_ptr, reqd_si,
5874  relock_on);
5875 
5876  /* Clear the path so tuning doesn't start now */
5877  path = INVALID_RES_ID;
5878  break;
5879  }
5880  else
5881 
5882  {
5883  STB_SPDebugWrite("[%s:%d]: Live path needs to be released but has an owner which isn't CI+\n",
5884  __FUNCTION__, __LINE__);
5885  }
5886  }
5887 
5888  if (!ask_release && (owner == RES_OWNER_CIPLUS))
5889  {
5890  /* If CI+ was trying to tune, report the failure */
5891  path = INVALID_RES_ID;
5892  ACI_TuneReply(path, *(U32BIT *)owner_info->data, CIP_TUNER_BUSY);
5893  }
5894  }
5895 #endif
5896  }
5897 
5898  FUNCTION_FINISH(AcquireLivePath);
5899 
5900  return(path);
5901 }
5902 
5903 static U8BIT AcquireRecordingPath(void *s_ptr, S_ACTL_OWNER_INFO *owner_info)
5904 {
5905  void *t_ptr;
5906  E_STB_DP_SIGNAL_TYPE sig_type;
5907  U8BIT path;
5908  E_STB_DP_RES_OWNER owner;
5909  BOOLEAN slot_acquired;
5910 #ifdef COMMON_INTERFACE
5911  void *owner_data;
5912  U32BIT data_size;
5913 #endif
5914  U8BIT *pmt_data;
5915  U16BIT data_len;
5916  U16BIT *ca_ids;
5917  U16BIT num_ca_ids;
5918 
5919  FUNCTION_START(AcquireRecordingPath);
5920 
5921  path = INVALID_RES_ID;
5922 
5923  if (owner_info != NULL)
5924  {
5925  owner = owner_info->owner;
5926  }
5927  else
5928  {
5929  owner = RES_OWNER_NONE;
5930  }
5931 
5932  /* Get the transport for the service to find out what tuner type is required */
5933  t_ptr = ADB_GetServiceTransportPtr(s_ptr);
5934  if (t_ptr != NULL)
5935  {
5936  sig_type = ADB_GetTransportSignalType(t_ptr);
5937 
5938  slot_acquired = FALSE;
5939 
5940  path = STB_DPAcquireTunerPath(sig_type, s_ptr, t_ptr, owner, DP_PRIORITY_HIGH, FALSE, TRUE);
5941  if (path != INVALID_RES_ID)
5942  {
5943  if (owner_info != NULL)
5944  {
5945  /* Save any owner data with the new path */
5946  STB_DPSetOwnerData(path, owner_info->data, owner_info->data_size);
5947  }
5948 
5949 #ifdef COMMON_INTERFACE
5950  slot_acquired = ACI_AcquireCISlotForRecording(path, s_ptr);
5951 #endif
5952  if (!slot_acquired)
5953  {
5954  if ((pmt_data = ADB_GetServicePMTData(s_ptr, &data_len)) != NULL)
5955  {
5956  /* Get the CA system IDs from the PMT */
5957  if ((num_ca_ids = STB_SIGetPmtCaIdDescArray(pmt_data, &ca_ids)) != 0)
5958  {
5959  /* Check whether the CA system needs to be involved in the recording */
5960  if (STB_CADescramblerRequiredForRecording(ca_ids, num_ca_ids))
5961  {
5962  ACA_AcquireCADescrambler(path, s_ptr);
5963  }
5964 
5965  STB_SIReleaseCaIdDescArray(ca_ids, num_ca_ids);
5966  }
5967  }
5968  }
5969 
5970  if (STB_DPIsLivePath(path) && (s_ptr != current_service[path]))
5971  {
5972  /* The live service has been changed, inform the UI */
5973  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_CHANGED, &s_ptr, sizeof(void *));
5974  }
5975  }
5976  else
5977  {
5978  /* No path available for recording. The live path would have been taken if it was
5979  * available, but it hasn't, so it is probably owned by another module */
5980  if ((path = STB_DPGetLivePath()) != INVALID_RES_ID)
5981  {
5982 #ifdef COMMON_INTERFACE
5983  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS))
5984  {
5985  /* Save the service to be tuned to if the live path is eventually released */
5986  tuneto_live_service = s_ptr;
5987  decode_lock_override_required = FALSE;
5988  tuneto_live_transport = NULL;
5989  tuneto_for_recording = TRUE;
5990  tuneto_owner_info = CopyOwnerInfo(owner_info);
5991 
5992  /* Request the path/tuner to be released */
5993  if ((owner_data = STB_DPGetOwnerData(path, &data_size)) != NULL)
5994  {
5995  ACI_AskRelease(*(U32BIT *)owner_data);
5996  }
5997  else
5998  {
5999  STB_SPDebugWrite("[%s:%d]: Need to ask for path %u to be released by CI+, but there's no owner data!",
6000  __FUNCTION__, __LINE__, path);
6001  }
6002 
6003  /* Clear the path so tuning doesn't start now */
6004  path = INVALID_RES_ID;
6005  }
6006  else
6007 #endif
6008  {
6009  path = INVALID_RES_ID;
6010  STB_SPDebugWrite("[%s:%d]: Live path needs to be released but has an owner which isn't CI+\n",
6011  __FUNCTION__, __LINE__);
6012  }
6013  }
6014  else
6015  {
6016  STB_SPDebugWrite("[%s:%d]: No live path but can't acquire a recording path!\n", __FUNCTION__, __LINE__);
6017  }
6018  }
6019  }
6020 
6021  FUNCTION_FINISH(AcquireRecordingPath);
6022 
6023  return(path);
6024 }
6025 
6026 #ifdef COMMON_INTERFACE
6027 static S_ACTL_OWNER_INFO* CopyOwnerInfo(S_ACTL_OWNER_INFO *owner_info)
6028 {
6029  S_ACTL_OWNER_INFO *copy;
6030 
6031  FUNCTION_START(CopyOwnerInfo);
6032 
6033  if (owner_info != NULL)
6034  {
6035  if ((copy = STB_AppGetMemory(sizeof(S_ACTL_OWNER_INFO))) != NULL)
6036  {
6037  copy->owner = owner_info->owner;
6038  copy->data = NULL;
6039  copy->data_size = 0;
6040 
6041  if ((owner_info->data != NULL) && (owner_info->data_size > 0))
6042  {
6043  if ((copy->data = STB_AppGetMemory(owner_info->data_size)) != NULL)
6044  {
6045  memcpy(copy->data, owner_info->data, owner_info->data_size);
6046  copy->data_size = owner_info->data_size;
6047  }
6048  }
6049  }
6050  }
6051  else
6052  {
6053  copy = NULL;
6054  }
6055 
6056  FUNCTION_FINISH(CopyOwnerInfo);
6057 
6058  return(copy);
6059 }
6060 
6061 #endif
6062 
6076 static void SetupForTuning(U8BIT path, U32BIT event)
6077 {
6078  U32BIT country_code;
6079  ACFG_ANA_RF_CHANNEL_DATA *ana_channel_table;
6080  ACFG_TER_RF_CHANNEL_DATA *ter_channel_table;
6081  ACFG_CAB_RF_CHANNEL_DATA *cab_channel_table;
6082  U16BIT num_rf_chans;
6083  S_MANUAL_TUNING_PARAMS tuning_params;
6084  U8BIT num_freqs;
6085  U32BIT *additional_freqs;
6086  BOOLEAN success;
6087 
6088  FUNCTION_START(SetupForTuning);
6089 
6090  if (event == INT_EVENT_RF_CHAN_TUNE_REQD)
6091  {
6092  country_code = ACFG_GetCountry();
6093 
6094  switch (signal_type_required)
6095  {
6096  case SIGNAL_ANALOG:
6097  success = ACFG_GetAnaRfChannelTable(country_code, &ana_channel_table, &num_rf_chans);
6098  break;
6099  case SIGNAL_COFDM:
6100  success = ACFG_GetTerRfChannelTable(country_code, &ter_channel_table, &num_rf_chans);
6101  break;
6102  case SIGNAL_QAM:
6103  success = ACFG_GetCabRfChannelTable(country_code, &cab_channel_table, &num_rf_chans);
6104  break;
6105  default:
6106  num_rf_chans = 0;
6107  success = FALSE;
6108  break;
6109  }
6110 
6111  if (success && (rf_chan_id_required < num_rf_chans))
6112  {
6113  switch (signal_type_required)
6114  {
6115  case SIGNAL_ANALOG:
6116  tuning_params.freq = ana_channel_table[rf_chan_id_required].freq_hz;
6117  tuning_params.u.ana.offset = 0;
6118  tuning_params.u.ana.vtype = ANLG_VIDEO_PAL_I;
6119  break;
6120  case SIGNAL_COFDM:
6121  tuning_params.freq = ter_channel_table[rf_chan_id_required].freq_hz;
6122  tuning_params.u.terr.type = ter_channel_table[rf_chan_id_required].type;
6123  tuning_params.u.terr.mode = ter_channel_table[rf_chan_id_required].mode;
6124  tuning_params.u.terr.bwidth = ter_channel_table[rf_chan_id_required].bwidth;
6125 
6126  /* When searching, the PLP will already have been set, so get the set value */
6127  tuning_params.u.terr.plp_id = STB_DPGetTerrPLP(path);
6128  break;
6129  case SIGNAL_QAM:
6130  tuning_params.freq = cab_channel_table[rf_chan_id_required].freq_hz;
6131  tuning_params.u.cab.mode = cab_channel_table[rf_chan_id_required].mode;
6132  tuning_params.u.cab.symbol_rate = cab_channel_table[rf_chan_id_required].symbol_rate;
6133  break;
6134  default:
6135  break;
6136  }
6137  }
6138  else
6139  {
6140  // can't access rf chan table - set frequency to 0 to force a not locked event when
6141  // STB_DPStartTune() is called
6142  tuning_params.freq = 0;
6143  }
6144  }
6145  else if (event == INT_EVENT_USERDEFINED_TUNE_REQD)
6146  {
6147  /* Copy the saved values */
6148  memcpy(&tuning_params, &user_tuning_params[path], sizeof(S_MANUAL_TUNING_PARAMS));
6149  }
6150  else
6151  {
6152  switch (signal_type_required)
6153  {
6154  case SIGNAL_ANALOG:
6155  ADB_GetTransportAnalogTuningParams(transport_required[path], &tuning_params.freq,
6156  &tuning_params.u.ana.offset, &tuning_params.u.ana.vtype);
6157  break;
6158  case SIGNAL_COFDM:
6159  ADB_GetTransportTerrestrialTuningParams(transport_required[path], &tuning_params.u.terr.type,
6160  &tuning_params.freq, &tuning_params.u.terr.mode, &tuning_params.u.terr.bwidth,
6161  &tuning_params.u.terr.plp_id);
6162  break;
6163  case SIGNAL_QAM:
6164  ADB_GetTransportCableTuningParams(transport_required[path], &tuning_params.freq,
6165  &tuning_params.u.cab.mode, &tuning_params.u.cab.symbol_rate);
6166  break;
6167  case SIGNAL_QPSK:
6168  tuning_params.u.sat.satellite = ADB_GetTransportSatellite(transport_required[path]);
6169  ADB_GetTransportSatTuningParams(transport_required[path], &tuning_params.freq,
6170  &tuning_params.u.sat.polarity, &tuning_params.u.sat.symbol_rate,
6171  &tuning_params.u.sat.fec, &tuning_params.u.sat.dvb_s2, &tuning_params.u.sat.modulation);
6172  break;
6173  default:
6174  tuning_params.freq = 0;
6175  break;
6176  }
6177 
6178  /* Set any additional frequencies that could be used for this transport so these can be tried
6179  * if the tuner fails to lock using the main frequency */
6180  DBDEF_GetTransportAdditionalFrequencies(transport_required[path], &num_freqs, &additional_freqs);
6181  STB_DPSetAdditionalFrequencies(path, num_freqs, additional_freqs);
6182  }
6183 
6184  StartTune(path, &tuning_params);
6185 
6186  FUNCTION_FINISH(SetupForTuning);
6187 }
6188 
6189 /*!**************************************************************************
6190  * @brief Internal function to setup the tuning parameters to the decode path
6191  * and start tuning based on the signal_type_required variable.
6192  * @param path - decode path to be tuned
6193  * @param tuning_params - structure defining the tuning params
6194  ****************************************************************************/
6195 static void StartTune(U8BIT path, S_MANUAL_TUNING_PARAMS *tuning_params)
6196 {
6197  void *lnb_ptr, *band;
6198  ADB_LNB_SETTINGS lnb_settings;
6199  static S_STB_DP_LNB_BAND *sat_lnb_bands = NULL;
6200  U8BIT n_bands, i;
6201 
6202  FUNCTION_START(StartTune);
6203 
6204  if (sat_lnb_bands != NULL)
6205  {
6206  STB_AppFreeMemory(sat_lnb_bands);
6207  sat_lnb_bands = NULL;
6208  }
6209 
6210  // setup tuning parameters...
6211  STB_DPSetSignalType(path, signal_type_required);
6212  STB_DPSetFrequency(path, tuning_params->freq);
6213 
6214  switch (signal_type_required)
6215  {
6216  case SIGNAL_ANALOG:
6217  STB_DPSetAnalogFreqOff(path, tuning_params->u.ana.offset);
6218  STB_DPSetAnalogVideoType(path, tuning_params->u.ana.vtype);
6219  current_satellite[path] = NULL;
6220  break;
6221  case SIGNAL_COFDM:
6222  STB_DPSetTerrType(path, tuning_params->u.terr.type);
6223  STB_DPSetTerrPLP(path, tuning_params->u.terr.plp_id);
6224  STB_DPSetTerrMode(path, tuning_params->u.terr.mode);
6225  STB_DPSetTerrBandwidth(path, tuning_params->u.terr.bwidth);
6226  current_satellite[path] = NULL;
6227  break;
6228  case SIGNAL_QAM:
6229  STB_DPSetCableMode(path, tuning_params->u.cab.mode);
6230  STB_DPSetSymbolRate(path, tuning_params->u.cab.symbol_rate);
6231  current_satellite[path] = NULL;
6232  break;
6233  case SIGNAL_QPSK:
6234  STB_DPSetPolarity(path, tuning_params->u.sat.polarity);
6235  STB_DPSetSymbolRate(path, tuning_params->u.sat.symbol_rate);
6236  STB_DPSetFEC(path, tuning_params->u.sat.fec);
6237  STB_DPSetDVBS2(path, tuning_params->u.sat.dvb_s2);
6238  STB_DPSetModulation(path, tuning_params->u.sat.modulation);
6239 
6240  /* Set the current satellite */
6241  current_satellite[path] = tuning_params->u.sat.satellite;
6242 
6243  /* Get the LNB associated with the given satellite */
6244  if ((lnb_ptr = ADB_GetSatelliteLNB(tuning_params->u.sat.satellite)) != NULL)
6245  {
6246  if (ADB_GetLNBSettings(lnb_ptr, &lnb_settings))
6247  {
6248  STB_DPSetLNBType(path, lnb_settings.type);
6249  STB_DPSetLNBPower(path, lnb_settings.power);
6250  STB_DPSetLNB12v(path, lnb_settings.is_12v);
6251  STB_DPSetLNB22k(path, lnb_settings.is_22k);
6252 
6253  // DiSEqC Support
6254  STB_DPSetDISEQCPosition(path, lnb_settings.is_diseqc_posn);
6255  STB_DPSetDISEQCCSwitch(path, lnb_settings.c_switch);
6256  STB_DPSetDISEQCUSwitch(path, lnb_settings.u_switch);
6257  STB_DPSetDISEQCTone(path, lnb_settings.diseqc_tone);
6258  STB_DPSetPulsePosition(path, lnb_settings.is_pulse_posn);
6259  STB_DPSetDISEQCSMATV(path, lnb_settings.is_smatv);
6260  STB_DPSetDISEQCRepeats(path, lnb_settings.diseqc_repeats);
6261  STB_DPSetUnicableFrequency(path, lnb_settings.unicable_if);
6262  STB_DPSetUnicableChannel(path, lnb_settings.unicable_chan);
6263 
6264  /* Set the bands only if it's a user defined LNB */
6265  if (lnb_settings.type == LNB_TYPE_USER_DEFINED)
6266  {
6267  band = ADB_GetNextLNBBand(NULL);
6268  n_bands = 0;
6269  while (band != NULL)
6270  {
6271  if (ADB_GetLNBBandLNB(band) == lnb_ptr)
6272  {
6273  n_bands++;
6274  }
6275  band = ADB_GetNextLNBBand(band);
6276  }
6277 
6278  if (n_bands > 0)
6279  {
6280  sat_lnb_bands = STB_AppGetMemory(n_bands * sizeof(S_STB_DP_LNB_BAND));
6281  if (sat_lnb_bands != NULL)
6282  {
6283  band = ADB_GetNextLNBBand(NULL);
6284  i = 0;
6285  while (band != NULL)
6286  {
6287  if (ADB_GetLNBBandLNB(band) == lnb_ptr)
6288  {
6289  ADB_GetLNBBandParameters(band, &(sat_lnb_bands[i++]));
6290  }
6291  if (i >= n_bands)
6292  {
6293  break;
6294  }
6295  band = ADB_GetNextLNBBand(band);
6296  }
6297 
6298  STB_DPSetUserDefinedLNBBands(path, n_bands, sat_lnb_bands);
6299  }
6300  }
6301 #ifdef DEBUG_TUNING
6302  else
6303  {
6304  STB_SPDebugWrite("StartTune: no bands defined for this user defined LNB");
6305  }
6306 #endif
6307  }
6308  }
6309  }
6310  break;
6311  default:
6312  break;
6313  }
6314 
6315  STB_DPSetTuneRelock(path, tuner_relock_required);
6316  STB_DPStartTune(path);
6317 
6318  current_transport[path] = transport_required[path];
6319  current_tuner_relock = tuner_relock_required;
6320  current_si[path] = APP_SI_MODE_NO_SI;
6321 
6322  FUNCTION_FINISH(StartTune);
6323 }
6324 
6336 static void SetupForDecoding(U8BIT path)
6337 {
6338  E_STB_AV_ASPECT_MODE aspect_mode;
6339  void **stream_list;
6340  U16BIT num_streams;
6341  U16BIT video_pid;
6342  U16BIT subt_pid;
6343  ADB_STREAM_TYPE stream_type;
6344  U16BIT i;
6345  U8BIT audio_decoder;
6346  E_STB_DIGITAL_AUDIO_TYPE audio_type;
6347  E_STB_DP_AUDIO_CODEC audio_codec;
6348  ADB_SUBT_INFO subt_info;
6349 
6350  FUNCTION_START(SetupForDecoding);
6351 
6352  // setup pids
6353  video_pid = ADB_GetServiceVideoPid(service_required[path]);
6354 
6355  if (!external_control)
6356  {
6357  STB_DPSetPCRPID(path, ADB_GetServicePCRPid(service_required[path]));
6358  STB_DPSetVideoPID(path, video_pid);
6359 
6360  /* Setup AV decoding according to the type of stream */
6361  ADB_GetStreamList(service_required[path], ADB_VIDEO_LIST_STREAM, &stream_list, &num_streams);
6362  if ((num_streams > 0) && (stream_list != NULL))
6363  {
6364  /* Find the video stream being used */
6365  for (i = 0; i < num_streams; i++)
6366  {
6367  if (ADB_GetStreamPID(stream_list[i]) == video_pid)
6368  {
6369  stream_type = ADB_GetStreamType(stream_list[i]);
6371  }
6372  }
6373 
6374  ADB_ReleaseStreamList(stream_list, num_streams);
6375  }
6376 
6377  ACTL_SetupAudioDecoding(path, service_required[path]);
6378  }
6379 
6380  if (STB_DPIsDecodingPath(path))
6381  {
6382  /* Ensure the audio output is setup correctly */
6383  audio_decoder = STB_DPGetPathAudioDecoder(path);
6384  audio_type = (E_STB_DIGITAL_AUDIO_TYPE)APP_NvmRead(SPDIF_OUTPUT_NVM);
6385  audio_codec = STB_DPGetAudioCodec(path);
6386  if ((audio_type == DIGITAL_AUDIO_COMPRESSED) && ((audio_codec == AUDIO_CODEC_MP2) ||
6387  (audio_codec == AUDIO_CODEC_MP3)))
6388  {
6389  audio_type = DIGITAL_AUDIO_PCM;
6390  }
6391  STB_AVSetSpdifMode(audio_decoder, audio_type);
6392  STB_AVSetAudioDelay(audio_decoder, (U16BIT)APP_NvmRead(LIP_SYNC_ADJUSTMENT_NVM));
6393  audio_type = (E_STB_DIGITAL_AUDIO_TYPE)APP_NvmRead(HDMI_AUDIO_OUTPUT_NVM);
6394  if ((audio_type == DIGITAL_AUDIO_COMPRESSED) && ((audio_codec == AUDIO_CODEC_MP2) ||
6395  (audio_codec == AUDIO_CODEC_MP3)))
6396  {
6397  audio_type = DIGITAL_AUDIO_PCM;
6398  }
6399  STB_AVSetHDMIAudioMode(audio_decoder, audio_type);
6400 
6401  subt_pid = GetSubtitlePidFunc(current_service[path], &subt_info);
6402  if (subt_pid != 0)
6403  {
6404  STB_ChangePesCollectionPID(path, subt_pid);
6405  }
6406 
6407  // reset aspect conversion to default
6408  aspect_mode = (E_STB_AV_ASPECT_MODE)APP_NvmRead(ASPECT_MODE_NVM);
6409 
6410  STB_VTSetVideoAlignmentPref(aspect_mode);
6411 
6412  AVSetAudioVolumes(FALSE);
6413 
6414  ACTL_ApplyParentalControl(path, service_required[path]);
6415  ACTL_ApplyHDCP(service_required[path]);
6416  }
6417 
6418  FUNCTION_FINISH(SetupForDecoding);
6419 }
6420 
6432 static void StartSiProcess(U8BIT path)
6433 {
6434  FUNCTION_START(StartSiProcess);
6435 
6436  if (si_required[path] == APP_SI_MODE_NO_SI)
6437  {
6438  STB_DPStopSI(path);
6439  }
6440  else
6441  {
6442  ASI_SetAppSiMode(path, si_required[path]);
6443 
6444  if (si_required[path] == APP_SI_MODE_UPDATE)
6445  {
6446  STB_DPSetSearchMode(path, FALSE);
6447  }
6448  else
6449  {
6450  STB_DPSetSearchMode(path, TRUE);
6451  }
6452  STB_DPStartSI(path);
6453  }
6454  current_si[path] = si_required[path];
6455 
6456  FUNCTION_FINISH(StartSiProcess);
6457 }
6458 
6473 static void ControlTuning(U8BIT path, E_ACTL_EVENT_TYPE type, U32BIT event)
6474 {
6475  U32BIT handle;
6476  void *s_ptr;
6477  E_STB_DP_TUNE_STATUS tune_status;
6478 #ifdef COMMON_INTERFACE
6479  void *owner_data;
6480  U32BIT data_size;
6481  U8BIT slot_id;
6482 #endif
6483 #if defined(INTEGRATE_HBBTV)
6484  U16BIT onet_id, ts_id, serv_id;
6485 #endif
6486 
6487  FUNCTION_START(ControlTuning);
6488 
6489  STB_OSMutexLock(cntrl_mutex[path]);
6490 
6491  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_INITIALISE))
6492  {
6493  // initialisation...
6494  memset(&user_tuning_params[path], 0, sizeof(S_MANUAL_TUNING_PARAMS));
6495  tuning_state[path] = TSTATE_OFF;
6496  tuned_status[path] = TUNED_STATUS_NO_SIGNAL;
6497 
6498  transport_required[path] = NULL;
6499  service_required[path] = NULL;
6500  si_required[path] = APP_SI_MODE_NO_SI;
6501 
6502  current_satellite[path] = NULL;
6503  current_service[path] = NULL;
6504  current_transport[path] = NULL;
6505  current_si[path] = APP_SI_MODE_NO_SI;
6506 
6507  current_tuner_relock = FALSE;
6508  #ifdef DEBUG_TUNING
6509  STB_SPDebugWrite(" new tune state(%d): Off", path);
6510  #endif
6511  }
6512  else
6513  {
6514  #ifdef DEBUG_TUNING
6515  {
6516  U8BIT *state_string;
6517  U8BIT *event_string;
6518 
6519  switch (tuning_state[path])
6520  {
6521  case TSTATE_OFF: {state_string = (U8BIT *)"Off"; break; }
6522  case TSTATE_TUNING: {state_string = (U8BIT *)"Tuning"; break; }
6523  case TSTATE_NOT_TUNED: {state_string = (U8BIT *)"Not tuned"; break; }
6524  case TSTATE_TUNED: {state_string = (U8BIT *)"Tuned"; break; }
6525  case TSTATE_ANALOG: {state_string = (U8BIT *)"Analogue"; break; }
6526  default: {state_string = (U8BIT *)"Unknown state - error"; break; }
6527  }
6528  event_string = GetEventDebugString(type, event);
6529  STB_SPDebugWrite("ControlTuning(%d): %s, %s", path, state_string, event_string);
6530  }
6531  #endif
6532 
6533  switch (tuning_state[path])
6534  {
6535  case TSTATE_OFF:
6536  {
6537  if ((type == INTERNAL_EVENT) &&
6538  ((event == INT_EVENT_RF_CHAN_TUNE_REQD) ||
6539  (event == INT_EVENT_TPTR_TUNE_REQD) ||
6540  (event == INT_EVENT_USERDEFINED_TUNE_REQD)))
6541  {
6542  if (signal_type_required == SIGNAL_ANALOG)
6543  {
6544  #ifdef DEBUG_TUNING
6545  STB_SPDebugWrite(" new tune state(%d): Analogue", path);
6546  #endif
6547  tuning_state[path] = TSTATE_ANALOG;
6548  SetupForTuning(path, event);
6549 
6550  if (service_required[path] != NULL)
6551  {
6552  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_STARTED, NULL, 0);
6553  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_ON);
6554  }
6555  }
6556  else
6557  {
6558  #ifdef DEBUG_TUNING
6559  STB_SPDebugWrite(" new tune state(%d): Tuning", path);
6560  #endif
6561  tuning_state[path] = TSTATE_TUNING;
6562  SetupForTuning(path, event);
6563  }
6564  }
6565  break;
6566  }
6567 
6568  case TSTATE_TUNING:
6569  {
6570  if (type == INTERNAL_EVENT)
6571  {
6572  if (event == INT_EVENT_TUNE_OFF)
6573  {
6574  #ifdef DEBUG_TUNING
6575  STB_SPDebugWrite(" new tune state(%d): Off", path);
6576  #endif
6577  // stop tuning
6578  STB_DPTuneOff(path);
6579  tuning_state[path] = TSTATE_OFF;
6580  }
6581  else if ((event == INT_EVENT_RF_CHAN_TUNE_REQD) ||
6582  (event == INT_EVENT_TPTR_TUNE_REQD) || (event == INT_EVENT_USERDEFINED_TUNE_REQD))
6583  {
6584  if (signal_type_required == SIGNAL_ANALOG)
6585  {
6586  #ifdef DEBUG_TUNING
6587  STB_SPDebugWrite(" new tune state(%d): Analogue", path);
6588  #endif
6589  tuning_state[path] = TSTATE_ANALOG;
6590  if (service_required[path] != NULL)
6591  {
6592  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_STARTED, NULL, 0);
6593  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_ON);
6594  }
6595  }
6596  SetupForTuning(path, event);
6597 #if defined(INTEGRATE_HBBTV)
6598  if (STB_DPIsLivePath(path))
6599  {
6600  /* Inform the presentation engine that the channel change was interrupted */
6601  if (service_required[path] != NULL)
6602  {
6603  ADB_GetServiceIds(service_required[path], &onet_id, &ts_id, &serv_id);
6604  }
6605  else
6606  {
6607  onet_id = ADB_INVALID_DVB_ID;
6608  ts_id = ADB_INVALID_DVB_ID;
6609  serv_id = ADB_INVALID_DVB_ID;
6610  }
6611  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
6612  HBBTV_CHANNEL_CHANGE_INTERRUPTED);
6613  }
6614 #endif
6615  }
6616  }
6617  else // i.e. external event
6618  {
6619  switch (event)
6620  {
6621  case STB_EVENT_TUNE_NOTLOCKED:
6622  {
6623  /* This event may be related to a previous tune request, so check the midware
6624  * tuner state and if it's still waiting to tune or has been stopped then
6625  * this event is for a previous tune request and should be ignored */
6626  tune_status = STB_DPGetTuneStatus(path);
6627  if (tune_status == TUNE_NO_LOCK)
6628  {
6629  // tried to tune but no signal - need to enable decode control so that it can
6630  // control status indication
6631  #ifdef DEBUG_TUNING
6632  STB_SPDebugWrite(" new tune state(%d): Not tuned", path);
6633  #endif
6634  /* Decoding should only be performed on the live path */
6635  if (STB_DPIsDecodingPath(path))
6636  {
6637  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_ENABLE);
6638  }
6639 
6640  tuning_state[path] = TSTATE_NOT_TUNED;
6641 
6642 #ifdef COMMON_INTERFACE
6643  /* If the tuner is being used by CI+ then it needs to be notified
6644  * of the tuning status */
6645  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS))
6646  {
6647  if ((owner_data = STB_DPGetOwnerData(path, &data_size)) != NULL)
6648  {
6649  ACI_TuneReply(path, *(U32BIT *)owner_data, CIP_TUNER_NOTLOCKED);
6650  }
6651  }
6652 #endif
6653  if (STB_DPIsRecordingPath(path))
6654  {
6655  if (STB_DPIsRecording(path, &handle))
6656  {
6657 #ifdef COMMON_INTERFACE
6658  if ((slot_id = STB_DPGetPathCISlot(path)) != INVALID_RES_ID)
6659  {
6660  STB_CiCcSendRecordStop(slot_id);
6661  }
6662 #endif
6663  /* Stop the recording and release the path */
6664  APVR_StopRecording(handle);
6665  }
6666  else
6667  {
6668  /* Recording not yet started */
6669  ATMR_RecordingFailed(path);
6670  STB_DPReleasePath(path, RES_OWNER_DVB);
6671 
6672  /* Send event to UI to inform a recording has failed */
6673  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION,
6674  EV_PVR_RECORDING_FAILED, NULL, 0);
6675  }
6676  }
6677 #if defined(INTEGRATE_HBBTV)
6678  if (STB_DPIsLivePath(path))
6679  {
6680  /* Inform the presentation engine that the channel change failed */
6681  if (service_required[path] != NULL)
6682  {
6683  ADB_GetServiceIds(service_required[path], &onet_id, &ts_id, &serv_id);
6684  }
6685  else
6686  {
6687  onet_id = ADB_INVALID_DVB_ID;
6688  ts_id = ADB_INVALID_DVB_ID;
6689  serv_id = ADB_INVALID_DVB_ID;
6690  }
6691  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
6692  HBBTV_CHANNEL_CHANGE_NO_SIGNAL);
6693  }
6694 #endif
6695  }
6696  break;
6697  }
6698  case STB_EVENT_TUNE_LOCKED:
6699  {
6700  /* This event may be related to a previous tune request, so check the midware
6701  * tuner state and if it's still waiting to tune or has been stopped then
6702  * this event is for a previous tune request and should be ignored */
6703  tune_status = STB_DPGetTuneStatus(path);
6704  if (tune_status == TUNE_LOCKED)
6705  {
6706  // tuned - enable decode control and start si
6707  #ifdef DEBUG_TUNING
6708  STB_SPDebugWrite(" new tune state(%d): Tuned", path);
6709  #endif
6710  tuning_state[path] = TSTATE_TUNED;
6711  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL;
6712 
6713  UpdateTransportParameters(path);
6714 
6715  /* Start SI processing */
6716  StartSiProcess(path);
6717 
6718  if (STB_DPIsLivePath(path) && (current_service[path] != NULL) &&
6719  current_service[path]->pmt_received)
6720  {
6721  /* The PMT has already been received for the service being tuned to
6722  * so the UI should be informed of the change of service now */
6723  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_CHANGED,
6724  &current_service[path], sizeof(void *));
6725 #if defined(INTEGRATE_HBBTV)
6726  /* Inform the presentation engine that the channel change succeeded */
6727  ADB_GetServiceIds(current_service[path], &onet_id, &ts_id, &serv_id);
6728  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
6729  HBBTV_CHANNEL_CHANGE_SUCCEEDED);
6730 #endif
6731  }
6732 
6733 #ifdef COMMON_INTERFACE
6734  /* If the path is owned by CI+, and we're tuning to a service or transport and
6735  * no SI collection is to be started or the PMT for the service has already
6736  * been received, then CI+ needs to be notified of the result of the tune.
6737  * If tuning to a service and SI collection will be performed and the PMT
6738  * hasn't yet been received, then CI+ will be notified when the event is
6739  * received indicating completion */
6740  if (STB_DPIsOwnedBy(path, RES_OWNER_CIPLUS) &&
6741  ((si_required[path] == APP_SI_MODE_NO_SI) ||
6742  ((current_service[path] != NULL) && current_service[path]->pmt_received)))
6743  {
6744  if ((owner_data = STB_DPGetOwnerData(path, &data_size)) != NULL)
6745  {
6746  ACI_TuneReply(path, *(U32BIT *)owner_data, CIP_TUNER_LOCKED);
6747  }
6748  }
6749 #endif
6750 
6751  if (STB_DPIsDecodingPath(path))
6752  {
6753  /* Start decoding. If this is also a recording path then
6754  * recording will be started after the decoding has started */
6755  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_ENABLE);
6756  }
6757  if (STB_DPIsRecordingPath(path) && !STB_DPIsRecording(path, &handle))
6758  {
6759  /* The recording can only be started here if the PIDs for the service
6760  * are known, otherwise it will have to start when the PMT for the service
6761  * has been received. */
6762  s_ptr = ATMR_GetRecordService(path);
6763  if ((ADB_GetServiceAudioPid(s_ptr) != 0) ||
6764  (ADB_GetServiceVideoPid(s_ptr) != 0))
6765  {
6766  ATMR_CheckRecordStatus(TRUE, s_ptr);
6767  }
6768  }
6769  }
6770  break;
6771  }
6772  }
6773  }
6774  break;
6775  }
6776 
6777  case TSTATE_NOT_TUNED:
6778  {
6779  if (type == INTERNAL_EVENT)
6780  {
6781  switch (event)
6782  {
6783  case INT_EVENT_TUNE_OFF:
6784  {
6785  // stop tuning
6786  #ifdef DEBUG_TUNING
6787  STB_SPDebugWrite(" new tune state(%d): Off", path);
6788  #endif
6789  if (STB_DPIsDecodingPath(path))
6790  {
6791  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
6792  }
6793  STB_DPTuneOff(path);
6794  tuning_state[path] = TSTATE_OFF;
6795  break;
6796  }
6797  case INT_EVENT_RF_CHAN_TUNE_REQD:
6798  case INT_EVENT_TPTR_TUNE_REQD:
6799  case INT_EVENT_USERDEFINED_TUNE_REQD:
6800  {
6801  if (STB_DPIsDecodingPath(path))
6802  {
6803  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
6804  }
6805  if (signal_type_required == SIGNAL_ANALOG)
6806  {
6807  #ifdef DEBUG_TUNING
6808  STB_SPDebugWrite(" new tune state(%d): Analogue", path);
6809  #endif
6810  tuning_state[path] = TSTATE_ANALOG;
6811  if (service_required[path] != NULL)
6812  {
6813  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_STARTED, NULL, 0);
6814  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_ON);
6815  }
6816  }
6817  else
6818  {
6819  #ifdef DEBUG_TUNING
6820  STB_SPDebugWrite(" new tune state(%d): Tuning", path);
6821  #endif
6822  tuning_state[path] = TSTATE_TUNING;
6823  }
6824  SetupForTuning(path, event);
6825  break;
6826  }
6827  }
6828  }
6829  else // i.e. external event
6830  {
6831  if (event == STB_EVENT_TUNE_LOCKED)
6832  {
6833  /* If the tuner is no longer locked then this event is no longer valid */
6834  tune_status = STB_DPGetTuneStatus(path);
6835  if (tune_status == TUNE_LOCKED)
6836  {
6837  // tuned - enable decode control and start si
6838  #ifdef DEBUG_TUNING
6839  STB_SPDebugWrite(" new tune state(%d): Tuned", path);
6840  #endif
6841  tuning_state[path] = TSTATE_TUNED;
6842  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL;
6843 
6844  if (STB_DPIsDecodingPath(path))
6845  {
6846  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_DECODING);
6847  }
6848 
6849  /* Start SI */
6850  StartSiProcess(path);
6851 
6852  if (STB_DPIsLivePath(path) && (current_service[path] != NULL) &&
6853  current_service[path]->pmt_received)
6854  {
6855  /* The PMT has already been received for the service being tuned to
6856  * so the UI should be informed of the change of service now */
6857  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_CHANGED,
6858  &current_service[path], sizeof(void *));
6859 #if defined(INTEGRATE_HBBTV)
6860  /* Inform the presentation engine that the channel change succeeded */
6861  ADB_GetServiceIds(current_service[path], &onet_id, &ts_id, &serv_id);
6862  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
6863  HBBTV_CHANNEL_CHANGE_SUCCEEDED);
6864 #endif
6865  }
6866  }
6867  }
6868  }
6869  break;
6870  }
6871 
6872  case TSTATE_TUNED:
6873  {
6874  if (type == INTERNAL_EVENT)
6875  {
6876  if ((event == INT_EVENT_TUNE_OFF) || (event == INT_EVENT_RF_CHAN_TUNE_REQD) ||
6877  (event == INT_EVENT_TPTR_TUNE_REQD) || (event == INT_EVENT_USERDEFINED_TUNE_REQD))
6878  {
6879  if (STB_DPIsLivePath(path))
6880  {
6881  // check if pmt has been reported (this must be read before StopSI is done
6882  // because that clears the flag
6883  ASI_PmtReported(path);
6884 
6885  // stop SI ready for re-tune
6886  STB_DPStopSI(path);
6887  }
6888  switch (event)
6889  {
6890  case INT_EVENT_TUNE_OFF:
6891  {
6892  // stop tuning
6893  #ifdef DEBUG_TUNING
6894  STB_SPDebugWrite(" new tune state(%d): Off", path);
6895  #endif
6896  tuning_state[path] = TSTATE_OFF;
6897  tuned_status[path] = TUNED_STATUS_NO_SIGNAL;
6898  if (STB_DPIsDecodingPath(path))
6899  {
6900  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
6901  }
6902  STB_DPTuneOff(path);
6903  break;
6904  }
6905  case INT_EVENT_RF_CHAN_TUNE_REQD:
6906  case INT_EVENT_USERDEFINED_TUNE_REQD:
6907  {
6908  tuned_status[path] = TUNED_STATUS_NO_SIGNAL;
6909  if (STB_DPIsDecodingPath(path))
6910  {
6911  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
6912  }
6913  if (signal_type_required == SIGNAL_ANALOG)
6914  {
6915  #ifdef DEBUG_TUNING
6916  STB_SPDebugWrite(" new tune state(%d): Analogue", path);
6917  #endif
6918  tuning_state[path] = TSTATE_ANALOG;
6919  }
6920  else
6921  {
6922  #ifdef DEBUG_TUNING
6923  STB_SPDebugWrite(" new tune state(%d): Tuning", path);
6924  #endif
6925  tuning_state[path] = TSTATE_TUNING;
6926  }
6927  SetupForTuning(path, event);
6928  break;
6929  }
6930  case INT_EVENT_TPTR_TUNE_REQD:
6931  {
6932  if ((transport_required[path] != current_transport[path]) ||
6933  (tuner_relock_required != current_tuner_relock) ||
6934  (si_required[path] != current_si[path]))
6935  {
6936  // something has changed - re-tune
6937  tuned_status[path] = TUNED_STATUS_NO_SIGNAL;
6938  if (STB_DPIsDecodingPath(path))
6939  {
6940  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_DISABLE);
6941  }
6942  if (signal_type_required == SIGNAL_ANALOG)
6943  {
6944  #ifdef DEBUG_TUNING
6945  STB_SPDebugWrite(" new tune state(%d): Analogue", path);
6946  #endif
6947  tuning_state[path] = TSTATE_ANALOG;
6948  if (service_required[path] != NULL)
6949  {
6950  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_STARTED, NULL, 0);
6951  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_ON);
6952  }
6953  }
6954  else
6955  {
6956  #ifdef DEBUG_TUNING
6957  STB_SPDebugWrite(" new tune state(%d): Tuning", path);
6958  #endif
6959  tuning_state[path] = TSTATE_TUNING;
6960  }
6961  SetupForTuning(path, event);
6962  }
6963  else
6964  {
6965  // already tuned to the correct transport - just restart decoding to the
6966  // new service and restart si.
6967  if (STB_DPIsDecodingPath(path))
6968  {
6969  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_RESTART_DECODING);
6970  }
6971 
6972  StartSiProcess(path);
6973  }
6974  break;
6975  }
6976  }
6977  }
6978  }
6979  else // i.e. external event
6980  {
6981  switch (event)
6982  {
6983  case STB_EVENT_TUNE_LOCKED:
6984  case STB_EVENT_TUNE_SIGNAL_DATA_OK:
6985  {
6986  tuned_status[path] = TUNED_STATUS_GOOD_SIGNAL;
6987  if (STB_DPIsDecodingPath(path))
6988  {
6989  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_UPDATE);
6990  }
6991  break;
6992  }
6993  case STB_EVENT_TUNE_NOTLOCKED:
6994  {
6995  tuned_status[path] = TUNED_STATUS_NO_SIGNAL;
6996  if (STB_DPIsDecodingPath(path))
6997  {
6998  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_UPDATE);
6999  }
7000  break;
7001  }
7002  case STB_EVENT_TUNE_SIGNAL_DATA_BAD:
7003  {
7004  tuned_status[path] = TUNED_STATUS_BAD_SIGNAL;
7005  if (STB_DPIsDecodingPath(path))
7006  {
7007  ControlDecoding(path, INTERNAL_EVENT, INT_EVENT_UPDATE);
7008  }
7009  break;
7010  }
7011  }
7012  }
7013  break;
7014  }
7015 
7016  case TSTATE_ANALOG:
7017  {
7018  // analogue signal...
7019  if (type == INTERNAL_EVENT)
7020  {
7021  if (event == INT_EVENT_TUNE_OFF)
7022  {
7023  #ifdef DEBUG_TUNING
7024  STB_SPDebugWrite(" new tune state(%d): Off", path);
7025  #endif
7026  // stop tuning
7027  STB_DPTuneOff(path);
7028  tuning_state[path] = TSTATE_OFF;
7029  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_OFF);
7030  }
7031  else if ((event == INT_EVENT_RF_CHAN_TUNE_REQD) ||
7032  (event == INT_EVENT_TPTR_TUNE_REQD) || (event == INT_EVENT_USERDEFINED_TUNE_REQD))
7033  {
7034  if (signal_type_required == SIGNAL_ANALOG)
7035  {
7036  if (service_required[path] != NULL)
7037  {
7038  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_SERVICE_ANALOG_STARTED, NULL, 0);
7039  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_ON);
7040  }
7041  }
7042  else
7043  {
7044  #ifdef DEBUG_TUNING
7045  STB_SPDebugWrite(" new tune state(%d): Tuning", path);
7046  #endif
7047  tuning_state[path] = TSTATE_TUNING;
7048  ControlAvOutput(INTERNAL_EVENT, INT_EVENT_ANALOG_TV_OFF);
7049  }
7050  SetupForTuning(path, event);
7051  }
7052  }
7053  break;
7054  }
7055  }
7056  }
7057 
7058  STB_OSMutexUnlock(cntrl_mutex[path]);
7059 
7060  FUNCTION_FINISH(ControlTuning);
7061 }
7062 
7077 static void ControlDecoding(U8BIT path, E_ACTL_EVENT_TYPE type, U32BIT event)
7078 {
7079  E_STB_DP_DECODE_STATUS video_status;
7080  E_STB_DP_DECODE_STATUS audio_status;
7081 #if defined(INTEGRATE_HBBTV)
7082  U16BIT onet_id, ts_id, serv_id;
7083 #endif
7084 
7085  FUNCTION_START(ControlDecoding);
7086 
7087  ASSERT(path < STB_DPGetNumPaths());
7088 
7089  STB_OSMutexLock(cntrl_mutex[path]);
7090 
7091  /* Treat service not running and pid update events from application SI
7092  * as a request to restart decoding */
7093  if (type == EXTERNAL_EVENT)
7094  {
7095  if (event == APP_EVENT_SERVICE_NOT_RUNNING)
7096  {
7097  type = INTERNAL_EVENT;
7098  event = INT_EVENT_DISABLE;
7099  }
7100  else if ((event == APP_EVENT_SERVICE_VIDEO_PID_UPDATE) ||
7101  (event == APP_EVENT_SERVICE_RUNNING))
7102  {
7103  type = INTERNAL_EVENT;
7104  if (decoding_state[path] == DSTATE_DISABLED)
7105  {
7106  event = INT_EVENT_ENABLE;
7107  }
7108  else
7109  {
7110  event = INT_EVENT_RESTART_DECODING;
7111  }
7112  }
7113  else if (event == APP_EVENT_SERVICE_SUBTITLE_UPDATE)
7114  {
7115  type = INTERNAL_EVENT;
7116  event = INT_EVENT_RESTART_SUBTITLES;
7117  }
7118  else if (event == APP_EVENT_SERVICE_SCRAMBLE_CHANGE)
7119  {
7120  type = INTERNAL_EVENT;
7121  if (decoding_state[path] == DSTATE_DISABLED)
7122  {
7123  event = INT_EVENT_ENABLE;
7124  }
7125  else
7126  {
7127  event = INT_EVENT_SCRAMBLE_CHANGE;
7128  }
7129  }
7130  }
7131  else if (type == INTERNAL_EVENT)
7132  {
7133  /* Decoding can't be restarted if the decoder is disabled, so change the event */
7134  if ((event == INT_EVENT_RESTART_DECODING) && (decoding_state[path] == DSTATE_DISABLED))
7135  {
7136  event = INT_EVENT_ENABLE;
7137  }
7138  }
7139 
7140  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_INITIALISE))
7141  {
7142  // initialisation...
7143  decoding_state[path] = DSTATE_DISABLED;
7144  decoding_started[path] = FALSE;
7145  decoding_locked[path] = FALSE;
7146  now_event_id[path] = -1;
7147  #ifdef DEBUG_DECODING
7148  STB_SPDebugWrite(" new decode state(%d): Disabled", path);
7149  #endif
7150  }
7151  else
7152  {
7153  #ifdef DEBUG_DECODING
7154  {
7155  U8BIT *state_string;
7156  U8BIT *event_string;
7157 
7158  switch (decoding_state[path])
7159  {
7160  case DSTATE_DISABLED: {state_string = (U8BIT *)"Disabled"; break; }
7161  case DSTATE_OFF: {state_string = (U8BIT *)"Off"; break; }
7162  case DSTATE_STARTING_BAD_SIGNAL: {state_string = (U8BIT *)"Starting bad"; break; }
7163  case DSTATE_STARTING: {state_string = (U8BIT *)"Starting"; break; }
7164  case DSTATE_LOCKED: {state_string = (U8BIT *)"Locked"; break; }
7165  case DSTATE_DECODING: {state_string = (U8BIT *)"Decoding"; break; }
7166  case DSTATE_PAUSED_SIGNAL: {state_string = (U8BIT *)"Signal pause"; break; }
7167  case DSTATE_PAUSED_USER: {state_string = (U8BIT *)"User pause"; break; }
7168  case DSTATE_PAUSED_SIGNAL_AND_USER: {state_string = (U8BIT *)"Signal/user pause"; break; }
7169  default: {state_string = (U8BIT *)"Unknown decode state - error"; break; }
7170  }
7171  event_string = GetEventDebugString(type, event);
7172  STB_SPDebugWrite("ControlDecoding(%d): %s, %s", path, state_string, event_string);
7173  }
7174  #endif
7175 
7176  // first, code common to all states...
7177  if ((type == INTERNAL_EVENT) &&
7178  ((event == INT_EVENT_DISABLE) ||
7179  (event == INT_EVENT_RESTART_DECODING) ||
7180  (event == INT_EVENT_SCRAMBLE_CHANGE)))
7181  {
7182  if (decoding_state[path] != DSTATE_DISABLED)
7183  {
7184  if (decoding_state[path] >= DSTATE_DECODING) // i.e. decoding or any of the paused states
7185  {
7186  if (STB_DPIsLivePath(path))
7187  {
7188  /* If MHEG-5 or other external is enabled, it will deal with PID updates */
7189  if (!external_control)
7190  {
7191  STB_AVBlankVideo(0, TRUE);
7192  }
7193 
7194  if (event != INT_EVENT_RESTART_DECODING)
7195  {
7196  /* Ensure subtitles are stopped */
7198  }
7199  }
7200  }
7201 
7202  if ((decoding_state[path] == DSTATE_STARTING) || (decoding_state[path] == DSTATE_DECODING))
7203  {
7204  /* Decoding needs to be stopped if the service being viewed has changed from
7205  * FTA to scrambled so that the video is no longer shown on screen, but MHEG
7206  * could be controlling the video and it may be viewing video from another
7207  * service that isn't scrambled. In this situation, MHEG needs to be told that
7208  * there's been an update to the current service so that it can decide to stop
7209  * decoding if it's using the service's video, but if it isn't then decoding
7210  * should be stopped here.
7211  * As it stands, this change will probably cause problem(s) with the MHEG test
7212  * suite, so the ability to notify MHEG about changes to the service needs to be
7213  * added soon.
7214  * There's an equivalent change to start decoding below which will also need to
7215  * be changed. */
7216  if (!external_control ||
7217  ((event == INT_EVENT_SCRAMBLE_CHANGE) &&
7218  ADB_GetServiceScrambledFlag(service_required[path])))
7219  {
7220  STB_DPStopDecoding(path);
7221  }
7222  }
7223 
7224  if ((event == INT_EVENT_DISABLE) ||
7225  ((event == INT_EVENT_RESTART_DECODING) && (service_required[path] == NULL)) ||
7226  (((event == INT_EVENT_RESTART_DECODING) || (event == INT_EVENT_SCRAMBLE_CHANGE)) &&
7227  (service_required[path] != NULL) &&
7228  (ADB_GetServiceNotRunningFlag(service_required[path]) == TRUE)))
7229  {
7230  if (decoding_state[path] >= DSTATE_STARTING) // i.e. starting, locked, decoding or any of the paused states
7231  {
7232  // clear pids to ensure no decoding takes place by accident
7233  if (!external_control)
7234  {
7235  STB_DPSetDecodePIDs(path, 0, 0, 0, 0, 0, 0);
7236  }
7237  }
7238  if (event == INT_EVENT_DISABLE)
7239  {
7240  #ifdef DEBUG_DECODING
7241  STB_SPDebugWrite(" new decode state(%d): Disabled", path);
7242  #endif
7243  decoding_state[path] = DSTATE_DISABLED;
7244  }
7245  else
7246  {
7247  #ifdef DEBUG_DECODING
7248  STB_SPDebugWrite(" new decode state(%d): Off", path);
7249  #endif
7250  decoding_state[path] = DSTATE_OFF;
7251  }
7252  }
7253  else // i.e. INT_EVENT_RESTART_DECODING and service_required != NULL
7254  {
7255  // setup system ready to start decoding...
7256  SetupForDecoding(path);
7257 
7258  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7259  {
7260  if (STB_DPIsDecodingPath(path))
7261  {
7262  #ifdef DEBUG_DECODING
7263  STB_SPDebugWrite(" new decode state(%d): Starting", path);
7264  #endif
7265  /* An MHEG app could be running when a service changes from scrambled to FTA
7266  * in which case starting decoding here could cause problems, but see above
7267  * when decoding is stopped for a fuller description */
7268  if (!external_control || (event == INT_EVENT_SCRAMBLE_CHANGE))
7269  {
7270  /* If external control is enabled, external (eg MHEG) will deal with PID updates */
7271  STB_DPStartDecoding(path);
7272  }
7273  }
7274 
7275  decoding_state[path] = DSTATE_STARTING;
7276  }
7277  else
7278  {
7279  #ifdef DEBUG_DECODING
7280  STB_SPDebugWrite(" new decode state(%d): Starting bad", path);
7281  #endif
7282  decoding_state[path] = DSTATE_STARTING_BAD_SIGNAL;
7283  }
7284  }
7285  }
7286  }
7287  else if (((type == INTERNAL_EVENT) && (event == INT_EVENT_RESTART_AUDIO)) ||
7288  (event == APP_EVENT_SERVICE_AUDIO_PID_UPDATE))
7289  {
7290  // if audio pid has already been set in decode path need to update it. Then, if decoding
7291  // has already started need to restart the audio decoding
7292 
7293  /* An MHEG app could be running when a service changes from scrambled to FTA
7294  * in which case starting decoding here could cause problems, but see above
7295  * when decoding is stopped for a fuller description */
7296  if (!external_control)
7297  {
7298  if (decoding_state[path] > DSTATE_OFF)
7299  {
7300  E_ACTL_DECODE_CHANGE changed;
7301 
7302  changed = ACTL_SetupAudioDecoding(path, service_required[path]);
7303 
7304  /* No need to restart audio decoding if the PID hasn't changed */
7305  if ((event != APP_EVENT_SERVICE_AUDIO_PID_UPDATE) || changed)
7306  {
7307  /* Audio PID has changed so need to restart audio decoding */
7308  if ((decoding_state[path] == DSTATE_STARTING) ||
7309  (decoding_state[path] == DSTATE_DECODING))
7310  {
7311  /* After stop func, start func will apply changes setup in ACTL_SetupAudioDecoding
7312  * Note: stop and start of AD does nothing, unless it was enabled and has valid pid */
7313  STB_DPStopADDecoding(path);
7316  STB_DPStartADDecoding(path);
7317  }
7318  }
7319  #ifdef DEBUG_DECODING
7320  else
7321  {
7322  STB_SPDebugWrite(" no audio PID change, not restarting audio decoding(%u)", path);
7323  }
7324  #endif
7325  }
7326  }
7327  }
7328  else if ((type == INTERNAL_EVENT) && (event == INT_EVENT_RESTART_SUBTITLES))
7329  {
7330  // subbtitles are running in decoding and paused states - so if in one of those states
7331  // stop and restart subtitles
7332  if ((decoding_state[path] == DSTATE_STARTING) || (decoding_state[path] >= DSTATE_DECODING))
7333  {
7334  /* Restart the subtitles, it will select either DVB subtitle or teletext subtitle */
7336  {
7337  /* Restart subtitles and display them, if available */
7340  }
7341  else if (ACTL_AreSubtitlesStarted())
7342  {
7343  /* Need to start and then pause subtitles to stop them being immediately shown */
7347  }
7348  }
7349  }
7350  else
7351  {
7352  // switch on state variable for code relevant to particular states
7353  switch (decoding_state[path])
7354  {
7355  case DSTATE_DISABLED:
7356  {
7357  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_ENABLE))
7358  {
7359  if (service_required[path] != NULL)
7360  {
7361  SetupForDecoding(path);
7362  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7363  {
7364  if (STB_DPIsDecodingPath(path))
7365  {
7366  #ifdef DEBUG_DECODING
7367  STB_SPDebugWrite(" new decode state(%d): Starting", path);
7368  #endif
7369  STB_DPStartDecoding(path);
7370  }
7371 
7372  decoding_state[path] = DSTATE_STARTING;
7373  }
7374  else
7375  {
7376  #ifdef DEBUG_DECODING
7377  STB_SPDebugWrite(" new decode state(%d): Starting bad", path);
7378  #endif
7379  decoding_state[path] = DSTATE_STARTING_BAD_SIGNAL;
7380  }
7381  }
7382  }
7383  break;
7384  }
7385 
7386  case DSTATE_OFF:
7387  {
7388  // DISABLE and RESTART DECODING events handled in general code above - nothing else
7389  // to do in this state
7390  break;
7391  }
7392 
7393  case DSTATE_STARTING_BAD_SIGNAL:
7394  {
7395  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7396  {
7397  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7398  {
7399  if (STB_DPIsLivePath(path))
7400  {
7401  #ifdef DEBUG_DECODING
7402  STB_SPDebugWrite(" new decode state(%d): Starting", path);
7403  #endif
7404  STB_DPStartDecoding(path);
7405  }
7406 
7407  decoding_state[path] = DSTATE_STARTING;
7408  }
7409  }
7410  break;
7411  }
7412 
7413  case DSTATE_STARTING:
7414  {
7415  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7416  {
7417  if (tuned_status[path] != TUNED_STATUS_GOOD_SIGNAL)
7418  {
7419  #ifdef DEBUG_DECODING
7420  STB_SPDebugWrite(" new decode state(%d): Starting bad", path);
7421  #endif
7422  STB_DPStopDecoding(path);
7423  decoding_state[path] = DSTATE_STARTING_BAD_SIGNAL;
7424  }
7425  }
7426  else if ((type == EXTERNAL_EVENT) && (event == STB_EVENT_DECODE_LOCKED))
7427  {
7428  #ifdef DEBUG_DECODING
7429  STB_SPDebugWrite(" new decode state(%d): Locked", path);
7430  #endif
7431  decoding_state[path] = DSTATE_LOCKED;
7432  if (path == STB_DPGetPlaybackPath())
7433  {
7434  STB_AVBlankVideo(0, TRUE);
7435  APVR_PausePlay();
7436  }
7437 #if defined(INTEGRATE_HBBTV)
7438  if (STB_DPIsLivePath(path))
7439  {
7440  /* Inform the presentation engine that the channel is locked */
7441  if (service_required[path] != NULL)
7442  {
7443  ADB_GetServiceIds(service_required[path], &onet_id, &ts_id, &serv_id);
7444  }
7445  else
7446  {
7447  onet_id = ADB_INVALID_DVB_ID;
7448  ts_id = ADB_INVALID_DVB_ID;
7449  serv_id = ADB_INVALID_DVB_ID;
7450  }
7451  HBBTV_NotifyChannelChangeStatus(onet_id, ts_id, serv_id,
7452  HBBTV_CHANNEL_CHANGE_PARENTAL_LOCKED);
7453  }
7454 #endif
7455  }
7456  else if ((type == EXTERNAL_EVENT) &&
7457  ((event == STB_EVENT_VIDEO_DECODE_STARTED) || (event == STB_EVENT_AUDIO_DECODE_STARTED)))
7458  {
7459  video_status = STB_DPGetVideoStatus(path);
7460  audio_status = STB_DPGetAudioStatus(path);
7461 
7462  if ((video_status == DECODE_RUNNING) || (audio_status == DECODE_RUNNING))
7463  {
7464  if (video_status == DECODE_RUNNING)
7465  {
7466  STB_AVBlankVideo(0, FALSE);
7467 #ifdef COMMON_INTERFACE
7468  /* Re-evaluate usage rules */
7470 #endif
7471  }
7472 
7473  if ((video_status == DECODE_RUNNING) ||
7474  ((audio_status == DECODE_RUNNING) && (STB_DPGetVideoPID(path) == 0)))
7475  {
7476  #ifdef DEBUG_DECODING
7477  STB_SPDebugWrite(" new decode state(%d): Decoding", path);
7478  #endif
7479  decoding_state[path] = DSTATE_DECODING;
7480  }
7481  }
7482  }
7483  break;
7484  }
7485 
7486  case DSTATE_LOCKED:
7487  {
7488  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_RELEASE_DECODE_LOCK))
7489  {
7490  STB_DPSetLockEnable(path, FALSE);
7491  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7492  {
7493  if (path == STB_DPGetPlaybackPath())
7494  {
7495  STB_AVBlankVideo(0, FALSE);
7496  }
7497  #ifdef DEBUG_DECODING
7498  STB_SPDebugWrite(" new decode state(%d): Starting", path);
7499  #endif
7500  STB_DPStartDecoding(path);
7501  decoding_state[path] = DSTATE_STARTING;
7502  }
7503  else
7504  {
7505  #ifdef DEBUG_DECODING
7506  STB_SPDebugWrite(" new decode state(%d): Starting bad", path);
7507  #endif
7508  decoding_state[path] = DSTATE_STARTING_BAD_SIGNAL;
7509  }
7510  }
7511  break;
7512  }
7513 
7514  case DSTATE_DECODING:
7515  {
7516  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7517  {
7518  if (tuned_status[path] != TUNED_STATUS_GOOD_SIGNAL)
7519  {
7520  #ifdef DEBUG_DECODING
7521  STB_SPDebugWrite(" new decode state(%d): Signal pause", path);
7522  #endif
7523  if (STB_DPIsLivePath(path))
7524  {
7525  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_DECODE_PAUSED, &path, sizeof(U8BIT));
7526  }
7527  decoding_state[path] = DSTATE_PAUSED_SIGNAL;
7528  STB_DPStopDecoding(path);
7529  }
7530  }
7531  else if ((type == EXTERNAL_EVENT) && (event == STB_EVENT_VIDEO_DECODE_STARTED))
7532  {
7533  video_status = STB_DPGetVideoStatus(path);
7534 
7535  //the video unblanking belows applies to both live & playback path
7536  if ((video_status == DECODE_RUNNING) && STB_DPIsDecodingPath(path))
7537  {
7538  STB_AVBlankVideo(0, FALSE);
7539 #ifdef COMMON_INTERFACE
7540  /* Re-evaluate usage rules */
7542 #endif
7543  }
7544  }
7545  break;
7546  }
7547 
7548  case DSTATE_PAUSED_SIGNAL:
7549  {
7550  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7551  {
7552  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7553  {
7554  if (STB_DPIsLivePath(path))
7555  {
7556  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_DECODE_RESUMED, &path, sizeof(U8BIT));
7557  #ifdef DEBUG_DECODING
7558  STB_SPDebugWrite(" new decode state(%d): Decoding", path);
7559  #endif
7560  STB_DPStartDecoding(path);
7561  }
7562 
7563  decoding_state[path] = DSTATE_DECODING;
7564  }
7565  }
7566  break;
7567  }
7568 
7569  case DSTATE_PAUSED_USER:
7570  {
7571  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7572  {
7573  if (tuned_status[path] != TUNED_STATUS_GOOD_SIGNAL)
7574  {
7575  #ifdef DEBUG_DECODING
7576  STB_SPDebugWrite(" new decode state(%d): Signal/user pause", path);
7577  #endif
7578  decoding_state[path] = DSTATE_PAUSED_SIGNAL_AND_USER;
7579  }
7580  }
7581  break;
7582  }
7583 
7584  case DSTATE_PAUSED_SIGNAL_AND_USER:
7585  {
7586  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_UPDATE))
7587  {
7588  if (tuned_status[path] == TUNED_STATUS_GOOD_SIGNAL)
7589  {
7590  #ifdef DEBUG_DECODING
7591  STB_SPDebugWrite(" new decode state(%d): User pause", path);
7592  #endif
7593  decoding_state[path] = DSTATE_PAUSED_USER;
7594  }
7595  }
7596  break;
7597  }
7598  }
7599  }
7600 
7601  // update decoding_started flag
7602  decoding_started[path] = (decoding_state[path] >= DSTATE_DECODING);
7603 
7604  // update decoding_locked flag
7605  decoding_locked[path] = (decoding_state[path] == DSTATE_LOCKED);
7606 
7607  //update decoding paused flag
7608  decode_paused_flag[path] = (decoding_state[path] >= DSTATE_PAUSED_SIGNAL);
7609  }
7610 
7611  STB_OSMutexUnlock(cntrl_mutex[path]);
7612 
7613  FUNCTION_FINISH(ControlDecoding);
7614 }
7615 
7629 static void ControlAvOutput(E_ACTL_EVENT_TYPE type, U32BIT event)
7630 {
7631  U8BIT path;
7632  BOOLEAN scart_ip_changed_to_on;
7633  BOOLEAN scart_ip_changed_to_off;
7634  E_STB_AV_VIDEO_FORMAT actual_mode;
7635  U16BIT width, height;
7636 
7637  static BOOLEAN allow_alt_av_sources;
7638  static BOOLEAN scart_ip_present;
7639 
7640  FUNCTION_START(ControlAvOutput);
7641 
7642  #ifdef DEBUG_AV_OUTPUT
7643  {
7644  U8BIT *state_string;
7645  U8BIT *event_string;
7646 
7647  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_INITIALISE))
7648  {
7649  state_string = "Uninitialised";
7650  }
7651  else
7652  {
7653  switch (av_mode)
7654  {
7655  case ACTL_STANDBY_MODE: {state_string = "Standby"; break; }
7656  case ACTL_STANDBY_SCART_MODE: {state_string = "Standby, vcr i/p"; break; }
7657  case ACTL_TV_MODE: {state_string = "Tv mode"; break; }
7658  case ACTL_SCART_MODE: {state_string = "Vcr i/p mode"; break; }
7659  }
7660  }
7661  event_string = GetEventDebugString(type, event);
7662  STB_SPDebugWrite("ACTL_AvOutput(%s): %s", state_string, event_string);
7663  }
7664  #endif
7665 
7666  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_INITIALISE))
7667  {
7668  // tell app SI task about change in standby state
7669  ASI_SetStandbyState(FALSE);
7670 
7671  // initialisation...
7672  av_mode = ACTL_TV_MODE;
7673  allow_alt_av_sources = FALSE;
7674  scart_ip_present = FALSE;
7675  audio_muted = FALSE;
7676  audio_volume = (U8BIT)APP_NvmRead(VOLUME_NVM);
7677  ad_volume = (U8BIT)APP_NvmRead(AD_VOLUME_NVM);
7678 
7679  if (ACTL_IsHDMIConnected())
7680  {
7681  ACTL_UpdateVideoMode((E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), TRUE);
7682  }
7683 
7684  #ifdef INCLUDE_UHF_MODULATOR
7685  STB_AVSetUhfModulatorChannel((U8BIT)APP_NvmRead(RF_CHANNEL_NUM_NVM));
7686  #endif
7687 
7688  /* Set SPDIF and lip-sync settings */
7689  path = ACTL_GetActivePath();
7690  if (path != INVALID_RES_ID)
7691  {
7692  STB_AVSetSpdifMode(STB_DPGetPathAudioDecoder(path), (E_STB_DIGITAL_AUDIO_TYPE)APP_NvmRead(SPDIF_OUTPUT_NVM));
7693  STB_AVSetAudioDelay(STB_DPGetPathAudioDecoder(path), (U16BIT)APP_NvmRead(LIP_SYNC_ADJUSTMENT_NVM));
7694  STB_AVSetHDMIAudioMode(STB_DPGetPathAudioDecoder(path), (E_STB_DIGITAL_AUDIO_TYPE)APP_NvmRead(HDMI_AUDIO_OUTPUT_NVM));
7695  }
7696 
7697  STB_AVSetAudioMute(0, FALSE);
7698 
7699  AVSetAudioVolumes(FALSE);
7700 
7701  #ifdef DEBUG_AV_OUTPUT
7702  STB_SPDebugWrite(" new state: TV mode");
7703  #endif
7704  }
7705  else if ((type == INTERNAL_EVENT) && (event == INT_EVENT_ALT_AV_ALLOWED))
7706  {
7707  allow_alt_av_sources = TRUE;
7708  }
7709  else if ((type == INTERNAL_EVENT) && (event == INT_EVENT_ALT_AV_NOT_ALLOWED))
7710  {
7711  allow_alt_av_sources = FALSE;
7712  }
7713  else
7714  {
7715  scart_ip_changed_to_on = FALSE;
7716  scart_ip_changed_to_off = FALSE;
7717 #if 0
7718  if ((type == EXTERNAL_EVENT) && (event == STB_EVENT_SCART_FORCE))
7719  {
7720  scart_ip_changed_to_on = TRUE;
7721  scart_ip_present = TRUE;
7722  }
7723  else if ((type == EXTERNAL_EVENT) && (event == STB_EVENT_SCART_DISCONNECTED))
7724  {
7725  scart_ip_changed_to_off = TRUE;
7726  scart_ip_present = FALSE;
7727  }
7728 #endif
7729 
7730  switch (av_mode)
7731  {
7732  case ACTL_STANDBY_MODE:
7733  {
7734  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_STANDBY_OFF))
7735  {
7736  // tell app SI task about change in standby state
7737  ASI_SetStandbyState(FALSE);
7738  STB_AVSetHDMIStandby(FALSE);
7739 
7740  AVSetAudioVolumes(FALSE);
7741 
7742  // changing to TV mode
7743  #ifdef DEBUG_AV_OUTPUT
7744  STB_SPDebugWrite(" new state: Tv mode");
7745  #endif
7746  STB_AVSetAVOutput(TRUE);
7747  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, (E_STB_AV_SOURCES)APP_NvmRead(TV_SCART_TYPE_NVM), 0);
7748  DBGPRINT("");
7749  actual_mode = ACTL_GetActualVideoMode(&width, &height);
7750  STB_AVSetTVType(0, (E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), actual_mode);
7751  STB_AVSetAVOutputSource(AV_OUTPUT_VCR_SCART, AV_SOURCE_ENCODER_COMPOSITE, 0);
7752  av_mode = ACTL_TV_MODE;
7753  }
7754  else if (scart_ip_present == TRUE)
7755  {
7756  // change to standby/vcr ip mode and allow input from vcr scart
7757  #ifdef DEBUG_AV_OUTPUT
7758  STB_SPDebugWrite(" new state: Standby, vcr i/p");
7759  #endif
7760  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, AV_SOURCE_VCR_COMPOSITE, 0);
7761  av_mode = ACTL_STANDBY_SCART_MODE;
7762  }
7763  break;
7764  }
7765  case ACTL_STANDBY_SCART_MODE:
7766  {
7767  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_STANDBY_OFF))
7768  {
7769  // tell app SI task about change in standby state
7770  ASI_SetStandbyState(FALSE);
7771  STB_AVSetHDMIStandby(FALSE);
7772 
7773  AVSetAudioVolumes(FALSE);
7774 
7775  // changing to TV mode
7776  #ifdef DEBUG_AV_OUTPUT
7777  STB_SPDebugWrite(" new state: Tv mode");
7778  #endif
7779  STB_AVSetAVOutput(TRUE);
7780  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, (E_STB_AV_SOURCES)APP_NvmRead(TV_SCART_TYPE_NVM), 0);
7781  DBGPRINT("");
7782  STB_AVSetTVType(0, (E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), VIDEO_FORMAT_PALI);
7783  STB_AVSetAVOutputSource(AV_OUTPUT_VCR_SCART, AV_SOURCE_ENCODER_COMPOSITE, 0);
7784  av_mode = ACTL_TV_MODE;
7785  }
7786  else if (scart_ip_present == FALSE)
7787  {
7788  // change to standby mode and blank video output
7789  #ifdef DEBUG_AV_OUTPUT
7790  STB_SPDebugWrite(" new state: Standby");
7791  #endif
7792  STB_AVSetAVOutput(FALSE);
7793  STB_AVSetHDMIStandby(TRUE);
7794  av_mode = ACTL_STANDBY_MODE;
7795  }
7796  break;
7797  }
7798  case ACTL_TV_MODE:
7799  {
7800  if ((type == INTERNAL_EVENT) && (event == INT_EVENT_STANDBY_ON))
7801  {
7802  if (scart_ip_present == TRUE)
7803  {
7804  // changing to standby/vcr ip mode
7805  #ifdef DEBUG_AV_OUTPUT
7806  STB_SPDebugWrite(" new state: Standby, vcr i/p");
7807  #endif
7808  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, AV_SOURCE_VCR_COMPOSITE, 0);
7809  av_mode = ACTL_STANDBY_SCART_MODE;
7810  }
7811  else
7812  {
7813  // changing to normal standby mode
7814  #ifdef DEBUG_AV_OUTPUT
7815  STB_SPDebugWrite(" new state: Standby");
7816  #endif
7817  STB_AVSetAVOutput(FALSE);
7818  STB_AVSetHDMIStandby(TRUE);
7819  av_mode = ACTL_STANDBY_MODE;
7820  }
7821  // tell app SI task about change in standby state
7822  ASI_SetStandbyState(TRUE);
7823  }
7824  else if ((allow_alt_av_sources == TRUE) && (scart_ip_changed_to_on == TRUE))
7825  {
7826  // change to vcr ip mode
7827  #ifdef DEBUG_AV_OUTPUT
7828  STB_SPDebugWrite(" new state: Vcr i/p mode");
7829  #endif
7830  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, AV_SOURCE_VCR_COMPOSITE, 0);
7831  av_mode = ACTL_SCART_MODE;
7832  }
7833  break;
7834  }
7835  case ACTL_SCART_MODE:
7836  {
7837  if ((type == INTERNAL_EVENT) &&
7838  ((event == INT_EVENT_STANDBY_ON) || (event == INT_EVENT_STANDBY_VCR_ACTIVE)))
7839  {
7840  #ifdef DEBUG_AV_OUTPUT
7841  STB_SPDebugWrite(" new state: Standby, vcr i/p");
7842  #endif
7843  // tell app SI task about change in standby state
7844  if (event == INT_EVENT_STANDBY_VCR_ACTIVE)
7845  {
7846  STB_AVSetAudioMute(0, TRUE);
7847  STB_AVSetAVOutputSource(AV_OUTPUT_VCR_SCART, AV_SOURCE_ENCODER_COMPOSITE, 0);
7848  }
7849  else
7850  {
7851  ASI_SetStandbyState(TRUE);
7852  }
7853  av_mode = ACTL_STANDBY_SCART_MODE;
7854  }
7855  else if (scart_ip_changed_to_off == TRUE)
7856  {
7857  // change to tv mode
7858  #ifdef DEBUG_AV_OUTPUT
7859  STB_SPDebugWrite(" new state: Tv mode");
7860  #endif
7861  STB_AVSetAVOutputSource(AV_OUTPUT_TV_SCART, (E_STB_AV_SOURCES)APP_NvmRead(TV_SCART_TYPE_NVM), 0);
7862  DBGPRINT("");
7863  STB_AVSetTVType(0, (E_STB_AV_ASPECT_RATIO)APP_NvmRead(ASPECT_RATIO_NVM), VIDEO_FORMAT_PALI);
7864  STB_AVSetAVOutputSource(AV_OUTPUT_VCR_SCART, AV_SOURCE_ENCODER_COMPOSITE, 0);
7865  av_mode = ACTL_TV_MODE;
7866  }
7867  break;
7868  }
7869  default:
7870  break;
7871  }
7872  }
7873 
7874  FUNCTION_FINISH(ControlAvOutput);
7875 }
7876 
7888 static void AVSetAudioVolumes(BOOLEAN save_to_nvm)
7889 {
7890  U8BIT path;
7891 
7892  path = ACTL_GetActivePath();
7893  if ((path == INVALID_RES_ID) || !STB_DPIsDecodingPath(path))
7894  {
7895  path = STB_DPGetPlaybackPath();
7896  }
7897 
7898  if (path != INVALID_RES_ID)
7899  {
7900  S16BIT scaled_vol = 0;
7901  S16BIT ad_scaled_vol = 0;
7902 
7903  if(audio_muted == FALSE)
7904  {
7905  scaled_vol = audio_volume + (volume_scaling * audio_volume)/100;
7906  if(scaled_vol < 0)
7907  scaled_vol = 0;
7908  if(scaled_vol > 100)
7909  scaled_vol = 100;
7910 
7911  ad_scaled_vol = ad_volume + (volume_scaling * ad_volume)/100;
7912  if(ad_scaled_vol < 0)
7913  ad_scaled_vol = 0;
7914  if(ad_scaled_vol > 100)
7915  ad_scaled_vol = 100;
7916  }
7917 
7919  STB_AVSetADVolume(STB_DPGetPathAudioDecoder(path), ad_scaled_vol);
7920  }
7921 
7922  if (save_to_nvm)
7923  {
7924  /* Save the unscaled volume levels whether the actual volume was able to be set or not */
7925  APP_NvmSave(VOLUME_NVM, audio_volume, TRUE);
7926  APP_NvmSave(AD_VOLUME_NVM, ad_volume, TRUE);
7927  }
7928 }
7929 
7930 /*!**************************************************************************
7931  * @brief Acquires a decode path for live signal for the given service
7932  * @param s_ptr the service the decode path will be used for
7933  * @param with_decoders TRUE if decoders are to be allocated
7934  * @param for_recording TRUE if the path will be used for recording
7935  * @param owner_info owner of the decode path
7936  * @return ID of path or INVALID_RES_ID on failure
7937  ****************************************************************************/
7938 static U8BIT AcquirePathForService(void *s_ptr, BOOLEAN with_decoders, BOOLEAN for_recording,
7939  S_ACTL_OWNER_INFO *owner_info)
7940 {
7941  void *t_ptr;
7942  E_STB_DP_SIGNAL_TYPE sig_type;
7943  U8BIT path;
7944  E_STB_DP_RES_OWNER owner;
7945 
7946  FUNCTION_START(AcquirePathForService);
7947 
7948  path = INVALID_RES_ID;
7949 
7950  /* Get the transport for the service to find out what tuner's required */
7951  t_ptr = ADB_GetServiceTransportPtr(s_ptr);
7952  if (t_ptr != NULL)
7953  {
7954  sig_type = ADB_GetTransportSignalType(t_ptr);
7955 
7956  if (owner_info != NULL)
7957  {
7958  owner = owner_info->owner;
7959  }
7960  else
7961  {
7962  owner = RES_OWNER_NONE;
7963  }
7964 
7965  path = STB_DPAcquireTunerPath(sig_type, s_ptr, t_ptr, owner, DP_PRIORITY_LOW, with_decoders,
7966  for_recording);
7967  if ((path != INVALID_RES_ID) && (owner_info != NULL))
7968  {
7969  STB_DPSetOwnerData(path, owner_info->data, owner_info->data_size);
7970  }
7971  }
7972 
7973  FUNCTION_FINISH(AcquirePathForService);
7974 
7975  return(path);
7976 }
7977 
7978 /*!**************************************************************************
7979  * @brief Function to handle events received during a service search
7980  * @param path - decode path being used for the search
7981  * @param event - event that caused this function to be called
7982  ****************************************************************************/
7983 static void ContinueServiceSearch(U8BIT path, U32BIT event)
7984 {
7985  void **tlist;
7986  U16BIT num_transports;
7987  void *t_ptr;
7988  S_MANUAL_TUNING_PARAMS tune_params;
7989 
7990  FUNCTION_START(ContinueServiceSearch);
7991 
7992  if ((required_search_type == SEARCH_TYPE_SERVICE_NETWORK) ||
7993  (required_search_type == SEARCH_TYPE_MANUAL_NETWORK))
7994  {
7995  ADB_GetTransportList(&tlist, &num_transports);
7996  }
7997  else
7998  {
7999  tlist = NULL;
8000  num_transports = 0;
8001  }
8002 
8003  if (event == STB_EVENT_TUNE_NOTLOCKED)
8004  {
8005  /* Report no signal to the SI task */
8006  if (((t_ptr = ADB_GetTunedTransport(path)) == NULL) && (tlist != NULL))
8007  {
8008  t_ptr = tlist[search_list_id];
8009  }
8010 
8011  if (t_ptr != NULL)
8012  {
8014  }
8015  if (signal_type_required == SIGNAL_COFDM)
8016  {
8017  if (ACTL_GetTerRfChanType(search_list_id) == TERR_TYPE_DVBT2)
8018  {
8019  /* Handle T2 PLP tuning */
8020  if ((terr_hierarchy != TUNE_THIERARCHY_NONE) && (t2_plp_id > 1))
8021  {
8022  /* Try tuning to the next PLP on this same frequency */
8023  t2_plp_id--;
8024  STB_DPSetTerrPLP(path, t2_plp_id);
8025  }
8026  else
8027  {
8028  /* Finished tuning to each possible PLP on this frequency,
8029  * so move to the next channel */
8030  search_list_id = NextSearchId(tlist, num_transports);
8031  terr_hierarchy = TUNE_THIERARCHY_NONE;
8032  }
8033  }
8034  else
8035  {
8036  /* DVB-T channel, so nothing else to do; move to next channel */
8037  terr_hierarchy = TUNE_THIERARCHY_NONE;
8038  t2_plp_id = 0;
8039  STB_DPSetTerrPLP(path, t2_plp_id);
8040  search_list_id = NextSearchId(tlist, num_transports);
8041  }
8042  }
8043  else
8044  {
8045  /* Move to next channel */
8046  search_list_id = NextSearchId(tlist, num_transports);
8047  }
8048 
8049  if (current_search_type == SEARCH_TYPE_SERVICE_FREQ)
8050  {
8051  if (((signal_type_required == SIGNAL_QPSK) && (search_list_id < GetNumSatSearchIds())) ||
8052  (search_list_id < ACTL_GetNumRfChanArrayEntries(signal_type_required)))
8053  {
8054  switch (signal_type_required)
8055  {
8056  case SIGNAL_ANALOG:
8057  /* Not finished yet - tune to next channel */
8058  ACTL_TuneToRfChanArrayAnalogEntry(path, search_list_id);
8059  break;
8060  case SIGNAL_COFDM:
8061  /* Not finished yet - tune to next channel or PLP */
8062  ACTL_TuneToRfChanArrayEntry(path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
8063  break;
8064  case SIGNAL_QAM:
8065  /* Not finished yet - tune to next channel */
8066  ACTL_TuneToRfChanArrayEntry(path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
8067  break;
8068  case SIGNAL_QPSK:
8069  /* Not finished yet - map the search list id to the next set of tuning params */
8070  MapIdToSatTuneParams(search_list_id, &tune_params);
8071  ACTL_TuneToUserDefinedParams(path, &tune_params, ACTL_SI_CHANNEL_SEARCH, FALSE);
8072  break;
8073  default:
8074  break;
8075  }
8076  }
8077  else
8078  {
8079  /* No more channels so search has finished */
8080  EndSearch(path);
8081  }
8082  }
8083  else if ((current_search_type == SEARCH_TYPE_SERVICE_NETWORK) ||
8084  (current_search_type == SEARCH_TYPE_MANUAL_NETWORK))
8085  {
8086 #ifdef DEBUG_SERVICE_SEARCH
8087  STB_SPDebugWrite("Tuning to transport %u of %u", search_list_id, num_transports);
8088 #endif
8089  if ((search_list_id < num_transports) && tlist)
8090  {
8091  ACTL_TuneToTransport(path, NULL, tlist[search_list_id], ACTL_SI_CHANNEL_SEARCH_NO_NIT, FALSE);
8092  }
8093  else
8094  {
8095  /* No more transports to search */
8096  EndSearch(path);
8097  }
8098  }
8099 
8100  if (!ASTE_InStandby())
8101  {
8102  /* Send event to update the UI */
8103  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8104  }
8105  }
8106  else if ((event == STB_EVENT_SEARCH_SUCCESS) || (event == STB_EVENT_SEARCH_FAIL))
8107  {
8108  t_ptr = ADB_GetTunedTransport(path);
8109  if (t_ptr != NULL)
8110  {
8111  /* Indicate that this transport has now been used during the search */
8112  ADB_SetTransportSearchFlag(t_ptr, TRUE);
8113  }
8114  if ((signal_type_required == SIGNAL_COFDM) &&
8115  (ACTL_GetTerRfChanType(search_list_id) == TERR_TYPE_DVBT2))
8116  {
8117  if (terr_hierarchy == TUNE_THIERARCHY_NONE)
8118  {
8119  /* Query the hierarchy to see how many PLPs are on this frequency and
8120  * try tuning to each one, starting at the maximum value */
8121  terr_hierarchy = STB_TuneGetActualTerrHierarchy(STB_DPGetPathTuner(path));
8122  if ((terr_hierarchy != TUNE_THIERARCHY_NONE) &&
8123  (terr_hierarchy > TUNE_THIERARCHY_NONE))
8124  {
8125  /* The hierarchy value returned is the maximum PLP id to be used */
8126  t2_plp_id = (U8BIT)terr_hierarchy;
8127  STB_DPSetTerrPLP(path, t2_plp_id);
8128  }
8129  else
8130  {
8131  if (current_search_type == SEARCH_TYPE_MANUAL_FREQ)
8132  {
8133  /* Search has finished */
8134  FinishManualSearch(path, event);
8135  }
8136  else
8137  {
8138  /* Just a single PLP on this frequency so move to next channel */
8139  search_list_id = NextSearchId(tlist, num_transports);
8140  terr_hierarchy = TUNE_THIERARCHY_NONE;
8141  }
8142  }
8143  }
8144  else if (t2_plp_id > 1)
8145  {
8146  t2_plp_id--;
8147  STB_DPSetTerrPLP(path, t2_plp_id);
8148  }
8149  else
8150  {
8151  /* Finished tuning to each possible PLP on this frequency */
8152  if (current_search_type == SEARCH_TYPE_MANUAL_FREQ)
8153  {
8154  /* No more PLPs, so search has completed */
8155  FinishManualSearch(path, event);
8156  }
8157  else
8158  {
8159  /* Move to the next channel */
8160  search_list_id = NextSearchId(tlist, num_transports);
8161  terr_hierarchy = TUNE_THIERARCHY_NONE;
8162  t2_plp_id = 0;
8163  STB_DPSetTerrPLP(path, t2_plp_id);
8164  }
8165  }
8166  }
8167  else
8168  {
8169  /* Nothing else to do; move to next channel */
8170  search_list_id = NextSearchId(tlist, num_transports);
8171  }
8172 
8173  if ((current_search_type == SEARCH_TYPE_SERVICE_FREQ) ||
8174  (current_search_type == SEARCH_TYPE_MANUAL_FREQ))
8175  {
8176  if (((signal_type_required == SIGNAL_QPSK) && (search_list_id < GetNumSatSearchIds())) ||
8177  (search_list_id < ACTL_GetNumRfChanArrayEntries(signal_type_required)))
8178  {
8179  switch (signal_type_required)
8180  {
8181  case SIGNAL_ANALOG:
8182  /* Not finished yet - tune to next channel */
8183  ACTL_TuneToRfChanArrayAnalogEntry(path, search_list_id);
8184  break;
8185  case SIGNAL_COFDM:
8186  /* Not finished yet - tune to next channel or PLP */
8187  ACTL_TuneToRfChanArrayEntry(path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
8188  break;
8189  case SIGNAL_QAM:
8190  /* Not finished yet - tune to next channel */
8191  ACTL_TuneToRfChanArrayEntry(path, search_list_id, ACTL_SI_CHANNEL_SEARCH, FALSE);
8192  break;
8193  case SIGNAL_QPSK:
8194  /* Not finished yet - map the search list id to the next set of tuning params */
8195  MapIdToSatTuneParams(search_list_id, &tune_params);
8196  ACTL_TuneToUserDefinedParams(path, &tune_params, ACTL_SI_CHANNEL_SEARCH, FALSE);
8197  break;
8198  default:
8199  break;
8200  }
8201  }
8202  else
8203  {
8204  /* No more channels so search has finished */
8205  EndSearch(path);
8206  }
8207  }
8208  else if ((current_search_type == SEARCH_TYPE_SERVICE_NETWORK) ||
8209  (current_search_type == SEARCH_TYPE_MANUAL_NETWORK))
8210  {
8211 #ifdef DEBUG_SERVICE_SEARCH
8212  STB_SPDebugWrite("Tuning to transport %u of %u", search_list_id, num_transports);
8213 #endif
8214  if (search_list_id < num_transports)
8215  {
8216  ACTL_TuneToTransport(path, NULL, tlist[search_list_id], ACTL_SI_CHANNEL_SEARCH_NO_NIT, FALSE);
8217  }
8218  else
8219  {
8220  /* No more transports to search */
8221  EndSearch(path);
8222  }
8223  }
8224 
8225  if (!ASTE_InStandby())
8226  {
8227  /* Send event to update the UI */
8228  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8229  }
8230  }
8231 
8232  if (tlist != NULL)
8233  {
8234  ADB_ReleaseTransportList(tlist, num_transports);
8235  }
8236 
8237  FUNCTION_FINISH(ContinueServiceSearch);
8238 }
8239 
8240 /*!**************************************************************************
8241  * @brief Checks for the switch from frequency search to network search and returns
8242  * the next search id as appropriate.
8243  * @return Next search id that should be used
8244  ****************************************************************************/
8245 static U16BIT NextSearchId(void **tlist, U16BIT num_transports)
8246 {
8247  U16BIT next_id;
8248 
8249  FUNCTION_START(NextSearchId);
8250 
8251  next_id = search_list_id;
8252 
8253  if ((required_search_type == SEARCH_TYPE_SERVICE_NETWORK) &&
8254  (current_search_type == SEARCH_TYPE_SERVICE_FREQ) && tlist)
8255  {
8256  /* Check to see if any transports have been added via delivery descriptors. If they have,
8257  * they won't have been searched yet */
8258  for (next_id = 0; next_id < num_transports; )
8259  {
8260  if (!ADB_GetTransportSearchFlag(tlist[next_id]))
8261  {
8262  /* Found a transport that hasn't been searched yet,
8263  * so take this as the switch to network search mode */
8264  current_search_type = SEARCH_TYPE_SERVICE_NETWORK;
8265  break;
8266  }
8267  else
8268  {
8269  next_id++;
8270  }
8271  }
8272 
8273  if (current_search_type != SEARCH_TYPE_SERVICE_NETWORK)
8274  {
8275  next_id = search_list_id + 1;
8276  }
8277  }
8278  else
8279  {
8280  if (((current_search_type == SEARCH_TYPE_SERVICE_NETWORK) ||
8281  (current_search_type == SEARCH_TYPE_MANUAL_NETWORK)) && tlist)
8282  {
8283  /* Find the next transport that hasn't been searched */
8284  for (; (next_id < num_transports) && ADB_GetTransportSearchFlag(tlist[next_id]); next_id++)
8285  ;
8286  }
8287  else
8288  {
8289  next_id++;
8290  }
8291  }
8292 
8293  FUNCTION_FINISH(NextSearchId);
8294 
8295  return(next_id);
8296 }
8297 
8298 static U16BIT GetNumSatSearchIds(void)
8299 {
8300  U32BIT country_code;
8301  U16BIT max_scan_ids;
8302 
8303  FUNCTION_START(GetNumSatSearchIds);
8304 
8305  country_code = ACFG_GetCountry();
8306 
8307  max_scan_ids = (ACFG_GetMaxSatelliteScanFreq(country_code) -
8308  ACFG_GetMinSatelliteScanFreq(country_code)) / ACFG_GetSatelliteScanFreqInc(country_code) + 1;
8309  max_scan_ids *= ACFG_GetSatelliteScanNumSymbolRates(country_code);
8310  max_scan_ids *= 2; /* For horizontal and vertical */
8311  if (ACFG_GetSatelliteScanDvbS2(country_code))
8312  {
8313  max_scan_ids *= 2;
8314  }
8315 
8316  FUNCTION_FINISH(GetNumSatSearchIds);
8317 
8318  return(max_scan_ids);
8319 }
8320 
8321 static void MapIdToSatTuneParams(U16BIT search_id, S_MANUAL_TUNING_PARAMS *tuning_params)
8322 {
8323  U32BIT country_code;
8324  U16BIT num_tunes_per_freq;
8325  U16BIT num_tunes_per_srate;
8326  U8BIT srate_id;
8327  U16BIT *srates;
8328 
8329  FUNCTION_START(MapIdToSatTuneParams);
8330 
8331  country_code = ACFG_GetCountry();
8332 
8333  /* Tune to horizontal and vertical for each symbol rate */
8334  num_tunes_per_srate = 2;
8335  if (ACFG_GetSatelliteScanDvbS2(country_code))
8336  {
8337  num_tunes_per_srate *= 2;
8338  }
8339 
8340  num_tunes_per_freq = num_tunes_per_srate * ACFG_GetSatelliteScanNumSymbolRates(country_code);
8341 
8342  tuning_params->freq = ACFG_GetMinSatelliteScanFreq(country_code) + (search_id / num_tunes_per_freq) *
8343  ACFG_GetSatelliteScanFreqInc(country_code);
8344 
8345  srate_id = (search_id % num_tunes_per_freq);
8346  srates = ACFG_GetSatelliteScanSymbolRates(country_code);
8347 
8348  tuning_params->u.sat.symbol_rate = srates[srate_id / num_tunes_per_srate];
8349 
8350  if ((srate_id % 2) == 0)
8351  {
8352  tuning_params->u.sat.polarity = POLARITY_HORIZONTAL;
8353  }
8354  else
8355  {
8356  tuning_params->u.sat.polarity = POLARITY_VERTICAL;
8357  }
8358 
8359  if (ACFG_GetSatelliteScanDvbS2(country_code))
8360  {
8361  if (((srate_id % 4) / 2) == 0)
8362  {
8363  tuning_params->u.sat.dvb_s2 = FALSE;
8364  }
8365  else
8366  {
8367  tuning_params->u.sat.dvb_s2 = TRUE;
8368  }
8369  }
8370  else
8371  {
8372  tuning_params->u.sat.dvb_s2 = FALSE;
8373  }
8374 
8375  tuning_params->u.sat.fec = FEC_AUTOMATIC;
8376  tuning_params->u.sat.modulation = MOD_QPSK;
8377  tuning_params->u.sat.satellite = ADB_GetNextSatellite(NULL);
8378 
8379 #ifdef DEBUG_SERVICE_SEARCH
8380  STB_SPDebugWrite("%s(%u): f=%u, sr=%u, p=%u, s2=%u", __FUNCTION__, search_id, tuning_params->freq,
8381  tuning_params->u.sat.symbol_rate, tuning_params->u.sat.polarity, tuning_params->u.sat.dvb_s2);
8382 #endif
8383 
8384  FUNCTION_FINISH(MapIdToSatTuneParams);
8385 }
8386 
8387 static void ReleasePath(U8BIT path)
8388 {
8389  FUNCTION_START(ReleasePath);
8390 
8391  /* Release the path being used */
8392  STB_DPReleasePath(path, RES_OWNER_DVB);
8393  if (search_path == path)
8394  {
8395  search_path = INVALID_RES_ID;
8396  }
8397 
8398  FUNCTION_FINISH(ReleasePath);
8399 }
8400 
8401 /*!**************************************************************************
8402  * @brief Called at the end of a service search to finalise the database and
8403  * determine whether a target region needs to be chosen to finish the search.
8404  ****************************************************************************/
8405 static void EndSearch(U8BIT path)
8406 {
8407  FUNCTION_START(EndSearch);
8408 
8409  /* Stop SI processing and release the path being used for the search */
8410  if (path != INVALID_RES_ID)
8411  {
8412  STB_DPStopSI(path);
8413  ReleasePath(path);
8414 
8416 
8417  /* Ensure first boot is false and set searching state to false */
8418  APP_NvmSave(FIRST_BOOT_NVM, (U32BIT)FALSE, FALSE);
8419  APP_NvmSave(SEARCHING_STATE_NVM, (U32BIT)FALSE, TRUE);
8420 
8421  current_search_type = SEARCH_TYPE_NOSEARCH;
8422  required_search_type = SEARCH_TYPE_NOSEARCH;
8423 
8424  if (ASTE_InStandby())
8425  {
8426  /* Was performing a background search in standby so re-enter standby
8427  * to see if anything else needs to be done */
8429 
8430  /* Although events aren't sent for each transport during a service search when in standby,
8431  * do send one now the search has finished as it was the app that started the search
8432  * and so needs to be informed that it's now finished */
8433  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8434  }
8435  }
8436 
8437  FUNCTION_FINISH(EndSearch);
8438 }
8439 
8440 /*!**************************************************************************
8441  * @brief Function to handle events received during a transport search (e.g. startup, SSU)
8442  * @param path - decode path being used for the search
8443  ****************************************************************************/
8444 static void ContinueTransportSearch(U8BIT path)
8445 {
8446  void **tlist;
8447  U16BIT num_transports;
8448  BOOLEAN search_complete;
8449 
8450  FUNCTION_START(ContinueTransportSearch);
8451 
8452  search_complete = FALSE;
8453  search_list_id++;
8454 
8455  if (search_list_id < search_num_transports)
8456  {
8457  ADB_GetTransportListForTunerType(current_search_tuner_type, &tlist, &num_transports);
8458 
8459  /* Release the current path and acquire one suitable for the next transport */
8460  STB_DPReleasePath(path, RES_OWNER_DVB);
8461 
8462  do
8463  {
8464  path = STB_DPAcquireTunerPath(ADB_GetTransportSignalType(tlist[search_list_id]),
8465  NULL, NULL, RES_OWNER_DVB, DP_PRIORITY_LOW, FALSE, FALSE);
8466 
8467  if (path == INVALID_RES_ID)
8468  {
8469  /* No tuner exists for this type of transport!
8470  * Try the next one */
8471  search_list_id++;
8472  }
8473  }
8474  while ((path == INVALID_RES_ID) && (search_list_id < search_num_transports));
8475 
8476  if (path != INVALID_RES_ID)
8477  {
8478  /* Next transport */
8479  switch (current_search_type)
8480  {
8481  case SEARCH_TYPE_STARTUP:
8482  ACTL_TuneToTransport(path, NULL, tlist[search_list_id], ACTL_SI_STARTUP_SEARCH, FALSE);
8483  break;
8484  case SEARCH_TYPE_TOT:
8485  ACTL_TuneToTransport(path, NULL, tlist[search_list_id], ACTL_SI_TOT_SEARCH, FALSE);
8486  break;
8487  case SEARCH_TYPE_SSU:
8488  ACTL_TuneToTransport(path, NULL, tlist[search_list_id], ACTL_SI_DVB_SSU_SEARCH, FALSE);
8489  break;
8490 
8491  default:
8492  /* Unknown search type so finish search */
8493  current_search_type = SEARCH_TYPE_NOSEARCH;
8494  required_search_type = SEARCH_TYPE_NOSEARCH;
8495  current_search_tuner_type = SIGNAL_NONE;
8496  break;
8497  }
8498  }
8499  else
8500  {
8501  /* Search has completed */
8502  current_search_type = SEARCH_TYPE_NOSEARCH;
8503  required_search_type = SEARCH_TYPE_NOSEARCH;
8504  current_search_tuner_type = SIGNAL_NONE;
8505  }
8506 
8507  ADB_ReleaseTransportList(tlist, num_transports);
8508  }
8509  else
8510  {
8511  /* Finished */
8512  required_search_type = SEARCH_TYPE_NOSEARCH;
8513 
8514  /* Release the path being used */
8515  ReleasePath(path);
8516 
8517  if (current_search_type == SEARCH_TYPE_SSU)
8518  {
8519  /* SSU search in standby will have been started by the app, so it needs to decide whether
8520  * to go back into standby */
8521  current_search_type = SEARCH_TYPE_NOSEARCH;
8522  current_search_tuner_type = SIGNAL_NONE;
8523 
8524  if (ASTE_InStandby())
8525  {
8527 
8528  search_complete = TRUE;
8529  }
8530  }
8531  else
8532  {
8533  current_search_type = SEARCH_TYPE_NOSEARCH;
8534  current_search_tuner_type = SIGNAL_NONE;
8535 
8536  if (ASTE_InStandby())
8537  {
8538  /* Was performing a background search in standby so re-enter standby
8539  * to see if anything else needs to be done */
8542 
8543  search_complete = TRUE;
8544  }
8545  }
8546  }
8547 
8548  /* A startup search will be done when in standby so the event wants to be sent otherwise
8549  * the UI won't know when the search completes */
8550  if (!ASTE_InStandby() || (ASTE_InStandby() && search_complete))
8551  {
8552  /* Send event to update the UI */
8553  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8554  }
8555 
8556  FUNCTION_FINISH(ContinueTransportSearch);
8557 }
8558 
8559 static BOOLEAN StartEitSearch(void)
8560 {
8561  BOOLEAN search_started;
8562  void *t_ptr;
8563  E_ACTL_SI_SRCH_REQD si_search;
8564 
8565  FUNCTION_START(StartEitSearch);
8566 
8567  for (search_started = FALSE; (search_list_id < search_num_transports) && !search_started; search_list_id++)
8568  {
8569  t_ptr = search_transport_list[search_list_id];
8570 
8571  search_path = STB_DPAcquireTunerPath(ADB_GetTransportSignalType(t_ptr), NULL, t_ptr,
8572  RES_OWNER_DVB, DP_PRIORITY_LOW, FALSE, FALSE);
8573  if (search_path != INVALID_RES_ID)
8574  {
8575  EIT_DBG(("%s: Tuning to transport %u of %u, freq %lu", __FUNCTION__,
8576  search_list_id, search_num_transports, ADB_GetTransportFreqHz(t_ptr)));
8577 
8578  switch (current_search_type)
8579  {
8580  case SEARCH_TYPE_EIT_PF:
8581  si_search = ACTL_SI_EVENT_PF_SEARCH;
8582  break;
8583  case SEARCH_TYPE_EIT_SCHED:
8584  si_search = ACTL_SI_EVENT_SCHED_SEARCH;
8585  break;
8586  case SEARCH_TYPE_EIT_PF_SCHED:
8587  si_search = ACTL_SI_EVENT_PF_SCHED_SEARCH;
8588  break;
8589  case SEARCH_TYPE_NOSEARCH:
8590  default:
8591  si_search = ACTL_SI_NO_SEARCH;
8592  break;
8593  }
8594 
8595  if (si_search != ACTL_SI_NO_SEARCH)
8596  {
8597  ACTL_TuneToTransport(search_path, NULL, t_ptr, si_search, TRUE);
8598  search_started = TRUE;
8599  }
8600  }
8601  }
8602 
8603  FUNCTION_FINISH(StartEitSearch);
8604 
8605  return(search_started);
8606 }
8607 
8608 static void ContinueEitSearch(U8BIT path)
8609 {
8610  BOOLEAN search_started;
8611 
8612  FUNCTION_START(ContinueEitSearch);
8613 
8614  if (path != INVALID_RES_ID)
8615  {
8616  ACTL_TuneOff(path);
8617  ReleasePath(path);
8618  path = INVALID_RES_ID;
8619  }
8620 
8621  search_started = StartEitSearch();
8622  if (!search_started)
8623  {
8624  FinishEitSearch(path);
8625  if (ASTE_InStandby())
8626  {
8627  /* Was performing an EIT search in standby so re-enter standby
8628  * to see if anything else needs to be done */
8630  }
8631  }
8632 
8633  FUNCTION_FINISH(ContinueEitSearch);
8634 }
8635 
8636 /*!**************************************************************************
8637  * @brief Function to handle events received during a manual search
8638  * @param path - decode path being used for the search
8639  * @param event - event that caused this function to be called
8640  ****************************************************************************/
8641 static void FinishManualSearch(U8BIT path, U32BIT event)
8642 {
8643  void *t_ptr;
8644 
8645  FUNCTION_START(FinishManualSearch);
8646 
8647  if (event == STB_EVENT_TUNE_NOTLOCKED)
8648  {
8649  if ((t_ptr = ADB_GetTunedTransport(path)) != NULL)
8650  {
8652  }
8653 
8654  ACTL_TuneOff(path);
8655 
8656  /* Search finished */
8657  current_search_type = SEARCH_TYPE_NOSEARCH;
8658  required_search_type = SEARCH_TYPE_NOSEARCH;
8659 
8660  ReleasePath(path);
8661  }
8662  else if ((event == STB_EVENT_SEARCH_SUCCESS) || (event == STB_EVENT_SEARCH_FAIL))
8663  {
8664  if ((t_ptr = ADB_GetTunedTransport(path)) != NULL)
8665  {
8666  ADB_SetTransportSearchFlag(t_ptr, TRUE);
8667  }
8668 
8669  ACTL_TuneOff(path);
8670 
8671  /* Search finished */
8672  current_search_type = SEARCH_TYPE_NOSEARCH;
8673  required_search_type = SEARCH_TYPE_NOSEARCH;
8674 
8675  ReleasePath(path);
8676  }
8677 
8678  /* Send event to update the UI */
8679  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8680 
8681  FUNCTION_FINISH(FinishManualSearch);
8682 }
8683 
8684 /*!**************************************************************************
8685  * @brief Stops a search, tunes off and releases the path
8686  * @param path - decode path being used for the search
8687  ****************************************************************************/
8688 static void FinishSearch(U8BIT path)
8689 {
8690  FUNCTION_START(FinishSearch);
8691 
8692  current_search_type = SEARCH_TYPE_NOSEARCH;
8693  current_search_tuner_type = SIGNAL_NONE;
8694  required_search_type = SEARCH_TYPE_NOSEARCH;
8695 
8696  ACTL_TuneOff(path);
8697 #if defined(DEBUG_TOT_SEARCH) || defined(DEBUG_EIT_SEARCH)
8698  STB_SPDebugWrite("FinishSearch stopping SI");
8699 #endif
8700 
8701  if (path != INVALID_RES_ID)
8702  {
8703  STB_DPStopSI(path);
8704  ReleasePath(path);
8705  }
8706 
8707  /* Send event to update the UI */
8708  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_UI, EV_TYPE_UPDATE, NULL, 0);
8709 
8710  FUNCTION_FINISH(FinishSearch);
8711 }
8712 
8720 static BOOLEAN GetNextEitSearchTime(U32DHMS *next)
8721 {
8722  U32DHMS last_eit_srch;
8723  U16BIT n_of_searches;
8724  U8BIT ohour, omin;
8725  U16BIT time_mins;
8726  U32DHMS next_srch_gmt;
8727  BOOLEAN srch_needed;
8728 
8729  last_eit_srch = (U32DHMS)APP_NvmRead(LAST_EIT_UPDATE_NVM);
8730 
8731  if (last_eit_srch == 0)
8732  {
8733  EIT_DBG(("GetNextEitSearchTime: never searched before"));
8734  /* Never searched before, start counting from now */
8735  last_eit_srch = GetDateTimeNow();
8736  APP_NvmSave(LAST_EIT_UPDATE_NVM, last_eit_srch, TRUE);
8737  }
8738 
8739  n_of_searches = ACFG_GetEitSearchesPerDay();
8740  if (n_of_searches > 0)
8741  {
8742  srch_needed = TRUE;
8743 
8744  time_mins = ((24 * 60)-1) / n_of_searches; /* time to wait in minutes */
8745  ohour = time_mins / 60;
8746  omin = time_mins % 60;
8747 
8748  EIT_DBG(("GetNextEitSearchTime: last day=%d time=%02u:%02u n_of_searches=%d, time to wait h=%d m=%d",
8749  DHMS_DATE(last_eit_srch), DHMS_HOUR(last_eit_srch), DHMS_MINS(last_eit_srch),
8750  n_of_searches, ohour, omin));
8751 
8752  *next = STB_GCCalculateDHMS(last_eit_srch, DHMS_CREATE(0, ohour, omin, 0), CALC_ADD);
8753 
8754  /* EIT search time is local, so convert to GMT to see if it's in the future */
8755  next_srch_gmt = STB_GCConvertDHMS(*next, CONV_GMT);
8756 
8757  if (!STB_GCIsFutureDateTime(DHMS_DATE(next_srch_gmt), DHMS_HOUR(next_srch_gmt),
8758  DHMS_MINS(next_srch_gmt), 0))
8759  {
8760  /* Last search was missed, so a search is needed now */
8761  *next = STB_GCNowDHMSLocal();
8762  }
8763  }
8764  else
8765  {
8766  srch_needed = FALSE;
8767  }
8768 
8769  return(srch_needed);
8770 }
8771 
8772 static BOOLEAN EitSearchNeededNow(void)
8773 {
8774  U32DHMS next_eit_srch;
8775  U32DHMS now_local;
8776  BOOLEAN retval = FALSE;
8777 
8778  if (GetNextEitSearchTime(&next_eit_srch))
8779  {
8780  now_local = STB_GCNowDHMSLocal();
8781 
8782  if (next_eit_srch <= now_local)
8783  {
8784  /* Search needs to be start immediately */
8785  retval = TRUE;
8786  }
8787  }
8788 
8789  return retval;
8790 }
8791 
8792 /*!**************************************************************************
8793  * @brief
8794  * @return
8795  ****************************************************************************/
8796 static BOOLEAN EnterStandby(void **recording_service)
8797 {
8798  BOOLEAN enter_standby;
8799  U32DHMS now_local;
8800  U8BIT day, wday, month;
8801  U16BIT year;
8802  BOOLEAN wakeup_for_search;
8803  U32DHMS wakeup_date_time;
8804  U32BIT time_diff;
8805  BOOLEAN wakeup_for_recording;
8806  U16BIT onet_id, trans_id, service_id;
8807  BOOLEAN standby_set;
8808  E_STB_DP_SIGNAL_TYPE tuner_type;
8809 
8810  FUNCTION_START(EnterStandby);
8811 
8812  enter_standby = FALSE;
8813  *recording_service = NULL;
8814 
8815  standby_set = FALSE;
8816 
8817  while (!standby_set)
8818  {
8819  standby_set = TRUE;
8820 
8821  now_local = GetDateTimeNow();
8822  if (DHMS_DATE(now_local) == 0)
8823  {
8824  /* Entering standby before date/time has been set, so it isn't possible to work out
8825  * what should be done, so all we can do is go into standby */
8826  enter_standby = TRUE;
8827  break;
8828  }
8829 
8830  GetNextWakeupTime(&wakeup_date_time, &wakeup_for_search, &tuner_type,
8831  &wakeup_for_recording, &onet_id, &trans_id, &service_id);
8832 
8833  DBG_STDBY(("EnterStandby: time now=%u@%02u:%02u, wakeup=%u@%02u:%02u",
8834  DHMS_DATE(now_local), DHMS_HOUR(now_local), DHMS_MINS(now_local),
8835  DHMS_DATE(wakeup_date_time), DHMS_HOUR(wakeup_date_time), DHMS_MINS(wakeup_date_time)));
8836 
8837  /* Is the current date/time within the wakeup time? */
8838  if ((!wakeup_for_search && !wakeup_for_recording) || (wakeup_date_time > now_local))
8839  {
8840  /* No search to be started now, so go into standby */
8841  enter_standby = TRUE;
8842 
8843  STB_PVRSetStandbyState(TRUE);
8845 
8846  /* Save state to indicate the reason for the next wakeup */
8847  if (wakeup_for_recording)
8848  {
8849  DBG_STDBY(("%s: Setting wakeup for recording", __FUNCTION__));
8850  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_WAKE_FOR_RECORDING, TRUE);
8851  }
8852  else if (wakeup_for_search)
8853  {
8854  DBG_STDBY(("%s: Setting wakeup for search", __FUNCTION__));
8855  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_WAKE_FOR_SEARCH, TRUE);
8856  }
8857  else
8858  {
8859  DBG_STDBY(("%s: No wakeup needed", __FUNCTION__));
8860  APP_NvmSave(STANDBY_STATE_NVM, (U32BIT)STDBY_STANDBY, TRUE);
8861  }
8862 
8863  /* Update the RTC in the front panel with the current local time */
8864  now_local = GetDateTimeNow();
8865  STB_GCGetDateInfo(DHMS_DATE(now_local), DHMS_HOUR(now_local), DHMS_MINS(now_local),
8866  &day, &wday, &month, &year);
8867 
8868  STB_FPSetClock(DHMS_DATE(now_local), year, month, day, DHMS_DATE(now_local),
8869  DHMS_DATE(now_local), DHMS_DATE(now_local));
8870 
8871 #ifdef DEBUG_STANDBY
8872  if (wakeup_for_search || wakeup_for_recording)
8873  {
8874  STB_GCGetDateInfo(DHMS_DATE(wakeup_date_time), DHMS_HOUR(wakeup_date_time),
8875  DHMS_MINS(wakeup_date_time), &day, &wday, &month, &year);
8876  DBG_STDBY(("%s: Wakeup date/time= %02u/%02u/%u @ %02u:%02u", __FUNCTION__,
8877  day, month, year, DHMS_HOUR(wakeup_date_time), DHMS_MINS(wakeup_date_time)));
8878  }
8879 #endif
8880 
8881  if ((BOOLEAN)APP_NvmRead(STANDBY_POWERSAVE_NVM))
8882  {
8883  /* Powersave mode is enabled */
8884  if (wakeup_for_search || wakeup_for_recording)
8885  {
8886  /* Calculate the difference between the current time and the wakeup time in minutes */
8887  time_diff = (DHMS_DATE(wakeup_date_time) - DHMS_DATE(now_local)) * 24 * 60 +
8888  (DHMS_HOUR(wakeup_date_time) - DHMS_HOUR(now_local)) * 60 +
8889  (DHMS_MINS(wakeup_date_time) - DHMS_MINS(now_local));
8890 
8891  /* If the wakeup time is very soon, or any time up to when the grace standby period
8892  * will expire, then don't bother going into passive or low power standby */
8893  if ((time_diff < 2) || (time_diff <= (U32BIT)(standby_grace_timeout + 59) / 60))
8894  {
8895  enter_standby = FALSE;
8896 
8897  /* Create a private timer set for the wakeup time */
8898  standby_wakeup_timer = CreateTimer(STB_GCConvertDHMS(wakeup_date_time, CONV_GMT));
8899  }
8900  else
8901  {
8902  /* Set the wakeup time */
8903  STB_GCGetDateInfo(DHMS_DATE(wakeup_date_time), DHMS_HOUR(wakeup_date_time),
8904  DHMS_MINS(wakeup_date_time), &day, &wday, &month, &year);
8905 
8906  STB_HWSetWakeUpTime(DHMS_DATE(wakeup_date_time), year, month, day,
8907  DHMS_HOUR(wakeup_date_time), DHMS_MINS(wakeup_date_time), time_diff);
8908  }
8909  }
8910  }
8911  else
8912  {
8913  if (wakeup_for_search || wakeup_for_recording)
8914  {
8915  /* Create a private timer set for the wakeup time */
8916  standby_wakeup_timer = CreateTimer(STB_GCConvertDHMS(wakeup_date_time, CONV_GMT));
8917  }
8918  }
8919  }
8920  else
8921  {
8922  enter_standby = FALSE;
8923 
8924  if (wakeup_for_recording)
8925  {
8926  /* Not going into standby because recording will be started soon.
8927  * Return the service to be recorded */
8928  *recording_service = ADB_FindServiceByIds(onet_id, trans_id, service_id);
8929  DBG_STDBY(("%s: Recording to be started", __FUNCTION__));
8930  }
8931  else if (wakeup_for_search)
8932  {
8933  DBG_STDBY(("%s: Search being started for tuner_type %u", __FUNCTION__, tuner_type));
8934 
8935  if (!StartSearch(tuner_type))
8936  {
8937  /* Should have started a search but the search failed,
8938  * so will need to work out what should be started instead */
8939  standby_set = FALSE;
8940  }
8941  }
8942  }
8943  }
8944 
8945  FUNCTION_FINISH(EnterStandby);
8946 
8947  return(enter_standby);
8948 }
8949 
8950 #ifdef COMMON_INTERFACE
8951 
8955 static void CIPowerDownReadyCallback(void)
8956 {
8957  FUNCTION_START(CIPowerDownReadyCallback);
8958 
8959  if (start_standby_time < STB_GCNowDHMSGmt() &&
8960  standby_grace_timer != INVALID_TIMER_HANDLE)
8961  {
8962  ATMR_DeleteTimer(standby_grace_timer);
8963  standby_grace_timer = INVALID_TIMER_HANDLE;
8964 
8965  DBG_STDBY(("Standby grace time with CI expired"));
8966 
8967  if ((BOOLEAN)APP_NvmRead(STANDBY_POWERSAVE_NVM))
8968  {
8969  /* Put box into low-power standby mode */
8970  DBG_STDBY(("Entering low power standby"));
8971  STB_HWSetStandbyState(HW_STANDBY_LOWPOWER);
8972  }
8973  else
8974  {
8975  /* Nothing is being started so go into the lowest active standby state */
8976  DBG_STDBY(("Entering passive standby"));
8977  STB_HWSetStandbyState(HW_STANDBY_PASSIVE);
8978  }
8979  }
8980 
8981  FUNCTION_FINISH(CIPowerDownReadyCallback);
8982 }
8983 
8984 #endif /*COMMON_INTERFACE*/
8985 
9003 static void GetNextWakeupTime(U32DHMS *wakeup_date_time, BOOLEAN *wakeup_for_search,
9004  E_STB_DP_SIGNAL_TYPE *search_tuner_type, BOOLEAN *wakeup_for_recording, U16BIT *onet_id,
9005  U16BIT *trans_id, U16BIT *service_id)
9006 {
9007  U32DHMS now_local;
9008  U16BIT search_date;
9009  U8BIT search_hours, search_mins;
9010  U16BIT time_mins;
9011  U16BIT last_service_srch;
9012  U16BIT background_search_start;
9013  U16BIT background_search_end;
9014  BOOLEAN service_search_enabled;
9015  BOOLEAN ssu_search_enabled;
9016  BOOLEAN eit_search_enabled;
9017  U16BIT last_update_srch;
9018  U8BIT hours, mins, secs;
9019  U16BIT date;
9020  U32BIT timer_handle;
9021  U32DHMS recording_wakeup;
9022  U32DHMS now_offset;
9023 #ifdef COMMON_INTERFACE
9024  U32BIT module;
9025  U32BIT time_diff;
9026 #endif
9027 
9028  FUNCTION_START(GetNextWakeupTime);
9029 
9030  /* Read from NVM when updates were last performed */
9031  last_service_srch = (U16BIT)APP_NvmRead(LAST_CHAN_SRCH_NVM);
9032  last_update_srch = (U16BIT)APP_NvmRead(OTA_LAST_UPDATE_SRCH_NVM);
9033 
9034  now_local = GetDateTimeNow();
9035 
9036  /* The number of minutes since midnight */
9037  time_mins = DHMS_HOUR(now_local) * 60 + DHMS_MINS(now_local);
9038 
9039  DBG_STDBY(("%s: today=%u time=%02u:%02u", __FUNCTION__, DHMS_DATE(now_local),
9040  DHMS_HOUR(now_local), DHMS_MINS(now_local)));
9041  DBG_STDBY((" last service search=%u", last_service_srch));
9042  DBG_STDBY((" last SSU search=%u", last_update_srch));
9043 
9044  /* Work out whether something should be started now or when the next operation needs to be performed */
9045  *wakeup_for_search = FALSE;
9046  *wakeup_for_recording = FALSE;
9047 
9048  service_search_enabled = ACFG_GetBackgroundServiceSearch();
9049  ssu_search_enabled = ACFG_GetBackgroundSSUSearch();
9050 
9051  ACFG_GetBackgroundSearchTime(&background_search_start, &background_search_end);
9052 
9053  DBG_STDBY(("%s: background_search_start=%d background_search_end=%d", __FUNCTION__,
9054  background_search_start, background_search_end));
9055 
9056  /* First calculate when the box should wakeup to do the next service, SSU or EIT search */
9057  if ((((last_service_srch == DHMS_DATE(now_local)) || !service_search_enabled) &&
9058  ((last_update_srch == DHMS_DATE(now_local)) || (APP_NvmRead(OTA_TYPE_NVM) != OTA_TYPE_AUTO) ||
9059  !ssu_search_enabled)) || (time_mins >= background_search_end))
9060  {
9061  /* Next time to search is tomorrow */
9062  search_date = DHMS_DATE(now_local) + 1;
9063  }
9064  else
9065  {
9066  /* Search can be done today */
9067  search_date = DHMS_DATE(now_local);
9068  }
9069 
9070  search_hours = background_search_start / 60;
9071  search_mins = background_search_start - (search_hours * 60);
9072 
9073  if (APP_NvmRead(STANDBY_STATE_NVM) == STDBY_POWER_ON)
9074  {
9075  /* If we're entering stand-by from POWER_ON state, reset the last EIT search time,
9076  as during power on the EITs have been collected */
9077  DBG_STDBY(("%s: resetting last EIT search to today", __FUNCTION__));
9078  APP_NvmSave(LAST_EIT_UPDATE_NVM, now_local, FALSE);
9079  }
9080 
9081 #ifdef FREEVIEW_PLAYBACK
9082  eit_search_enabled = TRUE;
9083 #else
9084  eit_search_enabled = FALSE;
9085 #endif
9086 
9087  /* Calculate when the box should wakeup for the next alarm or recording */
9088  timer_handle = ATMR_GetFirstWakeupTime(&recording_wakeup, onet_id, trans_id, service_id);
9089  if (timer_handle != INVALID_TIMER_HANDLE)
9090  {
9091  *wakeup_for_recording = TRUE;
9092  }
9093  else
9094  {
9095  *wakeup_for_recording = FALSE;
9096  }
9097 
9098  if (*wakeup_for_recording)
9099  {
9100  DBG_STDBY(("%s: Next wakeup on service 0x%04x/0x%04x/0x%04x on %u @ %02u:%02u",
9101  __FUNCTION__, *onet_id, *trans_id, *service_id, DHMS_DATE(recording_wakeup),
9102  DHMS_HOUR(recording_wakeup), DHMS_MINS(recording_wakeup)));
9103 
9104  if (ATMR_GetType(timer_handle) == TIMER_TYPE_PVR_RECORD)
9105  {
9106  /* Convert the wakeup time to local time and subtract 15 minutes to
9107  * ensure any updates to the event are detected */
9108  recording_wakeup = CalculateWakeupTime(recording_wakeup);
9109  }
9110 
9111  /* Work out which comes first, the recording or the search */
9112  if ((!service_search_enabled && !ssu_search_enabled && !eit_search_enabled) ||
9113  (recording_wakeup <= DHMS_CREATE(search_date, search_hours, search_mins, 0)) ||
9114  (recording_wakeup <= now_local))
9115  {
9116  /* Need to wakeup for recording first */
9117  *wakeup_date_time = recording_wakeup;
9118  }
9119  else
9120  {
9121  /* Search time is earlier, but make sure it isn't too close to the recording */
9122  STB_GCCalculateDateTime(search_date, search_hours, search_mins, 0, 0, 30, 0,
9123  &date, &hours, &mins, &secs, CALC_ADD);
9124 
9125  if (recording_wakeup <= DHMS_CREATE(date, hours, mins, secs))
9126  {
9127  /* There may not be time to do the search, so wakeup for recording first */
9128  *wakeup_date_time = recording_wakeup;
9129  }
9130  else
9131  {
9132  *search_tuner_type = SIGNAL_NONE;
9133 
9134  if (ACFG_IsNordigCountry())
9135  {
9136  if (ACFG_IsNordigService(SIGNAL_COFDM) && ASI_CheckForServiceChange(SIGNAL_COFDM))
9137  {
9138  DBG_STDBY(("%s: DVB-T service line-up may have changed", __FUNCTION__));
9139  *search_tuner_type = SIGNAL_COFDM;
9140  }
9141  else if (ACFG_IsNordigService(SIGNAL_QPSK) && ASI_CheckForServiceChange(SIGNAL_QPSK))
9142  {
9143  DBG_STDBY(("%s: DVB-S service line-up may have changed", __FUNCTION__));
9144  *search_tuner_type = SIGNAL_QPSK;
9145  }
9146  else if (ACFG_IsNordigService(SIGNAL_QAM) && ASI_CheckForServiceChange(SIGNAL_QAM))
9147  {
9148  DBG_STDBY(("%s: DVB-C service line-up may have changed", __FUNCTION__));
9149  *search_tuner_type = SIGNAL_QAM;
9150  }
9151 
9152  if (*search_tuner_type == SIGNAL_NONE)
9153  {
9154  /* No search needed so next wakeup is for the recording */
9155  *wakeup_date_time = recording_wakeup;
9156  }
9157  else
9158  {
9159  /* There's enough time to do the search, so set its wakeup time 2 minutes from
9160  * now so it doesn't start as soon as standby is entered, allowing time for
9161  * a user to exit standby */
9162  now_offset = STB_GCCalculateDHMS(now_local, DHMS_CREATE(0, 0, 2, 0), CALC_ADD);
9163  search_date = DHMS_DATE(now_offset);
9164  search_hours = DHMS_HOUR(now_offset);;
9165  search_mins = DHMS_MINS(now_offset);
9166 
9167  *wakeup_date_time = DHMS_CREATE(search_date, search_hours, search_mins, 0);
9168  *wakeup_for_recording = FALSE;
9169  *wakeup_for_search = TRUE;
9170  }
9171  }
9172  else
9173  {
9174  *wakeup_date_time = recording_wakeup;
9175  }
9176  }
9177  }
9178  }
9179  else
9180  {
9181  *search_tuner_type = SIGNAL_NONE;
9182 
9183  if (service_search_enabled && ACFG_IsNordigCountry())
9184  {
9185  if (ACFG_IsNordigService(SIGNAL_COFDM) && ASI_CheckForServiceChange(SIGNAL_COFDM))
9186  {
9187  DBG_STDBY(("%s: DVB-T service line-up may have changed", __FUNCTION__));
9188  *search_tuner_type = SIGNAL_COFDM;
9189  }
9190  else if (ACFG_IsNordigService(SIGNAL_QPSK) && ASI_CheckForServiceChange(SIGNAL_QPSK))
9191  {
9192  DBG_STDBY(("%s: DVB-S service line-up may have changed", __FUNCTION__));
9193  *search_tuner_type = SIGNAL_QPSK;
9194  }
9195  else if (ACFG_IsNordigService(SIGNAL_QAM) && ASI_CheckForServiceChange(SIGNAL_QAM))
9196  {
9197  DBG_STDBY(("%s: DVB-C service line-up may have changed", __FUNCTION__));
9198  *search_tuner_type = SIGNAL_QAM;
9199  }
9200  }
9201 
9202  if (((service_search_enabled || ssu_search_enabled) && (*search_tuner_type != SIGNAL_NONE))
9203  || eit_search_enabled)
9204  {
9205  /* Wakeup for the next update search so set its wakeup time 2 minutes from
9206  * now so it doesn't start as soon as standby is entered, allowing time for
9207  * a user to exit standby */
9208  now_offset = STB_GCCalculateDHMS(now_local, DHMS_CREATE(0, 0, 2, 0), CALC_ADD);
9209  search_date = DHMS_DATE(now_offset);
9210  search_hours = DHMS_HOUR(now_offset);;
9211  search_mins = DHMS_MINS(now_offset);
9212 
9213  *wakeup_date_time = DHMS_CREATE(search_date, search_hours, search_mins, 0);
9214  *wakeup_for_search = TRUE;
9215  }
9216  else
9217  {
9218  /* No reason to wakeup, just down to the user */
9219  *wakeup_date_time = DHMS_CREATE(0, 0, 0, 0);
9220  *wakeup_for_search = FALSE;
9221  }
9222  }
9223 
9224 #ifdef COMMON_INTERFACE
9225  /* Calculate the difference between the current time and the wakeup time in minutes */
9226  time_diff = (DHMS_DATE(*wakeup_date_time) - DHMS_DATE(now_local)) * 24 * 60 +
9227  (DHMS_HOUR(*wakeup_date_time) - DHMS_HOUR(now_local)) * 60 +
9228  (DHMS_MINS(*wakeup_date_time) - DHMS_MINS(now_local));
9229 
9230  /* Allow 30 minutes before any other search or recording needs to be started
9231  * before checking if an operator profile search needs to be started */
9232  if (!(*wakeup_for_search) || (time_diff > 30))
9233  {
9234  /* Check whether an operator search needs to be started immediately.
9235  * This will be true if a CAM has requested an update search and it isn't urgent
9236  * or the user rejected the request to run it at the time. In either case, it
9237  * may now be possible to run it. */
9239  {
9240  /* Set the date/time so the search starts now */
9241  *wakeup_date_time = now_local;
9242  *wakeup_for_search = TRUE;
9243  }
9244  else
9245  {
9246  /* Check if there are any profiles that need to be updated at a scheduled time */
9247  if (ACI_GetFirstScheduledOperatorSearch(&module, &search_date, &search_hours, &search_mins))
9248  {
9249  /* Allow 30 minutes to complete the operator search */
9250  STB_GCCalculateDateTime(search_date, search_hours, search_mins, 0, 0, 30, 0,
9251  &date, &hours, &mins, &secs, CALC_ADD);
9252 
9253  if ((*wakeup_date_time == 0) ||
9254  (DHMS_CREATE(date, hours, mins, 0) <= *wakeup_date_time))
9255  {
9256  /* The operator search can be started first */
9257  *wakeup_date_time = DHMS_CREATE(search_date, search_hours, search_mins, 0);
9258  *wakeup_for_search = TRUE;
9259  }
9260  }
9261  }
9262  }
9263  else
9264  {
9265  /* Check if there are any profiles that need to be updated at a scheduled time */
9266  if (ACI_GetFirstScheduledOperatorSearch(&module, &search_date, &search_hours, &search_mins))
9267  {
9268  /* Allow 30 minutes to complete the operator search */
9269  STB_GCCalculateDateTime(search_date, search_hours, search_mins, 0, 0, 30, 0,
9270  &date, &hours, &mins, &secs, CALC_ADD);
9271 
9272  if ((*wakeup_date_time == 0) ||
9273  (DHMS_CREATE(date, hours, mins, 0) <= *wakeup_date_time))
9274  {
9275  /* The operator search can be started first */
9276  *wakeup_date_time = DHMS_CREATE(search_date, search_hours, search_mins, 0);
9277  *wakeup_for_search = TRUE;
9278  }
9279  }
9280  }
9281 #endif
9282 
9283  DBG_STDBY(("%s: wakeup on %u@%02u:%02u", __FUNCTION__, DHMS_DATE(*wakeup_date_time),
9284  DHMS_HOUR(*wakeup_date_time), DHMS_MINS(*wakeup_date_time)));
9285 
9286  FUNCTION_FINISH(GetNextWakeupTime);
9287 }
9288 
9289 /*!**************************************************************************
9290  * @brief Checks whether a service or SSU search should be started, based on the
9291  * current date and time of day, and starts the search if required.
9292  * @return TRUE if search is started, FALSE otherwise
9293  ****************************************************************************/
9294 static BOOLEAN StartSearch(E_STB_DP_SIGNAL_TYPE tuner_type)
9295 {
9296  BOOLEAN search_started;
9297  U32DHMS now_local;
9298  U16BIT time_mins;
9299  U16BIT last_service_srch;
9300  U16BIT background_search_start;
9301  U16BIT background_search_end;
9302  U16BIT last_update_srch;
9303  #ifdef DEBUG_STANDBY
9304  U32DHMS last_eit_srch;
9305  #endif
9306  #ifdef COMMON_INTERFACE
9307  U32BIT module;
9308  U16BIT search_date;
9309  U8BIT search_hours, search_mins;
9310  U8BIT gmt_hours, gmt_mins;
9311  #endif
9312 
9313  FUNCTION_START(StartSearch);
9314 
9315  search_started = FALSE;
9316 
9317  if (tuner_type != SIGNAL_NONE)
9318  {
9319  /* Check whether a service update search should be started now */
9320  now_local = GetDateTimeNow();
9321 
9322  /* Number of minutes since midnight */
9323  time_mins = DHMS_HOUR(now_local) * 60 + DHMS_MINS(now_local);
9324 
9325  ACFG_GetBackgroundSearchTime(&background_search_start, &background_search_end);
9326 
9327  /* Read from NVM when updates were last performed */
9328  last_service_srch = (U16BIT)APP_NvmRead(LAST_CHAN_SRCH_NVM);
9329  last_update_srch = (U16BIT)APP_NvmRead(OTA_LAST_UPDATE_SRCH_NVM);
9330 #ifdef DEBUG_STANDBY
9331  last_eit_srch = (U32DHMS)APP_NvmRead(LAST_EIT_UPDATE_NVM);
9332 #endif
9333  DBG_STDBY(("%s: today=%u", __FUNCTION__, DHMS_DATE(now_local)));
9334  DBG_STDBY((" last service search=%u, enabled=%u", last_service_srch,
9336  DBG_STDBY((" last SSU search=%u, enabled=%u", last_update_srch, ACFG_GetBackgroundSSUSearch()));
9337  DBG_STDBY((" last EIT update=%u@%02u:%02u, needed=%u", DHMS_DATE(last_eit_srch),
9338  DHMS_HOUR(last_eit_srch), DHMS_MINS(last_eit_srch), EitSearchNeededNow()));
9339 
9340  if ((ACFG_IsNordigCountry() && ACFG_IsNordigService(tuner_type) && ASI_CheckForServiceChange(tuner_type)) ||
9341  (ACFG_GetBackgroundServiceSearch() && (last_service_srch != DHMS_DATE(now_local)) &&
9342  ((background_search_start <= time_mins) && (time_mins < background_search_end))))
9343  {
9344  /* Inform the app that a service search needs to be started */
9345  DBG_STDBY(("Sending request to start service search"));
9346  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_START_SERVICE_SEARCH,
9347  &tuner_type, sizeof(E_STB_DP_SIGNAL_TYPE));
9348  search_started = TRUE;
9349  }
9350 
9351  if (!search_started && ACFG_GetBackgroundSSUSearch() &&
9352  (APP_NvmRead(OTA_TYPE_NVM) == OTA_TYPE_AUTO) &&
9353  (last_update_srch != DHMS_DATE(now_local)) &&
9354  ((background_search_start <= time_mins) && (time_mins < background_search_end)))
9355  {
9356  /* An SSU search needs to be performed, so inform the app so it can start it */
9357  DBG_STDBY(("Sending request to start an SSU search"));
9358  STB_ERSendEvent(FALSE, FALSE, EV_CLASS_APPLICATION, EV_START_SSU_SEARCH, NULL, 0);
9359  search_started = TRUE;
9360  }
9361 
9362  if (!search_started && EitSearchNeededNow())
9363  {
9364  /* Start EIT update search */
9365 
9366  /* Save the date the search is being performed. This is set even if it doesn't start
9367  * successfully to prevent it constantly retrying */
9368  APP_NvmSave(LAST_EIT_UPDATE_NVM, now_local, TRUE);
9369 
9370  if (ACTL_StartEitSearch(SIGNAL_NONE, ACTL_EVENT_SEARCH_PF_SCHED))
9371  {
9372  if (ASTE_InStandby())
9373  {
9374  DBG_STDBY(("Setting STANDBY_STATE_NVM=STDBY_UPDATE_SEARCH"));
9375  APP_NvmSave(STANDBY_STATE_NVM, STDBY_UPDATE_SEARCH, FALSE);
9376  }
9377 
9378  search_started = TRUE;
9379  }
9380  }
9381 
9382 #ifdef COMMON_INTERFACE
9383  if (!search_started)
9384  {
9386  {
9387  DBG_STDBY(("Starting immediate CI+ operator profile search"));
9388 
9389  /* An operator search needs to be started immediately */
9391  {
9392  search_started = TRUE;
9393  }
9394  }
9395  else if (ACI_GetFirstOperatorSearchModule(&module))
9396  {
9397  DBG_STDBY(("Starting CI+ operator profile search for module %u", module));
9398 
9399  /* A module has requested an operator search but it
9400  * hasn't been run yet, so start it now */
9402  {
9403  search_started = TRUE;
9404  }
9405  }
9406  else
9407  {
9408  /* Check whether it's time to start a scheduled operator search */
9409  if (ACI_GetFirstScheduledOperatorSearch(&module, &search_date, &search_hours, &search_mins))
9410  {
9411  gmt_hours = time_mins / 60;
9412  gmt_mins = time_mins % 60;
9413 
9414  if (STB_GCCompareDateTime(DHMS_DATE(now_local), gmt_hours, gmt_mins, 0,
9415  search_date, search_hours, search_mins, 0, COMP_1GE2))
9416  {
9417  DBG_STDBY(("Starting scheduled CI+ operator profile search for module %u", module));
9418 
9419  /* The operator search for this module needs to be started */
9421  {
9422  search_started = TRUE;
9423  }
9424  }
9425  }
9426  }
9427  }
9428 #endif
9429  }
9430 
9431  FUNCTION_FINISH(StartSearch);
9432 
9433  return(search_started);
9434 }
9435 
9440 static U32DHMS GetDateTimeNow(void)
9441 {
9442  U32DHMS local_time;
9443 
9444  FUNCTION_START(GetDateTimeNow);
9445 
9446  local_time = STB_GCNowDHMSLocal();
9447 
9448  FUNCTION_FINISH(GetDateTimeNow);
9449 
9450  return(local_time);
9451 }
9452 
9459 static U32DHMS CalculateWakeupTime(U32DHMS date_time)
9460 {
9461  U32DHMS wakeup;
9462 
9463  FUNCTION_START(CalculateWakeupTime);
9464 
9465  wakeup = STB_GCConvertDHMS(date_time, CONV_LOCAL);
9466  wakeup = STB_GCCalculateDHMS(wakeup, DHMS_CREATE(0, 0, 15, 0), CALC_SUB);
9467 
9468  FUNCTION_FINISH(CalculateWakeupTime);
9469 
9470  return(wakeup);
9471 }
9472 
9473 static void FinishEitSearch(U8BIT path)
9474 {
9475  EIT_DBG(("FinishEitSearch(%u)", path));
9476 
9477  if (eit_search_end_timer != INVALID_TIMER_HANDLE)
9478  {
9479  ATMR_DeleteTimer(eit_search_end_timer);
9480  eit_search_end_timer = INVALID_TIMER_HANDLE;
9481  }
9482 
9483  FinishSearch(path);
9484 
9485  ADB_ReleaseTransportList(search_transport_list, search_num_transports);
9486  search_transport_list = NULL;
9487  search_num_transports = 0;
9488 }
9489 
9490 static void UpdateTransportParameters(U8BIT path)
9491 {
9492  U8BIT tuner;
9493  ADB_TRANSPORT_REC *t_ptr;
9494  E_STB_DP_TMODE tmode;
9495  E_STB_DP_TBWIDTH bwidth;
9496  E_STB_DP_TTYPE terr_type;
9497  E_STB_DP_CMODE cmode;
9498  U32BIT srate;
9499 
9500  FUNCTION_START(UpdateTransportParameters);
9501 
9502  tuner = STB_DPGetPathTuner(path);
9503  if (tuner != INVALID_RES_ID)
9504  {
9505  if ((t_ptr = current_transport[path]) == NULL)
9506  {
9507  t_ptr = ADB_GetTunedTransport(path);
9508  }
9509 
9510  if (t_ptr != NULL)
9511  {
9513 
9514  switch (t_ptr->sig_type)
9515  {
9516  case SIGNAL_COFDM:
9517  {
9518  t_ptr->u.terr.freq_offset = STB_TuneGetActualTerrFreqOffset(tuner);
9519  t_ptr->u.terr.constellation = STB_TuneGetActualTerrConstellation(tuner);
9520  t_ptr->u.terr.hierarchy = STB_TuneGetActualTerrHierarchy(tuner);
9521  t_ptr->u.terr.lp_code_rate = STB_TuneGetActualTerrLpCodeRate(tuner);
9522  t_ptr->u.terr.hp_code_rate = STB_TuneGetActualTerrHpCodeRate(tuner);
9523  t_ptr->u.terr.guard_int = STB_TuneGetActualTerrGuardInt(tuner);
9524  switch (STB_TuneGetActualTerrMode(tuner))
9525  {
9526  case TUNE_MODE_COFDM_1K: {tmode = MODE_COFDM_1K; break; }
9527  case TUNE_MODE_COFDM_2K: {tmode = MODE_COFDM_2K; break; }
9528  case TUNE_MODE_COFDM_4K: {tmode = MODE_COFDM_4K; break; }
9529  case TUNE_MODE_COFDM_8K: {tmode = MODE_COFDM_8K; break; }
9530  case TUNE_MODE_COFDM_16K: {tmode = MODE_COFDM_16K; break; }
9531  case TUNE_MODE_COFDM_32K: {tmode = MODE_COFDM_32K; break; }
9532  default: {tmode = MODE_COFDM_UNDEFINED; break; }
9533  }
9534  if (t_ptr->u.terr.tmode != tmode)
9535  {
9536  t_ptr->u.terr.tmode = tmode;
9537  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TTRAN_MODE, tmode);
9538  }
9539 
9540  switch (STB_TuneGetActualTerrBwidth(tuner))
9541  {
9542  case TUNE_TBWIDTH_8MHZ: {bwidth = TBWIDTH_8MHZ; break; }
9543  case TUNE_TBWIDTH_7MHZ: {bwidth = TBWIDTH_7MHZ; break; }
9544  case TUNE_TBWIDTH_6MHZ: {bwidth = TBWIDTH_6MHZ; break; }
9545  default: {bwidth = 0; break; }
9546  }
9547  if (t_ptr->u.terr.bwidth != bwidth)
9548  {
9549  t_ptr->u.terr.bwidth = bwidth;
9550  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TTRAN_BWIDTH, bwidth);
9551  }
9552 
9553  switch (STB_TuneGetSystemType(tuner))
9554  {
9555  case TUNE_SYSTEM_TYPE_DVBT2: {terr_type = TERR_TYPE_DVBT2; break; }
9556  case TUNE_SYSTEM_TYPE_DVBT: {terr_type = TERR_TYPE_DVBT; break; }
9557  default: {terr_type = TERR_TYPE_UNKNOWN; break; }
9558  }
9559 
9560  if (t_ptr->u.terr.terr_type != terr_type)
9561  {
9562  t_ptr->u.terr.terr_type = terr_type;
9563  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TTRAN_TERR_TYPE, terr_type);
9564  }
9565  break;
9566  }
9567  case SIGNAL_QAM:
9568  {
9569  /* Symbol rate is stored in Ksym/sec */
9570  if ((srate = STB_TuneGetActualSymbolRate(tuner)) != SYMBOL_RATE_AUTO)
9571  {
9572  srate = srate / 1000;
9573 
9574  if (t_ptr->u.cab.symbol_rate != srate)
9575  {
9576  t_ptr->u.cab.symbol_rate = srate;
9577  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRAN_SRATE, srate);
9578  }
9579  }
9580 
9581  switch (STB_TuneGetActualCableMode(tuner))
9582  {
9583  case TUNE_MODE_QAM_4: {cmode = MODE_QAM_4; break; }
9584  case TUNE_MODE_QAM_8: {cmode = MODE_QAM_8; break; }
9585  case TUNE_MODE_QAM_16: {cmode = MODE_QAM_16; break; }
9586  case TUNE_MODE_QAM_32: {cmode = MODE_QAM_32; break; }
9587  case TUNE_MODE_QAM_64: {cmode = MODE_QAM_64; break; }
9588  case TUNE_MODE_QAM_128: {cmode = MODE_QAM_128; break; }
9589  case TUNE_MODE_QAM_256: {cmode = MODE_QAM_256; break; }
9590  default: {cmode = MODE_QAM_AUTO; break; }
9591  }
9592  if (t_ptr->u.cab.cmode != cmode)
9593  {
9594  t_ptr->u.cab.cmode = cmode;
9595  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_CTRAN_MODE, cmode);
9596  }
9597  break;
9598  }
9599  case SIGNAL_QPSK:
9600  {
9601  /* Symbol rate is stored in Ksym/sec */
9602  if ((srate = STB_TuneGetActualSymbolRate(tuner)) != SYMBOL_RATE_AUTO)
9603  {
9604  srate = srate / 1000;
9605 
9606  if (t_ptr->u.sat.symbol_rate != srate)
9607  {
9608  t_ptr->u.sat.symbol_rate = (U16BIT)srate;
9609  DBA_SetFieldValue(t_ptr->dba_rec, DBA_FIELD_TRAN_SRATE, srate);
9610  }
9611  }
9612  break;
9613  }
9614  default:
9615  {
9616  break;
9617  }
9618  }
9619 
9621 
9622  ADB_SaveDatabase();
9623  }
9624  }
9625 
9626  FUNCTION_FINISH(UpdateTransportParameters);
9627 }
9628 
9629 static U32BIT CreateTimer(U32DHMS date_time)
9630 {
9631  U32BIT handle;
9632  S_TIMER_INFO timer_info;
9633 
9634  FUNCTION_START(CreateTimer);
9635 
9636  /* Initialise the timer info, set the date/time the timer is to trigger and create the timer */
9637  ATMR_InitialiseTimer(&timer_info, TIMER_TYPE_PRIVATE, NULL, NULL);
9638 
9639  timer_info.start_time = date_time;
9640  timer_info.ram_only = TRUE;
9641 
9642  handle = ATMR_AddTimer(&timer_info);
9643 
9644  FUNCTION_FINISH(CreateTimer);
9645 
9646  return(handle);
9647 }
9648 
9649 //**************************************************************************************************
9650 // End of File
9651 //**************************************************************************************************
void STB_DPSetDISEQCSMATV(U8BIT path, BOOLEAN state)
Enables/disables DiSEqC SMATV and writes status into decode path store.
Definition: stbdpc.c:5046
void STB_DPStartDecoding(U8BIT path)
Requests start of channel decoding process.
Definition: stbdpc.c:2686
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
BOOLEAN STB_DPSetVideoCodec(U8BIT path, E_STB_DP_VIDEO_CODEC codec)
Sets the type of CODEC to be used for Video decoding.
Definition: stbdpc.c:7638
U8BIT STB_DPGetPathForService(void *service)
Checks whether any of the paths are tuned to the given service.
Definition: stbdpc.c:1804
void APVR_PausePlay(void)
Pause playback.
Definition: ap_pvr.c:1377
Application level CI control functions.
BOOLEAN ACTL_StartManualSearchById(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT chan_id, BOOLEAN start_search)
Start a service search on, or just tune to, a transport, using chan_id as an index into the country&#39;s...
Definition: ap_cntrl.c:4357
void ACTL_SetParentalControl(BOOLEAN enabled)
Enables or disables parental control. This enables or disables locking on a per channel basis...
Definition: ap_cntrl.c:3084
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
BOOLEAN ADB_GetLNBBandParameters(void *band_ptr, S_STB_DP_LNB_BAND *params)
Returns the structure describing the band and the expected LNB behaviour in it.
Definition: ap_dbacc.c:832
U16BIT ADB_GetNumTransports(void)
Returns the number of transports in the database.
Definition: ap_dbacc.c:1816
void STB_DPSetADPID(U8BIT path, U16BIT pid)
Writes AD PID value into decode path store.
Definition: stbdpc.c:7211
E_STB_DP_TTYPE ACTL_GetTerRfChanType(U16BIT id)
Returns the terrestrial type (T or T2) for the given channel id.
Definition: ap_cntrl.c:1376
BOOLEAN STB_DPIsRecording(U8BIT path, U32BIT *handle)
Returns status of recording on specified path.
Definition: stbdpc.c:2189
void * APVR_GetPlaybackService(void)
A service instance is associated to the playback, this function returns its pointer. The handle can be used, for example, to call ADB_ServiceHasSubtitles as it&#39;s done for live channels.
Definition: ap_pvr.c:3607
BOOLEAN ATMR_CheckRecordStatus(BOOLEAN recordings_can_start, void *service)
Checks all timers to see whether any recordings should be started or stopped as a result of the now e...
Definition: ap_tmr.c:1939
BOOLEAN ACTL_TuneToRfChanArrayEntry(U8BIT path, U16BIT id, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
Tunes to the specified rf channel array entry for DVB-T and DVB-C.
Definition: ap_cntrl.c:1406
void STB_OTAContinueDownload(BOOLEAN status)
This function should be called to unblock the download process. This can be used to in the case where...
Definition: stbota.c:292
void ADB_SaveDatabase(void)
Saves the database to non-volatile memory.
Definition: ap_dbacc.c:502
API interfacing the midware with Intellibyte loader library.
U8BIT ACTL_GetVolume(void)
Returns the current audio volume.
Definition: ap_cntrl.c:4752
BOOLEAN APVR_GetRecordingHandle(U8BIT path, U32BIT *recording_handle_ptr)
Returns the handle of the recording taking place on the given decode path.
Definition: ap_pvr.c:2870
U16BIT(* F_ServiceGetSubtitlePid)(void *serv_ptr, ADB_SUBT_INFO *subt_info)
Function pointer definition: Determines subtitle PID and whether it is DVB or teletext, for the given service.
Definition: ap_cntrl.h:161
macros and function prototypes for public use
BOOLEAN ASI_CheckForServiceChange(E_STB_DP_SIGNAL_TYPE tuner_type)
Checks whether the NIT or SDT version numbers have changed, which may indicate a change to the servic...
Definition: ap_si.c:9765
void STB_AVEnableHDMIDecoding(void)
Enables AV output to HDMI.
BOOLEAN ACTL_IsDecodingLocked(U8BIT path)
Returns whether decoding is locked, due to parental locking, on the given path.
Definition: ap_cntrl.c:2215
void ACTL_StopAudioDescription(U8BIT path)
Stops AD decoding.
Definition: ap_cntrl.c:2771
U8BIT STB_DPGetPathCISlot(U8BIT path)
Returns the CI slot id associated with the given path.
Definition: stbdpc.c:1082
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
U32BIT ADB_GetTransportFreqHz(void *t_ptr)
Returns the frequency, in Hz for DVB-T/T2 and DVB-C, and MHz for DVB-S/S2, of the given transport...
Definition: ap_dbacc.c:2433
void * STB_DPGetTunedService(U8BIT path)
Returns the service saved with the given decode path.
Definition: stbdpc.c:1582
void ADB_DeleteServiceEvents(void *serv_ptr, BOOLEAN delete_now_next)
Deletes all events and event related data for the given service.
Definition: ap_dbacc.c:7949
U32DHMS STB_GCNowDHMSLocal(void)
Reads the current Local date code and time.
Definition: stbgc.c:2296
void STB_DPSetLNB12v(U8BIT path, BOOLEAN state)
Sets LNB 12v on or off and writes status into decode path store.
Definition: stbdpc.c:4664
void STB_DPSetLNB22k(U8BIT path, BOOLEAN state)
Sets LNB 22kHz on or off and writes status into decode path store.
Definition: stbdpc.c:4590
void * ADB_GetServiceTransportPtr(void *s_ptr)
Returns a pointer to the service&#39;s parent transport record.
Definition: ap_dbacc.c:5999
BOOLEAN ADB_GetServiceNotRunningFlag(void *s_ptr)
Returns the status of the &#39;not running&#39; flag of the given service. This flag indicates whether a serv...
Definition: ap_dbacc.c:5654
BOOLEAN STB_AVIsHDCPAuthenticated(void)
Returns whether HDCP has authenticated.
void ACFG_GetBackgroundSearchTime(U16BIT *start_time, U16BIT *end_time)
Gets the background start and end search times.
Definition: ap_cfg.c:1575
BOOLEAN STB_EBUTT_Show(E_EBUTT_CHARACTER_SET_DESIGNATION character_set_designation, BOOLEAN navigate_to_index_page, BOOLEAN show_header)
Called to initiate continuous display of TeleText page content. This will result in either the index ...
Definition: stbebutt.c:11356
void ACTL_SetMhegSubtitlePidFunc(F_ServiceGetSubtitlePid func)
Sets function retrieve Subtitle PID and info. Allows external MHEG5 module to override the default fu...
Definition: ap_cntrl.c:4716
void ACTL_StopServiceSearch(void)
Function to stop the service search before it completes.
Definition: ap_cntrl.c:3877
U16BIT ACFG_GetMinSatelliteScanFreq(U32BIT country_code)
Returns the minimum frequency to be used when performing a satellite based frequency scan in the give...
Definition: ap_cfg.c:1266
void STB_SUBStop(U8BIT path)
Stops subtitling display.
Definition: stbdsc.c:1069
void * ADB_GetFullSITransport(void *n_ptr)
Returns a transport that is signalled as containing a complete set of SI data via an NIT linkage desc...
Definition: ap_dbacc.c:10654
BOOLEAN STB_DPIsLivePath(U8BIT path)
Is the given decode path being used for live viewing.
Definition: stbdpc.c:1297
U8BIT ADB_GetServiceContentProtectionLevel(void *s_ptr)
Returns the content protection level value for the service that will have been set by the Nordig cont...
Definition: ap_dbacc.c:5751
void ACTL_SetVideoWindow(S16BIT win_x, S16BIT win_y, U16BIT win_width, U16BIT win_height)
Sets the video window to the size specified. Coordinates are relative to the screen resolution...
Definition: ap_cntrl.c:2310
BOOLEAN ACTL_StartServiceSearch(E_STB_DP_SIGNAL_TYPE tuner_type, E_ACTL_SEARCH_TYPE type)
Entry point for starting a service search for a full retune or to update the existing service lineup...
Definition: ap_cntrl.c:3687
void ACTL_SetADVolume(U8BIT volume)
Sets the AD volume.
Definition: ap_cntrl.c:2792
BOOLEAN ADB_GetServiceLockedFlag(void *s_ptr)
Returns the status of the &#39;locked&#39; flag of the given service, which is used by the parental control...
Definition: ap_dbacc.c:5805
void HBBTV_NotifyChannelChangeStatus(U16BIT onet_id, U16BIT trans_id, U16BIT serv_id, E_HBBTV_CHANNEL_CHANGE_STATUS status)
Notifies the HbbTV engine of a change in the status of the service identified by the specified DVB tr...
void ASTE_SearchComplete(void)
Definition: ap_state.c:185
void ACTL_LeaveStandby(void *s_ptr, BOOLEAN tune_to_service)
Brings the DVB out of standby mode.
Definition: ap_cntrl.c:5252
BOOLEAN ACTL_IsTargetRegionRequired(void)
When the search has completed, this function should be called to see whether the target region UI sho...
Definition: ap_cntrl.c:3852
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
BOOLEAN ACI_AskRelease(U32BIT module)
Ask the host control module to restore replaced PIDs and to close the session with the host control r...
Definition: ap_ci.c:2218
BOOLEAN ACA_AcquireCADescrambler(U8BIT path, void *s_ptr)
Acquires a CA descrambler for the given path on the given service if needed. No CA descrambler is acq...
Definition: ap_ca.c:79
U8BIT ADB_GetNetworkTargetCountries(U32BIT **code_array)
Returns a combined array of country codes for all discovered networks.
Definition: ap_dbacc.c:1296
ADB_STREAM_TYPE ADB_GetServiceVideoType(void *s_ptr)
Returns the video type being used by the given service.
Definition: ap_dbacc.c:5471
void ACTL_HDMIDisconnected(void)
Sets flag to indicate HDMI is now disconnected. This function is called by the event task when the HD...
Definition: ap_cntrl.c:2982
void STB_FPSetClock(U16BIT mjd, U16BIT year, U8BIT month, U8BIT day, U8BIT hours, U8BIT minutes, U8BIT seconds)
Set the current date on the front panel.
Application configuration.
U8BIT ACTL_SetVolume(U8BIT volume)
Sets the main audio volume and returns the new volume.
Definition: ap_cntrl.c:4764
void STB_AVSetSpdifMode(U8BIT path, E_STB_DIGITAL_AUDIO_TYPE audio_type)
Sets the SPDIF output mode, PCM or compressed audio.
U32BIT ACI_GetOperatorSearchModule(void)
Returns the module performing or requiring and operator search.
Definition: ap_ci.c:1125
void STB_DPSetVideoPID(U8BIT path, U16BIT pid)
Writes video PID value into decode path store.
Definition: stbdpc.c:7079
void * ADB_GetSatelliteLNB(void *sat_ptr)
Returns the LNB associated with the given satellite.
Definition: ap_dbacc.c:992
Application database control.
U32DHMS STB_GCNowDHMSGmt(void)
Reads the current GMT date code and time.
Definition: stbgc.c:2264
E_STB_DP_TUNE_STATUS STB_DPGetTuneStatus(U8BIT path)
Reads the tuning status from decode path store.
Definition: stbdpc.c:3332
U8BIT ACFG_GetEitUpdateTime(void)
Returns the number of minutes after which all the events should have been received during an EIT sear...
Definition: ap_cfg.c:1744
Header file - macros and function prototypes for public use.
BOOLEAN ACFG_GetAnaRfChannelTable(U32BIT country_code, ACFG_ANA_RF_CHANNEL_DATA **rf_chan_data_ptr, U16BIT *num_entries_ptr)
Returns a pointer to the channel table for an analog tuner for the given country. ...
Definition: ap_cfg.c:1001
void * ADB_FindServiceByLcn(U32BIT list_type, U16BIT lcn, BOOLEAN show_unselectable)
Returns the service matching the given LCN and list type.
Definition: ap_dbacc.c:3934
void * ADB_GetTunedNetwork(U8BIT path)
Returns the network currently tuned to on the given decode path.
Definition: ap_dbacc.c:1669
U8BIT STB_DPPathForTuner(U8BIT start_path, U8BIT tuner_num)
Returns the decode path that is using the given tuner ID.
Definition: stbdpc.c:1400
Header file for NVM data handling functions.
void STB_GCGetDateInfo(U16BIT code, U8BIT hour, U8BIT min, U8BIT *day, U8BIT *wday, U8BIT *month, U16BIT *year)
Get the day, weekday, month and the year from a date code and hour / minute offset.
Definition: stbgc.c:1867
void STB_DPSetDISEQCRepeats(U8BIT path, U8BIT count)
Sets DiSEqC repeats and writes value into decode path store.
Definition: stbdpc.c:5111
E_STB_DP_AUDIO_CODEC STB_DPGetAudioCodec(U8BIT path)
Returns the type of CODEC to be used for Audio decoding.
Definition: stbdpc.c:7925
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
void ACTL_SetStandbyGracePeriod(U16BIT num_seconds)
Sets a grace period during which a system will enter active standby before going into passive or low ...
Definition: ap_cntrl.c:5070
BOOLEAN ADB_GetServiceDoNotScramble(void *s_ptr)
Returns the do_not_scramble flag for the service which is based on the presence of an FTA descriptor...
Definition: ap_dbacc.c:5727
void ADB_ReleaseStreamList(void **streamlist_ptr, U16BIT num_entries)
Frees the memory allocated for a stream list using ADB_GetStreamList.
Definition: ap_dbacc.c:7052
void STB_DPStartAudioDecoding(U8BIT path)
Requests start of channel decoding process.
Definition: stbdpc.c:2585
void * STB_AppGetMemory(U32BIT bytes)
Attempts to allocate memory from the application heap.
Definition: stbheap.c:651
void STB_DPStartSI(U8BIT path)
Requests start of SI engine, mode is determined by flags in general control.
Definition: stbdpc.c:2934
void ACTL_StartPlayback(void *s_ptr)
Start streaming the specified service.
Definition: ap_cntrl.c:2022
void ACTL_SetAnalogChanIdString(U8BIT *str_ptr)
sends string to be displayed via pixelworks if it has changed (Must not send message to PixelWorks if...
Definition: ap_cntrl.c:2619
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 STB_AVGetHDMINativeResolution(U16BIT *width, U16BIT *height)
Returns the native resolution, i.e. the resolution that is set with a call to STB_AVSetTVType(path, ratio, VIDEO_FORMAT_AUTO);.
BOOLEAN ACTL_IsMuted(void)
Returns the muted state of the audio.
Definition: ap_cntrl.c:4882
Application level CA control functions.
void ACTL_ApplyHDCP(void *s_ptr)
Checks content protection requirements for the current event on the given service to determine whethe...
Definition: ap_cntrl.c:3311
Definition: ap_tmr.h:97
BOOLEAN ACI_RequestOperatorStatus(U32BIT module)
Called by the host to request changing to an operator profile and request the operator status to be s...
Definition: ap_ciop.c:227
BOOLEAN STB_DPSetOwnerData(U8BIT path, void *data, U32BIT data_size)
Saves a copy of the given data with the path. If data is passed as NULL and owner data already exists...
Definition: stbdpc.c:1911
void STB_GCCalculateDateTime(U16BIT code, U8BIT hour, U8BIT min, U8BIT secs, U8BIT ohour, U8BIT omin, U8BIT osecs, U16BIT *rcode, U8BIT *rhour, U8BIT *rmin, U8BIT *rsecs, E_STB_GC_CALCTYPE calc)
Adds or subtracts offset from a date/time.
Definition: stbgc.c:1540
void STB_AVSetHDMIAudioMode(U8BIT path, E_STB_DIGITAL_AUDIO_TYPE audio_type)
Sets the HDMI audio output mode, PCM or compressed.
E_STB_DP_AUDIO_MODE STB_DPGetADMode(U8BIT path)
Reads the AD mode value from decode path store.
Definition: stbdpc.c:7487
E_STB_TUNE_TCODERATE STB_TuneGetActualTerrHpCodeRate(U8BIT path)
Returns the HP code rate of the current terrestrial signal.
BOOLEAN STB_CiCcSendRecordStop(U8BIT slot_id)
Called by the app when a recording is stopped or completes.
Definition: stbcicc.c:1529
BOOLEAN ACTL_TuneUsingDSD(U8BIT path, SI_DELIVERY_SYS_DESC_TYPE dsd_type, SI_DELIVERY_SYS_DESC *dsd, U16BIT service_id, E_ACTL_SI_SRCH_REQD reqd_si)
Starts the process of tuning to a given transport or service that&#39;s defined by the given delivery sys...
Definition: ap_cntrl.c:1866
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 STB_CADescramblerRequiredForRecording(U16BIT *ca_ids, U16BIT num_ca_ids)
This function works out whether a CA descrambler is required to record a service with one of the give...
Definition: ca_glue.c:336
BOOLEAN ACTL_StartEitSearch(E_STB_DP_SIGNAL_TYPE tuner_type, E_ACTL_EVENT_SEARCH search_type)
Entry point for starting an EIT search.
Definition: ap_cntrl.c:4086
void STB_DPSetDISEQCPosition(U8BIT path, BOOLEAN state)
Enables/disables DiSEqC positioning and writes status into decode path store.
Definition: stbdpc.c:4790
void ACTL_SetupPlayback(void)
Starts the SI to acquire the PMT and fill the ip service in.
Definition: ap_cntrl.c:1995
void STB_DPSetSearchMode(U8BIT path, BOOLEAN state)
Writes SI search mode flag into decode path store.
Definition: stbdpc.c:3981
BOOLEAN ACI_OperatorExit(void)
Request the current operator module to exit operator profile.
Definition: ap_ciop.c:286
BOOLEAN STB_DPSetADCodec(U8BIT path, E_STB_DP_AUDIO_CODEC codec)
Sets the type of CODEC to be used for AD decoding.
Definition: stbdpc.c:7745
BOOLEAN ADB_GetLNBSettings(void *lnb_ptr, ADB_LNB_SETTINGS *settings)
Returns the current settings for the given LNB.
Definition: ap_dbacc.c:693
void * ADB_GetLNBBandLNB(void *band_ptr)
Returns the LNB associated with the band.
Definition: ap_dbacc.c:802
BOOLEAN ACI_AcquireCISlotForRecording(U8BIT path, void *s_ptr)
Acquires a CI slot for the recording path. This function may need to "steal" the CI slot from the liv...
Definition: ap_ci.c:1515
E_STB_TUNE_TBWIDTH STB_TuneGetActualTerrBwidth(U8BIT path)
Returns the actual bandwidth of the current terrestrial signal.
void ACTL_DecodeOff(U8BIT path)
Stops decoding on the given path.
Definition: ap_cntrl.c:2105
void STB_DPSetDISEQCUSwitch(U8BIT path, U8BIT state)
Sets DiSEqC uncommitted switch and writes status into decode path store.
Definition: stbdpc.c:4916
Header file - Function prototypes for A/V control.
void STB_DPSetTerrType(U8BIT path, E_STB_DP_TTYPE type)
Sets terrestrial tuning type into decode path store.
Definition: stbdpc.c:6608
U16BIT ADB_GetStreamPID(void *stream_ptr)
Returns the PID for the given stream.
Definition: ap_dbacc.c:7157
BOOLEAN ACTL_AcquirePathOwnership(U8BIT path, S_ACTL_OWNER_INFO *owner_info)
Attempts to take ownership of the given path (used by CI+)
Definition: ap_cntrl.c:4978
void * ADB_GetTransportSatellite(void *t_ptr)
Returns the parent satellite for the given transport.
Definition: ap_dbacc.c:2935
void STB_AVSetHDMIStandby(BOOLEAN standby)
Sets the standby state of the HDMI output.
void STB_ChangePesCollectionPID(U8BIT path, U16BIT text_pid)
Changes the PID that the DMX is using to gather data on.
Definition: stbpes.c:467
U8BIT STB_DPGetTerrPLP(U8BIT path)
Reads the terrestrial T2 PLP id from decode path store.
Definition: stbdpc.c:6709
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
void ADB_ReportNoSignalDuringSearch(void *t_ptr)
Set the signal level to 0 and searched flag to TRUE for the given transport.
Definition: ap_dbacc.c:2253
U32BIT APP_NvmRead(E_NVM_ITEMS nvm_item)
Returns the current value for the given DVB setting.
Definition: app_nvm.c:562
void DBDEF_SelectBroadcastProfile(void)
Sets the broadcast profile type for for all network, transport and service record accesses...
Definition: ap_dbdef.c:10174
U32DHMS STB_GCCreateDHMS(U16BIT date, U8BIT hour, U8BIT mins, U8BIT secs)
Makes U32DHMS formated date/time from date code, hour, minutes, seconds.
Definition: stbgc.c:2080
E_STB_TUNE_THIERARCHY STB_TuneGetActualTerrHierarchy(U8BIT path)
Returns the heirarchy of the current terrestrial signal.
ADB_PROFILE_TYPE ADB_GetProfileType(void *profile)
Returns the type of the given profile.
Definition: ap_dbacc.c:11407
ADB_STREAM_TYPE ADB_GetServiceAudioType(void *s_ptr)
Returns the audio type being used by the given service.
Definition: ap_dbacc.c:5212
void * ADB_FindServiceByIds(U16BIT onet_id, U16BIT tid, U16BIT sid)
Returns a pointer to the service matching the given IDs.
Definition: ap_dbacc.c:4071
U8BIT ADB_GetServiceNumRCTLinks(void *serv_ptr)
Returns the number of RCT links for the given service.
Definition: ap_dbacc.c:6179
U8BIT * ADB_GetServicePMTData(void *s_ptr, U16BIT *data_len)
Returns the current PMT data for the given service.
Definition: ap_dbacc.c:11293
Application timer functions and defines.
void ADB_GetTransportList(void ***tlist_ptr, U16BIT *num_entries_ptr)
Allocates and returns a list of all transport records in the database.
Definition: ap_dbacc.c:1691
void APP_NvmSave(E_NVM_ITEMS nvm_item, U32BIT new_value, BOOLEAN write_to_flash_now)
Sets the current value for the given DVB setting.
Definition: app_nvm.c:634
BOOLEAN ACTL_IsCiUiRequired(void)
Returns state of ci_ui_required flag.
Definition: ap_cntrl.c:2588
E_ACTL_AV_MODE ACTL_GetAvModeStatus(void)
Returns av_mode.
Definition: ap_cntrl.c:2424
E_STB_TUNE_SYSTEM_TYPE STB_TuneGetSystemType(U8BIT path)
Returns the signal type as set by STB_TuneSetTerrType or as re-written by the driver.
void ACTL_SetVolumeAdjustment(S8BIT scaling)
Sets the audio volume scaling to be applied.
Definition: ap_cntrl.c:4732
void * ASI_GetNextOTALocation(void *network, void *prev_location, U16BIT *onid_ptr, U16BIT *tid_ptr, U16BIT *sid_ptr)
Returns the DVB triplet for the next location containing a possible OTA update.
Definition: ap_si.c:9664
void ADB_GetNowNextEvents(void *serv_ptr, void **now_event, void **next_event)
Makes copies of the now and/or next events (EITp/f) for the given service. The returned events should...
Definition: ap_dbacc.c:7587
void STB_OSMutexUnlock(void *mutex)
Unlock a mutex (a.k.a. &#39;leave&#39;, &#39;signal&#39; or &#39;release&#39;)
BOOLEAN ACI_IsOperatorSearchRequired(void)
Returns whether an operator profile search has been requested.
Definition: ap_ci.c:1114
void STB_DPSetADMode(U8BIT path, E_STB_DP_AUDIO_MODE mode)
Writes AD mode value into decode path store.
Definition: stbdpc.c:7454
BOOLEAN STB_DPReleasePath(U8BIT path, E_STB_DP_RES_OWNER owner)
Releases the decode path and all resources no longer needed. The path won&#39;t be released if the path i...
Definition: stbdpc.c:785
U32DHMS STB_GCConvertDHMS(U32DHMS dhms, E_STB_GC_CONVTYPE conv)
Converts the given date/time to local or GMT.
Definition: stbgc.c:2206
Header file - macros and function prototypes for public use.
void ADB_ReleaseTransportList(void **tlist, U16BIT num_transports)
Frees a transport list returned from one of the ADB_GetTransportList functions.
Definition: ap_dbacc.c:1836
void ACTL_ReleaseLivePathForService(void *s_ptr, E_STB_DP_RES_OWNER owner)
Finds the path being used to view the given service and releases it.
Definition: ap_cntrl.c:4916
void STB_ERSendEvent(BOOLEAN latched, BOOLEAN repeat, U16BIT path_class, U16BIT type, void *data, U32BIT data_size)
Sends an event to event reporting control module.
Definition: stberc.c:571
U32BIT ACTL_GetRfChanFreqHz(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
Returns a pointer to the channel name.
Definition: ap_cntrl.c:1257
CI Content Control.
U16BIT ACTL_GetNumRfChanArrayEntries(E_STB_DP_SIGNAL_TYPE tuner_type)
Returns the number of entries in the rf channel table.
Definition: ap_cntrl.c:1096
void STB_DPSetUnicableFrequency(U8BIT path, U32BIT freq)
Sets the Unicable (IF) frequency.
Definition: stbdpc.c:5378
E_STB_DP_SIGNAL_TYPE STB_DPGetSignalType(U8BIT path)
Reads the signal type value from decode path store.
Definition: stbdpc.c:3836
E_STB_TUNE_TGUARDINT STB_TuneGetActualTerrGuardInt(U8BIT path)
Returns the guard interval of the current terrestrial signal.
void STB_DPSetAdditionalFrequencies(U8BIT path, U8BIT num_freqs, U32BIT *frequencies)
Sets an array of frequencies that can be tried when tuning to a transport if the tuner fails to lock ...
Definition: stbdpc.c:6933
void ACTL_HDMIConnected(void)
Checks that the selected HDMI resolution mode is supported and, if not, chooses the best one availabl...
Definition: ap_cntrl.c:2953
U8BIT ACTL_TuneToService(U8BIT path, S_ACTL_OWNER_INFO *owner_info, void *s_ptr, BOOLEAN override_lock, BOOLEAN for_live)
Starts the process of tuning to the specified service. If the service is to be tuned on the live path...
Definition: ap_cntrl.c:1651
void ACTL_EnableCiModule(void)
Enables CI module.
Definition: ap_cntrl.c:2563
BOOLEAN ACFG_GetBackgroundServiceSearch(void)
Returns whether the background service search is enabled or not.
Definition: ap_cfg.c:1609
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
void ADB_GetStreamList(void *serv_ptr, ADB_STREAM_LIST_TYPE stream_list_type, void ***streamlist_ptr, U16BIT *num_entries_ptr)
Allocates and returns an array of the streams of the given type and for the given service...
Definition: ap_dbacc.c:6882
BOOLEAN ACTL_SetActiveProfile(void *profile)
Sets the current profile. (CI+ only) If the profile is being set to CI+ profile and the necessary CAM...
Definition: ap_cntrl.c:5482
BOOLEAN ACTL_IsAudioDescriptionOn(void)
Returns whether audio description has been turned on.
Definition: ap_cntrl.c:2707
U16BIT STB_DPGetADPID(U8BIT path)
Reads the audio PID value from decode path store.
Definition: stbdpc.c:7256
void * ADB_GetTransportFromIds(U16BIT net_id, U16BIT onet_id, U16BIT tran_id)
Finds the transport with the given ids.
Definition: ap_dbacc.c:2968
void ACTL_AllowAnalogVideo(BOOLEAN allow_analog_video)
Enables or disables analog video display.
Definition: ap_cntrl.c:2684
void STB_SUBEnable(U8BIT path, BOOLEAN enable)
Enables or disables subtitling display.
Definition: stbdsc.c:995
void STB_DPSetAudioMode(U8BIT path, E_STB_DP_AUDIO_MODE mode)
Writes audio mode value into decode path store.
Definition: stbdpc.c:7519
U8BIT STB_DPGetNumPaths(void)
Returns the maximum number of decode paths.
Definition: stbdpc.c:532
BOOLEAN ACI_GetFirstOperatorSearchModule(U32BIT *module)
Checks all the CI+ profiles to see if any have requested an update search.
Definition: ap_ci.c:1138
void ASTE_Initialise(void)
Definition: ap_state.c:67
void ACI_UseCiModuleOnPath(U8BIT path, U32BIT module)
Use the CI module with the given path.
Definition: ap_ci.c:2257
U8BIT STB_DPGetPlaybackPath(void)
Returns the ID of the decode path being used for playback.
Definition: stbdpc.c:1373
U8BIT ADB_GetEventParentalAge(void *event_ptr)
Returns the parental age value for the given event.
Definition: ap_dbacc.c:8707
void ACTL_SetMhegAVControl(BOOLEAN control)
Sets the MHEG5 audio volume adjust to be applied.
Definition: ap_cntrl.c:4704
void STB_DPSetTerrBandwidth(U8BIT path, E_STB_DP_TBWIDTH bwidth)
Writes terrestrial bandwidth value into decode path store.
Definition: stbdpc.c:6478
void * ADB_GetNextSatellite(void *sat_ptr)
Returns the next satellite from the database.
Definition: ap_dbacc.c:942
void * ADB_GetTransportNetworkPtr(void *t_ptr)
Returns the network of the given transport.
Definition: ap_dbacc.c:2405
BOOLEAN ACTL_HasDecodingStarted(U8BIT path)
Returns whether decoding has been started on the given path.
Definition: ap_cntrl.c:2194
BOOLEAN ACFG_GetCabRfChannelTable(U32BIT country_code, ACFG_CAB_RF_CHANNEL_DATA **rf_chan_data_ptr, U16BIT *num_entries_ptr)
Returns a pointer to the channel table for a cable tuner for the given country.
Definition: ap_cfg.c:1059
E_STB_DP_SIGNAL_TYPE ADB_GetTransportSignalType(void *t_ptr)
Returns the signal type for the given transport.
Definition: ap_dbacc.c:2277
void ADB_ReleaseServiceList(void **slist, U16BIT num_servs)
Frees a list of services returned from one of the functions that returns a service list...
Definition: ap_dbacc.c:3556
BOOLEAN ACFG_GetBackgroundSSUSearch(void)
Returns whether the background SSU search is enabled or not.
Definition: ap_cfg.c:1639
U8BIT STB_DPGetLivePath(void)
Returns the ID of the decode path being used for live viewing.
Definition: stbdpc.c:1271
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
Header file - macros and function prototypes for public use.
void ACTL_DisableCiModule(void)
Disables CI module.
Definition: ap_cntrl.c:2575
void STB_AVSetUhfModulatorChannel(U8BIT chan)
Sets the output channel of the RF Modulator.
void STB_PVRSetStandbyState(BOOLEAN state)
Sets the standby state of the PVR path control.
Definition: stbpvr.c:457
void ADB_GetTransportAnalogTuningParams(void *t_ptr, U32BIT *freq_hz, S8BIT *offset, E_STB_DP_ANALOG_VIDEO_TYPE *vtype)
Returns the settings to tune to the given terrestrial analog transport.
Definition: ap_dbacc.c:2824
BOOLEAN ACTL_HandlePrivateTimerEvent(U32BIT timer_handle)
Handles all the private timer events.
Definition: ap_cntrl.c:960
void ASTE_EnterStandby(BOOLEAN recording)
Definition: ap_state.c:79
ADB_PROFILE_TYPE DBDEF_GetCurrentProfileType(void)
Returns the current profile type.
Definition: ap_dbdef.c:10163
BOOLEAN STB_DPIsDecodingPath(U8BIT path)
Is the given decode path being used for decoding.
Definition: stbdpc.c:1346
void ACTL_SetTVAspectMode(E_STB_AV_ASPECT_MODE aspect_mode)
Used to set the TV aspect mode which defines how the video will be displayed based on the aspect rati...
Definition: ap_cntrl.c:2370
void * ADB_GetNextLNBBand(void *band_ptr)
Returns the next LNB band from the database.
Definition: ap_dbacc.c:782
Header file - EBU Teletext driver.
void STB_DPSetAudioPID(U8BIT path, U16BIT pid)
Writes audio PID value into decode path store.
Definition: stbdpc.c:7145
BOOLEAN ACFG_GetSatelliteScanDvbS2(U32BIT country_code)
Returns whether DVB-S2 should be included when performing a satellite based frequency scan in the giv...
Definition: ap_cfg.c:1396
U8BIT ACTL_AcquirePathForService(void *s_ptr, BOOLEAN with_decoders, BOOLEAN for_recording, S_ACTL_OWNER_INFO *owner_info)
Acquires a decode path suitable for tuning to the given service.
Definition: ap_cntrl.c:4897
BOOLEAN STB_DPGetLockMode(U8BIT path)
Reads the lock mode value from decode path store.
Definition: stbdpc.c:7611
E_TIMER_TYPE ATMR_GetType(U32BIT handle)
Returns the type of the given timer.
Definition: ap_tmr.c:1164
void ACTL_SetTVAspectRatio(E_STB_AV_ASPECT_RATIO aspect_ratio)
Used to set the TV aspect ratio.
Definition: ap_cntrl.c:2336
U16BIT ADB_GetTransportTid(void *t_ptr)
Returns the transport id of the given transport.
Definition: ap_dbacc.c:2325
void STB_DPSetLockMode(U8BIT path, BOOLEAN mode)
Writes lock mode value into decode path store.
Definition: stbdpc.c:7584
void STB_DPTuneOff(U8BIT path)
Requests stop of tuning and powers down tuner.
Definition: stbdpc.c:2331
void DBDEF_ReleaseAccess(void)
Releases access to the app&#39;s database.
Definition: ap_dbdef.c:245
void ACTL_StopEitSearch(void)
Function to stop the EIT search before it completes.
Definition: ap_cntrl.c:4203
BOOLEAN ACTL_IsHDMIConnected(void)
Returns whether the HDMI is connected or not.
Definition: ap_cntrl.c:2994
void ACTL_ActionEvent(U32BIT event, void *event_data)
Actions external events.
Definition: ap_cntrl.c:502
U16BIT ADB_GetServiceLcn(void *s_ptr)
Returns the logical channel number assigned to the given service.
Definition: ap_dbacc.c:4940
void STB_DPSetTerrMode(U8BIT path, E_STB_DP_TMODE mode)
Writes terrestrial tuning mode value into decode path store.
Definition: stbdpc.c:6413
BOOLEAN ACFG_IsNordigCountry(void)
Returns whether the current country requires Nordig compliance for SI.
Definition: ap_cfg.c:1656
void ACTL_StopSubtitles(void)
Stops subtitles from being displayed and processed.
Definition: ap_cntrl.c:3579
BOOLEAN STB_DPIsOwnedBy(U8BIT path, E_STB_DP_RES_OWNER owner)
Checks whether the path is owned by the given owner.
Definition: stbdpc.c:1966
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.
Header file - Function prototypes for linked lists.
Header file - macros and function prototypes for public use.
void STB_AVSetAudioVolume(U8BIT path, U8BIT vol)
Sets the volume of the main audio output.
void ASI_SetStandbyState(BOOLEAN standby_state)
Performs the neccessary actions for this module when entering/exiting standby according to the value ...
Definition: ap_si.c:9630
void ACTL_SetParentalControlAge(U8BIT age)
Sets the age (valid values 4-18) at which parental control will be will be applied. If the age is invalid, no change will be made to the current setting.
Definition: ap_cntrl.c:3141
void * ADB_GetTunedTransport(U8BIT path)
Returns the transport that&#39;s tuned to on the given decode path.
Definition: ap_dbacc.c:3015
void STB_OSMutexLock(void *mutex)
Lock a mutex (a.k.a. &#39;enter&#39;, &#39;wait&#39; or &#39;get&#39;).
void ACTL_UpdateVideoMode(E_STB_AV_ASPECT_RATIO aspect, BOOLEAN force)
Update video mode sets MHEG resolution as well as platform Also, stops subtitles during the operation...
Definition: ap_cntrl.c:2908
Header file - macros and function prototypes for public use.
void STB_VTSetVideoAlignmentPref(E_VIDEO_ASPECT_MODE pref)
Set video alignment preference.
Definition: stbvtc.c:110
BOOLEAN ACTL_StartSubtitles(void)
Starts subtitle processing and display if the current service has valid subtitle data. If DVB subtitles aren&#39;t available, teletext will be used if available.
Definition: ap_cntrl.c:3474
BOOLEAN ACI_GetFirstScheduledOperatorSearch(U32BIT *module, U16BIT *date, U8BIT *hours, U8BIT *mins)
Checks all the CI+ profiles to find the one with the earliest scheduled search. All returned values a...
Definition: ap_ci.c:1181
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
BOOLEAN ADB_GetServiceScrambledFlag(void *s_ptr)
Returns the status of the &#39;scrambled&#39; flag of the given service. This flag is set depending on the sc...
Definition: ap_dbacc.c:5679
void * ADB_GetTunedService(U8BIT path)
Returns the tuned service for the given decode path.
Definition: ap_dbacc.c:6068
void STB_DPSetFrequency(U8BIT path, U32BIT freq)
Writes frequency value into decode path store.
Definition: stbdpc.c:6059
Database access defines, structures and public functions.
void ADB_SetTunedService(U8BIT path, void *s_ptr)
Sets the tuned service for the given path, together with the associated tuned transport and network...
Definition: ap_dbacc.c:6023
void STB_HWSetWakeUpTime(U16BIT mjd, U16BIT year, U8BIT month, U8BIT day, U8BIT hours, U8BIT minutes, U32BIT time_in_mins)
Used to set the wake up time for when the system is going to be put into the low power standby state...
BOOLEAN ACFG_IsNordigService(E_STB_DP_SIGNAL_TYPE tuner_type)
Returns whether the broadcast SI data for the given tuner type is to be treated as Nordig compliant...
Definition: ap_cfg.c:1683
void STB_DPSetAnalogFreqOff(U8BIT path, S8BIT offset)
Writes analogue frequency offset value into decode path store.
Definition: stbdpc.c:6873
U16BIT STB_DPGetAudioPID(U8BIT path)
Reads the audio PID value from decode path store.
Definition: stbdpc.c:7179
void ACI_UsageRulesStatusChanged(U8BIT path)
Re-evaluate current state follwing a change related to usage rules.
Definition: ap_ci.c:1612
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 ADB_ReleaseNetworkList(void **nlist)
Frees a network list returned by ADB_GetNetworkList.
Definition: ap_dbacc.c:1141
Application level CI - internal functions.
void ACTL_StopTotSearch(void)
Function to stop the TOT search before it completes.
Definition: ap_cntrl.c:4061
void STB_EBUTT_SetCacheMethod(E_EBUTT_CACHING_METHOD ebutt_caching_method)
Called to define the strategy used to determine what page content is to be displayed form the TeleTex...
Definition: stbebutt.c:11443
void STB_DPStartTune(U8BIT path)
Requests start of tuning process.
Definition: stbdpc.c:2206
U16BIT ADB_ServiceGetSubtitlePid(void *serv_ptr, ADB_SUBT_INFO *subt_info)
Determines subtitle PID and whether it is DVB or teletext, for the given service. ...
Definition: ap_dbacc.c:6745
void ACI_TuneReply(U8BIT path, U32BIT module, E_CIP_TUNER_STATUS status)
This function is called by the host to send the status of the tune operation to the module...
Definition: ap_ci.c:2242
void ASTE_LeaveStandby(void)
Definition: ap_state.c:102
void STB_AVSetAudioMute(U8BIT path, BOOLEAN mute)
Mute or unmute the audio output on the given audio decoder path.
U8BIT ACFG_GetEitSearchesPerDay(void)
Returns the number of EIT searches that should be performed per day when the box is in standby...
Definition: ap_cfg.c:1721
U32BIT ATMR_GetFirstWakeupTime(U32DHMS *rec_date_time, U16BIT *onet_id, U16BIT *trans_id, U16BIT *service_id)
Searches the timers for the first timer that will cause the DVB to wakeup that hasn&#39;t been missed...
Definition: ap_tmr.c:2895
BOOLEAN ACTL_StartStartupSearch(void)
Function to start the startup search when booting from cold. This search checks the validity of the s...
Definition: ap_cntrl.c:3893
void ASI_SetAppSiMode(U8BIT path, E_APP_SI_MODE si_mode)
Sets application SI mode - used before STB_DPStartSI() is called.
Definition: ap_si.c:9534
void ACTL_SetMute(BOOLEAN mute)
Sets the audio mute state.
Definition: ap_cntrl.c:4838
void STB_DPSetDecodePIDs(U8BIT path, U16BIT pcr_pid, U16BIT video_pid, U16BIT audio_pid, U16BIT text_pid, U16BIT data_pid, U16BIT AD_pid)
Definition: stbdpc.c:7414
BOOLEAN STB_DPCanTuneTo(E_STB_DP_SIGNAL_TYPE tuner_type, void *service, void *transport)
Checks whether there&#39;s a tuner available to tune to the given service or transport.
Definition: stbdpc.c:1830
U16BIT ADB_GetTransportOriginalNetworkId(void *t_ptr)
Returns the original network id of the given transport.
Definition: ap_dbacc.c:2385
void STB_DPSetPulsePosition(U8BIT path, BOOLEAN state)
Enables/disables pulse positioning and writes status into decode path store.
Definition: stbdpc.c:4729
void STB_DPSetSymbolRate(U8BIT path, U16BIT sym)
Writes symbol rate value into decode path store.
Definition: stbdpc.c:6189
U8BIT STB_DPGetPathTuner(U8BIT path)
Returns the tuner ID acquired by the given decode path.
Definition: stbdpc.c:1605
E_STB_AV_ASPECT_RATIO ACTL_GetTVAspectRatio(void)
Returns the current TV aspect ratio.
Definition: ap_cntrl.c:2357
void ACTL_StartDecoding(U8BIT path, void *s_ptr)
Sets up and starts decoding for the given service. This is used for PVR playback, but could also be u...
Definition: ap_cntrl.c:2058
U8BIT ACTL_GetActivePath(void)
Returns the active path (live, playback, etc...), i.e. the one using the decoders.
Definition: ap_cntrl.c:3663
Header file - Function prototypes for Event Reporting.
U8BIT ACFG_GetSatelliteScanNumSymbolRates(U32BIT country_code)
Returns the number of items in the fixed array of symbol rates to be used when performing a satellite...
Definition: ap_cfg.c:1370
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
void ACTL_SetStandbyState(BOOLEAN state)
Reports the standby state to the A/V output controller.
Definition: ap_cntrl.c:2235
BOOLEAN ACTL_AreSubtitlesDisplayed(void)
Returns whether subtitles are being displayed.
Definition: ap_cntrl.c:3616
U16BIT ADB_GetServiceVideoPid(void *s_ptr)
Returns the video PID for the given service.
Definition: ap_dbacc.c:5448
BOOLEAN ACTL_StartTotSearch(E_STB_DP_SIGNAL_TYPE tuner_type)
Function to start a TOT search which is required to set the system clock when starting from power off...
Definition: ap_cntrl.c:4005
Header file - Function prototypes for version numbers.
void STB_SUBStart(U8BIT path, U16BIT pid, U16BIT composition_id, U16BIT ancillary_id)
Starts subtitling display.
Definition: stbdsc.c:1044
U8BIT STB_DPGetPathAudioDecoder(U8BIT path)
Returns the audio decoder ID acquired by the given decode path.
Definition: stbdpc.c:1734
void STB_DPSetPCRPID(U8BIT path, U16BIT pid)
Writes PCR PID value into decode path store.
Definition: stbdpc.c:7013
void STB_DPSetAnalogVideoType(U8BIT path, E_STB_DP_ANALOG_VIDEO_TYPE vtype)
Writes analogue video type into decode path store.
Definition: stbdpc.c:6808
void HBBTV_NotifyParentalRatingChange(BOOLEAN blocked)
Notifies the HbbTV engine that the parental rating of the currently playing service has changed...
void ADB_SetTransportSearchFlag(void *t_ptr, BOOLEAN state)
Sets whether a transport has been used during a service scan operation.
Definition: ap_dbacc.c:2235
void DBDEF_RequestAccess(void)
Requests access to the app&#39;s database.
Definition: ap_dbdef.c:235
U8BIT ACTL_GetParentalControlAge(void)
Returns the current age set for parental control. 0 will be returned if parental control is disabled ...
Definition: ap_cntrl.c:3164
void ACTL_ResumeSubtitles(void)
Resumes the display of subtitles after they&#39;ve been paused.
Definition: ap_cntrl.c:3547
Glue layer between DVB and conditional access systems.
void STB_AVSetAVOutput(BOOLEAN av_on)
Turns on/off all AV outputs (e.g. for standby mode)
void STB_DPSetDISEQCCSwitch(U8BIT path, E_STB_DP_DISEQC_CSWITCH state)
Sets DiSEqC committed switch and writes status into decode path store.
Definition: stbdpc.c:4851
BOOLEAN ACTL_ParentalControlEnabled(void)
Returns whether parental control is enabled. This will also return TRUE if parental control has been ...
Definition: ap_cntrl.c:3115
E_STB_DP_DECODE_STATUS STB_DPGetVideoStatus(U8BIT path)
Reads the video status from decode path store.
Definition: stbdpc.c:3767
void STB_DPSetTuneRelock(U8BIT path, BOOLEAN state)
Writes tuner auto relock flag into decode path store.
Definition: stbdpc.c:3868
BOOLEAN STB_GCIsFutureDateTime(U16BIT code, U8BIT hour, U8BIT min, U8BIT secs)
Tests given date and time against current GMT date and time.
Definition: stbgc.c:1411
void STB_OTAStopLoader(void)
Stops the download process.
Definition: stbota.c:220
void ADB_GetServiceList(U32BIT list_type, void ***slist_ptr, U16BIT *num_entries_ptr)
Allocates and returns a list of all services in the database for the given list type.
Definition: ap_dbacc.c:3249
void STB_DPSetPolarity(U8BIT path, E_STB_DP_POLARITY pol)
Writes polarity value into decode path store.
Definition: stbdpc.c:6124
BOOLEAN ACTL_CheckLiveServiceChange(void)
Checks whether the service tuned to on the live path has changed and informs the UI if it has...
Definition: ap_cntrl.c:5443
void ADB_GetTransportSatTuningParams(void *t_ptr, U32BIT *freq_hz, E_STB_DP_POLARITY *polarity, U16BIT *symrate, E_STB_DP_FEC *fec, BOOLEAN *dvb_s2, E_STB_DP_MODULATION *modulation)
Returns the parameters needed to tune a satellite tuner to a transport.
Definition: ap_dbacc.c:2895
BOOLEAN ACTL_TuneToRfChanArrayAnalogEntry(U8BIT path, U16BIT id)
Tunes to the specified rf channel array entry in analogue mode.
Definition: ap_cntrl.c:1476
void APVR_StopPauseRecord(BOOLEAN return_to_live)
Stops timeshifted playback and recording and optionally restarts decoding of the live signal...
Definition: ap_pvr.c:2730
void STB_DPSetSignalType(U8BIT path, E_STB_DP_SIGNAL_TYPE sigtype)
Writes signal type value into decode path store.
Definition: stbdpc.c:3803
void HBBTV_NotifyServiceListChange(void)
Notifies the HbbTV ending that it must update Service list. This will cause the engine to subsequentl...
BOOLEAN STB_HWSetStandbyState(E_HW_STANDBY_STATE state)
Used to transition the system between the various standby states. It&#39;s assumed that the system can mo...
void ADB_FinaliseDatabaseAfterSearch(BOOLEAN save_changes, E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite, BOOLEAN search_completed, BOOLEAN clear_new_flags, BOOLEAN manual_search)
Completes the database setup after a search has completed or been stopped.
Definition: ap_dbacc.c:283
U16BIT ADB_GetServiceId(void *s_ptr)
Returns the signalled service id of the given service.
Definition: ap_dbacc.c:4960
E_ACTL_DECODE_CHANGE ACTL_SetupAudioDecoding(U8BIT path, void *s_ptr)
Setup default audio decoding params on current tuned service Can be used by external module (e...
Definition: ap_cntrl.c:5540
U32BIT ACFG_GetCountry(void)
Returns the country code the DVB is configured for.
Definition: ap_cfg.c:150
void ADB_GetNetworkList(void ***nlist_ptr, U16BIT *num_entries_ptr)
Allocates and returns a list of the network records in the database.
Definition: ap_dbacc.c:1100
E_STB_DP_DECODE_STATUS STB_DPGetAudioStatus(U8BIT path)
Reads the audio status from decode path store.
Definition: stbdpc.c:3674
application level SI task
BOOLEAN ACTL_IsTrailerBookingAvailable(void *serv_ptr)
Returns whether trailer booking is available based on whether it&#39;s enabled and the number of links cu...
Definition: ap_cntrl.c:3639
Application stb layer control.
E_STB_DP_AUDIO_CODEC STB_DPGetADCodec(U8BIT path)
Returns the type of CODEC to be used for AD decoding.
Definition: stbdpc.c:7816
void STB_DPSetDVBS2(U8BIT path, BOOLEAN dvb_s2)
Set whether the satellite should be tuned to DVB-S/S2 for the tuner in the given decode path...
Definition: stbdpc.c:6312
BOOLEAN APVR_IsRecordingInProgress(void)
Returns TRUE if there are any recordings currently in progress.
Definition: ap_pvr.c:2798
void ADB_SaveEventSchedule(E_STB_DP_SIGNAL_TYPE tuner_type, void *satellite)
Saves the event schedule for all services for the given type of tuner to the database. Note: the database has to support this operation.
Definition: ap_dbacc.c:524
void STB_DPStopDecoding(U8BIT path)
Requests stop of channel decoding (blanks screen).
Definition: stbdpc.c:2910
void ACTL_SetStandbyVCRActive(void)
Reports standby state to the a/v output control state machine.
Definition: ap_cntrl.c:2260
void ADB_GetTransportListForTunerType(E_STB_DP_SIGNAL_TYPE tuner_type, void ***tlist_ptr, U16BIT *num_entries_ptr)
Allocates and returns a list of all transport records in the database for the given type of tuner...
Definition: ap_dbacc.c:1711
Header file - Function prototypes for operating system.
BOOLEAN STB_CiCcIsHDCPRequired(U16BIT service_id)
Tell whether the given service requires HDCP.
Definition: stbcicc.c:609
System Wide Global Technical Data Type Definitions.
void STB_DPStopSI(U8BIT path)
Requests stop of SI engine.
Definition: stbdpc.c:3076
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
BOOLEAN APVR_StopRecording(U32BIT recording_handle)
Stops the given recording.
Definition: ap_pvr.c:2156
void STB_EBUTT_Start(U8BIT path, U16BIT text_pid, U8BIT magazine, U8BIT page)
These functions are called to control whether received TeleText data is processed. Using this functionality ensures that the process of collating page information can be halted when processing resources are a consideration. It is envisaged that some implementations may wish only to collate TeleText content only when the display is being shown, whilst other designs may which to cache significant page content as a background process. Abstracting this functionality from the initialisation routines gives the option to support both solution types.
Definition: stbebutt.c:11222
void STB_AppFreeMemory(void *addr)
Releases previously allocated application heap memory.
Definition: stbheap.c:781
U8BIT ACTL_GetSearchProgress(void)
Returns search progress as a percentage. This works for any of the available types of searches...
Definition: ap_cntrl.c:4242
void * ACTL_GetCurrentSatellite(U8BIT path)
Returns the current satellite being used by the given decode path.
Definition: ap_cntrl.c:1071
U8BIT ACTL_GetRfModulation(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
Returns the modulation mode.
Definition: ap_cntrl.c:1221
void STB_DPSetLNBPower(U8BIT path, E_STB_DP_LNB_POWER state)
Sets LNB power on or off and writes status into decode path store.
Definition: stbdpc.c:4433
Application level HBBTV callback functions.
U32BIT STB_TuneGetActualSymbolRate(U8BIT path)
Returns the actual symbol rate when a tuner has locked.
BOOLEAN ACTL_SuppressSubtitles(BOOLEAN suppress)
Stops subtitles being displayed if another OSD requires them to be hidden, such as CI+...
Definition: ap_cntrl.c:3456
U16BIT STB_DPGetVideoPID(U8BIT path)
Reads the video PID value from decode path store.
Definition: stbdpc.c:7113
void ACTL_FinishManualSearch(void)
Function to be called when a manual service search has completed, or is being stopped.
Definition: ap_cntrl.c:4522
void ATMR_RecordingFailed(U8BIT path)
Handles the timer when a recording fails to start for some reason. This may result in the timer being...
Definition: ap_tmr.c:665
S8BIT STB_TuneGetActualTerrFreqOffset(U8BIT path)
Returns the actual freq offset of the current terrestrial signal.
U8BIT STB_DPAcquireTunerPath(E_STB_DP_SIGNAL_TYPE tuner_type, void *service, void *transport, E_STB_DP_RES_OWNER owner, E_STB_DP_PRIORITY priority, BOOLEAN with_decoders, BOOLEAN for_recording)
Acquires a decode path and all the required resources (tuner, demux, audio and video decoders)...
Definition: stbdpc.c:558
U32BIT ATMR_AddTimer(S_TIMER_INFO *info)
Creates a new timer based on the information supplied.
Definition: ap_tmr.c:189
BOOLEAN ATMR_InitialiseTimer(S_TIMER_INFO *timer_info, E_TIMER_TYPE timer_type, void *serv_ptr, void *event_ptr)
Sets up the given timer info structure with default values for the given timer type using the service...
Definition: ap_tmr.c:724
BOOLEAN STB_DPIsRecordingPath(U8BIT path)
Is the given decode path being used for recording.
Definition: stbdpc.c:1320
void STB_DPSetUserDefinedLNBBands(U8BIT path, U8BIT number_of_bands, S_STB_DP_LNB_BAND *band_definitions)
Stores the pointer to the array of band definitions for the user defined LNB.
Definition: stbdpc.c:4560
E_STB_TUNE_CMODE STB_TuneGetActualCableMode(U8BIT path)
Returns the cable mode when the tuner has locked.
U16BIT ACFG_GetSatelliteScanFreqInc(U32BIT country_code)
Returns the increment frequency to be used when performing a satellite based frequency scan in the gi...
Definition: ap_cfg.c:1318
Header file - Function prototype for init function.
E_STB_AV_ASPECT_MODE ACTL_GetTVAspectMode(void)
Returns the current TV aspect mode.
Definition: ap_cntrl.c:2386
void STB_AVDisableHDMIDecoding(void)
Disables AV output to HDMI.
U8BIT * ACTL_GetRfChanName(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
Returns a pointer to the channel name.
Definition: ap_cntrl.c:1134
void STB_DPStartADDecoding(U8BIT path)
Requests start of channel decoding process.
Definition: stbdpc.c:2479
ADB_SERVICE_TYPE ADB_GetServiceType(void *s_ptr)
Returns the signalled type of the given service.
Definition: ap_dbacc.c:5494
void STB_DPSetModulation(U8BIT path, E_STB_DP_MODULATION modulation)
Set the satellite modulation for the tuner in the given decode path.
Definition: stbdpc.c:6359
void STB_VTSetVideoOutput(S_RECTANGLE *output)
DVBCore application output window for entire video.
Definition: stbvtc.c:150
void ACTL_EnterStandby(void)
Puts DVB into standby mode. It will continue to monitor SI for recordings, SSU updates, etc., unless it goes into low power standby.
Definition: ap_cntrl.c:5081
void STB_DPSetLNBType(U8BIT path, E_STB_DP_LNB_TYPE type)
Writes LNB type value into decode path store.
Definition: stbdpc.c:4498
void STB_DPSetLockEnable(U8BIT path, BOOLEAN state)
Writes lock enable flag into decode path store.
Definition: stbdpc.c:3931
void STB_AVSetAVOutputSource(E_STB_AV_OUTPUTS output, E_STB_AV_SOURCES source, U32BIT param)
Routes a specified AV source to a specified AV output.
U16BIT STB_SIGetPmtCaIdDescArray(U8BIT *pmt_data, U16BIT **pmt_ca_ids)
Parses the given PMT to produce an array of the CA system IDs required by the service or streams on t...
Definition: stbsitab.c:13038
U16BIT ADB_GetServicePCRPid(void *s_ptr)
Returns the PCR PID for the given service.
Definition: ap_dbacc.c:5164
void * STB_DPGetOwnerData(U8BIT path, U32BIT *data_size)
Returns the owner data saved with the path. This data should not be freed.
Definition: stbdpc.c:1993
BOOLEAN ASTE_InStandby(void)
Definition: ap_state.c:117
BOOLEAN ACI_StartOperatorSearchForModule(U32BIT module)
Called by the app to start an operator profile search for the given module.
Definition: ap_ci.c:1244
Header file - Function prototypes for DVB subtitles api.
Header file - Function prototypes for heap memory.
void ADB_GetServiceIds(void *s_ptr, U16BIT *onet_id, U16BIT *trans_id, U16BIT *serv_id)
Returns the original network id, transport id and service id for the given service.
Definition: ap_dbacc.c:4982
void ADB_GetTransportCableTuningParams(void *t_ptr, U32BIT *freq_hz, E_STB_DP_CMODE *mode, U16BIT *symrate)
Returns the parameters needed to tune a cable tuner to a transport.
Definition: ap_dbacc.c:2856
void STB_GCSetCIStandby(BOOLEAN standby)
Enables / disables CI standby state.
Definition: stbgc.c:690
BOOLEAN ACTL_StartAudioDescription(U8BIT path)
Starts decoding an audio description stream, if available, on the given path. If AD isn&#39;t currently a...
Definition: ap_cntrl.c:2721
void * STB_OSCreateMutex(void)
Create a mutex.
void STB_DPSetADEnabled(U8BIT path, BOOLEAN state)
Writes the AD Audio into decode path store. To be set to ON or OFF. The exact ON state is depends if ...
Definition: stbdpc.c:3371
BOOLEAN ACI_AcquireCISlot(U8BIT path, void *s_ptr)
Acquires a CI slot for the given path on the given service after releasing any slot already being use...
Definition: ap_ci.c:1433
U8BIT ACTL_ChangeVolume(S8BIT volume_change)
Changes the main audio volume and returns the new volume.
Definition: ap_cntrl.c:4791
BOOLEAN ATMR_DeleteTimer(U32BIT handle)
Deletes the timer with the given handle.
Definition: ap_tmr.c:436
void ACTL_InitialiseAppControl(void)
Control system initialisation.
Definition: ap_cntrl.c:437
void STB_DPSetDISEQCTone(U8BIT path, E_STB_DP_DISEQC_TONE state)
Sets DiSEqC tone and writes status into decode path store.
Definition: stbdpc.c:4981
U8BIT STB_AVGetHDMISupportedModes(E_STB_AV_VIDEO_FORMAT **modes)
Returns the resolutions supported by the HDMI.
Application header file.
void * ATMR_GetRecordService(U8BIT path)
Returns the service for the recording timer on the given path.
Definition: ap_tmr.c:972
void STB_AVSetADVolume(U8BIT path, U8BIT vol)
Sets the volume of the audio description output.
E_STB_DP_AUDIO_CODEC ADB_GetAudioCodecFromStream(ADB_STREAM_TYPE audio_stream_type)
Derive audio codec from stream.
Definition: ap_dbacc.c:12078
U16BIT * ACFG_GetSatelliteScanSymbolRates(U32BIT country_code)
Returns a fixed array of symbol rates to be used when performing a satellite based frequency scan in ...
Definition: ap_cfg.c:1344
void STB_SIReleaseCaIdDescArray(U16BIT *desc_array, U8BIT num_entries)
Frees the memory used by the descriptor array specified.
Definition: stbsitab.c:12090
BOOLEAN ACTL_TuneToUserDefinedParams(U8BIT path, S_MANUAL_TUNING_PARAMS *tuning_params, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
Tunes to the given set of tuning parameters.
Definition: ap_cntrl.c:1522
BOOLEAN ASI_PmtReported(U8BIT path)
Returns TRUE if pmt has been reported to third parties.
Definition: ap_si.c:9617
void ACTL_ApplyParentalControl(U8BIT path, void *s_ptr)
Checks the parental control for the current event on the given service to determine whether decoding ...
Definition: ap_cntrl.c:3187
BOOLEAN ADB_GetEventDoNotScramble(void *event_ptr)
Returns the do_not_scramble flag for the event, which will have been found by looking backwards in th...
Definition: ap_dbacc.c:9057
BOOLEAN STB_DPGetLockEnable(U8BIT path)
Reads the lock enable flag state from decode path store.
Definition: stbdpc.c:3954
void ADB_GetTransportServiceList(void *t_ptr, void ***slist_ptr, U16BIT *num_entries_ptr)
Allocates and returns a list of all services in the database on the given transport.
Definition: ap_dbacc.c:3332
void ASTE_StartServiceSearch(void)
Definition: ap_state.c:155
BOOLEAN ADB_GetServiceIsHd(void *s_ptr)
Returns whether the service is signalled as an HD service.
Definition: ap_dbacc.c:5260
BOOLEAN ACTL_GetDecodePausedState(U8BIT path)
Gets user paused flag value.
Definition: ap_cntrl.c:2600
BOOLEAN ACTL_StartManualSearch(E_STB_DP_SIGNAL_TYPE tuner_type, S_MANUAL_TUNING_PARAMS *tuning_params, E_ACTL_SEARCH_TYPE type)
Start a service search on, or just tune to, the transport defined by the given tuning parameters...
Definition: ap_cntrl.c:4425
U16BIT ADB_GetEventId(void *event_ptr)
Returns the event id for the given event.
Definition: ap_dbacc.c:8970
Header file - Function prototypes for Demux control.
void ACTL_SetTVAspectConversion(E_STB_AV_ASPECT_RATIO aspect_ratio, E_STB_AV_ASPECT_MODE aspect_mode)
Used to set the aspect conversion applied to the video based on the TV aspect ratio and aspect mode t...
Definition: ap_cntrl.c:2400
U16BIT ACTL_GetHDMIResolutions(E_STB_AV_VIDEO_FORMAT **video_formats, U16BIT *current_index)
Returns an array of valid HDMI resolutions and the index of the currently selected format...
Definition: ap_cntrl.c:3011
U8BIT STB_DPPathForAudioDecoder(U8BIT decoder_num)
Returns the decode path that is using the given audio decoder.
Definition: stbdpc.c:1436
BOOLEAN ACTL_CanServiceBeViewed(void *s_ptr)
Checks whether there&#39;s a tuner available to view the given service. This takes into account whether t...
Definition: ap_cntrl.c:5044
BOOLEAN STB_GCCompareDateTime(U16BIT code1, U8BIT hour1, U8BIT min1, U8BIT secs1, U16BIT code2, U8BIT hour2, U8BIT min2, U8BIT secs2, E_STB_GC_COMPTYPE comp)
Compares one date/time to another.
Definition: stbgc.c:1647
Header file - Function prototypes for PES collection task.
void STB_EBUTT_Hide(void)
Called to halt the continuous display of TeleText page content, and to clear the relevant area of the...
Definition: stbebutt.c:11403
U16BIT ACTL_GetRfSymbolRate(E_STB_DP_SIGNAL_TYPE tuner_type, U16BIT id)
Returns the channel symbol rate.
Definition: ap_cntrl.c:1185
BOOLEAN ACTL_IsTuned(U8BIT path)
Returns whether the given path is currently tuned.
Definition: ap_cntrl.c:1974
BOOLEAN ACFG_GetTerRfChannelTable(U32BIT country_code, ACFG_TER_RF_CHANNEL_DATA **rf_chan_data_ptr, U16BIT *num_entries_ptr)
Returns a pointer to the channel table for a terrestrial tuner for the given country.
Definition: ap_cfg.c:1030
U16BIT ACFG_GetMaxSatelliteScanFreq(U32BIT country_code)
Returns the maximum frequency to be used when performing a satellite based frequency scan in the give...
Definition: ap_cfg.c:1292
void STB_DPSetCableMode(U8BIT path, E_STB_DP_CMODE mode)
Writes cable tuning mode value into decode path store.
Definition: stbdpc.c:6743
void ACTL_PauseSubtitles(void)
Disables the display of subtitles but processing continues.
Definition: ap_cntrl.c:3519
E_STB_AV_VIDEO_FORMAT ACTL_GetActualVideoMode(U16BIT *width, U16BIT *height)
Reads the saved video format and returns the best mode available if it&#39;s set to AUTO or is invalid fo...
Definition: ap_cntrl.c:2810
void STB_DPSetFEC(U8BIT path, E_STB_DP_FEC fec)
Writes FEC value into decode path store.
Definition: stbdpc.c:6254
void STB_DPStopADDecoding(U8BIT path)
Requests stop of channel decoding.
Definition: stbdpc.c:2781
U8BIT ACTL_TuneToTransport(U8BIT path, S_ACTL_OWNER_INFO *owner_info, void *t_ptr, E_ACTL_SI_SRCH_REQD reqd_si, BOOLEAN relock_on)
Tunes to the given transport and sets the type of SI monitoring that will be started when the tuning ...
Definition: ap_cntrl.c:1584
BOOLEAN STB_DPSetAudioCodec(U8BIT path, E_STB_DP_AUDIO_CODEC codec)
Sets the type of CODEC to be used for Audio decoding.
Definition: stbdpc.c:7846
void STB_AVSetTVType(U8BIT path, E_STB_AV_ASPECT_RATIO ratio, E_STB_AV_VIDEO_FORMAT format)
Sets the aspect ratio and signal format for the connected television.
void STB_AVBlankVideo(U8BIT path, BOOLEAN blank)
Blanks or unblanks the video display.
U16BIT ADB_GetServiceAudioPid(void *s_ptr)
Returns the audio PID for the given service. This will be the one chosen based on the settings for la...
Definition: ap_dbacc.c:5189
BOOLEAN APVR_IsTimeshiftStarted(void)
Checks whether timeshift has been started, which includes both recording and playback.
Definition: ap_pvr.c:2454
E_STB_TUNE_TCODERATE STB_TuneGetActualTerrLpCodeRate(U8BIT path)
Returns the LP code rate of the current terrestrial signal.
#define DBGPRINT(...)
Definition: dbgfuncs.h:74
BOOLEAN ADB_ServiceHasSubtitles(void *serv_ptr, BOOLEAN *dvb_subs)
Determines whether the given service has subtitles, DVB or teletext.
Definition: ap_dbacc.c:6789
void STB_DPStopAudioDecoding(U8BIT path)
Requests stop of channel decoding.
Definition: stbdpc.c:2846
void ACTL_TuneOff(U8BIT path)
Stops tuning on the given path.
Definition: ap_cntrl.c:2079
BOOLEAN ACTL_ToggleMute(void)
Toggles the current mute state and returns the new mute setting.
Definition: ap_cntrl.c:4859
void ACTL_ReTuneSubtitles(void)
Stops and restarts subtitle decoding on the live path. This may be required due to a change in langua...
Definition: ap_cntrl.c:2173
void ACTL_ReleaseChannelLock(void)
Releases the lock on a channel after decoding has been blocked due to the service being parental lock...
Definition: ap_cntrl.c:2127
E_STB_TUNE_TCONST STB_TuneGetActualTerrConstellation(U8BIT path)
Returns the constellation of the current terrestrial signal.
U8BIT STB_DPPathForVideoDecoder(U8BIT decoder_num)
Returns the decode path that is using the given video decoder.
Definition: stbdpc.c:1490
BOOLEAN ACTL_IsSearchComplete(void)
Returns TRUE if current search has finished. This works for any of the available types of searches...
Definition: ap_cntrl.c:4228
BOOLEAN ACTL_ReleasePathOwnership(U8BIT path, E_STB_DP_RES_OWNER owner)
Releases ownership of the path, and frees any associated data, if the given owner is the path&#39;s owner...
Definition: ap_cntrl.c:5011
BOOLEAN STB_OTAStartLoader(U8BIT path, U16BIT onet_id, U16BIT tran_id, U16BIT serv_id, U16BIT download_pid, F_SSU_VERSION_CALLBACK version_cb)
Starts the over-the-air download process.
Definition: stbota.c:133
Application database access functions.
BOOLEAN ACTL_AreSubtitlesStarted(void)
Returns whether subtitles have been started, even if they aren&#39;t being displayed. ...
Definition: ap_cntrl.c:3626
void STB_DPSetUnicableChannel(U8BIT path, U8BIT chan)
Sets the current Unicable Channel (User Band).
Definition: stbdpc.c:5318
E_STB_TUNE_TMODE STB_TuneGetActualTerrMode(U8BIT path)
Returns the actual mode of the current terrestrial signal.
E_STB_DP_AUDIO_MODE STB_DPGetAudioMode(U8BIT path)
Reads the audio mode value from decode path store.
Definition: stbdpc.c:7552
BOOLEAN ACTL_ReleasePath(U8BIT path)
Releases the decode path and all resources no longer needed. The path may not be released if the path...
Definition: ap_cntrl.c:4941
ADB_STREAM_TYPE ADB_GetStreamType(void *stream_ptr)
Returns the type of the given stream.
Definition: ap_dbacc.c:7083
void ACTL_ReTuneAudio(void)
Stops and restarts audio decoding on the live path. This may be required due to a change in language ...
Definition: ap_cntrl.c:2153
Header file - Function prototypes for front panel control.
BOOLEAN ADB_GetTransportSearchFlag(void *t_ptr)
Returns whether a transport has been used during a service scan operation.
Definition: ap_dbacc.c:2210
void STB_DPReleaseAllPaths(void)
Releases all decode paths and all the resources they are using.
Definition: stbdpc.c:933
void STB_AVSetAudioDelay(U8BIT path, U16BIT millisecond)
Sets the audio delay on the given path.
void ADB_GetTransportTerrestrialTuningParams(void *t_ptr, E_STB_DP_TTYPE *terr_type, U32BIT *freq_hz, E_STB_DP_TMODE *mode, E_STB_DP_TBWIDTH *bwidth, U8BIT *plp_id)
Returns the settings to tune to the given DVB-T/T2 transport.
Definition: ap_dbacc.c:2776
void ADB_SetTunedTransport(U8BIT path, void *t_ptr)
Sets the given transport as the one tuned to on the given decode path. The transport&#39;s network is als...
Definition: ap_dbacc.c:2988
U8BIT ACTL_GetServiceSearchPath()
Returns path used buy currently running search. This works for any of the available types of searches...
Definition: ap_cntrl.c:4344
Header file - macros and function prototypes for public use.
Application level CI Operator Profile functions.
void STB_DPSetOwner(U8BIT path, E_STB_DP_RES_OWNER owner)
Sets the owner of the given path.
Definition: stbdpc.c:1885
void STB_DPSetTerrPLP(U8BIT path, U8BIT plp_id)
Sets terrestrial T2 PLP id into decode path store.
Definition: stbdpc.c:6675
E_STB_DP_VIDEO_CODEC ADB_GetVideoCodecFromStream(ADB_STREAM_TYPE video_stream_type)
Derive video codec from stream.
Definition: ap_dbacc.c:12108
void ASTE_StartSSUSearch(void)
Definition: ap_state.c:170
void ADB_ReleaseEventData(void *event_ptr)
Frees any memory allocated for the given event and the event itself.
Definition: ap_dbacc.c:7907