MHEG5  18.9.0
MHEG5 Documentation
fpa1_parserInvoke.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 "mh5final.h"
31 #include "vpa1_rdf.h"
32 #include "asn1_sys.h"
33 #include "mh5application.h"
34 #include "mh5scene.h"
35 #include "fpa1_rdf.h"
36 #include "fpa1_cho.h"
37 #include "asn1_createApplication.h"
38 #include "asn1_createScene.h"
39 #include "asn1_createAction.h"
40 #include "fpa1_parserInvoke.h"
41 #include "fpa1_BlockAlloc.h"
42 
43 #ifdef ASN1TEST
44 #include "asn1_testHarness.h"
45 #endif /* ASN1TEST */
46 
47 /*---constant definitions for this file--------------------------------------*/
48 
49 
50 /*---local typedef structs for this file-------------------------------------*/
51 
52 /*---local (static) variable declarations for this file----------------------*/
53 
54 /*---local function definitions----------------------------------------------*/
55 
56 /*---global function definitions---------------------------------------------*/
57 
66 MHEG5Application* asn1_parseApplication(unsigned char *asnData, unsigned long dataLength)
67 {
68  asnErr errVal = 0; /* internal use only */
69  fpa1_syntaxList *itemPtr;
70  MHEG5Application *application = NULL;
71  int size;
72 
73  if (asnData == NULL)
74  {
75  return NULL;
76  }
77 
78  /* create tag list, this will return NULL if it fails */
79  itemPtr = fpa1_parseScriptASN( asnData, dataLength);
80 
81  if (itemPtr != NULL)
82  {
83  /* Create application */
84  size = sizeof(MHEG5Application) +
86  (fpa1_GroupParamCount * sizeof(MHEG5GList)); /*todo: MHEG5GList -> MHEG5Generic*/
87 
88  application = (MHEG5Application *) MHEG5getMem( size );
89 
90  if (application == NULL)
91  {
92  DPL1(("ERROR:[ASN.1] unable to create application: malloc failed\n"));
93  application = NULL;
94  }
95  else
96  {
97  asn1_GroupActionPtr = (MHEG5Action *)(application + 1);
99 
100  /* fill application object */
101  memset(application, 0, size);
102  ((MHEG5Root *)application)->clazz = MHEG5APPLICATION;
103  MHEG5applicationInit(application);
104 
105  errVal |= asn1_decodeApplication(itemPtr, application);
106 
107  if (errVal)
108  {
109  DPL2(("WARNING:[ASN.1] Failed to decode the MHEG5Application object\n"));
110  /* no need to call MHEG5ApplicationDestruct here since asn1_decodeApplication
111  will have cleaned up anything it created */
112  MHEG5applicationDestruct(application);
113  MHEG5applicationFree(application);
114  MHEG5freeMem(application);
115  application = NULL;
116  }
117  #ifdef ASN1TEST
118  else
119  {
120  /* printouts, for testing only */
121  /*printRawASN(asnData, dataLength, "testApplication.asn");*/
122  /*printList(itemPtr, "testApplication.tree");*/
123  asn1_printApplication(application, ASN1_PARSER);
124  }
125  #endif /* ASN1TEST */
126  }
127  }
128  else
129  {
130  DPL2(("WARNING:[ASN.1] Failure to read application file\n"));
131  application = NULL;
132  }
133 
135 
136  return application;
137 }
138 
148 MHEG5Scene* asn1_parseScene(unsigned char *asnData, unsigned long dataLength)
149 {
150  asnErr errVal = 0; /* internal use only */
151  fpa1_syntaxList *itemPtr;
152  MHEG5Scene *scene = NULL;
153  int size;
154 
155  if (asnData == NULL)
156  {
157  return NULL;
158  }
159 
160  /* Create scene */
161  /* create tag list, this will return NULL if it fails */
162  itemPtr = fpa1_parseScriptASN( asnData, dataLength);
163 
164  /* create scene object */
165  if (itemPtr != NULL)
166  {
167  /* Create application */
168  size = sizeof(MHEG5Scene) +
169  (fpa1_GroupActionCount * sizeof(MHEG5Action)) +
170  (fpa1_GroupParamCount * sizeof(MHEG5GList)); /*todo: MHEG5GList -> MHEG5Generic*/
171 
172  scene = (MHEG5Scene *) MHEG5getMem( size );
173 
174  if (scene == NULL)
175  {
176  DPL1(("ERROR:[ASN.1] unable to create scene: malloc failed\n"));
177  scene = NULL;
178  }
179  else
180  {
181  asn1_GroupActionPtr = (MHEG5Action *)(scene + 1);
183 
184  memset(scene, 0, size);
185  ((MHEG5Root *)scene)->clazz = MHEG5SCENE;
186  MHEG5sceneInit(scene);
187 
188  errVal |= asn1_decodeScene(itemPtr, scene);
189  if (errVal)
190  {
191  DPL2(("WARNING:[ASN.1] Failed to decode the MHEG5Sccene object\n"));
192  MHEG5sceneDestruct(scene);
193  MHEG5sceneFree(scene);
194  MHEG5freeMem(scene);
195  scene = NULL;
196  }
197  #ifdef ASN1TEST
198  else
199  {
200  /* printouts, for testing only */
201  asn1_printScene(scene, ASN1_PARSER);
202  }
203  #endif /* ASN1TEST */
204  }
205  }
206  else
207  {
208  DPL2(("WARNING:[ASN.1] Failure to read scene file\n"));
209  scene = NULL;
210  }
211 
213 
214  return scene;
215 }
216 
void MHEG5applicationInit(MHEG5Application *application)
Initialise an application object with default values.
int fpa1_GroupActionCount
Definition: fpa1_rdf.c:67
void MHEG5sceneDestruct(MHEG5Scene *scene)
Destruct a scene object.
Definition: mh5scene.c:446
Distributor for Prepare, Destruct, Activate, Deactivate and Clone calls. Distribute the +Prepare +Des...
Contains functions/globals used to read MHEG-5 ASN.1 scripts.
void MHEG5applicationFree(MHEG5Application *application)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Functions to create a MHEG5Action from a MHEG5 script (in the form of a list of fpa1_syntaxList struc...
void MHEG5sceneFree(MHEG5Scene *scene)
Free off all memory associated with the specified object, including any exchanged attributes and inte...
Definition: mh5scene.c:395
fpa1_syntaxList * fpa1_parseScriptASN(unsigned char *asndata, unsigned long len)
Top level entry point to the ASN.1 script to fpa1_syntaxList converter. This function takes the origi...
Definition: fpa1_rdf.c:462
asnErr asn1_decodeScene(fpa1_syntaxList *listPtr, MHEG5Scene *scene)
int fpa1_freeUnusedData(void)
#define MHEG5getMem
Definition: glue_memory.h:93
Interface functions for invoking the ASN.1 parser.
Typedefs for script reading functions.
asnErr asn1_decodeApplication(fpa1_syntaxList *listPtr, MHEG5Application *application)
Decodes Group class. Refer to MHEG5 Specification (ISO/IEC 13522-2:1996), Appendix A...
void MHEG5sceneInit(MHEG5Scene *scene)
Initialise a scene object with default values.
Definition: mh5scene.c:378
typedefs etc for the whole object creation section.
Functions to create a MHEG5Scene from a MHEG5 script (in the form of a list of fpa1_syntaxList struct...
#define MHEG5freeMem
Definition: glue_memory.h:94
syntax item block manager Contains functions to create a mini memory manager for allocating syntax li...
MHEG5Action * asn1_GroupActionPtr
void MHEG5applicationDestruct(MHEG5Application *application)
Destruct an application object. This function destructs all parts of an application object...
#define DPL1(x)
Definition: glue_debug.h:191
MHEG5GList * asn1_GroupParamPtr
#define DPL2(x)
Definition: glue_debug.h:185
Implementation of the MHEG5 Application Class Defines a set of Ingredient objects, which are shared within an application scope. Base class: Group Subclasses: None Status: Concrete class.
Implementation of the MHEG5 Scene Class Scene Class Defines a set of Ingredient objects to be activat...
MHEG5Scene * asn1_parseScene(unsigned char *asnData, unsigned long dataLength)
Top level ASN.1 parser interface function. Creates and fills a MHEG5Scene object from a char array co...
Functions to create a MHEG5Application from a MHEG5 script (in the form of a list of fpa1_syntaxList ...
int asnErr
Definition: asn1_sys.h:41
MHEG5Application * asn1_parseApplication(unsigned char *asnData, unsigned long dataLength)
Top level ASN.1 parser interface function. Creates and fills a MHEG5Application object from a char ar...
int fpa1_GroupParamCount
Definition: fpa1_rdf.c:68