PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewermedia_streamingaudio.h"
  33. #include "llmimetypes.h"
  34. #include "llvfs.h"
  35. #include "lldir.h"
  36. LLStreamingAudio_MediaPlugins::LLStreamingAudio_MediaPlugins() :
  37. mMediaPlugin(NULL),
  38. mGain(1.0)
  39. {
  40. // nothing interesting to do?
  41. // we will lazily create a media plugin at play-time, if none exists.
  42. }
  43. LLStreamingAudio_MediaPlugins::~LLStreamingAudio_MediaPlugins()
  44. {
  45. delete mMediaPlugin;
  46. mMediaPlugin = NULL;
  47. }
  48. void LLStreamingAudio_MediaPlugins::start(const std::string& url)
  49. {
  50. if (!mMediaPlugin) // lazy-init the underlying media plugin
  51. {
  52. mMediaPlugin = initializeMedia("audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis.
  53. llinfos << "streaming audio mMediaPlugin is now " << mMediaPlugin << llendl;
  54. }
  55. if(!mMediaPlugin)
  56. return;
  57. if (!url.empty()) {
  58. llinfos << "Starting internet stream: " << url << llendl;
  59. mURL = url;
  60. mMediaPlugin->loadURI ( url );
  61. mMediaPlugin->start();
  62. llinfos << "Playing stream..." << llendl;
  63. } else {
  64. llinfos << "setting stream to NULL"<< llendl;
  65. mURL.clear();
  66. mMediaPlugin->stop();
  67. }
  68. }
  69. void LLStreamingAudio_MediaPlugins::stop()
  70. {
  71. llinfos << "Stopping internet stream." << llendl;
  72. if(mMediaPlugin)
  73. {
  74. mMediaPlugin->stop();
  75. }
  76. mURL.clear();
  77. }
  78. void LLStreamingAudio_MediaPlugins::pause(int pause)
  79. {
  80. if(!mMediaPlugin)
  81. return;
  82. if(pause)
  83. {
  84. llinfos << "Pausing internet stream." << llendl;
  85. mMediaPlugin->pause();
  86. }
  87. else
  88. {
  89. llinfos << "Unpausing internet stream." << llendl;
  90. mMediaPlugin->start();
  91. }
  92. }
  93. void LLStreamingAudio_MediaPlugins::update()
  94. {
  95. if (mMediaPlugin)
  96. mMediaPlugin->idle();
  97. }
  98. int LLStreamingAudio_MediaPlugins::isPlaying()
  99. {
  100. if (!mMediaPlugin)
  101. return 0; // stopped
  102. LLPluginClassMediaOwner::EMediaStatus status =
  103. mMediaPlugin->getStatus();
  104. switch (status)
  105. {
  106. case LLPluginClassMediaOwner::MEDIA_LOADING: // but not MEDIA_LOADED
  107. case LLPluginClassMediaOwner::MEDIA_PLAYING:
  108. return 1; // Active and playing
  109. case LLPluginClassMediaOwner::MEDIA_PAUSED:
  110. return 2; // paused
  111. default:
  112. return 0; // stopped
  113. }
  114. }
  115. void LLStreamingAudio_MediaPlugins::setGain(F32 vol)
  116. {
  117. mGain = vol;
  118. if(!mMediaPlugin)
  119. return;
  120. vol = llclamp(vol, 0.f, 1.f);
  121. mMediaPlugin->setVolume(vol);
  122. }
  123. F32 LLStreamingAudio_MediaPlugins::getGain()
  124. {
  125. return mGain;
  126. }
  127. std::string LLStreamingAudio_MediaPlugins::getURL()
  128. {
  129. return mURL;
  130. }
  131. LLPluginClassMedia* LLStreamingAudio_MediaPlugins::initializeMedia(const std::string& media_type)
  132. {
  133. LLPluginClassMediaOwner* owner = NULL;
  134. S32 default_size = 1; // audio-only - be minimal, doesn't matter
  135. LLPluginClassMedia* media_source = LLViewerMediaImpl::newSourceFromMediaType(media_type, owner, default_size, default_size);
  136. if (media_source)
  137. {
  138. media_source->setLoop(false); // audio streams are not expected to loop
  139. }
  140. return media_source;
  141. }