Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(763)

Side by Side Diff: media/cast/test/receiver.cc

Issue 125713002: Implement UdpTransport for Cast (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/cast/cast.gyp ('k') | media/cast/test/sender.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/udp_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
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } // namespace cast 210 } // namespace cast
210 } // namespace media 211 } // namespace media
211 212
212 int main(int argc, char** argv) { 213 int main(int argc, char** argv) {
213 base::AtExitManager at_exit; 214 base::AtExitManager at_exit;
214 base::MessageLoopForIO main_message_loop; 215 base::MessageLoopForIO main_message_loop;
215 CommandLine::Init(argc, argv); 216 CommandLine::Init(argc, argv);
216 InitLogging(logging::LoggingSettings()); 217 InitLogging(logging::LoggingSettings());
217 218
218 VLOG(1) << "Cast Receiver"; 219 VLOG(1) << "Cast Receiver";
219 base::Thread main_thread("Cast main send thread");
220 base::Thread audio_thread("Cast audio decoder thread"); 220 base::Thread audio_thread("Cast audio decoder thread");
221 base::Thread video_thread("Cast video decoder thread"); 221 base::Thread video_thread("Cast video decoder thread");
222 main_thread.Start();
223 audio_thread.Start(); 222 audio_thread.Start();
224 video_thread.Start(); 223 video_thread.Start();
225 224
226 base::DefaultTickClock clock; 225 base::DefaultTickClock clock;
227 // Enable receiver side threads, and disable logging. 226 // Enable receiver side threads, and disable logging.
228 scoped_refptr<media::cast::CastEnvironment> cast_environment(new 227 scoped_refptr<media::cast::CastEnvironment> cast_environment(new
229 media::cast::CastEnvironment(&clock, 228 media::cast::CastEnvironment(&clock,
230 main_thread.message_loop_proxy(), 229 main_message_loop.message_loop_proxy(),
231 NULL, 230 NULL,
232 audio_thread.message_loop_proxy(), 231 audio_thread.message_loop_proxy(),
233 NULL, 232 NULL,
234 video_thread.message_loop_proxy(), 233 video_thread.message_loop_proxy(),
235 main_thread.message_loop_proxy(), 234 main_message_loop.message_loop_proxy(),
236 media::cast::GetDefaultCastLoggingConfig())); 235 media::cast::GetDefaultCastLoggingConfig()));
237 236
238 media::cast::AudioReceiverConfig audio_config = 237 media::cast::AudioReceiverConfig audio_config =
239 media::cast::GetAudioReceiverConfig(); 238 media::cast::GetAudioReceiverConfig();
240 media::cast::VideoReceiverConfig video_config = 239 media::cast::VideoReceiverConfig video_config =
241 media::cast::GetVideoReceiverConfig(); 240 media::cast::GetVideoReceiverConfig();
242 241
243 scoped_ptr<media::cast::transport::Transport> transport( 242 int remote_port, local_port;
244 new media::cast::transport::Transport( 243 media::cast::GetPorts(&remote_port, &local_port);
245 main_message_loop.message_loop_proxy())); 244 if (!local_port) {
245 LOG(ERROR) << "Invalid local port.";
246 return 1;
247 }
248
249 std::string remote_ip_address = media::cast::GetIpAddress("Enter remote IP.");
250 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP.");
251 net::IPAddressNumber remote_ip_number;
252 net::IPAddressNumber local_ip_number;
253
254 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) {
255 LOG(ERROR) << "Invalid remote IP address.";
256 return 1;
257 }
258
259 if (!net::ParseIPLiteralToNumber(local_ip_address, &local_ip_number)) {
260 LOG(ERROR) << "Invalid local IP address.";
261 return 1;
262 }
263
264 net::IPEndPoint remote_end_point(remote_ip_number, remote_port);
265 net::IPEndPoint local_end_point(local_ip_number, local_port);
266
267 scoped_ptr<media::cast::transport::UdpTransport> transport(
268 new media::cast::transport::UdpTransport(
269 main_message_loop.message_loop_proxy(),
270 local_end_point,
271 remote_end_point));
246 scoped_ptr<media::cast::CastReceiver> cast_receiver( 272 scoped_ptr<media::cast::CastReceiver> cast_receiver(
247 media::cast::CastReceiver::CreateCastReceiver( 273 media::cast::CastReceiver::CreateCastReceiver(
248 cast_environment, 274 cast_environment,
249 audio_config, 275 audio_config,
250 video_config, 276 video_config,
251 transport->packet_sender())); 277 transport.get()));
252 278
253 media::cast::transport::PacketReceiver* packet_receiver = 279 media::cast::transport::PacketReceiver* packet_receiver =
254 cast_receiver->packet_receiver(); 280 cast_receiver->packet_receiver();
255 281
256 int send_to_port, receive_port; 282 transport->StartReceiving(packet_receiver);
257 media::cast::GetPorts(&send_to_port, &receive_port);
258 std::string ip_address = media::cast::GetIpAddress("Enter destination IP.");
259 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP.");
260 transport->SetLocalReceiver(packet_receiver, ip_address, local_ip_address,
261 receive_port);
262 transport->SetSendDestination(ip_address, send_to_port);
263 283
264 scoped_refptr<media::cast::ReceiveProcess> receive_process( 284 scoped_refptr<media::cast::ReceiveProcess> receive_process(
265 new media::cast::ReceiveProcess(cast_receiver->frame_receiver())); 285 new media::cast::ReceiveProcess(cast_receiver->frame_receiver()));
266 receive_process->Start(); 286 receive_process->Start();
267 main_message_loop.Run(); 287 main_message_loop.Run();
268 transport->StopReceiving();
269 return 0; 288 return 0;
270 } 289 }
OLDNEW
« no previous file with comments | « media/cast/cast.gyp ('k') | media/cast/test/sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698