Roll ANGLE bc75f36:ef9d63e
[chromium-blink-merge.git] / content / renderer / media / rtc_video_encoder_factory.cc
blobb21792204877947f0ac89cbb01098781239c62e9
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"
12 namespace content {
14 namespace {
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) {
43 switch (type) {
44 case webrtc::kVideoCodecVP8:
45 return media::VP8PROFILE_ANY;
46 case webrtc::kVideoCodecH264:
47 case webrtc::kVideoCodecGeneric:
48 return media::H264PROFILE_MAIN;
49 default:
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) {
70 bool found = false;
71 for (size_t i = 0; i < codecs_.size(); ++i) {
72 if (codecs_[i].type == type) {
73 found = true;
74 break;
77 if (!found)
78 return NULL;
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 {
91 return codecs_;
94 void RTCVideoEncoderFactory::DestroyVideoEncoder(
95 webrtc::VideoEncoder* encoder) {
96 delete encoder;
99 } // namespace content