blob: 49d18aee276028873db5fe3b8ec090da0806f4aa
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <limits.h> |
4 | #include <unistd.h> |
5 | #include <fcntl.h> |
6 | #include <sys/types.h> |
7 | //#include <cutils/properties.h> |
8 | |
9 | #include "cook_codec.h" |
10 | //#include <asm/cache.h> |
11 | |
12 | #ifndef __MW__ |
13 | #include <inttypes.h> |
14 | #else |
15 | #include <core/types.h> |
16 | #endif |
17 | #include "cook_decode.h" |
18 | #include "rm_parse.h" |
19 | #include "ra_depack.h" |
20 | #include "ra_decode.h" |
21 | |
22 | |
23 | |
24 | /********arm decoder header file **********/ |
25 | |
26 | #include "../../amadec/adec-armdec-mgt.h" |
27 | |
28 | #include <android/log.h> |
29 | |
30 | #define LOG_TAG "CookDecoder" |
31 | #define libcook_print(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) |
32 | |
33 | #define DefaultReadSize 32*1024 |
34 | #define DefaultOutBufSize 370*1024 |
35 | |
36 | |
37 | typedef struct { |
38 | rm_parser* pParser; |
39 | ra_depack* pDepack; |
40 | ra_decode* pDecode; |
41 | ra_format_info* pRaInfo; |
42 | rm_packet* pPacket; |
43 | ra_block* pBlock; |
44 | rm_stream_header* pHdr; |
45 | UINT32 usStreamNum; |
46 | } rm_info_t; |
47 | |
48 | typedef struct { |
49 | BYTE *buf; |
50 | int buf_len; |
51 | int buf_max; |
52 | int cousume; |
53 | int all_consume; |
54 | } cook_IObuf; |
55 | |
56 | struct frame_info { |
57 | int len; |
58 | unsigned long offset;/*steam start to here*/ |
59 | unsigned long buffered_len;/*data buffer in dsp,pcm datalen*/ |
60 | int reversed[1];/*for cache aligned 32 bytes*/ |
61 | }; |
62 | |
63 | static cook_IObuf cook_input; |
64 | static cook_IObuf cook_output; |
65 | |
66 | struct frame_info cur_frame; |
67 | static ra_decoder_info_t ra_dec_info ; |
68 | static rm_info_t ra_info ; |
69 | static char file_header[AUDIO_EXTRA_DATA_SIZE]; |
70 | #pragma align_to(64,file_header) |
71 | static char *cur_read_ptr = file_header; |
72 | static int reset = 0; |
73 | static void setsysfs(char * path, char * value) |
74 | { |
75 | int fd = -1; |
76 | fd = open(path, O_RDWR); |
77 | if (fd >= 0) { |
78 | write(fd, value, 2); |
79 | close(fd); |
80 | fd = -1; |
81 | } else { |
82 | libcook_print("setsysfs: open file failed.\n"); |
83 | } |
84 | } |
85 | |
86 | static void rm_error(void* pError, HX_RESULT result, const char* pszMsg) |
87 | { |
88 | //dsp_mailbox_send(1,M1B_IRQ7_DECODE_FATAL_ERR, 1, NULL, 0); |
89 | //trans_err_code(DECODE_FATAL_ERR); |
90 | //property_set("media.amplayer.noaudio", "1"); |
91 | setsysfs("/sys/class/audiodsp/codec_fatal_err", "2"); //Fatal error |
92 | libcook_print("rm_error pError=0x%08x result=0x%08x msg=%s\n", pError, result, pszMsg); |
93 | //while(1); |
94 | } |
95 | |
96 | //static int cook_decode_frame(unsigned char *buf, int maxlen, struct frame_fmt *fmt) |
97 | int audio_dec_decode(audio_decoder_operations_t *adec_ops, char *outbuf, int *outlen, char *inbuf, int inlen) |
98 | { |
99 | //libcook_print("audio_dec_decode, inlen = %d, cook_input.buf_len = %d\n", inlen, cook_input.buf_len); |
100 | HX_RESULT retVal = HXR_OK; |
101 | UINT32 ulBytesConsumed = 0; |
102 | UINT32 ulTotalConsumed = 0; |
103 | UINT32 ulBytesLeft = 0; |
104 | UINT32 ulNumSamplesOut = 0; |
105 | UINT32 ulMaxSamples = 0; |
106 | UINT32 out_data_len = 0; |
107 | |
108 | //ra_dec_info.input_buf = buf; |
109 | //ra_dec_info.input_buffer_size = maxlen; |
110 | if (inlen > 0) { |
111 | int len = inlen - cook_input.buf_len; |
112 | int read_len; |
113 | read_len = (inlen > cook_input.buf_max) ? cook_input.buf_max : inlen; |
114 | if (len > 0) { |
115 | memcpy(cook_input.buf + cook_input.buf_len, |
116 | inbuf + cook_input.buf_len, read_len - cook_input.buf_len); |
117 | cook_input.buf_len += read_len - cook_input.buf_len; |
118 | } |
119 | } |
120 | //libcook_print("audio_dec_decoder cook_input.buf_len = %d\n", cook_input.buf_len); |
121 | while (cook_output.buf_len <= 0) { |
122 | retVal = rm_parser_get_packet(ra_info.pParser, &ra_info.pPacket); |
123 | if (retVal == HXR_OK) { |
124 | //if (ra_info.pPacket->usStream == ra_info.usStreamNum) |
125 | { |
126 | retVal = ra_depack_add_packet(ra_info.pDepack, ra_info.pPacket); |
127 | |
128 | } |
129 | rm_parser_destroy_packet(ra_info.pParser, &ra_info.pPacket); |
130 | } |
131 | if (retVal != HXR_OK) { |
132 | libcook_print("cook_decode_frame£º add packet failed\n"); |
133 | break; |
134 | } |
135 | if (cook_input.buf_len <= 2048) { |
136 | break; |
137 | } |
138 | } |
139 | |
140 | *outlen = 0; |
141 | if (cook_output.buf_len > 0) { |
142 | memcpy(outbuf, cook_output.buf, cook_output.buf_len); |
143 | (*outlen) = cook_output.buf_len; |
144 | cook_output.buf_len = 0; |
145 | } |
146 | |
147 | int ret = 0; |
148 | //ret = ra_dec_info.decoded_size + cook_input.cousume; |
149 | ret = cook_input.cousume; |
150 | //libcook_print("ret decoder = %d\n", ret); |
151 | cook_input.cousume = 0; |
152 | adec_ops->pts = cur_frame.offset; |
153 | cur_frame.offset = 0; |
154 | return ret; |
155 | } |
156 | static UINT32 rm_io_read(void* pUserRead, BYTE* pBuf, UINT32 ulBytesToRead) |
157 | { |
158 | //memcpy(pBuf,cur_read_ptr,ulBytesToRead); |
159 | cur_read_ptr = cur_read_ptr + ulBytesToRead; |
160 | if ((unsigned)(cur_read_ptr - file_header) > AUDIO_EXTRA_DATA_SIZE) { |
161 | //trans_err_code(DECODE_INIT_ERR); |
162 | //property_set("media.amplayer.noaudio", "1"); |
163 | setsysfs("/sys/class/audiodsp/codec_fatal_err", "2"); //init err |
164 | libcook_print("warning :: cook.read byte exceed the the buffer then sent,%d \n", (unsigned)(cur_read_ptr - file_header)); |
165 | //while(1); |
166 | cur_read_ptr -= ulBytesToRead; |
167 | return 0; |
168 | |
169 | } |
170 | cur_read_ptr -= ulBytesToRead; |
171 | memcpy(pBuf, cur_read_ptr, ulBytesToRead); |
172 | cur_read_ptr = cur_read_ptr + ulBytesToRead; |
173 | return ulBytesToRead; |
174 | |
175 | } |
176 | static void rm_io_seek(void* pUserRead, UINT32 ulOffset, UINT32 ulOrigin) |
177 | { |
178 | char * tptr = cur_read_ptr; |
179 | if (ulOrigin == HX_SEEK_ORIGIN_CUR) { |
180 | cur_read_ptr += ulOffset; |
181 | } else if (ulOrigin == HX_SEEK_ORIGIN_SET) { |
182 | cur_read_ptr = (char *)pUserRead + ulOffset; |
183 | } else if (ulOrigin == HX_SEEK_ORIGIN_END) { |
184 | cur_read_ptr = sizeof(file_header) + (char *)pUserRead - ulOffset; |
185 | } |
186 | if ((unsigned)(cur_read_ptr - file_header) > AUDIO_EXTRA_DATA_SIZE) { |
187 | //trans_err_code(DECODE_INIT_ERR); |
188 | //property_set("media.amplayer.noaudio", "1"); |
189 | setsysfs("/sys/class/audiodsp/codec_fatal_err", "2"); //init err |
190 | libcook_print("warning :: cook.seek buffer pos exceed the the buffer then sent,%d \n", (unsigned)(cur_read_ptr - file_header)); |
191 | cur_read_ptr = tptr; |
192 | //while(1); |
193 | } |
194 | |
195 | } |
196 | static unsigned rm_ab_read(void* pUserRead, BYTE* pBuf, UINT32 ulBytesToRead) |
197 | { |
198 | int ret = 0; |
199 | //libcook_print("rm_ab_read, ulBytesToRead = %d\n", ulBytesToRead); |
200 | if (pBuf && ulBytesToRead) { |
201 | //libcook_print("enter into copy data, buf_len = %d\n",cook_input.buf_len); |
202 | if (cook_input.buf_len >= ulBytesToRead) { //ret = read_buffer(pBuf,ulBytesToRead); |
203 | memcpy(pBuf, cook_input.buf, ulBytesToRead); |
204 | ret = ulBytesToRead; |
205 | cook_input.buf_len -= ret; |
206 | //libcook_print("inpoint2 = %d, cook_input.buf_len = %d\n", cook_input.buf, cook_input.buf_len); |
207 | memcpy(cook_input.buf, cook_input.buf + ret, cook_input.buf_len); |
208 | } else { |
209 | libcook_print("rm_ab_read data is not enough \n"); |
210 | } |
211 | } |
212 | cook_input.cousume += ret; |
213 | cook_input.all_consume += ret; |
214 | return ret; |
215 | } |
216 | static void rm_ab_seek(void* pUserRead, UINT32 ulOffset, UINT32 ulOrigin) |
217 | { |
218 | //libcook_print("rm_ab_seek, buf_len = %d\n",cook_input.buf_len); |
219 | int i; |
220 | if (ulOrigin == HX_SEEK_ORIGIN_CUR) { |
221 | if (ulOffset <= cook_input.buf_len) { |
222 | //memcpy(cook_input.buf, cook_input.buf + ulOffset, cook_input.buf_len - ulOffset); |
223 | cook_input.buf_len -= ulOffset; |
224 | cook_input.cousume += ulOffset; |
225 | int i; |
226 | BYTE * tmpbuf; |
227 | tmpbuf = cook_input.buf + ulOffset; |
228 | for (i = 0; i < cook_input.buf_len; i++) { |
229 | cook_input.buf[i] = tmpbuf[i]; |
230 | } |
231 | } else { |
232 | libcook_print("rm_ab_seek failed\n"); |
233 | } |
234 | #if 0 |
235 | for (i = 0; i < ulOffset; i++) { |
236 | ; //read_byte(); |
237 | } |
238 | #endif |
239 | } else if (/*ulOrigin == HX_SEEK_ORIGIN_SET*/0) { |
240 | int offbuf = ulOffset - cook_input.all_consume; |
241 | if (offbuf > 0) { |
242 | if (cook_input.buf_len > offbuf) { |
243 | memcpy(cook_input.buf, cook_input.buf + offbuf, |
244 | cook_input.buf_len - offbuf); |
245 | cook_input.buf_len -= offbuf; |
246 | cook_input.cousume += offbuf; |
247 | cook_input.all_consume += offbuf; |
248 | } else { |
249 | libcook_print("data is not enough\n"); |
250 | } |
251 | } |
252 | } |
253 | } |
254 | static HX_RESULT _ra_block_available(void* pAvail, UINT32 ulSubStream, ra_block* pBlock) |
255 | { |
256 | //libcook_print("[%s,%d] enter into _ra_block_available\n", __FUNCTION__,__LINE__); |
257 | int len = 0, wlen; |
258 | int offset = 0; |
259 | HX_RESULT retVal = HXR_OK; |
260 | UINT32 ulBytesConsumed = 0; |
261 | UINT32 ulTotalConsumed = 0; |
262 | UINT32 ulBytesLeft = 0; |
263 | UINT32 ulNumSamplesOut = 0; |
264 | UINT32 ulMaxSamples = 0; |
265 | UINT32 out_data_len = 0; |
266 | UINT32 delay_pts = 0; |
267 | //BYTE* buf = ra_dec_info.input_buf;//passed from the audio dec thread |
268 | rm_info_t* pInfo = (rm_info_t*) pAvail; |
269 | if (pAvail && pBlock && pBlock->pData && pBlock->ulDataLen) { |
270 | ulBytesLeft = pBlock->ulDataLen; |
271 | if (retVal == HXR_OK && ulBytesLeft) { |
272 | retVal = ra_decode_decode(ra_dec_info.pDecode, |
273 | pBlock->pData + ulTotalConsumed, |
274 | pBlock->ulDataLen - ulTotalConsumed, |
275 | &ulBytesConsumed, |
276 | (UINT16*)ra_dec_info.pOutBuf, |
277 | ra_dec_info.ulOutBufSize / 2, |
278 | &ulNumSamplesOut, |
279 | pBlock->ulDataFlags, |
280 | pBlock->ulTimestamp * 90 + 1); |
281 | |
282 | if (retVal == HXR_OK) { |
283 | if (ulBytesConsumed) { |
284 | ulBytesLeft -= ulBytesConsumed; |
285 | ulTotalConsumed += ulBytesConsumed; |
286 | } |
287 | if (ulNumSamplesOut) { |
288 | len += ulNumSamplesOut * 2; |
289 | } |
290 | } else if (retVal == HXR_NO_DATA) { |
291 | libcook_print("ra decode not enough data.\n"); |
292 | return 0; |
293 | } else { |
294 | libcook_print("ra decode error.\n"); |
295 | return 0; |
296 | } |
297 | } |
298 | //ra_dec_info.decoded_size = out_data_len; |
299 | ra_dec_info.decoded_size = ulBytesConsumed; |
300 | } |
301 | #if 0 |
302 | FILE * fp1 = fopen("/data/audio_out", "a+"); |
303 | if (fp1) { |
304 | int flen = fwrite((char *)ra_dec_info.pOutBuf, 1, len, fp1); |
305 | libcook_print("flen = %d---outlen=%d ", flen, len); |
306 | fclose(fp1); |
307 | } else { |
308 | libcook_print("could not open file:audio_out"); |
309 | } |
310 | #endif |
311 | cur_frame.offset = pBlock->ulTimestamp * 90 + 1; |
312 | cur_frame.buffered_len = 0; |
313 | cur_frame.len = 0; |
314 | delay_pts = (ulNumSamplesOut / ra_info.pRaInfo->usNumChannels) * 90 / (ra_info.pRaInfo->ulSampleRate / 1000); |
315 | cur_frame.offset += delay_pts; |
316 | //refresh_swap_register1(cur_frame.offset+delay_pts, len); |
317 | //dsp_mailbox_send(1,M1B_IRQ4_DECODE_FINISH_FRAME,wlen,&cur_frame,sizeof(cur_frame)); |
318 | date_trans: |
319 | //wlen = write_buffer(ra_dec_info.pOutBuf + offset, len); |
320 | memcpy(cook_output.buf + cook_output.buf_len, ra_dec_info.pOutBuf, len); |
321 | cook_output.buf_len += len; |
322 | len = 0; |
323 | #if 0 |
324 | wlen = memcpy(cook_output.buf + cook_output.buf_len, ra_dec_info.pOutBuf + offset, len); |
325 | if (wlen > 0) { |
326 | offset += wlen; |
327 | cook_output.buf_len += wlen; |
328 | len -= wlen; |
329 | } |
330 | if (len > 0) { |
331 | goto date_trans; |
332 | } |
333 | #endif |
334 | //dsp_mailbox_send(1,M1B_IRQ4_DECODE_FINISH_FRAME,wlen,&cur_frame,sizeof(cur_frame)); |
335 | return retVal; |
336 | } |
337 | //static int cook_decode_init(struct frame_fmt * fmt) |
338 | int audio_dec_init(audio_decoder_operations_t *adec_ops) |
339 | { |
340 | HX_RESULT retVal = HXR_OK; |
341 | unsigned ulNumStreams = 0; |
342 | rm_parser* pParser = HXNULL; |
343 | rm_stream_header *pHdr = HXNULL; |
344 | ra_depack *pRADpack = HXNULL; |
345 | ra_format_info *pRAInfo = HXNULL; |
346 | unsigned ulCodec4CC = 0; |
347 | int i; |
348 | struct audio_info real_data; |
349 | //libcook_print("\n\n[%s]BuildDate--%s BuildTime--%s", __FUNCTION__, __DATE__, __TIME__); |
350 | real_data.bitrate = adec_ops->bps; |
351 | real_data.channels = adec_ops->channels; |
352 | real_data.extradata_size = adec_ops->extradata_size; |
353 | real_data.sample_rate = adec_ops->samplerate; |
354 | |
355 | adec_ops->nInBufSize = DefaultReadSize; |
356 | adec_ops->nOutBufSize = DefaultOutBufSize; |
357 | |
358 | memset(real_data.extradata, 0, AUDIO_EXTRA_DATA_SIZE); |
359 | libcook_print("%d,%d\n", real_data.extradata_size, adec_ops->extradata_size); |
360 | for (i = 0; i < real_data.extradata_size; i++) { |
361 | real_data.extradata[i] = adec_ops->extradata[i]; |
362 | } |
363 | |
364 | |
365 | libcook_print("cook audioinfo four data [0x%x], [0x%x],[0x%x],[0x%x],[0x%x],[0x%x],[0x%x],[0x%x],\n", real_data.extradata[0], \ |
366 | real_data.extradata[1], real_data.extradata[2], real_data.extradata[3], \ |
367 | real_data.extradata[4], real_data.extradata[5], real_data.extradata[6], real_data.extradata[7]); |
368 | |
369 | memcpy(file_header, real_data.extradata, AUDIO_EXTRA_DATA_SIZE); |
370 | cur_frame.offset = 0; |
371 | if (cook_input.buf == NULL) { |
372 | cook_input.buf = (BYTE *)malloc(DefaultReadSize * sizeof(BYTE)); |
373 | if (cook_input.buf != NULL) { |
374 | memset(cook_input.buf, 0, DefaultReadSize); |
375 | cook_input.buf_len = 0; |
376 | cook_input.buf_max = DefaultReadSize; |
377 | cook_input.cousume = 0; |
378 | cook_input.all_consume = 0; |
379 | } else { |
380 | libcook_print("inbuf malloc failed\n"); |
381 | return -1; |
382 | } |
383 | } |
384 | if (cook_output.buf == NULL) { |
385 | cook_output.buf = (BYTE *)malloc(DefaultOutBufSize * sizeof(BYTE)); |
386 | if (cook_output.buf != NULL) { |
387 | memset(cook_output.buf, 0, DefaultOutBufSize); |
388 | cook_output.buf_len = 0; |
389 | cook_output.buf_max = DefaultOutBufSize; |
390 | cook_output.cousume = 0; |
391 | } else { |
392 | libcook_print("outbuf malloc failed\n"); |
393 | return -1; |
394 | } |
395 | } |
396 | |
397 | if (cook_input.buf == NULL || cook_output.buf == NULL) { |
398 | libcook_print("malloc buf failed\n"); |
399 | return -1; |
400 | |
401 | } |
402 | /**********wait for implement*******/ |
403 | //dsp_cache_wback((unsigned)file_header,AUDIO_EXTRA_DATA_SIZE); |
404 | |
405 | |
406 | /*clear up the decoder structure */ |
407 | |
408 | memset(&ra_dec_info, 0, sizeof(ra_decoder_info_t)); |
409 | memset(&ra_info, 0, sizeof(rm_info_t)); |
410 | cur_read_ptr = file_header; |
411 | |
412 | /* Create the parser struct */ |
413 | pParser = rm_parser_create(NULL, rm_error); |
414 | if (!pParser) { |
415 | libcook_print("[cook decode],create parser failed\n"); |
416 | return -1; |
417 | } |
418 | /* Set the stream into the parser */ |
419 | #if 0 |
420 | for (i = 0; i < AUDIO_EXTRA_DATA_SIZE / 8; i++) { |
421 | printk("%d header data [0x%x],[0x%x],[0x%x],[0x%x],[0x%x],[0x%x],[0x%x],[0x%x]\n\t", i, \ |
422 | file_header[i * 8 + 0], file_header[i * 8 + 1], file_header[i * 8 + 2], file_header[i * 8 + 3], \ |
423 | file_header[i * 8 + 4], file_header[i * 8 + 5], file_header[i * 8 + 6], file_header[i * 8 + 7]); |
424 | } |
425 | #endif |
426 | retVal = rm_parser_init_io(pParser, file_header, rm_io_read, rm_io_seek); |
427 | if (retVal != HXR_OK) { |
428 | libcook_print("[cook decode], parser init IO failed\n"); |
429 | rm_parser_destroy(&pParser); |
430 | return -1; |
431 | } |
432 | /* Read all the headers at the beginning of the .rm file */ |
433 | retVal = rm_parser_read_headers(pParser); |
434 | if (retVal != HXR_OK) { |
435 | libcook_print("[cook decode], parser read header failed\n"); |
436 | rm_parser_destroy(&pParser); |
437 | return -1; |
438 | } |
439 | libcook_print(" rm_parser_read_headers finished \n"); |
440 | |
441 | /* Get the number of streams */ |
442 | ulNumStreams = rm_parser_get_num_streams(pParser); |
443 | if (ulNumStreams == 0) { |
444 | libcook_print("[cook decode], no stream found\n"); |
445 | rm_parser_destroy(&pParser); |
446 | return -1; |
447 | } |
448 | for (i = 0; i < ulNumStreams && retVal == HXR_OK; i++) { |
449 | retVal = rm_parser_get_stream_header(pParser, i, &pHdr); |
450 | if (retVal == HXR_OK) { |
451 | if (rm_stream_is_realaudio(pHdr)) { |
452 | /* Create the RealAudio depacketizer */ |
453 | pRADpack = ra_depack_create((void*)pParser, _ra_block_available, NULL, rm_error); |
454 | if (!pRADpack) { |
455 | libcook_print("[cook decode], create depack failed\n"); |
456 | rm_parser_destroy_stream_header(pParser, &pHdr); |
457 | rm_parser_destroy(&pParser); |
458 | return -1; |
459 | } |
460 | /* Initialize the RA depacketizer with the stream header */ |
461 | retVal = ra_depack_init(pRADpack, pHdr); |
462 | if (retVal != HXR_OK) { |
463 | libcook_print("[cook decode],init depack failed\n"); |
464 | ra_depack_destroy(&pRADpack); |
465 | rm_parser_destroy_stream_header(pParser, &pHdr); |
466 | rm_parser_destroy(&pParser); |
467 | return -1; |
468 | } |
469 | /* |
470 | * Get the codec 4CC of substream 0. We |
471 | * arbitrarily choose substream 0 here. |
472 | */ |
473 | ulCodec4CC = ra_depack_get_codec_4cc(pRADpack, 0); |
474 | if (ulCodec4CC == 0x636F6F6B) { /* cook */ |
475 | retVal = ra_depack_get_codec_init_info(pRADpack, 0, &pRAInfo); |
476 | ra_info.pRaInfo = pRAInfo; |
477 | |
478 | } else if ((ulCodec4CC == 0x72616163) || (ulCodec4CC == 0x72616370)) |
479 | /* raac racp */ |
480 | { |
481 | retVal = ra_depack_get_codec_init_info(pRADpack, 0, &pRAInfo); |
482 | ra_info.pRaInfo = pRAInfo; |
483 | } |
484 | ra_info.pDepack = pRADpack; |
485 | |
486 | } |
487 | rm_parser_destroy_stream_header(pParser, &pHdr); |
488 | } |
489 | libcook_print("cook rm_parser_get_stream_header finished\n"); |
490 | |
491 | } |
492 | /* Set the stream into the parser */ |
493 | //retVal = rm_parser_init_io(pParser, 0, rm_ab_read, rm_ab_seek); |
494 | retVal = rm_parser_init_io(pParser, 0, rm_ab_read, rm_ab_seek); |
495 | if (retVal != HXR_OK) { |
496 | if (pRADpack) { |
497 | ra_depack_destroy(&pRADpack); |
498 | ra_info.pDepack = NULL; |
499 | } |
500 | if (pParser) { |
501 | rm_parser_destroy(&pParser); |
502 | } |
503 | libcook_print("[cook decode],rm_parser_init_io failed,errid %d\n", retVal); |
504 | return -1; |
505 | } |
506 | ra_info.pParser = pParser; |
507 | rm_parser_set_stream(&pParser, 0); |
508 | rm_parser_file_seek(pParser, 0); |
509 | ra_dec_info.pDecode = ra_decode_create(HXNULL, rm_error); |
510 | if (retVal != HXR_OK) { |
511 | if (pRADpack) { |
512 | ra_depack_destroy(&pRADpack); |
513 | ra_info.pDepack = NULL; |
514 | } |
515 | if (pParser) { |
516 | rm_parser_destroy(&pParser); |
517 | } |
518 | libcook_print("[cook decode],ra_decode_create failed,errid %d\n", retVal); |
519 | return -1; |
520 | } |
521 | ra_dec_info.ulStatus = RADEC_PLAY; |
522 | ra_dec_info.ulTotalSample = 0; |
523 | ra_dec_info.ulTotalSamplePlayed = 0; |
524 | UINT32 ulMaxSamples = 0; |
525 | if (ra_dec_info.pOutBuf) { |
526 | ra_decode_reset(ra_dec_info.pDecode, |
527 | (UINT16*)ra_dec_info.pOutBuf, |
528 | ra_dec_info.ulOutBufSize / 2, |
529 | &ulMaxSamples); |
530 | } |
531 | retVal = ra_decode_init(ra_dec_info.pDecode, ulCodec4CC, HXNULL, 0, ra_info.pRaInfo); |
532 | if (retVal != HXR_OK) { |
533 | if (pRADpack) { |
534 | ra_depack_destroy(&pRADpack); |
535 | ra_info.pDepack = NULL; |
536 | } |
537 | if (pParser) { |
538 | rm_parser_destroy(&pParser); |
539 | } |
540 | libcook_print("[cook decode],ra_decode_init failed,errid %d\n", retVal); |
541 | return -1; |
542 | } |
543 | if (ra_dec_info.pOutBuf) { |
544 | ra_decode_getmaxsize(ra_dec_info.pDecode, &ulMaxSamples); |
545 | if (ulMaxSamples * sizeof(UINT16) > ra_dec_info.ulOutBufSize) { |
546 | free(ra_dec_info.pOutBuf); |
547 | ra_dec_info.ulOutBufSize = ulMaxSamples * sizeof(UINT16); |
548 | ra_dec_info.pOutBuf = (BYTE*) malloc(ra_dec_info.ulOutBufSize); |
549 | } |
550 | } else { |
551 | ra_decode_getmaxsize(ra_dec_info.pDecode, &ulMaxSamples); |
552 | ra_dec_info.ulOutBufSize = ulMaxSamples * sizeof(UINT16); |
553 | if (ra_dec_info.ulOutBufSize > 0) { |
554 | ra_dec_info.pOutBuf = (BYTE*) malloc(ra_dec_info.ulOutBufSize); |
555 | if (ra_dec_info.pOutBuf == NULL) { |
556 | if (pRADpack) { |
557 | ra_depack_destroy(&pRADpack); |
558 | ra_info.pDepack = NULL; |
559 | } |
560 | if (pParser) { |
561 | rm_parser_destroy(&pParser); |
562 | ra_info.pParser = NULL; |
563 | } |
564 | libcook_print("[cook decode],dsp malloc failed,request %s bytes\n", ra_dec_info.ulOutBufSize); |
565 | return -1; |
566 | } |
567 | } |
568 | |
569 | } |
570 | |
571 | return 0; |
572 | } |
573 | |
574 | static void ra_depack_cleanup(void) |
575 | { |
576 | /* Destroy the codec init info */ |
577 | if (ra_info.pRaInfo) { |
578 | ra_depack_destroy_codec_init_info(ra_info.pDepack, &ra_info.pRaInfo); |
579 | } |
580 | /* Destroy the depacketizer */ |
581 | if (ra_info.pDepack) { |
582 | ra_depack_destroy(&ra_info.pDepack); |
583 | } |
584 | /* If we have a packet, destroy it */ |
585 | if (ra_info.pPacket) { |
586 | rm_parser_destroy_packet(ra_info.pParser, &ra_info.pPacket); |
587 | } |
588 | if (ra_info.pParser) { |
589 | rm_parser_destroy(&ra_info.pParser); |
590 | } |
591 | memset(&ra_info, 0, sizeof(ra_info)); |
592 | } |
593 | |
594 | |
595 | //static int cook_decode_release(void) |
596 | int audio_dec_release(audio_decoder_operations_t *adec_ops) |
597 | { |
598 | if (cook_input.buf != NULL) { |
599 | free(cook_input.buf); |
600 | cook_input.buf = NULL; |
601 | } |
602 | if (cook_output.buf != NULL) { |
603 | free(cook_output.buf); |
604 | cook_output.buf = NULL; |
605 | } |
606 | |
607 | ra_decode_destroy(ra_dec_info.pDecode); |
608 | ra_dec_info.pDecode = HXNULL; |
609 | if (ra_dec_info.pOutBuf) { |
610 | free(ra_dec_info.pOutBuf); |
611 | ra_dec_info.pOutBuf = HXNULL; |
612 | } |
613 | ra_dec_info.ulStatus = RADEC_IDLE; |
614 | ra_depack_cleanup(); |
615 | libcook_print(" cook decoder release \n"); |
616 | return 0; |
617 | } |
618 | |
619 | int audio_dec_getinfo(audio_decoder_operations_t *adec_ops, void *pAudioInfo) |
620 | { |
621 | return 0; |
622 | } |
623 | |
624 | |
625 |