pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | |
| 11 | #ifndef WEBRTC_VIDEO_DECODER_H_ |
| 12 | #define WEBRTC_VIDEO_DECODER_H_ |
| 13 | |
kwiberg | c891eb4 | 2016-03-02 03:41:34 -0800 | [diff] [blame] | 14 | #include <memory> |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 15 | #include <string> |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
| 18 | #include "webrtc/common_types.h" |
| 19 | #include "webrtc/typedefs.h" |
| 20 | #include "webrtc/video_frame.h" |
| 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | class RTPFragmentationHeader; |
| 25 | // TODO(pbos): Expose these through a public (root) header or change these APIs. |
| 26 | struct CodecSpecificInfo; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame^] | 27 | class VideoCodec; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 28 | |
| 29 | class DecodedImageCallback { |
| 30 | public: |
| 31 | virtual ~DecodedImageCallback() {} |
| 32 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 33 | virtual int32_t Decoded(VideoFrame& decodedImage) = 0; |
Per | 327d8ba | 2015-11-10 14:00:27 +0100 | [diff] [blame] | 34 | // Provides an alternative interface that allows the decoder to specify the |
| 35 | // decode time excluding waiting time for any previous pending frame to |
| 36 | // return. This is necessary for breaking positive feedback in the delay |
| 37 | // estimation when the decoder has a single output buffer. |
| 38 | // TODO(perkj): Remove default implementation when chromium has been updated. |
| 39 | virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) { |
| 40 | // The default implementation ignores custom decode time value. |
| 41 | return Decoded(decodedImage); |
| 42 | } |
| 43 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 44 | virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) { |
| 45 | return -1; |
| 46 | } |
| 47 | |
| 48 | virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) { return -1; } |
| 49 | }; |
| 50 | |
| 51 | class VideoDecoder { |
| 52 | public: |
| 53 | enum DecoderType { |
Zeke Chin | 71f6f44 | 2015-06-29 14:34:58 -0700 | [diff] [blame] | 54 | kH264, |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 55 | kVp8, |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 56 | kVp9, |
| 57 | kUnsupportedCodec, |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static VideoDecoder* Create(DecoderType codec_type); |
| 61 | |
| 62 | virtual ~VideoDecoder() {} |
| 63 | |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 64 | virtual int32_t InitDecode(const VideoCodec* codec_settings, |
| 65 | int32_t number_of_cores) = 0; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 66 | |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 67 | virtual int32_t Decode(const EncodedImage& input_image, |
| 68 | bool missing_frames, |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 69 | const RTPFragmentationHeader* fragmentation, |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 70 | const CodecSpecificInfo* codec_specific_info = NULL, |
| 71 | int64_t render_time_ms = -1) = 0; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 72 | |
| 73 | virtual int32_t RegisterDecodeCompleteCallback( |
| 74 | DecodedImageCallback* callback) = 0; |
| 75 | |
| 76 | virtual int32_t Release() = 0; |
perkj | 796cfaf | 2015-12-10 09:27:38 -0800 | [diff] [blame] | 77 | |
| 78 | // Returns true if the decoder prefer to decode frames late. |
| 79 | // That is, it can not decode infinite number of frames before the decoded |
| 80 | // frame is consumed. |
| 81 | virtual bool PrefersLateDecoding() const { return true; } |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 82 | |
| 83 | virtual const char* ImplementationName() const { return "unknown"; } |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 86 | // Class used to wrap external VideoDecoders to provide a fallback option on |
| 87 | // software decoding when a hardware decoder fails to decode a stream due to |
| 88 | // hardware restrictions, such as max resolution. |
| 89 | class VideoDecoderSoftwareFallbackWrapper : public webrtc::VideoDecoder { |
| 90 | public: |
| 91 | VideoDecoderSoftwareFallbackWrapper(VideoCodecType codec_type, |
| 92 | VideoDecoder* decoder); |
| 93 | |
| 94 | int32_t InitDecode(const VideoCodec* codec_settings, |
| 95 | int32_t number_of_cores) override; |
| 96 | |
| 97 | int32_t Decode(const EncodedImage& input_image, |
| 98 | bool missing_frames, |
| 99 | const RTPFragmentationHeader* fragmentation, |
| 100 | const CodecSpecificInfo* codec_specific_info, |
| 101 | int64_t render_time_ms) override; |
| 102 | |
| 103 | int32_t RegisterDecodeCompleteCallback( |
| 104 | DecodedImageCallback* callback) override; |
| 105 | |
| 106 | int32_t Release() override; |
perkj | 796cfaf | 2015-12-10 09:27:38 -0800 | [diff] [blame] | 107 | bool PrefersLateDecoding() const override; |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 108 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 109 | const char* ImplementationName() const override; |
| 110 | |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 111 | private: |
| 112 | bool InitFallbackDecoder(); |
| 113 | |
| 114 | const DecoderType decoder_type_; |
| 115 | VideoDecoder* const decoder_; |
| 116 | |
| 117 | VideoCodec codec_settings_; |
| 118 | int32_t number_of_cores_; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 119 | std::string fallback_implementation_name_; |
kwiberg | c891eb4 | 2016-03-02 03:41:34 -0800 | [diff] [blame] | 120 | std::unique_ptr<VideoDecoder> fallback_decoder_; |
Peter Boström | 7252a2b | 2015-05-18 19:42:03 +0200 | [diff] [blame] | 121 | DecodedImageCallback* callback_; |
| 122 | }; |
| 123 | |
jbauch | e03ac51 | 2016-02-03 05:51:48 -0800 | [diff] [blame] | 124 | // Video decoder class to be used for unknown codecs. Doesn't support decoding |
| 125 | // but logs messages to LS_ERROR. |
| 126 | class NullVideoDecoder : public VideoDecoder { |
| 127 | public: |
| 128 | NullVideoDecoder(); |
| 129 | |
| 130 | int32_t InitDecode(const VideoCodec* codec_settings, |
| 131 | int32_t number_of_cores) override; |
| 132 | |
| 133 | int32_t Decode(const EncodedImage& input_image, |
| 134 | bool missing_frames, |
| 135 | const RTPFragmentationHeader* fragmentation, |
| 136 | const CodecSpecificInfo* codec_specific_info, |
| 137 | int64_t render_time_ms) override; |
| 138 | |
| 139 | int32_t RegisterDecodeCompleteCallback( |
| 140 | DecodedImageCallback* callback) override; |
| 141 | |
| 142 | int32_t Release() override; |
jbauch | e03ac51 | 2016-02-03 05:51:48 -0800 | [diff] [blame] | 143 | |
| 144 | const char* ImplementationName() const override; |
| 145 | }; |
| 146 | |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 147 | } // namespace webrtc |
| 148 | |
| 149 | #endif // WEBRTC_VIDEO_DECODER_H_ |