Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_SINK_OWNER_H_ |
| 6 | #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_SINK_OWNER_H_ |
| 7 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 8 | #include <vector> |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 9 | |
| 10 | #include "base/memory/ref_counted.h" |
| 11 | #include "base/synchronization/lock.h" |
| 12 | #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 13 | #include "media/audio/audio_parameters.h" |
| 14 | |
| 15 | namespace content { |
| 16 | |
| 17 | class WebRtcAudioCapturerSink; |
| 18 | |
| 19 | // Reference counted container of WebRtcAudioCapturerSink delegates. |
| 20 | class WebRtcAudioCapturerSinkOwner |
| 21 | : public base::RefCountedThreadSafe<WebRtcAudioCapturerSinkOwner>, |
| 22 | public WebRtcAudioCapturerSink { |
| 23 | public: |
| 24 | explicit WebRtcAudioCapturerSinkOwner(WebRtcAudioCapturerSink* sink); |
| 25 | |
| 26 | // WebRtcAudioCapturerSink implementation. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 27 | virtual int CaptureData(const std::vector<int>& channels, |
| 28 | const int16* audio_data, |
| 29 | int sample_rate, |
| 30 | int number_of_channels, |
| 31 | int number_of_frames, |
| 32 | int audio_delay_milliseconds, |
| 33 | int current_volume, |
| 34 | bool need_audio_processing) OVERRIDE; |
| 35 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 36 | virtual void SetCaptureFormat(const media::AudioParameters& params) OVERRIDE; |
| 37 | |
| 38 | bool IsEqual(const WebRtcAudioCapturerSink* other) const; |
| 39 | void Reset(); |
| 40 | |
| 41 | // Wrapper which allows to use std::find_if() when adding and removing |
| 42 | // sinks to/from the list. |
| 43 | struct WrapsSink { |
| 44 | WrapsSink(WebRtcAudioCapturerSink* sink) : sink_(sink) {} |
| 45 | bool operator()( |
| 46 | const scoped_refptr<WebRtcAudioCapturerSinkOwner>& owner) { |
| 47 | return owner->IsEqual(sink_); |
| 48 | } |
| 49 | WebRtcAudioCapturerSink* sink_; |
| 50 | }; |
| 51 | |
| 52 | protected: |
| 53 | virtual ~WebRtcAudioCapturerSinkOwner() {} |
| 54 | |
| 55 | private: |
| 56 | friend class base::RefCountedThreadSafe<WebRtcAudioCapturerSinkOwner>; |
| 57 | WebRtcAudioCapturerSink* delegate_; |
| 58 | mutable base::Lock lock_; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturerSinkOwner); |
| 61 | }; |
| 62 | |
| 63 | } // namespace content |
| 64 | |
| 65 | #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_SINK_OWNER_H_ |