annotate tremor/framing.c @ 20338:e5902385e9e1

r20318: capitalization fixes, add missing dots to sentences r20321: --enable-faad-external and --enable-libmaad fixes r20328: some random fixes (rewording, spelling,...) r20341: Remove obsolete parts, some updates.
author voroshil
date Sat, 21 Oct 2006 21:36:31 +0000
parents 052b4ad84883
children e83eef58b30a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
1 /********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
2 * *
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
7 * *
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
8 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
9 * by the Xiph.Org Foundation http://www.xiph.org/ *
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
10 * *
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
11 ********************************************************************
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
12
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
13 function: code raw [Vorbis] packets into framed OggSquish stream and
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
14 decode Ogg streams back into raw packets
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
15 last mod: $Id$
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
16
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
17 note: The CRC code is directly derived from public domain code by
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
18 Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
19 for details.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
20
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
21 ********************************************************************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
22
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
23 #include <stdlib.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
24 #include <string.h>
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
25 #include "ogg.h"
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
26
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
27 /* A complete description of Ogg framing exists in docs/framing.html */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
28
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
29 int ogg_page_version(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
30 return((int)(og->header[4]));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
31 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
32
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
33 int ogg_page_continued(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
34 return((int)(og->header[5]&0x01));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
35 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
36
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
37 int ogg_page_bos(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
38 return((int)(og->header[5]&0x02));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
39 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
40
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
41 int ogg_page_eos(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
42 return((int)(og->header[5]&0x04));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
43 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
44
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
45 ogg_int64_t ogg_page_granulepos(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
46 unsigned char *page=og->header;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
47 ogg_int64_t granulepos=page[13]&(0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
48 granulepos= (granulepos<<8)|(page[12]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
49 granulepos= (granulepos<<8)|(page[11]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
50 granulepos= (granulepos<<8)|(page[10]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
51 granulepos= (granulepos<<8)|(page[9]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
52 granulepos= (granulepos<<8)|(page[8]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
53 granulepos= (granulepos<<8)|(page[7]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
54 granulepos= (granulepos<<8)|(page[6]&0xff);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
55 return(granulepos);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
56 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
57
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
58 int ogg_page_serialno(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
59 return(og->header[14] |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
60 (og->header[15]<<8) |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
61 (og->header[16]<<16) |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
62 (og->header[17]<<24));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
63 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
64
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
65 long ogg_page_pageno(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
66 return(og->header[18] |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
67 (og->header[19]<<8) |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
68 (og->header[20]<<16) |
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
69 (og->header[21]<<24));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
70 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
71
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
72
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
73
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
74 /* returns the number of packets that are completed on this page (if
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
75 the leading packet is begun on a previous page, but ends on this
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
76 page, it's counted */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
77
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
78 /* NOTE:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
79 If a page consists of a packet begun on a previous page, and a new
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
80 packet begun (but not completed) on this page, the return will be:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
81 ogg_page_packets(page) ==1,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
82 ogg_page_continued(page) !=0
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
83
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
84 If a page happens to be a single packet that was begun on a
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
85 previous page, and spans to the next page (in the case of a three or
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
86 more page packet), the return will be:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
87 ogg_page_packets(page) ==0,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
88 ogg_page_continued(page) !=0
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
89 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
90
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
91 int ogg_page_packets(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
92 int i,n=og->header[26],count=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
93 for(i=0;i<n;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
94 if(og->header[27+i]<255)count++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
95 return(count);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
96 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
97
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
98
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
99 #if 0
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
100 /* helper to initialize lookup for direct-table CRC (illustrative; we
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
101 use the static init below) */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
102
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
103 static ogg_uint32_t _ogg_crc_entry(unsigned long index){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
104 int i;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
105 unsigned long r;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
106
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
107 r = index << 24;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
108 for (i=0; i<8; i++)
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
109 if (r & 0x80000000UL)
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
110 r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
111 polynomial, although we use an
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
112 unreflected alg and an init/final
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
113 of 0, not 0xffffffff */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
114 else
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
115 r<<=1;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
116 return (r & 0xffffffffUL);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
117 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
118 #endif
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
119
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
120 static const ogg_uint32_t crc_lookup[256]={
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
121 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
122 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
123 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
124 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
125 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
126 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
127 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
128 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
129 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
130 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
131 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
132 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
133 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
134 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
135 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
136 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
137 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
138 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
139 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
140 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
141 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
142 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
143 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
144 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
145 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
146 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
147 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
148 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
149 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
150 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
151 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
152 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
153 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
154 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
155 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
156 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
157 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
158 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
159 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
160 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
161 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
162 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
163 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
164 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
165 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
166 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
167 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
168 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
169 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
170 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
171 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
172 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
173 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
174 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
175 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
176 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
177 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
178 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
179 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
180 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
181 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
182 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
183 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
184 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
185
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
186 /* init the encode/decode logical stream state */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
187
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
188 int ogg_stream_init(ogg_stream_state *os,int serialno){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
189 if(os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
190 memset(os,0,sizeof(*os));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
191 os->body_storage=16*1024;
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
192 os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
193
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
194 os->lacing_storage=1024;
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
195 os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
196 os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
197
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
198 os->serialno=serialno;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
199
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
200 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
201 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
202 return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
203 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
204
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
205 /* _clear does not free os, only the non-flat storage within */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
206 int ogg_stream_clear(ogg_stream_state *os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
207 if(os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
208 if(os->body_data)_ogg_free(os->body_data);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
209 if(os->lacing_vals)_ogg_free(os->lacing_vals);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
210 if(os->granule_vals)_ogg_free(os->granule_vals);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
211
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
212 memset(os,0,sizeof(*os));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
213 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
214 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
215 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
216
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
217 int ogg_stream_destroy(ogg_stream_state *os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
218 if(os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
219 ogg_stream_clear(os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
220 _ogg_free(os);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
221 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
222 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
223 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
224
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
225 /* Helpers for ogg_stream_encode; this keeps the structure and
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
226 what's happening fairly clear */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
227
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
228 static void _os_body_expand(ogg_stream_state *os,int needed){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
229 if(os->body_storage<=os->body_fill+needed){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
230 os->body_storage+=(needed+1024);
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
231 os->body_data=_ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
232 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
233 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
234
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
235 static void _os_lacing_expand(ogg_stream_state *os,int needed){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
236 if(os->lacing_storage<=os->lacing_fill+needed){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
237 os->lacing_storage+=(needed+32);
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
238 os->lacing_vals=_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
239 os->granule_vals=_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
240 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
241 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
242
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
243 /* checksum the page */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
244 /* Direct table CRC; note that this will be faster in the future if we
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
245 perform the checksum silmultaneously with other copies */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
246
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
247 void ogg_page_checksum_set(ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
248 if(og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
249 ogg_uint32_t crc_reg=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
250 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
251
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
252 /* safety; needed for API behavior, but not framing code */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
253 og->header[22]=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
254 og->header[23]=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
255 og->header[24]=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
256 og->header[25]=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
257
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
258 for(i=0;i<og->header_len;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
259 crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
260 for(i=0;i<og->body_len;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
261 crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
262
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
263 og->header[22]=(unsigned char)(crc_reg&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
264 og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
265 og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
266 og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
267 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
268 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
269
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
270 /* submit data to the internal buffer of the framing engine */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
271 int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
272 int lacing_vals=op->bytes/255+1,i;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
273
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
274 if(os->body_returned){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
275 /* advance packet data according to the body_returned pointer. We
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
276 had to keep it around to return a pointer into the buffer last
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
277 call */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
278
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
279 os->body_fill-=os->body_returned;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
280 if(os->body_fill)
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
281 memmove(os->body_data,os->body_data+os->body_returned,
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
282 os->body_fill);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
283 os->body_returned=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
284 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
285
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
286 /* make sure we have the buffer storage */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
287 _os_body_expand(os,op->bytes);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
288 _os_lacing_expand(os,lacing_vals);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
289
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
290 /* Copy in the submitted packet. Yes, the copy is a waste; this is
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
291 the liability of overly clean abstraction for the time being. It
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
292 will actually be fairly easy to eliminate the extra copy in the
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
293 future */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
294
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
295 memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
296 os->body_fill+=op->bytes;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
297
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
298 /* Store lacing vals for this packet */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
299 for(i=0;i<lacing_vals-1;i++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
300 os->lacing_vals[os->lacing_fill+i]=255;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
301 os->granule_vals[os->lacing_fill+i]=os->granulepos;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
302 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
303 os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
304 os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
305
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
306 /* flag the first segment as the beginning of the packet */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
307 os->lacing_vals[os->lacing_fill]|= 0x100;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
308
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
309 os->lacing_fill+=lacing_vals;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
310
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
311 /* for the sake of completeness */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
312 os->packetno++;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
313
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
314 if(op->e_o_s)os->e_o_s=1;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
315
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
316 return(0);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
317 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
318
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
319 /* This will flush remaining packets into a page (returning nonzero),
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
320 even if there is not enough data to trigger a flush normally
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
321 (undersized page). If there are no packets or partial packets to
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
322 flush, ogg_stream_flush returns 0. Note that ogg_stream_flush will
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
323 try to flush a normal sized page like ogg_stream_pageout; a call to
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
324 ogg_stream_flush does not guarantee that all packets have flushed.
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
325 Only a return value of 0 from ogg_stream_flush indicates all packet
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
326 data is flushed into pages.
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
327
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
328 since ogg_stream_flush will flush the last page in a stream even if
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
329 it's undersized, you almost certainly want to use ogg_stream_pageout
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
330 (and *not* ogg_stream_flush) unless you specifically need to flush
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
331 an page regardless of size in the middle of a stream. */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
332
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
333 int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
334 int i;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
335 int vals=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
336 int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
337 int bytes=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
338 long acc=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
339 ogg_int64_t granule_pos=os->granule_vals[0];
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
340
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
341 if(maxvals==0)return(0);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
342
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
343 /* construct a page */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
344 /* decide how many segments to include */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
345
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
346 /* If this is the initial header case, the first page must only include
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
347 the initial header packet */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
348 if(os->b_o_s==0){ /* 'initial header page' case */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
349 granule_pos=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
350 for(vals=0;vals<maxvals;vals++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
351 if((os->lacing_vals[vals]&0x0ff)<255){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
352 vals++;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
353 break;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
354 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
355 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
356 }else{
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
357 for(vals=0;vals<maxvals;vals++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
358 if(acc>4096)break;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
359 acc+=os->lacing_vals[vals]&0x0ff;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
360 granule_pos=os->granule_vals[vals];
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
361 }
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
362 }
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
363
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
364 /* construct the header in temp storage */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
365 memcpy(os->header,"OggS",4);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
366
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
367 /* stream structure version */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
368 os->header[4]=0x00;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
369
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
370 /* continued packet flag? */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
371 os->header[5]=0x00;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
372 if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
373 /* first page flag? */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
374 if(os->b_o_s==0)os->header[5]|=0x02;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
375 /* last page flag? */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
376 if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
377 os->b_o_s=1;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
378
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
379 /* 64 bits of PCM position */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
380 for(i=6;i<14;i++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
381 os->header[i]=(unsigned char)(granule_pos&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
382 granule_pos>>=8;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
383 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
384
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
385 /* 32 bits of stream serial number */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
386 {
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
387 long serialno=os->serialno;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
388 for(i=14;i<18;i++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
389 os->header[i]=(unsigned char)(serialno&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
390 serialno>>=8;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
391 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
392 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
393
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
394 /* 32 bits of page counter (we have both counter and page header
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
395 because this val can roll over) */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
396 if(os->pageno==-1)os->pageno=0; /* because someone called
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
397 stream_reset; this would be a
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
398 strange thing to do in an
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
399 encode stream, but it has
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
400 plausible uses */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
401 {
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
402 long pageno=os->pageno++;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
403 for(i=18;i<22;i++){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
404 os->header[i]=(unsigned char)(pageno&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
405 pageno>>=8;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
406 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
407 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
408
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
409 /* zero for computation; filled in later */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
410 os->header[22]=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
411 os->header[23]=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
412 os->header[24]=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
413 os->header[25]=0;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
414
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
415 /* segment table */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
416 os->header[26]=(unsigned char)(vals&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
417 for(i=0;i<vals;i++)
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
418 bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
419
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
420 /* set pointers in the ogg_page struct */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
421 og->header=os->header;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
422 og->header_len=os->header_fill=vals+27;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
423 og->body=os->body_data+os->body_returned;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
424 og->body_len=bytes;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
425
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
426 /* advance the lacing data and set the body_returned pointer */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
427
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
428 os->lacing_fill-=vals;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
429 memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
430 memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
431 os->body_returned+=bytes;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
432
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
433 /* calculate the checksum */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
434
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
435 ogg_page_checksum_set(og);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
436
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
437 /* done */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
438 return(1);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
439 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
440
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
441
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
442 /* This constructs pages from buffered packet segments. The pointers
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
443 returned are to static buffers; do not free. The returned buffers are
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
444 good only until the next call (using the same ogg_stream_state) */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
445
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
446 int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
447
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
448 if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
449 os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
450 os->lacing_fill>=255 || /* 'segment table full' case */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
451 (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
452
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
453 return(ogg_stream_flush(os,og));
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
454 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
455
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
456 /* not enough data to construct a page and not end of stream */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
457 return(0);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
458 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
459
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
460 int ogg_stream_eos(ogg_stream_state *os){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
461 return os->e_o_s;
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
462 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
463
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
464 /* DECODING PRIMITIVES: packet streaming layer **********************/
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
465
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
466 /* This has two layers to place more of the multi-serialno and paging
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
467 control in the application's hands. First, we expose a data buffer
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
468 using ogg_sync_buffer(). The app either copies into the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
469 buffer, or passes it directly to read(), etc. We then call
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
470 ogg_sync_wrote() to tell how many bytes we just added.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
471
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
472 Pages are returned (pointers into the buffer in ogg_sync_state)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
473 by ogg_sync_pageout(). The page is then submitted to
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
474 ogg_stream_pagein() along with the appropriate
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
475 ogg_stream_state* (ie, matching serialno). We then get raw
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
476 packets out calling ogg_stream_packetout() with a
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
477 ogg_stream_state. See the 'frame-prog.txt' docs for details and
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
478 example code. */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
479
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
480 /* initialize the struct to a known state */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
481 int ogg_sync_init(ogg_sync_state *oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
482 if(oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
483 memset(oy,0,sizeof(*oy));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
484 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
485 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
486 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
487
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
488 /* clear non-flat storage within */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
489 int ogg_sync_clear(ogg_sync_state *oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
490 if(oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
491 if(oy->data)_ogg_free(oy->data);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
492 ogg_sync_init(oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
493 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
494 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
495 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
496
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
497 int ogg_sync_destroy(ogg_sync_state *oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
498 if(oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
499 ogg_sync_clear(oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
500 _ogg_free(oy);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
501 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
502 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
503 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
504
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
505 char *ogg_sync_buffer(ogg_sync_state *oy, long size){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
506
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
507 /* first, clear out any space that has been previously returned */
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
508 if(oy->returned){
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
509 oy->fill-=oy->returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
510 if(oy->fill>0)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
511 memmove(oy->data,oy->data+oy->returned,oy->fill);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
512 oy->returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
513 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
514
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
515 if(size>oy->storage-oy->fill){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
516 /* We need to extend the internal buffer */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
517 long newsize=size+oy->fill+4096; /* an extra page to be nice */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
518
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
519 if(oy->data)
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
520 oy->data=_ogg_realloc(oy->data,newsize);
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
521 else
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
522 oy->data=_ogg_malloc(newsize);
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
523 oy->storage=newsize;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
524 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
525
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
526 /* expose a segment at least as large as requested at the fill mark */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
527 return((char *)oy->data+oy->fill);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
528 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
529
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
530 int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
531 if(oy->fill+bytes>oy->storage)return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
532 oy->fill+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
533 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
534 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
535
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
536 /* sync the stream. This is meant to be useful for finding page
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
537 boundaries.
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
538
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
539 return values for this:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
540 -n) skipped n bytes
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
541 0) page not ready; more data (no bytes skipped)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
542 n) page synced at current location; page length n bytes
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
543
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
544 */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
545
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
546 long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
547 unsigned char *page=oy->data+oy->returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
548 unsigned char *next;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
549 long bytes=oy->fill-oy->returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
550
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
551 if(oy->headerbytes==0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
552 int headerbytes,i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
553 if(bytes<27)return(0); /* not enough for a header */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
554
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
555 /* verify capture pattern */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
556 if(memcmp(page,"OggS",4))goto sync_fail;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
557
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
558 headerbytes=page[26]+27;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
559 if(bytes<headerbytes)return(0); /* not enough for header + seg table */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
560
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
561 /* count up body length in the segment table */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
562
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
563 for(i=0;i<page[26];i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
564 oy->bodybytes+=page[27+i];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
565 oy->headerbytes=headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
566 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
567
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
568 if(oy->bodybytes+oy->headerbytes>bytes)return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
569
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
570 /* The whole test page is buffered. Verify the checksum */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
571 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
572 /* Grab the checksum bytes, set the header field to zero */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
573 char chksum[4];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
574 ogg_page log;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
575
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
576 memcpy(chksum,page+22,4);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
577 memset(page+22,0,4);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
578
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
579 /* set up a temp page struct and recompute the checksum */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
580 log.header=page;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
581 log.header_len=oy->headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
582 log.body=page+oy->headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
583 log.body_len=oy->bodybytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
584 ogg_page_checksum_set(&log);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
585
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
586 /* Compare */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
587 if(memcmp(chksum,page+22,4)){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
588 /* D'oh. Mismatch! Corrupt page (or miscapture and not a page
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
589 at all) */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
590 /* replace the computed checksum with the one actually read in */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
591 memcpy(page+22,chksum,4);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
592
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
593 /* Bad checksum. Lose sync */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
594 goto sync_fail;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
595 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
596 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
597
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
598 /* yes, have a whole page all ready to go */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
599 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
600 unsigned char *page=oy->data+oy->returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
601 long bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
602
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
603 if(og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
604 og->header=page;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
605 og->header_len=oy->headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
606 og->body=page+oy->headerbytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
607 og->body_len=oy->bodybytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
608 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
609
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
610 oy->unsynced=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
611 oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
612 oy->headerbytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
613 oy->bodybytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
614 return(bytes);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
615 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
616
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
617 sync_fail:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
618
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
619 oy->headerbytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
620 oy->bodybytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
621
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
622 /* search for possible capture */
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
623 next=memchr(page+1,'O',bytes-1);
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
624 if(!next)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
625 next=oy->data+oy->fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
626
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
627 oy->returned=next-oy->data;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
628 return(-(next-page));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
629 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
630
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
631 /* sync the stream and get a page. Keep trying until we find a page.
18613
052b4ad84883 Change "Supress" to "Suppress" in a couple comments.
corey
parents: 15250
diff changeset
632 Suppress 'sync errors' after reporting the first.
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
633
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
634 return values:
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
635 -1) recapture (hole in data)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
636 0) need more data
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
637 1) page returned
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
638
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
639 Returns pointers into buffered data; invalidated by next call to
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
640 _stream, _clear, _init, or _buffer */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
641
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
642 int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
643
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
644 /* all we need to do is verify a page at the head of the stream
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
645 buffer. If it doesn't verify, we look for the next potential
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
646 frame */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
647
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
648 for(;;){
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
649 long ret=ogg_sync_pageseek(oy,og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
650 if(ret>0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
651 /* have a page */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
652 return(1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
653 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
654 if(ret==0){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
655 /* need more data */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
656 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
657 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
658
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
659 /* head did not start a synced page... skipped some bytes */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
660 if(!oy->unsynced){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
661 oy->unsynced=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
662 return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
663 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
664
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
665 /* loop. keep looking */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
666
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
667 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
668 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
669
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
670 /* add the incoming page to the stream state; we decompose the page
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
671 into packet segments here as well. */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
672
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
673 int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
674 unsigned char *header=og->header;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
675 unsigned char *body=og->body;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
676 long bodysize=og->body_len;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
677 int segptr=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
678
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
679 int version=ogg_page_version(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
680 int continued=ogg_page_continued(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
681 int bos=ogg_page_bos(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
682 int eos=ogg_page_eos(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
683 ogg_int64_t granulepos=ogg_page_granulepos(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
684 int serialno=ogg_page_serialno(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
685 long pageno=ogg_page_pageno(og);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
686 int segments=header[26];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
687
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
688 /* clean up 'returned data' */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
689 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
690 long lr=os->lacing_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
691 long br=os->body_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
692
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
693 /* body data */
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
694 if(br){
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
695 os->body_fill-=br;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
696 if(os->body_fill)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
697 memmove(os->body_data,os->body_data+br,os->body_fill);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
698 os->body_returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
699 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
700
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
701 if(lr){
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
702 /* segment table */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
703 if(os->lacing_fill-lr){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
704 memmove(os->lacing_vals,os->lacing_vals+lr,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
705 (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
706 memmove(os->granule_vals,os->granule_vals+lr,
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
707 (os->lacing_fill-lr)*sizeof(*os->granule_vals));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
708 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
709 os->lacing_fill-=lr;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
710 os->lacing_packet-=lr;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
711 os->lacing_returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
712 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
713 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
714
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
715 /* check the serial number */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
716 if(serialno!=os->serialno)return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
717 if(version>0)return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
718
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
719 _os_lacing_expand(os,segments+1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
720
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
721 /* are we in sequence? */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
722 if(pageno!=os->pageno){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
723 int i;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
724
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
725 /* unroll previous partial packet (if any) */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
726 for(i=os->lacing_packet;i<os->lacing_fill;i++)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
727 os->body_fill-=os->lacing_vals[i]&0xff;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
728 os->lacing_fill=os->lacing_packet;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
729
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
730 /* make a note of dropped data in segment table */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
731 if(os->pageno!=-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
732 os->lacing_vals[os->lacing_fill++]=0x400;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
733 os->lacing_packet++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
734 }
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
735 }
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
736
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
737 /* are we a 'continued packet' page? If so, we may need to skip
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
738 some segments */
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
739 if(continued){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
740 if(os->lacing_fill<1 ||
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
741 os->lacing_vals[os->lacing_fill-1]==0x400){
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
742 bos=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
743 for(;segptr<segments;segptr++){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
744 int val=header[27+segptr];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
745 body+=val;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
746 bodysize-=val;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
747 if(val<255){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
748 segptr++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
749 break;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
750 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
751 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
752 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
753 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
754
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
755 if(bodysize){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
756 _os_body_expand(os,bodysize);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
757 memcpy(os->body_data+os->body_fill,body,bodysize);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
758 os->body_fill+=bodysize;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
759 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
760
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
761 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
762 int saved=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
763 while(segptr<segments){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
764 int val=header[27+segptr];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
765 os->lacing_vals[os->lacing_fill]=val;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
766 os->granule_vals[os->lacing_fill]=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
767
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
768 if(bos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
769 os->lacing_vals[os->lacing_fill]|=0x100;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
770 bos=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
771 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
772
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
773 if(val<255)saved=os->lacing_fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
774
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
775 os->lacing_fill++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
776 segptr++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
777
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
778 if(val<255)os->lacing_packet=os->lacing_fill;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
779 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
780
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
781 /* set the granulepos on the last granuleval of the last full packet */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
782 if(saved!=-1){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
783 os->granule_vals[saved]=granulepos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
784 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
785
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
786 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
787
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
788 if(eos){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
789 os->e_o_s=1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
790 if(os->lacing_fill>0)
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
791 os->lacing_vals[os->lacing_fill-1]|=0x200;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
792 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
793
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
794 os->pageno=pageno+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
795
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
796 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
797 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
798
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
799 /* clear things to an initial state. Good to call, eg, before seeking */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
800 int ogg_sync_reset(ogg_sync_state *oy){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
801 oy->fill=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
802 oy->returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
803 oy->unsynced=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
804 oy->headerbytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
805 oy->bodybytes=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
806 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
807 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
808
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
809 int ogg_stream_reset(ogg_stream_state *os){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
810 os->body_fill=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
811 os->body_returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
812
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
813 os->lacing_fill=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
814 os->lacing_packet=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
815 os->lacing_returned=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
816
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
817 os->header_fill=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
818
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
819 os->e_o_s=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
820 os->b_o_s=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
821 os->pageno=-1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
822 os->packetno=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
823 os->granulepos=0;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
824
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
825 return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
826 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
827
15250
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
828 int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
829 ogg_stream_reset(os);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
830 os->serialno=serialno;
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
831 return(0);
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
832 }
e891ff7a7b6c update to libogg 1.1.2 (needed for Theora)
henry
parents: 14280
diff changeset
833
14280
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
834 static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
835
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
836 /* The last part of decode. We have the stream broken into packet
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
837 segments. Now we need to group them into packets (or return the
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
838 out of sync markers) */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
839
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
840 int ptr=os->lacing_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
841
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
842 if(os->lacing_packet<=ptr)return(0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
843
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
844 if(os->lacing_vals[ptr]&0x400){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
845 /* we need to tell the codec there's a gap; it might need to
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
846 handle previous packet dependencies. */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
847 os->lacing_returned++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
848 os->packetno++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
849 return(-1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
850 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
851
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
852 if(!op && !adv)return(1); /* just using peek as an inexpensive way
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
853 to ask if there's a whole packet
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
854 waiting */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
855
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
856 /* Gather the whole packet. We'll have no holes or a partial packet */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
857 {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
858 int size=os->lacing_vals[ptr]&0xff;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
859 int bytes=size;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
860 int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
861 int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
862
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
863 while(size==255){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
864 int val=os->lacing_vals[++ptr];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
865 size=val&0xff;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
866 if(val&0x200)eos=0x200;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
867 bytes+=size;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
868 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
869
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
870 if(op){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
871 op->e_o_s=eos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
872 op->b_o_s=bos;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
873 op->packet=os->body_data+os->body_returned;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
874 op->packetno=os->packetno;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
875 op->granulepos=os->granule_vals[ptr];
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
876 op->bytes=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
877 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
878
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
879 if(adv){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
880 os->body_returned+=bytes;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
881 os->lacing_returned=ptr+1;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
882 os->packetno++;
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
883 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
884 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
885 return(1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
886 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
887
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
888 int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
889 return _packetout(os,op,1);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
890 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
891
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
892 int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
893 return _packetout(os,op,0);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
894 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
895
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
896 void ogg_packet_clear(ogg_packet *op) {
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
897 _ogg_free(op->packet);
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
898 memset(op, 0, sizeof(*op));
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
899 }
8631a3803289 internal Tremor decoder for Ogg/Vorbis
henry
parents:
diff changeset
900