Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_renderer_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
17 #include "media/base/limits.h"
16 18
17 using content::BrowserMessageFilter; 19 using content::BrowserMessageFilter;
18 using content::BrowserThread; 20 using content::BrowserThread;
19 21
20 AudioRendererHost::AudioEntry::AudioEntry() 22 AudioRendererHost::AudioEntry::AudioEntry()
21 : stream_id(0), 23 : stream_id(0),
22 pending_close(false) { 24 pending_close(false) {
23 } 25 }
24 26
25 AudioRendererHost::AudioEntry::~AudioEntry() {} 27 AudioRendererHost::AudioEntry::~AudioEntry() {}
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 192
191 return handled; 193 return handled;
192 } 194 }
193 195
194 void AudioRendererHost::OnCreateStream( 196 void AudioRendererHost::OnCreateStream(
195 int stream_id, const media::AudioParameters& params) { 197 int stream_id, const media::AudioParameters& params) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
197 DCHECK(LookupById(stream_id) == NULL); 199 DCHECK(LookupById(stream_id) == NULL);
198 200
199 media::AudioParameters audio_params(params); 201 media::AudioParameters audio_params(params);
200 DCHECK_GT(audio_params.frames_per_buffer(), 0); 202 uint32 buffer_size = media::AudioBus::CalculateMemorySize(audio_params);
201 203 DCHECK_GT(buffer_size, 0U);
202 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 204 DCHECK_LE(buffer_size,
205 static_cast<uint32>(media::limits::kMaxPacketSizeInBytes));
203 206
204 scoped_ptr<AudioEntry> entry(new AudioEntry()); 207 scoped_ptr<AudioEntry> entry(new AudioEntry());
205 208
206 // Create the shared memory and share with the renderer process. 209 // Create the shared memory and share with the renderer process.
207 uint32 shared_memory_size = 210 uint32 shared_memory_size =
208 media::TotalSharedMemorySizeInBytes(buffer_size); 211 media::TotalSharedMemorySizeInBytes(buffer_size);
209 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) { 212 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) {
210 // If creation of shared memory failed then send an error message. 213 // If creation of shared memory failed then send an error message.
211 SendErrorMessage(stream_id); 214 SendErrorMessage(stream_id);
212 return; 215 return;
213 } 216 }
214 217
215 // Create sync reader and try to initialize it. 218 // Create sync reader and try to initialize it.
216 scoped_ptr<AudioSyncReader> reader( 219 scoped_ptr<AudioSyncReader> reader(
217 new AudioSyncReader(&entry->shared_memory)); 220 new AudioSyncReader(&entry->shared_memory, params));
218 221
219 if (!reader->Init()) { 222 if (!reader->Init()) {
220 SendErrorMessage(stream_id); 223 SendErrorMessage(stream_id);
221 return; 224 return;
222 } 225 }
223 226
224 // If we have successfully created the SyncReader then assign it to the 227 // If we have successfully created the SyncReader then assign it to the
225 // entry and construct an AudioOutputController. 228 // entry and construct an AudioOutputController.
226 entry->reader.reset(reader.release()); 229 entry->reader.reset(reader.release());
227 entry->controller = media::AudioOutputController::Create( 230 entry->controller = media::AudioOutputController::Create(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 379
377 // Iterate the map of entries. 380 // Iterate the map of entries.
378 // TODO(hclam): Implement a faster look up method. 381 // TODO(hclam): Implement a faster look up method.
379 for (AudioEntryMap::iterator i = audio_entries_.begin(); 382 for (AudioEntryMap::iterator i = audio_entries_.begin();
380 i != audio_entries_.end(); ++i) { 383 i != audio_entries_.end(); ++i) {
381 if (!i->second->pending_close && controller == i->second->controller.get()) 384 if (!i->second->pending_close && controller == i->second->controller.get())
382 return i->second; 385 return i->second;
383 } 386 }
384 return NULL; 387 return NULL;
385 } 388 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_renderer_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698