Chromium Code Reviews| 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 "base/memory/weak_ptr.h" | |
| 8 #include "base/single_thread_task_runner.h" | |
| 7 #include "content/common/media/media_stream_options.h" | 9 #include "content/common/media/media_stream_options.h" |
| 8 #include "content/renderer/media/audio_device_factory.h" | 10 #include "content/renderer/media/audio_device_factory.h" |
| 9 #include "content/renderer/render_frame_impl.h" | 11 #include "content/renderer/render_frame_impl.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 LocalMediaStreamAudioSource::LocalMediaStreamAudioSource( | 15 LocalMediaStreamAudioSource::LocalMediaStreamAudioSource( |
| 14 int consumer_render_frame_id, | 16 int consumer_render_frame_id, |
| 15 const StreamDeviceInfo& device_info) | 17 const StreamDeviceInfo& device_info) |
| 16 : MediaStreamAudioSource(true /* is_local_source */), | 18 : MediaStreamAudioSource(true /* is_local_source */), |
| 17 consumer_render_frame_id_(consumer_render_frame_id) { | 19 consumer_render_frame_id_(consumer_render_frame_id), |
| 20 task_runner_(base::ThreadTaskRunnerHandle::Get()) { | |
| 18 DVLOG(1) << "LocalMediaStreamAudioSource::LocalMediaStreamAudioSource()"; | 21 DVLOG(1) << "LocalMediaStreamAudioSource::LocalMediaStreamAudioSource()"; |
| 19 MediaStreamSource::SetDeviceInfo(device_info); | 22 MediaStreamSource::SetDeviceInfo(device_info); |
| 20 | 23 |
| 21 // If the device buffer size was not provided, use a default. | 24 // If the device buffer size was not provided, use a default. |
| 22 int frames_per_buffer = device_info.device.input.frames_per_buffer; | 25 int frames_per_buffer = device_info.device.input.frames_per_buffer; |
| 23 if (frames_per_buffer <= 0) { | 26 if (frames_per_buffer <= 0) { |
| 24 // TODO(miu): Like in ProcessedLocalAudioSource::GetBufferSize(), we should | 27 // TODO(miu): Like in ProcessedLocalAudioSource::GetBufferSize(), we should |
| 25 // re-evaluate whether Android needs special treatment here. Or, perhaps we | 28 // re-evaluate whether Android needs special treatment here. Or, perhaps we |
| 26 // should just DCHECK_GT(device_info...frames_per_buffer, 0)? | 29 // should just DCHECK_GT(device_info...frames_per_buffer, 0)? |
| 27 // http://crbug.com/638081 | 30 // http://crbug.com/638081 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 // TODO(miu): Plumbing is needed to determine the actual capture timestamp | 95 // TODO(miu): Plumbing is needed to determine the actual capture timestamp |
| 93 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper | 96 // of the audio, instead of just snapshotting TimeTicks::Now(), for proper |
| 94 // audio/video sync. http://crbug.com/335335 | 97 // audio/video sync. http://crbug.com/335335 |
| 95 MediaStreamAudioSource::DeliverDataToTracks( | 98 MediaStreamAudioSource::DeliverDataToTracks( |
| 96 *audio_bus, | 99 *audio_bus, |
| 97 base::TimeTicks::Now() - | 100 base::TimeTicks::Now() - |
| 98 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | 101 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); |
| 99 } | 102 } |
| 100 | 103 |
| 101 void LocalMediaStreamAudioSource::OnCaptureError(const std::string& why) { | 104 void LocalMediaStreamAudioSource::OnCaptureError(const std::string& why) { |
| 102 // As of this writing, this method doesn't get called for anything useful, | 105 VLOG(1) << why; |
| 103 // and all other implementors just log the message, but don't disconnect sinks | 106 |
| 104 // or take any other action. So, just log the error. | 107 // Stop source when error occurs. |
| 105 LOG(ERROR) << why; | 108 task_runner_->PostTask( |
| 109 FROM_HERE, base::Bind(&MediaStreamSource::StopSource, AsWeakPtr())); | |
|
miu
2016/10/14 05:38:26
Why do we need the task runner? Isn't OnCaptureErr
xjz
2016/10/14 17:32:53
When tab is closed, this is called on io thread, n
| |
| 106 } | 110 } |
| 107 | 111 |
| 108 } // namespace content | 112 } // namespace content |
| OLD | NEW |