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_features.h" | |
| 8 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 9 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | 10 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" |
| 10 #include "content/renderer/media/gpu/rtc_video_encoder.h" | 11 #include "content/renderer/media/gpu/rtc_video_encoder.h" |
| 11 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" | 12 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" |
| 12 #include "media/renderers/gpu_video_accelerator_factories.h" | 13 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 13 #include "media/video/video_encode_accelerator.h" | 14 #include "media/video/video_encode_accelerator.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 namespace { | 18 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 return codec_filter.empty() || codec_filter == codec_name; | |
| 26 } | |
| 27 | 19 |
| 28 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | 20 // Translate from media::VideoEncodeAccelerator::SupportedProfile to |
| 29 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec | 21 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec |
| 30 void VEAToWebRTCCodecs( | 22 void VEAToWebRTCCodecs( |
| 31 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, | 23 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, |
| 32 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | 24 const media::VideoEncodeAccelerator::SupportedProfile& profile) { |
| 33 const int width = profile.max_resolution.width(); | 25 const int width = profile.max_resolution.width(); |
| 34 const int height = profile.max_resolution.height(); | 26 const int height = profile.max_resolution.height(); |
| 35 const int fps = profile.max_framerate_numerator; | 27 const int fps = profile.max_framerate_numerator; |
| 36 DCHECK_EQ(profile.max_framerate_denominator, 1U); | 28 DCHECK_EQ(profile.max_framerate_denominator, 1U); |
| 37 | 29 |
| 38 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 30 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 39 if (profile.profile >= media::VP8PROFILE_MIN && | 31 if (profile.profile >= media::VP8PROFILE_MIN && |
| 40 profile.profile <= media::VP8PROFILE_MAX) { | 32 profile.profile <= media::VP8PROFILE_MAX) { |
| 41 if (!IsCodecDisabledByCommandLine(cmd_line, | 33 if (!cmd_line->HasSwitch(switches::kDisableWebRtcHWEncoding)) { |
| 42 switches::kDisableWebRtcHWEncodingVPx)) { | |
| 43 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 34 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 44 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); | 35 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); |
| 45 } | 36 } |
| 46 } else if (profile.profile >= media::H264PROFILE_MIN && | 37 } else if (profile.profile >= media::H264PROFILE_MIN && |
| 47 profile.profile <= media::H264PROFILE_MAX) { | 38 profile.profile <= media::H264PROFILE_MAX) { |
| 48 // Enable H264 HW encode for WebRTC when SW fallback is available, which is | 39 // Enable H264 HW encode for WebRTC when SW fallback is available, which is |
| 49 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be | 40 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be |
| 50 // removed when SW implementation is fully enabled. | 41 // removed when SW implementation is fully enabled. |
| 51 bool webrtc_h264_sw_enabled = false; | 42 bool webrtc_h264_sw_enabled = false; |
| 52 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) | 43 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) |
| 53 webrtc_h264_sw_enabled = | 44 webrtc_h264_sw_enabled = |
| 54 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); | 45 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); |
| 55 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) | 46 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) |
| 56 if (webrtc_h264_sw_enabled || | 47 if (webrtc_h264_sw_enabled || |
| 57 !IsCodecDisabledByCommandLine(cmd_line, | 48 base::FeatureList::IsEnabled(features::kWebRtcHWH264EncodingAndroid)) { |
| 58 switches::kDisableWebRtcHWEncodingH264)) { | |
| 59 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | 49 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
|
Pawel Osciak
2016/12/06 04:13:00
Perhaps I'm misreading the logic of the decision t
braveyao
2016/12/06 17:50:13
That's true. We want to control H264 separately fr
piman
2016/12/06 21:29:42
Should we rename the flag to avoid confusion? E.g.
braveyao
2016/12/07 17:07:37
Done.
| |
| 60 webrtc::kVideoCodecH264, "H264", width, height, fps)); | 50 webrtc::kVideoCodecH264, "H264", width, height, fps)); |
| 61 } | 51 } |
| 62 } | 52 } |
| 63 } | 53 } |
| 64 | 54 |
| 65 } // anonymous namespace | 55 } // anonymous namespace |
| 66 | 56 |
| 67 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | 57 RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
| 68 media::GpuVideoAcceleratorFactories* gpu_factories) | 58 media::GpuVideoAcceleratorFactories* gpu_factories) |
| 69 : gpu_factories_(gpu_factories) { | 59 : gpu_factories_(gpu_factories) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 88 RTCVideoEncoderFactory::codecs() const { | 78 RTCVideoEncoderFactory::codecs() const { |
| 89 return codecs_; | 79 return codecs_; |
| 90 } | 80 } |
| 91 | 81 |
| 92 void RTCVideoEncoderFactory::DestroyVideoEncoder( | 82 void RTCVideoEncoderFactory::DestroyVideoEncoder( |
| 93 webrtc::VideoEncoder* encoder) { | 83 webrtc::VideoEncoder* encoder) { |
| 94 delete encoder; | 84 delete encoder; |
| 95 } | 85 } |
| 96 | 86 |
| 97 } // namespace content | 87 } // namespace content |
| OLD | NEW |