annotate oggparsevorbis.c @ 999:76287fba65ff libavformat

set track timescale to mov timescale if 0 patch by (Baptiste COUDURIER <baptiste.coudurier smartjog com)
author michael
date Mon, 06 Mar 2006 22:15:43 +0000
parents da1d5db0ce5c
children 91677ac6fb19
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
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
89 // took from Vorbis_I_spec
726
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
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 820
diff changeset
120 * [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
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
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
129 typedef struct {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
130 unsigned int len[3];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
131 unsigned char *packet[3];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
132 } oggvorbis_private_t;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
133
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
134
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
135 static unsigned int
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
136 fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv,
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
137 void **buf)
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
138 {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
139 int i,offset, len;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
140 unsigned char *ptr;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
141
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
142 len = priv->len[0] + priv->len[1] + priv->len[2];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
143 ptr = *buf = av_mallocz(len + len/255 + 64);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
144
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
145 ptr[0] = 2;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
146 offset = 1;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
147 offset += av_xiphlacing(&ptr[offset], priv->len[0]);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
148 offset += av_xiphlacing(&ptr[offset], priv->len[1]);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
149 for(i = 0; i < 3; i++) {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
150 memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
151 offset += priv->len[i];
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
152 }
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
153 *buf = av_realloc(*buf, offset);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
154 return offset;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
155 }
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
156
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
157
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
158 static int
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
159 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
160 {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
161 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
162 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
163 AVStream *st = s->streams[idx];
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
164 oggvorbis_private_t *priv;
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
165
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
166 if (os->seq > 2)
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
167 return 0;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
168
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
169 if(os->seq == 0) {
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
170 os->private = av_mallocz(sizeof(oggvorbis_private_t));
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
171 if(!os->private)
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
172 return 0;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
173 }
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
174
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
175 priv = os->private;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
176 priv->len[os->seq] = os->psize;
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
177 priv->packet[os->seq] = av_mallocz(os->psize);
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
178 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
179 if (os->buf[os->pstart] == 1) {
729
9372cd60d25d s/u_char/uint8_t/
mru
parents: 726
diff changeset
180 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
181 st->codec->channels = *p++;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
182 st->codec->sample_rate = le2me_32 (unaligned32 (p));
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
183 p += 8; //skip maximum and and nominal bitrate
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
184 st->codec->bit_rate = le2me_32 (unaligned32 (p)); //Minimum bitrate
726
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
185
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 760
diff changeset
186 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
187 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
188
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
189 } 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
190 vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8);
760
c72bba158baa change extradata format for vorbis
mru
parents: 729
diff changeset
191 } 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
192 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
193 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
194 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
195
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
196 return os->seq < 3;
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
197 }
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
198
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
199 ogg_codec_t vorbis_codec = {
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
200 .magic = "\001vorbis",
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
201 .magicsize = 7,
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
202 .header = vorbis_header
17178af951b4 Ogg demuxer ported from tcvp by Luca Barbato <lu_zero at gentoo dot org>,
mru
parents:
diff changeset
203 };