* #27232: jni: added pjproject checkout as regular git content

We will remove it once the next release of pjsip (with Android support)
comes out and is merged into SFLphone.
diff --git a/jni/pjproject-android/.svn/pristine/98/9802e6acb63ea373f549a88ae06fcb6e3cdde5ff.svn-base b/jni/pjproject-android/.svn/pristine/98/9802e6acb63ea373f549a88ae06fcb6e3cdde5ff.svn-base
new file mode 100644
index 0000000..ab81a30
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/9802e6acb63ea373f549a88ae06fcb6e3cdde5ff.svn-base
@@ -0,0 +1,1113 @@
+/***************************************************************************
+**
+**   ITU-T G.722.1 (2005-05) - Fixed point implementation for main body and Annex C
+**   > Software Release 2.1 (2008-06)
+**     (Simple repackaging; no change from 2005-05 Release 2.0 code)
+**
+**   © 2004 Polycom, Inc.
+**
+**   All rights reserved.
+**
+***************************************************************************/
+
+/***************************************************************************
+  Filename:    decoder.c    
+
+  Purpose:     Contains files used to implement the G.722.1 Annex C decoder
+		
+  Design Notes:
+
+***************************************************************************/
+
+/***************************************************************************
+ Include files                                                           
+***************************************************************************/
+#include "defs.h"
+#include "tables.h"
+#include "huff_def.h"
+#include "count.h"
+
+
+/***************************************************************************
+ Function:    decoder
+
+ Syntax:      void decoder(Bit_Obj *bitobj,                   
+                           Rand_Obj *randobj,             
+                           Word16 number_of_regions,
+                           Word16 *decoder_mlt_coefs,     
+                           Word16 *p_mag_shift,           
+                           Word16 *p_old_mag_shift,       
+                           Word16 *old_decoder_mlt_coefs,    
+                           Word16 frame_error_flag)      
+              
+              inputs:    Bit_Obj *bitobj
+                         Rand_Obj *randobj
+                         Word16 number_of_regions
+                         Word16 *p_old_mag_shift
+                         Word16 *old_decoder_mlt_coefs
+                         Word16 frame_error_flag
+              
+              outputs:   Word16 *decoder_mlt_coefs,    
+                         Word16 *p_mag_shift,          
+                  
+                  
+
+ Description: Decodes the out_words into mlt coefs using G.722.1 Annex C
+
+ Design Notes:
+ 
+ WMOPS:     7kHz |   24kbit    |    32kbit
+          -------|-------------|----------------
+            AVG  |    0.84     |    0.94
+          -------|-------------|----------------  
+            MAX  |    0.90     |    1.00
+          -------|-------------|---------------- 
+				
+           14kHz |   24kbit    |    32kbit      |     48kbit
+          -------|-------------|----------------|----------------
+            AVG  |    1.31     |    1.56        |     1.88   
+          -------|-------------|----------------|----------------
+            MAX  |    1.59     |    1.80        |     1.98   
+          -------|-------------|----------------|----------------
+				
+***************************************************************************/
+void decoder(Bit_Obj *bitobj,
+             Rand_Obj *randobj,
+             Word16 number_of_regions,
+	         Word16 *decoder_mlt_coefs,
+	         Word16 *p_mag_shift,
+             Word16 *p_old_mag_shift,
+             Word16 *old_decoder_mlt_coefs,
+             Word16 frame_error_flag)
+{
+
+
+    Word16  absolute_region_power_index[MAX_NUMBER_OF_REGIONS];
+    Word16  decoder_power_categories[MAX_NUMBER_OF_REGIONS];
+    Word16  decoder_category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES-1];
+    UWord16 categorization_control;
+    Word16  decoder_region_standard_deviation[MAX_NUMBER_OF_REGIONS];
+    Word16  i;
+
+    Word16  num_categorization_control_bits;
+    Word16  num_categorization_control_possibilities;
+    Word16  number_of_coefs;
+    Word16  number_of_valid_coefs;
+    
+    
+    test();
+    if (number_of_regions==NUMBER_OF_REGIONS)
+    {
+        num_categorization_control_bits = NUM_CATEGORIZATION_CONTROL_BITS;
+        move16();
+        num_categorization_control_possibilities = NUM_CATEGORIZATION_CONTROL_POSSIBILITIES;
+        move16();
+        number_of_coefs = DCT_LENGTH;
+        move16();
+        number_of_valid_coefs = NUMBER_OF_VALID_COEFS;
+        move16();
+    }
+    else
+    {
+        num_categorization_control_bits = MAX_NUM_CATEGORIZATION_CONTROL_BITS;
+        move16();
+        num_categorization_control_possibilities = MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES;
+        move16();
+        number_of_coefs = MAX_DCT_LENGTH;
+        move16();
+        number_of_valid_coefs = MAX_NUMBER_OF_VALID_COEFS;
+        move16();
+    }
+
+    test();
+    if (frame_error_flag == 0) 
+    {
+
+        /* convert the bits to absolute region power index and decoder_region_standard_deviation */
+        
+        decode_envelope(bitobj,
+                        number_of_regions,
+                        decoder_region_standard_deviation,
+		                absolute_region_power_index,
+		                p_mag_shift);
+
+        /* fill the categorization_control with NUM_CATEGORIZATION_CONTROL_BITS */
+        categorization_control = 0;
+        for (i=0; i<num_categorization_control_bits; i++) 
+        {
+        	get_next_bit(bitobj);
+        	categorization_control = shl_nocheck(categorization_control,1);
+        	categorization_control = add(categorization_control,bitobj->next_bit);
+        }
+        
+        bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,num_categorization_control_bits);
+
+        /* obtain decoder power categories and category balances */
+        /* based on the absolute region power index              */
+        categorize(bitobj->number_of_bits_left,
+	               number_of_regions,
+	               num_categorization_control_possibilities,
+	               absolute_region_power_index,
+	               decoder_power_categories,
+	               decoder_category_balances);
+
+        /* perform adjustmaents to the power categories and category balances based on the cat control */
+        rate_adjust_categories(categorization_control,
+			                   decoder_power_categories,
+			                   decoder_category_balances);
+
+        /* decode the quantized bits into mlt coefs */
+        decode_vector_quantized_mlt_indices(bitobj,
+                                            randobj,
+                                            number_of_regions,
+                                            decoder_region_standard_deviation,
+					                        decoder_power_categories,
+					                        decoder_mlt_coefs);
+
+        /* test for frame errors */
+        test_4_frame_errors(bitobj,
+                            number_of_regions,
+                            num_categorization_control_possibilities,
+                            &frame_error_flag,
+                            categorization_control,
+                            absolute_region_power_index);
+    }
+
+    /* perform error handling operations */
+    error_handling(number_of_coefs,
+                   number_of_valid_coefs,
+                   &frame_error_flag,
+                   decoder_mlt_coefs,
+                   old_decoder_mlt_coefs,
+                   p_mag_shift,
+                   p_old_mag_shift);
+
+}
+
+/***************************************************************************
+ Function:    decode_envelope
+
+ Syntax:      void decode_envelope(Bit_Obj *bitobj,                              
+                                   Word16  number_of_regions,
+                                   Word16  *decoder_region_standard_deviation,   
+                                   Word16  *absolute_region_power_index,         
+                                   Word16  *p_mag_shift)                         
+              
+              inputs:   Bit_Obj *bitobj
+                        Word16  number_of_regions
+                        
+                        
+              outputs:  Word16  *decoder_region_standard_deviation
+                        Word16  *absolute_region_power_index
+                        Word16  *p_mag_shift
+              
+ 
+ Description: Recover differential_region_power_index from code bits
+
+ Design Notes:
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |     0.04     |    0.04
+          -------|--------------|----------------  
+            MAX  |     0.05     |    0.05
+          -------|--------------|---------------- 
+				
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |     0.08     |    0.08        |     0.08   
+          -------|--------------|----------------|----------------
+            MAX  |     0.10     |    0.10        |     0.10   
+          -------|--------------|----------------|----------------
+				
+***************************************************************************/
+void decode_envelope(Bit_Obj *bitobj,
+                     Word16  number_of_regions,
+                     Word16  *decoder_region_standard_deviation,
+		             Word16  *absolute_region_power_index,
+		             Word16  *p_mag_shift)
+     
+{
+    Word16 region;
+    Word16 i;
+    Word16 index;
+    Word16 differential_region_power_index[MAX_NUMBER_OF_REGIONS];
+    Word16 max_index;
+    
+    Word16 temp;
+    Word16 temp1;
+    Word16 temp2;
+    Word32 acca;
+
+    index = 0;
+    move16();
+
+    /* get 5 bits from the current code word */
+    for (i=0; i<5; i++) 
+    {
+        get_next_bit(bitobj);
+        index = shl_nocheck(index,1);
+        index = add(index,bitobj->next_bit);
+    }
+    bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,5);
+
+    /* ESF_ADJUSTMENT_TO_RMS_INDEX compensates for the current (9/30/96)
+        IMLT being scaled to high by the ninth power of sqrt(2). */
+    differential_region_power_index[0] = sub(index,ESF_ADJUSTMENT_TO_RMS_INDEX);
+    move16();
+
+    /* obtain differential_region_power_index */
+    for (region=1; region<number_of_regions; region++) 
+    {
+        index = 0;
+        move16();
+        do 
+        {
+            get_next_bit(bitobj);
+            test();
+            if (bitobj->next_bit == 0)
+            {
+	            index = differential_region_power_decoder_tree[region][index][0];
+                move16();
+            }
+            else
+            {
+	            index = differential_region_power_decoder_tree[region][index][1];
+                move16();
+            }
+            bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
+            test();
+        } while (index > 0);
+        
+        differential_region_power_index[region] = negate(index);
+        move16();
+    }
+
+    /* Reconstruct absolute_region_power_index[] from differential_region_power_index[]. */
+    absolute_region_power_index[0] = differential_region_power_index[0];
+    move16();
+    for (region=1; region<number_of_regions; region++) 
+    {
+        acca = L_add(absolute_region_power_index[region-1],differential_region_power_index[region]);
+        acca = L_add(acca,DRP_DIFF_MIN);
+        absolute_region_power_index[region] = extract_l(acca);        
+    }
+
+    /* Reconstruct decoder_region_standard_deviation[] from absolute_region_power_index[]. */
+    /* DEBUG!!!! - This integer method jointly computes the mag_shift
+       and the standard deviations already mag_shift compensated. It
+       relies on REGION_POWER_STEPSIZE_DB being exactly 3.010299957 db
+       or a square root of 2 chnage in standard deviation. If
+       REGION_POWER_STEPSIZE_DB changes, this software must be
+       reworked. */
+
+    temp = 0;
+    move16();
+    max_index = 0;
+    move16();
+    for (region=0; region<number_of_regions; region++) 
+    {
+        acca = L_add(absolute_region_power_index[region],REGION_POWER_TABLE_NUM_NEGATIVES);
+        i = extract_l(acca);
+        
+        temp1 = sub(i,max_index);
+        test();
+        if (temp1 > 0) 
+        {
+            max_index = i;
+            move16();
+        }
+        temp = add(temp,int_region_standard_deviation_table[i]);
+    }
+    i = 9;
+    move16();
+
+    temp1 = sub(temp,8);
+    temp2 = sub(max_index,28);
+    test();
+    test();
+    logic16();
+    test();
+    logic16();
+    while ((i >= 0) && ((temp1 >= 0) || (temp2 > 0))) 
+    {
+        i = sub(i,1);
+        temp = shr_nocheck(temp,1);
+        max_index = sub(max_index,2);
+        temp1 = sub(temp,8);
+        temp2 = sub(max_index,28);
+        test();
+        test();
+        logic16();
+        test();
+        logic16();
+    }
+    
+    *p_mag_shift = i;
+    move16();
+    
+    /* pointer arithmetic */
+    temp = (Word16 )(REGION_POWER_TABLE_NUM_NEGATIVES + (*p_mag_shift * 2));
+    
+    for (region=0; region<number_of_regions; region++) 
+    {
+        acca = L_add(absolute_region_power_index[region],temp);
+        i = extract_l(acca);
+        decoder_region_standard_deviation[region] = int_region_standard_deviation_table[i];
+        move16();
+    }
+
+}
+
+/***************************************************************************
+ Function:     rate_adjust_categories
+
+ Syntax:       void rate_adjust_categories(Word16 categorization_control,            
+                                           Word16 *decoder_power_categories,         
+                                           Word16 *decoder_category_balances)        
+               
+               inputs:    Word16 categorization_control,   
+                          Word16 *decoder_power_categories,
+                          Word16 *decoder_category_balances
+                          
+               outputs:   Word16 categorization_control,   
+                          Word16 *decoder_power_categories,
+ 
+ Description:  Adjust the power categories based on the categorization control
+
+ Design Notes:
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.00      |    0.00
+          -------|--------------|----------------  
+            MAX  |    0.00      |    0.00
+          -------|--------------|---------------- 
+				
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.00      |    0.00        |     0.00   
+          -------|--------------|----------------|----------------
+            MAX  |    0.01      |    0.01        |     0.01   
+          -------|--------------|----------------|----------------
+				
+***************************************************************************/
+void rate_adjust_categories(Word16 categorization_control,
+			                Word16 *decoder_power_categories,
+			                Word16 *decoder_category_balances)
+{
+    Word16 i;
+    Word16 region;
+    
+    i = 0;
+    move16();
+
+    test();
+    while (categorization_control > 0) 
+    {
+        region = decoder_category_balances[i++];
+        move16();
+        decoder_power_categories[region] = add(decoder_power_categories[region],1);
+        move16();
+        categorization_control = sub(categorization_control,1);
+    }
+
+}
+
+/***************************************************************************
+ Function:    decode_vector_quantized_mlt_indices
+
+ Syntax:      void decode_vector_quantized_mlt_indices(Bit_Obj  *bitobj,                                      
+                                                       Rand_Obj *randobj,                           
+                                                       Word16   number_of_regions,
+                                                       Word16   *decoder_region_standard_deviation, 
+                                                       Word16   *decoder_power_categories,          
+                                                       Word16   *decoder_mlt_coefs)                 
+              inputs:    Bit_Obj  *bitobj                           
+                         Rand_Obj *randobj
+                         Word16   number_of_regions
+                         Word16   *decoder_region_standard_deviation
+                         Word16   *decoder_power_categories
+            
+            
+              outputs:   Word16   *decoder_mlt_coefs
+             
+
+ Description: Decode MLT coefficients
+
+ Design Notes:
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.60      |    0.72
+          -------|--------------|----------------  
+            MAX  |    0.67      |    0.76
+          -------|--------------|---------------- 
+				
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.77      |    0.98        |     1.28   
+          -------|--------------|----------------|----------------
+            MAX  |    1.05      |    1.18        |     1.36   
+          -------|--------------|----------------|----------------
+				
+***************************************************************************/
+void decode_vector_quantized_mlt_indices(Bit_Obj  *bitobj,
+                                         Rand_Obj *randobj,
+                                         Word16   number_of_regions,
+                                         Word16   *decoder_region_standard_deviation,
+					                     Word16   *decoder_power_categories,
+					                     Word16   *decoder_mlt_coefs)
+{
+    Word16 standard_deviation;
+    Word16 *decoder_mlt_ptr;
+    Word16 decoder_mlt_value;
+    Word16 noifillpos;
+    Word16 noifillneg;
+    Word16 noise_fill_factor[3] = {5793,8192,23170};
+    Word16 region;
+    Word16 category;
+    Word16 j,n;
+    Word16 k[MAX_VECTOR_DIMENSION];
+    Word16 vec_dim;
+    Word16 num_vecs;
+    Word16 index;
+    Word16 bit=0;
+    Word16 signs_index=0;
+    Word16 num_sign_bits;
+    Word16 ran_out_of_bits_flag;
+    Word16 *decoder_table_ptr;
+    Word16 random_word;
+    
+    Word16 temp1;
+    Word16 temp;
+    Word32 acca;
+
+    ran_out_of_bits_flag = 0;
+    move16();
+
+    for (region=0; region<number_of_regions; region++) 
+    {
+        category = (Word16)decoder_power_categories[region];
+        move16();
+        acca = L_mult0(region,REGION_SIZE);
+        index = extract_l(acca);
+        decoder_mlt_ptr = &decoder_mlt_coefs[index];
+        move16();
+        standard_deviation = decoder_region_standard_deviation[region];
+        move16();
+        
+        temp = sub(category,7);
+        test();
+        if (temp < 0)
+        {
+            /* Get the proper table of decoder tables, vec_dim, and num_vecs for the cat */
+            decoder_table_ptr = (Word16 *) table_of_decoder_tables[category];
+            move16();
+            vec_dim = vector_dimension[category];
+            move16();
+            num_vecs = number_of_vectors[category];
+            move16();
+            
+            for (n=0; n<num_vecs; n++) 
+            {
+                index = 0;
+                move16();
+                
+                /* get index */
+                do 
+                {
+                    test();
+                    if (bitobj->number_of_bits_left <= 0) 
+                    {
+                        ran_out_of_bits_flag = 1;
+                        move16();
+    	                break;
+    	            }
+    
+    	            get_next_bit(bitobj);
+	                
+                    test();
+                    if (bitobj->next_bit == 0)
+	                {
+                        temp = shl_nocheck(index,1);
+                        index = (Word16)*(decoder_table_ptr + temp);
+                        move16();
+                    }
+	                else
+	                {
+                        temp = shl_nocheck(index,1);
+                        index = (Word16)*(decoder_table_ptr + temp + 1);
+                        move16();
+                    }
+	                bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
+                    test();
+	            
+                } while (index > 0);
+	  
+                test();
+                if (ran_out_of_bits_flag != 0)
+	                break;
+	  
+                index = negate(index);
+	            
+                /* convert index into array used to access the centroid table */
+                /* get the number of sign bits in the index */
+                num_sign_bits = index_to_array(index,k,category);
+
+	            temp = sub(bitobj->number_of_bits_left,num_sign_bits);
+                test();
+                if (temp >= 0) 
+                {
+
+	                test();
+                    if (num_sign_bits != 0) 
+                    {
+	                    signs_index = 0;
+	                    move16();
+                        for (j=0; j<num_sign_bits; j++) 
+                        {
+		                    get_next_bit(bitobj);
+       		                signs_index = shl_nocheck(signs_index,1);
+		                    signs_index = add(signs_index,bitobj->next_bit);
+		                    bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
+	                    }
+	                    temp = sub(num_sign_bits,1);
+                        bit = shl_nocheck(1,(temp));
+	                }
+	                
+                    for (j=0; j<vec_dim; j++) 
+                    {
+	                    acca = L_mult0(standard_deviation,mlt_quant_centroid[category][k[j]]);
+                        acca = L_shr_nocheck(acca,12);
+                        decoder_mlt_value = extract_l(acca);
+	                    
+                        test();
+                        if (decoder_mlt_value != 0) 
+                        {
+		                    test();
+                            if ((signs_index & bit) == 0)
+		                        decoder_mlt_value = negate(decoder_mlt_value);
+		                    bit = shr_nocheck(bit,1);
+	                    }
+                        *decoder_mlt_ptr++ = decoder_mlt_value;
+                        move16();
+	                }
+	            }
+	            else 
+                {
+	                ran_out_of_bits_flag = 1;
+                    move16();
+	                break;
+	            }
+	        }
+            /* If ran out of bits during decoding do noise fill for remaining regions. */
+            /* DEBUG!! - For now also redo all of last region with all noise fill. */
+        	test();
+            if (ran_out_of_bits_flag != 0) 
+            {
+        	    temp = add(region,1);
+                for (j=temp; j<number_of_regions; j++)
+                {
+                    decoder_power_categories[j] = 7;
+                    move16();
+                }
+        	    category = 7;
+                move16();
+        	    decoder_mlt_ptr = &decoder_mlt_coefs[region*REGION_SIZE];
+                move16();
+        	}
+        }
+
+        temp = sub(category,5);
+        temp1 = sub(category,6);
+        test();
+        test();
+        logic16();
+        if ((temp == 0) || (temp1 == 0))
+        {
+ 
+	        decoder_mlt_ptr = &decoder_mlt_coefs[region*REGION_SIZE];
+	        move16();
+            noifillpos = mult(standard_deviation,noise_fill_factor[category - 5]);
+            noifillneg = negate(noifillpos);
+
+	        random_word = get_rand(randobj);
+
+	        for (j=0; j<10; j++) 
+            {
+	            test();
+                if (*decoder_mlt_ptr == 0) 
+                {
+	                logic16();
+                    test();
+                    if ((random_word & 1) == 0) 
+                    {
+                        temp1 = noifillneg;
+                        move16();
+                    }
+	                else
+                    {
+                        temp1 = noifillpos;
+                        move16();
+                    }
+	                *decoder_mlt_ptr = temp1;
+                    move16();
+	                random_word = shr_nocheck(random_word,1);
+	            }
+	            /* pointer arithmetic */
+                decoder_mlt_ptr++;
+	        }
+	        random_word = get_rand(randobj);
+	        for (j=0; j<10; j++) 
+            {
+	            test();
+                if (*decoder_mlt_ptr == 0) 
+                {
+	                logic16();
+                    test();
+                    if ((random_word & 1) == 0) 
+                    {
+                        temp1 = noifillneg;
+                        move16();
+                    }
+	                else
+                    {
+                        temp1 = noifillpos;
+                        move16();
+                    }
+	                *decoder_mlt_ptr = temp1;
+                    move16();
+	                random_word  = shr_nocheck(random_word,1);
+	            }
+	            /* pointer arithmetic */
+                decoder_mlt_ptr++;
+	        }
+        }
+
+        /* if (category == 7) */
+        temp1 = sub(category,7);
+        test();
+        if (temp1 == 0)
+        {
+	        index = sub(category,5);
+            noifillpos = mult(standard_deviation,noise_fill_factor[index]);
+	        noifillneg = negate(noifillpos);
+
+            random_word = get_rand(randobj);
+            for (j=0; j<10; j++) 
+            {
+                logic16();
+                test();
+                if ((random_word & 1) == 0) 
+                {
+                    temp1 = noifillneg;
+                    move16();
+                }
+                else
+                {
+                    temp1 = noifillpos;
+                    move16();
+                }
+                *decoder_mlt_ptr++ = temp1;
+                move16();
+                random_word = shr_nocheck(random_word,1);
+            }
+            random_word = get_rand(randobj);
+            for (j=0; j<10; j++) 
+            {
+                logic16();
+                test();
+                if ((random_word & 1) == 0) 
+                {
+                    temp1 = noifillneg;
+                    move16();
+                }
+                else
+                {
+                    temp1 = noifillpos;
+                    move16();
+                }
+                
+                *decoder_mlt_ptr++ = temp1;
+                move16();
+                random_word = shr_nocheck(random_word,1);
+            }
+        }
+    }
+
+    test();
+    if (ran_out_of_bits_flag)
+        bitobj->number_of_bits_left = sub(bitobj->number_of_bits_left,1);
+}
+/****************************************************************************************
+ Function:    index_to_array 
+
+ Syntax:      number_of_non_zero = index_to_array(Word16 index, 
+                                                  Word16 array[MAX_VECTOR_DIMENSION],
+                                                  Word16 category)
+
+                inputs:  Word16 index
+                         Word16 category                     
+                       
+                outputs: Word16 array[MAX_VECTOR_DIMENSION] - used in decoder to access
+                                                             mlt_quant_centroid table
+                        
+                         Word16 number_of_non_zero          - number of non zero elements
+                                                             in the array
+ 
+ Description: Computes an array of sign bits with the length of the category vector
+              Returns the number of sign bits and the array
+
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |     0.00     |     0.00
+          -------|--------------|----------------  
+            MAX  |     0.00     |     0.00
+          -------|--------------|---------------- 
+
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |     0.00     |     0.00       |      0.00   
+          -------|--------------|----------------|----------------
+            MAX  |     0.00     |     0.00       |      0.00   
+          -------|--------------|----------------|----------------
+
+****************************************************************************************/
+Word16 index_to_array(Word16 index,Word16 *array,Word16 category)
+{
+    Word16 j,q,p;
+    Word16 number_of_non_zero;
+    Word16 max_bin_plus_one;
+    Word16 inverse_of_max_bin_plus_one;
+    Word16 temp;
+
+    number_of_non_zero = 0;
+    move16();
+
+    p = index;
+    move16();
+
+    max_bin_plus_one = add(max_bin[category],1);
+    inverse_of_max_bin_plus_one = max_bin_plus_one_inverse[category];
+    move16();
+
+    temp = sub(vector_dimension[category],1);
+    for (j=temp; j>=0; j--) 
+    {
+        q = mult(p,inverse_of_max_bin_plus_one);
+		temp = extract_l(L_mult0(q,max_bin_plus_one));
+        array[j] = sub(p,temp);
+        move16();
+
+        p = q;
+        move16();
+
+        temp = array[j];
+        move16();
+        test();
+        if (temp != 0) 
+            number_of_non_zero = add(number_of_non_zero,1);
+    }
+    return(number_of_non_zero);
+}
+/***************************************************************************
+ Function:     test_4_frame_errors
+
+ Syntax:       void test_4_frame_errors(Bit_Obj *bitobj,                        
+                                        Word16 number_of_regions,
+                                        Word16 num_categorization_control_possibilities,
+                                        Word16 *frame_error_flag,                
+                                        Word16 categorization_control,          
+                                        Word16 *absolute_region_power_index)    
+        
+               inputs:   bit_obj
+                         number_of_regions
+                         num_categorization_control_possibilities
+                         frame_error_flag
+                         categorization_control
+                         absolute_region_power_index
+               
+               
+               outputs:  frame_error_flag
+               
+               
+               
+        
+ Description:  Tests for error conditions and sets the frame_error_flag accordingly 
+
+ Design Notes:
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.01      |     0.01
+          -------|--------------|----------------  
+            MAX  |    0.04      |     0.08
+          -------|--------------|---------------- 
+				
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.01      |     0.01       |      0.01   
+          -------|--------------|----------------|----------------
+            MAX  |    0.02      |     0.06       |      0.08   
+          -------|--------------|----------------|----------------
+				
+***************************************************************************/
+void test_4_frame_errors(Bit_Obj *bitobj,
+                         Word16 number_of_regions,
+                         Word16 num_categorization_control_possibilities,
+                         Word16 *frame_error_flag,
+                         Word16 categorization_control,
+                         Word16 *absolute_region_power_index)
+{
+    Word16 region;
+    Word16 i;
+    Word16 temp;
+    Word32 acca;
+    Word32 accb;
+    
+    /* Test for bit stream errors. */
+
+    test();
+    if (bitobj->number_of_bits_left > 0) 
+    {
+        for (i=0; i<bitobj->number_of_bits_left; i++) 
+        {
+            get_next_bit(bitobj);
+            test();
+            if (bitobj->next_bit == 0) 
+            {
+                *frame_error_flag = 1;
+                move16();
+            }
+        }	
+    }
+    else 
+    {
+        temp = sub(categorization_control,sub(num_categorization_control_possibilities,1));
+        test();
+        if (temp < 0) 
+        {
+            test();
+            if (bitobj->number_of_bits_left < 0)
+            {
+                *frame_error_flag |= 2;
+                logic16();
+            }
+        }
+    }
+
+    /* checks to ensure that abs_region_power_index is within range */
+    /* the error flag is set if it is out of range */
+    for (region=0; region<number_of_regions; region++) 
+    {
+        /*  the next two lines of comments were modified in release 1.2
+	   *  to correct the description of the range of 
+	   *  absolute_region_power_index[] to be tested in the next
+	   *  9 lines of code.
+	   */
+	  /*  if ((absolute_region_power_index[region] > 31) ||
+            (absolute_region_power_index[region] < -8) */
+
+        acca = L_add(absolute_region_power_index[region],ESF_ADJUSTMENT_TO_RMS_INDEX);
+        accb = L_sub(acca,31);
+        acca = L_add(acca,8);
+        test();
+
+        /* the next line was modifed in release 1.2 to
+	   * correct miss typed code and error checking.
+	   */
+        if ((accb > 0) || (acca < 0))
+        {
+            *frame_error_flag |= 4;
+            logic16();
+        }
+    }
+
+}
+/***************************************************************************
+ Function:    error_handling
+
+ Syntax:      void error_handling(Word16 number_of_coefs,
+                                  Word16 number_of_valid_coefs,
+                                  Word16 *frame_error_flag,     
+                                  Word16 *decoder_mlt_coefs,    
+                                  Word16 *old_decoder_mlt_coefs,
+                                  Word16 *p_mag_shift,          
+                                  Word16 *p_old_mag_shift)      
+              
+              inputs:  number_of_coefs
+                       number_of_valid_coefs
+                       frame_error_flag
+                       old_decoder_mlt_coefs
+                       p_old_mag_shift
+              
+              
+              outputs: decoder_mlt_coefs
+                       old_decoder_mlt_coefs
+                       p_mag_shift
+                       p_old_mag_shift
+ 
+       
+
+ Description: If both the current and previous frames are errored,             
+              set the mlt coefficients to 0. If only the current frame         
+              is errored, then repeat the previous frame's mlt coefficients.   
+    
+ Design Notes:
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.02      |     0.02
+          -------|--------------|----------------  
+            MAX  |    0.03      |     0.03
+          -------|--------------|---------------- 
+				
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.03      |     0.03       |     0.03   
+          -------|--------------|----------------|----------------
+            MAX  |    0.03      |     0.03       |     0.06   
+          -------|--------------|----------------|----------------
+				
+***************************************************************************/
+void error_handling(Word16 number_of_coefs,
+                    Word16 number_of_valid_coefs,
+                    Word16 *frame_error_flag,
+                    Word16 *decoder_mlt_coefs,
+                    Word16 *old_decoder_mlt_coefs,
+                    Word16 *p_mag_shift,
+                    Word16 *p_old_mag_shift)
+{
+    Word16 i;
+
+    test();
+    if (*frame_error_flag != 0) 
+    {
+
+        for (i = 0; i < number_of_valid_coefs; i++)
+        {
+            decoder_mlt_coefs[i] = old_decoder_mlt_coefs[i];
+            move16();
+        }
+
+        for (i = 0; i < number_of_valid_coefs; i++)
+        {
+            old_decoder_mlt_coefs[i] = 0;
+            move16();
+        }
+        
+        *p_mag_shift = *p_old_mag_shift;
+        move16();
+
+        *p_old_mag_shift = 0;
+        move16();
+    }
+    else 
+    {
+        /* Store in case next frame is errored. */
+        for (i = 0; i < number_of_valid_coefs; i++)
+        {
+            old_decoder_mlt_coefs[i] = decoder_mlt_coefs[i];
+            move16();
+        }
+  
+        *p_old_mag_shift = *p_mag_shift;
+        move16();
+    }
+
+
+    /* Zero out the upper 1/8 of the spectrum. */
+    for (i = number_of_valid_coefs; i < number_of_coefs; i++)
+    {
+        decoder_mlt_coefs[i] = 0;
+        move16();
+    }
+
+}
+/****************************************************************************************
+ Function:    get_next_bit
+
+ Syntax:      void get_next_bit(Bit_Obj *bitobj)
+ 
+ Description: Returns the next bit in the current word inside the bit object
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.00      |    0.00
+          -------|--------------|----------------  
+            MAX  |    0.00      |    0.00
+          -------|--------------|---------------- 
+
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.00      |    0.00        |     0.00   
+          -------|--------------|----------------|----------------
+            MAX  |    0.00      |    0.00        |     0.00   
+          -------|--------------|----------------|----------------
+
+****************************************************************************************/
+void get_next_bit(Bit_Obj *bitobj)
+{
+    Word16 temp;
+
+    test();
+    if (bitobj->code_bit_count == 0)
+    {                        
+        bitobj->current_word = *bitobj->code_word_ptr++; 
+        move16();
+        bitobj->code_bit_count = 16;           
+        move16();
+    }
+    bitobj->code_bit_count = sub(bitobj->code_bit_count,1);
+    temp = shr_nocheck(bitobj->current_word,bitobj->code_bit_count);
+    logic16();
+    bitobj->next_bit = (Word16 )(temp & 1);
+
+}
+/****************************************************************************************
+ Function:    get_rand
+
+ Syntax:      Word16 get_rand(Rand_Obj *randobj)
+ 
+ Description: Returns a random Word16 based on the seeds inside the rand object  
+ 
+ WMOPS:     7kHz |    24kbit    |    32kbit
+          -------|--------------|----------------
+            AVG  |    0.00      |    0.00
+          -------|--------------|----------------  
+            MAX  |    0.00      |    0.00
+          -------|--------------|---------------- 
+
+           14kHz |    24kbit    |    32kbit      |     48kbit
+          -------|--------------|----------------|----------------
+            AVG  |    0.00      |    0.00        |     0.00   
+          -------|--------------|----------------|----------------
+            MAX  |    0.00      |    0.00        |     0.00   
+          -------|--------------|----------------|----------------
+
+****************************************************************************************/
+Word16 get_rand(Rand_Obj *randobj)
+{
+    Word16 random_word;
+    Word32 acca;
+
+    acca = L_add(randobj->seed0,randobj->seed3); 
+    random_word = extract_l(acca);
+    
+    logic16();
+    test();
+	if ((random_word & 32768L) != 0)
+        random_word = add(random_word,1);
+    
+    randobj->seed3 = randobj->seed2;
+    move16();
+    randobj->seed2 = randobj->seed1;
+    move16();
+    randobj->seed1 = randobj->seed0;
+    move16();
+    randobj->seed0 = random_word;
+    move16();
+
+    return(random_word);
+}
diff --git a/jni/pjproject-android/.svn/pristine/98/9888dbf54a515d9fdb9d74bd896336397b80ebaf.svn-base b/jni/pjproject-android/.svn/pristine/98/9888dbf54a515d9fdb9d74bd896336397b80ebaf.svn-base
new file mode 100644
index 0000000..9e8c1bd
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/9888dbf54a515d9fdb9d74bd896336397b80ebaf.svn-base
@@ -0,0 +1 @@
+#include "../../../portaudio/src/hostapi/coreaudio/pa_mac_core_utilities.c"
diff --git a/jni/pjproject-android/.svn/pristine/98/9898f557ec2960113eb8ef2ed1ace43998dd2858.svn-base b/jni/pjproject-android/.svn/pristine/98/9898f557ec2960113eb8ef2ed1ace43998dd2858.svn-base
new file mode 100644
index 0000000..e77b14a
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/9898f557ec2960113eb8ef2ed1ace43998dd2858.svn-base
@@ -0,0 +1,295 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#include <pj/os.h>
+#include <pj/assert.h>
+#include <pj/errno.h>
+#include <pj/log.h>
+#include <windows.h>
+
+#define THIS_FILE   "os_timestamp_win32.c"
+
+
+#if 1
+#   define TRACE_(x)	    PJ_LOG(3,x)
+#else
+#   define TRACE_(x)	    ;
+#endif
+
+
+/////////////////////////////////////////////////////////////////////////////
+
+#if defined(PJ_TIMESTAMP_USE_RDTSC) && PJ_TIMESTAMP_USE_RDTSC!=0 && \
+    defined(PJ_M_I386) && PJ_M_I386 != 0 && \
+    defined(PJ_HAS_PENTIUM) && PJ_HAS_PENTIUM!=0 && \
+    defined(_MSC_VER)
+
+/*
+ * Use rdtsc to get the OS timestamp.
+ */
+static LONG CpuMhz;
+static pj_int64_t CpuHz;
+ 
+static pj_status_t GetCpuHz(void)
+{
+    HKEY key;
+    LONG rc;
+    DWORD size;
+
+#if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
+    rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+		      L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
+		      0, 0, &key);
+#else
+    rc = RegOpenKey( HKEY_LOCAL_MACHINE,
+		     "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
+		     &key);
+#endif
+
+    if (rc != ERROR_SUCCESS)
+	return PJ_RETURN_OS_ERROR(rc);
+
+    size = sizeof(CpuMhz);
+    rc = RegQueryValueEx(key, "~MHz", NULL, NULL, (BYTE*)&CpuMhz, &size);
+    RegCloseKey(key);
+
+    if (rc != ERROR_SUCCESS) {
+	return PJ_RETURN_OS_ERROR(rc);
+    }
+
+    CpuHz = CpuMhz;
+    CpuHz = CpuHz * 1000000;
+
+    return PJ_SUCCESS;
+}
+
+/* __int64 is nicely returned in EDX:EAX */
+__declspec(naked) __int64 rdtsc() 
+{
+    __asm 
+    {
+	RDTSC
+	RET
+    }
+}
+
+PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts)
+{
+    ts->u64 = rdtsc();
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
+{
+    pj_status_t status;
+
+    if (CpuHz == 0) {
+	status = GetCpuHz();
+	if (status != PJ_SUCCESS)
+	    return status;
+    }
+
+    freq->u64 = CpuHz;
+    return PJ_SUCCESS;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+#elif defined(PJ_TIMESTAMP_WIN32_USE_SAFE_QPC) && \
+         PJ_TIMESTAMP_WIN32_USE_SAFE_QPC!=0
+
+/* Use safe QueryPerformanceCounter.
+ * This implementation has some protection against bug in KB Q274323:
+ *   Performance counter value may unexpectedly leap forward
+ *   http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q274323
+ *
+ * THIS SHOULD NOT BE USED YET AS IT DOESN'T HANDLE SYSTEM TIME
+ * CHANGE.
+ */
+
+static pj_timestamp g_ts_freq;
+static pj_timestamp g_ts_base;
+static pj_int64_t   g_time_base;
+
+PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts)
+{
+    enum { MAX_RETRY = 10 };
+    unsigned i;
+
+
+    /* pj_get_timestamp_freq() must have been called before.
+     * This is done when application called pj_init().
+     */
+    pj_assert(g_ts_freq.u64 != 0);
+
+    /* Retry QueryPerformanceCounter() until we're sure that the
+     * value returned makes sense.
+     */
+    i = 0;
+    do {
+	LARGE_INTEGER val;
+	pj_int64_t counter64, time64, diff;
+	pj_time_val time_now;
+
+	/* Retrieve the counter */
+	if (!QueryPerformanceCounter(&val))
+	    return PJ_RETURN_OS_ERROR(GetLastError());
+
+	/* Regardless of the goodness of the value, we should put
+	 * the counter here, because normally application wouldn't
+	 * check the error result of this function.
+	 */
+	ts->u64 = val.QuadPart;
+
+	/* Retrieve time */
+	pj_gettimeofday(&time_now);
+
+	/* Get the counter elapsed time in miliseconds */
+	counter64 = (val.QuadPart - g_ts_base.u64) * 1000 / g_ts_freq.u64;
+	
+	/* Get the time elapsed in miliseconds. 
+	 * We don't want to use PJ_TIME_VAL_MSEC() since it's using
+	 * 32bit calculation, which limits the maximum elapsed time
+	 * to around 49 days only.
+	 */
+	time64 = time_now.sec;
+	time64 = time64 * 1000 + time_now.msec;
+	//time64 = GetTickCount();
+
+	/* It's good if the difference between two clocks are within
+	 * some compile time constant (default: 20ms, which to allow
+	 * context switch happen between QueryPerformanceCounter and
+	 * pj_gettimeofday()).
+	 */
+	diff = (time64 - g_time_base) - counter64;
+	if (diff >= -20 && diff <= 20) {
+	    /* It's good */
+	    return PJ_SUCCESS;
+	}
+
+	++i;
+
+    } while (i < MAX_RETRY);
+
+    TRACE_((THIS_FILE, "QueryPerformanceCounter returned bad value"));
+    return PJ_ETIMEDOUT;
+}
+
+static pj_status_t init_performance_counter(void)
+{
+    LARGE_INTEGER val;
+    pj_time_val time_base;
+    pj_status_t status;
+
+    /* Get the frequency */
+    if (!QueryPerformanceFrequency(&val))
+	return PJ_RETURN_OS_ERROR(GetLastError());
+
+    g_ts_freq.u64 = val.QuadPart;
+
+    /* Get the base timestamp */
+    if (!QueryPerformanceCounter(&val))
+	return PJ_RETURN_OS_ERROR(GetLastError());
+
+    g_ts_base.u64 = val.QuadPart;
+
+
+    /* Get the base time */
+    status = pj_gettimeofday(&time_base);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    /* Convert time base to 64bit value in msec */
+    g_time_base = time_base.sec;
+    g_time_base  = g_time_base * 1000 + time_base.msec;
+    //g_time_base = GetTickCount();
+
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
+{
+    if (g_ts_freq.u64 == 0) {
+	enum { MAX_REPEAT = 10 };
+	unsigned i;
+	pj_status_t status;
+
+	/* Make unellegant compiler happy */
+	status = 0;
+
+	/* Repeat initializing performance counter until we're sure
+	 * the base timing is correct. It is possible that the system
+	 * returns bad counter during this initialization!
+	 */
+	for (i=0; i<MAX_REPEAT; ++i) {
+
+	    pj_timestamp dummy;
+
+	    /* Init base time */
+	    status = init_performance_counter();
+	    if (status != PJ_SUCCESS)
+		return status;
+
+	    /* Try the base time */
+	    status = pj_get_timestamp(&dummy);
+	    if (status == PJ_SUCCESS)
+		break;
+	}
+
+	if (status != PJ_SUCCESS)
+	    return status;
+    }
+
+    freq->u64 = g_ts_freq.u64;
+    return PJ_SUCCESS;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+#else
+
+/*
+ * Use QueryPerformanceCounter and QueryPerformanceFrequency.
+ * This should be the default implementation to be used on Windows.
+ */
+PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts)
+{
+    LARGE_INTEGER val;
+
+    if (!QueryPerformanceCounter(&val))
+	return PJ_RETURN_OS_ERROR(GetLastError());
+
+    ts->u64 = val.QuadPart;
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
+{
+    LARGE_INTEGER val;
+
+    if (!QueryPerformanceFrequency(&val))
+	return PJ_RETURN_OS_ERROR(GetLastError());
+
+    freq->u64 = val.QuadPart;
+    return PJ_SUCCESS;
+}
+
+
+#endif	/* PJ_TIMESTAMP_USE_RDTSC */
+
diff --git a/jni/pjproject-android/.svn/pristine/98/98c2bf8689097082d0e171395b9cb912362581f3.svn-base b/jni/pjproject-android/.svn/pristine/98/98c2bf8689097082d0e171395b9cb912362581f3.svn-base
new file mode 100644
index 0000000..082a2b8
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/98c2bf8689097082d0e171395b9cb912362581f3.svn-base
@@ -0,0 +1,107 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#include "test.h"
+
+#include <pj/string.h>
+#include <pj/sock.h>
+#include <pj/log.h>
+#include <stdio.h>
+
+extern int param_echo_sock_type;
+extern const char *param_echo_server;
+extern int param_echo_port;
+
+
+//#if defined(PJ_WIN32) && PJ_WIN32!=0
+#if 0
+#include <windows.h>
+static void boost(void)
+{
+    SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
+}
+#else
+#define boost()
+#endif
+
+#if defined(PJ_SUNOS) && PJ_SUNOS!=0
+#include <signal.h>
+static void init_signals()
+{
+    struct sigaction act;
+
+    memset(&act, 0, sizeof(act));
+    act.sa_handler = SIG_IGN;
+
+    sigaction(SIGALRM, &act, NULL);
+}
+
+#else
+#define init_signals()
+#endif
+
+int main(int argc, char *argv[])
+{
+    int rc;
+    int interractive = 0;
+
+    boost();
+    init_signals();
+
+    while (argc > 1) {
+        char *arg = argv[--argc];
+
+	if (*arg=='-' && *(arg+1)=='i') {
+	    interractive = 1;
+
+	} else if (*arg=='-' && *(arg+1)=='p') {
+            pj_str_t port = pj_str(argv[--argc]);
+
+            param_echo_port = pj_strtoul(&port);
+
+        } else if (*arg=='-' && *(arg+1)=='s') {
+            param_echo_server = argv[--argc];
+
+        } else if (*arg=='-' && *(arg+1)=='t') {
+            pj_str_t type = pj_str(argv[--argc]);
+            
+            if (pj_stricmp2(&type, "tcp")==0)
+                param_echo_sock_type = pj_SOCK_STREAM();
+            else if (pj_stricmp2(&type, "udp")==0)
+                param_echo_sock_type = pj_SOCK_DGRAM();
+            else {
+                PJ_LOG(3,("", "error: unknown socket type %s", type.ptr));
+                return 1;
+            }
+        }
+    }
+
+    rc = test_main();
+
+    if (interractive) {
+	char s[10];
+	puts("");
+	puts("Press <ENTER> to exit");
+	if (!fgets(s, sizeof(s), stdin))
+	    return rc;
+    }
+
+    return rc;
+}
+
diff --git a/jni/pjproject-android/.svn/pristine/98/98d8705ab602b4235963f2b1a611d2002c61c10d.svn-base b/jni/pjproject-android/.svn/pristine/98/98d8705ab602b4235963f2b1a611d2002c61c10d.svn-base
new file mode 100644
index 0000000..4a998b1
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/98d8705ab602b4235963f2b1a611d2002c61c10d.svn-base
@@ -0,0 +1,190 @@
+/* $Id$ */
+/* 
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+#include "test.h"
+#include <pjlib.h>
+#include <pj/compat/high_precision.h>
+
+
+/**
+ * \page page_pjlib_sock_perf_test Test: Socket Performance
+ *
+ * Test the performance of the socket communication. This will perform
+ * simple producer-consumer type of test, where we calculate how long
+ * does it take to send certain number of packets from producer to
+ * consumer.
+ *
+ * This file is <b>pjlib-test/sock_perf.c</b>
+ *
+ * \include pjlib-test/sock_perf.c
+ */
+
+#if INCLUDE_SOCK_PERF_TEST
+
+/*
+ * sock_producer_consumer()
+ *
+ * Simple producer-consumer benchmarking. Send loop number of
+ * buf_size size packets as fast as possible.
+ */
+static int sock_producer_consumer(int sock_type,
+                                  pj_size_t buf_size,
+                                  unsigned loop, 
+                                  unsigned *p_bandwidth)
+{
+    pj_sock_t consumer, producer;
+    pj_pool_t *pool;
+    char *outgoing_buffer, *incoming_buffer;
+    pj_timestamp start, stop;
+    unsigned i;
+    pj_highprec_t elapsed, bandwidth;
+    pj_highprec_t total_received;
+    pj_status_t rc;
+
+    /* Create pool. */
+    pool = pj_pool_create(mem, NULL, 4096, 4096, NULL);
+    if (!pool)
+        return -10;
+
+    /* Create producer-consumer pair. */
+    rc = app_socketpair(pj_AF_INET(), sock_type, 0, &consumer, &producer);
+    if (rc != PJ_SUCCESS) {
+        app_perror("...error: create socket pair", rc);
+        return -20;
+    }
+
+    /* Create buffers. */
+    outgoing_buffer = (char*) pj_pool_alloc(pool, buf_size);
+    incoming_buffer = (char*) pj_pool_alloc(pool, buf_size);
+
+    /* Start loop. */
+    pj_get_timestamp(&start);
+    total_received = 0;
+    for (i=0; i<loop; ++i) {
+        pj_ssize_t sent, part_received, received;
+	pj_time_val delay;
+
+        sent = buf_size;
+        rc = pj_sock_send(producer, outgoing_buffer, &sent, 0);
+        if (rc != PJ_SUCCESS || sent != (pj_ssize_t)buf_size) {
+            app_perror("...error: send()", rc);
+            return -61;
+        }
+
+        /* Repeat recv() until all data is part_received.
+         * This applies only for non-UDP of course, since for UDP
+         * we would expect all data to be part_received in one packet.
+         */
+        received = 0;
+        do {
+            part_received = buf_size-received;
+	    rc = pj_sock_recv(consumer, incoming_buffer+received, 
+			      &part_received, 0);
+	    if (rc != PJ_SUCCESS) {
+	        app_perror("...recv error", rc);
+	        return -70;
+	    }
+            if (part_received <= 0) {
+                PJ_LOG(3,("", "...error: socket has closed (part_received=%d)!",
+                          part_received));
+                return -73;
+            }
+	    if ((pj_size_t)part_received != buf_size-received) {
+                if (sock_type != pj_SOCK_STREAM()) {
+	            PJ_LOG(3,("", "...error: expecting %u bytes, got %u bytes",
+                              buf_size-received, part_received));
+	            return -76;
+                }
+	    }
+            received += part_received;
+        } while ((pj_size_t)received < buf_size);
+
+	total_received += received;
+
+	/* Stop test if it's been runnign for more than 10 secs. */
+	pj_get_timestamp(&stop);
+	delay = pj_elapsed_time(&start, &stop);
+	if (delay.sec > 10)
+	    break;
+    }
+
+    /* Stop timer. */
+    pj_get_timestamp(&stop);
+
+    elapsed = pj_elapsed_usec(&start, &stop);
+
+    /* bandwidth = total_received * 1000 / elapsed */
+    bandwidth = total_received;
+    pj_highprec_mul(bandwidth, 1000);
+    pj_highprec_div(bandwidth, elapsed);
+    
+    *p_bandwidth = (pj_uint32_t)bandwidth;
+
+    /* Close sockets. */
+    pj_sock_close(consumer);
+    pj_sock_close(producer);
+
+    /* Done */
+    pj_pool_release(pool);
+
+    return 0;
+}
+
+/*
+ * sock_perf_test()
+ *
+ * Main test entry.
+ */
+int sock_perf_test(void)
+{
+    enum { LOOP = 64 * 1024 };
+    int rc;
+    unsigned bandwidth;
+
+    PJ_LOG(3,("", "...benchmarking socket "
+                  "(2 sockets, packet=512, single threaded):"));
+
+    /* Disable this test on Symbian since UDP connect()/send() failed
+     * with S60 3rd edition (including MR2).
+     * See http://www.pjsip.org/trac/ticket/264
+     */    
+#if !defined(PJ_SYMBIAN) || PJ_SYMBIAN==0
+    /* Benchmarking UDP */
+    rc = sock_producer_consumer(pj_SOCK_DGRAM(), 512, LOOP, &bandwidth);
+    if (rc != 0) return rc;
+    PJ_LOG(3,("", "....bandwidth UDP = %d KB/s", bandwidth));
+#endif
+
+    /* Benchmarking TCP */
+    rc = sock_producer_consumer(pj_SOCK_STREAM(), 512, LOOP, &bandwidth);
+    if (rc != 0) return rc;
+    PJ_LOG(3,("", "....bandwidth TCP = %d KB/s", bandwidth));
+
+    return rc;
+}
+
+
+#else
+/* To prevent warning about "translation unit is empty"
+ * when this test is disabled. 
+ */
+int dummy_sock_perf_test;
+#endif  /* INCLUDE_SOCK_PERF_TEST */
+
+
diff --git a/jni/pjproject-android/.svn/pristine/98/98ed655da685d56ef4b64a3642f1836568d30f6a.svn-base b/jni/pjproject-android/.svn/pristine/98/98ed655da685d56ef4b64a3642f1836568d30f6a.svn-base
new file mode 100644
index 0000000..a778f40
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/98ed655da685d56ef4b64a3642f1836568d30f6a.svn-base
@@ -0,0 +1 @@
+#include "../../../portaudio/src/hostapi/alsa/pa_linux_alsa.c"
diff --git a/jni/pjproject-android/.svn/pristine/98/98ef648ff7f0063e1ed88d8adb9ac971444c43e3.svn-base b/jni/pjproject-android/.svn/pristine/98/98ef648ff7f0063e1ed88d8adb9ac971444c43e3.svn-base
new file mode 100644
index 0000000..f7e6481
--- /dev/null
+++ b/jni/pjproject-android/.svn/pristine/98/98ef648ff7f0063e1ed88d8adb9ac971444c43e3.svn-base
@@ -0,0 +1,343 @@
+# $Id$
+#
+from socket import *
+import re
+import random
+import time
+import sys
+import inc_cfg as cfg
+from select import *
+
+# SIP request template
+req_templ = \
+"""$METHOD $TARGET_URI SIP/2.0\r
+Via: SIP/2.0/UDP $LOCAL_IP:$LOCAL_PORT;rport;branch=z9hG4bK$BRANCH\r
+Max-Forwards: 70\r
+From: <sip:caller@pjsip.org>$FROM_TAG\r
+To: <$TARGET_URI>$TO_TAG\r
+Contact: <sip:$LOCAL_IP:$LOCAL_PORT;transport=udp>\r
+Call-ID: $CALL_ID@pjsip.org\r
+CSeq: $CSEQ $METHOD\r
+Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, REFER\r
+Supported: replaces, 100rel, norefersub\r
+User-Agent: pjsip.org Python tester\r
+Content-Length: $CONTENT_LENGTH\r
+$SIP_HEADERS"""
+
+
+def is_request(msg):
+	return msg.split(" ", 1)[0] != "SIP/2.0"
+	
+def is_response(msg):
+	return msg.split(" ", 1)[0] == "SIP/2.0"
+
+def get_code(msg):
+	if msg=="":
+		return 0
+	return int(msg.split(" ", 2)[1])
+
+def get_tag(msg, hdr="To"):
+	pat = "^" + hdr + ":.*"
+	result = re.search(pat, msg, re.M | re.I)
+	if result==None:
+		return ""
+	line = result.group()
+	#print "line=", line
+	tags = line.split(";tag=")
+	if len(tags)>1:
+		return tags[1]
+	return ""
+	#return re.split("[;& ]", s)
+
+def get_header(msg, hname):
+	headers = msg.splitlines()
+	for hdr in headers:
+		hfields = hdr.split(": ", 2)
+		if hfields[0]==hname:
+			return hfields[1]
+	return None
+
+class Dialog:
+	sock = None
+	dst_addr = ""
+	dst_port = 5060
+	local_ip = ""
+	local_port = 0
+	tcp = False
+	call_id = str(random.random())
+	cseq = 0
+	local_tag = ";tag=" + str(random.random())
+	rem_tag = ""
+	last_resp_code = 0
+	inv_branch = ""
+	trace_enabled = True
+	last_request = ""
+	def __init__(self, dst_addr, dst_port=5060, tcp=False, trace=True, local_port=0):
+		self.dst_addr = dst_addr
+		self.dst_port = dst_port
+		self.tcp = tcp
+		self.trace_enabled = trace
+		if tcp==True:
+			self.sock = socket(AF_INET, SOCK_STREAM)
+			self.sock.connect(dst_addr, dst_port)
+		else:
+			self.sock = socket(AF_INET, SOCK_DGRAM)
+			self.sock.bind(("127.0.0.1", local_port))
+		
+		self.local_ip, self.local_port = self.sock.getsockname()
+		self.trace("Dialog socket bound to " + self.local_ip + ":" + str(self.local_port))
+
+	def trace(self, txt):
+		if self.trace_enabled:
+			print str(time.strftime("%H:%M:%S ")) + txt
+
+	def update_fields(self, msg):
+		if self.tcp:
+			transport_param = ";transport=tcp"
+		else:
+			transport_param = ""
+		msg = msg.replace("$TARGET_URI", "sip:"+self.dst_addr+":"+str(self.dst_port) + transport_param)
+		msg = msg.replace("$LOCAL_IP", self.local_ip)
+		msg = msg.replace("$LOCAL_PORT", str(self.local_port))
+		msg = msg.replace("$FROM_TAG", self.local_tag)
+		msg = msg.replace("$TO_TAG", self.rem_tag)
+		msg = msg.replace("$CALL_ID", self.call_id)
+		msg = msg.replace("$CSEQ", str(self.cseq))
+		branch=str(random.random())
+		msg = msg.replace("$BRANCH", branch)
+		return msg
+
+	def create_req(self, method, sdp, branch="", extra_headers="", body=""):
+		if branch=="":
+			self.cseq = self.cseq + 1
+		msg = req_templ
+		msg = msg.replace("$METHOD", method)
+		msg = msg.replace("$SIP_HEADERS", extra_headers)
+		if branch=="":
+			branch=str(random.random())
+		msg = msg.replace("$BRANCH", branch)
+		if sdp!="":
+			msg = msg.replace("$CONTENT_LENGTH", str(len(sdp)))
+			msg = msg + "Content-Type: application/sdp\r\n"
+			msg = msg + "\r\n"
+			msg = msg + sdp
+		elif body!="":
+			msg = msg.replace("$CONTENT_LENGTH", str(len(body)))
+			msg = msg + "\r\n"
+			msg = msg + body
+		else:
+			msg = msg.replace("$CONTENT_LENGTH", "0")
+		return self.update_fields(msg)
+
+	def create_response(self, request, code, reason, to_tag=""):
+		response = "SIP/2.0 " + str(code) + " " + reason + "\r\n"
+		lines = request.splitlines()
+		for line in lines:
+			hdr = line.split(":", 1)[0]
+			if hdr in ["Via", "From", "To", "CSeq", "Call-ID"]:
+				if hdr=="To" and to_tag!="":
+					line = line + ";tag=" + to_tag
+				elif hdr=="Via":
+					line = line + ";received=127.0.0.1"
+				response = response + line + "\r\n"
+		return response
+
+	def create_invite(self, sdp, extra_headers="", body=""):
+		self.inv_branch = str(random.random())
+		return self.create_req("INVITE", sdp, branch=self.inv_branch, extra_headers=extra_headers, body=body)
+
+	def create_ack(self, sdp="", extra_headers=""):
+		return self.create_req("ACK", sdp, extra_headers=extra_headers, branch=self.inv_branch)
+
+	def create_bye(self, extra_headers=""):
+		return self.create_req("BYE", "", extra_headers)
+
+	def send_msg(self, msg, dst_addr=None):
+		if (is_request(msg)):
+			self.last_request = msg.split(" ", 1)[0]
+		if not dst_addr:
+			dst_addr = (self.dst_addr, self.dst_port)
+		self.trace("============== TX MSG to " + str(dst_addr) + " ============= \n" + msg)
+		self.sock.sendto(msg, 0, dst_addr)
+
+	def wait_msg_from(self, timeout):
+		endtime = time.time() + timeout
+		msg = ""
+		src_addr = None
+		while time.time() < endtime:
+			readset = select([self.sock], [], [], 1)
+			if len(readset[0]) < 1 or not self.sock in readset[0]:
+				if len(readset[0]) < 1:
+					print "select() timeout (will wait for " + str(int(endtime - time.time())) + "more secs)"
+				elif not self.sock in readset[0]:
+					print "select() alien socket"
+				else:
+					print "select other error"
+				continue
+			try:
+				msg, src_addr = self.sock.recvfrom(4096)
+				break
+			except:
+				print "recv() exception: ", sys.exc_info()[0]
+				continue
+
+		if msg=="":
+			return "", None
+		if self.last_request=="INVITE" and self.rem_tag=="":
+			self.rem_tag = get_tag(msg, "To")
+			self.rem_tag = self.rem_tag.rstrip("\r\n;")
+			if self.rem_tag != "":
+				self.rem_tag = ";tag=" + self.rem_tag
+			self.trace("=== rem_tag:" + self.rem_tag)
+		self.trace("=========== RX MSG from " + str(src_addr) +  " ===========\n" + msg)
+		return (msg, src_addr)
+	
+	def wait_msg(self, timeout):
+		return self.wait_msg_from(timeout)[0]
+		
+	# Send request and wait for final response
+	def send_request_wait(self, msg, timeout):
+		t1 = 1.0
+		endtime = time.time() + timeout
+		resp = ""
+		code = 0
+		for i in range(0,5):
+			self.send_msg(msg)
+			resp = self.wait_msg(t1)
+			if resp!="" and is_response(resp):
+				code = get_code(resp)
+				break
+		last_resp = resp
+		while code < 200 and time.time() < endtime:
+			resp = self.wait_msg(endtime - time.time())
+			if resp != "" and is_response(resp):
+				code = get_code(resp)
+				last_resp = resp
+			elif resp=="":
+				break
+		return last_resp
+	
+	def hangup(self, last_code=0):
+		self.trace("====== hangup =====")
+		if last_code!=0:
+			self.last_resp_code = last_code
+		if self.last_resp_code>0 and self.last_resp_code<200:
+			msg = self.create_req("CANCEL", "", branch=self.inv_branch, extra_headers="")
+			self.send_request_wait(msg, 5)
+			msg = self.create_ack()
+			self.send_msg(msg)
+		elif self.last_resp_code>=200 and self.last_resp_code<300:
+			msg = self.create_ack()
+			self.send_msg(msg)
+			msg = self.create_bye()
+			self.send_request_wait(msg, 5)
+		else:
+			msg = self.create_ack()
+			self.send_msg(msg)
+
+
+class SendtoCfg:
+	# Test name
+	name = ""
+	# pjsua InstanceParam
+	inst_param = None
+	# Complete INVITE message. If this is not empty, then this
+	# message will be sent instead and the "sdp" and "extra_headers"
+	# settings will be ignored.
+	complete_msg = ""
+	# Initial SDP
+	sdp = ""
+	# Extra headers to add to request
+	extra_headers = ""
+	# Expected code
+	resp_code = 0
+	# Use TCP?
+	use_tcp = False
+	# List of RE patterns that must exist in response
+	resp_include = []
+	# List of RE patterns that must NOT exist in response
+	resp_exclude = []
+	# Full (non-SDP) body
+	body = ""
+	# Constructor
+	def __init__(self, name, pjsua_args, sdp, resp_code, 
+		     resp_inc=[], resp_exc=[], use_tcp=False,
+		     extra_headers="", body="", complete_msg="",
+		     enable_buffer = False):
+	 	self.complete_msg = complete_msg
+		self.sdp = sdp
+		self.resp_code = resp_code
+		self.resp_include = resp_inc
+		self.resp_exclude = resp_exc
+		self.use_tcp = use_tcp
+		self.extra_headers = extra_headers
+		self.body = body
+		self.inst_param = cfg.InstanceParam("pjsua", pjsua_args)
+		self.inst_param.enable_buffer = enable_buffer 
+
+
+class RecvfromTransaction:
+	# The test title for this transaction
+	title = ""
+	# Optinal list of pjsua command and optional expect patterns 
+	# to be invoked to make pjsua send a request
+	# Sample:
+	#	(to make call and wait for INVITE to be sent)
+	#	cmds = [ ["m"], ["sip:127.0.0.1", "INVITE sip:"]  ]
+	cmds = []
+	# Check if the CSeq must be greater than last Cseq?
+	check_cseq = True
+	# List of RE patterns that must exists in incoming request
+	include = []
+	# List of RE patterns that MUST NOT exist in incoming request
+	exclude = []
+	# Response code to send
+	resp_code = 0
+	# Additional list of headers to be sent on the response
+	# Note: no need to add CRLF on the header
+	resp_hdr = []
+	# Message body. This should include the Content-Type header too.
+	# Sample:
+	#	body = """Content-Type: application/sdp\r\n
+	#	\r\n
+	#	v=0\r\n
+	#	...
+	#	"""
+	body = None
+	# Pattern to be expected on pjsua when receiving the response
+	expect = ""
+	
+	def __init__(self, title, resp_code, check_cseq=True,
+			include=[], exclude=[], cmds=[], resp_hdr=[], resp_body=None, expect=""):
+		self.title = title
+		self.cmds = cmds
+		self.include = include
+		self.exclude = exclude
+		self.resp_code = resp_code
+		self.resp_hdr = resp_hdr
+		self.body = resp_body
+		self.expect = expect
+			
+
+class RecvfromCfg:
+	# Test name
+	name = ""
+	# pjsua InstanceParam
+	inst_param = None
+	# List of RecvfromTransaction
+	transaction = None
+	# Use TCP?
+	tcp = False
+
+	# Note:
+	#  Any "$PORT" string in the pjsua_args will be replaced
+	#  by server port
+	def __init__(self, name, pjsua_args, transaction, tcp=False):
+		self.name = name
+		self.inst_param = cfg.InstanceParam("pjsua", pjsua_args)
+		self.transaction = transaction
+		self.tcp=tcp
+
+
+
+