37#include <vorbis/codec.h>
38#include <vorbis/vorbisenc.h>
39#include <vorbis/vorbisfile.h>
53#define SAMPLES_MAX 512
54#define BUF_SIZE (2*SAMPLES_MAX)
56#define BLOCK_SIZE 4096
83#if !defined(HAVE_VORBIS_OPEN_CALLBACKS)
93 return fseek(f, off, whence);
97 (size_t (*)(
void *, size_t, size_t,
void *)) fread,
99 (int (*)(
void *))
NULL,
100 (long (*)(
void *)) ftell
126 if (
desc->ov_f.vi->channels != 1) {
127 ast_log(
LOG_ERROR,
"Only monophonic OGG/Vorbis files are currently supported!\n");
128 ov_clear(&
desc->ov_f);
133 ast_log(
LOG_ERROR,
"Only 8000Hz OGG/Vorbis files are currently supported!\n");
134 ov_clear(&
desc->ov_f);
151 ogg_packet header_comm;
152 ogg_packet header_code;
156 tmp->writing_pcm_pos = 0;
158 vorbis_info_init(&
tmp->vi);
162 vorbis_info_clear(&
tmp->vi);
166 vorbis_comment_init(&
tmp->vc);
167 vorbis_comment_add_tag(&
tmp->vc,
"ENCODER",
"Asterisk PBX");
169 vorbis_comment_add_tag(&
tmp->vc,
"COMMENT", (
char *)
comment);
171 vorbis_analysis_init(&
tmp->vd, &
tmp->vi);
172 vorbis_block_init(&
tmp->vd, &
tmp->vb);
176 vorbis_analysis_headerout(&
tmp->vd, &
tmp->vc, &
header, &header_comm,
179 ogg_stream_packetin(&
tmp->os, &header_comm);
180 ogg_stream_packetin(&
tmp->os, &header_code);
183 if (ogg_stream_flush(&
tmp->os, &
tmp->og) == 0)
185 if (fwrite(
tmp->og.header, 1,
tmp->og.header_len, s->
f) !=
tmp->og.header_len) {
188 if (fwrite(
tmp->og.body, 1,
tmp->og.body_len, s->
f) !=
tmp->og.body_len) {
191 if (ogg_page_eos(&
tmp->og))
205 while (vorbis_analysis_blockout(&s->
vd, &s->
vb) == 1) {
206 vorbis_analysis(&s->
vb,
NULL);
207 vorbis_bitrate_addblock(&s->
vb);
209 while (vorbis_bitrate_flushpacket(&s->
vd, &s->
op)) {
210 ogg_stream_packetin(&s->
os, &s->
op);
212 if (ogg_stream_pageout(&s->
os, &s->
og) == 0) {
215 if (fwrite(s->
og.header, 1, s->
og.header_len, f) != s->
og.header_len) {
218 if (fwrite(s->
og.body, 1, s->
og.body_len, f) != s->
og.body_len) {
221 if (ogg_page_eos(&s->
og)) {
251 buffer = vorbis_analysis_buffer(&s->
vd, f->
samples);
253 for (i = 0; i < f->
samples; i++)
254 buffer[0][i] = (
double)data[i] / 32768.0;
256 vorbis_analysis_wrote(&s->
vd, f->
samples);
276 vorbis_analysis_wrote(&s->
vd, 0);
280 ogg_stream_clear(&s->
os);
281 vorbis_block_clear(&s->
vb);
282 vorbis_dsp_clear(&s->
vd);
283 vorbis_comment_clear(&s->
vc);
284 vorbis_info_clear(&s->
vi);
301 int current_bitstream = -10;
315 bytes_read = ov_read(
326 if (bytes_read <= 0) {
361 return desc->writing_pcm_pos;
364 if ((pos = ov_pcm_tell(&
desc->ov_f)) < 0) {
379 int seek_result = -1;
380 off_t relative_pcm_pos;
384 ast_log(
LOG_WARNING,
"Seeking is not supported on OGG/Vorbis streams in writing mode!\n");
391 seek_result = ov_pcm_seek(&
desc->ov_f, sample_offset);
398 seek_result = ov_pcm_seek(&
desc->ov_f, relative_pcm_pos + sample_offset);
401 if ((relative_pcm_pos = ov_pcm_total(&
desc->ov_f, -1)) < 0) {
405 seek_result = ov_pcm_seek(&
desc->ov_f, relative_pcm_pos - sample_offset);
413 return (seek_result == 0) ? 0 : -1;
417 .
name =
"ogg_vorbis",
Asterisk main include file. File version handling, generic pbx functions.
#define DEFAULT_SAMPLE_RATE
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
I/O Management (derived from Cheops-NG)
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
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...
struct ast_frame fr
frame produced by read, typically
Data structure associated with a single frame of data.
union ast_frame::@226 data
int eos
Indicates whether an End of Stream condition has been detected.
off_t writing_pcm_pos
Stores the current pcm position to support tell() on writing mode.
int writing
Indicates whether this filestream is set up for reading or writing.
long int ast_random(void)