2
Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
4
Permission is hereby granted, free of charge, to any person
5
obtaining a copy of this software and associated documentation
6
files (the "Software"), to deal in the Software without
7
restriction, including without limitation the rights to use, copy,
8
modify, merge, publish, distribute, sublicense, and/or sell copies
9
of the Software, and to permit persons to whom the Software is
10
furnished to do so, subject to the following conditions:
12
The above copyright notice and this permission notice shall be
13
included in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
27
#include "bitstream.h"
32
vorbis_comment (AVFormatContext * as, uint8_t *buf, int size)
40
s = le2me_32 (unaligned32 (p));
50
n = le2me_32 (unaligned32 (p));
58
s = le2me_32 (unaligned32 (p));
70
v = memchr (t, '=', s);
82
for (j = 0; j < tl; j++)
83
tt[j] = toupper (t[j]);
89
// took from Vorbis_I_spec
90
if (!strcmp (tt, "AUTHOR"))
91
strncpy (as->author, ct, FFMIN(sizeof (as->author), vl));
92
else if (!strcmp (tt, "TITLE"))
93
strncpy (as->title, ct, FFMIN(sizeof (as->title), vl));
94
else if (!strcmp (tt, "COPYRIGHT"))
95
strncpy (as->copyright, ct, FFMIN(sizeof (as->copyright), vl));
96
else if (!strcmp (tt, "DESCRIPTION"))
97
strncpy (as->comment, ct, FFMIN(sizeof (as->comment), vl));
98
else if (!strcmp (tt, "GENRE"))
99
strncpy (as->genre, ct, FFMIN(sizeof (as->genre), vl));
100
else if (!strcmp (tt, "TRACKNUMBER"))
101
as->track = atoi (ct);
102
//Too bored to add others for today
107
av_log (as, AV_LOG_INFO, "%i bytes of comment header remain\n", size);
109
av_log (as, AV_LOG_INFO,
110
"truncated comment header, %i comments not found\n", n);
116
/** Parse the vorbis header
117
* Vorbis Identification header from Vorbis_I_spec.html#vorbis-spec-codec
118
* [vorbis_version] = read 32 bits as unsigned integer | Not used
119
* [audio_channels] = read 8 bit integer as unsigned | Used
120
* [audio_sample_rate] = read 32 bits as unsigned integer | Used
121
* [bitrate_maximum] = read 32 bits as signed integer | Not used yet
122
* [bitrate_nominal] = read 32 bits as signed integer | Not used yet
123
* [bitrate_minimum] = read 32 bits as signed integer | Used as bitrate
124
* [blocksize_0] = read 4 bits as unsigned integer | Not Used
125
* [blocksize_1] = read 4 bits as unsigned integer | Not Used
126
* [framing_flag] = read one bit | Not Used
131
unsigned char *packet[3];
132
} oggvorbis_private_t;
136
fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
142
len = priv->len[0] + priv->len[1] + priv->len[2];
143
ptr = *buf = av_mallocz(len + len/255 + 64);
147
offset += av_xiphlacing(&ptr[offset], priv->len[0]);
148
offset += av_xiphlacing(&ptr[offset], priv->len[1]);
149
for(i = 0; i < 3; i++) {
150
memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
151
offset += priv->len[i];
153
*buf = av_realloc(*buf, offset);
159
vorbis_header (AVFormatContext * s, int idx)
161
ogg_t *ogg = s->priv_data;
162
ogg_stream_t *os = ogg->streams + idx;
163
AVStream *st = s->streams[idx];
164
oggvorbis_private_t *priv;
170
os->private = av_mallocz(sizeof(oggvorbis_private_t));
176
priv->len[os->seq] = os->psize;
177
priv->packet[os->seq] = av_mallocz(os->psize);
178
memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize);
179
if (os->buf[os->pstart] == 1) {
180
uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels
181
st->codec->channels = *p++;
182
st->codec->sample_rate = le2me_32 (unaligned32 (p));
183
p += 8; //skip maximum and and nominal bitrate
184
st->codec->bit_rate = le2me_32 (unaligned32 (p)); //Minimum bitrate
186
st->codec->codec_type = CODEC_TYPE_AUDIO;
187
st->codec->codec_id = CODEC_ID_VORBIS;
189
st->time_base.num = 1;
190
st->time_base.den = st->codec->sample_rate;
191
} else if (os->buf[os->pstart] == 3) {
192
vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
194
st->codec->extradata_size =
195
fixup_vorbis_headers(s, priv, &st->codec->extradata);
201
ogg_codec_t vorbis_codec = {
202
.magic = "\001vorbis",
204
.header = vorbis_header