OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Test application that simulates a cast sender - Data can be either generated | 5 // Test application that simulates a cast sender - Data can be either generated |
6 // or read from a file. | 6 // or read from a file. |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 }; | 288 }; |
289 | 289 |
290 } // namespace cast | 290 } // namespace cast |
291 } // namespace media | 291 } // namespace media |
292 | 292 |
293 | 293 |
294 int main(int argc, char** argv) { | 294 int main(int argc, char** argv) { |
295 base::AtExitManager at_exit; | 295 base::AtExitManager at_exit; |
296 VLOG(1) << "Cast Sender"; | 296 VLOG(1) << "Cast Sender"; |
297 base::Thread test_thread("Cast sender test app thread"); | 297 base::Thread test_thread("Cast sender test app thread"); |
298 base::Thread main_thread("Cast main send thread"); | |
299 base::Thread audio_thread("Cast audio encoder thread"); | 298 base::Thread audio_thread("Cast audio encoder thread"); |
300 base::Thread video_thread("Cast video encoder thread"); | 299 base::Thread video_thread("Cast video encoder thread"); |
301 test_thread.Start(); | 300 test_thread.Start(); |
302 main_thread.Start(); | |
303 audio_thread.Start(); | 301 audio_thread.Start(); |
304 video_thread.Start(); | 302 video_thread.Start(); |
305 | 303 |
306 base::DefaultTickClock clock; | 304 base::DefaultTickClock clock; |
307 base::MessageLoopForIO io_message_loop; | 305 base::MessageLoopForIO io_message_loop; |
308 | 306 |
309 // Enable main and send side threads only. Disable logging. | 307 // Enable main and send side threads only. Disable logging. |
310 scoped_refptr<media::cast::CastEnvironment> cast_environment(new | 308 scoped_refptr<media::cast::CastEnvironment> cast_environment(new |
311 media::cast::CastEnvironment( | 309 media::cast::CastEnvironment( |
312 &clock, | 310 &clock, |
313 main_thread.message_loop_proxy(), | 311 io_message_loop.message_loop_proxy(), |
314 audio_thread.message_loop_proxy(), | 312 audio_thread.message_loop_proxy(), |
315 NULL, | 313 NULL, |
316 video_thread.message_loop_proxy(), | 314 video_thread.message_loop_proxy(), |
317 NULL, | 315 NULL, |
318 media::cast::GetDefaultCastLoggingConfig())); | 316 media::cast::GetDefaultCastLoggingConfig())); |
319 | 317 |
320 media::cast::AudioSenderConfig audio_config = | 318 media::cast::AudioSenderConfig audio_config = |
321 media::cast::GetAudioSenderConfig(); | 319 media::cast::GetAudioSenderConfig(); |
322 media::cast::VideoSenderConfig video_config = | 320 media::cast::VideoSenderConfig video_config = |
323 media::cast::GetVideoSenderConfig(); | 321 media::cast::GetVideoSenderConfig(); |
324 | 322 |
325 scoped_ptr<media::cast::transport::Transport> transport( | 323 int remote_port, local_port; |
326 new media::cast::transport::Transport( | 324 media::cast::GetPorts(&remote_port, &local_port); |
327 io_message_loop.message_loop_proxy())); | 325 |
| 326 std::string remote_ip_address = |
| 327 media::cast::GetIpAddress("Enter receiver IP."); |
| 328 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); |
| 329 net::IPAddressNumber remote_ip_number; |
| 330 net::IPAddressNumber local_ip_number; |
| 331 |
| 332 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) { |
| 333 LOG(ERROR) << "Invalid remote IP address."; |
| 334 return 1; |
| 335 } |
| 336 |
| 337 if (!net::ParseIPLiteralToNumber(local_ip_address, &local_ip_number)) { |
| 338 LOG(ERROR) << "Invalid local IP address."; |
| 339 return 1; |
| 340 } |
| 341 |
| 342 net::IPEndPoint remote_end_point(remote_ip_number, remote_port); |
| 343 net::IPEndPoint local_end_point(local_ip_number, local_port); |
| 344 scoped_ptr<media::cast::transport::UdpTransport> transport( |
| 345 new media::cast::transport::UdpTransport( |
| 346 io_message_loop.message_loop_proxy(), |
| 347 local_end_point, |
| 348 remote_end_point)); |
328 scoped_ptr<media::cast::CastSender> cast_sender( | 349 scoped_ptr<media::cast::CastSender> cast_sender( |
329 media::cast::CastSender::CreateCastSender(cast_environment, | 350 media::cast::CastSender::CreateCastSender(cast_environment, |
330 audio_config, | 351 audio_config, |
331 video_config, | 352 video_config, |
332 NULL, // VideoEncoderController. | 353 NULL, // VideoEncoderController. |
333 transport->packet_sender())); | 354 transport.get())); |
334 | 355 transport->StartReceiving(cast_sender->packet_receiver()); |
335 media::cast::PacketReceiver* packet_receiver = cast_sender->packet_receiver(); | |
336 | |
337 int send_to_port, receive_port; | |
338 media::cast::GetPorts(&send_to_port, &receive_port); | |
339 std::string ip_address = media::cast::GetIpAddress("Enter destination IP."); | |
340 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); | |
341 | |
342 transport->SetLocalReceiver(packet_receiver, ip_address, local_ip_address, | |
343 receive_port); | |
344 transport->SetSendDestination(ip_address, send_to_port); | |
345 | 356 |
346 media::cast::FrameInput* frame_input = cast_sender->frame_input(); | 357 media::cast::FrameInput* frame_input = cast_sender->frame_input(); |
347 scoped_ptr<media::cast::SendProcess> send_process(new | 358 scoped_ptr<media::cast::SendProcess> send_process(new |
348 media::cast::SendProcess(test_thread.message_loop_proxy(), | 359 media::cast::SendProcess(test_thread.message_loop_proxy(), |
349 cast_environment->Clock(), | 360 cast_environment->Clock(), |
350 video_config, | 361 video_config, |
351 frame_input)); | 362 frame_input)); |
352 | 363 |
353 send_process->SendFrame(); | 364 send_process->SendFrame(); |
354 io_message_loop.Run(); | 365 io_message_loop.Run(); |
355 transport->StopReceiving(); | |
356 return 0; | 366 return 0; |
357 } | 367 } |
OLD | NEW |