| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * Copyright (C) 2005, Jeff Ollie | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-26 13:03:17 +00:00
										 |  |  |  * \brief OGG/Vorbis streams. | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \arg File name extension: ogg | 
					
						
							|  |  |  |  * \ingroup formats | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | /* the order of these dependencies is important... it also specifies
 | 
					
						
							|  |  |  |    the link order of the libraries during linking | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							| 
									
										
										
										
											2006-07-05 20:12:29 +00:00
										 |  |  | 	<depend>vorbis</depend> | 
					
						
							|  |  |  | 	<depend>ogg</depend> | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | #include <vorbis/codec.h>
 | 
					
						
							|  |  |  | #include <vorbis/vorbisenc.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef _WIN32
 | 
					
						
							|  |  |  | #include <io.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-22 00:53:49 +00:00
										 |  |  | #include "asterisk/mod_format.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * this is the number of samples we deal with. Samples are converted | 
					
						
							|  |  |  |  * to SLINEAR so each one uses 2 bytes in the buffer. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | #define SAMPLES_MAX 160
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | #define	BUF_SIZE	(2*SAMPLES_MAX)
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | #define BLOCK_SIZE 4096		/* used internally in the vorbis routines */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct vorbis_desc {	/* format specific parameters */ | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	/* structures for handling the Ogg container */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	ogg_sync_state oy; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	ogg_stream_state os; | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	ogg_page og; | 
					
						
							|  |  |  | 	ogg_packet op; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* structures for handling Vorbis audio data */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	vorbis_info vi; | 
					
						
							|  |  |  | 	vorbis_comment vc; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	vorbis_dsp_state vd; | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	vorbis_block vb; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/*! \brief Indicates whether this filestream is set up for reading or writing. */ | 
					
						
							|  |  |  | 	int writing; | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	/*! \brief Indicates whether an End of Stream condition has been detected. */ | 
					
						
							|  |  |  | 	int eos; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Create a new OGG/Vorbis filestream and set it up for reading. | 
					
						
							| 
									
										
										
										
											2006-07-19 22:40:36 +00:00
										 |  |  |  * \param s File that points to on disk storage of the OGG/Vorbis data. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  * \return The new filestream. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | static int ogg_vorbis_open(struct ast_filestream *s) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int bytes; | 
					
						
							|  |  |  | 	int result; | 
					
						
							|  |  |  | 	char **ptr; | 
					
						
							|  |  |  | 	char *buffer; | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *tmp = (struct vorbis_desc *)s->_private; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	tmp->writing = 0; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	ogg_sync_init(&tmp->oy); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE); | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	bytes = fread(buffer, 1, BLOCK_SIZE, s->f); | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	ogg_sync_wrote(&tmp->oy, bytes); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	result = ogg_sync_pageout(&tmp->oy, &tmp->og); | 
					
						
							|  |  |  | 	if (result != 1) { | 
					
						
							|  |  |  | 		if(bytes < BLOCK_SIZE) { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Run out of data...\n"); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_log(LOG_ERROR, "Input does not appear to be an Ogg bitstream.\n"); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 		ogg_sync_clear(&tmp->oy); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ogg_stream_init(&tmp->os, ogg_page_serialno(&tmp->og)); | 
					
						
							|  |  |  | 	vorbis_info_init(&tmp->vi); | 
					
						
							|  |  |  | 	vorbis_comment_init(&tmp->vc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ogg_stream_pagein(&tmp->os, &tmp->og) < 0) {  | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Error reading first page of Ogg bitstream data.\n"); | 
					
						
							|  |  |  | error: | 
					
						
							|  |  |  | 		ogg_stream_clear(&tmp->os); | 
					
						
							|  |  |  | 		vorbis_comment_clear(&tmp->vc); | 
					
						
							|  |  |  | 		vorbis_info_clear(&tmp->vi); | 
					
						
							|  |  |  | 		ogg_sync_clear(&tmp->oy); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (ogg_stream_packetout(&tmp->os, &tmp->op) != 1) {  | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Error reading initial header packet.\n"); | 
					
						
							|  |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op) < 0) {  | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "This Ogg bitstream does not contain Vorbis audio data.\n"); | 
					
						
							|  |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	for (i = 0; i < 2 ; ) { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		while (i < 2) { | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 			result = ogg_sync_pageout(&tmp->oy, &tmp->og); | 
					
						
							|  |  |  | 			if (result == 0) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			if (result == 1) { | 
					
						
							|  |  |  | 				ogg_stream_pagein(&tmp->os, &tmp->og); | 
					
						
							|  |  |  | 				while(i < 2) { | 
					
						
							|  |  |  | 					result = ogg_stream_packetout(&tmp->os,&tmp->op); | 
					
						
							|  |  |  | 					if(result == 0) | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					if(result < 0) { | 
					
						
							|  |  |  | 						ast_log(LOG_ERROR, "Corrupt secondary header.  Exiting.\n"); | 
					
						
							|  |  |  | 						goto error; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 					vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op); | 
					
						
							|  |  |  | 					i++; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 		buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE); | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		bytes = fread(buffer, 1, BLOCK_SIZE, s->f); | 
					
						
							|  |  |  | 		if (bytes == 0 && i < 2) { | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 			ast_log(LOG_ERROR, "End of file before finding all Vorbis headers!\n"); | 
					
						
							|  |  |  | 			goto error; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 		ogg_sync_wrote(&tmp->oy, bytes); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	for (ptr = tmp->vc.user_comments; *ptr; ptr++) | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 		ast_debug(1, "OGG/Vorbis comment: %s\n", *ptr); | 
					
						
							|  |  |  | 		ast_debug(1, "OGG/Vorbis bitstream is %d channel, %ldHz\n", tmp->vi.channels, tmp->vi.rate); | 
					
						
							|  |  |  | 		ast_debug(1, "OGG/Vorbis file encoded by: %s\n", tmp->vc.vendor); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	if (tmp->vi.channels != 1) { | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Only monophonic OGG/Vorbis files are currently supported!\n"); | 
					
						
							|  |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	if (tmp->vi.rate != DEFAULT_SAMPLE_RATE) { | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Only 8000Hz OGG/Vorbis files are currently supported!\n"); | 
					
						
							|  |  |  | 		vorbis_block_clear(&tmp->vb); | 
					
						
							|  |  |  | 		vorbis_dsp_clear(&tmp->vd); | 
					
						
							|  |  |  | 		goto error; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	vorbis_synthesis_init(&tmp->vd, &tmp->vi); | 
					
						
							|  |  |  | 	vorbis_block_init(&tmp->vd, &tmp->vb); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Create a new OGG/Vorbis filestream and set it up for writing. | 
					
						
							| 
									
										
										
										
											2006-07-19 22:40:36 +00:00
										 |  |  |  * \param s File pointer that points to on-disk storage. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  * \param comment Comment that should be embedded in the OGG/Vorbis file. | 
					
						
							|  |  |  |  * \return A new filestream. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static int ogg_vorbis_rewrite(struct ast_filestream *s, | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 						 const char *comment) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ogg_packet header; | 
					
						
							|  |  |  | 	ogg_packet header_comm; | 
					
						
							|  |  |  | 	ogg_packet header_code; | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *tmp = (struct vorbis_desc *)s->_private; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	tmp->writing = 1; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	vorbis_info_init(&tmp->vi); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	if (vorbis_encode_init_vbr(&tmp->vi, 1, DEFAULT_SAMPLE_RATE, 0.4)) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Unable to initialize Vorbis encoder!\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	vorbis_comment_init(&tmp->vc); | 
					
						
							|  |  |  | 	vorbis_comment_add_tag(&tmp->vc, "ENCODER", "Asterisk PBX"); | 
					
						
							|  |  |  | 	if (comment) | 
					
						
							|  |  |  | 		vorbis_comment_add_tag(&tmp->vc, "COMMENT", (char *) comment); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	vorbis_analysis_init(&tmp->vd, &tmp->vi); | 
					
						
							|  |  |  | 	vorbis_block_init(&tmp->vd, &tmp->vb); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-05 17:44:44 +00:00
										 |  |  | 	ogg_stream_init(&tmp->os, ast_random()); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	vorbis_analysis_headerout(&tmp->vd, &tmp->vc, &header, &header_comm, | 
					
						
							|  |  |  | 				  &header_code); | 
					
						
							|  |  |  | 	ogg_stream_packetin(&tmp->os, &header); | 
					
						
							|  |  |  | 	ogg_stream_packetin(&tmp->os, &header_comm); | 
					
						
							|  |  |  | 	ogg_stream_packetin(&tmp->os, &header_code); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	while (!tmp->eos) { | 
					
						
							|  |  |  | 		if (ogg_stream_flush(&tmp->os, &tmp->og) == 0) | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		fwrite(tmp->og.header, 1, tmp->og.header_len, s->f); | 
					
						
							|  |  |  | 		fwrite(tmp->og.body, 1, tmp->og.body_len, s->f); | 
					
						
							|  |  |  | 		if (ogg_page_eos(&tmp->og)) | 
					
						
							|  |  |  | 			tmp->eos = 1; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Write out any pending encoded data. | 
					
						
							| 
									
										
										
										
											2006-10-30 16:33:02 +00:00
										 |  |  |  * \param s An OGG/Vorbis filestream. | 
					
						
							|  |  |  |  * \param f The file to write to. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static void write_stream(struct vorbis_desc *s, FILE *f) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	while (vorbis_analysis_blockout(&s->vd, &s->vb) == 1) { | 
					
						
							|  |  |  | 		vorbis_analysis(&s->vb, NULL); | 
					
						
							|  |  |  | 		vorbis_bitrate_addblock(&s->vb); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		while (vorbis_bitrate_flushpacket(&s->vd, &s->op)) { | 
					
						
							|  |  |  | 			ogg_stream_packetin(&s->os, &s->op); | 
					
						
							|  |  |  | 			while (!s->eos) { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 				if (ogg_stream_pageout(&s->os, &s->og) == 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 				fwrite(s->og.header, 1, s->og.header_len, f); | 
					
						
							|  |  |  | 				fwrite(s->og.body, 1, s->og.body_len, f); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 				if (ogg_page_eos(&s->og)) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 					s->eos = 1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Write audio data from a frame to an OGG/Vorbis filestream. | 
					
						
							| 
									
										
										
										
											2006-10-30 16:33:02 +00:00
										 |  |  |  * \param fs An OGG/Vorbis filestream. | 
					
						
							|  |  |  |  * \param f A frame containing audio to be written to the filestream. | 
					
						
							|  |  |  |  * \return -1 if there was an error, 0 on success. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static int ogg_vorbis_write(struct ast_filestream *fs, struct ast_frame *f) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	float **buffer; | 
					
						
							|  |  |  | 	short *data; | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *s = (struct vorbis_desc *)fs->_private; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (!s->writing) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "This stream is not set up for writing!\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (f->frametype != AST_FRAME_VOICE) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (f->subclass != AST_FORMAT_SLINEAR) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Asked to write non-SLINEAR frame (%d)!\n", | 
					
						
							|  |  |  | 				f->subclass); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (!f->datalen) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	data = (short *) f->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buffer = vorbis_analysis_buffer(&s->vd, f->samples); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	for (i = 0; i < f->samples; i++) | 
					
						
							|  |  |  | 		buffer[0][i] = (double)data[i] / 32768.0; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	vorbis_analysis_wrote(&s->vd, f->samples); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	write_stream(s, fs->f); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Close a OGG/Vorbis filestream. | 
					
						
							| 
									
										
										
										
											2006-07-19 22:40:36 +00:00
										 |  |  |  * \param fs A OGG/Vorbis filestream. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static void ogg_vorbis_close(struct ast_filestream *fs) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *s = (struct vorbis_desc *)fs->_private; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (s->writing) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		/* Tell the Vorbis encoder that the stream is finished
 | 
					
						
							|  |  |  | 		 * and write out the rest of the data */ | 
					
						
							|  |  |  | 		vorbis_analysis_wrote(&s->vd, 0); | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		write_stream(s, fs->f); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ogg_stream_clear(&s->os); | 
					
						
							|  |  |  | 	vorbis_block_clear(&s->vb); | 
					
						
							|  |  |  | 	vorbis_dsp_clear(&s->vd); | 
					
						
							|  |  |  | 	vorbis_comment_clear(&s->vc); | 
					
						
							|  |  |  | 	vorbis_info_clear(&s->vi); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (s->writing) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		ogg_sync_clear(&s->oy); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Get audio data. | 
					
						
							| 
									
										
										
										
											2006-07-19 22:40:36 +00:00
										 |  |  |  * \param fs An OGG/Vorbis filestream. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  * \param pcm Pointer to a buffere to store audio data in. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static int read_samples(struct ast_filestream *fs, float ***pcm) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int samples_in; | 
					
						
							|  |  |  | 	int result; | 
					
						
							|  |  |  | 	char *buffer; | 
					
						
							|  |  |  | 	int bytes; | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *s = (struct vorbis_desc *)fs->_private; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (1) { | 
					
						
							|  |  |  | 		samples_in = vorbis_synthesis_pcmout(&s->vd, pcm); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		if (samples_in > 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			return samples_in; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		/* The Vorbis decoder needs more data... */ | 
					
						
							|  |  |  | 		/* See ifOGG has any packets in the current page for the Vorbis decoder. */ | 
					
						
							|  |  |  | 		result = ogg_stream_packetout(&s->os, &s->op); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		if (result > 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			/* Yes OGG had some more packets for the Vorbis decoder. */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 			if (vorbis_synthesis(&s->vb, &s->op) == 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				vorbis_synthesis_blockin(&s->vd, &s->vb); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		if (result < 0) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 					"Corrupt or missing data at this page position; continuing...\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		/* No more packets left in the current page... */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		if (s->eos) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			/* No more pages left in the stream */ | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (!s->eos) { | 
					
						
							|  |  |  | 			/* See ifOGG has any pages in it's internal buffers */ | 
					
						
							|  |  |  | 			result = ogg_sync_pageout(&s->oy, &s->og); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 			if (result > 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				/* Yes, OGG has more pages in it's internal buffers,
 | 
					
						
							|  |  |  | 				   add the page to the stream state */ | 
					
						
							|  |  |  | 				result = ogg_stream_pagein(&s->os, &s->og); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 				if (result == 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 					/* Yes, got a new,valid page */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 					if (ogg_page_eos(&s->og)) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 						s->eos = 1; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 				ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 						"Invalid page in the bitstream; continuing...\n"); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (result < 0) | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, | 
					
						
							|  |  |  | 						"Corrupt or missing data in bitstream; continuing...\n"); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* No, we need to read more data from the file descrptor */ | 
					
						
							|  |  |  | 			/* get a buffer from OGG to read the data into */ | 
					
						
							|  |  |  | 			buffer = ogg_sync_buffer(&s->oy, BLOCK_SIZE); | 
					
						
							|  |  |  | 			/* read more data from the file descriptor */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 			bytes = fread(buffer, 1, BLOCK_SIZE, fs->f); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			/* Tell OGG how many bytes we actually read into the buffer */ | 
					
						
							|  |  |  | 			ogg_sync_wrote(&s->oy, bytes); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 			if (bytes == 0) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				s->eos = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Read a frame full of audio data from the filestream. | 
					
						
							| 
									
										
										
										
											2006-07-19 22:40:36 +00:00
										 |  |  |  * \param fs The filestream. | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  |  * \param whennext Number of sample times to schedule the next call. | 
					
						
							|  |  |  |  * \return A pointer to a frame containing audio data or NULL ifthere is no more audio data. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static struct ast_frame *ogg_vorbis_read(struct ast_filestream *fs, | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 					 int *whennext) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int clipflag = 0; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int j; | 
					
						
							|  |  |  | 	double accumulator[SAMPLES_MAX]; | 
					
						
							|  |  |  | 	int val; | 
					
						
							|  |  |  | 	int samples_in; | 
					
						
							|  |  |  | 	int samples_out = 0; | 
					
						
							| 
									
										
										
										
											2007-11-29 17:50:44 +00:00
										 |  |  | 	struct vorbis_desc *s = (struct vorbis_desc *)fs->_private; | 
					
						
							| 
									
										
										
										
											2006-09-25 14:49:56 +00:00
										 |  |  | 	short *buf;	/* SLIN data buffer */ | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	fs->fr.frametype = AST_FRAME_VOICE; | 
					
						
							|  |  |  | 	fs->fr.subclass = AST_FORMAT_SLINEAR; | 
					
						
							|  |  |  | 	fs->fr.mallocd = 0; | 
					
						
							| 
									
										
										
										
											2006-04-09 22:31:38 +00:00
										 |  |  | 	AST_FRAME_SET_BUFFER(&fs->fr, fs->buf, AST_FRIENDLY_OFFSET, BUF_SIZE); | 
					
						
							| 
									
										
										
										
											2006-09-25 14:49:56 +00:00
										 |  |  | 	buf = (short *)(fs->fr.data);	/* SLIN data buffer */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	while (samples_out != SAMPLES_MAX) { | 
					
						
							|  |  |  | 		float **pcm; | 
					
						
							|  |  |  | 		int len = SAMPLES_MAX - samples_out; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* See ifVorbis decoder has some audio data for us ... */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		samples_in = read_samples(fs, &pcm); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		if (samples_in <= 0) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* Got some audio data from Vorbis... */ | 
					
						
							|  |  |  | 		/* Convert the float audio data to 16-bit signed linear */ | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		clipflag = 0; | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		if (samples_in > len) | 
					
						
							|  |  |  | 			samples_in = len; | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		for (j = 0; j < samples_in; j++) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 			accumulator[j] = 0.0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 		for (i = 0; i < s->vi.channels; i++) { | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 			float *mono = pcm[i]; | 
					
						
							|  |  |  | 			for (j = 0; j < samples_in; j++) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				accumulator[j] += mono[j]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (j = 0; j < samples_in; j++) { | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 			val = accumulator[j] * 32767.0 / s->vi.channels; | 
					
						
							|  |  |  | 			if (val > 32767) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				val = 32767; | 
					
						
							|  |  |  | 				clipflag = 1; | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 			} else if (val < -32768) { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 				val = -32768; | 
					
						
							|  |  |  | 				clipflag = 1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 			buf[samples_out + j] = val; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (clipflag) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Clipping in frame %ld\n", (long) (s->vd.sequence)); | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		/* Tell the Vorbis decoder how many samples we actually used. */ | 
					
						
							|  |  |  | 		vorbis_synthesis_read(&s->vd, samples_in); | 
					
						
							|  |  |  | 		samples_out += samples_in; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 	if (samples_out > 0) { | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		fs->fr.datalen = samples_out * 2; | 
					
						
							|  |  |  | 		fs->fr.samples = samples_out; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 		*whennext = samples_out; | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 		return &fs->fr; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Trucate an OGG/Vorbis filestream. | 
					
						
							|  |  |  |  * \param s The filestream to truncate. | 
					
						
							|  |  |  |  * \return 0 on success, -1 on failure. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int ogg_vorbis_trunc(struct ast_filestream *s) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ast_log(LOG_WARNING, "Truncation is not supported on OGG/Vorbis streams!\n"); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Seek to a specific position in an OGG/Vorbis filestream. | 
					
						
							|  |  |  |  * \param s The filestream to truncate. | 
					
						
							|  |  |  |  * \param sample_offset New position for the filestream, measured in 8KHz samples. | 
					
						
							|  |  |  |  * \param whence Location to measure  | 
					
						
							|  |  |  |  * \return 0 on success, -1 on failure. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | static int ogg_vorbis_seek(struct ast_filestream *s, off_t sample_offset, int whence) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	ast_log(LOG_WARNING, "Seeking is not supported on OGG/Vorbis streams!\n"); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-20 23:35:12 +00:00
										 |  |  | static off_t ogg_vorbis_tell(struct ast_filestream *s) | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 	ast_log(LOG_WARNING, "Telling is not supported on OGG/Vorbis streams!\n"); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | static const struct ast_format vorbis_f = { | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	.name = "ogg_vorbis", | 
					
						
							|  |  |  | 	.exts = "ogg", | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	.format = AST_FORMAT_SLINEAR, | 
					
						
							|  |  |  | 	.open = ogg_vorbis_open, | 
					
						
							|  |  |  | 	.rewrite = ogg_vorbis_rewrite, | 
					
						
							|  |  |  | 	.write = ogg_vorbis_write, | 
					
						
							|  |  |  | 	.seek =	ogg_vorbis_seek, | 
					
						
							|  |  |  | 	.trunc = ogg_vorbis_trunc, | 
					
						
							|  |  |  | 	.tell = ogg_vorbis_tell, | 
					
						
							|  |  |  | 	.read = ogg_vorbis_read, | 
					
						
							|  |  |  | 	.close = ogg_vorbis_close, | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	.buf_size = BUF_SIZE + AST_FRIENDLY_OFFSET, | 
					
						
							| 
									
										
										
										
											2006-04-04 12:59:25 +00:00
										 |  |  | 	.desc_size = sizeof(struct vorbis_desc), | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-10-31 19:24:29 +00:00
										 |  |  | 	if (ast_format_register(&vorbis_f)) | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_FAILURE; | 
					
						
							|  |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-04 15:40:47 +00:00
										 |  |  | 	return ast_format_unregister(vorbis_f.name); | 
					
						
							| 
									
										
										
										
											2006-02-12 04:28:58 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-07-20 00:25:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "OGG/Vorbis audio"); | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  | 
 |