儲存庫 vbox 的更動 67367
- 時間撮記:
- 2017-6-13 下午02:21:32 (7 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp
r65636 r67367 48 48 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 2 /* Channels */), /* Shift */ 49 49 2, /* Channels */ 50 0, /* Alignment mask */ 50 51 44100, /* Hz */ 51 52 false /* Swap Endian */ … … 76 77 /* int64_t samples64[2] = { 0xEE, 0xFF }; - unused */ 77 78 78 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 , &samples8, sizeof(samples8), &cSamplesWritten));79 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &samples8, sizeof(samples8), &cSamplesWritten)); 79 80 RTTESTI_CHECK(cSamplesWritten == 0 /* Samples */); 80 81 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0, &samples16, sizeof(samples16), &cSamplesWritten)); 81 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 0); 82 83 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, &samples16, sizeof(samples16), &cSamplesWritten)); 82 84 RTTESTI_CHECK(cSamplesWritten == 1 /* Samples */); 83 84 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2, &samples32, sizeof(samples32), &cSamplesWritten)); 85 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 1); 86 87 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &samples32, sizeof(samples32), &cSamplesWritten)); 85 88 RTTESTI_CHECK(cSamplesWritten == 2 /* Samples */); 86 cSamplesWrittenAbs = 0;89 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2); 87 90 88 91 /* Beyond buffer. */ 89 92 RTTESTI_CHECK_RC(AudioMixBufWriteAt(&mb, AudioMixBufSize(&mb) + 1, &samples16, sizeof(samples16), 90 &cSamplesWritten), VINF_BUFFER_OVERFLOW); 91 /** @todo (bird): this was checking for VERR_BUFFER_OVERFLOW, which do you want 92 * the function to actually return? */ 93 &cSamplesWritten), VERR_BUFFER_OVERFLOW); 94 95 /* Offset wrap-around: When writing as much (or more) samples the mixing buffer can hold. */ 96 size_t cbSamples = cBufSize * sizeof(int16_t) * 2 /* Channels */; 97 RTTESTI_CHECK(cbSamples); 98 uint16_t *paSamples = (uint16_t *)RTMemAlloc(cbSamples); 99 RTTESTI_CHECK(paSamples); 100 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 0 /* Offset */, paSamples, cbSamples, &cSamplesWritten)); 101 RTTESTI_CHECK(cSamplesWritten == cBufSize /* Samples */); 102 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize); 103 RTTESTI_CHECK(AudioMixBufReadPos(&mb) == 0); 104 RTTESTI_CHECK(AudioMixBufWritePos(&mb) == 0); 105 RTMemFree(paSamples); 106 cbSamples = 0; 93 107 94 108 /* 95 109 * Circular writes. 96 110 */ 111 AudioMixBufReset(&mb); 112 113 RTTESTI_CHECK_RC_OK(AudioMixBufWriteAt(&mb, 2 /* Offset */, &samples32, sizeof(samples32), &cSamplesWritten)); 114 RTTESTI_CHECK(cSamplesWritten == 2 /* Samples */); 115 RTTESTI_CHECK(AudioMixBufUsed(&mb) == 2); 116 117 cSamplesWrittenAbs = AudioMixBufUsed(&mb); 118 97 119 uint32_t cToWrite = AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1; /* -1 as padding plus -2 samples for above. */ 98 120 for (uint32_t i = 0; i < cToWrite; i++) … … 114 136 /* Circular reads. */ 115 137 uint32_t cToRead = AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1; 116 for (uint32_t i = 0; i < cTo Write; i++)138 for (uint32_t i = 0; i < cToRead; i++) 117 139 { 118 140 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &cSamplesRead)); … … 123 145 RTTESTI_CHECK(AudioMixBufFree(&mb) == AudioMixBufSize(&mb) - cSamplesWrittenAbs - 1); 124 146 RTTESTI_CHECK(AudioMixBufFreeBytes(&mb) == AUDIOMIXBUF_S2B(&mb, cBufSize - cSamplesWrittenAbs - 1)); 125 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize - cToRead + cSamplesWrittenAbs);147 RTTESTI_CHECK(AudioMixBufUsed(&mb) == cBufSize - cToRead); 126 148 127 149 RTTESTI_CHECK_RC_OK(AudioMixBufReadCirc(&mb, &samples16, sizeof(samples16), &cSamplesRead)); … … 139 161 static int tstParentChild(RTTEST hTest) 140 162 { 141 uint32_t cSamples = 16; 142 uint32_t cBufSize = RTRandU32Ex(cSamples /* Min */, 256 /* Max */); 163 uint32_t cParentBufSize = RTRandU32Ex(_1K /* Min */, _16K /* Max */); /* Enough room for random sizes */ 143 164 144 165 /* 44100Hz, 2 Channels, S16 */ … … 149 170 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 2 /* Channels */), /* Shift */ 150 171 2, /* Channels */ 172 0, /* Alignment mask */ 151 173 44100, /* Hz */ 152 174 false /* Swap Endian */ … … 156 178 157 179 PDMAUDIOMIXBUF parent; 158 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &cfg_p, c BufSize));180 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&parent, "Parent", &cfg_p, cParentBufSize)); 159 181 160 182 /* 22050Hz, 2 Channels, S16 */ … … 165 187 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 2 /* Channels */), /* Shift */ 166 188 2, /* Channels */ 189 0, /* Alignment mask */ 167 190 22050, /* Hz */ 168 191 false /* Swap Endian */ … … 171 194 RTTESTI_CHECK(DrvAudioHlpPCMPropsAreValid(&cfg_c1)); 172 195 196 uint32_t cSamples = 16; 197 uint32_t cChildBufSize = RTRandU32Ex(cSamples /* Min */, 64 /* Max */); 198 173 199 PDMAUDIOMIXBUF child1; 174 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child1, "Child1", &cfg_c1, c BufSize));200 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child1, "Child1", &cfg_c1, cChildBufSize)); 175 201 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child1, &parent)); 176 202 … … 182 208 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 2 /* Channels */), /* Shift */ 183 209 2, /* Channels */ 210 0, /* Alignment mask */ 184 211 48000, /* Hz */ 185 212 false /* Swap Endian */ … … 189 216 190 217 PDMAUDIOMIXBUF child2; 191 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child2, "Child2", &cfg_c2, c BufSize));218 RTTESTI_CHECK_RC_OK(AudioMixBufInit(&child2, "Child2", &cfg_c2, cChildBufSize)); 192 219 RTTESTI_CHECK_RC_OK(AudioMixBufLinkTo(&child2, &parent)); 193 220 … … 203 230 uint32_t cSamplesChild2 = cSamples; 204 231 205 uint32_t t = RTRandU32() % 1024; 206 207 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "%RU32 iterations total\n", t); 232 uint32_t t = RTRandU32() % 32; 233 234 RTTestPrintf(hTest, RTTESTLVL_DEBUG, 235 "cParentBufSize=%RU32, cChildBufSize=%RU32, %RU32 samples -> %RU32 iterations total\n", 236 cParentBufSize, cChildBufSize, cSamples, t); 208 237 209 238 /* … … 212 241 RTTestSubF(hTest, "2 Children -> Parent (AudioMixBufWriteAt)"); 213 242 243 uint32_t cChildrenSamplesMixedTotal = 0; 244 214 245 for (uint32_t i = 0; i < t; i++) 215 246 { 216 247 RTTestPrintf(hTest, RTTESTLVL_DEBUG, "i=%RU32\n", i); 217 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &samples, sizeof(samples), &cSamplesWritten)); 218 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild1, ("Child1: Expected %RU32 written samples, got %RU32\n", cSamplesChild1, cSamplesWritten)); 219 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, cSamplesWritten, &cSamplesMixed)); 220 RTTESTI_CHECK_MSG_BREAK(AudioMixBufLive(&child1) == cSamplesMixed, ("Child1: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child1), cSamplesMixed)); 221 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == AUDIOMIXBUF_S2S_RATIO(&parent, cSamplesMixed), ("Child1: Expected %RU32 used samples, got %RU32\n", AudioMixBufLive(&child1), AUDIOMIXBUF_S2S_RATIO(&parent, cSamplesMixed))); 222 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&parent) == 0, ("Parent: Expected 0 used samples, got %RU32\n", AudioMixBufUsed(&parent))); 223 224 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &samples, sizeof(samples), &cSamplesWritten)); 225 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild2, ("Child2: Expected %RU32 written samples, got %RU32\n", cSamplesChild2, cSamplesWritten)); 226 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, cSamplesWritten, &cSamplesMixed)); 227 RTTESTI_CHECK_MSG_BREAK(AudioMixBufLive(&child2) == cSamplesMixed, ("Child2: Expected %RU32 mixed samples, got %RU32\n", AudioMixBufLive(&child2), AudioMixBufUsed(&parent))); 228 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == AUDIOMIXBUF_S2S_RATIO(&parent, cSamplesMixed), ("Child2: Expected %RU32 used samples, got %RU32\n", AudioMixBufLive(&child2), AUDIOMIXBUF_S2S_RATIO(&parent, cSamplesMixed))); 229 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&parent) == 0, ("Parent2: Expected 0 used samples, got %RU32\n", AudioMixBufUsed(&parent))); 230 } 231 232 RTTESTI_CHECK(AudioMixBufUsed(&parent) == AudioMixBufLive(&child1) + AudioMixBufLive(&child2)); 233 234 for (;;) 235 { 236 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &cSamplesRead)); 237 if (!cSamplesRead) 238 break; 239 AudioMixBufFinish(&parent, cSamplesRead); 248 249 uint32_t cChild1Writes = RTRandU32() % 8; 250 251 for (uint32_t c1 = 0; c1 < cChild1Writes; c1++) 252 { 253 /* Child 1. */ 254 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child1, 0, &samples, sizeof(samples), &cSamplesWritten)); 255 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild1, ("Child1: Expected %RU32 written samples, got %RU32\n", cSamplesChild1, cSamplesWritten)); 256 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child1, cSamplesWritten, &cSamplesMixed)); 257 258 cChildrenSamplesMixedTotal += cSamplesMixed; 259 260 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesMixed, ("Child1: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed)); 261 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child1) == 0, ("Child1: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child1))); 262 } 263 264 uint32_t cChild2Writes = RTRandU32() % 8; 265 266 for (uint32_t c2 = 0; c2 < cChild2Writes; c2++) 267 { 268 /* Child 2. */ 269 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufWriteAt(&child2, 0, &samples, sizeof(samples), &cSamplesWritten)); 270 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesChild2, ("Child2: Expected %RU32 written samples, got %RU32\n", cSamplesChild2, cSamplesWritten)); 271 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufMixToParent(&child2, cSamplesWritten, &cSamplesMixed)); 272 273 cChildrenSamplesMixedTotal += cSamplesMixed; 274 275 RTTESTI_CHECK_MSG_BREAK(cSamplesWritten == cSamplesMixed, ("Child2: Expected %RU32 mixed samples, got %RU32\n", cSamplesWritten, cSamplesMixed)); 276 RTTESTI_CHECK_MSG_BREAK(AudioMixBufUsed(&child2) == 0, ("Child2: Expected %RU32 used samples, got %RU32\n", 0, AudioMixBufUsed(&child2))); 277 } 278 279 /* 280 * Read out all samples from the parent buffer and also mark the just-read samples as finished 281 * so that both connected children buffers can keep track of their stuff. 282 */ 283 uint32_t cParentSamples = AudioMixBufUsed(&parent); 284 while (cParentSamples) 285 { 286 RTTESTI_CHECK_RC_OK_BREAK(AudioMixBufReadCirc(&parent, pvBuf, cbBuf, &cSamplesRead)); 287 if (!cSamplesRead) 288 break; 289 290 AudioMixBufFinish(&parent, cSamplesRead); 291 292 RTTESTI_CHECK(cParentSamples >= cSamplesRead); 293 cParentSamples -= cSamplesRead; 294 } 295 296 RTTESTI_CHECK(cParentSamples == 0); 240 297 } 241 298 … … 266 323 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(8 /* Bits */, 1 /* Channels */), /* Shift */ 267 324 1, /* Channels */ 325 0, /* Alignment mask */ 268 326 44100, /* Hz */ 269 327 false /* Swap Endian */ … … 290 348 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(8 /* Bits */, 1 /* Channels */), /* Shift */ 291 349 1, /* Channels */ 350 0, /* Alignment mask */ 292 351 22050, /* Hz */ 293 352 false /* Swap Endian */ … … 372 431 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 1 /* Channels */), /* Shift */ 373 432 1, /* Channels */ 433 0, /* Alignment mask */ 374 434 44100, /* Hz */ 375 435 false /* Swap Endian */ … … 388 448 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 1 /* Channels */), /* Shift */ 389 449 1, /* Channels */ 450 0, /* Alignment mask */ 390 451 22050, /* Hz */ 391 452 false /* Swap Endian */ … … 470 531 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(16 /* Bits */, 2 /* Channels */), /* Shift */ 471 532 2, /* Channels */ 533 0, /* Alignment mask */ 472 534 44100, /* Hz */ 473 535 false /* Swap Endian */
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器