Changeset 75962 in vbox for trunk/src/VBox/Devices/Audio/HDAStreamMap.cpp
- Timestamp:
- Dec 5, 2018 9:34:58 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/HDAStreamMap.cpp
r73529 r75962 5 5 6 6 /* 7 * Copyright (C) 2017 Oracle Corporation7 * Copyright (C) 2017-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 #ifdef IN_RING3 36 36 37 static int hdaR3StreamMapSetup(PHDASTREAMMAP pMap, PPDMAUDIOPCMPROPS pProps); 38 37 39 /** 38 40 * Initializes a stream mapping structure according to the given PCM properties. 39 41 * 40 42 * @return IPRT status code. 41 * @param pMap pingPointer to mapping to initialize.43 * @param pMap Pointer to mapping to initialize. 42 44 * @param pProps Pointer to PCM properties to use for initialization. 43 45 */ 44 int hdaR3StreamMapInit(PHDASTREAMMAP PING pMapping, PPDMAUDIOPCMPROPS pProps)46 int hdaR3StreamMapInit(PHDASTREAMMAP pMap, PPDMAUDIOPCMPROPS pProps) 45 47 { 46 AssertPtrReturn(pMap ping, VERR_INVALID_POINTER);48 AssertPtrReturn(pMap, VERR_INVALID_POINTER); 47 49 AssertPtrReturn(pProps, VERR_INVALID_POINTER); 48 50 … … 50 52 return VERR_INVALID_PARAMETER; 51 53 52 hdaR3StreamMapReset(pMap ping);54 hdaR3StreamMapReset(pMap); 53 55 54 pMapping->paChannels = (PPDMAUDIOSTREAMCHANNEL)RTMemAlloc(sizeof(PDMAUDIOSTREAMCHANNEL) * pProps->cChannels);55 if ( !pMapping->paChannels)56 return VERR_NO_MEMORY;56 int rc = hdaR3StreamMapSetup(pMap, pProps); 57 if (RT_FAILURE(rc)) 58 return rc; 57 59 58 int rc = VINF_SUCCESS; 59 60 Assert(RT_IS_POWER_OF_TWO(pProps->cBytes * 8)); 61 62 /** @todo We assume all channels in a stream have the same format. */ 63 PPDMAUDIOSTREAMCHANNEL pChan = pMapping->paChannels; 64 for (uint8_t i = 0; i < pProps->cChannels; i++) 65 { 66 pChan->uChannel = i; 67 pChan->cbStep = pProps->cBytes; 68 pChan->cbFrame = pChan->cbStep * pProps->cChannels; 69 pChan->cbFirst = i * pChan->cbStep; 70 pChan->cbOff = pChan->cbFirst; 71 72 int rc2 = hdaR3StreamChannelDataInit(&pChan->Data, PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE); 73 if (RT_SUCCESS(rc)) 74 rc = rc2; 75 76 if (RT_FAILURE(rc)) 77 break; 78 79 pChan++; 80 } 81 60 #ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND 82 61 if ( RT_SUCCESS(rc) 83 62 /* Create circular buffer if not created yet. */ 84 && !pMap ping->pCircBuf)63 && !pMap->pCircBuf) 85 64 { 86 rc = RTCircBufCreate(&pMap ping->pCircBuf, _4K); /** @todo Make size configurable? */65 rc = RTCircBufCreate(&pMap->pCircBuf, _4K); /** @todo Make size configurable? */ 87 66 } 67 #endif 88 68 89 69 if (RT_SUCCESS(rc)) 90 70 { 91 pMapping->cChannels = pProps->cChannels; 92 #ifdef VBOX_WITH_HDA_AUDIO_INTERLEAVING_STREAMS_SUPPORT 93 pMapping->enmLayout = PDMAUDIOSTREAMLAYOUT_INTERLEAVED; 94 #else 95 pMapping->enmLayout = PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED; 96 #endif 71 pMap->cbFrameSize = pProps->cChannels * pProps->cBytes; 72 73 LogFunc(("cChannels=%RU8, cBytes=%RU8 -> cbFrameSize=%RU32\n", 74 pProps->cChannels, pProps->cBytes, pMap->cbFrameSize)); 75 76 Assert(pMap->cbFrameSize); /* Frame size must not be 0. */ 77 78 pMap->enmLayout = PDMAUDIOSTREAMLAYOUT_INTERLEAVED; 97 79 } 98 80 … … 104 86 * Destroys a given stream mapping. 105 87 * 106 * @param pMap pingPointer to mapping to destroy.88 * @param pMap Pointer to mapping to destroy. 107 89 */ 108 void hdaR3StreamMapDestroy(PHDASTREAMMAP PING pMapping)90 void hdaR3StreamMapDestroy(PHDASTREAMMAP pMap) 109 91 { 110 hdaR3StreamMapReset(pMap ping);92 hdaR3StreamMapReset(pMap); 111 93 112 if (pMapping->pCircBuf) 94 #ifdef VBOX_WITH_AUDIO_HDA_51_SURROUND 95 if (pMap->pCircBuf) 113 96 { 114 RTCircBufDestroy(pMap ping->pCircBuf);115 pMap ping->pCircBuf = NULL;97 RTCircBufDestroy(pMap->pCircBuf); 98 pMap->pCircBuf = NULL; 116 99 } 100 #endif 117 101 } 118 102 … … 121 105 * Resets a given stream mapping. 122 106 * 123 * @param pMap pingPointer to mapping to reset.107 * @param pMap Pointer to mapping to reset. 124 108 */ 125 void hdaR3StreamMapReset(PHDASTREAMMAP PING pMapping)109 void hdaR3StreamMapReset(PHDASTREAMMAP pMap) 126 110 { 127 AssertPtrReturnVoid(pMap ping);111 AssertPtrReturnVoid(pMap); 128 112 129 pMap ping->enmLayout = PDMAUDIOSTREAMLAYOUT_UNKNOWN;113 pMap->enmLayout = PDMAUDIOSTREAMLAYOUT_UNKNOWN; 130 114 131 if (pMap ping->cChannels)115 if (pMap->paMappings) 132 116 { 133 for (uint8_t i = 0; i < pMap ping->cChannels; i++)134 hdaR3StreamChannelDataDestroy(&pMap ping->paChannels[i].Data);117 for (uint8_t i = 0; i < pMap->cMappings; i++) 118 hdaR3StreamChannelDataDestroy(&pMap->paMappings[i].Data); 135 119 136 AssertPtr(pMapping->paChannels); 137 RTMemFree(pMapping->paChannels); 138 pMapping->paChannels = NULL; 120 RTMemFree(pMap->paMappings); 121 pMap->paMappings = NULL; 139 122 140 pMap ping->cChannels = 0;123 pMap->cMappings = 0; 141 124 } 142 125 } 143 126 127 128 /** 129 * Sets up a stream mapping according to the given properties / configuration. 130 * 131 * @return VBox status code, or VERR_NOT_SUPPORTED if the channel setup is not supported (yet). 132 * @param pMap Pointer to mapping to set up. 133 * @param pProps PCM audio properties to use for lookup. 134 */ 135 static int hdaR3StreamMapSetup(PHDASTREAMMAP pMap, PPDMAUDIOPCMPROPS pProps) 136 { 137 int rc; 138 139 /** @todo We ASSUME that all channels in a stream ... 140 * - have the same format 141 * - are in a consecutive order with no gaps in between 142 * - have a simple (raw) data layout 143 * - work in a non-striped fashion, e.g. interleaved (only on one SDn, not spread over multiple SDns) */ 144 if ( pProps->cChannels == 1 /* Mono */ 145 || pProps->cChannels == 2 /* Stereo */ 146 || pProps->cChannels == 4 /* Quadrophonic */ 147 || pProps->cChannels == 6) /* Surround (5.1) */ 148 { 149 /* For now we don't have anything other as mono / stereo channels being covered by the backends. 150 * So just set up one channel covering those and skipping the rest (like configured rear or center/LFE outputs). */ 151 pMap->cMappings = 1; 152 pMap->paMappings = (PPDMAUDIOSTREAMMAP)RTMemAlloc(sizeof(PDMAUDIOSTREAMMAP) * pMap->cMappings); 153 if (!pMap->paMappings) 154 return VERR_NO_MEMORY; 155 156 PPDMAUDIOSTREAMMAP pMapLR = &pMap->paMappings[0]; 157 158 pMapLR->aID[0] = PDMAUDIOSTREAMCHANNELID_FRONT_LEFT; 159 pMapLR->aID[1] = PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT; 160 pMapLR->cbFrame = pProps->cBytes * pProps->cChannels; 161 pMapLR->cbSize = pProps->cBytes * 2 /* Front left + Front right channels */; 162 pMapLR->cbFirst = 0; 163 pMapLR->cbOff = pMapLR->cbFirst; 164 165 rc = hdaR3StreamChannelDataInit(&pMapLR->Data, PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE); 166 AssertRC(rc); 167 } 168 else 169 rc = VERR_NOT_SUPPORTED; /** @todo r=andy Support more setups. */ 170 171 return rc; 172 } 144 173 #endif /* IN_RING3 */ 145 174
Note:
See TracChangeset
for help on using the changeset viewer.