MHEG5  18.9.0
MHEG5 Documentation
glue_main.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2011 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 /*---includes for this file--------------------------------------------------*/
26 #include "stb_os.h"
27 #include "glue_memory.h"
28 #include "glue_debug.h"
29 #include "glue_queue.h"
30 #include "glue_timers.h"
31 #include "glue_main.h"
32 #include "mheg5_control.h"
33 #include "dvb_service.h"
34 #if defined(INCLUDE_IC)
35 #include "http_interface.h"
36 #endif
37 #ifdef INCLUDE_IC
38 #include "dvb_ics.h"
39 #endif
40 #ifndef CI_PLUS_ONLY
41 #include "glue_dsmcc.h"
42 #endif
43 #include "mh5control.h"
44 #include "mh5support.h"
45 #include "glue_events.h"
46 #ifdef INCLUDE_ICS
47 #include "mh5streamer.h"
48 #endif
49 #include "mg_osd.h"
50 
51 /*---constant definitions for this file--------------------------------------*/
52 
53 #define MAIN_STACK_SIZE 0x2000
54 
55 #define PRG_DONE_NONE 0
56 #define PRG_DONE_INIT 1
57 #define PRG_DONE_GRAPHICS 2
58 #define PRG_DONE_MEMORY 3
59 #define PRG_DONE_SYNCS 4
60 #define PRG_DONE_QUEUE 5
61 #define PRG_DONE_DSMCC 6
62 #define PRG_DONE_MAIN 7
63 #define PRG_DONE_TIMERS 8
64 #define PRG_DONE_HTTP 9
65 #define PRG_DONE_MHEG5 10
66 
67 /* Mheg has three post process funcs:
68  * 1) fileorm, 2) streamevent, 3) streamer,
69  * Very unlikely to need more than that
70  */
71 #define MAX_PP_FUNCS 4
72 
73 
74 /*---local typedef structs for this file-------------------------------------*/
75 
76 typedef struct s_pp_list
77 {
79 } S_PP_LIST;
80 
81 typedef enum
82 {
87 } E_ApiStatus;
88 
89 
90 /* Default service 'rec://svc/def' storage variable */
91 static S_DVB_LOCATOR default_service = { 0, 0, 0 };
92 
93 static S32BIT default_service_index = 0;
94 
95 /*---local (static) variable declarations for this file----------------------*/
96 
97 static void *task_handle;
98 /* Semaphore used to synchronise Stop/Quit/Reset functions */
99 static void *stop_sema = 0;
100 /* Semaphore used to synchronise Pause function */
101 static void *pause_sema = 0;
102 /* Mutex to protect against multiple threads accessing API functions */
103 static void *api_mutex = 0;
104 
105 static BOOLEAN active_state = TRUE;
106 static E_ApiStatus running_state = VS_STOPPED;
107 static E_ApiStatus started_state = VS_STOPPED;
108 static BOOLEAN restore_active = FALSE;
109 
110 static F_MainProcess main_proc_func;
111 static S_PP_LIST post_processes[MAX_PP_FUNCS];
112 static BOOLEAN ciplus_request_ndt = FALSE;
113 
114 /*---local function definitions----------------------------------------------*/
115 
116 /*---global function definitions---------------------------------------------*/
117 static void stopEngine(MHEG5StopEventParams_t *params);
118 
119 
120 static void DummyMainFunc(void)
121 {
122 }
123 
124 static BOOLEAN DummyPostFunc(void)
125 {
126  return FALSE;
127 }
128 
135 static void MHEG5Main(void *pArgs)
136 {
137  S_MhegMessage event_msg;
138  int i;
139  FUNCTION_START(x)
140  while (1)
141  {
142  if (VQ_GetMsg( &event_msg ) != MHERR_OK)
143  {
144  STB_OSTaskDelay(10);
145  }
146  else if (event_msg.proc_msg_func == NULL)
147  {
148  /* received Quit msg */
149  VQ_Close();
150  break;
151  }
152  else
153  {
154  event_msg.proc_msg_func( &(event_msg.data));
155 
156  for (i = 0; i != MAX_PP_FUNCS; i++)
157  {
158  if (post_processes[i].pp_func != DummyPostFunc)
159  {
160  do
161  {
162  main_proc_func();
163  }
164  while (post_processes[i].pp_func());
165  post_processes[i].pp_func = DummyPostFunc;
166  }
167  }
168  main_proc_func();
169  }
170  }
171  TRACE(TERROR, (" **** EXIT **** %d ", running_state));
172  if (running_state == VS_RUNNING)
173  {
175  stopEngine( &event_msg.data.stop );
176  }
177  else
178  {
179  STB_OSSemaphoreSignal(stop_sema);
180  }
181  FUNCTION_FINISH(x)
182 }
183 
184 static E_MhegErr CreateSyncs(void)
185 {
186  BOOLEAN result = MHERR_OK;
187  FUNCTION_START(x)
188  api_mutex = STB_OSCreateMutex();
189  if (api_mutex == NULL)
190  {
192  }
193  else
194  {
195  stop_sema = STB_OSCreateSemaphore();
196  if (stop_sema == NULL)
197  {
199  }
200  else
201  {
202  pause_sema = STB_OSCreateSemaphore();
203  if (pause_sema == NULL)
204  {
206  }
207  else
208  {
209  /* Initial value for semaphore is 1, so do wait to decrement value to 0 */
210  STB_OSSemaphoreWait(pause_sema);
211  STB_OSSemaphoreWait(stop_sema);
212  }
213  }
214  }
215  FUNCTION_FINISH(x)
216  return result;
217 }
218 
219 static void DestroySyncs(void)
220 {
221  FUNCTION_START(x)
222  if (pause_sema != 0)
223  {
224  STB_OSDeleteSemaphore(pause_sema);
225  pause_sema = 0;
226  }
227  if (stop_sema != 0)
228  {
229  STB_OSDeleteSemaphore(stop_sema);
230  stop_sema = 0;
231  }
232  if (api_mutex != 0)
233  {
234  STB_OSDeleteMutex(api_mutex);
235  api_mutex = 0;
236  }
237  FUNCTION_FINISH(x)
238 }
239 
240 /* Called by External tasks*/
242 {
243  BOOLEAN result;
244  STB_OSMutexLock( api_mutex );
245  result = (started_state == VS_RUNNING) ? TRUE : FALSE;
246  STB_OSMutexUnlock( api_mutex );
247  return result;
248 }
249 
251 {
252  STB_OSMutexLock( api_mutex );
253  if (started_state == VS_REBOOT)
254  {
255  /* as far as external API is concerned, 'running' is the current state */
256  started_state = VS_RUNNING;
257  }
258  STB_OSMutexUnlock( api_mutex );
259 }
260 
262 {
263  FUNCTION_START(x)
264  if (func == NULL)
265  {
266  main_proc_func = DummyMainFunc;
267  }
268  else
269  {
270  main_proc_func = func;
271  }
272  FUNCTION_FINISH(x)
273 }
274 
276 {
277  int i;
278  FUNCTION_START(x)
279  for (i = 0; i != MAX_PP_FUNCS; i++)
280  {
281  if (post_processes[i].pp_func == func)
282  break;
283  }
284  if (i == MAX_PP_FUNCS)
285  {
286  for (i = 1; i != MAX_PP_FUNCS; i++)
287  {
288  if (post_processes[i].pp_func == DummyPostFunc)
289  {
290  post_processes[i].pp_func = func;
291  break;
292  }
293  }
294  }
295  FUNCTION_FINISH(x)
296 }
297 
298 static void ResetPostFuncs( void )
299 {
300  int i;
301  FUNCTION_START(x)
302  for (i = 0; i != MAX_PP_FUNCS; i++)
303  {
304  post_processes[i].pp_func = DummyPostFunc;
305  }
306  FUNCTION_FINISH(x)
307 }
308 
314 static E_MhegErr MHEG5Exit( void )
315 {
316  E_MhegErr result;
317  S_MhegMessage msg;
318 
319  FUNCTION_START(x)
320  ResetPostFuncs();
322  TRACE(TSTATE, ("************** EXIT! *************"));
323  /* Post event to cause main task to quit */
324  msg.proc_msg_func = NULL;
325  msg.data_type = DT_NONE;
326  ResetPostFuncs();
327  result = VQ_PutMsg(&msg, PRTY_CRITICAL);
328  if (result == MHERR_OK)
329  {
330  /* Wait for the close event to be processed */
331  STB_OSSemaphoreWait( stop_sema );
332  STB_OSTaskDelay(10);
333  STB_OSDestroyTask(task_handle);
334  task_handle = NULL;
335  }
336  FUNCTION_FINISH(x)
337  return result;
338 }
339 
362 {
363  E_MhegErr result;
364  U32BIT progress = PRG_DONE_NONE;
365 
367 
368  TRACE(TSTATE,(""))
369 
370 #ifdef TRACING
371  trace_set_time();
372 #endif
373 
374  if (pSetup == NULL)
375  {
376  DPL1(("ERROR: Open - Setup NULL\n"));
377  result = MHERR_BAD_PARAMETER;
378  }
379  else if (strcmp(pSetup->version_string, MHEG5VersionString()))
380  {
381  DPL1(("ERROR: Open - Version Mismatch: \"%s\" == \"%s\"?\n",pSetup->version_string, MHEG5VersionString()));
382  result = MHERR_VERSION_MISMATCH;
383  }
384  else if (task_handle)
385  {
386  result = MHERR_COMP_ALREADY_OPEN;
387  }
388  else if (pSetup->taskPriority < MHEG5_MIN_TASK_PRIORITY)
389  {
390  DPL1(("Is taskPriority 0x%x >= 0x%x ?\n", pSetup->taskPriority, MHEG5_MIN_TASK_PRIORITY));
391  result = MHERR_BAD_TASK_PRIORITY;
392  }
393  else
394  {
395  TRACE(TSTATE,(""))
396 
397  // Initialise static data for this file
398  main_proc_func = DummyMainFunc;
399  ResetPostFuncs();
400 
401  result = MH5_SupportInitialise( pSetup );
402  if (result == MHERR_OK)
403  {
404  TRACE(TSTATE,(""))
405  progress = PRG_DONE_INIT;
406 
407  result = MG_Initialise( pSetup->screenWidth,
408  pSetup->screenHeight,
409  pSetup->colourDepth );
410  }
411  if (result == MHERR_OK)
412  {
413  TRACE(TSTATE,(""))
414  progress = PRG_DONE_GRAPHICS;
415 
417  {
419  }
420  else
421  {
422  progress = PRG_DONE_MEMORY;
423  result = CreateSyncs();
424  if (result == MHERR_OK)
425  {
426  progress = PRG_DONE_SYNCS;
427  result = VQ_Open( pSetup );
428  if (result == MHERR_OK)
429  {
430  progress = PRG_DONE_QUEUE;
431  #ifndef CI_PLUS_ONLY
432  result = MH5GlueDsmccOpen( pSetup->taskPriority );
433  #endif /* !CI_PLUS_ONLY */
434  }
435  }
436  }
437  }
438  if (result == MHERR_OK)
439  {
440  TRACE(TSTATE,(""))
441  progress = PRG_DONE_DSMCC;
442  active_state = TRUE;
443  task_handle = STB_OSCreateTask( MHEG5Main, NULL, MAIN_STACK_SIZE,
444  (U8BIT)pSetup->taskPriority, (U8BIT *)"MH5GlueMain");
445  if (task_handle == NULL)
446  {
447  TRACE(TERROR, ("Failed To Create Task"));
449  }
450  else
451  {
452  progress = PRG_DONE_MAIN;
453  /* timer task is +2 higher priority */
454  result = VT_TimersInit( pSetup->taskPriority + 2 );
455  if (result == MHERR_OK)
456  {
457  progress = PRG_DONE_TIMERS;
458  #if defined(INCLUDE_IC)
459  if (httpOpen(pSetup->taskPriority) != HTTP_OK)
460  {
461  TRACE(TERROR, ("Failed httpOpen"));
462  result = MHERR_COMP_NOT_OPEN;
463  }
464  #endif /* INCLUDE_IC */
465  }
466  }
467  }
468  if (result == MHERR_OK)
469  {
470  TRACE(TSTATE,(""))
471  progress = PRG_DONE_HTTP;
472  result = MHEG5Initialise( pSetup );
473  if (result == MHERR_OK)
474  {
475  progress = PRG_DONE_MHEG5;
476  #ifdef INCLUDE_ICS
477  /* Open the IC streamer */
478  result = MHEG5StreamerOpen(pSetup->streamerBuffer, pSetup->streamerBufferSize, pSetup->taskPriority);
479  #endif
480  }
481  }
482 
483  if (result == MHERR_OK)
484  {
486  }
487  }
488  /* ------------------------------------------------------------ */
489  if (result != MHERR_OK && result != MHERR_COMP_ALREADY_OPEN)
490  {
491  TRACE(TSTATE,("progress=%d",progress))
492  switch (progress)
493  {
494  case PRG_DONE_MHEG5:
495  MHEG5_Terminate();
496 
497  case PRG_DONE_HTTP:
498  #if defined(INCLUDE_IC)
499  httpClose();
500  #endif
501 
502  case PRG_DONE_TIMERS:
503  VT_TimersExit();
504 
505  case PRG_DONE_MAIN:
506  MHEG5Exit();
507 
508  case PRG_DONE_DSMCC:
509  #ifndef CI_PLUS_ONLY
511  #endif
512 
513  case PRG_DONE_QUEUE:
514  VQ_Close();
515 
516  case PRG_DONE_SYNCS:
517  DestroySyncs();
518 
519  case PRG_DONE_MEMORY:
521 
522  case PRG_DONE_GRAPHICS:
523  MG_Terminate();
524  case PRG_DONE_INIT:
525  default:
526  /*nothing*/;
527  }
528  }
529  TRACE(TSTATE,("result=%d",result))
531  return result;
532 }
533 
542 {
543  E_MhegErr result;
544 
545  FUNCTION_START(x)
546  if (task_handle == NULL)
547  {
548  result = MHERR_COMP_NOT_OPEN;
549  }
550  else
551  {
552  MHEG5_Stop();
553 
555 
556  #ifdef INCLUDE_ICS
557  /* Close the IC streamer */
559  #endif
560 
561  #if defined(INCLUDE_IC)
562  httpClose();
563  #endif /* INCLUDE_IC */
564 
565  VT_TimersExit();
566 
567  result = MHEG5Exit();
568 
569  MHEG5_Terminate();
570 
571  #ifndef CI_PLUS_ONLY
573  #endif /* !CI_PLUS_ONLY */
574 
575  VQ_Close();
576 
577  DestroySyncs();
578 
580 
581  MG_Terminate();
582 
583  }
584  FUNCTION_FINISH(x)
585  return result;
586 }
587 
588 /************************ Start / Stop Functions *********************************/
589 
597 static void startEngine( S_StartDsmApp *params )
598 {
599  S_DvbLocator locator;
600 #ifndef CI_PLUS_ONLY
601  U32BIT carouselId;
602  BOOLEAN clear;
603 #endif /*CI_PLUS_ONLY*/
604 
605  FUNCTION_START(x)
606  if (DVB_MhegIndexToDvbLocator(params->serviceIndex, &locator) != MHERR_OK)
607  {
608  TRACE(TERROR, ("si=%x", params->serviceIndex))
609  }
610  else
611  {
612  TRACE(TSTATE, ("starting sid=0x%x", locator.service_id))
613  #ifndef CI_PLUS_ONLY
614  if ( !ciplus_request_ndt &&
615  (locator.transport_stream_id != default_service.transport_stream_id ||
616  locator.original_network_id != default_service.original_network_id))
617  {
618  clear = TRUE;
619  }
620  else
621  {
622  ciplus_request_ndt = FALSE;
623  clear = FALSE;
624  }
625  carouselId = MHEG5tuneProcess(&locator, params->serviceIndex);
626  if (MH5GlueDsmccStart(&locator, carouselId, clear) == MHERR_OK)
627  {
628  TRACE(TSTATE, ("Started service 0x%x (%d)", locator.service_id, locator.service_id))
629  }
630  #else
631  TRACE(TSTATE, ("DSM-CC not build in"))
632  #endif /* !CI_PLUS_ONLY */
633  /* Store default service information */
634  default_service = locator;
635  default_service_index = params->serviceIndex;
636  }
637  FUNCTION_FINISH(x)
638 }
639 
640 /*******************************************************************************
641  * @brief This function starts MHEG5 engine on the current broadcast service.
642  * It will cause MHEG5 engine to start retrieving the associated
643  * service information (i.e. PMT) and launch an appropriate broadcast
644  * application. This should mean MHEG5 engine will mount an associated
645  * DSM-CC carousel for this application. If this should fail, MHEG5 engine
646  * will periodically try to mount the DSM-CC boot carousel in order to
647  * launch the default MHEG-5 auto boot application.
648  * This is a non-blocking function, which may return before completion.
649  * It should be called whenever a tuning process has completed and
650  * the external application is aware of a new broadcast service.
651  @ @param serviceIndex "Service Index" for the new service
652  * @param quietMode pointer to return channel change mode that MHEG5 requires
653  * of the external application. Can be NULL, if not interested in mode.
654  * @return MHERR_OK - Success
655  * MHERR_COMP_NOT_OPEN - Component not ready to start.
656  * MHERR_COMP_ALREADY_STARTED - Component has already been started.
657  * MHERR_BAD_PARAMETER - Invalid parameter.
658  *******************************************************************************/
659 E_MhegErr MHEG5_Start( S32BIT serviceIndex, E_ChannelStartMode *quietMode )
660 {
661  MHEG5eventMessage_t event_msg;
662  E_MhegErr err;
663  E_ApiStatus prev_state;
664  if (task_handle == NULL)
665  {
666  TRACE(TERROR, ("MHEG5 Not Open"));
667  err = MHERR_COMP_NOT_OPEN;
668  }
669  else
670  {
671  STB_OSMutexLock( api_mutex );
672  if (started_state == VS_RUNNING)
673  {
674  TRACE(TERROR, ("MHEG5 already Started"));
676  }
677  else
678  {
679  prev_state = started_state;
680  started_state = VS_RUNNING;
681  err = MHERR_OK;
682  }
683  STB_OSMutexUnlock( api_mutex );
684  if (err == MHERR_OK)
685  {
686  #ifndef CI_PLUS_ONLY
687  if (quietMode != NULL)
688  {
689  *quietMode = MHEG5_GetTuningInfoMode(serviceIndex);
690  }
691  #endif
692  TRACE(TSTATE, ("serviceIndex=%x", serviceIndex))
693  event_msg.proc_msg_func = (F_MSG_PROCESS)startEngine;
694  event_msg.data_type = DT_VALUE;
695  event_msg.data.start.serviceIndex = serviceIndex;
696  err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
697  if (err != MHERR_OK)
698  {
699  STB_OSMutexLock( api_mutex );
700  started_state = prev_state;
701  STB_OSMutexUnlock( api_mutex );
702  TRACE(TERROR, ("VQ_PutMsg Failed"));
703  }
704  }
705  }
706  return err;
707 }
708 
716 static void stopEngine(MHEG5StopEventParams_t *params)
717 {
718  U8BIT action = params->action;
719 
720  FUNCTION_START(x)
721  TRACE(TSTATE, ("action=%d", action));
722  action = MHEG5HandleEngineStopAction( action );
723  if (action == STOP_ACTION_MHEG_TUNE)
724  {
725  running_state = VS_TUNING;
726  }
727  else
728  {
729  running_state = VS_STOPPED;
730  }
731  if (action == STOP_ACTION_CI_PLUS_NDT)
732  {
733  ciplus_request_ndt = TRUE;
734  }
735 #ifndef CI_PLUS_ONLY
736  /* Attempt carousel unload or boot stop */
737  MH5GlueDsmccStop( action );
738 #endif /* !CI_PLUS_ONLY */
739 
740  TRACE(TSTATE, ("Last serv_id=0x%x,net_id=0x%x", default_service.service_id, default_service.original_network_id))
741 
742  /* free 'string' block memory no longer required */
743  STR_TidyUp();
744 
745  /*
746  default_service.original_network_id = 0;
747  default_service.transport_stream_id = 0;
748  */
749  default_service.service_id = 0;
750  /* signal that caller task can resume */
751  STB_OSSemaphoreSignal(stop_sema);
752  TRACE(TSTATE, ("done"));
753  FUNCTION_FINISH(x)
754 }
755 
756 /*******************************************************************************
757  * @brief Tells MHEG5 engine to enter stop state (i.e. no broadcast service).
758  * This function should kill any currently running MHEG5 broadcast
759  * application, and release allocated memory and resources.
760  * This is a synchronous blocking function.
761  * @return MHERR_OK - Success
762  * MHERR_COMP_NOT_STARTED - Component not ready to stop.
763  *******************************************************************************/
765 {
766  MHEG5eventMessage_t event_msg;
767  E_MhegErr cqu_err;
768  E_ApiStatus prev_state;
769 
770  FUNCTION_START(x)
771  if (task_handle == NULL)
772  {
773  TRACE(TERROR, ("MHEG5 Not Open"));
774  cqu_err = MHERR_COMP_NOT_OPEN;
775  }
776  else
777  {
778  STB_OSMutexLock( api_mutex );
779  prev_state = started_state;
780  if (started_state == VS_STOPPED)
781  {
782  TRACE(TERROR, ("MHEG5 Not Started"));
783  cqu_err = MHERR_COMP_NOT_STARTED;
784  }
785  else
786  {
787  started_state = VS_STOPPED;
788  cqu_err = MHERR_OK;
789  }
790  STB_OSMutexUnlock( api_mutex );
791  if (cqu_err == MHERR_OK)
792  {
793  event_msg.proc_msg_func = (F_MSG_PROCESS)stopEngine;
794  event_msg.data_type = DT_VALUE;
796  cqu_err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
797  if (cqu_err != MHERR_OK)
798  {
799  STB_OSMutexLock( api_mutex );
800  started_state = prev_state;
801  STB_OSMutexUnlock( api_mutex );
802  TRACE(TERROR, ("VQ_PutMsg Failed"));
803  }
804  else
805  {
806  /* Wait for notification that stop has been processed */
807  STB_OSSemaphoreWait(stop_sema);
808  TRACE(TSTATE, (" vgr done"));
809  }
810  }
811  }
812  FUNCTION_FINISH(x)
813  return cqu_err;
814 }
815 
816 
817 /*******************************************************************************
818  * @brief Tells MHEG5 engine to enter stop state (i.e. no broadcast service).
819  * This function should kill any currently running MHEG5 broadcast
820  * application, and release allocated memory and resources.
821  * This is a synchronous blocking function.
822  * @return MHERR_OK - Success
823  * MHERR_COMP_NOT_STARTED - Component not ready to stop.
824  *******************************************************************************/
826 {
827  MHEG5eventMessage_t event_msg;
828  E_MhegErr cqu_err;
829  E_ApiStatus prev_state;
830 
831  FUNCTION_START(x)
832  if (task_handle == NULL)
833  {
834  TRACE(TERROR, ("MHEG5 Not Open"));
835  cqu_err = MHERR_COMP_NOT_OPEN;
836  }
837  else
838  {
839  STB_OSMutexLock( api_mutex );
840  prev_state = started_state;
841  if (started_state == VS_STOPPED)
842  {
843  cqu_err = MHERR_COMP_NOT_STARTED;
844  }
845  else
846  {
847  started_state = VS_STOPPED;
848  cqu_err = MHERR_OK;
849  }
850  STB_OSMutexUnlock( api_mutex );
851  if (cqu_err == MHERR_OK)
852  {
853  event_msg.proc_msg_func = (F_MSG_PROCESS)stopEngine;
854  event_msg.data_type = DT_VALUE;
856  cqu_err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
857  if (cqu_err != MHERR_OK)
858  {
859  STB_OSMutexLock( api_mutex );
860  started_state = prev_state;
861  STB_OSMutexUnlock( api_mutex );
862  TRACE(TERROR, ("VQ_PutMsg Failed"));
863  }
864  else
865  {
866  /* Wait for notification that stop has been processed */
867  STB_OSSemaphoreWait(stop_sema);
868  TRACE(TSTATE, (" vgr done"));
869  }
870  }
871  }
872  FUNCTION_FINISH(x)
873  return cqu_err;
874 }
875 
876 /*******************************************************************************
877  * @brief Suspend MHEG5 engine (while there is no valid broadcast service).
878  * This function should be called as an alternative to MHEG5_Stop, when
879  * the external application is performing a tune as requested by MHEG5.
880  * This may or may not kill the running MHEG application.
881  * This suspend state will remain in effect until MHEG5_Start or
882  * MHEG5_Stop is called.
883  * @return MHERR_OK - Success
884  * MHERR_REQUEST_IGNORED - Already suspended
885  * MHERR_COMP_NOT_STARTED - Component not ready to stop.
886  *******************************************************************************/
888 {
889  MHEG5eventMessage_t event_msg;
890  E_MhegErr cqu_err;
891  E_ApiStatus prev_state;
892 
893  FUNCTION_START(x)
894  if (task_handle == NULL)
895  {
896  TRACE(TERROR, ("MHEG5 Not Open"));
897  cqu_err = MHERR_COMP_NOT_OPEN;
898  }
899  else
900  {
901  STB_OSMutexLock( api_mutex );
902  prev_state = started_state;
903  switch (started_state)
904  {
905  case VS_TUNING:
906  cqu_err = MHERR_REQUEST_IGNORED;
907  break;
908 
909  case VS_REBOOT:
910  case VS_RUNNING:
911  started_state = VS_TUNING;
912  cqu_err = MHERR_OK;
913  break;
914 
915  case VS_STOPPED:
916  cqu_err = MHERR_COMP_NOT_STARTED;
917  }
918  STB_OSMutexUnlock( api_mutex );
919  if (cqu_err == MHERR_OK)
920  {
921  event_msg.proc_msg_func = (F_MSG_PROCESS)stopEngine;
922  event_msg.data_type = DT_VALUE;
924  cqu_err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
925  if (cqu_err != MHERR_OK)
926  {
927  STB_OSMutexLock( api_mutex );
928  started_state = prev_state;
929  STB_OSMutexUnlock( api_mutex );
930  TRACE(TERROR, ("VQ_PutMsg Failed"));
931  }
932  else
933  {
934  /* Wait for notification that stop has been processed */
935  STB_OSSemaphoreWait(stop_sema);
936  TRACE(TSTATE, (" vgr done"));
937  }
938  }
939  }
940  FUNCTION_FINISH(x)
941  return cqu_err;
942 }
943 
944 #ifndef CI_PLUS_ONLY
945 
957 {
958  MHEG5eventMessage_t event_msg;
959  E_MhegErr cqu_err;
960  STB_OSMutexLock( api_mutex );
961  if (started_state == VS_RUNNING)
962  {
963  started_state = VS_REBOOT;
964  cqu_err = MHERR_OK;
965  }
966  else
967  {
968  cqu_err = MHERR_COMP_NOT_STARTED;
969  TRACE(TERROR, ("Not Started"));
970  }
971  STB_OSMutexUnlock( api_mutex );
972  if (cqu_err == MHERR_OK)
973  {
974  event_msg.proc_msg_func = MHEG5StartReboot;
975  event_msg.data_type = DT_NONE;
976  cqu_err = VQ_PutMsg(&event_msg, PRTY_HIGH);
977  if (cqu_err != MHERR_OK)
978  {
979  TRACE(TERROR, ("VQ_PutMsg Failed"));
980  }
981  else
982  {
983  TRACE(TMHBOOT, ("Starting reboot"));
984  }
985  }
986  return cqu_err;
987 }
988 
989 #endif /* !CI_PLUS_ONLY */
990 
991 /*********** Active State (Pause/Resume) Functions *********************************/
992 
994 {
995  /* Only called by MHEG5 task*/
996  return active_state;
997 }
998 
999 static void Pause( void *params )
1000 {
1001  FUNCTION_START(x)
1002  TRACE(TSTATE, ("state=%d", active_state))
1003  if (active_state)
1004  {
1005  #ifdef INCLUDE_ICS
1007  #endif
1008  MHEG5Pause();
1009  active_state = FALSE;
1010  }
1011  STB_OSSemaphoreSignal( pause_sema );
1012  FUNCTION_FINISH(x)
1013 }
1014 
1015 static void Resume( void *params )
1016 {
1017  FUNCTION_START(x)
1018  TRACE(TSTATE, ("state=%d", active_state))
1019  if (!active_state)
1020  {
1021  MHEG5Resume();
1022  #ifdef INCLUDE_ICS
1024  #endif
1025  active_state = TRUE;
1026  }
1027  FUNCTION_FINISH(x)
1028 }
1029 
1036 {
1037  MHEG5eventMessage_t event_msg;
1038  E_MhegErr cqu_err;
1039  FUNCTION_START(x)
1040  if (task_handle == NULL)
1041  {
1042  TRACE(TERROR, ("MHEG5 Not Open"));
1043  cqu_err = MHERR_COMP_NOT_OPEN;
1044  }
1045  else
1046  {
1047  event_msg.proc_msg_func = Pause;
1048  event_msg.data_type = DT_NONE;
1049  cqu_err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
1050  if (cqu_err != MHERR_OK)
1051  {
1052  TRACE(TERROR, ("VQ_PutMsg Failed"));
1053  }
1054  else
1055  {
1056  /* Wait for notification that 'pause' has been processed */
1057  STB_OSSemaphoreWait(pause_sema);
1058  TRACE(TSTATE | TMHAPI, ("done"))
1059  }
1060  }
1061  FUNCTION_FINISH(x)
1062  return cqu_err;
1063 }
1064 
1071 {
1072  MHEG5eventMessage_t event_msg;
1073  E_MhegErr cqu_err;
1074 
1075  FUNCTION_START(x)
1076  if (task_handle == NULL)
1077  {
1078  TRACE(TERROR, ("MHEG5 Not Open"));
1079  cqu_err = MHERR_COMP_NOT_OPEN;
1080  }
1081  else
1082  {
1083  event_msg.proc_msg_func = Resume;
1084  event_msg.data_type = DT_NONE;
1085  cqu_err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
1086  if (cqu_err != MHERR_OK)
1087  {
1088  TRACE(TERROR, ("VQ_PutMsg Failed"));
1089  }
1090  else
1091  {
1092  TRACE(TSTATE | TMHAPI, ("..."))
1093  }
1094  }
1095  FUNCTION_FINISH(x)
1096  return cqu_err;
1097 }
1098 
1099 static void ResetScreen( MHEG5ResetResolutionParams_t *params )
1100 {
1101  FUNCTION_START(x)
1102 
1103  *(params->pResult) = MHEG5ResetResolution( params->screenWidth, params->screenHeight );
1104 
1105  Pause( NULL );
1106 
1107  FUNCTION_FINISH(x)
1108 }
1109 
1115 E_MhegErr MHEG5_SetScreenResolution( U16BIT screenWidth, U16BIT screenHeight )
1116 {
1117  MHEG5eventMessage_t event_msg;
1118  E_MhegErr err;
1119 
1120  FUNCTION_START(x)
1121  /* Structure for passing event to the component task */
1122  TRACE(TMHAPI, ("( %d, %d, %d )", screenWidth, screenHeight))
1123 
1124  if (task_handle == NULL)
1125  {
1126  TRACE(TERROR, ("MHEG5 Not Open"));
1127  err = MHERR_COMP_NOT_OPEN;
1128  }
1129  else if (screenWidth < 720 || screenHeight < 576)
1130  {
1131  TRACE(TERROR, ("Bad Resolution (%d,%d)",screenWidth,screenHeight));
1132  err = MHERR_BAD_PARAMETER;
1133  }
1134  else
1135  {
1136  restore_active = active_state;
1137 
1138  event_msg.proc_msg_func = (F_MSG_PROCESS)ResetScreen;
1139  event_msg.data_type = DT_VALUE;
1140  event_msg.data.resetRes.screenWidth = screenWidth;
1141  event_msg.data.resetRes.screenHeight = screenHeight;
1142  event_msg.data.resetRes.pResult = &err;
1143  err = VQ_PutMsg(&event_msg, PRTY_CRITICAL);
1144  if (err == MHERR_OK)
1145  {
1146  /* Wait for notification that msg has been processed */
1147  STB_OSSemaphoreWait(pause_sema);
1148  }
1149  }
1150  FUNCTION_FINISH(x)
1151  return err;
1152 }
1153 
1160 {
1161  if (restore_active)
1162  {
1163  MHEG5_Resume();
1164  }
1165 }
1166 
1182 {
1183  return (newActiveState == FALSE) ? MHEG5_Pause() : MHEG5_Resume();
1184 }
1185 
1187 {
1188  *dvb_locator = default_service;
1189 }
1190 
1192 {
1193  return default_service.service_id;
1194 }
1195 
1197 {
1198  return default_service_index;
1199 }
BOOLEAN MH5GlueActiveState(void)
Definition: glue_main.c:993
U32BIT MHEG5tuneProcess(S_DvbLocator *pDvbLoc, S32BIT serviceIndex)
Definition: mh5control.c:955
void STB_OSSemaphoreWait(void *semaphore)
Wait on Semaphore Indefinity or Until Released.
#define PRG_DONE_INIT
Definition: glue_main.c:56
Implement MHEG5 engine control functions (i.e. start/stop etc)
E_ApiStatus
Definition: glue_main.c:81
E_ChannelStartMode
void MH5GlueDsmccClose(void)
Definition: glue_dsmcc.c:733
void * streamerBuffer
E_MhegErr VQ_PutMsg(S_MhegMessage *pMsg, E_PRIORITY priority)
Post event or section message on queue. Copies data into queue.
Definition: glue_queue.c:248
#define FUNCTION_FINISH(name)
Definition: glue_debug.h:143
E_MhegErr MHEG5_Close(void)
Free allocated memory region, and any other related resources. This is a synchronous blocking functio...
Definition: glue_main.c:541
E_MhegErr MH5GlueDsmccOpen(U32BIT taskPriority)
Definition: glue_dsmcc.c:691
F_MSG_PROCESS proc_msg_func
Definition: glue_queue.h:198
Interface functions to DSM-CC instance for MHEG5.
Manages the interface between MHEG5 Engine and the HTTP component.
E_MhegErr MHEG5_NotifyDvbEvent(E_DvbEvent eType, U32BIT eData)
Notifies MHEG5 of event from receiver platform This is a non-blocking function.
Definition: glue_events.c:189
void STB_OSTaskDelay(U16BIT timeout)
Delay Task for Specifed Time Period.
F_PostProcess pp_func
Definition: glue_main.c:78
void MHEG5Pause(void)
Definition: mh5control.c:1183
void(* F_MainProcess)(void)
Definition: glue_main.h:33
Debug tracing.
void STB_OSDeleteMutex(void *mutex)
Delete a mutex.
MHEG5 queue.
#define PRG_DONE_MHEG5
Definition: glue_main.c:65
E_MhegErr MHEG5_Stop(void)
Tells MHEG5 engine to enter stop state (i.e. no broadcast service). This function should kill any cur...
Definition: glue_main.c:764
E_MhegErr VT_TimersExit(void)
Uninitialise the timer component - all resources are freed. Other timer functions must not be called ...
Definition: glue_timers.c:474
E_MhegErr MHEG5_SetScreenResolution(U16BIT screenWidth, U16BIT screenHeight)
Reset OSD resolution for MHEG-5 engine.
Definition: glue_main.c:1115
E_MhegErr MHEG5ResetResolution(U16BIT screenWidth, U16BIT screenHeight)
Definition: mh5control.c:329
void MH5GlueDsmccStop(U8BIT action)
Definition: glue_dsmcc.c:761
E_MhegErr DVB_MhegIndexToDvbLocator(S32BIT serviceIndex, S_DvbLocator *location)
Convert "service index" into DVB locator information. This being original network ID...
E_HttpErr httpOpen(U32BIT task_priority)
Open the HTTP interface.
E_MhegErr MHEG5_StopWithoutKilling(void)
Suspend MHEG5 engine (while there is no valid broadcast service). This function should be called as a...
Definition: glue_main.c:825
void MHEG5Resume(void)
Definition: mh5control.c:1191
U16BIT transport_stream_id
Definition: dvblocator.h:33
E_MhegErr
Definition: mherrors.h:28
E_MhegErr MHEG5_Suspend(void)
Suspend MHEG5 engine (while there is no valid broadcast service). When the external application is pe...
Definition: glue_main.c:887
void MHEG5StreamerSetActiveState(BOOLEAN activeState)
Set the active state of the streamer. When it is not active, it is allowed to buffer data but not to ...
const char * MHEG5VersionString(void)
Definition: mh5support.c:220
E_MhegErr MH5GlueDsmccStart(S_DVB_LOCATOR *pDvbLoc, U32BIT carouselId, BOOLEAN clear)
Definition: glue_dsmcc.c:739
void(* F_MSG_PROCESS)(void *data)
Function to Process voyager message.
Definition: glue_queue.h:70
U16BIT original_network_id
Definition: dvblocator.h:32
E_MhegErr MHEG5_Resume(void)
Resume MHEG-5 engine.
Definition: glue_main.c:1070
uint8_t U8BIT
Definition: techtype.h:82
E_MhegErr MHEG5_Start(S32BIT serviceIndex, E_ChannelStartMode *quietMode)
This function starts MHEG5 engine on the current broadcast service. It will cause MHEG5 engine to sta...
Definition: glue_main.c:659
S_StartDsmApp start
Definition: glue_queue.h:209
void MHEG5_Terminate(void)
Terminate MHEG5 component.
Definition: mh5control.c:263
void VQ_Close(void)
Close component control and section queue component. Destroys all allocated memory and resources for ...
Definition: glue_queue.c:140
void MH5GlueDoneRebootMessage(void)
Definition: glue_main.c:250
Memory functions.
DVB Service information functions are required by MHEG5 engine. All required functions should be non-...
void STB_OSMutexUnlock(void *mutex)
Unlock a mutex (a.k.a. &#39;leave&#39;, &#39;signal&#39; or &#39;release&#39;)
#define PRG_DONE_MEMORY
Definition: glue_main.c:58
This file provides the control interface for MHEG5 engine. The use of this component MUST comply with...
API for IC streamer.
#define PRG_DONE_TIMERS
Definition: glue_main.c:63
void MHEG5StartReboot(void *dummy)
Definition: mh5control.c:1164
#define PRG_DONE_DSMCC
Definition: glue_main.c:61
void * STB_OSCreateSemaphore(void)
Create a Binary Semaphore. That is maximum value of 1. The initial value should be 1...
S32BIT MHEG5GetCurrentServiceIndex(void)
Definition: glue_main.c:1196
MHEG5ResetResolutionParams_t resetRes
Definition: glue_queue.h:224
S32BIT serviceIndex
Definition: glue_queue.h:75
U16BIT screenWidth
#define MAX_PP_FUNCS
Definition: glue_main.c:71
void MG_Terminate(void)
Free all OSD resources.
Definition: mg_osd.c:367
void * STB_OSCreateMutex(void)
Create a mutex.
Interface to OSD.
E_MhegErr MHEG5_SetActiveState(BOOLEAN newActiveState)
Set the active state for the MHEG-5 engine. When the active state is True, the MHEG-5 engine processe...
Definition: glue_main.c:1181
E_MhegErr MH5_SupportInitialise(S_MhegConfig *pConfig)
Initialise support module - called when &#39;Open&#39; engine.
Definition: mh5support.c:235
#define DPL1(x)
Definition: glue_debug.h:191
#define MHEG5_MIN_TASK_PRIORITY
Definition: mheg5_control.h:66
int32_t S32BIT
Definition: techtype.h:87
E_DATA_TYPE data_type
Definition: glue_queue.h:199
U32BIT taskPriority
U16BIT screenHeight
E_MhegErr VT_TimersInit(U32BIT task_priority)
Initialise the timer component. This function must be called before any other timer functions are inv...
Definition: glue_timers.c:407
#define PRG_DONE_NONE
Definition: glue_main.c:55
E_MhegErr MHEG5Initialise(S_MhegConfig *cfg_params)
initialise MHEG5 component
Definition: mh5control.c:203
uint16_t U16BIT
Definition: techtype.h:84
E_MhegErr VQ_GetMsg(S_MhegMessage *pElem)
Get an event or section from the component queues. This is a blocking function.
Definition: glue_queue.c:341
struct s_pp_list S_PP_LIST
void STR_TidyUp(void)
Definition: glue_memory.c:533
U16BIT service_id
Definition: dvblocator.h:34
E_MhegErr VQ_Open(S_MhegConfig *cfg_params)
Initialise component control and section queues. Allocates memory for, sets up and creates event (com...
Definition: glue_queue.c:96
U8BIT MHEG5HandleEngineStopAction(U8BIT action)
Definition: mh5control.c:1096
E_MhegErr DVB_MhegEventsStart(F_NotifyDvbEvent handler)
Start listening for DVB events.
void MHEG5GetDefaultService(S_DVB_LOCATOR *dvb_locator)
Definition: glue_main.c:1186
E_MhegErr MHEG5_Pause(void)
Pause MHEG-5 engine.
Definition: glue_main.c:1035
void MHEG5StreamerClose(void)
Close the IC streaming module.
BOOLEAN MH5GlueMemoryInitialise(void)
Definition: glue_memory.c:807
U16BIT MHEG5DefaultServiceId(void)
Definition: glue_main.c:1191
BOOLEAN(* F_PostProcess)(void)
Definition: glue_main.h:32
E_MhegErr MG_Initialise(U16BIT screenWidth, U16BIT screenHeight, U8BIT colourDepth)
Initialise OSD, font, and font fill information. Should only be called at start up.
Definition: mg_osd.c:281
#define FALSE
Definition: techtype.h:68
void STB_OSMutexLock(void *mutex)
Lock a mutex (a.k.a. &#39;enter&#39;, &#39;wait&#39; or &#39;get&#39;).
BOOLEAN MH5GlueIsStarted(void)
Definition: glue_main.c:241
The timer module allows the use of timers within the MHEG5 component. These timers can be set by othe...
E_MhegErr DVB_MhegEventsStop(void)
Stop listening for DVB events.
void httpClose(void)
Close the HTTP interface.
void MH5GlueSetMainPostFunc(F_MainProcess func)
Definition: glue_main.c:261
Interaction Channel Streaming functions required by MHEG5 engine References: [1] UK1 Profile - Digita...
U8BIT BOOLEAN
Definition: techtype.h:99
void MH5GlueAddPostProcessFunc(F_PostProcess func)
Definition: glue_main.c:275
#define TRUE
Definition: techtype.h:69
#define PRG_DONE_SYNCS
Definition: glue_main.c:59
void MHEG5_RestoreScreen(void)
Restore MHEG OSD after reset of resolution for MHEG-5 engine.
Definition: glue_main.c:1159
E_MhegErr MHEG5_Reboot(void)
Reboots MHEG5 Engine This function has the same effect as calling these two: MHEG5_Stop( STOP_ACTION_...
Definition: glue_main.c:956
const char * version_string
E_MhegErr MHEG5_Open(S_MhegConfig *pSetup)
Initialise MHEG5 instance. The following will be performed as a result of a call to this function: ...
Definition: glue_main.c:361
#define MAIN_STACK_SIZE
Definition: glue_main.c:53
void * STB_OSCreateTask(void(*function)(void *), void *param, U32BIT stack, U8BIT priority, U8BIT *name)
Create a New Task to the calling process. Upon success, the created task runs on its own stack...
void MH5GlueMemoryTerminate(void)
Definition: glue_memory.c:830
#define PRG_DONE_MAIN
Definition: glue_main.c:62
union s_mhg_message::@13 data
#define PRG_DONE_QUEUE
Definition: glue_main.c:60
#define FUNCTION_START(name)
Definition: glue_debug.h:142
uint32_t U32BIT
Definition: techtype.h:86
E_ChannelStartMode MHEG5_GetTuningInfoMode(S32BIT serviceIndex)
Get the current tuning mode for the target service. This is only relevant when MHEG5 has requested a ...
Definition: mh5control.c:934
#define PRG_DONE_GRAPHICS
Definition: glue_main.c:57
Engine support utility functions for MHEG5.
void STB_OSDestroyTask(void *task)
Delete Task must be called upon termination of each task as it frees all OS specific resources alloca...
U32BIT streamerBufferSize
MHEG5StopEventParams_t stop
Definition: glue_queue.h:211
void STB_OSDeleteSemaphore(void *semaphore)
Delete a Semaphore.
void STB_OSSemaphoreSignal(void *semaphore)
Signal a Semaphore to Release it by decrementing its counter.
E_MhegErr MHEG5StreamerOpen(void *buffer, U32BIT size, U32BIT taskPriority)
Open the IC streaming module.
#define TRACE(t, x)
Definition: glue_debug.h:118
#define PRG_DONE_HTTP
Definition: glue_main.c:64
Header file - Function prototypes for operating system.