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

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

Issue 228313002: Cast: Use 2 threads for encoding on capable systems (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/cast/cast_config.h » ('j') | no next file with comments »
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/sys_info.h"
11 #include "chrome/renderer/media/cast_session.h" 12 #include "chrome/renderer/media/cast_session.h"
12 #include "chrome/renderer/media/cast_udp_transport.h" 13 #include "chrome/renderer/media/cast_udp_transport.h"
13 #include "content/public/renderer/media_stream_audio_sink.h" 14 #include "content/public/renderer/media_stream_audio_sink.h"
14 #include "content/public/renderer/media_stream_video_sink.h" 15 #include "content/public/renderer/media_stream_video_sink.h"
15 #include "content/public/renderer/render_thread.h" 16 #include "content/public/renderer/render_thread.h"
16 #include "content/public/renderer/video_encode_accelerator.h" 17 #include "content/public/renderer/video_encode_accelerator.h"
17 #include "media/audio/audio_parameters.h" 18 #include "media/audio/audio_parameters.h"
18 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
19 #include "media/base/audio_fifo.h" 20 #include "media/base/audio_fifo.h"
20 #include "media/base/bind_to_current_loop.h" 21 #include "media/base/bind_to_current_loop.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 content::GetSupportedVideoEncodeAcceleratorProfiles(); 110 content::GetSupportedVideoEncodeAcceleratorProfiles();
110 for (size_t i = 0; i < vea_profiles.size(); ++i) { 111 for (size_t i = 0; i < vea_profiles.size(); ++i) {
111 if (vea_profiles[i].profile >= media::H264PROFILE_MIN && 112 if (vea_profiles[i].profile >= media::H264PROFILE_MIN &&
112 vea_profiles[i].profile <= media::H264PROFILE_MAX) { 113 vea_profiles[i].profile <= media::H264PROFILE_MAX) {
113 return true; 114 return true;
114 } 115 }
115 } 116 }
116 return false; 117 return false;
117 } 118 }
118 119
120 int NumberOfEncodeThreads() {
121 // We want to give CPU cycles for capturing and not to saturate the system
122 // just for encoding. So on a lower end system with only 1 or 2 cores we
123 // use only one thread for encoding.
124 if (base::SysInfo::NumberOfProcessors() <= 2)
125 return 1;
126
127 // On higher end we want to use 2 threads for encoding to reduce latency.
128 // In theory a physical CPU core has maximum 2 hyperthreads. Having 3 or
129 // more logical processors means the system has at least 2 physical cores.
130 return 2;
miu 2014/04/09 00:53:42 Unless I'm missing something, the change descripti
131 }
132
119 std::vector<CastRtpParams> SupportedAudioParams() { 133 std::vector<CastRtpParams> SupportedAudioParams() {
120 // TODO(hclam): Fill in more codecs here. 134 // TODO(hclam): Fill in more codecs here.
121 std::vector<CastRtpParams> supported_params; 135 std::vector<CastRtpParams> supported_params;
122 supported_params.push_back(CastRtpParams(DefaultOpusPayload())); 136 supported_params.push_back(CastRtpParams(DefaultOpusPayload()));
123 return supported_params; 137 return supported_params;
124 } 138 }
125 139
126 std::vector<CastRtpParams> SupportedVideoParams() { 140 std::vector<CastRtpParams> SupportedVideoParams() {
127 std::vector<CastRtpParams> supported_params; 141 std::vector<CastRtpParams> supported_params;
128 if (IsHardwareH264EncodingSupported()) 142 if (IsHardwareH264EncodingSupported())
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 config->max_bitrate = params.payload.max_bitrate * kBitrateMultiplier; 175 config->max_bitrate = params.payload.max_bitrate * kBitrateMultiplier;
162 if (params.payload.codec_name == kCodecNameVp8) { 176 if (params.payload.codec_name == kCodecNameVp8) {
163 config->use_external_encoder = IsHardwareVP8EncodingSupported(); 177 config->use_external_encoder = IsHardwareVP8EncodingSupported();
164 config->codec = media::cast::transport::kVp8; 178 config->codec = media::cast::transport::kVp8;
165 } else if (params.payload.codec_name == kCodecNameH264) { 179 } else if (params.payload.codec_name == kCodecNameH264) {
166 config->use_external_encoder = IsHardwareH264EncodingSupported(); 180 config->use_external_encoder = IsHardwareH264EncodingSupported();
167 config->codec = media::cast::transport::kH264; 181 config->codec = media::cast::transport::kH264;
168 } else { 182 } else {
169 return false; 183 return false;
170 } 184 }
185 if (!config->use_external_encoder) {
186 config->number_of_encode_threads = NumberOfEncodeThreads();
187 }
171 return true; 188 return true;
172 } 189 }
173 190
174 } // namespace 191 } // namespace
175 192
176 // This class receives MediaStreamTrack events and video frames from a 193 // This class receives MediaStreamTrack events and video frames from a
177 // MediaStreamTrack. Video frames are submitted to media::cast::FrameInput. 194 // MediaStreamTrack. Video frames are submitted to media::cast::FrameInput.
178 // 195 //
179 // Threading: Video frames are received on the render thread. 196 // Threading: Video frames are received on the render thread.
180 class CastVideoSink : public base::SupportsWeakPtr<CastVideoSink>, 197 class CastVideoSink : public base::SupportsWeakPtr<CastVideoSink>,
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 516 }
500 517
501 void CastRtpStream::DidEncounterError(const std::string& message) { 518 void CastRtpStream::DidEncounterError(const std::string& message) {
502 // Save the WeakPtr first because the error callback might delete this object. 519 // Save the WeakPtr first because the error callback might delete this object.
503 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr(); 520 base::WeakPtr<CastRtpStream> ptr = weak_factory_.GetWeakPtr();
504 error_callback_.Run(message); 521 error_callback_.Run(message);
505 content::RenderThread::Get()->GetMessageLoop()->PostTask( 522 content::RenderThread::Get()->GetMessageLoop()->PostTask(
506 FROM_HERE, 523 FROM_HERE,
507 base::Bind(&CastRtpStream::Stop, ptr)); 524 base::Bind(&CastRtpStream::Stop, ptr));
508 } 525 }
OLDNEW
« no previous file with comments | « no previous file | media/cast/cast_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698