OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 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/video_decoder.h" | 11 #include "webrtc/media/engine/internaldecoderfactory.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include <utility> |
| 14 |
14 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
15 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | 16 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
16 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 17 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
17 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | 18 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace cricket { |
20 VideoDecoder* VideoDecoder::Create(VideoDecoder::DecoderType codec_type) { | 21 |
21 switch (codec_type) { | 22 namespace { |
22 case kH264: | 23 |
23 if (!H264Decoder::IsSupported()) { | 24 // Video decoder class to be used for unknown codecs. Doesn't support decoding |
24 // This could happen in a software-fallback for a codec type only | 25 // but logs messages to LS_ERROR. |
25 // supported externally (e.g. H.264 on iOS or Android) or in current | 26 class NullVideoDecoder : public webrtc::VideoDecoder { |
26 // usage in WebRtcVideoEngine2 if the external decoder fails to be | 27 public: |
27 // created. | 28 int32_t InitDecode(const webrtc::VideoCodec* codec_settings, |
28 LOG(LS_ERROR) << "Unable to create an H.264 decoder fallback. " | 29 int32_t number_of_cores) override { |
29 << "Decoding of this stream will be broken."; | 30 LOG(LS_ERROR) << "Can't initialize NullVideoDecoder."; |
30 return new NullVideoDecoder(); | 31 return WEBRTC_VIDEO_CODEC_OK; |
31 } | 32 } |
32 return H264Decoder::Create(); | 33 |
33 case kVp8: | 34 int32_t Decode(const webrtc::EncodedImage& input_image, |
34 return VP8Decoder::Create(); | 35 bool missing_frames, |
35 case kVp9: | 36 const webrtc::RTPFragmentationHeader* fragmentation, |
36 RTC_DCHECK(VP9Decoder::IsSupported()); | 37 const webrtc::CodecSpecificInfo* codec_specific_info, |
37 return VP9Decoder::Create(); | 38 int64_t render_time_ms) override { |
38 case kUnsupportedCodec: | 39 LOG(LS_ERROR) << "The NullVideoDecoder doesn't support decoding."; |
| 40 return WEBRTC_VIDEO_CODEC_OK; |
| 41 } |
| 42 |
| 43 int32_t RegisterDecodeCompleteCallback( |
| 44 webrtc::DecodedImageCallback* callback) override { |
| 45 LOG(LS_ERROR) |
| 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 WebRtcVideoEngine2 if the external decoder fails to be created. |
| 71 LOG(LS_ERROR) << "Unable to create an H.264 decoder fallback. " |
| 72 << "Decoding of this stream will be broken."; |
| 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: |
39 LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; | 80 LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec."; |
40 return new NullVideoDecoder(); | 81 return new NullVideoDecoder(); |
41 } | 82 } |
42 RTC_NOTREACHED(); | |
43 return nullptr; | |
44 } | 83 } |
45 | 84 |
46 NullVideoDecoder::NullVideoDecoder() {} | 85 void InternalDecoderFactory::DestroyVideoDecoder( |
47 | 86 webrtc::VideoDecoder* decoder) { |
48 int32_t NullVideoDecoder::InitDecode(const VideoCodec* codec_settings, | 87 delete decoder; |
49 int32_t number_of_cores) { | |
50 LOG(LS_ERROR) << "Can't initialize NullVideoDecoder."; | |
51 return WEBRTC_VIDEO_CODEC_OK; | |
52 } | 88 } |
53 | 89 |
54 int32_t NullVideoDecoder::Decode(const EncodedImage& input_image, | 90 } // namespace cricket |
55 bool missing_frames, | |
56 const RTPFragmentationHeader* fragmentation, | |
57 const CodecSpecificInfo* codec_specific_info, | |
58 int64_t render_time_ms) { | |
59 LOG(LS_ERROR) << "The NullVideoDecoder doesn't support decoding."; | |
60 return WEBRTC_VIDEO_CODEC_OK; | |
61 } | |
62 | |
63 int32_t NullVideoDecoder::RegisterDecodeCompleteCallback( | |
64 DecodedImageCallback* callback) { | |
65 LOG(LS_ERROR) | |
66 << "Can't register decode complete callback on NullVideoDecoder."; | |
67 return WEBRTC_VIDEO_CODEC_OK; | |
68 } | |
69 | |
70 int32_t NullVideoDecoder::Release() { | |
71 return WEBRTC_VIDEO_CODEC_OK; | |
72 } | |
73 | |
74 const char* NullVideoDecoder::ImplementationName() const { | |
75 return "NullVideoDecoder"; | |
76 } | |
77 | |
78 } // namespace webrtc | |
OLD | NEW |