VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/HDAStreamChannel.cpp@ 73370

Last change on this file since 73370 was 71736, checked in by vboxsync, 7 years ago

DevHDA: Use hdaR3 as prefix for ring-3 only methods to make it less complicated to follow code.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: HDAStreamChannel.cpp 71736 2018-04-07 21:29:18Z vboxsync $ */
2/** @file
3 * HDAStreamChannel.cpp - Stream channel 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
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEV_HDA
23#include <VBox/log.h>
24
25#include <VBox/vmm/pdmdev.h>
26#include <VBox/vmm/pdmaudioifs.h>
27
28#include "HDAStreamChannel.h"
29
30/**
31 * Initializes a stream channel data structure.
32 *
33 * @returns IPRT status code.
34 * @param pChanData Channel data to initialize.
35 * @param fFlags
36 */
37int hdaR3StreamChannelDataInit(PPDMAUDIOSTREAMCHANNELDATA pChanData, uint32_t fFlags)
38{
39 int rc = RTCircBufCreate(&pChanData->pCircBuf, 256); /** @todo Make this configurable? */
40 if (RT_SUCCESS(rc))
41 {
42 pChanData->fFlags = fFlags;
43 }
44
45 return rc;
46}
47
48/**
49 * Destroys a stream channel data structure.
50 *
51 * @param pChanData Channel data to destroy.
52 */
53void hdaR3StreamChannelDataDestroy(PPDMAUDIOSTREAMCHANNELDATA pChanData)
54{
55 if (!pChanData)
56 return;
57
58 if (pChanData->pCircBuf)
59 {
60 RTCircBufDestroy(pChanData->pCircBuf);
61 pChanData->pCircBuf = NULL;
62 }
63
64 pChanData->fFlags = PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE;
65}
66
67/**
68 * Extracts HDA audio stream data and stores it into the given stream channel data block.
69 *
70 * @returns IPRT status code.
71 * @param pChan Channel data to extract audio stream data into.
72 * @param pvBuf Buffer of audio data to extract.
73 * @param cbBuf Size (in bytes) of audio data to extract.
74 */
75int hdaR3StreamChannelExtract(PPDMAUDIOSTREAMCHANNEL pChan, const void *pvBuf, size_t cbBuf)
76{
77 AssertPtrReturn(pChan, VERR_INVALID_POINTER);
78 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
79 AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
80
81 AssertRelease(pChan->cbOff <= cbBuf);
82
83 const uint8_t *pu8Buf = (const uint8_t *)pvBuf;
84
85 size_t cbSrc = cbBuf - pChan->cbOff;
86 const uint8_t *pvSrc = &pu8Buf[pChan->cbOff];
87
88 size_t cbDst;
89 uint8_t *pvDst;
90 RTCircBufAcquireWriteBlock(pChan->Data.pCircBuf, cbBuf, (void **)&pvDst, &cbDst);
91
92 cbSrc = RT_MIN(cbSrc, cbDst);
93
94 while (cbSrc)
95 {
96 AssertBreak(cbDst >= cbSrc);
97
98 /* Enough data for at least one next frame? */
99 if (cbSrc < pChan->cbFrame)
100 break;
101
102 memcpy(pvDst, pvSrc, pChan->cbFrame);
103
104 /* Advance to next channel frame in stream. */
105 pvSrc += pChan->cbStep;
106 Assert(cbSrc >= pChan->cbStep);
107 cbSrc -= pChan->cbStep;
108
109 /* Advance destination by one frame. */
110 pvDst += pChan->cbFrame;
111 Assert(cbDst >= pChan->cbFrame);
112 cbDst -= pChan->cbFrame;
113
114 /* Adjust offset. */
115 pChan->cbOff += pChan->cbFrame;
116 }
117
118 RTCircBufReleaseWriteBlock(pChan->Data.pCircBuf, cbDst);
119
120 return VINF_SUCCESS;
121}
122
123/**
124 * Advances the current read / write pointer by a certain amount.
125 *
126 * @returns IPRT status code.
127 * @param pChan Channel data to advance read / write pointer for.
128 * @param cbAdv Amount (in bytes) to advance read / write pointer.
129 *
130 * @remark Currently not used / implemented.
131 */
132int hdaR3StreamChannelAdvance(PPDMAUDIOSTREAMCHANNEL pChan, size_t cbAdv)
133{
134 AssertPtrReturn(pChan, VERR_INVALID_POINTER);
135
136 if (!cbAdv)
137 return VINF_SUCCESS;
138
139 return VINF_SUCCESS;
140}
141
142/**
143 * Acquires (reads) audio channel data.
144 * Must be released when done with hdaR3StreamChannelReleaseData().
145 *
146 * @returns IPRT status code.
147 * @param pChanData Channel data to acquire audio channel data from.
148 * @param ppvData Where to store the pointer to the acquired data.
149 * @param pcbData Size (in bytes) of acquired data.
150 */
151int hdaR3StreamChannelAcquireData(PPDMAUDIOSTREAMCHANNELDATA pChanData, void **ppvData, size_t *pcbData)
152{
153 AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
154 AssertPtrReturn(ppvData, VERR_INVALID_POINTER);
155 AssertPtrReturn(pcbData, VERR_INVALID_POINTER);
156
157 RTCircBufAcquireReadBlock(pChanData->pCircBuf, 256 /** @todo Make this configurarble? */, ppvData, &pChanData->cbAcq);
158
159 *pcbData = pChanData->cbAcq;
160 return VINF_SUCCESS;
161}
162
163/**
164 * Releases formerly acquired data by hdaR3StreamChannelAcquireData().
165 *
166 * @returns IPRT status code.
167 * @param pChanData Channel data to release formerly acquired data for.
168 */
169int hdaR3StreamChannelReleaseData(PPDMAUDIOSTREAMCHANNELDATA pChanData)
170{
171 AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
172 RTCircBufReleaseReadBlock(pChanData->pCircBuf, pChanData->cbAcq);
173
174 return VINF_SUCCESS;
175}
176
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