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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/sync_socket.h" | 9 #include "base/sync_socket.h" |
10 #include "content/browser/media/capture/audio_mirroring_manager.h" | 10 #include "content/browser/media/capture/audio_mirroring_manager.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 // these messages here and dispatch to our mock methods to verify the | 82 // these messages here and dispatch to our mock methods to verify the |
83 // conversation between this object and the renderer. | 83 // conversation between this object and the renderer. |
84 virtual bool Send(IPC::Message* message) { | 84 virtual bool Send(IPC::Message* message) { |
85 CHECK(message); | 85 CHECK(message); |
86 | 86 |
87 // In this method we dispatch the messages to the according handlers as if | 87 // In this method we dispatch the messages to the according handlers as if |
88 // we are the renderer. | 88 // we are the renderer. |
89 bool handled = true; | 89 bool handled = true; |
90 IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message) | 90 IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message) |
91 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, | 91 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, |
92 OnStreamCreated) | 92 OnNotifyStreamCreated) |
93 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged, | 93 IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged, |
94 OnStreamStateChanged) | 94 OnNotifyStreamStateChanged) |
95 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
96 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
97 EXPECT_TRUE(handled); | 97 EXPECT_TRUE(handled); |
98 | 98 |
99 delete message; | 99 delete message; |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 void OnStreamCreated(const IPC::Message& msg, | 103 void OnNotifyStreamCreated(int stream_id, |
104 int stream_id, | 104 base::SharedMemoryHandle handle, |
105 base::SharedMemoryHandle handle, | |
106 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
107 base::SyncSocket::Handle socket_handle, | 106 base::SyncSocket::Handle socket_handle, |
108 #else | 107 #else |
109 base::FileDescriptor socket_descriptor, | 108 base::FileDescriptor socket_descriptor, |
110 #endif | 109 #endif |
111 uint32 length) { | 110 uint32 length) { |
112 // Maps the shared memory. | 111 // Maps the shared memory. |
113 shared_memory_.reset(new base::SharedMemory(handle, false)); | 112 shared_memory_.reset(new base::SharedMemory(handle, false)); |
114 CHECK(shared_memory_->Map(length)); | 113 CHECK(shared_memory_->Map(length)); |
115 CHECK(shared_memory_->memory()); | 114 CHECK(shared_memory_->memory()); |
116 shared_memory_length_ = length; | 115 shared_memory_length_ = length; |
117 | 116 |
118 // Create the SyncSocket using the handle. | 117 // Create the SyncSocket using the handle. |
119 base::SyncSocket::Handle sync_socket_handle; | 118 base::SyncSocket::Handle sync_socket_handle; |
120 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
121 sync_socket_handle = socket_handle; | 120 sync_socket_handle = socket_handle; |
122 #else | 121 #else |
123 sync_socket_handle = socket_descriptor.fd; | 122 sync_socket_handle = socket_descriptor.fd; |
124 #endif | 123 #endif |
125 sync_socket_.reset(new base::SyncSocket(sync_socket_handle)); | 124 sync_socket_.reset(new base::SyncSocket(sync_socket_handle)); |
126 | 125 |
127 // And then delegate the call to the mock method. | 126 // And then delegate the call to the mock method. |
128 OnStreamCreated(stream_id, length); | 127 OnStreamCreated(stream_id, length); |
129 } | 128 } |
130 | 129 |
131 void OnStreamStateChanged(const IPC::Message& msg, | 130 void OnNotifyStreamStateChanged(int stream_id, |
132 int stream_id, | 131 media::AudioOutputIPCDelegate::State state) { |
133 media::AudioOutputIPCDelegate::State state) { | |
134 switch (state) { | 132 switch (state) { |
135 case media::AudioOutputIPCDelegate::kPlaying: | 133 case media::AudioOutputIPCDelegate::kPlaying: |
136 OnStreamPlaying(stream_id); | 134 OnStreamPlaying(stream_id); |
137 break; | 135 break; |
138 case media::AudioOutputIPCDelegate::kPaused: | 136 case media::AudioOutputIPCDelegate::kPaused: |
139 OnStreamPaused(stream_id); | 137 OnStreamPaused(stream_id); |
140 break; | 138 break; |
141 case media::AudioOutputIPCDelegate::kError: | 139 case media::AudioOutputIPCDelegate::kError: |
142 OnStreamError(stream_id); | 140 OnStreamError(stream_id); |
143 break; | 141 break; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 346 } |
349 | 347 |
350 TEST_F(AudioRendererHostTest, CreateUnifiedStreamAndClose) { | 348 TEST_F(AudioRendererHostTest, CreateUnifiedStreamAndClose) { |
351 Create(true); | 349 Create(true); |
352 Close(); | 350 Close(); |
353 } | 351 } |
354 | 352 |
355 // TODO(hclam): Add tests for data conversation in low latency mode. | 353 // TODO(hclam): Add tests for data conversation in low latency mode. |
356 | 354 |
357 } // namespace content | 355 } // namespace content |
OLD | NEW |