VirtualBox

Changeset 88356 in vbox for trunk/include/VBox/vmm


Ignore:
Timestamp:
Apr 4, 2021 10:45:13 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
143603
Message:

Audio: Trimmed down PDMAUDIOSTREAM a lot by moving non-essential stuff into an wrapper structure in DrvAudio. This allows for the mixing buffers and other stuff to move (back?) into AudioMixBuffer.h. Also started specifying away to skip the mixing in DrvAudio as only DevSB16 really needs this (goal is to reduce number of copies and bufferings). bugref:9890

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioifs.h

    r88307 r88356  
    8585 * Audio input / output data gets handed off to/from the device emulation in an
    8686 * unmodified (raw) way. The actual audio frame / sample conversion is done via
    87  * the PDMAUDIOMIXBUF API.
     87 * the AUDIOMIXBUF API.
    8888 *
    8989 * This concentrates the audio data processing in one place and makes it easier
     
    192192   |PDMAUDIOSTREAM           |        |PDMIAUDIOCONNECTOR       |
    193193   |-------------------------|        |-------------------------|
    194    |PDMAUDIOMIXBUF           |+------>|PDMAUDIOSTREAM Host      |
     194   |AUDIOMIXBUF              |+------>|PDMAUDIOSTREAM Host      |
    195195   |PDMAUDIOSTREAMCFG        |+------>|PDMAUDIOSTREAM Guest     |
    196196   |                         |        |Device capabilities      |
     
    904904#define PDMAUDIO_VOLUME_MAX     (255)
    905905
    906 /**
    907  * Rate processing information of a source & destination audio stream.
    908  *
    909  * This is needed because both streams can differ regarding their rates and
    910  * therefore need to be treated accordingly.
    911  */
    912 typedef struct PDMAUDIOSTREAMRATE
    913 {
    914     /** Current (absolute) offset in the output (destination) stream.
    915      * @todo r=bird: Please reveal which unit these members are given in. */
    916     uint64_t        offDst;
    917     /** Increment for moving offDst for the destination stream.
    918      * This is needed because the source <-> destination rate might be different. */
    919     uint64_t        uDstInc;
    920     /** Current (absolute) offset in the input stream. */
    921     uint32_t        offSrc;
    922     /** Explicit alignment padding. */
    923     uint32_t        u32AlignmentPadding;
    924     /** Last processed frame of the input stream.
    925      *  Needed for interpolation. */
    926     PDMAUDIOFRAME   SrcFrameLast;
    927 } PDMAUDIOSTREAMRATE;
    928 /** Pointer to rate processing information of a stream. */
    929 typedef PDMAUDIOSTREAMRATE *PPDMAUDIOSTREAMRATE;
    930 
    931 /**
    932  * Mixing buffer volume parameters.
    933  *
    934  * The volume values are in fixed point style and must be converted to/from
    935  * before using with e.g. PDMAUDIOVOLUME.
    936  */
    937 typedef struct PDMAUDMIXBUFVOL
    938 {
    939     /** Set to @c true if this stream is muted, @c false if not. */
    940     bool            fMuted;
    941     /** Left volume to apply during conversion.
    942      * Pass 0 to convert the original values. May not apply to all conversion functions. */
    943     uint32_t        uLeft;
    944     /** Right volume to apply during conversion.
    945      * Pass 0 to convert the original values. May not apply to all conversion functions. */
    946     uint32_t        uRight;
    947 } PDMAUDMIXBUFVOL;
    948 /** Pointer to mixing buffer volument parameters. */
    949 typedef PDMAUDMIXBUFVOL *PPDMAUDMIXBUFVOL;
    950 
    951 /*
    952  * Frame conversion parameters for the audioMixBufConvFromXXX / audioMixBufConvToXXX functions.
    953  */
    954 typedef struct PDMAUDMIXBUFCONVOPTS
    955 {
    956     /** Number of audio frames to convert. */
    957     uint32_t        cFrames;
    958     union
    959     {
    960         struct
    961         {
    962             /** Volume to use for conversion. */
    963             PDMAUDMIXBUFVOL Volume;
    964         } From;
    965     } RT_UNION_NM(u);
    966 } PDMAUDMIXBUFCONVOPTS;
    967 /** Pointer to conversion parameters for the audio mixer.   */
    968 typedef PDMAUDMIXBUFCONVOPTS *PPDMAUDMIXBUFCONVOPTS;
    969 /** Pointer to const conversion parameters for the audio mixer.   */
    970 typedef PDMAUDMIXBUFCONVOPTS const *PCPDMAUDMIXBUFCONVOPTS;
    971 
    972 /**
    973  * @note All internal handling is done in audio frames, not in bytes!
    974  * @todo r=bird: What does this node actually apply to?
    975  */
    976 typedef uint32_t PDMAUDIOMIXBUFFMT;
    977 typedef PDMAUDIOMIXBUFFMT *PPDMAUDIOMIXBUFFMT;
    978 
    979 /**
    980  * Convertion-from function used by the PDM audio buffer mixer.
    981  *
    982  * @returns Number of audio frames returned.
    983  * @param   paDst           Where to return the converted frames.
    984  * @param   pvSrc           The source frame bytes.
    985  * @param   cbSrc           Number of bytes to convert.
    986  * @param   pOpts           Conversion options.
    987  * @todo r=bird: The @a paDst size is presumable given in @a pOpts->cFrames?
    988  */
    989 typedef DECLCALLBACKTYPE(uint32_t, FNPDMAUDIOMIXBUFCONVFROM,(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc,
    990                                                              PCPDMAUDMIXBUFCONVOPTS pOpts));
    991 /** Pointer to a convertion-from function used by the PDM audio buffer mixer. */
    992 typedef FNPDMAUDIOMIXBUFCONVFROM *PFNPDMAUDIOMIXBUFCONVFROM;
    993 
    994 /**
    995  * Convertion-to function used by the PDM audio buffer mixer.
    996  *
    997  * @param   pvDst           Output buffer.
    998  * @param   paSrc           The input frames.
    999  * @param   pOpts           Conversion options.
    1000  * @todo r=bird: The @a paSrc size is presumable given in @a pOpts->cFrames and
    1001  *       this implicitly gives the pvDst size too, right?
    1002  */
    1003 typedef DECLCALLBACKTYPE(void, FNPDMAUDIOMIXBUFCONVTO,(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts));
    1004 /** Pointer to a convertion-to function used by the PDM audio buffer mixer. */
    1005 typedef FNPDMAUDIOMIXBUFCONVTO *PFNPDMAUDIOMIXBUFCONVTO;
    1006 
    1007 /** Pointer to audio mixing buffer.  */
    1008 typedef struct PDMAUDIOMIXBUF *PPDMAUDIOMIXBUF;
    1009 
    1010 /**
    1011  * Audio mixing buffer.
    1012  */
    1013 typedef struct PDMAUDIOMIXBUF
    1014 {
    1015     /** Magic value (PDMAUDIOMIXBUF_MAGIC). */
    1016     uint32_t                    uMagic;
    1017     uint8_t                     abPadding[4];
    1018     /* ???Undocumented??? */
    1019     RTLISTNODE                  Node;
    1020     /** Name of the buffer. */
    1021     char                       *pszName;
    1022     /** Frame buffer. */
    1023     PPDMAUDIOFRAME              pFrames;
    1024     /** Size of the frame buffer (in audio frames). */
    1025     uint32_t                    cFrames;
    1026     /** The current read position (in frames). */
    1027     uint32_t                    offRead;
    1028     /** The current write position (in frames). */
    1029     uint32_t                    offWrite;
    1030     /** Total frames already mixed down to the parent buffer (if any).
    1031      *
    1032      * Always starting at the parent's offRead position.
    1033      * @note Count always is specified in parent frames, as the sample count can
    1034      *       differ between parent and child.  */
    1035     uint32_t                    cMixed;
    1036     /** How much audio frames are currently being used in this buffer.
    1037      * @note This also is known as the distance in ring buffer terms. */
    1038     uint32_t                    cUsed;
    1039     /** Number of children mix buffers kept in lstChildren. */
    1040     uint32_t                    cChildren;
    1041     /** List of children mix buffers to keep in sync with (if being a parent buffer). */
    1042     RTLISTANCHOR                lstChildren;
    1043     /** Pointer to parent buffer (if any). */
    1044     PPDMAUDIOMIXBUF             pParent;
    1045     /** Intermediate structure for buffer conversion tasks. */
    1046     PPDMAUDIOSTREAMRATE         pRate;
    1047     /** Internal representation of current volume used for mixing. */
    1048     PDMAUDMIXBUFVOL             Volume;
    1049     /** This buffer's audio format.
    1050      * @todo r=bird: This seems to be a value created by AUDMIXBUF_AUDIO_FMT_MAKE(),
    1051      *       which is not define here.  Does this structure really belong here at
    1052      *       all?  */
    1053     PDMAUDIOMIXBUFFMT           uAudioFmt;
    1054     /** Audio input properties.
    1055      * @note There is only one set of audio properties here because we have one
    1056      *       mixer buffer for the guest side and a separate one for the host side.
    1057      * @todo r=bird: Why exactly do we need to use separate mixer buffers?
    1058      *       Couldn't we just have different conversion fuctions and save the
    1059      *       extra copying? */
    1060     PDMAUDIOPCMPROPS            Props;
    1061     /** Standard conversion-to function for set uAudioFmt. */
    1062     PFNPDMAUDIOMIXBUFCONVTO     pfnConvTo;
    1063     /** Standard conversion-from function for set uAudioFmt. */
    1064     PFNPDMAUDIOMIXBUFCONVFROM   pfnConvFrom;
    1065 
    1066     /** Ratio of the associated parent stream's frequency by this stream's
    1067      * frequency (1<<32), represented as a signed 64 bit integer.
    1068      *
    1069      * For example, if the parent stream has a frequency of 44 khZ, and this
    1070      * stream has a frequency of 11 kHz, the ration then would be
    1071      * (44/11 * (1 << 32)).
    1072      *
    1073      * Currently this does not get changed once assigned. */
    1074     int64_t                     iFreqRatio;
    1075 } PDMAUDIOMIXBUF;
    1076 
    1077 /** Magic value for PDMAUDIOMIXBUF. */
    1078 #define PDMAUDIOMIXBUF_MAGIC                PDM_VERSION_MAKE(0xa0d2, 1, 0)
    1079906
    1080907/** @name PDMAUDIOFILE_FLAGS_XXX
     
    11901017} PDMAUDIOBACKENDSTS;
    11911018
    1192 /**
    1193  * The specifics for an audio input stream.
    1194  *
    1195  * Do not use directly, use PDMAUDIOSTREAM instead.
    1196  */
    1197 typedef struct PDMAUDIOSTREAMIN
    1198 {
    1199     struct
    1200     {
    1201         /** File for writing stream reads. */
    1202         PPDMAUDIOFILE   pFileStreamRead;
    1203         /** File for writing non-interleaved captures. */
    1204         PPDMAUDIOFILE   pFileCaptureNonInterleaved;
    1205     } Dbg;
    1206     struct
    1207     {
    1208         STAMCOUNTER     TotalFramesCaptured;
    1209         STAMCOUNTER     AvgFramesCaptured;
    1210         STAMCOUNTER     TotalTimesCaptured;
    1211         STAMCOUNTER     TotalFramesRead;
    1212         STAMCOUNTER     AvgFramesRead;
    1213         STAMCOUNTER     TotalTimesRead;
    1214     } Stats;
    1215 } PDMAUDIOSTREAMIN;
    1216 /** Pointer to the specifics for an audio input stream. */
    1217 typedef PDMAUDIOSTREAMIN *PPDMAUDIOSTREAMIN;
    1218 
    1219 /**
    1220  * The specifics for an audio output stream.
    1221  *
    1222  * Do not use directly, use PDMAUDIOSTREAM instead.
    1223  */
    1224 typedef struct PDMAUDIOSTREAMOUT
    1225 {
    1226     struct
    1227     {
    1228         /** File for writing stream writes. */
    1229         PPDMAUDIOFILE   pFileStreamWrite;
    1230         /** File for writing stream playback. */
    1231         PPDMAUDIOFILE   pFilePlayNonInterleaved;
    1232     } Dbg;
    1233     struct
    1234     {
    1235         STAMCOUNTER     TotalFramesPlayed;
    1236         STAMCOUNTER     AvgFramesPlayed;
    1237         STAMCOUNTER     TotalTimesPlayed;
    1238         STAMCOUNTER     TotalFramesWritten;
    1239         STAMCOUNTER     AvgFramesWritten;
    1240         STAMCOUNTER     TotalTimesWritten;
    1241         uint32_t        cbBackendWritableBefore;
    1242         uint32_t        cbBackendWritableAfter;
    1243     } Stats;
    1244     /** Hack alert: Max writable amount reported by the backend.
    1245      * This is used to aid buffer underrun detection in DrvAudio while playing.
    1246      * Ideally, the backend should have a method for querying number of buffered
    1247      * bytes instead.  However this will do for now. */
    1248     uint32_t            cbBackendMaxWritable;
    1249 } PDMAUDIOSTREAMOUT;
    1250 /** Pointer to the specifics for an audio output stream. */
    1251 typedef PDMAUDIOSTREAMOUT *PPDMAUDIOSTREAMOUT;
    1252 
    1253 /** Pointer to an audio stream. */
    1254 typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
    1255 
    1256 /**
    1257  * Audio stream context.
    1258  * Needed for separating data from the guest and host side (per stream).
    1259  */
    1260 typedef struct PDMAUDIOSTREAMCTX
    1261 {
    1262     /** The stream's audio configuration. */
    1263     PDMAUDIOSTREAMCFG   Cfg;
    1264     /** This stream's mixing buffer. */
    1265     PDMAUDIOMIXBUF      MixBuf;
    1266 } PDMAUDIOSTREAMCTX;
    1267 
    1268 /** Pointer to an audio stream context. */
    1269 typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAMCTX;
     1019/** @name PDMAUDIOSTREAM_CREATE_F_XXX
     1020 * @{ */
     1021/** Does not need any mixing buffers, the device takes care of all conversion. */
     1022#define PDMAUDIOSTREAM_CREATE_F_NO_MIXBUF       RT_BIT_32(0)
     1023/** @} */
    12701024
    12711025/** @name PDMAUDIOSTREAM_WARN_FLAGS_XXX
     
    12841038    /** Magic value (PDMAUDIOSTREAM_MAGIC). */
    12851039    uint32_t                uMagic;
    1286     /** Size (in bytes) of the backend-specific stream data. */
    1287     uint32_t                cbBackend;
    1288     /** List entry (some DrvAudio internal list). */
    1289     RTLISTNODE              ListEntry;
    12901040    /** Number of references to this stream.
    12911041     *  Only can be destroyed when the reference count reaches 0. */
    1292     uint32_t                cRefs;
    1293     /** Number of (re-)tries while re-initializing the stream. */
    1294     uint32_t                cTriesReInit;
    1295     /** Warnings shown already in the release log.
    1296      *  See PDMAUDIOSTREAM_WARN_FLAGS_XXX. */
    1297     uint32_t                fWarningsShown;
     1042    uint32_t volatile       cRefs;
    12981043    /** Stream status flag. */
    12991044    PDMAUDIOSTREAMSTS       fStatus;
    13001045    /** Audio direction of this stream. */
    13011046    PDMAUDIODIR             enmDir;
    1302     /** For output streams this indicates whether the stream has reached
    1303      *  its playback threshold, e.g. is playing audio.
    1304      *  For input streams this  indicates whether the stream has enough input
    1305      *  data to actually start reading audio. */
    1306     bool                    fThresholdReached;
    1307     bool                    afPadding[3];
    1308     /** The guest side of the stream. */
    1309     PDMAUDIOSTREAMCTX       Guest;
    1310     /** The host side of the stream. */
    1311     PDMAUDIOSTREAMCTX       Host;
    1312     /** Timestamp (in ns) since last trying to re-initialize.
    1313      *  Might be 0 if has not been tried yet. */
    1314     uint64_t                tsLastReInitNs;
    1315     /** Timestamp (in ns) since last iteration. */
    1316     uint64_t                tsLastIteratedNs;
    1317     /** Timestamp (in ns) since last playback / capture. */
    1318     uint64_t                tsLastPlayedCapturedNs;
    1319     /** Timestamp (in ns) since last read (input streams) or
    1320      *  write (output streams). */
    1321     uint64_t                tsLastReadWrittenNs;
    1322     /** Data to backend-specific stream data.
    1323      *  This data block will be casted by the backend to access its backend-dependent data.
    1324      *
    1325      *  That way the backends do not have access to the audio connector's data. */
    1326     void                   *pvBackend;
     1047    /** Size (in bytes) of the backend-specific stream data. */
     1048    uint32_t                cbBackend;
     1049    /** Warnings shown already in the release log.
     1050     *  See PDMAUDIOSTREAM_WARN_FLAGS_XXX. */
     1051    uint32_t                fWarningsShown;
    13271052
    13281053    /** Name of this stream. */
    13291054    char                    szName[64];
    1330 
    1331     /** Union for input/output specifics depending on enmDir. */
    1332     union
    1333     {
    1334         PDMAUDIOSTREAMIN    In;
    1335         PDMAUDIOSTREAMOUT   Out;
    1336     } RT_UNION_NM(u);
    13371055} PDMAUDIOSTREAM;
     1056/** Pointer to an audio stream. */
     1057typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
     1058/** Pointer to a const audio stream. */
     1059typedef struct PDMAUDIOSTREAM const *PCPDMAUDIOSTREAM;
    13381060
    13391061/** Magic value for PDMAUDIOSTREAM. */
    1340 #define PDMAUDIOSTREAM_MAGIC    PDM_VERSION_MAKE(0xa0d3, 1, 1)
     1062#define PDMAUDIOSTREAM_MAGIC    PDM_VERSION_MAKE(0xa0d3, 2, 0)
    13411063
    13421064
     
    15221244     * @returns VBox status code.
    15231245     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1246     * @param   fFlags          PDMAUDIOSTREAM_CREATE_F_XXX.
    15241247     * @param   pCfgHost        Stream configuration for host side.
    15251248     * @param   pCfgGuest       Stream configuration for guest side.
     
    15281251     *       modified the DrvAudio...
    15291252     */
    1530     DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost,
     1253    DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, uint32_t fFlags, PPDMAUDIOSTREAMCFG pCfgHost,
    15311254                                                PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
    15321255
     
    16731396     * @param   paCallbacks          Pointer to array of callbacks to register.
    16741397     * @param   cCallbacks           Number of callbacks to register.
     1398     *
     1399     * @todo r=bird: Total misdesign. See more notes in drvAudioBackendCallback on
     1400     *       the subject.
    16751401     */
    16761402    DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCBRECORD paCallbacks,
     
    16801406
    16811407/** PDMIAUDIOCONNECTOR interface ID. */
    1682 #define PDMIAUDIOCONNECTOR_IID                  "00e704ef-0078-4bb6-0005-a5fd000ded9f"
     1408#define PDMIAUDIOCONNECTOR_IID                  "23c23c64-89aa-43b1-b20e-ba6881ab5746"
    16831409
    16841410
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