Chromium Code Reviews| 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 "content/renderer/media/rtc_video_encoder_factory.h" | 5 #include "content/renderer/media/rtc_video_encoder_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 8 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/renderer/media/rtc_video_encoder.h" | 10 #include "content/renderer/media/rtc_video_encoder.h" |
| 11 #include "media/renderers/gpu_video_accelerator_factories.h" | 11 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 12 #include "media/video/video_encode_accelerator.h" | 12 #include "media/video/video_encode_accelerator.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | 18 // Translate from media::VideoEncodeAccelerator::SupportedProfile to |
| 19 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec | 19 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec |
| 20 void VEAToWebRTCCodecs( | 20 void VEAToWebRTCCodecs( |
| 21 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, | 21 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, |
| 22 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | 22 const media::VideoEncodeAccelerator::SupportedProfile& profile) { |
| 23 int width = profile.max_resolution.width(); | 23 const int width = profile.max_resolution.width(); |
| 24 int height = profile.max_resolution.height(); | 24 const int height = profile.max_resolution.height(); |
| 25 int fps = profile.max_framerate_numerator; | 25 const int fps = profile.max_framerate_numerator; |
| 26 DCHECK_EQ(profile.max_framerate_denominator, 1U); | 26 DCHECK_EQ(profile.max_framerate_denominator, 1U); |
| 27 | 27 |
| 28 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 28 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 29 if (profile.profile >= media::VP8PROFILE_MIN && | 29 if (profile.profile >= media::VP8PROFILE_MIN && |
| 30 profile.profile <= media::VP8PROFILE_MAX) { | 30 profile.profile <= media::VP8PROFILE_MAX) { |
| 31 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 31 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 32 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); | 32 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); |
| 33 } else if (profile.profile >= media::H264PROFILE_MIN && | 33 } else if (profile.profile >= media::H264PROFILE_MIN && |
| 34 profile.profile <= media::H264PROFILE_MAX) { | 34 profile.profile <= media::H264PROFILE_MAX) { |
| 35 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding)) { | 35 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding)) { |
| 36 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 36 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 37 webrtc::kVideoCodecH264, "H264", width, height, fps)); | 37 webrtc::kVideoCodecH264, "H264", width, height, fps)); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // anonymous namespace | 42 } // anonymous namespace |
| 43 | 43 |
| 44 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | 44 RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
| 45 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) | 45 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) |
| 46 : gpu_factories_(gpu_factories) { | 46 : gpu_factories_(gpu_factories) { |
| 47 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | 47 const std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
|
emircan
2015/03/19 01:16:55
Consider assigning by reference to the rvalue to s
mcasas
2015/03/19 02:54:26
Done.
| |
| 48 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); | 48 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); |
| 49 for (size_t i = 0; i < profiles.size(); ++i) | 49 for (const auto& profile : profiles) |
| 50 VEAToWebRTCCodecs(&codecs_, profiles[i]); | 50 VEAToWebRTCCodecs(&codecs_, profile); |
| 51 } | 51 } |
| 52 | 52 |
| 53 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} | 53 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} |
| 54 | 54 |
| 55 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( | 55 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( |
| 56 webrtc::VideoCodecType type) { | 56 webrtc::VideoCodecType type) { |
| 57 bool found = false; | 57 for (const auto& codec : codecs_) { |
| 58 for (size_t i = 0; i < codecs_.size(); ++i) { | 58 if (codec.type == type) |
| 59 if (codecs_[i].type == type) { | 59 return new RTCVideoEncoder(type, gpu_factories_); |
|
emircan
2015/03/19 01:16:56
Consider using std::find_if for clarity.
mcasas
2015/03/19 02:54:25
Hmm in this case and since VideoCodec does not hav
| |
| 60 found = true; | |
| 61 break; | |
| 62 } | |
| 63 } | 60 } |
| 64 if (!found) | 61 return NULL; |
|
Pawel Osciak
2015/03/19 01:26:33
s/NULL/nullptr/
mcasas
2015/03/19 02:54:25
Done.
| |
| 65 return NULL; | |
| 66 return new RTCVideoEncoder(type, gpu_factories_); | |
| 67 } | 62 } |
| 68 | 63 |
| 69 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& | 64 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& |
| 70 RTCVideoEncoderFactory::codecs() const { | 65 RTCVideoEncoderFactory::codecs() const { |
| 71 return codecs_; | 66 return codecs_; |
| 72 } | 67 } |
| 73 | 68 |
| 74 void RTCVideoEncoderFactory::DestroyVideoEncoder( | 69 void RTCVideoEncoderFactory::DestroyVideoEncoder( |
| 75 webrtc::VideoEncoder* encoder) { | 70 webrtc::VideoEncoder* encoder) { |
| 76 delete encoder; | 71 delete encoder; |
| 77 } | 72 } |
| 78 | 73 |
| 79 } // namespace content | 74 } // namespace content |
| OLD | NEW |