VirtualBox

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

Last change on this file since 67751 was 67698, checked in by vboxsync, 8 years ago

Audio/HDA: Split out StreamMap and StreamChannel functions in own files for easier maintenance.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/* $Id: HDAStreamChannel.cpp 67698 2017-06-29 13:58:29Z 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* Header Files *
20*********************************************************************************************************************************/
21#define LOG_GROUP LOG_GROUP_DEV_HDA
22#include <VBox/log.h>
23
24#include <VBox/vmm/pdmdev.h>
25#include <VBox/vmm/pdmaudioifs.h>
26
27#include "HDAStreamChannel.h"
28
29int hdaStreamChannelDataInit(PPDMAUDIOSTREAMCHANNELDATA pChanData, uint32_t fFlags)
30{
31 int rc = RTCircBufCreate(&pChanData->pCircBuf, 256); /** @todo Make this configurable? */
32 if (RT_SUCCESS(rc))
33 {
34 pChanData->fFlags = fFlags;
35 }
36
37 return rc;
38}
39
40/**
41 * Frees a stream channel data block again.
42 *
43 * @param pChanData Pointer to channel data to free.
44 */
45void hdaStreamChannelDataDestroy(PPDMAUDIOSTREAMCHANNELDATA pChanData)
46{
47 if (!pChanData)
48 return;
49
50 if (pChanData->pCircBuf)
51 {
52 RTCircBufDestroy(pChanData->pCircBuf);
53 pChanData->pCircBuf = NULL;
54 }
55
56 pChanData->fFlags = PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE;
57}
58
59int hdaStreamChannelExtract(PPDMAUDIOSTREAMCHANNEL pChan, const void *pvBuf, size_t cbBuf)
60{
61 AssertPtrReturn(pChan, VERR_INVALID_POINTER);
62 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
63 AssertReturn(cbBuf, VERR_INVALID_PARAMETER);
64
65 AssertRelease(pChan->cbOff <= cbBuf);
66
67 const uint8_t *pu8Buf = (const uint8_t *)pvBuf;
68
69 size_t cbSrc = cbBuf - pChan->cbOff;
70 const uint8_t *pvSrc = &pu8Buf[pChan->cbOff];
71
72 size_t cbDst;
73 uint8_t *pvDst;
74 RTCircBufAcquireWriteBlock(pChan->Data.pCircBuf, cbBuf, (void **)&pvDst, &cbDst);
75
76 cbSrc = RT_MIN(cbSrc, cbDst);
77
78 while (cbSrc)
79 {
80 AssertBreak(cbDst >= cbSrc);
81
82 /* Enough data for at least one next frame? */
83 if (cbSrc < pChan->cbFrame)
84 break;
85
86 memcpy(pvDst, pvSrc, pChan->cbFrame);
87
88 /* Advance to next channel frame in stream. */
89 pvSrc += pChan->cbStep;
90 Assert(cbSrc >= pChan->cbStep);
91 cbSrc -= pChan->cbStep;
92
93 /* Advance destination by one frame. */
94 pvDst += pChan->cbFrame;
95 Assert(cbDst >= pChan->cbFrame);
96 cbDst -= pChan->cbFrame;
97
98 /* Adjust offset. */
99 pChan->cbOff += pChan->cbFrame;
100 }
101
102 RTCircBufReleaseWriteBlock(pChan->Data.pCircBuf, cbDst);
103
104 return VINF_SUCCESS;
105}
106
107int hdaStreamChannelAdvance(PPDMAUDIOSTREAMCHANNEL pChan, size_t cbAdv)
108{
109 AssertPtrReturn(pChan, VERR_INVALID_POINTER);
110
111 if (!cbAdv)
112 return VINF_SUCCESS;
113
114 return VINF_SUCCESS;
115}
116
117int hdaStreamChannelAcquireData(PPDMAUDIOSTREAMCHANNELDATA pChanData, void *pvData, size_t *pcbData)
118{
119 AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
120 AssertPtrReturn(pvData, VERR_INVALID_POINTER);
121 AssertPtrReturn(pcbData, VERR_INVALID_POINTER);
122
123 RTCircBufAcquireReadBlock(pChanData->pCircBuf, 256 /** @todo Make this configurarble? */, &pvData, &pChanData->cbAcq);
124
125 *pcbData = pChanData->cbAcq;
126 return VINF_SUCCESS;
127}
128
129int hdaStreamChannelReleaseData(PPDMAUDIOSTREAMCHANNELDATA pChanData)
130{
131 AssertPtrReturn(pChanData, VERR_INVALID_POINTER);
132 RTCircBufReleaseReadBlock(pChanData->pCircBuf, pChanData->cbAcq);
133
134 return VINF_SUCCESS;
135}
136
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