1 /*
2  *  Copyright 2004 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_PC_AUDIOMONITOR_H_
12 #define WEBRTC_PC_AUDIOMONITOR_H_
13 
14 #include <vector>
15 #include <utility>
16 
17 #include "webrtc/base/sigslot.h"
18 #include "webrtc/base/thread.h"
19 #include "webrtc/p2p/base/port.h"
20 
21 namespace cricket {
22 
23 class VoiceChannel;
24 
25 struct AudioInfo {
26   int input_level;
27   int output_level;
28   typedef std::vector<std::pair<uint32_t, int> > StreamList;
29   StreamList active_streams;  // ssrcs contributing to output_level
30 };
31 
32 class AudioMonitor : public rtc::MessageHandler,
33     public sigslot::has_slots<> {
34  public:
35   AudioMonitor(VoiceChannel* voice_channel, rtc::Thread *monitor_thread);
36   ~AudioMonitor();
37 
38   void Start(int cms);
39   void Stop();
40 
41   VoiceChannel* voice_channel();
42   rtc::Thread *monitor_thread();
43 
44   sigslot::signal2<AudioMonitor*, const AudioInfo&> SignalUpdate;
45 
46  protected:
47   void OnMessage(rtc::Message *message);
48   void PollVoiceChannel();
49 
50   AudioInfo audio_info_;
51   VoiceChannel* voice_channel_;
52   rtc::Thread* monitoring_thread_;
53   rtc::CriticalSection crit_;
54   uint32_t rate_;
55   bool monitoring_;
56 };
57 
58 }  // namespace cricket
59 
60 #endif  // WEBRTC_PC_AUDIOMONITOR_H_
61