| 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" |
| 14 #include "webrtc/modules/video_coding/include/video_error_codes.h" | 15 #include "webrtc/modules/video_coding/include/video_error_codes.h" |
| 15 | 16 |
| 16 namespace webrtc { | 17 namespace webrtc { |
| 17 | 18 |
| 18 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( | 19 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( |
| 19 VideoCodecType codec_type, | 20 const cricket::VideoCodec& codec, |
| 20 webrtc::VideoEncoder* encoder) | 21 webrtc::VideoEncoder* encoder) |
| 21 : rates_set_(false), | 22 : rates_set_(false), |
| 22 channel_parameters_set_(false), | 23 channel_parameters_set_(false), |
| 23 encoder_type_(CodecToEncoderType(codec_type)), | 24 codec_(codec), |
| 24 encoder_(encoder), | 25 encoder_(encoder), |
| 25 callback_(nullptr) {} | 26 callback_(nullptr) {} |
| 26 | 27 |
| 27 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { | 28 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { |
| 28 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { | 29 cricket::WebRtcVideoEncoderFactory& internal_factory = |
| 30 cricket::InternalEncoderFactory::GetInstance(); |
| 31 if (!FindMatchingCodec(internal_factory.supported_codecs(), codec_)) { |
| 29 LOG(LS_WARNING) | 32 LOG(LS_WARNING) |
| 30 << "Encoder requesting fallback to codec not supported in software."; | 33 << "Encoder requesting fallback to codec not supported in software."; |
| 31 return false; | 34 return false; |
| 32 } | 35 } |
| 33 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); | 36 fallback_encoder_.reset(internal_factory.CreateVideoEncoder(codec_)); |
| 34 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, | 37 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, |
| 35 max_payload_size_) != | 38 max_payload_size_) != |
| 36 WEBRTC_VIDEO_CODEC_OK) { | 39 WEBRTC_VIDEO_CODEC_OK) { |
| 37 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; | 40 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; |
| 38 fallback_encoder_->Release(); | 41 fallback_encoder_->Release(); |
| 39 fallback_encoder_.reset(); | 42 fallback_encoder_.reset(); |
| 40 return false; | 43 return false; |
| 41 } | 44 } |
| 42 // Replay callback, rates, and channel parameters. | 45 // Replay callback, rates, and channel parameters. |
| 43 if (callback_) | 46 if (callback_) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 // encoder after a failed Encode call. | 68 // encoder after a failed Encode call. |
| 66 codec_settings_ = *codec_settings; | 69 codec_settings_ = *codec_settings; |
| 67 number_of_cores_ = number_of_cores; | 70 number_of_cores_ = number_of_cores; |
| 68 max_payload_size_ = max_payload_size; | 71 max_payload_size_ = max_payload_size; |
| 69 // Clear stored rate/channel parameters. | 72 // Clear stored rate/channel parameters. |
| 70 rates_set_ = false; | 73 rates_set_ = false; |
| 71 channel_parameters_set_ = false; | 74 channel_parameters_set_ = false; |
| 72 | 75 |
| 73 int32_t ret = | 76 int32_t ret = |
| 74 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); | 77 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); |
| 75 if (ret == WEBRTC_VIDEO_CODEC_OK || encoder_type_ == kUnsupportedCodec) { | 78 if (ret == WEBRTC_VIDEO_CODEC_OK || codec_.name.empty()) { |
| 76 if (fallback_encoder_) | 79 if (fallback_encoder_) |
| 77 fallback_encoder_->Release(); | 80 fallback_encoder_->Release(); |
| 78 fallback_encoder_.reset(); | 81 fallback_encoder_.reset(); |
| 79 if (callback_) | 82 if (callback_) |
| 80 encoder_->RegisterEncodeCompleteCallback(callback_); | 83 encoder_->RegisterEncodeCompleteCallback(callback_); |
| 81 return ret; | 84 return ret; |
| 82 } | 85 } |
| 83 // Try to instantiate software codec. | 86 // Try to instantiate software codec. |
| 84 if (InitFallbackEncoder()) { | 87 if (InitFallbackEncoder()) { |
| 85 return WEBRTC_VIDEO_CODEC_OK; | 88 return WEBRTC_VIDEO_CODEC_OK; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return encoder_->OnDroppedFrame(); | 160 return encoder_->OnDroppedFrame(); |
| 158 } | 161 } |
| 159 | 162 |
| 160 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 163 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
| 161 if (fallback_encoder_) | 164 if (fallback_encoder_) |
| 162 return fallback_encoder_->SupportsNativeHandle(); | 165 return fallback_encoder_->SupportsNativeHandle(); |
| 163 return encoder_->SupportsNativeHandle(); | 166 return encoder_->SupportsNativeHandle(); |
| 164 } | 167 } |
| 165 | 168 |
| 166 } // namespace webrtc | 169 } // namespace webrtc |
| OLD | NEW |