ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef API_VIDEO_CODECS_VIDEO_DECODER_H_ |
| 12 | #define API_VIDEO_CODECS_VIDEO_DECODER_H_ |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Niels Möller | 4dc66c5 | 2018-10-05 14:17:58 +0200 | [diff] [blame] | 18 | #include "api/video/encoded_image.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "api/video/video_frame.h" |
Niels Möller | 802506c | 2018-05-31 10:44:51 +0200 | [diff] [blame] | 20 | #include "api/video_codecs/video_codec.h" |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame] | 21 | #include "rtc_base/system/rtc_export.h" |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
Mirko Bonadei | 977b46a | 2018-10-24 16:22:04 +0200 | [diff] [blame] | 25 | class RTC_EXPORT DecodedImageCallback { |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 26 | public: |
| 27 | virtual ~DecodedImageCallback() {} |
| 28 | |
| 29 | virtual int32_t Decoded(VideoFrame& decodedImage) = 0; |
| 30 | // Provides an alternative interface that allows the decoder to specify the |
| 31 | // decode time excluding waiting time for any previous pending frame to |
| 32 | // return. This is necessary for breaking positive feedback in the delay |
| 33 | // estimation when the decoder has a single output buffer. |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 34 | virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms); |
| 35 | |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 36 | // TODO(sakal): Remove other implementations when upstream projects have been |
| 37 | // updated. |
| 38 | virtual void Decoded(VideoFrame& decodedImage, |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 39 | absl::optional<int32_t> decode_time_ms, |
| 40 | absl::optional<uint8_t> qp); |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame] | 43 | class RTC_EXPORT VideoDecoder { |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 44 | public: |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame^] | 45 | struct DecoderInfo { |
| 46 | // Descriptive name of the decoder implementation. |
| 47 | std::string implementation_name; |
| 48 | |
| 49 | // True if the decoder is backed by hardware acceleration. |
| 50 | bool is_hardware_accelerated = false; |
| 51 | |
| 52 | std::string ToString() const; |
| 53 | bool operator==(const DecoderInfo& rhs) const; |
| 54 | bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); } |
| 55 | }; |
| 56 | |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 57 | virtual ~VideoDecoder() {} |
| 58 | |
| 59 | virtual int32_t InitDecode(const VideoCodec* codec_settings, |
| 60 | int32_t number_of_cores) = 0; |
| 61 | |
| 62 | virtual int32_t Decode(const EncodedImage& input_image, |
| 63 | bool missing_frames, |
Niels Möller | 5d34dcf | 2019-04-11 15:39:39 +0200 | [diff] [blame] | 64 | int64_t render_time_ms) = 0; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 65 | |
| 66 | virtual int32_t RegisterDecodeCompleteCallback( |
| 67 | DecodedImageCallback* callback) = 0; |
| 68 | |
| 69 | virtual int32_t Release() = 0; |
| 70 | |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame^] | 71 | virtual DecoderInfo GetDecoderInfo() const; |
| 72 | |
| 73 | // Deprecated, use GetDecoderInfo().prefers_late_decoding instead. |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 74 | // Returns true if the decoder prefer to decode frames late. |
| 75 | // That is, it can not decode infinite number of frames before the decoded |
| 76 | // frame is consumed. |
philipel | 360da05 | 2021-01-11 15:44:43 +0100 | [diff] [blame] | 77 | // TODO(bugs.webrtc.org/12271): Remove when downstream has been updated. |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 78 | virtual bool PrefersLateDecoding() const; |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame^] | 79 | // Deprecated, use GetDecoderInfo().implementation_name instead. |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 80 | virtual const char* ImplementationName() const; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace webrtc |
| 84 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 85 | #endif // API_VIDEO_CODECS_VIDEO_DECODER_H_ |