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