VirtualBox

Changeset 88819 in vbox for trunk/include/VBox


Ignore:
Timestamp:
May 3, 2021 10:26:28 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
144153
Message:

Audio: Added geberuc asynchronous init to DrvAudio for use in WAS (and maybe others). bugref:9890

  • Added optional asynchronous init via a worker thread pool in DrvAudio (pfnStreamInitAsync).
  • Added interface for the backend to use the thread pool from the backend (pfnDoOnWorkerThread).
  • s/PDMIAUDIONOTIFYFROMHOST/PDMIHOSTAUDIOPORT/g
  • New BACKEND_READY state flag (a bit confusing wrt to INITIALIZED, but whatever).
  • Don't RESUME streams which aren't actually paused (on VM resume).
  • Restore the backend state correctly when the per-direction enable flag is changed in DrvAudio. Would enable the streams regardless of actual state.
  • Move more PDMAUDIOSTREAM members from the public structure and into the DRVAUDIOSTREAM.
  • ++
Location:
trunk/include/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/err.h

    r88638 r88819  
    29302930/** Generic audio device enumeration error. */
    29312931#define VERR_AUDIO_ENUMERATION_FAILED               (-6607)
     2932/** Asynchronous stream initialization still on-going. */
     2933#define VERR_AUDIO_STREAM_INIT_IN_PROGRESS          (-6608)
     2934/** Special PDMIHOSTAUDIO::pfnStreamCreate return value for triggering
     2935 * calling of PDMIHOSTAUDIO::pfnStreamInitAsync on a worker thread. */
     2936#define VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED         (6609)
    29322937/** @} */
    29332938
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r88760 r88819  
    439439    /** The size of the backend specific stream data (in bytes). */
    440440    uint32_t        cbStream;
    441     /** Flags, MBZ. */
     441    /** PDMAUDIOBACKEND_F_XXX. */
    442442    uint32_t        fFlags;
    443443    /** Number of concurrent output (playback) streams supported on the host.
     
    450450/** Pointer to a static host audio audio configuration. */
    451451typedef PDMAUDIOBACKENDCFG *PPDMAUDIOBACKENDCFG;
     452
     453/** @name PDMAUDIOBACKEND_F_XXX - PDMAUDIOBACKENDCFG::fFlags
     454 * @{ */
     455/** PDMIHOSTAUDIO::pfnStreamConfigHint should preferably be called on a
     456 *  worker thread rather than EMT as it may take a good while. */
     457#define PDMAUDIOBACKEND_F_ASYNC_HINT    RT_BIT_32(0)
     458/** @} */
     459
    452460
    453461/**
     
    904912/** No flags being set. */
    905913#define PDMAUDIOSTREAM_STS_NONE                 UINT32_C(0)
    906 /** Set if the backend for the stream has been initialized.
     914/** Set if the backend for the stream has been created.
    907915 *
    908916 * PDMIAUDIOCONNECTOR: This is generally always set after stream creation, but
    909917 * can be cleared if the re-initialization of the stream fails later on.
     918 * Asynchronous init may still be incomplete, see
    910919 *
    911920 * PDMIHOSTAUDIO: This may not be set immediately if the backend is doing some
    912  * of the stream creation asynchronously.  The DrvAudio code will not report
    913  * this to the devices, but keep on prebuffering till it is set. */
     921 * of the stream creation asynchronously via PDMIHOSTAUDIO::pfnStreamInitAsync.
     922 * The DrvAudio code will not report this to the devices, but keep on
     923 * prebuffering till pfnStreamInitAsync is done and this bit is set. */
    914924#define PDMAUDIOSTREAM_STS_INITIALIZED          RT_BIT_32(0)
    915925/** Set if the stream is enabled, clear if disabled. */
    916926#define PDMAUDIOSTREAM_STS_ENABLED              RT_BIT_32(1)
    917927/** Set if the stream is paused.
    918  * Requires enabled status to be set when used. */
     928 * Requires the ENABLED status to be set when used. */
    919929#define PDMAUDIOSTREAM_STS_PAUSED               RT_BIT_32(2)
    920930/** Output only: Set when the stream is draining.
    921  * Requires the enabled status to be set when used.
     931 * Requires the ENABLED status to be set when used.
    922932 * @todo See todo in drvAudioStreamPlay() regarding the suitability of this
    923933 *       for PDMIHOSTAUDIO. */
     
    929939 * stream can resume operation where it left off.)  */
    930940#define PDMAUDIOSTREAM_STS_NEED_REINIT          RT_BIT_32(8)
     941/** PDMIAUDIOCONNECTOR: The backend is ready (PDMIHOSTAUDIO::pfnStreamInitAsync  done).
     942 * Requires the INITIALIZED status to be set.  */
     943#define PDMAUDIOSTREAM_STS_BACKEND_READY        RT_BIT_32(9)
    931944/** Validation mask for PDMIAUDIOCONNECTOR. */
    932 #define PDMAUDIOSTREAM_STS_VALID_MASK           UINT32_C(0x0000010f)
     945#define PDMAUDIOSTREAM_STS_VALID_MASK           UINT32_C(0x0000030f)
    933946/** Asserts the validity of the given stream status mask for PDMIAUDIOCONNECTOR. */
    934947#define PDMAUDIOSTREAM_STS_ASSERT_VALID(a_fStreamStatus) do { \
     
    936949        Assert(!((a_fStreamStatus) & PDMAUDIOSTREAM_STS_PAUSED)          || ((a_fStreamStatus) & PDMAUDIOSTREAM_STS_ENABLED)); \
    937950        Assert(!((a_fStreamStatus) & PDMAUDIOSTREAM_STS_PENDING_DISABLE) || ((a_fStreamStatus) & PDMAUDIOSTREAM_STS_ENABLED)); \
     951        Assert(!((a_fStreamStatus) & PDMAUDIOSTREAM_STS_BACKEND_READY)   || ((a_fStreamStatus) & PDMAUDIOSTREAM_STS_INITIALIZED)); \
    938952    } while (0)
    939953
    940954/** PDMIHOSTAUDIO: Backend is preparing a device switch, DrvAudio should
    941955 * pre-buffer to make that smoother and quicker.
    942  * Call PDMIAUDIONOTIFYFROMHOST::pfnStreamNotifyDeviceChanged when clearing. */
     956 * Call PDMIHOSTAUDIOPORT::pfnStreamNotifyDeviceChanged when clearing. */
    943957#define PDMAUDIOSTREAM_STS_PREPARING_SWITCH     RT_BIT_32(16)
    944958/** Validation mask for PDMIHOSTAUDIO. */
     
    9961010    /** Magic value (PDMAUDIOSTREAM_MAGIC). */
    9971011    uint32_t                uMagic;
    998     /** Number of references to this stream.
    999      *  Only can be destroyed when the reference count reaches 0. */
    1000     uint32_t volatile       cRefs;
    1001     /** Stream status - PDMAUDIOSTREAM_STS_XXX. */
    1002     uint32_t                fStatus;
    10031012    /** Audio direction of this stream. */
    10041013    PDMAUDIODIR             enmDir;
     
    10211030
    10221031/** Magic value for PDMAUDIOSTREAM. */
    1023 #define PDMAUDIOSTREAM_MAGIC    PDM_VERSION_MAKE(0xa0d3, 3, 0)
     1032#define PDMAUDIOSTREAM_MAGIC    PDM_VERSION_MAKE(0xa0d3, 4, 0)
    10241033
    10251034
     
    13031312
    13041313    /**
     1314     * Callback for genric on-worker-thread requests initiated by the backend itself.
     1315     *
     1316     * This is the counterpart to PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread that will
     1317     * be invoked on a worker thread when the backend requests it - optional.
     1318     *
     1319     * This does not return a value, so the backend must keep track of
     1320     * failure/success on its own.
     1321     *
     1322     * This method is optional.  A non-NULL will, together with pfnStreamInitAsync
     1323     * and PDMAUDIOBACKEND_F_ASYNC_HINT, force DrvAudio to create the thread pool.
     1324     *
     1325     * @param   pInterface  Pointer to this interface.
     1326     * @param   pStream     Optionally a backend stream if specified in the
     1327     *                      PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
     1328     * @param   uUser       User specific value as specified in the
     1329     *                      PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
     1330     * @param   pvUser      User specific pointer as specified in the
     1331     *                      PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
     1332     */
     1333    DECLR3CALLBACKMEMBER(void, pfnDoOnWorkerThread,(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
     1334                                                    uintptr_t uUser, void *pvUser));
     1335
     1336    /**
    13051337     * Gives the audio backend a hint about a typical configuration (optional).
    13061338     *
     
    13111343     * configuring host audio.
    13121344     *
     1345     * The backend can return PDMAUDIOBACKEND_F_ASYNC_HINT in
     1346     * PDMIHOSTAUDIO::pfnGetConfig to avoid having EMT making this call and thereby
     1347     * speeding up VM construction.
     1348     *
    13131349     * @param   pInterface      Pointer to this interface.
    13141350     * @param   pCfg            The typical configuration.  (Feel free to change it
     
    13251361     *
    13261362     * @returns VBox status code.
     1363     * @retval  VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED if
     1364     *          PDMIHOSTAUDIO::pfnStreamInitAsync should be called.
    13271365     * @param   pInterface          Pointer to the interface structure containing the called function pointer.
    13281366     * @param   pStream             Pointer to audio stream.
     
    13361374
    13371375    /**
     1376     * Asynchronous stream initialization step, optional.
     1377     *
     1378     * This is called on a worker thread iff the PDMIHOSTAUDIO::pfnStreamCreate
     1379     * method returns VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED.
     1380     *
     1381     * @returns VBox status code.
     1382     * @param   pInterface          Pointer to this interface.
     1383     * @param   pStream             Pointer to audio stream to continue
     1384     *                              initialization of.
     1385     * @param   fDestroyed          Set to @c true if the stream has been destroyed
     1386     *                              before the worker thread got to making this
     1387     *                              call.  The backend should just ready the stream
     1388     *                              for destruction in that case.
     1389     */
     1390    DECLR3CALLBACKMEMBER(int, pfnStreamInitAsync, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, bool fDestroyed));
     1391
     1392    /**
    13381393     * Destroys an audio stream.
    13391394     *
     
    13451400
    13461401    /**
    1347      * Called from PDMIAUDIONOTIFYFROMHOST::pfnNotifyDeviceChanged so the backend
    1348      * can start the device change for a stream.
     1402     * Called from PDMIHOSTAUDIOPORT::pfnNotifyDeviceChanged so the backend can start
     1403     * the device change for a stream.
    13491404     *
    13501405     * This is mainly to avoid the need for a list of streams in the backend.
     
    13531408     * @param   pStream             Pointer to audio stream.
    13541409     * @param   pvUser              Backend specific parameter from the call to
    1355      *                              PDMIAUDIONOTIFYFROMHOST::pfnNotifyDeviceChanged.
     1410     *                              PDMIHOSTAUDIOPORT::pfnNotifyDeviceChanged.
    13561411     */
    13571412    DECLR3CALLBACKMEMBER(void, pfnStreamNotifyDeviceChanged,(PPDMIHOSTAUDIO pInterface,
     
    14491504
    14501505/** PDMIHOSTAUDIO interface ID. */
    1451 #define PDMIHOSTAUDIO_IID                           "faab0061-c3c8-481e-b875-abbe81baf94a"
     1506#define PDMIHOSTAUDIO_IID                           "b320d6ab-6cbc-46a8-8011-57e7f7eb0e25"
    14521507
    14531508
    14541509/** Pointer to a audio notify from host interface. */
    1455 typedef struct PDMIAUDIONOTIFYFROMHOST *PPDMIAUDIONOTIFYFROMHOST;
    1456 
    1457 /**
    1458  * PDM audio notification interface, for use by host audio.
    1459  *
    1460  * @todo better name?
    1461  */
    1462 typedef struct PDMIAUDIONOTIFYFROMHOST
    1463 {
     1510typedef struct PDMIHOSTAUDIOPORT *PPDMIHOSTAUDIOPORT;
     1511
     1512/**
     1513 * PDM host audio port interface, upwards sibling of PDMIHOSTAUDIO.
     1514 */
     1515typedef struct PDMIHOSTAUDIOPORT
     1516{
     1517    /**
     1518     * Ask DrvAudio to call PDMIHOSTAUDIO::pfnDoOnWorkerThread on a worker thread.
     1519     *
     1520     * Generic method for doing asynchronous work using the DrvAudio thread pool.
     1521     *
     1522     * This function will not wait for PDMIHOSTAUDIO::pfnDoOnWorkerThread to
     1523     * complete, but returns immediately after submitting the request to the thread
     1524     * pool.
     1525     *
     1526     * @returns VBox status code.
     1527     * @param   pInterface  Pointer to this interface.
     1528     * @param   pStream     Optional backend stream structure to pass along.  The
     1529     *                      reference count will be increased till the call
     1530     *                      completes to make sure the stream stays valid.
     1531     * @param   uUser       User specific value.
     1532     * @param   pvUser      User specific pointer.
     1533     */
     1534    DECLR3CALLBACKMEMBER(int, pfnDoOnWorkerThread,(PPDMIHOSTAUDIOPORT pInterface, PPDMAUDIOBACKENDSTREAM pStream,
     1535                                                   uintptr_t uUser, void *pvUser));
     1536
    14641537    /**
    14651538     * The device for the given direction changed.
     
    14751548     *                      PDMIHOSTAUDIO::pfnStreamNotifyDeviceChanged.
    14761549     */
    1477     DECLR3CALLBACKMEMBER(void, pfnNotifyDeviceChanged,(PPDMIAUDIONOTIFYFROMHOST pInterface, PDMAUDIODIR enmDir, void *pvUser));
     1550    DECLR3CALLBACKMEMBER(void, pfnNotifyDeviceChanged,(PPDMIHOSTAUDIOPORT pInterface, PDMAUDIODIR enmDir, void *pvUser));
    14781551
    14791552    /**
     
    14851558     * @param   fReInit     Set if a re-init is required, clear if not.
    14861559     */
    1487     DECLR3CALLBACKMEMBER(void, pfnStreamNotifyDeviceChanged,(PPDMIAUDIONOTIFYFROMHOST pInterface,
     1560    DECLR3CALLBACKMEMBER(void, pfnStreamNotifyDeviceChanged,(PPDMIHOSTAUDIOPORT pInterface,
    14881561                                                             PPDMAUDIOBACKENDSTREAM pStream, bool fReInit));
    14891562
     
    14991572     * @param   pInterface  Pointer to this interface.
    15001573     */
    1501     DECLR3CALLBACKMEMBER(void, pfnNotifyDevicesChanged,(PPDMIAUDIONOTIFYFROMHOST pInterface));
    1502 } PDMIAUDIONOTIFYFROMHOST;
    1503 
    1504 /** PDMIAUDIONOTIFYFROMHOST interface ID. */
    1505 #define PDMIAUDIONOTIFYFROMHOST_IID                 "603f9d72-4b8b-4e0a-aa00-a76982931039"
     1574    DECLR3CALLBACKMEMBER(void, pfnNotifyDevicesChanged,(PPDMIHOSTAUDIOPORT pInterface));
     1575} PDMIHOSTAUDIOPORT;
     1576
     1577/** PDMIHOSTAUDIOPORT interface ID. */
     1578#define PDMIHOSTAUDIOPORT_IID                    "4d513a11-5be1-4f6f-9a06-a2f628cf67ac"
    15061579
    15071580/** @} */
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