Esempio n. 1
0
bool
AlsaSource::WriteRW ()
{
	snd_pcm_sframes_t avail;
	snd_pcm_sframes_t commitres = 0;
	guint32 frames;
	void *buffer;
	
	if (GetState () != AudioPlaying) {
		LOG_ALSA ("AlsaSource::WriteRW (): trying to write when we're not playing (state: %i)\n", GetState ());
		return false;
	}

	if (!PreparePcm (&avail))
		return false;
	
	LOG_ALSA ("AlsaSource::WriteRW (): entering play loop, avail: %" G_GINT64_FORMAT ", sample size: %i\n", (gint64) avail, (int) period_size);
	
	buffer = g_malloc (avail * GetOutputBytesPerFrame ());
	
	frames = Write (buffer, (guint32) avail);

	mutex.Lock ();
	if (initialized)
		commitres = snd_pcm_writei (pcm, buffer, frames);
	mutex.Unlock ();
	
	g_free (buffer);
	
	LOG_ALSA ("AlsaSource::WriteRW (): played %i samples, of %i available samples, result: %i.\n", (int) frames, (int) avail, (int) commitres);
	
	if (commitres < 0 || (snd_pcm_uframes_t) commitres != frames) {
		if (commitres == -EAGAIN)
			LOG_AUDIO ("AlsaSource::WriteRW (): not enough space for all the data\n");
		if (!XrunRecovery (commitres >= 0 ? -EPIPE : commitres)) {
			LOG_AUDIO ("AudioPlayer: could not write audio data: %s, commitres: %li, frames: %u\n", snd_strerror (commitres), commitres, frames);
			return false;
		}
		started = false;
	}

	return frames != 0;
}
Esempio n. 2
0
void
OpenSLESSource::NextBuffer ()
{
	LOG_OSL ("OpenSLESSource::PlayBuffer");

	// FIXME: allocate new buffer (or get it from a free list or something..)
	SLresult result;

	SLAndroidSimpleBufferQueueState bufferQueueState;
	result = (*playerBufferQueue)->GetState (playerBufferQueue, &bufferQueueState);
	CHECK_RESULT ("playerBufferQueue->GetState");

	void *pBuffer = buffers[(bufferQueueState.index+1) % NUM_BUFFERS_IN_QUEUE];
	int bufferSize = BUFFER_SIZE;

        Write (pBuffer, bufferSize / GetOutputBytesPerFrame ());

        result = (*playerBufferQueue)->Enqueue(playerBufferQueue, pBuffer, bufferSize);
	CHECK_RESULT("playerBufferQueue->Enqueue");
}