DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
sectionTimer.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  * Copyright © 2002 Koninklijke Philips Electronics N.V
5  *
6  * This file is part of a DTVKit Software Component
7  * You are permitted to copy, modify or distribute this file subject to the terms
8  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
9  *
10  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
11  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
12  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
13  *
14  * If you or your organisation is not a member of DTVKit then you have access
15  * to this source code outside of the terms of the licence agreement
16  * and you are expected to delete this and any associated files immediately.
17  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
18  *******************************************************************************/
25 /*---includes for this file--------------------------------------------------*/
26 #include "clDsmSystem.h"
27 #include "sectionFilter.h"
28 #include "sectionTimer.h"
29 
30 #include "objectCarousel.h"
31 #include "dataCarousel.h"
32 #include "module.h"
33 #include "siQuery.h"
34 #include "loadMgr.h"
35 
36 
37 /*------------------------------- Local Macros -------------------------------*/
38 #define SECTION_TIMER_DSI_TIMEOUT 5000
39 
40 /*------------------------------ Exported Data -----------------------------*/
41 
42 
43 /*--------------------------------Local Types --------------------------------*/
44 
45 
46 /*------------------------------- Local Statics ------------------------------*/
47 
48 
49 /*------------------- local prototypes/forward declarations ------------------*/
50 
51 #ifdef DSI_TIMEOUT_SUPPORT
52 static E_DscError sectionTimerDSIArm( P_DsmCoreInst idp,
53  /*IO*/ P_SecFilterInfo pSectionFilter);
54 #endif /* DSI_TIMEOUT_SUPPORT */
55 
56 static E_DscError sectionTimerDIIArm( P_DsmCoreInst idp,
57  /*IO*/ P_SecFilterInfo pSectionFilter);
58 
59 static E_DscError sectionTimerDDBArm( P_DsmCoreInst idp,
60  /*IO*/ P_SecFilterInfo pSectionFilter);
61 
62 
63 /*---------------------------- Exported Functions ----------------------------*/
64 
65 /*
66 -- According pSectionFilter-> targetKind call local function:
67 -- sectionTimerDSIArm(), sectionTimerDIIArm(), sectionTimerDSIArm()
68 */
69 E_DscError SectionTimerArm( P_DsmCoreInst idp,
70  /*IO*/ P_SecFilterInfo pSectionFilter)
71 {
72  E_DscError err = CLDSM_OK;
73 
74  dsmDP3(("SectionTimerArm(pSectionFilter = 0x%p)\n", pSectionFilter));
75  dsmAssert((idp != NULL));
76  dsmAssert((pSectionFilter != NULL));
77 
78  pSectionFilter->tms.mainTimerHandle = NULL;
79  pSectionFilter->tms.nextTimerHandle = NULL;
80  pSectionFilter->tms.nextDuration = 0;
81 
82  switch (pSectionFilter->target.kind)
83  {
84  case SFK_DSI:
85  #ifdef DSI_TIMEOUT_SUPPORT
86  sectionTimerDSIArm(idp, pSectionFilter);
87  #endif /* DSI_TIMEOUT_SUPPORT */
88  break;
89  case SFK_DII:
90  sectionTimerDIIArm(idp, pSectionFilter);
91  break;
92  case SFK_DDB:
93  sectionTimerDDBArm(idp, pSectionFilter);
94  break;
95 
96  case SFK_STREAM_DESCR: /* no timeout => avoid assert in default case */
97  break;
98 
99  default:
100  dsmDP1(("ERROR: Illegal section filter kind = %u\n", pSectionFilter->target.kind));
101  dsmAssert((0));
102  err = CLDSM_ERR_INTERNAL;
103  break;
104  }
105 
106  DEBUG_CHK( err == CLDSM_OK,
107  dsmDP1(("ERROR: sectionTimerUpdate %u\n", err)));
108  dsmDP3(("exit sectionTimerUpdate -> rtn: %u\n", err));
109  return err;
110 }
111 
112 /*
113 -- If the timer is refreshed, then re-arm main timer for the main duration
114 -- If the timer is not completed, then re-arm next timer for the
115  next duration.
116 -- If completed, destroy all timers
117 -- In any case update the timer handle fields, reset it to 0 if timer is not
118  re-armed
119 
120 */
121 E_DscError sectionTimerUpdate( P_DsmCoreInst idp,
122  /*IO*/ P_SecFilterInfo pSectionFilter,
123  /*I*/ BOOLEAN completed, BOOLEAN refresh)
124 {
125  E_DscError err = CLDSM_OK;
126  int cbErr;
127 
128  dsmDP3(("sectionTimerUpdate(pSectionFilter = 0x%p)\n", pSectionFilter));
129  dsmAssert((idp != NULL));
130  dsmAssert((pSectionFilter != NULL));
131 
132  if (idp->setup.startTimerFunc != NULL &&
133  idp->setup.stopTimerFunc != NULL)
134  {
135  if (completed)
136  {
137  /* Destroy all timers */
138  if (pSectionFilter->tms.nextTimerHandle != NULL)
139  {
140  idp->setup.stopTimerFunc( idp->setup.dsmControl, pSectionFilter->tms.nextTimerHandle );
141  }
142 
143  if (pSectionFilter->tms.mainTimerHandle != NULL)
144  {
145  /* Destroy the main timer */
146  idp->setup.stopTimerFunc( idp->setup.dsmControl, pSectionFilter->tms.mainTimerHandle );
147  }
148 
149  /* Reset the timer handle fields */
150  pSectionFilter->tms.mainTimerHandle = NULL;
151  pSectionFilter->tms.nextTimerHandle = NULL;
152  pSectionFilter->tms.nextDuration = 0;
153  }
154  else
155  {
156  void **timerHandle = &pSectionFilter->tms.nextTimerHandle;
157  U32BIT duration = pSectionFilter->tms.nextDuration;
158  if (refresh && pSectionFilter->target.kind == SFK_DDB)
159  {
160  timerHandle = &pSectionFilter->tms.mainTimerHandle;
161  duration = pSectionFilter->tms.mainDuration;
162  }
163 
164  /* Destroy the next timer if running */
165  if (*timerHandle != NULL)
166  {
167  idp->setup.stopTimerFunc( idp->setup.dsmControl, *timerHandle );
168  }
169 
170  if (duration != 0xFFFFFFFF && duration > 0)
171  {
172  /* Re-arm next timer for the next duration */
173  cbErr = idp->setup.startTimerFunc( idp->setup.dsmControl, duration, pSectionFilter, timerHandle );
174  if (cbErr)
175  {
176  dsmDP1(("ERROR: sectionTimerUpdate : startTimerFunc failure"));
177  //dsmAssert((0));
178  err = CLDSM_ERR_INTERNAL;
179  }
180  }
181  } /* if (completed) */
182  }
183 
184  DEBUG_CHK( err == CLDSM_OK,
185  dsmDP1(("ERROR: sectionTimerUpdate %u\n", err)));
186  dsmDP3(("exit sectionTimerUpdate -> rtn: %u\n", err));
187  return err;
188 }
189 
190 /*
191 -- If available, destroy the timer
192 */
193 E_DscError sectionTimerRemove( P_DsmCoreInst idp,
194  /*I*/ P_SecFilterInfo pSectionFilter)
195 {
196  E_DscError err = CLDSM_OK;
197 
198  dsmDP3(("sectionTimerRemove(pSectionFilter = 0x%p)\n", pSectionFilter));
199  dsmAssert((idp != NULL));
200  dsmAssert((pSectionFilter != NULL));
201 
202  if (idp->setup.stopTimerFunc != NULL)
203  {
204  if (NULL != pSectionFilter->tms.mainTimerHandle)
205  {
206  DBGLOG(DD_TIMER,"(pSF = 0x%p) thdl=%x", pSectionFilter, pSectionFilter->tms.mainTimerHandle);
207  idp->setup.stopTimerFunc( idp->setup.dsmControl, pSectionFilter->tms.mainTimerHandle );
208  pSectionFilter->tms.mainTimerHandle = NULL;
209  }
210 
211  if (NULL != pSectionFilter->tms.nextTimerHandle)
212  {
213  idp->setup.stopTimerFunc( idp->setup.dsmControl, pSectionFilter->tms.nextTimerHandle );
214  pSectionFilter->tms.nextTimerHandle = NULL;
215  }
216  }
217 
218  DEBUG_CHK( err == CLDSM_OK,
219  dsmDP1(("ERROR: sectionTimerRemove %u\n", err)));
220  dsmDP3(("exit sectionTimerRemove -> rtn: %u\n", err));
221  return err;
222 }
223 
224 /*------------------------------ Local Functions -----------------------------*/
225 
226 #ifdef DSI_TIMEOUT_SUPPORT
227 /*
228 -- Arm a timer for DSI section acquisition Timeout, that is to say 5000 milliseconds
229 */
230 static E_DscError sectionTimerDSIArm( P_DsmCoreInst idp,
231  /*IO*/ P_SecFilterInfo pSectionFilter)
232 {
233  E_DscError err = CLDSM_OK;
234  int cbErr;
235 
236  DBGLOG(DD_TIMER,"(pSectionFilter = 0x%p)", pSectionFilter)
237  dsmAssert((idp != NULL));
238  dsmAssert((pSectionFilter != NULL));
239 
240  if (idp->setup.startTimerFunc != NULL)
241  {
242  cbErr = idp->setup.startTimerFunc( idp->setup.dsmControl, SECTION_TIMER_DSI_TIMEOUT,
243  pSectionFilter, &(pSectionFilter->tms.mainTimerHandle));
244  if (cbErr)
245  {
246  dsmDP1(("ERROR: sectionTimerDSIArm : startTimerFunc failure\n"));
247  dsmAssert((0));
248  err = CLDSM_ERR_INTERNAL;
249  }
250  pSectionFilter->tms.nextTimerHandle = 0;
251  pSectionFilter->tms.nextDuration = 0;
252  }
253 
254  DEBUG_CHK( err == CLDSM_OK,
255  dsmDP1(("ERROR: sectionTimerDSIArm %u\n", err)));
256  dsmDP3(("exit sectionTimerDSIArm -> rtn: %u\n", err));
257  return err;
258 }
259 
260 #endif /* DSI_TIMEOUT_SUPPORT */
261 
262 /*
263 -- Arm a timer for DII section acquisition Timeout
264 */
265 static E_DscError sectionTimerDIIArm( P_DsmCoreInst idp,
266  /*IO*/ P_SecFilterInfo pSectionFilter)
267 {
268  E_DscError err = CLDSM_OK;
269  int cbErr;
270  P_DataCarousel pDC;
271  U32BIT timeout;
272 
273  DBGLOG(DD_TIMER,"(pSectionFilter = 0x%p)", pSectionFilter)
274  dsmAssert((idp != NULL));
275  dsmAssert((pSectionFilter != NULL));
276 
277  if (idp->setup.startTimerFunc != NULL)
278  {
279  /* duration is retrieved from target handle (hDataCarousel) :: tap::timeout */
280  pDC = pSectionFilter->target.u.pDC;
281  timeout = pDC->tap.timeout; /*µs*/
282 
283  dsmDP3(("sectionTimerDIIArm(-) timeout = %u microsecs\n", timeout));
284  cbErr = idp->setup.startTimerFunc( idp->setup.dsmControl, timeout / 1000, pSectionFilter, &(pSectionFilter->tms.mainTimerHandle));
285  if (cbErr)
286  {
287  dsmDP1(("ERROR: sectionTimerDIIArm : startTimerFunc failure\n"));
288  err = CLDSM_ERR_INTERNAL;
289  }
290  pSectionFilter->tms.nextTimerHandle = 0;
291  pSectionFilter->tms.nextDuration = 0;
292  }
293  return err;
294 }
295 
296 /*
297 -- Arm a timer for DDB sections acquisition Timeout
298 */
299 static E_DscError sectionTimerDDBArm( P_DsmCoreInst idp,
300  /*IO*/ P_SecFilterInfo pSectionFilter)
301 {
302  E_DscError err = CLDSM_OK;
303  int cbErr;
304  P_Module pModule;
305  U32BIT moduleTimeout, blockTimeout;
306 
307  dsmDP3(("sectionTimerDDBArm(pSectionFilter= 0x%p)\n", pSectionFilter));
308  dsmAssert((idp != NULL));
309  dsmAssert((pSectionFilter != NULL));
310 
311  if ((idp->setup.startTimerFunc != NULL) && (NULL != pSectionFilter->target.u.pModule))
312  {
313  /* duration (µs) is retrieved from target handle */
314  /* (hModule) :: moduleInfo:: profileInfo:: moduleTimeout */
315  pModule = pSectionFilter->target.u.pModule;
316  if ( pModule->moduleInfo.crslMagic == OC_MAGIC )
317  {
318  moduleTimeout = pModule->moduleInfo.u.mhgp.moduleTimeout;
319  if (moduleTimeout != 0)
320  {
321  moduleTimeout /= 1000; /*µs -> ms*/
322 
323  /* Next duration (µs) is retrieved from target heandle */
324  /* (hModule) :: moduleInfo:: profileInfo:: blockTimeout */
325  blockTimeout = pModule->moduleInfo.u.mhgp.blockTimeout / 1000; /*µs -> ms*/
326 
327  dsmDP3(("sectionTimerDDBArm(-) moduleTimeout = %u blockTimeout = %u microsecs\n", moduleTimeout, blockTimeout));
328  cbErr = idp->setup.startTimerFunc( idp->setup.dsmControl, moduleTimeout, pSectionFilter, &(pSectionFilter->tms.mainTimerHandle));
329  if (cbErr)
330  {
331  dsmDP1(("ERROR: sectionTimerDDBArm : startTimerFunc failure\n"));
332  err = CLDSM_ERR_INTERNAL;
333  }
334  pSectionFilter->tms.nextTimerHandle = 0;
335  pSectionFilter->tms.mainDuration = moduleTimeout;
336  pSectionFilter->tms.nextDuration = blockTimeout;
337  }
338  }
339  }
340  return err;
341 }
342 
343 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
Header to the loadMgr module.
Header to the sectionTimer module.
Header to the sectionFilter module.
Header to siQuery module - functions for managing SI queries.
Header to the 'module' module - Functions/methods for creating/destroying and managing attributes of ...