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

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

Issue 291173006: Revert 271764 "Detaching from the VM after calling MediaStreamMa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
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 | Annotate | Revision Log
« 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 #if defined(OS_ANDROID)
10 #include "base/android/jni_android.h"
11 #endif
12 #include "base/memory/shared_memory.h" 9 #include "base/memory/shared_memory.h"
13 #include "content/browser/renderer_host/media/media_stream_manager.h" 10 #include "content/browser/renderer_host/media/media_stream_manager.h"
14 11
15 static const uint32 kLogDelayThreadholdMs = 500; 12 static const uint32 kLogDelayThreadholdMs = 500;
16 13
17 namespace content { 14 namespace content {
18 15
19 AudioInputSyncWriter::AudioInputSyncWriter( 16 AudioInputSyncWriter::AudioInputSyncWriter(
20 base::SharedMemory* shared_memory, 17 base::SharedMemory* shared_memory,
21 int shared_memory_segment_count) 18 int shared_memory_segment_count)
(...skipping 24 matching lines...) Expand all
46 base::TimeDelta interval = base::Time::Now() - creation_time_; 43 base::TimeDelta interval = base::Time::Now() - creation_time_;
47 oss << "Audio input data received for the first time: delay = " 44 oss << "Audio input data received for the first time: delay = "
48 << interval.InMilliseconds() << "ms."; 45 << interval.InMilliseconds() << "ms.";
49 } else { 46 } else {
50 base::TimeDelta interval = base::Time::Now() - last_write_time_; 47 base::TimeDelta interval = base::Time::Now() - last_write_time_;
51 if (interval.InMilliseconds() > kLogDelayThreadholdMs) { 48 if (interval.InMilliseconds() > kLogDelayThreadholdMs) {
52 oss << "Audio input data delay unexpectedly long: delay = " 49 oss << "Audio input data delay unexpectedly long: delay = "
53 << interval.InMilliseconds() << "ms."; 50 << interval.InMilliseconds() << "ms.";
54 } 51 }
55 } 52 }
56 if (!oss.str().empty()) { 53 if (!oss.str().empty())
57 MediaStreamManager::SendMessageToNativeLog(oss.str()); 54 MediaStreamManager::SendMessageToNativeLog(oss.str());
58 55
59 // MediaStreamManager::SendMessageToNativeLog posts a task to the UI thread,
60 // which will attach the audio thread to the Android java VM. Unlike chrome
61 // created threads, the audio thread is owned by the OS and does not detach
62 // itself from the VM on exit, causing a crash (crbug/365915). So we detach
63 // here to make sure the thread exits clean.
64 #if defined(OS_ANDROID)
65 base::android::DetachFromVM();
66 #endif
67 }
68
69 last_write_time_ = base::Time::Now(); 56 last_write_time_ = base::Time::Now();
70 57
71 uint8* ptr = static_cast<uint8*>(shared_memory_->memory()); 58 uint8* ptr = static_cast<uint8*>(shared_memory_->memory());
72 ptr += current_segment_id_ * shared_memory_segment_size_; 59 ptr += current_segment_id_ * shared_memory_segment_size_;
73 media::AudioInputBuffer* buffer = 60 media::AudioInputBuffer* buffer =
74 reinterpret_cast<media::AudioInputBuffer*>(ptr); 61 reinterpret_cast<media::AudioInputBuffer*>(ptr);
75 buffer->params.volume = volume; 62 buffer->params.volume = volume;
76 buffer->params.size = size; 63 buffer->params.size = size;
77 buffer->params.key_pressed = key_pressed; 64 buffer->params.key_pressed = key_pressed;
78 memcpy(buffer->audio, data, size); 65 memcpy(buffer->audio, data, size);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 base::ProcessHandle process_handle, 98 base::ProcessHandle process_handle,
112 base::FileDescriptor* foreign_handle) { 99 base::FileDescriptor* foreign_handle) {
113 foreign_handle->fd = foreign_socket_->handle(); 100 foreign_handle->fd = foreign_socket_->handle();
114 foreign_handle->auto_close = false; 101 foreign_handle->auto_close = false;
115 return (foreign_handle->fd != -1); 102 return (foreign_handle->fd != -1);
116 } 103 }
117 104
118 #endif 105 #endif
119 106
120 } // namespace content 107 } // 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