- Timestamp:
- Aug 3, 2018 12:17:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostALSAAudio.cpp
r73408 r73473 99 99 /* latency = period_size * periods / (rate * bytes_per_frame) */ 100 100 101 typedef struct ALSAAUDIOCFG102 {103 int size_in_usec_in;104 int size_in_usec_out;105 const char *pcm_name_in;106 const char *pcm_name_out;107 unsigned int buffer_size_in;108 unsigned int period_size_in;109 unsigned int buffer_size_out;110 unsigned int period_size_out;111 unsigned int threshold;112 113 int buffer_size_in_overriden;114 int period_size_in_overriden;115 116 int buffer_size_out_overriden;117 int period_size_out_overriden;118 119 } ALSAAUDIOCFG, *PALSAAUDIOCFG;120 121 101 static int alsaStreamRecover(snd_pcm_t *phPCM); 122 123 static ALSAAUDIOCFG s_ALSAConf =124 {125 0,126 0,127 "default",128 "default",129 # define DEFAULT_PERIOD_FRAMES 4410 /* 100ms for 44,1 kHz. */130 # define DEFAULT_BUFFER_FRAMES DEFAULT_PERIOD_FRAMES * 2 /* Double (buffering) the period size. */131 DEFAULT_BUFFER_FRAMES,132 DEFAULT_PERIOD_FRAMES,133 DEFAULT_BUFFER_FRAMES,134 DEFAULT_PERIOD_FRAMES,135 DEFAULT_PERIOD_FRAMES * 2, /* Threshold, using double the period size to avoid stutters. */136 0,137 0,138 0,139 0140 };141 102 142 103 /** … … 563 524 do 564 525 { 565 const char *pszDev = fIn ? s_ALSAConf.pcm_name_in : s_ALSAConf.pcm_name_out;526 const char *pszDev = "default"; /** @todo Make this configurable through PALSAAUDIOSTREAMCFG. */ 566 527 if (!pszDev) 567 528 { … … 601 562 } 602 563 603 err = snd_pcm_hw_params_set_access(phPCM, pHWParms, 604 SND_PCM_ACCESS_RW_INTERLEAVED); 564 err = snd_pcm_hw_params_set_access(phPCM, pHWParms, SND_PCM_ACCESS_RW_INTERLEAVED); 605 565 if (err < 0) 606 566 { … … 642 602 } 643 603 644 unsigned int period_size = pCfgReq->period_size; 645 unsigned int buffer_size = pCfgReq->buffer_size; 646 647 if ( !((fIn && s_ALSAConf.size_in_usec_in) 648 || (!fIn && s_ALSAConf.size_in_usec_out))) 649 { 650 if (!buffer_size) 651 { 652 buffer_size = DEFAULT_BUFFER_FRAMES; 653 period_size = DEFAULT_PERIOD_FRAMES; 654 } 655 } 656 657 if (buffer_size) 658 { 659 if ( ( fIn && s_ALSAConf.size_in_usec_in) 660 || (!fIn && s_ALSAConf.size_in_usec_out)) 661 { 662 if (period_size) 663 { 664 err = snd_pcm_hw_params_set_period_time_near(phPCM, pHWParms, 665 &period_size, 0); 666 if (err < 0) 667 { 668 LogRel(("ALSA: Failed to set period time %d\n", pCfgReq->period_size)); 669 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 670 break; 671 } 672 } 673 674 err = snd_pcm_hw_params_set_buffer_time_near(phPCM, pHWParms, 675 &buffer_size, 0); 676 if (err < 0) 677 { 678 LogRel(("ALSA: Failed to set buffer time %d\n", pCfgReq->buffer_size)); 679 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 680 break; 681 } 682 } 683 else 684 { 685 snd_pcm_uframes_t period_size_f = (snd_pcm_uframes_t)period_size; 686 snd_pcm_uframes_t buffer_size_f = (snd_pcm_uframes_t)buffer_size; 687 688 snd_pcm_uframes_t minval; 689 690 if (period_size_f) 691 { 692 minval = period_size_f; 693 694 int dir = 0; 695 err = snd_pcm_hw_params_get_period_size_min(pHWParms, 696 &minval, &dir); 697 if (err < 0) 698 { 699 LogRel(("ALSA: Could not determine minimal period size\n")); 700 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 701 break; 702 } 703 else 704 { 705 LogFunc(("Minimal period size is: %ld\n", minval)); 706 if (period_size_f < minval) 707 { 708 if ( ( fIn && s_ALSAConf.period_size_in_overriden) 709 || (!fIn && s_ALSAConf.period_size_out_overriden)) 710 { 711 LogFunc(("Period size %RU32 is less than minimal period size %RU32\n", 712 period_size_f, minval)); 713 } 714 715 period_size_f = minval; 716 } 717 } 718 719 err = snd_pcm_hw_params_set_period_size_near(phPCM, pHWParms, 720 &period_size_f, 0); 721 LogFunc(("Period size is: %RU32\n", period_size_f)); 722 if (err < 0) 723 { 724 LogRel(("ALSA: Failed to set period size %d (%s)\n", 725 period_size_f, snd_strerror(err))); 726 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 727 break; 728 } 729 } 730 731 /* Calculate default buffer size here since it might have been changed 732 * in the _near functions */ 733 buffer_size_f = 4 * period_size_f; 734 735 minval = buffer_size_f; 736 err = snd_pcm_hw_params_get_buffer_size_min(pHWParms, &minval); 737 if (err < 0) 738 { 739 LogRel(("ALSA: Could not retrieve minimal buffer size\n")); 740 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 741 break; 742 } 743 else 744 { 745 LogFunc(("Minimal buffer size is: %RU32\n", minval)); 746 if (buffer_size_f < minval) 747 { 748 if ( ( fIn && s_ALSAConf.buffer_size_in_overriden) 749 || (!fIn && s_ALSAConf.buffer_size_out_overriden)) 750 { 751 LogFunc(("Buffer size %RU32 is less than minimal buffer size %RU32\n", 752 buffer_size_f, minval)); 753 } 754 755 buffer_size_f = minval; 756 } 757 } 758 759 err = snd_pcm_hw_params_set_buffer_size_near(phPCM, 760 pHWParms, &buffer_size_f); 761 if (err < 0) 762 { 763 LogRel(("ALSA: Failed to set near buffer size %RU32: %s\n", buffer_size_f, snd_strerror(err))); 764 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 765 break; 766 } 767 } 604 snd_pcm_uframes_t period_size_f = pCfgReq->period_size; 605 snd_pcm_uframes_t buffer_size_f = pCfgReq->buffer_size; 606 607 snd_pcm_uframes_t minval = period_size_f; 608 609 int dir = 0; 610 err = snd_pcm_hw_params_get_period_size_min(pHWParms, &minval, &dir); 611 if (err < 0) 612 { 613 LogRel(("ALSA: Could not determine minimal period size\n")); 614 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 615 break; 768 616 } 769 617 else 770 LogFunc(("Warning: Buffer size is not set\n")); 618 { 619 LogFunc(("Minimal period size is: %ld\n", minval)); 620 if (period_size_f < minval) 621 period_size_f = minval; 622 } 623 624 err = snd_pcm_hw_params_set_period_size_near(phPCM, pHWParms, &period_size_f, 0); 625 LogFunc(("Period size is: %RU32\n", period_size_f)); 626 if (err < 0) 627 { 628 LogRel(("ALSA: Failed to set period size %d (%s)\n", 629 period_size_f, snd_strerror(err))); 630 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 631 break; 632 } 633 634 minval = buffer_size_f; 635 err = snd_pcm_hw_params_get_buffer_size_min(pHWParms, &minval); 636 if (err < 0) 637 { 638 LogRel(("ALSA: Could not retrieve minimal buffer size\n")); 639 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 640 break; 641 } 642 else 643 LogFunc(("Minimal buffer size is: %RU32\n", minval)); 644 645 err = snd_pcm_hw_params_set_buffer_size_near(phPCM, pHWParms, &buffer_size_f); 646 if (err < 0) 647 { 648 LogRel(("ALSA: Failed to set near buffer size %RU32: %s\n", buffer_size_f, snd_strerror(err))); 649 rc = VERR_AUDIO_BACKEND_INIT_FAILED; 650 break; 651 } 771 652 772 653 err = snd_pcm_hw_params(phPCM, pHWParms); … … 787 668 788 669 snd_pcm_uframes_t obt_period_size; 789 int dir = 0;790 670 err = snd_pcm_hw_params_get_period_size(pHWParms, &obt_period_size, &dir); 791 671 if (err < 0)
Note:
See TracChangeset
for help on using the changeset viewer.