3
* Copyright 2011, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
// CurrentSpeakerMonitor monitors the audio levels for a session and determines
29
// which participant is currently speaking.
31
#ifndef TALK_SESSION_PHONE_CURRENTSPEAKERMONITOR_H_
32
#define TALK_SESSION_PHONE_CURRENTSPEAKERMONITOR_H_
36
#include "talk/base/basictypes.h"
37
#include "talk/base/sigslot.h"
47
// Note that the call's audio monitor must be started before this is started.
48
// It's recommended that the audio monitor be started with a 100 ms period.
49
class CurrentSpeakerMonitor : public sigslot::has_slots<> {
51
CurrentSpeakerMonitor(Call* call, BaseSession* session);
52
~CurrentSpeakerMonitor();
54
BaseSession* session() const { return session_; }
59
// Used by tests. Note that the actual minimum time between switches
60
// enforced by the monitor will be the given value plus or minus the
61
// resolution of the system clock.
62
void set_min_time_between_switches(uint32 min_time_between_switches);
64
// This is fired when the current speaker changes, and provides his audio
65
// SSRC. This only fires after the audio monitor on the underlying Call has
67
sigslot::signal2<CurrentSpeakerMonitor*, uint32> SignalUpdate;
70
void OnAudioMonitor(Call* call, const AudioInfo& info);
71
void OnMediaStreamsUpdate(Call* call,
73
const MediaStreams& added,
74
const MediaStreams& removed);
76
// These are states that a participant will pass through so that we gradually
77
// recognize that they have started and stopped speaking. This avoids
83
SS_WAS_SPEAKING_RECENTLY1,
84
SS_WAS_SPEAKING_RECENTLY2
89
BaseSession* session_;
90
std::map<uint32, SpeakingState> ssrc_to_speaking_state_map_;
91
uint32 current_speaker_ssrc_;
92
// To prevent overswitching, switching is disabled for some time after a
93
// switch is made. This gives us the earliest time a switch is permitted.
94
uint32 earliest_permitted_switch_time_;
95
uint32 min_time_between_switches_;
100
#endif // TALK_SESSION_PHONE_CURRENTSPEAKERMONITOR_H_