OLD | NEW |
1 /* | 1 /* |
2 * Ogg bitstream support | 2 * Ogg bitstream support |
3 * Luca Barbato <lu_zero@gentoo.org> | 3 * Luca Barbato <lu_zero@gentoo.org> |
4 * Based on tcvp implementation | 4 * Based on tcvp implementation |
5 * | 5 * |
6 */ | 6 */ |
7 | 7 |
8 /** | 8 /** |
9 Copyright (C) 2005 Michael Ahlberg, Måns Rullgård | 9 Copyright (C) 2005 Michael Ahlberg, Måns Rullgård |
10 | 10 |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 av_free (ogg->streams); | 603 av_free (ogg->streams); |
604 return 0; | 604 return 0; |
605 } | 605 } |
606 | 606 |
607 | 607 |
608 static int64_t | 608 static int64_t |
609 ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg, | 609 ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg, |
610 int64_t pos_limit) | 610 int64_t pos_limit) |
611 { | 611 { |
612 struct ogg *ogg = s->priv_data; | 612 struct ogg *ogg = s->priv_data; |
613 struct ogg_stream *os = ogg->streams + stream_index; | |
614 ByteIOContext *bc = s->pb; | 613 ByteIOContext *bc = s->pb; |
615 int64_t pts = AV_NOPTS_VALUE; | 614 int64_t pts = AV_NOPTS_VALUE; |
616 int i; | 615 int i = -1; |
617 int packet = 0; | 616 int packet = 0; |
618 int64_t start_pos = *pos_arg; | 617 int64_t start_pos = *pos_arg; |
619 url_fseek(bc, *pos_arg, SEEK_SET); | 618 url_fseek(bc, *pos_arg, SEEK_SET); |
620 ogg_reset(ogg); | 619 ogg_reset(ogg); |
621 | 620 |
622 while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg))
{ | 621 while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg))
{ |
623 if (i == stream_index) { | 622 if (i == stream_index) { |
| 623 struct ogg_stream *os = ogg->streams + stream_index; |
624 pts = ogg_calc_pts(s, i, NULL); | 624 pts = ogg_calc_pts(s, i, NULL); |
625 if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) | 625 if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) |
626 pts = AV_NOPTS_VALUE; | 626 pts = AV_NOPTS_VALUE; |
627 | 627 |
628 // This is for the special case for the first packet in the stream. | 628 // This is for the special case for the first packet in the stream. |
629 if (pts == AV_NOPTS_VALUE && start_pos <= s->data_offset && !packet)
{ | 629 if (pts == AV_NOPTS_VALUE && start_pos <= s->data_offset && !packet)
{ |
630 pts = 0; | 630 pts = 0; |
631 } | 631 } |
632 ++packet; | 632 ++packet; |
633 } | 633 } |
(...skipping 14 matching lines...) Expand all Loading... |
648 int64_t seek_pts; | 648 int64_t seek_pts; |
649 int i; | 649 int i; |
650 | 650 |
651 // Try seeking to a keyframe first. If this fails (very possible), | 651 // Try seeking to a keyframe first. If this fails (very possible), |
652 // av_seek_frame will fall back to ignoring keyframes | 652 // av_seek_frame will fall back to ignoring keyframes |
653 if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO | 653 if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO |
654 && !(flags & AVSEEK_FLAG_ANY)) | 654 && !(flags & AVSEEK_FLAG_ANY)) |
655 os->keyframe_seek = 1; | 655 os->keyframe_seek = 1; |
656 | 656 |
657 ret = av_seek_frame_binary(s, stream_index, timestamp, flags); | 657 ret = av_seek_frame_binary(s, stream_index, timestamp, flags); |
| 658 os = ogg->streams + stream_index; |
658 if (ret < 0) | 659 if (ret < 0) |
659 os->keyframe_seek = 0; | 660 os->keyframe_seek = 0; |
660 | 661 |
661 // Save the position seeked to. | 662 // Save the position seeked to. |
662 pos_arg = seek_pos = url_ftell(s->pb); | 663 pos_arg = seek_pos = url_ftell(s->pb); |
663 seek_pts = ogg_read_timestamp(s, stream_index, &pos_arg, url_fsize(s->pb)); | 664 seek_pts = ogg_read_timestamp(s, stream_index, &pos_arg, url_fsize(s->pb)); |
| 665 os = ogg->streams + stream_index; |
664 | 666 |
665 // Since we have seeked to the beginning then reset lastpts and lastdts to 0
. | 667 // Since we have seeked to the beginning then reset lastpts and lastdts to 0
. |
666 if (!seek_pts) { | 668 if (!seek_pts) { |
667 for (i = 0; i < ogg->nstreams; i++){ | 669 for (i = 0; i < ogg->nstreams; i++){ |
668 struct ogg_stream *stream = ogg->streams + i; | 670 struct ogg_stream *stream = ogg->streams + i; |
669 stream->lastpts = 0; | 671 stream->lastpts = 0; |
670 stream->lastdts = 0; | 672 stream->lastdts = 0; |
671 } | 673 } |
672 os->keyframe_seek = 0; | 674 os->keyframe_seek = 0; |
673 } | 675 } |
(...skipping 17 matching lines...) Expand all Loading... |
691 sizeof (struct ogg), | 693 sizeof (struct ogg), |
692 ogg_probe, | 694 ogg_probe, |
693 ogg_read_header, | 695 ogg_read_header, |
694 ogg_read_packet, | 696 ogg_read_packet, |
695 ogg_read_close, | 697 ogg_read_close, |
696 ogg_read_seek, | 698 ogg_read_seek, |
697 ogg_read_timestamp, | 699 ogg_read_timestamp, |
698 .extensions = "ogg", | 700 .extensions = "ogg", |
699 .flags = AVFMT_GENERIC_INDEX, | 701 .flags = AVFMT_GENERIC_INDEX, |
700 }; | 702 }; |
OLD | NEW |