Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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_encoding_video_capturer_factory.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "content/renderer/media/rtc_encoding_video_capturer.h" | |
| 9 #include "media/base/encoded_bitstream_buffer.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 RtcEncodingVideoCapturerFactory::RtcEncodingVideoCapturerFactory() | |
| 14 : encoded_video_source_(NULL), | |
| 15 next_stream_id_(1) { | |
| 16 } | |
| 17 | |
| 18 RtcEncodingVideoCapturerFactory::~RtcEncodingVideoCapturerFactory() { | |
| 19 for (EncoderMap::iterator it = encoder_map_.begin(); it != encoder_map_.end(); | |
| 20 ++it) | |
| 21 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
| |
| 22 if (encoded_video_source_) | |
| 23 encoded_video_source_->RemoveCapabilitiesObserver(this); | |
| 24 } | |
| 25 | |
| 26 void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceAdded( | |
| 27 media::EncodedVideoSource* source) { | |
| 28 // TODO: support multiple encoded video sources. | |
| 29 // 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.
| |
| 30 if (!encoded_video_source_) { | |
| 31 encoded_video_source_ = source; | |
| 32 source->AddCapabilitiesObserver(this); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceRemoved( | |
| 37 media::EncodedVideoSource* source) { | |
| 38 if (source && encoded_video_source_ == source) { | |
| 39 source->RemoveCapabilitiesObserver(this); | |
| 40 encoded_video_source_ = NULL; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 void RtcEncodingVideoCapturerFactory::OnCapabilitiesAvailable( | |
| 45 media::EncodedVideoSource* source) { | |
| 46 if (source && encoded_video_source_ == source) | |
| 47 RebuildCodecsList(); | |
| 48 } | |
| 49 | |
| 50 webrtc::VideoEncoder* RtcEncodingVideoCapturerFactory::CreateVideoEncoder( | |
| 51 webrtc::VideoCodecType type) { | |
| 52 for (size_t i = 0; i < codecs_.size(); ++i) { | |
| 53 if (codecs_[i].type == type) { | |
| 54 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
| |
| 55 new RtcEncodingVideoCapturer(next_stream_id_, encoded_video_source_); | |
| 56 if (capturer) | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
can never fail
hshi1
2013/06/10 21:49:35
Done.
| |
| 57 encoder_map_[next_stream_id_++] = capturer; | |
| 58 return capturer; | |
| 59 } | |
| 60 } | |
| 61 return NULL; | |
| 62 } | |
| 63 | |
| 64 void RtcEncodingVideoCapturerFactory::DestroyVideoEncoder( | |
| 65 webrtc::VideoEncoder* encoder) { | |
| 66 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.
| |
| 67 ++it) { | |
| 68 if (it->second == encoder) { | |
| 69 delete encoder; | |
| 70 encoder_map_.erase(it); | |
| 71 return; | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& | |
| 77 RtcEncodingVideoCapturerFactory::codecs() const { | |
| 78 return codecs_; | |
| 79 } | |
| 80 | |
| 81 void RtcEncodingVideoCapturerFactory::RebuildCodecsList() { | |
| 82 codecs_.clear(); | |
| 83 | |
| 84 DCHECK(encoded_video_source_); | |
| 85 if (!encoded_video_source_) | |
| 86 return; | |
|
Ami GONE FROM CHROMIUM
2013/06/08 00:18:01
l.85-86 unnecessary
hshi1
2013/06/10 21:49:35
Done.
| |
| 87 | |
| 88 media::VideoEncodingCapability caps = | |
| 89 encoded_video_source_->GetCapabilities(); | |
| 90 for (size_t i = 0; i < caps.size(); ++i) { | |
| 91 webrtc::VideoCodecType webrtc_codec_type = webrtc::kVideoCodecGeneric; | |
| 92 switch (caps[i].codec_type) { | |
| 93 case media::kCodecVP8: | |
| 94 webrtc_codec_type = webrtc::kVideoCodecVP8; | |
| 95 break; | |
| 96 default: | |
| 97 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.
| |
| 98 break; | |
| 99 } | |
| 100 codecs_.push_back(WebRtcVideoEncoderFactory::VideoCodec( | |
| 101 webrtc_codec_type, | |
| 102 caps[i].codec_name, | |
| 103 caps[i].max_resolution.width(), | |
| 104 caps[i].max_resolution.height(), | |
| 105 caps[i].max_frames_per_second)); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 } // namespace content | |
| OLD | NEW |