MHEG5  18.9.0
MHEG5 Documentation
asn1_createTokenGroup.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 © 2000 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  *******************************************************************************/
27 /*---includes for this file--------------------------------------------------*/
28 #include <stdio.h>
29 #include "vpa1_sys.h"
30 #include "vpa1_tgs.h"
31 #include "fpa1_syn.h"
32 #include "asn1_sys.h"
33 
34 #include "mh5base.h"
35 #include "mh5tokengroup.h"
36 #include "asn1_createAction.h"
37 #include "asn1_createExtras.h"
38 #include "asn1_createIngredient.h"
40 #include "asn1_createGroup.h"
41 #include "asn1_createTokenGroup.h"
42 
43 /*---constant definitions for this file--------------------------------------*/
44 
45 
46 /*---local typedef structs for this file-------------------------------------*/
47 
48 /*---local (static) variable declarations for this file----------------------*/
49 
50 /*---local function definitions----------------------------------------------*/
51 
52 /*---global function definitions---------------------------------------------*/
53 
64 static MHEG5ActionList* decodeActionSlot(fpa1_syntaxList *currItem,
65  MHEG5TokenSlot *token_ptr, MHEG5ActionList *actions_ptr )
66 {
67  U32BIT actions_cnt = 0;
68  assert(token_ptr);
69 
70  token_ptr->actions_ptr = actions_ptr;
71 
72  while (currItem != NULL)
73  {
74  if (currItem->tag == SEQ_SIZE_OF_ELEMENTARY_ACTION)
75  {
76  /* fill the actionSlot with the action */
77  asn1_decodeActions( currItem, actions_ptr );
78  }
79  /* else a NULL action, therefore actionSlot remains empty */
80  actions_ptr++;
81  actions_cnt++;
82  currItem = currItem->next;
83  }
84  token_ptr->actions_num = actions_cnt;
85 
86  return actions_ptr;
87 }
88 
97 static asnErr decodeTokenSlotRef(fpa1_syntaxList *tmpItem, MHEG5TokenSlot *token_ptr)
98 {
99  asnErr errVal = 0;
100  assert( tmpItem != NULL );
101  /* object reference */
102  if (tmpItem->tag == EXTERNAL_REFERENCE_TYPE)
103  {
104  tmpItem = tmpItem->children;
105  if (tmpItem == NULL)
106  {
107  errVal |= 1;
108  }
109  else
110  {
111  if (tmpItem->data.stringData.len == 0)
112  {
113  /* this would be an Mheg authoring cock-up, so assume ptr to group */
114  token_ptr->groupid.len = 0;
115  token_ptr->groupid.ptr.group = asn1_mainGroupPtr;
116  }
117  else
118  {
119  token_ptr->groupid.len = tmpItem->data.stringData.len;
120  token_ptr->groupid.ptr.name = tmpItem->data.stringData.data;
121  }
122 
123  /* remove the original reference to the string */
124  tmpItem->data.stringData.len = 0;
125  tmpItem->data.stringData.data = NULL;
126 
127  tmpItem = tmpItem->next;
128  if (tmpItem == NULL)
129  {
130  errVal |= 1;
131  }
132  else
133  {
134  token_ptr->id = tmpItem->data.intData;
135  }
136  }
137  }
138  else /* internal reference */
139  {
140  token_ptr->id = tmpItem->data.intData;
141  /* use the scene/app GID */
142  token_ptr->groupid.len = 0;
143  token_ptr->groupid.ptr.group = asn1_mainGroupPtr;
144  }
145  return errVal;
146 }
147 
157 {
158  MHEG5ActionList *actions_ptr;
159  MHEG5TokenSlot *token_ptr;
160  asnErr errVal = 0;
161  fpa1_syntaxList *currItem = listPtr->children;
162  fpa1_syntaxList *child, *gchild;
163 
164  DPL5((">> asn1_decodeTokenGroup(%X,%X)\n", listPtr, tokenGrp));
165 
166  assert(tokenGrp);
167  assert(listPtr);
168 
169  token_ptr = tokenGrp->tokens_ptr;
170  actions_ptr = (MHEG5ActionList *)(token_ptr + tokenGrp->tokens_num);
171 
172  token_ptr++; /* zero token position for the "No Token" actions */
173 
174  currItem = listPtr->children;
175 
176  /* searches current set of tags for local tags */
177  while (currItem != NULL)
178  {
179  /* most objects will have more than one local tag */
180  switch (currItem->tag)
181  {
182  case TGITEMS:
183  child = currItem->children;
184  while (child != NULL)
185  {
186  if (child->tag == TOKEN_GROUP_ITEM_TYPE)
187  {
188  gchild = child->children;
189  if (gchild != NULL)
190  {
191  errVal |= decodeTokenSlotRef(gchild, token_ptr);
192  gchild = gchild->next;
193  if (gchild != NULL)
194  {
195  actions_ptr = decodeActionSlot(gchild->children, token_ptr, actions_ptr);
196  }
197  }
198  token_ptr++;
199  }
200  child = child->next;
201  }
202  break;
203  case NOTOKEN:
204  actions_ptr = decodeActionSlot(currItem->children, tokenGrp->tokens_ptr, actions_ptr);
205  break;
206 
207  /**** decode inherited tags from TokenManager *****/
208  case MOVEMENTTABLE:
209  child = currItem->children;
210  while (child != NULL)
211  {
212  if (child->tag == SEQ_SIZE_OF_INTEGER)
213  {
215  gchild = child->children;
216  while (gchild != NULL)
217  {
218  if (gchild->tag == INTEGER)
219  {
220  MHEG5tokenManagerAddNumber( &tokenGrp->tokenManager, gchild->data.intData );
221  }
222  else
223  {
224  DPL2(("WARNING:[ASN.1] Unexpected tag in movementTable\n"));
225  errVal |= 0x01;
226  }
227  gchild = gchild->next;
228  }
229  }
230  child = child->next;
231  }
232  break;
233 
234  /**** decode inherited tags from Ingredient *****/
236  /* skip the Group ref 'child', as this must always reference current group */
237  assert( currItem->children );
238  child = currItem->children->next;
239  if (child == NULL ||
240  child->data.intData < 1)
241  {
242  /* illegal to have zero or negative object numbers for an ingredient */
243  errVal |= 0x01;
244  }
245  else
246  {
247  tokenGrp->ingredient.root.id = child->data.intData;
248  }
249  break;
250  case INTEGER: /* internal reference */
251  if (currItem->data.intData < 1)
252  {
253  /* illegal to have zero or negative object numbers for an ingredient */
254  errVal |= 0x01;
255  }
256  else
257  {
258  tokenGrp->ingredient.root.id = currItem->data.intData;
259  }
260  break;
261  case INITACTIVE:
262  if (currItem->data.boolData == 0)
263  {
265  }
266  break;
267  case CHOOK:
268  tokenGrp->ingredient.contentHook = currItem->data.intData;
269  break;
270  case SHARED:
271  if (currItem->data.boolData != 0)
272  {
273  tokenGrp->ingredient.shared = MHEG5TRUE;
274  }
275  break;
276 
277  default:
278  break;
279  }
280  currItem = currItem->next;
281  }
282 
283 #if (DPLEVEL >= 2)
284  if (errVal != 0)
285  {
286  DPL2(("WARNING:[ASN.1] asn1_decodeTokenGroup() returns errVal = %d\n", errVal));
287  }
288 #endif /* DPLEVEL >= 2 */
289 
290  DPL5(("<< asn1_decodeTokenGroup() Returns %d\n", errVal));
291 
292  return errVal;
293 }
294 
301 {
302  U32BIT itm_cnt = 1, ast_cnt = 0;
303 
304  /* searches current set of tags for local tags */
305  while (currItem != NULL)
306  {
307  /* most objects will have more than one local tag */
308  switch (currItem->tag)
309  {
310  case TGITEMS:
311  itm_cnt += currItem->childCount[0];
312  ast_cnt += currItem->childCount[2];
313  break;
314  case NOTOKEN:
315  ast_cnt += currItem->childCount[0];
316  break;
317  default:
318  break;
319  }
320  currItem = currItem->next;
321  }
322  return itm_cnt << 16 | ast_cnt;
323 }
324 
333 {
334  MHEG5TokenGroup *tokenGrp;
335  U32BIT itm_cnt, ast_cnt, size;
336 
337  assert( listPtr );
338 
339  itm_cnt = asn1_getTokenGroupItemCount( listPtr->children );
340  ast_cnt = itm_cnt & 0xffff;
341  itm_cnt >>= 16;
342 
343  size = sizeof(MHEG5TokenGroup) +
344  (itm_cnt * sizeof(MHEG5TokenSlot)) +
345  (ast_cnt * sizeof(MHEG5ActionList));
346 
347  tokenGrp = (MHEG5TokenGroup *)MHEG5getMem( size );
348  if (tokenGrp != NULL)
349  {
350  memset(tokenGrp, 0, size);
351  tokenGrp->ingredient.root.clazz = MHEG5TOKENGROUP;
352  tokenGrp->tokens_num = itm_cnt;
353  tokenGrp->tokens_ptr = (MHEG5TokenSlot *)(tokenGrp + 1);
354 
355  if (asn1_decodeTokenGroup(listPtr, tokenGrp) != ASN_NO_ERROR)
356  {
357  MHEG5freeMem( tokenGrp );
358  tokenGrp = NULL;
359  }
360  }
361  return (MHEG5Ingredient *)tokenGrp;
362 }
363 
asnErr asn1_decodeTokenGroup(fpa1_syntaxList *listPtr, MHEG5TokenGroup *tokenGrp)
Decodes TokenGroup class. Refer to MHEG5 Specification (ISO/IEC 13522-2:1996), Appendix A...
Basis MHEG5 data types.
MHEG5String stringData
Definition: fpa1_syn.h:46
Functions to create a MHEG5Action from a MHEG5 script (in the form of a list of fpa1_syntaxList struc...
Functions to create a MHEG5Ingredient from a MHEG5 script (in the form of a list of fpa1_syntaxList s...
MH5GroupPtr asn1_mainGroupPtr
#define INTEGER
Definition: vpa1_tgs.h:40
MHEG5Bool shared
Definition: mh5ingredient.h:72
Miscellaneous functions for decoding ASN.1 types.
void MHEG5tokenManagerAddRow(MHEG5TokenManager *tokenManager)
Add a new row to a TokenManager.
#define INITACTIVE
Definition: vpa1_tgs.h:105
Contains functions/structure used to do MHEG-5 ASN.1 syntax parsing.
Functions to create a MHEG5Group from a MHEG5 script (in the form of a list of fpa1_syntaxList struct...
#define MHEG5getMem
Definition: glue_memory.h:93
MHEG5Final clazz
Definition: mh5root.h:55
U32BIT asn1_getTokenGroupItemCount(fpa1_syntaxList *currItem)
Gets total count of TG Items and Action Slots.
Typedefs, macros used by all of parser. These may be duplicated elsewhere.
union sMH5GroupRef::@5 ptr
struct fpa1_syntaxItem * children
Definition: fpa1_syn.h:53
#define ASN_NO_ERROR
Definition: asn1_sys.h:36
syntaxItemData data
Definition: fpa1_syn.h:57
MHEG5Int tokens_num
Definition: mh5tokengroup.h:65
#define DPL5(x)
Definition: glue_debug.h:167
unsigned short childCount[3]
Definition: fpa1_syn.h:59
void MHEG5tokenManagerAddNumber(MHEG5TokenManager *tokenManager, MHEG5Int number)
Insert a number into the last element of the movement table.
typedefs etc for the whole object creation section.
Contains macros for MHEG-5 ASN.1 tags and structures.
MHEG5Ingredient * asn1_createTokenGroup(fpa1_syntaxList *listPtr)
Decodes TokenGroup class. Refer to MHEG5 Specification (ISO/IEC 13522-2:1996), Appendix A...
#define SHARED
Definition: vpa1_tgs.h:108
Functions to create a MHEG5TokenManager from a MHEG5 script (in the form of a list of fpa1_syntaxList...
Implement the MHEG5 Tokengroup Class 29 TokenGroup Class. Defines a group of Visible objects for navi...
#define MHEG5freeMem
Definition: glue_memory.h:94
void asn1_decodeActions(fpa1_syntaxList *listPtr, MHEG5ActionList *p_actions)
Decodes action class Refer to MHEG5 Specification (ISO/IEC 13522-2:1996), Appendix A...
MHEG5Bool boolData
Definition: fpa1_syn.h:44
MHEG5TokenSlot * tokens_ptr
Definition: mh5tokengroup.h:66
MHEG5Byte * data
Definition: mh5base.h:85
#define DPL2(x)
Definition: glue_debug.h:185
MHEG5Int actions_num
Definition: mh5tokengroup.h:53
#define MHEG5TRUE
Definition: mh5base.h:49
MHEG5Bool initiallyStopped
Definition: mh5ingredient.h:71
MHEG5Ingredient ingredient
Definition: mh5tokengroup.h:61
MHEG5Int len
Definition: mh5base.h:99
#define NOTOKEN
Definition: vpa1_tgs.h:121
MHEG5Byte * name
Definition: mh5base.h:102
MHEG5Int id
Definition: mh5root.h:48
#define MOVEMENTTABLE
Definition: vpa1_tgs.h:119
int asnErr
Definition: asn1_sys.h:41
MH5GroupRef groupid
Definition: mh5tokengroup.h:52
MH5GroupPtr group
Definition: mh5base.h:103
MHEG5ActionList * actions_ptr
Definition: mh5tokengroup.h:54
MHEG5Int len
Definition: mh5base.h:84
struct fpa1_syntaxItem * next
Definition: fpa1_syn.h:52
Functions to create a MHEG5TokenGroup from a MHEG5 script (in the form of a list of fpa1_syntaxList s...
MHEG5Int intData
Definition: fpa1_syn.h:45
MHEG5TokenManager tokenManager
Definition: mh5tokengroup.h:62
MHEG5Int contentHook
Definition: mh5ingredient.h:69
#define CHOOK
Definition: vpa1_tgs.h:106
#define TGITEMS
Definition: vpa1_tgs.h:120
uint32_t U32BIT
Definition: techtype.h:86