| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/scoped_file.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 14 #include "base/time/default_tick_clock.h" | 15 #include "base/time/default_tick_clock.h" |
| 15 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
| 16 #include "media/cast/cast_config.h" | 17 #include "media/cast/cast_config.h" |
| 17 #include "media/cast/cast_environment.h" | 18 #include "media/cast/cast_environment.h" |
| 18 #include "media/cast/cast_sender.h" | 19 #include "media/cast/cast_sender.h" |
| 19 #include "media/cast/logging/encoding_event_subscriber.h" | 20 #include "media/cast/logging/encoding_event_subscriber.h" |
| 20 #include "media/cast/logging/log_serializer.h" | 21 #include "media/cast/logging/log_serializer.h" |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 361 } |
| 361 | 362 |
| 362 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { | 363 net::IPEndPoint CreateUDPAddress(std::string ip_str, int port) { |
| 363 net::IPAddressNumber ip_number; | 364 net::IPAddressNumber ip_number; |
| 364 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); | 365 CHECK(net::ParseIPLiteralToNumber(ip_str, &ip_number)); |
| 365 return net::IPEndPoint(ip_number, port); | 366 return net::IPEndPoint(ip_number, port); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void DumpLoggingData( | 369 void DumpLoggingData( |
| 369 scoped_ptr<media::cast::EncodingEventSubscriber> event_subscriber, | 370 scoped_ptr<media::cast::EncodingEventSubscriber> event_subscriber, |
| 370 file_util::ScopedFILE log_file, | 371 base::ScopedFILE log_file, |
| 371 bool compress) { | 372 bool compress) { |
| 372 media::cast::FrameEventMap frame_events; | 373 media::cast::FrameEventMap frame_events; |
| 373 media::cast::PacketEventMap packet_events; | 374 media::cast::PacketEventMap packet_events; |
| 374 media::cast::proto::LogMetadata log_metadata; | 375 media::cast::proto::LogMetadata log_metadata; |
| 375 | 376 |
| 376 event_subscriber->GetEventsAndReset( | 377 event_subscriber->GetEventsAndReset( |
| 377 &log_metadata, &frame_events, &packet_events); | 378 &log_metadata, &frame_events, &packet_events); |
| 378 | 379 |
| 379 VLOG(0) << "Frame map size: " << frame_events.size(); | 380 VLOG(0) << "Frame map size: " << frame_events.size(); |
| 380 VLOG(0) << "Packet map size: " << packet_events.size(); | 381 VLOG(0) << "Packet map size: " << packet_events.size(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 396 | 397 |
| 397 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); | 398 int ret = fwrite(event_log.get(), 1, event_log_bytes, log_file.get()); |
| 398 if (ret != event_log_bytes) | 399 if (ret != event_log_bytes) |
| 399 VLOG(0) << "Failed to write logs to file."; | 400 VLOG(0) << "Failed to write logs to file."; |
| 400 } | 401 } |
| 401 | 402 |
| 402 void WriteLogsToFileAndStopSubscribing( | 403 void WriteLogsToFileAndStopSubscribing( |
| 403 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, | 404 const scoped_refptr<media::cast::CastEnvironment>& cast_environment, |
| 404 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber, | 405 scoped_ptr<media::cast::EncodingEventSubscriber> video_event_subscriber, |
| 405 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber, | 406 scoped_ptr<media::cast::EncodingEventSubscriber> audio_event_subscriber, |
| 406 file_util::ScopedFILE video_log_file, | 407 base::ScopedFILE video_log_file, |
| 407 file_util::ScopedFILE audio_log_file, | 408 base::ScopedFILE audio_log_file, |
| 408 bool compress) { | 409 bool compress) { |
| 409 // Serialize video events. | 410 // Serialize video events. |
| 410 cast_environment->Logging()->RemoveRawEventSubscriber( | 411 cast_environment->Logging()->RemoveRawEventSubscriber( |
| 411 video_event_subscriber.get()); | 412 video_event_subscriber.get()); |
| 412 cast_environment->Logging()->RemoveRawEventSubscriber( | 413 cast_environment->Logging()->RemoveRawEventSubscriber( |
| 413 audio_event_subscriber.get()); | 414 audio_event_subscriber.get()); |
| 414 | 415 |
| 415 VLOG(0) << "Dumping logging data for video stream."; | 416 VLOG(0) << "Dumping logging data for video stream."; |
| 416 DumpLoggingData( | 417 DumpLoggingData( |
| 417 video_event_subscriber.Pass(), video_log_file.Pass(), compress); | 418 video_event_subscriber.Pass(), video_log_file.Pass(), compress); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 media::cast::GetAudioLogFileDestination(compress)); | 524 media::cast::GetAudioLogFileDestination(compress)); |
| 524 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 525 video_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
| 525 media::cast::VIDEO_EVENT, 10000)); | 526 media::cast::VIDEO_EVENT, 10000)); |
| 526 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( | 527 audio_event_subscriber.reset(new media::cast::EncodingEventSubscriber( |
| 527 media::cast::AUDIO_EVENT, 10000)); | 528 media::cast::AUDIO_EVENT, 10000)); |
| 528 cast_environment->Logging()->AddRawEventSubscriber( | 529 cast_environment->Logging()->AddRawEventSubscriber( |
| 529 video_event_subscriber.get()); | 530 video_event_subscriber.get()); |
| 530 cast_environment->Logging()->AddRawEventSubscriber( | 531 cast_environment->Logging()->AddRawEventSubscriber( |
| 531 audio_event_subscriber.get()); | 532 audio_event_subscriber.get()); |
| 532 | 533 |
| 533 file_util::ScopedFILE video_log_file( | 534 base::ScopedFILE video_log_file(fopen(video_log_file_name.c_str(), "w")); |
| 534 fopen(video_log_file_name.c_str(), "w")); | |
| 535 if (!video_log_file) { | 535 if (!video_log_file) { |
| 536 VLOG(1) << "Failed to open video log file for writing."; | 536 VLOG(1) << "Failed to open video log file for writing."; |
| 537 exit(-1); | 537 exit(-1); |
| 538 } | 538 } |
| 539 | 539 |
| 540 file_util::ScopedFILE audio_log_file( | 540 base::ScopedFILE audio_log_file(fopen(audio_log_file_name.c_str(), "w")); |
| 541 fopen(audio_log_file_name.c_str(), "w")); | |
| 542 if (!audio_log_file) { | 541 if (!audio_log_file) { |
| 543 VLOG(1) << "Failed to open audio log file for writing."; | 542 VLOG(1) << "Failed to open audio log file for writing."; |
| 544 exit(-1); | 543 exit(-1); |
| 545 } | 544 } |
| 546 | 545 |
| 547 io_message_loop.message_loop_proxy()->PostDelayedTask( | 546 io_message_loop.message_loop_proxy()->PostDelayedTask( |
| 548 FROM_HERE, | 547 FROM_HERE, |
| 549 base::Bind(&WriteLogsToFileAndStopSubscribing, | 548 base::Bind(&WriteLogsToFileAndStopSubscribing, |
| 550 cast_environment, | 549 cast_environment, |
| 551 base::Passed(&video_event_subscriber), | 550 base::Passed(&video_event_subscriber), |
| 552 base::Passed(&audio_event_subscriber), | 551 base::Passed(&audio_event_subscriber), |
| 553 base::Passed(&video_log_file), | 552 base::Passed(&video_log_file), |
| 554 base::Passed(&audio_log_file), | 553 base::Passed(&audio_log_file), |
| 555 compress), | 554 compress), |
| 556 base::TimeDelta::FromSeconds(logging_duration)); | 555 base::TimeDelta::FromSeconds(logging_duration)); |
| 557 } | 556 } |
| 558 | 557 |
| 559 test_thread.message_loop_proxy()->PostTask( | 558 test_thread.message_loop_proxy()->PostTask( |
| 560 FROM_HERE, | 559 FROM_HERE, |
| 561 base::Bind(&media::cast::SendProcess::SendFrame, | 560 base::Bind(&media::cast::SendProcess::SendFrame, |
| 562 base::Unretained(send_process.get()))); | 561 base::Unretained(send_process.get()))); |
| 563 | 562 |
| 564 io_message_loop.Run(); | 563 io_message_loop.Run(); |
| 565 | 564 |
| 566 return 0; | 565 return 0; |
| 567 } | 566 } |
| OLD | NEW |