PageRenderTime 54ms CodeModel.GetById 33ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewermedia_streamingaudio.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 166 lines | 113 code | 25 blank | 28 comment | 13 complexity | fcdefe640ecb486323f1e00a7f0f141a MD5 | raw file
  1/** 
  2 * @file llviewermedia_streamingaudio.h
  3 * @author Tofu Linden, Sam Kolb
  4 * @brief LLStreamingAudio_MediaPlugins implementation - an implementation of the streaming audio interface which is implemented as a client of the media plugin API.
  5 *
  6 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27#include "llviewerprecompiledheaders.h"
 28#include "linden_common.h"
 29#include "llpluginclassmedia.h"
 30#include "llpluginclassmediaowner.h"
 31#include "llviewermedia.h"
 32
 33#include "llviewermedia_streamingaudio.h"
 34
 35#include "llmimetypes.h"
 36#include "llvfs.h"
 37#include "lldir.h"
 38
 39
 40LLStreamingAudio_MediaPlugins::LLStreamingAudio_MediaPlugins() :
 41	mMediaPlugin(NULL),
 42	mGain(1.0)
 43{
 44	// nothing interesting to do?
 45	// we will lazily create a media plugin at play-time, if none exists.
 46}
 47
 48LLStreamingAudio_MediaPlugins::~LLStreamingAudio_MediaPlugins()
 49{
 50	delete mMediaPlugin;
 51	mMediaPlugin = NULL;
 52}
 53
 54void LLStreamingAudio_MediaPlugins::start(const std::string& url)
 55{
 56	if (!mMediaPlugin) // lazy-init the underlying media plugin
 57	{
 58		mMediaPlugin = initializeMedia("audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis.
 59		llinfos << "streaming audio mMediaPlugin is now " << mMediaPlugin << llendl;
 60	}
 61
 62	if(!mMediaPlugin)
 63		return;
 64
 65	if (!url.empty()) {
 66		llinfos << "Starting internet stream: " << url << llendl;
 67		mURL = url;
 68		mMediaPlugin->loadURI ( url );
 69		mMediaPlugin->start();
 70		llinfos << "Playing stream..." << llendl;		
 71	} else {
 72		llinfos << "setting stream to NULL"<< llendl;
 73		mURL.clear();
 74		mMediaPlugin->stop();
 75	}
 76}
 77
 78void LLStreamingAudio_MediaPlugins::stop()
 79{
 80	llinfos << "Stopping internet stream." << llendl;
 81	if(mMediaPlugin)
 82	{
 83		mMediaPlugin->stop();
 84	}
 85
 86	mURL.clear();
 87}
 88
 89void LLStreamingAudio_MediaPlugins::pause(int pause)
 90{
 91	if(!mMediaPlugin)
 92		return;
 93	
 94	if(pause)
 95	{
 96		llinfos << "Pausing internet stream." << llendl;
 97		mMediaPlugin->pause();
 98	} 
 99	else 
100	{
101		llinfos << "Unpausing internet stream." << llendl;
102		mMediaPlugin->start();
103	}
104}
105
106void LLStreamingAudio_MediaPlugins::update()
107{
108	if (mMediaPlugin)
109		mMediaPlugin->idle();
110}
111
112int LLStreamingAudio_MediaPlugins::isPlaying()
113{
114	if (!mMediaPlugin)
115		return 0; // stopped
116	
117	LLPluginClassMediaOwner::EMediaStatus status =
118		mMediaPlugin->getStatus();
119
120	switch (status)
121	{
122	case LLPluginClassMediaOwner::MEDIA_LOADING: // but not MEDIA_LOADED
123	case LLPluginClassMediaOwner::MEDIA_PLAYING:
124		return 1; // Active and playing
125	case LLPluginClassMediaOwner::MEDIA_PAUSED:
126		return 2; // paused
127	default:
128		return 0; // stopped
129	}
130}
131
132void LLStreamingAudio_MediaPlugins::setGain(F32 vol)
133{
134	mGain = vol;
135
136	if(!mMediaPlugin)
137		return;
138
139	vol = llclamp(vol, 0.f, 1.f);
140	mMediaPlugin->setVolume(vol);
141}
142
143F32 LLStreamingAudio_MediaPlugins::getGain()
144{
145	return mGain;
146}
147
148std::string LLStreamingAudio_MediaPlugins::getURL()
149{
150	return mURL;
151}
152
153LLPluginClassMedia* LLStreamingAudio_MediaPlugins::initializeMedia(const std::string& media_type)
154{
155	LLPluginClassMediaOwner* owner = NULL;
156	S32 default_size = 1; // audio-only - be minimal, doesn't matter
157	LLPluginClassMedia* media_source = LLViewerMediaImpl::newSourceFromMediaType(media_type, owner, default_size, default_size);
158
159	if (media_source)
160	{
161		media_source->setLoop(false); // audio streams are not expected to loop
162	}
163
164	return media_source;
165}
166