| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #ifndef TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ | 31 #ifndef TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ |
| 32 #define TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ | 32 #define TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ |
| 33 | 33 |
| 34 #include <map> | 34 #include <map> |
| 35 | 35 |
| 36 #include "webrtc/base/basictypes.h" | 36 #include "webrtc/base/basictypes.h" |
| 37 #include "webrtc/base/sigslot.h" | 37 #include "webrtc/base/sigslot.h" |
| 38 | 38 |
| 39 namespace cricket { | 39 namespace cricket { |
| 40 | 40 |
| 41 class BaseSession; | |
| 42 struct AudioInfo; | 41 struct AudioInfo; |
| 43 struct MediaStreams; | 42 struct MediaStreams; |
| 44 | 43 |
| 45 class AudioSourceContext { | 44 class AudioSourceContext { |
| 46 public: | 45 public: |
| 47 sigslot::signal2<AudioSourceContext*, const cricket::AudioInfo&> | 46 sigslot::signal2<AudioSourceContext*, const cricket::AudioInfo&> |
| 48 SignalAudioMonitor; | 47 SignalAudioMonitor; |
| 49 sigslot::signal2<AudioSourceContext*, cricket::BaseSession*> | 48 sigslot::signal1<AudioSourceContext*> SignalMediaStreamsReset; |
| 50 SignalMediaStreamsReset; | 49 sigslot::signal3<AudioSourceContext*, |
| 51 sigslot::signal4<AudioSourceContext*, cricket::BaseSession*, | 50 const cricket::MediaStreams&, |
| 52 const cricket::MediaStreams&, const cricket::MediaStreams&> | 51 const cricket::MediaStreams&> SignalMediaStreamsUpdate; |
| 53 SignalMediaStreamsUpdate; | |
| 54 }; | 52 }; |
| 55 | 53 |
| 56 // CurrentSpeakerMonitor can be used to monitor the audio-levels from | 54 // CurrentSpeakerMonitor can be used to monitor the audio-levels from |
| 57 // many audio-sources and report on changes in the loudest audio-source. | 55 // many audio-sources and report on changes in the loudest audio-source. |
| 58 // Its a generic type and relies on an AudioSourceContext which is aware of | 56 // Its a generic type and relies on an AudioSourceContext which is aware of |
| 59 // the audio-sources. AudioSourceContext needs to provide two signals namely | 57 // the audio-sources. AudioSourceContext needs to provide two signals namely |
| 60 // SignalAudioInfoMonitor - provides audio info of the all current speakers. | 58 // SignalAudioInfoMonitor - provides audio info of the all current speakers. |
| 61 // SignalMediaSourcesUpdated - provides updates when a speaker leaves or joins. | 59 // SignalMediaSourcesUpdated - provides updates when a speaker leaves or joins. |
| 62 // Note that the AudioSourceContext's audio monitor must be started | 60 // Note that the AudioSourceContext's audio monitor must be started |
| 63 // before this is started. | 61 // before this is started. |
| 64 // It's recommended that the audio monitor be started with a 100 ms period. | 62 // It's recommended that the audio monitor be started with a 100 ms period. |
| 65 class CurrentSpeakerMonitor : public sigslot::has_slots<> { | 63 class CurrentSpeakerMonitor : public sigslot::has_slots<> { |
| 66 public: | 64 public: |
| 67 CurrentSpeakerMonitor(AudioSourceContext* audio_source_context, | 65 CurrentSpeakerMonitor(AudioSourceContext* audio_source_context); |
| 68 BaseSession* session); | |
| 69 ~CurrentSpeakerMonitor(); | 66 ~CurrentSpeakerMonitor(); |
| 70 | 67 |
| 71 BaseSession* session() const { return session_; } | |
| 72 | |
| 73 void Start(); | 68 void Start(); |
| 74 void Stop(); | 69 void Stop(); |
| 75 | 70 |
| 76 // Used by tests. Note that the actual minimum time between switches | 71 // Used by tests. Note that the actual minimum time between switches |
| 77 // enforced by the monitor will be the given value plus or minus the | 72 // enforced by the monitor will be the given value plus or minus the |
| 78 // resolution of the system clock. | 73 // resolution of the system clock. |
| 79 void set_min_time_between_switches(uint32_t min_time_between_switches); | 74 void set_min_time_between_switches(uint32_t min_time_between_switches); |
| 80 | 75 |
| 81 // This is fired when the current speaker changes, and provides his audio | 76 // This is fired when the current speaker changes, and provides his audio |
| 82 // SSRC. This only fires after the audio monitor on the underlying | 77 // SSRC. This only fires after the audio monitor on the underlying |
| 83 // AudioSourceContext has been started. | 78 // AudioSourceContext has been started. |
| 84 sigslot::signal2<CurrentSpeakerMonitor*, uint32_t> SignalUpdate; | 79 sigslot::signal2<CurrentSpeakerMonitor*, uint32_t> SignalUpdate; |
| 85 | 80 |
| 86 private: | 81 private: |
| 87 void OnAudioMonitor(AudioSourceContext* audio_source_context, | 82 void OnAudioMonitor(AudioSourceContext* audio_source_context, |
| 88 const AudioInfo& info); | 83 const AudioInfo& info); |
| 89 void OnMediaStreamsUpdate(AudioSourceContext* audio_source_context, | 84 void OnMediaStreamsUpdate(AudioSourceContext* audio_source_context, |
| 90 BaseSession* session, | |
| 91 const MediaStreams& added, | 85 const MediaStreams& added, |
| 92 const MediaStreams& removed); | 86 const MediaStreams& removed); |
| 93 void OnMediaStreamsReset(AudioSourceContext* audio_source_context, | 87 void OnMediaStreamsReset(AudioSourceContext* audio_source_context); |
| 94 BaseSession* session); | |
| 95 | 88 |
| 96 // These are states that a participant will pass through so that we gradually | 89 // These are states that a participant will pass through so that we gradually |
| 97 // recognize that they have started and stopped speaking. This avoids | 90 // recognize that they have started and stopped speaking. This avoids |
| 98 // "twitchiness". | 91 // "twitchiness". |
| 99 enum SpeakingState { | 92 enum SpeakingState { |
| 100 SS_NOT_SPEAKING, | 93 SS_NOT_SPEAKING, |
| 101 SS_MIGHT_BE_SPEAKING, | 94 SS_MIGHT_BE_SPEAKING, |
| 102 SS_SPEAKING, | 95 SS_SPEAKING, |
| 103 SS_WAS_SPEAKING_RECENTLY1, | 96 SS_WAS_SPEAKING_RECENTLY1, |
| 104 SS_WAS_SPEAKING_RECENTLY2 | 97 SS_WAS_SPEAKING_RECENTLY2 |
| 105 }; | 98 }; |
| 106 | 99 |
| 107 bool started_; | 100 bool started_; |
| 108 AudioSourceContext* audio_source_context_; | 101 AudioSourceContext* audio_source_context_; |
| 109 BaseSession* session_; | |
| 110 std::map<uint32_t, SpeakingState> ssrc_to_speaking_state_map_; | 102 std::map<uint32_t, SpeakingState> ssrc_to_speaking_state_map_; |
| 111 uint32_t current_speaker_ssrc_; | 103 uint32_t current_speaker_ssrc_; |
| 112 // To prevent overswitching, switching is disabled for some time after a | 104 // To prevent overswitching, switching is disabled for some time after a |
| 113 // switch is made. This gives us the earliest time a switch is permitted. | 105 // switch is made. This gives us the earliest time a switch is permitted. |
| 114 uint32_t earliest_permitted_switch_time_; | 106 uint32_t earliest_permitted_switch_time_; |
| 115 uint32_t min_time_between_switches_; | 107 uint32_t min_time_between_switches_; |
| 116 }; | 108 }; |
| 117 | 109 |
| 118 } | 110 } |
| 119 | 111 |
| 120 #endif // TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ | 112 #endif // TALK_SESSION_MEDIA_CURRENTSPEAKERMONITOR_H_ |
| OLD | NEW |