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