| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } |
| 86 return ip_address; | 86 return ip_address; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void GetSsrcs(AudioReceiverConfig* audio_config) { | 89 void GetAudioSsrcs(FrameReceiverConfig* audio_config) { |
| 90 test::InputBuilder input_tx( | 90 test::InputBuilder input_tx( |
| 91 "Choose audio sender SSRC.", DEFAULT_AUDIO_FEEDBACK_SSRC, 1, INT_MAX); | 91 "Choose audio sender SSRC.", DEFAULT_AUDIO_FEEDBACK_SSRC, 1, INT_MAX); |
| 92 audio_config->feedback_ssrc = input_tx.GetIntInput(); | 92 audio_config->feedback_ssrc = input_tx.GetIntInput(); |
| 93 | 93 |
| 94 test::InputBuilder input_rx( | 94 test::InputBuilder input_rx( |
| 95 "Choose audio receiver SSRC.", DEFAULT_AUDIO_INCOMING_SSRC, 1, INT_MAX); | 95 "Choose audio receiver SSRC.", DEFAULT_AUDIO_INCOMING_SSRC, 1, INT_MAX); |
| 96 audio_config->incoming_ssrc = input_rx.GetIntInput(); | 96 audio_config->incoming_ssrc = input_rx.GetIntInput(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void GetSsrcs(VideoReceiverConfig* video_config) { | 99 void GetVideoSsrcs(FrameReceiverConfig* video_config) { |
| 100 test::InputBuilder input_tx( | 100 test::InputBuilder input_tx( |
| 101 "Choose video sender SSRC.", DEFAULT_VIDEO_FEEDBACK_SSRC, 1, INT_MAX); | 101 "Choose video sender SSRC.", DEFAULT_VIDEO_FEEDBACK_SSRC, 1, INT_MAX); |
| 102 video_config->feedback_ssrc = input_tx.GetIntInput(); | 102 video_config->feedback_ssrc = input_tx.GetIntInput(); |
| 103 | 103 |
| 104 test::InputBuilder input_rx( | 104 test::InputBuilder input_rx( |
| 105 "Choose video receiver SSRC.", DEFAULT_VIDEO_INCOMING_SSRC, 1, INT_MAX); | 105 "Choose video receiver SSRC.", DEFAULT_VIDEO_INCOMING_SSRC, 1, INT_MAX); |
| 106 video_config->incoming_ssrc = input_rx.GetIntInput(); | 106 video_config->incoming_ssrc = input_rx.GetIntInput(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 #if defined(OS_LINUX) | 109 #if defined(OS_LINUX) |
| 110 void GetWindowSize(int* width, int* height) { | 110 void GetWindowSize(int* width, int* height) { |
| 111 // Resolution values based on sender settings | 111 // Resolution values based on sender settings |
| 112 test::InputBuilder input_w( | 112 test::InputBuilder input_w( |
| 113 "Choose window width.", kVideoWindowWidth, 144, 1920); | 113 "Choose window width.", kVideoWindowWidth, 144, 1920); |
| 114 *width = input_w.GetIntInput(); | 114 *width = input_w.GetIntInput(); |
| 115 | 115 |
| 116 test::InputBuilder input_h( | 116 test::InputBuilder input_h( |
| 117 "Choose window height.", kVideoWindowHeight, 176, 1080); | 117 "Choose window height.", kVideoWindowHeight, 176, 1080); |
| 118 *height = input_h.GetIntInput(); | 118 *height = input_h.GetIntInput(); |
| 119 } | 119 } |
| 120 #endif // OS_LINUX | 120 #endif // OS_LINUX |
| 121 | 121 |
| 122 void GetPayloadtype(AudioReceiverConfig* audio_config) { | 122 void GetAudioPayloadtype(FrameReceiverConfig* audio_config) { |
| 123 test::InputBuilder input("Choose audio receiver payload type.", | 123 test::InputBuilder input("Choose audio receiver payload type.", |
| 124 DEFAULT_AUDIO_PAYLOAD_TYPE, | 124 DEFAULT_AUDIO_PAYLOAD_TYPE, |
| 125 96, | 125 96, |
| 126 127); | 126 127); |
| 127 audio_config->rtp_payload_type = input.GetIntInput(); | 127 audio_config->rtp_payload_type = input.GetIntInput(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 AudioReceiverConfig GetAudioReceiverConfig() { | 130 FrameReceiverConfig GetAudioReceiverConfig() { |
| 131 AudioReceiverConfig audio_config = GetDefaultAudioReceiverConfig(); | 131 FrameReceiverConfig audio_config = GetDefaultAudioReceiverConfig(); |
| 132 GetSsrcs(&audio_config); | 132 GetAudioSsrcs(&audio_config); |
| 133 GetPayloadtype(&audio_config); | 133 GetAudioPayloadtype(&audio_config); |
| 134 audio_config.rtp_max_delay_ms = 300; | 134 audio_config.rtp_max_delay_ms = 300; |
| 135 return audio_config; | 135 return audio_config; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void GetPayloadtype(VideoReceiverConfig* video_config) { | 138 void GetVideoPayloadtype(FrameReceiverConfig* video_config) { |
| 139 test::InputBuilder input("Choose video receiver payload type.", | 139 test::InputBuilder input("Choose video receiver payload type.", |
| 140 DEFAULT_VIDEO_PAYLOAD_TYPE, | 140 DEFAULT_VIDEO_PAYLOAD_TYPE, |
| 141 96, | 141 96, |
| 142 127); | 142 127); |
| 143 video_config->rtp_payload_type = input.GetIntInput(); | 143 video_config->rtp_payload_type = input.GetIntInput(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 VideoReceiverConfig GetVideoReceiverConfig() { | 146 FrameReceiverConfig GetVideoReceiverConfig() { |
| 147 VideoReceiverConfig video_config = GetDefaultVideoReceiverConfig(); | 147 FrameReceiverConfig video_config = GetDefaultVideoReceiverConfig(); |
| 148 GetSsrcs(&video_config); | 148 GetVideoSsrcs(&video_config); |
| 149 GetPayloadtype(&video_config); | 149 GetVideoPayloadtype(&video_config); |
| 150 video_config.rtp_max_delay_ms = 300; | 150 video_config.rtp_max_delay_ms = 300; |
| 151 return video_config; | 151 return video_config; |
| 152 } | 152 } |
| 153 | 153 |
| 154 AudioParameters ToAudioParameters(const AudioReceiverConfig& config) { | 154 AudioParameters ToAudioParameters(const FrameReceiverConfig& config) { |
| 155 const int samples_in_10ms = config.frequency / 100; | 155 const int samples_in_10ms = config.frequency / 100; |
| 156 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 156 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 157 GuessChannelLayout(config.channels), | 157 GuessChannelLayout(config.channels), |
| 158 config.frequency, 32, samples_in_10ms); | 158 config.frequency, 32, samples_in_10ms); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // An InProcessReceiver that renders video frames to a LinuxOutputWindow and | 161 // An InProcessReceiver that renders video frames to a LinuxOutputWindow and |
| 162 // audio frames via Chromium's audio stack. | 162 // audio frames via Chromium's audio stack. |
| 163 // | 163 // |
| 164 // InProcessReceiver pushes audio and video frames to this subclass, and these | 164 // InProcessReceiver pushes audio and video frames to this subclass, and these |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 // 2. It makes no attempt to synchronize the timing of playout of the video | 175 // 2. It makes no attempt to synchronize the timing of playout of the video |
| 176 // frames with the audio frames. | 176 // frames with the audio frames. |
| 177 // 3. It does nothing to smooth or hide discontinuities in playback due to | 177 // 3. It does nothing to smooth or hide discontinuities in playback due to |
| 178 // timing issues or missing frames. | 178 // timing issues or missing frames. |
| 179 class NaivePlayer : public InProcessReceiver, | 179 class NaivePlayer : public InProcessReceiver, |
| 180 public AudioOutputStream::AudioSourceCallback { | 180 public AudioOutputStream::AudioSourceCallback { |
| 181 public: | 181 public: |
| 182 NaivePlayer(const scoped_refptr<CastEnvironment>& cast_environment, | 182 NaivePlayer(const scoped_refptr<CastEnvironment>& cast_environment, |
| 183 const net::IPEndPoint& local_end_point, | 183 const net::IPEndPoint& local_end_point, |
| 184 const net::IPEndPoint& remote_end_point, | 184 const net::IPEndPoint& remote_end_point, |
| 185 const AudioReceiverConfig& audio_config, | 185 const FrameReceiverConfig& audio_config, |
| 186 const VideoReceiverConfig& video_config, | 186 const FrameReceiverConfig& video_config, |
| 187 int window_width, | 187 int window_width, |
| 188 int window_height) | 188 int window_height) |
| 189 : InProcessReceiver(cast_environment, | 189 : InProcessReceiver(cast_environment, |
| 190 local_end_point, | 190 local_end_point, |
| 191 remote_end_point, | 191 remote_end_point, |
| 192 audio_config, | 192 audio_config, |
| 193 video_config), | 193 video_config), |
| 194 // Maximum age is the duration of 3 video frames. 3 was chosen | 194 // Maximum age is the duration of 3 video frames. 3 was chosen |
| 195 // arbitrarily, but seems to work well. | 195 // arbitrarily, but seems to work well. |
| 196 max_frame_age_(base::TimeDelta::FromSeconds(1) * 3 / | 196 max_frame_age_(base::TimeDelta::FromSeconds(1) * 3 / |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 546 |
| 547 scoped_refptr<media::cast::CastEnvironment> cast_environment( | 547 scoped_refptr<media::cast::CastEnvironment> cast_environment( |
| 548 new media::cast::StandaloneCastEnvironment); | 548 new media::cast::StandaloneCastEnvironment); |
| 549 | 549 |
| 550 // Start up Chromium audio system. | 550 // Start up Chromium audio system. |
| 551 media::FakeAudioLogFactory fake_audio_log_factory_; | 551 media::FakeAudioLogFactory fake_audio_log_factory_; |
| 552 const scoped_ptr<media::AudioManager> audio_manager( | 552 const scoped_ptr<media::AudioManager> audio_manager( |
| 553 media::AudioManager::Create(&fake_audio_log_factory_)); | 553 media::AudioManager::Create(&fake_audio_log_factory_)); |
| 554 CHECK(media::AudioManager::Get()); | 554 CHECK(media::AudioManager::Get()); |
| 555 | 555 |
| 556 media::cast::AudioReceiverConfig audio_config = | 556 media::cast::FrameReceiverConfig audio_config = |
| 557 media::cast::GetAudioReceiverConfig(); | 557 media::cast::GetAudioReceiverConfig(); |
| 558 media::cast::VideoReceiverConfig video_config = | 558 media::cast::FrameReceiverConfig video_config = |
| 559 media::cast::GetVideoReceiverConfig(); | 559 media::cast::GetVideoReceiverConfig(); |
| 560 | 560 |
| 561 // Determine local and remote endpoints. | 561 // Determine local and remote endpoints. |
| 562 int remote_port, local_port; | 562 int remote_port, local_port; |
| 563 media::cast::GetPorts(&remote_port, &local_port); | 563 media::cast::GetPorts(&remote_port, &local_port); |
| 564 if (!local_port) { | 564 if (!local_port) { |
| 565 LOG(ERROR) << "Invalid local port."; | 565 LOG(ERROR) << "Invalid local port."; |
| 566 return 1; | 566 return 1; |
| 567 } | 567 } |
| 568 std::string remote_ip_address = media::cast::GetIpAddress("Enter remote IP."); | 568 std::string remote_ip_address = media::cast::GetIpAddress("Enter remote IP."); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 592 audio_config, | 592 audio_config, |
| 593 video_config, | 593 video_config, |
| 594 window_width, | 594 window_width, |
| 595 window_height); | 595 window_height); |
| 596 player.Start(); | 596 player.Start(); |
| 597 | 597 |
| 598 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). | 598 base::MessageLoop().Run(); // Run forever (i.e., until SIGTERM). |
| 599 NOTREACHED(); | 599 NOTREACHED(); |
| 600 return 0; | 600 return 0; |
| 601 } | 601 } |
| OLD | NEW |