OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
6 #define CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "content/renderer/media/media_stream_audio_source.h" |
9 #include "base/memory/shared_memory.h" | 9 |
10 #include "content/browser/device_sensors/device_sensors_consts.h" | 10 #include "media/base/audio_capturer_source.h" |
11 #include "content/public/browser/browser_message_filter.h" | |
12 | 11 |
13 namespace content { | 12 namespace content { |
14 | 13 |
15 // A base class for device sensor related message filters. | 14 // Represents an externally-provided local or remote source of audio data. This |
16 class DeviceSensorMessageFilter : public BrowserMessageFilter { | 15 // allows users of the public content::MediaStreamApi to provide a |
| 16 // media::AudioCapturerSource to be used as the source of audio data in the |
| 17 // MediaStream framework. Audio data is transported directly to the tracks |
| 18 // (i.e., there is no audio processing). |
| 19 class CONTENT_EXPORT ExternalMediaStreamAudioSource final |
| 20 : NON_EXPORTED_BASE(public MediaStreamAudioSource), |
| 21 NON_EXPORTED_BASE(public media::AudioCapturerSource::CaptureCallback) { |
17 public: | 22 public: |
18 DeviceSensorMessageFilter(ConsumerType consumer_type, | 23 ExternalMediaStreamAudioSource( |
19 uint32_t message_class_to_filter); | 24 scoped_refptr<media::AudioCapturerSource> source, |
| 25 int sample_rate, |
| 26 media::ChannelLayout channel_layout, |
| 27 int frames_per_buffer, |
| 28 bool is_remote); |
20 | 29 |
21 protected: | 30 ~ExternalMediaStreamAudioSource() final; |
22 // All methods below to be called on the IO thread. | |
23 ~DeviceSensorMessageFilter() override; | |
24 | |
25 virtual void OnStartPolling(); | |
26 virtual void OnStopPolling(); | |
27 // To be overriden by the subclass in order to send the appropriate message | |
28 // to the renderer with a handle to shared memory. | |
29 virtual void DidStartPolling(base::SharedMemoryHandle handle) = 0; | |
30 | 31 |
31 private: | 32 private: |
32 ConsumerType consumer_type_; | 33 // MediaStreamAudioSource implementation. |
| 34 void DoStopSource() final; |
| 35 bool EnsureSourceIsStarted() final; |
| 36 |
| 37 // media::AudioCapturerSource::CaptureCallback implementation. |
| 38 void Capture(const media::AudioBus* audio_bus, |
| 39 int audio_delay_milliseconds, |
| 40 double volume, |
| 41 bool key_pressed) final; |
| 42 void OnCaptureError(const std::string& message) final; |
| 43 |
| 44 // The external source provided to the constructor. |
| 45 const scoped_refptr<media::AudioCapturerSource> source_; |
| 46 |
| 47 // True once the source has been started successfully. |
33 bool is_started_; | 48 bool is_started_; |
34 | 49 |
35 DISALLOW_COPY_AND_ASSIGN(DeviceSensorMessageFilter); | 50 DISALLOW_COPY_AND_ASSIGN(ExternalMediaStreamAudioSource); |
36 }; | 51 }; |
37 | 52 |
38 } // namespace content | 53 } // namespace content |
39 | 54 |
40 #endif // CONTENT_BROWSER_DEVICE_SENSORS_DEVICE_SENSOR_MESSAGE_FILTER_H_ | 55 #endif // CONTENT_RENDERER_MEDIA_EXTERNAL_MEDIA_STREAM_AUDIO_SOURCE_H_ |
OLD | NEW |