VirtualBox

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

Last change on this file since 70704 was 70594, checked in by vboxsync, 7 years ago

Audio/HDA: Fixes for Windows guest surround setups.

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

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