Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Low-latency audio rendering unit utilizing audio output stream provided | 5 // Low-latency audio rendering unit utilizing audio output stream provided |
| 6 // by browser process through IPC. | 6 // by browser process through IPC. |
| 7 // | 7 // |
| 8 // Relationship of classes. | 8 // Relationship of classes. |
| 9 // | 9 // |
| 10 // AudioOutputController AudioDevice | 10 // AudioOutputController AudioDevice |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 #include <vector> | 66 #include <vector> |
| 67 | 67 |
| 68 #include "base/basictypes.h" | 68 #include "base/basictypes.h" |
| 69 #include "base/memory/scoped_ptr.h" | 69 #include "base/memory/scoped_ptr.h" |
| 70 #include "base/shared_memory.h" | 70 #include "base/shared_memory.h" |
| 71 #include "base/synchronization/lock.h" | 71 #include "base/synchronization/lock.h" |
| 72 #include "base/threading/simple_thread.h" | 72 #include "base/threading/simple_thread.h" |
| 73 #include "content/common/content_export.h" | 73 #include "content/common/content_export.h" |
| 74 #include "content/renderer/media/audio_message_filter.h" | 74 #include "content/renderer/media/audio_message_filter.h" |
| 75 #include "media/audio/audio_parameters.h" | 75 #include "media/audio/audio_parameters.h" |
| 76 #include "media/filters/audio_renderer_sink.h" | |
| 76 | 77 |
| 77 class CONTENT_EXPORT AudioDevice | 78 class CONTENT_EXPORT AudioDevice |
| 78 : public AudioMessageFilter::Delegate, | 79 : public media::AudioRendererSink, |
| 79 public base::DelegateSimpleThread::Delegate, | 80 public AudioMessageFilter::Delegate, |
| 80 public base::RefCountedThreadSafe<AudioDevice> { | 81 public base::DelegateSimpleThread::Delegate { |
| 81 public: | 82 public: |
| 82 class CONTENT_EXPORT RenderCallback { | |
| 83 public: | |
| 84 virtual void Render(const std::vector<float*>& audio_data, | |
| 85 size_t number_of_frames, | |
| 86 size_t audio_delay_milliseconds) = 0; | |
| 87 protected: | |
| 88 virtual ~RenderCallback() {} | |
| 89 }; | |
| 90 | |
| 91 // Methods called on main render thread ------------------------------------- | 83 // Methods called on main render thread ------------------------------------- |
| 92 | 84 |
| 93 // Minimal constructor where Initialize() must be called later. | 85 // Minimal constructor where Initialize() must be called later. |
| 94 AudioDevice(); | 86 AudioDevice(); |
| 95 | 87 |
| 96 AudioDevice(size_t buffer_size, | 88 AudioDevice(size_t buffer_size, |
| 97 int channels, | 89 int channels, |
| 98 double sample_rate, | 90 double sample_rate, |
| 99 RenderCallback* callback); | 91 RenderCallback* callback); |
| 100 virtual ~AudioDevice(); | 92 virtual ~AudioDevice(); |
| 101 | 93 |
| 102 void Initialize(size_t buffer_size, | 94 // AudioRendererSink implementation. |
| 103 int channels, | |
| 104 double sample_rate, | |
| 105 AudioParameters::Format latency_format, | |
| 106 RenderCallback* callback); | |
| 107 bool IsInitialized(); | |
| 108 | 95 |
| 96 virtual void Initialize(size_t buffer_size, | |
| 97 int channels, | |
| 98 double sample_rate, | |
| 99 AudioParameters::Format latency_format, | |
| 100 RenderCallback* callback) OVERRIDE; | |
| 109 // Starts audio playback. | 101 // Starts audio playback. |
| 110 void Start(); | 102 virtual void Start() OVERRIDE; |
| 111 | 103 |
| 112 // Stops audio playback. | 104 // Stops audio playback. |
| 113 void Stop(); | 105 virtual void Stop() OVERRIDE; |
| 114 | 106 |
| 115 // Resumes playback if currently paused. | 107 // Resumes playback if currently paused. |
| 116 // TODO(crogers): it should be possible to remove the extra complexity | 108 // TODO(crogers): it should be possible to remove the extra complexity |
| 117 // of Play() and Pause() with additional re-factoring work in | 109 // of Play() and Pause() with additional re-factoring work in |
| 118 // AudioRendererImpl. | 110 // AudioRendererImpl. |
| 119 void Play(); | 111 virtual void Play() OVERRIDE; |
| 120 | 112 |
| 121 // Pauses playback. | 113 // Pauses playback. |
| 122 // If |flush| is true then any pending audio that is in the pipeline | 114 // If |flush| is true then any pending audio that is in the pipeline |
| 123 // (has not yet reached the hardware) will be discarded. In this case, | 115 // (has not yet reached the hardware) will be discarded. In this case, |
| 124 // when Play() is later called, no previous pending audio will be | 116 // when Play() is later called, no previous pending audio will be |
| 125 // rendered. | 117 // rendered. |
| 126 void Pause(bool flush); | 118 virtual void Pause(bool flush) OVERRIDE; |
| 127 | 119 |
| 128 // Sets the playback volume, with range [0.0, 1.0] inclusive. | 120 // Sets the playback volume, with range [0.0, 1.0] inclusive. |
| 129 // Returns |true| on success. | 121 // Returns |true| on success. |
| 130 bool SetVolume(double volume); | 122 virtual bool SetVolume(double volume) OVERRIDE; |
| 131 | 123 |
| 132 // Gets the playback volume, with range [0.0, 1.0] inclusive. | 124 // Gets the playback volume, with range [0.0, 1.0] inclusive. |
| 133 void GetVolume(double* volume); | 125 void GetVolume(double* volume); |
|
henrika (OOO until Aug 14)
2011/12/20 21:01:01
My proposal was to make this one virtual as well.
Chris Rogers
2011/12/21 01:38:17
Done.
| |
| 134 | 126 |
| 135 double sample_rate() const { return sample_rate_; } | 127 double sample_rate() const { return sample_rate_; } |
| 136 size_t buffer_size() const { return buffer_size_; } | 128 size_t buffer_size() const { return buffer_size_; } |
| 137 | 129 |
| 138 // Methods called on IO thread ---------------------------------------------- | 130 // Methods called on IO thread ---------------------------------------------- |
| 139 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. | 131 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
| 140 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE; | 132 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE; |
| 141 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 133 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 142 virtual void OnCreated(base::SharedMemoryHandle handle, | 134 virtual void OnCreated(base::SharedMemoryHandle handle, |
| 143 uint32 length) OVERRIDE; | 135 uint32 length) OVERRIDE; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 210 |
| 219 // Protects lifetime of: | 211 // Protects lifetime of: |
| 220 // socket_handle_ | 212 // socket_handle_ |
| 221 // audio_thread_ | 213 // audio_thread_ |
| 222 base::Lock lock_; | 214 base::Lock lock_; |
| 223 | 215 |
| 224 DISALLOW_COPY_AND_ASSIGN(AudioDevice); | 216 DISALLOW_COPY_AND_ASSIGN(AudioDevice); |
| 225 }; | 217 }; |
| 226 | 218 |
| 227 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 219 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
| OLD | NEW |