Index: content/renderer/media/rtc_encoding_video_capturer_factory.cc |
diff --git a/content/renderer/media/rtc_encoding_video_capturer_factory.cc b/content/renderer/media/rtc_encoding_video_capturer_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed28ff06c62068c9ec0a8d91c7f040ab641e79e6 |
--- /dev/null |
+++ b/content/renderer/media/rtc_encoding_video_capturer_factory.cc |
@@ -0,0 +1,109 @@ |
+// Copyright (c) 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_encoding_video_capturer_factory.h" |
+ |
+#include "base/logging.h" |
+#include "content/renderer/media/rtc_encoding_video_capturer.h" |
+#include "media/base/encoded_bitstream_buffer.h" |
+ |
+namespace content { |
+ |
+RtcEncodingVideoCapturerFactory::RtcEncodingVideoCapturerFactory() |
+ : encoded_video_source_(NULL), |
+ next_stream_id_(1) { |
+} |
+ |
+RtcEncodingVideoCapturerFactory::~RtcEncodingVideoCapturerFactory() { |
+ for (EncoderMap::iterator it = encoder_map_.begin(); it != encoder_map_.end(); |
+ ++it) |
+ delete it->second; |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
STLDeleteValues(&encoder_map_);
hshi1
2013/06/10 21:49:35
Thanks for the suggestion, done (although I'm usin
|
+ if (encoded_video_source_) |
+ encoded_video_source_->RemoveCapabilitiesObserver(this); |
+} |
+ |
+void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceAdded( |
+ media::EncodedVideoSource* source) { |
+ // TODO: support multiple encoded video sources. |
+ // For now we only support one instance of encoded video source at a time. |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
This doesn't seem super-legit, since the caller wo
hshi1
2013/06/10 21:49:35
Done.
|
+ if (!encoded_video_source_) { |
+ encoded_video_source_ = source; |
+ source->AddCapabilitiesObserver(this); |
+ } |
+} |
+ |
+void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceRemoved( |
+ media::EncodedVideoSource* source) { |
+ if (source && encoded_video_source_ == source) { |
+ source->RemoveCapabilitiesObserver(this); |
+ encoded_video_source_ = NULL; |
+ } |
+} |
+ |
+void RtcEncodingVideoCapturerFactory::OnCapabilitiesAvailable( |
+ media::EncodedVideoSource* source) { |
+ if (source && encoded_video_source_ == source) |
+ RebuildCodecsList(); |
+} |
+ |
+webrtc::VideoEncoder* RtcEncodingVideoCapturerFactory::CreateVideoEncoder( |
+ webrtc::VideoCodecType type) { |
+ for (size_t i = 0; i < codecs_.size(); ++i) { |
+ if (codecs_[i].type == type) { |
+ RtcEncodingVideoCapturer* capturer = |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
neither |type| nor |i| are used in l.54-58; suspic
hshi1
2013/06/10 21:49:35
Oops. I should pass the type to the ctor of the en
|
+ new RtcEncodingVideoCapturer(next_stream_id_, encoded_video_source_); |
+ if (capturer) |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
can never fail
hshi1
2013/06/10 21:49:35
Done.
|
+ encoder_map_[next_stream_id_++] = capturer; |
+ return capturer; |
+ } |
+ } |
+ return NULL; |
+} |
+ |
+void RtcEncodingVideoCapturerFactory::DestroyVideoEncoder( |
+ webrtc::VideoEncoder* encoder) { |
+ for (EncoderMap::iterator it = encoder_map_.begin(); it != encoder_map_.end(); |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
lol it's a map but you never use it as such.
typed
hshi1
2013/06/10 21:49:35
Done.
|
+ ++it) { |
+ if (it->second == encoder) { |
+ delete encoder; |
+ encoder_map_.erase(it); |
+ return; |
+ } |
+ } |
+} |
+ |
+const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& |
+RtcEncodingVideoCapturerFactory::codecs() const { |
+ return codecs_; |
+} |
+ |
+void RtcEncodingVideoCapturerFactory::RebuildCodecsList() { |
+ codecs_.clear(); |
+ |
+ DCHECK(encoded_video_source_); |
+ if (!encoded_video_source_) |
+ return; |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
l.85-86 unnecessary
hshi1
2013/06/10 21:49:35
Done.
|
+ |
+ media::VideoEncodingCapability caps = |
+ encoded_video_source_->GetCapabilities(); |
+ for (size_t i = 0; i < caps.size(); ++i) { |
+ webrtc::VideoCodecType webrtc_codec_type = webrtc::kVideoCodecGeneric; |
+ switch (caps[i].codec_type) { |
+ case media::kCodecVP8: |
+ webrtc_codec_type = webrtc::kVideoCodecVP8; |
+ break; |
+ default: |
+ webrtc_codec_type = webrtc::kVideoCodecGeneric; |
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
unnecessary given l.91
hshi1
2013/06/10 21:49:35
Done.
|
+ break; |
+ } |
+ codecs_.push_back(WebRtcVideoEncoderFactory::VideoCodec( |
+ webrtc_codec_type, |
+ caps[i].codec_name, |
+ caps[i].max_resolution.width(), |
+ caps[i].max_resolution.height(), |
+ caps[i].max_frames_per_second)); |
+ } |
+} |
+ |
+} // namespace content |