38 #include <vorbis/codec.h>
39 #include <vorbis/vorbisenc.h>
40 #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)
88 static int _ov_header_fseek_wrap(FILE *
f, ogg_int64_t off,
int whence)
93 return fseek(f, off, whence);
96 static ov_callbacks OV_CALLBACKS_NOCLOSE = {
97 (size_t (*)(
void *, size_t, size_t,
void *)) fread,
98 (int (*)(
void *, ogg_int64_t, int)) _ov_header_fseek_wrap,
99 (
int (*)(
void *)) NULL,
100 (
long (*)(
void *)) ftell
119 result = ov_open_callbacks(s->
f, &desc->
ov_f, NULL, 0, OV_CALLBACKS_NOCLOSE);
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;
158 vorbis_info_init(&tmp->
vi);
165 vorbis_comment_init(&tmp->
vc);
166 vorbis_comment_add_tag(&tmp->
vc,
"ENCODER",
"Asterisk PBX");
168 vorbis_comment_add_tag(&tmp->
vc,
"COMMENT", (
char *) comment);
170 vorbis_analysis_init(&tmp->
vd, &tmp->
vi);
171 vorbis_block_init(&tmp->
vd, &tmp->
vb);
175 vorbis_analysis_headerout(&tmp->
vd, &tmp->
vc, &header, &header_comm,
177 ogg_stream_packetin(&tmp->
os, &header);
178 ogg_stream_packetin(&tmp->
os, &header_comm);
179 ogg_stream_packetin(&tmp->
os, &header_code);
182 if (ogg_stream_flush(&tmp->
os, &tmp->
og) == 0)
184 if (!fwrite(tmp->
og.header, 1, tmp->
og.header_len, s->
f)) {
187 if (!fwrite(tmp->
og.body, 1, tmp->
og.body_len, s->
f)) {
190 if (ogg_page_eos(&tmp->
og))
204 while (vorbis_analysis_blockout(&s->
vd, &s->
vb) == 1) {
205 vorbis_analysis(&s->
vb, NULL);
206 vorbis_bitrate_addblock(&s->
vb);
208 while (vorbis_bitrate_flushpacket(&s->
vd, &s->
op)) {
209 ogg_stream_packetin(&s->
os, &s->
op);
211 if (ogg_stream_pageout(&s->
os, &s->
og) == 0) {
214 if (!fwrite(s->
og.header, 1, s->
og.header_len, f)) {
217 if (!fwrite(s->
og.body, 1, s->
og.body_len, f)) {
220 if (ogg_page_eos(&s->
og)) {
260 buffer = vorbis_analysis_buffer(&s->
vd, f->
samples);
262 for (i = 0; i < f->
samples; i++)
263 buffer[0][i] = (
double)data[i] / 32768.0;
265 vorbis_analysis_wrote(&s->
vd, f->
samples);
285 vorbis_analysis_wrote(&s->
vd, 0);
303 int current_bitstream = -10;
320 bytes_read = ov_read(
331 if (bytes_read <= 0) {
369 if ((pos = ov_pcm_tell(&desc->
ov_f)) < 0) {
384 int seek_result = -1;
385 off_t relative_pcm_pos;
389 ast_log(
LOG_WARNING,
"Seeking is not supported on OGG/Vorbis streams in writing mode!\n");
396 seek_result = ov_pcm_seek(&desc->
ov_f, sample_offset);
403 seek_result = ov_pcm_seek(&desc->
ov_f, relative_pcm_pos + sample_offset);
406 if ((relative_pcm_pos = ov_pcm_total(&desc->
ov_f, -1)) < 0) {
410 seek_result = ov_pcm_seek(&desc->
ov_f, relative_pcm_pos - sample_offset);
418 return (seek_result == 0) ? 0 : -1;
422 .
name =
"ogg_vorbis",
union ast_frame_subclass subclass
Asterisk main include file. File version handling, generic pbx functions.
int eos
Indicates whether an End of Stream condition has been detected.
#define DEFAULT_SAMPLE_RATE
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
I/O Management (derived from Cheops-NG)
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
off_t writing_pcm_pos
Stores the current pcm position to support tell() on writing mode.
long int ast_random(void)
char * ast_getformatname(format_t format)
Get the name of a format.
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
if(yyss+yystacksize-1<=yyssp)
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
#define AST_FORMAT_SLINEAR
Data structure associated with a single frame of data.
int writing
Indicates whether this filestream is set up for reading or writing.
enum ast_frame_type frametype
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
union ast_frame::@172 data
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.