| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/renderer/media/local_media_stream_audio_source.h" | 5 #include "content/renderer/media/local_media_stream_audio_source.h" |
| 6 | 6 |
| 7 #include "content/common/media/media_stream_options.h" | 7 #include "content/common/media/media_stream_options.h" |
| 8 #include "content/renderer/media/audio_device_factory.h" | 8 #include "content/renderer/media/audio_device_factory.h" |
| 9 #include "content/renderer/render_frame_impl.h" | 9 #include "content/renderer/render_frame_impl.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 LocalMediaStreamAudioSource::LocalMediaStreamAudioSource( | 13 LocalMediaStreamAudioSource::LocalMediaStreamAudioSource( |
| 14 int consumer_render_frame_id, | 14 int consumer_render_frame_id, |
| 15 const StreamDeviceInfo& device_info) | 15 const StreamDeviceInfo& device_info, |
| 16 const ConstraintsCallback& started_callback) |
| 16 : MediaStreamAudioSource(true /* is_local_source */), | 17 : MediaStreamAudioSource(true /* is_local_source */), |
| 17 consumer_render_frame_id_(consumer_render_frame_id) { | 18 consumer_render_frame_id_(consumer_render_frame_id), |
| 19 started_callback_(started_callback) { |
| 18 DVLOG(1) << "LocalMediaStreamAudioSource::LocalMediaStreamAudioSource()"; | 20 DVLOG(1) << "LocalMediaStreamAudioSource::LocalMediaStreamAudioSource()"; |
| 19 MediaStreamSource::SetDeviceInfo(device_info); | 21 MediaStreamSource::SetDeviceInfo(device_info); |
| 20 | 22 |
| 21 // If the device buffer size was not provided, use a default. | 23 // If the device buffer size was not provided, use a default. |
| 22 int frames_per_buffer = device_info.device.input.frames_per_buffer; | 24 int frames_per_buffer = device_info.device.input.frames_per_buffer; |
| 23 if (frames_per_buffer <= 0) { | 25 if (frames_per_buffer <= 0) { |
| 24 // TODO(miu): Like in ProcessedLocalAudioSource::GetBufferSize(), we should | 26 // TODO(miu): Like in ProcessedLocalAudioSource::GetBufferSize(), we should |
| 25 // re-evaluate whether Android needs special treatment here. Or, perhaps we | 27 // re-evaluate whether Android needs special treatment here. Or, perhaps we |
| 26 // should just DCHECK_GT(device_info...frames_per_buffer, 0)? | 28 // should just DCHECK_GT(device_info...frames_per_buffer, 0)? |
| 27 // http://crbug.com/638081 | 29 // http://crbug.com/638081 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 79 |
| 78 source_->Stop(); | 80 source_->Stop(); |
| 79 source_ = nullptr; | 81 source_ = nullptr; |
| 80 | 82 |
| 81 VLOG(1) << "Stopped local audio input device (session_id=" | 83 VLOG(1) << "Stopped local audio input device (session_id=" |
| 82 << device_info().session_id << ") for render frame " | 84 << device_info().session_id << ") for render frame " |
| 83 << consumer_render_frame_id_ << " with audio parameters={" | 85 << consumer_render_frame_id_ << " with audio parameters={" |
| 84 << GetAudioParameters().AsHumanReadableString() << "}."; | 86 << GetAudioParameters().AsHumanReadableString() << "}."; |
| 85 } | 87 } |
| 86 | 88 |
| 89 void LocalMediaStreamAudioSource::OnCaptureStarted() { |
| 90 started_callback_.Run(this, MEDIA_DEVICE_OK, ""); |
| 91 } |
| 92 |
| 87 void LocalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, | 93 void LocalMediaStreamAudioSource::Capture(const media::AudioBus* audio_bus, |
| 88 int audio_delay_milliseconds, | 94 int audio_delay_milliseconds, |
| 89 double volume, | 95 double volume, |
| 90 bool key_pressed) { | 96 bool key_pressed) { |
| 91 DCHECK(audio_bus); | 97 DCHECK(audio_bus); |
| 92 // TODO(miu): Plumbing is needed to determine the actual capture timestamp | 98 // TODO(miu): Plumbing is needed to determine the actual capture timestamp |
| 93 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 99 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
| 94 // audio/video sync. http://crbug.com/335335 | 100 // audio/video sync. http://crbug.com/335335 |
| 95 MediaStreamAudioSource::DeliverDataToTracks( | 101 MediaStreamAudioSource::DeliverDataToTracks( |
| 96 *audio_bus, | 102 *audio_bus, |
| 97 base::TimeTicks::Now() - | 103 base::TimeTicks::Now() - |
| 98 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | 104 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); |
| 99 } | 105 } |
| 100 | 106 |
| 101 void LocalMediaStreamAudioSource::OnCaptureError(const std::string& why) { | 107 void LocalMediaStreamAudioSource::OnCaptureError(const std::string& why) { |
| 102 StopSourceOnError(why); | 108 StopSourceOnError(why); |
| 103 } | 109 } |
| 104 | 110 |
| 105 } // namespace content | 111 } // namespace content |
| OLD | NEW |