MHEG5  18.9.0
MHEG5 Documentation
fpa1_set.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 <stdlib.h>
30 
31 #include "vpa1_rdf.h"
32 #include "vpa1_sys.h"
33 #include "vpa1_tgs.h"
34 
35 #include "fpa1_rdf.h"
36 #include "fpa1_seq.h"
37 #include "fpa1_set.h"
38 #include "fpa1_rdf.h"
39 #include "fpa1_tgs.h"
40 #include "fpa1_typ.h"
41 #include "fpa1_BlockAlloc.h"
42 
43 /*---local typedef structs for this file-------------------------------------*/
44 
45 /*---constant definitions for this file--------------------------------------*/
46 
47 
48 /*---local (static) variable declarations for this file----------------------*/
49 
50 /*---local function definitions----------------------------------------------*/
51 
52 /*---global function definitions---------------------------------------------*/
53 static int fpa1_setCheckTags( int, int * );
54 
59 static int fpa1_setCheckTags( int tag, int *optArr )
60 {
61  int count = 1;
62  int arrLimit = optArr[0];
63 
64  while (count < arrLimit)
65  {
66  if (tag == optArr[ count ])
67  {
68  break;
69  }
70 
71  /* tags every second element */
72  count += 2;
73  }
74 
75  return count;
76 } /* fpa1_setCheckTags() */
77 
82 static fpa1_syntaxList* fpa1_setCheckConstraints( int *optArr, fpa1_syntaxList *itemPtr )
83 {
84  int count = 1;
85  int arrLimit = optArr[0];
86  fpa1_syntaxList *tempPtr;
87 
88  while (count < arrLimit)
89  {
90  if (optArr[ count + 1 ] == SYN_NEEDED)
91  {
92  tempPtr = itemPtr;
93  while (tempPtr != NULL)
94  {
95  if (tempPtr->tag == optArr[ count ])
96  {
97  /* found a match - carry on */
98  break;
99  }
100 
101  tempPtr = tempPtr->next;
102  }
103 
104  if (tempPtr == NULL)
105  {
106 #ifdef DEBUG_ASN
107 
108  /* "NEEDED" item missing - delete list */
109  printf( "NEEDED tag = %d \n", optArr[ count ] );
110 
111  tempPtr = itemPtr;
112  while (tempPtr != NULL)
113  {
114 /* printf( "\nFree %p tag %d posn %d\n",
115  tempPtr,
116  tempPtr->tag,
117  tempPtr->tagPosition ); */
118 
119  tempPtr = tempPtr->next;
120  }
121 
122  printf( "SET removed \n" );
123 
124 #endif
125 
126  fpa1_delList( itemPtr );
127  itemPtr = NULL;
128  break;
129  }
130  }
131 
132  /* tags every second element */
133  count += 2;
134  }
135 
136  return itemPtr;
137 } /* fpa1_setCheckConstraints() */
138 
146 static fpa1_syntaxList* fpa1_setResetTypeTags( fpa1_syntaxList *itemPtr )
147 {
148  fpa1_syntaxList *newPtr = NULL;
149 
150  fpa1_syntaxList *tempPtr = itemPtr;
151 
152  while (tempPtr != NULL)
153  {
154  if (tempPtr->tag > MHEG5_TYPE)
155  {
157  newPtr = fpa1_typeParse( tempPtr->tag, tempPtr->nextTagPosition );
158 
159  if (newPtr != NULL)
160  {
161  tempPtr->tag = newPtr->tag;
162  }
163 
164  fpa1_delList( newPtr );
165  newPtr = NULL;
166  }
167 
168  tempPtr = tempPtr->next;
169  }
170 
171  return itemPtr;
172 } /* fpa1_setResetTypeTags() */
173 
178 fpa1_syntaxList* fpa1_setParse( int *setArrPtr, vpa1_filePos filePosLimit )
179 {
180  int limit = setArrPtr[0];
181  int count = 1;
182 
183  fpa1_syntaxList *itemPtr = NULL;
184  fpa1_syntaxList *setTagPtr = NULL;
185 
186  /* file position should be set up correctly */
187  /* before calling fpa1_setParse() */
188 
189  /* get all tags from current file position to limit */
190  fpa1_syntaxList *tagListPtr = fpa1_synGetAllTags( filePosLimit );
191 
192  /* got some items to check */
193  while (tagListPtr != NULL)
194  {
195  /* is it a Context Specific tag */
196  if (fpa1_setCheckTags( tagListPtr->tag, setArrPtr ) < limit)
197  {
198  itemPtr = fpa1_synCreateListItem( tagListPtr->tag,
199  tagListPtr->tagPosition,
200  tagListPtr->nextTagPosition );
201  /* looking for a TAG */
202  if (fpa1_tagsParse( itemPtr ) == FALSE)
203  {
204  /* a failure of some sort - delete item */
205  fpa1_delList( itemPtr );
206  itemPtr = NULL;
207  }
208  }
209  else
210  {
211  /* try TYPES */
212  count = 1;
213 
214  /* looking for a TYPE */
216 
217  while (count < limit)
218  {
219  if (setArrPtr[count] > MHEG5_TYPE)
220  {
221  itemPtr = fpa1_typeParse( setArrPtr[count],
222  filePosLimit );
223  if (itemPtr != NULL)
224  {
225  /* store tag value - for checking later */
226  itemPtr->tag = setArrPtr[count];
227  }
228  }
229  count += 2;
230  }
231  }
232 
233  /* add tag to list */
234  if (itemPtr != NULL)
235  {
236  /* add to list of sequence tags */
237  setTagPtr = fpa1_synAddItemToList( setTagPtr, itemPtr );
238  itemPtr = NULL;
239  }
240 
241  tagListPtr = fpa1_delFirstItem( tagListPtr );
242  }
243 
244  /* check the constraints */
245  if (setTagPtr != NULL)
246  {
247  setTagPtr = fpa1_setCheckConstraints( setArrPtr, setTagPtr );
248  }
249 
250  if (setTagPtr != NULL)
251  {
252  setTagPtr = fpa1_setResetTypeTags( setTagPtr );
253  }
254 
255  return setTagPtr;
256 } /* fpa1_setTxtParse() */
257 
Contains functions to decode MHEG-5 ASN.1 types.
#define SYN_NEEDED
Definition: fpa1_syn.h:34
fpa1_syntaxList * fpa1_synCreateListItem(int, vpa1_filePos, vpa1_filePos)
Definition: fpa1_syn.c:161
Contains functions/globals used to read MHEG-5 ASN.1 scripts.
fpa1_syntaxList * fpa1_synAddItemToList(fpa1_syntaxList *, fpa1_syntaxList *)
Definition: fpa1_syn.c:134
fpa1_syntaxList * fpa1_synGetAllTags(vpa1_filePos)
Definition: fpa1_syn.c:56
Contains function to parse MHEG-5 ASN.1 tags.
fpa1_syntaxList * fpa1_typeParse(int, vpa1_filePos)
Definition: fpa1_typ.c:219
int fpa1_tagsParse(fpa1_syntaxList *)
Definition: fpa1_tgs.c:532
Typedefs, macros used by all of parser. These may be duplicated elsewhere.
Typedefs for script reading functions.
Contains macros for MHEG-5 ASN.1 tags and structures.
fpa1_syntaxList * fpa1_setParse(int *setArrPtr, vpa1_filePos filePosLimit)
Definition: fpa1_set.c:178
vpa1_filePos nextTagPosition
Definition: fpa1_syn.h:56
syntax item block manager Contains functions to create a mini memory manager for allocating syntax li...
unsigned short count
int fpa1_delList(fpa1_syntaxList *firstComp)
vpa1_filePos tagPosition
Definition: fpa1_syn.h:55
Contains functions used to parse MHEG-5 ASN.1 SETs. SETs can have components in any order and as such...
#define FALSE
Definition: techtype.h:68
long vpa1_filePos
Definition: vpa1_sys.h:47
struct fpa1_syntaxItem * next
Definition: fpa1_syn.h:52
Contains functions used to parse MHEG-5 ASN.1 SEQUENCEs. SEQUENCEs have components in order...
fpa1_syntaxList * fpa1_delFirstItem(fpa1_syntaxList *firstComp)
int fpa1_rdfSetNewFilePosition(vpa1_filePos)
Definition: fpa1_rdf.c:375