Changeset 2174 for pjproject/trunk/pjsip-apps/src/symsndtest/app_main.cpp
- Timestamp:
- Jul 24, 2008 3:30:44 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/symsndtest/app_main.cpp
r1641 r2174 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include <pjmedia/delaybuf.h> 19 20 #include <pjmedia/sound.h> 20 21 #include <pj/errno.h> … … 28 29 #define CLOCK_RATE 8000 29 30 #define CHANNEL_COUNT 1 30 #define PTIME 10031 #define SAMPLES_PER_FRAME ( 80)31 #define PTIME 20 32 #define SAMPLES_PER_FRAME (CLOCK_RATE*PTIME/1000) 32 33 #define BITS_PER_SAMPLE 16 33 #define LOOPBACK_BUFF_COUNT 10034 34 35 35 extern CConsoleBase* console; … … 40 40 static pj_time_val t_start; 41 41 42 43 static pj_int16_t buff_loopback[SAMPLES_PER_FRAME*LOOPBACK_BUFF_COUNT]; 44 static pj_uint32_t pointer_w, pointer_r; 42 pj_pool_t *pool; 43 pjmedia_delay_buf *delaybuf; 45 44 46 45 /* Logging callback */ … … 74 73 pj_log_set_log_func((void (*)(int,const char*,int)) &log_writer); 75 74 pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 76 pj_log_set_level( 5);75 pj_log_set_level(3); 77 76 78 77 /* Init pjlib */ … … 104 103 info->default_samples_per_sec)); 105 104 } 105 106 /* Create pool */ 107 pool = pj_pool_create(&cp.factory, THIS_FILE, 512, 512, NULL); 108 if (pool == NULL) { 109 app_perror("pj_pool_create()", status); 110 pj_caching_pool_destroy(&cp); 111 pj_shutdown(); 112 return status; 113 } 114 115 /* Init delay buffer */ 116 status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, 117 SAMPLES_PER_FRAME, CHANNEL_COUNT, 118 0, 0, &delaybuf); 119 if (status != PJ_SUCCESS) { 120 app_perror("pjmedia_delay_buf_create()", status); 121 //pj_caching_pool_destroy(&cp); 122 //pj_shutdown(); 123 //return status; 124 } 106 125 107 126 return PJ_SUCCESS; … … 117 136 PJ_UNUSED_ARG(user_data); 118 137 PJ_UNUSED_ARG(timestamp); 119 PJ_UNUSED_ARG(input);120 138 PJ_UNUSED_ARG(size); 121 139 122 pj _memcpy(&buff_loopback[pointer_w*SAMPLES_PER_FRAME], input, size);140 pjmedia_delay_buf_put(delaybuf, (pj_int16_t*)input); 123 141 124 142 if (size != SAMPLES_PER_FRAME*2) { 125 143 PJ_LOG(3, (THIS_FILE, "Size captured = %u", 126 144 size)); 127 pj_bzero(&buff_loopback[pointer_w*SAMPLES_PER_FRAME]+size/2, SAMPLES_PER_FRAME*2 - size); 128 } 129 130 if (++pointer_w >= LOOPBACK_BUFF_COUNT) { 131 pointer_w = 0; 132 } 133 145 } 146 134 147 ++rec_cnt; 135 148 return PJ_SUCCESS; … … 144 157 PJ_UNUSED_ARG(user_data); 145 158 PJ_UNUSED_ARG(timestamp); 146 147 //pj_bzero(output, size); 148 pj_memcpy(output, &buff_loopback[pointer_r*SAMPLES_PER_FRAME], SAMPLES_PER_FRAME*2); 149 150 if (++pointer_r >= LOOPBACK_BUFF_COUNT) { 151 pointer_r = 0; 152 } 159 PJ_UNUSED_ARG(size); 160 161 pjmedia_delay_buf_get(delaybuf, (pj_int16_t*)output); 153 162 154 163 ++play_cnt; … … 187 196 pj_gettimeofday(&t_start); 188 197 198 pjmedia_delay_buf_reset(delaybuf); 199 189 200 status = pjmedia_snd_stream_start(strm); 190 201 if (status != PJ_SUCCESS) { … … 195 206 } 196 207 197 pointer_w = LOOPBACK_BUFF_COUNT/2;198 pointer_r = 0;199 200 208 return PJ_SUCCESS; 201 209 } … … 232 240 233 241 pjmedia_snd_deinit(); 242 pjmedia_delay_buf_destroy(delaybuf); 243 pj_pool_release(pool); 234 244 pj_caching_pool_destroy(&cp); 235 245 pj_shutdown(); … … 296 306 PJ_LOG(3, (THIS_FILE, "\n\n" 297 307 "Menu:\n" 298 " bStart bidir sound\n"299 " rStart recorder\n"308 " a Start bidir sound\n" 309 " t Start recorder\n" 300 310 " p Start player\n" 301 " cStop & close sound\n"302 " qQuit\n"));311 " d Stop & close sound\n" 312 " w Quit\n")); 303 313 } 304 314 … … 310 320 311 321 switch (kc) { 312 case ' q':322 case 'w': 313 323 asw_->AsyncStop(); 314 324 reschedule = PJ_FALSE; 315 325 break; 316 case ' b':326 case 'a': 317 327 snd_start(PJMEDIA_DIR_CAPTURE_PLAYBACK); 318 328 break; 319 case ' r':329 case 't': 320 330 snd_start(PJMEDIA_DIR_CAPTURE); 321 331 break; … … 323 333 snd_start(PJMEDIA_DIR_PLAYBACK); 324 334 break; 325 case ' c':335 case 'd': 326 336 snd_stop(); 327 337 break;
Note: See TracChangeset
for help on using the changeset viewer.