VirtualBox

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

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

Build fix.

  • 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 73242 2018-07-19 15:06:55Z 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#ifdef HDA_USE_DMA_ACCESS_HANDLER
168 /** List of DMA handlers. */
169 RTLISTANCHORR3 lstDMAHandlers;
170#endif
171 /** How much DMA data from a previous transfer is left to be processed (in bytes).
172 * This can happen if the stream's frame size is bigger (e.g. 16 bytes) than
173 * the current DMA FIFO can hold (e.g. 10 bytes). Mostly needed for more complex
174 * stuff like interleaved surround streams. */
175 uint16_t cbDMALeft;
176 /** Unused, padding. */
177 uint8_t abPadding3[1+4];
178} HDASTREAMSTATE;
179AssertCompileSizeAlignment(HDASTREAMSTATE, 8);
180typedef 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 /** The stream'S critical section to serialize access. */
225 RTCRITSECT CritSect;
226 /** Pointer to the stream's timer. */
227 PTMTIMERR3 pTimer;
228 /** Internal state of this stream. */
229 HDASTREAMSTATE State;
230 /** Debug information. */
231 HDASTREAMDBGINFO Dbg;
232} HDASTREAM, *PHDASTREAM;
233
234#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
235/**
236 * Structure for keeping a HDA stream thread context.
237 */
238typedef struct HDASTREAMTHREADCTX
239{
240 PHDASTATE pThis;
241 PHDASTREAM pStream;
242} HDASTREAMTHREADCTX, *PHDASTREAMTHREADCTX;
243#endif
244
245#ifdef IN_RING3
246
247/** @name Stream functions.
248 * @{
249 */
250int hdaR3StreamCreate(PHDASTREAM pStream, PHDASTATE pThis, uint8_t u8SD);
251void hdaR3StreamDestroy(PHDASTREAM pStream);
252int hdaR3StreamInit(PHDASTREAM pStream, uint8_t uSD);
253void hdaR3StreamReset(PHDASTATE pThis, PHDASTREAM pStream, uint8_t uSD);
254int hdaR3StreamEnable(PHDASTREAM pStream, bool fEnable);
255uint32_t hdaR3StreamGetPosition(PHDASTATE pThis, PHDASTREAM pStream);
256void hdaR3StreamSetPosition(PHDASTREAM pStream, uint32_t u32LPIB);
257uint32_t hdaR3StreamGetFree(PHDASTREAM pStream);
258uint32_t hdaR3StreamGetUsed(PHDASTREAM pStream);
259bool hdaR3StreamTransferIsScheduled(PHDASTREAM pStream);
260uint64_t hdaR3StreamTransferGetNext(PHDASTREAM pStream);
261int hdaR3StreamTransfer(PHDASTREAM pStream, uint32_t cbToProcessMax);
262void hdaR3StreamLock(PHDASTREAM pStream);
263void hdaR3StreamUnlock(PHDASTREAM pStream);
264int hdaR3StreamRead(PHDASTREAM pStream, uint32_t cbToRead, uint32_t *pcbRead);
265int hdaR3StreamWrite(PHDASTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
266void hdaR3StreamUpdate(PHDASTREAM pStream, bool fAsync);
267# ifdef HDA_USE_DMA_ACCESS_HANDLER
268bool hdaR3StreamRegisterDMAHandlers(PHDASTREAM pStream);
269void hdaR3StreamUnregisterDMAHandlers(PHDASTREAM pStream);
270# endif /* HDA_USE_DMA_ACCESS_HANDLER */
271/** @} */
272
273/** @name Timer functions.
274 * @{
275 */
276DECLCALLBACK(void) hdaR3StreamTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser);
277/** @} */
278
279
280/** @name Async I/O stream functions.
281 * @{
282 */
283# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
284DECLCALLBACK(int) hdaR3StreamAsyncIOThread(RTTHREAD hThreadSelf, void *pvUser);
285int hdaR3StreamAsyncIOCreate(PHDASTREAM pStream);
286int hdaR3StreamAsyncIODestroy(PHDASTREAM pStream);
287int hdaR3StreamAsyncIONotify(PHDASTREAM pStream);
288void hdaR3StreamAsyncIOLock(PHDASTREAM pStream);
289void hdaR3StreamAsyncIOUnlock(PHDASTREAM pStream);
290void hdaR3StreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable);
291# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
292/** @} */
293
294#endif /* IN_RING3 */
295#endif /* !HDA_STREAM_H */
296
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