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

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

Issue 20632002: Add media::VideoEncodeAccelerator with WebRTC integration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 4cd5068c WIP - almost done, just comments (and debugging prints) left Created 7 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
(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 "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"
11
12 namespace content {
13
14 namespace {
15
16 // Translate from media::VideoEncodeAccelerator::SupportedProfile to
17 // cricket::WebRtcVideoEncoderFactory::VideoCodec
18 cricket::WebRtcVideoEncoderFactory::VideoCodec GVEAToWebRTCCodec(
19 const media::VideoEncodeAccelerator::SupportedProfile& profile) {
20 webrtc::VideoCodecType type = webrtc::kVideoCodecUnknown;
21 std::string name;
22 int width = 0, height = 0, fps = 0;
23
24 if (profile.profile >= media::VP8PROFILE_MIN &&
25 profile.profile <= media::VP8PROFILE_MAX) {
26 type = webrtc::kVideoCodecVP8;
27 name = std::string("VP8");
28 }
29
30 if (type != webrtc::kVideoCodecUnknown) {
31 width = profile.max_resolution.width();
32 height = profile.max_resolution.height();
33 DCHECK_EQ(profile.max_framerate.denominator, 1U);
34 fps = profile.max_framerate.numerator;
35 }
36
37 return cricket::WebRtcVideoEncoderFactory::VideoCodec(
38 type, name, width, height, fps);
39 }
40
41 // Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to
42 // media::VideoCodecProfile. Pick a default profile for each codec type.
43 media::VideoCodecProfile WebRTCCodecToVideoCodecProfile(
44 webrtc::VideoCodecType type) {
45 switch (type) {
46 case webrtc::kVideoCodecVP8:
47 return media::VP8PROFILE_MAIN;
48 default:
49 return media::VIDEO_CODEC_PROFILE_UNKNOWN;
50 }
51 }
52
53 } // anonymous namespace
54
55 RTCVideoEncoderFactory::RTCVideoEncoderFactory(
56 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories)
57 : gpu_factories_(gpu_factories) {
58 // Query media::VideoEncodeAccelerator (statically) for our supported codecs.
59 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles =
60 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles();
61 for (size_t i = 0; i < profiles.size(); ++i) {
62 VideoCodec codec = GVEAToWebRTCCodec(profiles[i]);
63 if (codec.type != webrtc::kVideoCodecUnknown)
64 codecs_.push_back(codec);
65 }
66 }
67
68 RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {}
69
70 webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder(
71 webrtc::VideoCodecType type) {
72 bool found = false;
73 for (size_t i = 0; i < codecs_.size(); ++i) {
74 if (codecs_[i].type == type) {
75 found = true;
76 break;
77 }
78 }
79 if (!found)
80 return NULL;
81 // GpuVideoAcceleratorFactories is not thread safe. It cannot be shared
82 // by different decoders. Since we aren't running on the child thread and
83 // cannot create a new factory, clone one instead.
84 return new RTCVideoEncoder(WebRTCCodecToVideoCodecProfile(type),
85 gpu_factories_->Clone());
86 }
87
88 void RTCVideoEncoderFactory::AddObserver(Observer* observer) {
89 // No-op: our codec list is populated on installation.
90 }
91
92 void RTCVideoEncoderFactory::RemoveObserver(Observer* observer) {}
93
94 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>&
95 RTCVideoEncoderFactory::codecs() const {
96 return codecs_;
97 }
98
99 void RTCVideoEncoderFactory::DestroyVideoEncoder(
100 webrtc::VideoEncoder* encoder) {
101 delete encoder;
102 }
103
104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698