VirtualBox

Changeset 88561 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Apr 16, 2021 11:39:41 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143856
Message:

Audio: Moved the HostAudioNotResponding runtime error reporting during driver attching and initialization into DrvAudio instead of having it duplicated in every audio device. Also simplified the NULL driver replacing by skipping the CFGM + PDM work and just use the NULL driver vtable directly. bugref:9890

Location:
trunk/src/VBox/Devices
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevHda.cpp

    r88503 r88561  
    44724472}
    44734473
     4474
    44744475/**
    44754476 * @interface_method_impl{PDMDEVREG,pfnAttach}
     
    44964497    return VINF_SUCCESS;
    44974498}
     4499
    44984500
    44994501/**
     
    45274529}
    45284530
     4531
    45294532/**
    45304533 * Powers off the device.
     
    45584561}
    45594562
     4563
     4564# ifdef VBOX_WITH_AUDIO_HDA_ONETIME_INIT
    45604565/**
    45614566 * Replaces a driver with a the NullAudio drivers.
     
    45754580    return rc;
    45764581}
     4582# endif
    45774583
    45784584
     
    49054911            break;
    49064912        }
    4907         if (rc == VERR_AUDIO_BACKEND_INIT_FAILED)
    4908         {
    4909             hdaR3ReconfigLunWithNullAudio(pDevIns, pThis, pThisCC, iLun); /* Pretend attaching to the NULL audio backend will never fail. */
    4910             PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding",
    4911                                        N_("Host audio backend initialization has failed. Selecting the NULL audio backend with the consequence that no sound is audible"));
    4912         }
    4913         else
    4914             AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
     4913        AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
    49154914    }
    49164915
  • trunk/src/VBox/Devices/Audio/DevIchAc97.cpp

    r88357 r88561  
    41134113}
    41144114
     4115
     4116# ifdef VBOX_WITH_AUDIO_AC97_ONETIME_INIT
    41154117/**
    41164118 * Replaces a driver with a the NullAudio drivers.
     
    41294131    return rc;
    41304132}
     4133# endif
     4134
    41314135
    41324136/**
     
    43114315            break;
    43124316        }
    4313         if (rc == VERR_AUDIO_BACKEND_INIT_FAILED)
    4314         {
    4315             ichac97R3ReconfigLunWithNullAudio(pDevIns, pThisCC, iLun); /* Pretend attaching to the NULL audio backend will never fail. */
    4316             PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding",
    4317                                        N_("Host audio backend initialization has failed. "
    4318                                           "Selecting the NULL audio backend with the consequence that no sound is audible"));
    4319         }
    4320         else
    4321             AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
     4317        AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
    43224318    }
    43234319
  • trunk/src/VBox/Devices/Audio/DevSB16.cpp

    r88356 r88561  
    22532253}
    22542254
     2255
     2256#ifdef VBOX_WITH_AUDIO_SB16_ONETIME_INIT
    22552257/**
    22562258 * Replaces a driver with a the NullAudio drivers.
     
    22682270    return rc;
    22692271}
     2272#endif
     2273
    22702274
    22712275/**
     
    24942498            break;
    24952499        }
    2496         if (rc == VERR_AUDIO_BACKEND_INIT_FAILED)
    2497         {
    2498             sb16ReconfigLunWithNullAudio(pThis, iLun); /* Pretend attaching to the NULL audio backend will never fail. */
    2499             PDMDevHlpVMSetRuntimeError(pDevIns, 0 /*fFlags*/, "HostAudioNotResponding",
    2500                                        N_("Host audio backend initialization has failed. "
    2501                                           "Selecting the NULL audio backend with the consequence that no sound is audible"));
    2502         }
    2503         else
    2504             AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
     2500        AssertLogRelMsgReturn(RT_SUCCESS(rc),  ("LUN#%u: rc=%Rrc\n", iLun, rc), rc);
    25052501    }
    25062502
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r88559 r88561  
    22512251/**
    22522252 * Initializes the host backend and queries its initial configuration.
    2253  * If the host backend fails, VERR_AUDIO_BACKEND_INIT_FAILED will be returned.
    2254  *
    2255  * Note: As this routine is called when attaching to the device LUN in the
    2256  *       device emulation, we either check for success or VERR_AUDIO_BACKEND_INIT_FAILED.
    2257  *       Everything else is considered as fatal and must be handled separately in
    2258  *       the device emulation!
    22592253 *
    22602254 * @returns VBox status code.
     
    30303024            /* Retrieve host driver name for easier identification. */
    30313025            AssertPtr(pThis->pHostDrvAudio);
    3032             PPDMDRVINS pDrvAudioInst = PDMIBASE_2_PDMDRV(pThis->pDrvIns->pDownBase);
    30333026            RTStrPrintf(pStreamEx->Core.szName, RT_ELEMENTS(pStreamEx->Core.szName), "[%s] %s",
    3034                         pDrvAudioInst && pDrvAudioInst->pReg && pDrvAudioInst->pReg->szName[0]
    3035                         ? pDrvAudioInst->pReg->szName : "none",
    3036                         pCfgHost->szName[0] != '\0' ? pCfgHost->szName : "<Untitled>");
     3027                        pThis->BackendCfg.szName, pCfgHost->szName[0] != '\0' ? pCfgHost->szName : "<Untitled>");
    30373028
    30383029            pStreamEx->Core.enmDir    = pCfgHost->enmDir;
     
    37563747 *
    37573748 * @returns VBox status code.
     3749 * @param   pDrvIns     The driver instance.
    37583750 * @param   pThis       Pointer to driver instance.
    37593751 * @param   fFlags      Attach flags; see PDMDrvHlpAttach().
    37603752 */
    3761 static int drvAudioDoAttachInternal(PDRVAUDIO pThis, uint32_t fFlags)
     3753static int drvAudioDoAttachInternal(PPDMDRVINS pDrvIns, PDRVAUDIO pThis, uint32_t fFlags)
    37623754{
    37633755    Assert(pThis->pHostDrvAudio == NULL); /* No nested attaching. */
     
    37673759     */
    37683760    PPDMIBASE pDownBase;
    3769     int rc = PDMDrvHlpAttach(pThis->pDrvIns, fFlags, &pDownBase);
     3761    int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
    37703762    if (RT_SUCCESS(rc))
    37713763    {
     
    37873779        }
    37883780    }
    3789 
    3790     /*
    3791      * Do some status code simplification for beningn host driver init failures.
    3792      * The device above us will then replace it will the Null driver.
    3793      */
    3794     /** @todo Do the Null driver replacment here, then we don't have to duplicate
    3795      *        it in 3+ devices! */
    3796     if (   rc == VERR_MODULE_NOT_FOUND
    3797         || rc == VERR_SYMBOL_NOT_FOUND
    3798         || rc == VERR_FILE_NOT_FOUND
    3799         || rc == VERR_PATH_NOT_FOUND)
    3800     {
    3801         LogRel(("Audio: %Rrc -> VERR_AUDIO_BACKEND_INIT_FAILED\n", rc));
    3802         rc = VERR_AUDIO_BACKEND_INIT_FAILED;
     3781    /*
     3782     * If the host driver below us failed to construct for some beningn reason,
     3783     * we'll report it as a runtime error and replace it with the Null driver.
     3784     *
     3785     * Note! We do NOT change anything in PDM (or CFGM), so pDrvIns->pDownBase
     3786     *       will remain NULL in this case.
     3787     */
     3788    else if (   rc == VERR_AUDIO_BACKEND_INIT_FAILED
     3789             || rc == VERR_MODULE_NOT_FOUND
     3790             || rc == VERR_SYMBOL_NOT_FOUND
     3791             || rc == VERR_FILE_NOT_FOUND
     3792             || rc == VERR_PATH_NOT_FOUND)
     3793    {
     3794        /* Complain: */
     3795        LogRel(("DrvAudio: Host audio driver '%s' init failed with %Rrc. Switching to the NULL driver for now.\n",
     3796                pThis->szName, rc));
     3797        PDMDrvHlpVMSetRuntimeError(pDrvIns, 0 /*fFlags*/, "HostAudioNotResponding",
     3798                                   N_("Host audio backend (%s) initialization has failed. Selecting the NULL audio backend with the consequence that no sound is audible"),
     3799                                   pThis->szName);
     3800
     3801        /* Replace with null audio: */
     3802        pThis->pHostDrvAudio = (PPDMIHOSTAUDIO)&g_DrvHostAudioNull;
     3803        RTStrCopy(pThis->szName, sizeof(pThis->szName), "NULL");
     3804        rc = drvAudioHostInit(pThis);
     3805        AssertRC(rc);
    38033806    }
    38043807
     
    38233826    AssertRCReturn(rc, rc);
    38243827
    3825     rc = drvAudioDoAttachInternal(pThis, fFlags);
     3828    rc = drvAudioDoAttachInternal(pDrvIns, pThis, fFlags);
    38263829
    38273830    RTCritSectLeave(&pThis->CritSect);
     
    41784181     * Attach the host driver, if present.
    41794182     */
    4180     rc = drvAudioDoAttachInternal(pThis, fFlags);
     4183    rc = drvAudioDoAttachInternal(pDrvIns, pThis, fFlags);
    41814184    if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    41824185        rc = VINF_SUCCESS;
  • trunk/src/VBox/Devices/Audio/DrvHostAudioNull.cpp

    r88534 r88561  
    2222*   Header Files                                                                                                                 *
    2323*********************************************************************************************************************************/
    24 #include <iprt/mem.h>
    2524#include <iprt/uuid.h> /* For PDMIBASE_2_PDMDRV. */
    2625
     
    4443/** Pointer to a null audio stream.   */
    4544typedef NULLAUDIOSTREAM *PNULLAUDIOSTREAM;
    46 
    47 /**
    48  * NULL audio driver instance data.
    49  * @implements PDMIAUDIOCONNECTOR
    50  */
    51 typedef struct DRVHOSTNULLAUDIO
    52 {
    53     /** Pointer to the driver instance structure. */
    54     PPDMDRVINS          pDrvIns;
    55     /** Pointer to host audio interface. */
    56     PDMIHOSTAUDIO       IHostAudio;
    57 } DRVHOSTNULLAUDIO;
    58 /** Pointer to the instance data for a null audio host driver. */
    59 typedef DRVHOSTNULLAUDIO *PDRVHOSTNULLAUDIO;
    6045
    6146
     
    237222
    238223/**
     224 * This is used directly by DrvAudio when a backend fails to initialize in a
     225 * non-fatal manner.
     226 */
     227DECL_HIDDEN_CONST(PDMIHOSTAUDIO) const g_DrvHostAudioNull =
     228{
     229    /* .pfnGetConfig          =*/ drvHostNullAudioHA_GetConfig,
     230    /* .pfnGetDevices         =*/ NULL,
     231    /* .pfnGetStatus          =*/ drvHostNullAudioHA_GetStatus,
     232    /* .pfnStreamCreate       =*/ drvHostNullAudioHA_StreamCreate,
     233    /* .pfnStreamDestroy      =*/ drvHostNullAudioHA_StreamDestroy,
     234    /* .pfnStreamControl      =*/ drvHostNullAudioHA_StreamControl,
     235    /* .pfnStreamGetReadable  =*/ drvHostNullAudioHA_StreamGetReadable,
     236    /* .pfnStreamGetWritable  =*/ drvHostNullAudioHA_StreamGetWritable,
     237    /* .pfnStreamGetPending   =*/ drvHostNullAudioHA_StreamGetPending,
     238    /* .pfnStreamGetStatus    =*/ drvHostNullAudioHA_StreamGetStatus,
     239    /* .pfnStreamPlay         =*/ drvHostNullAudioHA_StreamPlay,
     240    /* .pfnStreamCapture      =*/ drvHostNullAudioHA_StreamCapture,
     241};
     242
     243
     244/**
    239245 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
    240246 */
     
    242248{
    243249    PPDMDRVINS        pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
    244     PDRVHOSTNULLAUDIO pThis   = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
     250    PPDMIHOSTAUDIO    pThis   = PDMINS_2_DATA(pDrvIns, PPDMIHOSTAUDIO);
    245251
    246252    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
    247     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
     253    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, pThis);
    248254    return NULL;
    249255}
     
    258264{
    259265    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
    260     PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
     266    PPDMIHOSTAUDIO pThis = PDMINS_2_DATA(pDrvIns, PPDMIHOSTAUDIO);
    261267    RT_NOREF(pCfg, fFlags);
    262268    LogRel(("Audio: Initializing NULL driver\n"));
     
    265271     * Init the static parts.
    266272     */
    267     pThis->pDrvIns                   = pDrvIns;
    268273    /* IBase */
    269274    pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
    270275    /* IHostAudio */
    271     pThis->IHostAudio.pfnGetConfig          = drvHostNullAudioHA_GetConfig;
    272     pThis->IHostAudio.pfnGetDevices         = NULL;
    273     pThis->IHostAudio.pfnGetStatus          = drvHostNullAudioHA_GetStatus;
    274     pThis->IHostAudio.pfnStreamCreate       = drvHostNullAudioHA_StreamCreate;
    275     pThis->IHostAudio.pfnStreamDestroy      = drvHostNullAudioHA_StreamDestroy;
    276     pThis->IHostAudio.pfnStreamControl      = drvHostNullAudioHA_StreamControl;
    277     pThis->IHostAudio.pfnStreamGetReadable  = drvHostNullAudioHA_StreamGetReadable;
    278     pThis->IHostAudio.pfnStreamGetWritable  = drvHostNullAudioHA_StreamGetWritable;
    279     pThis->IHostAudio.pfnStreamGetPending   = drvHostNullAudioHA_StreamGetPending;
    280     pThis->IHostAudio.pfnStreamGetStatus    = drvHostNullAudioHA_StreamGetStatus;
    281     pThis->IHostAudio.pfnStreamPlay         = drvHostNullAudioHA_StreamPlay;
    282     pThis->IHostAudio.pfnStreamCapture      = drvHostNullAudioHA_StreamCapture;
     276    *pThis = g_DrvHostAudioNull;
    283277
    284278    return VINF_SUCCESS;
     
    308302    ~0U,
    309303    /* cbInstance */
    310     sizeof(DRVHOSTNULLAUDIO),
     304    sizeof(PDMIHOSTAUDIO),
    311305    /* pfnConstruct */
    312306    drvHostNullAudioConstruct,
  • trunk/src/VBox/Devices/build/VBoxDD.h

    r88153 r88561  
    138138#endif
    139139extern const PDMDRVREG g_DrvHostNullAudio;
     140extern DECL_HIDDEN_DATA(struct PDMIHOSTAUDIO) const g_DrvHostAudioNull;
    140141#if defined(RT_OS_WINDOWS)
    141142extern const PDMDRVREG g_DrvHostDSound;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette