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 #include <algorithm> | 5 #include <algorithm> |
6 #include <climits> | 6 #include <climits> |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <cstdio> | 8 #include <cstdio> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/time/default_tick_clock.h" | 18 #include "base/time/default_tick_clock.h" |
19 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
20 #include "media/cast/cast_config.h" | 20 #include "media/cast/cast_config.h" |
21 #include "media/cast/cast_environment.h" | 21 #include "media/cast/cast_environment.h" |
22 #include "media/cast/cast_receiver.h" | 22 #include "media/cast/cast_receiver.h" |
23 #include "media/cast/logging/logging_defines.h" | 23 #include "media/cast/logging/logging_defines.h" |
24 #include "media/cast/test/utility/input_helper.h" | 24 #include "media/cast/test/utility/input_helper.h" |
25 #include "media/cast/transport/transport/transport.h" | 25 #include "media/cast/transport/transport/transport.h" |
26 #include "net/base/net_util.h" | |
26 | 27 |
27 #if defined(OS_LINUX) | 28 #if defined(OS_LINUX) |
28 #include "media/cast/test/linux_output_window.h" | 29 #include "media/cast/test/linux_output_window.h" |
29 #endif // OS_LINUX | 30 #endif // OS_LINUX |
30 | 31 |
31 namespace media { | 32 namespace media { |
32 namespace cast { | 33 namespace cast { |
33 // Settings chosen to match default sender settings. | 34 // Settings chosen to match default sender settings. |
34 #define DEFAULT_SEND_PORT "2346" | 35 #define DEFAULT_SEND_PORT "0" |
35 #define DEFAULT_RECEIVE_PORT "2344" | 36 #define DEFAULT_RECEIVE_PORT "2344" |
36 #define DEFAULT_SEND_IP "127.0.0.1" | 37 #define DEFAULT_SEND_IP "0.0.0.0" |
37 #define DEFAULT_RESTART "0" | 38 #define DEFAULT_RESTART "0" |
38 #define DEFAULT_AUDIO_FEEDBACK_SSRC "1" | 39 #define DEFAULT_AUDIO_FEEDBACK_SSRC "1" |
39 #define DEFAULT_AUDIO_INCOMING_SSRC "2" | 40 #define DEFAULT_AUDIO_INCOMING_SSRC "2" |
40 #define DEFAULT_AUDIO_PAYLOAD_TYPE "127" | 41 #define DEFAULT_AUDIO_PAYLOAD_TYPE "127" |
41 #define DEFAULT_VIDEO_FEEDBACK_SSRC "12" | 42 #define DEFAULT_VIDEO_FEEDBACK_SSRC "12" |
42 #define DEFAULT_VIDEO_INCOMING_SSRC "11" | 43 #define DEFAULT_VIDEO_INCOMING_SSRC "11" |
43 #define DEFAULT_VIDEO_PAYLOAD_TYPE "96" | 44 #define DEFAULT_VIDEO_PAYLOAD_TYPE "96" |
44 #define DEFAULT_VIDEO_CODEC_WIDTH "640" | 45 #define DEFAULT_VIDEO_CODEC_WIDTH "640" |
45 #define DEFAULT_VIDEO_CODEC_HEIGHT "480" | 46 #define DEFAULT_VIDEO_CODEC_HEIGHT "480" |
46 #define DEFAULT_VIDEO_CODEC_BITRATE "2000" | 47 #define DEFAULT_VIDEO_CODEC_BITRATE "2000" |
(...skipping 10 matching lines...) Expand all Loading... | |
57 test::InputBuilder tx_input("Enter send port.", | 58 test::InputBuilder tx_input("Enter send port.", |
58 DEFAULT_SEND_PORT, 1, INT_MAX); | 59 DEFAULT_SEND_PORT, 1, INT_MAX); |
59 *tx_port = tx_input.GetIntInput(); | 60 *tx_port = tx_input.GetIntInput(); |
60 | 61 |
61 test::InputBuilder rx_input("Enter receive port.", | 62 test::InputBuilder rx_input("Enter receive port.", |
62 DEFAULT_RECEIVE_PORT, 1, INT_MAX); | 63 DEFAULT_RECEIVE_PORT, 1, INT_MAX); |
63 *rx_port = rx_input.GetIntInput(); | 64 *rx_port = rx_input.GetIntInput(); |
64 } | 65 } |
65 | 66 |
66 std::string GetIpAddress(const std::string display_text) { | 67 std::string GetIpAddress(const std::string display_text) { |
67 test::InputBuilder input(display_text, DEFAULT_SEND_IP, | 68 test::InputBuilder input(display_text, DEFAULT_SEND_IP, INT_MIN, INT_MAX); |
68 INT_MIN, INT_MAX); | |
69 std::string ip_address = input.GetStringInput(); | 69 std::string ip_address = input.GetStringInput(); |
70 // Ensure correct form: | 70 // Ensure IP address is either the default value or in correct form. |
71 while (std::count(ip_address.begin(), ip_address.end(), '.') != 3) { | 71 while (ip_address != DEFAULT_SEND_IP && |
72 std::count(ip_address.begin(), ip_address.end(), '.') != 3) { | |
72 ip_address = input.GetStringInput(); | 73 ip_address = input.GetStringInput(); |
73 } | 74 } |
74 return ip_address; | 75 return ip_address; |
75 } | 76 } |
76 | 77 |
77 void GetSsrcs(AudioReceiverConfig* audio_config) { | 78 void GetSsrcs(AudioReceiverConfig* audio_config) { |
78 test::InputBuilder input_tx("Choose audio sender SSRC.", | 79 test::InputBuilder input_tx("Choose audio sender SSRC.", |
79 DEFAULT_AUDIO_FEEDBACK_SSRC, 1, INT_MAX); | 80 DEFAULT_AUDIO_FEEDBACK_SSRC, 1, INT_MAX); |
80 audio_config->feedback_ssrc = input_tx.GetIntInput(); | 81 audio_config->feedback_ssrc = input_tx.GetIntInput(); |
81 | 82 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 audio_thread.message_loop_proxy(), | 233 audio_thread.message_loop_proxy(), |
233 NULL, | 234 NULL, |
234 video_thread.message_loop_proxy(), | 235 video_thread.message_loop_proxy(), |
235 media::cast::GetDefaultCastLoggingConfig())); | 236 media::cast::GetDefaultCastLoggingConfig())); |
236 | 237 |
237 media::cast::AudioReceiverConfig audio_config = | 238 media::cast::AudioReceiverConfig audio_config = |
238 media::cast::GetAudioReceiverConfig(); | 239 media::cast::GetAudioReceiverConfig(); |
239 media::cast::VideoReceiverConfig video_config = | 240 media::cast::VideoReceiverConfig video_config = |
240 media::cast::GetVideoReceiverConfig(); | 241 media::cast::GetVideoReceiverConfig(); |
241 | 242 |
242 scoped_ptr<media::cast::transport::Transport> transport( | 243 int remote_port, local_port; |
243 new media::cast::transport::Transport( | 244 media::cast::GetPorts(&remote_port, &local_port); |
244 main_message_loop.message_loop_proxy())); | 245 if (!local_port) { |
246 LOG(ERROR) << "Invalid local port."; | |
247 return 1; | |
248 } | |
249 | |
250 std::string remote_ip_address = media::cast::GetIpAddress("Enter sender IP."); | |
mikhal1
2014/01/07 20:50:06
nit: can you sync the variable name and the msg, i
Alpha Left Google
2014/01/08 00:37:11
Done.
| |
251 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); | |
252 net::IPAddressNumber remote_ip_number; | |
253 net::IPAddressNumber local_ip_number; | |
254 | |
255 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) { | |
256 LOG(ERROR) << "Invalid remote IP address."; | |
257 return 1; | |
258 } | |
259 | |
260 if (!net::ParseIPLiteralToNumber(local_ip_address, &local_ip_number)) { | |
261 LOG(ERROR) << "Invalid local IP address."; | |
262 return 1; | |
263 } | |
264 | |
265 net::IPEndPoint remote_end_point(remote_ip_number, remote_port); | |
266 net::IPEndPoint local_end_point(local_ip_number, local_port); | |
267 | |
268 scoped_ptr<media::cast::transport::UdpTransport> transport( | |
269 new media::cast::transport::UdpTransport( | |
270 main_message_loop.message_loop_proxy(), | |
271 local_end_point, | |
272 remote_end_point)); | |
245 scoped_ptr<media::cast::CastReceiver> cast_receiver( | 273 scoped_ptr<media::cast::CastReceiver> cast_receiver( |
246 media::cast::CastReceiver::CreateCastReceiver( | 274 media::cast::CastReceiver::CreateCastReceiver( |
247 cast_environment, | 275 cast_environment, |
248 audio_config, | 276 audio_config, |
249 video_config, | 277 video_config, |
250 transport->packet_sender())); | 278 transport.get())); |
251 | |
252 media::cast::PacketReceiver* packet_receiver = | 279 media::cast::PacketReceiver* packet_receiver = |
253 cast_receiver->packet_receiver(); | 280 cast_receiver->packet_receiver(); |
254 | 281 |
255 int send_to_port, receive_port; | 282 transport->StartReceiving(packet_receiver); |
256 media::cast::GetPorts(&send_to_port, &receive_port); | |
257 std::string ip_address = media::cast::GetIpAddress("Enter destination IP."); | |
258 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); | |
259 transport->SetLocalReceiver(packet_receiver, ip_address, local_ip_address, | |
260 receive_port); | |
261 transport->SetSendDestination(ip_address, send_to_port); | |
262 | 283 |
263 scoped_refptr<media::cast::ReceiveProcess> receive_process( | 284 scoped_refptr<media::cast::ReceiveProcess> receive_process( |
264 new media::cast::ReceiveProcess(cast_receiver->frame_receiver())); | 285 new media::cast::ReceiveProcess(cast_receiver->frame_receiver())); |
265 receive_process->Start(); | 286 receive_process->Start(); |
266 main_message_loop.Run(); | 287 main_message_loop.Run(); |
267 transport->StopReceiving(); | |
268 return 0; | 288 return 0; |
269 } | 289 } |
OLD | NEW |