Changeset 50686 in vbox
- Timestamp:
- Mar 4, 2014 7:21:18 PM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92630
- Location:
- trunk
- Files:
-
- 19 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Config.kmk
r50594 r50686 409 409 # Enable PCI passthrough support. 410 410 VBOX_WITH_PCI_PASSTHROUGH = 1 411 # Enable PDM based audio driver 412 VBOX_WITH_PDM_AUDIO_DRIVER = 411 413 # Enable statically linked dbus support. 412 414 if1of ($(KBUILD_TARGET), linux solaris) -
trunk/include/VBox/vmm/pdmifs.h
r49474 r50686 2533 2533 2534 2534 2535 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 2535 2536 /** Pointer to a network connector interface */ 2536 2537 typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR; … … 2550 2551 2551 2552 2553 #endif 2552 2554 /** @todo r=bird: the two following interfaces are hacks to work around the missing audio driver 2553 2555 * interface. This should be addressed rather than making more temporary hacks. */ -
trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
r45025 r50686 21 21 #define LOG_GROUP LOG_GROUP_DEV_AUDIO 22 22 #include <VBox/vmm/pdmdev.h> 23 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 24 #include <VBox/vmm/pdmaudioifs.h> 25 #endif 23 26 #include <iprt/assert.h> 24 27 #include <iprt/uuid.h> … … 26 29 27 30 #include "VBoxDD.h" 28 31 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 29 32 extern "C" { 30 33 #include "audio.h" 31 34 } 35 #endif 32 36 33 37 … … 194 198 195 199 /** Audio stuff. */ 196 QEMUSoundCard card; 197 200 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 201 QEMUSoundCard card; 202 #endif 198 203 /** Global Control (Bus Master Control Register) */ 199 204 uint32_t glob_cnt; … … 206 211 AC97BusMasterRegs bm_regs[3]; 207 212 uint8_t mixer_data[256]; 213 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 214 /** PCM in */ 215 PPDMGSTVOICEIN voice_pi[2]; 216 /** PCM out */ 217 PPDMGSTVOICEOUT voice_po[2]; 218 /** Mic in */ 219 PPDMGSTVOICEIN voice_mc[2]; 220 #else 208 221 /** PCM in */ 209 222 SWVoiceIn *voice_pi; … … 212 225 /** Mic in */ 213 226 SWVoiceIn *voice_mc; 227 #endif 214 228 uint8_t silence[128]; 215 229 int bup_flag; … … 217 231 PPDMDEVINSR3 pDevIns; 218 232 /** Pointer to the connector of the attached audio driver. */ 233 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 234 PPDMIAUDIOCONNECTOR pDrv[2]; 235 #else 219 236 PPDMIAUDIOCONNECTOR pDrv; 237 #endif 220 238 /** Pointer to the attached audio driver. */ 221 239 PPDMIBASE pDrvBase; … … 355 373 switch (bm_index) 356 374 { 375 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 376 uint32_t lun; 377 case PI_INDEX: 378 for (lun = 0; lun < 2; lun++) 379 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->voice_pi[lun], on); 380 break; 381 case PO_INDEX: 382 for (lun = 0; lun < 2; lun++) 383 pThis->pDrv[lun]->pfnEnableOut(pThis->pDrv[lun], pThis->voice_po[lun], on); 384 break; 385 case MC_INDEX: 386 for (lun = 0; lun < 2; lun++) 387 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->voice_mc[lun], on); 388 break; 389 #else 357 390 case PI_INDEX: AUD_set_active_in( pThis->voice_pi, on); break; 358 391 case PO_INDEX: AUD_set_active_out(pThis->voice_po, on); break; 359 392 case MC_INDEX: AUD_set_active_in( pThis->voice_mc, on); break; 393 #endif 360 394 default: AssertFailed (); break; 361 395 } … … 374 408 pReg->cr = pReg->cr & CR_DONT_CLEAR_MASK; 375 409 pReg->bd_valid = 0; 376 377 410 voice_set_active(pThis, pReg - pThis->bm_regs, 0); 378 411 memset(pThis->silence, 0, sizeof(pThis->silence)); … … 408 441 static void open_voice(PAC97STATE pThis, int index, int freq) 409 442 { 410 audsettings_t as; 411 443 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 444 int rc; 445 #endif 446 LogFlow(("DevIchAC97: open_voice freq = %d\n", freq)); 412 447 if (freq) 413 448 { 449 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 450 audsettings_t as; 414 451 as.freq = freq; 415 452 as.nchannels = 2; 416 453 as.fmt = AUD_FMT_S16; 417 454 as.endianness = 0; 418 455 uint32_t lun; 456 #endif 419 457 switch (index) 420 458 { 421 459 case PI_INDEX: /* PCM in */ 460 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 461 for (uint32_t lun = 0; lun < 2; lun++) 462 rc = pThis->pDrv[lun]->pfnOpenIn(pThis->pDrv[lun], &pThis->voice_pi[lun], "ac97.pi", 463 pThis, pi_callback, freq, 2, AUD_FMT_S16, 0); 464 #else 422 465 pThis->voice_pi = AUD_open_in(&pThis->card, pThis->voice_pi, "ac97.pi", pThis, pi_callback, &as); 466 #endif 423 467 #ifdef LOG_VOICES 424 468 LogRel(("AC97: open PI freq=%d (%s)\n", freq, pThis->voice_pi ? "ok" : "FAIL")); … … 427 471 428 472 case PO_INDEX: /* PCM out */ 473 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 474 for (int lun = 0; lun < 2; lun++) 475 { 476 LogFlow(("LUN###%d\n", lun)); 477 rc = pThis->pDrv[lun]->pfnOpenOut(pThis->pDrv[lun], &pThis->voice_po[lun], "ac97.po", 478 pThis, po_callback, freq, 2, AUD_FMT_S16, 0); 479 } 480 #else 429 481 pThis->voice_po = AUD_open_out(&pThis->card, pThis->voice_po, "ac97.po", pThis, po_callback, &as); 482 #endif 430 483 #ifdef LOG_VOICES 431 484 LogRel(("AC97: open PO freq=%d (%s)\n", freq, pThis->voice_po ? "ok" : "FAIL")); … … 434 487 435 488 case MC_INDEX: /* Mic in */ 489 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 490 for (uint32_t lun = 0; lun < 2; lun++) 491 rc = pThis->pDrv[lun]->pfnOpenIn(pThis->pDrv[lun], &pThis->voice_mc[lun], "ac97.mc", 492 pThis, mc_callback, freq, 2, AUD_FMT_S16, 0); 493 #else 436 494 pThis->voice_mc = AUD_open_in(&pThis->card, pThis->voice_mc, "ac97.mc", pThis, mc_callback, &as); 495 #endif 437 496 #ifdef LOG_VOICES 438 497 LogRel(("AC97: open MC freq=%d (%s)\n", freq, pThis->voice_mc ? "ok" : "FAIL")); … … 446 505 { 447 506 case PI_INDEX: 507 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 508 for (uint32_t lun = 0; lun < 2; lun++) 509 { 510 pThis->pDrv[lun]->pfnCloseIn(pThis->pDrv[lun], pThis->voice_pi[lun]); 511 pThis->voice_pi[lun] = NULL; 512 } 513 #else 448 514 AUD_close_in(&pThis->card, pThis->voice_pi); 515 pThis->voice_pi = NULL; 516 #endif 449 517 #ifdef LOG_VOICES 450 518 LogRel(("AC97: Closing PCM IN\n")); 451 519 #endif 452 pThis->voice_pi = NULL;453 520 break; 454 521 455 522 case PO_INDEX: 523 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 524 for (uint32_t lun = 0; lun < 2; lun++) 525 { 526 pThis->pDrv[lun]->pfnCloseOut(pThis->pDrv[lun], pThis->voice_po[lun]); 527 pThis->voice_po[lun] = NULL; 528 } 529 #else 456 530 AUD_close_out(&pThis->card, pThis->voice_po); 531 pThis->voice_po = NULL; 532 #endif 457 533 #ifdef LOG_VOICES 458 534 LogRel(("AC97: Closing PCM OUT\n")); 459 535 #endif 460 pThis->voice_po = NULL;461 536 break; 462 537 463 538 case MC_INDEX: 539 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 540 for (uint32_t lun = 0; lun < 2; lun++) 541 { 542 pThis->pDrv[lun]->pfnCloseIn(pThis->pDrv[lun], pThis->voice_mc[lun]); 543 pThis->voice_mc[lun] = NULL; 544 } 545 #else 464 546 AUD_close_in(&pThis->card, pThis->voice_mc); 547 pThis->voice_mc = NULL; 548 #endif 465 549 #ifdef LOG_VOICES 466 550 LogRel(("AC97: Closing MIC IN\n")); 467 551 #endif 468 pThis->voice_mc = NULL;469 552 break; 470 553 } … … 478 561 freq = mixer_load(pThis, AC97_PCM_LR_ADC_Rate); 479 562 open_voice(pThis, PI_INDEX, freq); 563 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 564 for (uint32_t lun = 0; lun < 2; lun++) 565 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->voice_pi[lun], active[PI_INDEX]); 566 #else 480 567 AUD_set_active_in(pThis->voice_pi, active[PI_INDEX]); 481 568 #endif 482 569 freq = mixer_load(pThis, AC97_PCM_Front_DAC_Rate); 570 LogFlow(("DevIchAC97: reset_voices calling open_voice freq = %d\n", freq)); 483 571 open_voice(pThis, PO_INDEX, freq); 572 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 573 for (uint32_t lun = 0; lun < 2; lun++) 574 pThis->pDrv[lun]->pfnEnableOut(pThis->pDrv[lun], pThis->voice_po[lun], active[PO_INDEX]); 575 #else 484 576 AUD_set_active_out(pThis->voice_po, active[PO_INDEX]); 577 #endif 485 578 486 579 freq = mixer_load(pThis, AC97_MIC_ADC_Rate); 487 580 open_voice(pThis, MC_INDEX, freq); 581 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 582 for (uint32_t lun = 0; lun < 2; lun++) 583 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->voice_mc[lun], active[MC_INDEX]); 584 #else 488 585 AUD_set_active_in(pThis->voice_mc, active[MC_INDEX]); 586 #endif 489 587 } 490 588 … … 501 599 # ifdef SOFT_VOLUME 502 600 if (index == AC97_Master_Volume_Mute) 601 { 602 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 603 for (uint32_t lun = 0; lun < 1; lun++) 604 pThis->pDrv[lun]->pfnIsSetOutVolume(pThis->pDrv[lun], pThis->voice_po[lun], mute, lvol, rvol); 605 # else 503 606 AUD_set_volume_out(pThis->voice_po, mute, lvol, rvol); 607 # endif 608 } 504 609 else 610 { 611 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 612 for (uint32_t lun = 0; lun < 1; lun++) 613 /* @tod0 in SetVolume no passing audmixerctl_in as its not used in DrvAudio.c */ 614 pThis->pDrv[lun]->pfnSetVolume(pThis->pDrv[lun], &mute, &lvol, &rvol); 615 # else 505 616 AUD_set_volume(mt, &mute, &lvol, &rvol); 617 # endif 618 } 506 619 # else 620 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 621 for (uint32_t lun = 0; lun < 1; lun++) 622 pThis->pDrv[lun]->pfnSetVolume(pThis->pDrv[lun], &mute, &lvol, &rvol); 623 # else 507 624 AUD_set_volume(mt, &mute, &lvol, &rvol); 625 # endif 508 626 # endif 509 627 … … 565 683 audrecsource_t ars = ac97_to_aud_record_source(rs); 566 684 audrecsource_t als = ac97_to_aud_record_source(ls); 567 AUD_set_record_source(&als, &ars);685 //AUD_set_record_source(&als, &ars); 568 686 rs = aud_to_ac97_record_source(ars); 569 687 ls = aud_to_ac97_record_source(als); … … 607 725 mixer_store(pThis, AC97_MIC_ADC_Rate , 0xbb80); 608 726 727 728 609 729 #ifdef USE_MIXER 610 730 record_select(pThis, 0); … … 630 750 uint32_t written = 0; 631 751 int to_copy = 0; 752 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 753 /* count of bytes left in buf to read = samples left in buffer (each of 16 bit) to read denoted by picb * 2) */ 754 uint32_t cbToRead = pReg->picb << 1; 755 uint32_t cbMinToRead; 756 uint8_t tmpbufCopy[4096]; 757 int lun = 0; 758 uint32_t slowestLun; 759 uint32_t cSamplesLeft; 760 #endif 632 761 633 762 temp = audio_MIN(temp, (uint32_t)max); … … 643 772 to_copy = audio_MIN(temp, sizeof(tmpbuf)); 644 773 PDMDevHlpPhysRead(pDevIns, addr, tmpbuf, to_copy); 774 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 775 /* save a copy of the audio samples read */ 776 memcpy(tmpbufCopy, tmpbuf, to_copy); 777 uint32_t slowlun = 0; 778 for (lun = 0; lun < 2; lun++) 779 { 780 LogFlow(("DevIchAC97: write_audio to_copy = %d LUN##%d\n", to_copy, lun)); 781 copied = pThis->pDrv[lun]->pfnWrite(pThis->pDrv[lun], pThis->voice_po[lun], tmpbuf, to_copy); 782 /* call pfnwrite with the same data that has been read from the guest physical memory */ 783 LogFlow(("DevIchAC97: write_audio copied = %d\n", copied)); 784 } 785 #else 645 786 copied = AUD_write(pThis->voice_po, tmpbuf, to_copy); 646 Log(("ac97: write_audio max=%x to_copy=%x copied=%x\n", max, to_copy, copied)); 787 #endif 647 788 if (!copied) 648 789 { … … 673 814 { 674 815 int written = 0; 675 676 816 Log(("ac97: write_bup\n")); 677 817 if (!(pThis->bup_flag & BUP_SET)) … … 693 833 { 694 834 unsigned int temp = audio_MIN((unsigned int)elapsed, sizeof(pThis->silence)); 835 int copied; 695 836 while (temp) 696 837 { 838 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 839 for (int lun = 0; lun < 2; lun++) 840 { 841 LogFlow(("DevIchAC97: write_silence LUN##%d , to_copy=%d\n", lun, temp)); 842 copied = pThis->pDrv[lun]->pfnWrite(pThis->pDrv[lun], pThis->voice_po[lun], pThis->silence, temp); 843 LogFlow(("DevIchAC97: write_silence LUN##%d , copied=%d\n", lun, copied)); 844 } 845 #else 697 846 int copied = AUD_write(pThis->voice_po, pThis->silence, temp); 847 #endif 698 848 if (!copied) 699 849 return; … … 708 858 { 709 859 PPDMDEVINS pDevIns = ICHAC97STATE_2_DEVINS(pThis); 710 uint8_t tmpbuf[4096]; 860 711 861 uint32_t addr = pReg->bd.addr; 712 862 uint32_t temp = pReg->picb << 1; 713 863 uint32_t nread = 0; 714 864 int to_copy = 0; 865 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 866 uint8_t u8DupBuf[4096]; 867 PDMHOSTSTEREOSAMPLE tmpbuf[4096]; 868 PDMHOSTSTEREOSAMPLE MixBuf[2000]; 869 PDMHOSTSTEREOSAMPLE InputBuf[2000]; 870 PPDMHOSTSTEREOSAMPLE SrcBuf; 871 uint32_t cSamplesMixed = 0; 872 uint32_t cTotalSamplesMixed = 0; 873 uint32_t cSamplesRead = 0; 874 uint32_t offRead = 0; 875 uint32_t offWrite = 0; 876 uint32_t cTotalSamplesRead = 0; 877 uint32_t isamp = 0, osamp = 0; 878 uint32_t lun =0; 879 PPDMGSTVOICEIN voice[2]; 880 memset(MixBuf, 0, sizeof(MixBuf)); 881 memset(InputBuf, 0, sizeof(InputBuf)); 882 memset(u8DupBuf, 0, sizeof(u8DupBuf)); 883 void * rate[2]; 884 885 for (lun = 0; lun < 2; lun++) 886 voice[lun] = (pReg - pThis->bm_regs) == MC_INDEX ? pThis->voice_mc[lun] : pThis->voice_pi[lun]; 887 #else 715 888 SWVoiceIn *voice = (pReg - pThis->bm_regs) == MC_INDEX ? pThis->voice_mc : pThis->voice_pi; 889 #endif 716 890 717 891 temp = audio_MIN(temp, (uint32_t)max); … … 722 896 } 723 897 898 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 899 rate[0] = pThis->pDrv[0]->pfnPrepareAudioConversion(pThis->pDrv[0], 48000, 48000); 900 //rate[1] = pThis->pDrv[1]->pfnPrepareAudioConversion(pThis->pDrv[1], 22100, 22100); 901 rate[1] = pThis->pDrv[1]->pfnPrepareAudioConversion(pThis->pDrv[1], 48000, 48000); 902 for (lun = 0; lun < 2; lun++) 903 { 904 temp = pReg->picb << 1; 905 temp = audio_MIN(temp, (uint32_t)max); 906 LogFlow(("DevIchAC97: temp = %d and max = %d\n", temp, max)); 907 if (!temp) 908 { 909 *stop = 1; 910 return 0; 911 } 912 memset(tmpbuf, 0, sizeof(tmpbuf)); 913 offRead = 0; 914 offWrite = 0; 915 cSamplesMixed = 0; 916 nread = 0; 917 while (temp) 918 { 919 int acquired; 920 to_copy = audio_MIN(temp, sizeof(tmpbuf)); 921 acquired = pThis->pDrv[lun]->pfnRead(pThis->pDrv[lun], voice[lun], tmpbuf, to_copy); 922 cSamplesRead = acquired >> voice[lun]->Props.cShift; 923 while (cSamplesRead) 924 { 925 SrcBuf = tmpbuf + offRead; 926 isamp = cSamplesRead; 927 if (!isamp) 928 { 929 LogFlow(("DevichAC97: No Input samples \n")); 930 break; 931 } 932 osamp = cSamplesRead - cSamplesMixed; /*sizeof(MixBuf)*/; 933 pThis->pDrv[lun]->pfnDoRateConvAndMix(pThis->pDrv[lun], rate[lun], SrcBuf, 934 MixBuf, &isamp, &osamp); 935 cSamplesRead -= isamp; 936 offRead += isamp; 937 offWrite += osamp; 938 cSamplesMixed += isamp; 939 } 940 if (!acquired) 941 { 942 *stop = 1; 943 break; 944 } 945 pThis->pDrv[lun]->pfnConvStSampleToDevFmt(pThis->pDrv[lun], u8DupBuf, MixBuf, cSamplesMixed); 946 temp -= acquired; 947 //addr += acquired; 948 //addr += (ctotalSamplexMixed << voice->Props.cShift); 949 //nread += (cSamplesMixed << voice->Props.cShift); 950 nread += acquired; 951 LogFlow(("DevIchAC97: looping temp = %d\n", temp)); 952 cTotalSamplesRead = audio_MAX(cTotalSamplesRead, nread); 953 cTotalSamplesMixed = audio_MAX(cTotalSamplesMixed, cSamplesMixed); 954 } 955 } 956 if (cTotalSamplesMixed) 957 PDMDevHlpPCIPhysWrite(pDevIns, addr, u8DupBuf, (cTotalSamplesMixed << voice[0]->Props.cShift)); 958 addr += (cTotalSamplesMixed << voice[0]->Props.cShift); 959 nread = cTotalSamplesRead; 960 #else 961 uint8_t tmpbuf[4096]; 724 962 while (temp) 725 963 { … … 737 975 nread += acquired; 738 976 } 739 977 #endif 740 978 pReg->bd.addr = addr; 741 979 return nread; … … 806 1044 break; 807 1045 } 808 809 1046 Log(("pReg->picb = %d\n", pReg->picb)); 810 1047 … … 814 1051 815 1052 if (pReg->bd.ctl_len & BD_IOC) 1053 { 816 1054 new_sr |= SR_BCIS; 1055 } 817 1056 818 1057 if (pReg->civ == pReg->lvi) … … 1262 1501 { 1263 1502 mixer_store(pThis, AC97_MIC_ADC_Rate, 0xbb80); 1264 open_voice(pThis, MC_INDEX, 48000);1503 open_voice(pThis, MC_INDEX, 48000); 1265 1504 } 1266 1505 Log(("ac97: Setting extended audio control to %#x\n", u32)); … … 1378 1617 1379 1618 uint8_t active[LAST_INDEX]; 1619 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1620 /* writing only host backend values here and ignoring for webm and VRDE */ 1621 active[PI_INDEX] = pThis->pDrv[0]->pfnIsActiveIn(pThis->pDrv[0], pThis->voice_pi[0]) ? 1 : 0; 1622 active[PO_INDEX] = pThis->pDrv[0]->pfnIsActiveOut(pThis->pDrv[0], pThis->voice_po[0]) ? 1 : 0; 1623 active[MC_INDEX] = pThis->pDrv[0]->pfnIsActiveIn(pThis->pDrv[0], pThis->voice_mc[0]) ? 1 : 0; 1624 #else 1380 1625 active[PI_INDEX] = AUD_is_active_in( pThis->voice_pi) ? 1 : 0; 1381 1626 active[PO_INDEX] = AUD_is_active_out(pThis->voice_po) ? 1 : 0; 1382 1627 active[MC_INDEX] = AUD_is_active_in( pThis->voice_mc) ? 1 : 0; 1628 #endif 1383 1629 SSMR3PutMem(pSSM, active, sizeof(active)); 1384 1630 … … 1543 1789 * Attach driver. 1544 1790 */ 1791 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1792 for (uint32_t lun = 0; lun < 2; lun++) 1793 { 1794 rc = PDMDevHlpDriverAttach(pDevIns, lun, &pThis->IBase, &pThis->pDrvBase, "Audio Driver Port"); 1795 if (RT_SUCCESS(rc)) 1796 { 1797 pThis->pDrv[lun] = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIAUDIOCONNECTOR); 1798 AssertMsgReturn(pThis->pDrv[lun], 1799 ("Configuration error: instance %d has no host audio interface!\n", iInstance), 1800 VERR_PDM_MISSING_INTERFACE); 1801 } 1802 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 1803 Log(("ac97: No attached driver!\n")); 1804 else if (RT_FAILURE(rc)) 1805 { 1806 AssertMsgFailed(("Failed to attach AC97 LUN #%d! rc=%Rrc\n", lun, rc)); 1807 return rc; 1808 } 1809 } 1810 #else 1545 1811 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Audio Driver Port"); 1546 1812 if (rc == VERR_PDM_NO_ATTACHED_DRIVER) … … 1551 1817 return rc; 1552 1818 } 1553 1819 #endif 1820 1821 1822 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1823 pThis->pDrv[0]->pfnRegisterCard(pThis->pDrv[0], "ICH0" ); 1824 #else 1554 1825 AUD_register_card("ICH0", &pThis->card); 1555 1826 #endif 1556 1827 ac97Reset(pDevIns); 1557 1828 1829 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1830 for (uint32_t lun =0; lun < 2; lun++) 1831 { 1832 if (!pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_pi[lun])) 1833 LogRel(("AC97: WARNING: Unable to open PCM IN!\n")); 1834 if (!pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_mc[lun])) 1835 LogRel(("AC97: WARNING: Unable to open PCM MC!\n")); 1836 if (!pThis->pDrv[lun]->pfnIsHostVoiceOutOK(pThis->pDrv[lun], pThis->voice_po[lun])) 1837 LogRel(("AC97: WARNING: Unable to open PCM OUT!\n")); 1838 } 1839 #else 1558 1840 if (!AUD_is_host_voice_in_ok(pThis->voice_pi)) 1559 1841 LogRel(("AC97: WARNING: Unable to open PCM IN!\n")); … … 1563 1845 LogRel(("AC97: WARNING: Unable to open PCM OUT!\n")); 1564 1846 1847 #endif 1848 1849 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1850 for (uint32_t lun = 0; lun < 2; lun++) 1851 { 1852 if ( !pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_pi[lun]) 1853 && !pThis->pDrv[lun]->pfnIsHostVoiceOutOK(pThis->pDrv[lun], pThis->voice_po[lun]) 1854 && !pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_mc[lun])) 1855 { 1856 /* Was not able initialize *any* voice. Select the NULL audio driver instead */ 1857 pThis->pDrv[lun]->pfnCloseIn(pThis->pDrv[lun], pThis->voice_pi[lun]); 1858 pThis->pDrv[lun]->pfnCloseOut(pThis->pDrv[lun], pThis->voice_po[lun]); 1859 pThis->pDrv[lun]->pfnCloseIn(pThis->pDrv[lun], pThis->voice_mc[lun]); 1860 1861 pThis->voice_po[lun] = NULL; 1862 pThis->voice_pi[lun] = NULL; 1863 pThis->voice_mc[lun] = NULL; 1864 1865 pThis->pDrv[lun]->pfnInitNull(pThis->pDrv[lun]); 1866 ac97Reset(pDevIns); 1867 1868 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding", 1869 N_("No audio devices could be opened. Selecting the NULL audio backend " 1870 "with the consequence that no sound is audible")); 1871 } 1872 else if ( !pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_pi[lun]) 1873 || !pThis->pDrv[lun]->pfnIsHostVoiceOutOK(pThis->pDrv[lun], pThis->voice_po[lun]) 1874 || !pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_mc[lun])) 1875 { 1876 char szMissingVoices[128]; 1877 size_t len = 0; 1878 if (!pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_pi[lun])) 1879 len = RTStrPrintf(szMissingVoices, sizeof(szMissingVoices), "PCM_in"); 1880 if (!pThis->pDrv[lun]->pfnIsHostVoiceOutOK(pThis->pDrv[lun], pThis->voice_po[lun])) 1881 len += RTStrPrintf(szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_out" : "PCM_out"); 1882 if (!pThis->pDrv[lun]->pfnIsHostVoiceInOK(pThis->pDrv[lun], pThis->voice_mc[lun])) 1883 len += RTStrPrintf(szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_mic" : "PCM_mic"); 1884 1885 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding", 1886 N_("Some audio devices (%s) could not be opened. Guest applications generating audio " 1887 "output or depending on audio input may hang. Make sure your host audio device " 1888 "is working properly. Check the logfile for error messages of the audio " 1889 "subsystem"), szMissingVoices); 1890 } 1891 } 1892 #else 1565 1893 if ( !AUD_is_host_voice_in_ok( pThis->voice_pi) 1566 1894 && !AUD_is_host_voice_out_ok(pThis->voice_po) 1567 1895 && !AUD_is_host_voice_in_ok( pThis->voice_mc)) 1568 1896 { 1569 /* Was not able initialize *any* voice. Select the NULL audio driver instead */ 1570 AUD_close_in( &pThis->card, pThis->voice_pi); 1897 AUD_close_in(&pThis->card, pThis->voice_pi); 1571 1898 AUD_close_out(&pThis->card, pThis->voice_po); 1572 AUD_close_in( &pThis->card, pThis->voice_mc); 1899 AUD_close_in(&pThis->card, pThis->voice_mc); 1900 1573 1901 pThis->voice_po = NULL; 1574 1902 pThis->voice_pi = NULL; … … 1600 1928 "subsystem"), szMissingVoices); 1601 1929 } 1602 1930 #endif 1603 1931 return VINF_SUCCESS; 1604 1932 } -
trunk/src/VBox/Devices/Audio/DevIchHda.cpp
r49305 r50686 25 25 #define LOG_GROUP LOG_GROUP_DEV_AUDIO 26 26 #include <VBox/vmm/pdmdev.h> 27 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 28 #include <VBox/vmm/pdmaudioifs.h> 29 #endif 27 30 #include <VBox/version.h> 28 31 … … 38 41 #include "VBoxDD.h" 39 42 43 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 40 44 extern "C" { 41 45 #include "audio.h" 42 46 } 47 #endif 43 48 #include "DevIchHdaCodec.h" 44 49 … … 547 552 548 553 /** Pointer to the connector of the attached audio driver. */ 554 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 555 R3PTRTYPE(PPDMIAUDIOCONNECTOR) pDrv[2]; 556 #else 549 557 R3PTRTYPE(PPDMIAUDIOCONNECTOR) pDrv; 558 #endif 550 559 /** Pointer to the attached audio driver. */ 551 560 R3PTRTYPE(PPDMIBASE) pDrvBase; … … 577 586 /** Flag whether the RC part is enabled. */ 578 587 bool fRCEnabled; 588 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 579 589 /** The HDA codec state. */ 590 R3PTRTYPE(PHDACODEC) pCodec[2]; 591 #else 580 592 R3PTRTYPE(PHDACODEC) pCodec; 593 #endif 581 594 uint64_t u64BaseTS; 582 595 /** 1.2.3.4.5.6.7. - someone please tell me what I'm counting! - .8.9.10... */ … … 1108 1121 corbRp++; 1109 1122 cmd = pThis->pu32CorbBuf[corbRp]; 1123 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1124 for (uint32_t lun = 0; lun < 1; lun++) 1125 rc = pThis->pCodec[lun]->pfnLookup(pThis->pCodec[lun], cmd, &pfn); 1126 #else 1110 1127 rc = pThis->pCodec->pfnLookup(pThis->pCodec, cmd, &pfn); 1128 #endif 1111 1129 if (RT_FAILURE(rc)) 1112 1130 AssertRCReturn(rc, rc); … … 1115 1133 1116 1134 if (RT_LIKELY(pfn)) 1135 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1136 { 1137 for (uint32_t lun = 0; lun < 1; lun++) 1138 rc = pfn(pThis->pCodec[lun], cmd, &resp); 1139 } 1140 #else 1117 1141 rc = pfn(pThis->pCodec, cmd, &resp); 1142 #endif 1118 1143 else 1119 1144 rc = VERR_INVALID_FUNCTION; … … 1433 1458 { 1434 1459 case HDA_REG_SD0CTL: 1460 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1461 for (uint32_t lun = 0; lun < 1; lun++) 1462 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->pCodec[lun]->SwVoiceIn, fRun); 1463 #else 1435 1464 AUD_set_active_in(pThis->pCodec->SwVoiceIn, fRun); 1465 #endif 1436 1466 break; 1437 1467 case HDA_REG_SD4CTL: 1468 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1469 for (uint32_t lun = 0; lun < 1; lun++) 1470 pThis->pDrv[lun]->pfnEnableOut(pThis->pDrv[lun], pThis->pCodec[lun]->SwVoiceOut, fRun); 1471 #else 1438 1472 AUD_set_active_out(pThis->pCodec->SwVoiceOut, fRun); 1473 #endif 1439 1474 break; 1440 1475 default: … … 1524 1559 1525 1560 #ifdef IN_RING3 1561 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1562 static void hdaSdFmtToAudSettings(uint32_t u32SdFmt, uint32_t * pFrequency, uint32_t * pChannels, audfmt_e *pFormat, uint32_t *pEndian) 1563 # else 1526 1564 static void hdaSdFmtToAudSettings(uint32_t u32SdFmt, audsettings_t *pAudSetting) 1527 { 1565 # endif 1566 { 1567 # ifndef VBOX_WITH_PDM_AUDIO_DRIVER 1528 1568 Assert((pAudSetting)); 1529 #define EXTRACT_VALUE(v, mask, shift) ((v & ((mask) << (shift))) >> (shift)) 1569 # endif 1570 # define EXTRACT_VALUE(v, mask, shift) ((v & ((mask) << (shift))) >> (shift)) 1530 1571 uint32_t u32Hz = (u32SdFmt & HDA_SDFMT_BASE_RATE_SHIFT) ? 44100 : 48000; 1531 1572 uint32_t u32HzMult = 1; … … 1551 1592 case 7: u32HzDiv = 8; break; 1552 1593 } 1594 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1595 *pFrequency = u32Hz * u32HzMult / u32HzDiv; 1596 # else 1553 1597 pAudSetting->freq = u32Hz * u32HzMult / u32HzDiv; 1598 # endif 1554 1599 1555 1600 switch (EXTRACT_VALUE(u32SdFmt, HDA_SDFMT_BITS_MASK, HDA_SDFMT_BITS_SHIFT)) … … 1557 1602 case 0: 1558 1603 Log(("hda: %s requested 8-bit\n", __FUNCTION__)); 1604 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1605 *pFormat = AUD_FMT_S8; 1606 # else 1559 1607 pAudSetting->fmt = AUD_FMT_S8; 1608 # endif 1560 1609 break; 1561 1610 case 1: 1562 1611 Log(("hda: %s requested 16-bit\n", __FUNCTION__)); 1612 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1613 *pFormat = AUD_FMT_S16; 1614 # else 1563 1615 pAudSetting->fmt = AUD_FMT_S16; 1616 # endif 1564 1617 break; 1565 1618 case 2: … … 1571 1624 case 4: 1572 1625 Log(("hda: %s requested 32-bit\n", __FUNCTION__)); 1626 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1627 *pFormat = AUD_FMT_S32; 1628 # else 1573 1629 pAudSetting->fmt = AUD_FMT_S32; 1630 # endif 1574 1631 break; 1575 1632 default: 1576 1633 AssertMsgFailed(("Unsupported")); 1577 1634 } 1635 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1636 *pChannels = (u32SdFmt & 0xf) + 1; 1637 *pFormat = AUD_FMT_S16; 1638 *pEndian = 0; 1639 # else 1578 1640 pAudSetting->nchannels = (u32SdFmt & 0xf) + 1; 1579 1641 pAudSetting->fmt = AUD_FMT_S16; 1580 1642 pAudSetting->endianness = 0; 1581 #undef EXTRACT_VALUE 1643 # endif 1644 # undef EXTRACT_VALUE 1582 1645 } 1583 1646 #endif … … 1589 1652 /** @todo a bit more investigation is required here. */ 1590 1653 int rc = 0; 1591 audsettings_t as;1592 1654 /* no reason to reopen voice with same settings */ 1593 1655 if (u32Value == HDA_REG_IND(pThis, iReg)) 1594 1656 return VINF_SUCCESS; 1657 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1658 uint32_t uFrequency; 1659 uint32_t cChannels; 1660 audfmt_e Format; 1661 uint32_t Endian; 1662 hdaSdFmtToAudSettings(u32Value, &uFrequency, &cChannels, &Format, &Endian); 1663 # else 1664 audsettings_t as; 1595 1665 hdaSdFmtToAudSettings(u32Value, &as); 1666 # endif 1596 1667 switch (iReg) 1597 1668 { 1598 1669 case HDA_REG_SD0FMT: 1670 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1671 for (uint32_t lun = 0; lun < 1; lun++) 1672 rc = hdaCodecOpenVoice(pThis->pCodec[lun], PI_INDEX, uFrequency, cChannels, Format, Endian); 1673 # else 1599 1674 rc = hdaCodecOpenVoice(pThis->pCodec, PI_INDEX, &as); 1675 # endif 1600 1676 break; 1601 1677 case HDA_REG_SD4FMT: 1678 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1679 for (uint32_t lun = 0; lun < 1; lun++) 1680 rc = hdaCodecOpenVoice(pThis->pCodec[lun], PO_INDEX, uFrequency, cChannels, Format, Endian); 1681 # else 1602 1682 rc = hdaCodecOpenVoice(pThis->pCodec, PO_INDEX, &as); 1683 # endif 1603 1684 break; 1604 1685 default: … … 1668 1749 HDA_REG(pThis, IRS) = HDA_REG_FIELD_FLAG_MASK(IRS, ICB); /* busy */ 1669 1750 Log(("hda: IC:%x\n", cmd)); 1751 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1752 for (uint32_t lun = 0; lun < 1; lun++) 1753 rc = pThis->pCodec[lun]->pfnLookup(pThis->pCodec[lun], cmd, &pfn); 1754 # else 1670 1755 rc = pThis->pCodec->pfnLookup(pThis->pCodec, cmd, &pfn); 1756 # endif 1671 1757 if (RT_FAILURE(rc)) 1672 1758 AssertRCReturn(rc, rc); 1759 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1760 for (uint32_t lun = 0; lun < 1; lun++) 1761 rc = pfn(pThis->pCodec[lun], cmd, &resp); 1762 #else 1673 1763 rc = pfn(pThis->pCodec, cmd, &resp); 1764 #endif 1674 1765 if (RT_FAILURE(rc)) 1675 1766 AssertRCReturn(rc, rc); … … 1974 2065 * read from backend input line to the last unreported position or at the begining. 1975 2066 */ 2067 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2068 //cbBackendCopy = pThis->pDrv[0]->pfnRead(pThis->pDrv[0], pThis->pCodec[0]->SwVoiceIn, pBdle->au8HdaBuffer, cb2Copy); 2069 //cbBackendCopy = pThis->pDrv[0]->pfnRead(pThis->pDrv[0], pThis->pCodec[1]->SwVoiceIn, pBdle->au8HdaBuffer, cb2Copy); 2070 #else 1976 2071 cbBackendCopy = AUD_read(pThis->pCodec->SwVoiceIn, pBdle->au8HdaBuffer, cb2Copy); 2072 #endif 1977 2073 /* 1978 2074 * write the HDA DMA buffer … … 2025 2121 * Feed the newly fetched samples, including unreported ones, to the backend. 2026 2122 */ 2123 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2124 for (uint32_t lun = 0; lun < 1; lun++) 2125 cbBackendCopy = pThis->pDrv[lun]->pfnWrite(pThis->pDrv[lun], pThis->pCodec[lun]->SwVoiceOut, pBdle->au8HdaBuffer, cb2Copy + pBdle->cbUnderFifoW); 2126 LogFlow(("cbBackendCopy write %d bytes \n", cbBackendCopy)); 2127 #else 2027 2128 cbBackendCopy = AUD_write (pThis->pCodec->SwVoiceOut, pBdle->au8HdaBuffer, cb2Copy + pBdle->cbUnderFifoW); 2129 #endif 2028 2130 hdaBackendWriteTransferReported(pBdle, cb2Copy, cbBackendCopy, &cbTransferred, pu32Avail); 2029 2131 } … … 2548 2650 PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE); 2549 2651 /* Save Codec nodes states */ 2652 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2653 hdaCodecSaveState(pThis->pCodec[0], pSSM); 2654 #else 2550 2655 hdaCodecSaveState(pThis->pCodec, pSSM); 2656 #endif 2551 2657 2552 2658 /* Save MMIO registers */ … … 2575 2681 * Load Codec nodes states. 2576 2682 */ 2683 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2684 int rc = hdaCodecLoadState(pThis->pCodec[0], pSSM, uVersion); 2685 #else 2577 2686 int rc = hdaCodecLoadState(pThis->pCodec, pSSM, uVersion); 2687 #endif 2578 2688 if (RT_FAILURE(rc)) 2579 2689 return rc; … … 2637 2747 * Update stuff after the state changes. 2638 2748 */ 2749 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2750 for (uint32_t lun = 0; lun < 1; lun++) 2751 { 2752 pThis->pDrv[lun]->pfnEnableIn(pThis->pDrv[lun], pThis->pCodec[lun]->SwVoiceIn, SDCTL(pThis, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN)); 2753 pThis->pDrv[lun]->pfnEnableOut(pThis->pDrv[lun], pThis->pCodec[lun]->SwVoiceOut, SDCTL(pThis, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN)); 2754 } 2755 #else 2639 2756 AUD_set_active_in(pThis->pCodec->SwVoiceIn, SDCTL(pThis, 0) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN)); 2640 2757 AUD_set_active_out(pThis->pCodec->SwVoiceOut, SDCTL(pThis, 4) & HDA_REG_FIELD_FLAG_MASK(SDCTL, RUN)); 2758 #endif 2641 2759 2642 2760 pThis->u64CORBBase = RT_MAKE_U64(HDA_REG(pThis, CORBLBASE), HDA_REG(pThis, CORBUBASE)); … … 2813 2931 { 2814 2932 PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE); 2933 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2934 for (uint32_t lun = 0; lun < 1; lun++) 2935 if (pThis->pCodec[lun]->pfnCodecDbgListNodes) 2936 pThis->pCodec[lun]->pfnCodecDbgListNodes(pThis->pCodec[lun], pHlp, pszArgs); 2937 else 2938 pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n"); 2939 #else 2815 2940 if (pThis->pCodec->pfnCodecDbgListNodes) 2816 2941 pThis->pCodec->pfnCodecDbgListNodes(pThis->pCodec, pHlp, pszArgs); 2817 2942 else 2818 2943 pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n"); 2944 #endif 2819 2945 } 2820 2946 … … 2826 2952 { 2827 2953 PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE); 2954 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2955 for (uint32_t lun = 0; lun < 1; lun++) 2956 if (pThis->pCodec[lun]->pfnCodecDbgSelector) 2957 pThis->pCodec[lun]->pfnCodecDbgSelector(pThis->pCodec[lun], pHlp, pszArgs); 2958 else 2959 pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n"); 2960 #else 2828 2961 if (pThis->pCodec->pfnCodecDbgSelector) 2829 2962 pThis->pCodec->pfnCodecDbgSelector(pThis->pCodec, pHlp, pszArgs); 2830 2963 else 2831 2964 pHlp->pfnPrintf(pHlp, "Codec implementation doesn't provide corresponding callback.\n"); 2965 #endif 2832 2966 } 2833 2967 … … 2922 3056 PHDASTATE pThis = PDMINS_2_DATA(pDevIns, PHDASTATE); 2923 3057 3058 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 3059 for (uint32_t lun = 0; lun < 1; lun++) 3060 { 3061 if (pThis->pCodec[lun]) 3062 { 3063 int rc = hdaCodecDestruct(pThis->pCodec[lun]); 3064 AssertRC(rc); 3065 RTMemFree(pThis->pCodec[lun]); 3066 pThis->pCodec[lun] = NULL; 3067 } 3068 } 3069 #else 2924 3070 if (pThis->pCodec) 2925 3071 { … … 2930 3076 pThis->pCodec = NULL; 2931 3077 } 3078 #endif 2932 3079 2933 3080 RTMemFree(pThis->pu32CorbBuf); … … 3082 3229 if (RT_FAILURE(rc)) 3083 3230 return rc; 3084 3231 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 3232 //for (iter = 0; i < 3; i++) 3233 { 3234 /* 3235 * Attach driver. 3236 */ 3237 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Audio Driver Port"); 3238 if (RT_SUCCESS(rc)) 3239 { 3240 pThis->pDrv[0] = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIAUDIOCONNECTOR); 3241 AssertMsgReturn(pThis->pDrv, 3242 ("Configuration error: instance %d has no host audio interface!\n", iInstance), 3243 VERR_PDM_MISSING_INTERFACE); 3244 } 3245 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 3246 { 3247 Log(("ac97: No attached driver!\n")); 3248 } 3249 else if (RT_FAILURE(rc)) 3250 { 3251 AssertMsgFailed(("Failed to attach AC97 LUN #0! rc=%Rrc\n", rc)); 3252 return rc; 3253 } 3254 rc = PDMDevHlpDriverAttach(pDevIns, 1, &pThis->IBase, &pThis->pDrvBase, "Audio Driver Port"); 3255 if (RT_SUCCESS(rc)) 3256 { 3257 pThis->pDrv[1] = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIAUDIOCONNECTOR); 3258 AssertMsgReturn(pThis->pDrv[1], 3259 ("Configuration error: instance %d has no host audio interface!\n", iInstance), 3260 VERR_PDM_MISSING_INTERFACE); 3261 } 3262 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 3263 { 3264 Log(("ac97: No attached driver! LUN#1\n")); 3265 } 3266 else if (RT_FAILURE(rc)) 3267 { 3268 AssertMsgFailed(("Failed to attach AC97 LUN #1! rc=%Rrc\n", rc)); 3269 return rc; 3270 } 3271 } 3272 #else 3085 3273 /* 3086 3274 * Attach driver. … … 3094 3282 return rc; 3095 3283 } 3096 3284 #endif 3097 3285 /* Construct codec state. */ 3286 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 3287 pThis->pCodec[0] = (PHDACODEC)RTMemAllocZ(sizeof(HDACODEC)); 3288 if (!pThis->pCodec[0]) 3289 return PDMDEV_SET_ERROR(pDevIns, VERR_NO_MEMORY, N_("HDA: Out of memory allocating codec state")); 3290 pThis->pCodec[1] = (PHDACODEC)RTMemAllocZ(sizeof(HDACODEC)); 3291 if (!pThis->pCodec[1]) 3292 return PDMDEV_SET_ERROR(pDevIns, VERR_NO_MEMORY, N_("HDA: Out of memory allocating codec state")); 3293 3294 pThis->pCodec[0]->pvHDAState = pThis; 3295 pThis->pCodec[1]->pvHDAState = pThis; 3296 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 3297 pThis->pCodec[0]->pDrv = pThis->pDrv[0]; 3298 //pThis->pCodec[1]->pDrv = pThis->pDrv[1]; 3299 #endif 3300 rc = hdaCodecConstruct(pDevIns, pThis->pCodec[0], pCfgHandle); 3301 if (RT_FAILURE(rc)) 3302 AssertRCReturn(rc, rc); 3303 rc = hdaCodecConstruct(pDevIns, pThis->pCodec[1], pCfgHandle); 3304 if (RT_FAILURE(rc)) 3305 AssertRCReturn(rc, rc); 3306 3307 /* ICH6 datasheet defines 0 values for SVID and SID (18.1.14-15), which together with values returned for 3308 verb F20 should provide device/codec recognition. */ 3309 Assert(pThis->pCodec[0]->u16VendorId); 3310 Assert(pThis->pCodec[0]->u16DeviceId); 3311 Assert(pThis->pCodec[1]->u16VendorId); 3312 Assert(pThis->pCodec[1]->u16DeviceId); 3313 PCIDevSetSubSystemVendorId(&pThis->PciDev, pThis->pCodec[0]->u16VendorId); /* 2c ro - intel.) */ 3314 PCIDevSetSubSystemId( &pThis->PciDev, pThis->pCodec[0]->u16DeviceId); /* 2e ro. */ 3315 PCIDevSetSubSystemVendorId(&pThis->PciDev, pThis->pCodec[1]->u16VendorId); /* 2c ro - intel.) */ 3316 PCIDevSetSubSystemId( &pThis->PciDev, pThis->pCodec[1]->u16DeviceId); /* 2e ro. */ 3317 3318 hdaReset(pDevIns); 3319 pThis->pCodec[0]->id = 0; 3320 pThis->pCodec[0]->pfnTransfer = hdaTransfer; 3321 pThis->pCodec[0]->pfnReset = hdaCodecReset; 3322 pThis->pCodec[1]->id = 0; 3323 pThis->pCodec[1]->pfnTransfer = hdaTransfer; 3324 pThis->pCodec[1]->pfnReset = hdaCodecReset; 3325 #else 3326 3098 3327 pThis->pCodec = (PHDACODEC)RTMemAllocZ(sizeof(HDACODEC)); 3099 3328 if (!pThis->pCodec) … … 3123 3352 HDA_REG(pThis, WAKEEN) = 0x0; 3124 3353 HDA_REG(pThis, STATESTS) = 0x0; 3125 3354 #endif 3126 3355 /* 3127 3356 * Debug and string formatter types. -
trunk/src/VBox/Devices/Audio/DevIchHdaCodec.cpp
r44669 r50686 26 26 #define LOG_GROUP LOG_GROUP_DEV_AUDIO 27 27 #include <VBox/vmm/pdmdev.h> 28 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 29 #include <VBox/vmm/pdmaudioifs.h> 30 #endif 28 31 #include <iprt/assert.h> 29 32 #include <iprt/uuid.h> … … 34 37 35 38 #include "VBoxDD.h" 39 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 36 40 extern "C" { 37 41 #include "audio.h" 38 42 } 43 #endif 39 44 #include "DevIchHdaCodec.h" 40 45 … … 696 701 } CODECNODE, *PCODECNODE; 697 702 AssertNodeSize(CODECNODE, 60 + 6); 698 699 700 703 /******************************************************************************* 701 704 * Global Variables * … … 1160 1163 * Misc helpers. 1161 1164 */ 1162 1165 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1166 static int hdaCodecToAudVolume(PHDACODEC pThis, AMPLIFIER *pAmp, audmixerctl_t mt) 1167 #else 1163 1168 static int hdaCodecToAudVolume(AMPLIFIER *pAmp, audmixerctl_t mt) 1169 #endif 1164 1170 { 1165 1171 uint32_t dir = AMPLIFIER_OUT; … … 1180 1186 uint8_t lVol = AMPLIFIER_REGISTER(*pAmp, dir, AMPLIFIER_LEFT, 0) & 0x7f; 1181 1187 uint8_t rVol = AMPLIFIER_REGISTER(*pAmp, dir, AMPLIFIER_RIGHT, 0) & 0x7f; 1188 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1189 /* @todo in SetVolume no passing audmixerctl_in as its not used in DrvAudio.c */ 1190 pThis->pDrv->pfnSetVolume(pThis->pDrv, &mute, &lVol, &rVol); 1191 #else 1182 1192 AUD_set_volume(mt, &mute, &lVol, &rVol); 1193 #endif 1183 1194 return VINF_SUCCESS; 1184 1195 } … … 1328 1339 } 1329 1340 if (CODEC_NID(cmd) == pThis->u8DacLineOut) 1341 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1342 hdaCodecToAudVolume(pThis, pAmplifier, AUD_MIXER_VOLUME); 1343 #else 1330 1344 hdaCodecToAudVolume(pAmplifier, AUD_MIXER_VOLUME); 1345 #endif 1331 1346 if (CODEC_NID(cmd) == pThis->u8AdcVolsLineIn) /* Microphone */ 1347 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1348 hdaCodecToAudVolume(pThis, pAmplifier, AUD_MIXER_LINE_IN); 1349 #else 1332 1350 hdaCodecToAudVolume(pAmplifier, AUD_MIXER_LINE_IN); 1351 #endif 1333 1352 return VINF_SUCCESS; 1334 1353 } … … 2238 2257 2239 2258 2240 2241 2259 /* 2242 2260 * APIs exposed to DevHDA. … … 2252 2270 * format) before enabling. 2253 2271 */ 2272 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2273 int hdaCodecOpenVoice(PHDACODEC pThis, ENMSOUNDSOURCE enmSoundSource, uint32_t uFrequency, uint32_t cChannels, 2274 audfmt_e fmt, uint32_t Endian) 2275 #else 2254 2276 int hdaCodecOpenVoice(PHDACODEC pThis, ENMSOUNDSOURCE enmSoundSource, audsettings_t *pAudioSettings) 2277 #endif 2255 2278 { 2256 2279 int rc; 2280 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2281 Assert(pThis); 2282 if (!pThis) 2283 return -1; 2284 #else 2257 2285 Assert(pThis && pAudioSettings); 2258 2286 if ( !pThis 2259 2287 || !pAudioSettings) 2260 2288 return -1; 2289 #endif 2261 2290 switch (enmSoundSource) 2262 2291 { 2263 2292 case PI_INDEX: 2293 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2294 /* old and new stream settings are not same. Then only call open */ 2295 2296 //if (!hdaCodecCompareAudioSettings(&(pThis->SwVoiceIn)->info, pAudioSettings) && !pThis->SwVoiceIn) 2297 rc = pThis->pDrv->pfnOpenIn(pThis->pDrv, &pThis->SwVoiceIn, "hda.in", pThis, pi_callback, uFrequency, 2298 cChannels, fmt, Endian); 2299 #else 2264 2300 pThis->SwVoiceIn = AUD_open_in(&pThis->card, pThis->SwVoiceIn, "hda.in", pThis, pi_callback, pAudioSettings); 2301 #endif 2265 2302 rc = pThis->SwVoiceIn ? 0 : 1; 2266 2303 break; 2267 2304 case PO_INDEX: 2305 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2306 rc = pThis->pDrv->pfnOpenOut(pThis->pDrv, &pThis->SwVoiceOut, "hda.out", pThis, po_callback, uFrequency, 2307 cChannels, fmt, Endian); 2308 #else 2268 2309 pThis->SwVoiceOut = AUD_open_out(&pThis->card, pThis->SwVoiceOut, "hda.out", pThis, po_callback, pAudioSettings); 2310 #endif 2269 2311 rc = pThis->SwVoiceOut ? 0 : 1; 2270 2312 break; … … 2273 2315 } 2274 2316 if (!rc) 2317 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2318 LogRel(("HdaCodec: can't open %s fmt(freq: %d)\n", enmSoundSource == PI_INDEX? "in" : "out", uFrequency)); 2319 #else 2275 2320 LogRel(("HdaCodec: can't open %s fmt(freq: %d)\n", enmSoundSource == PI_INDEX? "in" : "out", pAudioSettings->freq)); 2321 #endif 2276 2322 return rc; 2277 2323 } … … 2344 2390 */ 2345 2391 if (hdaCodecIsDacNode(pThis, pThis->u8DacLineOut)) 2392 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2393 hdaCodecToAudVolume(pThis, &pThis->paNodes[pThis->u8DacLineOut].dac.B_params, AUD_MIXER_VOLUME); 2394 #else 2346 2395 hdaCodecToAudVolume(&pThis->paNodes[pThis->u8DacLineOut].dac.B_params, AUD_MIXER_VOLUME); 2396 #endif 2347 2397 else if (hdaCodecIsSpdifOutNode(pThis, pThis->u8DacLineOut)) 2398 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2399 hdaCodecToAudVolume(pThis, &pThis->paNodes[pThis->u8DacLineOut].spdifout.B_params, AUD_MIXER_VOLUME); 2400 hdaCodecToAudVolume(pThis, &pThis->paNodes[pThis->u8AdcVolsLineIn].adcvol.B_params, AUD_MIXER_LINE_IN); 2401 #else 2348 2402 hdaCodecToAudVolume(&pThis->paNodes[pThis->u8DacLineOut].spdifout.B_params, AUD_MIXER_VOLUME); 2349 2403 hdaCodecToAudVolume(&pThis->paNodes[pThis->u8AdcVolsLineIn].adcvol.B_params, AUD_MIXER_LINE_IN); 2404 #endif 2350 2405 2351 2406 return VINF_SUCCESS; … … 2368 2423 int rc = stac9220Construct(pThis); 2369 2424 AssertRC(rc); 2425 2370 2426 2371 2427 /* common root node initializers */ … … 2378 2434 2379 2435 /// @todo r=michaln: Was this meant to be 'HDA' or something like that? (AC'97 was on ICH0) 2380 AUD_register_card ("ICH0", &pThis->card); 2436 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2437 pThis->pDrv->pfnRegisterCard(pThis->pDrv, "ICH0"); 2438 #else 2439 AUD_register_card("ICH0", &pThis->card); 2381 2440 2382 2441 /* 44.1 kHz */ … … 2386 2445 as.fmt = AUD_FMT_S16; 2387 2446 as.endianness = 0; 2447 #endif 2388 2448 2389 2449 pThis->paNodes[1].node.au32F00_param[0xA] = CODEC_F00_0A_16_BIT; 2450 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2451 hdaCodecOpenVoice(pThis, PI_INDEX, 44100, 2, AUD_FMT_S16, 0); 2452 hdaCodecOpenVoice(pThis, PO_INDEX, 44100, 2, AUD_FMT_S16, 0); 2453 #else 2390 2454 hdaCodecOpenVoice(pThis, PI_INDEX, &as); 2391 2455 hdaCodecOpenVoice(pThis, PO_INDEX, &as); 2456 #endif 2457 2392 2458 pThis->paNodes[1].node.au32F00_param[0xA] |= CODEC_F00_0A_44_1KHZ; 2393 2459 … … 2399 2465 pThis->pfnCodecNodeReset(pThis, i, &pThis->paNodes[i]); 2400 2466 } 2401 2467 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2468 hdaCodecToAudVolume(pThis, &pThis->paNodes[pThis->u8DacLineOut].dac.B_params, AUD_MIXER_VOLUME); 2469 hdaCodecToAudVolume(pThis, &pThis->paNodes[pThis->u8AdcVolsLineIn].adcvol.B_params, AUD_MIXER_LINE_IN); 2470 #else 2402 2471 hdaCodecToAudVolume(&pThis->paNodes[pThis->u8DacLineOut].dac.B_params, AUD_MIXER_VOLUME); 2403 2472 hdaCodecToAudVolume(&pThis->paNodes[pThis->u8AdcVolsLineIn].adcvol.B_params, AUD_MIXER_LINE_IN); 2473 #endif 2404 2474 2405 2475 /* If no host voices were created, then fallback to nul audio. */ 2476 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2477 if (!pThis->pDrv->pfnIsHostVoiceInOK(pThis->pDrv, pThis->SwVoiceIn)) 2478 LogRel (("HDA: pfnIsHostVoiceInOK WARNING: Unable to open PCM IN!\n")); 2479 if (!pThis->pDrv->pfnIsHostVoiceOutOK(pThis->pDrv, pThis->SwVoiceOut)) 2480 LogRel (("HDA: pfnIsHostVoiceOutOK WARNING: Unable to open PCM OUT!\n")); 2481 #else 2406 2482 if (!AUD_is_host_voice_in_ok(pThis->SwVoiceIn)) 2407 2483 LogRel (("HDA: WARNING: Unable to open PCM IN!\n")); 2408 2484 if (!AUD_is_host_voice_out_ok(pThis->SwVoiceOut)) 2409 2485 LogRel (("HDA: WARNING: Unable to open PCM OUT!\n")); 2410 2486 #endif 2487 2488 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2489 if ( !pThis->pDrv->pfnIsHostVoiceInOK(pThis->pDrv, pThis->SwVoiceIn) 2490 && !pThis->pDrv->pfnIsHostVoiceOutOK(pThis->pDrv, pThis->SwVoiceOut)) 2491 #else 2411 2492 if ( !AUD_is_host_voice_in_ok(pThis->SwVoiceIn) 2412 2493 && !AUD_is_host_voice_out_ok(pThis->SwVoiceOut)) 2494 #endif 2413 2495 { 2414 2496 /* Was not able initialize *any* voice. Select the NULL audio driver instead */ 2415 AUD_close_in (&pThis->card, pThis->SwVoiceIn); 2416 AUD_close_out (&pThis->card, pThis->SwVoiceOut); 2497 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2498 pThis->pDrv->pfnCloseIn(pThis->pDrv, pThis->SwVoiceIn); 2499 pThis->pDrv->pfnCloseOut(pThis->pDrv, pThis->SwVoiceOut); 2500 #else 2501 AUD_close_in(&pThis->card, pThis->SwVoiceIn); 2502 AUD_close_out(&pThis->card, pThis->SwVoiceOut); 2503 #endif 2417 2504 pThis->SwVoiceOut = NULL; 2418 2505 pThis->SwVoiceIn = NULL; 2506 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2507 pThis->pDrv->pfnInitNull(pThis->pDrv); 2508 #else 2419 2509 AUD_init_null (); 2510 #endif 2420 2511 2421 2512 PDMDevHlpVMSetRuntimeError (pDevIns, 0 /*fFlags*/, "HostAudioNotResponding", … … 2423 2514 "with the consequence that no sound is audible")); 2424 2515 } 2516 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2517 else if ( !pThis->pDrv->pfnIsHostVoiceInOK(pThis->pDrv, pThis->SwVoiceIn) 2518 || !pThis->pDrv->pfnIsHostVoiceOutOK(pThis->pDrv, pThis->SwVoiceOut)) 2519 2520 #else 2425 2521 else if ( !AUD_is_host_voice_in_ok(pThis->SwVoiceIn) 2426 2522 || !AUD_is_host_voice_out_ok(pThis->SwVoiceOut)) 2523 #endif 2427 2524 { 2428 2525 char szMissingVoices[128]; 2429 2526 size_t len = 0; 2527 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2528 if (!pThis->pDrv->pfnIsHostVoiceInOK(pThis->pDrv, pThis->SwVoiceIn)) 2529 len = RTStrPrintf (szMissingVoices, sizeof(szMissingVoices), "PCM_in"); 2530 if (!pThis->pDrv->pfnIsHostVoiceOutOK(pThis->pDrv, pThis->SwVoiceOut)) 2531 len += RTStrPrintf (szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_out" : "PCM_out"); 2532 #else 2430 2533 if (!AUD_is_host_voice_in_ok(pThis->SwVoiceIn)) 2431 2534 len = RTStrPrintf (szMissingVoices, sizeof(szMissingVoices), "PCM_in"); … … 2433 2536 len += RTStrPrintf (szMissingVoices + len, sizeof(szMissingVoices) - len, len ? ", PCM_out" : "PCM_out"); 2434 2537 2538 #endif 2435 2539 PDMDevHlpVMSetRuntimeError (pDevIns, 0 /*fFlags*/, "HostAudioNotResponding", 2436 2540 N_ ("Some audio devices (%s) could not be opened. Guest applications generating audio " -
trunk/src/VBox/Devices/Audio/DevIchHdaCodec.h
r44669 r50686 18 18 #ifndef DEV_CODEC_H 19 19 #define DEV_CODEC_H 20 20 //#include <VBox/vmm/pdmdev.h> 21 21 /** The ICH HDA (Intel) codec state. */ 22 22 typedef struct HDACODEC HDACODEC; 23 23 /** Pointer to the Intel ICH HDA codec state. */ 24 24 typedef HDACODEC *PHDACODEC; 25 25 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 26 typedef struct PDMIAUDIOCONNECTOR * PPDMIAUDIOCONNECTOR; 27 typedef struct PDMGSTVOICEOUT *PPDMGSTVOICEOUT; 28 typedef struct PDMGSTVOICEIN *PPDMGSTVOICEIN; 29 #endif 26 30 /** 27 31 * Verb processor method. … … 72 76 uint8_t u8BSKU; 73 77 uint8_t u8AssemblyId; 78 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 79 R3PTRTYPE(PPDMIAUDIOCONNECTOR) pDrv; 80 /** Pointer to the attached audio driver. */ 81 R3PTRTYPE(PPDMIBASE) pDrvBase; 82 #endif 83 74 84 #ifndef VBOX_WITH_HDA_CODEC_EMU 75 85 CODECVERB const *paVerbs; … … 79 89 #endif 80 90 PCODECNODE paNodes; 91 92 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 93 /** PCM in */ 94 R3PTRTYPE(PPDMGSTVOICEIN) SwVoiceIn; 95 /** PCM out */ 96 R3PTRTYPE(PPDMGSTVOICEOUT) SwVoiceOut; 97 #else 81 98 QEMUSoundCard card; 82 99 /** PCM in */ … … 84 101 /** PCM out */ 85 102 SWVoiceOut *SwVoiceOut; 103 #endif 86 104 void *pvHDAState; 87 105 bool fInReset; -
trunk/src/VBox/Devices/Audio/DevSB16.cpp
r45025 r50686 34 34 #define LOG_GROUP LOG_GROUP_DEV_AUDIO 35 35 #include <VBox/vmm/pdmdev.h> 36 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 37 #include <VBox/vmm/pdmaudioifs.h> 38 #endif 36 39 #include <iprt/assert.h> 37 40 #include <iprt/string.h> … … 39 42 #include "vl_vbox.h" 40 43 44 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 41 45 extern "C" { 42 46 #include "audio.h" 43 47 } 44 45 #ifndef VBOX 46 48 #endif 49 50 #ifndef VBOX 47 51 #define LENOFA(a) ((int) (sizeof(a)/sizeof(a[0]))) 48 49 #define dolog(...) AUD_log ("sb16", __VA_ARGS__)50 51 /* #define DEBUG */52 /* #define DEBUG_SB16_MOST */53 54 #ifdef DEBUG55 #define ldebug(...) dolog (__VA_ARGS__)56 #else57 #define ldebug(...)58 #endif59 60 52 #else /* VBOX */ 61 62 53 /** Current saved state version. */ 63 54 #define SB16_SAVE_STATE_VERSION 2 … … 65 56 * the config dump. */ 66 57 #define SB16_SAVE_STATE_VERSION_VBOX_30 1 67 68 DECLINLINE(void) dolog (const char *fmt, ...)69 {70 va_list ap;71 va_start (ap, fmt);72 AUD_vlog ("sb16", fmt, ap);73 va_end (ap);74 }75 76 # ifdef DEBUG77 static void ldebug (const char *fmt, ...)78 {79 va_list ap;80 81 va_start (ap, fmt);82 AUD_vlog ("sb16", fmt, ap);83 va_end (ap);84 }85 # else86 DECLINLINE(void) ldebug (const char *fmt, ...)87 {88 (void)fmt;89 }90 # endif91 92 58 #endif /* VBOX */ 93 59 … … 122 88 typedef struct SB16State { 123 89 #ifdef VBOX 90 /** Pointer to the device instance. */ 124 91 PPDMDEVINSR3 pDevIns; 125 #endif 92 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 93 /** Pointer to the connector of the attached audio driver. */ 94 PPDMIAUDIOCONNECTOR pDrv; 95 # endif 96 #endif 97 #ifndef VBOX 98 qemu_irq *pic; 99 #endif 100 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 126 101 QEMUSoundCard card; 127 #ifndef VBOX128 qemu_irq *pic;129 102 #endif 130 103 #ifdef VBOX /* lazy bird */ … … 182 155 int align; 183 156 int audio_free; 157 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 158 PPDMGSTVOICEOUT voice; 159 #else 184 160 SWVoiceOut *voice; 161 #endif 185 162 186 163 #ifndef VBOX … … 211 188 return 8; 212 189 default: 213 dolog ("bad irq %d\n", irq);190 LogFlow(("SB16: bad irq %d\n", irq)); 214 191 return 2; 215 192 } … … 228 205 return 10; 229 206 default: 230 dolog ("bad irq magic %d\n", magic);207 LogFlow(("SB16: bad irq magic %d\n", magic)); 231 208 return -1; 232 209 } … … 259 236 s->dma_running = hold; 260 237 261 ldebug ("hold %d high %d dma %d\n", hold, s->use_hdma, dma);238 LogFlow(("SB16: hold %d high %d dma %d\n", hold, s->use_hdma, dma)); 262 239 263 240 #ifndef VBOX … … 275 252 PDMDevHlpDMASetDREQ (s->pDevIns, dma, 1); 276 253 PDMDevHlpDMASchedule (s->pDevIns); 254 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 255 s->pDrv->pfnEnableOut(s->pDrv, s->voice, 1); 256 #else 277 257 AUD_set_active_out (s->voice, 1); 258 #endif 278 259 } 279 260 else 280 261 { 281 262 PDMDevHlpDMASetDREQ (s->pDevIns, dma, 0); 263 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 264 s->pDrv->pfnEnableOut(s->pDrv, s->voice, 0); 265 #else 282 266 AUD_set_active_out (s->voice, 0); 267 #endif 283 268 } 284 269 #endif /* VBOX */ … … 306 291 static void continue_dma8 (SB16State *s) 307 292 { 293 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 294 int rc; 295 #endif 308 296 if (s->freq > 0) { 297 298 s->audio_free = 0; 299 300 301 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 302 rc = s->pDrv->pfnOpenOut(s->pDrv, &s->voice, "sb16", s, SB_audio_callback, s->freq, 1 << s->fmt_stereo, 303 s->fmt, 0); 304 #else 309 305 audsettings_t as; 310 311 s->audio_free = 0;312 313 306 as.freq = s->freq; 314 307 as.nchannels = 1 << s->fmt_stereo; 315 308 as.fmt = s->fmt; 316 309 as.endianness = 0; 317 318 310 s->voice = AUD_open_out ( 319 311 &s->card, … … 324 316 &as 325 317 ); 318 #endif 326 319 } 327 320 … … 367 360 368 361 if (s->block_size & s->align) { 369 dolog ("warning: misaligned block size %d, alignment %d\n",370 s->block_size, s->align + 1) ;371 } 372 373 ldebug ("freq %d, stereo %d, sign %d, bits %d, "362 LogFlow(("SB16: warning: misaligned block size %d, alignment %d\n", 363 s->block_size, s->align + 1)); 364 } 365 366 LogFlow(("SB16: freq %d, stereo %d, sign %d, bits %d, " 374 367 "dma %d, auto %d, fifo %d, high %d\n", 375 368 s->freq, s->fmt_stereo, s->fmt_signed, s->fmt_bits, 376 s->block_size, s->dma_auto, s->fifo, s->highspeed) ;369 s->block_size, s->dma_auto, s->fifo, s->highspeed)); 377 370 378 371 continue_dma8 (s); … … 419 412 } 420 413 421 ldebug ("freq %d, stereo %d, sign %d, bits %d, "414 LogFlow(("SB16: freq %d, stereo %d, sign %d, bits %d, " 422 415 "dma %d, auto %d, fifo %d, high %d\n", 423 416 s->freq, s->fmt_stereo, s->fmt_signed, s->fmt_bits, 424 s->block_size, s->dma_auto, s->fifo, s->highspeed) ;417 s->block_size, s->dma_auto, s->fifo, s->highspeed)); 425 418 426 419 if (16 == s->fmt_bits) { … … 447 440 s->align = (1 << (s->fmt_stereo + (s->fmt_bits == 16))) - 1; 448 441 if (s->block_size & s->align) { 449 dolog ("warning: misaligned block size %d, alignment %d\n",450 s->block_size, s->align + 1) ;442 LogFlow(("SB16: warning: misaligned block size %d, alignment %d\n", 443 s->block_size, s->align + 1)); 451 444 } 452 445 453 446 if (s->freq) { 447 448 s->audio_free = 0; 449 450 451 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 452 int rc; 453 rc = s->pDrv->pfnOpenOut(s->pDrv, &s->voice, "sb16", s,SB_audio_callback, s->freq, 1 << s->fmt_stereo, s->fmt, 0); 454 #else 454 455 audsettings_t as; 455 456 s->audio_free = 0;457 458 456 as.freq = s->freq; 459 457 as.nchannels = 1 << s->fmt_stereo; 460 458 as.fmt = s->fmt; 461 459 as.endianness = 0; 462 463 460 s->voice = AUD_open_out ( 464 461 &s->card, … … 469 466 &as 470 467 ); 468 #endif 471 469 } 472 470 … … 477 475 static inline void dsp_out_data (SB16State *s, uint8_t val) 478 476 { 479 ldebug ("outdata %#x\n", val);477 LogFlow(("SB16: outdata %#x\n", val)); 480 478 if ((size_t) s->out_data_len < sizeof (s->out_data)) { 481 479 s->out_data[s->out_data_len++] = val; … … 489 487 } 490 488 else { 491 dolog ("buffer underflow\n");489 LogFlow(("SB16: buffer underflow\n")); 492 490 return 0; 493 491 } … … 496 494 static void command (SB16State *s, uint8_t cmd) 497 495 { 498 ldebug ("command %#x\n", cmd);496 LogFlow(("SB16: command %#x\n", cmd)); 499 497 500 498 if (cmd > 0xaf && cmd < 0xd0) { 501 499 if (cmd & 8) { 502 dolog ("ADC not yet supported (command %#x)\n", cmd);500 LogFlow(("SB16: ADC not yet supported (command %#x)\n", cmd)); 503 501 } 504 502 … … 508 506 break; 509 507 default: 510 dolog ("%#x wrong bits\n", cmd);508 LogFlow(("SB16: %#x wrong bits\n", cmd)); 511 509 } 512 510 s->needed_bytes = 3; … … 562 560 563 561 case 0x35: 564 dolog ("0x35 - MIDI command not implemented\n");562 LogFlow(("SB16: 0x35 - MIDI command not implemented\n")); 565 563 break; 566 564 … … 596 594 case 0x74: 597 595 s->needed_bytes = 2; /* DMA DAC, 4-bit ADPCM */ 598 dolog ("0x75 - DMA DAC, 4-bit ADPCM not implemented\n");596 LogFlow(("SB16: 0x75 - DMA DAC, 4-bit ADPCM not implemented\n")); 599 597 break; 600 598 601 599 case 0x75: /* DMA DAC, 4-bit ADPCM Reference */ 602 600 s->needed_bytes = 2; 603 dolog ("0x74 - DMA DAC, 4-bit ADPCM Reference not implemented\n");601 LogFlow(("SB16: 0x74 - DMA DAC, 4-bit ADPCM Reference not implemented\n")); 604 602 break; 605 603 606 604 case 0x76: /* DMA DAC, 2.6-bit ADPCM */ 607 605 s->needed_bytes = 2; 608 dolog ("0x74 - DMA DAC, 2.6-bit ADPCM not implemented\n");606 LogFlow(("SB16: 0x74 - DMA DAC, 2.6-bit ADPCM not implemented\n")); 609 607 break; 610 608 611 609 case 0x77: /* DMA DAC, 2.6-bit ADPCM Reference */ 612 610 s->needed_bytes = 2; 613 dolog ("0x74 - DMA DAC, 2.6-bit ADPCM Reference not implemented\n");611 LogFlow(("SB16: 0x74 - DMA DAC, 2.6-bit ADPCM Reference not implemented\n")); 614 612 break; 615 613 616 614 case 0x7d: 617 dolog ("0x7d - Autio-Initialize DMA DAC, 4-bit ADPCM Reference\n");618 dolog ("not implemented\n");615 LogFlow(("SB16: 0x7d - Autio-Initialize DMA DAC, 4-bit ADPCM Reference\n")); 616 LogFlow(("SB16: not implemented\n")); 619 617 break; 620 618 621 619 case 0x7f: 622 dolog ( 623 "0x7d - Autio-Initialize DMA DAC, 2.6-bit ADPCM Reference\n" 624 ); 625 dolog ("not implemented\n"); 620 LogFlow(("SB16: 0x7d - Autio-Initialize DMA DAC, 2.6-bit ADPCM Reference\n")); 621 LogFlow(("SB16: not implemented\n")); 626 622 break; 627 623 … … 695 691 696 692 case 0xe7: 697 dolog ("Attempt to probe for ESS (0xe7)?\n");693 LogFlow(("SB16: Attempt to probe for ESS (0xe7)?\n")); 698 694 break; 699 695 … … 726 722 727 723 default: 728 dolog ("Unrecognized command %#x\n", cmd);724 LogFlow(("SB16: Unrecognized command %#x\n", cmd)); 729 725 break; 730 726 } … … 732 728 733 729 if (!s->needed_bytes) { 734 ldebug ("\n");730 LogFlow(("\n")); 735 731 } 736 732 … … 745 741 746 742 warn: 747 dolog ("warning: command %#x,%d is not truly understood yet\n",748 cmd, s->needed_bytes) ;743 LogFlow(("SB16: warning: command %#x,%d is not truly understood yet\n", 744 cmd, s->needed_bytes)); 749 745 goto exit; 750 746 … … 768 764 { 769 765 int d0, d1, d2; 770 ldebug ("complete command %#x, in_index %d, needed_bytes %d\n",771 s->cmd, s->in_index, s->needed_bytes) ;766 LogFlow(("SB16: complete command %#x, in_index %d, needed_bytes %d\n", 767 s->cmd, s->in_index, s->needed_bytes)); 772 768 773 769 if (s->cmd > 0xaf && s->cmd < 0xd0) { … … 777 773 778 774 if (s->cmd & 8) { 779 dolog ("ADC params cmd = %#x d0 = %d, d1 = %d, d2 = %d\n",780 s->cmd, d0, d1, d2) ;775 LogFlow(("SB16: ADC params cmd = %#x d0 = %d, d1 = %d, d2 = %d\n", 776 s->cmd, d0, d1, d2)); 781 777 } 782 778 else { 783 ldebug ("cmd = %#x d0 = %d, d1 = %d, d2 = %d\n",784 s->cmd, d0, d1, d2) ;779 LogFlow(("SB16: cmd = %#x d0 = %d, d1 = %d, d2 = %d\n", 780 s->cmd, d0, d1, d2)); 785 781 dma_cmd (s, s->cmd, d0, d1 + (d2 << 8)); 786 782 } … … 792 788 s->csp_reg83r = 0; 793 789 s->csp_reg83w = 0; 794 ldebug ("CSP command 0x04: mode=%#x\n", s->csp_mode);790 LogFlow(("SB16: CSP command 0x04: mode=%#x\n", s->csp_mode)); 795 791 break; 796 792 … … 798 794 s->csp_param = dsp_get_data (s); 799 795 s->csp_value = dsp_get_data (s); 800 ldebug ("CSP command 0x05: param=%#x value=%#x\n",796 LogFlow(("SB16: CSP command 0x05: param=%#x value=%#x\n", 801 797 s->csp_param, 802 s->csp_value) ;798 s->csp_value)); 803 799 break; 804 800 … … 806 802 d0 = dsp_get_data (s); 807 803 d1 = dsp_get_data (s); 808 ldebug ("write CSP register %d <- %#x\n", d1, d0);804 LogFlow(("SB16: write CSP register %d <- %#x\n", d1, d0)); 809 805 if (d1 == 0x83) { 810 ldebug ("0x83[%d] <- %#x\n", s->csp_reg83r, d0);806 LogFlow(("SB16: 0x83[%d] <- %#x\n", s->csp_reg83r, d0)); 811 807 s->csp_reg83[s->csp_reg83r % 4] = d0; 812 808 s->csp_reg83r += 1; … … 819 815 case 0x0f: 820 816 d0 = dsp_get_data (s); 821 ldebug ("read CSP register %#x -> %#x, mode=%#x\n",822 d0, s->csp_regs[d0], s->csp_mode) ;817 LogFlow(("SB16: read CSP register %#x -> %#x, mode=%#x\n", 818 d0, s->csp_regs[d0], s->csp_mode)); 823 819 if (d0 == 0x83) { 824 ldebug ("0x83[%d] -> %#x\n",820 LogFlow(("SB16: 0x83[%d] -> %#x\n", 825 821 s->csp_reg83w, 826 s->csp_reg83[s->csp_reg83w % 4]) ;822 s->csp_reg83[s->csp_reg83w % 4])); 827 823 dsp_out_data (s, s->csp_reg83[s->csp_reg83w % 4]); 828 824 s->csp_reg83w += 1; … … 835 831 case 0x10: 836 832 d0 = dsp_get_data (s); 837 dolog ("cmd 0x10 d0=%#x\n", d0);833 LogFlow(("SB16: cmd 0x10 d0=%#x\n", d0)); 838 834 break; 839 835 … … 844 840 case 0x40: 845 841 s->time_const = dsp_get_data (s); 846 ldebug ("set time const %d\n", s->time_const);842 LogFlow(("SB16: set time const %d\n", s->time_const)); 847 843 break; 848 844 … … 853 849 case 0x41: 854 850 s->freq = dsp_get_hilo (s); 855 ldebug ("set freq %d\n", s->freq);851 LogFlow(("SB16: set freq %d\n", s->freq)); 856 852 break; 857 853 858 854 case 0x48: 859 855 s->block_size = dsp_get_lohi (s) + 1; 860 ldebug ("set dma block len %d\n", s->block_size);856 LogFlow(("SB16: set dma block len %d\n", s->block_size)); 861 857 break; 862 858 … … 889 885 } 890 886 } 891 ldebug ("mix silence %d %d %" PRId64 "\n", samples, bytes, ticks);887 LogFlow(("SB16: mix silence %d %d %" PRId64 "\n", samples, bytes, ticks)); 892 888 #else /* VBOX */ 893 889 ticks = (bytes * TMTimerGetFreq(s->pTimer)) / freq; … … 896 892 else 897 893 TMTimerSet(s->pTimer, TMTimerGet(s->pTimer) + ticks); 898 ldebug ("mix silence %d %d % %RU64\n", samples, bytes, ticks);894 LogFlow(("SB16: mix silence %d %d % %RU64\n", samples, bytes, ticks)); 899 895 #endif /* VBOX */ 900 896 } … … 904 900 d0 = dsp_get_data (s); 905 901 s->out_data_len = 0; 906 ldebug ("E0 data = %#x\n", d0);902 LogFlow(("SB16: E0 data = %#x\n", d0)); 907 903 dsp_out_data (s, ~d0); 908 904 break; … … 910 906 case 0xe2: 911 907 d0 = dsp_get_data (s); 912 ldebug ("E2 = %#x\n", d0);908 LogFlow(("SB16:E2 = %#x\n", d0)); 913 909 break; 914 910 … … 919 915 case 0xf9: 920 916 d0 = dsp_get_data (s); 921 ldebug ("command 0xf9 with %#x\n", d0);917 LogFlow(("SB16: command 0xf9 with %#x\n", d0)); 922 918 switch (d0) { 923 919 case 0x0e: … … 940 936 941 937 default: 942 dolog ("complete: unrecognized command %#x\n", s->cmd);938 LogFlow(("SB16: complete: unrecognized command %#x\n", s->cmd)); 943 939 return; 944 940 } 945 941 } 946 942 947 ldebug ("\n");943 LogFlow(("\n")); 948 944 s->cmd = -1; 949 945 return; … … 952 948 static void legacy_reset (SB16State *s) 953 949 { 954 audsettings_t as;955 950 956 951 s->freq = 11025; … … 959 954 s->fmt_stereo = 0; 960 955 956 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 957 int rc; 958 rc = s->pDrv->pfnOpenOut(s->pDrv, &s->voice, "sb16", s, SB_audio_callback, 11025, 1, AUD_FMT_U8, 0); 959 #else 960 audsettings_t as; 961 961 as.freq = s->freq; 962 962 as.nchannels = 1; 963 963 as.fmt = AUD_FMT_U8; 964 964 as.endianness = 0; 965 966 965 s->voice = AUD_open_out ( 967 966 &s->card, … … 973 972 ); 974 973 974 #endif 975 975 /* Not sure about that... */ 976 976 /* AUD_set_active_out (s->voice, 1); */ … … 1016 1016 int iport = nport - s->port; 1017 1017 1018 ldebug ("write %#x <- %#x\n", nport, val);1018 LogFlow(("SB16: write %#x <- %#x\n", nport, val)); 1019 1019 switch (iport) { 1020 1020 case 0x06: … … 1077 1077 else { 1078 1078 if (s->in_index == sizeof (s->in2_data)) { 1079 dolog ("in data overrun\n");1079 LogFlow(("SB16: in data overrun\n")); 1080 1080 } 1081 1081 else { … … 1093 1093 1094 1094 default: 1095 ldebug ("(nport=%#x, val=%#x)\n", nport, val);1095 LogFlow(("SB16: nport=%#x, val=%#x)\n", nport, val)); 1096 1096 break; 1097 1097 } … … 1125 1125 else { 1126 1126 if (s->cmd != -1) { 1127 dolog ("empty output buffer for command %#x\n",1128 s->cmd) ;1127 LogFlow(("SB16: empty output buffer for command %#x\n", 1128 s->cmd)); 1129 1129 } 1130 1130 retval = s->last_read_byte; … … 1173 1173 1174 1174 if (!ack) { 1175 ldebug ("read %#x -> %#x\n", nport, retval);1175 LogFlow(("SB16: read %#x -> %#x\n", nport, retval)); 1176 1176 } 1177 1177 … … 1184 1184 1185 1185 error: 1186 dolog ("warning: dsp_read %#x error\n", nport);1186 LogFlow(("SB16: warning: dsp_read %#x error\n", nport)); 1187 1187 #ifndef VBOX 1188 1188 return 0xff; … … 1232 1232 #endif 1233 1233 } 1234 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1235 uint32_t popcount (uint32_t u) 1236 { 1237 u = ((u&0x55555555) + ((u>>1)&0x55555555)); 1238 u = ((u&0x33333333) + ((u>>2)&0x33333333)); 1239 u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f)); 1240 u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff)); 1241 u = ( u&0x0000ffff) + (u>>16); 1242 return u; 1243 } 1244 1245 uint32_t lsbindex (uint32_t u) 1246 { 1247 return popcount ((u&-u)-1); 1248 } 1249 #endif 1234 1250 1235 1251 static IO_WRITE_PROTO(mixer_write_datab) … … 1240 1256 1241 1257 (void) nport; 1242 ldebug ("mixer_write [%#x] <- %#x\n", s->mixer_nreg, val);1258 LogFlow(("SB16: mixer_write [%#x] <- %#x\n", s->mixer_nreg, val)); 1243 1259 1244 1260 switch (s->mixer_nreg) { … … 1291 1307 { 1292 1308 int irq = irq_of_magic (val); 1293 ldebug ("setting irq to %d (val=%#x)\n", irq, val);1309 LogFlow(("SB16: setting irq to %d (val=%#x)\n", irq, val)); 1294 1310 if (irq > 0) { 1295 1311 s->irq = irq; … … 1305 1321 hdma = lsbindex (val & 0xf0); 1306 1322 if (dma != s->dma || hdma != s->hdma) { 1307 dolog(1308 " attempt to change DMA "1323 LogFlow(( 1324 "SB16: attempt to change DMA " 1309 1325 "8bit %d(%d), 16bit %d(%d) (val=%#x)\n", 1310 dma, s->dma, hdma, s->hdma, val) ;1326 dma, s->dma, hdma, s->hdma, val)); 1311 1327 } 1312 1328 #if 0 … … 1318 1334 1319 1335 case 0x82: 1320 dolog ("attempt to write into IRQ status register (val=%#x)\n",1321 val) ;1336 LogFlow(("SB16: attempt to write into IRQ status register (val=%#x)\n", 1337 val)); 1322 1338 #ifdef VBOX 1323 1339 return VINF_SUCCESS; … … 1326 1342 default: 1327 1343 if (s->mixer_nreg >= 0x80) { 1328 ldebug ("attempt to write mixer[%#x] <- %#x\n", s->mixer_nreg, val);1344 LogFlow(("SB16: attempt to write mixer[%#x] <- %#x\n", s->mixer_nreg, val)); 1329 1345 } 1330 1346 break; … … 1340 1356 uint8_t lvol = s->mixer_regs[0x30]; 1341 1357 uint8_t rvol = s->mixer_regs[0x31]; 1358 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1359 /*@todo not passinga audmixer_Ctl values as its not used in DrvAudio.c */ 1360 s->pDrv->pfnSetVolume(s->pDrv, &mute, &lvol, &rvol); 1361 #else 1342 1362 AUD_set_volume(AUD_MIXER_VOLUME, &mute, &lvol, &rvol); 1363 #endif 1343 1364 } 1344 1365 /* Update the voice (PCM) volume. */ … … 1348 1369 uint8_t lvol = s->mixer_regs[0x32]; 1349 1370 uint8_t rvol = s->mixer_regs[0x33]; 1371 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1372 s->pDrv->pfnSetVolume(s->pDrv, &mute, &lvol, &rvol); 1373 #else 1350 1374 AUD_set_volume(AUD_MIXER_PCM, &mute, &lvol, &rvol); 1375 #endif 1351 1376 } 1352 1377 #endif /* VBOX */ … … 1397 1422 #ifndef DEBUG_SB16_MOST 1398 1423 if (s->mixer_nreg != 0x82) { 1399 ldebug ("mixer_read[%#x] -> %#x\n",1400 s->mixer_nreg, s->mixer_regs[s->mixer_nreg]) ;1401 } 1402 #else 1403 ldebug ("mixer_read[%#x] -> %#x\n",1404 s->mixer_nreg, s->mixer_regs[s->mixer_nreg]) ;1424 LogFlow(("SB16: mixer_read[%#x] -> %#x\n", 1425 s->mixer_nreg, s->mixer_regs[s->mixer_nreg])); 1426 } 1427 #else 1428 LogFlow(("SB16: mixer_read[%#x] -> %#x\n", 1429 s->mixer_nreg, s->mixer_regs[s->mixer_nreg])); 1405 1430 #endif 1406 1431 #ifndef VBOX … … 1444 1469 #endif 1445 1470 1471 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1472 copied = s->pDrv->pfnWrite(s->pDrv, s->voice, tmpbuf, copied); 1473 #else 1446 1474 copied = AUD_write (s->voice, tmpbuf, copied); 1475 #endif 1447 1476 1448 1477 temp -= copied; … … 1468 1497 1469 1498 if (s->block_size <= 0) { 1470 dolog ("invalid block size=%d nchan=%d dma_pos=%d dma_len=%d\n",1471 s->block_size, nchan, dma_pos, dma_len) ;1499 LogFlow(("SB16: invalid block size=%d nchan=%d dma_pos=%d dma_len=%d\n", 1500 s->block_size, nchan, dma_pos, dma_len)); 1472 1501 return dma_pos; 1473 1502 } … … 1491 1520 1492 1521 #ifdef DEBUG_SB16_MOST 1493 dolog ("pos:%06d %d till:%d len:%d\n",1494 dma_pos, free, till, dma_len) ;1522 LogFlow(("SB16: pos:%06d %d till:%d len:%d\n", 1523 dma_pos, free, till, dma_len)); 1495 1524 #endif 1496 1525 … … 1523 1552 1524 1553 #ifdef DEBUG_SB16_MOST 1525 ldebug ("pos %5d free %5d size %5d till % 5d copy %5d written %5d size %5d\n",1554 LogFlow(("SB16: pos %5d free %5d size %5d till % 5d copy %5d written %5d size %5d\n", 1526 1555 dma_pos, free, dma_len, s->left_till_irq, copy, written, 1527 s->block_size) ;1556 s->block_size)); 1528 1557 #endif 1529 1558 … … 1663 1692 1664 1693 if (s->voice) { 1694 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1695 s->pDrv->pfnCloseOut(s->pDrv, s->voice); 1696 #else 1665 1697 AUD_close_out (&s->card, s->voice); 1698 #endif 1666 1699 s->voice = NULL; 1667 1700 } … … 1669 1702 if (s->dma_running) { 1670 1703 if (s->freq) { 1704 1705 s->audio_free = 0; 1706 1707 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1708 int rc; 1709 rc = s->pDrv->pfnOpenOut(s->pDrv, &s->voice, "sb16", s, SB_audio_callback, s->freq, 1 << s->fmt_stereo, s->fmt, 0); 1710 #else 1671 1711 audsettings_t as; 1672 1673 s->audio_free = 0;1674 1675 1712 as.freq = s->freq; 1676 1713 as.nchannels = 1 << s->fmt_stereo; 1677 1714 as.fmt = s->fmt; 1678 1715 as.endianness = 0; 1679 1680 1716 s->voice = AUD_open_out ( 1681 1717 &s->card, … … 1686 1722 &as 1687 1723 ); 1724 #endif 1688 1725 } 1689 1726 … … 1706 1743 1707 1744 if (!audio) { 1708 dolog ("No audio state\n");1745 LogFlow(("SB16: No audio state\n")); 1709 1746 return -1; 1710 1747 } … … 1712 1749 s = qemu_mallocz (sizeof (*s)); 1713 1750 if (!s) { 1714 dolog ("Could not allocate memory for SB16 (%zu bytes)\n",1715 sizeof (*s)) ;1751 LogFlow(("SB16: Could not allocate memory for SB16 (%zu bytes)\n", 1752 sizeof (*s))); 1716 1753 return -1; 1717 1754 } … … 1735 1772 s->aux_ts = qemu_new_timer (vm_clock, aux_timer, s); 1736 1773 if (!s->aux_ts) { 1737 dolog ("warning: Could not create auxiliary timer\n");1774 LogFlow(("SB16: warning: Could not create auxiliary timer\n")); 1738 1775 } 1739 1776 … … 1756 1793 1757 1794 register_savevm ("sb16", 0, 1, SB_save, SB_load, s); 1758 AUD_register_card (audio, "sb16" , &s->card);1795 AUD_register_card (audio, "sb16"); 1759 1796 return 0; 1760 1797 } … … 1943 1980 1944 1981 rc = PDMDevHlpDriverAttach(pDevIns, 0, &s->IBase, &s->pDrvBase, "Audio Driver Port"); 1982 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1983 if(RT_SUCCESS(rc)) 1984 { 1985 s->pDrv = PDMIBASE_QUERY_INTERFACE(s->pDrvBase, PDMIAUDIOCONNECTOR); 1986 AssertMsgReturn(s->pDrv, 1987 ("Configuration error: instance %d has no host audio interface!\n", iInstance), 1988 VERR_PDM_MISSING_INTERFACE); 1989 } 1990 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 1991 #else 1945 1992 if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 1946 Log(("sb16: No attached driver!\n")); 1993 #endif 1994 Log(("ac97: No attached driver!\n")); 1947 1995 else if (RT_FAILURE(rc)) 1948 AssertMsgFailedReturn(("Failed to attach SB16 LUN #0! rc=%Rrc\n", rc), rc); 1949 1996 { 1997 AssertMsgFailed(("Failed to attach AC97 LUN #0! rc=%Rrc\n", rc)); 1998 return rc; 1999 } 2000 2001 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2002 s->pDrv->pfnRegisterCard(s->pDrv, "sb16"); 2003 #else 1950 2004 AUD_register_card("sb16", &s->card); 2005 #endif 1951 2006 legacy_reset(s); 1952 2007 2008 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2009 if (!s->pDrv->pfnIsHostVoiceOutOK(s->pDrv,s->voice)) 2010 #else 1953 2011 if (!AUD_is_host_voice_out_ok(s->voice)) 2012 #endif 1954 2013 { 1955 2014 LogRel (("SB16: WARNING: Unable to open PCM OUT!\n")); 1956 AUD_close_out(&s->card, s->voice); 2015 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2016 s->pDrv->pfnCloseOut(s->pDrv, s->voice ); 2017 #else 2018 AUD_close_out (&s->card, s->voice); 2019 #endif 1957 2020 s->voice = NULL; 2021 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2022 s->pDrv->pfnInitNull(s->pDrv); 2023 #else 1958 2024 AUD_init_null(); 2025 #endif 1959 2026 PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding", 1960 2027 N_("No audio devices could be opened. Selecting the NULL audio backend " -
trunk/src/VBox/Devices/Audio/mixeng.c
r35353 r50686 26 26 #include "VBoxDD.h" 27 27 #include "vl_vbox.h" 28 #include "audio.h"29 28 #ifdef VBOX 30 29 # include <iprt/asm-math.h> … … 33 32 34 33 #define AUDIO_CAP "mixeng" 34 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 35 #include "DrvAudio.h" 36 #else 37 #include "audio.h" 35 38 #include "audio_int.h" 39 #endif 36 40 37 41 #ifndef VBOX … … 309 313 void *st_rate_start (int inrate, int outrate) 310 314 { 315 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 316 struct rate *rate = (struct rate *)RTMemAllocZ(1 * sizeof (*rate)); 317 #else 311 318 struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate)); 319 #endif 312 320 313 321 if (!rate) { 314 dolog ("Could not allocate resampler (%" FMTZ "u bytes)\n", 315 sizeof (*rate)); 322 LogFlow(("Could not allocate resampler %u bytes)\n", sizeof (*rate))); 316 323 return NULL; 317 324 } … … 338 345 void st_rate_stop (void *opaque) 339 346 { 347 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 348 RTMemFree(opaque); 349 #else 340 350 qemu_free (opaque); 341 } 342 351 #endif 352 } 353 354 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 355 void mixeng_clear(PPDMHOSTSTEREOSAMPLE buf, int len) 356 { 357 memset (buf, 0, len * sizeof (PDMHOSTSTEREOSAMPLE)); 358 } 359 #else 343 360 void mixeng_clear (st_sample_t *buf, int len) 344 361 { 345 362 memset (buf, 0, len * sizeof (st_sample_t)); 346 363 } 347 364 #endif 365 366 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 367 void mixeng_sniff_and_clear (PPDMHOSTVOICEOUT hw, PPDMHOSTSTEREOSAMPLE src, int len) 368 #else 348 369 void mixeng_sniff_and_clear (HWVoiceOut *hw, st_sample_t *src, int len) 349 { 370 #endif 371 { 372 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 373 LogFlow(("mixeng: sniffer_run_out\n")); 350 374 sniffer_run_out (hw, src, len); 375 #endif 351 376 mixeng_clear (src, len); 352 377 } -
trunk/src/VBox/Devices/Audio/mixeng.h
r6521 r50686 29 29 #ifdef VBOX 30 30 /* use faster ASMMult2xS32RetS64 */ 31 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 31 32 typedef struct { int mute; uint32_t r; uint32_t l; } volume_t; 33 #endif 32 34 typedef struct { int64_t l; int64_t r; } st_sample_t; 33 35 #else /* !VBOX */ … … 41 43 #endif 42 44 #endif /* VBOX */ 43 45 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 44 46 typedef void (t_sample) (st_sample_t *dst, const void *src, 45 47 int samples, volume_t *vol); 48 #endif 46 49 typedef void (f_sample) (void *dst, const st_sample_t *src, int samples); 47 50 … … 55 58 int *isamp, int *osamp); 56 59 void st_rate_stop (void *opaque); 60 # ifdef VBOX_WITH_PDM_AUDIO_DRIVER 61 void mixeng_clear(PPDMHOSTSTEREOSAMPLE buf, int len); 62 void mixeng_sniff_and_clear(PPDMHOSTVOICEOUT hw, PPDMHOSTSTEREOSAMPLE src, int len); 63 # else 57 64 void mixeng_clear (st_sample_t *buf, int len); 58 65 void mixeng_sniff_and_clear (struct HWVoiceOut *hw, st_sample_t *src, int len); 66 # endif 59 67 60 68 #endif /* mixeng.h */ -
trunk/src/VBox/Devices/Audio/mixeng_template.h
r6521 r50686 114 114 115 115 static void glue (glue (conv_, ET), _to_stereo) 116 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 117 (PPDMHOSTSTEREOSAMPLE dst, const void *src, int samples, volume_t *vol) 118 #else 116 119 (st_sample_t *dst, const void *src, int samples, volume_t *vol) 117 { 120 #endif 121 { 122 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 123 PPDMHOSTSTEREOSAMPLE out = dst; 124 #else 118 125 st_sample_t *out = dst; 126 #endif 119 127 IN_T *in = (IN_T *) src; 120 128 #ifndef NOVOL … … 127 135 #endif 128 136 while (samples--) { 137 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 138 out->u64LSample = VOL (glue (conv_, ET) (*in++), vol->l); 139 out->u64RSample = VOL (glue (conv_, ET) (*in++), vol->r); 140 #else 129 141 out->l = VOL (glue (conv_, ET) (*in++), vol->l); 130 142 out->r = VOL (glue (conv_, ET) (*in++), vol->r); 143 #endif 131 144 out += 1; 132 145 } … … 134 147 135 148 static void glue (glue (conv_, ET), _to_mono) 149 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 150 (PPDMHOSTSTEREOSAMPLE dst, const void *src, int samples, volume_t *vol) 151 #else 136 152 (st_sample_t *dst, const void *src, int samples, volume_t *vol) 137 { 153 #endif 154 { 155 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 156 PPDMHOSTSTEREOSAMPLE out = dst; 157 #else 138 158 st_sample_t *out = dst; 159 #endif 139 160 IN_T *in = (IN_T *) src; 140 161 #ifndef NOVOL … … 147 168 #endif 148 169 while (samples--) { 170 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 171 out->u64LSample = VOL (glue (conv_, ET) (in[0]), vol->l); 172 out->u64RSample = out->u64LSample; 173 #else 149 174 out->l = VOL (glue (conv_, ET) (in[0]), vol->l); 150 175 out->r = out->l; 176 177 #endif 151 178 out += 1; 152 179 in += 1; -
trunk/src/VBox/Devices/Makefile.kmk
r50674 r50686 165 165 Parallel/DevParallel.cpp \ 166 166 \ 167 Audio/audio.c \168 Audio/audiosniffer.c \169 167 Audio/mixeng.c \ 170 Audio/noaudio.c \171 Audio/filteraudio.c \172 168 Input/DrvKeyboardQueue.cpp \ 173 169 Input/DrvMouseQueue.cpp \ … … 497 493 # --- Audio bits. --- 498 494 495 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 496 VBoxDD_DEFS +=VBOX_WITH_PDM_AUDIO_DRIVER 497 endif 498 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 499 VBoxDD_SOURCES += Audio/DrvAudio.c \ 500 Audio/DrvAudioUtil.c \ 501 Audio/DrvHostNullAudio.c 502 else 503 VBoxDD_SOURCES += Audio/audio.c \ 504 Audio/audiosniffer.c \ 505 Audio/noaudio.c \ 506 Audio/filteraudio.c 507 endif 508 499 509 ifdef VBOX_WITH_ALSA 500 510 VBoxDD_DEFS.linux += VBOX_WITH_ALSA 501 VBoxDD_SOURCES.linux += \ 502 Audio/alsaaudio.c \ 503 Audio/alsa_stubs.c 511 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 512 VBoxDD_DEFS.linux += VBOX_WITH_WITH_PDM_AUDIO_DRIVER 513 VBoxDD_SOURCES.linux += \ 514 Audio/DrvHostAlsaAudio.c \ 515 Audio/alsa_stubs.c 516 else 517 VBoxDD_SOURCES.linux += \ 518 Audio/alsaaudio.c \ 519 Audio/alsa_stubs.c 520 endif 504 521 endif 505 522 506 523 ifdef VBOX_WITH_PULSE 507 524 VBoxDD_DEFS.linux += VBOX_WITH_PULSE 508 VBoxDD_SOURCES.linux += \ 509 Audio/pulseaudio.c \ 510 Audio/pulse_stubs.c 525 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 526 VBoxDD_DEFS.linux += VBOX_WITH_PDM_AUDIO_DRIVER 527 VBoxDD_SOURCES.linux += \ 528 Audio/DrvHostPulseAudio.c \ 529 Audio/pulse_stubs.c 530 else 531 VBoxDD_SOURCES.linux += \ 532 Audio/pulseaudio.c \ 533 Audio/pulse_stubs.c 534 endif 511 535 VBoxDD_DEFS.freebsd += VBOX_WITH_PULSE 512 VBoxDD_SOURCES.freebsd+= \ 513 Audio/pulseaudio.c \ 514 Audio/pulse_stubs.c 536 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 537 VBoxDD_SOURCES.freebsd+= \ 538 Audio/DrvHostPulseAudio.c \ 539 Audio/pulse_stubs.c 540 else 541 VBoxDD_SOURCES.freebsd+= \ 542 Audio/pulseaudio.c \ 543 Audio/pulse_stubs.c 544 endif 515 545 endif 516 546 … … 631 661 632 662 ifeq ($(KBUILD_TARGET),freebsd) 633 VBoxDD_SOURCES := \ 634 $(filter-out Storage/DrvHostFloppy%, $(VBoxDD_SOURCES)) \ 635 Audio/ossaudio.c \ 636 Serial/DrvHostSerial.cpp 637 VBoxDD_SOURCES.freebsd += \ 638 Network/DrvTAP.cpp 663 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 664 VBoxDD_SOURCES := \ 665 $(filter-out Storage/DrvHostFloppy%, $(VBoxDD_SOURCES)) \ 666 Audio/DrvHostOssAudio.c \ 667 Serial/DrvHostSerial.cpp 668 VBoxDD_SOURCES.freebsd += \ 669 Network/DrvTAP.cpp 670 else 671 VBoxDD_SOURCES := \ 672 $(filter-out Storage/DrvHostFloppy%, $(VBoxDD_SOURCES)) \ 673 Audio/ossaudio.c \ 674 Serial/DrvHostSerial.cpp 675 VBoxDD_SOURCES.freebsd += \ 676 Network/DrvTAP.cpp 677 endif 639 678 endif # freebsd 640 679 641 680 VBoxDD_SOURCES.linux += \ 642 681 Network/DrvTAP.cpp \ 643 Audio/ossaudio.c \644 682 Parallel/DrvHostParallel.cpp \ 645 683 Serial/DrvHostSerial.cpp 646 684 685 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 686 VBoxDD_SOURCES.linux += \ 687 Audio/DrvHostOssAudio.c 688 else 689 VBoxDD_SOURCES.linux += \ 690 Audio/ossaudio.c 691 endif 692 647 693 ifeq ($(KBUILD_TARGET),os2) 648 694 VBoxDD_SOURCES := $(filter-out Storage/DrvHost%, $(VBoxDD_SOURCES)) … … 650 696 651 697 ifeq ($(KBUILD_TARGET),solaris) 652 VBoxDD_SOURCES := $(filter-out Storage/DrvHostFloppy%, $(VBoxDD_SOURCES)) 653 VBoxDD_SOURCES.solaris += \ 654 Audio/solaudio.c \ 698 VBoxDD_SOURCES := $(filter-out Storage/DrvHostFloppy%, $(VBoxDD_SOURCES)) 699 VBoxDD_SOURCES.solaris += \ 655 700 Serial/DrvHostSerial.cpp 701 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 702 VBoxDD_SOURCES.solaris += \ 703 Audio/DrvHostSolAudio.c 704 else 705 VBoxDD_SOURCES.solaris += \ 706 Audio/solaudio.c 707 endif 656 708 ifdef VBOX_WITH_SOLARIS_OSS 657 VBoxDD_SOURCES += Audio/ossaudio.c 658 VBoxDD_DEFS += VBOX_WITH_SOLARIS_OSS 709 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 710 VBoxDD_SOURCES += Audio/DrvHostOssAudio.c 711 else 712 VBoxDD_SOURCES += Audio/ossaudio.c 713 endif 714 VBoxDD_DEFS += VBOX_WITH_SOLARIS_OSS 659 715 endif 660 716 ifdef VBOX_WITH_SUID_WRAPPER … … 664 720 665 721 VBoxDD_DEFS.win += VBOX_WITH_WIN_PARPORT_SUP 722 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 723 VBoxDD_DEFS.win += VBOX_WITH_PDM_AUDIO_DRIVER 724 endif 666 725 VBoxDD_SOURCES.win += \ 667 Audio/dsoundaudio.c \668 726 Serial/DrvHostSerial.cpp \ 669 727 Parallel/DrvHostParallel.cpp 728 729 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 730 VBoxDD_SOURCES.win += \ 731 Audio/DrvHostDSound.c 732 else 733 VBoxDD_SOURCES.win += \ 734 Audio/dsoundaudio.c 735 endif 670 736 671 737 if defined(VBOX_WITH_NETFLT) -
trunk/src/VBox/Devices/build/VBoxDD.cpp
r49316 r50686 127 127 if (RT_FAILURE(rc)) 128 128 return rc; 129 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 130 //rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceAudioVRDE); 131 //if (RT_FAILURE(rc)) 132 // return rc; 133 #else 129 134 rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceAudioSniffer); 130 135 if (RT_FAILURE(rc)) 131 136 return rc; 137 #endif 132 138 #ifdef VBOX_WITH_VUSB 133 139 rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceOHCI); … … 266 272 if (RT_FAILURE(rc)) 267 273 return rc; 274 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 275 # if defined(RT_OS_WINDOWS) 276 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostDSound); 277 if (RT_FAILURE(rc)) 278 return rc; 279 # endif 280 # if defined(RT_OS_LINUX) 281 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostPulseAudio); 282 if (RT_FAILURE(rc)) 283 return rc; 284 # endif 285 # if defined(RT_OS_FREEBSD) 286 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostOssAudio); 287 if (RT_FAILURE(rc)) 288 return rc; 289 # endif 290 # if defined(RT_OS_DARWIN) 291 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostCoreAudio); 292 if (RT_FAILURE(rc)) 293 return rc; 294 # endif 295 # if defined(RT_OS_SOLARIS) 296 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostSolAudio); 297 if (RT_FAILURE(rc)) 298 return rc; 299 # endif 300 #endif 268 301 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvACPI); 269 302 if (RT_FAILURE(rc)) -
trunk/src/VBox/Devices/build/VBoxDD.h
r49316 r50686 56 56 extern const PDMDEVREG g_DeviceSB16; 57 57 extern const PDMDEVREG g_DeviceICH6_HDA; 58 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 58 59 extern const PDMDEVREG g_DeviceAudioSniffer; 60 #endif 59 61 extern const PDMDEVREG g_DeviceOHCI; 60 62 extern const PDMDEVREG g_DeviceEHCI; … … 111 113 extern const PDMDRVREG g_DrvNetSniffer; 112 114 extern const PDMDRVREG g_DrvAUDIO; 115 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 116 # if defined(RT_OS_WINDOWS) 117 extern const PDMDRVREG g_DrvHostDSound; 118 # endif 119 # if defined(RT_OS_LINUX) 120 extern const PDMDRVREG g_DrvHostPulseAudio; 121 # endif 122 # if defined(RT_OS_DARWIN) 123 extern const PDMDRVREG g_DrvHostCoreAudio; 124 # endif 125 # if defined(RT_OS_SOLARIS) 126 extern const PDMDRVREG g_DrvHostSolAudio; 127 # endif 128 # if defined(RT_OS_FREEBSD) 129 extern const PDMDRVREG g_DrvHostOssAudio; 130 # endif 131 #endif 113 132 extern const PDMDRVREG g_DrvACPI; 114 133 extern const PDMDRVREG g_DrvAcpiCpu; -
trunk/src/VBox/Main/Makefile.kmk
r50560 r50686 282 282 $(if $(VBOX_WITH_S3),VBOX_WITH_S3,) \ 283 283 $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,) \ 284 $(if $(VBOX_WITH_PDM_AUDIO_DRIVER),VBOX_WITH_PDM_AUDIO_DRIVER,) \ 284 285 $(if $(VBOX_WITH_NAT_SERVICE),VBOX_WITH_NAT_SERVICE,) \ 285 286 $(if $(VBOX_WITH_CROGL),VBOX_WITH_CROGL,) \ … … 615 616 $(if $(VBOX_WITH_EXTPACK),VBOX_WITH_EXTPACK,) \ 616 617 $(if $(VBOX_WITH_PCI_PASSTHROUGH),VBOX_WITH_PCI_PASSTHROUGH,) \ 617 $(if $(VBOX_WITH_VPX),VBOX_WITH_VPX,) 618 $(if $(VBOX_WITH_VPX),VBOX_WITH_VPX,) \ 619 $(if $(VBOX_WITH_PDM_AUDIO_DRIVER),VBOX_WITH_PDM_AUDIO_DRIVER,) 618 620 ifdef VBOX_WITH_CRHGSMI 619 621 VBoxC_DEFS += VBOX_WITH_CRHGSMI … … 693 695 src-client/Nvram.cpp \ 694 696 src-client/AdditionsFacilityImpl.cpp \ 695 src-client/AudioSnifferInterface.cpp \696 697 src-client/BusAssignmentManager.cpp \ 697 698 $(if $(VBOX_WITH_PCI_PASSTHROUGH),src-client/PCIRawDevImpl.cpp,) \ … … 721 722 $(VBOX_AUTOGEN_EVENT_CPP) \ 722 723 $(VBOX_XML_SCHEMADEFS_CPP) 724 ifdef VBOX_WITH_PDM_AUDIO_DRIVER 725 VBoxC_SOURCES += \ 726 src-client/DrvAudioVRDE.cpp 727 else 728 VBoxC_SOURCES += \ 729 src-client/AudioSnifferInterface.cpp 730 endif 723 731 VBoxC_SOURCES.win = \ 724 732 src-client/win/dllmain.cpp \ -
trunk/src/VBox/Main/include/ConsoleImpl.h
r49983 r50686 34 34 class VRDEServerInfo; 35 35 class EmulatedUSB; 36 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 37 class AudioVRDE; 38 #else 36 39 class AudioSniffer; 40 #endif 37 41 class Nvram; 38 42 #ifdef VBOX_WITH_USB_CARDREADER … … 190 194 Display *getDisplay() const { return mDisplay; } 191 195 MachineDebugger *getMachineDebugger() const { return mDebugger; } 196 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 197 AudioVRDE *getAudioVRDE() const { return mAudioVRDE; } 198 #else 192 199 AudioSniffer *getAudioSniffer() const { return mAudioSniffer; } 200 #endif 193 201 194 202 const ComPtr<IMachine> &machine() const { return mMachine; } … … 235 243 int hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName); 236 244 VMMDev *getVMMDev() { return m_pVMMDev; } 245 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 246 AudioVRDE *getAudioVRDE() { return mAudioVRDE; } 247 #else 237 248 AudioSniffer *getAudioSniffer() { return mAudioSniffer; } 249 #endif 250 238 251 #ifdef VBOX_WITH_EXTPACK 239 252 ExtPackManager *getExtPackManager(); … … 825 838 826 839 VMMDev * m_pVMMDev; 840 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 841 AudioVRDE * const mAudioVRDE; 842 #else 827 843 AudioSniffer * const mAudioSniffer; 844 #endif 828 845 Nvram * const mNvram; 829 846 #ifdef VBOX_WITH_USB_CARDREADER -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r50544 r50686 56 56 #include "RemoteUSBDeviceImpl.h" 57 57 #include "SharedFolderImpl.h" 58 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 59 #include "DrvAudioVRDE.h" 60 #else 58 61 #include "AudioSnifferInterface.h" 62 #endif 59 63 #include "Nvram.h" 60 64 #ifdef VBOX_WITH_USB_CARDREADER … … 404 408 , mpVmm2UserMethods(NULL) 405 409 , m_pVMMDev(NULL) 410 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 406 411 , mAudioSniffer(NULL) 412 #endif 407 413 , mNvram(NULL) 408 414 #ifdef VBOX_WITH_USB_CARDREADER … … 564 570 // AssertReturn(mVMMDev, E_FAIL); 565 571 572 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 573 unconst(mAudioVRDE) = new AudioVRDE(this); 574 AssertComRCReturnRC(rc); 575 #else 566 576 unconst(mAudioSniffer) = new AudioSniffer(this); 567 577 AssertReturn(mAudioSniffer, E_FAIL); 578 #endif 568 579 569 580 FirmwareType_T enmFirmwareType; … … 683 694 } 684 695 #endif 685 696 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 686 697 if (mAudioSniffer) 687 698 { … … 689 700 unconst(mAudioSniffer) = NULL; 690 701 } 702 #endif 691 703 692 704 // if the VM had a VMMDev with an HGCM thread, then remove that here … … 1389 1401 if (mcAudioRefs <= 0) 1390 1402 { 1403 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 1391 1404 if (mAudioSniffer) 1392 1405 { … … 1397 1410 } 1398 1411 } 1412 #endif 1399 1413 } 1400 1414 } … … 1430 1444 AutoCaller autoCaller(this); 1431 1445 AssertComRCReturnVoid(autoCaller.rc()); 1432 1446 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 1433 1447 LogFlowFunc(("mAudioSniffer %p, u32ClientId %d.\n", 1434 1448 mAudioSniffer, u32ClientId)); 1435 1449 NOREF(u32ClientId); 1450 #endif 1436 1451 1437 1452 ++mcAudioRefs; … … 1439 1454 if (mcAudioRefs == 1) 1440 1455 { 1456 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 1441 1457 if (mAudioSniffer) 1442 1458 { … … 1447 1463 } 1448 1464 } 1465 #endif 1449 1466 } 1450 1467 -
trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
r50585 r50686 2503 2503 attachStatusDriver(pInst, &mapSharedFolderLed, 0, 0, NULL, NULL, 0); 2504 2504 2505 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 2505 2506 /* 2506 2507 * Audio Sniffer Device … … 2516 2517 AudioSniffer *pAudioSniffer = mAudioSniffer; 2517 2518 InsertConfigInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); 2519 #endif 2518 2520 2519 2521 /* … … 2569 2571 /* the Audio driver */ 2570 2572 InsertConfigNode(pInst, "LUN#0", &pLunL0); 2571 InsertConfigString(pLunL0, "Driver", "AUDIO"); 2573 InsertConfigString(pLunL0, "Driver", "AUDIO"); 2574 2575 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2576 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1); 2577 InsertConfigString(pLunL1, "Driver", "PulseAudio"); 2578 #endif 2579 2572 2580 InsertConfigNode(pLunL0, "Config", &pCfg); 2573 2581 … … 2591 2599 case AudioDriverType_DirectSound: 2592 2600 { 2601 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2602 InsertConfigString(pCfg, "AudioDriver", "DSoundAudio"); 2603 #else 2593 2604 InsertConfigString(pCfg, "AudioDriver", "dsound"); 2605 #endif 2594 2606 break; 2595 2607 } … … 2606 2618 case AudioDriverType_ALSA: 2607 2619 { 2620 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2621 InsertConfigString(pCfg, "AudioDriver", "AlsaAudio"); 2622 #else 2608 2623 InsertConfigString(pCfg, "AudioDriver", "alsa"); 2624 #endif 2609 2625 break; 2610 2626 } … … 2613 2629 case AudioDriverType_Pulse: 2614 2630 { 2631 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2632 InsertConfigString(pCfg, "AudioDriver", "PulseAudio"); 2633 #else 2615 2634 InsertConfigString(pCfg, "AudioDriver", "pulse"); 2635 #endif 2616 2636 break; 2617 2637 } … … 2629 2649 case AudioDriverType_Pulse: 2630 2650 { 2651 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2652 InsertConfigString(pCfg, "AudioDriver", "PulseAudio"); 2653 #else 2631 2654 InsertConfigString(pCfg, "AudioDriver", "pulse"); 2655 #endif 2632 2656 break; 2633 2657 } … … 2644 2668 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H(); 2645 2669 InsertConfigString(pCfg, "StreamName", bstr); 2670 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 2671 /* the Audio driver */ 2672 InsertConfigNode(pInst, "LUN#1", &pLunL0); 2673 InsertConfigString(pLunL0, "Driver", "AUDIO"); 2674 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1); 2675 InsertConfigString(pLunL1, "Driver", "AudioVRDE"); 2676 InsertConfigNode(pLunL0, "Config", &pCfg); 2677 InsertConfigString(pCfg, "AudioDriver", "AudioVRDE"); 2678 InsertConfigString(pCfg, "StreamName", bstr); 2679 InsertConfigNode(pLunL1, "Config", &pCfg); 2680 InsertConfigInteger(pCfg, "Object", (uintptr_t)mAudioVRDE); 2681 InsertConfigInteger(pCfg, "ObjectVRDPServer", (uintptr_t)mConsoleVRDPServer); 2682 2683 #endif 2646 2684 } 2647 2685 -
trunk/src/VBox/Main/src-client/ConsoleVRDPServer.cpp
r50319 r50686 21 21 #include "KeyboardImpl.h" 22 22 #include "MouseImpl.h" 23 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 24 #include "DrvAudioVRDE.h" 25 #else 23 26 #include "AudioSnifferInterface.h" 27 #endif 24 28 #ifdef VBOX_WITH_EXTPACK 25 29 # include "ExtPackManagerImpl.h" … … 947 951 ASMAtomicWriteU32(&server->mu32AudioInputClientId, 0); 948 952 953 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 954 server->mConsole->getAudioVRDE()->handleVRDESvrCmdAudioInputIntercept(false); 955 #else 949 956 PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort(); 950 957 if (pPort) … … 956 963 AssertFailed(); 957 964 } 965 #endif 958 966 } 959 967 … … 1010 1018 { 1011 1019 Log(("AUDIOIN: connected client %u\n", u32ClientId)); 1012 1020 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1021 server->mConsole->getAudioVRDE()->handleVRDESvrCmdAudioInputIntercept(true); 1022 #else 1013 1023 PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort(); 1014 1024 if (pPort) … … 1026 1036 rc = VERR_NOT_SUPPORTED; 1027 1037 } 1038 #endif 1028 1039 } 1029 1040 else … … 1294 1305 { 1295 1306 ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback); 1296 1307 #ifndef VBOX_WITH_PDM_AUDIO_DRIVER 1297 1308 PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort(); 1309 #endif 1298 1310 1299 1311 switch (u32Event) … … 1302 1314 { 1303 1315 const VRDEAUDIOINBEGIN *pParms = (const VRDEAUDIOINBEGIN *)pvData; 1304 1316 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1317 server->mConsole->getAudioVRDE()->handleVRDESvrCmdAudioInputEventBegin(pvCtx, 1318 VRDE_AUDIO_FMT_SAMPLE_FREQ(pParms->fmt), 1319 VRDE_AUDIO_FMT_CHANNELS(pParms->fmt), 1320 VRDE_AUDIO_FMT_BITS_PER_SAMPLE(pParms->fmt), 1321 VRDE_AUDIO_FMT_SIGNED(pParms->fmt) 1322 ); 1323 #else 1305 1324 pPort->pfnAudioInputEventBegin (pPort, pvCtx, 1306 1325 VRDE_AUDIO_FMT_SAMPLE_FREQ(pParms->fmt), … … 1309 1328 VRDE_AUDIO_FMT_SIGNED(pParms->fmt) 1310 1329 ); 1330 #endif 1311 1331 } break; 1312 1332 1313 1333 case VRDE_AUDIOIN_DATA: 1314 1334 { 1335 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1336 server->mConsole->getAudioVRDE()->handleVRDESvrCmdAudioInputEventData(pvCtx, pvData, cbData); 1337 #else 1315 1338 pPort->pfnAudioInputEventData (pPort, pvCtx, pvData, cbData); 1339 #endif 1316 1340 } break; 1317 1341 1318 1342 case VRDE_AUDIOIN_END: 1319 1343 { 1344 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 1345 server->mConsole->getAudioVRDE()->handleVRDESvrCmdAudioInputEventEnd(pvCtx); 1346 #else 1320 1347 pPort->pfnAudioInputEventEnd (pPort, pvCtx); 1348 #endif 1321 1349 } break; 1322 1350 … … 1336 1364 mcClipboardRefs = 0; 1337 1365 mpfnClipboardCallback = NULL; 1338 1339 1366 #ifdef VBOX_WITH_USB 1340 1367 mUSBBackends.pHead = NULL; … … 3880 3907 audioFormat, 3881 3908 cSamples); 3909 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 3910 //*ppvUserCtx = NULL; 3911 #else 3882 3912 *ppvUserCtx = NULL; /* This is the ConsoleVRDPServer context. 3883 * Currently not used because only one client is allowed to 3884 * do audio input and the client id is saved by the ConsoleVRDPServer. 3885 */ 3913 - * Currently not used because only one client is allowed to 3914 - * do audio input and the client id is saved by the ConsoleVRDPServer. 3915 - */ 3916 #endif 3886 3917 3887 3918 return VINF_SUCCESS; -
trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
r50177 r50686 1 1 /* $Id$ */ 2 2 /** @file 3 * VirtualBox Driver Interface to Audio Sniffer device 3 * 4 * VBox Audio VRDE backend 4 5 */ 5 6 6 7 /* 7 * Copyright (C) 2006-201 2Oracle Corporation8 * Copyright (C) 2006-2010 Oracle Corporation 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 15 16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 17 */ 17 18 #include "AudioSnifferInterface.h" 18 #include "DrvAudioVRDE.h" 19 19 #include "ConsoleImpl.h" 20 20 #include "ConsoleVRDPServer.h" … … 22 22 #include "Logging.h" 23 23 24 #include <VBox/vmm/pdmaudioifs.h> 24 25 #include <VBox/vmm/pdmdrv.h> 25 26 #include <VBox/RemoteDesktop/VRDE.h> 26 27 #include <VBox/vmm/cfgm.h> 27 28 #include <VBox/err.h> 28 29 // 30 // defines 31 // 32 33 34 // 35 // globals 36 // 37 38 29 #include <iprt/mem.h> 30 #include <iprt/cdefs.h> 31 32 33 /******************************************************************************* 34 * 35 * IO Ring Buffer section 36 * 37 ******************************************************************************/ 38 39 /* Implementation of a lock free ring buffer which could be used in a multi 40 * threaded environment. Note that only the acquire, release and getter 41 * functions are threading aware. So don't use reset if the ring buffer is 42 * still in use. */ 43 typedef struct IORINGBUFFER 44 { 45 /* The current read position in the buffer */ 46 uint32_t uReadPos; 47 /* The current write position in the buffer */ 48 uint32_t uWritePos; 49 /* How much space of the buffer is currently in use */ 50 volatile uint32_t cBufferUsed; 51 /* How big is the buffer */ 52 uint32_t cBufSize; 53 /* The buffer itself */ 54 char *pBuffer; 55 } IORINGBUFFER; 56 /* Pointer to an ring buffer structure */ 57 typedef IORINGBUFFER* PIORINGBUFFER; 58 59 PPDMDRVINS gpDrvIns; //@todo handle this bad programming; 60 61 static void IORingBufferCreate(PIORINGBUFFER *ppBuffer, uint32_t cSize) 62 { 63 PIORINGBUFFER pTmpBuffer; 64 65 AssertPtr(ppBuffer); 66 67 *ppBuffer = NULL; 68 pTmpBuffer = RTMemAllocZ(sizeof(IORINGBUFFER)); 69 if (pTmpBuffer) 70 { 71 pTmpBuffer->pBuffer = RTMemAlloc(cSize); 72 if(pTmpBuffer->pBuffer) 73 { 74 pTmpBuffer->cBufSize = cSize; 75 *ppBuffer = pTmpBuffer; 76 } 77 else 78 RTMemFree(pTmpBuffer); 79 } 80 } 81 82 static void IORingBufferDestroy(PIORINGBUFFER pBuffer) 83 { 84 if (pBuffer) 85 { 86 if (pBuffer->pBuffer) 87 RTMemFree(pBuffer->pBuffer); 88 RTMemFree(pBuffer); 89 } 90 } 91 92 DECL_FORCE_INLINE(void) IORingBufferReset(PIORINGBUFFER pBuffer) 93 { 94 AssertPtr(pBuffer); 95 96 pBuffer->uReadPos = 0; 97 pBuffer->uWritePos = 0; 98 pBuffer->cBufferUsed = 0; 99 } 100 101 DECL_FORCE_INLINE(uint32_t) IORingBufferFree(PIORINGBUFFER pBuffer) 102 { 103 AssertPtr(pBuffer); 104 return pBuffer->cBufSize - ASMAtomicReadU32(&pBuffer->cBufferUsed); 105 } 106 107 DECL_FORCE_INLINE(uint32_t) IORingBufferUsed(PIORINGBUFFER pBuffer) 108 { 109 AssertPtr(pBuffer); 110 return ASMAtomicReadU32(&pBuffer->cBufferUsed); 111 } 112 113 DECL_FORCE_INLINE(uint32_t) IORingBufferSize(PIORINGBUFFER pBuffer) 114 { 115 AssertPtr(pBuffer); 116 return pBuffer->cBufSize; 117 } 118 119 static void IORingBufferAquireReadBlock(PIORINGBUFFER pBuffer, uint32_t cReqSize, char **ppStart, uint32_t *pcSize) 120 { 121 uint32_t uUsed = 0; 122 uint32_t uSize = 0; 123 124 AssertPtr(pBuffer); 125 126 *ppStart = 0; 127 *pcSize = 0; 128 129 /* How much is in use? */ 130 uUsed = ASMAtomicReadU32(&pBuffer->cBufferUsed); 131 if (uUsed > 0) 132 { 133 /* Get the size out of the requested size, the read block till the end 134 * of the buffer & the currently used size. */ 135 uSize = RT_MIN(cReqSize, RT_MIN(pBuffer->cBufSize - pBuffer->uReadPos, uUsed)); 136 if (uSize > 0) 137 { 138 /* Return the pointer address which point to the current read 139 * position. */ 140 *ppStart = pBuffer->pBuffer + pBuffer->uReadPos; 141 *pcSize = uSize; 142 } 143 } 144 } 145 146 DECL_FORCE_INLINE(void) IORingBufferReleaseReadBlock(PIORINGBUFFER pBuffer, uint32_t cSize) 147 { 148 AssertPtr(pBuffer); 149 150 /* Split at the end of the buffer. */ 151 pBuffer->uReadPos = (pBuffer->uReadPos + cSize) % pBuffer->cBufSize; 152 ASMAtomicSubU32(&pBuffer->cBufferUsed, cSize); 153 } 154 155 static void IORingBufferAquireWriteBlock(PIORINGBUFFER pBuffer, uint32_t cReqSize, char **ppStart, uint32_t *pcSize) 156 { 157 uint32_t uFree; 158 uint32_t uSize; 159 160 AssertPtr(pBuffer); 161 162 *ppStart = 0; 163 *pcSize = 0; 164 165 /* How much is free? */ 166 uFree = pBuffer->cBufSize - ASMAtomicReadU32(&pBuffer->cBufferUsed); 167 if (uFree > 0) 168 { 169 /* Get the size out of the requested size, the write block till the end 170 * of the buffer & the currently free size. */ 171 uSize = RT_MIN(cReqSize, RT_MIN(pBuffer->cBufSize - pBuffer->uWritePos, uFree)); 172 if (uSize > 0) 173 { 174 /* Return the pointer address which point to the current write 175 * position. */ 176 *ppStart = pBuffer->pBuffer + pBuffer->uWritePos; 177 *pcSize = uSize; 178 } 179 } 180 } 181 182 DECL_FORCE_INLINE(void) IORingBufferReleaseWriteBlock(PIORINGBUFFER pBuffer, uint32_t cSize) 183 { 184 AssertPtr(pBuffer); 185 186 /* Split at the end of the buffer. */ 187 pBuffer->uWritePos = (pBuffer->uWritePos + cSize) % pBuffer->cBufSize; 188 189 ASMAtomicAddU32(&pBuffer->cBufferUsed, cSize); 190 } 191 192 /****************** Ring Buffer Function Ends *****************/ 193 194 //@todo need to see if they need to move to pdmifs.h 195 #define AUDIO_HOST_ENDIANNESS 0 196 #define VOICE_ENABLE 1 197 #define VOICE_DISABLE 2 198 199 200 /* Initialization status indicator used for the recreation of the AudioUnits. */ 201 #define CA_STATUS_UNINIT UINT32_C(0) /* The device is uninitialized */ 202 #define CA_STATUS_IN_INIT UINT32_C(1) /* The device is currently initializing */ 203 #define CA_STATUS_INIT UINT32_C(2) /* The device is initialized */ 204 #define CA_STATUS_IN_UNINIT UINT32_C(3) /* The device is currently uninitializing */ 205 206 //@todo move t_sample as a PDM interface 207 //typedef struct { int mute; uint32_t r; uint32_t l; } volume_t; 208 209 #define INT_MAX 0x7fffffff 210 volume_t nominal_volume = { 211 0, 212 INT_MAX, 213 INT_MAX 214 }; 215 216 /* The desired buffer length in milliseconds. Will be the target total stream 217 * latency on newer version of pulse. Apparent latency can be less (or more.) 218 * In case its need to be used. Currently its not used. 219 */ 220 #if 0 221 static struct 222 { 223 int buffer_msecs_out; 224 int buffer_msecs_in; 225 } confAudioVRDE 226 = 227 { 228 INIT_FIELD (.buffer_msecs_out = ) 100, 229 INIT_FIELD (.buffer_msecs_in = ) 100, 230 }; 231 #endif 39 232 /** 40 * Audio Snifferdriver instance data.233 * Audio VRDE driver instance data. 41 234 * 42 235 * @extends PDMIAUDIOSNIFFERCONNECTOR 43 236 */ 44 typedef struct DRVAUDIO SNIFFER45 { 46 /** Pointer to the Audio Sniffer object.*/47 Audio Sniffer *pAudioSniffer;48 237 typedef struct DRVAUDIOVRDE 238 { 239 /** Pointer to audio VRDE object */ 240 AudioVRDE *pAudioVRDE; 241 PPDMDRVINS pDrvIns; 49 242 /** Pointer to the driver instance structure. */ 50 PPDMDRVINS pDrvIns; 51 52 /** Pointer to the AudioSniffer port interface of the driver/device above us. */ 53 PPDMIAUDIOSNIFFERPORT pUpPort; 54 /** Our VMM device connector interface. */ 55 PDMIAUDIOSNIFFERCONNECTOR Connector; 56 57 } DRVAUDIOSNIFFER, *PDRVAUDIOSNIFFER; 58 59 /** Converts PDMIAUDIOSNIFFERCONNECTOR pointer to a DRVAUDIOSNIFFER pointer. */ 60 #define PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface) RT_FROM_MEMBER(pInterface, DRVAUDIOSNIFFER, Connector) 61 62 63 // 64 // constructor / destructor 65 // 66 AudioSniffer::AudioSniffer(Console *console) 243 PDMIHOSTAUDIO IHostAudioR3; 244 ConsoleVRDPServer *pConsoleVRDPServer; 245 /** Pointer to the DrvAudio port interface that is above it. */ 246 PPDMIAUDIOCONNECTOR pUpPort; 247 } DRVAUDIOVRDE, *PDRVAUDIOVRDE; 248 typedef struct PDMHOSTVOICEOUT PDMHOSTVOICEOUT; 249 typedef PDMHOSTVOICEOUT *PPDMHOSTVOICEOUT; 250 251 typedef struct VRDEVoice 252 { 253 /* Audio and audio details for recording */ 254 PDMHOSTVOICEIN pHostVoiceIn; 255 void * pvUserCtx; 256 /* Number of bytes per frame (bitsPerSample * channels) of the actual input format. */ 257 uint32_t cBytesPerFrame; 258 /* Frequency of the actual audio format. */ 259 uint32_t uFrequency; 260 /* If the actual format frequence differs from the requested format, this is not NULL. */ 261 void *rate; 262 /* Temporary buffer for st_sample_t representation of the input audio data. */ 263 void *pvSamplesBuffer; 264 /* buffer for bytes of samples (not rate converted) */ 265 uint32_t cbSamplesBufferAllocated; 266 /* Temporary buffer for frequency conversion. */ 267 void *pvRateBuffer; 268 /* buffer for bytes rate converted samples */ 269 uint32_t cbRateBufferAllocated; 270 /* A ring buffer for transferring data to the playback thread */ 271 PIORINGBUFFER pRecordedVoiceBuf; 272 t_sample * convAudioDevFmtToStSampl; 273 uint32_t fIsInit; 274 uint32_t status; 275 }; 276 typedef VRDEVoice *PVRDEVoice; 277 278 typedef struct VRDEVoiceOut 279 { 280 PDMHOSTVOICEOUT pHostVoiceOut; 281 uint64_t old_ticks; 282 uint64_t cSamplesSentPerSec; 283 }; 284 typedef VRDEVoiceOut * PVRDEVoiceOut; 285 286 /** Makes a PDRVBLOCK out of a PPDMIBLOCK. */ 287 #define PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface) ( (PDRVAUDIOVRDE)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIOVRDE, IHostAudioR3)) ) 288 289 AudioVRDE::AudioVRDE(Console *console) 67 290 : mpDrv(NULL), 68 291 mParent(console) … … 70 293 } 71 294 72 Audio Sniffer::~AudioSniffer()295 AudioVRDE::~AudioVRDE() 73 296 { 74 297 if (mpDrv) 75 298 { 76 mpDrv->pAudio Sniffer= NULL;299 mpDrv->pAudioVRDE = NULL; 77 300 mpDrv = NULL; 78 301 } 79 302 } 80 303 81 PPDMIAUDIO SNIFFERPORT AudioSniffer::getAudioSnifferPort()304 PPDMIAUDIOCONNECTOR AudioVRDE::getDrvAudioPort() 82 305 { 83 306 Assert(mpDrv); … … 85 308 } 86 309 87 88 89 // 90 // public methods 91 // 92 93 DECLCALLBACK(void) iface_AudioSamplesOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, void *pvSamples, uint32_t cSamples, 94 int samplesPerSec, int nChannels, int bitsPerSample, bool fUnsigned) 95 { 96 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface); 97 310 void AudioVRDE::handleVRDESvrCmdAudioInputIntercept(bool fIntercept) 311 { 312 LogFlow(("AudioVRDE: handleVRDPCmdInputIntercept\n")); 313 } 314 315 static DECLCALLBACK(void *) drvAudioVRDEInit(PPDMIHOSTAUDIO pInterface) 316 { 317 LogFlow(("drvAudioVRDEInit \n")); 318 return 1; 319 } 320 321 static void drvAudioVRDEPcmInitInfo(PDMPCMPROPERTIES * pProps, audsettings_t *as) 322 { 323 int bits = 8, sign = 0, shift = 0; 324 LogFlow(("AudioVRDE: PcmInitInfo \n")); 325 326 switch (as->fmt) { 327 case AUD_FMT_S8: 328 sign = 1; 329 case AUD_FMT_U8: 330 break; 331 332 case AUD_FMT_S16: 333 sign = 1; 334 case AUD_FMT_U16: 335 bits = 16; 336 shift = 1; 337 break; 338 339 case AUD_FMT_S32: 340 sign = 1; 341 case AUD_FMT_U32: 342 bits = 32; 343 shift = 2; 344 break; 345 } 346 347 pProps->uFrequency = as->freq; 348 pProps->cBits = bits; 349 pProps->fSigned = sign; 350 pProps->cChannels = as->nchannels; 351 pProps->cShift = (as->nchannels == 2) + shift; 352 pProps->fAlign = (1 << pProps->cShift) - 1; 353 pProps->cbPerSec = pProps->uFrequency << pProps->cShift; 354 pProps->fSwapEndian = (as->endianness != AUDIO_HOST_ENDIANNESS); 355 } 356 357 /* 358 * Hard voice (playback) 359 */ 360 static int audio_pcm_hw_find_min_out (PPDMHOSTVOICEOUT hw, int *nb_livep) 361 { 362 PPDMGSTVOICEOUT sw; 363 PPDMGSTVOICEOUT pIter; 364 int m = INT_MAX; 365 int nb_live = 0; 366 LogFlow(("Hard Voice Playback \n")); 367 368 RTListForEach(&hw->HeadGstVoiceOut, pIter, PDMGSTVOICEOUT, ListGstVoiceOut) 369 { 370 sw = pIter; 371 if (sw->State.fActive || !sw->State.fEmpty) 372 { 373 m = audio_MIN (m, sw->cSamplesMixed); 374 nb_live += 1; 375 } 376 } 377 378 *nb_livep = nb_live; 379 return m; 380 } 381 382 int audio_pcm_hw_get_live_out2 (PPDMHOSTVOICEOUT hw, int *nb_live) 383 { 384 int smin; 385 386 smin = audio_pcm_hw_find_min_out (hw, nb_live); 387 388 if (!*nb_live) { 389 return 0; 390 } 391 else 392 { 393 int live = smin; 394 395 if (live < 0 || live > hw->cSamples) 396 { 397 LogFlow(("Error: live=%d hw->samples=%d\n", live, hw->cSamples)); 398 return 0; 399 } 400 return live; 401 } 402 } 403 404 405 int audio_pcm_hw_get_live_out (PPDMHOSTVOICEOUT hw) 406 { 407 int nb_live; 408 int live; 409 410 live = audio_pcm_hw_get_live_out2 (hw, &nb_live); 411 if (live < 0 || live > hw->cSamples) 412 { 413 LogFlow(("Error: live=%d hw->samples=%d\n", live, hw->cSamples)); 414 return 0; 415 } 416 return live; 417 } 418 419 /* 420 * Hard voice (capture) 421 */ 422 static int audio_pcm_hw_find_min_in (PPDMHOSTVOICEIN hw) 423 { 424 PPDMGSTVOICEIN pIter; 425 int m = hw->cSamplesCaptured; 426 427 RTListForEach(&hw->HeadGstVoiceIn, pIter, PDMGSTVOICEIN, ListGstVoiceIn) 428 { 429 if (pIter->State.fActive) 430 { 431 m = audio_MIN (m, pIter->cHostSamplesAcquired); 432 } 433 } 434 return m; 435 } 436 437 int audio_pcm_hw_get_live_in (PPDMHOSTVOICEIN hw) 438 { 439 int live = hw->cSamplesCaptured - audio_pcm_hw_find_min_in (hw); 440 if (live < 0 || live > hw->cSamples) 441 { 442 LogFlow(("Error: live=%d hw->samples=%d\n", live, hw->cSamples)); 443 return 0; 444 } 445 return live; 446 } 447 448 static inline void *advance (void *p, int incr) 449 { 450 uint8_t *d = (uint8_t*)p; 451 return (d + incr); 452 } 453 454 uint64_t audio_get_ticks_per_sec (void) 455 { 456 return PDMDrvHlpTMGetVirtualFreq (gpDrvIns); 457 } 458 459 uint64_t audio_get_clock (void) 460 { 461 return PDMDrvHlpTMGetVirtualTime (gpDrvIns); 462 } 463 464 void VRDEReallocSampleBuf(PVRDEVoice pVRDEVoice, uint32_t cSamples) 465 { 466 uint32_t cbBuffer = cSamples * sizeof(PDMHOSTSTEREOSAMPLE); 467 if (cbBuffer > pVRDEVoice->cbSamplesBufferAllocated) 468 { 469 if (pVRDEVoice->pvSamplesBuffer) 470 { 471 RTMemFree(pVRDEVoice->pvSamplesBuffer); 472 pVRDEVoice->pvSamplesBuffer = NULL; 473 } 474 pVRDEVoice->pvSamplesBuffer = RTMemAlloc(cbBuffer); 475 if (pVRDEVoice->pvSamplesBuffer) 476 pVRDEVoice->cbSamplesBufferAllocated = cbBuffer; 477 else 478 pVRDEVoice->cbSamplesBufferAllocated = 0; 479 } 480 481 } 482 483 void VRDEReallocRateAdjSampleBuf(PVRDEVoice pVRDEVoice, uint32_t cSamples) 484 { 485 uint32_t cbBuffer = cSamples * sizeof(PDMHOSTSTEREOSAMPLE); 486 if (cbBuffer > pVRDEVoice->cbRateBufferAllocated) 487 { 488 RTMemFree(pVRDEVoice->pvRateBuffer); 489 pVRDEVoice->pvRateBuffer = RTMemAlloc(cbBuffer); 490 if (pVRDEVoice->pvRateBuffer) 491 pVRDEVoice->cbRateBufferAllocated = cbBuffer; 492 else 493 pVRDEVoice->cbRateBufferAllocated = 0; 494 } 495 } 496 497 /******************************************************************************* 498 * 499 * AudioVRDE input section 500 * 501 ******************************************************************************/ 502 503 /* 504 * Callback to feed audio input buffer. Samples format is be the same as 505 * in the voice. The caller prepares st_sample_t. 506 * 507 * @param cbSamples Size of pvSamples array in bytes. 508 * @param pvSamples Points to an array of samples. 509 * 510 * @return IPRT status code. 511 */ 512 static int fltRecordingCallback(PVRDEVoice pVRDEVoice, uint32_t cbSamples, const void *pvSamples) 513 { 514 int rc = VINF_SUCCESS; 515 uint32_t csAvail = 0; 516 uint32_t csToWrite = 0; 517 uint32_t cbToWrite = 0; 518 uint32_t csWritten = 0; 519 char *pcDst = NULL; 520 521 LogFlow(("audio-filter: fltRecordingCallback\n")); 522 523 Assert((cbSamples % sizeof(PDMHOSTSTEREOSAMPLE)) == 0); 524 525 if (!pVRDEVoice->fIsInit) 526 return VINF_SUCCESS; 527 528 /* If nothing is pending return immediately. */ 529 if (cbSamples == 0) 530 return VINF_SUCCESS; 531 532 /* How much space is free in the ring buffer? */ 533 PPDMHOSTSTEREOSAMPLE psSrc; 534 csAvail = IORingBufferFree(pVRDEVoice->pRecordedVoiceBuf) / sizeof(PDMHOSTSTEREOSAMPLE); /* bytes -> samples */ 535 536 /* How much space is used in the audio buffer. Use the smaller size of the too. */ 537 csAvail = RT_MIN(csAvail, cbSamples / sizeof(PDMHOSTSTEREOSAMPLE)); 538 539 /* Iterate as long as data is available */ 540 while(csWritten < csAvail) 541 { 542 /* How much is left? */ 543 csToWrite = csAvail - csWritten; 544 cbToWrite = csToWrite * sizeof(PDMHOSTSTEREOSAMPLE); 545 546 /* Try to acquire the necessary space from the ring buffer. */ 547 IORingBufferAquireWriteBlock(pVRDEVoice->pRecordedVoiceBuf, cbToWrite, &pcDst, &cbToWrite); 548 549 /* How much do we get? */ 550 csToWrite = cbToWrite / sizeof(PDMHOSTSTEREOSAMPLE); 551 552 /* Break if nothing is free anymore. */ 553 if (RT_UNLIKELY(csToWrite == 0)) 554 break; 555 556 /* Copy the data from the audio buffer to the ring buffer in PVRDEVoice. */ 557 memcpy(pcDst, (uint8_t *)pvSamples + (csWritten * sizeof(PDMHOSTSTEREOSAMPLE)), cbToWrite); 558 559 /* Release the ring buffer, so the main thread could start reading this data. */ 560 IORingBufferReleaseWriteBlock(pVRDEVoice->pRecordedVoiceBuf, cbToWrite); 561 562 csWritten += csToWrite; 563 } 564 565 LogFlow(("AudioVRDE: [Input] Finished writing buffer with %RU32 samples (%RU32 bytes)\n", 566 csWritten, csWritten * sizeof(PDMHOSTSTEREOSAMPLE))); 567 568 return rc; 569 } 570 571 572 STDMETHODIMP AudioVRDE::handleVRDESvrCmdAudioInputEventBegin(void *pvContext, int iSampleHz, int cChannels, int cBits, bool fUnsigned) 573 { 574 int bitIdx; 575 PVRDEVoice pVRDEVoice = (PVRDEVoice)pvContext; 576 LogFlow(("AudioVRDE: handleVRDPCmdInputEventBegin\n")); 577 /* Prepare a format convertion for the actually used format. */ 578 pVRDEVoice->cBytesPerFrame = ((cBits + 7) / 8) * cChannels; 579 if (cBits == 16) 580 { 581 bitIdx = 1; 582 } 583 else if (cBits == 32) 584 { 585 bitIdx = 2; 586 } 587 else 588 { 589 bitIdx = 0; 590 } 591 //PPDMIAUDIOCONNECTOR pPort = server->mConsole->getAudioVRDE()->getDrvAudioPort(); 592 /* Call DrvAudio interface to get the t_sample type conversion function */ 593 pVRDEVoice->convAudioDevFmtToStSampl = mpDrv->pUpPort->pfnConvDevFmtToStSample(mpDrv->pUpPort, 594 (cChannels == 2) ? 1 : 0, 595 !fUnsigned, 0, bitIdx 596 ); 597 if (pVRDEVoice->convAudioDevFmtToStSampl) 598 { 599 LogFlow(("AudioVRDE: Failed to get the conversion function \n")); 600 } 601 LogFlow(("AudioVRDE: Required freq as requested by VRDP Server = %d\n", iSampleHz)); 602 //if (iSampleHz && iSampleHz != pVRDEVoice->pHostVoiceIn.Props.uFrequency) 603 { 604 /* @todo if the above condition is false then pVRDEVoice->uFrequency will remain 0 */ 605 pVRDEVoice->rate = mpDrv->pUpPort->pfnPrepareAudioConversion(mpDrv->pUpPort, iSampleHz, 606 pVRDEVoice->pHostVoiceIn.Props.uFrequency); 607 pVRDEVoice->uFrequency = iSampleHz; 608 LogFlow(("AudioVRDE: pVRDEVoice assigned requested freq =%d\n", pVRDEVoice->uFrequency)); 609 } 610 return VINF_SUCCESS; 611 } 612 613 /* 614 * pvContext: pointer to VRDP voice returned by the VRDP server. The is same pointer that we initialized in 615 * drvAudioVRDEDisableEnableIn VOICE_ENABLE case. 616 */ 617 void AudioVRDE::handleVRDESvrCmdAudioInputEventData(void *pvContext, const void *pvData, uint32_t cbData) 618 { 619 PVRDEVoice pVRDEVoice = (PVRDEVoice)pvContext; 620 PPDMHOSTSTEREOSAMPLE pHostStereoSampleBuf; /* target sample buffer */ 621 PPDMHOSTSTEREOSAMPLE pConvertedSampleBuf; /* samples adjusted for rate */ 622 uint32_t cSamples = cbData / pVRDEVoice->cBytesPerFrame; /* Count of samples */ 623 void * pTmpSampleBuf = NULL; 624 uint32_t cConvertedSamples; /* samples adjusted for rate */ 625 uint32_t cbSamples; /* count of bytes occupied by samples */ 626 uint32_t rc; 627 LogFlow(("AudioVRDE: handleVRDPCmdInputEventData cbData = %d, bytesperfram=%d\n", 628 cbData, pVRDEVoice->cBytesPerFrame)); 629 630 VRDEReallocSampleBuf(pVRDEVoice, cSamples); 631 pHostStereoSampleBuf = (PPDMHOSTSTEREOSAMPLE)pVRDEVoice->pvSamplesBuffer; 632 pVRDEVoice->convAudioDevFmtToStSampl(pHostStereoSampleBuf, pvData, cSamples, &nominal_volume); 633 634 /* count of rate adjusted samples */ 635 pVRDEVoice->uFrequency = 22100; /* @todo handle this. How pVRDEVoice will get proper value */ 636 cConvertedSamples = (cSamples * pVRDEVoice->pHostVoiceIn.Props.uFrequency) / pVRDEVoice->uFrequency; 637 VRDEReallocRateAdjSampleBuf(pVRDEVoice, cConvertedSamples); 638 639 pConvertedSampleBuf = (PPDMHOSTSTEREOSAMPLE)pVRDEVoice->pvRateBuffer; 640 641 if (pConvertedSampleBuf) 642 { 643 uint32_t cSampleSrc = cSamples; 644 uint32_t cSampleDst = cConvertedSamples; 645 mpDrv->pUpPort->pfnDoRateConversion(mpDrv->pUpPort, pVRDEVoice->rate, pHostStereoSampleBuf, 646 pConvertedSampleBuf, &cSampleSrc, &cConvertedSamples); 647 pTmpSampleBuf = pConvertedSampleBuf; 648 cbSamples = cConvertedSamples * sizeof(PDMHOSTSTEREOSAMPLE); 649 } 650 651 if (cbSamples) 652 { 653 rc = fltRecordingCallback(pVRDEVoice, cbSamples, pTmpSampleBuf); 654 } 655 } 656 657 /* 658 * pvContext: pointer to VRDP voice returned by the VRDP server. The is same pointer that we initialized in 659 * drvAudioVRDEDisableEnableIn VOICE_ENABLE case. 660 */ 661 void AudioVRDE::handleVRDESvrCmdAudioInputEventEnd(void *pvContext) 662 { 663 PVRDEVoice pVRDEVoice = (PVRDEVoice)pvContext; 664 LogFlow(("AudioVRDE: handleVRDPCmdInputEventEnd\n")); 665 /* The caller will not use this context anymore. */ 666 if (pVRDEVoice->rate) 667 { 668 mpDrv->pUpPort->pfnEndAudioConversion(mpDrv->pUpPort, pVRDEVoice->rate); 669 } 670 671 if (pVRDEVoice->pvSamplesBuffer) 672 { 673 RTMemFree(pVRDEVoice->pvSamplesBuffer); 674 pVRDEVoice->pvSamplesBuffer = NULL; 675 } 676 if(pVRDEVoice->pvRateBuffer) 677 { 678 RTMemFree(pVRDEVoice->pvRateBuffer); 679 pVRDEVoice->pvRateBuffer = NULL; 680 } 681 } 682 683 static DECLCALLBACK(int) drvAudioVRDEInitOut(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEOUT pHostVoiceOut, audsettings_t *as) 684 { 685 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 686 PVRDEVoiceOut pVRDEVoiceOut = (PVRDEVoiceOut)pHostVoiceOut; 687 LogFlow(("DrvAudioVRDEInitOut: audio input begin cShift=%d\n", pHostVoiceOut->Props.cShift)); 688 pHostVoiceOut->cSamples = 6174; 689 drvAudioVRDEPcmInitInfo(&pVRDEVoiceOut->pHostVoiceOut.Props, as); 690 return VINF_SUCCESS; 691 692 } 693 694 static DECLCALLBACK(int) drvAudioVRDEInitIn (PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEIN pHostVoiceIn, audsettings_t *as) 695 { 696 LogFlow(("DrvAudioVRDE: drvAudioVRDEInitIn \n")); 697 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 698 PVRDEVoice pVRDEVoice = (PVRDEVoice)pHostVoiceIn; 699 pHostVoiceIn->cSamples = 6174; 700 drvAudioVRDEPcmInitInfo(&pVRDEVoice->pHostVoiceIn.Props, as); 701 return VINF_SUCCESS; 702 } 703 704 static DECLCALLBACK(int) drvAudioVRDEPlayIn(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEIN pHostVoiceIn) 705 { 706 uint32_t cbAvlblRingBuffer = 0; 707 uint32_t cSamplesRingBuffer = 0; 708 uint32_t cSamplesToRead = 0; 709 uint32_t cSamplesRead = 0; 710 uint32_t cbToRead; 711 char *pcSrc; 712 PDMHOSTSTEREOSAMPLE * psDst; 713 //@todo take care of the size of the buffer allocated to pHostVoiceIn 714 PVRDEVoice pVRDEVoice = (PVRDEVoice)pHostVoiceIn; 715 LogFlow(("DrvAudioVRDE: drvAudioVRDEPlayIn \n")); 716 717 /* use this from DrvHostCoreAudio.c */ 718 if (ASMAtomicReadU32(&pVRDEVoice->status) != CA_STATUS_INIT) 719 { 720 LogFlow(("AudioVRDE: VRDE voice not initialized \n")); 721 return 0; 722 } 723 724 /* how much space is used in the ring buffer in pRecordedVocieBuf with pAudioVRDE . Bytes-> samples*/ 725 cSamplesRingBuffer = IORingBufferUsed(pVRDEVoice->pRecordedVoiceBuf) / sizeof(PDMHOSTSTEREOSAMPLE); 726 727 /* How much space is available in the mix buffer. Use the smaller size of the too. */ 728 cSamplesRingBuffer = RT_MIN(cSamplesRingBuffer, (uint32_t)(pVRDEVoice->pHostVoiceIn.cSamples - 729 audio_pcm_hw_get_live_in (&pVRDEVoice->pHostVoiceIn))); 730 LogFlow(("AudioVRDE: [Input] Start reading buffer with %d samples (%d bytes)\n", cSamplesRingBuffer, 731 cSamplesRingBuffer * sizeof(PDMHOSTSTEREOSAMPLE))); 732 733 /* Iterate as long as data is available */ 734 while (cSamplesRead < cSamplesRingBuffer) 735 { 736 /* How much is left? Split request at the end of our samples buffer. */ 737 cSamplesToRead = RT_MIN(cSamplesRingBuffer - cSamplesRead, 738 (uint32_t)(pVRDEVoice->pHostVoiceIn.cSamples - pVRDEVoice->pHostVoiceIn.offWrite)); 739 cbToRead = cSamplesToRead * sizeof(PDMHOSTSTEREOSAMPLE); 740 LogFlow(("AudioVRDE: [Input] Try reading %RU32 samples (%RU32 bytes)\n", cSamplesToRead, cbToRead)); 741 742 /* Try to acquire the necessary block from the ring buffer. Remeber in fltRecrodCallback we 743 * we are filling this buffer with the audio data available from VRDP. Here we are reading it 744 */ 745 /*todo do I need to introduce a thread to fill the buffer in fltRecordcallback. So that 746 * filling is in separate thread and the reading of that buffer is in separate thread 747 */ 748 IORingBufferAquireReadBlock(pVRDEVoice->pRecordedVoiceBuf, cbToRead, &pcSrc, &cbToRead); 749 750 /* How much to we get? */ 751 cSamplesToRead = cbToRead / sizeof(PDMHOSTSTEREOSAMPLE); 752 LogFlow(("AuderVRDE: [Input] There are %d samples (%d bytes) available\n", cSamplesToRead, cbToRead)); 753 754 /* Break if nothing is used anymore. */ 755 if (cSamplesToRead == 0) 756 { 757 LogFlow(("AudioVRDE: Nothing to read \n")); 758 break; 759 } 760 761 /* Copy the data from our ring buffer to the mix buffer. */ 762 psDst = pVRDEVoice->pHostVoiceIn.pConversionBuf + pVRDEVoice->pHostVoiceIn.offWrite; 763 memcpy(psDst, pcSrc, cbToRead); 764 765 /* Release the read buffer, so it could be used for new data. */ 766 IORingBufferReleaseReadBlock(pVRDEVoice->pRecordedVoiceBuf, cbToRead); 767 768 pVRDEVoice->pHostVoiceIn.offWrite = (pVRDEVoice->pHostVoiceIn.offWrite + cSamplesToRead) 769 % pVRDEVoice->pHostVoiceIn.cSamples; 770 771 /* How much have we reads so far. */ 772 cSamplesRead += cSamplesToRead; 773 } 774 LogFlow(("AudioVRDE: [Input] Finished reading buffer with %d samples (%d bytes)\n", 775 cSamplesRead, cSamplesRead * sizeof(PDMHOSTSTEREOSAMPLE))); 776 777 return cSamplesRead; 778 } 779 780 static DECLCALLBACK(int) drvAudioVRDEPlayOut(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEOUT pHostVoiceOut) 781 { 782 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 783 PVRDEVoiceOut pVRDEVoiceOut = (PVRDEVoiceOut)pHostVoiceOut; 784 int live; 785 uint8_t *pu8Dst; 786 int cSamplesPlayed; 787 int cSamplesToSend = 0; 98 788 /* 99 789 * Just call the VRDP server with the data. 100 790 */ 101 VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(samplesPerSec, nChannels, bitsPerSample, !fUnsigned); 102 pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioSamples(pvSamples, cSamples, format); 103 } 104 105 DECLCALLBACK(void) iface_AudioVolumeOut (PPDMIAUDIOSNIFFERCONNECTOR pInterface, uint16_t left, uint16_t right) 106 { 107 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface); 108 109 /* 110 * Just call the VRDP server with the data. 791 live = audio_pcm_hw_get_live_out (pHostVoiceOut); 792 uint64_t now = audio_get_clock(); 793 uint64_t ticks = now - pVRDEVoiceOut->old_ticks; 794 uint64_t ticks_per_second = audio_get_ticks_per_sec(); 795 cSamplesPlayed = (int)((2 * ticks * pHostVoiceOut->Props.uFrequency + ticks_per_second) / ticks_per_second / 2); 796 if (cSamplesPlayed < 0) 797 cSamplesPlayed = live; 798 pHostVoiceOut->Props.cBits = 128; 799 VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pHostVoiceOut->Props.uFrequency, 800 pHostVoiceOut->Props.cChannels, 801 pHostVoiceOut->Props.cBits, /* bits per sample */ 802 !pHostVoiceOut->Props.fSigned); 803 LogFlow(("DrvAudioVRDE: send audio sample freq=%d, chan=%d, cBits = %d, fsigned = %d, cSamples=%d format=%d \n", 804 pHostVoiceOut->Props.uFrequency, pHostVoiceOut->Props.cChannels, 805 pHostVoiceOut->Props.cBits, pHostVoiceOut->Props.fSigned, 806 pHostVoiceOut->cSamples, format) 807 ); 808 pVRDEVoiceOut->old_ticks = now; 809 cSamplesToSend = RT_MIN(live, cSamplesPlayed); 810 if (pHostVoiceOut->offRead + cSamplesToSend > pHostVoiceOut->cSamples) 811 { 812 /* send the samples till the end of pHostStereoSampleBuf */ 813 pDrv->pConsoleVRDPServer->SendAudioSamples(&pHostVoiceOut->pHostSterioSampleBuf[pHostVoiceOut->offRead], 814 (pHostVoiceOut->cSamples - pHostVoiceOut->offRead), format); 815 /*pHostStereoSampleBuff already has the samples which exceeded its space. They have overwriten the old 816 * played sampled starting from offset 0. So based on the number of samples that we had to play, 817 * read the number of samples from offset 0 . 818 */ 819 pDrv->pConsoleVRDPServer->SendAudioSamples(&pHostVoiceOut->pHostSterioSampleBuf[0], 820 (cSamplesToSend - (pHostVoiceOut->cSamples - 821 pHostVoiceOut->offRead)), 822 format); 823 } 824 else 825 { 826 pDrv->pConsoleVRDPServer->SendAudioSamples(&pHostVoiceOut->pHostSterioSampleBuf[pHostVoiceOut->offRead], 827 cSamplesToSend, format); 828 } 829 pHostVoiceOut->offRead = (pHostVoiceOut->offRead + cSamplesToSend) % pHostVoiceOut->cSamples; 830 return cSamplesToSend; 831 } 832 833 static DECLCALLBACK(void) drvAudioVRDEFiniIn(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEIN hw) 834 { 835 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 836 LogFlow(("DrvAudioVRDE: drvAudioVRDEFiniIn \n")); 837 pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL); 838 } 839 840 static DECLCALLBACK(void) drvAudioVRDEFiniOut(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEOUT pHostVoiceOut) 841 { 842 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 843 LogFlow(("DrvAudioVRDE: audio input end\n")); 844 } 845 846 static DECLCALLBACK(int) drvAudioVRDEDisableEnableOut(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEOUT hw, int cmd) 847 { 848 LogFlow(("DrvAudioVRDE: drvAudioVRDEDisableEnableOut \n")); 849 return VINF_SUCCESS; 850 } 851 852 static DECLCALLBACK(int) drvAudioVRDEDisableEnableIn(PPDMIHOSTAUDIO pInterface, PPDMHOSTVOICEIN pHostVoiceIn, int cmd) 853 { 854 PDRVAUDIOVRDE pDrv = PDMIHOSTAUDIO_2_DRVAUDIOVRDE(pInterface); 855 856 /* Initialize VRDEVoice and return to VRDP server which returns this struct back to us 857 * in the form void * pvContext 111 858 */ 112 pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioVolume(left, right); 113 } 114 115 DECLCALLBACK(int) iface_AudioInputBegin (PPDMIAUDIOSNIFFERCONNECTOR pInterface, 116 void **ppvUserCtx, 117 void *pvContext, 118 uint32_t cSamples, 119 uint32_t iSampleHz, 120 uint32_t cChannels, 121 uint32_t cBits) 122 { 123 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface); 124 125 return pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioInputBegin(ppvUserCtx, 126 pvContext, 127 cSamples, 128 iSampleHz, 129 cChannels, 130 cBits); 131 } 132 133 DECLCALLBACK(void) iface_AudioInputEnd (PPDMIAUDIOSNIFFERCONNECTOR pInterface, 134 void *pvUserCtx) 135 { 136 PDRVAUDIOSNIFFER pDrv = PDMIAUDIOSNIFFERCONNECTOR_2_MAINAUDIOSNIFFER(pInterface); 137 138 pDrv->pAudioSniffer->getParent()->consoleVRDPServer()->SendAudioInputEnd(pvUserCtx); 139 } 140 859 PVRDEVoice pVRDEVoice = (PVRDEVoice)pHostVoiceIn; 860 LogFlow(("DrvAudioVRDE: drvAudioVRDEDisableEnableIn \n")); 861 /* initialize only if not already done */ 862 if (cmd == VOICE_ENABLE) 863 { 864 //@todo if (!pVRDEVoice->fIsInit) 865 // IORingBufferReset(pVRDEVoice->pRecordedVoiceBuf); 866 LogFlow(("DrvAudioVRDE: Intializing the VRDE params and buffer \n")); 867 pVRDEVoice->fIsInit = 1; 868 pVRDEVoice->pHostVoiceIn = *pHostVoiceIn; 869 pVRDEVoice->cBytesPerFrame =1 ; 870 pVRDEVoice->uFrequency = 0; 871 pVRDEVoice->rate = NULL; 872 pVRDEVoice->cbSamplesBufferAllocated = 0; 873 pVRDEVoice->pvRateBuffer = NULL; 874 pVRDEVoice->cbRateBufferAllocated = 0; 875 876 pVRDEVoice->pHostVoiceIn.cSamples = 2048; 877 /* Initialize the hardware info section with the audio settings */ 878 879 ASMAtomicWriteU32(&pVRDEVoice->status, CA_STATUS_IN_INIT); 880 881 /* Create the internal ring buffer. */ 882 IORingBufferCreate(&pVRDEVoice->pRecordedVoiceBuf, 883 pVRDEVoice->pHostVoiceIn.cSamples * sizeof(PDMHOSTSTEREOSAMPLE)); 884 885 if (!RT_VALID_PTR(pVRDEVoice->pRecordedVoiceBuf)) 886 { 887 LogRel(("AudioVRDE: [Input] Failed to create internal ring buffer\n")); 888 return VERR_NO_MEMORY; 889 } 890 891 ASMAtomicWriteU32(&pVRDEVoice->status, CA_STATUS_INIT); 892 return pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pVRDEVoice, pHostVoiceIn->cSamples, 893 pHostVoiceIn->Props.uFrequency, 894 pHostVoiceIn->Props.cChannels, pHostVoiceIn->Props.cBits); 895 } 896 else if (cmd == VOICE_DISABLE) 897 { 898 LogFlow(("DrvAudioVRDE: Cmd to disable VRDE \n")); 899 pVRDEVoice->fIsInit = 0; 900 ASMAtomicWriteU32(&pVRDEVoice->status, CA_STATUS_IN_UNINIT); 901 IORingBufferDestroy(pVRDEVoice->pRecordedVoiceBuf); 902 pVRDEVoice->pRecordedVoiceBuf = NULL; 903 ASMAtomicWriteU32(&pVRDEVoice->status, CA_STATUS_UNINIT); 904 pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL); 905 } 906 return VINF_SUCCESS; 907 } 908 909 static DECLCALLBACK(void) drvAudioVRDEGetConf(PPDMIBASE pInterface, PPDMAUDIOCONF pAudioConf) 910 { 911 LogFlow(("drvAudioVRDE: drvAudioVRDEGetConf \n")); 912 /* @todo check if szHostVoiceOut = sizeof VRDEVoice works. VRDEVoice doesn't contain HOSTVOICEOUT. */ 913 pAudioConf->szHostVoiceOut = sizeof(VRDEVoice); 914 pAudioConf->szHostVoiceIn = sizeof(VRDEVoice); 915 pAudioConf->MaxHostVoicesOut = 1; 916 pAudioConf->MaxHostVoicesIn = 1; 917 } 141 918 142 919 /** 143 920 * @interface_method_impl{PDMIBASE,pfnQueryInterface} 144 921 */ 145 DECLCALLBACK(void *) AudioSniffer::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)922 static DECLCALLBACK(void *) drvAudioVRDEQueryInterface(PPDMIBASE pInterface, const char *pszIID) 146 923 { 147 924 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface); 148 PDRVAUDIO SNIFFER pDrv = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER);925 PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE); 149 926 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase); 150 PDMIBASE_RETURN_INTERFACE(pszIID, PDMI AUDIOSNIFFERCONNECTOR, &pDrv->Connector);927 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudioR3); 151 928 return NULL; 152 929 } 153 930 154 931 932 static DECLCALLBACK(void) drvAudioVRDEDestruct(PPDMDRVINS pDrvIns) 933 { 934 } 935 155 936 /** 156 * Destruct a Audio Sniffer driver instance. 157 * 158 * @returns VBox status. 159 * @param pDrvIns The driver instance data. 160 */ 161 DECLCALLBACK(void) AudioSniffer::drvDestruct(PPDMDRVINS pDrvIns) 162 { 163 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 164 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER); 165 LogFlow(("AudioSniffer::drvDestruct: iInstance=%d\n", pDrvIns->iInstance)); 166 167 if (pThis->pAudioSniffer) 168 { 169 pThis->pAudioSniffer->mpDrv = NULL; 170 } 171 } 172 173 174 /** 175 * Construct a AudioSniffer driver instance. 937 * Construct a DirectSound Audio driver instance. 176 938 * 177 939 * @copydoc FNPDMDRVCONSTRUCT 178 940 */ 179 DECLCALLBACK(int) AudioSniffer::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags) 180 { 181 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); 182 PDRVAUDIOSNIFFER pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOSNIFFER); 183 184 LogFlow(("AudioSniffer::drvConstruct: iInstance=%d\n", pDrvIns->iInstance)); 185 186 /* 187 * Validate configuration. 941 DECLCALLBACK(int) AudioVRDE::drvAudioVRDEConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags) 942 { 943 PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE); 944 LogRel(("drvAudioVRDEConstruct\n")); 945 946 /* we save the address of AudioVRDE in Object node in CFGM tree and address of VRDP server in 947 * ObjectVRDPServer node. So presence of both is necessary. 188 948 */ 189 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))190 949 //if (!CFGMR3AreValuesValid(pCfg, "Object\0") || !CFGMR3AreValuesValid(pCfg, "ObjectVRDPServer\0")) 950 // return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES; 191 951 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER, 192 952 ("Configuration error: Not possible to attach anything to this driver!\n"), … … 194 954 195 955 /* 196 * I Base.956 * Init the static parts. 197 957 */ 198 pDrvIns->IBase.pfnQueryInterface = AudioSniffer::drvQueryInterface; 199 200 /* Audio Sniffer connector. */ 201 pThis->Connector.pfnAudioSamplesOut = iface_AudioSamplesOut; 202 pThis->Connector.pfnAudioVolumeOut = iface_AudioVolumeOut; 203 pThis->Connector.pfnAudioInputBegin = iface_AudioInputBegin; 204 pThis->Connector.pfnAudioInputEnd = iface_AudioInputEnd; 205 958 pThis->pDrvIns = pDrvIns; 959 gpDrvIns = pDrvIns; 960 /* IBase */ 961 pDrvIns->IBase.pfnQueryInterface = drvAudioVRDEQueryInterface; 962 pThis->IHostAudioR3.pfnInitIn = drvAudioVRDEInitIn; 963 pThis->IHostAudioR3.pfnInitOut = drvAudioVRDEInitOut; 964 pThis->IHostAudioR3.pfnDisableEnableOut = drvAudioVRDEDisableEnableOut; 965 pThis->IHostAudioR3.pfnDisableEnableIn = drvAudioVRDEDisableEnableIn; 966 pThis->IHostAudioR3.pfnFiniIn = drvAudioVRDEFiniIn; 967 pThis->IHostAudioR3.pfnFiniOut = drvAudioVRDEFiniOut; 968 pThis->IHostAudioR3.pfnPlayIn = drvAudioVRDEPlayIn; 969 pThis->IHostAudioR3.pfnPlayOut = drvAudioVRDEPlayOut; 970 pThis->IHostAudioR3.pfnGetConf = drvAudioVRDEGetConf; 971 pThis->IHostAudioR3.pfnInit = drvAudioVRDEInit; 972 973 /* Get VRDPServer pointer */ 974 void *pv; 975 int rc = CFGMR3QueryPtr(pCfg, "ObjectVRDPServer", &pv); 976 if (RT_FAILURE(rc)) 977 { 978 AssertMsgFailed(("DrvAudioVRDE Confguration error: No/bad \"Object\" value! rc=%Rrc\n", rc)); 979 return rc; 980 } 981 /* CFGM tree saves the pointer to ConsoleVRDPServer in the Object node of AudioVRDE */ 982 pThis->pConsoleVRDPServer = (ConsoleVRDPServer *)pv; 983 pv = NULL; 984 985 rc = CFGMR3QueryPtr(pCfg, "Object", &pv); 986 if (RT_FAILURE(rc)) 987 { 988 AssertMsgFailed(("DrvAudioVRDE Confguration error: No/bad \"Object\" value! rc=%Rrc\n", rc)); 989 return rc; 990 } 991 pThis->pAudioVRDE = (AudioVRDE *)pv; 992 pThis->pAudioVRDE->mpDrv = pThis; 206 993 /* 207 * Get the Audio Sniffer Port interface of the above driver/device. 994 * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls . 995 * Described in CFGM tree. 208 996 */ 209 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIO SNIFFERPORT);997 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR); 210 998 if (!pThis->pUpPort) 211 999 { … … 214 1002 } 215 1003 216 /*217 * Get the Console object pointer and update the mpDrv member.218 */219 void *pv;220 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);221 if (RT_FAILURE(rc))222 {223 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));224 return rc;225 }226 pThis->pAudioSniffer = (AudioSniffer *)pv; /** @todo Check this cast! */227 pThis->pAudioSniffer->mpDrv = pThis;228 229 1004 return VINF_SUCCESS; 230 1005 } … … 232 1007 233 1008 /** 234 * Audio Sniffer driver registration record. 235 */ 236 const PDMDRVREG AudioSniffer::DrvReg = 237 { 238 /* u32Version */ 239 PDM_DRVREG_VERSION, 240 /* szName */ 241 "MainAudioSniffer", 1009 * Char driver registration record. 1010 */ 1011 const PDMDRVREG g_DrvAudioVRDE = 1012 { 1013 PDM_DRVREG_VERSION, 1014 /* szName */ 1015 "AudioVRDE", 242 1016 /* szRCMod */ 243 1017 "", … … 245 1019 "", 246 1020 /* pszDescription */ 247 " Main Audio Sniffer driver (Main as in the API).",1021 "Audio VRDE", 248 1022 /* fFlags */ 249 1023 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT, … … 253 1027 ~0U, 254 1028 /* cbInstance */ 255 sizeof(DRVAUDIO SNIFFER),1029 sizeof(DRVAUDIOVRDE), 256 1030 /* pfnConstruct */ 257 Audio Sniffer::drvConstruct,1031 AudioVRDE::drvAudioVRDEConstruct, 258 1032 /* pfnDestruct */ 259 AudioSniffer::drvDestruct,1033 drvAudioVRDEDestruct, 260 1034 /* pfnRelocate */ 261 1035 NULL, … … 281 1055 PDM_DRVREG_VERSION 282 1056 }; 283 /* vi: set tabstop=4 shiftwidth=4 expandtab: */ 1057 1058 1059 -
trunk/src/VBox/Main/src-client/VBoxDriversRegister.cpp
r48406 r50686 24 24 #include "DisplayImpl.h" 25 25 #include "VMMDev.h" 26 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 27 #include "DrvAudioVRDE.h" 28 #else 26 29 #include "AudioSnifferInterface.h" 30 #endif 27 31 #include "Nvram.h" 28 32 #include "UsbWebcamInterface.h" … … 67 71 if (RT_FAILURE(rc)) 68 72 return rc; 69 73 #ifdef VBOX_WITH_PDM_AUDIO_DRIVER 74 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvAudioVRDE); 75 #else 70 76 rc = pCallbacks->pfnRegister(pCallbacks, &AudioSniffer::DrvReg); 77 #endif 71 78 if (RT_FAILURE(rc)) 72 79 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.