PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/media_plugins/webkit/windows_volume_catcher.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 117 lines | 67 code | 19 blank | 31 comment | 4 complexity | dd9d935dfb957cf0333e06e0de3d3ce9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file windows_volume_catcher.cpp
  3. * @brief A Windows implementation of volume level control of all audio channels opened by a process.
  4. *
  5. * @cond
  6. * $LicenseInfo:firstyear=2010&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. * @endcond
  27. */
  28. #include "volume_catcher.h"
  29. #include <windows.h>
  30. #include "llsingleton.h"
  31. class VolumeCatcherImpl : public LLSingleton<VolumeCatcherImpl>
  32. {
  33. friend LLSingleton<VolumeCatcherImpl>;
  34. public:
  35. void setVolume(F32 volume);
  36. void setPan(F32 pan);
  37. private:
  38. // This is a singleton class -- both callers and the component implementation should use getInstance() to find the instance.
  39. VolumeCatcherImpl();
  40. ~VolumeCatcherImpl();
  41. typedef void (WINAPI *set_volume_func_t)(F32);
  42. typedef void (WINAPI *set_mute_func_t)(bool);
  43. set_volume_func_t mSetVolumeFunc;
  44. set_mute_func_t mSetMuteFunc;
  45. F32 mVolume;
  46. F32 mPan;
  47. };
  48. VolumeCatcherImpl::VolumeCatcherImpl()
  49. : mVolume(1.0f), // default volume is max
  50. mPan(0.f) // default pan is centered
  51. {
  52. HMODULE handle = ::LoadLibrary(L"winmm.dll");
  53. if(handle)
  54. {
  55. mSetVolumeFunc = (set_volume_func_t)::GetProcAddress(handle, "setPluginVolume");
  56. mSetMuteFunc = (set_mute_func_t)::GetProcAddress(handle, "setPluginMute");
  57. }
  58. }
  59. VolumeCatcherImpl::~VolumeCatcherImpl()
  60. {
  61. }
  62. void VolumeCatcherImpl::setVolume(F32 volume)
  63. {
  64. mVolume = volume;
  65. if (mSetMuteFunc)
  66. {
  67. mSetMuteFunc(volume == 0.f);
  68. }
  69. if (mSetVolumeFunc)
  70. {
  71. mSetVolumeFunc(mVolume);
  72. }
  73. }
  74. void VolumeCatcherImpl::setPan(F32 pan)
  75. { // remember pan for calculating individual channel levels later
  76. mPan = pan;
  77. }
  78. /////////////////////////////////////////////////////
  79. VolumeCatcher::VolumeCatcher()
  80. {
  81. pimpl = VolumeCatcherImpl::getInstance();
  82. }
  83. VolumeCatcher::~VolumeCatcher()
  84. {
  85. // Let the instance persist until exit.
  86. }
  87. void VolumeCatcher::setVolume(F32 volume)
  88. {
  89. pimpl->setVolume(volume);
  90. }
  91. void VolumeCatcher::setPan(F32 pan)
  92. {
  93. pimpl->setPan(pan);
  94. }
  95. void VolumeCatcher::pump()
  96. {
  97. // No periodic tasks are necessary for this implementation.
  98. }