OLD | NEW |
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 |
(...skipping 25 matching lines...) Expand all Loading... |
36 RTC_DCHECK(VP9Decoder::IsSupported()); | 36 RTC_DCHECK(VP9Decoder::IsSupported()); |
37 return VP9Decoder::Create(); | 37 return VP9Decoder::Create(); |
38 case kUnsupportedCodec: | 38 case kUnsupportedCodec: |
39 LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; | 39 LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; |
40 return new NullVideoDecoder(); | 40 return new NullVideoDecoder(); |
41 } | 41 } |
42 RTC_NOTREACHED(); | 42 RTC_NOTREACHED(); |
43 return nullptr; | 43 return nullptr; |
44 } | 44 } |
45 | 45 |
46 VideoDecoder::DecoderType CodecTypeToDecoderType(VideoCodecType codec_type) { | |
47 switch (codec_type) { | |
48 case kVideoCodecH264: | |
49 return VideoDecoder::kH264; | |
50 case kVideoCodecVP8: | |
51 return VideoDecoder::kVp8; | |
52 case kVideoCodecVP9: | |
53 return VideoDecoder::kVp9; | |
54 default: | |
55 return VideoDecoder::kUnsupportedCodec; | |
56 } | |
57 } | |
58 | |
59 VideoDecoderSoftwareFallbackWrapper::VideoDecoderSoftwareFallbackWrapper( | |
60 VideoCodecType codec_type, | |
61 VideoDecoder* decoder) | |
62 : decoder_type_(CodecTypeToDecoderType(codec_type)), | |
63 decoder_(decoder), | |
64 callback_(nullptr) { | |
65 } | |
66 | |
67 int32_t VideoDecoderSoftwareFallbackWrapper::InitDecode( | |
68 const VideoCodec* codec_settings, | |
69 int32_t number_of_cores) { | |
70 codec_settings_ = *codec_settings; | |
71 number_of_cores_ = number_of_cores; | |
72 return decoder_->InitDecode(codec_settings, number_of_cores); | |
73 } | |
74 | |
75 bool VideoDecoderSoftwareFallbackWrapper::InitFallbackDecoder() { | |
76 RTC_CHECK(decoder_type_ != kUnsupportedCodec) | |
77 << "Decoder requesting fallback to codec not supported in software."; | |
78 LOG(LS_WARNING) << "Decoder falling back to software decoding."; | |
79 fallback_decoder_.reset(VideoDecoder::Create(decoder_type_)); | |
80 if (fallback_decoder_->InitDecode(&codec_settings_, number_of_cores_) != | |
81 WEBRTC_VIDEO_CODEC_OK) { | |
82 LOG(LS_ERROR) << "Failed to initialize software-decoder fallback."; | |
83 fallback_decoder_.reset(); | |
84 return false; | |
85 } | |
86 if (callback_) | |
87 fallback_decoder_->RegisterDecodeCompleteCallback(callback_); | |
88 fallback_implementation_name_ = | |
89 std::string(fallback_decoder_->ImplementationName()) + | |
90 " (fallback from: " + decoder_->ImplementationName() + ")"; | |
91 return true; | |
92 } | |
93 | |
94 int32_t VideoDecoderSoftwareFallbackWrapper::Decode( | |
95 const EncodedImage& input_image, | |
96 bool missing_frames, | |
97 const RTPFragmentationHeader* fragmentation, | |
98 const CodecSpecificInfo* codec_specific_info, | |
99 int64_t render_time_ms) { | |
100 // Try decoding with the provided decoder on every keyframe or when there's no | |
101 // fallback decoder. This is the normal case. | |
102 if (!fallback_decoder_ || input_image._frameType == kVideoFrameKey) { | |
103 int32_t ret = decoder_->Decode(input_image, missing_frames, fragmentation, | |
104 codec_specific_info, render_time_ms); | |
105 if (ret == WEBRTC_VIDEO_CODEC_OK) { | |
106 if (fallback_decoder_) { | |
107 // Decode OK -> stop using fallback decoder. | |
108 fallback_decoder_->Release(); | |
109 fallback_decoder_.reset(); | |
110 return WEBRTC_VIDEO_CODEC_OK; | |
111 } | |
112 } | |
113 if (ret != WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE) | |
114 return ret; | |
115 if (!fallback_decoder_) { | |
116 // Try to initialize fallback decoder. | |
117 if (!InitFallbackDecoder()) | |
118 return ret; | |
119 } | |
120 } | |
121 return fallback_decoder_->Decode(input_image, missing_frames, fragmentation, | |
122 codec_specific_info, render_time_ms); | |
123 } | |
124 | |
125 int32_t VideoDecoderSoftwareFallbackWrapper::RegisterDecodeCompleteCallback( | |
126 DecodedImageCallback* callback) { | |
127 callback_ = callback; | |
128 int32_t ret = decoder_->RegisterDecodeCompleteCallback(callback); | |
129 if (fallback_decoder_) | |
130 return fallback_decoder_->RegisterDecodeCompleteCallback(callback); | |
131 return ret; | |
132 } | |
133 | |
134 int32_t VideoDecoderSoftwareFallbackWrapper::Release() { | |
135 if (fallback_decoder_) | |
136 fallback_decoder_->Release(); | |
137 return decoder_->Release(); | |
138 } | |
139 | |
140 bool VideoDecoderSoftwareFallbackWrapper::PrefersLateDecoding() const { | |
141 if (fallback_decoder_) | |
142 return fallback_decoder_->PrefersLateDecoding(); | |
143 return decoder_->PrefersLateDecoding(); | |
144 } | |
145 | |
146 const char* VideoDecoderSoftwareFallbackWrapper::ImplementationName() const { | |
147 if (fallback_decoder_) | |
148 return fallback_implementation_name_.c_str(); | |
149 return decoder_->ImplementationName(); | |
150 } | |
151 | |
152 NullVideoDecoder::NullVideoDecoder() {} | 46 NullVideoDecoder::NullVideoDecoder() {} |
153 | 47 |
154 int32_t NullVideoDecoder::InitDecode(const VideoCodec* codec_settings, | 48 int32_t NullVideoDecoder::InitDecode(const VideoCodec* codec_settings, |
155 int32_t number_of_cores) { | 49 int32_t number_of_cores) { |
156 LOG(LS_ERROR) << "Can't initialize NullVideoDecoder."; | 50 LOG(LS_ERROR) << "Can't initialize NullVideoDecoder."; |
157 return WEBRTC_VIDEO_CODEC_OK; | 51 return WEBRTC_VIDEO_CODEC_OK; |
158 } | 52 } |
159 | 53 |
160 int32_t NullVideoDecoder::Decode(const EncodedImage& input_image, | 54 int32_t NullVideoDecoder::Decode(const EncodedImage& input_image, |
161 bool missing_frames, | 55 bool missing_frames, |
(...skipping 13 matching lines...) Expand all Loading... |
175 | 69 |
176 int32_t NullVideoDecoder::Release() { | 70 int32_t NullVideoDecoder::Release() { |
177 return WEBRTC_VIDEO_CODEC_OK; | 71 return WEBRTC_VIDEO_CODEC_OK; |
178 } | 72 } |
179 | 73 |
180 const char* NullVideoDecoder::ImplementationName() const { | 74 const char* NullVideoDecoder::ImplementationName() const { |
181 return "NullVideoDecoder"; | 75 return "NullVideoDecoder"; |
182 } | 76 } |
183 | 77 |
184 } // namespace webrtc | 78 } // namespace webrtc |
OLD | NEW |