uint32_t nsNativeAudioStream::Available() { // If the audio backend failed to open, lie and say we'll accept some // data. if (mInError) return FAKE_BUFFER_SIZE; size_t s = 0; if (sa_stream_get_write_size(static_cast<sa_stream_t*>(mAudioHandle), &s) != SA_SUCCESS) return 0; return s / mChannels / sizeof(short); }
int sa_stream_drain(sa_stream_t *s) { if (s == NULL || s->output_unit == NULL) { return SA_ERROR_NO_INIT; } /* There is no way with the Android SDK to determine exactly how long to playback. So estimate and sleep for the long. */ size_t available; sa_stream_get_write_size(s, &available); long x = (s->bufferSize - available) * 1000 / s->channels / s->rate / sizeof(int16_t) * NANOSECONDS_IN_MILLISECOND; ALOG("%x - Drain - sleep for %f ns", s, x); struct timespec ts = {0, x}; nanosleep(&ts, NULL); return SA_SUCCESS; }