VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/HDAStream.h@ 73241

Last change on this file since 73241 was 73241, checked in by vboxsync, 6 years ago

Audio/PDM: Added (tweakable) parameters to the audio stream configuration and give the audio connector(s) a scheduling hint from the device emulation(s), if available.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
1/* $Id: HDAStream.h 73241 2018-07-19 14:56:24Z vboxsync $ */
2/** @file
3 * HDAStream.h - Stream functions for HD Audio.
4 */
5
6/*
7 * Copyright (C) 2017-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef HDA_STREAM_H
19#define HDA_STREAM_H
20
21#include "DevHDACommon.h"
22
23#include "HDAStreamMap.h"
24#include "HDAStreamPeriod.h"
25
26
27typedef struct HDAMIXERSINK *PHDAMIXERSINK;
28
29#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
30/**
31 * Structure keeping the HDA stream's state for asynchronous I/O.
32 */
33typedef struct HDASTREAMSTATEAIO
34{
35 /** Thread handle for the actual I/O thread. */
36 RTTHREAD Thread;
37 /** Event for letting the thread know there is some data to process. */
38 RTSEMEVENT Event;
39 /** Critical section for synchronizing access. */
40 RTCRITSECT CritSect;
41 /** Started indicator. */
42 volatile bool fStarted;
43 /** Shutdown indicator. */
44 volatile bool fShutdown;
45 /** Whether the thread should do any data processing or not. */
46 volatile bool fEnabled;
47 uint32_t Padding1;
48} HDASTREAMSTATEAIO, *PHDASTREAMSTATEAIO;
49#endif
50
51/**
52 * Structure containing HDA stream debug stuff, configurable at runtime.
53 */
54typedef struct HDASTREAMDBGINFORT
55{
56 /** Whether debugging is enabled or not. */
57 bool fEnabled;
58 uint8_t Padding[7];
59 /** File for dumping stream reads / writes.
60 * For input streams, this dumps data being written to the device FIFO,
61 * whereas for output streams this dumps data being read from the device FIFO. */
62 R3PTRTYPE(PPDMAUDIOFILE) pFileStream;
63 /** File for dumping DMA reads / writes.
64 * For input streams, this dumps data being written to the device DMA,
65 * whereas for output streams this dumps data being read from the device DMA. */
66 R3PTRTYPE(PPDMAUDIOFILE) pFileDMA;
67} HDASTREAMDBGINFORT, *PHDASTREAMDBGINFORT;
68
69/**
70 * Structure containing HDA stream debug information.
71 */
72typedef struct HDASTREAMDBGINFO
73{
74#ifdef DEBUG
75 /** Critical section to serialize access if needed. */
76 RTCRITSECT CritSect;
77 uint32_t Padding0[2];
78 /** Number of total read accesses. */
79 uint64_t cReadsTotal;
80 /** Number of total DMA bytes read. */
81 uint64_t cbReadTotal;
82 /** Timestamp (in ns) of last read access. */
83 uint64_t tsLastReadNs;
84 /** Number of total write accesses. */
85 uint64_t cWritesTotal;
86 /** Number of total DMA bytes written. */
87 uint64_t cbWrittenTotal;
88 /** Number of total write accesses since last iteration (Hz). */
89 uint64_t cWritesHz;
90 /** Number of total DMA bytes written since last iteration (Hz). */
91 uint64_t cbWrittenHz;
92 /** Timestamp (in ns) of beginning a new write slot. */
93 uint64_t tsWriteSlotBegin;
94 /** Number of current silence samples in a (consecutive) row. */
95 uint64_t csSilence;
96 /** Number of silent samples in a row to consider an audio block as audio gap (silence). */
97 uint64_t cSilenceThreshold;
98 /** How many bytes to skip in an audio stream before detecting silence.
99 * (useful for intros and silence at the beginning of a song). */
100 uint64_t cbSilenceReadMin;
101#endif
102 /** Runtime debug info. */
103 HDASTREAMDBGINFORT Runtime;
104} HDASTREAMDBGINFO ,*PHDASTREAMDBGINFO;
105
106/**
107 * Internal state of a HDA stream.
108 */
109typedef struct HDASTREAMSTATE
110{
111 /** Current BDLE to use. Wraps around to 0 if
112 * maximum (cBDLE) is reached. */
113 uint16_t uCurBDLE;
114 /** Flag indicating whether this stream currently is
115 * in reset mode and therefore not acccessible by the guest. */
116 volatile bool fInReset;
117 /** Flag indicating if the stream is in running state or not. */
118 volatile bool fRunning;
119 /** Unused, padding. */
120 uint8_t Padding0[4];
121#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
122 /** Asynchronous I/O state members. */
123 HDASTREAMSTATEAIO AIO;
124#endif
125 /** This stream's data mapping. */
126 HDASTREAMMAPPING Mapping;
127 /** Current BDLE (Buffer Descriptor List Entry). */
128 HDABDLE BDLE;
129 /** Circular buffer (FIFO) for holding DMA'ed data. */
130 R3PTRTYPE(PRTCIRCBUF) pCircBuf;
131#if HC_ARCH_BITS == 32
132 RTR3PTR Padding1;
133#endif
134 /** Timestamp of the last DMA data transfer. */
135 uint64_t tsTransferLast;
136 /** Timestamp of the next DMA data transfer.
137 * Next for determining the next scheduling window.
138 * Can be 0 if no next transfer is scheduled. */
139 uint64_t tsTransferNext;
140 /** Total transfer size (in bytes) of a transfer period. */
141 uint32_t cbTransferSize;
142 /** Transfer chunk size (in bytes) of a transfer period. */
143 uint32_t cbTransferChunk;
144 /** How many bytes already have been processed in within
145 * the current transfer period. */
146 uint32_t cbTransferProcessed;
147 /** How many interrupts are pending due to
148 * BDLE interrupt-on-completion (IOC) bits set. */
149 uint8_t cTransferPendingInterrupts;
150 /** The stream's current audio frame size (in bytes). */
151 uint32_t cbFrameSize;
152 /** How many audio data frames are left to be processed
153 * for the position adjustment handling.
154 *
155 * 0 if position adjustment handling is done or inactive. */
156 uint16_t cPosAdjustFramesLeft;
157 uint8_t Padding2[2];
158 /** (Virtual) clock ticks per byte. */
159 uint64_t cTicksPerByte;
160 /** (Virtual) clock ticks per transfer. */
161 uint64_t cTransferTicks;
162 /** The stream's period. Need for timing. */
163 HDASTREAMPERIOD Period;
164 /** The stream's current configuration.
165 * Should match SDFMT. */
166 PDMAUDIOSTREAMCFG Cfg;
167 uint32_t aPadding3;
168#ifdef HDA_USE_DMA_ACCESS_HANDLER
169 /** List of DMA handlers. */
170 RTLISTANCHORR3 lstDMAHandlers;
171#endif
172 /** How much DMA data from a previous transfer is left to be processed (in bytes).
173 * This can happen if the stream's frame size is bigger (e.g. 16 bytes) than
174 * the current DMA FIFO can hold (e.g. 10 bytes). Mostly needed for more complex
175 * stuff like interleaved surround streams. */
176 uint16_t cbDMALeft;
177 /** Unused, padding. */
178 uint8_t abPadding4[2+4];
179} HDASTREAMSTATE;
180AssertCompileSizeAlignment(HDASTREAMSTATE, 8);
181typedef HDASTREAMSTATE *PHDASTREAMSTATE;
182
183/**
184 * Structure for keeping a HDA stream (SDI / SDO).
185 *
186 * Note: This HDA stream has nothing to do with a regular audio stream handled
187 * by the audio connector or the audio mixer. This HDA stream is a serial data in/out
188 * stream (SDI/SDO) defined in hardware and can contain multiple audio streams
189 * in one single SDI/SDO (interleaving streams).
190 *
191 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
192 * stream channel mappings.
193 *
194 * Contains only register values which do *not* change until a
195 * stream reset occurs.
196 */
197typedef struct HDASTREAM
198{
199 /** Stream descriptor number (SDn). */
200 uint8_t u8SD;
201 /** Current channel index.
202 * For a stereo stream, this is u8Channel + 1. */
203 uint8_t u8Channel;
204 uint8_t Padding0[6];
205 /** DMA base address (SDnBDPU - SDnBDPL). */
206 uint64_t u64BDLBase;
207 /** Cyclic Buffer Length (SDnCBL).
208 * Represents the size of the ring buffer. */
209 uint32_t u32CBL;
210 /** Format (SDnFMT). */
211 uint16_t u16FMT;
212 /** FIFO Size (FIFOS).
213 * Maximum number of bytes that may have been DMA'd into
214 * memory but not yet transmitted on the link. */
215 uint16_t u16FIFOS;
216 /** FIFO Watermark. */
217 uint16_t u16FIFOW;
218 /** Last Valid Index (SDnLVI). */
219 uint16_t u16LVI;
220 uint16_t Padding1[2];
221 /** Pointer to the HDA state this stream is attached to. */
222 R3PTRTYPE(PHDASTATE) pHDAState;
223 /** Pointer to HDA sink this stream is attached to. */
224 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
225 /** The stream'S critical section to serialize access. */
226 RTCRITSECT CritSect;
227 /** Pointer to the stream's timer. */
228 PTMTIMERR3 pTimer;
229 /** Internal state of this stream. */
230 HDASTREAMSTATE State;
231 /** Debug information. */
232 HDASTREAMDBGINFO Dbg;
233} HDASTREAM, *PHDASTREAM;
234
235#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
236/**
237 * Structure for keeping a HDA stream thread context.
238 */
239typedef struct HDASTREAMTHREADCTX
240{
241 PHDASTATE pThis;
242 PHDASTREAM pStream;
243} HDASTREAMTHREADCTX, *PHDASTREAMTHREADCTX;
244#endif
245
246#ifdef IN_RING3
247
248/** @name Stream functions.
249 * @{
250 */
251int hdaR3StreamCreate(PHDASTREAM pStream, PHDASTATE pThis, uint8_t u8SD);
252void hdaR3StreamDestroy(PHDASTREAM pStream);
253int hdaR3StreamInit(PHDASTREAM pStream, uint8_t uSD);
254void hdaR3StreamReset(PHDASTATE pThis, PHDASTREAM pStream, uint8_t uSD);
255int hdaR3StreamEnable(PHDASTREAM pStream, bool fEnable);
256uint32_t hdaR3StreamGetPosition(PHDASTATE pThis, PHDASTREAM pStream);
257void hdaR3StreamSetPosition(PHDASTREAM pStream, uint32_t u32LPIB);
258uint32_t hdaR3StreamGetFree(PHDASTREAM pStream);
259uint32_t hdaR3StreamGetUsed(PHDASTREAM pStream);
260bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStream);
261uint64_t hdaR3StreamTransferGetNext(PHDASTREAM pStream);
262int hdaR3StreamTransfer(PHDASTREAM pStream, uint32_t cbToProcessMax);
263void hdaR3StreamLock(PHDASTREAM pStream);
264void hdaR3StreamUnlock(PHDASTREAM pStream);
265int hdaR3StreamRead(PHDASTREAM pStream, uint32_t cbToRead, uint32_t *pcbRead);
266int hdaR3StreamWrite(PHDASTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
267void hdaR3StreamUpdate(PHDASTREAM pStream, bool fAsync);
268# ifdef HDA_USE_DMA_ACCESS_HANDLER
269bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
270void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
271# endif /* HDA_USE_DMA_ACCESS_HANDLER */
272/** @} */
273
274/** @name Timer functions.
275 * @{
276 */
277DECLCALLBACK(void) hdaR3StreamTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
278/** @} */
279
280
281/** @name Async I/O stream functions.
282 * @{
283 */
284# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
285DECLCALLBACK(int) hdaR3StreamAsyncIOThread(RTTHREAD hThreadSelf, void *pvUser);
286int hdaR3StreamAsyncIOCreate(PHDASTREAM pStream);
287int hdaR3StreamAsyncIODestroy(PHDASTREAM pStream);
288int hdaR3StreamAsyncIONotify(PHDASTREAM pStream);
289void hdaR3StreamAsyncIOLock(PHDASTREAM pStream);
290void hdaR3StreamAsyncIOUnlock(PHDASTREAM pStream);
291void hdaR3StreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable);
292# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
293/** @} */
294
295#endif /* IN_RING3 */
296#endif /* !HDA_STREAM_H */
297
Note: See TracBrowser for help on using the repository browser.

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