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/libfaad/syntax.c b/audio_codec/libfaad/syntax.c
new file mode 100644
index 0000000..a2d0f4b
--- a/dev/null
+++ b/audio_codec/libfaad/syntax.c
@@ -0,0 +1,2539 @@
+/*
+** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
+** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**
+** Any non-GPL usage of this software or parts of this software is strictly
+** forbidden.
+**
+** The "appropriate copyright message" mentioned in section 2c of the GPLv2
+** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
+**
+** Commercial non-GPL licensing of this software is possible.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
+**
+** $Id: syntax.c,v 1.93 2009/01/26 23:51:15 menno Exp $
+**/
+
+/*
+ Reads the AAC bitstream as defined in 14496-3 (MPEG-4 Audio)
+*/
+#include <stdlib.h>
+#include "common.h"
+#include "structs.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "syntax.h"
+#include "specrec.h"
+#include "huffman.h"
+#include "bits.h"
+#include "pulse.h"
+#include "analysis.h"
+#include "drc.h"
+#ifdef ERROR_RESILIENCE
+#include "rvlc.h"
+#endif
+#ifdef SBR_DEC
+#include "sbr_syntax.h"
+#endif
+#include "mp4.h"
+
+
+/* static function declarations */
+static void decode_sce_lfe(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele);
+static void decode_cpe(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele);
+static uint8_t single_lfe_channel_element(NeAACDecStruct *hDecoder, bitfile *ld,
+ uint8_t channel, uint8_t *tag);
+static uint8_t channel_pair_element(NeAACDecStruct *hDecoder, bitfile *ld,
+ uint8_t channel, uint8_t *tag);
+#ifdef COUPLING_DEC
+static uint8_t coupling_channel_element(NeAACDecStruct *hDecoder, bitfile *ld);
+#endif
+static uint16_t data_stream_element(NeAACDecStruct *hDecoder, bitfile *ld);
+static uint8_t program_config_element(program_config *pce, bitfile *ld);
+static uint8_t fill_element(NeAACDecStruct *hDecoder, bitfile *ld, drc_info *drc
+#ifdef SBR_DEC
+ , uint8_t sbr_ele
+#endif
+ );
+static uint8_t individual_channel_stream(NeAACDecStruct *hDecoder, element *ele,
+ bitfile *ld, ic_stream *ics, uint8_t scal_flag,
+ int16_t *spec_data);
+static uint8_t ics_info(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld,
+ uint8_t common_window);
+static uint8_t section_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld);
+static uint8_t scale_factor_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld);
+#ifdef SSR_DEC
+static void gain_control_data(bitfile *ld, ic_stream *ics);
+#endif
+static uint8_t spectral_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld,
+ int16_t *spectral_data);
+static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count);
+static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
+static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
+#ifdef LTP_DEC
+static uint8_t ltp_data(NeAACDecStruct *hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
+#endif
+static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);
+static void adts_variable_header(adts_header *adts, bitfile *ld);
+static void adts_error_check(adts_header *adts, bitfile *ld);
+static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc);
+static uint8_t excluded_channels(bitfile *ld, drc_info *drc);
+static uint8_t side_info(NeAACDecStruct *hDecoder, element *ele,
+ bitfile *ld, ic_stream *ics, uint8_t scal_flag);
+#ifdef DRM
+static int8_t DRM_aac_scalable_main_header(NeAACDecStruct *hDecoder, ic_stream *ics1, ic_stream *ics2,
+ bitfile *ld, uint8_t this_layer_stereo);
+#endif
+
+
+/* Table 4.4.1 */
+int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC,
+ program_config *pce_out)
+{
+ program_config pce;
+
+ /* 1024 or 960 */
+ mp4ASC->frameLengthFlag = faad_get1bit(ld
+ DEBUGVAR(1, 138, "GASpecificConfig(): FrameLengthFlag"));
+#ifndef ALLOW_SMALL_FRAMELENGTH
+ if (mp4ASC->frameLengthFlag == 1) {
+ return -3;
+ }
+#endif
+
+ mp4ASC->dependsOnCoreCoder = faad_get1bit(ld
+ DEBUGVAR(1, 139, "GASpecificConfig(): DependsOnCoreCoder"));
+ if (mp4ASC->dependsOnCoreCoder == 1) {
+ mp4ASC->coreCoderDelay = (uint16_t)faad_getbits(ld, 14
+ DEBUGVAR(1, 140, "GASpecificConfig(): CoreCoderDelay"));
+ }
+
+ mp4ASC->extensionFlag = faad_get1bit(ld DEBUGVAR(1, 141, "GASpecificConfig(): ExtensionFlag"));
+ if (mp4ASC->channelsConfiguration == 0) {
+ if (program_config_element(&pce, ld)) {
+ return -3;
+ }
+ //mp4ASC->channelsConfiguration = pce.channels;
+
+ if (pce_out != NULL) {
+ memcpy(pce_out, &pce, sizeof(program_config));
+ }
+
+ /*
+ if (pce.num_valid_cc_elements)
+ return -3;
+ */
+ }
+
+#ifdef ERROR_RESILIENCE
+ if (mp4ASC->extensionFlag == 1) {
+ /* Error resilience not supported yet */
+ if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) {
+ mp4ASC->aacSectionDataResilienceFlag = faad_get1bit(ld
+ DEBUGVAR(1, 144, "GASpecificConfig(): aacSectionDataResilienceFlag"));
+ mp4ASC->aacScalefactorDataResilienceFlag = faad_get1bit(ld
+ DEBUGVAR(1, 145, "GASpecificConfig(): aacScalefactorDataResilienceFlag"));
+ mp4ASC->aacSpectralDataResilienceFlag = faad_get1bit(ld
+ DEBUGVAR(1, 146, "GASpecificConfig(): aacSpectralDataResilienceFlag"));
+ }
+ /* 1 bit: extensionFlag3 */
+ faad_getbits(ld, 1);
+ }
+#endif
+
+ return 0;
+}
+
+/* Table 4.4.2 */
+/* An MPEG-4 Audio decoder is only required to follow the Program
+ Configuration Element in GASpecificConfig(). The decoder shall ignore
+ any Program Configuration Elements that may occur in raw data blocks.
+ PCEs transmitted in raw data blocks cannot be used to convey decoder
+ configuration information.
+*/
+static uint8_t program_config_element(program_config *pce, bitfile *ld)
+{
+ uint8_t i;
+
+ memset(pce, 0, sizeof(program_config));
+
+ pce->channels = 0;
+
+ pce->element_instance_tag = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 10, "program_config_element(): element_instance_tag"));
+
+ pce->object_type = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 11, "program_config_element(): object_type"));
+ pce->sf_index = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 12, "program_config_element(): sf_index"));
+ pce->num_front_channel_elements = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 13, "program_config_element(): num_front_channel_elements"));
+ pce->num_side_channel_elements = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 14, "program_config_element(): num_side_channel_elements"));
+ pce->num_back_channel_elements = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 15, "program_config_element(): num_back_channel_elements"));
+ pce->num_lfe_channel_elements = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 16, "program_config_element(): num_lfe_channel_elements"));
+ pce->num_assoc_data_elements = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 17, "program_config_element(): num_assoc_data_elements"));
+ pce->num_valid_cc_elements = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 18, "program_config_element(): num_valid_cc_elements"));
+
+ pce->mono_mixdown_present = faad_get1bit(ld
+ DEBUGVAR(1, 19, "program_config_element(): mono_mixdown_present"));
+ if (pce->mono_mixdown_present == 1) {
+ pce->mono_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 20, "program_config_element(): mono_mixdown_element_number"));
+ }
+
+ pce->stereo_mixdown_present = faad_get1bit(ld
+ DEBUGVAR(1, 21, "program_config_element(): stereo_mixdown_present"));
+ if (pce->stereo_mixdown_present == 1) {
+ pce->stereo_mixdown_element_number = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 22, "program_config_element(): stereo_mixdown_element_number"));
+ }
+
+ pce->matrix_mixdown_idx_present = faad_get1bit(ld
+ DEBUGVAR(1, 23, "program_config_element(): matrix_mixdown_idx_present"));
+ if (pce->matrix_mixdown_idx_present == 1) {
+ pce->matrix_mixdown_idx = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 24, "program_config_element(): matrix_mixdown_idx"));
+ pce->pseudo_surround_enable = faad_get1bit(ld
+ DEBUGVAR(1, 25, "program_config_element(): pseudo_surround_enable"));
+ }
+
+ for (i = 0; i < pce->num_front_channel_elements; i++) {
+ pce->front_element_is_cpe[i] = faad_get1bit(ld
+ DEBUGVAR(1, 26, "program_config_element(): front_element_is_cpe"));
+ pce->front_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 27, "program_config_element(): front_element_tag_select"));
+
+ if (pce->front_element_is_cpe[i] & 1) {
+ pce->cpe_channel[pce->front_element_tag_select[i]] = pce->channels;
+ pce->num_front_channels += 2;
+ pce->channels += 2;
+ } else {
+ pce->sce_channel[pce->front_element_tag_select[i]] = pce->channels;
+ pce->num_front_channels++;
+ pce->channels++;
+ }
+ }
+
+ for (i = 0; i < pce->num_side_channel_elements; i++) {
+ pce->side_element_is_cpe[i] = faad_get1bit(ld
+ DEBUGVAR(1, 28, "program_config_element(): side_element_is_cpe"));
+ pce->side_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 29, "program_config_element(): side_element_tag_select"));
+
+ if (pce->side_element_is_cpe[i] & 1) {
+ pce->cpe_channel[pce->side_element_tag_select[i]] = pce->channels;
+ pce->num_side_channels += 2;
+ pce->channels += 2;
+ } else {
+ pce->sce_channel[pce->side_element_tag_select[i]] = pce->channels;
+ pce->num_side_channels++;
+ pce->channels++;
+ }
+ }
+
+ for (i = 0; i < pce->num_back_channel_elements; i++) {
+ pce->back_element_is_cpe[i] = faad_get1bit(ld
+ DEBUGVAR(1, 30, "program_config_element(): back_element_is_cpe"));
+ pce->back_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 31, "program_config_element(): back_element_tag_select"));
+
+ if (pce->back_element_is_cpe[i] & 1) {
+ pce->cpe_channel[pce->back_element_tag_select[i]] = pce->channels;
+ pce->channels += 2;
+ pce->num_back_channels += 2;
+ } else {
+ pce->sce_channel[pce->back_element_tag_select[i]] = pce->channels;
+ pce->num_back_channels++;
+ pce->channels++;
+ }
+ }
+
+ for (i = 0; i < pce->num_lfe_channel_elements; i++) {
+ pce->lfe_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 32, "program_config_element(): lfe_element_tag_select"));
+
+ pce->sce_channel[pce->lfe_element_tag_select[i]] = pce->channels;
+ pce->num_lfe_channels++;
+ pce->channels++;
+ }
+
+ for (i = 0; i < pce->num_assoc_data_elements; i++)
+ pce->assoc_data_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 33, "program_config_element(): assoc_data_element_tag_select"));
+
+ for (i = 0; i < pce->num_valid_cc_elements; i++) {
+ pce->cc_element_is_ind_sw[i] = faad_get1bit(ld
+ DEBUGVAR(1, 34, "program_config_element(): cc_element_is_ind_sw"));
+ pce->valid_cc_element_tag_select[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 35, "program_config_element(): valid_cc_element_tag_select"));
+ }
+
+ faad_byte_align(ld);
+
+ pce->comment_field_bytes = (uint8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 36, "program_config_element(): comment_field_bytes"));
+
+ for (i = 0; i < pce->comment_field_bytes; i++) {
+ pce->comment_field_data[i] = (uint8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 37, "program_config_element(): comment_field_data"));
+ }
+ pce->comment_field_data[i] = 0;
+
+ if (pce->channels > MAX_CHANNELS) {
+ return 22;
+ }
+
+ return 0;
+}
+
+static void decode_sce_lfe(NeAACDecStruct *hDecoder,
+ NeAACDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele)
+{
+ uint8_t channels = hDecoder->fr_channels;
+ uint8_t tag = 0;
+
+ if (channels + 1 > MAX_CHANNELS) {
+ hInfo->error = 12;
+ return;
+ }
+ if (hDecoder->fr_ch_ele + 1 > MAX_SYNTAX_ELEMENTS) {
+ hInfo->error = 13;
+ return;
+ }
+
+ /* for SCE hDecoder->element_output_channels[] is not set here because this
+ can become 2 when some form of Parametric Stereo coding is used
+ */
+
+ /* save the syntax element id */
+ hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
+
+ /* decode the element */
+ hInfo->error = single_lfe_channel_element(hDecoder, ld, channels, &tag);
+
+ /* map output channels position to internal data channels */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2) {
+ /* this might be faulty when pce_set is true */
+ hDecoder->internal_channel[channels] = channels;
+ hDecoder->internal_channel[channels + 1] = channels + 1;
+ } else {
+ if (hDecoder->pce_set) {
+ hDecoder->internal_channel[hDecoder->pce.sce_channel[tag]] = channels;
+ } else {
+ hDecoder->internal_channel[channels] = channels;
+ }
+ }
+
+ hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
+ hDecoder->fr_ch_ele++;
+}
+
+static void decode_cpe(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo, bitfile *ld,
+ uint8_t id_syn_ele)
+{
+ uint8_t channels = hDecoder->fr_channels;
+ uint8_t tag = 0;
+
+ if (channels + 2 > MAX_CHANNELS) {
+ hInfo->error = 12;
+ return;
+ }
+ if (hDecoder->fr_ch_ele + 1 > MAX_SYNTAX_ELEMENTS) {
+ hInfo->error = 13;
+ return;
+ }
+
+ /* for CPE the number of output channels is always 2 */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) {
+ /* element_output_channels not set yet */
+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2;
+ } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != 2) {
+ /* element inconsistency */
+ hInfo->error = 21;
+ return;
+ }
+
+ /* save the syntax element id */
+ hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele;
+
+ /* decode the element */
+ hInfo->error = channel_pair_element(hDecoder, ld, channels, &tag);
+
+ /* map output channel position to internal data channels */
+ if (hDecoder->pce_set) {
+ hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag]] = channels;
+ hDecoder->internal_channel[hDecoder->pce.cpe_channel[tag] + 1] = channels + 1;
+ } else {
+ hDecoder->internal_channel[channels] = channels;
+ hDecoder->internal_channel[channels + 1] = channels + 1;
+ }
+
+ hDecoder->fr_channels += 2;
+ hDecoder->fr_ch_ele++;
+}
+
+void raw_data_block(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo,
+ bitfile *ld, program_config *pce, drc_info *drc)
+{
+ uint8_t id_syn_ele;
+ uint8_t ele_this_frame = 0;
+
+ hDecoder->fr_channels = 0;
+ hDecoder->fr_ch_ele = 0;
+ hDecoder->first_syn_ele = 25;
+ hDecoder->has_lfe = 0;
+
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->object_type < ER_OBJECT_START) {
+#endif
+ /* Table 4.4.3: raw_data_block() */
+ while ((id_syn_ele = (uint8_t)faad_getbits(ld, LEN_SE_ID
+ DEBUGVAR(1, 4, "NeAACDecDecode(): id_syn_ele"))) != ID_END) {
+ switch (id_syn_ele) {
+ case ID_SCE:
+ ele_this_frame++;
+ if (hDecoder->first_syn_ele == 25) {
+ hDecoder->first_syn_ele = id_syn_ele;
+ }
+ decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case ID_CPE:
+ ele_this_frame++;
+ if (hDecoder->first_syn_ele == 25) {
+ hDecoder->first_syn_ele = id_syn_ele;
+ }
+ decode_cpe(hDecoder, hInfo, ld, id_syn_ele);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case ID_LFE:
+#ifdef DRM
+ hInfo->error = 32;
+#else
+ ele_this_frame++;
+ hDecoder->has_lfe++;
+ decode_sce_lfe(hDecoder, hInfo, ld, id_syn_ele);
+#endif
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case ID_CCE: /* not implemented yet, but skip the bits */
+#ifdef DRM
+ hInfo->error = 32;
+#else
+ ele_this_frame++;
+#ifdef COUPLING_DEC
+ hInfo->error = coupling_channel_element(hDecoder, ld);
+#else
+ hInfo->error = 6;
+#endif
+#endif
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case ID_DSE:
+ ele_this_frame++;
+ data_stream_element(hDecoder, ld);
+ break;
+ case ID_PCE:
+ if (ele_this_frame != 0) {
+ hInfo->error = 31;
+ return;
+ }
+ ele_this_frame++;
+ /* 14496-4: 5.6.4.1.2.1.3: */
+ /* program_configuration_element()'s in access units shall be ignored */
+ program_config_element(pce, ld);
+ //if ((hInfo->error = program_config_element(pce, ld)) > 0)
+ // return;
+ //hDecoder->pce_set = 1;
+ break;
+ case ID_FIL:
+ ele_this_frame++;
+ /* one sbr_info describes a channel_element not a channel! */
+ /* if we encounter SBR data here: error */
+ /* SBR data will be read directly in the SCE/LFE/CPE element */
+ if ((hInfo->error = fill_element(hDecoder, ld, drc
+#ifdef SBR_DEC
+ , INVALID_SBR_ELEMENT
+#endif
+ )) > 0) {
+ return;
+ }
+ break;
+ }
+ }
+#ifdef ERROR_RESILIENCE
+ } else {
+ /* Table 262: er_raw_data_block() */
+ switch (hDecoder->channelConfiguration) {
+ case 1:
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 2:
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 3:
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 4:
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 5:
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 6:
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ case 7: /* 8 channels */
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_SCE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_cpe(hDecoder, hInfo, ld, ID_CPE);
+ decode_sce_lfe(hDecoder, hInfo, ld, ID_LFE);
+ if (hInfo->error > 0) {
+ return;
+ }
+ break;
+ default:
+ hInfo->error = 7;
+ return;
+ }
+#if 0
+ cnt = bits_to_decode() / 8;
+ while (cnt >= 1) {
+ cnt -= extension_payload(cnt);
+ }
+#endif
+ }
+#endif
+
+ /* new in corrigendum 14496-3:2002 */
+#ifdef DRM
+ if (hDecoder->object_type != DRM_ER_LC
+#if 0
+ && !hDecoder->latm_header_present
+#endif
+ )
+#endif
+ {
+ faad_byte_align(ld);
+ }
+
+ return;
+}
+
+/* Table 4.4.4 and */
+/* Table 4.4.9 */
+static uint8_t single_lfe_channel_element(NeAACDecStruct *hDecoder, bitfile *ld,
+ uint8_t channel, uint8_t *tag)
+{
+ uint8_t retval = 0;
+ element sce = {0};
+ ic_stream *ics = &(sce.ics1);
+ ALIGN int16_t spec_data[1024] = {0};
+
+ sce.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
+ DEBUGVAR(1, 38, "single_lfe_channel_element(): element_instance_tag"));
+
+ *tag = sce.element_instance_tag;
+ sce.channel = channel;
+ sce.paired_channel = -1;
+
+ retval = individual_channel_stream(hDecoder, &sce, ld, ics, 0, spec_data);
+ if (retval > 0) {
+ return retval;
+ }
+
+ /* IS not allowed in single channel */
+ if (ics->is_used) {
+ return 32;
+ }
+
+#ifdef SBR_DEC
+ /* check if next bitstream element is a fill element */
+ /* if so, read it now so SBR decoding can be done in case of a file with SBR */
+ if (faad_showbits(ld, LEN_SE_ID) == ID_FIL) {
+ faad_flushbits(ld, LEN_SE_ID);
+
+ /* one sbr_info describes a channel_element not a channel! */
+ if ((retval = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0) {
+ return retval;
+ }
+ }
+#endif
+
+ /* noiseless coding is done, spectral reconstruction is done now */
+ retval = reconstruct_single_channel(hDecoder, ics, &sce, spec_data);
+ if (retval > 0) {
+ return retval;
+ }
+
+ return 0;
+}
+
+/* Table 4.4.5 */
+static uint8_t channel_pair_element(NeAACDecStruct *hDecoder, bitfile *ld,
+ uint8_t channels, uint8_t *tag)
+{
+ ALIGN int16_t spec_data1[1024] = {0};
+ ALIGN int16_t spec_data2[1024] = {0};
+ element cpe = {0};
+ ic_stream *ics1 = &(cpe.ics1);
+ ic_stream *ics2 = &(cpe.ics2);
+ uint8_t result;
+
+ cpe.channel = channels;
+ cpe.paired_channel = channels + 1;
+
+ cpe.element_instance_tag = (uint8_t)faad_getbits(ld, LEN_TAG
+ DEBUGVAR(1, 39, "channel_pair_element(): element_instance_tag"));
+ *tag = cpe.element_instance_tag;
+
+ if ((cpe.common_window = faad_get1bit(ld
+ DEBUGVAR(1, 40, "channel_pair_element(): common_window"))) & 1) {
+ /* both channels have common ics information */
+ if ((result = ics_info(hDecoder, ics1, ld, cpe.common_window)) > 0) {
+ return result;
+ }
+
+ ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 41, "channel_pair_element(): ms_mask_present"));
+ if (ics1->ms_mask_present == 3) {
+ /* bitstream error */
+ return 32;
+ }
+ if (ics1->ms_mask_present == 1) {
+ uint8_t g, sfb;
+ for (g = 0; g < ics1->num_window_groups; g++) {
+ for (sfb = 0; sfb < ics1->max_sfb; sfb++) {
+ ics1->ms_used[g][sfb] = faad_get1bit(ld
+ DEBUGVAR(1, 42, "channel_pair_element(): faad_get1bit"));
+ }
+ }
+ }
+
+#ifdef ERROR_RESILIENCE
+ if ((hDecoder->object_type >= ER_OBJECT_START) && (ics1->predictor_data_present)) {
+ if ((
+#ifdef LTP_DEC
+ ics1->ltp.data_present =
+#endif
+ faad_get1bit(ld DEBUGVAR(1, 50, "channel_pair_element(): ltp.data_present"))) & 1) {
+#ifdef LTP_DEC
+ if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp), ld)) > 0) {
+ return result;
+ }
+#else
+ return 26;
+#endif
+ }
+ }
+#endif
+
+ memcpy(ics2, ics1, sizeof(ic_stream));
+ } else {
+ ics1->ms_mask_present = 0;
+ }
+
+ if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics1,
+ 0, spec_data1)) > 0) {
+ return result;
+ }
+
+#ifdef ERROR_RESILIENCE
+ if (cpe.common_window && (hDecoder->object_type >= ER_OBJECT_START) &&
+ (ics1->predictor_data_present)) {
+ if ((
+#ifdef LTP_DEC
+ ics1->ltp2.data_present =
+#endif
+ faad_get1bit(ld DEBUGVAR(1, 50, "channel_pair_element(): ltp.data_present"))) & 1) {
+#ifdef LTP_DEC
+ if ((result = ltp_data(hDecoder, ics1, &(ics1->ltp2), ld)) > 0) {
+ return result;
+ }
+#else
+ return 26;
+#endif
+ }
+ }
+#endif
+
+ if ((result = individual_channel_stream(hDecoder, &cpe, ld, ics2,
+ 0, spec_data2)) > 0) {
+ return result;
+ }
+
+#ifdef SBR_DEC
+ /* check if next bitstream element is a fill element */
+ /* if so, read it now so SBR decoding can be done in case of a file with SBR */
+ if (faad_showbits(ld, LEN_SE_ID) == ID_FIL) {
+ faad_flushbits(ld, LEN_SE_ID);
+
+ /* one sbr_info describes a channel_element not a channel! */
+ if ((result = fill_element(hDecoder, ld, hDecoder->drc, hDecoder->fr_ch_ele)) > 0) {
+ return result;
+ }
+ }
+#endif
+
+ /* noiseless coding is done, spectral reconstruction is done now */
+ if ((result = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe,
+ spec_data1, spec_data2)) > 0) {
+ return result;
+ }
+
+ return 0;
+}
+
+/* Table 4.4.6 */
+static uint8_t ics_info(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld,
+ uint8_t common_window)
+{
+ uint8_t retval = 0;
+ uint8_t ics_reserved_bit;
+
+ ics_reserved_bit = faad_get1bit(ld
+ DEBUGVAR(1, 43, "ics_info(): ics_reserved_bit"));
+ if (ics_reserved_bit != 0) {
+ return 32;
+ }
+ ics->window_sequence = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 44, "ics_info(): window_sequence"));
+ ics->window_shape = faad_get1bit(ld
+ DEBUGVAR(1, 45, "ics_info(): window_shape"));
+
+#ifdef LD_DEC
+ /* No block switching in LD */
+ if ((hDecoder->object_type == LD) && (ics->window_sequence != ONLY_LONG_SEQUENCE)) {
+ return 32;
+ }
+#endif
+
+ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ ics->max_sfb = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 46, "ics_info(): max_sfb (short)"));
+ ics->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
+ DEBUGVAR(1, 47, "ics_info(): scale_factor_grouping"));
+ } else {
+ ics->max_sfb = (uint8_t)faad_getbits(ld, 6
+ DEBUGVAR(1, 48, "ics_info(): max_sfb (long)"));
+ }
+
+ /* get the grouping information */
+ if ((retval = window_grouping_info(hDecoder, ics)) > 0) {
+ return retval;
+ }
+
+
+ /* should be an error */
+ /* check the range of max_sfb */
+ if (ics->max_sfb > ics->num_swb) {
+ return 16;
+ }
+
+ if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) {
+ if ((ics->predictor_data_present = faad_get1bit(ld
+ DEBUGVAR(1, 49, "ics_info(): predictor_data_present"))) & 1) {
+ if (hDecoder->object_type == MAIN) { /* MPEG2 style AAC predictor */
+ uint8_t sfb;
+
+ uint8_t limit = min(ics->max_sfb, max_pred_sfb(hDecoder->sf_index));
+#ifdef MAIN_DEC
+ ics->pred.limit = limit;
+#endif
+
+ if ((
+#ifdef MAIN_DEC
+ ics->pred.predictor_reset =
+#endif
+ faad_get1bit(ld DEBUGVAR(1, 53, "ics_info(): pred.predictor_reset"))) & 1) {
+#ifdef MAIN_DEC
+ ics->pred.predictor_reset_group_number =
+#endif
+ (uint8_t)faad_getbits(ld, 5 DEBUGVAR(1, 54, "ics_info(): pred.predictor_reset_group_number"));
+ }
+
+ for (sfb = 0; sfb < limit; sfb++) {
+#ifdef MAIN_DEC
+ ics->pred.prediction_used[sfb] =
+#endif
+ faad_get1bit(ld DEBUGVAR(1, 55, "ics_info(): pred.prediction_used"));
+ }
+ }
+#ifdef LTP_DEC
+ else { /* Long Term Prediction */
+ if (hDecoder->object_type < ER_OBJECT_START) {
+ if ((ics->ltp.data_present = faad_get1bit(ld
+ DEBUGVAR(1, 50, "ics_info(): ltp.data_present"))) & 1) {
+ if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0) {
+ return retval;
+ }
+ }
+ if (common_window) {
+ if ((ics->ltp2.data_present = faad_get1bit(ld
+ DEBUGVAR(1, 51, "ics_info(): ltp2.data_present"))) & 1) {
+ if ((retval = ltp_data(hDecoder, ics, &(ics->ltp2), ld)) > 0) {
+ return retval;
+ }
+ }
+ }
+ }
+#ifdef ERROR_RESILIENCE
+ if (!common_window && (hDecoder->object_type >= ER_OBJECT_START)) {
+ if ((ics->ltp.data_present = faad_get1bit(ld
+ DEBUGVAR(1, 50, "ics_info(): ltp.data_present"))) & 1) {
+ ltp_data(hDecoder, ics, &(ics->ltp), ld);
+ }
+ }
+#endif
+ }
+#endif
+ }
+ }
+
+ return retval;
+}
+
+/* Table 4.4.7 */
+static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
+{
+ uint8_t i;
+
+ pul->number_pulse = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 56, "pulse_data(): number_pulse"));
+ pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6
+ DEBUGVAR(1, 57, "pulse_data(): pulse_start_sfb"));
+
+ /* check the range of pulse_start_sfb */
+ if (pul->pulse_start_sfb > ics->num_swb) {
+ return 16;
+ }
+
+ for (i = 0; i < pul->number_pulse + 1; i++) {
+ pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5
+ DEBUGVAR(1, 58, "pulse_data(): pulse_offset"));
+#if 0
+ printf("%d\n", pul->pulse_offset[i]);
+#endif
+ pul->pulse_amp[i] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 59, "pulse_data(): pulse_amp"));
+#if 0
+ printf("%d\n", pul->pulse_amp[i]);
+#endif
+ }
+
+ return 0;
+}
+
+#ifdef COUPLING_DEC
+/* Table 4.4.8: Currently just for skipping the bits... */
+static uint8_t coupling_channel_element(NeAACDecStruct *hDecoder, bitfile *ld)
+{
+ uint8_t c, result = 0;
+ uint8_t ind_sw_cce_flag = 0;
+ uint8_t num_gain_element_lists = 0;
+ uint8_t num_coupled_elements = 0;
+
+ element el_empty = {0};
+ ic_stream ics_empty = {0};
+ int16_t sh_data[1024];
+
+ c = faad_getbits(ld, LEN_TAG
+ DEBUGVAR(1, 900, "coupling_channel_element(): element_instance_tag"));
+
+ ind_sw_cce_flag = faad_get1bit(ld
+ DEBUGVAR(1, 901, "coupling_channel_element(): ind_sw_cce_flag"));
+ num_coupled_elements = faad_getbits(ld, 3
+ DEBUGVAR(1, 902, "coupling_channel_element(): num_coupled_elements"));
+
+ for (c = 0; c < num_coupled_elements + 1; c++) {
+ uint8_t cc_target_is_cpe, cc_target_tag_select;
+
+ num_gain_element_lists++;
+
+ cc_target_is_cpe = faad_get1bit(ld
+ DEBUGVAR(1, 903, "coupling_channel_element(): cc_target_is_cpe"));
+ cc_target_tag_select = faad_getbits(ld, 4
+ DEBUGVAR(1, 904, "coupling_channel_element(): cc_target_tag_select"));
+
+ if (cc_target_is_cpe) {
+ uint8_t cc_l = faad_get1bit(ld
+ DEBUGVAR(1, 905, "coupling_channel_element(): cc_l"));
+ uint8_t cc_r = faad_get1bit(ld
+ DEBUGVAR(1, 906, "coupling_channel_element(): cc_r"));
+
+ if (cc_l && cc_r) {
+ num_gain_element_lists++;
+ }
+ }
+ }
+
+ faad_get1bit(ld
+ DEBUGVAR(1, 907, "coupling_channel_element(): cc_domain"));
+ faad_get1bit(ld
+ DEBUGVAR(1, 908, "coupling_channel_element(): gain_element_sign"));
+ faad_getbits(ld, 2
+ DEBUGVAR(1, 909, "coupling_channel_element(): gain_element_scale"));
+
+ if ((result = individual_channel_stream(hDecoder, &el_empty, ld, &ics_empty,
+ 0, sh_data)) > 0) {
+ return result;
+ }
+
+ /* IS not allowed in single channel */
+ if (ics->is_used) {
+ return 32;
+ }
+
+ for (c = 1; c < num_gain_element_lists; c++) {
+ uint8_t cge;
+
+ if (ind_sw_cce_flag) {
+ cge = 1;
+ } else {
+ cge = faad_get1bit(ld
+ DEBUGVAR(1, 910, "coupling_channel_element(): common_gain_element_present"));
+ }
+
+ if (cge) {
+ huffman_scale_factor(ld);
+ } else {
+ uint8_t g, sfb;
+
+ for (g = 0; g < ics_empty.num_window_groups; g++) {
+ for (sfb = 0; sfb < ics_empty.max_sfb; sfb++) {
+ if (ics_empty.sfb_cb[g][sfb] != ZERO_HCB) {
+ huffman_scale_factor(ld);
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+#endif
+
+/* Table 4.4.10 */
+static uint16_t data_stream_element(NeAACDecStruct *hDecoder, bitfile *ld)
+{
+ uint8_t byte_aligned;
+ uint16_t i, count;
+
+ /* element_instance_tag = */
+ faad_getbits(ld, LEN_TAG
+ DEBUGVAR(1, 60, "data_stream_element(): element_instance_tag"));
+ byte_aligned = faad_get1bit(ld
+ DEBUGVAR(1, 61, "data_stream_element(): byte_aligned"));
+ count = (uint16_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 62, "data_stream_element(): count"));
+ if (count == 255) {
+ count += (uint16_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 63, "data_stream_element(): extra count"));
+ }
+ if (byte_aligned) {
+ faad_byte_align(ld);
+ }
+
+ for (i = 0; i < count; i++) {
+ faad_getbits(ld, LEN_BYTE
+ DEBUGVAR(1, 64, "data_stream_element(): data_stream_byte"));
+ }
+
+ return count;
+}
+
+/* Table 4.4.11 */
+static uint8_t fill_element(NeAACDecStruct *hDecoder, bitfile *ld, drc_info *drc
+#ifdef SBR_DEC
+ , uint8_t sbr_ele
+#endif
+ )
+{
+ uint16_t count;
+#ifdef SBR_DEC
+ uint8_t bs_extension_type;
+#endif
+
+ count = (uint16_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 65, "fill_element(): count"));
+ if (count == 15) {
+ count += (uint16_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 66, "fill_element(): extra count")) - 1;
+ }
+
+ if (count > 0) {
+#ifdef SBR_DEC
+ bs_extension_type = (uint8_t)faad_showbits(ld, 4);
+
+ if ((bs_extension_type == EXT_SBR_DATA) ||
+ (bs_extension_type == EXT_SBR_DATA_CRC)) {
+ if (sbr_ele == INVALID_SBR_ELEMENT) {
+ return 24;
+ }
+
+ if (!hDecoder->sbr[sbr_ele]) {
+ hDecoder->sbr[sbr_ele] = sbrDecodeInit(hDecoder->frameLength,
+ hDecoder->element_id[sbr_ele], 2 * get_sample_rate(hDecoder->sf_index),
+ hDecoder->downSampledSBR
+#ifdef DRM
+ , 0
+#endif
+ );
+ }
+#ifdef DISABLE_SBR
+ if (hDecoder->latm_header_present) {
+ unsigned cnt_1 = count << 3;
+ while (cnt_1 > 7) {
+ faad_getbits(ld, 8
+ DEBUGVAR(1, 999, "sbr_bitstream(): num_align_bits"));
+ cnt_1 -= 8;
+ }
+ faad_getbits(ld, cnt_1);
+ return 0;//
+ }
+#endif
+ hDecoder->sbr_present_flag = 1;
+
+ /* parse the SBR data */
+ hDecoder->sbr[sbr_ele]->ret = sbr_extension_data(ld, hDecoder->sbr[sbr_ele], count,
+ hDecoder->postSeekResetFlag);
+
+#if 0
+ if (hDecoder->sbr[sbr_ele]->ret > 0) {
+ printf("%s\n", NeAACDecGetErrorMessage(hDecoder->sbr[sbr_ele]->ret));
+ }
+#endif
+
+#if (defined(PS_DEC) || defined(DRM_PS))
+ if (hDecoder->sbr[sbr_ele]->ps_used) {
+ hDecoder->ps_used[sbr_ele] = 1;
+
+ /* set element independent flag to 1 as well */
+ hDecoder->ps_used_global = 1;
+ }
+#endif
+ } else {
+#endif
+#ifndef DRM
+ while (count > 0) {
+ count -= extension_payload(ld, drc, count);
+ }
+#else
+ return 30;
+#endif
+#ifdef SBR_DEC
+ }
+#endif
+ }
+
+ return 0;
+}
+
+/* Table 4.4.12 */
+#ifdef SSR_DEC
+static void gain_control_data(bitfile *ld, ic_stream *ics)
+{
+ uint8_t bd, wd, ad;
+ ssr_info *ssr = &(ics->ssr);
+
+ ssr->max_band = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 1000, "gain_control_data(): max_band"));
+
+ if (ics->window_sequence == ONLY_LONG_SEQUENCE) {
+ for (bd = 1; bd <= ssr->max_band; bd++) {
+ for (wd = 0; wd < 1; wd++) {
+ ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 1001, "gain_control_data(): adjust_num"));
+
+ for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) {
+ ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1002, "gain_control_data(): alevcode"));
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ }
+ }
+ }
+ } else if (ics->window_sequence == LONG_START_SEQUENCE) {
+ for (bd = 1; bd <= ssr->max_band; bd++) {
+ for (wd = 0; wd < 2; wd++) {
+ ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 1001, "gain_control_data(): adjust_num"));
+
+ for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) {
+ ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1002, "gain_control_data(): alevcode"));
+ if (wd == 0) {
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ } else {
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ }
+ }
+ }
+ }
+ } else if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ for (bd = 1; bd <= ssr->max_band; bd++) {
+ for (wd = 0; wd < 8; wd++) {
+ ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 1001, "gain_control_data(): adjust_num"));
+
+ for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) {
+ ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1002, "gain_control_data(): alevcode"));
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ }
+ }
+ }
+ } else if (ics->window_sequence == LONG_STOP_SEQUENCE) {
+ for (bd = 1; bd <= ssr->max_band; bd++) {
+ for (wd = 0; wd < 2; wd++) {
+ ssr->adjust_num[bd][wd] = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 1001, "gain_control_data(): adjust_num"));
+
+ for (ad = 0; ad < ssr->adjust_num[bd][wd]; ad++) {
+ ssr->alevcode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1002, "gain_control_data(): alevcode"));
+
+ if (wd == 0) {
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ } else {
+ ssr->aloccode[bd][wd][ad] = (uint8_t)faad_getbits(ld, 5
+ DEBUGVAR(1, 1003, "gain_control_data(): aloccode"));
+ }
+ }
+ }
+ }
+ }
+}
+#endif
+
+#ifdef DRM
+/* Table 4.4.13 ASME */
+void DRM_aac_scalable_main_element(NeAACDecStruct *hDecoder, NeAACDecFrameInfo *hInfo,
+ bitfile *ld, program_config *pce, drc_info *drc)
+{
+ uint8_t retval = 0;
+ uint8_t channels = hDecoder->fr_channels = 0;
+ uint8_t ch;
+ uint8_t this_layer_stereo = (hDecoder->channelConfiguration > 1) ? 1 : 0;
+ element cpe = {0};
+ ic_stream *ics1 = &(cpe.ics1);
+ ic_stream *ics2 = &(cpe.ics2);
+ int16_t *spec_data;
+ ALIGN int16_t spec_data1[1024] = {0};
+ ALIGN int16_t spec_data2[1024] = {0};
+
+ hDecoder->fr_ch_ele = 0;
+
+ hInfo->error = DRM_aac_scalable_main_header(hDecoder, ics1, ics2, ld, this_layer_stereo);
+ if (hInfo->error > 0) {
+ return;
+ }
+
+ cpe.common_window = 1;
+ if (this_layer_stereo) {
+ hDecoder->element_id[0] = ID_CPE;
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) {
+ hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2;
+ }
+ } else {
+ hDecoder->element_id[0] = ID_SCE;
+ }
+
+ if (this_layer_stereo) {
+ cpe.channel = 0;
+ cpe.paired_channel = 1;
+ }
+
+
+ /* Stereo2 / Mono1 */
+ ics1->tns_data_present = faad_get1bit(ld);
+
+#if defined(LTP_DEC)
+ ics1->ltp.data_present = faad_get1bit(ld);
+#elif defined (DRM)
+ if (faad_get1bit(ld)) {
+ hInfo->error = 26;
+ return;
+ }
+#else
+ faad_get1bit(ld);
+#endif
+
+ hInfo->error = side_info(hDecoder, &cpe, ld, ics1, 1);
+ if (hInfo->error > 0) {
+ return;
+ }
+ if (this_layer_stereo) {
+ /* Stereo3 */
+ ics2->tns_data_present = faad_get1bit(ld);
+#ifdef LTP_DEC
+ ics1->ltp.data_present =
+#endif
+ faad_get1bit(ld);
+ hInfo->error = side_info(hDecoder, &cpe, ld, ics2, 1);
+ if (hInfo->error > 0) {
+ return;
+ }
+ }
+ /* Stereo4 / Mono2 */
+ if (ics1->tns_data_present) {
+ tns_data(ics1, &(ics1->tns), ld);
+ }
+ if (this_layer_stereo) {
+ /* Stereo5 */
+ if (ics2->tns_data_present) {
+ tns_data(ics2, &(ics2->tns), ld);
+ }
+ }
+
+#ifdef DRM
+ /* CRC check */
+ if (hDecoder->object_type == DRM_ER_LC) {
+ if ((hInfo->error = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0) {
+ return;
+ }
+ }
+#endif
+
+ /* Stereo6 / Mono3 */
+ /* error resilient spectral data decoding */
+ if ((hInfo->error = reordered_spectral_data(hDecoder, ics1, ld, spec_data1)) > 0) {
+ return;
+ }
+ if (this_layer_stereo) {
+ /* Stereo7 */
+ /* error resilient spectral data decoding */
+ if ((hInfo->error = reordered_spectral_data(hDecoder, ics2, ld, spec_data2)) > 0) {
+ return;
+ }
+ }
+
+
+#ifdef DRM
+#ifdef SBR_DEC
+ /* In case of DRM we need to read the SBR info before channel reconstruction */
+ if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC)) {
+ bitfile ld_sbr = {0};
+ uint32_t i;
+ uint16_t count = 0;
+ uint8_t *revbuffer;
+ uint8_t *prevbufstart;
+ uint8_t *pbufend;
+
+ /* all forward bitreading should be finished at this point */
+ uint32_t bitsconsumed = faad_get_processed_bits(ld);
+ uint32_t buffer_size = faad_origbitbuffer_size(ld);
+ uint8_t *buffer = (uint8_t*)faad_origbitbuffer(ld);
+
+ if (bitsconsumed + 8 > buffer_size * 8) {
+ hInfo->error = 14;
+ return;
+ }
+
+ if (!hDecoder->sbr[0]) {
+ hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
+ 2 * get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
+ }
+
+ /* Reverse bit reading of SBR data in DRM audio frame */
+ revbuffer = (uint8_t*)faad_malloc(buffer_size * sizeof(uint8_t));
+ prevbufstart = revbuffer;
+ pbufend = &buffer[buffer_size - 1];
+ for (i = 0; i < buffer_size; i++) {
+ *prevbufstart++ = tabFlipbits[*pbufend--];
+ }
+
+ /* Set SBR data */
+ /* consider 8 bits from AAC-CRC */
+ /* SBR buffer size is original buffer size minus AAC buffer size */
+ count = (uint16_t)bit2byte(buffer_size * 8 - bitsconsumed);
+ faad_initbits(&ld_sbr, revbuffer, count);
+
+ hDecoder->sbr[0]->sample_rate = get_sample_rate(hDecoder->sf_index);
+ hDecoder->sbr[0]->sample_rate *= 2;
+
+ faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */
+
+ hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count, hDecoder->postSeekResetFlag);
+#if (defined(PS_DEC) || defined(DRM_PS))
+ if (hDecoder->sbr[0]->ps_used) {
+ hDecoder->ps_used[0] = 1;
+ hDecoder->ps_used_global = 1;
+ }
+#endif
+
+ if (ld_sbr.error) {
+ hDecoder->sbr[0]->ret = 1;
+ }
+
+ /* check CRC */
+ /* no need to check it if there was already an error */
+ if (hDecoder->sbr[0]->ret == 0) {
+ hDecoder->sbr[0]->ret = (uint8_t)faad_check_CRC(&ld_sbr, (uint16_t)faad_get_processed_bits(&ld_sbr) - 8);
+ }
+
+ /* SBR data was corrupted, disable it until the next header */
+ if (hDecoder->sbr[0]->ret != 0) {
+ hDecoder->sbr[0]->header_count = 0;
+ }
+
+ faad_endbits(&ld_sbr);
+
+ if (revbuffer) {
+ faad_free(revbuffer);
+ }
+ }
+#endif
+#endif
+
+ if (this_layer_stereo) {
+ hInfo->error = reconstruct_channel_pair(hDecoder, ics1, ics2, &cpe, spec_data1, spec_data2);
+ if (hInfo->error > 0) {
+ return;
+ }
+ } else {
+ hInfo->error = reconstruct_single_channel(hDecoder, ics1, &cpe, spec_data1);
+ if (hInfo->error > 0) {
+ return;
+ }
+ }
+
+ /* map output channels position to internal data channels */
+ if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2) {
+ /* this might be faulty when pce_set is true */
+ hDecoder->internal_channel[channels] = channels;
+ hDecoder->internal_channel[channels + 1] = channels + 1;
+ } else {
+ hDecoder->internal_channel[channels] = channels;
+ }
+
+ hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
+ hDecoder->fr_ch_ele++;
+
+ return;
+}
+
+/* Table 4.4.15 */
+static int8_t DRM_aac_scalable_main_header(NeAACDecStruct *hDecoder, ic_stream *ics1, ic_stream *ics2,
+ bitfile *ld, uint8_t this_layer_stereo)
+{
+ uint8_t retval = 0;
+ uint8_t ch;
+ ic_stream *ics;
+ uint8_t ics_reserved_bit;
+
+ ics_reserved_bit = faad_get1bit(ld
+ DEBUGVAR(1, 300, "aac_scalable_main_header(): ics_reserved_bits"));
+ if (ics_reserved_bit != 0) {
+ return 32;
+ }
+ ics1->window_sequence = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 301, "aac_scalable_main_header(): window_sequence"));
+ ics1->window_shape = faad_get1bit(ld
+ DEBUGVAR(1, 302, "aac_scalable_main_header(): window_shape"));
+
+ if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ ics1->max_sfb = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 303, "aac_scalable_main_header(): max_sfb (short)"));
+ ics1->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
+ DEBUGVAR(1, 304, "aac_scalable_main_header(): scale_factor_grouping"));
+ } else {
+ ics1->max_sfb = (uint8_t)faad_getbits(ld, 6
+ DEBUGVAR(1, 305, "aac_scalable_main_header(): max_sfb (long)"));
+ }
+
+ /* get the grouping information */
+ if ((retval = window_grouping_info(hDecoder, ics1)) > 0) {
+ return retval;
+ }
+
+ /* should be an error */
+ /* check the range of max_sfb */
+ if (ics1->max_sfb > ics1->num_swb) {
+ return 16;
+ }
+
+ if (this_layer_stereo) {
+ ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 306, "aac_scalable_main_header(): ms_mask_present"));
+ if (ics1->ms_mask_present == 3) {
+ /* bitstream error */
+ return 32;
+ }
+ if (ics1->ms_mask_present == 1) {
+ uint8_t g, sfb;
+ for (g = 0; g < ics1->num_window_groups; g++) {
+ for (sfb = 0; sfb < ics1->max_sfb; sfb++) {
+ ics1->ms_used[g][sfb] = faad_get1bit(ld
+ DEBUGVAR(1, 307, "aac_scalable_main_header(): faad_get1bit"));
+ }
+ }
+ }
+
+ memcpy(ics2, ics1, sizeof(ic_stream));
+ } else {
+ ics1->ms_mask_present = 0;
+ }
+
+ return 0;
+}
+#endif
+
+static uint8_t side_info(NeAACDecStruct *hDecoder, element *ele,
+ bitfile *ld, ic_stream *ics, uint8_t scal_flag)
+{
+ uint8_t result;
+
+ ics->global_gain = (uint8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 67, "individual_channel_stream(): global_gain"));
+
+ if (!ele->common_window && !scal_flag) {
+ if ((result = ics_info(hDecoder, ics, ld, ele->common_window)) > 0) {
+ return result;
+ }
+ }
+
+ if ((result = section_data(hDecoder, ics, ld)) > 0) {
+ return result;
+ }
+
+ if ((result = scale_factor_data(hDecoder, ics, ld)) > 0) {
+ return result;
+ }
+
+ if (!scal_flag) {
+ /**
+ ** NOTE: It could be that pulse data is available in scalable AAC too,
+ ** as said in Amendment 1, this could be only the case for ER AAC,
+ ** though. (have to check this out later)
+ **/
+ /* get pulse data */
+ if ((ics->pulse_data_present = faad_get1bit(ld
+ DEBUGVAR(1, 68, "individual_channel_stream(): pulse_data_present"))) & 1) {
+ if ((result = pulse_data(ics, &(ics->pul), ld)) > 0) {
+ return result;
+ }
+ }
+
+ /* get tns data */
+ if ((ics->tns_data_present = faad_get1bit(ld
+ DEBUGVAR(1, 69, "individual_channel_stream(): tns_data_present"))) & 1) {
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->object_type < ER_OBJECT_START)
+#endif
+ tns_data(ics, &(ics->tns), ld);
+ }
+
+ /* get gain control data */
+ if ((ics->gain_control_data_present = faad_get1bit(ld
+ DEBUGVAR(1, 70, "individual_channel_stream(): gain_control_data_present"))) & 1) {
+#ifdef SSR_DEC
+ if (hDecoder->object_type != SSR) {
+ return 1;
+ } else {
+ gain_control_data(ld, ics);
+ }
+#else
+ return 1;
+#endif
+ }
+ }
+
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->aacSpectralDataResilienceFlag) {
+ ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
+ DEBUGVAR(1, 147, "individual_channel_stream(): length_of_reordered_spectral_data"));
+
+ if (hDecoder->channelConfiguration == 2) {
+ if (ics->length_of_reordered_spectral_data > 6144) {
+ ics->length_of_reordered_spectral_data = 6144;
+ }
+ } else {
+ if (ics->length_of_reordered_spectral_data > 12288) {
+ ics->length_of_reordered_spectral_data = 12288;
+ }
+ }
+
+ ics->length_of_longest_codeword = (uint8_t)faad_getbits(ld, 6
+ DEBUGVAR(1, 148, "individual_channel_stream(): length_of_longest_codeword"));
+ if (ics->length_of_longest_codeword >= 49) {
+ ics->length_of_longest_codeword = 49;
+ }
+ }
+
+ /* RVLC spectral data is put here */
+ if (hDecoder->aacScalefactorDataResilienceFlag) {
+ if ((result = rvlc_decode_scale_factors(ics, ld)) > 0) {
+ return result;
+ }
+ }
+#endif
+
+ return 0;
+}
+
+/* Table 4.4.24 */
+static uint8_t individual_channel_stream(NeAACDecStruct *hDecoder, element *ele,
+ bitfile *ld, ic_stream *ics, uint8_t scal_flag,
+ int16_t *spec_data)
+{
+ uint8_t result;
+
+ result = side_info(hDecoder, ele, ld, ics, scal_flag);
+ if (result > 0) {
+ return result;
+ }
+
+ if (hDecoder->object_type >= ER_OBJECT_START) {
+ if (ics->tns_data_present) {
+ tns_data(ics, &(ics->tns), ld);
+ }
+ }
+
+#ifdef DRM
+ /* CRC check */
+ if (hDecoder->object_type == DRM_ER_LC) {
+ if ((result = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0) {
+ return result;
+ }
+ }
+#endif
+
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->aacSpectralDataResilienceFlag) {
+ /* error resilient spectral data decoding */
+ if ((result = reordered_spectral_data(hDecoder, ics, ld, spec_data)) > 0) {
+ return result;
+ }
+ } else {
+#endif
+ /* decode the spectral data */
+ if ((result = spectral_data(hDecoder, ics, ld, spec_data)) > 0) {
+ return result;
+ }
+#ifdef ERROR_RESILIENCE
+ }
+#endif
+
+ /* pulse coding reconstruction */
+ if (ics->pulse_data_present) {
+ if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) {
+ if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0) {
+ return result;
+ }
+ } else {
+ return 2; /* pulse coding not allowed for short blocks */
+ }
+ }
+
+ return 0;
+}
+
+/* Table 4.4.25 */
+static uint8_t section_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld)
+{
+ uint8_t g;
+ uint8_t sect_esc_val, sect_bits;
+
+ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ sect_bits = 3;
+ } else {
+ sect_bits = 5;
+ }
+ sect_esc_val = (1 << sect_bits) - 1;
+
+#if 0
+ printf("\ntotal sfb %d\n", ics->max_sfb);
+ printf(" sect top cb\n");
+#endif
+
+ for (g = 0; g < ics->num_window_groups; g++) {
+ uint8_t k = 0;
+ uint8_t i = 0;
+
+ while (k < ics->max_sfb) {
+#ifdef ERROR_RESILIENCE
+ uint8_t vcb11 = 0;
+#endif
+ uint8_t sfb;
+ uint8_t sect_len_incr;
+ uint16_t sect_len = 0;
+ uint8_t sect_cb_bits = 4;
+
+ /* if "faad_getbits" detects error and returns "0", "k" is never
+ incremented and we cannot leave the while loop */
+ if (ld->error != 0) {
+ return 14;
+ }
+
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->aacSectionDataResilienceFlag) {
+ sect_cb_bits = 5;
+ }
+#endif
+
+ ics->sect_cb[g][i] = (uint8_t)faad_getbits(ld, sect_cb_bits
+ DEBUGVAR(1, 71, "section_data(): sect_cb"));
+
+ if (ics->sect_cb[g][i] == 12) {
+ return 32;
+ }
+
+#if 0
+ printf("%d\n", ics->sect_cb[g][i]);
+#endif
+
+#ifndef DRM
+ if (ics->sect_cb[g][i] == NOISE_HCB) {
+ ics->noise_used = 1;
+ }
+#else
+ /* PNS not allowed in DRM */
+ if (ics->sect_cb[g][i] == NOISE_HCB) {
+ return 29;
+ }
+#endif
+ if (ics->sect_cb[g][i] == INTENSITY_HCB2 || ics->sect_cb[g][i] == INTENSITY_HCB) {
+ ics->is_used = 1;
+ }
+
+#ifdef ERROR_RESILIENCE
+ if (hDecoder->aacSectionDataResilienceFlag) {
+ if ((ics->sect_cb[g][i] == 11) ||
+ ((ics->sect_cb[g][i] >= 16) && (ics->sect_cb[g][i] <= 32))) {
+ vcb11 = 1;
+ }
+ }
+ if (vcb11) {
+ sect_len_incr = 1;
+ } else {
+#endif
+ sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits
+ DEBUGVAR(1, 72, "section_data(): sect_len_incr"));
+#ifdef ERROR_RESILIENCE
+ }
+#endif
+ while ((sect_len_incr == sect_esc_val) /* &&
+ (k+sect_len < ics->max_sfb)*/) {
+ sect_len += sect_len_incr;
+ sect_len_incr = (uint8_t)faad_getbits(ld, sect_bits
+ DEBUGVAR(1, 72, "section_data(): sect_len_incr"));
+ }
+
+ sect_len += sect_len_incr;
+
+ ics->sect_start[g][i] = k;
+ ics->sect_end[g][i] = k + sect_len;
+
+#if 0
+ printf("%d\n", ics->sect_start[g][i]);
+#endif
+#if 0
+ printf("%d\n", ics->sect_end[g][i]);
+#endif
+
+ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ if (k + sect_len > 8 * 15) {
+ return 15;
+ }
+ if (i >= 8 * 15) {
+ return 15;
+ }
+ } else {
+ if (k + sect_len > MAX_SFB) {
+ return 15;
+ }
+ if (i >= MAX_SFB) {
+ return 15;
+ }
+ }
+
+ for (sfb = k; sfb < k + sect_len; sfb++) {
+ ics->sfb_cb[g][sfb] = ics->sect_cb[g][i];
+#if 0
+ printf("%d\n", ics->sfb_cb[g][sfb]);
+#endif
+ }
+
+#if 0
+ printf(" %6d %6d %6d\n",
+ i,
+ ics->sect_end[g][i],
+ ics->sect_cb[g][i]);
+#endif
+
+ k += sect_len;
+ i++;
+ }
+ ics->num_sec[g] = i;
+
+ /* the sum of all sect_len_incr elements for a given window
+ * group shall equal max_sfb */
+ if (k != ics->max_sfb) {
+ return 32;
+ }
+#if 0
+ printf("%d\n", ics->num_sec[g]);
+#endif
+ }
+
+#if 0
+ printf("\n");
+#endif
+
+ return 0;
+}
+
+/*
+ * decode_scale_factors()
+ * decodes the scalefactors from the bitstream
+ */
+/*
+ * All scalefactors (and also the stereo positions and pns energies) are
+ * transmitted using Huffman coded DPCM relative to the previous active
+ * scalefactor (respectively previous stereo position or previous pns energy,
+ * see subclause 4.6.2 and 4.6.3). The first active scalefactor is
+ * differentially coded relative to the global gain.
+ */
+static uint8_t decode_scale_factors(ic_stream *ics, bitfile *ld)
+{
+ uint8_t g, sfb;
+ int16_t t;
+ int8_t noise_pcm_flag = 1;
+
+ int16_t scale_factor = ics->global_gain;
+ int16_t is_position = 0;
+ int16_t noise_energy = ics->global_gain - 90;
+
+ for (g = 0; g < ics->num_window_groups; g++) {
+ for (sfb = 0; sfb < ics->max_sfb; sfb++) {
+ switch (ics->sfb_cb[g][sfb]) {
+ case ZERO_HCB: /* zero book */
+ ics->scale_factors[g][sfb] = 0;
+ //#define SF_PRINT
+#ifdef SF_PRINT
+ printf("%d\n", ics->scale_factors[g][sfb]);
+#endif
+ break;
+ case INTENSITY_HCB: /* intensity books */
+ case INTENSITY_HCB2:
+
+ /* decode intensity position */
+ t = huffman_scale_factor(ld);
+ is_position += (t - 60);
+ ics->scale_factors[g][sfb] = is_position;
+#ifdef SF_PRINT
+ printf("%d\n", ics->scale_factors[g][sfb]);
+#endif
+
+ break;
+ case NOISE_HCB: /* noise books */
+
+#ifndef DRM
+ /* decode noise energy */
+ if (noise_pcm_flag) {
+ noise_pcm_flag = 0;
+ t = (int16_t)faad_getbits(ld, 9
+ DEBUGVAR(1, 73, "scale_factor_data(): first noise")) - 256;
+ } else {
+ t = huffman_scale_factor(ld);
+ t -= 60;
+ }
+ noise_energy += t;
+ ics->scale_factors[g][sfb] = noise_energy;
+#ifdef SF_PRINT
+ printf("%d\n", ics->scale_factors[g][sfb]);
+#endif
+#else
+ /* PNS not allowed in DRM */
+ return 29;
+#endif
+
+ break;
+ default: /* spectral books */
+
+ /* ics->scale_factors[g][sfb] must be between 0 and 255 */
+
+ ics->scale_factors[g][sfb] = 0;
+
+ /* decode scale factor */
+ t = huffman_scale_factor(ld);
+ scale_factor += (t - 60);
+ if (scale_factor < 0 || scale_factor > 255) {
+ return 4;
+ }
+ ics->scale_factors[g][sfb] = scale_factor;
+#ifdef SF_PRINT
+ printf("%d\n", ics->scale_factors[g][sfb]);
+#endif
+
+ break;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* Table 4.4.26 */
+static uint8_t scale_factor_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld)
+{
+ uint8_t ret = 0;
+#ifdef PROFILE
+ int64_t count = faad_get_ts();
+#endif
+
+#ifdef ERROR_RESILIENCE
+ if (!hDecoder->aacScalefactorDataResilienceFlag) {
+#endif
+ ret = decode_scale_factors(ics, ld);
+#ifdef ERROR_RESILIENCE
+ } else {
+ /* In ER AAC the parameters for RVLC are seperated from the actual
+ data that holds the scale_factors.
+ Strangely enough, 2 parameters for HCR are put inbetween them.
+ */
+ ret = rvlc_scale_factor_data(ics, ld);
+ }
+#endif
+
+#ifdef PROFILE
+ count = faad_get_ts() - count;
+ hDecoder->scalefac_cycles += count;
+#endif
+
+ return ret;
+}
+
+/* Table 4.4.27 */
+static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld)
+{
+ uint8_t w, filt, i, start_coef_bits, coef_bits;
+ uint8_t n_filt_bits = 2;
+ uint8_t length_bits = 6;
+ uint8_t order_bits = 5;
+
+ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ n_filt_bits = 1;
+ length_bits = 4;
+ order_bits = 3;
+ }
+
+ for (w = 0; w < ics->num_windows; w++) {
+ tns->n_filt[w] = (uint8_t)faad_getbits(ld, n_filt_bits
+ DEBUGVAR(1, 74, "tns_data(): n_filt"));
+#if 0
+ printf("%d\n", tns->n_filt[w]);
+#endif
+
+ if (tns->n_filt[w]) {
+ if ((tns->coef_res[w] = faad_get1bit(ld
+ DEBUGVAR(1, 75, "tns_data(): coef_res"))) & 1) {
+ start_coef_bits = 4;
+ } else {
+ start_coef_bits = 3;
+ }
+#if 0
+ printf("%d\n", tns->coef_res[w]);
+#endif
+ }
+
+ for (filt = 0; filt < tns->n_filt[w]; filt++) {
+ tns->length[w][filt] = (uint8_t)faad_getbits(ld, length_bits
+ DEBUGVAR(1, 76, "tns_data(): length"));
+#if 0
+ printf("%d\n", tns->length[w][filt]);
+#endif
+ tns->order[w][filt] = (uint8_t)faad_getbits(ld, order_bits
+ DEBUGVAR(1, 77, "tns_data(): order"));
+#if 0
+ printf("%d\n", tns->order[w][filt]);
+#endif
+ if (tns->order[w][filt]) {
+ tns->direction[w][filt] = faad_get1bit(ld
+ DEBUGVAR(1, 78, "tns_data(): direction"));
+#if 0
+ printf("%d\n", tns->direction[w][filt]);
+#endif
+ tns->coef_compress[w][filt] = faad_get1bit(ld
+ DEBUGVAR(1, 79, "tns_data(): coef_compress"));
+#if 0
+ printf("%d\n", tns->coef_compress[w][filt]);
+#endif
+
+ coef_bits = start_coef_bits - tns->coef_compress[w][filt];
+ for (i = 0; i < tns->order[w][filt]; i++) {
+ tns->coef[w][filt][i] = (uint8_t)faad_getbits(ld, coef_bits
+ DEBUGVAR(1, 80, "tns_data(): coef"));
+#if 0
+ printf("%d\n", tns->coef[w][filt][i]);
+#endif
+ }
+ }
+ }
+ }
+}
+
+#ifdef LTP_DEC
+/* Table 4.4.28 */
+static uint8_t ltp_data(NeAACDecStruct *hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld)
+{
+ uint8_t sfb, w;
+
+ ltp->lag = 0;
+
+#ifdef LD_DEC
+ if (hDecoder->object_type == LD) {
+ ltp->lag_update = (uint8_t)faad_getbits(ld, 1
+ DEBUGVAR(1, 142, "ltp_data(): lag_update"));
+
+ if (ltp->lag_update) {
+ ltp->lag = (uint16_t)faad_getbits(ld, 10
+ DEBUGVAR(1, 81, "ltp_data(): lag"));
+ }
+ } else {
+#endif
+ ltp->lag = (uint16_t)faad_getbits(ld, 11
+ DEBUGVAR(1, 81, "ltp_data(): lag"));
+#ifdef LD_DEC
+ }
+#endif
+
+ /* Check length of lag */
+ if (ltp->lag > (hDecoder->frameLength << 1)) {
+ return 18;
+ }
+
+ ltp->coef = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 82, "ltp_data(): coef"));
+
+ if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) {
+ for (w = 0; w < ics->num_windows; w++) {
+ if ((ltp->short_used[w] = faad_get1bit(ld
+ DEBUGVAR(1, 83, "ltp_data(): short_used"))) & 1) {
+ ltp->short_lag_present[w] = faad_get1bit(ld
+ DEBUGVAR(1, 84, "ltp_data(): short_lag_present"));
+ if (ltp->short_lag_present[w]) {
+ ltp->short_lag[w] = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 85, "ltp_data(): short_lag"));
+ }
+ }
+ }
+ } else {
+ ltp->last_band = (ics->max_sfb < MAX_LTP_SFB ? ics->max_sfb : MAX_LTP_SFB);
+
+ for (sfb = 0; sfb < ltp->last_band; sfb++) {
+ ltp->long_used[sfb] = faad_get1bit(ld
+ DEBUGVAR(1, 86, "ltp_data(): long_used"));
+ }
+ }
+
+ return 0;
+}
+#endif
+
+/* Table 4.4.29 */
+static uint8_t spectral_data(NeAACDecStruct *hDecoder, ic_stream *ics, bitfile *ld,
+ int16_t *spectral_data)
+{
+ int8_t i;
+ uint8_t g;
+ uint16_t inc, k, p = 0;
+ uint8_t groups = 0;
+ uint8_t sect_cb;
+ uint8_t result;
+ uint16_t nshort = hDecoder->frameLength / 8;
+
+#ifdef PROFILE
+ int64_t count = faad_get_ts();
+#endif
+
+ for (g = 0; g < ics->num_window_groups; g++) {
+ p = groups * nshort;
+
+ for (i = 0; i < ics->num_sec[g]; i++) {
+ sect_cb = ics->sect_cb[g][i];
+
+ inc = (sect_cb >= FIRST_PAIR_HCB) ? 2 : 4;
+
+ switch (sect_cb) {
+ case ZERO_HCB:
+ case NOISE_HCB:
+ case INTENSITY_HCB:
+ case INTENSITY_HCB2:
+ //#define SD_PRINT
+#ifdef SD_PRINT
+ {
+ int j;
+ for (j = ics->sect_sfb_offset[g][ics->sect_start[g][i]]; j < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; j++) {
+ printf("%d\n", 0);
+ }
+ }
+#endif
+ //#define SFBO_PRINT
+#ifdef SFBO_PRINT
+ printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
+#endif
+ p += (ics->sect_sfb_offset[g][ics->sect_end[g][i]] -
+ ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
+ break;
+ default:
+#ifdef SFBO_PRINT
+ printf("%d\n", ics->sect_sfb_offset[g][ics->sect_start[g][i]]);
+#endif
+ for (k = ics->sect_sfb_offset[g][ics->sect_start[g][i]];
+ k < ics->sect_sfb_offset[g][ics->sect_end[g][i]]; k += inc) {
+ if ((result = huffman_spectral_data(sect_cb, ld, &spectral_data[p])) > 0) {
+ return result;
+ }
+#ifdef SD_PRINT
+ {
+ int j;
+ for (j = p; j < p + inc; j++) {
+ printf("%d\n", spectral_data[j]);
+ }
+ }
+#endif
+ p += inc;
+ }
+ break;
+ }
+ }
+ groups += ics->window_group_length[g];
+ }
+
+#ifdef PROFILE
+ count = faad_get_ts() - count;
+ hDecoder->spectral_cycles += count;
+#endif
+
+ return 0;
+}
+
+/* Table 4.4.30 */
+static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count)
+{
+ uint16_t i, n, dataElementLength;
+ uint8_t dataElementLengthPart;
+ uint8_t align = 4, data_element_version, loopCounter;
+
+ uint8_t extension_type = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 87, "extension_payload(): extension_type"));
+
+ switch (extension_type) {
+ case EXT_DYNAMIC_RANGE:
+ drc->present = 1;
+ n = dynamic_range_info(ld, drc);
+ return n;
+ case EXT_FILL_DATA:
+ /* fill_nibble = */
+ faad_getbits(ld, 4
+ DEBUGVAR(1, 136, "extension_payload(): fill_nibble")); /* must be ‘0000’ */
+ for (i = 0; i < count - 1; i++) {
+ /* fill_byte[i] = */ faad_getbits(ld, 8
+ DEBUGVAR(1, 88, "extension_payload(): fill_byte")); /* must be ‘10100101’ */
+ }
+ return count;
+ case EXT_DATA_ELEMENT:
+ data_element_version = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 400, "extension_payload(): data_element_version"));
+ switch (data_element_version) {
+ case ANC_DATA:
+ loopCounter = 0;
+ dataElementLength = 0;
+ do {
+ dataElementLengthPart = (uint8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 401, "extension_payload(): dataElementLengthPart"));
+ dataElementLength += dataElementLengthPart;
+ loopCounter++;
+ } while (dataElementLengthPart == 255);
+
+ for (i = 0; i < dataElementLength; i++) {
+ /* data_element_byte[i] = */ faad_getbits(ld, 8
+ DEBUGVAR(1, 402, "extension_payload(): data_element_byte"));
+ return (dataElementLength + loopCounter + 1);
+ }
+ default:
+ align = 0;
+ }
+ case EXT_FIL:
+ default:
+ faad_getbits(ld, align
+ DEBUGVAR(1, 88, "extension_payload(): fill_nibble"));
+ for (i = 0; i < count - 1; i++) {
+ /* other_bits[i] = */ faad_getbits(ld, 8
+ DEBUGVAR(1, 89, "extension_payload(): fill_bit"));
+ }
+ return count;
+ }
+}
+
+/* Table 4.4.31 */
+static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc)
+{
+ uint8_t i, n = 1;
+ uint8_t band_incr;
+
+ drc->num_bands = 1;
+
+ if (faad_get1bit(ld
+ DEBUGVAR(1, 90, "dynamic_range_info(): has instance_tag")) & 1) {
+ drc->pce_instance_tag = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 91, "dynamic_range_info(): pce_instance_tag"));
+ /* drc->drc_tag_reserved_bits = */
+ faad_getbits(ld, 4
+ DEBUGVAR(1, 92, "dynamic_range_info(): drc_tag_reserved_bits"));
+ n++;
+ }
+
+ drc->excluded_chns_present = faad_get1bit(ld
+ DEBUGVAR(1, 93, "dynamic_range_info(): excluded_chns_present"));
+ if (drc->excluded_chns_present == 1) {
+ n += excluded_channels(ld, drc);
+ }
+
+ if (faad_get1bit(ld
+ DEBUGVAR(1, 94, "dynamic_range_info(): has bands data")) & 1) {
+ band_incr = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 95, "dynamic_range_info(): band_incr"));
+ /* drc->drc_bands_reserved_bits = */
+ faad_getbits(ld, 4
+ DEBUGVAR(1, 96, "dynamic_range_info(): drc_bands_reserved_bits"));
+ n++;
+ drc->num_bands += band_incr;
+
+ for (i = 0; i < drc->num_bands; i++) {
+ drc->band_top[i] = (uint8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 97, "dynamic_range_info(): band_top"));
+ n++;
+ }
+ }
+
+ if (faad_get1bit(ld
+ DEBUGVAR(1, 98, "dynamic_range_info(): has prog_ref_level")) & 1) {
+ drc->prog_ref_level = (uint8_t)faad_getbits(ld, 7
+ DEBUGVAR(1, 99, "dynamic_range_info(): prog_ref_level"));
+ /* drc->prog_ref_level_reserved_bits = */
+ faad_get1bit(ld
+ DEBUGVAR(1, 100, "dynamic_range_info(): prog_ref_level_reserved_bits"));
+ n++;
+ }
+
+ for (i = 0; i < drc->num_bands; i++) {
+ drc->dyn_rng_sgn[i] = faad_get1bit(ld
+ DEBUGVAR(1, 101, "dynamic_range_info(): dyn_rng_sgn"));
+ drc->dyn_rng_ctl[i] = (uint8_t)faad_getbits(ld, 7
+ DEBUGVAR(1, 102, "dynamic_range_info(): dyn_rng_ctl"));
+ n++;
+ }
+
+ return n;
+}
+
+/* Table 4.4.32 */
+static uint8_t excluded_channels(bitfile *ld, drc_info *drc)
+{
+ uint8_t i, n = 0;
+ uint8_t num_excl_chan = 7;
+
+ for (i = 0; i < 7; i++) {
+ drc->exclude_mask[i] = faad_get1bit(ld
+ DEBUGVAR(1, 103, "excluded_channels(): exclude_mask"));
+ }
+ n++;
+
+ while ((drc->additional_excluded_chns[n - 1] = faad_get1bit(ld
+ DEBUGVAR(1, 104, "excluded_channels(): additional_excluded_chns"))) == 1) {
+ for (i = num_excl_chan; i < num_excl_chan + 7; i++) {
+ drc->exclude_mask[i] = faad_get1bit(ld
+ DEBUGVAR(1, 105, "excluded_channels(): exclude_mask"));
+ }
+ n++;
+ num_excl_chan += 7;
+ }
+
+ return n;
+}
+
+/* Annex A: Audio Interchange Formats */
+
+/* Table 1.A.2 */
+void get_adif_header(adif_header *adif, bitfile *ld)
+{
+ uint8_t i;
+
+ /* adif_id[0] = */
+ faad_getbits(ld, 8
+ DEBUGVAR(1, 106, "get_adif_header(): adif_id[0]"));
+ /* adif_id[1] = */
+ faad_getbits(ld, 8
+ DEBUGVAR(1, 107, "get_adif_header(): adif_id[1]"));
+ /* adif_id[2] = */
+ faad_getbits(ld, 8
+ DEBUGVAR(1, 108, "get_adif_header(): adif_id[2]"));
+ /* adif_id[3] = */
+ faad_getbits(ld, 8
+ DEBUGVAR(1, 109, "get_adif_header(): adif_id[3]"));
+ adif->copyright_id_present = faad_get1bit(ld
+ DEBUGVAR(1, 110, "get_adif_header(): copyright_id_present"));
+ if (adif->copyright_id_present) {
+ for (i = 0; i < 72 / 8; i++) {
+ adif->copyright_id[i] = (int8_t)faad_getbits(ld, 8
+ DEBUGVAR(1, 111, "get_adif_header(): copyright_id"));
+ }
+ adif->copyright_id[i] = 0;
+ }
+ adif->original_copy = faad_get1bit(ld
+ DEBUGVAR(1, 112, "get_adif_header(): original_copy"));
+ adif->home = faad_get1bit(ld
+ DEBUGVAR(1, 113, "get_adif_header(): home"));
+ adif->bitstream_type = faad_get1bit(ld
+ DEBUGVAR(1, 114, "get_adif_header(): bitstream_type"));
+ adif->bitrate = faad_getbits(ld, 23
+ DEBUGVAR(1, 115, "get_adif_header(): bitrate"));
+ adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 116, "get_adif_header(): num_program_config_elements"));
+
+ for (i = 0; i < adif->num_program_config_elements + 1; i++) {
+ if (adif->bitstream_type == 0) {
+ adif->adif_buffer_fullness = faad_getbits(ld, 20
+ DEBUGVAR(1, 117, "get_adif_header(): adif_buffer_fullness"));
+ } else {
+ adif->adif_buffer_fullness = 0;
+ }
+
+ program_config_element(&adif->pce[i], ld);
+ }
+}
+
+/* Table 1.A.5 */
+uint8_t adts_frame(adts_header *adts, bitfile *ld)
+{
+ /* faad_byte_align(ld); */
+ if (adts_fixed_header(adts, ld)) {
+ return 5;
+ }
+ adts_variable_header(adts, ld);
+ adts_error_check(adts, ld);
+
+ return 0;
+}
+
+/* Table 1.A.6 */
+static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld)
+{
+ uint16_t i;
+ uint8_t sync_err = 1;
+
+ /* try to recover from sync errors */
+ for (i = 0; i < 768; i++) {
+ adts->syncword = (uint16_t)faad_showbits(ld, 12);
+ if (adts->syncword != 0xFFF) {
+ faad_getbits(ld, 8
+ DEBUGVAR(0, 0, ""));
+ } else {
+ sync_err = 0;
+ faad_getbits(ld, 12
+ DEBUGVAR(1, 118, "adts_fixed_header(): syncword"));
+ break;
+ }
+ }
+ if (sync_err) {
+ return 5;
+ }
+
+ adts->id = faad_get1bit(ld
+ DEBUGVAR(1, 119, "adts_fixed_header(): id"));
+ adts->layer = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 120, "adts_fixed_header(): layer"));
+ adts->protection_absent = faad_get1bit(ld
+ DEBUGVAR(1, 121, "adts_fixed_header(): protection_absent"));
+ adts->profile = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 122, "adts_fixed_header(): profile"));
+ adts->sf_index = (uint8_t)faad_getbits(ld, 4
+ DEBUGVAR(1, 123, "adts_fixed_header(): sf_index"));
+ adts->private_bit = faad_get1bit(ld
+ DEBUGVAR(1, 124, "adts_fixed_header(): private_bit"));
+ adts->channel_configuration = (uint8_t)faad_getbits(ld, 3
+ DEBUGVAR(1, 125, "adts_fixed_header(): channel_configuration"));
+ adts->original = faad_get1bit(ld
+ DEBUGVAR(1, 126, "adts_fixed_header(): original"));
+ adts->home = faad_get1bit(ld
+ DEBUGVAR(1, 127, "adts_fixed_header(): home"));
+
+ if (adts->old_format == 1) {
+ /* Removed in corrigendum 14496-3:2002 */
+ if (adts->id == 0) {
+ adts->emphasis = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 128, "adts_fixed_header(): emphasis"));
+ }
+ }
+
+ return 0;
+}
+
+/* Table 1.A.7 */
+static void adts_variable_header(adts_header *adts, bitfile *ld)
+{
+ adts->copyright_identification_bit = faad_get1bit(ld
+ DEBUGVAR(1, 129, "adts_variable_header(): copyright_identification_bit"));
+ adts->copyright_identification_start = faad_get1bit(ld
+ DEBUGVAR(1, 130, "adts_variable_header(): copyright_identification_start"));
+ adts->aac_frame_length = (uint16_t)faad_getbits(ld, 13
+ DEBUGVAR(1, 131, "adts_variable_header(): aac_frame_length"));
+ adts->adts_buffer_fullness = (uint16_t)faad_getbits(ld, 11
+ DEBUGVAR(1, 132, "adts_variable_header(): adts_buffer_fullness"));
+ adts->no_raw_data_blocks_in_frame = (uint8_t)faad_getbits(ld, 2
+ DEBUGVAR(1, 133, "adts_variable_header(): no_raw_data_blocks_in_frame"));
+}
+
+/* Table 1.A.8 */
+static void adts_error_check(adts_header *adts, bitfile *ld)
+{
+ if (adts->protection_absent == 0) {
+ adts->crc_check = (uint16_t)faad_getbits(ld, 16
+ DEBUGVAR(1, 134, "adts_error_check(): crc_check"));
+ }
+}
+
+/* LATM parsing functions */
+
+static uint32_t latm_get_value(bitfile *ld)
+{
+ uint32_t l, value;
+ uint8_t bytesForValue;
+
+ bytesForValue = (uint8_t)faad_getbits(ld, 2);
+ value = 0;
+ for (l = 0; l < bytesForValue; l++) {
+ value = (value << 8) | (uint8_t)faad_getbits(ld, 8);
+ }
+
+ return value;
+}
+
+
+static uint32_t latmParsePayload(latm_header *latm, bitfile *ld)
+{
+ //assuming there's only one program with a single layer and 1 subFrame,
+ //allStreamsSametimeframing is set,
+ uint32_t framelen;
+ uint8_t tmp;
+
+ //this should be the payload length field for the current configuration
+ framelen = 0;
+ if (latm->framelen_type == 0) {
+ do {
+ tmp = (uint8_t)faad_getbits(ld, 8);
+ framelen += tmp;
+ } while (tmp == 0xff);
+ } else if (latm->framelen_type == 1) {
+ framelen = latm->frameLength;
+ }
+
+ return framelen;
+}
+
+
+static uint32_t latmAudioMuxElement(latm_header *latm, bitfile *ld)
+{
+ uint32_t ascLen, asc_bits = 0;
+ uint32_t x1, y1, m, n, i;
+ program_config pce;
+ mp4AudioSpecificConfig mp4ASC;
+
+ latm->useSameStreamMux = (uint8_t)faad_getbits(ld, 1);
+ if (!latm->useSameStreamMux) {
+ //parseSameStreamMuxConfig
+ latm->version = (uint8_t) faad_getbits(ld, 1);
+ if (latm->version) {
+ latm->versionA = (uint8_t) faad_getbits(ld, 1);
+ }
+ if (latm->versionA) {
+ //dunno the payload format for versionA
+ fprintf(stderr, "versionA not supported\n");
+ return 0;
+ }
+ if (latm->version) { //read taraBufferFullness
+ latm_get_value(ld);
+ }
+ latm->allStreamsSameTimeFraming = (uint8_t)faad_getbits(ld, 1);
+ latm->numSubFrames = (uint8_t)faad_getbits(ld, 6) + 1;
+ latm->numPrograms = (uint8_t)faad_getbits(ld, 4) + 1;
+ latm->numLayers = faad_getbits(ld, 3) + 1;
+ if (latm->numPrograms > 1 || !latm->allStreamsSameTimeFraming || latm->numSubFrames > 1 || latm->numLayers > 1) {
+ fprintf(stderr, "\r\nUnsupported LATM configuration: %d programs/ %d subframes, %d layers, allstreams: %d\n",
+ latm->numPrograms, latm->numSubFrames, latm->numLayers, latm->allStreamsSameTimeFraming);
+ return 0;
+ }
+ ascLen = 0;
+ if (latm->version) {
+ ascLen = latm_get_value(ld);
+ }
+
+ x1 = faad_get_processed_bits(ld);
+ if (AudioSpecificConfigFromBitfile(ld, &mp4ASC, &pce, 0, 1) < 0) {
+ return 0;
+ }
+
+ //horrid hack to unread the ASC bits and store them in latm->ASC
+ //the correct code would rely on an ideal faad_ungetbits()
+ y1 = faad_get_processed_bits(ld);
+ if ((y1 - x1) <= MAX_ASC_BYTES * 8) {
+ faad_rewindbits(ld);
+ m = x1;
+ while (m > 0) {
+ n = min(m, 32);
+ faad_getbits(ld, n);
+ m -= n;
+ }
+
+ i = 0;
+ m = latm->ASCbits = y1 - x1;
+ while (m > 0) {
+ n = min(m, 8);
+ latm->ASC[i++] = (uint8_t) faad_getbits(ld, n);
+ m -= n;
+ }
+ }
+
+ asc_bits = y1 - x1;
+
+ if (ascLen > asc_bits) {
+ faad_getbits(ld, ascLen - asc_bits);
+ }
+
+ latm->framelen_type = (uint8_t) faad_getbits(ld, 3);
+ if (latm->framelen_type == 0) {
+ latm->frameLength = 0;
+ faad_getbits(ld, 8); //buffer fullness for frame_len_type==0, useless
+ } else if (latm->framelen_type == 1) {
+ latm->frameLength = faad_getbits(ld, 9);
+ if (latm->frameLength == 0) {
+ fprintf(stderr, "Invalid frameLength: 0\r\n");
+ return 0;
+ }
+ latm->frameLength = (latm->frameLength + 20) * 8;
+ } else {
+ //hellish CELP or HCVX stuff, discard
+ fprintf(stderr, "Unsupported CELP/HCVX framelentype: %d\n", latm->framelen_type);
+ return 0;
+ }
+
+ latm->otherDataLenBits = 0;
+ if (faad_getbits(ld, 1)) {
+ //other data present
+ int esc, tmp;
+ if (latm->version) {
+ latm->otherDataLenBits = latm_get_value(ld);
+ } else do {
+ esc = faad_getbits(ld, 1);
+ tmp = faad_getbits(ld, 8);
+ latm->otherDataLenBits = (latm->otherDataLenBits << 8) + tmp;
+ } while (esc);
+ }
+ if (faad_getbits(ld, 1)) { //crc
+ faad_getbits(ld, 8);
+ }
+ latm->inited = 1;
+ }
+
+ //read payload
+ if (latm->inited) {
+ return latmParsePayload(latm, ld);
+ } else {
+ return 0;
+ }
+}
+
+
+uint32_t faad_latm_frame(latm_header *latm, bitfile *ld)
+{
+ uint16_t len;
+ uint32_t initpos, endpos, firstpos, ret;
+
+ firstpos = faad_get_processed_bits(ld);
+ while (ld->bytes_left) {
+ faad_byte_align(ld);
+ if (faad_showbits(ld, 11) != 0x2B7) {
+ faad_getbits(ld, 8);
+ continue;
+ }
+ faad_getbits(ld, 11);
+ len = faad_getbits(ld, 13);
+ if (!len) {
+ continue;
+ }
+ initpos = faad_get_processed_bits(ld);
+ ret = latmAudioMuxElement(latm, ld);
+ endpos = faad_get_processed_bits(ld);
+ if (ret > 0) {
+ return (len * 8) - (endpos - initpos);
+ }
+ //faad_getbits(ld, initpos-endpos); //go back to initpos, but is valid a getbits(-N) ?
+ }
+ return -1U;
+}