| 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" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
| 13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 14 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
| 15 #include "media/cast/cast_environment.h" | 15 #include "media/cast/cast_environment.h" |
| 16 #include "media/cast/cast_sender.h" | 16 #include "media/cast/cast_sender.h" |
| 17 #include "media/cast/logging/logging_defines.h" | 17 #include "media/cast/logging/logging_defines.h" |
| 18 #include "media/cast/test/audio_utility.h" | 18 #include "media/cast/test/audio_utility.h" |
| 19 #include "media/cast/test/utility/input_helper.h" | 19 #include "media/cast/test/utility/input_helper.h" |
| 20 #include "media/cast/test/video_utility.h" | 20 #include "media/cast/test/video_utility.h" |
| 21 #include "media/cast/transport/transport/transport.h" | 21 #include "media/cast/transport/transport/udp_transport.h" |
| 22 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 namespace cast { | 25 namespace cast { |
| 26 // Settings chosen to match default receiver settings. | 26 // Settings chosen to match default receiver settings. |
| 27 #define DEFAULT_SEND_PORT "2344" | 27 #define DEFAULT_SEND_PORT "2344" |
| 28 #define DEFAULT_RECEIVE_PORT "2346" | 28 #define DEFAULT_RECEIVE_PORT "2346" |
| 29 #define DEFAULT_SEND_IP "127.0.0.1" | 29 #define DEFAULT_SEND_IP "127.0.0.1" |
| 30 #define DEFAULT_READ_FROM_FILE "0" | 30 #define DEFAULT_READ_FROM_FILE "0" |
| 31 #define DEFAULT_AUDIO_SENDER_SSRC "1" | 31 #define DEFAULT_AUDIO_SENDER_SSRC "1" |
| (...skipping 256 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 main_thread.message_loop_proxy(), | 316 io_message_loop.message_loop_proxy(), |
| 319 media::cast::GetDefaultCastLoggingConfig())); | 317 media::cast::GetDefaultCastLoggingConfig())); |
| 320 | 318 |
| 321 media::cast::AudioSenderConfig audio_config = | 319 media::cast::AudioSenderConfig audio_config = |
| 322 media::cast::GetAudioSenderConfig(); | 320 media::cast::GetAudioSenderConfig(); |
| 323 media::cast::VideoSenderConfig video_config = | 321 media::cast::VideoSenderConfig video_config = |
| 324 media::cast::GetVideoSenderConfig(); | 322 media::cast::GetVideoSenderConfig(); |
| 325 | 323 |
| 326 scoped_ptr<media::cast::transport::Transport> transport( | 324 int remote_port, local_port; |
| 327 new media::cast::transport::Transport( | 325 media::cast::GetPorts(&remote_port, &local_port); |
| 328 io_message_loop.message_loop_proxy())); | 326 |
| 327 std::string remote_ip_address = |
| 328 media::cast::GetIpAddress("Enter receiver IP."); |
| 329 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); |
| 330 net::IPAddressNumber remote_ip_number; |
| 331 net::IPAddressNumber local_ip_number; |
| 332 |
| 333 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) { |
| 334 LOG(ERROR) << "Invalid remote IP address."; |
| 335 return 1; |
| 336 } |
| 337 |
| 338 if (!net::ParseIPLiteralToNumber(local_ip_address, &local_ip_number)) { |
| 339 LOG(ERROR) << "Invalid local IP address."; |
| 340 return 1; |
| 341 } |
| 342 |
| 343 net::IPEndPoint remote_end_point(remote_ip_number, remote_port); |
| 344 net::IPEndPoint local_end_point(local_ip_number, local_port); |
| 345 scoped_ptr<media::cast::transport::UdpTransport> transport( |
| 346 new media::cast::transport::UdpTransport( |
| 347 io_message_loop.message_loop_proxy(), |
| 348 local_end_point, |
| 349 remote_end_point)); |
| 329 scoped_ptr<media::cast::CastSender> cast_sender( | 350 scoped_ptr<media::cast::CastSender> cast_sender( |
| 330 media::cast::CastSender::CreateCastSender(cast_environment, | 351 media::cast::CastSender::CreateCastSender(cast_environment, |
| 331 audio_config, | 352 audio_config, |
| 332 video_config, | 353 video_config, |
| 333 NULL, // VideoEncoderController. | 354 NULL, // VideoEncoderController. |
| 334 transport->packet_sender())); | 355 transport.get())); |
| 335 | 356 transport->StartReceiving(cast_sender->packet_receiver()); |
| 336 media::cast::transport::PacketReceiver* packet_receiver = | |
| 337 cast_sender->packet_receiver(); | |
| 338 | |
| 339 int send_to_port, receive_port; | |
| 340 media::cast::GetPorts(&send_to_port, &receive_port); | |
| 341 std::string ip_address = media::cast::GetIpAddress("Enter destination IP."); | |
| 342 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); | |
| 343 | |
| 344 transport->SetLocalReceiver(packet_receiver, ip_address, local_ip_address, | |
| 345 receive_port); | |
| 346 transport->SetSendDestination(ip_address, send_to_port); | |
| 347 | 357 |
| 348 media::cast::FrameInput* frame_input = cast_sender->frame_input(); | 358 media::cast::FrameInput* frame_input = cast_sender->frame_input(); |
| 349 scoped_ptr<media::cast::SendProcess> send_process(new | 359 scoped_ptr<media::cast::SendProcess> send_process(new |
| 350 media::cast::SendProcess(test_thread.message_loop_proxy(), | 360 media::cast::SendProcess(test_thread.message_loop_proxy(), |
| 351 cast_environment->Clock(), | 361 cast_environment->Clock(), |
| 352 video_config, | 362 video_config, |
| 353 frame_input)); | 363 frame_input)); |
| 354 | 364 |
| 355 send_process->SendFrame(); | 365 send_process->SendFrame(); |
| 356 io_message_loop.Run(); | 366 io_message_loop.Run(); |
| 357 transport->StopReceiving(); | |
| 358 return 0; | 367 return 0; |
| 359 } | 368 } |
| OLD | NEW |