blob: b78c8f0204df8f764718b4c9a40f2afce411612d
1 | #include <memory.h> |
2 | #include "../include/helix_types.h" |
3 | #include "../include/helix_result.h" |
4 | #include "../include/ra_depack.h" |
5 | #include "ra_depack_internal.h" |
6 | #include "../include/rm_memory_default.h" |
7 | #include "../include/rm_error_default.h" |
8 | #include "../include/memory_utils.h" |
9 | #include "../include/stream_hdr_utils.h" |
10 | |
11 | ra_depack* ra_depack_create(void* pAvail, |
12 | ra_block_avail_func_ptr fpAvail, |
13 | void* pUserError, |
14 | rm_error_func_ptr fpError) |
15 | { |
16 | return ra_depack_create2(pAvail, |
17 | fpAvail, |
18 | pUserError, |
19 | fpError, |
20 | HXNULL, |
21 | rm_memory_default_malloc, |
22 | rm_memory_default_free); |
23 | } |
24 | |
25 | ra_depack* ra_depack_create2(void* pAvail, |
26 | ra_block_avail_func_ptr fpAvail, |
27 | void* pUserError, |
28 | rm_error_func_ptr fpError, |
29 | void* pUserMem, |
30 | rm_malloc_func_ptr fpMalloc, |
31 | rm_free_func_ptr fpFree) |
32 | { |
33 | ra_depack* pRet = HXNULL; |
34 | |
35 | if (fpAvail && fpMalloc && fpFree) { |
36 | /* Allocate space for the ra_depack_internal struct |
37 | * by using the passed-in malloc function |
38 | */ |
39 | ra_depack_internal* pInt = |
40 | (ra_depack_internal*) fpMalloc(pUserMem, sizeof(ra_depack_internal)); |
41 | if (pInt) { |
42 | /* Zero out the struct */ |
43 | memset((void*) pInt, 0, sizeof(ra_depack_internal)); |
44 | /* Assign the frame callback members */ |
45 | pInt->pAvail = pAvail; |
46 | pInt->fpAvail = fpAvail; |
47 | /* |
48 | * Assign the error members. If the caller did not |
49 | * provide an error callback, then use the default |
50 | * rm_error_default(). |
51 | */ |
52 | if (fpError) { |
53 | pInt->fpError = fpError; |
54 | pInt->pUserError = pUserError; |
55 | } else { |
56 | pInt->fpError = rm_error_default; |
57 | pInt->pUserError = HXNULL; |
58 | } |
59 | /* Assign the memory functions */ |
60 | pInt->fpMalloc = fpMalloc; |
61 | pInt->fpFree = fpFree; |
62 | pInt->pUserMem = pUserMem; |
63 | /* Assign the return value */ |
64 | pRet = (ra_depack*) pInt; |
65 | } |
66 | } |
67 | |
68 | return pRet; |
69 | } |
70 | |
71 | HX_RESULT ra_depack_init(ra_depack* pDepack, rm_stream_header* header) |
72 | { |
73 | HX_RESULT retVal = HXR_FAIL; |
74 | |
75 | if (pDepack && header) { |
76 | /* Get the internal struct */ |
77 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
78 | /* Call the internal init */ |
79 | retVal = ra_depacki_init(pInt, header); |
80 | } |
81 | |
82 | return retVal; |
83 | } |
84 | |
85 | UINT32 ra_depack_get_num_substreams(ra_depack* pDepack) |
86 | { |
87 | UINT32 ulRet = 0; |
88 | |
89 | if (pDepack) { |
90 | /* Get the internal struct */ |
91 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
92 | /* Return the number of substreams */ |
93 | ulRet = pInt->multiStreamHdr.ulNumSubStreams; |
94 | } |
95 | |
96 | return ulRet; |
97 | } |
98 | |
99 | UINT32 ra_depack_get_codec_4cc(ra_depack* pDepack, UINT32 ulSubStream) |
100 | { |
101 | UINT32 ulRet = 0; |
102 | |
103 | if (pDepack) { |
104 | /* Get the internal struct */ |
105 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
106 | /* Make sure the substream index is legal */ |
107 | if (pInt->pSubStreamHdr && |
108 | ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) { |
109 | ulRet = pInt->pSubStreamHdr[ulSubStream].ulCodecID; |
110 | } |
111 | } |
112 | |
113 | return ulRet; |
114 | } |
115 | |
116 | HX_RESULT ra_depack_get_codec_init_info(ra_depack* pDepack, |
117 | UINT32 ulSubStream, |
118 | ra_format_info** ppInfo) |
119 | { |
120 | HX_RESULT retVal = HXR_FAIL; |
121 | |
122 | if (pDepack && ppInfo) { |
123 | /* Init local variables */ |
124 | UINT32 ulSize = sizeof(ra_format_info); |
125 | ra_format_info* pInfo = HXNULL; |
126 | /* Get the internal struct */ |
127 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
128 | /* Allocate space for the struct */ |
129 | pInfo = ra_depacki_malloc(pInt, ulSize); |
130 | if (pInfo) { |
131 | /* NULL out the memory */ |
132 | memset(pInfo, 0, ulSize); |
133 | /* Fill in the init info struct */ |
134 | retVal = ra_depacki_get_format_info(pInt, ulSubStream, pInfo); |
135 | if (retVal == HXR_OK) { |
136 | /* Assign the out parameter */ |
137 | *ppInfo = pInfo; |
138 | } else { |
139 | /* We failed so free the memory we allocated */ |
140 | ra_depacki_free(pInt, pInfo); |
141 | } |
142 | } |
143 | } |
144 | |
145 | return retVal; |
146 | } |
147 | |
148 | void ra_depack_destroy_codec_init_info(ra_depack* pDepack, ra_format_info** ppInfo) |
149 | { |
150 | if (pDepack && ppInfo && *ppInfo) { |
151 | /* Get the internal struct */ |
152 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
153 | /* Clean up the format info struct */ |
154 | ra_depacki_cleanup_format_info(pInt, *ppInfo); |
155 | /* Delete the memory associated with it */ |
156 | ra_depacki_free(pInt, *ppInfo); |
157 | /* NULL the pointer out */ |
158 | *ppInfo = HXNULL; |
159 | } |
160 | } |
161 | |
162 | HX_RESULT ra_depack_add_packet(ra_depack* pDepack, rm_packet* packet) |
163 | { |
164 | HX_RESULT retVal = HXR_FAIL; |
165 | |
166 | if (pDepack && packet) { |
167 | /* Get the internal struct */ |
168 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
169 | /* Call the internal function */ |
170 | retVal = ra_depacki_add_packet(pInt, packet); |
171 | } |
172 | |
173 | return retVal; |
174 | } |
175 | |
176 | void ra_depack_destroy_block(ra_depack* pDepack, ra_block** ppBlock) |
177 | { |
178 | if (pDepack && ppBlock && *ppBlock) { |
179 | /* Get the internal struct */ |
180 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
181 | /* Free the data */ |
182 | if ((*ppBlock)->pData) { |
183 | ra_depacki_free(pInt, (*ppBlock)->pData); |
184 | (*ppBlock)->pData = HXNULL; |
185 | } |
186 | /* Free the memory itself */ |
187 | ra_depacki_free(pInt, *ppBlock); |
188 | /* Null out the pointer */ |
189 | *ppBlock = HXNULL; |
190 | } |
191 | } |
192 | |
193 | HX_RESULT ra_depack_seek(ra_depack* pDepack, UINT32 ulTime) |
194 | { |
195 | HX_RESULT retVal = HXR_FAIL; |
196 | |
197 | if (pDepack) { |
198 | /* Get the internal struct */ |
199 | ra_depack_internal* pInt = (ra_depack_internal*) pDepack; |
200 | /* Call the internal seek function */ |
201 | retVal = ra_depacki_seek(pInt, ulTime); |
202 | } |
203 | |
204 | return retVal; |
205 | } |
206 | |
207 | void ra_depack_destroy(ra_depack** ppDepack) |
208 | { |
209 | if (ppDepack) { |
210 | ra_depack_internal* pInt = (ra_depack_internal*) * ppDepack; |
211 | if (pInt && pInt->fpFree) { |
212 | /* Save a pointer to fpFree and pUserMem */ |
213 | rm_free_func_ptr fpFree = pInt->fpFree; |
214 | void* pUserMem = pInt->pUserMem; |
215 | /* Clean up multistream header */ |
216 | rm_cleanup_multistream_hdr(fpFree, pUserMem, &pInt->multiStreamHdr); |
217 | /* Clean up rule map */ |
218 | rm_cleanup_rule_map(fpFree, pUserMem, &pInt->rule2Flag); |
219 | /* Clean up the substream header array */ |
220 | ra_depacki_cleanup_substream_hdr_array(pInt); |
221 | /* Null everything out */ |
222 | memset(pInt, 0, sizeof(ra_depack_internal)); |
223 | /* Free the rm_parser_internal struct memory */ |
224 | fpFree(pUserMem, pInt); |
225 | /* NULL out the pointer */ |
226 | *ppDepack = HXNULL; |
227 | } |
228 | } |
229 | } |
230 | |
231 |