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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 base::WeakPtrFactory<SendProcess> weak_factory_; | 310 base::WeakPtrFactory<SendProcess> weak_factory_; |
311 }; | 311 }; |
312 | 312 |
313 } // namespace cast | 313 } // namespace cast |
314 } // namespace media | 314 } // namespace media |
315 | 315 |
316 namespace { | 316 namespace { |
317 void UpdateCastTransportStatus( | 317 void UpdateCastTransportStatus( |
318 media::cast::transport::CastTransportStatus status) {} | 318 media::cast::transport::CastTransportStatus status) {} |
319 | 319 |
| 320 void LogRawEvents( |
| 321 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, |
| 322 const std::vector<media::cast::PacketEvent>& packet_events) { |
| 323 VLOG(1) << "Got packet events from transport, size: " << packet_events.size(); |
| 324 for (std::vector<media::cast::PacketEvent>::const_iterator it = |
| 325 packet_events.begin(); |
| 326 it != packet_events.end(); |
| 327 ++it) { |
| 328 cast_environment->Logging()->InsertPacketEvent(it->timestamp, |
| 329 it->type, |
| 330 it->rtp_timestamp, |
| 331 it->frame_id, |
| 332 it->packet_id, |
| 333 it->max_packet_id, |
| 334 it->size); |
| 335 } |
| 336 } |
| 337 |
320 void InitializationResult(media::cast::CastInitializationStatus result) { | 338 void InitializationResult(media::cast::CastInitializationStatus result) { |
321 CHECK_EQ(result, media::cast::STATUS_INITIALIZED); | 339 CHECK_EQ(result, media::cast::STATUS_INITIALIZED); |
322 VLOG(1) << "Cast Sender initialized"; | 340 VLOG(1) << "Cast Sender initialized"; |
323 } | 341 } |
324 | 342 |
325 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { | 343 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { |
326 net::IPAddressNumber ip_number; | 344 net::IPAddressNumber ip_number; |
327 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); | 345 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); |
328 return net::IPEndPoint(ip_number, port); | 346 return net::IPEndPoint(ip_number, port); |
329 } | 347 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 | 432 |
415 // Setting up transport config. | 433 // Setting up transport config. |
416 media::cast::transport::CastTransportConfig config; | 434 media::cast::transport::CastTransportConfig config; |
417 config.receiver_endpoint = CreateUDPAddress(remote_ip_address, remote_port); | 435 config.receiver_endpoint = CreateUDPAddress(remote_ip_address, remote_port); |
418 config.local_endpoint = CreateUDPAddress("0.0.0.0", 0); | 436 config.local_endpoint = CreateUDPAddress("0.0.0.0", 0); |
419 config.audio_ssrc = audio_config.sender_ssrc; | 437 config.audio_ssrc = audio_config.sender_ssrc; |
420 config.video_ssrc = video_config.sender_ssrc; | 438 config.video_ssrc = video_config.sender_ssrc; |
421 config.audio_rtp_config = audio_config.rtp_config; | 439 config.audio_rtp_config = audio_config.rtp_config; |
422 config.video_rtp_config = video_config.rtp_config; | 440 config.video_rtp_config = video_config.rtp_config; |
423 | 441 |
424 scoped_ptr<media::cast::transport::CastTransportSender> transport_sender( | |
425 media::cast::transport::CastTransportSender::CreateCastTransportSender( | |
426 NULL, | |
427 clock.get(), | |
428 config, | |
429 base::Bind(&UpdateCastTransportStatus), | |
430 io_message_loop.message_loop_proxy())); | |
431 | |
432 // Enable main and send side threads only. Enable raw event logging. | 442 // Enable main and send side threads only. Enable raw event logging. |
433 // Running transport on the main thread. | 443 // Running transport on the main thread. |
434 media::cast::CastLoggingConfig logging_config; | 444 media::cast::CastLoggingConfig logging_config; |
435 logging_config.enable_raw_data_collection = true; | 445 logging_config.enable_raw_data_collection = true; |
436 | 446 |
437 scoped_refptr<media::cast::CastEnvironment> cast_environment( | 447 scoped_refptr<media::cast::CastEnvironment> cast_environment( |
438 new media::cast::CastEnvironment(clock.Pass(), | 448 new media::cast::CastEnvironment(clock.Pass(), |
439 io_message_loop.message_loop_proxy(), | 449 io_message_loop.message_loop_proxy(), |
440 audio_thread.message_loop_proxy(), | 450 audio_thread.message_loop_proxy(), |
441 NULL, | 451 NULL, |
442 video_thread.message_loop_proxy(), | 452 video_thread.message_loop_proxy(), |
443 NULL, | 453 NULL, |
444 io_message_loop.message_loop_proxy(), | 454 io_message_loop.message_loop_proxy(), |
445 logging_config)); | 455 logging_config)); |
446 | 456 |
| 457 scoped_ptr<media::cast::transport::CastTransportSender> transport_sender( |
| 458 media::cast::transport::CastTransportSender::CreateCastTransportSender( |
| 459 NULL, |
| 460 cast_environment->Clock(), |
| 461 config, |
| 462 logging_config, |
| 463 base::Bind(&UpdateCastTransportStatus), |
| 464 base::Bind(&LogRawEvents, cast_environment), |
| 465 base::TimeDelta::FromSeconds(1), |
| 466 io_message_loop.message_loop_proxy())); |
| 467 |
447 scoped_ptr<media::cast::CastSender> cast_sender( | 468 scoped_ptr<media::cast::CastSender> cast_sender( |
448 media::cast::CastSender::CreateCastSender( | 469 media::cast::CastSender::CreateCastSender( |
449 cast_environment, | 470 cast_environment, |
450 &audio_config, | 471 &audio_config, |
451 &video_config, | 472 &video_config, |
452 NULL, // gpu_factories. | 473 NULL, // gpu_factories. |
453 base::Bind(&InitializationResult), | 474 base::Bind(&InitializationResult), |
454 transport_sender.get())); | 475 transport_sender.get())); |
455 | 476 |
456 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); | 477 transport_sender->SetPacketReceiver(cast_sender->packet_receiver()); |
457 | 478 |
458 media::cast::FrameInput* frame_input = cast_sender->frame_input(); | 479 media::cast::FrameInput* frame_input = cast_sender->frame_input(); |
459 scoped_ptr<media::cast::SendProcess> send_process( | 480 scoped_ptr<media::cast::SendProcess> send_process( |
460 new media::cast::SendProcess(test_thread.message_loop_proxy(), | 481 new media::cast::SendProcess(test_thread.message_loop_proxy(), |
461 cast_environment->Clock(), | 482 cast_environment->Clock(), |
462 video_config, | 483 video_config, |
463 frame_input)); | 484 frame_input)); |
464 | 485 |
465 // Set up event subscribers. | 486 // Set up event subscribers. |
466 // TODO(imcheng): Set up separate subscribers for audio / video / other. | |
467 int logging_duration = media::cast::GetLoggingDuration(); | 487 int logging_duration = media::cast::GetLoggingDuration(); |
468 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; | 488 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber; |
469 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; | 489 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber; |
470 if (logging_duration > 0) { | 490 if (logging_duration > 0) { |
471 std::string log_file_name(media::cast::GetLogFileDestination()); | 491 std::string log_file_name(media::cast::GetLogFileDestination()); |
472 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 492 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
473 media::cast::VIDEO_EVENT, 10000)); | 493 media::cast::VIDEO_EVENT, 10000)); |
474 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 494 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
475 media::cast::AUDIO_EVENT, 10000)); | 495 media::cast::AUDIO_EVENT, 10000)); |
476 cast_environment->Logging()->AddRawEventSubscriber( | 496 cast_environment->Logging()->AddRawEventSubscriber( |
(...skipping 18 matching lines...) Expand all Loading... |
495 | 515 |
496 test_thread.message_loop_proxy()->PostTask( | 516 test_thread.message_loop_proxy()->PostTask( |
497 FROM_HERE, | 517 FROM_HERE, |
498 base::Bind(&media::cast::SendProcess::SendFrame, | 518 base::Bind(&media::cast::SendProcess::SendFrame, |
499 base::Unretained(send_process.get()))); | 519 base::Unretained(send_process.get()))); |
500 | 520 |
501 io_message_loop.Run(); | 521 io_message_loop.Run(); |
502 | 522 |
503 return 0; | 523 return 0; |
504 } | 524 } |
OLD | NEW |