| 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/metrics/histogram.h" |    9 #include "base/metrics/histogram.h" | 
|   10 #include "base/strings/stringprintf.h" |   10 #include "base/strings/stringprintf.h" | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   56   DVLOG(1) << "audio_bus_memory_size: " << audio_bus_memory_size_; |   56   DVLOG(1) << "audio_bus_memory_size: " << audio_bus_memory_size_; | 
|   57  |   57  | 
|   58   // Create vector of audio buses by wrapping existing blocks of memory. |   58   // Create vector of audio buses by wrapping existing blocks of memory. | 
|   59   uint8_t* ptr = shared_memory_; |   59   uint8_t* ptr = shared_memory_; | 
|   60   for (int i = 0; i < shared_memory_segment_count; ++i) { |   60   for (int i = 0; i < shared_memory_segment_count; ++i) { | 
|   61     CHECK_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & |   61     CHECK_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & | 
|   62         (AudioBus::kChannelAlignment - 1)); |   62         (AudioBus::kChannelAlignment - 1)); | 
|   63     AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); |   63     AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr); | 
|   64     scoped_ptr<AudioBus> audio_bus = |   64     scoped_ptr<AudioBus> audio_bus = | 
|   65         AudioBus::WrapMemory(params, buffer->audio); |   65         AudioBus::WrapMemory(params, buffer->audio); | 
|   66     audio_buses_.push_back(audio_bus.release()); |   66     audio_buses_.push_back(std::move(audio_bus)); | 
|   67     ptr += shared_memory_segment_size_; |   67     ptr += shared_memory_segment_size_; | 
|   68   } |   68   } | 
|   69 } |   69 } | 
|   70  |   70  | 
|   71 AudioInputSyncWriter::~AudioInputSyncWriter() { |   71 AudioInputSyncWriter::~AudioInputSyncWriter() { | 
|   72   // We log the following: |   72   // We log the following: | 
|   73   // - Percentage of data written to fifo (and not to shared memory). |   73   // - Percentage of data written to fifo (and not to shared memory). | 
|   74   // - 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). | 
|   75   // - Glitch yes/no (at least 1 drop). |   75   // - Glitch yes/no (at least 1 drop). | 
|   76   // |   76   // | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  245   } |  245   } | 
|  246  |  246  | 
|  247   // Push parameters to fifo. |  247   // Push parameters to fifo. | 
|  248   OverflowParams params = { volume, hardware_delay_bytes, key_pressed }; |  248   OverflowParams params = { volume, hardware_delay_bytes, key_pressed }; | 
|  249   overflow_params_.push_back(params); |  249   overflow_params_.push_back(params); | 
|  250  |  250  | 
|  251   // Push audio data to fifo. |  251   // Push audio data to fifo. | 
|  252   scoped_ptr<AudioBus> audio_bus = |  252   scoped_ptr<AudioBus> audio_bus = | 
|  253       AudioBus::Create(data->channels(), data->frames()); |  253       AudioBus::Create(data->channels(), data->frames()); | 
|  254   data->CopyTo(audio_bus.get()); |  254   data->CopyTo(audio_bus.get()); | 
|  255   overflow_buses_.push_back(audio_bus.release()); |  255   overflow_buses_.push_back(std::move(audio_bus)); | 
|  256  |  256  | 
|  257   DCHECK_LE(overflow_buses_.size(), static_cast<size_t>(kMaxOverflowBusesSize)); |  257   DCHECK_LE(overflow_buses_.size(), static_cast<size_t>(kMaxOverflowBusesSize)); | 
|  258   DCHECK_EQ(overflow_params_.size(), overflow_buses_.size()); |  258   DCHECK_EQ(overflow_params_.size(), overflow_buses_.size()); | 
|  259  |  259  | 
|  260   return true; |  260   return true; | 
|  261 } |  261 } | 
|  262  |  262  | 
|  263 bool AudioInputSyncWriter::WriteDataFromFifoToSharedMemory() { |  263 bool AudioInputSyncWriter::WriteDataFromFifoToSharedMemory() { | 
|  264   if (overflow_buses_.empty()) |  264   if (overflow_buses_.empty()) | 
|  265     return true; |  265     return true; | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  329     current_segment_id_ = 0; |  329     current_segment_id_ = 0; | 
|  330   ++number_of_filled_segments_; |  330   ++number_of_filled_segments_; | 
|  331   CHECK_LE(number_of_filled_segments_, |  331   CHECK_LE(number_of_filled_segments_, | 
|  332            static_cast<int>(shared_memory_segment_count_)); |  332            static_cast<int>(shared_memory_segment_count_)); | 
|  333   ++next_buffer_id_; |  333   ++next_buffer_id_; | 
|  334  |  334  | 
|  335   return true; |  335   return true; | 
|  336 } |  336 } | 
|  337  |  337  | 
|  338 }  // namespace content |  338 }  // namespace content | 
| OLD | NEW |