Revision 73823cb9

View differences:

libavformat/oggdec.c
120 120
        os->granule = -1;
121 121
        os->lastpts = AV_NOPTS_VALUE;
122 122
        os->lastdts = AV_NOPTS_VALUE;
123
        os->sync_pos = -1;
124
        os->page_pos = 0;
123 125
        os->nsegs = 0;
124 126
        os->segp = 0;
125 127
        os->incomplete = 0;
......
255 257
    }
256 258

  
257 259
    os = ogg->streams + idx;
260
    os->page_pos = url_ftell(bc) - 27;
258 261

  
259 262
    if(os->psize > 0)
260 263
        ogg_new_buf(ogg, idx);
......
277 280
                if (seg < 255)
278 281
                    break;
279 282
            }
283
            os->sync_pos = os->page_pos;
280 284
        }
281 285
    }else{
282 286
        os->psize = 0;
287
        os->sync_pos = os->page_pos;
283 288
    }
284 289

  
285 290
    if (os->bufsize - os->bufpos < size){
......
303 308
}
304 309

  
305 310
static int
306
ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize)
311
ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize, int64_t *fpos)
307 312
{
308 313
    struct ogg *ogg = s->priv_data;
309 314
    int idx, i;
......
394 399
            *dstart = os->pstart;
395 400
        if (dsize)
396 401
            *dsize = os->psize;
402
        if (fpos)
403
            *fpos = os->sync_pos;
397 404
        os->pstart += os->psize;
398 405
        os->psize = 0;
406
        os->sync_pos = os->page_pos;
399 407
    }
400 408

  
401 409
    // determine whether there are more complete packets in this page
......
420 428
    struct ogg *ogg = s->priv_data;
421 429

  
422 430
    do{
423
        if (ogg_packet (s, NULL, NULL, NULL) < 0)
431
        if (ogg_packet (s, NULL, NULL, NULL, NULL) < 0)
424 432
            return -1;
425 433
    }while (!ogg->headers);
426 434

  
......
520 528
    struct ogg_stream *os;
521 529
    int idx = -1;
522 530
    int pstart, psize;
531
    int64_t fpos;
523 532

  
524 533
    //Get an ogg packet
525 534
    do{
526
        if (ogg_packet (s, &idx, &pstart, &psize) < 0)
535
        if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0)
527 536
            return AVERROR(EIO);
528 537
    }while (idx < 0 || !s->streams[idx]);
529 538

  
......
557 566

  
558 567
    pkt->flags = os->pflags;
559 568
    pkt->duration = os->pduration;
569
    pkt->pos = fpos;
560 570

  
561 571
    return psize;
562 572
}
libavformat/oggdec.h
66 66
    uint64_t granule;
67 67
    int64_t lastpts;
68 68
    int64_t lastdts;
69
    int64_t sync_pos;   ///< file offset of the first page needed to reconstruct the current packet
70
    int64_t page_pos;   ///< file offset of the current page
69 71
    int flags;
70 72
    const struct ogg_codec *codec;
71 73
    int header;
tests/ref/seek/lavf.ogg.ref
1
ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:     -1 size:  1364
1
ret: 0         st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos:    125 size:  1364
2 2
ret: 0         st:-1 flags:0  ts:-1.000000
3
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1390
3
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   5768 size:  1390
4 4
ret: 0         st:-1 flags:1  ts: 1.894167
5 5
ret:-EIO
6 6
ret: 0         st: 0 flags:0  ts: 0.788345
7
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1365
7
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  11410 size:  1365
8 8
ret: 0         st: 0 flags:1  ts:-0.317506
9
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1384
9
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   2936 size:  1384
10 10
ret: 0         st:-1 flags:0  ts: 2.576668
11
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
11
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
12 12
ret: 0         st:-1 flags:1  ts: 1.470835
13 13
ret:-EIO
14 14
ret: 0         st: 0 flags:0  ts: 0.365011
15
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1390
15
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   5768 size:  1390
16 16
ret: 0         st: 0 flags:1  ts:-0.740839
17
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1384
17
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   2936 size:  1384
18 18
ret: 0         st:-1 flags:0  ts: 2.153336
19
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
19
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
20 20
ret: 0         st:-1 flags:1  ts: 1.047503
21 21
ret:-EIO
22 22
ret: 0         st: 0 flags:0  ts:-0.058322
23
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1390
23
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   5768 size:  1390
24 24
ret: 0         st: 0 flags:1  ts: 2.835828
25 25
ret:-EIO
26 26
ret: 0         st:-1 flags:0  ts: 1.730004
27
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
27
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
28 28
ret: 0         st:-1 flags:1  ts: 0.624171
29
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1370
29
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   7191 size:  1370
30 30
ret: 0         st: 0 flags:0  ts:-0.481655
31
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1390
31
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   5768 size:  1390
32 32
ret: 0         st: 0 flags:1  ts: 2.412494
33 33
ret:-EIO
34 34
ret: 0         st:-1 flags:0  ts: 1.306672
35
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
35
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
36 36
ret: 0         st:-1 flags:1  ts: 0.200839
37
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1384
37
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   2936 size:  1384
38 38
ret: 0         st: 0 flags:0  ts:-0.904989
39
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1390
39
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   5768 size:  1390
40 40
ret: 0         st: 0 flags:1  ts: 1.989184
41 41
ret:-EIO
42 42
ret: 0         st:-1 flags:0  ts: 0.883340
43
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
43
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
44 44
ret: 0         st:-1 flags:1  ts:-0.222493
45
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1384
45
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   2936 size:  1384
46 46
ret: 0         st: 0 flags:0  ts: 2.671678
47
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1223
47
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:  12808 size:  1223
48 48
ret: 0         st: 0 flags:1  ts: 1.565850
49 49
ret:-EIO
50 50
ret: 0         st:-1 flags:0  ts: 0.460008
51
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1381
51
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   8594 size:  1381
52 52
ret: 0         st:-1 flags:1  ts:-0.645825
53
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:     -1 size:  1384
53
ret: 0         st: 0 flags:1 dts: NOPTS    pts: NOPTS    pos:   2936 size:  1384

Also available in: Unified diff