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.
5 #include "content/renderer/media/rtc_video_encoder_factory.h"
7 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h"
8 #include "content/renderer/media/rtc_video_encoder.h"
9 #include "media/filters/gpu_video_accelerator_factories.h"
10 #include "media/video/video_encode_accelerator.h"
16 // Translate from media::VideoEncodeAccelerator::SupportedProfile to
17 // one or more instances of cricket::WebRtcVideoEncoderFactory::VideoCodec
18 void VEAToWebRTCCodecs(
19 std::vector
<cricket::WebRtcVideoEncoderFactory::VideoCodec
>* codecs
,
20 const media::VideoEncodeAccelerator::SupportedProfile
& profile
) {
21 int width
= profile
.max_resolution
.width();
22 int height
= profile
.max_resolution
.height();
23 int fps
= profile
.max_framerate
.numerator
;
24 DCHECK_EQ(profile
.max_framerate
.denominator
, 1U);
26 if (profile
.profile
>= media::VP8PROFILE_MIN
&&
27 profile
.profile
<= media::VP8PROFILE_MAX
) {
28 codecs
->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec(
29 webrtc::kVideoCodecVP8
, "VP8", width
, height
, fps
));
30 } else if (profile
.profile
>= media::H264PROFILE_MIN
&&
31 profile
.profile
<= media::H264PROFILE_MAX
) {
32 codecs
->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec(
33 webrtc::kVideoCodecGeneric
, "CAST1", width
, height
, fps
));
34 codecs
->push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec(
35 webrtc::kVideoCodecH264
, "H264", width
, height
, fps
));
39 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to
40 // media::VideoCodecProfile. Pick a default profile for each codec type.
41 media::VideoCodecProfile
WebRTCCodecToVideoCodecProfile(
42 webrtc::VideoCodecType type
) {
44 case webrtc::kVideoCodecVP8
:
45 return media::VP8PROFILE_ANY
;
46 case webrtc::kVideoCodecH264
:
47 case webrtc::kVideoCodecGeneric
:
48 return media::H264PROFILE_MAIN
;
50 return media::VIDEO_CODEC_PROFILE_UNKNOWN
;
54 } // anonymous namespace
56 RTCVideoEncoderFactory::RTCVideoEncoderFactory(
57 const scoped_refptr
<media::GpuVideoAcceleratorFactories
>& gpu_factories
)
58 : gpu_factories_(gpu_factories
) {
59 // Query media::VideoEncodeAccelerator (statically) for our supported codecs.
60 std::vector
<media::VideoEncodeAccelerator::SupportedProfile
> profiles
=
61 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles();
62 for (size_t i
= 0; i
< profiles
.size(); ++i
)
63 VEAToWebRTCCodecs(&codecs_
, profiles
[i
]);
66 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {}
68 webrtc::VideoEncoder
* RTCVideoEncoderFactory::CreateVideoEncoder(
69 webrtc::VideoCodecType type
) {
71 for (size_t i
= 0; i
< codecs_
.size(); ++i
) {
72 if (codecs_
[i
].type
== type
) {
79 return new RTCVideoEncoder(
80 type
, WebRTCCodecToVideoCodecProfile(type
), gpu_factories_
);
83 void RTCVideoEncoderFactory::AddObserver(Observer
* observer
) {
84 // No-op: our codec list is populated on installation.
87 void RTCVideoEncoderFactory::RemoveObserver(Observer
* observer
) {}
89 const std::vector
<cricket::WebRtcVideoEncoderFactory::VideoCodec
>&
90 RTCVideoEncoderFactory::codecs() const {
94 void RTCVideoEncoderFactory::DestroyVideoEncoder(
95 webrtc::VideoEncoder
* encoder
) {
99 } // namespace content