| 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 <deque> | 9 #include <deque> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #define DEFAULT_AUDIO_PAYLOAD_TYPE "127" | 58 #define DEFAULT_AUDIO_PAYLOAD_TYPE "127" |
| 59 #define DEFAULT_VIDEO_FEEDBACK_SSRC "12" | 59 #define DEFAULT_VIDEO_FEEDBACK_SSRC "12" |
| 60 #define DEFAULT_VIDEO_INCOMING_SSRC "11" | 60 #define DEFAULT_VIDEO_INCOMING_SSRC "11" |
| 61 #define DEFAULT_VIDEO_PAYLOAD_TYPE "96" | 61 #define DEFAULT_VIDEO_PAYLOAD_TYPE "96" |
| 62 | 62 |
| 63 #if defined(USE_X11) | 63 #if defined(USE_X11) |
| 64 const char* kVideoWindowWidth = "1280"; | 64 const char* kVideoWindowWidth = "1280"; |
| 65 const char* kVideoWindowHeight = "720"; | 65 const char* kVideoWindowHeight = "720"; |
| 66 #endif // defined(USE_X11) | 66 #endif // defined(USE_X11) |
| 67 | 67 |
| 68 void GetPorts(uint16* tx_port, uint16* rx_port) { | 68 void GetPorts(uint16_t* tx_port, uint16_t* rx_port) { |
| 69 test::InputBuilder tx_input( | 69 test::InputBuilder tx_input( |
| 70 "Enter send port.", DEFAULT_SEND_PORT, 1, 65535); | 70 "Enter send port.", DEFAULT_SEND_PORT, 1, 65535); |
| 71 *tx_port = static_cast<uint16>(tx_input.GetIntInput()); | 71 *tx_port = static_cast<uint16_t>(tx_input.GetIntInput()); |
| 72 | 72 |
| 73 test::InputBuilder rx_input( | 73 test::InputBuilder rx_input( |
| 74 "Enter receive port.", DEFAULT_RECEIVE_PORT, 1, 65535); | 74 "Enter receive port.", DEFAULT_RECEIVE_PORT, 1, 65535); |
| 75 *rx_port = static_cast<uint16>(rx_input.GetIntInput()); | 75 *rx_port = static_cast<uint16_t>(rx_input.GetIntInput()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 std::string GetIpAddress(const std::string& display_text) { | 78 std::string GetIpAddress(const std::string& display_text) { |
| 79 test::InputBuilder input(display_text, DEFAULT_SEND_IP, INT_MIN, INT_MAX); | 79 test::InputBuilder input(display_text, DEFAULT_SEND_IP, INT_MIN, INT_MAX); |
| 80 std::string ip_address = input.GetStringInput(); | 80 std::string ip_address = input.GetStringInput(); |
| 81 // Ensure IP address is either the default value or in correct form. | 81 // Ensure IP address is either the default value or in correct form. |
| 82 while (ip_address != DEFAULT_SEND_IP && | 82 while (ip_address != DEFAULT_SEND_IP && |
| 83 std::count(ip_address.begin(), ip_address.end(), '.') != 3) { | 83 std::count(ip_address.begin(), ip_address.end(), '.') != 3) { |
| 84 ip_address = input.GetStringInput(); | 84 ip_address = input.GetStringInput(); |
| 85 } | 85 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // InProcessReceiver finals. | 266 // InProcessReceiver finals. |
| 267 | 267 |
| 268 void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | 268 void OnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, |
| 269 const base::TimeTicks& playout_time, | 269 const base::TimeTicks& playout_time, |
| 270 bool is_continuous) final { | 270 bool is_continuous) final { |
| 271 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 271 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
| 272 LOG_IF(WARNING, !is_continuous) | 272 LOG_IF(WARNING, !is_continuous) |
| 273 << "Video: Discontinuity in received frames."; | 273 << "Video: Discontinuity in received frames."; |
| 274 video_playout_queue_.push_back(std::make_pair(playout_time, video_frame)); | 274 video_playout_queue_.push_back(std::make_pair(playout_time, video_frame)); |
| 275 ScheduleVideoPlayout(); | 275 ScheduleVideoPlayout(); |
| 276 uint16 frame_no; | 276 uint16_t frame_no; |
| 277 if (media::cast::test::DecodeBarcode(video_frame, &frame_no)) { | 277 if (media::cast::test::DecodeBarcode(video_frame, &frame_no)) { |
| 278 video_play_times_.insert( | 278 video_play_times_.insert( |
| 279 std::pair<uint16, base::TimeTicks>(frame_no, playout_time)); | 279 std::pair<uint16_t, base::TimeTicks>(frame_no, playout_time)); |
| 280 } else { | 280 } else { |
| 281 VLOG(2) << "Barcode decode failed!"; | 281 VLOG(2) << "Barcode decode failed!"; |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 void OnAudioFrame(scoped_ptr<AudioBus> audio_frame, | 285 void OnAudioFrame(scoped_ptr<AudioBus> audio_frame, |
| 286 const base::TimeTicks& playout_time, | 286 const base::TimeTicks& playout_time, |
| 287 bool is_continuous) final { | 287 bool is_continuous) final { |
| 288 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); | 288 DCHECK(cast_env()->CurrentlyOn(CastEnvironment::MAIN)); |
| 289 LOG_IF(WARNING, !is_continuous) | 289 LOG_IF(WARNING, !is_continuous) |
| 290 << "Audio: Discontinuity in received frames."; | 290 << "Audio: Discontinuity in received frames."; |
| 291 base::AutoLock auto_lock(audio_lock_); | 291 base::AutoLock auto_lock(audio_lock_); |
| 292 uint16 frame_no; | 292 uint16_t frame_no; |
| 293 if (media::cast::DecodeTimestamp(audio_frame->channel(0), | 293 if (media::cast::DecodeTimestamp(audio_frame->channel(0), |
| 294 audio_frame->frames(), | 294 audio_frame->frames(), |
| 295 &frame_no)) { | 295 &frame_no)) { |
| 296 // Since there are lots of audio packets with the same frame_no, | 296 // Since there are lots of audio packets with the same frame_no, |
| 297 // we really want to make sure that we get the playout_time from | 297 // we really want to make sure that we get the playout_time from |
| 298 // the first one. If is_continous is true, then it's possible | 298 // the first one. If is_continous is true, then it's possible |
| 299 // that we already missed the first one. | 299 // that we already missed the first one. |
| 300 if (is_continuous && frame_no == last_audio_frame_no_ + 1) { | 300 if (is_continuous && frame_no == last_audio_frame_no_ + 1) { |
| 301 audio_play_times_.insert( | 301 audio_play_times_.insert( |
| 302 std::pair<uint16, base::TimeTicks>(frame_no, playout_time)); | 302 std::pair<uint16_t, base::TimeTicks>(frame_no, playout_time)); |
| 303 } | 303 } |
| 304 last_audio_frame_no_ = frame_no; | 304 last_audio_frame_no_ = frame_no; |
| 305 } else { | 305 } else { |
| 306 VLOG(2) << "Audio decode failed!"; | 306 VLOG(2) << "Audio decode failed!"; |
| 307 last_audio_frame_no_ = -2; | 307 last_audio_frame_no_ = -2; |
| 308 } | 308 } |
| 309 audio_playout_queue_.push_back( | 309 audio_playout_queue_.push_back( |
| 310 std::make_pair(playout_time, audio_frame.release())); | 310 std::make_pair(playout_time, audio_frame.release())); |
| 311 } | 311 } |
| 312 | 312 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 audio_playout_queue_.pop_front(); | 469 audio_playout_queue_.pop_front(); |
| 470 ++num_audio_frames_processed_; | 470 ++num_audio_frames_processed_; |
| 471 return ret.Pass(); | 471 return ret.Pass(); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void CheckAVSync() { | 474 void CheckAVSync() { |
| 475 if (video_play_times_.size() > 30 && | 475 if (video_play_times_.size() > 30 && |
| 476 audio_play_times_.size() > 30) { | 476 audio_play_times_.size() > 30) { |
| 477 size_t num_events = 0; | 477 size_t num_events = 0; |
| 478 base::TimeDelta delta; | 478 base::TimeDelta delta; |
| 479 std::map<uint16, base::TimeTicks>::iterator audio_iter, video_iter; | 479 std::map<uint16_t, base::TimeTicks>::iterator audio_iter, video_iter; |
| 480 for (video_iter = video_play_times_.begin(); | 480 for (video_iter = video_play_times_.begin(); |
| 481 video_iter != video_play_times_.end(); | 481 video_iter != video_play_times_.end(); |
| 482 ++video_iter) { | 482 ++video_iter) { |
| 483 audio_iter = audio_play_times_.find(video_iter->first); | 483 audio_iter = audio_play_times_.find(video_iter->first); |
| 484 if (audio_iter != audio_play_times_.end()) { | 484 if (audio_iter != audio_play_times_.end()) { |
| 485 num_events++; | 485 num_events++; |
| 486 // Positive values means audio is running behind video. | 486 // Positive values means audio is running behind video. |
| 487 delta += audio_iter->second - video_iter->second; | 487 delta += audio_iter->second - video_iter->second; |
| 488 } | 488 } |
| 489 } | 489 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 510 #if defined(USE_X11) | 510 #if defined(USE_X11) |
| 511 test::LinuxOutputWindow render_; | 511 test::LinuxOutputWindow render_; |
| 512 #endif // defined(USE_X11) | 512 #endif // defined(USE_X11) |
| 513 scoped_ptr<AudioOutputStream> audio_output_stream_; | 513 scoped_ptr<AudioOutputStream> audio_output_stream_; |
| 514 | 514 |
| 515 // Video playout queue. | 515 // Video playout queue. |
| 516 typedef std::pair<base::TimeTicks, scoped_refptr<VideoFrame> > | 516 typedef std::pair<base::TimeTicks, scoped_refptr<VideoFrame> > |
| 517 VideoQueueEntry; | 517 VideoQueueEntry; |
| 518 std::deque<VideoQueueEntry> video_playout_queue_; | 518 std::deque<VideoQueueEntry> video_playout_queue_; |
| 519 base::TimeTicks last_popped_video_playout_time_; | 519 base::TimeTicks last_popped_video_playout_time_; |
| 520 int64 num_video_frames_processed_; | 520 int64_t num_video_frames_processed_; |
| 521 | 521 |
| 522 base::OneShotTimer video_playout_timer_; | 522 base::OneShotTimer video_playout_timer_; |
| 523 | 523 |
| 524 // Audio playout queue, synchronized by |audio_lock_|. | 524 // Audio playout queue, synchronized by |audio_lock_|. |
| 525 base::Lock audio_lock_; | 525 base::Lock audio_lock_; |
| 526 typedef std::pair<base::TimeTicks, AudioBus*> AudioQueueEntry; | 526 typedef std::pair<base::TimeTicks, AudioBus*> AudioQueueEntry; |
| 527 std::deque<AudioQueueEntry> audio_playout_queue_; | 527 std::deque<AudioQueueEntry> audio_playout_queue_; |
| 528 base::TimeTicks last_popped_audio_playout_time_; | 528 base::TimeTicks last_popped_audio_playout_time_; |
| 529 int64 num_audio_frames_processed_; | 529 int64_t num_audio_frames_processed_; |
| 530 | 530 |
| 531 // These must only be used on the audio thread calling OnMoreData(). | 531 // These must only be used on the audio thread calling OnMoreData(). |
| 532 scoped_ptr<AudioBus> currently_playing_audio_frame_; | 532 scoped_ptr<AudioBus> currently_playing_audio_frame_; |
| 533 int currently_playing_audio_frame_start_; | 533 int currently_playing_audio_frame_start_; |
| 534 | 534 |
| 535 std::map<uint16, base::TimeTicks> audio_play_times_; | 535 std::map<uint16_t, base::TimeTicks> audio_play_times_; |
| 536 std::map<uint16, base::TimeTicks> video_play_times_; | 536 std::map<uint16_t, base::TimeTicks> video_play_times_; |
| 537 int32 last_audio_frame_no_; | 537 int32_t last_audio_frame_no_; |
| 538 }; | 538 }; |
| 539 | 539 |
| 540 } // namespace cast | 540 } // namespace cast |
| 541 } // namespace media | 541 } // namespace media |
| 542 | 542 |
| 543 int main(int argc, char** argv) { | 543 int main(int argc, char** argv) { |
| 544 base::AtExitManager at_exit; | 544 base::AtExitManager at_exit; |
| 545 base::CommandLine::Init(argc, argv); | 545 base::CommandLine::Init(argc, argv); |
| 546 InitLogging(logging::LoggingSettings()); | 546 InitLogging(logging::LoggingSettings()); |
| 547 | 547 |
| 548 scoped_refptr<media::cast::CastEnvironment> cast_environment( | 548 scoped_refptr<media::cast::CastEnvironment> cast_environment( |
| 549 new media::cast::StandaloneCastEnvironment); | 549 new media::cast::StandaloneCastEnvironment); |
| 550 | 550 |
| 551 // Start up Chromium audio system. | 551 // Start up Chromium audio system. |
| 552 media::FakeAudioLogFactory fake_audio_log_factory_; | 552 media::FakeAudioLogFactory fake_audio_log_factory_; |
| 553 const scoped_ptr<media::AudioManager> audio_manager( | 553 const scoped_ptr<media::AudioManager> audio_manager( |
| 554 media::AudioManager::Create(&fake_audio_log_factory_)); | 554 media::AudioManager::Create(&fake_audio_log_factory_)); |
| 555 CHECK(media::AudioManager::Get()); | 555 CHECK(media::AudioManager::Get()); |
| 556 | 556 |
| 557 media::cast::FrameReceiverConfig audio_config = | 557 media::cast::FrameReceiverConfig audio_config = |
| 558 media::cast::GetAudioReceiverConfig(); | 558 media::cast::GetAudioReceiverConfig(); |
| 559 media::cast::FrameReceiverConfig video_config = | 559 media::cast::FrameReceiverConfig video_config = |
| 560 media::cast::GetVideoReceiverConfig(); | 560 media::cast::GetVideoReceiverConfig(); |
| 561 | 561 |
| 562 // Determine local and remote endpoints. | 562 // Determine local and remote endpoints. |
| 563 uint16 remote_port, local_port; | 563 uint16_t remote_port, local_port; |
| 564 media::cast::GetPorts(&remote_port, &local_port); | 564 media::cast::GetPorts(&remote_port, &local_port); |
| 565 if (!local_port) { | 565 if (!local_port) { |
| 566 LOG(ERROR) << "Invalid local port."; | 566 LOG(ERROR) << "Invalid local port."; |
| 567 return 1; | 567 return 1; |
| 568 } | 568 } |
| 569 std::string remote_ip_address = media::cast::GetIpAddress("Enter remote IP."); | 569 std::string remote_ip_address = media::cast::GetIpAddress("Enter remote IP."); |
| 570 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); | 570 std::string local_ip_address = media::cast::GetIpAddress("Enter local IP."); |
| 571 net::IPAddressNumber remote_ip_number; | 571 net::IPAddressNumber remote_ip_number; |
| 572 net::IPAddressNumber local_ip_number; | 572 net::IPAddressNumber local_ip_number; |
| 573 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) { | 573 if (!net::ParseIPLiteralToNumber(remote_ip_address, &remote_ip_number)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 593 audio_config, | 593 audio_config, |
| 594 video_config, | 594 video_config, |
| 595 window_width, | 595 window_width, |
| 596 window_height); | 596 window_height); |
| 597 player.Start(); | 597 player.Start(); |
| 598 | 598 |
| 599 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). | 599 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). |
| 600 NOTREACHED(); | 600 NOTREACHED(); |
| 601 return 0; | 601 return 0; |
| 602 } | 602 } |
| OLD | NEW |