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 : number_of_cores_(0), | 22 : number_of_cores_(0), |
22 max_payload_size_(0), | 23 max_payload_size_(0), |
23 rates_set_(false), | 24 rates_set_(false), |
24 framerate_(0), | 25 framerate_(0), |
25 channel_parameters_set_(false), | 26 channel_parameters_set_(false), |
26 packet_loss_(0), | 27 packet_loss_(0), |
27 rtt_(0), | 28 rtt_(0), |
28 encoder_type_(CodecToEncoderType(codec_type)), | 29 codec_(codec), |
29 encoder_(encoder), | 30 encoder_(encoder), |
30 callback_(nullptr) {} | 31 callback_(nullptr) {} |
31 | 32 |
32 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { | 33 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { |
33 if (!VideoEncoder::IsSupportedSoftware(encoder_type_)) { | 34 cricket::WebRtcVideoEncoderFactory& internal_factory = |
| 35 cricket::InternalEncoderFactory::GetInstance(); |
| 36 if (!FindMatchingCodec(internal_factory.supported_codecs(), codec_)) { |
34 LOG(LS_WARNING) | 37 LOG(LS_WARNING) |
35 << "Encoder requesting fallback to codec not supported in software."; | 38 << "Encoder requesting fallback to codec not supported in software."; |
36 return false; | 39 return false; |
37 } | 40 } |
38 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); | 41 fallback_encoder_.reset(internal_factory.CreateVideoEncoder(codec_)); |
39 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, | 42 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, |
40 max_payload_size_) != | 43 max_payload_size_) != |
41 WEBRTC_VIDEO_CODEC_OK) { | 44 WEBRTC_VIDEO_CODEC_OK) { |
42 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; | 45 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; |
43 fallback_encoder_->Release(); | 46 fallback_encoder_->Release(); |
44 fallback_encoder_.reset(); | 47 fallback_encoder_.reset(); |
45 return false; | 48 return false; |
46 } | 49 } |
47 // Replay callback, rates, and channel parameters. | 50 // Replay callback, rates, and channel parameters. |
48 if (callback_) | 51 if (callback_) |
(...skipping 21 matching lines...) Expand all Loading... |
70 // encoder after a failed Encode call. | 73 // encoder after a failed Encode call. |
71 codec_settings_ = *codec_settings; | 74 codec_settings_ = *codec_settings; |
72 number_of_cores_ = number_of_cores; | 75 number_of_cores_ = number_of_cores; |
73 max_payload_size_ = max_payload_size; | 76 max_payload_size_ = max_payload_size; |
74 // Clear stored rate/channel parameters. | 77 // Clear stored rate/channel parameters. |
75 rates_set_ = false; | 78 rates_set_ = false; |
76 channel_parameters_set_ = false; | 79 channel_parameters_set_ = false; |
77 | 80 |
78 int32_t ret = | 81 int32_t ret = |
79 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); | 82 encoder_->InitEncode(codec_settings, number_of_cores, max_payload_size); |
80 if (ret == WEBRTC_VIDEO_CODEC_OK || encoder_type_ == kUnsupportedCodec) { | 83 if (ret == WEBRTC_VIDEO_CODEC_OK || codec_.name.empty()) { |
81 if (fallback_encoder_) | 84 if (fallback_encoder_) |
82 fallback_encoder_->Release(); | 85 fallback_encoder_->Release(); |
83 fallback_encoder_.reset(); | 86 fallback_encoder_.reset(); |
84 if (callback_) | 87 if (callback_) |
85 encoder_->RegisterEncodeCompleteCallback(callback_); | 88 encoder_->RegisterEncodeCompleteCallback(callback_); |
86 return ret; | 89 return ret; |
87 } | 90 } |
88 // Try to instantiate software codec. | 91 // Try to instantiate software codec. |
89 if (InitFallbackEncoder()) { | 92 if (InitFallbackEncoder()) { |
90 return WEBRTC_VIDEO_CODEC_OK; | 93 return WEBRTC_VIDEO_CODEC_OK; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return encoder_->OnDroppedFrame(); | 166 return encoder_->OnDroppedFrame(); |
164 } | 167 } |
165 | 168 |
166 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { | 169 bool VideoEncoderSoftwareFallbackWrapper::SupportsNativeHandle() const { |
167 if (fallback_encoder_) | 170 if (fallback_encoder_) |
168 return fallback_encoder_->SupportsNativeHandle(); | 171 return fallback_encoder_->SupportsNativeHandle(); |
169 return encoder_->SupportsNativeHandle(); | 172 return encoder_->SupportsNativeHandle(); |
170 } | 173 } |
171 | 174 |
172 } // namespace webrtc | 175 } // namespace webrtc |
OLD | NEW |