36 #include <speex/speex_header.h>
39 #define BLOCK_SIZE 4096
64 result = ogg_stream_packetout(&s->os, &s->op);
66 if (s->op.bytes >= 5 && !memcmp(s->op.packet,
"Speex", 5)) {
67 s->serialno = s->os.serialno;
69 if (s->serialno == -1 || s->os.serialno != s->serialno) {
77 "Corrupt or missing data at this page position; continuing...\n");
88 result = ogg_sync_pageout(&s->oy, &s->og);
91 if (ogg_page_serialno(&s->og) != s->os.serialno) {
92 ogg_stream_reset_serialno(&s->os, ogg_page_serialno(&s->og));
96 result = ogg_stream_pagein(&s->os, &s->og);
99 if (ogg_page_eos(&s->og) &&
100 ogg_page_serialno(&s->og) == s->serialno)
105 "Invalid page in the bitstream; continuing...\n");
110 "Corrupt or missing data in bitstream; continuing...\n");
115 buffer = ogg_sync_buffer(&s->oy, BLOCK_SIZE);
116 bytes = fread(buffer, 1, BLOCK_SIZE, fs->f);
117 ogg_sync_wrote(&s->oy, bytes);
135 SpeexHeader *hdr = NULL;
136 int i, result, expected_rate;
140 ogg_sync_init(&s->oy);
142 buffer = ogg_sync_buffer(&s->oy, BLOCK_SIZE);
143 bytes = fread(buffer, 1, BLOCK_SIZE, fs->f);
144 ogg_sync_wrote(&s->oy, bytes);
146 result = ogg_sync_pageout(&s->oy, &s->og);
148 if(bytes < BLOCK_SIZE) {
149 ast_log(LOG_ERROR,
"Run out of data...\n");
151 ast_log(LOG_ERROR,
"Input does not appear to be an Ogg bitstream.\n");
153 ogg_sync_clear(&s->oy);
157 ogg_stream_init(&s->os, ogg_page_serialno(&s->og));
158 if (ogg_stream_pagein(&s->os, &s->og) < 0) {
159 ast_log(LOG_ERROR,
"Error reading first page of Ogg bitstream data.\n");
163 if (read_packet(fs) < 0) {
164 ast_log(LOG_ERROR,
"Error reading initial header packet.\n");
168 hdr = speex_packet_to_header((
char*)s->op.packet, s->op.bytes);
169 if (memcmp(hdr->speex_string,
"Speex ", 8)) {
170 ast_log(LOG_ERROR,
"OGG container does not contain Speex audio!\n");
173 if (hdr->frames_per_packet != 1) {
174 ast_log(LOG_ERROR,
"Only one frame-per-packet OGG/Speex files are currently supported!\n");
177 if (hdr->nb_channels != 1) {
178 ast_log(LOG_ERROR,
"Only monophonic OGG/Speex files are currently supported!\n");
181 if (hdr->rate != expected_rate) {
182 ast_log(LOG_ERROR,
"Unexpected sampling rate (%d != %d)!\n",
183 hdr->rate, expected_rate);
188 if (read_packet(fs) < 0) {
189 ast_log(LOG_ERROR,
"Error reading comment packet.\n");
192 for (i = 0; i < hdr->extra_headers; i++) {
193 if (read_packet(fs) < 0) {
194 ast_log(LOG_ERROR,
"Error reading extra header packet %d.\n", i+1);
198 speex_header_free(hdr);
203 speex_header_free(hdr);
205 ogg_stream_clear(&s->os);
206 ogg_sync_clear(&s->oy);
218 ogg_stream_clear(&s->os);
219 ogg_sync_clear(&s->oy);
233 if (read_packet(fs) < 0) {
238 memcpy(fs->
fr.
data.ptr, s->op.packet, s->op.bytes);
253 ast_log(LOG_WARNING,
"Truncation is not supported on OGG/Speex streams!\n");
259 ast_log(LOG_WARNING,
"Writing is not supported on OGG/Speex streams!\n");
272 ast_log(LOG_WARNING,
"Seeking is not supported on OGG/Speex streams!\n");
278 ast_log(LOG_WARNING,
"Telling is not supported on OGG/Speex streams!\n");
286 .write = ogg_speex_write,
289 .tell = ogg_speex_tell,
297 .
name =
"ogg_speex16",
300 .write = ogg_speex_write,
303 .tell = ogg_speex_tell,
311 .
name =
"ogg_speex32",
314 .write = ogg_speex_write,
317 .tell = ogg_speex_tell,
324 static int unload_module(
void)
333 static int load_module(
void)
339 if (ast_format_def_register(&speex_f) ||
340 ast_format_def_register(&speex16_f) ||
341 ast_format_def_register(&speex32_f)) {
349 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"OGG/Speex audio",
350 .support_level = AST_MODULE_SUPPORT_EXTENDED,
352 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
int eos
Indicates whether an End of Stream condition has been detected.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
struct ast_format_def * fmt
struct ast_frame fr
frame produced by read, typically
unsigned int ast_codec_samples_count(struct ast_frame *frame)
Get the number of samples contained within a frame.
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
union ast_frame::@224 data
Module has failed to load, may be in an inconsistent state.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Data structure associated with a single frame of data.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.