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_sync_reader.h" | 5 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
12 #include "media/audio/audio_buffers_state.h" | 12 #include "media/audio/audio_buffers_state.h" |
13 #include "media/audio/audio_util.h" | 13 #include "media/audio/shared_memory_util.h" |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 const int kMinIntervalBetweenReadCallsInMs = 10; | 16 const int kMinIntervalBetweenReadCallsInMs = 10; |
17 #endif | 17 #endif |
18 | 18 |
19 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory) | 19 AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory) |
20 : shared_memory_(shared_memory) { | 20 : shared_memory_(shared_memory) { |
21 } | 21 } |
22 | 22 |
23 AudioSyncReader::~AudioSyncReader() { | 23 AudioSyncReader::~AudioSyncReader() { |
24 } | 24 } |
25 | 25 |
26 bool AudioSyncReader::DataReady() { | 26 bool AudioSyncReader::DataReady() { |
27 return !media::IsUnknownDataSize( | 27 return !media::IsUnknownDataSize( |
28 shared_memory_, | 28 shared_memory_, |
29 media::PacketSizeSizeInBytes(shared_memory_->created_size())); | 29 media::PacketSizeInBytes(shared_memory_->created_size())); |
30 } | 30 } |
31 | 31 |
32 // media::AudioOutputController::SyncReader implementations. | 32 // media::AudioOutputController::SyncReader implementations. |
33 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { | 33 void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { |
34 if (bytes != static_cast<uint32>(media::AudioOutputController::kPauseMark)) { | 34 if (bytes != static_cast<uint32>(media::kPauseMark)) { |
35 // Store unknown length of data into buffer, so we later | 35 // Store unknown length of data into buffer, so we later |
36 // can find out if data became available. | 36 // can find out if data became available. |
37 media::SetUnknownDataSize( | 37 media::SetUnknownDataSize( |
38 shared_memory_, | 38 shared_memory_, |
39 media::PacketSizeSizeInBytes(shared_memory_->created_size())); | 39 media::PacketSizeInBytes(shared_memory_->created_size())); |
40 } | 40 } |
41 | 41 |
42 if (socket_.get()) { | 42 if (socket_.get()) { |
43 socket_->Send(&bytes, sizeof(bytes)); | 43 socket_->Send(&bytes, sizeof(bytes)); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 uint32 AudioSyncReader::Read(void* data, uint32 size) { | 47 uint32 AudioSyncReader::Read(void* data, uint32 size) { |
48 uint32 max_size = media::PacketSizeSizeInBytes( | 48 uint32 max_size = media::PacketSizeInBytes( |
49 shared_memory_->created_size()); | 49 shared_memory_->created_size()); |
50 | 50 |
51 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
52 // HACK: yield if reader is called too often. | 52 // HACK: yield if reader is called too often. |
53 // Problem is lack of synchronization between host and renderer. We cannot be | 53 // Problem is lack of synchronization between host and renderer. We cannot be |
54 // sure if renderer already filled the buffer, and due to all the plugins we | 54 // sure if renderer already filled the buffer, and due to all the plugins we |
55 // cannot change the API, so we yield if previous call was too recent. | 55 // cannot change the API, so we yield if previous call was too recent. |
56 // Optimization: if renderer is "new" one that writes length of data we can | 56 // Optimization: if renderer is "new" one that writes length of data we can |
57 // stop yielding the moment length is written -- not ideal solution, | 57 // stop yielding the moment length is written -- not ideal solution, |
58 // but better than nothing. | 58 // but better than nothing. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 bool AudioSyncReader::PrepareForeignSocketHandle( | 113 bool AudioSyncReader::PrepareForeignSocketHandle( |
114 base::ProcessHandle process_handle, | 114 base::ProcessHandle process_handle, |
115 base::FileDescriptor* foreign_handle) { | 115 base::FileDescriptor* foreign_handle) { |
116 foreign_handle->fd = foreign_socket_->handle(); | 116 foreign_handle->fd = foreign_socket_->handle(); |
117 foreign_handle->auto_close = false; | 117 foreign_handle->auto_close = false; |
118 if (foreign_handle->fd != -1) | 118 if (foreign_handle->fd != -1) |
119 return true; | 119 return true; |
120 return false; | 120 return false; |
121 } | 121 } |
122 #endif | 122 #endif |
OLD | NEW |