| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 uint32 AudioSyncReader::Read(void* data, uint32 size) { | 26 uint32 AudioSyncReader::Read(void* data, uint32 size) { |
| 27 uint32 max_size = media::PacketSizeSizeInBytes( | 27 uint32 max_size = media::PacketSizeSizeInBytes( |
| 28 shared_memory_->created_size()); | 28 shared_memory_->created_size()); |
| 29 uint32 read_size = std::min(media::GetActualDataSizeInBytes(shared_memory_, | 29 uint32 read_size = std::min(media::GetActualDataSizeInBytes(shared_memory_, |
| 30 max_size), | 30 max_size), |
| 31 size); | 31 size); |
| 32 | 32 |
| 33 // Get the data from the buffer. | 33 // Get the data from the buffer. |
| 34 memcpy(data, shared_memory_->memory(), read_size); | 34 memcpy(data, shared_memory_->memory(), read_size); |
| 35 | 35 |
| 36 // If amount read was less than requested, then zero out the remainder. |
| 37 if (read_size < size) |
| 38 memset(static_cast<char*>(data) + read_size, 0, size - read_size); |
| 39 |
| 36 // Zero out the entire buffer. | 40 // Zero out the entire buffer. |
| 37 memset(shared_memory_->memory(), 0, max_size); | 41 memset(shared_memory_->memory(), 0, max_size); |
| 38 | 42 |
| 39 // Store max length of data into buffer, in case client does not do that. | 43 // Store max length of data into buffer, in case client does not do that. |
| 40 media::SetActualDataSizeInBytes(shared_memory_, max_size, max_size); | 44 media::SetActualDataSizeInBytes(shared_memory_, max_size, max_size); |
| 41 | 45 |
| 42 return read_size; | 46 return read_size; |
| 43 } | 47 } |
| 44 | 48 |
| 45 void AudioSyncReader::Close() { | 49 void AudioSyncReader::Close() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 bool AudioSyncReader::PrepareForeignSocketHandle( | 75 bool AudioSyncReader::PrepareForeignSocketHandle( |
| 72 base::ProcessHandle process_handle, | 76 base::ProcessHandle process_handle, |
| 73 base::FileDescriptor* foreign_handle) { | 77 base::FileDescriptor* foreign_handle) { |
| 74 foreign_handle->fd = foreign_socket_->handle(); | 78 foreign_handle->fd = foreign_socket_->handle(); |
| 75 foreign_handle->auto_close = false; | 79 foreign_handle->auto_close = false; |
| 76 if (foreign_handle->fd != -1) | 80 if (foreign_handle->fd != -1) |
| 77 return true; | 81 return true; |
| 78 return false; | 82 return false; |
| 79 } | 83 } |
| 80 #endif | 84 #endif |
| OLD | NEW |