| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" | 11 #include "webrtc/media/engine/videoencodersoftwarefallbackwrapper.h" |
| 12 | 12 |
| 13 #include "webrtc/base/logging.h" | 13 #include "webrtc/base/logging.h" |
| 14 #include "webrtc/media/engine/internalencoderfactory.h" | |
| 15 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 16 | 15 |
| 17 namespace webrtc { | 16 namespace webrtc { |
| 18 | 17 |
| 19 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( | 18 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( |
| 20 const cricket::VideoCodec& codec, | 19 VideoCodecType codec_type, |
| 21 webrtc::VideoEncoder* encoder) | 20 webrtc::VideoEncoder* encoder) |
| 22 : number_of_cores_(0), | 21 : number_of_cores_(0), |
| 23 max_payload_size_(0), | 22 max_payload_size_(0), |
| 24 rates_set_(false), | 23 rates_set_(false), |
| 25 framerate_(0), | 24 framerate_(0), |
| 26 channel_parameters_set_(false), | 25 channel_parameters_set_(false), |
| 27 packet_loss_(0), | 26 packet_loss_(0), |
| 28 rtt_(0), | 27 rtt_(0), |
| 29 codec_(codec), | 28 encoder_type_(CodecToEncoderType(codec_type)), |
| 30 encoder_(encoder), | 29 encoder_(encoder), |
| 31 callback_(nullptr) {} | 30 callback_(nullptr) {} |
| 32 | 31 |
| 33 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { | 32 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { |
| 34 cricket::WebRtcVideoEncoderFactory& internal_factory = | 33 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { |
| 35 cricket::InternalEncoderFactory::GetInstance(); | |
| 36 if (!FindMatchingCodec(internal_factory.supported_codecs(), codec_)) { | |
| 37 LOG(LS_WARNING) | 34 LOG(LS_WARNING) |
| 38 << "Encoder requesting fallback to codec not supported in software."; | 35 << "Encoder requesting fallback to codec not supported in software."; |
| 39 return false; | 36 return false; |
| 40 } | 37 } |
| 41 fallback_encoder_.reset(internal_factory.CreateVideoEncoder(codec_)); | 38 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); |
| 42 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, | 39 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, |
| 43 max_payload_size_) != | 40 max_payload_size_) != |
| 44 WEBRTC_VIDEO_CODEC_OK) { | 41 WEBRTC_VIDEO_CODEC_OK) { |
| 45 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; | 42 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; |
| 46 fallback_encoder_->Release(); | 43 fallback_encoder_->Release(); |
| 47 fallback_encoder_.reset(); | 44 fallback_encoder_.reset(); |
| 48 return false; | 45 return false; |
| 49 } | 46 } |
| 50 // Replay callback, rates, and channel parameters. | 47 // Replay callback, rates, and channel parameters. |
| 51 if (callback_) | 48 if (callback_) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 // encoder after a failed Encode call. | 70 // encoder after a failed Encode call. |
| 74 codec_settings_ = *codec_settings; | 71 codec_settings_ = *codec_settings; |
| 75 number_of_cores_ = number_of_cores; | 72 number_of_cores_ = number_of_cores; |
| 76 max_payload_size_ = max_payload_size; | 73 max_payload_size_ = max_payload_size; |
| 77 // Clear stored rate/channel parameters. | 74 // Clear stored rate/channel parameters. |
| 78 rates_set_ = false; | 75 rates_set_ = false; |
| 79 channel_parameters_set_ = false; | 76 channel_parameters_set_ = false; |
| 80 | 77 |
| 81 int32_t ret = | 78 int32_t ret = |
| 82 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); | 79 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); |
| 83 if (ret == WEBRTC_VIDEO_CODEC_OK || codec_.name.empty()) { | 80 if (ret == WEBRTC_VIDEO_CODEC_OK || encoder_type_ == kUnsupportedCodec) { |
| 84 if (fallback_encoder_) | 81 if (fallback_encoder_) |
| 85 fallback_encoder_->Release(); | 82 fallback_encoder_->Release(); |
| 86 fallback_encoder_.reset(); | 83 fallback_encoder_.reset(); |
| 87 if (callback_) | 84 if (callback_) |
| 88 encoder_->RegisterEncodeCompleteCallback(callback_); | 85 encoder_->RegisterEncodeCompleteCallback(callback_); |
| 89 return ret; | 86 return ret; |
| 90 } | 87 } |
| 91 // Try to instantiate software codec. | 88 // Try to instantiate software codec. |
| 92 if (InitFallbackEncoder()) { | 89 if (InitFallbackEncoder()) { |
| 93 return WEBRTC_VIDEO_CODEC_OK; | 90 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return encoder_->OnDroppedFrame(); | 163 return encoder_->OnDroppedFrame(); |
| 167 } | 164 } |
| 168 | 165 |
| 169 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 166 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
| 170 if (fallback_encoder_) | 167 if (fallback_encoder_) |
| 171 return fallback_encoder_->SupportsNativeHandle(); | 168 return fallback_encoder_->SupportsNativeHandle(); |
| 172 return encoder_->SupportsNativeHandle(); | 169 return encoder_->SupportsNativeHandle(); |
| 173 } | 170 } |
| 174 | 171 |
| 175 } // namespace webrtc | 172 } // namespace webrtc |
| OLD | NEW |