• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // ----------------------------------------------------------------------
19 //
20 // This Software is an original work of authorship of PacketVideo Corporation.
21 // Portions of the Software were developed in collaboration with NTT  DoCoMo,
22 // Inc. or were derived from the public domain or materials licensed from
23 // third parties.  Title and ownership, including all intellectual property
24 // rights in and to the Software shall remain with PacketVideo Corporation
25 // and NTT DoCoMo, Inc.
26 //
27 // -----------------------------------------------------------------------
28 // ============================================================
29 // FILE: AnalyzePER.c
30 //
31 // DESCRIPTION: PER analysis support routines.
32 //   These routines provide support for the automatically
33 //   generated functions in h245_analysis.[ch].
34 //
35 // Written by Ralph Neff, PacketVideo, 3/6/2000
36 // (c) 2000 PacketVideo Corp.
37 // ============================================================
38 
39 #include "oscl_base.h"
40 #include "per_headers.h"
41 #include "genericper.h"
42 #include "analyzeper.h"
43 
44 #ifdef PVANALYZER   // Analyzer interface function
45 #include <tchar.h>
46 void PVAnalyzer(unsigned int tag, Tint8 *message_fmt, ...);
47 #endif
48 
49 /* --------------------------------------------- */
50 /* ----------- BASE LEVEL int32ERFACE ------------ */
51 /* --------------------------------------------- */
52 
53 /*
54 void MyPVAnalyzer(uint16 tag, uint8 *outString)
55 {
56     FILE *fp = fopen("analyzer.txt","a");
57     fprintf(fp, outString);
58     fprintf(fp, "\n");
59     fclose(fp);
60 }
61 */
62 
63 // =========================================================
64 // Show245()
65 //
66 // This function takes an output analysis line, adds the
67 // proper indent, and sends the result out to the display
68 // routine.  The 'tag' argument is simply passed on.
69 // =========================================================
Show245(uint16 tag,uint16 indent,const char * inString)70 void Show245(uint16 tag, uint16 indent, const char* inString)
71 {
72     OSCL_UNUSED_ARG(tag);
73     OSCL_UNUSED_ARG(indent);
74     OSCL_UNUSED_ARG(inString);
75 #ifdef PVANALYZER  //07/12/01wjj
76     uint32 i;
77     uint8 outString[200];
78 
79     /* Construct outString with proper indent */
80     for (i = 0; i < indent; ++i)
81     {
82         outString[i] = ' ';
83     }
84     sprintf(outString + i, "%s", inString);
85 
86 //#ifdef PVANALYZER  //07/12/01wjj
87     /* Send outString to display */
88     PVAnalyzer(tag, outString);        /* The real deal */
89 #endif
90 }
91 
92 // =========================================================
93 // ShowHexData()
94 //
95 // This function shows a hex dump of a string of uint8s.
96 // The resulting output line(s) gets displayed by call to
97 // Show245().  The first two input arguments (tag, indent)
98 // are simply passed through.
99 // =========================================================
ShowHexData(uint16 tag,uint16 indent,uint16 size,uint8 * data)100 void ShowHexData(uint16 tag, uint16 indent, uint16 size, uint8* data)
101 {
102     OSCL_UNUSED_ARG(tag);
103     OSCL_UNUSED_ARG(indent);
104     OSCL_UNUSED_ARG(size);
105     OSCL_UNUSED_ARG(data);
106 #ifdef PVANALYZER  //07/12/01wjj
107     uint32 i;
108     uint8 outString[100];
109 
110     for (i = 0; i < size; ++i)
111     {
112         sprintf(outString + 3*(i % 16), "%02x ", data[i]);
113         if ((i % 16) == 15 || (i + 1) == size)
114         {
115             outString[3*(i%16+1)] = '\0';
116             Show245(tag, indent, outString);
117         }
118     }
119 #endif
120 }
121 
122 /* --------------------------------------------- */
123 /* ----------- LOW LEVEL OBJECTS --------------- */
124 /* --------------------------------------------- */
125 
126 // =========================================================
127 // ShowPERNull()
128 //
129 // This function displays a NULL object via call to Show245().
130 // =========================================================
ShowPERNull(uint16 tag,uint16 indent,const char * label)131 void ShowPERNull(uint16 tag, uint16 indent, const char* label)
132 {
133     OSCL_UNUSED_ARG(tag);
134     OSCL_UNUSED_ARG(indent);
135     OSCL_UNUSED_ARG(label);
136 #ifdef PVANALYZER  //07/12/01wjj
137     uint8 outString[100];
138 
139     sprintf(outString, "%s = NULL", label);
140     Show245(tag, indent, outString);
141 #endif
142 }
143 
144 // =========================================================
145 // ShowPERBoolean()
146 //
147 // This function displays a BOOLEAN object via call to
148 // Show245().
149 // =========================================================
ShowPERBoolean(uint16 tag,uint16 indent,const char * label,uint32 value)150 void ShowPERBoolean(uint16 tag, uint16 indent, const char* label, uint32 value)
151 {
152     OSCL_UNUSED_ARG(tag);
153     OSCL_UNUSED_ARG(indent);
154     OSCL_UNUSED_ARG(label);
155     OSCL_UNUSED_ARG(value);
156 #ifdef PVANALYZER  //07/12/01wjj
157     uint8 outString[100];
158 
159     if (value)
160     {
161         sprintf(outString, "%s = TRUE", label);
162     }
163     else
164     {
165         sprintf(outString, "%s = FALSE", label);
166     }
167     Show245(tag, indent, outString);
168 #endif
169 }
170 
171 // =========================================================
172 // ShowPERInteger()
173 //
174 // This function displays an int32EGER object via call to
175 // Show245().
176 // =========================================================
ShowPERInteger(uint16 tag,uint16 indent,const char * label,uint32 value)177 void ShowPERInteger(uint16 tag, uint16 indent, const char* label, uint32 value)
178 {
179     OSCL_UNUSED_ARG(tag);
180     OSCL_UNUSED_ARG(indent);
181     OSCL_UNUSED_ARG(label);
182     OSCL_UNUSED_ARG(value);
183 #ifdef PVANALYZER  //07/12/01wjj
184     uint8 outString[100];
185 
186     sprintf(outString, "%s = %u", label, value);
187     Show245(tag, indent, outString);
188 #endif
189 }
190 
191 // =========================================================
192 // ShowPERSignedInteger()
193 //
194 // This function displays the signed variant of an int32EGER
195 // object via call to Show245().
196 // =========================================================
ShowPERSignedInteger(uint16 tag,uint16 indent,const char * label,int32 value)197 void ShowPERSignedInteger(uint16 tag, uint16 indent, const char* label, int32 value)
198 {
199     OSCL_UNUSED_ARG(tag);
200     OSCL_UNUSED_ARG(indent);
201     OSCL_UNUSED_ARG(label);
202     OSCL_UNUSED_ARG(value);
203 #ifdef PVANALYZER  //07/12/01wjj
204     uint8 outString[100];
205 
206     sprintf(outString, "%s = %d", label, value);
207     Show245(tag, indent, outString);
208 #endif
209 }
210 
211 // =========================================================
212 // ShowPERUnboundedInteger()
213 //
214 // This function displays the unbounded variant of an int32EGER
215 // object via call to Show245().  We currently take the
216 // input type to be uint32.
217 // =========================================================
ShowPERUnboundedInteger(uint16 tag,uint16 indent,const char * label,uint32 value)218 void ShowPERUnboundedInteger(uint16 tag, uint16 indent, const char* label, uint32 value)
219 {
220     OSCL_UNUSED_ARG(tag);
221     OSCL_UNUSED_ARG(indent);
222     OSCL_UNUSED_ARG(label);
223     OSCL_UNUSED_ARG(value);
224 #ifdef PVANALYZER  //07/12/01wjj
225     uint8 outString[100];
226 
227     sprintf(outString, "%s = %u", label, value);
228     Show245(tag, indent, outString);
229 #endif
230 }
231 
232 // =========================================================
233 // ShowPEROctetString()
234 //
235 // This function displays an OCTETSTRING object via call
236 // to Show245().
237 // =========================================================
ShowPEROctetString(uint16 tag,uint16 indent,const char * label,PS_OCTETSTRING x)238 void ShowPEROctetString(uint16 tag, uint16 indent, const char* label, PS_OCTETSTRING x)
239 {
240     OSCL_UNUSED_ARG(tag);
241     OSCL_UNUSED_ARG(indent);
242     OSCL_UNUSED_ARG(label);
243     OSCL_UNUSED_ARG(x);
244 #ifdef PVANALYZER  //07/12/01wjj
245     uint8 outString[100];
246 
247     sprintf(outString, "%s is an OCTET STRING (SIZE = %hu)",
248             label, x->size);
249     Show245(tag, indent, outString);
250     ShowHexData(tag, (uint16)(indent + 2), x->size, x->data);
251 #endif
252 }
253 
254 // =========================================================
255 // ShowPERBitString()
256 //
257 // This function displays a BITSTRING object via calls
258 // to Show245().
259 // =========================================================
ShowPERBitString(uint16 tag,uint16 indent,const char * label,PS_BITSTRING x)260 void ShowPERBitString(uint16 tag, uint16 indent, const char *label, PS_BITSTRING x)
261 {
262     OSCL_UNUSED_ARG(tag);
263     OSCL_UNUSED_ARG(indent);
264     OSCL_UNUSED_ARG(label);
265     OSCL_UNUSED_ARG(x);
266 #ifdef PVANALYZER  //07/12/01wjj
267     uint8 outString[100];
268 
269     sprintf(outString, "%s is a BIT STRING (SIZE = %hu)",
270             label, x->size);
271     Show245(tag, indent, outString);
272     ShowHexData(tag, (uint16)(indent + 2), (uint16)(x->size / 8), x->data);
273 #endif
274 }
275 
276 // =========================================================
277 // ShowPERCharString()
278 //
279 // This function displays a int8STRING object via calls
280 // to Show245().
281 // =========================================================
ShowPERCharString(uint16 tag,uint16 indent,const char * label,PS_int8STRING x)282 void ShowPERCharString(uint16 tag, uint16 indent, const char* label, PS_int8STRING x)
283 {
284     OSCL_UNUSED_ARG(tag);
285     OSCL_UNUSED_ARG(indent);
286     OSCL_UNUSED_ARG(label);
287     OSCL_UNUSED_ARG(x);
288 #ifdef PVANALYZER  //07/12/01wjj
289     uint8 outString[100];
290     uint8 displayType = 1;  /* Select output type -- See Below */
291 
292     sprintf(outString, "%s is a int8 STRING (SIZE = %hu)",
293             label, x->size);
294     Show245(tag, indent, outString);
295 
296     if (displayType == 0)
297     {
298         /* Show Hex Version of string data */
299         ShowHexData(tag, (uint16)(indent + 2), x->size, x->data);
300     }
301     else
302     {
303         /* Show Printable character version */
304         sprintf(outString, "stringdata = \"%s\"", x->data);
305         Show245(tag, (uint16)(indent + 2), outString);
306     }
307 #endif
308 }
309 
310 // =========================================================
311 // ShowPERObjectID()
312 //
313 // This function displays an OBJECT IDENTIFIER via calls
314 // to Show245().
315 // =========================================================
ShowPERObjectID(uint16 tag,uint16 indent,const char * label,PS_OBJECTIDENT x)316 void ShowPERObjectID(uint16 tag, uint16 indent, const char* label, PS_OBJECTIDENT x)
317 {
318     OSCL_UNUSED_ARG(tag);
319     OSCL_UNUSED_ARG(indent);
320     OSCL_UNUSED_ARG(label);
321     OSCL_UNUSED_ARG(x);
322 #ifdef PVANALYZER  //07/12/01wjj
323     uint8 outString[100];
324 
325     sprintf(outString, "%s is an OBJECT IDENTIFIER (SIZE = %hu)",
326             label, x->size);
327     Show245(tag, indent, outString);
328     ShowHexData(tag, (uint16)(indent + 2), x->size, x->data);
329 #endif
330 }
331 
332 /* --------------------------------------------- */
333 /* ---------- HIGHER LEVEL OBJECTS ------------- */
334 /* --------------------------------------------- */
335 
336 // =========================================================
337 // ShowPERChoice()
338 //
339 // This function displays the identity of a toplevel
340 // CHOICE definition.
341 // =========================================================
ShowPERChoice(uint16 tag,uint16 indent,const char * label,const char * typestring)342 void ShowPERChoice(uint16 tag, uint16 indent, const char *label, const char *typestring)
343 {
344     OSCL_UNUSED_ARG(tag);
345     OSCL_UNUSED_ARG(indent);
346     OSCL_UNUSED_ARG(label);
347     OSCL_UNUSED_ARG(typestring);
348 #ifdef PVANALYZER  //07/12/01wjj
349     uint8 outString[100];
350 
351     sprintf(outString, "%s = %s (CHOICE)", label, typestring);
352     Show245(tag, indent, outString);
353 #endif
354 }
355 
356 // =========================================================
357 // ShowPERSequence()
358 //
359 // This function displays the identity of a toplevel
360 // SEQUENCE definition.
361 // =========================================================
ShowPERSequence(uint16 tag,uint16 indent,const char * label,const char * typestring)362 void ShowPERSequence(uint16 tag, uint16 indent, const char* label, const char* typestring)
363 {
364     OSCL_UNUSED_ARG(tag);
365     OSCL_UNUSED_ARG(indent);
366     OSCL_UNUSED_ARG(label);
367     OSCL_UNUSED_ARG(typestring);
368 #ifdef PVANALYZER  //07/12/01wjj
369     uint8 outString[100];
370 
371     sprintf(outString, "%s = %s (SEQUENCE)", label, typestring);
372     Show245(tag, indent, outString);
373 #endif
374 }
375 
376 // =========================================================
377 // ShowPERSequenceof()
378 //
379 // This function displays the identity of a toplevel
380 // SEQUENCE OF definition.
381 // =========================================================
ShowPERSequenceof(uint16 tag,uint16 indent,const char * label,const char * typestring)382 void ShowPERSequenceof(uint16 tag, uint16 indent, const char* label, const char* typestring)
383 {
384     OSCL_UNUSED_ARG(tag);
385     OSCL_UNUSED_ARG(indent);
386     OSCL_UNUSED_ARG(label);
387     OSCL_UNUSED_ARG(typestring);
388 #ifdef PVANALYZER  //07/12/01wjj
389     uint8 outString[100];
390 
391     sprintf(outString, "%s = %s (SEQUENCE-OF)", label, typestring);
392     Show245(tag, indent, outString);
393 #endif
394 }
395 
396 // =========================================================
397 // ShowPERSetof()
398 //
399 // This function displays the identity of a toplevel
400 // SET OF definition.
401 // =========================================================
ShowPERSetof(uint16 tag,uint16 indent,const char * label,const char * typestring)402 void ShowPERSetof(uint16 tag, uint16 indent, const char* label, const char* typestring)
403 {
404     OSCL_UNUSED_ARG(tag);
405     OSCL_UNUSED_ARG(indent);
406     OSCL_UNUSED_ARG(label);
407     OSCL_UNUSED_ARG(typestring);
408 #ifdef PVANALYZER  //07/12/01wjj
409     uint8 outString[100];
410 
411     sprintf(outString, "%s = %s (SET-OF)", label, typestring);
412     Show245(tag, indent, outString);
413 #endif
414 }
415 
416 // =========================================================
417 // ShowPERClosure()
418 //
419 // This function displays the closure of a top level object.
420 // It should be called once with the existing (already
421 // incremented) indent level.
422 // =========================================================
ShowPERClosure(uint16 tag,uint16 indent,const char * label)423 void ShowPERClosure(uint16 tag, uint16 indent, const char* label)
424 {
425     OSCL_UNUSED_ARG(tag);
426     OSCL_UNUSED_ARG(indent);
427     OSCL_UNUSED_ARG(label);
428 #ifdef PVANALYZER  //07/12/01wjj
429     uint8 outString[100];
430 
431     if (indent >= 2)  /* Reduce indent, guarantee minimum 0 */
432     {
433         indent -= 2;
434     }
435     sprintf(outString, "(end of %s)", label);
436     Show245(tag, indent, outString);
437 #endif
438 }
439 
440 /* --------------------------------------------- */
441 /* ----------- ARRAYS OF OBJECTS --------------- */
442 /* --------------------------------------------- */
443 
444 // =========================================================
445 // ShowPERIntegers()
446 //
447 // This function displays an int32EGER object which is the
448 // ofitem of a SeqOf or SetOf.  It does so via call to
449 // ShowPERInteger(), after constructing a special label.
450 // =========================================================
ShowPERIntegers(uint16 tag,uint16 indent,const char * label,uint32 value,uint32 number)451 void ShowPERIntegers(uint16 tag, uint16 indent, const char* label, uint32 value, uint32 number)
452 {
453     OSCL_UNUSED_ARG(tag);
454     OSCL_UNUSED_ARG(indent);
455     OSCL_UNUSED_ARG(label);
456     OSCL_UNUSED_ARG(value);
457     OSCL_UNUSED_ARG(number);
458 #ifdef PVANALYZER  //07/12/01wjj
459     uint8 outString[100];
460 
461     sprintf(outString, "%s[%u]", label, number);
462     ShowPERInteger(tag, indent, outString, value);
463 #endif
464 }
465 
466 // =========================================================
467 // ShowPEROctetStrings()
468 //
469 // This function displays an OCTET STRING which is the
470 // ofitem of a SeqOf or SetOf.  It does so via call to
471 // ShowPEROctetString(), after constructing a special label.
472 // =========================================================
ShowPEROctetStrings(uint16 tag,uint16 indent,const char * label,PS_OCTETSTRING x,uint32 number)473 void ShowPEROctetStrings(uint16 tag, uint16 indent, const char* label, PS_OCTETSTRING x, uint32 number)
474 {
475     OSCL_UNUSED_ARG(tag);
476     OSCL_UNUSED_ARG(indent);
477     OSCL_UNUSED_ARG(label);
478     OSCL_UNUSED_ARG(x);
479     OSCL_UNUSED_ARG(number);
480 #ifdef PVANALYZER  //07/12/01wjj
481     uint8 outString[100];
482 
483     sprintf(outString, "%s[%u]", label, number);
484     ShowPEROctetString(tag, indent, outString, x);
485 #endif
486 }
487 
488 // -----------------------------------------------------------
489 // Dummy PVAnalyzer() Function
490 // --> This may be added to provide the analyzer function if
491 //       PVAnalyzer() is not provided at the application layer.
492 //       However, the app layer is really where the analyzer
493 //       should reside.
494 // --> Note: This requires <stdio.h> and <time.h> to be included.
495 // -----------------------------------------------------------
496 //#ifdef PVANALYZER
497 //void PVAnalyzer( uint32 tag, Tint8 *pPerDataIn,...)
498 //{
499 //  FILE    *pFile;
500 //  uint8 *pFileName ="h245per.txt";
501 //  uint8 pTimeBuf[32];
502 //  uint8 *tagString;
503 //
504 //  pFile = fopen( pFileName, "a+");
505 //  if( pFile != NULL )
506 //  {
507 //    _tzset();
508 //    _strtime( pTimeBuf );
509 //
510 //    if(tag==2)
511 //        tagString="PerEnc";
512 //    else if(tag==4)
513 //        tagString="PerEnx";
514 //    else if(tag==8)
515 //        tagString="PerDec";
516 //    else if(tag==16)
517 //        tagString="PerDe";
518 //    else if(tag==32)
519 //        tagString="  Se  ";
520 //    else if(tag==64)
521 //        tagString="  Tsc ";
522 //
523 //    fprintf( pFile, "<%s> <%s> %s\n", pTimeBuf, tagString, pPerDataIn );
524 //    fclose(pFile);
525 //  } /*end if(pFile != NULL) */
526 //}
527 //#endif
528