annotate oggparsevorbis.c @ 726:17178af951b4 libavformat

Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>, fixups by me.
author mru
date Sat, 09 Apr 2005 15:32:58 +0000
parents
children 9372cd60d25d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
1 /**
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
2 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
3
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
4 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
5 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
6 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
7 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
8 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
9 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
10 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
11
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
12 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
13 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
14
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
15 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
16 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
17 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
18 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
19 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
20 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
21 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
22 DEALINGS IN THE SOFTWARE.
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
23 **/
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
24
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
25 #include <stdlib.h>
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
26 #include "avformat.h"
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
27 #include "bitstream.h"
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
28 #include "bswap.h"
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
29 #include "ogg2.h"
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 extern int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
32 vorbis_comment (AVFormatContext * as, char *buf, int size)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
33 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
34 char *p = buf;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
35 int s, n, j;
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 if (size < 4)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
38 return -1;
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 s = le2me_32 (unaligned32 (p));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
41 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
42 size -= 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
43
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
44 if (size < s + 4)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
45 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
46
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
47 p += s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
48 size -= s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
49
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
50 n = le2me_32 (unaligned32 (p));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
51 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
52 size -= 4;
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 while (size >= 4){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
55 char *t, *v;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
56 int tl, vl;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
57
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
58 s = le2me_32 (unaligned32 (p));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
59 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
60 size -= 4;
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 if (size < s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
63 break;
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 t = p;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
66 p += s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
67 size -= s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
68 n--;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
69
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
70 v = memchr (t, '=', s);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
71 if (!v)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
72 continue;
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 tl = v - t;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
75 vl = s - tl - 1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
76 v++;
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 if (tl && vl){
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
79 char tt[tl + 1];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
80 char ct[vl + 1];
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 for (j = 0; j < tl; j++)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
83 tt[j] = toupper (t[j]);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
84 tt[tl] = 0;
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 memcpy (ct, v, vl);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
87 ct[vl] = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
88
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
89 // took from Vorbis_I_spec
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
90 if (!strcmp (tt, "AUTHOR"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
91 strncpy (as->author, ct, FFMIN(sizeof (as->author), vl));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
92 else if (!strcmp (tt, "TITLE"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
93 strncpy (as->title, ct, FFMIN(sizeof (as->title), vl));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
94 else if (!strcmp (tt, "COPYRIGHT"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
95 strncpy (as->copyright, ct, FFMIN(sizeof (as->copyright), vl));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
96 else if (!strcmp (tt, "DESCRIPTION"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
97 strncpy (as->comment, ct, FFMIN(sizeof (as->comment), vl));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
98 else if (!strcmp (tt, "GENRE"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
99 strncpy (as->genre, ct, FFMIN(sizeof (as->genre), vl));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
100 else if (!strcmp (tt, "TRACKNUMBER"))
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
101 as->track = atoi (ct);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
102 //Too bored to add others for today
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
103 }
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
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
106 if (size > 0)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
107 av_log (as, AV_LOG_INFO, "%i bytes of comment header remain\n", size);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
108 if (n > 0)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
109 av_log (as, AV_LOG_INFO,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
110 "truncated comment header, %i comments not found\n", n);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
111
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
112 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
113 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
114
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
115
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
116 /** Parse the vorbis header
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
117 * Vorbis Identification header from Vorbis_I_spec.html#vorbis-spec-codec
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
118 * [vorbis_version] = read 32 bits as unsigned integer | Not used
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
119 * [audio_channels] = read 8 bit integer as unsigned | Used
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
120 * [audio_sample_rate] = read 32 bits as unsigned integer | Used
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
121 * [bitrate_maximum] = read 32 bits as signed integer | Not used yet
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
122 * [bitrate_nominal] = read 32 bits as signed integer | Not used yet
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
123 * [bitrate_minimum] = read 32 bits as signed integer | Used as bitrate
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
124 * [blocksize_0] = read 4 bits as unsigned integer | Not Used
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
125 * [blocksize_1] = read 4 bits as unsigned integer | Not Used
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
126 * [framing_flag] = read one bit | Not Used
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
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
129 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
130 vorbis_header (AVFormatContext * s, int idx)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
131 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
132 ogg_t *ogg = s->priv_data;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
133 ogg_stream_t *os = ogg->streams + idx;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
134 AVStream *st = s->streams[idx];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
135 int cds = st->codec.extradata_size + os->psize + 2;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
136 u_char *cdp;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
137
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
138 if (os->seq > 2)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
139 return 0;
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 st->codec.extradata = av_realloc (st->codec.extradata, cds);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
142 cdp = st->codec.extradata + st->codec.extradata_size;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
143 *cdp++ = os->psize >> 8;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
144 *cdp++ = os->psize & 0xff;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
145 memcpy (cdp, os->buf + os->pstart, os->psize);
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
146 st->codec.extradata_size = cds;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
147
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
148 if (os->buf[os->pstart] == 1) {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
149 u_char *p = os->buf + os->pstart + 11; //skip up to the audio channels
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
150 st->codec.channels = *p++;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
151 st->codec.sample_rate = le2me_32 (unaligned32 (p));
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
152 p += 8; //skip maximum and and nominal bitrate
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
153 st->codec.bit_rate = le2me_32 (unaligned32 (p)); //Minimum bitrate
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 st->codec.codec_type = CODEC_TYPE_AUDIO;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
156 st->codec.codec_id = CODEC_ID_VORBIS;
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 } else if (os->buf[os->pstart] == 3) {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
159 vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
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
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
162 return os->seq < 3;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
163 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
164
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
165 ogg_codec_t vorbis_codec = {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
166 .magic = "\001vorbis",
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
167 .magicsize = 7,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
168 .header = vorbis_header
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
169 };