VirtualBox

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

Last change on this file since 68253 was 67903, checked in by vboxsync, 7 years ago

Build fix.

  • Property svn:executable set to *
File size: 8.9 KB
Line 
1/* $Id$ */
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#if defined (DEBUG) || defined(HDA_USE_DMA_ACCESS_HANDLER)
55typedef struct HDASTREAMDBGINFO
56{
57 /** Critical section to serialize access if needed. */
58 RTCRITSECT CritSect;
59 uint32_t Padding1[2];
60 /** Number of total read accesses. */
61 uint64_t cReadsTotal;
62 /** Number of total DMA bytes read. */
63 uint64_t cbReadTotal;
64 /** Timestamp (in ns) of last read access. */
65 uint64_t tsLastReadNs;
66 /** Number of total write accesses. */
67 uint64_t cWritesTotal;
68 /** Number of total DMA bytes written. */
69 uint64_t cbWrittenTotal;
70 /** Number of total write accesses since last iteration (Hz). */
71 uint64_t cWritesHz;
72 /** Number of total DMA bytes written since last iteration (Hz). */
73 uint64_t cbWrittenHz;
74 /** Timestamp (in ns) of beginning a new write slot. */
75 uint64_t tsWriteSlotBegin;
76 /** Number of current silence samples in a (consecutive) row. */
77 uint64_t csSilence;
78 /** Number of silent samples in a row to consider an audio block as audio gap (silence). */
79 uint64_t cSilenceThreshold;
80 /** How many bytes to skip in an audio stream before detecting silence.
81 * (useful for intros and silence at the beginning of a song). */
82 uint64_t cbSilenceReadMin;
83} HDASTREAMDBGINFO ,*PHDASTREAMDBGINFO;
84#endif /* defined (DEBUG) || defined(HDA_USE_DMA_ACCESS_HANDLER) */
85
86/**
87 * Internal state of a HDA stream.
88 */
89typedef struct HDASTREAMSTATE
90{
91 /** Current BDLE to use. Wraps around to 0 if
92 * maximum (cBDLE) is reached. */
93 uint16_t uCurBDLE;
94 /** Flag indicating whether this stream currently is
95 * in reset mode and therefore not acccessible by the guest. */
96 volatile bool fInReset;
97 /** Unused, padding. */
98 uint32_t Padding0;
99 /** Critical section to serialize access. */
100 RTCRITSECT CritSect;
101#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
102 /** Asynchronous I/O state members. */
103 HDASTREAMSTATEAIO AIO;
104#endif
105 /** This stream's data mapping. */
106 HDASTREAMMAPPING Mapping;
107 /** Current BDLE (Buffer Descriptor List Entry). */
108 HDABDLE BDLE;
109 /** Circular buffer (FIFO) for holding DMA'ed data. */
110 R3PTRTYPE(PRTCIRCBUF) pCircBuf;
111 /** Timestamp of the last success DMA data transfer.
112 * Used to calculate the time actually elapsed between two transfers. */
113 uint64_t uTimerTS;
114 /** The stream's period. Need for timing. */
115 HDASTREAMPERIOD Period;
116 /** The stream's current configuration.
117 * Should match SDFMT. */
118 PDMAUDIOSTREAMCFG strmCfg;
119#ifdef HDA_USE_DMA_ACCESS_HANDLER
120 /** List of DMA handlers. */
121 RTLISTANCHORR3 lstDMAHandlers;
122#endif
123 /** Unused, padding. */
124 uint8_t Padding1[3];
125} HDASTREAMSTATE, *PHDASTREAMSTATE;
126
127/**
128 * Structure for keeping a HDA stream (SDI / SDO).
129 *
130 * Note: This HDA stream has nothing to do with a regular audio stream handled
131 * by the audio connector or the audio mixer. This HDA stream is a serial data in/out
132 * stream (SDI/SDO) defined in hardware and can contain multiple audio streams
133 * in one single SDI/SDO (interleaving streams).
134 *
135 * How a specific SDI/SDO is mapped to our internal audio streams relies on the
136 * stream channel mappings.
137 *
138 * Contains only register values which do *not* change until a
139 * stream reset occurs.
140 */
141typedef struct HDASTREAM
142{
143 /** Stream descriptor number (SDn). */
144 uint8_t u8SD;
145 uint8_t Padding0[7];
146 /** DMA base address (SDnBDPU - SDnBDPL). */
147 uint64_t u64BDLBase;
148 /** Cyclic Buffer Length (SDnCBL).
149 * Represents the size of the ring buffer. */
150 uint32_t u32CBL;
151 /** Format (SDnFMT). */
152 uint16_t u16FMT;
153 /** FIFO Size (FIFOS).
154 * Maximum number of bytes that may have been DMA'd into
155 * memory but not yet transmitted on the link. */
156 uint16_t u16FIFOS;
157 /** FIFO Watermark. */
158 uint16_t u16FIFOW;
159 /** Last Valid Index (SDnLVI). */
160 uint16_t u16LVI;
161 uint16_t Padding1[2];
162 /** Pointer to the HDA state this stream is attached to. */
163 R3PTRTYPE(PHDASTATE) pHDAState;
164 /** Pointer to HDA sink this stream is attached to. */
165 R3PTRTYPE(PHDAMIXERSINK) pMixSink;
166 /** Internal state of this stream. */
167 HDASTREAMSTATE State;
168#ifdef DEBUG
169 /** Debug information. */
170 HDASTREAMDBGINFO Dbg;
171#endif
172} HDASTREAM, *PHDASTREAM;
173
174#ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
175/**
176 * Structure for keeping a HDA stream thread context.
177 */
178typedef struct HDASTREAMTHREADCTX
179{
180 PHDASTATE pThis;
181 PHDASTREAM pStream;
182} HDASTREAMTHREADCTX, *PHDASTREAMTHREADCTX;
183#endif
184
185#ifdef IN_RING3
186
187/** @name Stream functions.
188 * @{
189 */
190int hdaStreamCreate(PHDASTREAM pStream, PHDASTATE pThis);
191void hdaStreamDestroy(PHDASTREAM pStream);
192int hdaStreamInit(PHDASTREAM pStream, uint8_t uSD);
193void hdaStreamReset(PHDASTATE pThis, PHDASTREAM pStream, uint8_t uSD);
194int hdaStreamEnable(PHDASTREAM pStream, bool fEnable);
195uint32_t hdaStreamGetUsed(PHDASTREAM pStream);
196uint32_t hdaStreamGetFree(PHDASTREAM pStream);
197int hdaStreamTransfer(PHDASTREAM pStream, uint32_t cbToProcessMax);
198uint32_t hdaStreamUpdateLPIB(PHDASTREAM pStream, uint32_t u32LPIB);
199void hdaStreamLock(PHDASTREAM pStream);
200void hdaStreamUnlock(PHDASTREAM pStream);
201int hdaStreamRead(PHDASTREAM pStream, uint32_t cbToRead, uint32_t *pcbRead);
202int hdaStreamWrite(PHDASTREAM pStream, uint32_t cbToWrite, uint32_t *pcbWritten);
203void hdaStreamUpdate(PHDASTREAM pStream, bool fAsync);
204# ifdef HDA_USE_DMA_ACCESS_HANDLER
205bool hdaStreamRegisterDMAHandlers(PHDASTREAM pStream);
206void hdaStreamUnregisterDMAHandlers(PHDASTREAM pStream);
207# endif /* HDA_USE_DMA_ACCESS_HANDLER */
208/** @} */
209
210/** @name Async I/O stream functions.
211 * @{
212 */
213# ifdef VBOX_WITH_AUDIO_HDA_ASYNC_IO
214DECLCALLBACK(int) hdaStreamAsyncIOThread(RTTHREAD hThreadSelf, void *pvUser);
215int hdaStreamAsyncIOCreate(PHDASTREAM pStream);
216int hdaStreamAsyncIODestroy(PHDASTREAM pStream);
217int hdaStreamAsyncIONotify(PHDASTREAM pStream);
218void hdaStreamAsyncIOLock(PHDASTREAM pStream);
219void hdaStreamAsyncIOUnlock(PHDASTREAM pStream);
220void hdaStreamAsyncIOEnable(PHDASTREAM pStream, bool fEnable);
221# endif /* VBOX_WITH_AUDIO_HDA_ASYNC_IO */
222/** @} */
223
224#endif /* IN_RING3 */
225
226#endif /* !HDA_STREAM_H */
227
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