const bool cSoundSourceStream::Play(){
	// adds this to step list for handle streaming
	mpSoundSystem->mlSourceStream.push_back(this);

	// init buffers
	if(RemainingBytes() > 0)StreamBuffer(mlBuffer[0]);
	if(RemainingBytes() > 0)StreamBuffer(mlBuffer[1]);
	// and stream them
	alSourceQueueBuffers(miId, 2, (ALuint *)mlBuffer);
	CheckOpenAl();	
	
	// and play them
	return cSoundSourceOpenAl::Play();
}
 bool Read(T* val) {
     assert(val != nullptr);
     if (RemainingBytes() < sizeof(T))
         return false;
     *val = *reinterpret_cast<T*>(reinterpret_cast<char*>(_message->data()) + _pos);
     _pos += sizeof(T);
     return true;
 }
void cSoundSourceStream::Step(){
	int processed = 0;

	if(RemainingBytes() == 0 && IsPlaying() && !IsPaused()){
		// sound is finished
		Stop();
	} else if(IsPlaying() && RemainingBytes() > 0){
		// read the number of played buffers
		alGetSourcei(miId, AL_BUFFERS_PROCESSED, &processed);
		CheckOpenAl();
		
		// and refill them
		while(processed--){
			ALuint buffer;
			alSourceUnqueueBuffers(miId, 1, &buffer);
			CheckOpenAl();
			StreamBuffer(buffer);		
			alSourceQueueBuffers(miId, 1, &buffer);
			CheckOpenAl();
			//printf("#### source step remaining=%i playing=%d paused=%d\n",mpStream->RemainingBytes(),IsPlaying(),IsPaused());
		}
	}
}
Exemple #4
0
void
IORequest::NotifyFinished()
{
	TRACE("IORequest::NotifyFinished(): request: %p\n", this);

	MutexLocker locker(fLock);

	if (fStatus == B_OK && !fPartialTransfer && RemainingBytes() > 0) {
		// The request is not really done yet. If it has an iteration callback,
		// call it.
		if (fIterationCallback != NULL) {
			ResetStatus();
			locker.Unlock();
			bool partialTransfer = false;
			status_t error = fIterationCallback(fIterationCookie, this,
				&partialTransfer);
			if (error == B_OK && !partialTransfer)
				return;

			// Iteration failed, which means we're responsible for notifying the
			// requests finished.
			locker.Lock();
			fStatus = error;
			fPartialTransfer = true;
		}
	}

	ASSERT(fPendingChildren == 0);
	ASSERT(fChildren.IsEmpty()
		|| dynamic_cast<IOOperation*>(fChildren.Head()) == NULL);

	// unlock the memory
	if (fBuffer->IsMemoryLocked())
		fBuffer->UnlockMemory(fTeam, fIsWrite);

	// Cache the callbacks before we unblock waiters and unlock. Any of the
	// following could delete this request, so we don't want to touch it
	// once we have started telling others that it is done.
	IORequest* parent = fParent;
	io_request_finished_callback finishedCallback = fFinishedCallback;
	void* finishedCookie = fFinishedCookie;
	status_t status = fStatus;
	size_t lastTransferredOffset = fRelativeParentOffset + fTransferSize;
	bool partialTransfer = status != B_OK || fPartialTransfer;
	bool deleteRequest = (fFlags & B_DELETE_IO_REQUEST) != 0;

	// unblock waiters
	fIsNotified = true;
	fFinishedCondition.NotifyAll();

	locker.Unlock();

	// notify callback
	if (finishedCallback != NULL) {
		finishedCallback(finishedCookie, this, status, partialTransfer,
			lastTransferredOffset);
	}

	// notify parent
	if (parent != NULL) {
		parent->SubRequestFinished(this, status, partialTransfer,
			lastTransferredOffset);
	}

	if (deleteRequest)
		delete this;
}