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

Side by Side Diff: chrome/renderer/media/cast_rtp_stream.cc

Issue 1337243003: Extracted hardcoded constants from cast_rtp_stream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | media/cast/cast_defines.h » ('j') | media/cast/cast_defines.h » ('J')
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 "chrome/renderer/media/cast_rtp_stream.h" 5 #include "chrome/renderer/media/cast_rtp_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/sys_info.h" 15 #include "base/sys_info.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/renderer/media/cast_session.h" 18 #include "chrome/renderer/media/cast_session.h"
19 #include "chrome/renderer/media/cast_udp_transport.h" 19 #include "chrome/renderer/media/cast_udp_transport.h"
20 #include "content/public/renderer/media_stream_audio_sink.h" 20 #include "content/public/renderer/media_stream_audio_sink.h"
21 #include "content/public/renderer/media_stream_video_sink.h" 21 #include "content/public/renderer/media_stream_video_sink.h"
22 #include "content/public/renderer/render_thread.h" 22 #include "content/public/renderer/render_thread.h"
23 #include "content/public/renderer/video_encode_accelerator.h" 23 #include "content/public/renderer/video_encode_accelerator.h"
24 #include "media/audio/audio_parameters.h" 24 #include "media/audio/audio_parameters.h"
25 #include "media/base/audio_bus.h" 25 #include "media/base/audio_bus.h"
26 #include "media/base/audio_converter.h" 26 #include "media/base/audio_converter.h"
27 #include "media/base/audio_fifo.h" 27 #include "media/base/audio_fifo.h"
28 #include "media/base/bind_to_current_loop.h" 28 #include "media/base/bind_to_current_loop.h"
29 #include "media/base/limits.h"
29 #include "media/base/video_frame.h" 30 #include "media/base/video_frame.h"
30 #include "media/cast/cast_config.h" 31 #include "media/cast/cast_config.h"
31 #include "media/cast/cast_defines.h" 32 #include "media/cast/cast_defines.h"
32 #include "media/cast/cast_sender.h" 33 #include "media/cast/cast_sender.h"
33 #include "media/cast/net/cast_transport_config.h" 34 #include "media/cast/net/cast_transport_config.h"
34 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 35 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
35 #include "ui/gfx/geometry/size.h" 36 #include "ui/gfx/geometry/size.h"
36 37
37 using media::cast::AudioSenderConfig; 38 using media::cast::AudioSenderConfig;
38 using media::cast::VideoSenderConfig; 39 using media::cast::VideoSenderConfig;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 payload.min_bitrate = 50; 74 payload.min_bitrate = 50;
74 payload.channels = 1; 75 payload.channels = 1;
75 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate; 76 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate;
76 payload.codec_name = kCodecNameVp8; 77 payload.codec_name = kCodecNameVp8;
77 return payload; 78 return payload;
78 } 79 }
79 80
80 CastRtpPayloadParams DefaultH264Payload() { 81 CastRtpPayloadParams DefaultH264Payload() {
81 CastRtpPayloadParams payload; 82 CastRtpPayloadParams payload;
82 // TODO(hshi): set different ssrc/rtpPayloadType values for H264 and VP8 83 // TODO(hshi): set different ssrc/rtpPayloadType values for H264 and VP8
83 // once b/13696137 is fixed. 84 // once b/13696137 is fixed.
mcasas 2015/09/15 16:59:39 Note: We shouldn't have buganizer bugs in Chromium
miu 2015/09/15 22:05:22 Note: esnada@ is an external-to-Google contributor
msu.koo 2015/09/17 07:00:50 This comment lines were removed.
84 payload.payload_type = 96; 85 payload.payload_type = 96;
85 payload.max_latency_ms = media::cast::kDefaultRtpMaxDelayMs; 86 payload.max_latency_ms = media::cast::kDefaultRtpMaxDelayMs;
86 payload.ssrc = 11; 87 payload.ssrc = 11;
87 payload.feedback_ssrc = 12; 88 payload.feedback_ssrc = 12;
88 payload.clock_rate = media::cast::kVideoFrequency; 89 payload.clock_rate = media::cast::kVideoFrequency;
89 payload.max_bitrate = 2000; 90 payload.max_bitrate = 2000;
90 payload.min_bitrate = 50; 91 payload.min_bitrate = 50;
mcasas 2015/09/15 16:59:39 What about these |50| and |2000| ? (l.73-74, 90-91
91 payload.channels = 1; 92 payload.channels = 1;
92 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate; 93 payload.max_frame_rate = media::cast::kDefaultMaxFrameRate;
93 payload.codec_name = kCodecNameH264; 94 payload.codec_name = kCodecNameH264;
94 return payload; 95 return payload;
95 } 96 }
96 97
97 bool IsHardwareVP8EncodingSupported() { 98 bool IsHardwareVP8EncodingSupported() {
98 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 99 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
99 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) { 100 if (cmd_line->HasSwitch(switches::kDisableCastStreamingHWEncoding)) {
100 DVLOG(1) << "Disabled hardware VP8 support for Cast Streaming."; 101 DVLOG(1) << "Disabled hardware VP8 support for Cast Streaming.";
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 161
161 return supported_params; 162 return supported_params;
162 } 163 }
163 164
164 bool ToAudioSenderConfig(const CastRtpParams& params, 165 bool ToAudioSenderConfig(const CastRtpParams& params,
165 AudioSenderConfig* config) { 166 AudioSenderConfig* config) {
166 config->ssrc = params.payload.ssrc; 167 config->ssrc = params.payload.ssrc;
167 config->receiver_ssrc = params.payload.feedback_ssrc; 168 config->receiver_ssrc = params.payload.feedback_ssrc;
168 if (config->ssrc == config->receiver_ssrc) 169 if (config->ssrc == config->receiver_ssrc)
169 return false; 170 return false;
170 config->min_playout_delay = 171 config->min_playout_delay =
mcasas 2015/09/15 16:59:39 see my comment on l.207
msu.koo 2015/09/17 07:00:50 Done.
171 base::TimeDelta::FromMilliseconds( 172 base::TimeDelta::FromMilliseconds(
172 params.payload.min_latency_ms ? 173 params.payload.min_latency_ms ?
173 params.payload.min_latency_ms : 174 params.payload.min_latency_ms :
174 params.payload.max_latency_ms); 175 params.payload.max_latency_ms);
175 config->max_playout_delay = 176 config->max_playout_delay =
176 base::TimeDelta::FromMilliseconds(params.payload.max_latency_ms); 177 base::TimeDelta::FromMilliseconds(params.payload.max_latency_ms);
177 if (config->min_playout_delay <= base::TimeDelta()) 178 if (config->min_playout_delay <= base::TimeDelta())
178 return false; 179 return false;
179 if (config->min_playout_delay > config->max_playout_delay) 180 if (config->min_playout_delay > config->max_playout_delay)
180 return false; 181 return false;
181 config->rtp_payload_type = params.payload.payload_type; 182 config->rtp_payload_type = params.payload.payload_type;
182 config->use_external_encoder = false; 183 config->use_external_encoder = false;
183 config->frequency = params.payload.clock_rate; 184 config->frequency = params.payload.clock_rate;
184 if (config->frequency < 8000) 185 if (config->frequency < media::cast::kMinSampleRateForEncoding)
mcasas 2015/09/15 16:59:39 If |kMinSampleRateForEncoding| is only used in thi
miu 2015/09/15 22:05:22 I disagree with this one. IMO, the constant belon
185 return false; 186 return false;
186 config->channels = params.payload.channels; 187 config->channels = params.payload.channels;
187 if (config->channels < 1) 188 if (config->channels < 1)
188 return false; 189 return false;
189 config->bitrate = params.payload.max_bitrate * kBitrateMultiplier; 190 config->bitrate = params.payload.max_bitrate * kBitrateMultiplier;
190 if (params.payload.codec_name == kCodecNameOpus) 191 if (params.payload.codec_name == kCodecNameOpus)
191 config->codec = media::cast::CODEC_AUDIO_OPUS; 192 config->codec = media::cast::CODEC_AUDIO_OPUS;
192 else 193 else
193 return false; 194 return false;
194 config->aes_key = params.payload.aes_key; 195 config->aes_key = params.payload.aes_key;
195 config->aes_iv_mask = params.payload.aes_iv_mask; 196 config->aes_iv_mask = params.payload.aes_iv_mask;
196 return true; 197 return true;
197 } 198 }
198 199
199 bool ToVideoSenderConfig(const CastRtpParams& params, 200 bool ToVideoSenderConfig(const CastRtpParams& params,
200 VideoSenderConfig* config) { 201 VideoSenderConfig* config) {
201 config->ssrc = params.payload.ssrc; 202 config->ssrc = params.payload.ssrc;
202 config->receiver_ssrc = params.payload.feedback_ssrc; 203 config->receiver_ssrc = params.payload.feedback_ssrc;
203 if (config->ssrc == config->receiver_ssrc) 204 if (config->ssrc == config->receiver_ssrc)
204 return false; 205 return false;
205 config->min_playout_delay = 206 config->min_playout_delay =
206 base::TimeDelta::FromMilliseconds( 207 base::TimeDelta::FromMilliseconds(
mcasas 2015/09/15 16:59:39 l.206-210 should be formatted: config->min_play
msu.koo 2015/09/17 07:00:50 Done.
207 params.payload.min_latency_ms ? 208 params.payload.min_latency_ms ?
208 params.payload.min_latency_ms : 209 params.payload.min_latency_ms :
209 params.payload.max_latency_ms); 210 params.payload.max_latency_ms);
210 config->max_playout_delay = 211 config->max_playout_delay =
211 base::TimeDelta::FromMilliseconds(params.payload.max_latency_ms); 212 base::TimeDelta::FromMilliseconds(params.payload.max_latency_ms);
212 if (config->min_playout_delay <= base::TimeDelta()) 213 if (config->min_playout_delay <= base::TimeDelta())
213 return false; 214 return false;
214 if (config->min_playout_delay > config->max_playout_delay) 215 if (config->min_playout_delay > config->max_playout_delay)
215 return false; 216 return false;
216 config->rtp_payload_type = params.payload.payload_type; 217 config->rtp_payload_type = params.payload.payload_type;
217 config->min_bitrate = config->start_bitrate = 218 config->min_bitrate = config->start_bitrate =
218 params.payload.min_bitrate * kBitrateMultiplier; 219 params.payload.min_bitrate * kBitrateMultiplier;
219 config->max_bitrate = params.payload.max_bitrate * kBitrateMultiplier; 220 config->max_bitrate = params.payload.max_bitrate * kBitrateMultiplier;
220 if (config->min_bitrate > config->max_bitrate) 221 if (config->min_bitrate > config->max_bitrate)
221 return false; 222 return false;
222 config->start_bitrate = config->min_bitrate; 223 config->start_bitrate = config->min_bitrate;
223 config->max_frame_rate = static_cast<int>( 224 config->max_frame_rate = static_cast<int>(
224 std::max(1.0, params.payload.max_frame_rate) + 0.5); 225 std::max(1.0, params.payload.max_frame_rate) + 0.5);
225 if (config->max_frame_rate > 120) 226 if (config->max_frame_rate > media::limits::kMaxFramesPerSecond)
226 return false; 227 return false;
227 if (params.payload.codec_name == kCodecNameVp8) { 228 if (params.payload.codec_name == kCodecNameVp8) {
228 config->use_external_encoder = IsHardwareVP8EncodingSupported(); 229 config->use_external_encoder = IsHardwareVP8EncodingSupported();
229 config->codec = media::cast::CODEC_VIDEO_VP8; 230 config->codec = media::cast::CODEC_VIDEO_VP8;
230 } else if (params.payload.codec_name == kCodecNameH264) { 231 } else if (params.payload.codec_name == kCodecNameH264) {
231 config->use_external_encoder = IsHardwareH264EncodingSupported(); 232 config->use_external_encoder = IsHardwareH264EncodingSupported();
232 config->codec = media::cast::CODEC_VIDEO_H264; 233 config->codec = media::cast::CODEC_VIDEO_H264;
233 } else { 234 } else {
234 return false; 235 return false;
235 } 236 }
236 if (!config->use_external_encoder) { 237 if (!config->use_external_encoder) {
mcasas 2015/09/15 16:59:39 no {}
msu.koo 2015/09/17 07:00:50 Done.
237 config->number_of_encode_threads = NumberOfEncodeThreads(); 238 config->number_of_encode_threads = NumberOfEncodeThreads();
238 } 239 }
239 config->aes_key = params.payload.aes_key; 240 config->aes_key = params.payload.aes_key;
240 config->aes_iv_mask = params.payload.aes_iv_mask; 241 config->aes_iv_mask = params.payload.aes_iv_mask;
241 return true; 242 return true;
242 } 243 }
243 244
244 } // namespace 245 } // namespace
245 246
246 // This class receives MediaStreamTrack events and video frames from a 247 // This class receives MediaStreamTrack events and video frames from a
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 DCHECK(content::RenderThread::Get()); 576 DCHECK(content::RenderThread::Get());
576 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = " 577 DVLOG(1) << "CastRtpStream::DidEncounterError(" << message << ") = "
577 << (IsAudio() ? "audio" : "video"); 578 << (IsAudio() ? "audio" : "video");
578 // Save the WeakPtr first because the error callback might delete this object. 579 // Save the WeakPtr first because the error callback might delete this object.
579 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); 580 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr();
580 error_callback_.Run(message); 581 error_callback_.Run(message);
581 base::ThreadTaskRunnerHandle::Get()->PostTask( 582 base::ThreadTaskRunnerHandle::Get()->PostTask(
582 FROM_HERE, 583 FROM_HERE,
583 base::Bind(&CastRtpStream::Stop, ptr)); 584 base::Bind(&CastRtpStream::Stop, ptr));
584 } 585 }
OLDNEW
« no previous file with comments | « no previous file | media/cast/cast_defines.h » ('j') | media/cast/cast_defines.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698