blob: 00a4374e204bef886dc65f2c54bfabe5bf4d9a6d
1 | /* ***** BEGIN LICENSE BLOCK ***** |
2 | * Source last modified: $Id: rv_depack.c,v 1.1.1.1.2.1 2005/05/04 18:21:20 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 "../include/helix_types.h" |
40 | #include "../include/helix_result.h" |
41 | #include "../include/rv_depack.h" |
42 | #include "rv_depack_internal.h" |
43 | #include "../include/rm_memory_default.h" |
44 | #include "../include/rm_error_default.h" |
45 | #include "../include/memory_utils.h" |
46 | |
47 | rv_depack* rv_depack_create(void* pAvail, |
48 | rv_frame_avail_func_ptr fpAvail, |
49 | void* pUserError, |
50 | rm_error_func_ptr fpError) |
51 | { |
52 | return rv_depack_create2(pAvail, |
53 | fpAvail, |
54 | pUserError, |
55 | fpError, |
56 | HXNULL, |
57 | rm_memory_default_malloc, |
58 | rm_memory_default_free); |
59 | } |
60 | |
61 | rv_depack* rv_depack_create2(void* pAvail, |
62 | rv_frame_avail_func_ptr fpAvail, |
63 | void* pUserError, |
64 | rm_error_func_ptr fpError, |
65 | void* pUserMem, |
66 | rm_malloc_func_ptr fpMalloc, |
67 | rm_free_func_ptr fpFree) |
68 | { |
69 | rv_depack* pRet = HXNULL; |
70 | |
71 | if (fpAvail && fpMalloc && fpFree) { |
72 | /* Allocate space for the rv_depack_internal struct |
73 | * by using the passed-in malloc function |
74 | */ |
75 | rv_depack_internal* pInt = |
76 | (rv_depack_internal*) fpMalloc(pUserMem, sizeof(rv_depack_internal)); |
77 | if (pInt) { |
78 | /* Zero out the struct */ |
79 | memset((void*) pInt, 0, sizeof(rv_depack_internal)); |
80 | /* Assign the frame callback members */ |
81 | pInt->pAvail = pAvail; |
82 | pInt->fpAvail = fpAvail; |
83 | /* |
84 | * Assign the error members. If the caller did not |
85 | * provide an error callback, then use the default |
86 | * rm_error_default(). |
87 | */ |
88 | if (fpError) { |
89 | pInt->fpError = fpError; |
90 | pInt->pUserError = pUserError; |
91 | } else { |
92 | pInt->fpError = rm_error_default; |
93 | pInt->pUserError = HXNULL; |
94 | } |
95 | /* Assign the memory functions */ |
96 | pInt->fpMalloc = fpMalloc; |
97 | pInt->fpFree = fpFree; |
98 | pInt->pUserMem = pUserMem; |
99 | /* Assign the return value */ |
100 | pRet = (rv_depack*) pInt; |
101 | } |
102 | } |
103 | |
104 | return pRet; |
105 | } |
106 | |
107 | HX_RESULT rv_depack_init(rv_depack* pDepack, rm_stream_header* header) |
108 | { |
109 | HX_RESULT retVal = HXR_FAIL; |
110 | |
111 | if (pDepack && header) { |
112 | /* Get the internal struct */ |
113 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
114 | /* Call the internal init */ |
115 | retVal = rv_depacki_init(pInt, header); |
116 | } |
117 | |
118 | return retVal; |
119 | } |
120 | |
121 | UINT32 rv_depack_get_num_substreams(rv_depack* pDepack) |
122 | { |
123 | UINT32 ulRet = 0; |
124 | |
125 | if (pDepack) { |
126 | /* Get the internal struct */ |
127 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
128 | /* Return the number of substreams */ |
129 | ulRet = pInt->multiStreamHdr.ulNumSubStreams; |
130 | } |
131 | |
132 | return ulRet; |
133 | } |
134 | |
135 | UINT32 rv_depack_get_codec_4cc(rv_depack* pDepack) |
136 | { |
137 | UINT32 ulRet = 0; |
138 | |
139 | if (pDepack) { |
140 | /* Get the internal struct */ |
141 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
142 | if (pInt->pSubStreamHdr && |
143 | pInt->ulActiveSubStream < pInt->multiStreamHdr.ulNumSubStreams) { |
144 | /* Copy the subMOF tag */ |
145 | ulRet = pInt->pSubStreamHdr[pInt->ulActiveSubStream].ulSubMOFTag; |
146 | } |
147 | } |
148 | |
149 | return ulRet; |
150 | } |
151 | |
152 | HX_RESULT rv_depack_get_codec_init_info(rv_depack* pDepack, rv_format_info** ppInfo) |
153 | { |
154 | HX_RESULT retVal = HXR_FAIL; |
155 | |
156 | if (pDepack && ppInfo) { |
157 | /* Get the internal struct */ |
158 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
159 | if (pInt->pSubStreamHdr && |
160 | pInt->ulActiveSubStream < pInt->multiStreamHdr.ulNumSubStreams) { |
161 | /* Clean up any existing format info */ |
162 | rv_depacki_cleanup_format_info(pInt, *ppInfo); |
163 | /* Allocate memory for the format info */ |
164 | *ppInfo = rv_depacki_malloc(pInt, sizeof(rv_format_info)); |
165 | if (*ppInfo) { |
166 | /* NULL out the memory */ |
167 | memset(*ppInfo, 0, sizeof(rv_format_info)); |
168 | /* Make a deep copy of the format info */ |
169 | retVal = rv_depacki_copy_format_info(pInt, |
170 | &pInt->pSubStreamHdr[pInt->ulActiveSubStream], |
171 | *ppInfo); |
172 | } |
173 | } |
174 | } |
175 | |
176 | return retVal; |
177 | } |
178 | |
179 | void rv_depack_destroy_codec_init_info(rv_depack* pDepack, rv_format_info** ppInfo) |
180 | { |
181 | if (pDepack && ppInfo && *ppInfo) { |
182 | /* Get the internal struct */ |
183 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
184 | /* Clean up the format info's internal allocs */ |
185 | rv_depacki_cleanup_format_info(pInt, *ppInfo); |
186 | /* NULL it out */ |
187 | memset(*ppInfo, 0, sizeof(rv_format_info)); |
188 | /* Delete the memory associated with it */ |
189 | rv_depacki_free(pInt, *ppInfo); |
190 | /* NULL the pointer out */ |
191 | *ppInfo = HXNULL; |
192 | } |
193 | } |
194 | |
195 | HX_RESULT rv_depack_add_packet(rv_depack* pDepack, rm_packet* packet) |
196 | { |
197 | HX_RESULT retVal = HXR_FAIL; |
198 | |
199 | if (pDepack && packet) { |
200 | /* Get the internal struct */ |
201 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
202 | /* Call the internal function */ |
203 | retVal = rv_depacki_add_packet(pInt, packet); |
204 | } |
205 | |
206 | return retVal; |
207 | } |
208 | |
209 | void rv_depack_destroy_frame(rv_depack* pDepack, rv_frame** ppFrame) |
210 | { |
211 | if (pDepack && ppFrame && *ppFrame) { |
212 | /* Get the internal struct */ |
213 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
214 | /* Call the internal function */ |
215 | rv_depacki_cleanup_frame(pInt, ppFrame); |
216 | } |
217 | } |
218 | |
219 | HX_RESULT rv_depack_seek(rv_depack* pDepack, UINT32 ulTime) |
220 | { |
221 | HX_RESULT retVal = HXR_FAIL; |
222 | |
223 | if (pDepack) { |
224 | /* Get the internal struct */ |
225 | rv_depack_internal* pInt = (rv_depack_internal*) pDepack; |
226 | /* Call the internal function */ |
227 | retVal = rv_depacki_seek(pInt, ulTime); |
228 | } |
229 | |
230 | return retVal; |
231 | } |
232 | |
233 | void rv_depack_destroy(rv_depack** ppDepack) |
234 | { |
235 | if (ppDepack) { |
236 | rv_depack_internal* pInt = (rv_depack_internal*) * ppDepack; |
237 | if (pInt && pInt->fpFree) { |
238 | /* Save a pointer to fpFree and pUserMem */ |
239 | rm_free_func_ptr fpFree = pInt->fpFree; |
240 | void* pUserMem = pInt->pUserMem; |
241 | /* Clean up the rule to flag map */ |
242 | if (pInt->rule2Flag.pulMap) { |
243 | rv_depacki_free(pInt, pInt->rule2Flag.pulMap); |
244 | pInt->rule2Flag.pulMap = HXNULL; |
245 | pInt->rule2Flag.ulNumRules = 0; |
246 | } |
247 | /* Clean up the rule to header map */ |
248 | if (pInt->multiStreamHdr.rule2SubStream.pulMap) { |
249 | rv_depacki_free(pInt, pInt->multiStreamHdr.rule2SubStream.pulMap); |
250 | pInt->multiStreamHdr.rule2SubStream.pulMap = HXNULL; |
251 | pInt->multiStreamHdr.rule2SubStream.ulNumRules = 0; |
252 | } |
253 | /* Clean up the format info array */ |
254 | rv_depacki_cleanup_format_info_array(pInt); |
255 | /* Clean up ignore header array */ |
256 | if (pInt->bIgnoreSubStream) { |
257 | rv_depacki_free(pInt, pInt->bIgnoreSubStream); |
258 | pInt->bIgnoreSubStream = HXNULL; |
259 | } |
260 | /* Clean up any current frame */ |
261 | rv_depacki_cleanup_frame(pInt, &pInt->pCurFrame); |
262 | /* Null everything out */ |
263 | memset(pInt, 0, sizeof(rv_depack_internal)); |
264 | /* Free the rm_parser_internal struct memory */ |
265 | fpFree(pUserMem, pInt); |
266 | /* NULL out the pointer */ |
267 | *ppDepack = HXNULL; |
268 | } |
269 | } |
270 | } |
271 | |
272 |