summaryrefslogtreecommitdiff
path: root/audio_codec/libcook/stream_hdr_utils.c (plain)
blob: 386e0437ddc2a0e976afea5079b02ebd01d69835
1/* ***** BEGIN LICENSE BLOCK *****
2 * Source last modified: $Id: stream_hdr_utils.c,v 1.1.1.1.2.1 2005/05/04 18:21:24 hubbe Exp $
3 *
4 * REALNETWORKS CONFIDENTIAL--NOT FOR DISTRIBUTION IN SOURCE CODE FORM
5 * Portions Copyright (c) 1995-2005 RealNetworks, Inc.
6 * All Rights Reserved.
7 *
8 * The contents of this file, and the files included with this file,
9 * are subject to the current version of the Real Format Source Code
10 * Porting and Optimization License, available at
11 * https://helixcommunity.org/2005/license/realformatsource (unless
12 * RealNetworks otherwise expressly agrees in writing that you are
13 * subject to a different license). You may also obtain the license
14 * terms directly from RealNetworks. You may not use this file except
15 * in compliance with the Real Format Source Code Porting and
16 * Optimization License. There are no redistribution rights for the
17 * source code of this file. Please see the Real Format Source Code
18 * Porting and Optimization License for the rights, obligations and
19 * limitations governing use of the contents of the file.
20 *
21 * RealNetworks is the developer of the Original Code and owns the
22 * copyrights in the portions it created.
23 *
24 * This file, and the files included with this file, is distributed and
25 * made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND,
26 * EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL
27 * SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT
29 * OR NON-INFRINGEMENT.
30 *
31 * Technology Compatibility Kit Test Suite(s) Location:
32 * https://rarvcode-tck.helixcommunity.org
33 *
34 * Contributor(s):
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#include <memory.h>
39#include "helix_types.h"
40#include "helix_result.h"
41#include "rm_memory.h"
42#include "pack_utils.h"
43#include "memory_utils.h"
44#include "stream_hdr_structs.h"
45#include "stream_hdr_utils.h"
46
47HX_RESULT rm_unpack_rule_map(BYTE** ppBuf,
48 UINT32* pulLen,
49 rm_malloc_func_ptr fpMalloc,
50 rm_free_func_ptr fpFree,
51 void* pUserMem,
52 rm_rule_map* pMap)
53{
54 HX_RESULT retVal = HXR_FAIL;
55
56 if (ppBuf && pulLen && fpMalloc && fpFree && pMap &&
57 *ppBuf && *pulLen >= 2) {
58 /* Initialize local variables */
59 UINT32 ulSize = 0;
60 UINT32 i = 0;
61 /* Clean up any existing rule to flag map */
62 rm_cleanup_rule_map(fpFree, pUserMem, pMap);
63 /* Unpack the number of rules */
64 pMap->ulNumRules = rm_unpack16(ppBuf, pulLen);
65 if (pMap->ulNumRules && *pulLen >= pMap->ulNumRules * 2) {
66 /* Allocate the map array */
67 ulSize = pMap->ulNumRules * sizeof(UINT32);
68 pMap->pulMap = (UINT32*) fpMalloc(pUserMem, ulSize);
69 if (pMap->pulMap) {
70 /* Zero out the memory */
71 memset(pMap->pulMap, 0, ulSize);
72 /* Unpack each of the flags */
73 for (i = 0; i < pMap->ulNumRules; i++) {
74 pMap->pulMap[i] = rm_unpack16(ppBuf, pulLen);
75 }
76 /* Clear the return value */
77 retVal = HXR_OK;
78 }
79 } else {
80 /* No rules - not an error */
81 retVal = HXR_OK;
82 }
83 }
84
85 return retVal;
86}
87
88void rm_cleanup_rule_map(rm_free_func_ptr fpFree,
89 void* pUserMem,
90 rm_rule_map* pMap)
91{
92 if (fpFree && pMap && pMap->pulMap) {
93 fpFree(pUserMem, pMap->pulMap);
94 pMap->pulMap = HXNULL;
95 pMap->ulNumRules = 0;
96 }
97}
98
99HX_RESULT rm_unpack_multistream_hdr(BYTE** ppBuf,
100 UINT32* pulLen,
101 rm_malloc_func_ptr fpMalloc,
102 rm_free_func_ptr fpFree,
103 void* pUserMem,
104 rm_multistream_hdr* hdr)
105{
106 HX_RESULT retVal = HXR_FAIL;
107
108 if (ppBuf && pulLen && fpMalloc && fpFree && hdr &&
109 *ppBuf && *pulLen >= 4) {
110 /* Unpack the multistream members */
111 hdr->ulID = rm_unpack32(ppBuf, pulLen);
112 /* Unpack the rule to substream map */
113 retVal = rm_unpack_rule_map(ppBuf, pulLen,
114 fpMalloc, fpFree, pUserMem,
115 &hdr->rule2SubStream);
116 if (retVal == HXR_OK) {
117 if (*pulLen >= 2) {
118 /* Unpack the number of substreams */
119 hdr->ulNumSubStreams = rm_unpack16(ppBuf, pulLen);
120 } else {
121 retVal = HXR_FAIL;
122 }
123 }
124 }
125
126 return retVal;
127}
128
129void rm_cleanup_multistream_hdr(rm_free_func_ptr fpFree,
130 void* pUserMem,
131 rm_multistream_hdr* hdr)
132{
133 if (hdr) {
134 rm_cleanup_rule_map(fpFree, pUserMem, &hdr->rule2SubStream);
135 }
136}
137