DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
streamObject.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 "clDsmUtils.h"
28 #include "streamObject.h"
29 #include "defMemUtilsMgd.h" /* -- Default mem type for module */
30 #include "siQuery.h"
31 
32 /*------------------------------- Local Macros -------------------------------*/
33 
34 
35 /*------------------------------ Exported Data -----------------------------*/
36 
37 
38 /*--------------------------------Local Types --------------------------------*/
39 
40 
41 /*------------------------------- Local Statics ------------------------------*/
42 
43 
44 /*------------------- local prototypes/forward declarations ------------------*/
45 
46 
47 
48 /*------------------------------ Local Functions -----------------------------*/
49 
50 
63 static BOOLEAN GetTapAssocTag( MemSeqRef addr, U16BIT targetTapUse, U16BIT *pAssocTag)
64 {
65  BOOLEAN tapFound = FALSE; /* Return value - assume not found */
66  U32BIT initialOffset;
67  U8BIT taps_count;
68  U16BIT tapUse;
69  U8BIT ui8;
70  U8BIT i; /* General purpose 8-bit loop counter */
71 
72  /* Remember the offset, so we can restore position before return */
73  memSeqReadPos(addr, &initialOffset);
74 
75  /* Read taps count */
76  memSeqReadByte(addr, &taps_count);
77 
78  for (i = 0; (i < taps_count) && (tapFound == FALSE); i++)
79  {
80  /* Skip ID */
81  memSeqSetPosRel(addr, 2);
82  /* Read use */
83  readUInt16Seq(addr, &tapUse);
84 
85  /* Have we found the tap ? */
86  if (tapUse == targetTapUse)
87  {
88  /* Read associationTag */
89  readUInt16Seq(addr, pAssocTag);
90  tapFound = TRUE;
91  }
92  else
93  {
94  /* Skip use */
95  memSeqSetPosRel(addr, 2);
96  /* Read selectorLength */
97  memSeqReadByte(addr, &ui8);
98  /* Skip selector */
99  memSeqSetPosRel(addr, (U32BIT)ui8);
100  }
101  }
102 
103  /* Reset offset to start */
104  memSeqSetPosAbs(addr, initialOffset);
105 
106  return tapFound;
107 }
108 
109 /*---------------------------- Exported Functions ----------------------------*/
110 
142  /*I*/ H_DsmObject streamObject, void *userData1, void *userData2,
143  /*O*/ S_DvbLocator **ppDeferredService )
144 {
145  P_DsmCoreInst idp = (P_DsmCoreInst) instance;
146  P_DsmObject pDsmObject = (P_DsmObject)streamObject;
147  E_DscError err;
148  U16BIT associationTag;
149 
150  dsmDP2(("dsmStreamGetDeferredService(%u)\n", streamObject));
151 
152  if (!DSM_OBJECT_VALIDATE(pDsmObject))
153  {
154  dsmDP1(("ERROR: Invalid object handle\n"));
155  err = CLDSM_ERR_INVALID_OBJECT_HANDLE;
156  dsmAssert((0)); /* FATAL */
157  }
158  else if (pDsmObject->kind != STREAM_OBJ &&
159  pDsmObject->kind != STREAM_OBJ_WITH_EVENTS)
160  {
161  dsmDP1(("ERROR: Incorrect kind=%d\n", pDsmObject->kind));
162  err = CLDSM_ERR_INVALID_OBJECT_TYPE;
163  }
164  else if (pDsmObject->status != OBJ_LOAD_COMPLETED)
165  {
166  dsmDP1(("ERROR: Object load not completed\n"));
167  err = CLDSM_ERR_OBJECT_NOT_LOADED;
168  }
169  else if (pDsmObject->objectDataSeq == NULL)
170  {
171  dsmDP1(("ERROR: Object not open\n"));
172  err = CLDSM_ERR_OBJECT_NOT_OPEN;
173  }
174  else if (pDsmObject->data.so.retrieved == DEFFERED_SERVICE_RECEIVED)
175  {
176  /* Great! Deferred service has already been retrieved - just pass it back */
177  *ppDeferredService = &pDsmObject->data.so.multiplex;
178  err = CLDSM_OK;
179  }
180  else if (!GetTapAssocTag(pDsmObject->objectDataSeq, BIOP_PROGRAM_USE, &associationTag))
181  {
182  dsmDP1(("ERROR: Cannot find BIOP_PROGRAM_USE tap\n"));
183  err = CLDSM_ERR_UNABLE_TO_GET_PROGRAM_ASSOC_TAG;
184  }
185  else
186  {
187  /* Got association tag. */
188  S_SIQueryRequest siQueryData;
189  S_SIQueryResult siQueryResult;
190 
191  siQueryData.kind = SIQUERY_DEFERRED_SERVICE;
192  siQueryData.serviceId = idp->dvbLocator.service_id;
193  siQueryData.associationTag = associationTag;
194 
195  err = siQueryStart( idp, &siQueryData, (void *)streamObject, &siQueryResult );
196 
197  switch (err)
198  {
199  case CLDSM_OK:
200  /* Store stream object's deferred service */
201  pDsmObject->data.so.multiplex = siQueryResult.data.deferredService;
202  pDsmObject->data.so.retrieved = DEFFERED_SERVICE_RECEIVED;
203  *ppDeferredService = &pDsmObject->data.so.multiplex;
204  break;
205 
206  case CLDSM_PENDING:
207  /* Store query ref in object */
208  pDsmObject->r.pPendingSiQueryRef = siQueryResult.data.queryHandle;
209  pDsmObject->data.ds.userData1 = userData1;
210  pDsmObject->data.ds.userData2 = userData2;
211  break;
212 
213  default:
214  /* Store currrent service in stream object */
215  pDsmObject->data.so.multiplex = idp->dvbLocator;
216  pDsmObject->data.so.retrieved = DEFFERED_SERVICE_RECEIVED; /* well, we tried! */
217  *ppDeferredService = &pDsmObject->data.so.multiplex;
218  err = CLDSM_OK;
219  }
220  }
221  return err;
222 }
223 
224 /* DSC_StrmObjectStoreDeferred called when SiQuery result returned */
225 void DSC_StrmObjectStoreDeferred( P_DsmCoreInst idp, P_DsmObject pDsmObject,
226  S_DvbLocator multiplex )
227 {
228  void *ds_ud1;
229  void *ds_ud2;
230 
231  if (DSM_OBJECT_VALIDATE(pDsmObject) &&
232  (pDsmObject->status == OBJ_LOAD_COMPLETED) &&
233  (pDsmObject->kind == STREAM_OBJ || pDsmObject->kind == STREAM_OBJ_WITH_EVENTS) &&
234  (pDsmObject->r.pPendingSiQueryRef != NULL)
235  )
236  {
237  ds_ud1 = pDsmObject->data.ds.userData1;
238  ds_ud2 = pDsmObject->data.ds.userData2;
239  pDsmObject->data.so.multiplex = multiplex;
240  pDsmObject->data.so.retrieved = DEFFERED_SERVICE_RECEIVED;
241  pDsmObject->r.pPendingSiQueryRef = NULL;
242  if (idp->setup.notifyDeferredServiceFunc)
243  {
244  idp->setup.notifyDeferredServiceFunc( ds_ud1, ds_ud2, &pDsmObject->data.so.multiplex );
245  }
246  }
247 }
248 
249 /*----------------------------------------------------------------------------*/
General include file for clDsm library internal definitions.
E_DscError siQueryStart(P_DsmCoreInst idp, P_SIQueryRequest pQueryData, void *queryTarget, P_SIQueryResult pResult)
Starts an SI Query. First tests if we have already made this query and the results are stored or stil...
Definition: siQuery.c:76
Header to siQuery module - functions for managing SI queries.
E_DscError CDSM_StreamGetDeferredService(H_DsmCoreInst instance, H_DsmObject streamObject, void *userData1, void *userData2, S_DvbLocator **ppDeferredService)
The Client calls this function to obtain the Association Tag which can be used to determine the PID o...
Definition: streamObject.c:141
DSM-CC stream object.
Defines memory access utils to work with managed (MemMgr) memory.
eader to the clDsmUtils module.