Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: webrtc/video/video_encoder.cc

Issue 2263043003: Make MediaCodecEncoder fallback to a software encoder on failure. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove empty lines. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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/video_encoder.h" 11 #include "webrtc/video_encoder.h"
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" 15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
16 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" 16 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
17 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" 17 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) { 20 VideoEncoder* VideoEncoder::Create(VideoEncoder::EncoderType codec_type) {
21 RTC_DCHECK(IsSupported(codec_type));
21 switch (codec_type) { 22 switch (codec_type) {
22 case kH264: 23 case kH264:
23 RTC_DCHECK(H264Encoder::IsSupported());
24 return H264Encoder::Create(); 24 return H264Encoder::Create();
25 case kVp8: 25 case kVp8:
26 return VP8Encoder::Create(); 26 return VP8Encoder::Create();
27 case kVp9: 27 case kVp9:
28 RTC_DCHECK(VP9Encoder::IsSupported());
29 return VP9Encoder::Create(); 28 return VP9Encoder::Create();
30 case kUnsupportedCodec: 29 case kUnsupportedCodec:
31 RTC_NOTREACHED(); 30 RTC_NOTREACHED();
32 return nullptr; 31 return nullptr;
33 } 32 }
34 RTC_NOTREACHED(); 33 RTC_NOTREACHED();
35 return nullptr; 34 return nullptr;
36 } 35 }
37 36
37 bool VideoEncoder::IsSupported(EncoderType codec_type) {
38 switch (codec_type) {
39 case kH264:
40 return H264Encoder::IsSupported();
41 case kVp8:
42 return true;
43 case kVp9:
44 return VP9Encoder::IsSupported();
45 case kUnsupportedCodec:
46 RTC_NOTREACHED();
47 return false;
48 }
49 RTC_NOTREACHED();
50 return false;
51 }
52
38 VideoEncoder::EncoderType CodecToEncoderType(VideoCodecType codec_type) { 53 VideoEncoder::EncoderType CodecToEncoderType(VideoCodecType codec_type) {
39 switch (codec_type) { 54 switch (codec_type) {
40 case kVideoCodecH264: 55 case kVideoCodecH264:
41 return VideoEncoder::kH264; 56 return VideoEncoder::kH264;
42 case kVideoCodecVP8: 57 case kVideoCodecVP8:
43 return VideoEncoder::kVp8; 58 return VideoEncoder::kVp8;
44 case kVideoCodecVP9: 59 case kVideoCodecVP9:
45 return VideoEncoder::kVp9; 60 return VideoEncoder::kVp9;
46 default: 61 default:
47 return VideoEncoder::kUnsupportedCodec; 62 return VideoEncoder::kUnsupportedCodec;
48 } 63 }
49 } 64 }
50 65
51 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper( 66 VideoEncoderSoftwareFallbackWrapper::VideoEncoderSoftwareFallbackWrapper(
52 VideoCodecType codec_type, 67 VideoCodecType codec_type,
53 webrtc::VideoEncoder* encoder) 68 webrtc::VideoEncoder* encoder)
54 : rates_set_(false), 69 : rates_set_(false),
55 channel_parameters_set_(false), 70 channel_parameters_set_(false),
56 encoder_type_(CodecToEncoderType(codec_type)), 71 encoder_type_(CodecToEncoderType(codec_type)),
57 encoder_(encoder), 72 encoder_(encoder),
58 callback_(nullptr) {} 73 callback_(nullptr) {}
59 74
60 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() { 75 bool VideoEncoderSoftwareFallbackWrapper::InitFallbackEncoder() {
61 RTC_CHECK(encoder_type_ != kUnsupportedCodec) 76 if (!VideoEncoder::IsSupported(encoder_type_)) {
62 << "Encoder requesting fallback to codec not supported in software."; 77 LOG(LS_WARNING)
78 << "Encoder requesting fallback to codec not supported in software.";
79 return false;
80 }
63 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_)); 81 fallback_encoder_.reset(VideoEncoder::Create(encoder_type_));
64 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_, 82 if (fallback_encoder_->InitEncode(&codec_settings_, number_of_cores_,
65 max_payload_size_) != 83 max_payload_size_) !=
66 WEBRTC_VIDEO_CODEC_OK) { 84 WEBRTC_VIDEO_CODEC_OK) {
67 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback."; 85 LOG(LS_ERROR) << "Failed to initialize software-encoder fallback.";
68 fallback_encoder_->Release(); 86 fallback_encoder_->Release();
69 fallback_encoder_.reset(); 87 fallback_encoder_.reset();
70 return false; 88 return false;
71 } 89 }
72 // Replay callback, rates, and channel parameters. 90 // Replay callback, rates, and channel parameters.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 156
139 int32_t VideoEncoderSoftwareFallbackWrapper::Encode( 157 int32_t VideoEncoderSoftwareFallbackWrapper::Encode(
140 const VideoFrame& frame, 158 const VideoFrame& frame,
141 const CodecSpecificInfo* codec_specific_info, 159 const CodecSpecificInfo* codec_specific_info,
142 const std::vector<FrameType>* frame_types) { 160 const std::vector<FrameType>* frame_types) {
143 if (fallback_encoder_) 161 if (fallback_encoder_)
144 return fallback_encoder_->Encode(frame, codec_specific_info, frame_types); 162 return fallback_encoder_->Encode(frame, codec_specific_info, frame_types);
145 int32_t ret = encoder_->Encode(frame, codec_specific_info, frame_types); 163 int32_t ret = encoder_->Encode(frame, codec_specific_info, frame_types);
146 // If requested, try a software fallback. 164 // If requested, try a software fallback.
147 if (ret == WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE && InitFallbackEncoder()) { 165 if (ret == WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE && InitFallbackEncoder()) {
166 if (frame.video_frame_buffer()->native_handle() &&
167 !fallback_encoder_->SupportsNativeHandle()) {
168 LOG(LS_WARNING) << "Fallback encoder doesn't support native frames, "
magjed_webrtc 2016/08/23 12:09:50 So what will happen when the HW encoder fails on A
sakal 2016/08/23 12:26:51 When fallback_encoder_ is initialized, SupportsNat
magjed_webrtc 2016/08/23 14:28:08 Acknowledged.
169 << "dropping one frame.";
170 return WEBRTC_VIDEO_CODEC_ERROR;
171 }
172
148 // Fallback was successful, so start using it with this frame. 173 // Fallback was successful, so start using it with this frame.
149 return fallback_encoder_->Encode(frame, codec_specific_info, frame_types); 174 return fallback_encoder_->Encode(frame, codec_specific_info, frame_types);
150 } 175 }
151 return ret; 176 return ret;
152 } 177 }
153 178
154 int32_t VideoEncoderSoftwareFallbackWrapper::SetChannelParameters( 179 int32_t VideoEncoderSoftwareFallbackWrapper::SetChannelParameters(
155 uint32_t packet_loss, 180 uint32_t packet_loss,
156 int64_t rtt) { 181 int64_t rtt) {
157 channel_parameters_set_ = true; 182 channel_parameters_set_ = true;
(...skipping 28 matching lines...) Expand all
186 return encoder_->SupportsNativeHandle(); 211 return encoder_->SupportsNativeHandle();
187 } 212 }
188 213
189 const char* VideoEncoderSoftwareFallbackWrapper::ImplementationName() const { 214 const char* VideoEncoderSoftwareFallbackWrapper::ImplementationName() const {
190 if (fallback_encoder_) 215 if (fallback_encoder_)
191 return fallback_implementation_name_.c_str(); 216 return fallback_implementation_name_.c_str();
192 return encoder_->ImplementationName(); 217 return encoder_->ImplementationName();
193 } 218 }
194 219
195 } // namespace webrtc 220 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698