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 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
11 #include "content/browser/browser_main_loop.h" | 11 #include "content/browser/browser_main_loop.h" |
12 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 12 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
13 #include "content/common/media/audio_messages.h" | 13 #include "content/common/media/audio_messages.h" |
14 #include "content/public/browser/media_observer.h" | 14 #include "content/public/browser/media_observer.h" |
15 #include "media/audio/shared_memory_util.h" | 15 #include "media/audio/shared_memory_util.h" |
16 #include "media/base/audio_bus.h" | |
16 | 17 |
17 using content::BrowserMessageFilter; | 18 using content::BrowserMessageFilter; |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 | 20 |
20 AudioRendererHost::AudioEntry::AudioEntry() | 21 AudioRendererHost::AudioEntry::AudioEntry() |
21 : stream_id(0), | 22 : stream_id(0), |
22 pending_close(false) { | 23 pending_close(false) { |
23 } | 24 } |
24 | 25 |
25 AudioRendererHost::AudioEntry::~AudioEntry() {} | 26 AudioRendererHost::AudioEntry::~AudioEntry() {} |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 return handled; | 192 return handled; |
192 } | 193 } |
193 | 194 |
194 void AudioRendererHost::OnCreateStream( | 195 void AudioRendererHost::OnCreateStream( |
195 int stream_id, const media::AudioParameters& params) { | 196 int stream_id, const media::AudioParameters& params) { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
197 DCHECK(LookupById(stream_id) == NULL); | 198 DCHECK(LookupById(stream_id) == NULL); |
198 | 199 |
199 media::AudioParameters audio_params(params); | 200 media::AudioParameters audio_params(params); |
200 DCHECK_GT(audio_params.frames_per_buffer(), 0); | 201 DCHECK_GT(audio_params.frames_per_buffer(), 0); |
201 | 202 uint32 buffer_size = media::AudioBus::CalculateMemorySize(audio_params); |
202 uint32 buffer_size = audio_params.GetBytesPerBuffer(); | 203 DCHECK_GT(buffer_size, 0U); |
Chris Rogers
2012/08/24 20:20:26
Does this DCHECK make sense? Since uint32 is unsi
DaleCurtis
2012/08/24 23:53:12
It does make sense since buffer_size could still b
| |
203 | 204 |
204 scoped_ptr<AudioEntry> entry(new AudioEntry()); | 205 scoped_ptr<AudioEntry> entry(new AudioEntry()); |
205 | 206 |
206 // Create the shared memory and share with the renderer process. | 207 // Create the shared memory and share with the renderer process. |
207 uint32 shared_memory_size = | 208 uint32 shared_memory_size = |
208 media::TotalSharedMemorySizeInBytes(buffer_size); | 209 media::TotalSharedMemorySizeInBytes(buffer_size); |
209 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) { | 210 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) { |
210 // If creation of shared memory failed then send an error message. | 211 // If creation of shared memory failed then send an error message. |
211 SendErrorMessage(stream_id); | 212 SendErrorMessage(stream_id); |
212 return; | 213 return; |
213 } | 214 } |
214 | 215 |
215 // Create sync reader and try to initialize it. | 216 // Create sync reader and try to initialize it. |
216 scoped_ptr<AudioSyncReader> reader( | 217 scoped_ptr<AudioSyncReader> reader( |
217 new AudioSyncReader(&entry->shared_memory)); | 218 new AudioSyncReader(&entry->shared_memory, params)); |
218 | 219 |
219 if (!reader->Init()) { | 220 if (!reader->Init()) { |
220 SendErrorMessage(stream_id); | 221 SendErrorMessage(stream_id); |
221 return; | 222 return; |
222 } | 223 } |
223 | 224 |
224 // If we have successfully created the SyncReader then assign it to the | 225 // If we have successfully created the SyncReader then assign it to the |
225 // entry and construct an AudioOutputController. | 226 // entry and construct an AudioOutputController. |
226 entry->reader.reset(reader.release()); | 227 entry->reader.reset(reader.release()); |
227 entry->controller = media::AudioOutputController::Create( | 228 entry->controller = media::AudioOutputController::Create( |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 377 |
377 // Iterate the map of entries. | 378 // Iterate the map of entries. |
378 // TODO(hclam): Implement a faster look up method. | 379 // TODO(hclam): Implement a faster look up method. |
379 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 380 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
380 i != audio_entries_.end(); ++i) { | 381 i != audio_entries_.end(); ++i) { |
381 if (!i->second->pending_close && controller == i->second->controller.get()) | 382 if (!i->second->pending_close && controller == i->second->controller.get()) |
382 return i->second; | 383 return i->second; |
383 } | 384 } |
384 return NULL; | 385 return NULL; |
385 } | 386 } |
OLD | NEW |