OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/media/rtc_video_encoder_factory.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "content/public/common/content_switches.h" | |
9 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | |
10 #include "content/renderer/media/rtc_video_encoder.h" | |
11 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" | |
12 #include "media/renderers/gpu_video_accelerator_factories.h" | |
13 #include "media/video/video_encode_accelerator.h" | |
14 | |
15 namespace content { | |
16 | |
17 namespace { | |
18 | |
19 // Translate from media::VideoEncodeAccelerator::SupportedProfile to | |
20 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec | |
21 void VEAToWebRTCCodecs( | |
22 std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>* codecs, | |
23 const media::VideoEncodeAccelerator::SupportedProfile& profile) { | |
24 const int width = profile.max_resolution.width(); | |
25 const int height = profile.max_resolution.height(); | |
26 const int fps = profile.max_framerate_numerator; | |
27 DCHECK_EQ(profile.max_framerate_denominator, 1U); | |
28 | |
29 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
30 if (profile.profile >= media::VP8PROFILE_MIN && | |
31 profile.profile <= media::VP8PROFILE_MAX) { | |
32 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | |
33 webrtc::kVideoCodecVP8, "VP8", width, height, fps)); | |
34 } else if (profile.profile >= media::H264PROFILE_MIN && | |
35 profile.profile <= media::H264PROFILE_MAX) { | |
36 bool webrtc_h264_enabled = false; | |
37 #if BUILDFLAG(RTC_USE_H264) && defined(OS_MACOSX) | |
38 webrtc_h264_enabled = | |
39 base::FeatureList::IsEnabled(kWebRtcH264WithOpenH264FFmpeg); | |
40 #endif // BUILDFLAG(RTC_USE_H264) && defined(OS_MACOSX) | |
41 if (cmd_line->HasSwitch(switches::kEnableWebRtcHWH264Encoding) || | |
42 webrtc_h264_enabled) { | |
43 codecs->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( | |
44 webrtc::kVideoCodecH264, "H264", width, height, fps)); | |
45 } | |
46 } | |
47 } | |
48 | |
49 } // anonymous namespace | |
50 | |
51 RTCVideoEncoderFactory::RTCVideoEncoderFactory( | |
52 media::GpuVideoAcceleratorFactories* gpu_factories) | |
53 : gpu_factories_(gpu_factories) { | |
54 const media::VideoEncodeAccelerator::SupportedProfiles& profiles = | |
55 gpu_factories_->GetVideoEncodeAcceleratorSupportedProfiles(); | |
56 for (const auto& profile : profiles) | |
57 VEAToWebRTCCodecs(&codecs_, profile); | |
58 } | |
59 | |
60 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} | |
61 | |
62 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( | |
63 webrtc::VideoCodecType type) { | |
64 for (const auto& codec : codecs_) { | |
65 if (codec.type == type) | |
66 return new RTCVideoEncoder(type, gpu_factories_); | |
67 } | |
68 return nullptr; | |
69 } | |
70 | |
71 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& | |
72 RTCVideoEncoderFactory::codecs() const { | |
73 return codecs_; | |
74 } | |
75 | |
76 void RTCVideoEncoderFactory::DestroyVideoEncoder( | |
77 webrtc::VideoEncoder* encoder) { | |
78 delete encoder; | |
79 } | |
80 | |
81 } // namespace content | |
OLD | NEW |