summaryrefslogtreecommitdiff
Diffstat
-rw-r--r--Android.mk1
-rwxr-xr-xamadec/Android.mk282
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_dcvdec.so80
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_dtshd.so85
-rw-r--r--amadec/acodec_lib_50/libstagefright_soft_truehddec.so41
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_dcvdec.so109
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_dtshd.so272
-rw-r--r--amadec/acodec_lib_android_n/libstagefright_soft_truehddec.so87
-rwxr-xr-xamadec/acodec_lib_mx/libstagefright_soft_ddpdec.so113
-rwxr-xr-xamadec/acodec_lib_mx/libstagefright_soft_dtshd.so121
-rw-r--r--amadec/adec-armdec-mgt.h57
-rw-r--r--amadec/adec-external-ctrl.c899
-rw-r--r--amadec/adec-ffmpeg-mgt.c1550
-rw-r--r--amadec/adec-internal-mgt.c772
-rw-r--r--amadec/adec-message.c156
-rw-r--r--amadec/adec-message.h61
-rwxr-xr-xamadec/adec-pts-mgt.c1107
-rw-r--r--amadec/adec-pts-mgt.h82
-rw-r--r--amadec/adec-wfd-out.cpp361
-rw-r--r--amadec/adec-wfd.c811
-rw-r--r--amadec/adec_omx_brige.c284
-rw-r--r--amadec/adec_omx_brige.h56
-rw-r--r--amadec/adec_read.c200
-rw-r--r--amadec/adec_reg.h76
-rw-r--r--amadec/adec_write.c189
-rw-r--r--amadec/adec_write.h42
-rw-r--r--amadec/audio-dec.h314
-rw-r--r--amadec/audio_out/alsa-out.c1082
-rw-r--r--amadec/audio_out/aml_resample.c708
-rw-r--r--amadec/audio_out/aml_resample.h86
-rwxr-xr-xamadec/audio_out/android-out.cpp1640
-rw-r--r--amadec/audiodsp_update_format.c188
-rw-r--r--amadec/dsp/audiodsp-ctl.c471
-rw-r--r--amadec/dts_enc.c209
-rw-r--r--amadec/dts_enc.h11
-rw-r--r--amadec/dts_transenc_api.c143
-rw-r--r--amadec/dts_transenc_api.h19
-rw-r--r--amadec/feeder.c231
-rw-r--r--amadec/feeder.h26
-rw-r--r--amadec/include/adec-external-ctrl.h63
-rwxr-xr-xamadec/include/adec-macros.h41
-rw-r--r--amadec/include/adec-types.h53
-rwxr-xr-xamadec/include/alsa-out.h26
-rw-r--r--amadec/include/audio-out.h41
-rw-r--r--amadec/include/audiodsp.h142
-rw-r--r--amadec/include/audiodsp_update_format.h25
-rw-r--r--amadec/include/log-print.h26
-rwxr-xr-xamadec/omx_audio/ALAC_mediasource.cpp205
-rw-r--r--amadec/omx_audio/ALAC_mediasource.h62
-rwxr-xr-xamadec/omx_audio/ASF_mediasource.cpp184
-rw-r--r--amadec/omx_audio/ASF_mediasource.h127
-rwxr-xr-xamadec/omx_audio/Android.mk34
-rwxr-xr-xamadec/omx_audio/DDP_mediasource.cpp528
-rw-r--r--amadec/omx_audio/DDP_mediasource.h141
-rw-r--r--amadec/omx_audio/DTSHD_mediasource.cpp316
-rw-r--r--amadec/omx_audio/DTSHD_mediasource.h74
-rwxr-xr-xamadec/omx_audio/MP3_mediasource.cpp579
-rw-r--r--amadec/omx_audio/MP3_mediasource.h80
-rw-r--r--amadec/omx_audio/THD_mediasource.cpp229
-rw-r--r--amadec/omx_audio/THD_mediasource.h74
-rwxr-xr-xamadec/omx_audio/Vorbis_mediasource.cpp245
-rw-r--r--amadec/omx_audio/Vorbis_mediasource.h58
-rw-r--r--amadec/omx_audio/adec_omx.cpp421
-rw-r--r--amadec/omx_audio/adec_omx.h71
-rwxr-xr-xamadec/omx_audio/audio_mediasource.cpp37
-rw-r--r--amadec/omx_audio/audio_mediasource.h46
-rw-r--r--amadec/omx_audio/audio_medissource.h137
-rw-r--r--amadec/pcmenc_api.c147
-rw-r--r--amadec/pcmenc_api.h25
-rw-r--r--amadec/spdif_api.c306
-rw-r--r--amadec/spdif_api.h26
-rwxr-xr-xaudio_codec/Android.mk1
-rw-r--r--audio_codec/config.mk10
-rwxr-xr-xaudio_codec/libadpcm/Android.mk12
-rw-r--r--audio_codec/libadpcm/adpcm.h346
-rw-r--r--audio_codec/libadpcm/adpcm_decode.c841
-rwxr-xr-xaudio_codec/libamr/Android.mk25
-rwxr-xr-xaudio_codec/libamr/Makefile5
-rw-r--r--audio_codec/libamr/amr_decode.c186
-rw-r--r--audio_codec/libamr/amr_decode.h8
-rwxr-xr-xaudio_codec/libamr/dec.h18
-rw-r--r--audio_codec/libamr/dec_acelp.c620
-rwxr-xr-xaudio_codec/libamr/dec_acelp.h17
-rw-r--r--audio_codec/libamr/dec_dtx.c683
-rw-r--r--audio_codec/libamr/dec_dtx.h49
-rw-r--r--audio_codec/libamr/dec_gain.c853
-rw-r--r--audio_codec/libamr/dec_gain.h28
-rw-r--r--audio_codec/libamr/dec_if.c834
-rwxr-xr-xaudio_codec/libamr/dec_if.h23
-rw-r--r--audio_codec/libamr/dec_lpc.c789
-rw-r--r--audio_codec/libamr/dec_lpc.h25
-rw-r--r--audio_codec/libamr/dec_main.c842
-rw-r--r--audio_codec/libamr/dec_main.h57
-rw-r--r--audio_codec/libamr/dec_rom.c2114
-rw-r--r--audio_codec/libamr/dec_util.c1304
-rw-r--r--audio_codec/libamr/dec_util.h33
-rw-r--r--audio_codec/libamr/if_rom.c1030
-rwxr-xr-xaudio_codec/libamr/if_rom.h70
-rw-r--r--audio_codec/libamr/interf_dec.c906
-rw-r--r--audio_codec/libamr/interf_dec.h56
-rw-r--r--audio_codec/libamr/interf_rom.h1788
-rw-r--r--audio_codec/libamr/rom_dec.h13274
-rw-r--r--audio_codec/libamr/sp_dec.c6078
-rw-r--r--audio_codec/libamr/sp_dec.h83
-rwxr-xr-xaudio_codec/libamr/typedef.h17
-rwxr-xr-xaudio_codec/libape/Android.mk28
-rw-r--r--audio_codec/libape/Ape_decoder.h216
-rw-r--r--audio_codec/libape/amlogic_r30813_audio_ape_lib.c1
-rw-r--r--audio_codec/libape/apedec.c1120
-rw-r--r--audio_codec/libcook/Android.mk28
-rw-r--r--audio_codec/libcook/aac_bitstream.h133
-rw-r--r--audio_codec/libcook/aac_decode.h148
-rw-r--r--audio_codec/libcook/aac_reorder.h53
-rw-r--r--audio_codec/libcook/assembly.h119
-rw-r--r--audio_codec/libcook/challenge.h132
-rw-r--r--audio_codec/libcook/codec_defines.h93
-rw-r--r--audio_codec/libcook/coder.h287
-rw-r--r--audio_codec/libcook/cook_codec.h30
-rw-r--r--audio_codec/libcook/cook_decode.c624
-rw-r--r--audio_codec/libcook/cook_decode.h35
-rw-r--r--audio_codec/libcook/ga_config.h86
-rw-r--r--audio_codec/libcook/gecko2codec.c833
-rw-r--r--audio_codec/libcook/gecko2codec.h60
-rw-r--r--audio_codec/libcook/helix_config.h92
-rw-r--r--audio_codec/libcook/helix_mime_types.h56
-rw-r--r--audio_codec/libcook/helix_result.h107
-rw-r--r--audio_codec/libcook/helix_types.h305
-rw-r--r--audio_codec/libcook/helix_utils.h106
-rw-r--r--audio_codec/libcook/md5.h113
-rw-r--r--audio_codec/libcook/memory_utils.c100
-rw-r--r--audio_codec/libcook/memory_utils.h58
-rw-r--r--audio_codec/libcook/pack_utils.c306
-rw-r--r--audio_codec/libcook/pack_utils.h93
-rw-r--r--audio_codec/libcook/packet_defines.h48
-rw-r--r--audio_codec/libcook/ra8lbr_decode.c378
-rw-r--r--audio_codec/libcook/ra8lbr_decode.h161
-rw-r--r--audio_codec/libcook/ra_backend.h94
-rw-r--r--audio_codec/libcook/ra_bitpack.c197
-rw-r--r--audio_codec/libcook/ra_buffers.c127
-rw-r--r--audio_codec/libcook/ra_category.c298
-rw-r--r--audio_codec/libcook/ra_couple.c224
-rw-r--r--audio_codec/libcook/ra_decode.c321
-rw-r--r--audio_codec/libcook/ra_decode.h183
-rw-r--r--audio_codec/libcook/ra_depack.c230
-rw-r--r--audio_codec/libcook/ra_depack.h177
-rw-r--r--audio_codec/libcook/ra_depack_internal.c1710
-rw-r--r--audio_codec/libcook/ra_depack_internal.h232
-rw-r--r--audio_codec/libcook/ra_envelope.c123
-rw-r--r--audio_codec/libcook/ra_fft.c368
-rw-r--r--audio_codec/libcook/ra_format_info.h60
-rw-r--r--audio_codec/libcook/ra_gainctrl.c584
-rw-r--r--audio_codec/libcook/ra_huffman.c86
-rw-r--r--audio_codec/libcook/ra_hufftabs.c244
-rw-r--r--audio_codec/libcook/ra_mlt.c357
-rw-r--r--audio_codec/libcook/ra_sqvh.c431
-rw-r--r--audio_codec/libcook/ra_trigtabs.c932
-rw-r--r--audio_codec/libcook/rasl.c376
-rw-r--r--audio_codec/libcook/rasl.h71
-rw-r--r--audio_codec/libcook/rdtpck.h153
-rw-r--r--audio_codec/libcook/rm_error.h54
-rw-r--r--audio_codec/libcook/rm_error_default.c58
-rw-r--r--audio_codec/libcook/rm_error_default.h53
-rw-r--r--audio_codec/libcook/rm_io_default.c101
-rw-r--r--audio_codec/libcook/rm_io_default.h49
-rw-r--r--audio_codec/libcook/rm_memory.h54
-rw-r--r--audio_codec/libcook/rm_memory_default.c54
-rw-r--r--audio_codec/libcook/rm_memory_default.h46
-rw-r--r--audio_codec/libcook/rm_packet.c117
-rw-r--r--audio_codec/libcook/rm_packet.h80
-rw-r--r--audio_codec/libcook/rm_parse.h302
-rw-r--r--audio_codec/libcook/rm_parser.c649
-rw-r--r--audio_codec/libcook/rm_parser_internal.c3342
-rw-r--r--audio_codec/libcook/rm_parser_internal.h420
-rw-r--r--audio_codec/libcook/rm_property.c105
-rw-r--r--audio_codec/libcook/rm_property.h107
-rw-r--r--audio_codec/libcook/rm_stream.c356
-rw-r--r--audio_codec/libcook/rm_stream.h115
-rw-r--r--audio_codec/libcook/rm_stream_internal.h77
-rw-r--r--audio_codec/libcook/rv20backend.h69
-rw-r--r--audio_codec/libcook/rv30backend.h68
-rw-r--r--audio_codec/libcook/rv_backend.h84
-rw-r--r--audio_codec/libcook/rv_backend_types.h198
-rw-r--r--audio_codec/libcook/rv_decode.h208
-rw-r--r--audio_codec/libcook/rv_decode_message.h492
-rw-r--r--audio_codec/libcook/rv_depack.c271
-rw-r--r--audio_codec/libcook/rv_depack.h162
-rw-r--r--audio_codec/libcook/rv_depack_internal.c1071
-rw-r--r--audio_codec/libcook/rv_depack_internal.h171
-rw-r--r--audio_codec/libcook/rv_format_info.h91
-rw-r--r--audio_codec/libcook/statname.h118
-rw-r--r--audio_codec/libcook/stream_hdr_structs.h66
-rw-r--r--audio_codec/libcook/stream_hdr_utils.c136
-rw-r--r--audio_codec/libcook/stream_hdr_utils.h77
-rw-r--r--audio_codec/libcook/string_utils.c87
-rw-r--r--audio_codec/libcook/string_utils.h62
-rw-r--r--audio_codec/libcook/tngpkt.h400
-rwxr-xr-xaudio_codec/libfaad/Android.mk101
-rwxr-xr-xaudio_codec/libfaad/Makefile130
-rw-r--r--audio_codec/libfaad/analysis.h52
-rwxr-xr-xaudio_codec/libfaad/audio.d3
-rw-r--r--audio_codec/libfaad/bits.c261
-rwxr-xr-xaudio_codec/libfaad/bits.d18
-rw-r--r--audio_codec/libfaad/bits.h446
-rw-r--r--audio_codec/libfaad/cfft.c988
-rw-r--r--audio_codec/libfaad/cfft.h55
-rw-r--r--audio_codec/libfaad/cfft_tab.h1816
-rw-r--r--audio_codec/libfaad/codebook/hcb.h140
-rw-r--r--audio_codec/libfaad/codebook/hcb_1.h186
-rw-r--r--audio_codec/libfaad/codebook/hcb_10.h312
-rw-r--r--audio_codec/libfaad/codebook/hcb_11.h415
-rw-r--r--audio_codec/libfaad/codebook/hcb_2.h185
-rw-r--r--audio_codec/libfaad/codebook/hcb_3.h196
-rw-r--r--audio_codec/libfaad/codebook/hcb_4.h199
-rw-r--r--audio_codec/libfaad/codebook/hcb_5.h196
-rw-r--r--audio_codec/libfaad/codebook/hcb_6.h182
-rw-r--r--audio_codec/libfaad/codebook/hcb_7.h162
-rw-r--r--audio_codec/libfaad/codebook/hcb_8.h173
-rw-r--r--audio_codec/libfaad/codebook/hcb_9.h372
-rw-r--r--audio_codec/libfaad/codebook/hcb_sf.h276
-rw-r--r--audio_codec/libfaad/common.c558
-rw-r--r--audio_codec/libfaad/common.h453
-rw-r--r--audio_codec/libfaad/decoder.c2266
-rw-r--r--audio_codec/libfaad/drc.c173
-rw-r--r--audio_codec/libfaad/drc.h49
-rw-r--r--audio_codec/libfaad/drm_dec.c912
-rw-r--r--audio_codec/libfaad/drm_dec.h99
-rw-r--r--audio_codec/libfaad/error.c72
-rw-r--r--audio_codec/libfaad/error.h44
-rw-r--r--audio_codec/libfaad/filtbank.c408
-rw-r--r--audio_codec/libfaad/filtbank.h61
-rw-r--r--audio_codec/libfaad/fixed.h287
-rw-r--r--audio_codec/libfaad/hcr.c422
-rw-r--r--audio_codec/libfaad/helixaac/aaccommon.h210
-rw-r--r--audio_codec/libfaad/helixaac/aacdec.c508
-rw-r--r--audio_codec/libfaad/helixaac/aacdec.h206
-rw-r--r--audio_codec/libfaad/helixaac/aactabs.c157
-rw-r--r--audio_codec/libfaad/helixaac/assembly.h631
-rw-r--r--audio_codec/libfaad/helixaac/assembly_mw.h743
-rw-r--r--audio_codec/libfaad/helixaac/bitstream.c261
-rw-r--r--audio_codec/libfaad/helixaac/bitstream.h74
-rw-r--r--audio_codec/libfaad/helixaac/buffers.c140
-rw-r--r--audio_codec/libfaad/helixaac/coder.h369
-rw-r--r--audio_codec/libfaad/helixaac/dct4.c337
-rw-r--r--audio_codec/libfaad/helixaac/decelmnt.c445
-rw-r--r--audio_codec/libfaad/helixaac/dequant.c379
-rw-r--r--audio_codec/libfaad/helixaac/fft.c391
-rw-r--r--audio_codec/libfaad/helixaac/filefmt.c539
-rw-r--r--audio_codec/libfaad/helixaac/huffman_helix.c450
-rw-r--r--audio_codec/libfaad/helixaac/hufftabs.c177
-rw-r--r--audio_codec/libfaad/helixaac/imdct.c596
-rw-r--r--audio_codec/libfaad/helixaac/noiseless.c513
-rw-r--r--audio_codec/libfaad/helixaac/pns_helix.c371
-rw-r--r--audio_codec/libfaad/helixaac/sbr.c433
-rw-r--r--audio_codec/libfaad/helixaac/sbr.h380
-rw-r--r--audio_codec/libfaad/helixaac/sbrfft.c368
-rw-r--r--audio_codec/libfaad/helixaac/sbrfreq.c673
-rw-r--r--audio_codec/libfaad/helixaac/sbrhfadj.c882
-rw-r--r--audio_codec/libfaad/helixaac/sbrhfgen.c655
-rw-r--r--audio_codec/libfaad/helixaac/sbrhuff.c494
-rw-r--r--audio_codec/libfaad/helixaac/sbrimdct.c447
-rw-r--r--audio_codec/libfaad/helixaac/sbrmath.c198
-rw-r--r--audio_codec/libfaad/helixaac/sbrqmf.c648
-rw-r--r--audio_codec/libfaad/helixaac/sbrside.c634
-rw-r--r--audio_codec/libfaad/helixaac/sbrtabs.c400
-rw-r--r--audio_codec/libfaad/helixaac/statname.h115
-rw-r--r--audio_codec/libfaad/helixaac/stproc.c251
-rw-r--r--audio_codec/libfaad/helixaac/tns_helix.c307
-rw-r--r--audio_codec/libfaad/helixaac/trigtabs.c1000
-rw-r--r--audio_codec/libfaad/helixaac/trigtabs_fltgen.c357
-rw-r--r--audio_codec/libfaad/huffman.c582
-rw-r--r--audio_codec/libfaad/huffman.h47
-rw-r--r--audio_codec/libfaad/ic_predict.c258
-rw-r--r--audio_codec/libfaad/ic_predict.h252
-rw-r--r--audio_codec/libfaad/iq_table.h16456
-rw-r--r--audio_codec/libfaad/is.c106
-rw-r--r--audio_codec/libfaad/is.h67
-rw-r--r--audio_codec/libfaad/kbd_win.h2294
-rw-r--r--audio_codec/libfaad/libaacdec.c544
-rw-r--r--audio_codec/libfaad/libaacdec.h64
-rwxr-xr-xaudio_codec/libfaad/libfaad2.def14
-rw-r--r--audio_codec/libfaad/lt_predict.c205
-rw-r--r--audio_codec/libfaad/lt_predict.h66
-rw-r--r--audio_codec/libfaad/mdct.c307
-rw-r--r--audio_codec/libfaad/mdct.h48
-rw-r--r--audio_codec/libfaad/mdct_tab.h3639
-rw-r--r--audio_codec/libfaad/mp4.c307
-rw-r--r--audio_codec/libfaad/mp4.h52
-rw-r--r--audio_codec/libfaad/ms.c71
-rw-r--r--audio_codec/libfaad/ms.h44
-rw-r--r--audio_codec/libfaad/neaacdec.h257
-rw-r--r--audio_codec/libfaad/output.c583
-rw-r--r--audio_codec/libfaad/output.h48
-rw-r--r--audio_codec/libfaad/pns.c273
-rw-r--r--audio_codec/libfaad/pns.h58
-rw-r--r--audio_codec/libfaad/ps_dec.c1905
-rw-r--r--audio_codec/libfaad/ps_dec.h151
-rw-r--r--audio_codec/libfaad/ps_syntax.c532
-rw-r--r--audio_codec/libfaad/ps_tables.h547
-rw-r--r--audio_codec/libfaad/pulse.c59
-rw-r--r--audio_codec/libfaad/pulse.h43
-rw-r--r--audio_codec/libfaad/rvlc.c524
-rw-r--r--audio_codec/libfaad/rvlc.h55
-rw-r--r--audio_codec/libfaad/sbr_dct.c2267
-rw-r--r--audio_codec/libfaad/sbr_dct.h52
-rw-r--r--audio_codec/libfaad/sbr_dec.c679
-rw-r--r--audio_codec/libfaad/sbr_dec.h253
-rw-r--r--audio_codec/libfaad/sbr_e_nf.c475
-rw-r--r--audio_codec/libfaad/sbr_e_nf.h50
-rw-r--r--audio_codec/libfaad/sbr_fbt.c737
-rw-r--r--audio_codec/libfaad/sbr_fbt.h55
-rw-r--r--audio_codec/libfaad/sbr_hfadj.c1644
-rw-r--r--audio_codec/libfaad/sbr_hfadj.h56
-rw-r--r--audio_codec/libfaad/sbr_hfgen.c647
-rw-r--r--audio_codec/libfaad/sbr_hfgen.h49
-rw-r--r--audio_codec/libfaad/sbr_huff.c344
-rw-r--r--audio_codec/libfaad/sbr_huff.h46
-rw-r--r--audio_codec/libfaad/sbr_noise.h564
-rw-r--r--audio_codec/libfaad/sbr_qmf.c614
-rw-r--r--audio_codec/libfaad/sbr_qmf.h55
-rw-r--r--audio_codec/libfaad/sbr_qmf_c.h368
-rw-r--r--audio_codec/libfaad/sbr_syntax.c893
-rw-r--r--audio_codec/libfaad/sbr_syntax.h68
-rw-r--r--audio_codec/libfaad/sbr_tf_grid.c247
-rw-r--r--audio_codec/libfaad/sbr_tf_grid.h47
-rw-r--r--audio_codec/libfaad/sine_win.h4296
-rw-r--r--audio_codec/libfaad/specrec.c1249
-rw-r--r--audio_codec/libfaad/specrec.h49
-rw-r--r--audio_codec/libfaad/ssr.c170
-rw-r--r--audio_codec/libfaad/ssr.h59
-rw-r--r--audio_codec/libfaad/ssr_fb.c191
-rw-r--r--audio_codec/libfaad/ssr_fb.h53
-rw-r--r--audio_codec/libfaad/ssr_ipqf.c171
-rw-r--r--audio_codec/libfaad/ssr_ipqf.h46
-rw-r--r--audio_codec/libfaad/ssr_win.h635
-rw-r--r--audio_codec/libfaad/structs.h513
-rw-r--r--audio_codec/libfaad/syntax.c2539
-rw-r--r--audio_codec/libfaad/syntax.h129
-rw-r--r--audio_codec/libfaad/tns.c304
-rw-r--r--audio_codec/libfaad/tns.h51
-rwxr-xr-xaudio_codec/libflac/Android.mk22
-rw-r--r--audio_codec/libflac/avcodec.h337
-rw-r--r--audio_codec/libflac/bswap.h94
-rw-r--r--audio_codec/libflac/codec.h36
-rw-r--r--audio_codec/libflac/codec_message.h109
-rw-r--r--audio_codec/libflac/common.h356
-rw-r--r--audio_codec/libflac/crc.c146
-rw-r--r--audio_codec/libflac/crc.h46
-rw-r--r--audio_codec/libflac/flac.c43
-rw-r--r--audio_codec/libflac/flac.h124
-rw-r--r--audio_codec/libflac/flac_decode.c943
-rw-r--r--audio_codec/libflac/flacdata.c38
-rw-r--r--audio_codec/libflac/flacdata.h29
-rw-r--r--audio_codec/libflac/get_bits.h564
-rw-r--r--audio_codec/libflac/golomb.h585
-rw-r--r--audio_codec/libflac/internal.h195
-rw-r--r--audio_codec/libflac/intreadwrite.h390
-rw-r--r--audio_codec/libflac/mathops.h78
-rw-r--r--audio_codec/libflac/types.h49
-rwxr-xr-xaudio_codec/liblpcm/Android.mk13
-rw-r--r--audio_codec/liblpcm/lpcm_decode.c437
-rwxr-xr-xaudio_codec/libmad/Android.mk13
-rwxr-xr-xaudio_codec/libmad/D.dat607
-rw-r--r--audio_codec/libmad/bit.c244
-rw-r--r--audio_codec/libmad/bit.h47
-rw-r--r--audio_codec/libmad/config.h133
-rw-r--r--audio_codec/libmad/decoder.c1102
-rw-r--r--audio_codec/libmad/decoder.h91
-rw-r--r--audio_codec/libmad/fixed.c85
-rw-r--r--audio_codec/libmad/fixed.h499
-rw-r--r--audio_codec/libmad/frame.c525
-rw-r--r--audio_codec/libmad/frame.h118
-rw-r--r--audio_codec/libmad/global.h58
-rw-r--r--audio_codec/libmad/huffman.c3109
-rw-r--r--audio_codec/libmad/huffman.h66
-rwxr-xr-xaudio_codec/libmad/imdct_l_arm.S1000
-rwxr-xr-xaudio_codec/libmad/imdct_s.dat62
-rw-r--r--audio_codec/libmad/layer12.c552
-rwxr-xr-xaudio_codec/libmad/layer12.h31
-rw-r--r--audio_codec/libmad/layer3.c2742
-rwxr-xr-xaudio_codec/libmad/layer3.h30
-rw-r--r--audio_codec/libmad/mad.h966
-rwxr-xr-xaudio_codec/libmad/qc_table.dat77
-rwxr-xr-xaudio_codec/libmad/rq_table.dat8747
-rwxr-xr-xaudio_codec/libmad/sf_table.dat106
-rw-r--r--audio_codec/libmad/stream.c185
-rw-r--r--audio_codec/libmad/stream.h111
-rw-r--r--audio_codec/libmad/synth.c921
-rw-r--r--audio_codec/libmad/synth.h69
-rw-r--r--audio_codec/libmad/timer.c493
-rw-r--r--audio_codec/libmad/timer.h100
-rw-r--r--audio_codec/libmad/version.c91
-rw-r--r--audio_codec/libmad/version.h47
-rwxr-xr-xaudio_codec/libpcm/Android.mk11
-rw-r--r--audio_codec/libpcm/intreadwrite.h390
-rw-r--r--audio_codec/libpcm/pcm_decode.c780
-rw-r--r--audio_codec/libraac/Android.mk51
-rw-r--r--audio_codec/libraac/aac_bitstream.c200
-rw-r--r--audio_codec/libraac/aac_bitstream.h133
-rw-r--r--audio_codec/libraac/aac_decode.h148
-rw-r--r--audio_codec/libraac/aac_decode_main.c396
-rw-r--r--audio_codec/libraac/aac_reorder.c85
-rw-r--r--audio_codec/libraac/aac_reorder.h53
-rw-r--r--audio_codec/libraac/aaccommon.h200
-rw-r--r--audio_codec/libraac/aacdec.c607
-rw-r--r--audio_codec/libraac/aacdec.h200
-rw-r--r--audio_codec/libraac/aactabs.c157
-rw-r--r--audio_codec/libraac/assembly.h147
-rw-r--r--audio_codec/libraac/bitstream.c451
-rw-r--r--audio_codec/libraac/bitstream.h76
-rw-r--r--audio_codec/libraac/buffers.c132
-rw-r--r--audio_codec/libraac/coder.h370
-rw-r--r--audio_codec/libraac/dct4.c339
-rw-r--r--audio_codec/libraac/decelmnt.c451
-rw-r--r--audio_codec/libraac/dequant.c382
-rw-r--r--audio_codec/libraac/fft.c393
-rw-r--r--audio_codec/libraac/filefmt.c531
-rw-r--r--audio_codec/libraac/ga_config.c209
-rw-r--r--audio_codec/libraac/ga_config.h86
-rw-r--r--audio_codec/libraac/huffman.c449
-rw-r--r--audio_codec/libraac/hufftabs.c177
-rw-r--r--audio_codec/libraac/imdct.c598
-rw-r--r--audio_codec/libraac/include/challenge.h132
-rw-r--r--audio_codec/libraac/include/codec_defines.h93
-rw-r--r--audio_codec/libraac/include/gecko2codec.h60
-rw-r--r--audio_codec/libraac/include/helix_config.h92
-rw-r--r--audio_codec/libraac/include/helix_mime_types.h56
-rw-r--r--audio_codec/libraac/include/helix_result.h107
-rw-r--r--audio_codec/libraac/include/helix_types.h305
-rw-r--r--audio_codec/libraac/include/helix_utils.h106
-rw-r--r--audio_codec/libraac/include/md5.h113
-rw-r--r--audio_codec/libraac/include/memory_utils.h58
-rw-r--r--audio_codec/libraac/include/pack_utils.h93
-rw-r--r--audio_codec/libraac/include/packet_defines.h48
-rw-r--r--audio_codec/libraac/include/ra8lbr_decode.h161
-rw-r--r--audio_codec/libraac/include/ra_backend.h94
-rw-r--r--audio_codec/libraac/include/ra_decode.h183
-rw-r--r--audio_codec/libraac/include/ra_depack.h177
-rw-r--r--audio_codec/libraac/include/ra_format_info.h60
-rw-r--r--audio_codec/libraac/include/rasl.h71
-rw-r--r--audio_codec/libraac/include/rdtpck.h153
-rw-r--r--audio_codec/libraac/include/rm_error.h54
-rw-r--r--audio_codec/libraac/include/rm_error_default.h53
-rw-r--r--audio_codec/libraac/include/rm_io_default.h49
-rw-r--r--audio_codec/libraac/include/rm_memory.h54
-rw-r--r--audio_codec/libraac/include/rm_memory_default.h46
-rw-r--r--audio_codec/libraac/include/rm_packet.h80
-rw-r--r--audio_codec/libraac/include/rm_parse.h302
-rw-r--r--audio_codec/libraac/include/rm_property.h107
-rw-r--r--audio_codec/libraac/include/rm_stream.h115
-rw-r--r--audio_codec/libraac/include/rm_stream_internal.h77
-rw-r--r--audio_codec/libraac/include/rv20backend.h69
-rw-r--r--audio_codec/libraac/include/rv30backend.h68
-rw-r--r--audio_codec/libraac/include/rv_backend.h84
-rw-r--r--audio_codec/libraac/include/rv_backend_types.h198
-rw-r--r--audio_codec/libraac/include/rv_decode.h208
-rw-r--r--audio_codec/libraac/include/rv_decode_message.h492
-rw-r--r--audio_codec/libraac/include/rv_depack.h162
-rw-r--r--audio_codec/libraac/include/rv_format_info.h91
-rw-r--r--audio_codec/libraac/include/statname.h118
-rw-r--r--audio_codec/libraac/include/stream_hdr_structs.h66
-rw-r--r--audio_codec/libraac/include/stream_hdr_utils.h77
-rw-r--r--audio_codec/libraac/include/string_utils.h62
-rw-r--r--audio_codec/libraac/include/tngpkt.h400
-rw-r--r--audio_codec/libraac/memory_utils.c100
-rw-r--r--audio_codec/libraac/noiseless.c503
-rw-r--r--audio_codec/libraac/pack_utils.c306
-rw-r--r--audio_codec/libraac/pns.c369
-rw-r--r--audio_codec/libraac/ra_depack.c230
-rw-r--r--audio_codec/libraac/ra_depack_internal.c1713
-rw-r--r--audio_codec/libraac/ra_depack_internal.h232
-rw-r--r--audio_codec/libraac/raac_decode.c854
-rw-r--r--audio_codec/libraac/raac_decode.h37
-rw-r--r--audio_codec/libraac/rm_error_default.c60
-rw-r--r--audio_codec/libraac/rm_io_default.c101
-rw-r--r--audio_codec/libraac/rm_memory_default.c54
-rw-r--r--audio_codec/libraac/rm_packet.c117
-rw-r--r--audio_codec/libraac/rm_parser.c649
-rw-r--r--audio_codec/libraac/rm_parser_internal.c3342
-rw-r--r--audio_codec/libraac/rm_parser_internal.h420
-rw-r--r--audio_codec/libraac/rm_property.c105
-rw-r--r--audio_codec/libraac/rm_stream.c356
-rw-r--r--audio_codec/libraac/rv_depack.c271
-rw-r--r--audio_codec/libraac/rv_depack_internal.c1071
-rw-r--r--audio_codec/libraac/rv_depack_internal.h171
-rw-r--r--audio_codec/libraac/sbr.c431
-rw-r--r--audio_codec/libraac/sbr.h381
-rwxr-xr-xaudio_codec/libraac/sbrcov.s164
-rw-r--r--audio_codec/libraac/sbrfft.c368
-rw-r--r--audio_codec/libraac/sbrfreq.c667
-rw-r--r--audio_codec/libraac/sbrhfadj.c877
-rw-r--r--audio_codec/libraac/sbrhfgen.c646
-rw-r--r--audio_codec/libraac/sbrhuff.c492
-rw-r--r--audio_codec/libraac/sbrimdct.c447
-rw-r--r--audio_codec/libraac/sbrmath.c198
-rw-r--r--audio_codec/libraac/sbrqmf.c643
-rwxr-xr-xaudio_codec/libraac/sbrqmfak.s182
-rwxr-xr-xaudio_codec/libraac/sbrqmfsk.s130
-rw-r--r--audio_codec/libraac/sbrside.c615
-rw-r--r--audio_codec/libraac/sbrtabs.c400
-rw-r--r--audio_codec/libraac/statname.h115
-rw-r--r--audio_codec/libraac/stproc.c252
-rw-r--r--audio_codec/libraac/stream_hdr_utils.c136
-rw-r--r--audio_codec/libraac/string_utils.c87
-rw-r--r--audio_codec/libraac/tns.c307
-rw-r--r--audio_codec/libraac/trigtabs.c1000
-rw-r--r--audio_codec/libraac/trigtabs_fltgen.c357
-rwxr-xr-xaudio_codec/wfd_aac_decoder/Android.mk23
-rw-r--r--audio_codec/wfd_aac_decoder/aaccommon.h210
-rw-r--r--audio_codec/wfd_aac_decoder/aacdec.c508
-rw-r--r--audio_codec/wfd_aac_decoder/aacdec.h206
-rw-r--r--audio_codec/wfd_aac_decoder/aactabs.c157
-rw-r--r--audio_codec/wfd_aac_decoder/assembly.h640
-rw-r--r--audio_codec/wfd_aac_decoder/assembly_mw.h743
-rw-r--r--audio_codec/wfd_aac_decoder/bitstream.c261
-rw-r--r--audio_codec/wfd_aac_decoder/bitstream.h74
-rw-r--r--audio_codec/wfd_aac_decoder/buffers.c140
-rw-r--r--audio_codec/wfd_aac_decoder/coder.h369
-rw-r--r--audio_codec/wfd_aac_decoder/dct4.c337
-rw-r--r--audio_codec/wfd_aac_decoder/decelmnt.c445
-rw-r--r--audio_codec/wfd_aac_decoder/dequant.c379
-rw-r--r--audio_codec/wfd_aac_decoder/fft.c391
-rw-r--r--audio_codec/wfd_aac_decoder/filefmt.c539
-rw-r--r--audio_codec/wfd_aac_decoder/helix_aac_decode.c548
-rw-r--r--audio_codec/wfd_aac_decoder/huffman.c450
-rw-r--r--audio_codec/wfd_aac_decoder/hufftabs.c177
-rw-r--r--audio_codec/wfd_aac_decoder/imdct.c596
-rw-r--r--audio_codec/wfd_aac_decoder/noiseless.c513
-rw-r--r--audio_codec/wfd_aac_decoder/pns.c371
-rw-r--r--audio_codec/wfd_aac_decoder/sbr.c434
-rw-r--r--audio_codec/wfd_aac_decoder/sbr.h380
-rw-r--r--audio_codec/wfd_aac_decoder/sbrfft.c368
-rw-r--r--audio_codec/wfd_aac_decoder/sbrfreq.c673
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhfadj.c882
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhfgen.c655
-rw-r--r--audio_codec/wfd_aac_decoder/sbrhuff.c494
-rw-r--r--audio_codec/wfd_aac_decoder/sbrimdct.c447
-rw-r--r--audio_codec/wfd_aac_decoder/sbrmath.c198
-rw-r--r--audio_codec/wfd_aac_decoder/sbrqmf.c648
-rw-r--r--audio_codec/wfd_aac_decoder/sbrside.c634
-rw-r--r--audio_codec/wfd_aac_decoder/sbrtabs.c400
-rw-r--r--audio_codec/wfd_aac_decoder/statname.h115
-rw-r--r--audio_codec/wfd_aac_decoder/stproc.c251
-rw-r--r--audio_codec/wfd_aac_decoder/tns.c307
-rw-r--r--audio_codec/wfd_aac_decoder/trigtabs.c1000
-rw-r--r--audio_codec/wfd_aac_decoder/trigtabs_fltgen.c357
545 files changed, 230976 insertions, 0 deletions
diff --git a/audio_codec/libcook/ra_depack_internal.c b/audio_codec/libcook/ra_depack_internal.c
new file mode 100644
index 0000000..d889cbc
--- a/dev/null
+++ b/audio_codec/libcook/ra_depack_internal.c
@@ -0,0 +1,1710 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <memory.h>
+#include "helix_types.h"
+#include "helix_result.h"
+#include "pack_utils.h"
+#include "string_utils.h"
+#include "memory_utils.h"
+#include "packet_defines.h"
+#include "codec_defines.h"
+#include "stream_hdr_utils.h"
+#include "ra_depack_internal.h"
+#include "rasl.h"
+
+/* Defines */
+#define TIMESTAMP_GAP_FUDGE_FACTOR 1 /* Maximum non-loss, non-seek gap in ms between packets */
+#define INITIAL_FRAG_BUFFER_SIZE 2048 /* Initial size of frag buffer */
+#define RA_COPY_BUF 0
+
+void* ra_depacki_malloc(ra_depack_internal* pInt, UINT32 ulSize)
+{
+ void* pRet = HXNULL;
+
+ if (pInt && pInt->fpMalloc) {
+ pRet = pInt->fpMalloc(pInt->pUserMem, ulSize);
+ }
+
+ return pRet;
+}
+
+void ra_depacki_free(ra_depack_internal* pInt, void* pMem)
+{
+ if (pInt && pInt->fpFree) {
+ pInt->fpFree(pInt->pUserMem, pMem);
+ }
+}
+
+HX_RESULT ra_depacki_init(ra_depack_internal* pInt, rm_stream_header* hdr)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && hdr) {
+ /* Initialize local variables */
+ UINT32 ulTmp = 0;
+ BYTE* pTmp = HXNULL;
+ /* Check if we have a "HasRelativeTS" property - OK if we don't */
+ if (HX_SUCCEEDED(rm_stream_get_property_int(hdr, "TrackStartTime", &ulTmp))) {
+ pInt->bForceTrackStartTime = TRUE;
+ pInt->ulTrackStartTime = ulTmp;
+ }
+ /* Check if we have a "ZeroTimeOffset" property - OK if we don't */
+ if (HX_SUCCEEDED(rm_stream_get_property_int(hdr, "TrackEndTime", &ulTmp))) {
+ pInt->bForceTrackEndTime = TRUE;
+ pInt->ulTrackEndTime = ulTmp;
+ }
+ /* Check if we have an EndTime property */
+ if (HX_SUCCEEDED(rm_stream_get_property_int(hdr, "EndTime", &ulTmp))) {
+ pInt->bHasEndTime = TRUE;
+ pInt->ulEndTime = ulTmp;
+ }
+ /* Copy the stream duration */
+ pInt->ulStreamDuration = hdr->ulDuration;
+ /* If we have an end time, then clip the duration */
+ if (pInt->bHasEndTime &&
+ pInt->ulEndTime &&
+ pInt->ulStreamDuration > pInt->ulEndTime) {
+ pInt->ulStreamDuration = pInt->ulEndTime;
+ }
+ if (pInt->ulStreamDuration == 0) {
+ pInt->ulStreamDuration = 0x7fffffff;
+ }
+ /* Check if we have a "RMFF 1.0 Flags" property */
+ retVal = rm_stream_get_property_buf(hdr, "RMFF 1.0 Flags", &pTmp, &ulTmp);
+ if (retVal == HXR_OK) {
+ /* Parse the "RMFF 1.0 Flags" property */
+ retVal = ra_depacki_unpack_rule_map(pInt, &pInt->rule2Flag,
+ &pTmp, &ulTmp);
+ if (retVal == HXR_OK) {
+ /* Get the "OpaqueData" property */
+ retVal = rm_stream_get_property_buf(hdr, "OpaqueData", &pTmp, &ulTmp);
+ if (retVal == HXR_OK) {
+ /* Unpack the opaque data */
+ retVal = ra_depacki_unpack_opaque_data(pInt, pTmp, ulTmp);
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_unpack_rule_map(ra_depack_internal* pInt,
+ rm_rule_map* pMap,
+ BYTE** ppBuf,
+ UINT32* pulLen)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt) {
+ retVal = rm_unpack_rule_map(ppBuf, pulLen,
+ pInt->fpMalloc,
+ pInt->fpFree,
+ pInt->pUserMem,
+ pMap);
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_unpack_multistream_hdr(ra_depack_internal* pInt,
+ BYTE** ppBuf,
+ UINT32* pulLen)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt) {
+ retVal = rm_unpack_multistream_hdr(ppBuf, pulLen,
+ pInt->fpMalloc,
+ pInt->fpFree,
+ pInt->pUserMem,
+ &pInt->multiStreamHdr);
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_unpack_opaque_data(ra_depack_internal* pInt,
+ BYTE* pBuf,
+ UINT32 ulLen)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pBuf && ulLen >= 4) {
+ /* Initialize local variables */
+ UINT32 ulSize = 0;
+ UINT32 ulID = 0;
+ UINT32 i = 0;
+ UINT32 ulTmp = 0;
+ /*
+ * If the first four bytes are MLTI, then we
+ * know the opaque data contains a multistream header
+ * followed by several normal headers. So first we
+ * need to check the first four bytes.
+ */
+ ulID = rm_unpack32(&pBuf, &ulLen);
+ /* Now back up 4 bytes */
+ pBuf -= 4;
+ ulLen += 4;
+ /* Is this a multistream header? */
+ if (ulID == RM_MULTIHEADER_OBJECT) {
+ /* Unpack the multistream header */
+ retVal = ra_depacki_unpack_multistream_hdr(pInt, &pBuf, &ulLen);
+ if (retVal == HXR_OK) {
+ pInt->bStreamSwitchable = TRUE;
+ }
+ } else if (ulID == RA_FORMAT_ID) {
+ /* Single-rate stream */
+ pInt->multiStreamHdr.ulNumSubStreams = 1;
+ /* Clear the stream switchable flag */
+ pInt->bStreamSwitchable = FALSE;
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ /* Clean up any existing substream header array */
+ ra_depacki_cleanup_substream_hdr_array(pInt);
+ /* Set the return value */
+ retVal = HXR_FAIL;
+ /* Allocate space for substream header array */
+ ulSize = pInt->multiStreamHdr.ulNumSubStreams * sizeof(ra_substream_hdr);
+ pInt->pSubStreamHdr = (ra_substream_hdr*) ra_depacki_malloc(pInt, ulSize);
+ if (pInt->pSubStreamHdr) {
+ /* NULL out the memory */
+ memset(pInt->pSubStreamHdr, 0, ulSize);
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* Loop through and unpack each substream header */
+ for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams && retVal == HXR_OK; i++) {
+ /* Is this a multiheader? */
+ if (pInt->bStreamSwitchable) {
+ /*
+ * If this is a multistream header, then there
+ * is a 4-byte length in front of every substream header
+ */
+ if (ulLen >= 4) {
+ ulSize = rm_unpack32(&pBuf, &ulLen);
+ } else {
+ retVal = HXR_FAIL;
+ }
+ } else {
+ /*
+ * If this is not a multi-stream header, then
+ * the rest of the buffer is a single substream header
+ */
+ ulSize = ulLen;
+ }
+ /* Make sure we have enough parsing buffer */
+ if (ulLen >= ulSize) {
+ /* Now unpack an substream header */
+ retVal = ra_depacki_unpack_substream_hdr(pInt, pBuf, ulSize,
+ &pInt->pSubStreamHdr[i]);
+ if (retVal == HXR_OK) {
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[i];
+ /*
+ * If the interleaver ID is either VBRS of VBRF,
+ * then this is a VBR stream.
+ */
+ if (pHdr->ulInterleaverID == RA_INTERLEAVER_VBRS ||
+ pHdr->ulInterleaverID == RA_INTERLEAVER_VBRF) {
+ pHdr->bIsVBR = TRUE;
+ }
+ /* Compute the number of codec frames per superblock */
+ if (pHdr->ulCodecFrameSize) {
+ pHdr->ulNumCodecFrames = pHdr->ulInterleaveBlockSize *
+ pHdr->ulInterleaveFactor /
+ pHdr->ulCodecFrameSize;
+ }
+ /* Compute the ms per block */
+ if (pHdr->ulBytesPerMin) {
+ pHdr->dBlockDuration = ((double) pHdr->ulInterleaveBlockSize) *
+ 60000.0 /
+ ((double) pHdr->ulBytesPerMin);
+ }
+ /* Compute the superblock size and time */
+ pHdr->ulSuperBlockSize = pHdr->ulInterleaveBlockSize *
+ pHdr->ulInterleaveFactor;
+ pHdr->ulSuperBlockTime = (UINT32)(pHdr->dBlockDuration *
+ ((double) pHdr->ulInterleaveFactor));
+ /* Is this stream VBR? */
+ if (pHdr->bIsVBR) {
+ /* Init the last sent block end time */
+ pHdr->ulLastSentEndTime = 0;
+ /*
+ * Init the frag buffer members. The frag buffer
+ * willl be set up the first time it is needed.
+ */
+ pHdr->pFragBuffer = HXNULL;
+ pHdr->ulFragBufferSize = 0;
+ pHdr->ulFragBufferOffset = 0;
+ pHdr->ulFragBufferTime = 0;
+ } else {
+ /* Set the return value */
+ retVal = HXR_OUTOFMEMORY;
+ /* Set the superblock keyframe time */
+ pHdr->bHasKeyTime = FALSE;
+ pHdr->ulKeyTime = 0;
+ /* Allocate the interleaved buffer */
+ pHdr->pIBuffer = (BYTE*) ra_depacki_malloc(pInt, pHdr->ulSuperBlockSize);
+ if (pHdr->pIBuffer) {
+ /* Zero out the buffer */
+ memset(pHdr->pIBuffer, 0, pHdr->ulSuperBlockSize);
+ /* Allocate the de-interleaved buffer */
+ pHdr->pDBuffer = (BYTE*) ra_depacki_malloc(pInt, pHdr->ulSuperBlockSize);
+ if (pHdr->pDBuffer) {
+ /* Zero out the buffer */
+ memset(pHdr->pDBuffer, 0, pHdr->ulSuperBlockSize);
+ /* Allocate the interleaved flags */
+ ulTmp = pHdr->ulInterleaveFactor * sizeof(UINT32);
+ pHdr->pIPresentFlags = (UINT32*) ra_depacki_malloc(pInt, ulTmp);
+ if (pHdr->pIPresentFlags) {
+ /* Zero out the flags */
+ memset(pHdr->pIPresentFlags, 0, ulTmp);
+ /* Allocate the de-interleaved flags */
+ pHdr->pDPresentFlags = (UINT32*) ra_depacki_malloc(pInt, ulTmp);
+ if (pHdr->pDPresentFlags) {
+ /* Null out the memory */
+ memset(pHdr->pDPresentFlags, 0, ulTmp);
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* If this is GENR interleaving, then init the tables */
+ if (pHdr->ulInterleaverID == RA_INTERLEAVER_GENR) {
+ retVal = ra_depacki_init_genr(pInt, i);
+ }
+ }
+ }
+ }
+ }
+ }
+ /* Update the buffer cursors */
+ pBuf += ulSize;
+ ulLen -= ulSize;
+ }
+ } else {
+ retVal = HXR_FAIL;
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+void ra_depacki_cleanup_substream_hdr(ra_depack_internal* pInt,
+ ra_substream_hdr* hdr)
+{
+ if (pInt && hdr) {
+ if (hdr->pulInterleavePattern) {
+ ra_depacki_free(pInt, hdr->pulInterleavePattern);
+ hdr->pulInterleavePattern = HXNULL;
+ }
+ if (hdr->pOpaqueData) {
+ ra_depacki_free(pInt, hdr->pOpaqueData);
+ hdr->pOpaqueData = HXNULL;
+ }
+ if (hdr->pFragBuffer) {
+ ra_depacki_free(pInt, hdr->pFragBuffer);
+ hdr->pFragBuffer = HXNULL;
+ }
+ if (hdr->pIBuffer) {
+ ra_depacki_free(pInt, hdr->pIBuffer);
+ hdr->pIBuffer = HXNULL;
+ }
+ if (hdr->pDBuffer) {
+ ra_depacki_free(pInt, hdr->pDBuffer);
+ hdr->pDBuffer = HXNULL;
+ }
+ if (hdr->pIPresentFlags) {
+ ra_depacki_free(pInt, hdr->pIPresentFlags);
+ hdr->pIPresentFlags = HXNULL;
+ }
+ if (hdr->pDPresentFlags) {
+ ra_depacki_free(pInt, hdr->pDPresentFlags);
+ hdr->pDPresentFlags = HXNULL;
+ }
+ if (hdr->pulGENRPattern) {
+ ra_depacki_free(pInt, hdr->pulGENRPattern);
+ hdr->pulGENRPattern = HXNULL;
+ }
+ if (hdr->pulGENRBlockNum) {
+ ra_depacki_free(pInt, hdr->pulGENRBlockNum);
+ hdr->pulGENRBlockNum = HXNULL;
+ }
+ if (hdr->pulGENRBlockOffset) {
+ ra_depacki_free(pInt, hdr->pulGENRBlockOffset);
+ hdr->pulGENRBlockOffset = HXNULL;
+ }
+ }
+}
+
+void ra_depacki_cleanup_substream_hdr_array(ra_depack_internal* pInt)
+{
+ if (pInt && pInt->pSubStreamHdr) {
+ UINT32 i = 0;
+ for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams; i++) {
+ ra_depacki_cleanup_substream_hdr(pInt, &pInt->pSubStreamHdr[i]);
+ }
+ /* Free the header array */
+ ra_depacki_free(pInt, pInt->pSubStreamHdr);
+ /* NULL out the pointer */
+ pInt->pSubStreamHdr = HXNULL;
+ }
+}
+
+HX_RESULT ra_depacki_unpack_substream_hdr(ra_depack_internal* pInt,
+ BYTE* pBuf,
+ UINT32 ulLen,
+ ra_substream_hdr* pHdr)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pBuf && ulLen >= 6 && pHdr) {
+ UINT32 ulID = 0;
+ UINT16 usVersion = 0;
+ /* Clean up any existing header info */
+ ra_depacki_cleanup_substream_hdr(pInt, pHdr);
+ /* Read the ID and the RAFormat version */
+ ulID = rm_unpack32(&pBuf, &ulLen);
+ usVersion = rm_unpack16(&pBuf, &ulLen);
+ /* Sanity check on ID */
+ if (ulID == RA_FORMAT_ID) {
+ /* Switch based on RAFormat version */
+ switch (usVersion) {
+ case 3:
+ retVal = ra_depacki_unpack_raformat3(pInt, pBuf, ulLen, pHdr);
+ break;
+ case 4:
+ retVal = ra_depacki_unpack_raformat4(pInt, pBuf, ulLen, pHdr);
+ break;
+ case 5:
+ retVal = ra_depacki_unpack_raformat5(pInt, pBuf, ulLen, pHdr);
+ break;
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_unpack_raformat3(ra_depack_internal* pInt,
+ BYTE* pBuf,
+ UINT32 ulLen,
+ ra_substream_hdr* pHdr)
+{
+ return HXR_NOTIMPL;
+}
+
+HX_RESULT ra_depacki_unpack_raformat4(ra_depack_internal* pInt,
+ BYTE* pBuf,
+ UINT32 ulLen,
+ ra_substream_hdr* pHdr)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pBuf && ulLen >= 63 && pHdr) {
+ /* Skip first 10 bytes */
+ pBuf += 10;
+ ulLen -= 10;
+ /* Read the version and revision */
+ pHdr->usRAFormatVersion = rm_unpack16(&pBuf, &ulLen);
+ pHdr->usRAFormatRevision = rm_unpack16(&pBuf, &ulLen);
+ /* Sanity check */
+ if (pHdr->usRAFormatVersion == 4 &&
+ pHdr->usRAFormatRevision == 0) {
+ pHdr->usHeaderBytes = rm_unpack16(&pBuf, &ulLen);
+ pHdr->usFlavorIndex = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulGranularity = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulTotalBytes = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulBytesPerMin = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulBytesPerMin2 = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulInterleaveFactor = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulInterleaveBlockSize = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulUserData = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulSampleRate = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulSampleRate >>= 16;
+ pHdr->ulSampleSize = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulChannels = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulInterleaverID = rm_unpack32_from_byte_string(&pBuf, &ulLen);
+ pHdr->ulCodecID = rm_unpack32_from_byte_string(&pBuf, &ulLen);
+ pHdr->bIsInterleaved = rm_unpack8(&pBuf, &ulLen);
+ pHdr->bCopyByte = rm_unpack8(&pBuf, &ulLen);
+ pHdr->ucStreamType = rm_unpack8(&pBuf, &ulLen);
+ /*
+ * If the bIsInterleaved flag says we are
+ * not interleaved, then make sure the
+ * interleaverID is set to no interleaver.
+ */
+ if (!pHdr->bIsInterleaved) {
+ pHdr->ulInterleaverID = RA_NO_INTERLEAVER;
+ }
+ /* If the interleave factor is 0, make it 1. */
+ if (!pHdr->ulInterleaveFactor) {
+ pHdr->ulInterleaveFactor = 1;
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_unpack_raformat5(ra_depack_internal* pInt,
+ BYTE* pBuf,
+ UINT32 ulLen,
+ ra_substream_hdr* pHdr)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pBuf && ulLen >= 68 && pHdr) {
+ /* Init local variables */
+ UINT32 ulSize = 0;
+ UINT32 i = 0;
+ /* Skip first 10 bytes */
+ pBuf += 10;
+ ulLen -= 10;
+ /* Read the version and revision */
+ pHdr->usRAFormatVersion = rm_unpack16(&pBuf, &ulLen);
+ pHdr->usRAFormatRevision = rm_unpack16(&pBuf, &ulLen);
+ /* Sanity check */
+ if (pHdr->usRAFormatVersion == 5 &&
+ pHdr->usRAFormatRevision == 0) {
+ pHdr->usHeaderBytes = rm_unpack16(&pBuf, &ulLen);
+ pHdr->usFlavorIndex = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulGranularity = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulTotalBytes = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulBytesPerMin = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulBytesPerMin2 = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulInterleaveFactor = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulInterleaveBlockSize = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulCodecFrameSize = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulUserData = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulSampleRate = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulSampleRate >>= 16;
+ pHdr->ulActualSampleRate = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulActualSampleRate >>= 16;
+ pHdr->ulSampleSize = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulChannels = rm_unpack16(&pBuf, &ulLen);
+ pHdr->ulInterleaverID = rm_unpack32(&pBuf, &ulLen);
+ pHdr->ulCodecID = rm_unpack32(&pBuf, &ulLen);
+ pHdr->bIsInterleaved = rm_unpack8(&pBuf, &ulLen);
+ pHdr->bCopyByte = rm_unpack8(&pBuf, &ulLen);
+ pHdr->ucStreamType = rm_unpack8(&pBuf, &ulLen);
+ pHdr->ucScatterType = rm_unpack8(&pBuf, &ulLen);
+ pHdr->ulNumCodecFrames = pHdr->ulInterleaveFactor *
+ pHdr->ulInterleaveBlockSize /
+ pHdr->ulCodecFrameSize;
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /*
+ * If ucScatterType is non-zero, then we have
+ * to read in an interleave pattern.
+ */
+ if (pHdr->ucScatterType) {
+ /* Set the return value */
+ retVal = HXR_FAIL;
+ /* Allocate space for the interleave pattern */
+ ulSize = pHdr->ulNumCodecFrames * sizeof(UINT32);
+ pHdr->pulInterleavePattern = ra_depacki_malloc(pInt, ulSize);
+ if (pHdr->pulInterleavePattern) {
+ /* NULL out all the memory */
+ memset(pHdr->pulInterleavePattern, 0, ulSize);
+ /* Make sure we have enough parsing buffer left */
+ if (ulLen >= ulSize) {
+ /* Read in the interleave pattern */
+ for (i = 0; i < pHdr->ulNumCodecFrames; i++) {
+ pHdr->pulInterleavePattern[i] = rm_unpack16(&pBuf, &ulLen);
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+ }
+ if (retVal == HXR_OK) {
+ /* Set the return value */
+ retVal = HXR_FAIL;
+ /* Make sure we have four bytes */
+ if (ulLen >= 4) {
+ /* Read in the opaque data size */
+ pHdr->ulOpaqueDataSize = rm_unpack32(&pBuf, &ulLen);
+ /* Make sure we have this much parsing space left */
+ if ((ulLen >= pHdr->ulOpaqueDataSize) && (pHdr->ulOpaqueDataSize > 0)) {
+ /* Allocate the buffer */
+ pHdr->pOpaqueData = ra_depacki_malloc(pInt, pHdr->ulOpaqueDataSize);
+ if (pHdr->pOpaqueData) {
+ /* Copy the opaque data */
+ memcpy(pHdr->pOpaqueData, pBuf, pHdr->ulOpaqueDataSize);
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /*
+ * If the bIsInterleaved flag says we are
+ * not interleaved, then make sure the
+ * interleaverID is set to no interleaver.
+ */
+ if (!pHdr->bIsInterleaved) {
+ pHdr->ulInterleaverID = RA_NO_INTERLEAVER;
+ }
+ /* If the interleave factor is 0, make it 1. */
+ if (!pHdr->ulInterleaveFactor) {
+ pHdr->ulInterleaveFactor = 1;
+ }
+ }
+ } else if (pHdr->ulOpaqueDataSize == 0) {
+ retVal = HXR_OK;
+ }
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_get_format_info(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ ra_format_info* pInfo)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInfo && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init local variables */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ if (pHdr) {
+ /* Clean up any existing format info */
+ ra_depacki_cleanup_format_info(pInt, pInfo);
+ /* Assign members */
+ pInfo->ulSampleRate = pHdr->ulSampleRate;
+ pInfo->ulActualRate = pHdr->ulActualSampleRate;
+ pInfo->usBitsPerSample = (UINT16) pHdr->ulSampleSize;
+ pInfo->usNumChannels = (UINT16) pHdr->ulChannels;
+ pInfo->usAudioQuality = 100;
+ pInfo->usFlavorIndex = pHdr->usFlavorIndex;
+ pInfo->ulBitsPerFrame = pHdr->ulCodecFrameSize;
+ pInfo->ulGranularity = pHdr->ulGranularity;
+ pInfo->ulOpaqueDataSize = pHdr->ulOpaqueDataSize;
+ /* Copy the opaque data buffer */
+ pInfo->pOpaqueData = copy_buffer(pInt->pUserMem,
+ pInt->fpMalloc,
+ pHdr->pOpaqueData,
+ pHdr->ulOpaqueDataSize);
+ if (!pInfo->ulOpaqueDataSize || pInfo->pOpaqueData) {
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+ }
+
+ return retVal;
+}
+
+void ra_depacki_cleanup_format_info(ra_depack_internal* pInt,
+ ra_format_info* pInfo)
+{
+ if (pInt && pInfo && pInfo->pOpaqueData) {
+ ra_depacki_free(pInt, pInfo->pOpaqueData);
+ pInfo->pOpaqueData = HXNULL;
+ }
+}
+
+UINT32 ra_depacki_rule_to_flags(ra_depack_internal* pInt, UINT32 ulRule)
+{
+ UINT32 ulRet = 0;
+
+ if (pInt && pInt->rule2Flag.pulMap &&
+ ulRule < pInt->rule2Flag.ulNumRules) {
+ ulRet = pInt->rule2Flag.pulMap[ulRule];
+ }
+
+ return ulRet;
+}
+
+HXBOOL ra_depacki_is_keyframe_rule(ra_depack_internal* pInt, UINT32 ulRule)
+{
+ UINT32 ulFlag = ra_depacki_rule_to_flags(pInt, ulRule);
+ return (ulFlag & HX_KEYFRAME_FLAG ? TRUE : FALSE);
+}
+
+UINT32 ra_depacki_rule_to_substream(ra_depack_internal* pInt, UINT32 ulRule)
+{
+ UINT32 ulRet = 0;
+
+ if (pInt && pInt->multiStreamHdr.rule2SubStream.pulMap &&
+ ulRule < pInt->multiStreamHdr.rule2SubStream.ulNumRules) {
+ ulRet = pInt->multiStreamHdr.rule2SubStream.pulMap[ulRule];
+ }
+
+ return ulRet;
+}
+
+HX_RESULT ra_depacki_add_packet(ra_depack_internal* pInt,
+ rm_packet* pPacket)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pPacket) {
+ /* Init local variables */
+ UINT32 i = 0;
+ /* Was this packet lost? */
+ if (!pPacket->ucLost) {
+ /* This packet was not lost, so we can look up the substream. */
+ UINT32 ulSubStream = ra_depacki_rule_to_substream(pInt, pPacket->ucASMRule);
+ /* Sanity check */
+ if (pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Is this substream VBR? */
+ if (pInt->pSubStreamHdr[ulSubStream].bIsVBR) {
+ /* Add the VBR packet */
+ retVal = ra_depacki_add_vbr_packet(pInt, ulSubStream, pPacket);
+ } else {
+ /* Add the non-VBR packet */
+ retVal = ra_depacki_add_non_vbr_packet(pInt, ulSubStream, pPacket);
+ }
+ }
+ } else {
+ /* Are we multistream or single-stream? */
+ if (pInt->bStreamSwitchable) {
+ /*
+ * We are multi-stream. Therefore, we don't know which
+ * substream this packet came from. So we simply set the
+ * flag saying some loss happened in each substream.
+ */
+ for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams; i++) {
+ pInt->pSubStreamHdr[i].bLossOccurred = TRUE;
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ } else {
+ /*
+ * We are single substream, so we just pass the
+ * lost packet on. It has to be substream 0, of course.
+ */
+ if (pInt->pSubStreamHdr &&
+ pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Is the single substream VBR? */
+ if (pInt->pSubStreamHdr[0].bIsVBR) {
+ retVal = ra_depacki_add_vbr_packet(pInt, 0, pPacket);
+ } else {
+ retVal = ra_depacki_add_non_vbr_packet(pInt, 0, pPacket);
+ }
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_add_vbr_packet(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ rm_packet* pPacket)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pPacket) {
+ /* Is the packet lost? */
+ if (!pPacket->ucLost) {
+ /* Packet was not lost */
+ if (pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Init local variables */
+ UINT32 ulNumAU = 0;
+ HXBOOL bFrag = FALSE;
+ UINT32 ulAUSize = 0;
+ UINT32 ulAUFragSize = 0;
+ /* Parse this VBR packet */
+ retVal = ra_depacki_parse_vbr_packet(pInt, pPacket, &ulNumAU, &bFrag,
+ &ulAUSize, &ulAUFragSize);
+ if (retVal == HXR_OK) {
+ /*
+ * Are we within the tolerance? We expect to
+ * be if we didn't seek. Otherwise, we had loss.
+ */
+ if (pPacket->ulTime > pHdr->ulLastSentEndTime + TIMESTAMP_GAP_FUDGE_FACTOR &&
+ !pHdr->bSeeked) {
+ /* We need to send some loss packets */
+ retVal = ra_depacki_generate_and_send_loss(pInt,
+ ulSubStream,
+ pHdr->ulLastSentEndTime,
+ pPacket->ulTime);
+ if (retVal == HXR_OK) {
+ pHdr->ulLastSentEndTime = pPacket->ulTime;
+ }
+ }
+ /* Have we just seeked? */
+ if (pHdr->bSeeked) {
+ /* Clear any remaining fragment */
+ ra_depacki_clear_frag_buffer(pInt, pHdr);
+ /* Set the last sent time to this time */
+ pHdr->ulLastSentEndTime = pPacket->ulTime;
+ /* Clear the seeked flag */
+ pHdr->bSeeked = FALSE;
+ }
+ /* Does this packet hold a fragmented AU? */
+ if (bFrag) {
+ /* Handle the fragmented packet */
+ retVal = ra_depacki_handle_frag_packet(pInt, ulSubStream, pPacket,
+ ulAUSize, ulAUFragSize);
+ } else {
+ /* Handle the non-fragmented packet */
+ retVal = ra_depacki_handle_nonfrag_packet(pInt, ulSubStream,
+ pPacket, ulNumAU);
+ }
+ }
+ }
+ } else {
+ /* Packet is lost - not an error */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_add_non_vbr_packet(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ rm_packet* pPacket)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pPacket && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init local variables */
+ HXBOOL bKey = FALSE;
+ HXDOUBLE dTimeDiff = 0.0;
+ HXDOUBLE dBlockNum = 0;
+ UINT32 ulBlockNum = 0;
+ HXDOUBLE dTSOffset = 0.0;
+ UINT32 ulTSOffset = 0;
+ UINT32 ulPacketTime = pPacket->ulTime;
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Is the packet lost? */
+ if (!pPacket->ucLost) {
+ /* Is this a keyframe packet? */
+ bKey = ra_depacki_is_keyframe_rule(pInt, pPacket->ucASMRule);
+ /*
+ * We need to determine the index of this block
+ * in this superblock. We will do this by knowing
+ * the timestamp of this packet (block), the timestamp
+ * of the key block in this superblock, and the block
+ * duration. First we make sure we have a key block time.
+ */
+ if (bKey && !pHdr->bHasKeyTime) {
+ /* We note the timestamp of this key block */
+ pHdr->ulKeyTime = pPacket->ulTime;
+ /* Set the flag saying we have a key time */
+ pHdr->bHasKeyTime = TRUE;
+ }
+ /* Now we should have a key time */
+ if (pHdr->bHasKeyTime && ulPacketTime >= pHdr->ulKeyTime) {
+ /*
+ * Have we yet determined whether or
+ * not we need to adjust timestamps?
+ */
+ if (!pHdr->bKnowIfAdjustNeeded) {
+ /*
+ * If the last packet was not lost and was a
+ * keyframe and this packet is not a keyframe
+ * and the timestamps are the same, then we need
+ * to adjust timestamps.
+ */
+ if (pHdr->bHasLastPacket &&
+ !pHdr->lastPacket.ucLost &&
+ !bKey) {
+ /* Is this timestamp the same as the last packets? */
+ if (ulPacketTime == pHdr->lastPacket.ulTime) {
+ pHdr->bAdjustTimestamps = TRUE;
+ } else {
+ pHdr->bAdjustTimestamps = FALSE;
+ }
+ /* Now we know */
+ pHdr->bKnowIfAdjustNeeded = TRUE;
+ }
+ }
+ /* Do we need to adjust timestamps? */
+ if (pHdr->bKnowIfAdjustNeeded &&
+ pHdr->bAdjustTimestamps &&
+ !bKey) {
+ dTSOffset = pHdr->ulBlockCount * pHdr->dBlockDuration;
+ ulTSOffset = (UINT32)(dTSOffset + 0.5);
+ ulPacketTime += ulTSOffset;
+ }
+ /* Compute the index of the block within the superblock */
+ dTimeDiff = (HXDOUBLE)(ulPacketTime - pHdr->ulKeyTime);
+#ifndef __ARC600__
+ if (pHdr->dBlockDuration)
+#else
+ if (pHdr->dBlockDuration == 0.0) {
+ ;
+ } else
+#endif
+
+ {
+ dBlockNum = dTimeDiff / pHdr->dBlockDuration;
+ }
+ ulBlockNum = (UINT32)(dBlockNum + 0.5);
+ /* Is this block beyond our superblock? */
+ if (ulBlockNum >= pHdr->ulInterleaveFactor) {
+ /*
+ * We must have had loss at the end of the
+ * previous superblock, since we have received
+ * a packet in the next superblock without having
+ * sent the current superblock. Therefore, we attempt
+ * to finish out the current superblock and send it.
+ */
+ retVal = ra_depacki_deinterleave_send(pInt, ulSubStream);
+ if (retVal == HXR_OK) {
+ /* Now we need to update the block index */
+ if (bKey) {
+ /*
+ * This packet is a keyframe packet, so
+ * we simply assign the new time and set
+ * the block index to 0.
+ */
+ pHdr->ulKeyTime = pPacket->ulTime;
+ ulBlockNum = 0;
+ } else {
+ /*
+ * This is not a keyframe packet, so we need to
+ * keep adding the superblock time to the key time
+ * and keep subtracting interleave factor to the block
+ * index until we reach the range [0,intereaveFactor-1]
+ * for the index.
+ */
+ do {
+ pHdr->ulKeyTime += pHdr->ulSuperBlockTime;
+ ulBlockNum -= pHdr->ulInterleaveFactor;
+ } while (ulBlockNum < pHdr->ulInterleaveFactor);
+ }
+ }
+ }
+ /* Sanity check on buffer copy parameters */
+ if (ulBlockNum < pHdr->ulInterleaveFactor &&
+ ((UINT32) pPacket->usDataLen) == pHdr->ulInterleaveBlockSize &&
+ pHdr->pIPresentFlags) {
+ /* Copy the data into the interleave buffer */
+ memcpy(pHdr->pIBuffer + ulBlockNum * pHdr->ulInterleaveBlockSize,
+ pPacket->pData,
+ pHdr->ulInterleaveBlockSize);
+ /* Set all the flags to be present for this block */
+ pHdr->pIPresentFlags[ulBlockNum] = 0xFFFFFFFF;
+ /* Increment the block count in this superblock */
+ pHdr->ulBlockCount++;
+ /* Is this the last block in the superblock? */
+ if (ulBlockNum == pHdr->ulInterleaveFactor - 1) {
+ /* Deinterleave and send the blocks */
+ retVal = ra_depacki_deinterleave_send(pInt, ulSubStream);
+ } else {
+ /* Not ready to send yet. Clear the return */
+ retVal = HXR_OK;
+ }
+ }
+ } else {
+ /*
+ * We don't have a key block time or the key block time
+ * that we have is greater than the packet time, so we
+ * can't compute what slot this block should be in. This
+ * probably occurred because of loss at the beginning of the
+ * stream. We have to throw this packet away.
+ */
+ retVal = HXR_OK;
+ }
+ } else {
+ /*
+ * The packet was lost. For now, don't do anything
+ * with the packet. We will deduce loss based entirely
+ * on timestamps for now.
+ */
+ retVal = HXR_OK;
+ }
+ /* Save the information about the last packet */
+ pHdr->lastPacket.ulTime = pPacket->ulTime;
+ pHdr->lastPacket.usStream = pPacket->usStream;
+ pHdr->lastPacket.usASMFlags = pPacket->usASMFlags;
+ pHdr->lastPacket.ucASMRule = pPacket->ucASMRule;
+ pHdr->lastPacket.ucLost = pPacket->ucLost;
+ pHdr->bHasLastPacket = TRUE;
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_parse_vbr_packet(ra_depack_internal* pInt,
+ rm_packet* pPacket,
+ UINT32* pulNumAU,
+ HXBOOL* pbFragmented,
+ UINT32* pulAUSize,
+ UINT32* pulAUFragSize)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pPacket && pulNumAU && pbFragmented &&
+ pulAUSize && pulAUFragSize &&
+ pPacket->pData && pPacket->usDataLen) {
+ /* Init local variables */
+ BYTE* pBuf = pPacket->pData;
+ UINT32 ulSize = pPacket->usDataLen;
+ UINT32 ulPacketSize = ulSize;
+ UINT32 ulAUHeaderSizeBits = 0;
+ UINT32 ulAUHeaderSize = 0;
+ UINT32 ulNumAU = 0;
+ UINT32 ulAUSize = 0;
+ UINT32 ulAUSizeTotal = 0;
+ UINT32 i = 0;
+ UINT32 ulExpectedSize = 0;
+ /* Sanity check on size */
+ if (ulSize >= 2) {
+ /* Get the AU header size in bits */
+ ulAUHeaderSizeBits = rm_unpack16(&pBuf, &ulSize);
+ /* Convert to bytes (rounding up to next byte) */
+ ulAUHeaderSize = (ulAUHeaderSizeBits + 7) >> 3;
+ /*
+ * Sanity check to make sure that the AU header size is
+ * greater than 0 and a multiple of 2 bytes
+ */
+ if (ulAUHeaderSize && !(ulAUHeaderSize & 1)) {
+ /*
+ * Since we know that each AU header is 2 bytes, then
+ * we know that the number of AU's in this packet is
+ * ulAUHeaderSize / 2.
+ */
+ ulNumAU = ulAUHeaderSize >> 1;
+ /*
+ * The audio/mpeg-generic spec says that each packet
+ * can either have a complete AU, a fragment of a single
+ * AU, or multiple complete AUs. Therefore, if the
+ * number of AUs is greater than 1, then we know we
+ * have ulNumAU *complete* AUs. Therefore, for more
+ * than one AU, we know what the exact size of the
+ * packet should be, and that should match up with
+ * the data size of the packet.
+ */
+ retVal = HXR_OK;
+ for (i = 0; i < ulNumAU && retVal == HXR_OK; i++) {
+ if (ulSize >= 2) {
+ ulAUSize = rm_unpack16(&pBuf, &ulSize);
+ ulAUSizeTotal += ulAUSize;
+ } else {
+ retVal = HXR_FAIL;
+ }
+ }
+ if (retVal == HXR_OK) {
+ /* Compute the expected size of the packet */
+ ulExpectedSize = 2 + /* AU header size (16 bits) */
+ ulNumAU * 2 + /* AU sizes */
+ ulAUSizeTotal; /* the AU's themselves */
+ /*
+ * Check this against the actual size. If we have
+ * 1 AU, then the expected size can be greater than
+ * the actual size due to fragmentation. If we have
+ * more than more AU, then the expected size MUST
+ * match the actual size.
+ */
+ if (ulNumAU > 1) {
+ if (ulExpectedSize == ulPacketSize) {
+ /* Multiple AUs, no fragmentation */
+ *pbFragmented = FALSE;
+ } else {
+ /* Something wrong */
+ retVal = HXR_FAIL;
+ }
+ } else if (ulNumAU == 1) {
+ if (ulExpectedSize > ulPacketSize) {
+ /* Fragmented single AU */
+ *pbFragmented = TRUE;
+ } else {
+ /* Single AU, no fragmentation */
+ *pbFragmented = FALSE;
+ }
+ /* Set the AU size */
+ *pulAUSize = ulAUSizeTotal;
+ *pulAUFragSize = ulPacketSize - 4;
+ }
+ /* Assign the number of AU out parameter */
+ if (retVal == HXR_OK) {
+ *pulNumAU = ulNumAU;
+ }
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_generate_and_send_loss(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ UINT32 ulFirstStartTime,
+ UINT32 ulLastEndTime)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && ulSubStream < pInt->multiStreamHdr.ulNumSubStreams &&
+ ulLastEndTime > ulFirstStartTime) {
+ HXDOUBLE dAUDuration = pInt->pSubStreamHdr[ulSubStream].dBlockDuration;
+ HXDOUBLE dDiff = ulLastEndTime - ulFirstStartTime;
+ UINT32 ulNumLossPackets = 0;
+ UINT32 i = 0;
+ UINT32 ulTSOffset = 0;
+ UINT32 ulTime = 0;
+ /* Compute the number of packets */
+#ifndef __ARC600__
+ if (dAUDuration != 0.0)
+#else
+ if (dAUDuration == 0.0) {
+ ;
+ } else
+#endif
+ {
+ ulNumLossPackets = (UINT32)(dDiff / dAUDuration);
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* Generate loss packets */
+ for (i = 0; i < ulNumLossPackets && HX_SUCCEEDED(retVal); i++) {
+ ulTSOffset = (UINT32)(i * dAUDuration);
+ ulTime = ulFirstStartTime + ulTSOffset;
+ retVal = ra_depacki_send_block(pInt,
+ ulSubStream,
+ HXNULL,
+ 0,
+ ulTime,
+ 0); /* Flags of 0 indicate loss */
+ }
+ }
+
+ return retVal;
+}
+
+#if RA_COPY_BUF
+void ra_depacki_free_block(ra_block* pBlock)
+{
+ /* Free the data */
+ if (pBlock->pData) {
+ AVMem_free(pBlock->pData);
+ pBlock->pData = HXNULL;
+ }
+}
+#endif
+
+HX_RESULT ra_depacki_send_block(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ BYTE* pBuf,
+ UINT32 ulLen,
+ UINT32 ulTime,
+ UINT32 ulFlags)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->fpAvail) {
+ /* Allocate space for a ra_block structure */
+ ra_block Block;
+ memset(&Block, 0, sizeof(Block));
+ {
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* Copy the buffer */
+ if (pBuf && ulLen) {
+#if RA_COPY_BUF
+ Block.pData = copy_buffer(pInt->pUserMem,
+ pInt->fpMalloc,
+ pBuf, ulLen);
+ if (Block.pData) {
+ Block.ulDataLen = ulLen;
+ } else {
+ retVal = HXR_OUTOFMEMORY;
+ }
+#else
+ Block.pData = pBuf;
+ Block.ulDataLen = ulLen;
+#endif
+ }
+ if (retVal == HXR_OK) {
+ /* Assign the timestamp and flags */
+ Block.ulTimestamp = ulTime;
+ Block.ulDataFlags = ulFlags;
+ /* Send the block */
+ retVal = pInt->fpAvail(pInt->pAvail,
+ ulSubStream,
+ &Block);
+ }
+#if RA_COPY_BUF
+ ra_depacki_free_block(&Block);
+#endif
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_handle_frag_packet(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ rm_packet* pPacket,
+ UINT32 ulAUSize,
+ UINT32 ulAUFragSize)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr && pPacket &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ UINT32 ulPacketSize = (UINT32) pPacket->usDataLen;
+ UINT32 ulPacketOffset = (ulPacketSize >= ulAUFragSize ?
+ ulPacketSize - ulAUFragSize : 0);
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* Have we allocated the frag buffer yet? */
+ if (!pHdr->pFragBuffer) {
+ retVal = ra_depacki_init_frag_buffer(pInt, pHdr);
+ }
+ if (HX_SUCCEEDED(retVal)) {
+ /*
+ * Do we have a current fragment, and if so, is it
+ * a different timestamp from this fragment?
+ */
+ if (pHdr->bHasFrag && pHdr->ulFragBufferTime != pPacket->ulTime) {
+ /* Clear the frag buffer */
+ ra_depacki_clear_frag_buffer(pInt, pHdr);
+ }
+ /*
+ * Are we currently processing a fragment? If not,
+ * then initialize this fragment, resizing the
+ * buffer if necessary.
+ */
+ if (!pHdr->bHasFrag) {
+ /* Make sure the buffer size is big enough */
+ if (ulAUSize > pHdr->ulFragBufferSize) {
+ retVal = ra_depacki_resize_frag_buffer(pInt, pHdr, ulAUSize);
+ }
+ if (HX_SUCCEEDED(retVal)) {
+ /* Init the members for this fragment */
+ pHdr->ulFragBufferOffset = 0;
+ pHdr->ulFragBufferTime = pPacket->ulTime;
+ pHdr->ulFragBufferAUSize = ulAUSize;
+ pHdr->bHasFrag = TRUE;
+ }
+ }
+ if (HX_SUCCEEDED(retVal)) {
+ /* Make sure we have room for the memcpy */
+ if (pHdr->ulFragBufferOffset + ulAUFragSize <= pHdr->ulFragBufferSize &&
+ ulPacketOffset + ulAUFragSize <= ulPacketSize) {
+ /* Copy this buffer in */
+ memcpy(pHdr->pFragBuffer + pHdr->ulFragBufferOffset,
+ pPacket->pData + ulPacketOffset,
+ ulAUFragSize);
+ /* Update the frag buffer offset */
+ pHdr->ulFragBufferOffset += ulAUFragSize;
+ /* Have we finished the fragmented AU? */
+ if (pHdr->ulFragBufferOffset >= pHdr->ulFragBufferAUSize) {
+ /* Send the frag buffer */
+ retVal = ra_depacki_send_block(pInt, ulSubStream,
+ pHdr->pFragBuffer,
+ pHdr->ulFragBufferAUSize,
+ pHdr->ulFragBufferTime,
+ 0xFFFFFFFF);
+ /* Whether we succeed or not, clear the frag buffer */
+ ra_depacki_clear_frag_buffer(pInt, pHdr);
+ }
+ } else {
+ retVal = HXR_FAIL;
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_handle_nonfrag_packet(ra_depack_internal* pInt,
+ UINT32 ulSubStream,
+ rm_packet* pPacket,
+ UINT32 ulNumAU)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr && pPacket &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init the local variables */
+ UINT32 ulAUDataSizeSum = 0;
+ UINT32 i = 0;
+ BYTE* pBuf = pPacket->pData;
+ UINT32 ulLen = pPacket->usDataLen;
+ UINT32 ulTSOffset = 0;
+ UINT32 ulAUSize = 0;
+ UINT32 ulBufOffset = 0;
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /*
+ * We can clear the frag queue. If there was no
+ * loss in the last fragmented AU, then it was
+ * cleared after the packet was created. If there
+ * WAS loss in the last fragmented AU, then we
+ * just handled it by generating loss packets.
+ */
+ ra_depacki_clear_frag_buffer(pInt, pHdr);
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /* Step through the packet sending blocks */
+ for (i = 0; i < ulNumAU && HX_SUCCEEDED(retVal); i++) {
+ /* Set the return value */
+ retVal = HXR_FAIL;
+ /* Compute the time offset for this block */
+ ulTSOffset = (UINT32)(i * pHdr->dBlockDuration);
+ /* Compute the buffer offset for the AU size */
+ ulBufOffset = 2 + (i << 1);
+ /* Sanity check on packet size */
+ if (ulBufOffset + 1 < ulLen) {
+ /* Parse out the size of this AU */
+ ulAUSize = rm_unpack16_nse(pBuf + ulBufOffset,
+ ulLen - ulBufOffset);
+ /* Compute the offset of the AU */
+ ulBufOffset = 2 + ulNumAU * 2 + ulAUDataSizeSum;
+ /* Sanity check on size */
+ if (ulBufOffset + ulAUSize <= ulLen) {
+ /* Send this AU */
+ retVal = ra_depacki_send_block(pInt,
+ ulSubStream,
+ pBuf + ulBufOffset,
+ ulAUSize,
+ pPacket->ulTime + ulTSOffset,
+ 0xFFFFFFFF);
+ if (retVal == HXR_OK) {
+ /* Update the AU data size sum */
+ ulAUDataSizeSum += ulAUSize;
+ }
+ }
+ }
+ }
+ if (HX_SUCCEEDED(retVal)) {
+ /* Update the end time of the last block sent */
+ ulTSOffset = (UINT32)(ulNumAU * pHdr->dBlockDuration);
+ pHdr->ulLastSentEndTime = pPacket->ulTime + ulTSOffset;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_init_frag_buffer(ra_depack_internal* pInt,
+ ra_substream_hdr* pHdr)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pHdr && !pHdr->pFragBuffer) {
+ /* Allocate the frag buffer */
+ pHdr->pFragBuffer = ra_depacki_malloc(pInt, INITIAL_FRAG_BUFFER_SIZE);
+ if (pHdr->pFragBuffer) {
+ /* Zero out the buffer */
+ memset(pHdr->pFragBuffer, 0, INITIAL_FRAG_BUFFER_SIZE);
+ /* Init the members */
+ pHdr->ulFragBufferSize = INITIAL_FRAG_BUFFER_SIZE;
+ pHdr->ulFragBufferTime = 0;
+ pHdr->ulFragBufferOffset = 0;
+ pHdr->ulFragBufferAUSize = 0;
+ pHdr->bHasFrag = FALSE;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_resize_frag_buffer(ra_depack_internal* pInt,
+ ra_substream_hdr* pHdr,
+ UINT32 ulNewSize)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pHdr && pHdr->pFragBuffer) {
+ /* Allocate a new buffer */
+ BYTE* pNewBuf = ra_depacki_malloc(pInt, ulNewSize);
+ if (pNewBuf) {
+ /* Copy the old buffer */
+ if (pHdr->ulFragBufferOffset) {
+ memcpy(pNewBuf, pHdr->pFragBuffer, pHdr->ulFragBufferOffset);
+ }
+ /* NULL out the rest of the buffer */
+ memset(pNewBuf + pHdr->ulFragBufferOffset, 0,
+ ulNewSize - pHdr->ulFragBufferOffset);
+ /* Free the old buffer */
+ ra_depacki_free(pInt, pHdr->pFragBuffer);
+ /* Assign the members. We won't change time or offset */
+ pHdr->pFragBuffer = pNewBuf;
+ pHdr->ulFragBufferSize = ulNewSize;
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}
+
+void ra_depacki_clear_frag_buffer(ra_depack_internal* pInt,
+ ra_substream_hdr* hdr)
+{
+ if (pInt && hdr && hdr->bHasFrag) {
+ /* Clear the frag buffer members */
+ hdr->bHasFrag = FALSE;
+ hdr->ulFragBufferAUSize = 0;
+ hdr->ulFragBufferOffset = 0;
+ hdr->ulFragBufferTime = 0;
+ }
+}
+
+HX_RESULT ra_depacki_seek(ra_depack_internal* pInt, UINT32 ulTime)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr) {
+ /*
+ * Loop through all the substream headers
+ * and set the bSeeked flag.
+ */
+ UINT32 i = 0;
+ for (i = 0; i < pInt->multiStreamHdr.ulNumSubStreams; i++) {
+ pInt->pSubStreamHdr[i].bSeeked = TRUE;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_deinterleave_send(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams &&
+ pInt->fpAvail) {
+ /* Init local variables */
+ UINT32 i = 0;
+ UINT32 ulTimeOffset = 0;
+ UINT32 ulTimestamp = 0;
+ HXDOUBLE dTimeOffset = 0.0;
+ ra_block Block;
+ /* Deinterleave the superblock */
+ retVal = ra_depacki_deinterleave(pInt, ulSubStream);
+ if (retVal == HXR_OK) {
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Send the blocks from the deinterleave buffer */
+ for (i = 0; i < pHdr->ulBlockCount&& i < pHdr->ulInterleaveFactor && HX_SUCCEEDED(retVal); i++) {
+ /* Set the return value */
+ retVal = HXR_OUTOFMEMORY;
+ /* Compute the time offset for this block */
+ dTimeOffset = i * pHdr->dBlockDuration;
+ ulTimeOffset = (UINT32) dTimeOffset;
+ ulTimestamp = pHdr->ulKeyTime + ulTimeOffset;
+ /* Make sure the time is less than the stream duration */
+ if (ulTimestamp <= pInt->ulStreamDuration) {
+#if RA_COPY_BUF
+ /* Alloc and copy the buffer */
+ Block.pData = copy_buffer(pInt->pUserMem,
+ pInt->fpMalloc,
+ pHdr->pDBuffer + i * pHdr->ulInterleaveBlockSize,
+ pHdr->ulInterleaveBlockSize);
+#else
+ Block.pData = pHdr->pDBuffer + i * pHdr->ulInterleaveBlockSize;
+#endif
+ if (Block.pData) {
+ Block.ulDataLen = pHdr->ulInterleaveBlockSize;
+ Block.ulTimestamp = ulTimestamp;
+ Block.ulDataFlags = pHdr->pDPresentFlags[i];
+ /* Send the block */
+ retVal = pInt->fpAvail(pInt->pAvail, ulSubStream, &Block);
+ }
+#if RA_COPY_BUF
+ ra_depacki_free_block(&Block);
+#endif
+ } else {
+ /*
+ * Block is after the stream duration, so clear
+ * the return value and break out of the loop.
+ */
+ retVal = HXR_OK;
+ break;
+ }
+ }
+ /* Clear the interleaving buffers */
+ memset(pHdr->pIBuffer, 0, pHdr->ulSuperBlockSize);
+ memset(pHdr->pDBuffer, 0, pHdr->ulSuperBlockSize);
+ memset(pHdr->pIPresentFlags, 0, pHdr->ulInterleaveFactor * sizeof(UINT32));
+ memset(pHdr->pDPresentFlags, 0, pHdr->ulInterleaveFactor * sizeof(UINT32));
+ /* Clear the state */
+ pHdr->bHasKeyTime = FALSE;
+ pHdr->ulKeyTime = 0;
+ pHdr->ulBlockCount = 0;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_deinterleave(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Get the interleaver ID */
+ UINT32 ulID = pInt->pSubStreamHdr[ulSubStream].ulInterleaverID;
+ /* Switch based on ID */
+ switch (ulID) {
+#if 0
+ case RA_INTERLEAVER_SIPR:
+ retVal = ra_depacki_deinterleave_sipr(pInt, ulSubStream);
+ break;
+#endif
+ case RA_INTERLEAVER_GENR:
+ retVal = ra_depacki_deinterleave_genr(pInt, ulSubStream);
+ break;
+ case RA_NO_INTERLEAVER:
+ retVal = ra_depacki_deinterleave_no(pInt, ulSubStream);
+ break;
+ }
+ }
+
+ return retVal;
+}
+
+#if 0
+HX_RESULT ra_depacki_deinterleave_sipr(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Sanity check */
+ if (pHdr->pIBuffer && pHdr->pDBuffer &&
+ pHdr->pIPresentFlags && pHdr->pDPresentFlags) {
+ /*
+ * This is an in-place interleaving, so copy from
+ * pIBuffer to pDBuffer and then we will do the
+ * de-interleaving in-place in pDBuffer.
+ */
+ memcpy(pHdr->pDBuffer, pHdr->pIBuffer, pHdr->ulSuperBlockSize);
+ /* Copy the flags */
+ memcpy(pHdr->pDPresentFlags, pHdr->pIPresentFlags,
+ pHdr->ulInterleaveFactor * sizeof(UINT32));
+ /* Do the de-interleave */
+ RASL_DeInterleave((char*) pHdr->pDBuffer,
+ pHdr->ulSuperBlockSize,
+ pHdr->usFlavorIndex,
+ pHdr->pDPresentFlags);
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}
+#endif
+
+HX_RESULT ra_depacki_init_genr(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init local variables */
+ UINT32 ulFramesPerBlock = 0;
+ UINT32 ulSize = 0;
+ UINT32 ulBlockIndx = 0;
+ UINT32 ulFrameIndx = 0;
+ UINT32 ulIndx = 0;
+ UINT32 i = 0;
+ UINT32 j = 0;
+ UINT32 ulCount = 0;
+ HXBOOL bEven = FALSE;
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Sanity check */
+ if (pHdr->ulCodecFrameSize && pHdr->ulNumCodecFrames) {
+ /* Compute the codec frames per block */
+ ulFramesPerBlock = pHdr->ulInterleaveBlockSize / pHdr->ulCodecFrameSize;
+ /* Allocate space for the block num and offset */
+ ulSize = pHdr->ulNumCodecFrames * sizeof(UINT32);
+ pHdr->pulGENRBlockNum = (UINT32*) ra_depacki_malloc(pInt, ulSize);
+ if (pHdr->pulGENRBlockNum) {
+ pHdr->pulGENRBlockOffset = (UINT32*) ra_depacki_malloc(pInt, ulSize);
+ if (pHdr->pulGENRBlockOffset) {
+ pHdr->pulGENRPattern = (UINT32*) ra_depacki_malloc(pInt, ulSize);
+ if (pHdr->pulGENRPattern) {
+ /* Initialize the block num and offset arrays */
+ for (ulBlockIndx = 0; ulBlockIndx < pHdr->ulInterleaveFactor; ulBlockIndx++) {
+ for (ulFrameIndx = 0; ulFrameIndx < ulFramesPerBlock; ulFrameIndx++) {
+ ulIndx = ulBlockIndx * ulFramesPerBlock + ulFrameIndx;
+ pHdr->pulGENRBlockNum[ulIndx] = ulBlockIndx;
+ pHdr->pulGENRBlockOffset[ulIndx] = ulFrameIndx;
+ }
+ }
+ /* Do we have a pattern from the stream header? */
+ if (pHdr->pulInterleavePattern) {
+ /* Copy the pattern from the stream header */
+ memcpy(pHdr->pulGENRPattern,
+ pHdr->pulInterleavePattern,
+ ulSize);
+ /*
+ * Check the pattern for validity by making sure
+ * that each frame index is used once and only
+ * once in the interleave pattern.
+ */
+ retVal = HXR_OK;
+ for (i = 0; i < pHdr->ulNumCodecFrames; i++) {
+ /* Init the count */
+ ulCount = 0;
+ /* Count how many times index i appears in table */
+ for (j = 0; j < pHdr->ulNumCodecFrames; j++) {
+ if (pHdr->pulGENRPattern[j] == i) {
+ ulCount++;
+ }
+ }
+ /* Make sure it's just once */
+ if (ulCount != 1) {
+ retVal = HXR_FAIL;
+ break;
+ }
+ }
+ } else {
+ /* Clear the return value */
+ retVal = HXR_OK;
+ /*
+ * We don't have a stream header pattern, so
+ * we generate the standard interleave pattern.
+ */
+ if (pHdr->ulInterleaveFactor == 1) {
+ for (i = 0; i < pHdr->ulNumCodecFrames; i++) {
+ pHdr->pulGENRPattern[i] = i;
+ }
+ } else {
+ bEven = TRUE;
+ ulCount = 0;
+ ulBlockIndx = 0;
+ ulFrameIndx = 0;
+ while (ulCount < pHdr->ulNumCodecFrames) {
+ pHdr->pulGENRPattern[ulCount] = ulBlockIndx * ulFramesPerBlock + ulFrameIndx;
+ ulCount++;
+ ulBlockIndx += 2;
+ if (ulBlockIndx >= pHdr->ulInterleaveFactor) {
+ if (bEven) {
+ bEven = FALSE;
+ ulBlockIndx = 1;
+ } else {
+ bEven = TRUE;
+ ulBlockIndx = 0;
+ ulFrameIndx++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_deinterleave_genr(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init local variables */
+ UINT32 fi = 0;
+ UINT32 fo = 0;
+ UINT32 ulBlkIndxIn = 0;
+ UINT32 ulBlkIndxOut = 0;
+ UINT32 ulBlkOffset = 0;
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Sanity check */
+ if (pHdr->pIBuffer && pHdr->pDBuffer &&
+ pHdr->pIPresentFlags && pHdr->pDPresentFlags) {
+ /* Set all the output flags to present initially */
+ memset(pHdr->pDPresentFlags, 0xFF,
+ pHdr->ulInterleaveFactor * sizeof(UINT32));
+ /* Deinterleave the data */
+ for (fo = 0; fo < pHdr->ulNumCodecFrames; fo++) {
+ /* Copy the data */
+ fi = pHdr->pulGENRPattern[fo];
+ memcpy(pHdr->pDBuffer + fo * pHdr->ulCodecFrameSize,
+ pHdr->pIBuffer + fi * pHdr->ulCodecFrameSize,
+ pHdr->ulCodecFrameSize);
+ /* Look up which block this frame comes from */
+ ulBlkIndxIn = pHdr->pulGENRBlockNum[fi];
+ /* Is this codec frame present? */
+ if (!pHdr->pIPresentFlags[ulBlkIndxIn]) {
+ /*
+ * Frame was part of a lost block. So clear
+ * the bit that says the frame was present.
+ */
+ ulBlkIndxOut = pHdr->pulGENRBlockNum[fo];
+ ulBlkOffset = pHdr->pulGENRBlockOffset[fo];
+ pHdr->pDPresentFlags[ulBlkIndxOut] ^= (1 << ulBlkOffset);
+ }
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}
+
+HX_RESULT ra_depacki_deinterleave_no(ra_depack_internal* pInt, UINT32 ulSubStream)
+{
+ HX_RESULT retVal = HXR_FAIL;
+
+ if (pInt && pInt->pSubStreamHdr &&
+ ulSubStream < pInt->multiStreamHdr.ulNumSubStreams) {
+ /* Init local variables */
+ UINT32 fi = 0;
+ UINT32 fo = 0;
+ UINT32 ulBlkIndxIn = 0;
+ UINT32 ulBlkIndxOut = 0;
+ UINT32 ulBlkOffset = 0;
+ /* Get the substream header */
+ ra_substream_hdr* pHdr = &pInt->pSubStreamHdr[ulSubStream];
+ /* Sanity check */
+ if (pHdr->pIBuffer && pHdr->pDBuffer &&
+ pHdr->pIPresentFlags && pHdr->pDPresentFlags) {
+ /* Set all the output flags to present initially */
+ memset(pHdr->pDPresentFlags, 0xFF,
+ pHdr->ulInterleaveFactor * sizeof(UINT32));
+ /* Deinterleave the data */
+ for (fo = 0; fo < pHdr->ulNumCodecFrames; fo++) {
+ /* Copy the data */
+ fi = fo;
+ memcpy(pHdr->pDBuffer + fo * pHdr->ulCodecFrameSize,
+ pHdr->pIBuffer + fi * pHdr->ulCodecFrameSize,
+ pHdr->ulCodecFrameSize);
+ /* Look up which block this frame comes from */
+ ulBlkIndxIn = pHdr->pulGENRBlockNum[fi];
+ /* Is this codec frame present? */
+ if (!pHdr->pIPresentFlags[ulBlkIndxIn]) {
+ /*
+ * Frame was part of a lost block. So clear
+ * the bit that says the frame was present.
+ */
+ ulBlkIndxOut = pHdr->pulGENRBlockNum[fo];
+ ulBlkOffset = pHdr->pulGENRBlockOffset[fo];
+ pHdr->pDPresentFlags[ulBlkIndxOut] ^= (1 << ulBlkOffset);
+ }
+ }
+ /* Clear the return value */
+ retVal = HXR_OK;
+ }
+ }
+
+ return retVal;
+}