static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
{
    IEC61937Context *ctx = s->priv_data;
    AACADTSHeaderInfo hdr;
    GetBitContext gbc;
    int ret;
    init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
    ret = ff_aac_parse_header(&gbc, &hdr);
    if (ret < 0) {
        av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
        return AVERROR_INVALIDDATA;
    }
    ctx->pkt_offset = hdr.samples << 2;
    switch (hdr.num_aac_frames) {
    case 1:
        ctx->data_type = IEC61937_MPEG2_AAC;
        break;
    case 2:
        ctx->data_type = IEC61937_MPEG2_AAC_LSF_2048;
        break;
    case 4:
        ctx->data_type = IEC61937_MPEG2_AAC_LSF_4096;
        break;
    default:
        av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\n",
               hdr.samples);
        return AVERROR(EINVAL);
    }
    return 0;
}
['static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)\n{\n    IEC61937Context *ctx = s->priv_data;\n    AACADTSHeaderInfo hdr;\n    GetBitContext gbc;\n    int ret;\n    init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);\n    ret = ff_aac_parse_header(&gbc, &hdr);\n    if (ret < 0) {\n        av_log(s, AV_LOG_ERROR, "Wrong AAC file format\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    ctx->pkt_offset = hdr.samples << 2;\n    switch (hdr.num_aac_frames) {\n    case 1:\n        ctx->data_type = IEC61937_MPEG2_AAC;\n        break;\n    case 2:\n        ctx->data_type = IEC61937_MPEG2_AAC_LSF_2048;\n        break;\n    case 4:\n        ctx->data_type = IEC61937_MPEG2_AAC_LSF_4096;\n        break;\n    default:\n        av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\\n",\n               hdr.samples);\n        return AVERROR(EINVAL);\n    }\n    return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n                   const uint8_t *buffer, int bit_size)\n{\n    int buffer_size = (bit_size+7)>>3;\n    if (buffer_size < 0 || bit_size < 0) {\n        buffer_size = bit_size = 0;\n        buffer = NULL;\n    }\n    s->buffer       = buffer;\n    s->size_in_bits = bit_size;\n    s->buffer_end   = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n    s->index        = 0;\n#elif defined A32_BITSTREAM_READER\n    s->buffer_ptr   = (uint32_t*)((intptr_t)buffer & ~3);\n    s->bit_count    = 32 +     8*((intptr_t)buffer &  3);\n    skip_bits_long(s, 0);\n#endif\n}', 'int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)\n{\n    int size, rdb, ch, sr;\n    int aot, crc_abs;\n    if(get_bits(gbc, 12) != 0xfff)\n        return AAC_AC3_PARSE_ERROR_SYNC;\n    skip_bits1(gbc);\n    skip_bits(gbc, 2);\n    crc_abs = get_bits1(gbc);\n    aot     = get_bits(gbc, 2);\n    sr      = get_bits(gbc, 4);\n    if(!ff_mpeg4audio_sample_rates[sr])\n        return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;\n    skip_bits1(gbc);\n    ch      = get_bits(gbc, 3);\n    skip_bits1(gbc);\n    skip_bits1(gbc);\n    skip_bits1(gbc);\n    skip_bits1(gbc);\n    size    = get_bits(gbc, 13);\n    if(size < AAC_ADTS_HEADER_SIZE)\n        return AAC_AC3_PARSE_ERROR_FRAME_SIZE;\n    skip_bits(gbc, 11);\n    rdb = get_bits(gbc, 2);\n    hdr->object_type    = aot + 1;\n    hdr->chan_config    = ch;\n    hdr->crc_absent     = crc_abs;\n    hdr->num_aac_frames = rdb + 1;\n    hdr->sampling_index = sr;\n    hdr->sample_rate    = ff_mpeg4audio_sample_rates[sr];\n    hdr->samples        = (rdb + 1) * 1024;\n    hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;\n    return size;\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n){\n    register int tmp;\n    OPEN_READER(re, s);\n    UPDATE_CACHE(re, s);\n    tmp = SHOW_UBITS(re, s, n);\n    LAST_SKIP_BITS(re, s, n);\n    CLOSE_READER(re, s);\n    return tmp;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n    x= (x>>16) | (x<<16);\n    return x;\n}', 'static inline void skip_bits1(GetBitContext *s){\n    skip_bits(s, 1);\n}', 'static inline void skip_bits(GetBitContext *s, int n){\n    OPEN_READER(re, s);\n    UPDATE_CACHE(re, s);\n    LAST_SKIP_BITS(re, s, n);\n    CLOSE_READER(re, s);\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n    unsigned int index = s->index;\n    uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n    result >>= index & 7;\n    result &= 1;\n#else\n    result <<= index & 7;\n    result >>= 8 - 1;\n#endif\n    index++;\n    s->index = index;\n    return result;\n#else\n    return get_bits(s, 1);\n#endif\n}']