Changeset 73392 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jul 30, 2018 12:02:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostDSound.cpp
r73380 r73392 1151 1151 1152 1152 /** 1153 * Transfers audio data from the DirectSound capture instance to the internal buffer. 1154 * Due to internal accounting and querying DirectSound, this function knows how much it can transfer at once. 1155 * 1156 * @return IPRT status code. 1157 * @param pThis Host audio driver instance. 1158 */ 1159 static int dsoundCaptureTransfer(PDRVHOSTDSOUND pThis) 1160 { 1161 PDSOUNDSTREAM pStreamDS = pThis->pDSStrmIn; 1162 AssertPtr(pStreamDS); 1163 1164 LPDIRECTSOUNDCAPTUREBUFFER8 pDSCB = pStreamDS->In.pDSCB; 1165 AssertPtr(pDSCB); 1166 1167 DWORD offCaptureCursor; 1168 HRESULT hr = IDirectSoundCaptureBuffer_GetCurrentPosition(pDSCB, NULL, &offCaptureCursor); 1169 if (FAILED(hr)) 1170 return VERR_ACCESS_DENIED; /** @todo Find a better rc. */ 1171 1172 DWORD cbUsed = dsoundRingDistance(offCaptureCursor, pStreamDS->In.offReadPos, pStreamDS->cbBufSize); 1173 1174 PRTCIRCBUF pCircBuf = pStreamDS->pCircBuf; 1175 AssertPtr(pCircBuf); 1176 1177 uint32_t cbFree = (uint32_t)RTCircBufFree(pCircBuf); 1178 if ( !cbFree 1179 || pStreamDS->In.cOverruns < 32) /** @todo Make this configurable. */ 1180 { 1181 DSLOG(("DSound: Warning: Capture buffer full, skipping to record data (%RU32 bytes)\n", cbUsed)); 1182 pStreamDS->In.cOverruns++; 1183 } 1184 1185 DWORD cbToCapture = RT_MIN(cbUsed, cbFree); 1186 1187 Log3Func(("cbUsed=%ld, cbToCapture=%ld\n", cbUsed, cbToCapture)); 1188 1189 while (cbToCapture) 1190 { 1191 void *pvBuf; 1192 size_t cbBuf; 1193 RTCircBufAcquireWriteBlock(pCircBuf, cbToCapture, &pvBuf, &cbBuf); 1194 1195 if (cbBuf) 1196 { 1197 PVOID pv1, pv2; 1198 DWORD cb1, cb2; 1199 hr = directSoundCaptureLock(pStreamDS, pStreamDS->In.offReadPos, (DWORD)cbBuf, 1200 &pv1, &pv2, &cb1, &cb2, 0 /* dwFlags */); 1201 if (FAILED(hr)) 1202 break; 1203 1204 AssertPtr(pv1); 1205 Assert(cb1); 1206 1207 memcpy(pvBuf, pv1, cb1); 1208 1209 if (pv2 && cb2) /* Buffer wrap-around? Write second part. */ 1210 memcpy((uint8_t *)pvBuf + cb1, pv2, cb2); 1211 1212 directSoundCaptureUnlock(pDSCB, pv1, pv2, cb1, cb2); 1213 1214 pStreamDS->In.offReadPos = (pStreamDS->In.offReadPos + cb1 + cb2) % pStreamDS->cbBufSize; 1215 1216 Assert(cbToCapture >= cbBuf); 1217 cbToCapture -= (uint32_t)cbBuf; 1218 } 1219 1220 #ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA 1221 if (cbBuf) 1222 { 1223 RTFILE fh; 1224 int rc2 = RTFileOpen(&fh, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "dsoundCapture.pcm", 1225 RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE); 1226 if (RT_SUCCESS(rc2)) 1227 { 1228 RTFileWrite(fh, pvBuf, cbBuf, NULL); 1229 RTFileClose(fh); 1230 } 1231 } 1232 #endif 1233 RTCircBufReleaseWriteBlock(pCircBuf, cbBuf); 1234 } 1235 1236 return VINF_SUCCESS; 1237 } 1238 1239 /** 1153 1240 * Destroys the DirectSound capturing interface. 1154 1241 * … … 2261 2348 AssertPtrReturn(pStream, VERR_INVALID_POINTER); 2262 2349 2263 /* Nothing to do here for DSound. */ 2350 PDRVHOSTDSOUND pThis = PDMIHOSTAUDIO_2_DRVHOSTDSOUND(pInterface); 2351 PDSOUNDSTREAM pStreamDS = (PDSOUNDSTREAM)pStream; 2352 2353 if (pStreamDS->Cfg.enmDir == PDMAUDIODIR_IN) 2354 return dsoundCaptureTransfer(pThis); 2355 2264 2356 return VINF_SUCCESS; 2265 2357 }
Note:
See TracChangeset
for help on using the changeset viewer.