Changeset 4793 for pjproject/trunk
- Timestamp:
- Mar 14, 2014 4:09:50 AM (11 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/wav_port.h
r3553 r4793 50 50 PJMEDIA_FILE_NO_LOOP = 1 51 51 }; 52 53 54 /** 55 * Additional information about the WAV player. 56 */ 57 typedef struct pjmedia_wav_player_info 58 { 59 /** 60 * Format ID of the payload. 61 */ 62 pjmedia_format_id fmt_id; 63 64 /** 65 * The number of bits per sample of the file payload. For example, 66 * the value is 16 for PCM WAV and 8 for Alaw/Ulas WAV files. 67 */ 68 unsigned payload_bits_per_sample; 69 70 /** 71 * The WAV payload size in bytes. 72 */ 73 pj_uint32_t size_bytes; 74 75 /** 76 * The WAV payload size in samples. 77 */ 78 pj_uint32_t size_samples; 79 80 } pjmedia_wav_player_info; 52 81 53 82 … … 77 106 pjmedia_port **p_port ); 78 107 108 /** 109 * Get additional info about the file player. 110 * 111 * @param port The file port. 112 * @param i The info. 113 * 114 * @return PJ_SUCCESS on success or the appropriate error code. 115 */ 116 PJ_DECL(pj_status_t) pjmedia_wav_player_get_info(pjmedia_port *port, 117 pjmedia_wav_player_info *i); 79 118 80 119 /** … … 83 122 * @param port The file player port. 84 123 * 85 * @return The length of the data, in bytes. Upon error it will86 * returnnegative value.124 * @return The length of the data, in bytes. On error, the 125 * error code is given as negative value. 87 126 */ 88 127 PJ_DECL(pj_ssize_t) pjmedia_wav_player_get_len(pjmedia_port *port); … … 103 142 104 143 /** 105 * Get the file play position of WAV player. 106 * 107 * @param port The file player port. 108 * 109 * @return PJ_SUCCESS on success. 144 * Get the file play position of WAV player, in bytes. 145 * 146 * @param port The file player port. 147 * 148 * @return The current play position, in bytes. On error, the 149 * error code is given as negative value. 110 150 */ 111 151 PJ_DECL(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port ); -
pjproject/trunk/pjmedia/src/pjmedia/wav_player.c
r4537 r4793 426 426 427 427 /* 428 * Get additional info about the file player. 429 */ 430 PJ_DEF(pj_status_t) pjmedia_wav_player_get_info( 431 pjmedia_port *port, 432 pjmedia_wav_player_info *info) 433 { 434 struct file_reader_port *fport; 435 PJ_ASSERT_RETURN(port && info, PJ_EINVAL); 436 437 pj_bzero(info, sizeof(*info)); 438 439 /* Check that this is really a player port */ 440 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP); 441 442 fport = (struct file_reader_port*) port; 443 444 if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) { 445 info->fmt_id = PJMEDIA_FORMAT_PCM; 446 info->payload_bits_per_sample = 16; 447 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) { 448 info->fmt_id = PJMEDIA_FORMAT_ULAW; 449 info->payload_bits_per_sample = 8; 450 } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) { 451 info->fmt_id = PJMEDIA_FORMAT_ALAW; 452 info->payload_bits_per_sample = 8; 453 } else { 454 pj_assert(!"Unsupported format"); 455 return PJ_ENOTSUP; 456 } 457 458 info->size_bytes = pjmedia_wav_player_get_len(port); 459 info->size_samples = info->size_bytes / 460 (info->payload_bits_per_sample / 8); 461 462 return PJ_SUCCESS; 463 } 464 465 /* 428 466 * Get the data length, in bytes. 429 467 */ … … 485 523 486 524 /* 487 * Get the file play position of WAV player .525 * Get the file play position of WAV player (in bytes). 488 526 */ 489 527 PJ_DEF(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port ) -
pjproject/trunk/pjsip-apps/src/3rdparty_media_sample/alt_pjsua_aud.c
r4174 r4793 497 497 } 498 498 499 /* Get number of bits per sample of the WAV payload */ 500 PJ_DEF(pj_status_t) pjsua_player_get_info(pjsua_player_id id, 501 pjmedia_wav_player_info *info) 502 { 503 UNIMPLEMENTED(pjsua_player_get_info) 504 return PJ_ENOTSUP; 505 } 506 507 /* Get position in samples */ 508 PJ_DEF(pj_ssize_t) pjsua_player_get_pos(pjsua_player_id id) 509 { 510 UNIMPLEMENTED(pjsua_player_get_pos) 511 return -PJ_ENOTSUP; 512 } 513 499 514 /* Set playback position. */ 500 515 PJ_DEF(pj_status_t) pjsua_player_set_pos( pjsua_player_id id, -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r4739 r4793 6072 6072 6073 6073 /** 6074 * Get additional info about the file player. This operation is not valid 6075 * for playlist. 6076 * 6077 * @param port The file player ID. 6078 * @param info The info. 6079 * 6080 * @return PJ_SUCCESS on success or the appropriate error code. 6081 */ 6082 PJ_DECL(pj_status_t) pjsua_player_get_info(pjsua_player_id id, 6083 pjmedia_wav_player_info *info); 6084 6085 6086 /** 6087 * Get playback position. This operation is not valid for playlist. 6088 * 6089 * @param id The file player ID. 6090 * 6091 * @return The current playback position, in samples. On error, 6092 * return the error code as negative value. 6093 */ 6094 PJ_DECL(pj_ssize_t) pjsua_player_get_pos(pjsua_player_id id); 6095 6096 /** 6074 6097 * Set playback position. This operation is not valid for playlist. 6075 6098 * … … 6082 6105 PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id, 6083 6106 pj_uint32_t samples); 6084 6085 6107 6086 6108 /** -
pjproject/trunk/pjsip/include/pjsua2/media.hpp
r4771 r4793 315 315 316 316 /** 317 * This structure contains additional info about AudioMediaPlayer. 318 */ 319 struct AudioMediaPlayerInfo 320 { 321 /** 322 * Format ID of the payload. 323 */ 324 pjmedia_format_id formatId; 325 326 /** 327 * The number of bits per sample of the file payload. For example, 328 * the value is 16 for PCM WAV and 8 for Alaw/Ulas WAV files. 329 */ 330 unsigned payloadBitsPerSample; 331 332 /** 333 * The WAV payload size in bytes. 334 */ 335 pj_uint32_t sizeBytes; 336 337 /** 338 * The WAV payload size in samples. 339 */ 340 pj_uint32_t sizeSamples; 341 }; 342 343 /** 317 344 * Audio Media Player. 318 345 */ … … 355 382 356 383 /** 357 * Set playback position. This operation is not valid for playlist. 384 * Get additional info about the player. This operation is only valid 385 * for player. For playlist, Error will be thrown. 386 * 387 * @return the info. 388 */ 389 AudioMediaPlayerInfo getInfo() const throw(Error); 390 391 /** 392 * Get current playback position in samples. This operation is not valid 393 * for playlist. 394 * 395 * @return Current playback position, in samples. 396 */ 397 pj_uint32_t getPos() const throw(Error); 398 399 /** 400 * Set playback position in samples. This operation is not valid for 401 * playlist. 358 402 * 359 403 * @param samples The desired playback position, in samples. … … 372 416 373 417 /** 374 * Virtual destructor.418 * Destructor. 375 419 */ 376 420 virtual ~AudioMediaPlayer(); 377 421 422 public: 423 /* 424 * Callbacks 425 */ 426 427 /** 428 * Register a callback to be called when the file player reading has 429 * reached the end of file, or when the file reading has reached the 430 * end of file of the last file for a playlist. If the file or playlist 431 * is set to play repeatedly, then the callback will be called multiple 432 * times. 433 * 434 * @return If the callback returns false, the playback 435 * will stop. Note that if application destroys 436 * the player in the callback, it must return 437 * false here. 438 */ 439 virtual bool onEof() 440 { return true; } 441 442 378 443 private: 379 444 /** … … 382 447 int playerId; 383 448 449 /** 450 * Low level PJMEDIA callback 451 */ 452 static pj_status_t eof_cb(pjmedia_port *port, 453 void *usr_data); 384 454 }; 385 455 … … 431 501 432 502 /** 433 * Virtual destructor.503 * Destructor. 434 504 */ 435 505 virtual ~AudioMediaRecorder(); -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c
r4704 r4793 1193 1193 PJ_DEF(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id) 1194 1194 { 1195 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), 1195 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL); 1196 1196 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); 1197 1197 … … 1205 1205 pjmedia_port **p_port) 1206 1206 { 1207 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), 1207 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL); 1208 1208 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); 1209 1209 PJ_ASSERT_RETURN(p_port != NULL, PJ_EINVAL); … … 1215 1215 1216 1216 /* 1217 * Get player info. 1218 */ 1219 PJ_DEF(pj_status_t) pjsua_player_get_info(pjsua_player_id id, 1220 pjmedia_wav_player_info *info) 1221 { 1222 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), 1223 -PJ_EINVAL); 1224 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); 1225 PJ_ASSERT_RETURN(pjsua_var.player[id].type == 0, PJ_EINVAL); 1226 1227 return pjmedia_wav_player_get_info(pjsua_var.player[id].port, info); 1228 } 1229 1230 /* 1231 * Get playback position. 1232 */ 1233 PJ_DEF(pj_ssize_t) pjsua_player_get_pos( pjsua_player_id id ) 1234 { 1235 pj_ssize_t pos_bytes; 1236 pjmedia_wav_player_info info; 1237 pj_status_t status; 1238 1239 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), 1240 -PJ_EINVAL); 1241 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, -PJ_EINVAL); 1242 PJ_ASSERT_RETURN(pjsua_var.player[id].type == 0, -PJ_EINVAL); 1243 1244 pos_bytes = pjmedia_wav_player_port_get_pos(pjsua_var.player[id].port); 1245 if (pos_bytes < 0) 1246 return pos_bytes; 1247 1248 status = pjmedia_wav_player_get_info(pjsua_var.player[id].port, &info); 1249 if (status != PJ_SUCCESS) 1250 return -status; 1251 1252 return pos_bytes / (info.payload_bits_per_sample / 8); 1253 } 1254 1255 /* 1217 1256 * Set playback position. 1218 1257 */ … … 1220 1259 pj_uint32_t samples) 1221 1260 { 1222 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), PJ_EINVAL); 1261 pjmedia_wav_player_info info; 1262 pj_uint32_t pos_bytes; 1263 pj_status_t status; 1264 1265 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL); 1223 1266 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); 1224 1267 PJ_ASSERT_RETURN(pjsua_var.player[id].type == 0, PJ_EINVAL); 1225 1268 1226 return pjmedia_wav_player_port_set_pos(pjsua_var.player[id].port, samples); 1269 status = pjmedia_wav_player_get_info(pjsua_var.player[id].port, &info); 1270 if (status != PJ_SUCCESS) 1271 return status; 1272 1273 pos_bytes = samples * (info.payload_bits_per_sample / 8); 1274 return pjmedia_wav_player_port_set_pos(pjsua_var.player[id].port, 1275 pos_bytes); 1227 1276 } 1228 1277 … … 1234 1283 PJ_DEF(pj_status_t) pjsua_player_destroy(pjsua_player_id id) 1235 1284 { 1236 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), 1285 PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player),PJ_EINVAL); 1237 1286 PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); 1238 1287 -
pjproject/trunk/pjsip/src/pjsua2/media.cpp
r4776 r4793 263 263 &playerId) ); 264 264 265 /* Register EOF callback */ 266 pjmedia_port *port; 267 pj_status_t status; 268 269 status = pjsua_player_get_port(playerId, &port); 270 if (status != PJ_SUCCESS) { 271 pjsua_player_destroy(playerId); 272 PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlayer()"); 273 } 274 status = pjmedia_wav_player_set_eof_cb(port, this, &eof_cb); 275 if (status != PJ_SUCCESS) { 276 pjsua_player_destroy(playerId); 277 PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlayer()"); 278 } 279 265 280 /* Get media port id. */ 266 281 id = pjsua_player_get_conf_port(playerId); … … 281 296 unsigned i, count = 0; 282 297 pj_str_t pj_lbl = str2Pj(label); 298 pj_status_t status; 283 299 284 300 count = PJ_ARRAY_SIZE(pj_files); … … 297 313 &playerId) ); 298 314 315 /* Register EOF callback */ 316 pjmedia_port *port; 317 status = pjsua_player_get_port(playerId, &port); 318 if (status != PJ_SUCCESS) { 319 pjsua_player_destroy(playerId); 320 PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlaylist()"); 321 } 322 status = pjmedia_wav_playlist_set_eof_cb(port, this, &eof_cb); 323 if (status != PJ_SUCCESS) { 324 pjsua_player_destroy(playerId); 325 PJSUA2_RAISE_ERROR2(status, "AudioMediaPlayer::createPlaylist()"); 326 } 327 299 328 /* Get media port id. */ 300 329 id = pjsua_player_get_conf_port(playerId); … … 303 332 } 304 333 334 AudioMediaPlayerInfo AudioMediaPlayer::getInfo() const throw(Error) 335 { 336 AudioMediaPlayerInfo info; 337 pjmedia_wav_player_info pj_info; 338 339 PJSUA2_CHECK_EXPR( pjsua_player_get_info(playerId, &pj_info) ); 340 341 pj_bzero(&info, sizeof(info)); 342 info.formatId = pj_info.fmt_id; 343 info.payloadBitsPerSample = pj_info.payload_bits_per_sample; 344 info.sizeBytes = pj_info.size_bytes; 345 info.sizeSamples = pj_info.size_samples; 346 347 return info; 348 } 349 350 pj_uint32_t AudioMediaPlayer::getPos() const throw(Error) 351 { 352 pj_ssize_t pos = pjsua_player_get_pos(playerId); 353 if (pos < 0) { 354 PJSUA2_RAISE_ERROR2(-pos, "AudioMediaPlayer::getPos()"); 355 } 356 return (pj_uint32_t)pos; 357 } 358 305 359 void AudioMediaPlayer::setPos(pj_uint32_t samples) throw(Error) 306 360 { … … 312 366 { 313 367 return static_cast<AudioMediaPlayer*>(media); 368 } 369 370 pj_status_t AudioMediaPlayer::eof_cb(pjmedia_port *port, 371 void *usr_data) 372 { 373 AudioMediaPlayer *player = (AudioMediaPlayer*)usr_data; 374 return player->onEof() ? PJ_SUCCESS : PJ_EEOF; 314 375 } 315 376
Note: See TracChangeset
for help on using the changeset viewer.