2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Copyright 2011 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// CurrentSpeakerMonitor monitors the audio levels for a session and determines
|
|
|
|
|
// which participant is currently speaking.
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef PC_CURRENTSPEAKERMONITOR_H_
|
|
|
|
|
#define PC_CURRENTSPEAKERMONITOR_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-01-02 08:42:32 -08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
#include <map>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/sigslot.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
struct AudioInfo;
|
|
|
|
|
struct MediaStreams;
|
|
|
|
|
|
2014-05-08 23:10:23 +00:00
|
|
|
class AudioSourceContext {
|
|
|
|
|
public:
|
|
|
|
|
sigslot::signal2<AudioSourceContext*, const cricket::AudioInfo&>
|
|
|
|
|
SignalAudioMonitor;
|
2015-10-14 15:02:44 -07:00
|
|
|
sigslot::signal1<AudioSourceContext*> SignalMediaStreamsReset;
|
|
|
|
|
sigslot::signal3<AudioSourceContext*,
|
|
|
|
|
const cricket::MediaStreams&,
|
|
|
|
|
const cricket::MediaStreams&> SignalMediaStreamsUpdate;
|
2014-05-08 23:10:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CurrentSpeakerMonitor can be used to monitor the audio-levels from
|
|
|
|
|
// many audio-sources and report on changes in the loudest audio-source.
|
|
|
|
|
// Its a generic type and relies on an AudioSourceContext which is aware of
|
|
|
|
|
// the audio-sources. AudioSourceContext needs to provide two signals namely
|
|
|
|
|
// SignalAudioInfoMonitor - provides audio info of the all current speakers.
|
|
|
|
|
// SignalMediaSourcesUpdated - provides updates when a speaker leaves or joins.
|
|
|
|
|
// Note that the AudioSourceContext's audio monitor must be started
|
|
|
|
|
// before this is started.
|
2013-07-10 00:45:36 +00:00
|
|
|
// It's recommended that the audio monitor be started with a 100 ms period.
|
|
|
|
|
class CurrentSpeakerMonitor : public sigslot::has_slots<> {
|
|
|
|
|
public:
|
2016-04-26 05:28:11 -07:00
|
|
|
explicit CurrentSpeakerMonitor(AudioSourceContext* audio_source_context);
|
2013-07-10 00:45:36 +00:00
|
|
|
~CurrentSpeakerMonitor();
|
|
|
|
|
|
|
|
|
|
void Start();
|
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
|
|
// Used by tests. Note that the actual minimum time between switches
|
|
|
|
|
// enforced by the monitor will be the given value plus or minus the
|
|
|
|
|
// resolution of the system clock.
|
2016-05-06 11:29:15 -07:00
|
|
|
void set_min_time_between_switches(int min_time_between_switches);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// This is fired when the current speaker changes, and provides his audio
|
2014-06-16 07:11:01 +00:00
|
|
|
// SSRC. This only fires after the audio monitor on the underlying
|
|
|
|
|
// AudioSourceContext has been started.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
sigslot::signal2<CurrentSpeakerMonitor*, uint32_t> SignalUpdate;
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
private:
|
2014-06-16 07:11:01 +00:00
|
|
|
void OnAudioMonitor(AudioSourceContext* audio_source_context,
|
|
|
|
|
const AudioInfo& info);
|
|
|
|
|
void OnMediaStreamsUpdate(AudioSourceContext* audio_source_context,
|
2013-07-10 00:45:36 +00:00
|
|
|
const MediaStreams& added,
|
|
|
|
|
const MediaStreams& removed);
|
2015-10-14 15:02:44 -07:00
|
|
|
void OnMediaStreamsReset(AudioSourceContext* audio_source_context);
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// These are states that a participant will pass through so that we gradually
|
|
|
|
|
// recognize that they have started and stopped speaking. This avoids
|
|
|
|
|
// "twitchiness".
|
|
|
|
|
enum SpeakingState {
|
|
|
|
|
SS_NOT_SPEAKING,
|
|
|
|
|
SS_MIGHT_BE_SPEAKING,
|
|
|
|
|
SS_SPEAKING,
|
|
|
|
|
SS_WAS_SPEAKING_RECENTLY1,
|
|
|
|
|
SS_WAS_SPEAKING_RECENTLY2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool started_;
|
2014-05-08 23:10:23 +00:00
|
|
|
AudioSourceContext* audio_source_context_;
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
std::map<uint32_t, SpeakingState> ssrc_to_speaking_state_map_;
|
|
|
|
|
uint32_t current_speaker_ssrc_;
|
2013-07-10 00:45:36 +00:00
|
|
|
// To prevent overswitching, switching is disabled for some time after a
|
|
|
|
|
// switch is made. This gives us the earliest time a switch is permitted.
|
2016-05-06 11:29:15 -07:00
|
|
|
int64_t earliest_permitted_switch_time_;
|
|
|
|
|
int min_time_between_switches_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
2016-04-26 05:28:11 -07:00
|
|
|
} // namespace cricket
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // PC_CURRENTSPEAKERMONITOR_H_
|