Index: content/renderer/media/rtc_video_encoder_factory.cc |
diff --git a/content/renderer/media/rtc_video_encoder_factory.cc b/content/renderer/media/rtc_video_encoder_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73b48b313a4d89567dd16a2854048ad7812b9ef7 |
--- /dev/null |
+++ b/content/renderer/media/rtc_video_encoder_factory.cc |
@@ -0,0 +1,110 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/media/rtc_video_encoder_factory.h" |
+ |
+#include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
+#include "content/renderer/media/rtc_video_encoder.h" |
+#include "media/filters/gpu_video_accelerator_factories.h" |
+#include "media/video/video_encode_accelerator.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+// Translate from media::VideoEncodeAccelerator::SupportedProfile to |
+// cricket::WebRtcVideoEncoderFactory::VideoCodec |
+cricket::WebRtcVideoEncoderFactory::VideoCodec GVEAToWebRTCCodec( |
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
s/GVEA/VEA/
sheu
2013/08/02 01:27:49
Done.
|
+ const media::VideoEncodeAccelerator::SupportedProfile& profile) { |
+ webrtc::VideoCodecType type = webrtc::kVideoCodecUnknown; |
+ std::string name; |
+ int width = 0, height = 0, fps = 0; |
+ |
+ if (profile.profile >= media::VP8PROFILE_MIN && |
+ profile.profile <= media::VP8PROFILE_MAX) { |
+ type = webrtc::kVideoCodecVP8; |
+ name = std::string("VP8"); |
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
here and elsewhere, the explicit std::string() is
sheu
2013/08/02 01:27:49
Done.
|
+ } else if (profile.profile >= media::H264PROFILE_MIN && |
+ profile.profile <= media::H264PROFILE_MAX) { |
+ type = webrtc::kVideoCodecGeneric; |
+ name = std::string("CAST1"); |
+ } |
+ |
+ if (type != webrtc::kVideoCodecUnknown) { |
+ width = profile.max_resolution.width(); |
+ height = profile.max_resolution.height(); |
+ DCHECK_EQ(profile.max_framerate.denominator, 1U); |
+ fps = profile.max_framerate.numerator; |
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
DCHECK_EQ(denominator, 1);
or handle the division.
sheu
2013/08/02 01:27:49
The DCHECK is above, maybe not where you'd expect.
|
+ } |
+ |
+ return cricket::WebRtcVideoEncoderFactory::VideoCodec( |
+ type, name, width, height, fps); |
+} |
+ |
+// Translate from cricket::WebRtcVideoEncoderFactory::VideoCodec to |
+// media::VideoCodecProfile. Pick a default profile for each codec type. |
+media::VideoCodecProfile WebRTCCodecToVideoCodecProfile( |
+ webrtc::VideoCodecType type) { |
+ switch (type) { |
+ case webrtc::kVideoCodecVP8: |
+ return media::VP8PROFILE_MAIN; |
+ case webrtc::kVideoCodecGeneric: |
+ return media::H264PROFILE_MAIN; |
+ default: |
+ return media::VIDEO_CODEC_PROFILE_UNKNOWN; |
+ } |
+} |
+ |
+} // anonymous namespace |
+ |
+RTCVideoEncoderFactory::RTCVideoEncoderFactory( |
+ const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories) |
+ : gpu_factories_(gpu_factories) { |
+ // Query media::VideoEncodeAccelerator (statically) for our supported codecs. |
+ std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
+ GpuVideoEncodeAcceleratorHost::GetSupportedProfiles(); |
+ for (size_t i = 0; i < profiles.size(); ++i) { |
+ VideoCodec codec = GVEAToWebRTCCodec(profiles[i]); |
+ if (codec.type != webrtc::kVideoCodecUnknown) |
+ codecs_.push_back(codec); |
+ } |
+} |
+ |
+RTCVideoEncoderFactory::~RTCVideoEncoderFactory() {} |
+ |
+webrtc::VideoEncoder* RTCVideoEncoderFactory::CreateVideoEncoder( |
+ webrtc::VideoCodecType type) { |
+ bool found = false; |
+ for (size_t i = 0; i < codecs_.size(); ++i) { |
+ if (codecs_[i].type == type) { |
+ found = true; |
+ break; |
+ } |
+ } |
+ if (!found) |
+ return NULL; |
+ // GpuVideoAcceleratorFactories is not thread safe. It cannot be shared |
+ // by different decoders. Since we aren't running on the child thread and |
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
s/decoders/encoders/
sheu
2013/08/02 01:27:49
Done.
|
+ // cannot create a new factory, clone one instead. |
+ return new RTCVideoEncoder(WebRTCCodecToVideoCodecProfile(type), |
+ gpu_factories_->Clone()); |
+} |
+ |
+void RTCVideoEncoderFactory::AddObserver(Observer* observer) { |
+ // No-op: our codec list is populated on installation. |
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
Yeah, I doubt this is going to fly...
sheu
2013/08/02 01:27:49
It does quite nicely.
According to the interface
|
+} |
+ |
+void RTCVideoEncoderFactory::RemoveObserver(Observer* observer) {} |
+ |
+const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& |
+RTCVideoEncoderFactory::codecs() const { |
+ return codecs_; |
+} |
+ |
+void RTCVideoEncoderFactory::DestroyVideoEncoder( |
+ webrtc::VideoEncoder* encoder) { |
+ delete encoder; |
+} |
+ |
+} // namespace content |