Mercurial > libavformat.hg
annotate oggdec.c @ 5510:47ef38389cd3 libavformat
Deluxe Paint Animation demuxer
author | pross |
---|---|
date | Sun, 10 Jan 2010 05:47:50 +0000 |
parents | 68c8e7affd44 |
children | 60671fac35ad |
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 | 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 | 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" |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
36 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
37 #define MAX_PAGE_SIZE 65307 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
38 #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
|
39 |
4016 | 40 static const struct ogg_codec * const ogg_codecs[] = { |
3770 | 41 &ff_speex_codec, |
42 &ff_vorbis_codec, | |
43 &ff_theora_codec, | |
44 &ff_flac_codec, | |
45 &ff_old_flac_codec, | |
46 &ff_ogm_video_codec, | |
47 &ff_ogm_audio_codec, | |
48 &ff_ogm_text_codec, | |
49 &ff_ogm_old_codec, | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
50 NULL |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
51 }; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
52 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
53 //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
|
54 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
55 ogg_save (AVFormatContext * s) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
56 { |
4016 | 57 struct ogg *ogg = s->priv_data; |
58 struct ogg_state *ost = | |
727 | 59 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
|
60 int i; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
61 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
|
62 ost->curidx = ogg->curidx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
63 ost->next = ogg->state; |
1657 | 64 ost->nstreams = ogg->nstreams; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
65 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
|
66 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
67 for (i = 0; i < ogg->nstreams; i++){ |
4016 | 68 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
|
69 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
|
70 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
|
71 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
|
72 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
73 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
74 ogg->state = ost; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
75 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
76 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
79 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
80 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
|
81 { |
4016 | 82 struct ogg *ogg = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
83 ByteIOContext *bc = s->pb; |
4016 | 84 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
|
85 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
86 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
87 if (!ost) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
88 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
89 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
90 ogg->state = ost->next; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
91 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
92 if (!discard){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
93 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
|
94 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
|
95 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
96 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
|
97 ogg->curidx = ost->curidx; |
1657 | 98 ogg->nstreams = ost->nstreams; |
99 memcpy(ogg->streams, ost->streams, | |
100 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
|
101 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
102 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
103 av_free (ost); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
104 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
105 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
108 static int |
4016 | 109 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
|
110 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
111 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
112 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
113 for (i = 0; i < ogg->nstreams; i++){ |
4016 | 114 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
|
115 os->bufpos = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
116 os->pstart = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
117 os->psize = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
118 os->granule = -1; |
5434 | 119 os->lastpts = AV_NOPTS_VALUE; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
120 os->nsegs = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
121 os->segp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
122 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
123 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
124 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
125 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
126 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
127 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
128 |
4016 | 129 static const struct ogg_codec * |
728 | 130 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
|
131 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
132 int i; |
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 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
|
135 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
|
136 !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
|
137 return ogg_codecs[i]; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
138 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
139 return NULL; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
140 } |
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 static int |
4016 | 143 ogg_find_stream (struct ogg * ogg, int serial) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
144 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
145 int 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 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
|
148 if (ogg->streams[i].serial == serial) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
149 return i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
150 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
151 return -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
154 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
155 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
|
156 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
157 |
4016 | 158 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
|
159 int idx = ogg->nstreams++; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
160 AVStream *st; |
4016 | 161 struct ogg_stream *os; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
162 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
163 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
|
164 ogg->nstreams * sizeof (*ogg->streams)); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
165 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
|
166 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
167 os->serial = serial; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
168 os->bufsize = DECODER_BUFFER_SIZE; |
1133 | 169 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
|
170 os->header = -1; |
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 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
|
173 if (!st) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2001
diff
changeset
|
174 return AVERROR(ENOMEM); |
726
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 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
|
177 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
178 return idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
179 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
180 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
181 static int |
4016 | 182 ogg_new_buf(struct ogg *ogg, int idx) |
1132 | 183 { |
4016 | 184 struct ogg_stream *os = ogg->streams + idx; |
1134 | 185 uint8_t *nb = av_malloc(os->bufsize); |
1132 | 186 int size = os->bufpos - os->pstart; |
187 if(os->buf){ | |
188 memcpy(nb, os->buf + os->pstart, size); | |
189 av_free(os->buf); | |
190 } | |
191 os->buf = nb; | |
192 os->bufpos = size; | |
193 os->pstart = 0; | |
194 | |
195 return 0; | |
196 } | |
197 | |
198 static int | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
199 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
|
200 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
201 ByteIOContext *bc = s->pb; |
4016 | 202 struct ogg *ogg = s->priv_data; |
203 struct ogg_stream *os; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
204 int i = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
205 int flags, nsegs; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
206 uint64_t gp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
207 uint32_t serial; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
208 uint32_t seq; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
209 uint32_t crc; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
210 int size, idx; |
1332 | 211 uint8_t sync[4]; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
212 int sp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
213 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
214 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
|
215 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
216 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
217 do{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
218 int c; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
219 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
220 if (sync[sp & 3] == 'O' && |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
221 sync[(sp + 1) & 3] == 'g' && |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
222 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
|
223 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
224 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
225 c = url_fgetc (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
226 if (c < 0) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
227 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
228 sync[sp++ & 3] = c; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
229 }while (i++ < MAX_PAGE_SIZE); |
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 if (i >= MAX_PAGE_SIZE){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
232 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
|
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
236 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
|
237 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
238 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
239 flags = url_fgetc (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
240 gp = get_le64 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
241 serial = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
242 seq = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
243 crc = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
244 nsegs = url_fgetc (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
245 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
246 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
|
247 if (idx < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
248 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
|
249 if (idx < 0) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
250 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
251 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
252 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
253 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
254 |
1133 | 255 if(os->psize > 0) |
1132 | 256 ogg_new_buf(ogg, idx); |
257 | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
258 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
|
259 return -1; |
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 os->nsegs = nsegs; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
262 os->segp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
263 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
264 size = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
265 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
|
266 size += os->segments[i]; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
267 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
268 if (flags & OGG_FLAG_CONT){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
269 if (!os->psize){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
270 while (os->segp < os->nsegs){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
271 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
|
272 os->pstart += seg; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
273 if (seg < 255) |
4483 | 274 break; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
275 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
276 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
277 }else{ |
4483 | 278 os->psize = 0; |
726
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
281 if (os->bufsize - os->bufpos < size){ |
728 | 282 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
|
283 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
|
284 av_free (os->buf); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
285 os->buf = nb; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
288 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
|
289 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
290 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
291 os->bufpos += size; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
292 os->granule = gp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
293 os->flags = flags; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
294 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
295 if (str) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
296 *str = idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
297 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
298 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
301 static int |
1132 | 302 ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
303 { |
4016 | 304 struct ogg *ogg = s->priv_data; |
5434 | 305 int idx, i; |
4016 | 306 struct ogg_stream *os; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
307 int complete = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
308 int segp = 0, psize = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
309 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
310 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
311 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
|
312 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
313 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
314 do{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
315 idx = ogg->curidx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
316 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
317 while (idx < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
318 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
|
319 return -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
322 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
323 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
324 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
325 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
|
326 "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
|
327 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
|
328 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
329 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
330 if (!os->codec){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
331 if (os->header < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
332 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
|
333 if (!os->codec){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
334 os->header = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
335 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
336 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
337 }else{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
338 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
342 segp = os->segp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
343 psize = os->psize; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
344 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
345 while (os->segp < os->nsegs){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
346 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
|
347 os->psize += ss; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
348 if (ss < 255){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
349 complete = 1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
350 break; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
354 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
|
355 ogg->curidx = -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
365 ogg->curidx = idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
366 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
367 if (os->header < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
368 int hdr = os->codec->header (s, idx); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
369 if (!hdr){ |
4483 | 370 os->header = os->seq; |
371 os->segp = segp; | |
372 os->psize = psize; | |
373 ogg->headers = 1; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
374 }else{ |
4483 | 375 os->pstart += os->psize; |
376 os->psize = 0; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
377 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
378 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
379 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
380 if (os->header > -1 && os->seq > os->header){ |
2732 | 381 os->pflags = 0; |
5276
5de92e352cf9
Calculate correct packet durations when demuxing Ogg/Speex. This involves
jbr
parents:
5240
diff
changeset
|
382 os->pduration = 0; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
383 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
|
384 os->codec->packet (s, idx); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
385 if (str) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
386 *str = idx; |
1132 | 387 if (dstart) |
388 *dstart = os->pstart; | |
389 if (dsize) | |
390 *dsize = os->psize; | |
391 os->pstart += os->psize; | |
392 os->psize = 0; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
393 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
394 |
5434 | 395 // determine whether there are more complete packets in this page |
396 // if not, the page's granule will apply to this packet | |
397 os->page_end = 1; | |
398 for (i = os->segp; i < os->nsegs; i++) | |
399 if (os->segments[i] < 255) { | |
400 os->page_end = 0; | |
401 break; | |
402 } | |
403 | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
404 os->seq++; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
405 if (os->segp == os->nsegs) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
406 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
407 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
408 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
409 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
410 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
411 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
412 ogg_get_headers (AVFormatContext * s) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
413 { |
4016 | 414 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
|
415 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
416 do{ |
1132 | 417 if (ogg_packet (s, NULL, NULL, NULL) < 0) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
418 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
419 }while (!ogg->headers); |
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 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
422 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
|
423 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
424 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
425 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
426 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
427 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
428 static uint64_t |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
429 ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
430 { |
4016 | 431 struct ogg *ogg = s->priv_data; |
432 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
|
433 uint64_t pts = AV_NOPTS_VALUE; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
434 |
755 | 435 if(os->codec->gptopts){ |
887 | 436 pts = os->codec->gptopts(s, i, gp); |
1077 | 437 } else { |
755 | 438 pts = gp; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
439 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
440 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
441 return pts; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
444 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
445 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
446 ogg_get_length (AVFormatContext * s) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
447 { |
4016 | 448 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
|
449 int idx = -1, i; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3770
diff
changeset
|
450 int64_t size, end; |
766 | 451 |
2841 | 452 if(url_is_streamed(s->pb)) |
766 | 453 return 0; |
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 // already set |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
456 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
|
457 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
458 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
459 size = url_fsize(s->pb); |
1104 | 460 if(size < 0) |
461 return 0; | |
4876
3a1ffb822e81
Ensure that there's pages to read for duration calculation in the ogg demuxer
conrad
parents:
4483
diff
changeset
|
462 end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0; |
1104 | 463 |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
464 ogg_save (s); |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
465 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
|
466 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
467 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
|
468 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && |
2400a22af998
check for sane values in ogg_get_length(), fix lol-ffplay.ogm fuzz test
mru
parents:
1657
diff
changeset
|
469 ogg->streams[i].codec) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
470 idx = i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
471 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
472 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
473 if (idx != -1){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
474 s->streams[idx]->duration = |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
475 ogg_gptopts (s, idx, ogg->streams[idx].granule); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
476 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
477 |
1104 | 478 ogg->size = size; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
479 ogg_restore (s, 0); |
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 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
482 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
483 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
484 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
485 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
486 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
|
487 { |
4016 | 488 struct ogg *ogg = s->priv_data; |
5240
432736854b4c
Disable parsing for ogg streams where no ogg header was found,
reimar
parents:
5032
diff
changeset
|
489 int i; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
490 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
491 //linear headers seek from start |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
492 if (ogg_get_headers (s) < 0){ |
4483 | 493 return -1; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
494 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
495 |
5240
432736854b4c
Disable parsing for ogg streams where no ogg header was found,
reimar
parents:
5032
diff
changeset
|
496 for (i = 0; i < ogg->nstreams; i++) |
432736854b4c
Disable parsing for ogg streams where no ogg header was found,
reimar
parents:
5032
diff
changeset
|
497 if (ogg->streams[i].header < 0) |
432736854b4c
Disable parsing for ogg streams where no ogg header was found,
reimar
parents:
5032
diff
changeset
|
498 ogg->streams[i].codec = NULL; |
432736854b4c
Disable parsing for ogg streams where no ogg header was found,
reimar
parents:
5032
diff
changeset
|
499 |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
500 //linear granulepos seek from end |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
501 ogg_get_length (s); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
502 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
503 //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
|
504 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
505 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
506 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
507 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
508 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
509 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
|
510 { |
4016 | 511 struct ogg *ogg; |
512 struct ogg_stream *os; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
513 int idx = -1; |
1132 | 514 int pstart, psize; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
515 |
885 | 516 //Get an ogg packet |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
517 do{ |
1132 | 518 if (ogg_packet (s, &idx, &pstart, &psize) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
519 return AVERROR(EIO); |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
520 }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
|
521 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
522 ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
523 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
524 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
525 //Alloc a pkt |
1132 | 526 if (av_new_packet (pkt, psize) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
527 return AVERROR(EIO); |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
528 pkt->stream_index = idx; |
1132 | 529 memcpy (pkt->data, os->buf + pstart, psize); |
5434 | 530 |
531 if (os->lastpts != AV_NOPTS_VALUE) { | |
532 pkt->pts = os->lastpts; | |
533 os->lastpts = AV_NOPTS_VALUE; | |
534 } | |
535 if (os->page_end) { | |
536 if (os->granule != -1LL) { | |
537 if (os->codec && os->codec->granule_is_start) | |
538 pkt->pts = ogg_gptopts(s, idx, os->granule); | |
539 else | |
540 os->lastpts = ogg_gptopts(s, idx, os->granule); | |
541 os->granule = -1LL; | |
542 } else | |
543 av_log(s, AV_LOG_WARNING, "Packet is missing granule\n"); | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
544 } |
1132 | 545 |
2732 | 546 pkt->flags = os->pflags; |
5276
5de92e352cf9
Calculate correct packet durations when demuxing Ogg/Speex. This involves
jbr
parents:
5240
diff
changeset
|
547 pkt->duration = os->pduration; |
2732 | 548 |
1132 | 549 return psize; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
550 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
551 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
552 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
553 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
554 ogg_read_close (AVFormatContext * s) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
555 { |
4016 | 556 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
|
557 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
558 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
559 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
|
560 av_free (ogg->streams[i].buf); |
755 | 561 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
|
562 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
563 av_free (ogg->streams); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
564 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
565 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
566 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
567 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
568 static int64_t |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
569 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
|
570 int64_t pos_limit) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
571 { |
4016 | 572 struct ogg *ogg = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2732
diff
changeset
|
573 ByteIOContext *bc = s->pb; |
2592 | 574 int64_t pts = AV_NOPTS_VALUE; |
575 int i; | |
576 url_fseek(bc, *pos_arg, SEEK_SET); | |
577 while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) { | |
578 if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && | |
579 ogg->streams[i].codec && i == stream_index) { | |
580 pts = ogg_gptopts(s, i, ogg->streams[i].granule); | |
581 // FIXME: this is the position of the packet after the one with above | |
582 // pts. | |
583 *pos_arg = url_ftell(bc); | |
584 break; | |
585 } | |
586 } | |
587 ogg_reset(ogg); | |
588 return pts; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
589 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
590 |
877 | 591 static int ogg_probe(AVProbeData *p) |
592 { | |
593 if (p->buf[0] == 'O' && p->buf[1] == 'g' && | |
594 p->buf[2] == 'g' && p->buf[3] == 'S' && | |
595 p->buf[4] == 0x0 && p->buf[5] <= 0x7 ) | |
596 return AVPROBE_SCORE_MAX; | |
597 else | |
598 return 0; | |
599 } | |
600 | |
1169 | 601 AVInputFormat ogg_demuxer = { |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
602 "ogg", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3023
diff
changeset
|
603 NULL_IF_CONFIG_SMALL("Ogg"), |
4016 | 604 sizeof (struct ogg), |
877 | 605 ogg_probe, |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
606 ogg_read_header, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
607 ogg_read_packet, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
608 ogg_read_close, |
2593
16aa09b0f20f
Remove ogg seek function, instead use generic seek via read_timestamp function
reimar
parents:
2592
diff
changeset
|
609 NULL, |
2592 | 610 ogg_read_timestamp, |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
611 .extensions = "ogg", |
5032
3aabdadf9d5f
Add a VorbisComment metadata conversion table and use it in the FLAC and
jbr
parents:
4876
diff
changeset
|
612 .metadata_conv = ff_vorbiscomment_metadata_conv, |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
613 }; |