Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1546)

Side by Side Diff: content/browser/renderer_host/media/audio_input_sync_writer.cc

Issue 294803003: Do not call SendMessageToNativeLog on Android in AudioInputSyncWriter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_sync_writer.h" 5 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
10 #include "content/browser/renderer_host/media/media_stream_manager.h" 10 #include "content/browser/renderer_host/media/media_stream_manager.h"
11 11 #include "content/public/browser/browser_thread.h"
Feng Qian 2014/05/21 18:23:30 This is unnecessary now.
jiayl 2014/05/21 18:29:21 Done.
12 static const uint32 kLogDelayThreadholdMs = 500;
13 12
14 namespace content { 13 namespace content {
15 14
16 AudioInputSyncWriter::AudioInputSyncWriter( 15 AudioInputSyncWriter::AudioInputSyncWriter(
17 base::SharedMemory* shared_memory, 16 base::SharedMemory* shared_memory,
18 int shared_memory_segment_count) 17 int shared_memory_segment_count)
19 : shared_memory_(shared_memory), 18 : shared_memory_(shared_memory),
20 shared_memory_segment_count_(shared_memory_segment_count), 19 shared_memory_segment_count_(shared_memory_segment_count),
21 current_segment_id_(0), 20 current_segment_id_(0),
22 creation_time_(base::Time::Now()) { 21 creation_time_(base::Time::Now()) {
23 DCHECK_GT(shared_memory_segment_count, 0); 22 DCHECK_GT(shared_memory_segment_count, 0);
24 DCHECK_EQ(shared_memory->requested_size() % shared_memory_segment_count, 0u); 23 DCHECK_EQ(shared_memory->requested_size() % shared_memory_segment_count, 0u);
25 shared_memory_segment_size_ = 24 shared_memory_segment_size_ =
26 shared_memory->requested_size() / shared_memory_segment_count; 25 shared_memory->requested_size() / shared_memory_segment_count;
27 } 26 }
28 27
29 AudioInputSyncWriter::~AudioInputSyncWriter() {} 28 AudioInputSyncWriter::~AudioInputSyncWriter() {}
30 29
31 // TODO(henrika): Combine into one method (including Write). 30 // TODO(henrika): Combine into one method (including Write).
32 void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) { 31 void AudioInputSyncWriter::UpdateRecordedBytes(uint32 bytes) {
33 socket_->Send(&bytes, sizeof(bytes)); 32 socket_->Send(&bytes, sizeof(bytes));
34 } 33 }
35 34
36 uint32 AudioInputSyncWriter::Write(const void* data, 35 uint32 AudioInputSyncWriter::Write(const void* data,
37 uint32 size, 36 uint32 size,
38 double volume, 37 double volume,
39 bool key_pressed) { 38 bool key_pressed) {
39 #if !defined(OS_ANDROID)
40 static const uint32 kLogDelayThreadholdMs = 500;
41
40 std::ostringstream oss; 42 std::ostringstream oss;
41 if (last_write_time_.is_null()) { 43 if (last_write_time_.is_null()) {
42 // This is the first time Write is called. 44 // This is the first time Write is called.
43 base::TimeDelta interval = base::Time::Now() - creation_time_; 45 base::TimeDelta interval = base::Time::Now() - creation_time_;
44 oss << "Audio input data received for the first time: delay = " 46 oss << "Audio input data received for the first time: delay = "
45 << interval.InMilliseconds() << "ms."; 47 << interval.InMilliseconds() << "ms.";
46 } else { 48 } else {
47 base::TimeDelta interval = base::Time::Now() - last_write_time_; 49 base::TimeDelta interval = base::Time::Now() - last_write_time_;
48 if (interval.InMilliseconds() > kLogDelayThreadholdMs) { 50 if (interval.InMilliseconds() > kLogDelayThreadholdMs) {
49 oss << "Audio input data delay unexpectedly long: delay = " 51 oss << "Audio input data delay unexpectedly long: delay = "
50 << interval.InMilliseconds() << "ms."; 52 << interval.InMilliseconds() << "ms.";
51 } 53 }
52 } 54 }
53 if (!oss.str().empty()) 55 if (!oss.str().empty()) {
Feng Qian 2014/05/21 18:23:30 remove {}
jiayl 2014/05/21 18:29:21 Done.
54 MediaStreamManager::SendMessageToNativeLog(oss.str()); 56 MediaStreamManager::SendMessageToNativeLog(oss.str());
57 }
55 58
56 last_write_time_ = base::Time::Now(); 59 last_write_time_ = base::Time::Now();
60 #endif
57 61
58 uint8* ptr = static_cast<uint8*>(shared_memory_->memory()); 62 uint8* ptr = static_cast<uint8*>(shared_memory_->memory());
59 ptr += current_segment_id_ * shared_memory_segment_size_; 63 ptr += current_segment_id_ * shared_memory_segment_size_;
60 media::AudioInputBuffer* buffer = 64 media::AudioInputBuffer* buffer =
61 reinterpret_cast<media::AudioInputBuffer*>(ptr); 65 reinterpret_cast<media::AudioInputBuffer*>(ptr);
62 buffer->params.volume = volume; 66 buffer->params.volume = volume;
63 buffer->params.size = size; 67 buffer->params.size = size;
64 buffer->params.key_pressed = key_pressed; 68 buffer->params.key_pressed = key_pressed;
65 memcpy(buffer->audio, data, size); 69 memcpy(buffer->audio, data, size);
66 70
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 base::ProcessHandle process_handle, 102 base::ProcessHandle process_handle,
99 base::FileDescriptor* foreign_handle) { 103 base::FileDescriptor* foreign_handle) {
100 foreign_handle->fd = foreign_socket_->handle(); 104 foreign_handle->fd = foreign_socket_->handle();
101 foreign_handle->auto_close = false; 105 foreign_handle->auto_close = false;
102 return (foreign_handle->fd != -1); 106 return (foreign_handle->fd != -1);
103 } 107 }
104 108
105 #endif 109 #endif
106 110
107 } // namespace content 111 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698