annotate oggdec.c @ 6091:9c8c96356051 libavformat

fix raw 555 pixel format, add abgr fourcc
author bcoudurier
date Fri, 04 Jun 2010 23:30:58 +0000
parents 4bedd06c54e2
children 49eedb93140e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
1 /*
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
2 * Ogg bitstream support
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
3 * Luca Barbato <lu_zero@gentoo.org>
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
4 * Based on tcvp implementation
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 877
diff changeset
5 *
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
6 */
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
7
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
8 /**
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
9 Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
10
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
11 Permission is hereby granted, free of charge, to any person
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
12 obtaining a copy of this software and associated documentation
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
13 files (the "Software"), to deal in the Software without
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
14 restriction, including without limitation the rights to use, copy,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
15 modify, merge, publish, distribute, sublicense, and/or sell copies
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
16 of the Software, and to permit persons to whom the Software is
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
17 furnished to do so, subject to the following conditions:
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
18
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
19 The above copyright notice and this permission notice shall be
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
20 included in all copies or substantial portions of the Software.
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
21
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
26 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
29 DEALINGS IN THE SOFTWARE.
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
30 **/
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
31
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
32
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
33 #include <stdio.h>
2714
b22ba392ac21 Rename ogg2.[ch] to oggdec.[ch].
diego
parents: 2713
diff changeset
34 #include "oggdec.h"
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
35 #include "avformat.h"
5857
121d6994c20e Add VorbisComment writing to FLAC files.
jbr
parents: 5829
diff changeset
36 #include "vorbiscomment.h"
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
37
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
38 #define MAX_PAGE_SIZE 65307
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
39 #define DECODER_BUFFER_SIZE MAX_PAGE_SIZE
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
40
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
41 static const struct ogg_codec * const ogg_codecs[] = {
5812
c66b238d4d33 oggdec: Parse skeleton to determine the start time of each stream
conrad
parents: 5810
diff changeset
42 &ff_skeleton_codec,
5512
60671fac35ad Add support for dirac in ogg
conrad
parents: 5434
diff changeset
43 &ff_dirac_codec,
3770
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
44 &ff_speex_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
45 &ff_vorbis_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
46 &ff_theora_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
47 &ff_flac_codec,
5512
60671fac35ad Add support for dirac in ogg
conrad
parents: 5434
diff changeset
48 &ff_old_dirac_codec,
3770
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
49 &ff_old_flac_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
50 &ff_ogm_video_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
51 &ff_ogm_audio_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
52 &ff_ogm_text_codec,
6c71b789c69e Add ff_ prefix to ogg_codec_t structs
reimar
parents: 3767
diff changeset
53 &ff_ogm_old_codec,
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
54 NULL
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
55 };
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
56
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
57 //FIXME We could avoid some structure duplication
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
58 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
59 ogg_save (AVFormatContext * s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
60 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
61 struct ogg *ogg = s->priv_data;
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
62 struct ogg_state *ost =
727
a827309802b5 pre-c99 compatibility
mru
parents: 726
diff changeset
63 av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams));
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
64 int i;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
65 ost->pos = url_ftell (s->pb);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
66 ost->curidx = ogg->curidx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
67 ost->next = ogg->state;
1657
a472266b5d39 save/restore number of streams
mru
parents: 1397
diff changeset
68 ost->nstreams = ogg->nstreams;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
69 memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
70
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
71 for (i = 0; i < ogg->nstreams; i++){
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
72 struct ogg_stream *os = ogg->streams + i;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
73 os->buf = av_malloc (os->bufsize);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
74 memset (os->buf, 0, os->bufsize);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
75 memcpy (os->buf, ost->streams[i].buf, os->bufpos);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
76 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
77
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
78 ogg->state = ost;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
79
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
80 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
81 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
82
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
83 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
84 ogg_restore (AVFormatContext * s, int discard)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
85 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
86 struct ogg *ogg = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
87 ByteIOContext *bc = s->pb;
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
88 struct ogg_state *ost = ogg->state;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
89 int i;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
90
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
91 if (!ost)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
92 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
93
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
94 ogg->state = ost->next;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
95
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
96 if (!discard){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
97 for (i = 0; i < ogg->nstreams; i++)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
98 av_free (ogg->streams[i].buf);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
99
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
100 url_fseek (bc, ost->pos, SEEK_SET);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
101 ogg->curidx = ost->curidx;
1657
a472266b5d39 save/restore number of streams
mru
parents: 1397
diff changeset
102 ogg->nstreams = ost->nstreams;
a472266b5d39 save/restore number of streams
mru
parents: 1397
diff changeset
103 memcpy(ogg->streams, ost->streams,
a472266b5d39 save/restore number of streams
mru
parents: 1397
diff changeset
104 ost->nstreams * sizeof(*ogg->streams));
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
105 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
106
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
107 av_free (ost);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
108
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
109 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
110 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
111
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
112 static int
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
113 ogg_reset (struct ogg * ogg)
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
114 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
115 int i;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
116
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
117 for (i = 0; i < ogg->nstreams; i++){
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
118 struct ogg_stream *os = ogg->streams + i;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
119 os->bufpos = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
120 os->pstart = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
121 os->psize = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
122 os->granule = -1;
5434
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
123 os->lastpts = AV_NOPTS_VALUE;
5514
52c7b29eca31 oggdec: Set dts when known
conrad
parents: 5512
diff changeset
124 os->lastdts = AV_NOPTS_VALUE;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
125 os->sync_pos = -1;
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
126 os->page_pos = 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
127 os->nsegs = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
128 os->segp = 0;
5637
37e2c3e635b3 Fix playback with invalid files that don't set the continuation flag for
conrad
parents: 5514
diff changeset
129 os->incomplete = 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
130 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
131
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
132 ogg->curidx = -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
133
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
134 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
135 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
136
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
137 static const struct ogg_codec *
728
db6846a618bd s/u_char/uint8_t/
mru
parents: 727
diff changeset
138 ogg_find_codec (uint8_t * buf, int size)
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
139 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
140 int i;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
141
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
142 for (i = 0; ogg_codecs[i]; i++)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
143 if (size >= ogg_codecs[i]->magicsize &&
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
144 !memcmp (buf, ogg_codecs[i]->magic, ogg_codecs[i]->magicsize))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
145 return ogg_codecs[i];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
146
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
147 return NULL;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
148 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
149
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
150 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
151 ogg_new_stream (AVFormatContext * s, uint32_t serial)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
152 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
153
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
154 struct ogg *ogg = s->priv_data;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
155 int idx = ogg->nstreams++;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
156 AVStream *st;
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
157 struct ogg_stream *os;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
158
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
159 ogg->streams = av_realloc (ogg->streams,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
160 ogg->nstreams * sizeof (*ogg->streams));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
161 memset (ogg->streams + idx, 0, sizeof (*ogg->streams));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
162 os = ogg->streams + idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
163 os->serial = serial;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
164 os->bufsize = DECODER_BUFFER_SIZE;
1133
554cc16341da 10l: don't allocate a new buffer quite so often
mru
parents: 1132
diff changeset
165 os->buf = av_malloc(os->bufsize);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
166 os->header = -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
167
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
168 st = av_new_stream (s, idx);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
169 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2001
diff changeset
170 return AVERROR(ENOMEM);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
171
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
172 av_set_pts_info(st, 64, 1, 1000000);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
173
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
174 return idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
175 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
176
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
177 static int
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
178 ogg_new_buf(struct ogg *ogg, int idx)
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
179 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
180 struct ogg_stream *os = ogg->streams + idx;
1134
19ceddeafe2e s/u_char/uint8_t/ accidentally copied from tcvp
mru
parents: 1133
diff changeset
181 uint8_t *nb = av_malloc(os->bufsize);
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
182 int size = os->bufpos - os->pstart;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
183 if(os->buf){
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
184 memcpy(nb, os->buf + os->pstart, size);
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
185 av_free(os->buf);
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
186 }
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
187 os->buf = nb;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
188 os->bufpos = size;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
189 os->pstart = 0;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
190
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
191 return 0;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
192 }
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
193
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
194 static int
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
195 ogg_read_page (AVFormatContext * s, int *str)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
196 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
197 ByteIOContext *bc = s->pb;
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
198 struct ogg *ogg = s->priv_data;
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
199 struct ogg_stream *os;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
200 int i = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
201 int flags, nsegs;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
202 uint64_t gp;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
203 uint32_t serial;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
204 uint32_t seq;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
205 uint32_t crc;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
206 int size, idx;
1332
7474cc6383d4 fix some signedness warnings
mru
parents: 1331
diff changeset
207 uint8_t sync[4];
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
208 int sp = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
209
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
210 if (get_buffer (bc, sync, 4) < 4)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
211 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
212
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
213 do{
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
214 int c;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
215
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
216 if (sync[sp & 3] == 'O' &&
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
217 sync[(sp + 1) & 3] == 'g' &&
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
218 sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S')
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
219 break;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
220
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
221 c = url_fgetc (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
222 if (c < 0)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
223 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
224 sync[sp++ & 3] = c;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
225 }while (i++ < MAX_PAGE_SIZE);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
226
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
227 if (i >= MAX_PAGE_SIZE){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
228 av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n");
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
229 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
230 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
231
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
232 if (url_fgetc (bc) != 0) /* version */
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
233 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
234
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
235 flags = url_fgetc (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
236 gp = get_le64 (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
237 serial = get_le32 (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
238 seq = get_le32 (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
239 crc = get_le32 (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
240 nsegs = url_fgetc (bc);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
241
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
242 idx = ogg_find_stream (ogg, serial);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
243 if (idx < 0){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
244 idx = ogg_new_stream (s, serial);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
245 if (idx < 0)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
246 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
247 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
248
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
249 os = ogg->streams + idx;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
250 os->page_pos = url_ftell(bc) - 27;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
251
1133
554cc16341da 10l: don't allocate a new buffer quite so often
mru
parents: 1132
diff changeset
252 if(os->psize > 0)
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
253 ogg_new_buf(ogg, idx);
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
254
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
255 if (get_buffer (bc, os->segments, nsegs) < nsegs)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
256 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
257
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
258 os->nsegs = nsegs;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
259 os->segp = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
260
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
261 size = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
262 for (i = 0; i < nsegs; i++)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
263 size += os->segments[i];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
264
5637
37e2c3e635b3 Fix playback with invalid files that don't set the continuation flag for
conrad
parents: 5514
diff changeset
265 if (flags & OGG_FLAG_CONT || os->incomplete){
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
266 if (!os->psize){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
267 while (os->segp < os->nsegs){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
268 int seg = os->segments[os->segp++];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
269 os->pstart += seg;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
270 if (seg < 255)
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
271 break;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
272 }
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
273 os->sync_pos = os->page_pos;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
274 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
275 }else{
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
276 os->psize = 0;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
277 os->sync_pos = os->page_pos;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
278 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
279
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
280 if (os->bufsize - os->bufpos < size){
728
db6846a618bd s/u_char/uint8_t/
mru
parents: 727
diff changeset
281 uint8_t *nb = av_malloc (os->bufsize *= 2);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
282 memcpy (nb, os->buf, os->bufpos);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
283 av_free (os->buf);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
284 os->buf = nb;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
285 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
286
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
287 if (get_buffer (bc, os->buf + os->bufpos, size) < size)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
288 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
289
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
290 os->bufpos += size;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
291 os->granule = gp;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
292 os->flags = flags;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
293
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
294 if (str)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
295 *str = idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
296
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
297 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
298 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
299
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
300 static int
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
301 ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize, int64_t *fpos)
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
302 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
303 struct ogg *ogg = s->priv_data;
5434
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
304 int idx, i;
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
305 struct ogg_stream *os;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
306 int complete = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
307 int segp = 0, psize = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
308
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
309 #if 0
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
310 av_log (s, AV_LOG_DEBUG, "ogg_packet: curidx=%i\n", ogg->curidx);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
311 #endif
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
312
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
313 do{
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
314 idx = ogg->curidx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
315
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
316 while (idx < 0){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
317 if (ogg_read_page (s, &idx) < 0)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
318 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
319 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
320
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
321 os = ogg->streams + idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
322
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
323 #if 0
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
324 av_log (s, AV_LOG_DEBUG,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
325 "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n",
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
326 idx, os->pstart, os->psize, os->segp, os->nsegs);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
327 #endif
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
328
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
329 if (!os->codec){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
330 if (os->header < 0){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
331 os->codec = ogg_find_codec (os->buf, os->bufpos);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
332 if (!os->codec){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
333 os->header = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
334 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
335 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
336 }else{
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
337 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
338 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
339 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
340
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
341 segp = os->segp;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
342 psize = os->psize;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
343
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
344 while (os->segp < os->nsegs){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
345 int ss = os->segments[os->segp++];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
346 os->psize += ss;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
347 if (ss < 255){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
348 complete = 1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
349 break;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
350 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
351 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
352
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
353 if (!complete && os->segp == os->nsegs){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
354 ogg->curidx = -1;
5637
37e2c3e635b3 Fix playback with invalid files that don't set the continuation flag for
conrad
parents: 5514
diff changeset
355 os->incomplete = 1;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
356 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
357 }while (!complete);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
358
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
359 #if 0
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
360 av_log (s, AV_LOG_DEBUG,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
361 "ogg_packet: idx %i, frame size %i, start %i\n",
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
362 idx, os->psize, os->pstart);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
363 #endif
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
364
5958
ad447f146859 oggdec: Move warning about missing granule to the correct place
conrad
parents: 5957
diff changeset
365 if (os->granule == -1)
ad447f146859 oggdec: Move warning about missing granule to the correct place
conrad
parents: 5957
diff changeset
366 av_log(s, AV_LOG_WARNING, "Page at %lld is missing granule\n", os->page_pos);
ad447f146859 oggdec: Move warning about missing granule to the correct place
conrad
parents: 5957
diff changeset
367
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
368 ogg->curidx = idx;
5637
37e2c3e635b3 Fix playback with invalid files that don't set the continuation flag for
conrad
parents: 5514
diff changeset
369 os->incomplete = 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
370
5829
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
371 if (os->header) {
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
372 os->header = os->codec->header (s, idx);
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
373 if (!os->header){
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
374 os->segp = segp;
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
375 os->psize = psize;
5829
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
376 if (!ogg->headers)
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
377 s->data_offset = os->sync_pos;
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
378 ogg->headers = 1;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
379 }else{
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
380 os->pstart += os->psize;
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
381 os->psize = 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
382 }
5829
8e97be5c4b94 oggdec: Pass packets to header() until the stream is done with them
conrad
parents: 5818
diff changeset
383 } else {
2732
2b101e9d25c0 set PKT_FLAG_KEY for Theora and OGM streams
mru
parents: 2714
diff changeset
384 os->pflags = 0;
5276
5de92e352cf9 Calculate correct packet durations when demuxing Ogg/Speex. This involves
jbr
parents: 5240
diff changeset
385 os->pduration = 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
386 if (os->codec && os->codec->packet)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
387 os->codec->packet (s, idx);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
388 if (str)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
389 *str = idx;
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
390 if (dstart)
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
391 *dstart = os->pstart;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
392 if (dsize)
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
393 *dsize = os->psize;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
394 if (fpos)
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
395 *fpos = os->sync_pos;
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
396 os->pstart += os->psize;
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
397 os->psize = 0;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
398 os->sync_pos = os->page_pos;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
399 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
400
5434
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
401 // determine whether there are more complete packets in this page
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
402 // if not, the page's granule will apply to this packet
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
403 os->page_end = 1;
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
404 for (i = os->segp; i < os->nsegs; i++)
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
405 if (os->segments[i] < 255) {
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
406 os->page_end = 0;
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
407 break;
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
408 }
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
409
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
410 if (os->segp == os->nsegs)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
411 ogg->curidx = -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
412
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
413 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
414 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
415
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
416 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
417 ogg_get_headers (AVFormatContext * s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
418 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
419 struct ogg *ogg = s->priv_data;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
420
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
421 do{
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
422 if (ogg_packet (s, NULL, NULL, NULL, NULL) < 0)
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
423 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
424 }while (!ogg->headers);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
425
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
426 #if 0
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
427 av_log (s, AV_LOG_DEBUG, "found headers\n");
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
428 #endif
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
429
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
430 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
431 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
432
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
433 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
434 ogg_get_length (AVFormatContext * s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
435 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
436 struct ogg *ogg = s->priv_data;
5957
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
437 int i;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3770
diff changeset
438 int64_t size, end;
766
ed249b9caa2f don't try to find file length if streaming
mru
parents: 764
diff changeset
439
2841
a41a1ec2213c use proper url_is_streamed() API
aurel
parents: 2771
diff changeset
440 if(url_is_streamed(s->pb))
766
ed249b9caa2f don't try to find file length if streaming
mru
parents: 764
diff changeset
441 return 0;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
442
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
443 // already set
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
444 if (s->duration != AV_NOPTS_VALUE)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
445 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
446
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
447 size = url_fsize(s->pb);
1104
2a31a69400f3 fix seek related bugs
mru
parents: 1077
diff changeset
448 if(size < 0)
2a31a69400f3 fix seek related bugs
mru
parents: 1077
diff changeset
449 return 0;
4876
3a1ffb822e81 Ensure that there's pages to read for duration calculation in the ogg demuxer
conrad
parents: 4483
diff changeset
450 end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0;
1104
2a31a69400f3 fix seek related bugs
mru
parents: 1077
diff changeset
451
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
452 ogg_save (s);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
453 url_fseek (s->pb, end, SEEK_SET);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
454
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
455 while (!ogg_read_page (s, &i)){
1658
2400a22af998 check for sane values in ogg_get_length(), fix lol-ffplay.ogm fuzz test
mru
parents: 1657
diff changeset
456 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
5957
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
457 ogg->streams[i].codec) {
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
458 s->streams[i]->duration =
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
459 ogg_gptopts (s, i, ogg->streams[i].granule, NULL);
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
460 if (s->streams[i]->start_time != AV_NOPTS_VALUE)
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
461 s->streams[i]->duration -= s->streams[i]->start_time;
986168b721ca oggdec: Fix duration calculation if the last page in a file has no granule
conrad
parents: 5956
diff changeset
462 }
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
463 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
464
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
465 ogg_restore (s, 0);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
466
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
467 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
468 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
469
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
470
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
471 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
472 ogg_read_header (AVFormatContext * s, AVFormatParameters * ap)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
473 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
474 struct ogg *ogg = s->priv_data;
5240
432736854b4c Disable parsing for ogg streams where no ogg header was found,
reimar
parents: 5032
diff changeset
475 int i;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
476 ogg->curidx = -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
477 //linear headers seek from start
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
478 if (ogg_get_headers (s) < 0){
4483
187c981dfcb0 Use consistent indent style in oggdec.
pross
parents: 4016
diff changeset
479 return -1;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
480 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
481
5240
432736854b4c Disable parsing for ogg streams where no ogg header was found,
reimar
parents: 5032
diff changeset
482 for (i = 0; i < ogg->nstreams; i++)
432736854b4c Disable parsing for ogg streams where no ogg header was found,
reimar
parents: 5032
diff changeset
483 if (ogg->streams[i].header < 0)
432736854b4c Disable parsing for ogg streams where no ogg header was found,
reimar
parents: 5032
diff changeset
484 ogg->streams[i].codec = NULL;
432736854b4c Disable parsing for ogg streams where no ogg header was found,
reimar
parents: 5032
diff changeset
485
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
486 //linear granulepos seek from end
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
487 ogg_get_length (s);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
488
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
489 //fill the extradata in the per codec callbacks
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
490 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
491 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
492
5816
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
493 static int64_t ogg_calc_pts(AVFormatContext *s, int idx, int64_t *dts)
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
494 {
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
495 struct ogg *ogg = s->priv_data;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
496 struct ogg_stream *os = ogg->streams + idx;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
497 int64_t pts = AV_NOPTS_VALUE;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
498
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
499 if (dts)
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
500 *dts = AV_NOPTS_VALUE;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
501
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
502 if (os->lastpts != AV_NOPTS_VALUE) {
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
503 pts = os->lastpts;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
504 os->lastpts = AV_NOPTS_VALUE;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
505 }
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
506 if (os->lastdts != AV_NOPTS_VALUE) {
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
507 if (dts)
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
508 *dts = os->lastdts;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
509 os->lastdts = AV_NOPTS_VALUE;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
510 }
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
511 if (os->page_end) {
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
512 if (os->granule != -1LL) {
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
513 if (os->codec && os->codec->granule_is_start)
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
514 pts = ogg_gptopts(s, idx, os->granule, dts);
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
515 else
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
516 os->lastpts = ogg_gptopts(s, idx, os->granule, &os->lastdts);
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
517 os->granule = -1LL;
5958
ad447f146859 oggdec: Move warning about missing granule to the correct place
conrad
parents: 5957
diff changeset
518 }
5816
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
519 }
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
520 return pts;
c587ece53810 oggdec: Move PTS/DTS calculation to a function
conrad
parents: 5813
diff changeset
521 }
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
522
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
523 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
524 ogg_read_packet (AVFormatContext * s, AVPacket * pkt)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
525 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
526 struct ogg *ogg;
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
527 struct ogg_stream *os;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
528 int idx = -1;
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
529 int pstart, psize;
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
530 int64_t fpos, pts, dts;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
531
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 877
diff changeset
532 //Get an ogg packet
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
533 retry:
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
534 do{
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
535 if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
536 return AVERROR(EIO);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
537 }while (idx < 0 || !s->streams[idx]);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
538
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
539 ogg = s->priv_data;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
540 os = ogg->streams + idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
541
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
542 // pflags might not be set until after this
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
543 pts = ogg_calc_pts(s, idx, &dts);
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
544
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
545 if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
546 goto retry;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
547 os->keyframe_seek = 0;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
548
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
549 //Alloc a pkt
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
550 if (av_new_packet (pkt, psize) < 0)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
551 return AVERROR(EIO);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
552 pkt->stream_index = idx;
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
553 memcpy (pkt->data, os->buf + pstart, psize);
5434
68c8e7affd44 Fix PTS for OGM codecs.
conrad
parents: 5276
diff changeset
554
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
555 pkt->pts = pts;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
556 pkt->dts = dts;
2732
2b101e9d25c0 set PKT_FLAG_KEY for Theora and OGM streams
mru
parents: 2714
diff changeset
557 pkt->flags = os->pflags;
5276
5de92e352cf9 Calculate correct packet durations when demuxing Ogg/Speex. This involves
jbr
parents: 5240
diff changeset
558 pkt->duration = os->pduration;
5808
9145ca829bce oggdec: Save offset of the page needed to reconstruct the current packet
conrad
parents: 5639
diff changeset
559 pkt->pos = fpos;
2732
2b101e9d25c0 set PKT_FLAG_KEY for Theora and OGM streams
mru
parents: 2714
diff changeset
560
1132
a5487f44bbfa cleaned up buffer management
mru
parents: 1120
diff changeset
561 return psize;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
562 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
563
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
564
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
565 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
566 ogg_read_close (AVFormatContext * s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
567 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
568 struct ogg *ogg = s->priv_data;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
569 int i;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
570
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
571 for (i = 0; i < ogg->nstreams; i++){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
572 av_free (ogg->streams[i].buf);
755
27449ee55201 support theora in ogg, plus required ogg core changes
mru
parents: 730
diff changeset
573 av_free (ogg->streams[i].private);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
574 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
575 av_free (ogg->streams);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
576 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
577 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
578
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
579
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
580 static int64_t
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
581 ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
582 int64_t pos_limit)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
583 {
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
584 struct ogg *ogg = s->priv_data;
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
585 struct ogg_stream *os = ogg->streams + stream_index;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2732
diff changeset
586 ByteIOContext *bc = s->pb;
2592
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
587 int64_t pts = AV_NOPTS_VALUE;
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
588 int i;
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
589 url_fseek(bc, *pos_arg, SEEK_SET);
5817
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
590 ogg_reset(ogg);
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
591
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
592 while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) {
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
593 if (i == stream_index) {
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
594 pts = ogg_calc_pts(s, i, NULL);
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
595 if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
596 pts = AV_NOPTS_VALUE;
5817
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
597 }
eb9c746c3584 oggdec: Determine pts and filepos on a packet basis in read_timestamp
conrad
parents: 5816
diff changeset
598 if (pts != AV_NOPTS_VALUE)
2592
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
599 break;
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
600 }
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
601 ogg_reset(ogg);
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
602 return pts;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
603 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
604
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
605 static int ogg_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
606 {
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
607 struct ogg *ogg = s->priv_data;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
608 struct ogg_stream *os = ogg->streams + stream_index;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
609 int ret;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
610
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
611 // Try seeking to a keyframe first. If this fails (very possible),
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
612 // av_seek_frame will fall back to ignoring keyframes
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5857
diff changeset
613 if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_VIDEO
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
614 && !(flags & AVSEEK_FLAG_ANY))
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
615 os->keyframe_seek = 1;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
616
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
617 ret = av_seek_frame_binary(s, stream_index, timestamp, flags);
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
618 if (ret < 0)
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
619 os->keyframe_seek = 0;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
620 return ret;
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
621 }
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
622
877
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
623 static int ogg_probe(AVProbeData *p)
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
624 {
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
625 if (p->buf[0] == 'O' && p->buf[1] == 'g' &&
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
626 p->buf[2] == 'g' && p->buf[3] == 'S' &&
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
627 p->buf[4] == 0x0 && p->buf[5] <= 0x7 )
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
628 return AVPROBE_SCORE_MAX;
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
629 else
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
630 return 0;
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
631 }
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
632
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
633 AVInputFormat ogg_demuxer = {
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
634 "ogg",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3023
diff changeset
635 NULL_IF_CONFIG_SMALL("Ogg"),
4016
6cd006bc2de9 OGG: untypedef demuxer structs
mru
parents: 3973
diff changeset
636 sizeof (struct ogg),
877
7e42b4e47dfc ogg format probe function by Ivo <ivop at euronet nl>
mru
parents: 858
diff changeset
637 ogg_probe,
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
638 ogg_read_header,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
639 ogg_read_packet,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
640 ogg_read_close,
5818
1a3c4f74f17d oggdec: Seek to keyframes
conrad
parents: 5817
diff changeset
641 ogg_read_seek,
2592
c2f4fba2c234 Add a read_timestamp function to ogg demuxer
reimar
parents: 2378
diff changeset
642 ogg_read_timestamp,
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
643 .extensions = "ogg",
5032
3aabdadf9d5f Add a VorbisComment metadata conversion table and use it in the FLAC and
jbr
parents: 4876
diff changeset
644 .metadata_conv = ff_vorbiscomment_metadata_conv,
6047
4bedd06c54e2 Enable AVFMT_GENERIC_INDEX for Ogg demuxer. This avoids the many
reimar
parents: 5958
diff changeset
645 .flags = AVFMT_GENERIC_INDEX,
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
646 };