| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/sync_socket.h" | 14 #include "base/sync_socket.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "media/audio/audio_device_thread.h" |
| 18 #include "media/base/audio_bus.h" | 19 #include "media/base/audio_bus.h" |
| 19 #include "media/base/audio_parameters.h" | 20 #include "media/base/audio_parameters.h" |
| 20 #include "media/base/channel_layout.h" | 21 #include "media/base/channel_layout.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 using ::testing::_; | 25 using ::testing::_; |
| 25 using base::TimeDelta; | 26 using base::TimeDelta; |
| 26 using media::AudioBus; | 27 using media::AudioBus; |
| 27 using media::AudioParameters; | 28 using media::AudioParameters; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 40 const int bits_per_sample = 16; | 41 const int bits_per_sample = 16; |
| 41 | 42 |
| 42 // Faked ring buffer. Must be aligned. | 43 // Faked ring buffer. Must be aligned. |
| 43 #define DATA_ALIGNMENT 16 | 44 #define DATA_ALIGNMENT 16 |
| 44 static_assert(AudioBus::kChannelAlignment == DATA_ALIGNMENT, | 45 static_assert(AudioBus::kChannelAlignment == DATA_ALIGNMENT, |
| 45 "Data alignment not same as AudioBus"); | 46 "Data alignment not same as AudioBus"); |
| 46 ALIGNAS(DATA_ALIGNMENT) | 47 ALIGNAS(DATA_ALIGNMENT) |
| 47 uint8_t data[kSegments * (sizeof(media::AudioInputBufferParameters) + | 48 uint8_t data[kSegments * (sizeof(media::AudioInputBufferParameters) + |
| 48 frames * channels * sizeof(float))]; | 49 frames * channels * sizeof(float))]; |
| 49 | 50 |
| 51 const size_t kWriterPacketSize = sizeof(media::AudioDeviceThread::Packet); |
| 52 |
| 50 } // namespace | 53 } // namespace |
| 51 | 54 |
| 52 // Mocked out sockets used for Send/ReceiveWithTimeout. Counts the number of | 55 // Mocked out sockets used for Send/ReceiveWithTimeout. Counts the number of |
| 53 // outstanding reads, i.e. the diff between send and receive calls. | 56 // outstanding reads, i.e. the diff between send and receive calls. |
| 54 class MockCancelableSyncSocket : public base::CancelableSyncSocket { | 57 class MockCancelableSyncSocket : public base::CancelableSyncSocket { |
| 55 public: | 58 public: |
| 56 MockCancelableSyncSocket(int buffer_size) | 59 MockCancelableSyncSocket(int buffer_size) |
| 57 : in_failure_mode_(false), | 60 : in_failure_mode_(false), |
| 58 writes_(0), | 61 writes_(0), |
| 59 reads_(0), | 62 reads_(0), |
| 60 receives_(0), | 63 receives_(0), |
| 61 buffer_size_(buffer_size), | 64 buffer_size_(buffer_size), |
| 62 read_buffer_index_(0) {} | 65 read_buffer_index_(0) {} |
| 63 | 66 |
| 64 size_t Send(const void* buffer, size_t length) override { | 67 size_t Send(const void* buffer, size_t length) override { |
| 65 EXPECT_EQ(length, sizeof(uint32_t)); | 68 EXPECT_EQ(length, kWriterPacketSize); |
| 66 | 69 |
| 67 ++writes_; | 70 ++writes_; |
| 68 EXPECT_LE(NumberOfBuffersFilled(), buffer_size_); | 71 EXPECT_LE(NumberOfBuffersFilled(), buffer_size_); |
| 69 return length; | 72 return length; |
| 70 } | 73 } |
| 71 | 74 |
| 72 size_t Receive(void* buffer, size_t length) override { | 75 size_t Receive(void* buffer, size_t length) override { |
| 73 EXPECT_EQ(0u, length % sizeof(uint32_t)); | 76 EXPECT_EQ(0u, length % sizeof(uint32_t)); |
| 74 | 77 |
| 75 if (in_failure_mode_) | 78 if (in_failure_mode_) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2)); | 362 EXPECT_TRUE(TestSocketAndFifoExpectations(kSegments, 0, 2)); |
| 360 | 363 |
| 361 // Empty both. Should render a log call for emptying the fifo. | 364 // Empty both. Should render a log call for emptying the fifo. |
| 362 socket_->Read(kSegments); | 365 socket_->Read(kSegments); |
| 363 writer_->Write(audio_bus_.get(), 0, false, 0); | 366 writer_->Write(audio_bus_.get(), 0, false, 0); |
| 364 socket_->Read(3); | 367 socket_->Read(3); |
| 365 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0)); | 368 EXPECT_TRUE(TestSocketAndFifoExpectations(0, 3 * sizeof(uint32_t), 0)); |
| 366 } | 369 } |
| 367 | 370 |
| 368 } // namespace content | 371 } // namespace content |
| OLD | NEW |