static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    TTAContext *c = s->priv_data;
    AVStream *st;
    int i, channels, bps, samplerate, datalen, framelen, start;
    start = url_ftell(&s->pb);
    if (get_le32(&s->pb) != ff_get_fourcc("TTA1"))
        return -1; // not tta file
    url_fskip(&s->pb, 2); // FIXME: flags
    channels = get_le16(&s->pb);
    bps = get_le16(&s->pb);
    samplerate = get_le32(&s->pb);
    datalen = get_le32(&s->pb);
    url_fskip(&s->pb, 4); // header crc
    framelen = 1.04489795918367346939 * samplerate;
    c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);
    c->currentframe = 0;
    c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes);
    if (!c->seektable)
        return AVERROR_NOMEM;
    for (i = 0; i < c->totalframes; i++)
            c->seektable[i] = get_le32(&s->pb);
    url_fskip(&s->pb, 4); // seektable crc
    st = av_new_stream(s, 0);
//    av_set_pts_info(st, 32, 1, 1000);
    if (!st)
        return AVERROR_NOMEM;
    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) - start;
    if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){
        //this check is redundant as get_buffer should fail
        av_log(s, AV_LOG_ERROR, "extradata_size too large\n");
    st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
    url_fseek(&s->pb, start, SEEK_SET); // or SEEK_CUR and -size ? :)
    get_buffer(&s->pb, st->codec->extradata, st->codec->extradata_size);
    return 0;
static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
    TTAContext *c = s->priv_data;
    AVStream *st;
    int i, channels, bps, samplerate, datalen, framelen, start;
    start = url_ftell(&s->pb);
    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);
    datalen = get_le32(&s->pb);
    url_fskip(&s->pb, 4); 
    framelen = 1.04489795918367346939 * samplerate;
    c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0);
    c->currentframe = 0;
    c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes);
    if (!c->seektable)
        return AVERROR_NOMEM;
    for (i = 0; i < c->totalframes; i++)
            c->seektable[i] = get_le32(&s->pb);
    url_fskip(&s->pb, 4); 
    st = av_new_stream(s, 0);

    if (!st)
        return AVERROR_NOMEM;
    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) - start;
    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");
    st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
    url_fseek(&s->pb, start, SEEK_SET); 
    get_buffer(&s->pb, st->codec->extradata, st->codec->extradata_size);
    return 0;
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{
    TTAContext *c = VAR_0->priv_data;
    AVStream *st;
    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8;
    VAR_8 = url_ftell(&VAR_0->pb);
    if (get_le32(&VAR_0->pb) != ff_get_fourcc("TTA1"))
        return -1; 
    url_fskip(&VAR_0->pb, 2); 
    VAR_3 = get_le16(&VAR_0->pb);
    VAR_4 = get_le16(&VAR_0->pb);
    VAR_5 = get_le32(&VAR_0->pb);
    VAR_6 = get_le32(&VAR_0->pb);
    url_fskip(&VAR_0->pb, 4); 
    VAR_7 = 1.04489795918367346939 * VAR_5;
    c->totalframes = VAR_6 / VAR_7 + ((VAR_6 % VAR_7) ? 1 : 0);
    c->currentframe = 0;
    c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes);
    if (!c->seektable)
        return AVERROR_NOMEM;
    for (VAR_2 = 0; VAR_2 < c->totalframes; VAR_2++)
            c->seektable[VAR_2] = get_le32(&VAR_0->pb);
    url_fskip(&VAR_0->pb, 4); 
    st = av_new_stream(VAR_0, 0);

    if (!st)
        return AVERROR_NOMEM;
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_TTA;
    st->codec->VAR_3 = VAR_3;
    st->codec->sample_rate = VAR_5;
    st->codec->bits_per_sample = VAR_4;
    st->codec->extradata_size = url_ftell(&VAR_0->pb) - VAR_8;
    if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){
        
        av_log(VAR_0, AV_LOG_ERROR, "extradata_size too large\n");
    st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE);
    url_fseek(&VAR_0->pb, VAR_8, SEEK_SET); 
    get_buffer(&VAR_0->pb, st->codec->extradata, st->codec->extradata_size);
    return 0;
static int FUNC_0(AVFormatContext *VAR_0, AVFormatParameters *VAR_1)
{ TTAContext *c = VAR_0->priv_data; AVStream *st; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7, VAR_8; VAR_8 = url_ftell(&VAR_0->pb); if (get_le32(&VAR_0->pb) != ff_get_fourcc("TTA1"))
return -1; url_fskip(&VAR_0->pb, 2); VAR_3 = get_le16(&VAR_0->pb); VAR_4 = get_le16(&VAR_0->pb); VAR_5 = get_le32(&VAR_0->pb); VAR_6 = get_le32(&VAR_0->pb); url_fskip(&VAR_0->pb, 4); VAR_7 = 1.04489795918367346939 * VAR_5; c->totalframes = VAR_6 / VAR_7 + ((VAR_6 % VAR_7) ? 1 : 0); c->currentframe = 0; c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes); if (!c->seektable)
return AVERROR_NOMEM; for (VAR_2 = 0; VAR_2 < c->totalframes; VAR_2++) c->seektable[VAR_2] = get_le32(&VAR_0->pb); url_fskip(&VAR_0->pb, 4); st = av_new_stream(VAR_0, 0); if (!st)
return AVERROR_NOMEM; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_TTA; st->codec->VAR_3 = VAR_3; st->codec->sample_rate = VAR_5; st->codec->bits_per_sample = VAR_4; st->codec->extradata_size = url_ftell(&VAR_0->pb) - VAR_8; if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ av_log(VAR_0, AV_LOG_ERROR, "extradata_size too large\n"); st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); url_fseek(&VAR_0->pb, VAR_8, SEEK_SET); get_buffer(&VAR_0->pb, st->codec->extradata, st->codec->extradata_size); return 0;