1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Asterisk  - -  An  open  source  telephony  toolkit . 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Copyright  ( C )  1999  -  2006 ,  Digium ,  Inc . 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2004-12-06 21:53:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  Mark  Spencer  < markster @ digium . com > 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											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 . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 *  This  program  is  free  software ,  distributed  under  the  terms  of 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  the  GNU  General  Public  License  Version  2.  See  the  LICENSE  file 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  at  the  top  of  the  source  tree . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 20:12:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \file
  
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 20:12:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  \ brief  Translate  via  the  use  of  pseudo  channels 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-30 21:18:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ author  Mark  Spencer  < markster @ digium . com >  
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-07 18:54:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "asterisk.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ASTERISK_FILE_VERSION ( __FILE__ ,  " $Revision$ " )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-04-22 13:11:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <sys/time.h> 
  
						 
					
						
							
								
									
										
										
										
											2007-09-29 00:19:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <sys/resource.h> 
  
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <math.h> 
  
						 
					
						
							
								
									
										
										
										
											2005-04-22 13:11:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-04-21 06:02:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "asterisk/lock.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "asterisk/channel.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "asterisk/translate.h" 
  
						 
					
						
							
								
									
										
										
										
											2006-04-14 14:08:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "asterisk/module.h" 
  
						 
					
						
							
								
									
										
										
										
											2005-04-21 06:02:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  "asterisk/frame.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "asterisk/sched.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "asterisk/cli.h" 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  "asterisk/term.h" 
  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-20 22:53:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# define MAX_RECALC 1000  /* max sample recalc */ 
  
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief the list of translators */  
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  AST_RWLIST_HEAD_STATIC ( translators ,  ast_translator ) ;  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*! \brief these values indicate how a translation path will affect the sample rate
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *   \ note  These  must  stay  in  this  order .   They  are  ordered  by  most  optimal  selection  first . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								enum  path_samp_change  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RATE_CHANGE_NONE  =  0 ,  /*!< path uses the same sample rate consistently */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RATE_CHANGE_UPSAMP  =  1 ,  /*!< path will up the sample rate during a translation */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RATE_CHANGE_DOWNSAMP  =  2 ,  /*!< path will have to down the sample rate during a translation. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									RATE_CHANGE_UPSAMP_DOWNSAMP  =  3 ,  /*!< path will both up and down the sample rate during translation */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  translator_path  {  
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_translator  * step ; 	/*!< Next step translator */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									unsigned  int  cost ; 		/*!< Complete cost to destination */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									unsigned  int  multistep ; 		/*!< Multiple conversions required for this translation */ 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									enum  path_samp_change  rate_change ;  /*!< does this path require a sample rate change, if so what kind. */ 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief a matrix that, for any pair of supported formats,
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  indicates  the  total  cost  of  translation  and  the  first  step . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  The  full  path  can  be  reconstricted  iterating  on  the  matrix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  until  step - > dstfmt  = =  desired_format . 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-17 16:42:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Array  indexes  are  ' src '  and  ' dest ' ,  in  that  order . 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Note :  the  lock  in  the  ' translators '  list  is  also  used  to  protect 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  this  structure . 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  struct  translator_path  tr_matrix [ MAX_FORMAT ] [ MAX_FORMAT ] ;  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-04 08:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \todo
  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  TODO :  sample  frames  for  each  supported  input  format . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  We  build  this  on  the  fly ,  by  taking  an  SLIN  frame  and  using 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  the  existing  converter  to  play  with  it . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-04 08:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief returns the index of the lowest bit set */  
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  force_inline  int  powerof ( format_t  d )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2009-12-04 21:06:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  x  =  ffsll ( d ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-06-13 20:59:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( x ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  x  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_log ( LOG_WARNING ,  " No bits set? %llu \n " ,  ( unsigned  long  long )  d ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-06-13 20:59:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  wrappers  around  the  translator  routines . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*!
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ brief  Allocate  the  descriptor ,  required  outbuf  space , 
							 
						 
					
						
							
								
									
										
										
										
											2010-06-03 17:09:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  and  possibly  desc . 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  void  * newpvt ( struct  ast_translator  * t )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * pvt ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									char  * ofs ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-14 14:08:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  compute  the  required  size  adding  private  descriptor , 
							 
						 
					
						
							
								
									
										
										
										
											2010-06-03 17:09:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									 *  buffer ,  AST_FRIENDLY_OFFSET . 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									len  =  sizeof ( * pvt )  +  t - > desc_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( t - > buf_size ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										len  + =  AST_FRIENDLY_OFFSET  +  t - > buf_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pvt  =  ast_calloc ( 1 ,  len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! pvt ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pvt - > t  =  t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ofs  =  ( char  * ) ( pvt  +  1 ) ; 	/* pointer to data space */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( t - > desc_size )  { 		/* first comes the descriptor */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pvt - > pvt  =  ofs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ofs  + =  t - > desc_size ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( t - > buf_size ) 		/* finally buffer and header */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-26 17:06:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										pvt - > outbuf . c  =  ofs  +  AST_FRIENDLY_OFFSET ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* call local init routine, if present */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-06-24 19:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > newpvt  & &  t - > newpvt ( pvt ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_free ( pvt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_module_ref ( t - > module ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  pvt ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  void  destroy ( struct  ast_trans_pvt  * pvt )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  ast_translator  * t  =  pvt - > t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( t - > destroy ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t - > destroy ( pvt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_free ( pvt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_module_unref ( t - > module ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-06-03 17:09:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief framein wrapper, deals with bound checks.  */  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  int  framein ( struct  ast_trans_pvt  * pvt ,  struct  ast_frame  * f )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  samples  =  pvt - > samples ; 	/* initial value */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-31 16:56:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* Copy the last in jb timing info to the pvt */ 
							 
						 
					
						
							
								
									
										
											 
										
											
												Merged revisions 98943 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed.  Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code.  The reason this
happens is that the channel might get masqueraded during this time.  During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way.  (This one is
 for you, paravoid!)
It changes an int in ast_frame to be used as flag bits.  The 1 bit is still used
to indicate that the frame contains timing information.  Also, a second flag has
been added to indicate that the frame came from a translator.  When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed.  At this point, the flag gets
cleared.  Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack.  But, it does fix the issue, and I was not able 
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2008-01-15 23:31:53 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_copy_flags ( & pvt - > f ,  f ,  AST_FRFLAG_HAS_TIMING_INFO ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-31 16:56:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									pvt - > f . ts  =  f - > ts ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pvt - > f . len  =  f - > len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									pvt - > f . seqno  =  f - > seqno ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( f - > samples  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " no samples for %s \n " ,  pvt - > t - > name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( pvt - > t - > buffer_samples )  { 	/* do not pass empty frames to callback */ 
							 
						 
					
						
							
								
									
										
										
										
											2010-06-03 17:09:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( f - > datalen  = =  0 )  {  /* perform native PLC if available */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											/* If the codec has native PLC, then do that */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-24 15:28:29 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ! pvt - > t - > native_plc ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( pvt - > samples  +  f - > samples  >  pvt - > t - > buffer_samples )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_log ( LOG_WARNING ,  " Out of buffer space \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* we require a framein routine, wouldn't know how to do
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  it  otherwise . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ret  =  pvt - > t - > framein ( pvt ,  f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* diagnostic ... */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( pvt - > samples  = =  samples ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " %s did not update samples %d \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											pvt - > t - > name ,  pvt - > samples ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:04:29 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-04 08:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief generic frameout routine.
  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								 *  If  samples  and  datalen  are  0 ,  take  whatever  is  in  pvt 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  and  reset  them ,  otherwise  take  the  values  in  the  caller  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  leave  alone  the  pvt  values . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								struct  ast_frame  * ast_trans_frameout ( struct  ast_trans_pvt  * pvt ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  datalen ,  int  samples ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  ast_frame  * f  =  & pvt - > f ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 16:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( samples ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										f - > samples  =  samples ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( pvt - > samples  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f - > samples  =  pvt - > samples ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pvt - > samples  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( datalen ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f - > datalen  =  datalen ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										f - > datalen  =  pvt - > datalen ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pvt - > datalen  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f - > frametype  =  AST_FRAME_VOICE ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f - > subclass . codec  =  1LL  < <  ( pvt - > t - > dstfmt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f - > mallocd  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f - > offset  =  AST_FRIENDLY_OFFSET ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									f - > src  =  pvt - > t - > name ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-26 17:06:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									f - > data . ptr  =  pvt - > outbuf . c ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-14 17:39:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-10-21 03:09:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  ast_frisolate ( f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  struct  ast_frame  * default_frameout ( struct  ast_trans_pvt  * pvt )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ast_trans_frameout ( pvt ,  0 ,  0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/* end of callback wrappers and helpers */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								void  ast_translator_free_path ( struct  ast_trans_pvt  * p )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * pn  =  p ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									while  (  ( p  =  pn )  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pn  =  p - > next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										destroy ( p ) ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-04 08:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief Build a chain of translators based upon the given source and dest formats */  
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  ast_trans_pvt  * ast_translator_build_path ( format_t  dest ,  format_t  source )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * head  =  NULL ,  * tail  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-25 19:10:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									source  =  powerof ( source ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dest  =  powerof ( dest ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-06 03:29:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( source  = =  - 1  | |  dest  = =  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " No translator path: (%s codec is not valid) \n " ,  source  = =  - 1  ?  " starting "  :  " ending " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-03-29 04:09:31 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									while  ( source  ! =  dest )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										struct  ast_trans_pvt  * cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										struct  ast_translator  * t  =  tr_matrix [ source ] [ dest ] . step ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! t )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-08-16 05:10:35 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_log ( LOG_WARNING ,  " No translator path from %s to %s \n " ,  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_getformatname ( source ) ,  ast_getformatname ( dest ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( cur  =  newpvt ( t ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_log ( LOG_WARNING ,  " Failed to build translator step from %s to %s \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_getformatname ( source ) ,  ast_getformatname ( dest ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( head ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_translator_free_path ( head ) ; 	
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-25 19:10:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! head ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											head  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											tail - > next  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										tail  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										cur - > nextin  =  cur - > nextout  =  ast_tv ( 0 ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-25 19:10:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/* Keep going if this isn't the final destination */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										source  =  cur - > t - > dstfmt ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  head ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief do the actual translation */  
						 
					
						
							
								
									
										
										
										
											2001-03-22 04:20:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								struct  ast_frame  * ast_translate ( struct  ast_trans_pvt  * path ,  struct  ast_frame  * f ,  int  consume )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * p  =  path ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-21 16:46:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_frame  * out  =  f ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-20 15:28:58 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  timeval  delivery ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-31 16:56:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  has_timing_info ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									long  ts ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									long  len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  seqno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										
											
												Merged revisions 98943 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed.  Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code.  The reason this
happens is that the channel might get masqueraded during this time.  During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way.  (This one is
 for you, paravoid!)
It changes an int in ast_frame to be used as flag bits.  The 1 bit is still used
to indicate that the frame contains timing information.  Also, a second flag has
been added to indicate that the frame came from a translator.  When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed.  At this point, the flag gets
cleared.  Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack.  But, it does fix the issue, and I was not able 
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2008-01-15 23:31:53 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									has_timing_info  =  ast_test_flag ( f ,  AST_FRFLAG_HAS_TIMING_INFO ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-31 16:56:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ts  =  f - > ts ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									len  =  f - > len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									seqno  =  f - > seqno ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* XXX hmmm... check this below */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! ast_tvzero ( f - > delivery ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ast_tvzero ( path - > nextin ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-05 20:47:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											/* Make sure this is in line with what we were expecting */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ! ast_tveq ( path - > nextin ,  f - > delivery ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-05 20:47:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												/* The time has changed between what we expected and this
 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-25 19:41:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												   most  recent  time  on  the  new  packet .   If  we  have  a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												   valid  prediction  adjust  our  output  time  appropriately  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ! ast_tvzero ( path - > nextout ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													path - > nextout  =  ast_tvadd ( path - > nextout , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																  ast_tvsub ( f - > delivery ,  path - > nextin ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												path - > nextin  =  f - > delivery ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-05 20:47:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											/* This is our first pass.  Make sure the timing looks good */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											path - > nextin  =  f - > delivery ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											path - > nextout  =  f - > delivery ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-05 20:47:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* Predict next incoming sample */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										path - > nextin  =  ast_tvadd ( path - > nextin ,  ast_samp2tv ( f - > samples ,  ast_format_rate ( f - > subclass . codec ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-04-05 19:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									delivery  =  f - > delivery ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  (  ;  out  & &  p  ;  p  =  p - > next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										framein ( p ,  out ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-31 23:14:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( out  ! =  f ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_frfree ( out ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										out  =  p - > t - > frameout ( p ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2001-03-22 04:20:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( consume ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_frfree ( f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( out  = =  NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* we have a frame, play with times */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! ast_tvzero ( delivery ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* Regenerate prediction after a discontinuity */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ast_tvzero ( path - > nextout ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											path - > nextout  =  ast_tvnow ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* Use next predicted outgoing timestamp */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										out - > delivery  =  path - > nextout ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* Predict next outgoing timestamp from samples in this
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										   frame .  */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										path - > nextout  =  ast_tvadd ( path - > nextout ,  ast_samp2tv ( out - > samples ,  ast_format_rate ( out - > subclass . codec ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										out - > delivery  =  ast_tv ( 0 ,  0 ) ; 
							 
						 
					
						
							
								
									
										
											 
										
											
												Merged revisions 98943 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r98943 | russell | 2008-01-15 17:26:52 -0600 (Tue, 15 Jan 2008) | 25 lines
Commit a fix for some memory access errors pointed out by the valgrind2.txt
output on issue #11698.
The issue here is that it is possible for an instance of a translator to get
destroyed while the frame allocated as a part of the translator is still being
processed.  Specifically, this is possible anywhere between a call to ast_read()
and ast_frame_free(), which is _a lot_ of places in the code.  The reason this
happens is that the channel might get masqueraded during this time.  During a
masquerade, existing translation paths get destroyed.
So, this patch fixes the issue in an API and ABI compatible way.  (This one is
 for you, paravoid!)
It changes an int in ast_frame to be used as flag bits.  The 1 bit is still used
to indicate that the frame contains timing information.  Also, a second flag has
been added to indicate that the frame came from a translator.  When a frame with
this flag gets released and has this flag, a function is called in translate.c to
let it know that this frame is doing being processed.  At this point, the flag gets
cleared.  Also, if the translator was requested to be destroyed while its internal
frame still had this flag set, its destruction has been deffered until it finds out
that the frame is no longer being processed.
Admittedly, this feels like a hack.  But, it does fix the issue, and I was not able 
to think of a better solution ...
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@98944 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2008-01-15 23:31:53 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_set2_flag ( out ,  has_timing_info ,  AST_FRFLAG_HAS_TIMING_INFO ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-31 16:56:50 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( has_timing_info )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											out - > ts  =  ts ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											out - > len  =  len ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											out - > seqno  =  seqno ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* Invalidate prediction if we're entering a silence period */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( out - > frametype  = =  AST_FRAME_CNG ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										path - > nextout  =  ast_tv ( 0 ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-10-21 16:46:22 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  out ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief compute the cost of a single translation step */  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  void  calc_cost ( struct  ast_translator  * t ,  int  seconds )  
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  num_samples  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * pvt ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-29 00:19:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  rusage  start ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  rusage  end ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  cost ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 01:54:16 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  out_rate  =  ast_format_rate ( t - > dstfmt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! seconds ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										seconds  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* If they don't make samples, give them a terrible score */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! t - > sample )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Translator '%s' does not produce sample frames. \n " ,  t - > name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-20 22:53:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t - > cost  =  999999 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									pvt  =  newpvt ( t ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! pvt )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Translator '%s' appears to be broken and will probably fail. \n " ,  t - > name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-20 22:53:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t - > cost  =  999999 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-29 00:19:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getrusage ( RUSAGE_SELF ,  & start ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* Call the encoder until we've processed the required number of samples */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									while  ( num_samples  <  seconds  *  out_rate )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										struct  ast_frame  * f  =  t - > sample ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! f )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_log ( LOG_WARNING ,  " Translator '%s' failed to produce a sample frame. \n " ,  t - > name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											destroy ( pvt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-20 22:53:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t - > cost  =  999999 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										framein ( pvt ,  f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_frfree ( f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										while  ( ( f  =  t - > frameout ( pvt ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											num_samples  + =  f - > samples ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_frfree ( f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-29 00:19:15 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getrusage ( RUSAGE_SELF ,  & end ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cost  =  ( ( end . ru_utime . tv_sec  -  start . ru_utime . tv_sec )  *  1000000 )  +  end . ru_utime . tv_usec  -  start . ru_utime . tv_usec ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									cost  + =  ( ( end . ru_stime . tv_sec  -  start . ru_stime . tv_sec )  *  1000000 )  +  end . ru_stime . tv_usec  -  start . ru_stime . tv_usec ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									destroy ( pvt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									t - > cost  =  cost  /  seconds ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 23:33:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! t - > cost ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t - > cost  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  enum  path_samp_change  get_rate_change_result ( format_t  src ,  format_t  dst )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  src_rate  =  ast_format_rate ( src ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  dst_rate  =  ast_format_rate ( dst ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* if src rate is less than dst rate, a sample upgrade is required */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( src_rate  <  dst_rate )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RATE_CHANGE_UPSAMP ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* if src rate is larger than dst rate, a downgrade is required */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( src_rate  >  dst_rate )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  RATE_CHANGE_DOWNSAMP ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  RATE_CHANGE_NONE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*!
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ brief  rebuild  a  translation  matrix . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  \ note  This  function  expects  the  list  of  translators  to  be  locked 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-11 05:00:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								*/  
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  void  rebuild_matrix ( int  samples )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  ast_translator  * t ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  new_rate_change ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  newcost ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  x ;       /* source format index */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  y ;       /* intermediate format index */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  z ;       /* destination format index */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_debug ( 1 ,  " Resetting translation matrix \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-09 14:17:33 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									memset ( tr_matrix ,  ' \0 ' ,  sizeof ( tr_matrix ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-18 21:39:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* first, compute all direct costs */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_TRAVERSE ( & translators ,  t ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! t - > active ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										x  =  t - > srcfmt ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										z  =  t - > dstfmt ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( samples ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											calc_cost ( t ,  samples ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										new_rate_change  =  get_rate_change_result ( 1LL  < <  t - > srcfmt ,  1LL  < <  t - > dstfmt ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* this translator is the best choice if any of the below are true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  1.  no  translation  path  is  set  between  x  and  z  yet . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  2.  the  new  translation  costs  less  and  sample  rate  is  no  worse  than  old  one .  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  3.  the  new  translation  has  a  better  sample  rate  conversion  than  the  old  one . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! tr_matrix [ x ] [ z ] . step  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											( ( t - > cost  <  tr_matrix [ x ] [ z ] . cost )  & &  ( new_rate_change  < =  tr_matrix [ x ] [ z ] . rate_change ) )  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											( new_rate_change  <  tr_matrix [ x ] [ z ] . rate_change ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											tr_matrix [ x ] [ z ] . step  =  t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											tr_matrix [ x ] [ z ] . cost  =  t - > cost ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											tr_matrix [ x ] [ z ] . rate_change  =  new_rate_change ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-18 21:39:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  For  each  triple  x ,  y ,  z  of  distinct  formats ,  check  if  there  is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  a  path  from  x  to  z  through  y  which  is  cheaper  than  what  is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  currently  known ,  and  in  case ,  update  the  matrix . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 *  Repeat  until  the  matrix  is  stable . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( ; ; )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										int  changed  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										int  better_choice  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( x  =  0 ;  x  <  MAX_FORMAT ;  x + + )  {       /* source format */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-11 18:27:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  ( y  =  0 ;  y  <  MAX_FORMAT ;  y + + )  {     /* intermediate format */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( x  = =  y )                      /* skip ourselves */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												for  ( z  =  0 ;  z  <  MAX_FORMAT ;  z + + )  {   /* dst format */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( z  = =  x  | |  z  = =  y )        /* skip null conversions */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( ! tr_matrix [ x ] [ y ] . step )   /* no path from x to y */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if  ( ! tr_matrix [ y ] [ z ] . step )   /* no path from y to z */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													/* Does x->y->z result in a less optimal sample rate change?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  Never  downgrade  the  sample  rate  conversion  quality  regardless 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  of  any  cost  improvements  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( tr_matrix [ x ] [ z ] . step  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														( ( tr_matrix [ x ] [ z ] . rate_change  <  tr_matrix [ x ] [ y ] . rate_change )  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														( tr_matrix [ x ] [ z ] . rate_change  <  tr_matrix [ y ] [ z ] . rate_change ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													/* is x->y->z a better sample rate confersion that the current x->z? */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													new_rate_change  =  tr_matrix [ x ] [ y ] . rate_change  +  tr_matrix [ y ] [ z ] . rate_change ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													/* calculate cost from x->y->z */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													newcost  =  tr_matrix [ x ] [ y ] . cost  +  tr_matrix [ y ] [ z ] . cost ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													/* Is x->y->z a better choice than x->z?
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  There  are  three  conditions  for  x - > y - > z  to  be  a  better  choice  than  x - > z 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  1.  if  there  is  no  step  directly  between  x - > z  then  x - > y - > z  is  the  best  and  only  current  option . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  2.  if  x - > y - > z  costs  less  and  the  sample  rate  conversion  is  no  less  optimal . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  3.  if  x - > y - > z  results  in  a  more  optimal  sample  rate  conversion .  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( ! tr_matrix [ x ] [ z ] . step )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														better_choice  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  if  ( ( newcost  <  tr_matrix [ x ] [ z ] . cost )  & &  ( new_rate_change  < =  tr_matrix [ x ] [ z ] . rate_change ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														better_choice  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  if  ( new_rate_change  <  tr_matrix [ x ] [ z ] . rate_change )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														better_choice  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														better_choice  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( ! better_choice )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													/* ok, we can get from x to z via y with a cost that
 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													   is  the  sum  of  the  transition  from  x  to  y  and  from  y  to  z  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													tr_matrix [ x ] [ z ] . step  =  tr_matrix [ x ] [ y ] . step ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													tr_matrix [ x ] [ z ] . cost  =  newcost ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													tr_matrix [ x ] [ z ] . multistep  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													/* now calculate what kind of sample rate change is required for this multi-step path
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  if  both  paths  require  a  change  in  rate ,  and  they  are  not  in  the  same  direction 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  then  this  is  a  up  sample  down  sample  conversion  scenario .  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( ( tr_matrix [ x ] [ y ] . rate_change  >  RATE_CHANGE_NONE )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														( tr_matrix [ y ] [ z ] . rate_change  >  RATE_CHANGE_NONE )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														( tr_matrix [ x ] [ y ] . rate_change  ! =  tr_matrix [ y ] [ z ] . rate_change ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														tr_matrix [ x ] [ z ] . rate_change  =  RATE_CHANGE_UPSAMP_DOWNSAMP ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														/* else just set the rate change to whichever is worse */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														tr_matrix [ x ] [ z ] . rate_change  =  tr_matrix [ x ] [ y ] . rate_change  >  tr_matrix [ y ] [ z ] . rate_change 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															?  tr_matrix [ x ] [ y ] . rate_change  :  tr_matrix [ y ] [ z ] . rate_change ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-14 08:06:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													ast_debug ( 3 ,  " Discovered %d cost path from %s to %s, via %s \n " ,  tr_matrix [ x ] [ z ] . cost , 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														  ast_getformatname ( 1LL  < <  x ) ,  ast_getformatname ( 1LL  < <  z ) ,  ast_getformatname ( 1LL  < <  y ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													changed + + ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! changed ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  char  * ast_translate_path_to_str ( struct  ast_trans_pvt  * p ,  struct  ast_str  * * str )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									struct  ast_trans_pvt  * pn  =  p ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! p  | |  ! p - > t )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ast_str_set ( str ,  0 ,  " %s " ,  ast_getformatname ( 1LL  < <  p - > t - > srcfmt ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									while  (  ( p  =  pn )  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										pn  =  p - > next ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_str_append ( str ,  0 ,  " ->%s " ,  ast_getformatname ( 1LL  < <  p - > t - > dstfmt ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ast_str_buffer ( * str ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								static  char  * complete_trans_path_choice ( const  char  * line ,  const  char  * word ,  int  pos ,  int  state )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  which  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  wordlen  =  strlen ( word ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									char  * ret  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									size_t  len  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									const  struct  ast_format_list  * format_list  =  ast_get_format_list ( & len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( i  =  0 ;  i  <  len ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ( format_list [ i ] . bits  &  AST_FORMAT_AUDIO_MASK ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! strncasecmp ( word ,  format_list [ i ] . name ,  wordlen )  & &  + + which  >  state )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ret  =  ast_strdup ( format_list [ i ] . name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  char  * handle_cli_core_show_translation ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a )  
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# define SHOW_TRANS 64 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									static  const  char  *  const  option1 [ ]  =  {  " recalc " ,  " paths " ,  NULL  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  x ,  y ,  z ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  curlen  =  0 ,  longest  =  0 ,  magnitude [ SHOW_TRANS ]  =  {  0 ,  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										e - > command  =  " core show translation " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										e - > usage  = 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											" Usage: 'core show translation' can be used in two ways. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"        1. 'core show translation [recalc [<recalc seconds>]] \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"           Displays known codec translators and the cost associated \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"           with each conversion.  If the argument 'recalc' is supplied along \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"           with optional number of seconds to test a new test will be performed \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"           as the chart is being displayed. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"        2. 'core show translation paths [codec]' \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											"            This will display all the translation paths associated with a codec \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( a - > pos  = =  3 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  ast_cli_complete ( a - > word ,  option1 ,  a - > n ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( a - > pos  = =  4  & &  ! strcasecmp ( a - > argv [ 3 ] ,  option1 [ 1 ] ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  complete_trans_path_choice ( a - > line ,  a - > word ,  a - > pos ,  a - > n ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( a - > argc  >  5 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( a - > argv [ 3 ]  & &  ! strcasecmp ( a - > argv [ 3 ] ,  option1 [ 1 ] )  & &  a - > argc  = =  5 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										format_t  input_src  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										format_t  src  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										size_t  len  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										int  dst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										int  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  struct  ast_format_list  * format_list  =  ast_get_format_list ( & len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										struct  ast_str  * str  =  ast_str_alloca ( 256 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										struct  ast_translator  * step ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( i  =  0 ;  i  <  len ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! ( format_list [ i ] . bits  &  AST_FORMAT_AUDIO_MASK ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! strncasecmp ( format_list [ i ] . name ,  a - > argv [ 4 ] ,  strlen ( format_list [ i ] . name ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												input_src  =  format_list [ i ] . bits ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! input_src )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_cli ( a - > fd ,  " Source codec  \" %s \"  is not found. \n " ,  a - > argv [ 4 ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  CLI_FAILURE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_cli ( a - > fd ,  " --- Translation paths SRC Codec  \" %s \"  sample rate %d --- \n " ,  a - > argv [ 4 ] ,  ast_format_rate ( input_src ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										for  ( i  =  0 ;  i  <  len ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ! ( format_list [ i ] . bits  &  AST_FORMAT_AUDIO_MASK )  | |  ( format_list [ i ] . bits  = =  input_src ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											dst  =  powerof ( format_list [ i ] . bits ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											src  =  powerof ( input_src ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_str_reset ( str ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( tr_matrix [ src ] [ dst ] . step )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_str_append ( & str ,  0 ,  " %s " ,  ast_getformatname ( 1LL  < <  tr_matrix [ src ] [ dst ] . step - > srcfmt ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												while  ( src  ! =  dst )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													step  =  tr_matrix [ src ] [ dst ] . step ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if  ( ! step )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														ast_str_reset ( str ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													ast_str_append ( & str ,  0 ,  " ->%s " ,  ast_getformatname ( 1LL  < <  step - > dstfmt ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													src  =  step - > dstfmt ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ast_strlen_zero ( ast_str_buffer ( str ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_str_set ( & str ,  0 ,  " No Translation Path " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											ast_cli ( a - > fd ,  " \t %-10.10s To %-10.10s: %-60.60s \n " ,  a - > argv [ 4 ] ,  format_list [ i ] . name ,  ast_str_buffer ( str ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									}  else  if  ( a - > argv [ 3 ]  & &  ! strcasecmp ( a - > argv [ 3 ] ,  " recalc " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										z  =  a - > argv [ 4 ]  ?  atoi ( a - > argv [ 4 ] )  :  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( z  < =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_cli ( a - > fd ,  "          Recalc must be greater than 0.  Defaulting to 1. \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											z  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( z  >  MAX_RECALC )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_cli ( a - > fd ,  "          Maximum limit of recalc exceeded by %d, truncating value to %d \n " ,  z  -  MAX_RECALC ,  MAX_RECALC ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											z  =  MAX_RECALC ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_cli ( a - > fd ,  "          Recalculating Codec Translation (number of sample seconds: %d) \n \n " ,  z ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AST_RWLIST_WRLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										rebuild_matrix ( z ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-20 15:00:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  if  ( a - > argc  >  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_cli ( a - > fd ,  "          Translation times between formats (in microseconds) for one second of data \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									ast_cli ( a - > fd ,  "           Source Format (Rows) Destination Format (Columns) \n \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* Get the length of the longest (usable?) codec name, so we know how wide the left side should be */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( x  =  0 ;  x  <  SHOW_TRANS ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/* translation only applies to audio right now. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ( AST_FORMAT_AUDIO_MASK  &  ( 1LL  < <  ( x ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										curlen  =  strlen ( ast_getformatname ( 1LL  < <  ( x ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( curlen  >  longest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											longest  =  curlen ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( y  =  0 ;  y  <  SHOW_TRANS ;  y + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ! ( AST_FORMAT_AUDIO_MASK  &  ( 1LL  < <  ( y ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( tr_matrix [ x ] [ y ] . cost  >  pow ( 10 ,  magnitude [ x ] ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												magnitude [ y ]  =  floor ( log10 ( tr_matrix [ x ] [ y ] . cost ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									for  ( x  =  - 1 ;  x  <  SHOW_TRANS ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										struct  ast_str  * out  =  ast_str_alloca ( 256 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* translation only applies to audio right now. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( x  > =  0  & &  ! ( AST_FORMAT_AUDIO_MASK  &  ( 1LL  < <  ( x ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-11 00:54:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/*Go ahead and move to next iteration if dealing with an unknown codec*/ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( x  > =  0  & &  ! strcmp ( ast_getformatname ( 1LL  < <  ( x ) ) ,  " unknown " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-11 00:54:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:46:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_str_set ( & out ,  - 1 ,  "   " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( y  =  - 1 ;  y  <  SHOW_TRANS ;  y + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											/* translation only applies to audio right now. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( y  > =  0  & &  ! ( AST_FORMAT_AUDIO_MASK  &  ( 1LL  < <  ( y ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-11 00:54:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											/*Go ahead and move to next iteration if dealing with an unknown codec*/ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( y  > =  0  & &  ! strcmp ( ast_getformatname ( 1LL  < <  ( y ) ) ,  " unknown " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-11 00:54:54 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-17 22:50:49 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( y  > =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												curlen  =  strlen ( ast_getformatname ( 1LL  < <  ( y ) ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( y  > =  0  & &  magnitude [ y ]  +  1  >  curlen )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												curlen  =  magnitude [ y ]  +  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-20 22:53:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( curlen  <  5 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												curlen  =  5 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( x  > =  0  & &  y  > =  0  & &  tr_matrix [ x ] [ y ] . step )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												/* Actual codec output */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												ast_str_append ( & out ,  - 1 ,  " %*d " ,  curlen  +  1 ,  tr_matrix [ x ] [ y ] . cost ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( x  = =  - 1  & &  y  > =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												/* Top row - use a dynamic size */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ast_str_append ( & out ,  - 1 ,  " %*s " ,  curlen  +  1 ,  ast_getformatname ( 1LL  < <  ( y ) )  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( y  = =  - 1  & &  x  > =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												/* Left column - use a static size. */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ast_str_append ( & out ,  - 1 ,  " %*s " ,  longest ,  ast_getformatname ( 1LL  < <  ( x ) )  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  if  ( x  > =  0  & &  y  > =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												/* Codec not supported */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:46:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ast_str_append ( & out ,  - 1 ,  " %*s " ,  curlen  +  1 ,  " - " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												/* Upper left hand corner */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:46:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												ast_str_append ( & out ,  - 1 ,  " %*s " ,  longest ,  " " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:46:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_str_append ( & out ,  - 1 ,  " \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-12 17:32:13 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_cli ( a - > fd ,  " %s " ,  ast_str_buffer ( out ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-11 19:03:06 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								static  struct  ast_cli_entry  cli_translate [ ]  =  {  
						 
					
						
							
								
									
										
										
										
											2007-10-22 20:05:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_CLI_DEFINE ( handle_cli_core_show_translation ,  " Display translation matrix " ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-18 19:54:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-04 08:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief register codec translator */  
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								int  __ast_register_translator ( struct  ast_translator  * t ,  struct  ast_module  * mod )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									static  int  added_cli  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_translator  * u ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-26 15:49:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									char  tmp [ 80 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! mod )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-14 14:08:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Missing module pointer, you need to supply one \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! t - > buf_size )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " empty buf size, you need to supply one \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 02:11:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t - > module  =  mod ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t - > srcfmt  =  powerof ( t - > srcfmt ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t - > dstfmt  =  powerof ( t - > dstfmt ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									t - > active  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-08-06 03:29:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > srcfmt  = =  - 1  | |  t - > dstfmt  = =  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Invalid translator path: (%s codec is not valid) \n " ,  t - > srcfmt  = =  - 1  ?  " starting "  :  " ending " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-05 14:00:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > srcfmt  > =  MAX_FORMAT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Source format %s is larger than MAX_FORMAT \n " ,  ast_getformatname ( t - > srcfmt ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-07-05 14:00:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > dstfmt  > =  MAX_FORMAT )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " Destination format %s is larger than MAX_FORMAT \n " ,  ast_getformatname ( t - > dstfmt ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > buf_size )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:04:29 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  Align  buf_size  properly ,  rounding  up  to  the  machine - specific 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  alignment  for  pointers . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										struct  _test_align  {  void  * a ,  * b ;  }  p ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										int  align  =  ( char  * ) & p . b  -  ( char  * ) & p . a ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										t - > buf_size  =  ( ( t - > buf_size  +  align  -  1 )  /  align )  *  align ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( t - > frameout  = =  NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										t - > frameout  =  default_frameout ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  
							 
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									calc_cost ( t ,  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-26 15:49:18 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									ast_verb ( 2 ,  " Registered translator '%s' from format %s to %s, cost %d \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											    term_color ( tmp ,  t - > name ,  COLOR_MAGENTA ,  COLOR_BLACK ,  sizeof ( tmp ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											    ast_getformatname ( 1LL  < <  t - > srcfmt ) ,  ast_getformatname ( 1LL  < <  t - > dstfmt ) ,  t - > cost ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( ! added_cli )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-05 10:31:25 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										ast_cli_register_multiple ( cli_translate ,  ARRAY_LEN ( cli_translate ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										added_cli + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_WRLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* find any existing translators that provide this same srcfmt/dstfmt,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   and  put  this  one  in  order  based  on  cost  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_TRAVERSE_SAFE_BEGIN ( & translators ,  u ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ( u - > srcfmt  = =  t - > srcfmt )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										    ( u - > dstfmt  = =  t - > dstfmt )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										    ( u - > cost  >  t - > cost ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											AST_RWLIST_INSERT_BEFORE_CURRENT ( t ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											t  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-07-16 15:20:40 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* if no existing translator was found for this format combination,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   add  it  to  the  beginning  of  the  list  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( t ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AST_RWLIST_INSERT_HEAD ( & translators ,  t ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-17 22:59:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									rebuild_matrix ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief unregister codec translator */  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								int  ast_unregister_translator ( struct  ast_translator  * t )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2004-04-21 04:26:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									char  tmp [ 80 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-11 05:00:45 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									struct  ast_translator  * u ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  found  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_WRLOCK ( & translators ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									AST_RWLIST_TRAVERSE_SAFE_BEGIN ( & translators ,  u ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
										if  ( u  = =  t )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											AST_RWLIST_REMOVE_CURRENT ( list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											ast_verb ( 2 ,  " Unregistered translator '%s' from format %s to %s \n " ,  term_color ( tmp ,  t - > name ,  COLOR_MAGENTA ,  COLOR_BLACK ,  sizeof ( tmp ) ) ,  ast_getformatname ( 1LL  < <  t - > srcfmt ) ,  ast_getformatname ( 1LL  < <  t - > dstfmt ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											found  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( found ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										rebuild_matrix ( 0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									return  ( u  ?  0  :  - 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								void  ast_translator_activate ( struct  ast_translator  * t )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_WRLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									t - > active  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rebuild_matrix ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								void  ast_translator_deactivate ( struct  ast_translator  * t )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_WRLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									t - > active  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									rebuild_matrix ( 0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 22:19:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/*! \brief Calculate our best translator source format, given costs, and a desired destination */  
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								format_t  ast_translator_best_choice ( format_t  * dst ,  format_t  * srcs )  
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2000-01-05 20:03:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  x , y ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									int  better  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  besttime  =  INT_MAX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									int  beststeps  =  INT_MAX ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									unsigned  int  best_rate_change  =  INT_MAX ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									format_t  best  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  bestdst  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  cur ,  cursrc ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  common  =  ( ( * dst )  &  ( * srcs ) )  &  AST_FORMAT_AUDIO_MASK ; 	/* are there common formats ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( common )  {  /* yes, pick one and return */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-27 14:52:07 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( cur  =  1 ,  y  =  0 ;  y  < =  MAX_AUDIO_FORMAT ;  cur  < < =  1 ,  y + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( ! ( cur  &  common ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											/* We are guaranteed to find one common format. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( best  = =  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												best  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											/* If there are multiple common formats, pick the one with the highest sample rate */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if  ( ast_format_rate ( best )  <  ast_format_rate ( cur ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												best  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2004-12-06 21:53:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/* We are done, this is a common format to both. */ 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										* srcs  =  * dst  =  best ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									}  else  {       /* No, we will need to translate */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-27 14:52:07 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for  ( cur  =  1 ,  y  =  0 ;  y  < =  MAX_AUDIO_FORMAT ;  cur  < < =  1 ,  y + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if  ( !  ( cur  &  * dst ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-27 14:52:07 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for  ( cursrc  =  1 ,  x  =  0 ;  x  < =  MAX_AUDIO_FORMAT ;  cursrc  < < =  1 ,  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if  ( ! ( * srcs  &  cursrc )  | |  ! tr_matrix [ x ] [ y ] . step )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												/* This is a better choice if any of the following are true.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 *  1.  The  sample  rate  conversion  is  better  than  the  current  pick . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 *  2.  the  sample  rate  conversion  is  no  worse  than  the  current  pick  and  the  cost  or  multistep  is  better 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												better  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( tr_matrix [ x ] [ y ] . rate_change  <  best_rate_change )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													better  =  1 ;  /* this match has a better rate conversion */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( ( tr_matrix [ x ] [ y ] . rate_change  < =  best_rate_change )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													( tr_matrix [ x ] [ y ] . cost  <  besttime  | |  tr_matrix [ x ] [ y ] . multistep  <  beststeps ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													better  =  1 ;  /* this match has no worse rate conversion and the conversion cost is less */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if  ( better )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													/* better than what we have so far */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													best  =  cursrc ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													bestdst  =  cur ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													besttime  =  tr_matrix [ x ] [ y ] . cost ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													beststeps  =  tr_matrix [ x ] [ y ] . multistep ; 
							 
						 
					
						
							
								
									
										
										
										
											2010-08-12 20:15:41 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													best_rate_change  =  tr_matrix [ x ] [ y ] . rate_change ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-12-06 21:53:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-25 05:11:44 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2004-12-06 21:53:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-08 21:40:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( best  >  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											* srcs  =  best ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											* dst  =  bestdst ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											best  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  best ; 
							 
						 
					
						
							
								
									
										
										
										
											1999-12-05 02:03:40 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2006-04-17 16:42:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								unsigned  int  ast_translate_path_steps ( format_t  dest ,  format_t  src )  
						 
					
						
							
								
									
										
										
										
											2006-04-17 16:42:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									unsigned  int  res  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-18 21:39:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* convert bitwise format numbers into array indices */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									src  =  powerof ( src ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									dest  =  powerof ( dest ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-08-06 03:29:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									if  ( src  = =  - 1  | |  dest  = =  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										ast_log ( LOG_WARNING ,  " No translator path: (%s codec is not valid) \n " ,  src  = =  - 1  ?  " starting "  :  " ending " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( tr_matrix [ src ] [ dest ] . step ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										res  =  tr_matrix [ src ] [ dest ] . multistep  +  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-17 16:42:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
									
										
										
										
											2006-07-10 19:05:48 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								format_t  ast_translate_available_formats ( format_t  dest ,  format_t  src )  
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									format_t  res  =  dest ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  src_audio  =  src  &  AST_FORMAT_AUDIO_MASK ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									format_t  src_video  =  src  &  AST_FORMAT_VIDEO_MASK ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* if we don't have a source format, we just have to try all
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   possible  destination  formats  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( ! src ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  dest ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 16:35:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* If we have a source audio format, get its format index */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( src_audio ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										src_audio  =  powerof ( src_audio ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									/* If we have a source video format, get its format index */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									if  ( src_video ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										src_video  =  powerof ( src_video ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_RDLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 16:35:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* For a given source audio format, traverse the list of
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   known  audio  formats  to  determine  whether  there  exists 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   a  translation  path  from  the  source  format  to  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   destination  format .  */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( x  =  1LL ;  src_audio  & &  x  >  0 ;  x  < < =  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ( x  &  AST_FORMAT_AUDIO_MASK ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/* if this is not a desired format, nothing to do */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-27 01:20:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( dest  &  x ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* if the source is supplying this format, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										   we  can  leave  it  in  the  result  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( src  &  x ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* if we don't have a translation path from the src
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										   to  this  format ,  remove  it  from  the  result  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 06:10:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! tr_matrix [ src_audio ] [ powerof ( x ) ] . step )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res  & =  ~ x ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 06:10:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* now check the opposite direction */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! tr_matrix [ powerof ( x ) ] [ src_audio ] . step ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res  & =  ~ x ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 16:35:34 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									/* For a given source video format, traverse the list of
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   known  video  formats  to  determine  whether  there  exists 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   a  translation  path  from  the  source  format  to  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									   destination  format .  */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-11-04 14:05:12 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									for  ( x  =  1LL ;  src_video  & &  x  >  0 ;  x  < < =  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! ( x  &  AST_FORMAT_VIDEO_MASK ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/* if this is not a desired format, nothing to do */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-07-27 01:20:37 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! ( dest  &  x ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* if the source is supplying this format, then
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										   we  can  leave  it  in  the  result  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( src  &  x ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* if we don't have a translation path from the src
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										   to  this  format ,  remove  it  from  the  result  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 06:10:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if  ( ! tr_matrix [ src_video ] [ powerof ( x ) ] . step )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											res  & =  ~ x ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 06:10:59 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 22:27:56 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/* now check the opposite direction */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if  ( ! tr_matrix [ powerof ( x ) ] [ src_video ] . step ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											res  & =  ~ x ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-02 18:01:10 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									AST_RWLIST_UNLOCK ( & translators ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-25 14:55:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									return  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}