1 /*******************************************************************************
3 * Copyright (c) 2001, Tobias Waldvogel *
4 * All rights reserved. *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
9 * - Redistributions of source code must retain the above copyright notice, *
10 * this list of conditions and the following disclaimer. *
12 * - Redistributions in binary form must reproduce the above copyright notice, *
13 * this list of conditions and the following disclaimer in the documentation *
14 * and/or other materials provided with the distribution. *
16 * - The names of the contributors may not be used to endorse or promote *
17 * products derived from this software without specific prior written *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE *
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN *
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
30 * POSSIBILITY OF SUCH DAMAGE. *
32 *******************************************************************************/
40 #endif /* __cplusplus*/
43 #include "vorbis/codec.h"
45 // "reference time" in this file is defined as 100ns units
48 // These are the identifiers in the header package
49 #define MT_Video "video"
50 #define MT_Audio "audio"
51 #define MT_Text "text"
53 // One second in reference time
54 #define SEC_IN_REFTIME 10000000
56 typedef struct stream_header_video
60 } stream_header_video
;
62 typedef struct stream_header_audio
65 ogg_int16_t blockalign
;
66 ogg_int32_t avgbytespersec
;
67 } stream_header_audio
;
69 // This structure is used as header packet
70 // The library use this structure similar to
71 // vorbis_info for vorbis
72 typedef struct stream_header
77 ogg_int32_t size
; // size of the structure
79 ogg_int64_t time_unit
; // in reference time
80 ogg_int64_t samples_per_unit
;
81 ogg_int32_t default_len
; // in media time
83 ogg_int32_t buffersize
;
84 ogg_int16_t bits_per_sample
;
89 stream_header_video video
;
91 stream_header_audio audio
;
95 typedef struct stream_state
100 ogg_int32_t lastsize
;
102 // For creating streams ...
103 unsigned char* buffer
;
105 ogg_int64_t packetno
;
110 extern void stream_header_init(stream_header
* sh
);
111 extern void stream_header_clear(stream_header
* sh
);
112 extern int stream_header_setup_video(stream_header
** sh
, char* FOURCC
,
113 ogg_int64_t avg_time_per_frame
,
114 ogg_int32_t width
, ogg_int32_t height
,
115 ogg_int16_t bit_count
,
116 ogg_int32_t buffersize
);
117 extern int stream_header_setup_audio(stream_header
** sh
, ogg_int16_t audioid
,
118 ogg_int16_t channels
,
119 ogg_int16_t blockalign
,
120 ogg_int32_t avgbytespersec
,
121 ogg_int32_t samplespersec
,
122 ogg_int16_t bitspersample
,
123 unsigned char* extradata
,
124 ogg_int32_t extralen
,
125 ogg_int32_t buffersize
);
126 extern int stream_header_setup_text(stream_header
** sh
);
128 extern int stream_header_in(stream_header
** sh
, ogg_packet
* op
);
129 extern int stream_headerout_header(stream_state
* ss
, stream_header
* sh
);
130 extern int stream_headerout_comment(stream_state
* ss
, vorbis_comment
* vc
);
131 extern int stream_headerout_codebook(stream_state
* ss
, stream_header
* sh
);
133 extern void stream_state_init(stream_state
* ss
, int serialno
);
134 extern void stream_state_clear(stream_state
* ss
);
135 extern void stream_state_reset(stream_state
* ss
);
138 extern int stream_samplein_getbuffer(stream_state
* ss
,
139 unsigned char** buffer
, int len
);
140 extern int stream_samplein_vorbis(stream_state
* ss
, vorbis_info
* vi
,
142 ogg_int64_t
* mediastart
, ogg_int64_t
* refstart
,
144 extern int stream_samplein(stream_state
* ss
, stream_header
* sh
,
146 ogg_int64_t
* mediastart
, ogg_int64_t
* medialen
,
147 ogg_int64_t
* refstart
, ogg_int64_t
* refstop
,
149 extern int stream_sampleout_vorbis(stream_state
* ss
, vorbis_info
* vi
,
151 ogg_int64_t
* mediastart
, ogg_int64_t
* refstart
,
152 unsigned char** buffer
, int* bufferlen
);
153 extern int stream_sampleout(stream_state
* ss
, stream_header
* sh
,
154 bool* eos
, bool* sync
,
155 ogg_int64_t
* mediastart
, ogg_int64_t
* medialen
,
156 ogg_int64_t
* refstart
, ogg_int64_t
* refstop
,
157 unsigned char** buffer
, int* bufferlen
);
160 extern ogg_int32_t
stream_packet_len(stream_header
* sh
, ogg_packet
* op
);
163 ogg_int64_t
reference_time_to_mediatime(ogg_int64_t time_unit
, ogg_int64_t samples_per_unit
,
164 ogg_int64_t reftime
);
165 ogg_int64_t
mediatime_to_reference_time(ogg_int64_t time_unit
, ogg_int64_t samples_per_unit
,
166 ogg_int64_t mediatime
);
168 #define PACKET_TYPE_HEADER 0x01
169 #define PACKET_TYPE_COMMENT 0x03
170 #define PACKET_TYPE_CODEBOOK 0x05
171 #define PACKET_TYPE_BITS 0x07
173 #define PACKET_IS_SYNCPOINT 0x08
174 #define PACKET_LEN_BITS01 0xc0
175 #define PACKET_LEN_BITS2 0x02
177 #define E_INVPOINTER -2048
178 #define E_NOTDATA -2049
179 #define E_NOTHEADER -2050
180 #define E_UNKNOWNHEADER -2051
181 #define E_TIMEINVAILD -2052
187 #endif /* __cplusplus */