You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2011 Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. // CurrentSpeakerMonitor monitors the audio levels for a session and determines
  28. // which participant is currently speaking.
  29. #ifndef TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_
  30. #define TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_
  31. #include <map>
  32. #include "talk/base/basictypes.h"
  33. #include "talk/base/sigslot.h"
  34. namespace cricket {
  35. class BaseSession;
  36. class Call;
  37. class Session;
  38. struct AudioInfo;
  39. struct MediaStreams;
  40. // Note that the call's audio monitor must be started before this is started.
  41. // It's recommended that the audio monitor be started with a 100 ms period.
  42. class CurrentSpeakerMonitor : public sigslot::has_slots<> {
  43. public:
  44. CurrentSpeakerMonitor(Call* call, BaseSession* session);
  45. ~CurrentSpeakerMonitor();
  46. BaseSession* session() const { return session_; }
  47. void Start();
  48. void Stop();
  49. // Used by tests. Note that the actual minimum time between switches
  50. // enforced by the monitor will be the given value plus or minus the
  51. // resolution of the system clock.
  52. void set_min_time_between_switches(uint32 min_time_between_switches);
  53. // This is fired when the current speaker changes, and provides his audio
  54. // SSRC. This only fires after the audio monitor on the underlying Call has
  55. // been started.
  56. sigslot::signal2<CurrentSpeakerMonitor*, uint32> SignalUpdate;
  57. private:
  58. void OnAudioMonitor(Call* call, const AudioInfo& info);
  59. void OnMediaStreamsUpdate(Call* call,
  60. Session* session,
  61. const MediaStreams& added,
  62. const MediaStreams& removed);
  63. // These are states that a participant will pass through so that we gradually
  64. // recognize that they have started and stopped speaking. This avoids
  65. // "twitchiness".
  66. enum SpeakingState {
  67. SS_NOT_SPEAKING,
  68. SS_MIGHT_BE_SPEAKING,
  69. SS_SPEAKING,
  70. SS_WAS_SPEAKING_RECENTLY1,
  71. SS_WAS_SPEAKING_RECENTLY2
  72. };
  73. bool started_;
  74. Call* call_;
  75. BaseSession* session_;
  76. std::map<uint32, SpeakingState> ssrc_to_speaking_state_map_;
  77. uint32 current_speaker_ssrc_;
  78. // To prevent overswitching, switching is disabled for some time after a
  79. // switch is made. This gives us the earliest time a switch is permitted.
  80. uint32 earliest_permitted_switch_time_;
  81. uint32 min_time_between_switches_;
  82. };
  83. }
  84. #endif // TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_