annotate oggparsevorbis.c @ 2279:3c02e08e7b5a libavformat

use the most appropriate codec id for A_MPEG/L1 and L2
author aurel
date Wed, 25 Jul 2007 15:59:26 +0000
parents 7c13baaa4f87
children a7755990bb9c
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"
2194
b1a13cba29f8 replace strncpy with av_strlcpy
mru
parents: 1332
diff changeset
30 #include "avstring.h"
726
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 extern int
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
33 vorbis_comment(AVFormatContext * as, 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
34 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
35 char *p = buf;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
36 int s, n, j;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
37
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
38 if (size < 4)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
39 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
40
2196
5864dc9a9741 use AV_RL32
mru
parents: 2195
diff changeset
41 s = AV_RL32(p);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
42 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
43 size -= 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
44
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
45 if (size < s + 4)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
46 return -1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
47
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
48 p += s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
49 size -= s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
50
2196
5864dc9a9741 use AV_RL32
mru
parents: 2195
diff changeset
51 n = AV_RL32(p);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
52 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
53 size -= 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
54
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
55 while (size >= 4) {
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
56 char *t, *v;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
57 int tl, vl;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
58
2196
5864dc9a9741 use AV_RL32
mru
parents: 2195
diff changeset
59 s = AV_RL32(p);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
60 p += 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
61 size -= 4;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
62
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
63 if (size < s)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
64 break;
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 t = p;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
67 p += s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
68 size -= s;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
69 n--;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
70
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
71 v = memchr(t, '=', s);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
72 if (!v)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
73 continue;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
74
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
75 tl = v - t;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
76 vl = s - tl - 1;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
77 v++;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
78
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
79 if (tl && vl) {
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
80 char tt[tl + 1];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
81 char ct[vl + 1];
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
82
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
83 for (j = 0; j < tl; j++)
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
84 tt[j] = toupper(t[j]);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
85 tt[tl] = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
86
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
87 memcpy(ct, v, vl);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
88 ct[vl] = 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
89
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
90 // took from Vorbis_I_spec
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
91 if (!strcmp(tt, "AUTHOR") || !strcmp(tt, "ARTIST"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
92 av_strlcpy(as->author, ct, sizeof(as->author));
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
93 else if (!strcmp(tt, "TITLE"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
94 av_strlcpy(as->title, ct, sizeof(as->title));
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
95 else if (!strcmp(tt, "COPYRIGHT"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
96 av_strlcpy(as->copyright, ct, sizeof(as->copyright));
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
97 else if (!strcmp(tt, "DESCRIPTION"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
98 av_strlcpy(as->comment, ct, sizeof(as->comment));
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
99 else if (!strcmp(tt, "GENRE"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
100 av_strlcpy(as->genre, ct, sizeof(as->genre));
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
101 else if (!strcmp(tt, "TRACKNUMBER"))
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
102 as->track = atoi(ct);
2195
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
103 else if (!strcmp(tt, "ALBUM"))
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
104 av_strlcpy(as->album, ct, sizeof(as->album));
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
105 else if (!strcmp(tt, "GENRE"))
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
106 av_strlcpy(as->genre, ct, sizeof(as->genre));
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
107 else if (!strcmp(tt, "DESCRIPTION"))
ab9e3ecd5583 use more Vorbis metadata tags
mru
parents: 2194
diff changeset
108 av_strlcpy(as->comment, ct, sizeof(as->comment));
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
109 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
110 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
111
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
112 if (size > 0)
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
113 av_log(as, AV_LOG_INFO, "%i bytes of comment header remain\n", size);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
114 if (n > 0)
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
115 av_log(as, AV_LOG_INFO,
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
116 "truncated comment header, %i comments not found\n", n);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
117
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
118 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
119 }
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
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
122 /** Parse the vorbis header
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
123 * 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
124 * [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
125 * [audio_channels] = read 8 bit integer as unsigned | Used
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
126 * [audio_sample_rate] = read 32 bits as unsigned integer | Used
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
127 * [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
128 * [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
129 * [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
130 * [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
131 * [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
132 * [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
133 * */
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
134
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
135 typedef struct {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
136 unsigned int len[3];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
137 unsigned char *packet[3];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
138 } oggvorbis_private_t;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
139
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
140
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
141 static unsigned int
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
142 fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
2198
7c13baaa4f87 warnings--
mru
parents: 2197
diff changeset
143 uint8_t **buf)
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
144 {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
145 int i,offset, len;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
146 unsigned char *ptr;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
147
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
148 len = priv->len[0] + priv->len[1] + priv->len[2];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
149 ptr = *buf = av_mallocz(len + len/255 + 64);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
150
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
151 ptr[0] = 2;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
152 offset = 1;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
153 offset += av_xiphlacing(&ptr[offset], priv->len[0]);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
154 offset += av_xiphlacing(&ptr[offset], priv->len[1]);
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
155 for (i = 0; i < 3; i++) {
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
156 memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
157 offset += priv->len[i];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
158 }
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
159 *buf = av_realloc(*buf, offset);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
160 return offset;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
161 }
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
162
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
163
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
164 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
165 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
166 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
167 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
168 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
169 AVStream *st = s->streams[idx];
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
170 oggvorbis_private_t *priv;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
171
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
172 if (os->seq > 2)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
173 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
174
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
175 if (os->seq == 0) {
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
176 os->private = av_mallocz(sizeof(oggvorbis_private_t));
2197
94d11eaef9bf whitespace cosmetics
mru
parents: 2196
diff changeset
177 if (!os->private)
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
178 return 0;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
179 }
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
180
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
181 priv = os->private;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
182 priv->len[os->seq] = os->psize;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
183 priv->packet[os->seq] = av_mallocz(os->psize);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
184 memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
185 if (os->buf[os->pstart] == 1) {
729
9372cd60d25d s/u_char/uint8_t/
mru
parents: 726
diff changeset
186 uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
187 st->codec->channels = *p++;
2196
5864dc9a9741 use AV_RL32
mru
parents: 2195
diff changeset
188 st->codec->sample_rate = AV_RL32(p);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
189 p += 8; //skip maximum and and nominal bitrate
2196
5864dc9a9741 use AV_RL32
mru
parents: 2195
diff changeset
190 st->codec->bit_rate = AV_RL32(p); //Minimum bitrate
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
191
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
192 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
193 st->codec->codec_id = CODEC_ID_VORBIS;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
194
1077
91677ac6fb19 set stream time_base properly
mru
parents: 885
diff changeset
195 st->time_base.num = 1;
91677ac6fb19 set stream time_base properly
mru
parents: 885
diff changeset
196 st->time_base.den = st->codec->sample_rate;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
197 } 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
198 vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
199 } else {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
200 st->codec->extradata_size =
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
201 fixup_vorbis_headers(s, priv, &st->codec->extradata);
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
202 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
203
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
204 return os->seq < 3;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
205 }
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 ogg_codec_t vorbis_codec = {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
208 .magic = "\001vorbis",
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
209 .magicsize = 7,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
210 .header = vorbis_header
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
211 };