Revision d8b91fae libavformat/oggdec.c
libavformat/oggdec.c | ||
---|---|---|
531 | 531 |
struct ogg_stream *os; |
532 | 532 |
int idx = -1; |
533 | 533 |
int pstart, psize; |
534 |
int64_t fpos; |
|
534 |
int64_t fpos, pts, dts;
|
|
535 | 535 |
|
536 | 536 |
//Get an ogg packet |
537 |
retry: |
|
537 | 538 |
do{ |
538 | 539 |
if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0) |
539 | 540 |
return AVERROR(EIO); |
... | ... | |
542 | 543 |
ogg = s->priv_data; |
543 | 544 |
os = ogg->streams + idx; |
544 | 545 |
|
546 |
// pflags might not be set until after this |
|
547 |
pts = ogg_calc_pts(s, idx, &dts); |
|
548 |
|
|
549 |
if (os->keyframe_seek && !(os->pflags & PKT_FLAG_KEY)) |
|
550 |
goto retry; |
|
551 |
os->keyframe_seek = 0; |
|
552 |
|
|
545 | 553 |
//Alloc a pkt |
546 | 554 |
if (av_new_packet (pkt, psize) < 0) |
547 | 555 |
return AVERROR(EIO); |
548 | 556 |
pkt->stream_index = idx; |
549 | 557 |
memcpy (pkt->data, os->buf + pstart, psize); |
550 | 558 |
|
551 |
pkt->pts = ogg_calc_pts(s, idx, &pkt->dts); |
|
559 |
pkt->pts = pts; |
|
560 |
pkt->dts = dts; |
|
552 | 561 |
pkt->flags = os->pflags; |
553 | 562 |
pkt->duration = os->pduration; |
554 | 563 |
pkt->pos = fpos; |
... | ... | |
577 | 586 |
int64_t pos_limit) |
578 | 587 |
{ |
579 | 588 |
struct ogg *ogg = s->priv_data; |
589 |
struct ogg_stream *os = ogg->streams + stream_index; |
|
580 | 590 |
ByteIOContext *bc = s->pb; |
581 | 591 |
int64_t pts = AV_NOPTS_VALUE; |
582 | 592 |
int i; |
... | ... | |
586 | 596 |
while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) { |
587 | 597 |
if (i == stream_index) { |
588 | 598 |
pts = ogg_calc_pts(s, i, NULL); |
599 |
if (os->keyframe_seek && !(os->pflags & PKT_FLAG_KEY)) |
|
600 |
pts = AV_NOPTS_VALUE; |
|
589 | 601 |
} |
590 | 602 |
if (pts != AV_NOPTS_VALUE) |
591 | 603 |
break; |
... | ... | |
594 | 606 |
return pts; |
595 | 607 |
} |
596 | 608 |
|
609 |
static int ogg_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) |
|
610 |
{ |
|
611 |
struct ogg *ogg = s->priv_data; |
|
612 |
struct ogg_stream *os = ogg->streams + stream_index; |
|
613 |
int ret; |
|
614 |
|
|
615 |
// Try seeking to a keyframe first. If this fails (very possible), |
|
616 |
// av_seek_frame will fall back to ignoring keyframes |
|
617 |
if (s->streams[stream_index]->codec->codec_type == CODEC_TYPE_VIDEO |
|
618 |
&& !(flags & AVSEEK_FLAG_ANY)) |
|
619 |
os->keyframe_seek = 1; |
|
620 |
|
|
621 |
ret = av_seek_frame_binary(s, stream_index, timestamp, flags); |
|
622 |
if (ret < 0) |
|
623 |
os->keyframe_seek = 0; |
|
624 |
return ret; |
|
625 |
} |
|
626 |
|
|
597 | 627 |
static int ogg_probe(AVProbeData *p) |
598 | 628 |
{ |
599 | 629 |
if (p->buf[0] == 'O' && p->buf[1] == 'g' && |
... | ... | |
612 | 642 |
ogg_read_header, |
613 | 643 |
ogg_read_packet, |
614 | 644 |
ogg_read_close, |
615 |
NULL,
|
|
645 |
ogg_read_seek,
|
|
616 | 646 |
ogg_read_timestamp, |
617 | 647 |
.extensions = "ogg", |
618 | 648 |
.metadata_conv = ff_vorbiscomment_metadata_conv, |
Also available in: Unified diff