| 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 // 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/base/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 // Fills entire buffer of length |number_of_frames| but returns actual | |
| 85 // number of frames it got from its source (|number_of_frames| in case of | |
| 86 // continuous stream). That actual number of frames is passed to host | |
| 87 // together with PCM audio data and host is free to use or ignore it. | |
| 88 virtual size_t Render(const std::vector<float*>& audio_data, | |
| 89 size_t number_of_frames, | |
| 90 size_t audio_delay_milliseconds) = 0; | |
| 91 protected: | |
| 92 virtual ~RenderCallback() {} | |
| 93 }; | |
| 94 | |
| 95 // Methods called on main render thread ------------------------------------- | 83 // Methods called on main render thread ------------------------------------- |
| 96 | 84 |
| 97 // Minimal constructor where Initialize() must be called later. | 85 // Minimal constructor where Initialize() must be called later. |
| 98 AudioDevice(); | 86 AudioDevice(); |
| 99 | 87 |
| 100 AudioDevice(size_t buffer_size, | 88 AudioDevice(size_t buffer_size, |
| 101 int channels, | 89 int channels, |
| 102 double sample_rate, | 90 double sample_rate, |
| 103 RenderCallback* callback); | 91 RenderCallback* callback); |
| 104 virtual ~AudioDevice(); | 92 virtual ~AudioDevice(); |
| 105 | 93 |
| 106 void Initialize(size_t buffer_size, | 94 // AudioRendererSink implementation. |
| 107 int channels, | |
| 108 double sample_rate, | |
| 109 AudioParameters::Format latency_format, | |
| 110 RenderCallback* callback); | |
| 111 bool IsInitialized(); | |
| 112 | 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; |
| 113 // Starts audio playback. | 101 // Starts audio playback. |
| 114 void Start(); | 102 virtual void Start() OVERRIDE; |
| 115 | 103 |
| 116 // Stops audio playback. | 104 // Stops audio playback. |
| 117 void Stop(); | 105 virtual void Stop() OVERRIDE; |
| 118 | 106 |
| 119 // Resumes playback if currently paused. | 107 // Resumes playback if currently paused. |
| 120 // TODO(crogers): it should be possible to remove the extra complexity | 108 // TODO(crogers): it should be possible to remove the extra complexity |
| 121 // of Play() and Pause() with additional re-factoring work in | 109 // of Play() and Pause() with additional re-factoring work in |
| 122 // AudioRendererImpl. | 110 // AudioRendererImpl. |
| 123 void Play(); | 111 virtual void Play() OVERRIDE; |
| 124 | 112 |
| 125 // Pauses playback. | 113 // Pauses playback. |
| 126 // 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 |
| 127 // (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, |
| 128 // when Play() is later called, no previous pending audio will be | 116 // when Play() is later called, no previous pending audio will be |
| 129 // rendered. | 117 // rendered. |
| 130 void Pause(bool flush); | 118 virtual void Pause(bool flush) OVERRIDE; |
| 131 | 119 |
| 132 // Sets the playback volume, with range [0.0, 1.0] inclusive. | 120 // Sets the playback volume, with range [0.0, 1.0] inclusive. |
| 133 // Returns |true| on success. | 121 // Returns |true| on success. |
| 134 bool SetVolume(double volume); | 122 virtual bool SetVolume(double volume) OVERRIDE; |
| 135 | 123 |
| 136 // Gets the playback volume, with range [0.0, 1.0] inclusive. | 124 // Gets the playback volume, with range [0.0, 1.0] inclusive. |
| 137 void GetVolume(double* volume); | 125 virtual void GetVolume(double* volume) OVERRIDE; |
| 138 | 126 |
| 139 double sample_rate() const { return sample_rate_; } | 127 double sample_rate() const { return sample_rate_; } |
| 140 size_t buffer_size() const { return buffer_size_; } | 128 size_t buffer_size() const { return buffer_size_; } |
| 141 | 129 |
| 142 // Methods called on IO thread ---------------------------------------------- | 130 // Methods called on IO thread ---------------------------------------------- |
| 143 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. | 131 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
| 144 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE; | 132 virtual void OnRequestPacket(AudioBuffersState buffers_state) OVERRIDE; |
| 145 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 133 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 146 virtual void OnCreated(base::SharedMemoryHandle handle, | 134 virtual void OnCreated(base::SharedMemoryHandle handle, |
| 147 uint32 length) OVERRIDE; | 135 uint32 length) OVERRIDE; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 240 |
| 253 // Protects lifetime of: | 241 // Protects lifetime of: |
| 254 // audio_socket_ | 242 // audio_socket_ |
| 255 // audio_thread_ | 243 // audio_thread_ |
| 256 base::Lock lock_; | 244 base::Lock lock_; |
| 257 | 245 |
| 258 DISALLOW_COPY_AND_ASSIGN(AudioDevice); | 246 DISALLOW_COPY_AND_ASSIGN(AudioDevice); |
| 259 }; | 247 }; |
| 260 | 248 |
| 261 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 249 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
| OLD | NEW |