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

Side by Side Diff: chrome/browser/renderer_host/audio_renderer_host.cc

Issue 155372: Fix a bug in AudioRendererHost and add hooks for test (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 | « chrome/browser/renderer_host/audio_renderer_host.h ('k') | no next file » | 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/histogram.h" 5 #include "base/histogram.h"
6 #include "base/lock.h" 6 #include "base/lock.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/process.h" 8 #include "base/process.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "base/waitable_event.h" 10 #include "base/waitable_event.h"
11 #include "chrome/browser/renderer_host/audio_renderer_host.h" 11 #include "chrome/browser/renderer_host/audio_renderer_host.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 : host_(host), 63 : host_(host),
64 process_id_(process_id), 64 process_id_(process_id),
65 route_id_(route_id), 65 route_id_(route_id),
66 stream_id_(stream_id), 66 stream_id_(stream_id),
67 stream_(stream), 67 stream_(stream),
68 hardware_packet_size_(hardware_packet_size), 68 hardware_packet_size_(hardware_packet_size),
69 decoded_packet_size_(decoded_packet_size), 69 decoded_packet_size_(decoded_packet_size),
70 buffer_capacity_(buffer_capacity), 70 buffer_capacity_(buffer_capacity),
71 state_(AudioOutputStream::STATE_CREATED), 71 state_(AudioOutputStream::STATE_CREATED),
72 push_source_(hardware_packet_size), 72 push_source_(hardware_packet_size),
73 outstanding_request_(false) { 73 outstanding_request_(false),
74 last_copied_bytes_(0) {
74 } 75 }
75 76
76 AudioRendererHost::IPCAudioSource::~IPCAudioSource() { 77 AudioRendererHost::IPCAudioSource::~IPCAudioSource() {
78 DCHECK_EQ(AudioOutputStream::STATE_STOPPED, state_);
77 } 79 }
78 80
79 // static 81 // static
80 AudioRendererHost::IPCAudioSource* 82 AudioRendererHost::IPCAudioSource*
81 AudioRendererHost::IPCAudioSource::CreateIPCAudioSource( 83 AudioRendererHost::IPCAudioSource::CreateIPCAudioSource(
82 AudioRendererHost* host, 84 AudioRendererHost* host,
83 int process_id, 85 int process_id,
84 int route_id, 86 int route_id,
85 int stream_id, 87 int stream_id,
86 base::ProcessHandle process_handle, 88 base::ProcessHandle process_handle,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 host_->DestroySource(this); 248 host_->DestroySource(this);
247 } 249 }
248 250
249 void AudioRendererHost::IPCAudioSource::NotifyPacketReady( 251 void AudioRendererHost::IPCAudioSource::NotifyPacketReady(
250 size_t decoded_packet_size) { 252 size_t decoded_packet_size) {
251 bool ok = true; 253 bool ok = true;
252 { 254 {
253 AutoLock auto_lock(lock_); 255 AutoLock auto_lock(lock_);
254 outstanding_request_ = false; 256 outstanding_request_ = false;
255 #ifdef IPC_MESSAGE_LOG_ENABLED 257 #ifdef IPC_MESSAGE_LOG_ENABLED
256 if (IPC::Logging::current()->Enabled()) { 258 if (IPC::Logging::current() && IPC::Logging::current()->Enabled()) {
257 RecordRoundTripLatency(base::Time::Now() - outstanding_request_time_); 259 RecordRoundTripLatency(base::Time::Now() - outstanding_request_time_);
258 } 260 }
259 #endif 261 #endif
260 // If reported size is greater than capacity of the shared memory, we have 262 // If reported size is greater than capacity of the shared memory, we have
261 // an error. 263 // an error.
262 if (decoded_packet_size <= decoded_packet_size_) { 264 if (decoded_packet_size <= decoded_packet_size_) {
263 for (size_t i = 0; i < decoded_packet_size; i += hardware_packet_size_) { 265 for (size_t i = 0; i < decoded_packet_size; i += hardware_packet_size_) {
264 size_t size = std::min(decoded_packet_size - i, hardware_packet_size_); 266 size_t size = std::min(decoded_packet_size - i, hardware_packet_size_);
265 ok &= push_source_.Write( 267 ok &= push_source_.Write(
266 static_cast<char*>(shared_memory_.memory()) + i, size); 268 static_cast<char*>(shared_memory_.memory()) + i, size);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 process_handle_(0), 334 process_handle_(0),
333 ipc_sender_(NULL), 335 ipc_sender_(NULL),
334 io_loop_(message_loop) { 336 io_loop_(message_loop) {
335 // Make sure we perform actual initialization operations in the thread where 337 // Make sure we perform actual initialization operations in the thread where
336 // this object should live. 338 // this object should live.
337 io_loop_->PostTask(FROM_HERE, 339 io_loop_->PostTask(FROM_HERE,
338 NewRunnableMethod(this, &AudioRendererHost::OnInitialized)); 340 NewRunnableMethod(this, &AudioRendererHost::OnInitialized));
339 } 341 }
340 342
341 AudioRendererHost::~AudioRendererHost() { 343 AudioRendererHost::~AudioRendererHost() {
344 DCHECK(sources_.empty());
342 } 345 }
343 346
344 void AudioRendererHost::Destroy() { 347 void AudioRendererHost::Destroy() {
345 // Post a message to the thread where this object should live and do the 348 // Post a message to the thread where this object should live and do the
346 // actual operations there. 349 // actual operations there.
347 io_loop_->PostTask( 350 io_loop_->PostTask(
348 FROM_HERE, NewRunnableMethod(this, &AudioRendererHost::OnDestroyed)); 351 FROM_HERE, NewRunnableMethod(this, &AudioRendererHost::OnDestroyed));
349 } 352 }
350 353
351 // Event received when IPC channel is connected to the renderer process. 354 // Event received when IPC channel is connected to the renderer process.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 void AudioRendererHost::OnNotifyPacketReady(const IPC::Message& msg, 487 void AudioRendererHost::OnNotifyPacketReady(const IPC::Message& msg,
485 int stream_id, size_t packet_size) { 488 int stream_id, size_t packet_size) {
486 DCHECK(MessageLoop::current() == io_loop_); 489 DCHECK(MessageLoop::current() == io_loop_);
487 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); 490 IPCAudioSource* source = Lookup(msg.routing_id(), stream_id);
488 if (source) { 491 if (source) {
489 source->NotifyPacketReady(packet_size); 492 source->NotifyPacketReady(packet_size);
490 } else { 493 } else {
491 SendErrorMessage(msg.routing_id(), stream_id, 0); 494 SendErrorMessage(msg.routing_id(), stream_id, 0);
492 } 495 }
493 #ifdef IPC_MESSAGE_LOG_ENABLED 496 #ifdef IPC_MESSAGE_LOG_ENABLED
494 if (IPC::Logging::current()->Enabled()) { 497 if (IPC::Logging::current() && IPC::Logging::current()->Enabled()) {
495 RecordReceiveLatency(base::Time::FromInternalValue(msg.received_time()) - 498 RecordReceiveLatency(base::Time::FromInternalValue(msg.received_time()) -
496 base::Time::FromInternalValue(msg.sent_time())); 499 base::Time::FromInternalValue(msg.sent_time()));
497 RecordProcessTime(base::Time::Now() - 500 RecordProcessTime(base::Time::Now() -
498 base::Time::FromInternalValue(msg.received_time())); 501 base::Time::FromInternalValue(msg.received_time()));
499 } 502 }
500 #endif 503 #endif
501 } 504 }
502 505
503 void AudioRendererHost::OnInitialized() { 506 void AudioRendererHost::OnInitialized() {
504 DCHECK(MessageLoop::current() == io_loop_); 507 DCHECK(MessageLoop::current() == io_loop_);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (MessageLoop::current() == io_loop_) { 579 if (MessageLoop::current() == io_loop_) {
577 OnDestroySource(source); 580 OnDestroySource(source);
578 } else { 581 } else {
579 // TODO(hclam): make sure it's always safe to post a task to IO loop. 582 // TODO(hclam): make sure it's always safe to post a task to IO loop.
580 // It is possible that IO message loop is destroyed but there's still some 583 // It is possible that IO message loop is destroyed but there's still some
581 // dangling audio hardware threads that try to call this method. 584 // dangling audio hardware threads that try to call this method.
582 io_loop_->PostTask(FROM_HERE, 585 io_loop_->PostTask(FROM_HERE,
583 NewRunnableMethod(this, &AudioRendererHost::OnDestroySource, source)); 586 NewRunnableMethod(this, &AudioRendererHost::OnDestroySource, source));
584 } 587 }
585 } 588 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/audio_renderer_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698