Exemple #1
0
// virtual
void LLAudioEngine::startInternetStream(const std::string& url)
{
	llinfos << "entered startInternetStream()" << llendl;

	if (!mInternetStreamMedia)
	{
		LLMediaManager* mgr = LLMediaManager::getInstance();
		if (mgr)
		{
			mInternetStreamMedia = mgr->createSourceFromMimeType(LLURI(url).scheme(), "audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis.
			llinfos << "mInternetStreamMedia is now " << mInternetStreamMedia << llendl;
		}
	}

	if(!mInternetStreamMedia)
	{
		return;
	}
	// Check for a dead stream from gstreamer, just in case
	else if(getStatus() == LLMediaBase::STATUS_DEAD)
	{
		llinfos << "don't play dead stream urls"<< llendl;
		mInternetStreamURL.clear();
		mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP);
		mInternetStreamMedia->updateMedia();
		stopInternetStream();
	}
	else if (url.empty())
	{
		llinfos << "url is emptly. Setting stream to NULL"<< llendl;
		mInternetStreamURL.clear();
		mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP);
		mInternetStreamMedia->updateMedia();
	}
	// Stream appears to be good, attempting to play
	else
	{
		// stop any other stream first
		stopInternetStream();

		llinfos << "Starting internet stream: " << url << llendl;
		mInternetStreamURL = url;
		mInternetStreamMedia->navigateTo(url);
		//llinfos << "Playing....." << llendl;		
		mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START);
		mInternetStreamMedia->updateMedia();
		mStatus = LLMediaBase::STATUS_STARTED;
	}
}
void LLAudioEngine_FMOD::shutdown()
{
	if (mWindDSP)
	{
		FSOUND_DSP_SetActive(mWindDSP,false);
		FSOUND_DSP_Free(mWindDSP);
	}

	stopInternetStream();

	LLAudioEngine::shutdown();
	
	llinfos << "LLAudioEngine_FMOD::shutdown() closing FMOD" << llendl;
	FSOUND_Close();
	llinfos << "LLAudioEngine_FMOD::shutdown() done closing FMOD" << llendl;

	delete mListenerp;
	mListenerp = NULL;
}
void LLAudioEngine_FMOD::pauseInternetStream(int pause)
{
	if (pause < 0)
	{
		pause = mCurrentInternetStreamp ? 1 : 0;
	}

	if (pause)
	{
		if (mCurrentInternetStreamp)
		{
			stopInternetStream();
		}
	}
	else
	{
		startInternetStream(mInternetStreamURL);
	}
}
void LLAudioEngine_FMOD::startInternetStream(const std::string& url)
{
	if (!mInited)
	{
		llwarns << "startInternetStream before audio initialized" << llendl;
		return;
	}

	// "stop" stream but don't clear url, etc. in calse url == mInternetStreamURL
	stopInternetStream();
	if (!url.empty())
	{
		llinfos << "Starting internet stream: " << url << llendl;
		mCurrentInternetStreamp = new LLAudioStreamFMOD(url);
		mInternetStreamURL = url;
	}
	else
	{
		llinfos << "Set internet stream to null" << llendl;
		mInternetStreamURL.clear();
	}
}
void LLAudioEngine_FMOD::updateInternetStream()
{
	// Kill dead internet streams, if possible
	std::list<LLAudioStreamFMOD *>::iterator iter;
	for (iter = mDeadStreams.begin(); iter != mDeadStreams.end();)
	{
		LLAudioStreamFMOD *streamp = *iter;
		if (streamp->stopStream())
		{
			llinfos << "Closed dead stream" << llendl;
			delete streamp;
			mDeadStreams.erase(iter++);
		}
		else
		{
			iter++;
		}
	}

	// Don't do anything if there are no streams playing
	if (!mCurrentInternetStreamp)
	{
		return;
	}

    int open_state = mCurrentInternetStreamp->getOpenState();

	if (!open_state)
	{
		// Stream is live


		// start the stream if it's ready
		if (mInternetStreamChannel < 0)
		{
			mInternetStreamChannel = mCurrentInternetStreamp->startStream();

			if (mInternetStreamChannel != -1)
			{
				// Reset volume to previously set volume
				setInternetStreamGain(mInternetStreamGain);
				FSOUND_SetPaused(mInternetStreamChannel, false);
				//FSOUND_Stream_Net_SetMetadataCallback(mInternetStream, callbackMetaData, this);
			}
		}
	}
		
	switch(open_state)
	{
	default:
	case 0:
		// success
		break;
	case -1:
		// stream handle is invalid
		llwarns << "InternetStream - invalid handle" << llendl;
		stopInternetStream();
		return;
	case -2:
		// opening
		//strlcpy(mInternetStreamArtist, "Opening", 256);
		break;
	case -3:
		// failed to open, file not found, perhaps
		llwarns << "InternetSteam - failed to open" << llendl;
		stopInternetStream();
		return;
	case -4:
		// connecting
		//strlcpy(mInternetStreamArtist, "Connecting", 256);
		break;
	case -5:
		// buffering
		//strlcpy(mInternetStreamArtist, "Buffering", 256);
		break;
	}

}