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 // 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 // AudioOutputController AudioDevice | 10 // AudioOutputController AudioDevice |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // - Pause() is asynchronous/non-blocking. | 59 // - Pause() is asynchronous/non-blocking. |
60 // - The user must call Stop() before deleting the class instance. | 60 // - The user must call Stop() before deleting the class instance. |
61 | 61 |
62 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 62 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
63 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 63 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
64 #pragma once | 64 #pragma once |
65 | 65 |
66 #include <vector> | 66 #include <vector> |
67 | 67 |
68 #include "base/basictypes.h" | 68 #include "base/basictypes.h" |
| 69 #include "base/bind.h" |
69 #include "base/memory/scoped_ptr.h" | 70 #include "base/memory/scoped_ptr.h" |
| 71 #include "base/message_loop.h" |
70 #include "base/shared_memory.h" | 72 #include "base/shared_memory.h" |
71 #include "base/synchronization/lock.h" | 73 #include "base/synchronization/lock.h" |
72 #include "base/threading/simple_thread.h" | 74 #include "base/threading/simple_thread.h" |
73 #include "content/common/content_export.h" | 75 #include "content/common/content_export.h" |
74 #include "content/renderer/media/audio_message_filter.h" | 76 #include "content/renderer/media/audio_message_filter.h" |
| 77 #include "content/renderer/media/scoped_loop_observer.h" |
75 #include "media/audio/audio_parameters.h" | 78 #include "media/audio/audio_parameters.h" |
76 #include "media/base/audio_renderer_sink.h" | 79 #include "media/base/audio_renderer_sink.h" |
77 | 80 |
78 namespace base { | |
79 class WaitableEvent; | |
80 } | |
81 | |
82 class CONTENT_EXPORT AudioDevice | 81 class CONTENT_EXPORT AudioDevice |
83 : NON_EXPORTED_BASE(public media::AudioRendererSink), | 82 : NON_EXPORTED_BASE(public media::AudioRendererSink), |
84 public AudioMessageFilter::Delegate, | 83 public AudioMessageFilter::Delegate, |
85 public base::DelegateSimpleThread::Delegate { | 84 public base::DelegateSimpleThread::Delegate, |
| 85 public ScopedLoopObserver { |
86 public: | 86 public: |
87 // Methods called on main render thread ------------------------------------- | 87 // Methods called on main render thread ------------------------------------- |
88 | 88 |
89 // Minimal constructor where Initialize() must be called later. | 89 // Minimal constructor where Initialize() must be called later. |
90 AudioDevice(); | 90 AudioDevice(); |
91 | 91 |
92 AudioDevice(size_t buffer_size, | 92 AudioDevice(size_t buffer_size, |
93 int channels, | 93 int channels, |
94 double sample_rate, | 94 double sample_rate, |
95 RenderCallback* callback); | 95 RenderCallback* callback); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // continuous stream host just ignores it and assumes buffer is always filled | 162 // continuous stream host just ignores it and assumes buffer is always filled |
163 // to its capacity. | 163 // to its capacity. |
164 size_t FireRenderCallback(int16* data); | 164 size_t FireRenderCallback(int16* data); |
165 | 165 |
166 // DelegateSimpleThread::Delegate implementation. | 166 // DelegateSimpleThread::Delegate implementation. |
167 virtual void Run() OVERRIDE; | 167 virtual void Run() OVERRIDE; |
168 | 168 |
169 // Closes socket and joins with the audio thread. | 169 // Closes socket and joins with the audio thread. |
170 void ShutDownAudioThread(); | 170 void ShutDownAudioThread(); |
171 | 171 |
| 172 // MessageLoop::DestructionObserver implementation for the IO loop. |
| 173 // If the IO loop dies before we do, we shut down the audio thread from here. |
| 174 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 175 |
172 // Format | 176 // Format |
173 size_t buffer_size_; // in sample-frames | 177 size_t buffer_size_; // in sample-frames |
174 int channels_; | 178 int channels_; |
175 int bits_per_sample_; | 179 int bits_per_sample_; |
176 double sample_rate_; | 180 double sample_rate_; |
177 AudioParameters::Format latency_format_; | 181 AudioParameters::Format latency_format_; |
178 | 182 |
179 RenderCallback* callback_; | 183 RenderCallback* callback_; |
180 | 184 |
181 // The client callback renders audio into here. | 185 // The client callback renders audio into here. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // These variables must only be set on the IO thread while the audio_thread_ | 221 // These variables must only be set on the IO thread while the audio_thread_ |
218 // is not running. | 222 // is not running. |
219 base::SharedMemoryHandle shared_memory_handle_; | 223 base::SharedMemoryHandle shared_memory_handle_; |
220 scoped_ptr<base::CancelableSyncSocket> audio_socket_; | 224 scoped_ptr<base::CancelableSyncSocket> audio_socket_; |
221 int memory_length_; | 225 int memory_length_; |
222 | 226 |
223 DISALLOW_COPY_AND_ASSIGN(AudioDevice); | 227 DISALLOW_COPY_AND_ASSIGN(AudioDevice); |
224 }; | 228 }; |
225 | 229 |
226 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 230 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
OLD | NEW |