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/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/renderer/media/rtc_encoding_video_capturer.h" |
| 10 #include "media/base/encoded_bitstream_buffer.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 RtcEncodingVideoCapturerFactory::RtcEncodingVideoCapturerFactory() |
| 15 : encoded_video_source_(NULL), |
| 16 weak_ptr_factory_(this) { |
| 17 } |
| 18 |
| 19 RtcEncodingVideoCapturerFactory::~RtcEncodingVideoCapturerFactory() { |
| 20 DCHECK(encoder_set_.empty()); |
| 21 } |
| 22 |
| 23 void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceAdded( |
| 24 media::EncodedVideoSource* source) { |
| 25 // TODO(hshi): support multiple encoded video sources. |
| 26 // For now we only support one instance of encoded video source at a time. |
| 27 DCHECK(!encoded_video_source_); |
| 28 encoded_video_source_ = source; |
| 29 source->RequestCapabilities(base::Bind( |
| 30 &RtcEncodingVideoCapturerFactory::OnCapabilitiesAvailable, |
| 31 weak_ptr_factory_.GetWeakPtr())); |
| 32 } |
| 33 |
| 34 void RtcEncodingVideoCapturerFactory::OnEncodedVideoSourceRemoved( |
| 35 media::EncodedVideoSource* source) { |
| 36 encoded_video_source_ = NULL; |
| 37 } |
| 38 |
| 39 webrtc::VideoEncoder* RtcEncodingVideoCapturerFactory::CreateVideoEncoder( |
| 40 webrtc::VideoCodecType type) { |
| 41 for (size_t i = 0; i < codecs_.size(); ++i) { |
| 42 if (codecs_[i].type == type) { |
| 43 RtcEncodingVideoCapturer* capturer = |
| 44 new RtcEncodingVideoCapturer(encoded_video_source_, type); |
| 45 encoder_set_.insert(capturer); |
| 46 return capturer; |
| 47 } |
| 48 } |
| 49 return NULL; |
| 50 } |
| 51 |
| 52 void RtcEncodingVideoCapturerFactory::DestroyVideoEncoder( |
| 53 webrtc::VideoEncoder* encoder) { |
| 54 EncoderSet::iterator it = encoder_set_.find(encoder); |
| 55 if (it != encoder_set_.end()) { |
| 56 delete encoder; |
| 57 encoder_set_.erase(it); |
| 58 } |
| 59 } |
| 60 |
| 61 const std::vector<cricket::WebRtcVideoEncoderFactory::VideoCodec>& |
| 62 RtcEncodingVideoCapturerFactory::codecs() const { |
| 63 return codecs_; |
| 64 } |
| 65 |
| 66 void RtcEncodingVideoCapturerFactory::OnCapabilitiesAvailable( |
| 67 const media::VideoEncodingCapabilities& caps) { |
| 68 codecs_.clear(); |
| 69 |
| 70 for (size_t i = 0; i < caps.size(); ++i) { |
| 71 webrtc::VideoCodecType webrtc_codec_type = webrtc::kVideoCodecGeneric; |
| 72 switch (caps[i].codec_type) { |
| 73 case media::kCodecVP8: |
| 74 webrtc_codec_type = webrtc::kVideoCodecVP8; |
| 75 break; |
| 76 default: |
| 77 break; |
| 78 } |
| 79 codecs_.push_back(cricket::WebRtcVideoEncoderFactory::VideoCodec( |
| 80 webrtc_codec_type, |
| 81 caps[i].codec_name, |
| 82 caps[i].max_resolution.width(), |
| 83 caps[i].max_resolution.height(), |
| 84 caps[i].max_frames_per_second)); |
| 85 } |
| 86 } |
| 87 |
| 88 } // namespace content |
OLD | NEW |