- while (lengthIter > 0) {
- size_t l;
-
- while (__mpSyncReadDataPtr == NULL) {
- ret = mpPulseAudioClient->peek(&__mpSyncReadDataPtr, &__mSyncReadLength);
- if (ret != 0) {
- THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INTERNAL_OPERATION, "Failed CPulseAudioClient::peek() ret:[%d]", ret);
- }
-
- if (__mSyncReadLength <= 0) {
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD("readLength(%d byte) is not valid.. wait..", __mSyncReadLength);
-#endif
- internalWait();
- } else if (__mpSyncReadDataPtr == NULL) {
- /* There's a hole in the stream, skip it. We could generate
- * silence, but that wouldn't work for compressed streams.
- */
- ret = mpPulseAudioClient->drop();
- if (ret != 0) {
- THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INTERNAL_OPERATION, "Failed CPulseAudioClient::drop() ret:[%d]", ret);
- }
- } else {
- __mSyncReadIndex = 0;
- }
- }//end of while (pReadData == NULL)
-
- if (__mSyncReadLength < lengthIter) {
- l = __mSyncReadLength;
- } else {
- l = lengthIter;
- }
-
- // Copy partial pcm data on out parameter
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD("memcpy() that a peeked buffer(%p), index(%d), length(%d), on out buffer", (const uint8_t*)(__mpSyncReadDataPtr) + __mSyncReadIndex, __mSyncReadIndex, l);
-#endif
- memcpy(buffer, (const uint8_t*)__mpSyncReadDataPtr + __mSyncReadIndex, l);
-
- // Move next position
- buffer = (uint8_t*)buffer + l;
- lengthIter -= l;
-
- // Adjusts the rest length
- __mSyncReadIndex += l;
- __mSyncReadLength -= l;
-
- if (__mSyncReadLength == 0) {
-#ifdef _AUDIO_IO_DEBUG_TIMING_
- AUDIO_IO_LOGD("__mSyncReadLength is zero - Do drop()");
-#endif
- ret = mpPulseAudioClient->drop();
- if (ret != 0) {
- THROW_ERROR_MSG_FORMAT(CAudioError::ERROR_INTERNAL_OPERATION, "Failed CPulseAudioClient::drop() ret:[%d]", ret);
- }
-
- // Reset the internal pointer
- __mpSyncReadDataPtr = NULL;
- __mSyncReadLength = 0;
- __mSyncReadIndex = 0;
- }
- } // End of while (length > 0)