| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 last_processing_time_(-1), | 51 last_processing_time_(-1), |
| 52 last_non_silent_time_(-1), | 52 last_non_silent_time_(-1), |
| 53 connection_ref_count_(0), | 53 connection_ref_count_(0), |
| 54 is_disabled_(false), | 54 is_disabled_(false), |
| 55 channel_count_(2) { | 55 channel_count_(2) { |
| 56 SetNodeType(node_type); | 56 SetNodeType(node_type); |
| 57 SetInternalChannelCountMode(kMax); | 57 SetInternalChannelCountMode(kMax); |
| 58 SetInternalChannelInterpretation(AudioBus::kSpeakers); | 58 SetInternalChannelInterpretation(AudioBus::kSpeakers); |
| 59 | 59 |
| 60 #if DEBUG_AUDIONODE_REFERENCES | 60 #if DEBUG_AUDIONODE_REFERENCES |
| 61 if (!s_isNodeCountInitialized) { | 61 if (!is_node_count_initialized_) { |
| 62 s_isNodeCountInitialized = true; | 62 is_node_count_initialized_ = true; |
| 63 atexit(AudioHandler::printNodeCounts); | 63 atexit(AudioHandler::PrintNodeCounts); |
| 64 } | 64 } |
| 65 #endif | 65 #endif |
| 66 InstanceCounters::IncrementCounter(InstanceCounters::kAudioHandlerCounter); | 66 InstanceCounters::IncrementCounter(InstanceCounters::kAudioHandlerCounter); |
| 67 } | 67 } |
| 68 | 68 |
| 69 AudioHandler::~AudioHandler() { | 69 AudioHandler::~AudioHandler() { |
| 70 DCHECK(IsMainThread()); | 70 DCHECK(IsMainThread()); |
| 71 // dispose() should be called. | 71 // dispose() should be called. |
| 72 DCHECK(!GetNode()); | 72 DCHECK(!GetNode()); |
| 73 InstanceCounters::DecrementCounter(InstanceCounters::kAudioHandlerCounter); | 73 InstanceCounters::DecrementCounter(InstanceCounters::kAudioHandlerCounter); |
| 74 #if DEBUG_AUDIONODE_REFERENCES | 74 #if DEBUG_AUDIONODE_REFERENCES |
| 75 --s_nodeCount[getNodeType()]; | 75 --node_count_[GetNodeType()]; |
| 76 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::~AudioHandler() %d [%d]\n", | 76 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::~AudioHandler() %d [%d]\n", |
| 77 context(), this, getNodeType(), m_connectionRefCount, | 77 Context(), this, GetNodeType(), connection_ref_count_, |
| 78 s_nodeCount[getNodeType()]); | 78 node_count_[GetNodeType()]); |
| 79 #endif | 79 #endif |
| 80 } | 80 } |
| 81 | 81 |
| 82 void AudioHandler::Initialize() { | 82 void AudioHandler::Initialize() { |
| 83 DCHECK_EQ(new_channel_count_mode_, channel_count_mode_); | 83 DCHECK_EQ(new_channel_count_mode_, channel_count_mode_); |
| 84 DCHECK_EQ(new_channel_interpretation_, channel_interpretation_); | 84 DCHECK_EQ(new_channel_interpretation_, channel_interpretation_); |
| 85 | 85 |
| 86 is_initialized_ = true; | 86 is_initialized_ = true; |
| 87 } | 87 } |
| 88 | 88 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void AudioHandler::SetNodeType(NodeType type) { | 162 void AudioHandler::SetNodeType(NodeType type) { |
| 163 // Don't allow the node type to be changed to a different node type, after | 163 // Don't allow the node type to be changed to a different node type, after |
| 164 // it's already been set. And the new type can't be unknown or end. | 164 // it's already been set. And the new type can't be unknown or end. |
| 165 DCHECK_EQ(node_type_, kNodeTypeUnknown); | 165 DCHECK_EQ(node_type_, kNodeTypeUnknown); |
| 166 DCHECK_NE(type, kNodeTypeUnknown); | 166 DCHECK_NE(type, kNodeTypeUnknown); |
| 167 DCHECK_NE(type, kNodeTypeEnd); | 167 DCHECK_NE(type, kNodeTypeEnd); |
| 168 | 168 |
| 169 node_type_ = type; | 169 node_type_ = type; |
| 170 | 170 |
| 171 #if DEBUG_AUDIONODE_REFERENCES | 171 #if DEBUG_AUDIONODE_REFERENCES |
| 172 ++s_nodeCount[type]; | 172 ++node_count_[type]; |
| 173 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::AudioHandler [%3d]\n", | 173 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::AudioHandler [%3d]\n", |
| 174 context(), this, getNodeType(), s_nodeCount[getNodeType()]); | 174 Context(), this, GetNodeType(), node_count_[GetNodeType()]); |
| 175 #endif | 175 #endif |
| 176 } | 176 } |
| 177 | 177 |
| 178 void AudioHandler::AddInput() { | 178 void AudioHandler::AddInput() { |
| 179 inputs_.push_back(AudioNodeInput::Create(*this)); | 179 inputs_.push_back(AudioNodeInput::Create(*this)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void AudioHandler::AddOutput(unsigned number_of_channels) { | 182 void AudioHandler::AddOutput(unsigned number_of_channels) { |
| 183 DCHECK(IsMainThread()); | 183 DCHECK(IsMainThread()); |
| 184 outputs_.push_back(AudioNodeOutput::Create(this, number_of_channels)); | 184 outputs_.push_back(AudioNodeOutput::Create(this, number_of_channels)); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 output->Disable(); | 447 output->Disable(); |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 void AudioHandler::MakeConnection() { | 452 void AudioHandler::MakeConnection() { |
| 453 AtomicIncrement(&connection_ref_count_); | 453 AtomicIncrement(&connection_ref_count_); |
| 454 | 454 |
| 455 #if DEBUG_AUDIONODE_REFERENCES | 455 #if DEBUG_AUDIONODE_REFERENCES |
| 456 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::ref %3d [%3d]\n", | 456 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::ref %3d [%3d]\n", |
| 457 context(), this, getNodeType(), m_connectionRefCount, | 457 Context(), this, GetNodeType(), connection_ref_count_, |
| 458 s_nodeCount[getNodeType()]); | 458 node_count_[GetNodeType()]); |
| 459 #endif | 459 #endif |
| 460 // See the disabling code in disableOutputsIfNecessary(). This handles | 460 // See the disabling code in disableOutputsIfNecessary(). This handles |
| 461 // the case where a node is being re-connected after being used at least | 461 // the case where a node is being re-connected after being used at least |
| 462 // once and disconnected. In this case, we need to re-enable. | 462 // once and disconnected. In this case, we need to re-enable. |
| 463 EnableOutputsIfNecessary(); | 463 EnableOutputsIfNecessary(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void AudioHandler::BreakConnection() { | 466 void AudioHandler::BreakConnection() { |
| 467 // The actual work for deref happens completely within the audio context's | 467 // The actual work for deref happens completely within the audio context's |
| 468 // graph lock. In the case of the audio thread, we must use a tryLock to | 468 // graph lock. In the case of the audio thread, we must use a tryLock to |
| (...skipping 16 matching lines...) Expand all Loading... |
| 485 DCHECK(Context()->IsAudioThread()); | 485 DCHECK(Context()->IsAudioThread()); |
| 486 Context()->GetDeferredTaskHandler().AddDeferredBreakConnection(*this); | 486 Context()->GetDeferredTaskHandler().AddDeferredBreakConnection(*this); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 void AudioHandler::BreakConnectionWithLock() { | 490 void AudioHandler::BreakConnectionWithLock() { |
| 491 AtomicDecrement(&connection_ref_count_); | 491 AtomicDecrement(&connection_ref_count_); |
| 492 | 492 |
| 493 #if DEBUG_AUDIONODE_REFERENCES | 493 #if DEBUG_AUDIONODE_REFERENCES |
| 494 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::deref %3d [%3d]\n", | 494 fprintf(stderr, "[%16p]: %16p: %2d: AudioHandler::deref %3d [%3d]\n", |
| 495 context(), this, getNodeType(), m_connectionRefCount, | 495 Context(), this, GetNodeType(), connection_ref_count_, |
| 496 s_nodeCount[getNodeType()]); | 496 node_count_[GetNodeType()]); |
| 497 #endif | 497 #endif |
| 498 | 498 |
| 499 if (!connection_ref_count_) | 499 if (!connection_ref_count_) |
| 500 DisableOutputsIfNecessary(); | 500 DisableOutputsIfNecessary(); |
| 501 } | 501 } |
| 502 | 502 |
| 503 #if DEBUG_AUDIONODE_REFERENCES | 503 #if DEBUG_AUDIONODE_REFERENCES |
| 504 | 504 |
| 505 bool AudioHandler::s_isNodeCountInitialized = false; | 505 bool AudioHandler::is_node_count_initialized_ = false; |
| 506 int AudioHandler::s_nodeCount[NodeTypeEnd]; | 506 int AudioHandler::node_count_[kNodeTypeEnd]; |
| 507 | 507 |
| 508 void AudioHandler::printNodeCounts() { | 508 void AudioHandler::PrintNodeCounts() { |
| 509 fprintf(stderr, "\n\n"); | 509 fprintf(stderr, "\n\n"); |
| 510 fprintf(stderr, "===========================\n"); | 510 fprintf(stderr, "===========================\n"); |
| 511 fprintf(stderr, "AudioNode: reference counts\n"); | 511 fprintf(stderr, "AudioNode: reference counts\n"); |
| 512 fprintf(stderr, "===========================\n"); | 512 fprintf(stderr, "===========================\n"); |
| 513 | 513 |
| 514 for (unsigned i = 0; i < NodeTypeEnd; ++i) | 514 for (unsigned i = 0; i < kNodeTypeEnd; ++i) |
| 515 fprintf(stderr, "%2d: %d\n", i, s_nodeCount[i]); | 515 fprintf(stderr, "%2d: %d\n", i, node_count_[i]); |
| 516 | 516 |
| 517 fprintf(stderr, "===========================\n\n\n"); | 517 fprintf(stderr, "===========================\n\n\n"); |
| 518 } | 518 } |
| 519 | 519 |
| 520 #endif // DEBUG_AUDIONODE_REFERENCES | 520 #endif // DEBUG_AUDIONODE_REFERENCES |
| 521 | 521 |
| 522 void AudioHandler::UpdateChannelCountMode() { | 522 void AudioHandler::UpdateChannelCountMode() { |
| 523 channel_count_mode_ = new_channel_count_mode_; | 523 channel_count_mode_ = new_channel_count_mode_; |
| 524 UpdateChannelsForInputs(); | 524 UpdateChannelsForInputs(); |
| 525 } | 525 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 539 } | 539 } |
| 540 // ---------------------------------------------------------------- | 540 // ---------------------------------------------------------------- |
| 541 | 541 |
| 542 AudioNode::AudioNode(BaseAudioContext& context) | 542 AudioNode::AudioNode(BaseAudioContext& context) |
| 543 : context_(context), handler_(nullptr) {} | 543 : context_(context), handler_(nullptr) {} |
| 544 | 544 |
| 545 void AudioNode::Dispose() { | 545 void AudioNode::Dispose() { |
| 546 DCHECK(IsMainThread()); | 546 DCHECK(IsMainThread()); |
| 547 #if DEBUG_AUDIONODE_REFERENCES | 547 #if DEBUG_AUDIONODE_REFERENCES |
| 548 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::dispose %16p\n", context(), | 548 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::dispose %16p\n", context(), |
| 549 this, handler().getNodeType(), m_handler.get()); | 549 this, Handler().GetNodeType(), handler_.Get()); |
| 550 #endif | 550 #endif |
| 551 BaseAudioContext::AutoLocker locker(context()); | 551 BaseAudioContext::AutoLocker locker(context()); |
| 552 Handler().Dispose(); | 552 Handler().Dispose(); |
| 553 if (context()->ContextState() == BaseAudioContext::kRunning) | 553 if (context()->ContextState() == BaseAudioContext::kRunning) |
| 554 context()->GetDeferredTaskHandler().AddRenderingOrphanHandler( | 554 context()->GetDeferredTaskHandler().AddRenderingOrphanHandler( |
| 555 handler_.Release()); | 555 handler_.Release()); |
| 556 } | 556 } |
| 557 | 557 |
| 558 void AudioNode::SetHandler(PassRefPtr<AudioHandler> handler) { | 558 void AudioNode::SetHandler(PassRefPtr<AudioHandler> handler) { |
| 559 DCHECK(handler); | 559 DCHECK(handler); |
| 560 handler_ = std::move(handler); | 560 handler_ = std::move(handler); |
| 561 | 561 |
| 562 #if DEBUG_AUDIONODE_REFERENCES | 562 #if DEBUG_AUDIONODE_REFERENCES |
| 563 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::AudioNode %16p\n", context(), | 563 fprintf(stderr, "[%16p]: %16p: %2d: AudioNode::AudioNode %16p\n", context(), |
| 564 this, m_handler->getNodeType(), m_handler.get()); | 564 this, handler_->GetNodeType(), handler_.Get()); |
| 565 #endif | 565 #endif |
| 566 } | 566 } |
| 567 | 567 |
| 568 AudioHandler& AudioNode::Handler() const { | 568 AudioHandler& AudioNode::Handler() const { |
| 569 return *handler_; | 569 return *handler_; |
| 570 } | 570 } |
| 571 | 571 |
| 572 DEFINE_TRACE(AudioNode) { | 572 DEFINE_TRACE(AudioNode) { |
| 573 visitor->Trace(context_); | 573 visitor->Trace(context_); |
| 574 visitor->Trace(connected_nodes_); | 574 visitor->Trace(connected_nodes_); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 } | 968 } |
| 969 | 969 |
| 970 void AudioNode::DidAddOutput(unsigned number_of_outputs) { | 970 void AudioNode::DidAddOutput(unsigned number_of_outputs) { |
| 971 connected_nodes_.push_back(nullptr); | 971 connected_nodes_.push_back(nullptr); |
| 972 DCHECK_EQ(number_of_outputs, connected_nodes_.size()); | 972 DCHECK_EQ(number_of_outputs, connected_nodes_.size()); |
| 973 connected_params_.push_back(nullptr); | 973 connected_params_.push_back(nullptr); |
| 974 DCHECK_EQ(number_of_outputs, connected_params_.size()); | 974 DCHECK_EQ(number_of_outputs, connected_params_.size()); |
| 975 } | 975 } |
| 976 | 976 |
| 977 } // namespace blink | 977 } // namespace blink |
| OLD | NEW |