1 | /* $Id: HDAStreamChannel.cpp 82252 2019-11-27 21:31:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * HDAStreamChannel.cpp - Stream channel functions for HD Audio.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2017-2019 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 | */
|
---|
37 | int 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 | */
|
---|
53 | void 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_FLAGS_NONE;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Acquires (reads) audio channel data.
|
---|
69 | * Must be released when done with hdaR3StreamChannelReleaseData().
|
---|
70 | *
|
---|
71 | * @returns IPRT status code.
|
---|
72 | * @param pChanData Channel data to acquire audio channel data from.
|
---|
73 | * @param ppvData Where to store the pointer to the acquired data.
|
---|
74 | * @param pcbData Size (in bytes) of acquired data.
|
---|
75 | */
|
---|
76 | int hdaR3StreamChannelAcquireData(PPDMAUDIOSTREAMCHANNELDATA pChanData, void **ppvData, size_t *pcbData)
|
---|
77 | {
|
---|
78 | AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
|
---|
79 | AssertPtrReturn(ppvData, VERR_INVALID_POINTER);
|
---|
80 | AssertPtrReturn(pcbData, VERR_INVALID_POINTER);
|
---|
81 |
|
---|
82 | RTCircBufAcquireReadBlock(pChanData->pCircBuf, 256 /** @todo Make this configurarble? */, ppvData, &pChanData->cbAcq);
|
---|
83 |
|
---|
84 | *pcbData = pChanData->cbAcq;
|
---|
85 | return VINF_SUCCESS;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Releases formerly acquired data by hdaR3StreamChannelAcquireData().
|
---|
90 | *
|
---|
91 | * @returns IPRT status code.
|
---|
92 | * @param pChanData Channel data to release formerly acquired data for.
|
---|
93 | */
|
---|
94 | int hdaR3StreamChannelReleaseData(PPDMAUDIOSTREAMCHANNELDATA pChanData)
|
---|
95 | {
|
---|
96 | AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
|
---|
97 | RTCircBufReleaseReadBlock(pChanData->pCircBuf, pChanData->cbAcq);
|
---|
98 |
|
---|
99 | return VINF_SUCCESS;
|
---|
100 | }
|
---|
101 |
|
---|