| 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_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/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 DVLOG(1) << "shared_memory_size: " << shared_memory_size; | 56 DVLOG(1) << "shared_memory_size: " << shared_memory_size; |
| 57 DVLOG(1) << "shared_memory_segment_count: " << shared_memory_segment_count; | 57 DVLOG(1) << "shared_memory_segment_count: " << shared_memory_segment_count; |
| 58 DVLOG(1) << "audio_bus_memory_size: " << audio_bus_memory_size_; | 58 DVLOG(1) << "audio_bus_memory_size: " << audio_bus_memory_size_; |
| 59 | 59 |
| 60 // Create vector of audio buses by wrapping existing blocks of memory. | 60 // Create vector of audio buses by wrapping existing blocks of memory. |
| 61 uint8_t* ptr = shared_memory_; | 61 uint8_t* ptr = shared_memory_; |
| 62 for (int i = 0; i < shared_memory_segment_count; ++i) { | 62 for (int i = 0; i < shared_memory_segment_count; ++i) { |
| 63 CHECK_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & | 63 CHECK_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & |
| 64 (AudioBus::kChannelAlignment - 1)); | 64 (AudioBus::kChannelAlignment - 1)); |
| 65 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 65 AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |
| 66 std::unique_ptr<AudioBus> audio_bus = | 66 audio_buses_.push_back(AudioBus::WrapMemory(params, buffer->audio)); |
| 67 AudioBus::WrapMemory(params, buffer->audio); | |
| 68 audio_buses_.push_back(std::move(audio_bus)); | |
| 69 ptr += shared_memory_segment_size_; | 67 ptr += shared_memory_segment_size_; |
| 70 } | 68 } |
| 71 } | 69 } |
| 72 | 70 |
| 73 AudioInputSyncWriter::~AudioInputSyncWriter() { | 71 AudioInputSyncWriter::~AudioInputSyncWriter() { |
| 74 // We log the following: | 72 // We log the following: |
| 75 // - Percentage of data written to fifo (and not to shared memory). | 73 // - Percentage of data written to fifo (and not to shared memory). |
| 76 // - Percentage of data dropped (fifo reached max size or socket buffer full). | 74 // - Percentage of data dropped (fifo reached max size or socket buffer full). |
| 77 // - Glitch yes/no (at least 1 drop). | 75 // - Glitch yes/no (at least 1 drop). |
| 78 // | 76 // |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 144 |
| 147 bool write_error = !WriteDataFromFifoToSharedMemory(); | 145 bool write_error = !WriteDataFromFifoToSharedMemory(); |
| 148 | 146 |
| 149 // Write the current data to the shared memory if there is room, otherwise | 147 // Write the current data to the shared memory if there is room, otherwise |
| 150 // put it in the fifo. | 148 // put it in the fifo. |
| 151 if (number_of_filled_segments_ < | 149 if (number_of_filled_segments_ < |
| 152 static_cast<int>(shared_memory_segment_count_)) { | 150 static_cast<int>(shared_memory_segment_count_)) { |
| 153 WriteParametersToCurrentSegment(volume, key_pressed, hardware_delay_bytes); | 151 WriteParametersToCurrentSegment(volume, key_pressed, hardware_delay_bytes); |
| 154 | 152 |
| 155 // Copy data into shared memory using pre-allocated audio buses. | 153 // Copy data into shared memory using pre-allocated audio buses. |
| 156 AudioBus* audio_bus = audio_buses_[current_segment_id_]; | 154 data->CopyTo(audio_buses_[current_segment_id_].get()); |
| 157 data->CopyTo(audio_bus); | |
| 158 | 155 |
| 159 if (!SignalDataWrittenAndUpdateCounters()) | 156 if (!SignalDataWrittenAndUpdateCounters()) |
| 160 write_error = true; | 157 write_error = true; |
| 161 | 158 |
| 162 trailing_write_to_fifo_count_ = 0; | 159 trailing_write_to_fifo_count_ = 0; |
| 163 } else { | 160 } else { |
| 164 if (!PushDataToFifo(data, volume, key_pressed, hardware_delay_bytes)) | 161 if (!PushDataToFifo(data, volume, key_pressed, hardware_delay_bytes)) |
| 165 write_error = true; | 162 write_error = true; |
| 166 | 163 |
| 167 ++write_to_fifo_count_; | 164 ++write_to_fifo_count_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 281 |
| 285 while (audio_bus_it != overflow_buses_.end() && | 282 while (audio_bus_it != overflow_buses_.end() && |
| 286 number_of_filled_segments_ < segment_count) { | 283 number_of_filled_segments_ < segment_count) { |
| 287 // Write parameters to shared memory. | 284 // Write parameters to shared memory. |
| 288 WriteParametersToCurrentSegment((*params_it).volume, | 285 WriteParametersToCurrentSegment((*params_it).volume, |
| 289 (*params_it).key_pressed, | 286 (*params_it).key_pressed, |
| 290 (*params_it).hardware_delay_bytes); | 287 (*params_it).hardware_delay_bytes); |
| 291 | 288 |
| 292 // Copy data from the fifo into shared memory using pre-allocated audio | 289 // Copy data from the fifo into shared memory using pre-allocated audio |
| 293 // buses. | 290 // buses. |
| 294 (*audio_bus_it)->CopyTo(audio_buses_[current_segment_id_]); | 291 (*audio_bus_it)->CopyTo(audio_buses_[current_segment_id_].get()); |
| 295 | 292 |
| 296 if (!SignalDataWrittenAndUpdateCounters()) | 293 if (!SignalDataWrittenAndUpdateCounters()) |
| 297 write_error = true; | 294 write_error = true; |
| 298 | 295 |
| 299 ++params_it; | 296 ++params_it; |
| 300 ++audio_bus_it; | 297 ++audio_bus_it; |
| 301 } | 298 } |
| 302 | 299 |
| 303 // Erase all copied data from fifo. | 300 // Erase all copied data from fifo. |
| 304 overflow_params_.erase(overflow_params_.begin(), params_it); | 301 overflow_params_.erase(overflow_params_.begin(), params_it); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 current_segment_id_ = 0; | 341 current_segment_id_ = 0; |
| 345 ++number_of_filled_segments_; | 342 ++number_of_filled_segments_; |
| 346 CHECK_LE(number_of_filled_segments_, | 343 CHECK_LE(number_of_filled_segments_, |
| 347 static_cast<int>(shared_memory_segment_count_)); | 344 static_cast<int>(shared_memory_segment_count_)); |
| 348 ++next_buffer_id_; | 345 ++next_buffer_id_; |
| 349 | 346 |
| 350 return true; | 347 return true; |
| 351 } | 348 } |
| 352 | 349 |
| 353 } // namespace content | 350 } // namespace content |
| OLD | NEW |