void MediaStreamAudioDestinationHandler::setChannelCount(unsigned long channelCount, ExceptionState& exceptionState)
{
    ASSERT(isMainThread());

    // Currently the maximum channel count supported for this node is 8,
    // which is constrained by m_source (WebAudioCapturereSource). Although
    // it has its own safety check for the excessive channels, throwing an
    // exception here is useful to developers.
    if (channelCount > maxChannelCount()) {
        exceptionState.throwDOMException(
            IndexSizeError,
            ExceptionMessages::indexOutsideRange<unsigned>("channel count",
                channelCount,
                1,
                ExceptionMessages::InclusiveBound,
                maxChannelCount(),
                ExceptionMessages::InclusiveBound));
        return;
    }

    unsigned long oldChannelCount = this->channelCount();
    AudioHandler::setChannelCount(channelCount, exceptionState);

    // Update the pipeline with the new channel count only if absolutely
    // necessary. This process requires the graph lock.
    //
    // TODO(hongchan): There might be a data race here since both threads
    // have access to m_mixBus.
    if (!exceptionState.hadException() && this->channelCount() != oldChannelCount && isInitialized()) {
        AbstractAudioContext::AutoLocker locker(context());
        m_mixBus = AudioBus::create(channelCount, ProcessingSizeInFrames);
        m_source->setAudioFormat(channelCount, context()->sampleRate());
    }
}
void DefaultAudioDestinationHandler::setChannelCount(
    unsigned long channelCount,
    ExceptionState& exceptionState) {
  // The channelCount for the input to this node controls the actual number of
  // channels we send to the audio hardware. It can only be set depending on the
  // maximum number of channels supported by the hardware.

  DCHECK(isMainThread());

  if (!maxChannelCount() || channelCount > maxChannelCount()) {
    exceptionState.throwDOMException(
        IndexSizeError,
        ExceptionMessages::indexOutsideRange<unsigned>(
            "channel count", channelCount, 1, ExceptionMessages::InclusiveBound,
            maxChannelCount(), ExceptionMessages::InclusiveBound));
    return;
  }

  unsigned long oldChannelCount = this->channelCount();
  AudioHandler::setChannelCount(channelCount, exceptionState);

  if (!exceptionState.hadException() &&
      this->channelCount() != oldChannelCount && isInitialized()) {
    // Re-create destination.
    m_destination->stop();
    createDestination();
    m_destination->start();
  }
}
void DefaultAudioDestinationNode::setChannelCount(ContextGraphLock& g, unsigned long channelCount)
{
    // The channelCount for the input to this node controls the actual number of channels we
    // send to the audio hardware. It can only be set depending on the maximum number of
    // channels supported by the hardware.
    
    ASSERT(g.context());
    
    if (!maxChannelCount() || channelCount > maxChannelCount())
    {
        throw std::invalid_argument("Max channel count invalid");
    }
    
    unsigned long oldChannelCount = this->channelCount();
    AudioNode::setChannelCount(g, channelCount);
    
    if (this->channelCount() != oldChannelCount && isInitialized())
    {
        // Re-create destination.
        m_destination->stop();
        createDestination();
        m_destination->start();
    }
}