2007-03-29 22:34:40 +00:00
/*
* FreeSWITCH Modular Media Switching Software Library / Soft - Switch Application
2009-02-13 23:37:37 +00:00
* Copyright ( C ) 2005 - 2009 , Anthony Minessale II < anthm @ freeswitch . org >
2007-03-29 22:34:40 +00:00
*
* Version : MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 ( the " License " ) ; you may not use this file except in compliance with
* the License . You may obtain a copy of the License at
* http : //www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
* for the specific language governing rights and limitations under the
* License .
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft - Switch Application
*
* The Initial Developer of the Original Code is
2009-02-04 21:20:54 +00:00
* Anthony Minessale II < anthm @ freeswitch . org >
2007-03-29 22:34:40 +00:00
* Portions created by the Initial Developer are Copyright ( C )
* the Initial Developer . All Rights Reserved .
*
* Contributor ( s ) :
*
2009-02-04 21:20:54 +00:00
* Anthony Minessale II < anthm @ freeswitch . org >
2007-03-29 22:34:40 +00:00
* Michael Jerris < mike @ jerris . com >
* Paul D . Tinsley < pdt at jackhammer . org >
*
*
* switch_core_media_bug . c - - Main Core Library ( Media Bugs )
*
*/
2008-01-27 17:36:53 +00:00
2007-03-29 22:34:40 +00:00
# include "switch.h"
2007-05-14 17:10:46 +00:00
# include "private/switch_core_pvt.h"
2007-03-29 22:34:40 +00:00
static void switch_core_media_bug_destroy ( switch_media_bug_t * bug )
{
2009-01-21 18:41:53 +00:00
if ( bug - > raw_read_buffer ) {
switch_buffer_destroy ( & bug - > raw_read_buffer ) ;
}
if ( bug - > raw_write_buffer ) {
switch_buffer_destroy ( & bug - > raw_write_buffer ) ;
}
2007-03-29 22:34:40 +00:00
}
2009-01-23 18:44:25 +00:00
SWITCH_DECLARE ( void ) switch_core_media_bug_pause ( switch_core_session_t * session )
{
switch_channel_set_flag ( session - > channel , CF_PAUSE_BUGS ) ;
}
SWITCH_DECLARE ( void ) switch_core_media_bug_resume ( switch_core_session_t * session )
{
switch_channel_clear_flag ( session - > channel , CF_PAUSE_BUGS ) ;
}
2007-11-23 18:35:38 +00:00
SWITCH_DECLARE ( uint32_t ) switch_core_media_bug_test_flag ( switch_media_bug_t * bug , uint32_t flag )
{
return switch_test_flag ( bug , flag ) ;
}
SWITCH_DECLARE ( switch_core_session_t * ) switch_core_media_bug_get_session ( switch_media_bug_t * bug )
{
return bug - > session ;
}
2007-03-29 22:34:40 +00:00
2007-06-13 03:09:53 +00:00
SWITCH_DECLARE ( switch_frame_t * ) switch_core_media_bug_get_write_replace_frame ( switch_media_bug_t * bug )
2007-03-29 22:34:40 +00:00
{
2007-06-13 03:09:53 +00:00
return bug - > write_replace_frame_in ;
2007-03-29 22:34:40 +00:00
}
2007-06-13 03:09:53 +00:00
SWITCH_DECLARE ( void ) switch_core_media_bug_set_write_replace_frame ( switch_media_bug_t * bug , switch_frame_t * frame )
2007-03-29 22:34:40 +00:00
{
2007-06-13 03:09:53 +00:00
bug - > write_replace_frame_out = frame ;
}
SWITCH_DECLARE ( switch_frame_t * ) switch_core_media_bug_get_read_replace_frame ( switch_media_bug_t * bug )
{
return bug - > read_replace_frame_in ;
}
SWITCH_DECLARE ( void ) switch_core_media_bug_set_read_replace_frame ( switch_media_bug_t * bug , switch_frame_t * frame )
{
bug - > read_replace_frame_out = frame ;
2007-03-29 22:34:40 +00:00
}
SWITCH_DECLARE ( void * ) switch_core_media_bug_get_user_data ( switch_media_bug_t * bug )
{
return bug - > user_data ;
}
2008-11-12 11:44:13 +00:00
SWITCH_DECLARE ( void ) switch_core_media_bug_flush ( switch_media_bug_t * bug )
{
2008-11-12 19:45:21 +00:00
if ( bug - > raw_read_buffer ) {
switch_buffer_zero ( bug - > raw_read_buffer ) ;
}
if ( bug - > raw_write_buffer ) {
switch_buffer_zero ( bug - > raw_write_buffer ) ;
}
2008-11-12 11:44:13 +00:00
}
2009-07-06 22:21:45 +00:00
SWITCH_DECLARE ( void ) switch_core_media_bug_inuse ( switch_media_bug_t * bug , switch_size_t * readp , switch_size_t * writep )
{
if ( switch_test_flag ( bug , SMBF_READ_STREAM ) ) {
switch_mutex_lock ( bug - > read_mutex ) ;
* readp = bug - > raw_read_buffer ? switch_buffer_inuse ( bug - > raw_read_buffer ) : 0 ;
switch_mutex_unlock ( bug - > read_mutex ) ;
} else {
* readp = 0 ;
}
if ( switch_test_flag ( bug , SMBF_WRITE_STREAM ) ) {
switch_mutex_lock ( bug - > write_mutex ) ;
* writep = bug - > raw_write_buffer ? switch_buffer_inuse ( bug - > raw_write_buffer ) : 0 ;
switch_mutex_unlock ( bug - > write_mutex ) ;
} else {
* writep = 0 ;
}
}
2009-06-05 19:52:02 +00:00
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_read ( switch_media_bug_t * bug , switch_frame_t * frame , switch_bool_t fill )
2007-03-29 22:34:40 +00:00
{
2009-07-03 21:55:50 +00:00
switch_size_t bytes = 0 , datalen = 0 , ttl = 0 ;
2007-03-29 22:34:40 +00:00
int16_t * dp , * fp ;
uint32_t x ;
size_t rlen = 0 ;
size_t wlen = 0 ;
uint32_t blen ;
2009-02-10 19:09:06 +00:00
switch_codec_implementation_t read_impl = { 0 } ;
2009-03-02 19:30:41 +00:00
int16_t * tp ;
2009-02-10 19:09:06 +00:00
switch_core_session_get_read_impl ( bug - > session , & read_impl ) ;
2007-03-29 22:34:40 +00:00
2009-03-02 19:30:41 +00:00
bytes = read_impl . decoded_bytes_per_packet ;
2007-03-29 22:34:40 +00:00
2009-03-02 19:30:41 +00:00
if ( frame - > buflen < bytes ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( switch_core_media_bug_get_session ( bug ) ) , SWITCH_LOG_ERROR , " %s frame buffer too small! \n " , switch_channel_get_name ( bug - > session - > channel ) ) ;
2007-03-29 22:34:40 +00:00
return SWITCH_STATUS_FALSE ;
}
2009-03-02 19:30:41 +00:00
2009-03-04 23:15:13 +00:00
if ( ! ( bug - > raw_read_buffer & & ( bug - > raw_write_buffer | | ! switch_test_flag ( bug , SMBF_WRITE_STREAM ) ) ) ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( switch_core_media_bug_get_session ( bug ) ) , SWITCH_LOG_ERROR , " %s Buffer Error \n " , switch_channel_get_name ( bug - > session - > channel ) ) ;
2009-03-05 04:49:19 +00:00
return SWITCH_STATUS_FALSE ;
2007-03-29 22:34:40 +00:00
}
2009-07-03 21:55:50 +00:00
frame - > flags = 0 ;
2007-03-29 22:34:40 +00:00
frame - > datalen = 0 ;
2009-07-06 22:21:45 +00:00
if ( ! switch_buffer_inuse ( bug - > raw_read_buffer ) ) {
return SWITCH_STATUS_FALSE ;
}
2009-03-02 19:30:41 +00:00
switch_mutex_lock ( bug - > read_mutex ) ;
frame - > datalen = ( uint32_t ) switch_buffer_read ( bug - > raw_read_buffer , frame - > data , bytes ) ;
2009-07-03 21:55:50 +00:00
ttl + = frame - > datalen ;
2009-03-02 19:30:41 +00:00
switch_mutex_unlock ( bug - > read_mutex ) ;
2009-03-04 23:15:13 +00:00
if ( switch_test_flag ( bug , SMBF_WRITE_STREAM ) ) {
2009-03-05 04:49:19 +00:00
switch_assert ( bug - > raw_write_buffer ) ;
2009-03-04 23:15:13 +00:00
switch_mutex_lock ( bug - > write_mutex ) ;
datalen = ( uint32_t ) switch_buffer_read ( bug - > raw_write_buffer , bug - > data , bytes ) ;
2009-07-03 21:55:50 +00:00
ttl + = datalen ;
2009-06-05 19:52:02 +00:00
if ( fill & & datalen < bytes ) {
2009-03-04 23:15:13 +00:00
memset ( ( ( unsigned char * ) bug - > data ) + datalen , 0 , bytes - datalen ) ;
datalen = bytes ;
}
switch_mutex_unlock ( bug - > write_mutex ) ;
2007-03-29 22:34:40 +00:00
}
2009-03-02 19:30:41 +00:00
tp = bug - > tmp ;
dp = ( int16_t * ) bug - > data ;
fp = ( int16_t * ) frame - > data ;
rlen = frame - > datalen / 2 ;
wlen = datalen / 2 ;
blen = bytes / 2 ;
2009-06-05 19:52:02 +00:00
if ( ! fill & & rlen = = 0 & & wlen = = 0 ) {
frame - > datalen = 0 ;
frame - > samples = 0 ;
frame - > rate = read_impl . actual_samples_per_second ;
frame - > codec = NULL ;
return SWITCH_STATUS_FALSE ;
}
2009-03-02 19:30:41 +00:00
if ( switch_test_flag ( bug , SMBF_STEREO ) ) {
for ( x = 0 ; x < blen ; x + + ) {
if ( x < rlen ) {
* ( tp + + ) = * ( fp + x ) ;
} else {
* ( tp + + ) = 0 ;
2007-03-29 22:34:40 +00:00
}
2009-03-02 19:30:41 +00:00
if ( x < wlen ) {
* ( tp + + ) = * ( dp + x ) ;
} else {
* ( tp + + ) = 0 ;
2007-03-29 22:34:40 +00:00
}
}
2009-03-02 19:30:41 +00:00
memcpy ( frame - > data , bug - > tmp , bytes * 2 ) ;
} else {
for ( x = 0 ; x < blen ; x + + ) {
int32_t z = 0 ;
2007-03-29 22:34:40 +00:00
2009-03-02 19:30:41 +00:00
if ( x < rlen ) {
z + = ( int32_t ) * ( fp + x ) ;
}
if ( x < wlen ) {
z + = ( int32_t ) * ( dp + x ) ;
}
switch_normalize_to_16bit ( z ) ;
* ( fp + x ) = ( int16_t ) z / 2 ;
}
2007-03-29 22:34:40 +00:00
}
2008-05-27 04:30:03 +00:00
2009-07-03 21:55:50 +00:00
if ( ! ttl ) {
switch_set_flag ( frame , SFF_CNG ) ;
}
2009-03-02 19:30:41 +00:00
frame - > datalen = bytes ;
frame - > samples = bytes / sizeof ( int16_t ) ;
frame - > rate = read_impl . actual_samples_per_second ;
frame - > codec = NULL ;
return SWITCH_STATUS_SUCCESS ;
2007-03-29 22:34:40 +00:00
}
# define MAX_BUG_BUFFER 1024 * 512
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_add ( switch_core_session_t * session ,
switch_media_bug_callback_t callback ,
2007-05-31 14:42:23 +00:00
void * user_data , time_t stop_time , switch_media_bug_flag_t flags , switch_media_bug_t * * new_bug )
2007-03-29 22:34:40 +00:00
{
2008-05-27 04:30:03 +00:00
switch_media_bug_t * bug ; //, *bp;
2007-03-29 22:34:40 +00:00
switch_size_t bytes ;
2009-02-16 14:15:38 +00:00
switch_codec_implementation_t read_impl = { 0 } ;
switch_codec_implementation_t write_impl = { 0 } ;
if ( ! switch_channel_media_ready ( session - > channel ) ) {
if ( switch_channel_pre_answer ( session - > channel ) ! = SWITCH_STATUS_SUCCESS ) {
return SWITCH_STATUS_FALSE ;
}
}
switch_core_session_get_read_impl ( session , & read_impl ) ;
switch_core_session_get_write_impl ( session , & write_impl ) ;
2007-03-29 22:34:40 +00:00
2009-01-21 18:41:53 +00:00
* new_bug = NULL ;
2007-06-19 18:25:17 +00:00
#if 0
2009-01-21 18:41:53 +00:00
if ( flags & SMBF_WRITE_REPLACE ) {
2007-03-29 22:34:40 +00:00
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
for ( bp = session - > bugs ; bp ; bp = bp - > next ) {
if ( switch_test_flag ( bp , SMBF_WRITE_REPLACE ) ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_ERROR , " Only one bug of this type allowed! \n " ) ;
2007-03-29 22:34:40 +00:00
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
return SWITCH_STATUS_GENERR ;
}
}
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
}
2007-06-13 03:09:53 +00:00
if ( flags & SMBF_READ_REPLACE ) {
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
for ( bp = session - > bugs ; bp ; bp = bp - > next ) {
if ( switch_test_flag ( bp , SMBF_READ_REPLACE ) ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_ERROR , " Only one bug of this type allowed! \n " ) ;
2007-06-13 03:09:53 +00:00
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
return SWITCH_STATUS_GENERR ;
}
}
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
}
2009-01-21 18:41:53 +00:00
# endif
2007-06-13 03:09:53 +00:00
2007-03-29 22:34:40 +00:00
if ( ! ( bug = switch_core_session_alloc ( session , sizeof ( * bug ) ) ) ) {
return SWITCH_STATUS_MEMERR ;
}
bug - > callback = callback ;
bug - > user_data = user_data ;
bug - > session = session ;
bug - > flags = flags ;
2008-01-14 19:20:59 +00:00
2007-05-31 14:42:23 +00:00
bug - > stop_time = stop_time ;
2009-02-16 14:15:38 +00:00
bytes = read_impl . decoded_bytes_per_packet ;
2007-03-29 22:34:40 +00:00
if ( ! bug - > flags ) {
bug - > flags = ( SMBF_READ_STREAM | SMBF_WRITE_STREAM ) ;
}
2008-01-14 19:20:59 +00:00
if ( switch_test_flag ( bug , SMBF_READ_STREAM ) | | switch_test_flag ( bug , SMBF_READ_PING ) ) {
2007-03-30 00:13:31 +00:00
switch_buffer_create_dynamic ( & bug - > raw_read_buffer , bytes * SWITCH_BUFFER_BLOCK_FRAMES , bytes * SWITCH_BUFFER_START_FRAMES , MAX_BUG_BUFFER ) ;
2007-03-29 22:34:40 +00:00
switch_mutex_init ( & bug - > read_mutex , SWITCH_MUTEX_NESTED , session - > pool ) ;
}
2009-02-16 14:15:38 +00:00
bytes = write_impl . decoded_bytes_per_packet ;
2007-03-29 22:34:40 +00:00
if ( switch_test_flag ( bug , SMBF_WRITE_STREAM ) ) {
2007-03-30 00:13:31 +00:00
switch_buffer_create_dynamic ( & bug - > raw_write_buffer , bytes * SWITCH_BUFFER_BLOCK_FRAMES , bytes * SWITCH_BUFFER_START_FRAMES , MAX_BUG_BUFFER ) ;
2007-03-29 22:34:40 +00:00
switch_mutex_init ( & bug - > write_mutex , SWITCH_MUTEX_NESTED , session - > pool ) ;
}
2008-01-21 17:14:43 +00:00
if ( ( bug - > flags & SMBF_THREAD_LOCK ) ) {
bug - > thread_id = switch_thread_self ( ) ;
}
2009-01-20 13:55:00 +00:00
if ( bug - > callback ) {
switch_bool_t result = bug - > callback ( bug , bug - > user_data , SWITCH_ABC_TYPE_INIT ) ;
if ( result = = SWITCH_FALSE ) {
2009-01-21 18:41:53 +00:00
switch_core_media_bug_destroy ( bug ) ;
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_ERROR , " Error attaching BUG to %s \n " , switch_channel_get_name ( session - > channel ) ) ;
2009-01-20 13:55:00 +00:00
return SWITCH_STATUS_GENERR ;
}
}
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_DEBUG , " Attaching BUG to %s \n " , switch_channel_get_name ( session - > channel ) ) ;
2008-01-14 19:20:59 +00:00
bug - > ready = 1 ;
2007-03-29 22:34:40 +00:00
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
bug - > next = session - > bugs ;
session - > bugs = bug ;
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
* new_bug = bug ;
return SWITCH_STATUS_SUCCESS ;
}
2008-11-12 11:44:13 +00:00
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_flush_all ( switch_core_session_t * session )
{
switch_media_bug_t * bp ;
if ( session - > bugs ) {
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
for ( bp = session - > bugs ; bp ; bp = bp - > next ) {
switch_core_media_bug_flush ( bp ) ;
}
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
return SWITCH_STATUS_SUCCESS ;
}
return SWITCH_STATUS_FALSE ;
}
2007-03-29 22:34:40 +00:00
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_remove_all ( switch_core_session_t * session )
{
switch_media_bug_t * bp ;
2008-11-12 11:44:13 +00:00
switch_status_t status = SWITCH_STATUS_FALSE ;
2007-03-29 22:34:40 +00:00
if ( session - > bugs ) {
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
for ( bp = session - > bugs ; bp ; bp = bp - > next ) {
2008-01-21 17:14:43 +00:00
if ( bp - > thread_id & & bp - > thread_id ! = switch_thread_self ( ) ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_DEBUG , " BUG is thread locked skipping. \n " ) ;
2008-01-21 17:14:43 +00:00
continue ;
}
2007-03-29 22:34:40 +00:00
if ( bp - > callback ) {
bp - > callback ( bp , bp - > user_data , SWITCH_ABC_TYPE_CLOSE ) ;
}
switch_core_media_bug_destroy ( bp ) ;
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( session ) , SWITCH_LOG_DEBUG , " Removing BUG from %s \n " , switch_channel_get_name ( session - > channel ) ) ;
2007-03-29 22:34:40 +00:00
}
session - > bugs = NULL ;
2008-02-14 01:53:20 +00:00
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
2008-11-12 11:44:13 +00:00
status = SWITCH_STATUS_SUCCESS ;
2007-03-29 22:34:40 +00:00
}
2008-05-27 04:30:03 +00:00
2009-04-09 17:17:12 +00:00
if ( switch_core_codec_ready ( & session - > bug_codec ) ) {
2008-03-17 23:26:38 +00:00
switch_core_codec_destroy ( & session - > bug_codec ) ;
2008-10-29 00:04:20 +00:00
memset ( & session - > bug_codec , 0 , sizeof ( session - > bug_codec ) ) ;
2008-03-17 23:26:38 +00:00
}
2008-11-12 11:44:13 +00:00
return status ;
2007-03-29 22:34:40 +00:00
}
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_close ( switch_media_bug_t * * bug )
{
switch_media_bug_t * bp = * bug ;
if ( bp ) {
2008-01-21 17:14:43 +00:00
if ( bp - > thread_id & & bp - > thread_id ! = switch_thread_self ( ) ) {
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( switch_core_media_bug_get_session ( * bug ) ) , SWITCH_LOG_DEBUG , " BUG is thread locked skipping. \n " ) ;
2008-01-21 17:14:43 +00:00
return SWITCH_STATUS_FALSE ;
}
2007-03-29 22:34:40 +00:00
if ( bp - > callback ) {
bp - > callback ( bp , bp - > user_data , SWITCH_ABC_TYPE_CLOSE ) ;
bp - > ready = 0 ;
}
switch_core_media_bug_destroy ( bp ) ;
2009-08-13 20:35:02 +00:00
switch_log_printf ( SWITCH_CHANNEL_SESSION_LOG ( switch_core_media_bug_get_session ( * bug ) ) , SWITCH_LOG_DEBUG , " Removing BUG from %s \n " , switch_channel_get_name ( bp - > session - > channel ) ) ;
2007-03-29 22:34:40 +00:00
* bug = NULL ;
return SWITCH_STATUS_SUCCESS ;
}
2008-05-27 04:30:03 +00:00
2007-03-29 22:34:40 +00:00
return SWITCH_STATUS_FALSE ;
}
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_remove ( switch_core_session_t * session , switch_media_bug_t * * bug )
{
switch_media_bug_t * bp = NULL , * last = NULL ;
switch_status_t status = SWITCH_STATUS_FALSE ;
if ( session - > bugs ) {
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
for ( bp = session - > bugs ; bp ; bp = bp - > next ) {
2009-03-05 01:15:17 +00:00
if ( ( ! bp - > thread_id | | bp - > thread_id = = switch_thread_self ( ) ) & & bp - > ready & & bp = = * bug ) {
2007-03-29 22:34:40 +00:00
if ( last ) {
last - > next = bp - > next ;
} else {
session - > bugs = bp - > next ;
}
break ;
}
2009-03-05 01:15:17 +00:00
2007-03-29 22:34:40 +00:00
last = bp ;
}
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
2009-01-21 18:41:53 +00:00
if ( bp ) {
status = switch_core_media_bug_close ( & bp ) ;
}
2007-03-29 22:34:40 +00:00
}
2008-10-29 00:04:20 +00:00
2009-04-09 17:17:12 +00:00
if ( ! session - > bugs & & switch_core_codec_ready ( & session - > bug_codec ) ) {
2008-03-17 23:26:38 +00:00
switch_core_codec_destroy ( & session - > bug_codec ) ;
2008-10-29 00:04:20 +00:00
memset ( & session - > bug_codec , 0 , sizeof ( session - > bug_codec ) ) ;
2008-03-17 23:26:38 +00:00
}
2008-05-27 04:30:03 +00:00
2007-03-29 22:34:40 +00:00
return status ;
}
2008-01-27 05:02:52 +00:00
2009-03-05 01:15:17 +00:00
SWITCH_DECLARE ( switch_status_t ) switch_core_media_bug_remove_callback ( switch_core_session_t * session , switch_media_bug_callback_t callback )
{
switch_media_bug_t * cur = NULL , * bp = NULL , * last = NULL ;
int total = 0 ;
if ( session - > bugs ) {
switch_thread_rwlock_wrlock ( session - > bug_rwlock ) ;
bp = session - > bugs ;
while ( bp ) {
cur = bp ;
bp = bp - > next ;
if ( ( ! cur - > thread_id | | cur - > thread_id = = switch_thread_self ( ) ) & & cur - > ready & & cur - > callback = = callback ) {
if ( last ) {
last - > next = cur - > next ;
} else {
session - > bugs = cur - > next ;
}
if ( switch_core_media_bug_close ( & cur ) = = SWITCH_STATUS_SUCCESS ) {
total + + ;
}
} else {
last = cur ;
}
}
switch_thread_rwlock_unlock ( session - > bug_rwlock ) ;
}
2009-04-09 17:17:12 +00:00
if ( ! session - > bugs & & switch_core_codec_ready ( & session - > bug_codec ) ) {
2009-03-05 01:15:17 +00:00
switch_core_codec_destroy ( & session - > bug_codec ) ;
memset ( & session - > bug_codec , 0 , sizeof ( session - > bug_codec ) ) ;
}
return total ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE ;
}
2008-01-27 05:02:52 +00:00
/* For Emacs:
* Local Variables :
* mode : c
2008-02-03 22:14:57 +00:00
* indent - tabs - mode : t
2008-01-27 05:02:52 +00:00
* tab - width : 4
* c - basic - offset : 4
* End :
* For VIM :
2008-07-03 19:12:26 +00:00
* vim : set softtabstop = 4 shiftwidth = 4 tabstop = 4 :
2008-01-27 05:02:52 +00:00
*/