Revision 756fb7fe

View differences:

libavformat/tta.c
23 23

  
24 24
typedef struct {
25 25
    int totalframes, currentframe;
26
    uint32_t *seektable;
27 26
} TTAContext;
28 27

  
29 28
static int tta_probe(AVProbeData *p)
......
39 38
    TTAContext *c = s->priv_data;
40 39
    AVStream *st;
41 40
    int i, channels, bps, samplerate, datalen, framelen;
41
    uint64_t framepos;
42 42

  
43 43
    if (get_le32(&s->pb) != ff_get_fourcc("TTA1"))
44 44
        return -1; // not tta file
......
68 68
        av_log(s, AV_LOG_ERROR, "totalframes too large\n");
69 69
        return -1;
70 70
    }
71
    c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes);
72
    if (!c->seektable)
73
        return AVERROR_NOMEM;
74

  
75
    for (i = 0; i < c->totalframes; i++)
76
        c->seektable[i] = get_le32(&s->pb);
77
    url_fskip(&s->pb, 4); // seektable crc
78 71

  
79 72
    st = av_new_stream(s, 0);
80
//    av_set_pts_info(st, 32, 1, 1000);
81 73
    if (!st)
82 74
        return AVERROR_NOMEM;
75

  
76
    av_set_pts_info(st, 64, 1, samplerate);
77
    st->start_time = 0;
78
    st->duration = datalen;
79

  
80
    framepos = url_ftell(&s->pb) + 4*c->totalframes + 4;
81

  
82
    for (i = 0; i < c->totalframes; i++) {
83
        uint32_t size = get_le32(&s->pb);
84
        av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME);
85
        framepos += size;
86
    }
87
    url_fskip(&s->pb, 4); // seektable crc
88

  
83 89
    st->codec->codec_type = CODEC_TYPE_AUDIO;
84 90
    st->codec->codec_id = CODEC_ID_TTA;
85 91
    st->codec->channels = channels;
......
102 108
static int tta_read_packet(AVFormatContext *s, AVPacket *pkt)
103 109
{
104 110
    TTAContext *c = s->priv_data;
105
    int ret, size;
111
    AVStream *st = s->streams[0];
112
    int size;
106 113

  
107 114
    // FIXME!
108 115
    if (c->currentframe > c->totalframes)
109
        size = 0;
110
    else
111
        size = c->seektable[c->currentframe];
112

  
113
    c->currentframe++;
114

  
115
    if (av_new_packet(pkt, size) < 0)
116
        return AVERROR_IO;
116
        return -1;
117 117

  
118
    pkt->pos = url_ftell(&s->pb);
119
    pkt->stream_index = 0;
120
    ret = get_buffer(&s->pb, pkt->data, size);
121
    if (ret <= 0) {
122
        av_free_packet(pkt);
123
        return AVERROR_IO;
124
    }
125
    pkt->size = ret;
126
//    av_log(s, AV_LOG_INFO, "TTA packet #%d desired size: %d read size: %d at pos %d\n",
127
//        c->currentframe, size, ret, pkt->pos);
128
    return 0; //ret;
129
}
118
    size = st->index_entries[c->currentframe++].size;
130 119

  
131
static int tta_read_close(AVFormatContext *s)
132
{
133
    TTAContext *c = s->priv_data;
134
    if (c->seektable)
135
        av_free(c->seektable);
136
    return 0;
120
    return av_get_packet(&s->pb, pkt, size);
137 121
}
138 122

  
139 123
AVInputFormat tta_demuxer = {
......
143 127
    tta_probe,
144 128
    tta_read_header,
145 129
    tta_read_packet,
146
    tta_read_close,
130
    NULL,
147 131
    .extensions = "tta",
148 132
};

Also available in: Unified diff