- Timestamp:
- Feb 18, 2009 1:55:03 PM (16 years ago)
- Location:
- pjproject/branches/projects/aps-direct/pjmedia
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjmedia/build/pjmedia_audiodev.dsp
r2458 r2459 96 96 SOURCE="..\src\pjmedia-audiodev\pa_dev.c" 97 97 # End Source File 98 # Begin Source File 99 100 SOURCE="..\src\pjmedia-audiodev\wmme_dev.c" 101 # End Source File 98 102 # End Group 99 103 # Begin Group "Header Files" -
pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-audiodev/audiodev.h
r2458 r2459 25 25 * @brief Audio device API. 26 26 */ 27 #include <pjmedia/ types.h>27 #include <pjmedia/port.h> 28 28 #include <pj/pool.h> 29 29 … … 100 100 101 101 /** 102 * Support for setting the audio device volume level. The value of this 103 * capability is an unsigned integer representing the audio volume in 104 * percent. 105 */ 106 PJMEDIA_AUD_DEV_CAP_SET_VOLUME = 8, 107 108 /** 109 * Support for audio volume level query. The value of this capability 110 * is unsigned integer representing the audio volume in percent. 111 */ 112 PJMEDIA_AUD_DEV_CAP_GET_VOLUME = 16, 113 114 /** 115 * Support for audio routing (e.g. loudspeaker vs earpiece). The value 116 * of this capability is an integer containing #pjmedia_aud_dev_route 102 * Support for setting/retrieving the audio input device volume level. 103 * The value of this capability is an unsigned integer representing 104 * the input audio volume setting in percent. 105 */ 106 PJMEDIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING = 8, 107 108 /** 109 * Support for setting/retrieving the audio output device volume level. 110 * The value of this capability is an unsigned integer representing 111 * the output audio volume setting in percent. 112 */ 113 PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING = 16, 114 115 /** 116 * Support for monitoring the current audio input signal volume. 117 * The value of this capability is an unsigned integer representing 118 * the audio volume in percent. 119 */ 120 PJMEDIA_AUD_DEV_CAP_INPUT_SIGNAL_VOLUME = 32, 121 122 /** 123 * Support for monitoring the current audio output signal volume. 124 * The value of this capability is an unsigned integer representing 125 * the audio volume in percent. 126 */ 127 PJMEDIA_AUD_DEV_CAP_OUTPUT_SIGNAL_VOLUME = 64, 128 129 /** 130 * Support for audio input routing. The value of this capability is an 131 * integer containing #pjmedia_aud_dev_route enumeration. 132 */ 133 PJMEDIA_AUD_DEV_CAP_INPUT_ROUTE = 128, 134 135 /** 136 * Support for audio output routing (e.g. loudspeaker vs earpiece). The 137 * value of this capability is an integer containing #pjmedia_aud_dev_route 117 138 * enumeration. 118 139 */ 119 PJMEDIA_AUD_DEV_CAP_ ROUTE = 32,140 PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE = 256, 120 141 121 142 /** … … 123 144 * capability is an integer containing boolean PJ_TRUE or PJ_FALSE. 124 145 */ 125 PJMEDIA_AUD_DEV_CAP_EC = 64,146 PJMEDIA_AUD_DEV_CAP_EC = 512, 126 147 127 148 /** … … 130 151 * echo tail in milliseconds. 131 152 */ 132 PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1 28,153 PJMEDIA_AUD_DEV_CAP_EC_TAIL = 1024, 133 154 134 155 /** … … 137 158 * PJ_FALSE. 138 159 */ 139 PJMEDIA_AUD_DEV_CAP_VAD = 2 56,160 PJMEDIA_AUD_DEV_CAP_VAD = 2048, 140 161 141 162 /** … … 144 165 * PJ_FALSE. 145 166 */ 146 PJMEDIA_AUD_DEV_CAP_CNG = 512,167 PJMEDIA_AUD_DEV_CAP_CNG = 4096, 147 168 148 169 /** … … 151 172 * PJ_FALSE. 152 173 */ 153 PJMEDIA_AUD_DEV_CAP_PLC = 1024174 PJMEDIA_AUD_DEV_CAP_PLC = 8192 154 175 155 176 } pjmedia_aud_dev_cap; … … 239 260 * buffer with audio samples. 240 261 * 241 * @param user_data User data associated with the stream. 242 * @param ts Timestamp, in samples. 243 * @param output Buffer to be filled out by application. 244 * @param size The size requested in bytes, which will be equal to 245 * the size of one whole packet. 246 * 247 * @return Non-zero to stop the stream. 248 */ 249 typedef pj_status_t (*pjmedia_aud_play_cb)(/* in */ void *user_data, 250 /* in */ const pj_timestamp *ts, 251 /* out */ void *output, 252 /* out */ unsigned size); 262 * The frame argument contains the following values: 263 * - timestamp Playback timestamp, in samples. 264 * - buf Buffer to be filled out by application. 265 * - size The size requested in bytes, which will be equal to 266 * the size of one whole packet. 267 * 268 * @param user_data User data associated with the stream. 269 * @param frame Audio frame, which buffer is to be filled in by 270 * the application. 271 * 272 * @return Returning non-PJ_SUCCESS will cause the audio stream 273 * to stop 274 */ 275 typedef pj_status_t (*pjmedia_aud_play_cb)(void *user_data, 276 pjmedia_frame *frame); 253 277 254 278 /** … … 256 280 * packet worth of audio samples. 257 281 * 258 * @param user_data User data associated with the stream. 259 * @param ts Timestamp, in samples. 260 * @param output Buffer containing the captured audio samples. 261 * @param size The size of the data in the buffer, in bytes. 262 * 263 * @return Non-zero to stop the stream. 264 */ 265 typedef pj_status_t (*pjmedia_aud_rec_cb)(/* in */ void *user_data, 266 /* in */ const pj_timestamp *ts, 267 /* in */ void *input, 268 /* in*/ unsigned size); 282 * @param user_data User data associated with the stream. 283 * @param frame Captured frame. 284 * 285 * @return Returning non-PJ_SUCCESS will cause the audio stream 286 * to stop 287 */ 288 typedef pj_status_t (*pjmedia_aud_rec_cb)(void *user_data, 289 pjmedia_frame *frame); 269 290 270 291 /** … … 335 356 336 357 /** 337 * Set the audio route. This setting is optional, and will only be used338 * if PJMEDIA_AUD_DEV_CAP_ROUTE is set in the flags.339 */ 340 pjmedia_aud_dev_route route;358 * Set the audio output route. This setting is optional, and will only be 359 * used if PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE is set in the flags. 360 */ 361 pjmedia_aud_dev_route out_route; 341 362 342 363 /** … … 546 567 #define PJMEDIA_EAUD_INVDEV -1 547 568 569 /* Found no devices */ 570 #define PJMEDIA_EAUD_NODEV -1 571 572 /* Unknown system error */ 573 #define PJMEDIA_EAUD_SYSERR -1 574 575 548 576 /** 549 577 * @) -
pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia-audiodev/audiodev_imp.h
r2458 r2459 61 61 * 62 62 * @param f The audio device factory. 63 * @param i d The audio device ID.63 * @param index Device index. 64 64 * @param info The audio device information structure which will be 65 65 * initialized by this function once it returns … … 67 67 */ 68 68 pj_status_t (*get_dev_info)(pjmedia_aud_dev_factory *f, 69 pjmedia_aud_dev_id id,69 unsigned index, 70 70 pjmedia_aud_dev_info *info); 71 71 … … 75 75 * 76 76 * @param f The audio device factory. 77 * @param i d Device ID.77 * @param index Device index. 78 78 * @param param The audio device parameter. 79 79 */ 80 80 pj_status_t (*default_param)(pjmedia_aud_dev_factory *f, 81 pjmedia_aud_dev_id id,81 unsigned index, 82 82 pjmedia_aud_dev_param *param); 83 83 … … 167 167 168 168 169 170 169 171 /** 170 172 * @} -
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/audiodev.c
r2458 r2459 21 21 #include <pj/errno.h> 22 22 23 23 /* 24 * The Device ID seen by application and driver is different. 25 * 26 * At application level, device ID is a 32bit value. The high 16bit contains 27 * the factory ID, and the low 16bit contains the device index in the 28 * specified factory. The device ID may also be -1 to denote default device. 29 * 30 * At driver level, device ID is a 16bit unsigned integer index. 31 */ 24 32 #define MAKE_DEV_ID(f_id, index) (((f_id & 0xFFFF) << 16) & (index & 0xFFFF)) 25 33 #define GET_INDEX(dev_id) ((dev_id) & 0xFFFF) 26 34 #define GET_FID(dev_id) ((dev_id) >> 16) 27 28 29 /* extern */ 35 #define DEFAULT_DEV_ID 0 36 37 38 /* extern functions to create factories */ 30 39 pjmedia_aud_dev_factory* pjmedia_pa_factory(pj_pool_factory *pf); 40 pjmedia_aud_dev_factory* pjmedia_wmme_factory(pj_pool_factory *pf); 41 31 42 32 43 /* Array of factories */ … … 38 49 } factories[] = 39 50 { 51 /* WMME */ 52 { 53 &pjmedia_wmme_factory 54 }, 55 /* PortAudio: */ 40 56 { 41 57 &pjmedia_pa_factory 42 } 58 }, 43 59 }; 44 60 static unsigned factory_cnt; … … 130 146 int f_id, index; 131 147 148 if (id == PJMEDIA_AUD_DEV_DEFAULT_ID) 149 id = DEFAULT_DEV_ID; 150 132 151 f_id = GET_FID(id); 133 152 index = GET_INDEX(id); … … 151 170 int f_id, index; 152 171 pj_status_t status; 172 173 if (id == PJMEDIA_AUD_DEV_DEFAULT_ID) 174 id = DEFAULT_DEV_ID; 153 175 154 176 f_id = GET_FID(id); … … 190 212 191 213 /* Set default device */ 192 if (param.rec_id == PJMEDIA_AUD_DEV_DEFAULT_ID) param.rec_id = 0; 193 if (param.play_id == PJMEDIA_AUD_DEV_DEFAULT_ID) param.play_id = 0; 214 if (param.rec_id == PJMEDIA_AUD_DEV_DEFAULT_ID) 215 param.rec_id = DEFAULT_DEV_ID; 216 if (param.play_id == PJMEDIA_AUD_DEV_DEFAULT_ID) 217 param.play_id = DEFAULT_DEV_ID; 194 218 195 219 if (param.dir & PJMEDIA_DIR_CAPTURE) -
pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/pa_dev.c
r2458 r2459 27 27 28 28 #define THIS_FILE "pa_dev.c" 29 #define DRIVER_NAME " portaudio"29 #define DRIVER_NAME "PA" 30 30 31 31 struct pa_aud_factory … … 102 102 static unsigned pa_get_dev_count(pjmedia_aud_dev_factory *f); 103 103 static pj_status_t pa_get_dev_info(pjmedia_aud_dev_factory *f, 104 pjmedia_aud_dev_id id,104 unsigned index, 105 105 pjmedia_aud_dev_info *info); 106 106 static pj_status_t pa_default_param(pjmedia_aud_dev_factory *f, 107 pjmedia_aud_dev_id id,107 unsigned index, 108 108 pjmedia_aud_dev_param *param); 109 109 static pj_status_t pa_create_stream(pjmedia_aud_dev_factory *f, … … 190 190 ++stream->overflow; 191 191 192 stream->rec_timestamp.u64 += frameCount;193 194 192 /* Calculate number of samples we've got */ 195 193 nsamples = frameCount * stream->channel_count + stream->rec_buf_count; … … 202 200 if (stream->rec_buf_count) { 203 201 unsigned chunk_count = 0; 202 pjmedia_frame frame; 204 203 205 204 chunk_count = stream->samples_per_frame - stream->rec_buf_count; 206 205 pjmedia_copy_samples(stream->rec_buf + stream->rec_buf_count, 207 206 (pj_int16_t*)input, chunk_count); 208 status = (*stream->rec_cb)(stream->user_data, 209 &stream->rec_timestamp, 210 (void*) stream->rec_buf, 211 stream->samples_per_frame * 212 stream->bytes_per_sample); 207 208 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 209 frame.buf = (void*) stream->rec_buf; 210 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 211 frame.timestamp.u64 = stream->rec_timestamp.u64; 212 frame.bit_info = 0; 213 214 status = (*stream->rec_cb)(stream->user_data, &frame); 213 215 214 216 input = (pj_int16_t*) input + chunk_count; 215 217 nsamples -= stream->samples_per_frame; 216 218 stream->rec_buf_count = 0; 219 stream->rec_timestamp.u64 += stream->samples_per_frame / 220 stream->channel_count; 217 221 } 218 222 219 223 /* Give all frames we have */ 220 224 while (nsamples >= stream->samples_per_frame && status == 0) { 221 status = (*stream->rec_cb)(stream->user_data, 222 &stream->rec_timestamp, 223 (void*) input, 224 stream->samples_per_frame * 225 stream->bytes_per_sample); 225 pjmedia_frame frame; 226 227 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 228 frame.buf = (void*) input; 229 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 230 frame.timestamp.u64 = stream->rec_timestamp.u64; 231 frame.bit_info = 0; 232 233 status = (*stream->rec_cb)(stream->user_data, &frame); 234 226 235 input = (pj_int16_t*) input + stream->samples_per_frame; 227 236 nsamples -= stream->samples_per_frame; 237 stream->rec_timestamp.u64 += stream->samples_per_frame / 238 stream->channel_count; 228 239 } 229 240 … … 291 302 ++stream->overflow; 292 303 293 stream->play_timestamp.u64 += frameCount;294 304 295 305 /* Check if any buffered samples */ … … 319 329 while (nsamples_req && status == 0) { 320 330 if (nsamples_req >= stream->samples_per_frame) { 321 status = (*stream->play_cb)(stream->user_data, 322 &stream->play_timestamp, 323 output, 324 stream->samples_per_frame * 325 stream->bytes_per_sample); 331 pjmedia_frame frame; 332 333 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 334 frame.buf = output; 335 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 336 frame.timestamp.u64 = stream->play_timestamp.u64; 337 frame.bit_info = 0; 338 339 status = (*stream->play_cb)(stream->user_data, &frame); 340 if (status != PJ_SUCCESS) 341 goto on_break; 342 343 if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 344 pj_bzero(frame.buf, frame.size); 345 326 346 nsamples_req -= stream->samples_per_frame; 327 347 output = (pj_int16_t*)output + stream->samples_per_frame; 328 348 } else { 329 status = (*stream->play_cb)(stream->user_data, 330 &stream->play_timestamp, 331 stream->play_buf, 332 stream->samples_per_frame * 333 stream->bytes_per_sample); 349 pjmedia_frame frame; 350 351 frame.type = PJMEDIA_FRAME_TYPE_AUDIO; 352 frame.buf = stream->play_buf; 353 frame.size = stream->samples_per_frame * stream->bytes_per_sample; 354 frame.timestamp.u64 = stream->play_timestamp.u64; 355 frame.bit_info = 0; 356 357 status = (*stream->play_cb)(stream->user_data, &frame); 358 if (status != PJ_SUCCESS) 359 goto on_break; 360 361 if (frame.type != PJMEDIA_FRAME_TYPE_AUDIO) 362 pj_bzero(frame.buf, frame.size); 363 334 364 pjmedia_copy_samples((pj_int16_t*)output, stream->play_buf, 335 365 nsamples_req); … … 340 370 nsamples_req = 0; 341 371 } 372 373 stream->play_timestamp.u64 += stream->samples_per_frame / 374 stream->channel_count; 342 375 } 343 376 … … 453 486 /* API: Get device info. */ 454 487 static pj_status_t pa_get_dev_info(pjmedia_aud_dev_factory *f, 455 pjmedia_aud_dev_id id,488 unsigned index, 456 489 pjmedia_aud_dev_info *info) 457 490 { … … 460 493 PJ_UNUSED_ARG(f); 461 494 462 pa_info = Pa_GetDeviceInfo(i d);495 pa_info = Pa_GetDeviceInfo(index); 463 496 if (!pa_info) 464 497 return PJMEDIA_EAUD_INVDEV; … … 481 514 /* API: fill in with default parameter. */ 482 515 static pj_status_t pa_default_param(pjmedia_aud_dev_factory *f, 483 pjmedia_aud_dev_id id,516 unsigned index, 484 517 pjmedia_aud_dev_param *param) 485 518 { … … 489 522 PJ_UNUSED_ARG(f); 490 523 491 status = p jmedia_aud_dev_get_info(id, &adi);524 status = pa_get_dev_info(f, index, &adi); 492 525 if (status != PJ_SUCCESS) 493 526 return status; … … 496 529 if (adi.input_count && adi.output_count) { 497 530 param->dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 498 param->rec_id = i d;499 param->play_id = i d;531 param->rec_id = index; 532 param->play_id = index; 500 533 } else if (adi.input_count) { 501 534 param->dir = PJMEDIA_DIR_CAPTURE; 502 param->rec_id = i d;535 param->rec_id = index; 503 536 param->play_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 504 537 } else if (adi.output_count) { 505 538 param->dir = PJMEDIA_DIR_PLAYBACK; 506 param->play_id = i d;539 param->play_id = index; 507 540 param->rec_id = PJMEDIA_AUD_DEV_DEFAULT_ID; 508 541 } else { … … 1080 1113 pi->flags |= PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY; 1081 1114 pi->input_latency_ms = (unsigned)(paRecSI ? paRecSI->inputLatency * 1082 paRecSI->sampleRate: 0);1115 1000 : 0); 1083 1116 } 1084 1117 if (paPlaySI) { 1085 1118 pi->flags |= PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY; 1086 1119 pi->output_latency_ms = (unsigned)(paPlaySI? paPlaySI->outputLatency * 1087 paPlaySI->sampleRate: 0);1120 1000 : 0); 1088 1121 } 1089 1122 … … 1106 1139 return PJ_EINVALIDOP; 1107 1140 1108 *(unsigned*)pval = (unsigned)(si->inputLatency * si->sampleRate);1141 *(unsigned*)pval = (unsigned)(si->inputLatency * 1000); 1109 1142 return PJ_SUCCESS; 1110 1143 } else if (cap==PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY && strm->play_strm) { … … 1113 1146 return PJ_EINVALIDOP; 1114 1147 1115 *(unsigned*)pval = (unsigned)(si->outputLatency * si->sampleRate);1148 *(unsigned*)pval = (unsigned)(si->outputLatency * 1000); 1116 1149 return PJ_SUCCESS; 1117 1150 } else {
Note: See TracChangeset
for help on using the changeset viewer.