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/gpu/rtc_video_encoder_factory.h" | 5 #include "content/renderer/media/gpu/rtc_video_encoder_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "content/public/common/content_switches.h" | 8 #include "content/public/common/content_switches.h" |
| 9 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | 9 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" |
| 10 #include "content/renderer/media/gpu/rtc_video_encoder.h" | 10 #include "content/renderer/media/gpu/rtc_video_encoder.h" |
| 11 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" | 11 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" |
| 12 #include "media/renderers/gpu_video_accelerator_factories.h" | 12 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 13 #include "media/video/video_encode_accelerator.h" | 13 #include "media/video/video_encode_accelerator.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 bool IsCodecDisabledByCommandLine(const base::CommandLine* cmd_line, | |
| 19 const std::string codec_name) { | |
| 20 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding)) | |
| 21 return false; | |
| 22 | |
| 23 const std::string codec_filter = | |
| 24 cmd_line->GetSwitchValueASCII(switches::kDisableWebRtcHWEncoding); | |
| 25 if (!codec_filter.empty() && codec_filter != codec_name) | |
| 26 return false; | |
|
watk
2016/10/01 01:06:54
nit: can return the expression in the if-statement
braveyao
2016/10/03 23:50:14
Done.
| |
| 27 | |
| 28 return true; | |
| 29 } | |
| 18 | 30 |
| 19 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | 31 // Translate from media::VideoEncodeAccelerator::SupportedProfile to |
| 20 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec | 32 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec |
| 21 void VEAToWebRTCCodecs( | 33 void VEAToWebRTCCodecs( |
| 22 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, | 34 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, |
| 23 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | 35 const media::VideoEncodeAccelerator::SupportedProfile& profile) { |
| 24 const int width = profile.max_resolution.width(); | 36 const int width = profile.max_resolution.width(); |
| 25 const int height = profile.max_resolution.height(); | 37 const int height = profile.max_resolution.height(); |
| 26 const int fps = profile.max_framerate_numerator; | 38 const int fps = profile.max_framerate_numerator; |
| 27 DCHECK_EQ(profile.max_framerate_denominator, 1U); | 39 DCHECK_EQ(profile.max_framerate_denominator, 1U); |
| 28 | 40 |
| 29 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 41 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 30 if (profile.profile >= media::VP8PROFILE_MIN && | 42 if (profile.profile >= media::VP8PROFILE_MIN && |
| 31 profile.profile <= media::VP8PROFILE_MAX) { | 43 profile.profile <= media::VP8PROFILE_MAX) { |
| 32 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 44 if (!IsCodecDisabledByCommandLine(cmd_line, |
| 33 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); | 45 switches::kDisableWebRtcHWEncodingVPx)) { |
| 46 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | |
| 47 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); | |
| 48 } | |
| 34 } else if (profile.profile >= media::H264PROFILE_MIN && | 49 } else if (profile.profile >= media::H264PROFILE_MIN && |
| 35 profile.profile <= media::H264PROFILE_MAX) { | 50 profile.profile <= media::H264PROFILE_MAX) { |
| 36 // Enable H264 HW encode for WebRTC when SW fallback is available, which is | 51 // Enable H264 HW encode for WebRTC when SW fallback is available, which is |
| 37 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be | 52 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be |
| 38 // removed when SW implementation is fully enabled. | 53 // removed when SW implementation is fully enabled. |
| 39 // kEnableWebRtcHWH264Encoding flag is only enabled for extensions, and | 54 // kEnableWebRtcHWH264Encoding flag is only enabled for extensions, and |
| 40 // can be used without SW fallback. | 55 // can be used without SW fallback. |
| 41 bool webrtc_h264_sw_enabled = false; | 56 bool webrtc_h264_sw_enabled = false; |
| 42 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) | 57 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) |
| 43 webrtc_h264_sw_enabled = | 58 webrtc_h264_sw_enabled = |
| 44 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); | 59 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); |
| 45 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) | 60 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) |
| 46 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding) || | 61 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding) || |
| 47 webrtc_h264_sw_enabled) { | 62 webrtc_h264_sw_enabled || |
| 63 !IsCodecDisabledByCommandLine(cmd_line, | |
| 64 switches::kDisableWebRtcHWEncodingH264)) { | |
| 48 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 65 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 49 webrtc::kVideoCodecH264, "H264", width, height, fps)); | 66 webrtc::kVideoCodecH264, "H264", width, height, fps)); |
| 50 } | 67 } |
| 51 } | 68 } |
| 52 } | 69 } |
| 53 | 70 |
| 54 } // anonymous namespace | 71 } // anonymous namespace |
| 55 | 72 |
| 56 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | 73 RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
| 57 media::GpuVideoAcceleratorFactories* gpu_factories) | 74 media::GpuVideoAcceleratorFactories* gpu_factories) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 77 RTCVideoEncoderFactory::codecs() const { | 94 RTCVideoEncoderFactory::codecs() const { |
| 78 return codecs_; | 95 return codecs_; |
| 79 } | 96 } |
| 80 | 97 |
| 81 void RTCVideoEncoderFactory::DestroyVideoEncoder( | 98 void RTCVideoEncoderFactory::DestroyVideoEncoder( |
| 82 webrtc::VideoEncoder* encoder) { | 99 webrtc::VideoEncoder* encoder) { |
| 83 delete encoder; | 100 delete encoder; |
| 84 } | 101 } |
| 85 | 102 |
| 86 } // namespace content | 103 } // namespace content |
| OLD | NEW |