static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    TTAContext *c = s->priv_data;
    AVStream *st;
    int i, channels, bps, samplerate, datalen, framelen;
    uint64_t framepos;
    if (get_le32(s->pb) != ff_get_fourcc("TTA1"))
        return -1;
    url_fskip(s->pb, 2);
    channels = get_le16(s->pb);
    bps = get_le16(s->pb);
    samplerate = get_le32(s->pb);
    if(samplerate <= 0 || samplerate > 1000000){
        av_log(s, AV_LOG_ERROR, "nonsense samplerate\n");
        return -1;
    }
    datalen = get_le32(s->pb);
    if(datalen < 0){
        av_log(s, AV_LOG_ERROR, "nonsense datalen\n");
        return -1;
    }
    url_fskip(s->pb, 4);
    framelen = samplerate*256/245;
    c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);
    c->currentframe = 0;
    if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){
        av_log(s, AV_LOG_ERROR, "totalframes too large\n");
        return -1;
    }
    st = av_new_stream(s, 0);
    if (!st)
        return AVERROR(ENOMEM);
    av_set_pts_info(st, 64, 1, samplerate);
    st->start_time = 0;
    st->duration = datalen;
    framepos = url_ftell(s->pb) + 4*c->totalframes + 4;
    for (i = 0; i < c->totalframes; i++) {
        uint32_t size = get_le32(s->pb);
        av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME);
        framepos += size;
    }
    url_fskip(s->pb, 4);
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_TTA;
    st->codec->channels = channels;
    st->codec->sample_rate = samplerate;
    st->codec->bits_per_sample = bps;
    st->codec->extradata_size = url_ftell(s->pb);
    if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){
        av_log(s, AV_LOG_ERROR, "extradata_size too large\n");
        return -1;
    }
    st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
    url_fseek(s->pb, 0, SEEK_SET);
    get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size);
    return 0;
}
['static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n    TTAContext *c = s->priv_data;\n    AVStream *st;\n    int i, channels, bps, samplerate, datalen, framelen;\n    uint64_t framepos;\n    if (get_le32(s->pb) != ff_get_fourcc("TTA1"))\n        return -1;\n    url_fskip(s->pb, 2);\n    channels = get_le16(s->pb);\n    bps = get_le16(s->pb);\n    samplerate = get_le32(s->pb);\n    if(samplerate <= 0 || samplerate > 1000000){\n        av_log(s, AV_LOG_ERROR, "nonsense samplerate\\n");\n        return -1;\n    }\n    datalen = get_le32(s->pb);\n    if(datalen < 0){\n        av_log(s, AV_LOG_ERROR, "nonsense datalen\\n");\n        return -1;\n    }\n    url_fskip(s->pb, 4);\n    framelen = samplerate*256/245;\n    c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);\n    c->currentframe = 0;\n    if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){\n        av_log(s, AV_LOG_ERROR, "totalframes too large\\n");\n        return -1;\n    }\n    st = av_new_stream(s, 0);\n    if (!st)\n        return AVERROR(ENOMEM);\n    av_set_pts_info(st, 64, 1, samplerate);\n    st->start_time = 0;\n    st->duration = datalen;\n    framepos = url_ftell(s->pb) + 4*c->totalframes + 4;\n    for (i = 0; i < c->totalframes; i++) {\n        uint32_t size = get_le32(s->pb);\n        av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME);\n        framepos += size;\n    }\n    url_fskip(s->pb, 4);\n    st->codec->codec_type = CODEC_TYPE_AUDIO;\n    st->codec->codec_id = CODEC_ID_TTA;\n    st->codec->channels = channels;\n    st->codec->sample_rate = samplerate;\n    st->codec->bits_per_sample = bps;\n    st->codec->extradata_size = url_ftell(s->pb);\n    if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){\n        av_log(s, AV_LOG_ERROR, "extradata_size too large\\n");\n        return -1;\n    }\n    st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);\n    url_fseek(s->pb, 0, SEEK_SET);\n    get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size);\n    return 0;\n}', 'unsigned int get_le32(ByteIOContext *s)\n{\n    unsigned int val;\n    val = get_le16(s);\n    val |= get_le16(s) << 16;\n    return val;\n}', 'unsigned int get_le16(ByteIOContext *s)\n{\n    unsigned int val;\n    val = get_byte(s);\n    val |= get_byte(s) << 8;\n    return val;\n}', 'int get_byte(ByteIOContext *s)\n{\n    if (s->buf_ptr < s->buf_end) {\n        return *s->buf_ptr++;\n    } else {\n        fill_buffer(s);\n        if (s->buf_ptr < s->buf_end)\n            return *s->buf_ptr++;\n        else\n            return 0;\n    }\n}']