Changeset 4230 for pjproject/trunk
- Timestamp:
- Aug 14, 2012 8:39:59 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/bb10_dev.c
r4151 r4230 34 34 #if defined(PJMEDIA_AUDIO_DEV_HAS_BB10) && PJMEDIA_AUDIO_DEV_HAS_BB10 != 0 35 35 36 #ifndef PJ_BBSDK_VER 37 /* Format: 0xMMNNRR: MM: major, NN: minor, RR: revision */ 38 # define PJ_BBSDK_VER 0x100006 39 #endif 40 36 41 #include <sys/time.h> 37 42 #include <sys/types.h> … … 41 46 #include <errno.h> 42 47 #include <sys/asoundlib.h> 48 #if PJ_BBSDK_VER >= 0x100006 49 #include <audio/audio_manager_routing.h> 50 #endif 43 51 44 52 … … 116 124 /* Playback */ 117 125 snd_pcm_t *pb_pcm; 118 snd_mixer_t *pb_mixer;119 126 unsigned long pb_frames; /* samples_per_frame */ 120 127 pjmedia_aud_play_cb pb_cb; … … 125 132 /* Capture */ 126 133 snd_pcm_t *ca_pcm; 127 snd_mixer_t *ca_mixer;128 134 unsigned long ca_frames; /* samples_per_frame */ 129 135 pjmedia_aud_rec_cb ca_cb; … … 163 169 int card = -1; 164 170 int dev = 0; 171 unsigned int handle; 165 172 snd_pcm_t *pcm_handle; 166 173 … … 172 179 TRACE_((THIS_FILE, "bb10_add_dev Enter")); 173 180 181 #if PJ_BBSDK_VER >= 0x100006 182 if ((pb_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 183 &pcm_handle, 184 &handle, 185 "/dev/snd/voicep", 186 SND_PCM_OPEN_PLAYBACK)) 187 >= 0) 188 #else 189 PJ_UNUSED_ARG(handle); 174 190 if ((pb_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 175 191 SND_PCM_OPEN_PLAYBACK)) >= 0) 192 #endif 176 193 { 177 194 TRACE_((THIS_FILE, "Try to open the device for playback - success")); … … 181 198 } 182 199 200 #if PJ_BBSDK_VER >= 0x100006 201 if ((ca_result = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 202 &pcm_handle, 203 &handle, 204 "/dev/snd/voicec", 205 SND_PCM_OPEN_CAPTURE)) 206 >= 0) 207 #else 183 208 if ((ca_result = snd_pcm_open_preferred (&pcm_handle, &card, &dev, 184 209 SND_PCM_OPEN_CAPTURE)) >=0) 210 #endif 185 211 { 186 212 TRACE_((THIS_FILE, "Try to open the device for capture - success")); … … 240 266 { 241 267 pj_status_t status; 242 268 243 269 status = bb10_factory_refresh(f); 244 270 if (status != PJ_SUCCESS) … … 315 341 info->caps = PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 316 342 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY; 317 343 318 344 return PJ_SUCCESS; 319 345 } … … 359 385 " spf = %d", param->clock_rate, param->flags, 360 386 param->samples_per_frame)); 361 387 362 388 return PJ_SUCCESS; 363 389 } … … 372 398 } 373 399 374 static void close_play_mixer(struct bb10_stream *stream)375 {376 if (stream != NULL && stream->pb_mixer != NULL) {377 snd_mixer_close(stream->pb_mixer);378 stream->pb_mixer = NULL;379 }380 }381 382 400 static void flush_play(struct bb10_stream *stream) 383 401 { … … 392 410 snd_pcm_close(stream->ca_pcm); 393 411 stream->ca_pcm = NULL; 394 }395 }396 397 static void close_capture_mixer(struct bb10_stream *stream)398 {399 if (stream != NULL && stream->ca_mixer != NULL) {400 snd_mixer_close(stream->ca_mixer);401 stream->ca_mixer = NULL;402 412 } 403 413 } … … 436 446 SND_PCM_CHANNEL_PLAYBACK)) < 0) 437 447 { 438 close_play_mixer(stream);439 448 close_play_pcm(stream); 440 449 TRACE_((THIS_FILE, "pb_thread_func failed prepare = %d", result)); … … 461 470 /* Write 640 to play unit */ 462 471 result = snd_pcm_plugin_write(stream->pb_pcm,buf,size); 463 if (result != size) { 472 if (result != size || result < 0) { 473 snd_pcm_channel_status_t status; 474 if (snd_pcm_plugin_status (stream->pb_pcm, &status) < 0) { 475 PJ_LOG(4,(THIS_FILE, 476 "underrun: playback channel status error")); 477 continue; 478 } 479 480 if (status.status == SND_PCM_STATUS_READY || 481 status.status == SND_PCM_STATUS_UNDERRUN) 482 { 483 if (snd_pcm_plugin_prepare (stream->pb_pcm, 484 SND_PCM_CHANNEL_PLAYBACK) < 0) 485 { 486 PJ_LOG(4,(THIS_FILE, 487 "underrun: playback channel prepare error")); 488 continue; 489 } 490 } 491 464 492 TRACE_((THIS_FILE, "pb_thread_func failed write = %d", result)); 465 493 } … … 469 497 470 498 flush_play(stream); 471 close_play_mixer(stream);472 499 close_play_pcm(stream); 473 500 TRACE_((THIS_FILE, "pb_thread_func: Stopped")); 474 501 475 502 return PJ_SUCCESS; 476 503 } … … 514 541 SND_PCM_CHANNEL_CAPTURE)) < 0) 515 542 { 516 close_capture_mixer(stream);517 543 close_capture_pcm(stream); 518 544 TRACE_((THIS_FILE, "ca_thread_func failed prepare = %d", result)); … … 524 550 525 551 pj_bzero (buf, size); 526 552 527 553 result = snd_pcm_plugin_read(stream->ca_pcm, buf,size); 528 if (result == -EPIPE) { 529 PJ_LOG (4,(THIS_FILE, "ca_thread_func: overrun!")); 530 snd_pcm_plugin_prepare (stream->ca_pcm, SND_PCM_CHANNEL_CAPTURE); 531 continue; 532 } else if (result < 0) { 533 PJ_LOG (4,(THIS_FILE, "ca_thread_func: error reading data!")); 554 if(result <0 || result != size) { 555 snd_pcm_channel_status_t status; 556 if (snd_pcm_plugin_status (stream->ca_pcm, &status) < 0) { 557 PJ_LOG (4,(THIS_FILE, "overrun: capture channel status " 558 "error")); 559 continue; 560 } 561 562 if (status.status == SND_PCM_STATUS_READY || 563 status.status == SND_PCM_STATUS_OVERRUN) { 564 if (snd_pcm_plugin_prepare (stream->ca_pcm, 565 SND_PCM_CHANNEL_CAPTURE) < 0) 566 { 567 PJ_LOG (4,(THIS_FILE, "overrun: capture channel prepare " 568 "error")); 569 continue; 570 } 571 } 534 572 } 535 573 … … 551 589 552 590 flush_capture(stream); 553 close_capture_mixer(stream);554 591 close_capture_pcm(stream); 555 592 TRACE_((THIS_FILE, "ca_thread_func: Stopped")); … … 571 608 unsigned int rate; 572 609 unsigned long tmp_buf_size; 610 unsigned int handle; 573 611 574 612 if (param->play_id < 0 || param->play_id >= stream->af->dev_cnt) { … … 576 614 } 577 615 616 #if PJ_BBSDK_VER >= 0x100006 617 if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 618 &stream->pb_pcm, &handle, 619 "/dev/snd/voicep", 620 SND_PCM_OPEN_PLAYBACK)) < 0) 621 { 622 TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret)); 623 return PJMEDIA_EAUD_SYSERR; 624 } 625 626 #else 578 627 if ((ret = snd_pcm_open_preferred (&stream->pb_pcm, &card, &dev, 579 628 SND_PCM_OPEN_PLAYBACK)) < 0) … … 582 631 return PJMEDIA_EAUD_SYSERR; 583 632 } 633 #endif 584 634 585 635 /* TODO PJ_ZERO */ … … 623 673 setup.channel = SND_PCM_CHANNEL_PLAYBACK; 624 674 setup.mixer_gid = &group.gid; 625 675 626 676 if ((ret = snd_pcm_plugin_setup (stream->pb_pcm, &setup)) < 0) { 627 677 TRACE_((THIS_FILE, "snd_pcm_plugin_setup ret = %d", ret)); … … 632 682 return PJMEDIA_EAUD_SYSERR; 633 683 } 634 635 if ((ret = snd_mixer_open (&stream->pb_mixer, card,636 setup.mixer_device)) < 0)637 {638 TRACE_((THIS_FILE, "snd_mixer_open ret = %d", ret));639 return PJMEDIA_EAUD_SYSERR;640 }641 642 684 643 685 rate = param->clock_rate; … … 676 718 snd_pcm_channel_params_t pp; 677 719 snd_pcm_channel_setup_t setup; 720 unsigned int handle; 678 721 679 722 if (param->rec_id < 0 || param->rec_id >= stream->af->dev_cnt) 680 723 return PJMEDIA_EAUD_INVDEV; 681 724 725 #if PJ_BBSDK_VER >= 0x100006 726 if ((ret = audio_manager_snd_pcm_open_name(AUDIO_TYPE_VOICE, 727 &stream->ca_pcm, 728 &handle, 729 "/dev/snd/voicec", 730 SND_PCM_OPEN_CAPTURE)) < 0) 731 { 732 TRACE_((THIS_FILE, "audio_manager_snd_pcm_open_name ret = %d", ret)); 733 return PJMEDIA_EAUD_SYSERR; 734 } 735 #else 682 736 /* BB10 Audio init here (not prepare) */ 737 PJ_UNUSED_ARG(handle); 683 738 if ((ret = snd_pcm_open_preferred (&stream->ca_pcm, &card, &dev, 684 739 SND_PCM_OPEN_CAPTURE)) < 0) … … 687 742 return PJMEDIA_EAUD_SYSERR; 688 743 } 744 #endif 689 745 690 746 /* sample reads the capabilities of the capture */ … … 741 797 } 742 798 743 if ((ret = snd_mixer_open (&stream->ca_mixer, card,744 setup.mixer_device)) < 0)745 {746 TRACE_((THIS_FILE,"snd_mixer_open ret = %d",ret));747 return PJMEDIA_EAUD_SYSERR;748 }749 750 799 /* frag_size should be 160 */ 751 800 frame_size = setup.buf.block.frag_size; … … 821 870 if (status != PJ_SUCCESS) { 822 871 if (param->dir & PJMEDIA_DIR_PLAYBACK) { 823 close_play_mixer(stream);824 872 close_play_pcm(stream); 825 873 } … … 953 1001 { 954 1002 struct bb10_stream *stream = (struct bb10_stream*)s; 955 1003 956 1004 TRACE_((THIS_FILE,"bb10_stream_destroy()")); 957 1005
Note: See TracChangeset
for help on using the changeset viewer.