MHEG5  18.9.0
MHEG5 Documentation
fpa1_syn.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  *******************************************************************************/
26 /*---includes for this file--------------------------------------------------*/
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "vpa1_tgs.h"
31 #include "vpa1_rdf.h"
32 
33 #include "fpa1_rdf.h"
34 #include "fpa1_syn.h"
35 #include "fpa1_tgs.h"
36 
37 #include "pa1_mem.h"
38 
39 #include "fpa1_BlockAlloc.h"
40 
41 /*---local typedef structs for this file-------------------------------------*/
42 
43 /*---constant definitions for this file--------------------------------------*/
44 
45 
46 /*---local (static) variable declarations for this file----------------------*/
47 
48 /*---local function definitions----------------------------------------------*/
49 
50 /*---global function definitions---------------------------------------------*/
51 
57 {
58  int tag;
59  vpa1_filePos curFilePosition, nextTagPosition;
60  fpa1_syntaxList *tempPtr;
61 
62  fpa1_syntaxList *compListPtr = NULL;
63 
64  tag = 1;
65 
66  /* save current file position */
67  curFilePosition = fpa1_rdfGetCurrentFilePosition();
68 
69  while ((tag > 0) && (curFilePosition < filePosLimit))
70  {
71  /* Go through all tags until there are no more */
72  tag = fpa1_rdfGetTag();
73  nextTagPosition = fpa1_rdfGetNextTagPosn();
74 
75  /* run of unknown components has been broken */
76  tempPtr = fpa1_synCreateListItem( tag, curFilePosition, nextTagPosition );
77 
78  if (tempPtr != NULL)
79  {
80  /* get primative data */
81  if (tempPtr->tag < CONT_SPEC_TAGS)
82  {
83  fpa1_parseData(tempPtr);
84  }
85 
86  compListPtr = fpa1_synAddItemToList( compListPtr, tempPtr);
87  }
88 
89  /* set up current file position variable */
90  curFilePosition = nextTagPosition;
91  fpa1_rdfSetNewFilePosition( curFilePosition );
92  }
93 
94  return compListPtr;
95 }
96 
102  fpa1_syntaxList *compToAdd )
103 {
104  fpa1_syntaxList *lastItemPtr;
105 
106  if (listPtr != NULL)
107  {
108  if (compToAdd != NULL)
109  {
110  lastItemPtr = compToAdd;
111  /* get last item and tack list onto to end of it */
112  while (lastItemPtr->next != NULL)
113  lastItemPtr = lastItemPtr->next;
114 
115  lastItemPtr->next = listPtr;
116 
117  return compToAdd;
118  }
119  else
120  {
121  return listPtr;
122  }
123  }
124  else
125  {
126  return compToAdd;
127  }
128 } /* fpa1_synAddItemToStartOfList */
129 
135  fpa1_syntaxList *compToAdd )
136 {
137  /* Possibly a bit over the top */
138  fpa1_syntaxList *tempPtr = firstComp;
139 
140  if (tempPtr != NULL)
141  {
142  while ((tempPtr->next != NULL))
143  {
144  tempPtr = tempPtr->next;
145  }
146 
147  tempPtr->next = compToAdd;
148 
149  return firstComp;
150  }
151  else
152  {
153  return compToAdd;
154  }
155 } /* fpa1_synAddItemToList */
156 
162  vpa1_filePos tagPosition,
163  vpa1_filePos nextTagPosition )
164 {
165  fpa1_syntaxList *tempPtr;
166 
167  /*tempPtr = (fpa1_syntaxList *) pa1_malloc( sizeof( fpa1_syntaxList ) );*/
168  tempPtr = fpa1_getTagItem();
169 
170  if (tempPtr != NULL)
171  {
172  /* next points to tags on the same level i.e. tags */
173  /* within sequences or sets */
174  tempPtr->next = NULL;
175 
176  /* children points to tags NOT on same level */
177  /* i.e. sequences within sequences */
178  tempPtr->children = NULL;
179  tempPtr->tag = tag;
180  tempPtr->tagPosition = tagPosition;
181  tempPtr->nextTagPosition = nextTagPosition;
182  tempPtr->childCount[0] = 0;
183  tempPtr->childCount[1] = 0;
184  tempPtr->childCount[2] = 0;
185  tempPtr->dataTotal = 0;
186 
187  /* printf("\nCreate %p posn %d tag %d\n", tempPtr, tagPosition, tag ); */
188  }
189 
190  return tempPtr;
191 } /* fpa1_synCreateListItem() */
192 
199 {
200  fpa1_syntaxList *nextComp = firstComp;
201 
202  if (nextComp != NULL)
203  {
204  /* are there any children */
205  if (firstComp->children != NULL)
206  {
207  fpa1_synFreeList( firstComp->children );
208  firstComp->children = NULL;
209  }
210 
211  /* get next item in list - for return */
212  nextComp = nextComp->next;
213 
214  /* printf("\nFree %p posn %d tag %d\n", firstComp,
215  firstComp->tagPosition,
216  firstComp->tag ); */
217 
218  /* clean up structure pointers */
219  firstComp->next = NULL;
220 
221  /*pa1_free( (void *) firstComp);*/
222  }
223 
224  return nextComp;
225 } /* fpa1_synFreeFirstItem() */
226 
233 {
234  while (firstComp != NULL)
235  {
236  firstComp = fpa1_synFreeFirstItem( firstComp );
237  }
238 } /* fpa1_synFreeList() */
239 
246  vpa1_filePos endPosition,
247  fpa1_syntaxList *inputPtr )
248 {
249  fpa1_syntaxList *tempPtr;
250  fpa1_syntaxList *unknownPtr = NULL;
251 
252  while (inputPtr != NULL)
253  {
254  /* we have a list! */
255  if (inputPtr->tagPosition == startPosition)
256  {
257  /* tag contiguous with last tag - move on to the next one */
258  startPosition = inputPtr->nextTagPosition;
259  inputPtr = inputPtr->next;
260  }
261  else
262  {
263  /* found a gap in tag list - create an "unknown" item */
264 
265  /* set up position */
266  fpa1_rdfSetNewFilePosition( startPosition );
267 
268  /* create item - unknown tag goes from current position to start */
270  startPosition,
271  inputPtr->tagPosition );
272 
273  /* get primative data */
274  if (tempPtr->tag < CONT_SPEC_TAGS)
275  {
276  fpa1_parseData(tempPtr);
277  }
278 
279  unknownPtr = fpa1_synAddItemToList( unknownPtr, tempPtr );
280 
281  /* reset start position */
282  startPosition = inputPtr->tagPosition;
283  }
284  }
285 
286  /* test for unknown "end" section */
287  if (startPosition != endPosition)
288  {
289  /* create unknown "end" item */
290  fpa1_rdfSetNewFilePosition( startPosition );
291 
292  /* create item - unknown tag goes from current position to start */
294  startPosition,
295  endPosition );
296 
297  /* get primative data */
298  if (tempPtr->tag < CONT_SPEC_TAGS)
299  {
300  fpa1_parseData(tempPtr);
301  }
302 
303  unknownPtr = fpa1_synAddItemToList( unknownPtr, tempPtr );
304  }
305 
306  return unknownPtr;
307 } /* fpa1_synGetUnknowns () */
308 
vpa1_filePos fpa1_rdfGetCurrentFilePosition(void)
Definition: fpa1_rdf.c:253
Contains functions/globals used to read MHEG-5 ASN.1 scripts.
fpa1_syntaxList * fpa1_synAddItemToList(fpa1_syntaxList *firstComp, fpa1_syntaxList *compToAdd)
Definition: fpa1_syn.c:134
Contains function to parse MHEG-5 ASN.1 tags.
vpa1_filePos fpa1_rdfGetNextTagPosn(void)
Definition: fpa1_rdf.c:336
fpa1_syntaxList * fpa1_getTagItem(void)
Contains functions/structure used to do MHEG-5 ASN.1 syntax parsing.
struct fpa1_syntaxItem * children
Definition: fpa1_syn.h:53
int fpa1_parseData(fpa1_syntaxList *listPtr)
Gets primitave data item from script and puts it in current syntaxList item.
Definition: fpa1_tgs.c:510
Typedefs for script reading functions.
unsigned short childCount[3]
Definition: fpa1_syn.h:59
Contains macros for MHEG-5 ASN.1 tags and structures.
void fpa1_synFreeList(fpa1_syntaxList *firstComp)
Definition: fpa1_syn.c:232
vpa1_filePos nextTagPosition
Definition: fpa1_syn.h:56
#define CONT_SPEC_TAGS
Definition: vpa1_tgs.h:48
syntax item block manager Contains functions to create a mini memory manager for allocating syntax li...
unsigned short dataTotal
Definition: fpa1_syn.h:60
vpa1_filePos tagPosition
Definition: fpa1_syn.h:55
fpa1_syntaxList * fpa1_synGetAllTags(vpa1_filePos filePosLimit)
Definition: fpa1_syn.c:56
int fpa1_rdfGetTag(void)
Definition: fpa1_rdf.c:142
Contains memory management functions.
fpa1_syntaxList * fpa1_synAddItemToStartOfList(fpa1_syntaxList *listPtr, fpa1_syntaxList *compToAdd)
Definition: fpa1_syn.c:101
fpa1_syntaxList * fpa1_synFreeFirstItem(fpa1_syntaxList *firstComp)
Definition: fpa1_syn.c:198
long vpa1_filePos
Definition: vpa1_sys.h:47
struct fpa1_syntaxItem * next
Definition: fpa1_syn.h:52
int fpa1_rdfSetNewFilePosition(vpa1_filePos)
Definition: fpa1_rdf.c:375
fpa1_syntaxList * fpa1_synCreateListItem(int tag, vpa1_filePos tagPosition, vpa1_filePos nextTagPosition)
Definition: fpa1_syn.c:161
fpa1_syntaxList * fpa1_synGetUnknowns(vpa1_filePos startPosition, vpa1_filePos endPosition, fpa1_syntaxList *inputPtr)
Definition: fpa1_syn.c:245