// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/media/media_stream_audio_source.h"

namespace content {

MediaStreamAudioSource::MediaStreamAudioSource(
    int render_view_id,
    const StreamDeviceInfo& device_info,
    const SourceStoppedCallback& stop_callback,
    MediaStreamDependencyFactory* factory)
    : render_view_id_(render_view_id),
      factory_(factory) {
  SetDeviceInfo(device_info);
  SetStopCallback(stop_callback);
}

MediaStreamAudioSource::MediaStreamAudioSource()
    : render_view_id_(-1),
      factory_(NULL) {
}

MediaStreamAudioSource::~MediaStreamAudioSource() {}

void MediaStreamAudioSource::DoStopSource() {
  audio_capturer_->Stop();
}

void MediaStreamAudioSource::AddTrack(
    const blink::WebMediaStreamTrack& track,
    const blink::WebMediaConstraints& constraints,
    const ConstraintsCallback& callback) {
  // TODO(xians): Properly implement for audio sources.
  bool result = true;
  if (factory_ && !local_audio_source_) {
    result = factory_->InitializeMediaStreamAudioSource(render_view_id_,
                                                        constraints,
                                                        this);
  }
  callback.Run(this, result);
}

void MediaStreamAudioSource::RemoveTrack(
    const blink::WebMediaStreamTrack& track) {
  NOTIMPLEMENTED();
}

}  // namespace content

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/media/media_stream_audio_source.h"

namespace content {

MediaStreamAudioSource::MediaStreamAudioSource(
    int render_view_id,
    const StreamDeviceInfo& device_info,
    const SourceStoppedCallback& stop_callback,
    MediaStreamDependencyFactory* factory)
    : render_view_id_(render_view_id),
      factory_(factory) {
  SetDeviceInfo(device_info);
  SetStopCallback(stop_callback);
}

MediaStreamAudioSource::MediaStreamAudioSource()
    : render_view_id_(-1),
      factory_(NULL) {
}

MediaStreamAudioSource::~MediaStreamAudioSource() {}

void MediaStreamAudioSource::DoStopSource() {
  if (audio_capturer_.get())
    audio_capturer_->Stop();
}

void MediaStreamAudioSource::AddTrack(
    const blink::WebMediaStreamTrack& track,
    const blink::WebMediaConstraints& constraints,
    const ConstraintsCallback& callback) {
  // TODO(xians): Properly implement for audio sources.
  bool result = true;
  if (factory_ && !local_audio_source_) {
    result = factory_->InitializeMediaStreamAudioSource(render_view_id_,
                                                        constraints,
                                                        this);
  }
  callback.Run(this, result);
}

void MediaStreamAudioSource::RemoveTrack(
    const blink::WebMediaStreamTrack& track) {
  NOTIMPLEMENTED();
}

}  // namespace content

Fix use of invalid pointer in MediaStreamAudioSource. If the source is not initiated correctly it can happen that the |audio_capturer_| is not set. MediaStreamAudioSource::DoStop will then crash.
Fix use of invalid pointer in MediaStreamAudioSource.
If the source is not initiated correctly it can happen that the |audio_capturer_| is not set.
MediaStreamAudioSource::DoStop will then crash.

BUG= 340492
R=xians@chromium.org

Review URL: https://codereview.chromium.org/153643003

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@248763 0039d316-1c4b-4281-b951-d872f2087c98
