blob: 5e69602a5d958eba2cc64ba6daba33266e805c1c [file] [log] [blame]
magjeddd407022016-12-01 00:27:27 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/engine/internaldecoderfactory.h"
magjeddd407022016-12-01 00:27:27 -080012
13#include <utility>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#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"
magjeddd407022016-12-01 00:27:27 -080019
20namespace cricket {
21
22namespace {
23
24// Video decoder class to be used for unknown codecs. Doesn't support decoding
25// but logs messages to LS_ERROR.
26class NullVideoDecoder : public webrtc::VideoDecoder {
27 public:
28 int32_t InitDecode(const webrtc::VideoCodec* codec_settings,
29 int32_t number_of_cores) override {
30 LOG(LS_ERROR) << "Can't initialize NullVideoDecoder.";
31 return WEBRTC_VIDEO_CODEC_OK;
32 }
33
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 {
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
57InternalDecoderFactory::InternalDecoderFactory() {}
58
59InternalDecoderFactory::~InternalDecoderFactory() {}
60
61// WebRtcVideoDecoderFactory implementation.
62webrtc::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
eladalonf1841382017-06-12 01:16:46 -070070 // in WebRtcVideoEngine if the external decoder fails to be created.
magjeddd407022016-12-01 00:27:27 -080071 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:
80 LOG(LS_ERROR) << "Creating NullVideoDecoder for unsupported codec.";
81 return new NullVideoDecoder();
82 }
83}
84
85void InternalDecoderFactory::DestroyVideoDecoder(
86 webrtc::VideoDecoder* decoder) {
87 delete decoder;
88}
89
90} // namespace cricket