| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/sequence_checker.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/threading/non_thread_safe.h" | |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "content/public/renderer/media_stream_audio_renderer.h" | 21 #include "content/public/renderer/media_stream_audio_renderer.h" |
| 22 #include "content/renderer/media/webrtc_audio_device_impl.h" | 22 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 23 #include "media/base/audio_decoder.h" | 23 #include "media/base/audio_decoder.h" |
| 24 #include "media/base/audio_pull_fifo.h" | 24 #include "media/base/audio_pull_fifo.h" |
| 25 #include "media/base/audio_renderer_sink.h" | 25 #include "media/base/audio_renderer_sink.h" |
| 26 #include "media/base/channel_layout.h" | 26 #include "media/base/channel_layout.h" |
| 27 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 27 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 28 | 28 |
| 29 namespace webrtc { | 29 namespace webrtc { |
| 30 class AudioSourceInterface; | 30 class AudioSourceInterface; |
| 31 } // namespace webrtc | 31 } // namespace webrtc |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 class WebRtcAudioRendererSource; | 35 class WebRtcAudioRendererSource; |
| 36 | 36 |
| 37 // This renderer handles calls from the pipeline and WebRtc ADM. It is used | 37 // This renderer handles calls from the pipeline and WebRtc ADM. It is used |
| 38 // for connecting WebRtc MediaStream with the audio pipeline. | 38 // for connecting WebRtc MediaStream with the audio pipeline. |
| 39 class CONTENT_EXPORT WebRtcAudioRenderer | 39 class CONTENT_EXPORT WebRtcAudioRenderer |
| 40 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), | 40 : NON_EXPORTED_BASE(public media::AudioRendererSink::RenderCallback), |
| 41 NON_EXPORTED_BASE(public MediaStreamAudioRenderer) { | 41 NON_EXPORTED_BASE(public MediaStreamAudioRenderer) { |
| 42 public: | 42 public: |
| 43 // This is a little utility class that holds the configured state of an audio | 43 // This is a little utility class that holds the configured state of an audio |
| 44 // stream. | 44 // stream. |
| 45 // It is used by both WebRtcAudioRenderer and SharedAudioRenderer (see cc | 45 // It is used by both WebRtcAudioRenderer and SharedAudioRenderer (see cc |
| 46 // file) so a part of why it exists is to avoid code duplication and track | 46 // file) so a part of why it exists is to avoid code duplication and track |
| 47 // the state in the same way in WebRtcAudioRenderer and SharedAudioRenderer. | 47 // the state in the same way in WebRtcAudioRenderer and SharedAudioRenderer. |
| 48 class PlayingState : public base::NonThreadSafe { | 48 class PlayingState { |
| 49 public: | 49 public: |
| 50 PlayingState() : playing_(false), volume_(1.0f) {} | 50 PlayingState() : playing_(false), volume_(1.0f) {} |
| 51 | 51 |
| 52 ~PlayingState() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } |
| 53 |
| 52 bool playing() const { | 54 bool playing() const { |
| 53 DCHECK(CalledOnValidThread()); | 55 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 54 return playing_; | 56 return playing_; |
| 55 } | 57 } |
| 56 | 58 |
| 57 void set_playing(bool playing) { | 59 void set_playing(bool playing) { |
| 58 DCHECK(CalledOnValidThread()); | 60 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 59 playing_ = playing; | 61 playing_ = playing; |
| 60 } | 62 } |
| 61 | 63 |
| 62 float volume() const { | 64 float volume() const { |
| 63 DCHECK(CalledOnValidThread()); | 65 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 64 return volume_; | 66 return volume_; |
| 65 } | 67 } |
| 66 | 68 |
| 67 void set_volume(float volume) { | 69 void set_volume(float volume) { |
| 68 DCHECK(CalledOnValidThread()); | 70 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 69 volume_ = volume; | 71 volume_ = volume; |
| 70 } | 72 } |
| 71 | 73 |
| 72 private: | 74 private: |
| 73 bool playing_; | 75 bool playing_; |
| 74 float volume_; | 76 float volume_; |
| 77 |
| 78 SEQUENCE_CHECKER(sequence_checker_); |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 WebRtcAudioRenderer( | 81 WebRtcAudioRenderer( |
| 78 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread, | 82 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread, |
| 79 const blink::WebMediaStream& media_stream, | 83 const blink::WebMediaStream& media_stream, |
| 80 int source_render_frame_id, | 84 int source_render_frame_id, |
| 81 int session_id, | 85 int session_id, |
| 82 const std::string& device_id, | 86 const std::string& device_id, |
| 83 const url::Origin& security_origin); | 87 const url::Origin& security_origin); |
| 84 | 88 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // Stores the maximum time spent waiting for render data from the source. Used | 262 // Stores the maximum time spent waiting for render data from the source. Used |
| 259 // for logging UMA data. Logged and reset when Stop() is called. | 263 // for logging UMA data. Logged and reset when Stop() is called. |
| 260 base::TimeDelta max_render_time_; | 264 base::TimeDelta max_render_time_; |
| 261 | 265 |
| 262 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); | 266 DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioRenderer); |
| 263 }; | 267 }; |
| 264 | 268 |
| 265 } // namespace content | 269 } // namespace content |
| 266 | 270 |
| 267 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ | 271 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_RENDERER_H_ |
| OLD | NEW |