Revision 8f8320d7

View differences:

libavformat/oggparsespeex.c
32 32

  
33 33
struct speex_params {
34 34
    int final_packet_duration;
35
    int seq;
35 36
};
36 37

  
37 38
static int speex_header(AVFormatContext *s, int idx) {
38 39
    struct ogg *ogg = s->priv_data;
39 40
    struct ogg_stream *os = ogg->streams + idx;
41
    struct speex_params *spxp = os->private;
40 42
    AVStream *st = s->streams[idx];
41 43
    uint8_t *p = os->buf + os->pstart;
42 44

  
43
    if (os->seq > 1)
45
    if (!spxp) {
46
        spxp = av_mallocz(sizeof(*spxp));
47
        os->private = spxp;
48
    }
49

  
50
    if (spxp->seq > 1)
44 51
        return 0;
45 52

  
46
    if (os->seq == 0) {
53
    if (spxp->seq == 0) {
47 54
        int frames_per_packet;
48 55
        st->codec->codec_type = CODEC_TYPE_AUDIO;
49 56
        st->codec->codec_id = CODEC_ID_SPEEX;
......
70 77
    } else
71 78
        vorbis_comment(s, p, os->psize);
72 79

  
80
    spxp->seq++;
73 81
    return 1;
74 82
}
75 83

  
......
90 98
    struct speex_params *spxp = os->private;
91 99
    int packet_size = s->streams[idx]->codec->frame_size;
92 100

  
93
    if (!spxp) {
94
        spxp = av_mallocz(sizeof(*spxp));
95
        os->private = spxp;
96
    }
97

  
98 101
    if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE &&
99 102
        os->granule > 0) {
100 103
        /* first packet of final page. we have to calculate the final packet
libavformat/oggparsevorbis.c
166 166
    struct ogg_stream *os = ogg->streams + idx;
167 167
    AVStream *st = s->streams[idx];
168 168
    struct oggvorbis_private *priv;
169
    int pkt_type = os->buf[os->pstart];
169 170

  
170
    if (os->seq > 2)
171
    if (!(pkt_type & 1))
171 172
        return 0;
172 173

  
173
    if (os->seq == 0) {
174
    if (!os->private) {
174 175
        os->private = av_mallocz(sizeof(struct oggvorbis_private));
175 176
        if (!os->private)
176 177
            return 0;
177 178
    }
178 179

  
179
    if (os->psize < 1)
180
    if (os->psize < 1 || pkt_type > 5)
180 181
        return -1;
181 182

  
182 183
    priv = os->private;
183
    priv->len[os->seq] = os->psize;
184
    priv->packet[os->seq] = av_mallocz(os->psize);
185
    memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize);
184
    priv->len[pkt_type >> 1] = os->psize;
185
    priv->packet[pkt_type >> 1] = av_mallocz(os->psize);
186
    memcpy(priv->packet[pkt_type >> 1], os->buf + os->pstart, os->psize);
186 187
    if (os->buf[os->pstart] == 1) {
187 188
        const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */
188 189
        unsigned blocksize, bs0, bs1;
......
224 225
            fixup_vorbis_headers(s, priv, &st->codec->extradata);
225 226
    }
226 227

  
227
    return os->seq < 3;
228
    return 1;
228 229
}
229 230

  
230 231
const struct ogg_codec ff_vorbis_codec = {

Also available in: Unified diff