OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/media/audio_input_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/files/file.h" | 10 #include "base/files/file.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
11 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_math.h" | 14 #include "base/numerics/safe_math.h" |
13 #include "base/process/process.h" | 15 #include "base/process/process.h" |
14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
(...skipping 30 matching lines...) Expand all Loading... |
47 } | 49 } |
48 | 50 |
49 #ifdef ENABLE_WEBRTC | 51 #ifdef ENABLE_WEBRTC |
50 base::File CreateDebugRecordingFile(base::FilePath file_path) { | 52 base::File CreateDebugRecordingFile(base::FilePath file_path) { |
51 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 53 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
52 base::File recording_file( | 54 base::File recording_file( |
53 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); | 55 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); |
54 PLOG_IF(ERROR, !recording_file.IsValid()) | 56 PLOG_IF(ERROR, !recording_file.IsValid()) |
55 << "Could not open debug recording file, error=" | 57 << "Could not open debug recording file, error=" |
56 << recording_file.error_details(); | 58 << recording_file.error_details(); |
57 return recording_file.Pass(); | 59 return recording_file; |
58 } | 60 } |
59 | 61 |
60 void CloseFile(base::File file) { | 62 void CloseFile(base::File file) { |
61 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 63 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
62 // |file| must be closed and destroyed on FILE thread. | 64 // |file| must be closed and destroyed on FILE thread. |
63 } | 65 } |
64 | 66 |
65 void DeleteInputDebugWriterOnFileThread( | 67 void DeleteInputDebugWriterOnFileThread( |
66 scoped_ptr<AudioInputDebugWriter> writer) { | 68 scoped_ptr<AudioInputDebugWriter> writer) { |
67 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 69 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 #if defined(OS_CHROMEOS) | 580 #if defined(OS_CHROMEOS) |
579 if (entry->has_keyboard_mic) { | 581 if (entry->has_keyboard_mic) { |
580 media_stream_manager_->audio_input_device_manager() | 582 media_stream_manager_->audio_input_device_manager() |
581 ->UnregisterKeyboardMicStream(); | 583 ->UnregisterKeyboardMicStream(); |
582 } | 584 } |
583 #endif | 585 #endif |
584 | 586 |
585 #if defined(ENABLE_WEBRTC) | 587 #if defined(ENABLE_WEBRTC) |
586 if (entry->input_debug_writer.get()) { | 588 if (entry->input_debug_writer.get()) { |
587 BrowserThread::PostTask( | 589 BrowserThread::PostTask( |
588 BrowserThread::FILE, | 590 BrowserThread::FILE, FROM_HERE, |
589 FROM_HERE, | |
590 base::Bind(&DeleteInputDebugWriterOnFileThread, | 591 base::Bind(&DeleteInputDebugWriterOnFileThread, |
591 base::Passed(entry->input_debug_writer.Pass()))); | 592 base::Passed(std::move(entry->input_debug_writer)))); |
592 } | 593 } |
593 #endif | 594 #endif |
594 | 595 |
595 // Delete the entry when this method goes out of scope. | 596 // Delete the entry when this method goes out of scope. |
596 scoped_ptr<AudioEntry> entry_deleter(entry); | 597 scoped_ptr<AudioEntry> entry_deleter(entry); |
597 | 598 |
598 // Erase the entry from the map. | 599 // Erase the entry from the map. |
599 audio_entries_.erase(entry->stream_id); | 600 audio_entries_.erase(entry->stream_id); |
600 } | 601 } |
601 | 602 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 #undef IntToStringType | 694 #undef IntToStringType |
694 | 695 |
695 void AudioInputRendererHost::DoEnableDebugRecording( | 696 void AudioInputRendererHost::DoEnableDebugRecording( |
696 int stream_id, | 697 int stream_id, |
697 base::File file) { | 698 base::File file) { |
698 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 699 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
699 if (!file.IsValid()) | 700 if (!file.IsValid()) |
700 return; | 701 return; |
701 AudioEntry* entry = LookupById(stream_id); | 702 AudioEntry* entry = LookupById(stream_id); |
702 if (!entry) { | 703 if (!entry) { |
703 BrowserThread::PostTask( | 704 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
704 BrowserThread::FILE, | 705 base::Bind(&CloseFile, Passed(std::move(file)))); |
705 FROM_HERE, | |
706 base::Bind( | |
707 &CloseFile, | |
708 Passed(file.Pass()))); | |
709 return; | 706 return; |
710 } | 707 } |
711 entry->input_debug_writer.reset(new AudioInputDebugWriter(file.Pass())); | 708 entry->input_debug_writer.reset(new AudioInputDebugWriter(std::move(file))); |
712 entry->controller->EnableDebugRecording(entry->input_debug_writer.get()); | 709 entry->controller->EnableDebugRecording(entry->input_debug_writer.get()); |
713 } | 710 } |
714 | 711 |
715 void AudioInputRendererHost::DeleteDebugWriter(int stream_id) { | 712 void AudioInputRendererHost::DeleteDebugWriter(int stream_id) { |
716 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 713 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
717 AudioEntry* entry = LookupById(stream_id); | 714 AudioEntry* entry = LookupById(stream_id); |
718 if (!entry) { | 715 if (!entry) { |
719 // This happens if DisableDebugRecording is called right after | 716 // This happens if DisableDebugRecording is called right after |
720 // DeleteEntries. | 717 // DeleteEntries. |
721 return; | 718 return; |
722 } | 719 } |
723 | 720 |
724 if (entry->input_debug_writer.get()) { | 721 if (entry->input_debug_writer.get()) { |
725 BrowserThread::PostTask( | 722 BrowserThread::PostTask( |
726 BrowserThread::FILE, | 723 BrowserThread::FILE, FROM_HERE, |
727 FROM_HERE, | |
728 base::Bind(&DeleteInputDebugWriterOnFileThread, | 724 base::Bind(&DeleteInputDebugWriterOnFileThread, |
729 base::Passed(entry->input_debug_writer.Pass()))); | 725 base::Passed(std::move(entry->input_debug_writer)))); |
730 } | 726 } |
731 } | 727 } |
732 #endif // defined(ENABLE_WEBRTC) | 728 #endif // defined(ENABLE_WEBRTC) |
733 | 729 |
734 } // namespace content | 730 } // namespace content |
OLD | NEW |