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