| 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 // Audio rendering unit utilizing audio output stream provided by browser | 5 // Audio rendering unit utilizing audio output stream provided by browser |
| 6 // process through IPC. | 6 // process through IPC. |
| 7 // | 7 // |
| 8 // Relationship of classes. | 8 // Relationship of classes. |
| 9 // | 9 // |
| 10 // AudioRendererHost AudioRendererImpl | 10 // AudioRendererHost AudioRendererImpl |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "media/filters/audio_renderer_base.h" | 51 #include "media/filters/audio_renderer_base.h" |
| 52 | 52 |
| 53 class AudioMessageFilter; | 53 class AudioMessageFilter; |
| 54 | 54 |
| 55 class AudioRendererImpl : public media::AudioRendererBase, | 55 class AudioRendererImpl : public media::AudioRendererBase, |
| 56 public AudioMessageFilter::Delegate, | 56 public AudioMessageFilter::Delegate, |
| 57 public base::DelegateSimpleThread::Delegate, | 57 public base::DelegateSimpleThread::Delegate, |
| 58 public MessageLoop::DestructionObserver { | 58 public MessageLoop::DestructionObserver { |
| 59 public: | 59 public: |
| 60 // Methods called on Render thread ------------------------------------------ | 60 // Methods called on Render thread ------------------------------------------ |
| 61 explicit AudioRendererImpl(AudioMessageFilter* filter); | 61 explicit AudioRendererImpl(); |
| 62 virtual ~AudioRendererImpl(); | 62 virtual ~AudioRendererImpl(); |
| 63 | 63 |
| 64 // Methods called on IO thread ---------------------------------------------- | 64 // Methods called on IO thread ---------------------------------------------- |
| 65 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. | 65 // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. |
| 66 virtual void OnRequestPacket(AudioBuffersState buffers_state); | 66 virtual void OnRequestPacket(AudioBuffersState buffers_state); |
| 67 virtual void OnStateChanged(AudioStreamState state); | 67 virtual void OnStateChanged(AudioStreamState state); |
| 68 virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length); | 68 virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length); |
| 69 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, | 69 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, |
| 70 base::SyncSocket::Handle socket_handle, | 70 base::SyncSocket::Handle socket_handle, |
| 71 uint32 length); | 71 uint32 length); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 94 // We are using either low- or high-latency code path. | 94 // We are using either low- or high-latency code path. |
| 95 enum LatencyType { | 95 enum LatencyType { |
| 96 kUninitializedLatency = 0, | 96 kUninitializedLatency = 0, |
| 97 kLowLatency, | 97 kLowLatency, |
| 98 kHighLatency | 98 kHighLatency |
| 99 }; | 99 }; |
| 100 static LatencyType latency_type_; | 100 static LatencyType latency_type_; |
| 101 | 101 |
| 102 // For access to constructor and IO thread methods. | 102 // For access to constructor and IO thread methods. |
| 103 friend class AudioRendererImplTest; | 103 friend class AudioRendererImplTest; |
| 104 friend class DelegateCaller; |
| 104 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Stop); | 105 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, Stop); |
| 105 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, | 106 FRIEND_TEST_ALL_PREFIXES(AudioRendererImplTest, |
| 106 DestroyedMessageLoop_ConsumeAudioSamples); | 107 DestroyedMessageLoop_ConsumeAudioSamples); |
| 107 // Helper methods. | 108 // Helper methods. |
| 108 // Convert number of bytes to duration of time using information about the | 109 // Convert number of bytes to duration of time using information about the |
| 109 // number of channels, sample rate and sample bits. | 110 // number of channels, sample rate and sample bits. |
| 110 base::TimeDelta ConvertToDuration(int bytes); | 111 base::TimeDelta ConvertToDuration(int bytes); |
| 111 | 112 |
| 112 // Methods call on IO thread ------------------------------------------------ | 113 // Methods call on IO thread ------------------------------------------------ |
| 113 // The following methods are tasks posted on the IO thread that needs to | 114 // The following methods are tasks posted on the IO thread that needs to |
| (...skipping 23 matching lines...) Expand all Loading... |
| 137 virtual void CreateAudioThread(); | 138 virtual void CreateAudioThread(); |
| 138 | 139 |
| 139 // Accessors used by tests. | 140 // Accessors used by tests. |
| 140 LatencyType latency_type() { | 141 LatencyType latency_type() { |
| 141 return latency_type_; | 142 return latency_type_; |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Should be called before any class instance is created. | 145 // Should be called before any class instance is created. |
| 145 static void set_latency_type(LatencyType latency_type); | 146 static void set_latency_type(LatencyType latency_type); |
| 146 | 147 |
| 148 // Helper method for IPC send calls. |
| 149 void Send(IPC::Message* message); |
| 150 |
| 147 // Used to calculate audio delay given bytes. | 151 // Used to calculate audio delay given bytes. |
| 148 uint32 bytes_per_second_; | 152 uint32 bytes_per_second_; |
| 149 | 153 |
| 150 scoped_refptr<AudioMessageFilter> filter_; | |
| 151 | |
| 152 // ID of the stream created in the browser process. | 154 // ID of the stream created in the browser process. |
| 153 int32 stream_id_; | 155 int32 stream_id_; |
| 154 | 156 |
| 155 // Memory shared by the browser process for audio buffer. | 157 // Memory shared by the browser process for audio buffer. |
| 156 scoped_ptr<base::SharedMemory> shared_memory_; | 158 scoped_ptr<base::SharedMemory> shared_memory_; |
| 157 uint32 shared_memory_size_; | 159 uint32 shared_memory_size_; |
| 158 | 160 |
| 161 // Cached audio message filter (lives on the main render thread). |
| 162 scoped_refptr<AudioMessageFilter> filter_; |
| 163 |
| 159 // Low latency IPC stuff. | 164 // Low latency IPC stuff. |
| 160 scoped_ptr<base::SyncSocket> socket_; | 165 scoped_ptr<base::SyncSocket> socket_; |
| 161 | 166 |
| 162 // That thread waits for audio input. | 167 // That thread waits for audio input. |
| 163 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 168 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 164 | 169 |
| 165 // Message loop for the IO thread. | |
| 166 MessageLoop* io_loop_; | |
| 167 | |
| 168 // Protects: | 170 // Protects: |
| 169 // - |stopped_| | 171 // - |stopped_| |
| 170 // - |pending_request_| | 172 // - |pending_request_| |
| 171 // - |request_buffers_state_| | 173 // - |request_buffers_state_| |
| 172 base::Lock lock_; | 174 base::Lock lock_; |
| 173 | 175 |
| 174 // A flag that indicates this filter is called to stop. | 176 // A flag that indicates this filter is called to stop. |
| 175 bool stopped_; | 177 bool stopped_; |
| 176 | 178 |
| 177 // A flag that indicates an outstanding packet request. | 179 // A flag that indicates an outstanding packet request. |
| 178 bool pending_request_; | 180 bool pending_request_; |
| 179 | 181 |
| 180 // State of the audio buffers at time of the last request. | 182 // State of the audio buffers at time of the last request. |
| 181 AudioBuffersState request_buffers_state_; | 183 AudioBuffersState request_buffers_state_; |
| 182 | 184 |
| 183 // State variables for prerolling. | 185 // State variables for prerolling. |
| 184 bool prerolling_; | 186 bool prerolling_; |
| 185 | 187 |
| 186 // Remaining bytes for prerolling to complete. | 188 // Remaining bytes for prerolling to complete. |
| 187 uint32 preroll_bytes_; | 189 uint32 preroll_bytes_; |
| 188 | 190 |
| 189 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); | 191 DISALLOW_COPY_AND_ASSIGN(AudioRendererImpl); |
| 190 }; | 192 }; |
| 191 | 193 |
| 192 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_ | 194 #endif // CONTENT_RENDERER_MEDIA_AUDIO_RENDERER_IMPL_H_ |
| OLD | NEW |