magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/engine/internaldecoderfactory.h" |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 12 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 13 | #include <utility> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "modules/video_coding/codecs/h264/include/h264.h" |
| 16 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
| 17 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
| 18 | #include "rtc_base/logging.h" |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 19 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 20 | namespace cricket { |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 21 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 22 | namespace { |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 23 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 24 | // Video decoder class to be used for unknown codecs. Doesn't support decoding |
| 25 | // but logs messages to LS_ERROR. |
| 26 | class NullVideoDecoder : public webrtc::VideoDecoder { |
| 27 | public: |
| 28 | int32_t InitDecode(const webrtc::VideoCodec* codec_settings, |
| 29 | int32_t number_of_cores) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 30 | RTC_LOG(LS_ERROR) << "Can't initialize NullVideoDecoder."; |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 31 | return WEBRTC_VIDEO_CODEC_OK; |
Magnus Jedvert | b2fc9b1 | 2017-11-06 17:41:54 +0100 | [diff] [blame] | 32 | } |
| 33 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 34 | int32_t Decode(const webrtc::EncodedImage& input_image, |
| 35 | bool missing_frames, |
| 36 | const webrtc::RTPFragmentationHeader* fragmentation, |
| 37 | const webrtc::CodecSpecificInfo* codec_specific_info, |
| 38 | int64_t render_time_ms) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 39 | RTC_LOG(LS_ERROR) << "The NullVideoDecoder doesn't support decoding."; |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 40 | return WEBRTC_VIDEO_CODEC_OK; |
| 41 | } |
Magnus Jedvert | b2fc9b1 | 2017-11-06 17:41:54 +0100 | [diff] [blame] | 42 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 43 | int32_t RegisterDecodeCompleteCallback( |
| 44 | webrtc::DecodedImageCallback* callback) override { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 45 | RTC_LOG(LS_ERROR) |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 46 | << "Can't register decode complete callback on NullVideoDecoder."; |
| 47 | return WEBRTC_VIDEO_CODEC_OK; |
| 48 | } |
| 49 | |
| 50 | int32_t Release() override { return WEBRTC_VIDEO_CODEC_OK; } |
| 51 | |
| 52 | const char* ImplementationName() const override { return "NullVideoDecoder"; } |
| 53 | }; |
| 54 | |
| 55 | } // anonymous namespace |
| 56 | |
| 57 | InternalDecoderFactory::InternalDecoderFactory() {} |
| 58 | |
| 59 | InternalDecoderFactory::~InternalDecoderFactory() {} |
| 60 | |
| 61 | // WebRtcVideoDecoderFactory implementation. |
| 62 | webrtc::VideoDecoder* InternalDecoderFactory::CreateVideoDecoder( |
| 63 | webrtc::VideoCodecType type) { |
| 64 | switch (type) { |
| 65 | case webrtc::kVideoCodecH264: |
| 66 | if (webrtc::H264Decoder::IsSupported()) |
| 67 | return webrtc::H264Decoder::Create(); |
| 68 | // This could happen in a software-fallback for a codec type only |
| 69 | // supported externally (e.g. H.264 on iOS or Android) or in current usage |
| 70 | // in WebRtcVideoEngine if the external decoder fails to be created. |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 71 | RTC_LOG(LS_ERROR) << "Unable to create an H.264 decoder fallback. " |
| 72 | << "Decoding of this stream will be broken."; |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 73 | return new NullVideoDecoder(); |
| 74 | case webrtc::kVideoCodecVP8: |
| 75 | return webrtc::VP8Decoder::Create(); |
| 76 | case webrtc::kVideoCodecVP9: |
| 77 | RTC_DCHECK(webrtc::VP9Decoder::IsSupported()); |
| 78 | return webrtc::VP9Decoder::Create(); |
| 79 | default: |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 80 | RTC_LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 81 | return new NullVideoDecoder(); |
| 82 | } |
magjed | dd40702 | 2016-12-01 00:27:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Christian Fremerey | 267d84b | 2017-11-08 23:26:44 +0000 | [diff] [blame] | 85 | void InternalDecoderFactory::DestroyVideoDecoder( |
| 86 | webrtc::VideoDecoder* decoder) { |
| 87 | delete decoder; |
| 88 | } |
| 89 | |
| 90 | } // namespace cricket |