src/platform/openal/OpenAlPlayer.cpp
//! Generates and loads buffer for stream.
Generates and loads buffer for stream.
Generates and loads buffer for stream .
boost::optional<ALuint> OpenAlPlayer::BufferLoader::getBufferId(uint32_t packetIndex) {
	lock_guard<mutex> lock(bufferAccessMutex); 
	if (packetIndex < bufferIds.size()) {
		return bufferIds[packetIndex];
	} else if(packetIndex > bufferIds.size()) {
		throw std::runtime_error("Invalid usage, getBufferId needs to be called with sequentially increasing packetIndex");
	}
	if (finishedLoading) {
		return boost::optional<ALuint>();
	}
	auto packet = pcmStream->getPacket(packetIndex); 
	if (!packet) {
		finishedLoading = true;
		pcmStream.reset();
		return boost::optional<ALuint>();
	}
	resetAlError();
	ALuint bufferId;
	alGenBuffers(1, &bufferId);
	checkAlError("alGenBuffers");
	alBufferData(bufferId, format, &((*packet)[0]), (*packet).size(), pcmInfo.frequency);
	checkAlError("alBufferData");
	bufferIds.push_back(bufferId);
	return bufferId;
}
boost :: optional < ALuint > OpenAlPlayer :: BufferLoader :: getBufferId ( uint32_t packetIndex ) { lock_guard < mutex > lock ( bufferAccessMutex ) ; if ( packetIndex < bufferIds . size ( ) ) { return bufferIds [ packetIndex ] ; } else if ( packetIndex > bufferIds . size ( ) ) { throw std :: runtime_error ( " " ) ; } if ( finishedLoading ) { return boost :: optional < ALuint > ( ) ; } auto packet = pcmStream -> getPacket ( packetIndex ) ; if ( ! packet ) { finishedLoading = true ; pcmStream . reset ( ) ; return boost :: optional < ALuint > ( ) ; } resetAlError ( ) ; ALuint bufferId ; alGenBuffers ( 1 , & bufferId ) ; checkAlError ( " " ) ; alBufferData ( bufferId , format , & ( ( * packet ) [ 0 ] ) , ( * packet ) . size ( ) , pcmInfo . frequency ) ; checkAlError ( " " ) ; bufferIds . push_back ( bufferId ) ; return bufferId ; }
Generates and loads buffer for stream.
Generates and loads buffer for stream .
// This method is accessed through several threads, for buffer management to work // we need to lock access to this method to one thread at a time. // Check if packet has already been loaded // Fetch packet // Blocks until packet is available.