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

Side by Side Diff: content/renderer/media/gpu/rtc_video_encoder_factory.cc

Issue 2985263002: Reland of RTCVideoEncoder: Report H264 profile information to WebRTC (Closed)
Patch Set: Add default argument to SetDefaultVideoCodec Created 3 years, 4 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
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 "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_features.h"
9 #include "content/public/common/content_switches.h" 9 #include "content/public/common/content_switches.h"
10 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" 10 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h"
11 #include "content/renderer/media/gpu/rtc_video_encoder.h" 11 #include "content/renderer/media/gpu/rtc_video_encoder.h"
12 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" 12 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h"
13 #include "media/renderers/gpu_video_accelerator_factories.h" 13 #include "media/renderers/gpu_video_accelerator_factories.h"
14 #include "media/video/video_encode_accelerator.h" 14 #include "third_party/webrtc/common_video/h264/profile_level_id.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 namespace { 18 namespace {
19 19
20 // Translate from media::VideoEncodeAccelerator::SupportedProfile to 20 // Translate from media::VideoEncodeAccelerator::SupportedProfile to
21 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec 21 // cricket::WebRtcVideoEncoderFactory::VideoCodec, or return nothing if the
22 void VEAToWebRTCCodecs( 22 // profile isn't supported.
23 std::vector<cricket::VideoCodec>* codecs, 23 base::Optional<cricket::VideoCodec> VEAToWebRTCCodec(
24 const media::VideoEncodeAccelerator::SupportedProfile& profile) { 24 const media::VideoEncodeAccelerator::SupportedProfile& profile) {
25 DCHECK_EQ(profile.max_framerate_denominator, 1U); 25 DCHECK_EQ(profile.max_framerate_denominator, 1U);
26 26
27 if (profile.profile >= media::VP8PROFILE_MIN && 27 if (profile.profile >= media::VP8PROFILE_MIN &&
28 profile.profile <= media::VP8PROFILE_MAX) { 28 profile.profile <= media::VP8PROFILE_MAX) {
29 if (base::FeatureList::IsEnabled(features::kWebRtcHWVP8Encoding)) { 29 if (base::FeatureList::IsEnabled(features::kWebRtcHWVP8Encoding)) {
30 codecs->push_back(cricket::VideoCodec("VP8")); 30 return base::Optional<cricket::VideoCodec>(cricket::VideoCodec("VP8"));
31 } 31 }
32 } else if (profile.profile >= media::H264PROFILE_MIN && 32 } else if (profile.profile >= media::H264PROFILE_MIN &&
33 profile.profile <= media::H264PROFILE_MAX) { 33 profile.profile <= media::H264PROFILE_MAX) {
34 // Enable H264 HW encode for WebRTC when SW fallback is available, which is 34 // Enable H264 HW encode for WebRTC when SW fallback is available, which is
35 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be 35 // checked by kWebRtcH264WithOpenH264FFmpeg flag. This check should be
36 // removed when SW implementation is fully enabled. 36 // removed when SW implementation is fully enabled.
37 bool webrtc_h264_sw_enabled = false; 37 bool webrtc_h264_sw_enabled = false;
38 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) 38 #if BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG)
39 webrtc_h264_sw_enabled = 39 webrtc_h264_sw_enabled =
40 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); 40 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg);
41 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG) 41 #endif // BUILDFLAG(RTC_USE_H264) && !defined(MEDIA_DISABLE_FFMPEG)
42 if (webrtc_h264_sw_enabled || 42 if (webrtc_h264_sw_enabled ||
43 base::FeatureList::IsEnabled(features::kWebRtcHWH264Encoding)) { 43 base::FeatureList::IsEnabled(features::kWebRtcHWH264Encoding)) {
44 // TODO(magjed): Propagate H264 profile information. 44 webrtc::H264::Profile h264_profile;
45 codecs->push_back(cricket::VideoCodec("H264")); 45 switch (profile.profile) {
46 case media::H264PROFILE_BASELINE:
47 h264_profile = webrtc::H264::kProfileBaseline;
48 break;
49 case media::H264PROFILE_MAIN:
50 h264_profile = webrtc::H264::kProfileMain;
51 break;
52 case media::H264PROFILE_HIGH:
53 h264_profile = webrtc::H264::kProfileHigh;
54 break;
55 default:
56 // Unsupported H264 profile in WebRTC.
57 return base::Optional<cricket::VideoCodec>();
58 }
59
60 const int width = profile.max_resolution.width();
61 const int height = profile.max_resolution.height();
62 const int fps = profile.max_framerate_numerator;
63 DCHECK_EQ(1u, profile.max_framerate_denominator);
64
65 const rtc::Optional<webrtc::H264::Level> h264_level =
66 webrtc::H264::SupportedLevel(width * height, fps);
67 const webrtc::H264::ProfileLevelId profile_level_id(
68 h264_profile, h264_level.value_or(webrtc::H264::kLevel1));
69
70 cricket::VideoCodec codec("H264");
71 codec.SetParam(cricket::kH264FmtpProfileLevelId,
72 *webrtc::H264::ProfileLevelIdToString(profile_level_id));
73 codec.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
74 codec.SetParam(cricket::kH264FmtpPacketizationMode, "1");
75 return base::Optional<cricket::VideoCodec>(codec);
46 } 76 }
47 } 77 }
78 return base::Optional<cricket::VideoCodec>();
48 } 79 }
49 80
50 } // anonymous namespace 81 } // anonymous namespace
51 82
52 RTCVideoEncoderFactory::RTCVideoEncoderFactory( 83 RTCVideoEncoderFactory::RTCVideoEncoderFactory(
53 media::GpuVideoAcceleratorFactories* gpu_factories) 84 media::GpuVideoAcceleratorFactories* gpu_factories)
54 : gpu_factories_(gpu_factories) { 85 : gpu_factories_(gpu_factories) {
55 const media::VideoEncodeAccelerator::SupportedProfiles& profiles = 86 const media::VideoEncodeAccelerator::SupportedProfiles& profiles =
56 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); 87 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles();
57 for (const auto& profile : profiles) 88 for (const auto& profile : profiles) {
58 VEAToWebRTCCodecs(&supported_codecs_, profile); 89 base::Optional<cricket::VideoCodec> codec = VEAToWebRTCCodec(profile);
90 if (codec) {
91 supported_codecs_.push_back(std::move(*codec));
92 profiles_.push_back(profile.profile);
93 }
94 }
95 // There should be a 1:1 mapping between media::VideoCodecProfile and
96 // cricket::VideoCodec.
97 CHECK_EQ(profiles_.size(), supported_codecs_.size());
59 } 98 }
60 99
61 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} 100 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {}
62 101
63 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( 102 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder(
64 const cricket::VideoCodec& codec) { 103 const cricket::VideoCodec& codec) {
65 for (const cricket::VideoCodec& supported_codec : supported_codecs_) { 104 for (size_t i = 0; i < supported_codecs_.size(); ++i) {
66 if (cricket::CodecNamesEq(codec.name, supported_codec.name)) { 105 if (!cricket::CodecNamesEq(codec.name, supported_codecs_[i].name))
67 webrtc::VideoCodecType type = webrtc::PayloadNameToCodecType(codec.name) 106 continue;
68 .value_or(webrtc::kVideoCodecUnknown); 107 // Check H264 profile.
69 return new RTCVideoEncoder(type, gpu_factories_); 108 using webrtc::H264::ParseSdpProfileLevelId;
109 if (cricket::CodecNamesEq(codec.name.c_str(), cricket::kH264CodecName) &&
110 ParseSdpProfileLevelId(codec.params)->profile !=
111 ParseSdpProfileLevelId(supported_codecs_[i].params)->profile) {
112 continue;
70 } 113 }
114 // There should be a 1:1 mapping between media::VideoCodecProfile and
115 // cricket::VideoCodec.
116 CHECK_EQ(profiles_.size(), supported_codecs_.size());
117 return new RTCVideoEncoder(profiles_[i], gpu_factories_);
71 } 118 }
72 return nullptr; 119 return nullptr;
73 } 120 }
74 121
75 const std::vector<cricket::VideoCodec>& 122 const std::vector<cricket::VideoCodec>&
76 RTCVideoEncoderFactory::supported_codecs() const { 123 RTCVideoEncoderFactory::supported_codecs() const {
77 return supported_codecs_; 124 return supported_codecs_;
78 } 125 }
79 126
80 void RTCVideoEncoderFactory::DestroyVideoEncoder( 127 void RTCVideoEncoderFactory::DestroyVideoEncoder(
81 webrtc::VideoEncoder* encoder) { 128 webrtc::VideoEncoder* encoder) {
82 delete encoder; 129 delete encoder;
83 } 130 }
84 131
85 } // namespace content 132 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/gpu/rtc_video_encoder_factory.h ('k') | content/renderer/media/gpu/rtc_video_encoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698