static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
                                 FLACFrameInfo *fi)
{
    GetBitContext gb;
    init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
    return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
}
['static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,\n                                 FLACFrameInfo *fi)\n{\n    GetBitContext gb;\n    init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);\n    return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,\n                                FLACFrameInfo *fi, int log_level_offset)\n{\n    int bs_code, sr_code, bps_code;\n    if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    fi->is_var_size = get_bits1(gb);\n    bs_code = get_bits(gb, 4);\n    sr_code = get_bits(gb, 4);\n    fi->ch_mode = get_bits(gb, 4);\n    if (fi->ch_mode < FLAC_MAX_CHANNELS) {\n        fi->channels = fi->ch_mode + 1;\n        fi->ch_mode = FLAC_CHMODE_INDEPENDENT;\n    } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {\n        fi->channels = 2;\n        fi->ch_mode -= FLAC_MAX_CHANNELS - 1;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid channel mode: %d\\n", fi->ch_mode);\n        return AVERROR_INVALIDDATA;\n    }\n    bps_code = get_bits(gb, 3);\n    if (bps_code == 3 || bps_code == 7) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "invalid sample size code (%d)\\n",\n               bps_code);\n        return AVERROR_INVALIDDATA;\n    }\n    fi->bps = sample_size_table[bps_code];\n    if (get_bits1(gb)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "broken stream, invalid padding\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    fi->frame_or_sample_num = get_utf8(gb);\n    if (fi->frame_or_sample_num < 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "sample/frame number invalid; utf8 fscked\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (bs_code == 0) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "reserved blocksize code: 0\\n");\n        return AVERROR_INVALIDDATA;\n    } else if (bs_code == 6) {\n        fi->blocksize = get_bits(gb, 8) + 1;\n    } else if (bs_code == 7) {\n        fi->blocksize = get_bits(gb, 16) + 1;\n    } else {\n        fi->blocksize = ff_flac_blocksize_table[bs_code];\n    }\n    if (sr_code < 12) {\n        fi->samplerate = ff_flac_sample_rate_table[sr_code];\n    } else if (sr_code == 12) {\n        fi->samplerate = get_bits(gb, 8) * 1000;\n    } else if (sr_code == 13) {\n        fi->samplerate = get_bits(gb, 16);\n    } else if (sr_code == 14) {\n        fi->samplerate = get_bits(gb, 16) * 10;\n    } else {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "illegal sample rate code %d\\n",\n               sr_code);\n        return AVERROR_INVALIDDATA;\n    }\n    skip_bits(gb, 8);\n    if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,\n               get_bits_count(gb)/8)) {\n        av_log(avctx, AV_LOG_ERROR + log_level_offset,\n               "header crc mismatch\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n    unsigned int index = s->index;\n    uint8_t result     = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n    result >>= index & 7;\n    result  &= 1;\n#else\n    result <<= index & 7;\n    result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n    if (s->index < s->size_in_bits_plus8)\n#endif\n        index++;\n    s->index = index;\n    return result;\n}']