Mercurial > libavformat.hg
annotate ogg2.c @ 1737:8d3489fa8a92 libavformat
use more portable PRIu64
author | gpoirier |
---|---|
date | Thu, 25 Jan 2007 10:01:28 +0000 |
parents | 2400a22af998 |
children | 6dd0da50623a |
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> |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
34 #include "ogg2.h" |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
40 static ogg_codec_t *ogg_codecs[] = { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
41 &vorbis_codec, |
755 | 42 &theora_codec, |
756 | 43 &flac_codec, |
1076 | 44 &ogm_video_codec, |
45 &ogm_audio_codec, | |
46 &ogm_old_codec, | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
47 NULL |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
48 }; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
49 |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
820
diff
changeset
|
50 #if 0 // CONFIG_MUXERS |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
51 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
52 ogg_write_header (AVFormatContext * avfcontext) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
53 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
54 } |
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 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
57 ogg_write_packet (AVFormatContext * avfcontext, AVPacket * pkt) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
58 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
59 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
60 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
61 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
62 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
63 ogg_write_trailer (AVFormatContext * avfcontext) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
64 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
65 } |
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 |
1169 | 68 AVOutputFormat ogg_muxer = { |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
69 "ogg", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
70 "Ogg Vorbis", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
71 "audio/x-vorbis", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
72 "ogg", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
73 sizeof (OggContext), |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
74 CODEC_ID_VORBIS, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
75 0, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
76 ogg_write_header, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
77 ogg_write_packet, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
78 ogg_write_trailer, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
79 }; |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
820
diff
changeset
|
80 #endif //CONFIG_MUXERS |
726
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 //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
|
83 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
84 ogg_save (AVFormatContext * s) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
85 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
86 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
87 ogg_state_t *ost = |
727 | 88 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
|
89 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
90 ost->pos = url_ftell (&s->pb);; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
91 ost->curidx = ogg->curidx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
92 ost->next = ogg->state; |
1657 | 93 ost->nstreams = ogg->nstreams; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
94 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
|
95 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
96 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
|
97 ogg_stream_t *os = ogg->streams + i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
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 ogg->state = 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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
109 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
|
110 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
111 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
112 ByteIOContext *bc = &s->pb; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
113 ogg_state_t *ost = ogg->state; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
114 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
115 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
116 if (!ost) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
117 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
118 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
119 ogg->state = ost->next; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
120 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
121 if (!discard){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
122 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
|
123 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
|
124 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
125 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
|
126 ogg->curidx = ost->curidx; |
1657 | 127 ogg->nstreams = ost->nstreams; |
128 memcpy(ogg->streams, ost->streams, | |
129 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
|
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 av_free (ost); |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
137 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
138 ogg_reset (ogg_t * ogg) |
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; i < ogg->nstreams; i++){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
143 ogg_stream_t *os = ogg->streams + i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
144 os->bufpos = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
145 os->pstart = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
146 os->psize = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
147 os->granule = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
148 os->lastgp = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
149 os->nsegs = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
150 os->segp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
151 } |
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 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
154 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
155 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
158 static ogg_codec_t * |
728 | 159 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
|
160 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
161 int i; |
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 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
|
164 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
|
165 !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
|
166 return ogg_codecs[i]; |
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 return NULL; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
169 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
170 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
171 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
172 ogg_find_stream (ogg_t * ogg, int serial) |
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 int i; |
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 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
|
177 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
|
178 return i; |
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 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
181 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
182 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
183 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
184 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
|
185 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
186 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
187 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
188 int idx = ogg->nstreams++; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
189 AVStream *st; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
190 ogg_stream_t *os; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
191 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
192 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
|
193 ogg->nstreams * sizeof (*ogg->streams)); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
194 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
|
195 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
196 os->serial = serial; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
197 os->bufsize = DECODER_BUFFER_SIZE; |
1133 | 198 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
|
199 os->header = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
200 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
201 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
|
202 if (!st) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
203 return AVERROR_NOMEM; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
204 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
205 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
|
206 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
207 return idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
208 } |
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 static int |
1132 | 211 ogg_new_buf(ogg_t *ogg, int idx) |
212 { | |
213 ogg_stream_t *os = ogg->streams + idx; | |
1134 | 214 uint8_t *nb = av_malloc(os->bufsize); |
1132 | 215 int size = os->bufpos - os->pstart; |
216 if(os->buf){ | |
217 memcpy(nb, os->buf + os->pstart, size); | |
218 av_free(os->buf); | |
219 } | |
220 os->buf = nb; | |
221 os->bufpos = size; | |
222 os->pstart = 0; | |
223 | |
224 return 0; | |
225 } | |
226 | |
227 static int | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
228 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
|
229 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
230 ByteIOContext *bc = &s->pb; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
231 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
232 ogg_stream_t *os; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
233 int i = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
234 int flags, nsegs; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
235 uint64_t gp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
236 uint32_t serial; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
237 uint32_t seq; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
238 uint32_t crc; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
239 int size, idx; |
1332 | 240 uint8_t sync[4]; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
241 int sp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
242 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
243 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
|
244 return -1; |
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 do{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
247 int c; |
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 if (sync[sp & 3] == 'O' && |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
250 sync[(sp + 1) & 3] == 'g' && |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
251 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
|
252 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
253 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
254 c = url_fgetc (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
255 if (c < 0) |
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 sync[sp++ & 3] = c; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
258 }while (i++ < MAX_PAGE_SIZE); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
259 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
260 if (i >= MAX_PAGE_SIZE){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
261 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
|
262 return -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
265 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
|
266 return -1; |
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 flags = url_fgetc (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
269 gp = get_le64 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
270 serial = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
271 seq = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
272 crc = get_le32 (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
273 nsegs = url_fgetc (bc); |
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 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
|
276 if (idx < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
277 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
|
278 if (idx < 0) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
279 return -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
282 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
283 |
1133 | 284 if(os->psize > 0) |
1132 | 285 ogg_new_buf(ogg, idx); |
286 | |
726
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->segments, nsegs) < nsegs) |
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->nsegs = nsegs; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
291 os->segp = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
292 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
293 size = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
294 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
|
295 size += os->segments[i]; |
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 if (flags & OGG_FLAG_CONT){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
298 if (!os->psize){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
299 while (os->segp < os->nsegs){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
300 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
|
301 os->pstart += seg; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
302 if (seg < 255) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
303 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
304 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
305 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
306 }else{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
307 os->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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
310 if (os->bufsize - os->bufpos < size){ |
728 | 311 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
|
312 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
|
313 av_free (os->buf); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
314 os->buf = nb; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
317 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
|
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 os->lastgp = os->granule; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
321 os->bufpos += size; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
322 os->granule = gp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
323 os->flags = flags; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
324 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
325 if (str) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
326 *str = idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
327 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
328 return 0; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
331 static int |
1132 | 332 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
|
333 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
334 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
335 int idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
336 ogg_stream_t *os; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
337 int complete = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
338 int segp = 0, psize = 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 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
341 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
|
342 #endif |
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 do{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
345 idx = ogg->curidx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
346 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
347 while (idx < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
348 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
|
349 return -1; |
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 os = ogg->streams + idx; |
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 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
355 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
|
356 "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
|
357 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
|
358 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
359 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
360 if (!os->codec){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
361 if (os->header < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
362 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
|
363 if (!os->codec){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
364 os->header = 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
365 return 0; |
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 }else{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
368 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
369 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
370 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
371 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
372 segp = os->segp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
373 psize = os->psize; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
374 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
375 while (os->segp < os->nsegs){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
376 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
|
377 os->psize += ss; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
378 if (ss < 255){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
379 complete = 1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
380 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
381 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
382 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
383 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
384 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
|
385 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
386 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
387 }while (!complete); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
388 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
389 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
390 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
|
391 "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
|
392 idx, os->psize, os->pstart); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
393 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
394 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
395 ogg->curidx = idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
396 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
397 if (os->header < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
398 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
|
399 if (!hdr){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
400 os->header = os->seq; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
401 os->segp = segp; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
402 os->psize = psize; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
403 ogg->headers = 1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
404 }else{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
405 os->pstart += os->psize; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
406 os->psize = 0; |
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 } |
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 if (os->header > -1 && os->seq > os->header){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
411 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
|
412 os->codec->packet (s, idx); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
413 if (str) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
414 *str = idx; |
1132 | 415 if (dstart) |
416 *dstart = os->pstart; | |
417 if (dsize) | |
418 *dsize = os->psize; | |
419 os->pstart += os->psize; | |
420 os->psize = 0; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
421 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
422 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
423 os->seq++; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
424 if (os->segp == os->nsegs) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
425 ogg->curidx = -1; |
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 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
428 } |
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 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
431 ogg_get_headers (AVFormatContext * s) |
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 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
434 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
435 do{ |
1132 | 436 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
|
437 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
438 }while (!ogg->headers); |
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 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
441 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
|
442 #endif |
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 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
445 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
446 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
447 static uint64_t |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
448 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
|
449 { |
755 | 450 ogg_t *ogg = s->priv_data; |
451 ogg_stream_t *os = ogg->streams + i; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
452 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
|
453 |
755 | 454 if(os->codec->gptopts){ |
887 | 455 pts = os->codec->gptopts(s, i, gp); |
1077 | 456 } else { |
755 | 457 pts = gp; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
458 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
459 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
460 return pts; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
461 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
462 |
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 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
465 ogg_get_length (AVFormatContext * s) |
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 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
468 int idx = -1, i; |
1104 | 469 offset_t size, end; |
766 | 470 |
471 if(s->pb.is_streamed) | |
472 return 0; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
473 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
474 // already set |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
475 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
|
476 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
477 |
1104 | 478 size = url_fsize(&s->pb); |
479 if(size < 0) | |
480 return 0; | |
481 end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size; | |
482 | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
483 ogg_save (s); |
1104 | 484 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
|
485 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
486 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
|
487 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
|
488 ogg->streams[i].codec) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
489 idx = i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
490 } |
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 if (idx != -1){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
493 s->streams[idx]->duration = |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
494 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
|
495 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
496 |
1104 | 497 ogg->size = size; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
498 ogg_restore (s, 0); |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
499 ogg_save (s); |
1397
21755fe31dd7
10l inverted condition check generated an endless loop
aurel
parents:
1379
diff
changeset
|
500 while (!ogg_read_page (s, &i)) { |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
501 if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
502 break; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
503 } |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
504 if (i == idx) { |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
505 s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule); |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
506 s->streams[idx]->duration -= s->streams[idx]->start_time; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
507 } |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
508 ogg_restore (s, 0); |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
509 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
510 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
511 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
512 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
513 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
514 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
515 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
|
516 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
517 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
518 ogg->curidx = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
519 //linear headers seek from start |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
520 if (ogg_get_headers (s) < 0){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
521 return -1; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
524 //linear granulepos seek from end |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
525 ogg_get_length (s); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
526 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
527 //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
|
528 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
529 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
530 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
531 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
532 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
533 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
|
534 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
535 ogg_t *ogg; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
536 ogg_stream_t *os; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
537 int idx = -1; |
1132 | 538 int pstart, psize; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
539 |
885 | 540 //Get an ogg packet |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
541 do{ |
1132 | 542 if (ogg_packet (s, &idx, &pstart, &psize) < 0) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
543 return AVERROR_IO; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
544 }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
|
545 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
546 ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
547 os = ogg->streams + idx; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
548 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
549 //Alloc a pkt |
1132 | 550 if (av_new_packet (pkt, psize) < 0) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
551 return AVERROR_IO; |
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 | 553 memcpy (pkt->data, os->buf + pstart, psize); |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
554 if (os->lastgp != -1LL){ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
555 pkt->pts = ogg_gptopts (s, idx, os->lastgp); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
556 os->lastgp = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
557 } |
1132 | 558 |
559 return psize; | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
560 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
561 |
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 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
564 ogg_read_close (AVFormatContext * s) |
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 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
567 int i; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
568 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
569 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
|
570 av_free (ogg->streams[i].buf); |
755 | 571 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
|
572 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
573 av_free (ogg->streams); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
574 return 0; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
575 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
576 |
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 static int |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
579 ogg_read_seek (AVFormatContext * s, int stream_index, int64_t target_ts, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
580 int flags) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
581 { |
1104 | 582 AVStream *st = s->streams[stream_index]; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
583 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
584 ByteIOContext *bc = &s->pb; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
585 uint64_t min = 0, max = ogg->size; |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
586 uint64_t tmin = st->start_time, tmax = st->start_time + st->duration; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
587 int64_t pts = AV_NOPTS_VALUE; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
588 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
589 ogg_save (s); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
590 |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
591 if ((uint64_t)target_ts < tmin || target_ts < 0) |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
592 target_ts = tmin; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
593 while (min <= max && tmin < tmax){ |
730 | 594 uint64_t p = min + (max - min) * (target_ts - tmin) / (tmax - tmin); |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
595 int i = -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
596 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
597 url_fseek (bc, p, SEEK_SET); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
598 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
599 while (!ogg_read_page (s, &i)){ |
1104 | 600 if (i == stream_index && ogg->streams[i].granule != 0 && |
601 ogg->streams[i].granule != -1) | |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
602 break; |
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 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
605 if (i == -1) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
606 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
607 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
608 pts = ogg_gptopts (s, i, ogg->streams[i].granule); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
609 p = url_ftell (bc); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
610 |
1379 | 611 if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den) |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
612 break; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
613 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
614 if (pts > target_ts){ |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
615 if (max == p && tmax == pts) { |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
616 // probably our tmin is wrong, causing us to always end up too late in the file |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
617 tmin = (target_ts + tmin + 1) / 2; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
618 if (tmin == target_ts) { |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
619 url_fseek(bc, min, SEEK_SET); |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
620 break; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
621 } |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
622 } |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
623 max = p; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
624 tmax = pts; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
625 }else{ |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
626 if (min == p && tmin == pts) { |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
627 // probably our tmax is wrong, causing us to always end up too early in the file |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
628 tmax = (target_ts + tmax) / 2; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
629 if (tmax == target_ts) { |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
630 url_fseek(bc, max, SEEK_SET); |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
631 break; |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
632 } |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
633 } |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
634 min = p; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
635 tmin = pts; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
636 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
637 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
638 |
1379 | 639 if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den){ |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
640 ogg_restore (s, 1); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
641 ogg_reset (ogg); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
642 }else{ |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
643 ogg_restore (s, 0); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
644 pts = AV_NOPTS_VALUE; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
645 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
646 |
1185
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
647 av_update_cur_dts(s, st, pts); |
13dc486b272b
Try to find out correct start time to make seeking faster and add some
reimar
parents:
1169
diff
changeset
|
648 return 0; |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
649 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
650 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
651 //later... |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
652 int64_t pos; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
653 if (av_seek_frame_binary (s, stream_index, target_ts, flags) < 0) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
654 return -1; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
655 pos = url_ftell (&s->pb); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
656 ogg_read_timestamp (s, stream_index, &pos, pos - 1); |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
657 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
658 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
659 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
660 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
661 #if 0 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
662 static int64_t |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
663 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
|
664 int64_t pos_limit) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
665 { |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
666 ogg_t *ogg = s->priv_data; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
667 ByteIOContext *bc = &s->pb; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
668 int64_t pos, pts; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
669 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
670 if (*pos_arg < 0) |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
671 return AV_NOPTS_VALUE; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
672 |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
673 pos = *pos_arg; |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
674 } |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
675 #endif |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
676 |
877 | 677 static int ogg_probe(AVProbeData *p) |
678 { | |
679 if (p->buf_size < 6) | |
680 return 0; | |
681 if (p->buf[0] == 'O' && p->buf[1] == 'g' && | |
682 p->buf[2] == 'g' && p->buf[3] == 'S' && | |
683 p->buf[4] == 0x0 && p->buf[5] <= 0x7 ) | |
684 return AVPROBE_SCORE_MAX; | |
685 else | |
686 return 0; | |
687 } | |
688 | |
1169 | 689 AVInputFormat ogg_demuxer = { |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
690 "ogg", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
691 "Ogg", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
692 sizeof (ogg_t), |
877 | 693 ogg_probe, |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
694 ogg_read_header, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
695 ogg_read_packet, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
696 ogg_read_close, |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
697 ogg_read_seek, |
885 | 698 // ogg_read_timestamp, |
726
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
699 .extensions = "ogg", |
17178af951b4
Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff
changeset
|
700 }; |