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 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 18 | #include "absl/types/optional.h" |
Niels Möller | 4dc66c5 | 2018-10-05 14:17:58 +0200 | [diff] [blame] | 19 | #include "api/video/encoded_image.h" |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 20 | #include "api/video/render_resolution.h" |
| 21 | #include "api/video/video_codec_type.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "api/video/video_frame.h" |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame] | 23 | #include "rtc_base/system/rtc_export.h" |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
Mirko Bonadei | 977b46a | 2018-10-24 16:22:04 +0200 | [diff] [blame] | 27 | class RTC_EXPORT DecodedImageCallback { |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 28 | public: |
| 29 | virtual ~DecodedImageCallback() {} |
| 30 | |
| 31 | virtual int32_t Decoded(VideoFrame& decodedImage) = 0; |
| 32 | // Provides an alternative interface that allows the decoder to specify the |
| 33 | // decode time excluding waiting time for any previous pending frame to |
| 34 | // return. This is necessary for breaking positive feedback in the delay |
| 35 | // estimation when the decoder has a single output buffer. |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 36 | virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms); |
| 37 | |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 38 | // TODO(sakal): Remove other implementations when upstream projects have been |
| 39 | // updated. |
| 40 | virtual void Decoded(VideoFrame& decodedImage, |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 41 | absl::optional<int32_t> decode_time_ms, |
| 42 | absl::optional<uint8_t> qp); |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Mirko Bonadei | 276827c | 2018-10-16 14:13:50 +0200 | [diff] [blame] | 45 | class RTC_EXPORT VideoDecoder { |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 46 | public: |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 47 | struct DecoderInfo { |
| 48 | // Descriptive name of the decoder implementation. |
| 49 | std::string implementation_name; |
| 50 | |
| 51 | // True if the decoder is backed by hardware acceleration. |
| 52 | bool is_hardware_accelerated = false; |
| 53 | |
| 54 | std::string ToString() const; |
| 55 | bool operator==(const DecoderInfo& rhs) const; |
| 56 | bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); } |
| 57 | }; |
| 58 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 59 | class Settings { |
| 60 | public: |
| 61 | Settings() = default; |
| 62 | Settings(const Settings&) = default; |
| 63 | Settings& operator=(const Settings&) = default; |
| 64 | ~Settings() = default; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 65 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 66 | // The size of pool which is used to store video frame buffers inside |
| 67 | // decoder. If value isn't present some codec-default value will be used. If |
| 68 | // value is present and decoder doesn't have buffer pool the value will be |
| 69 | // ignored. |
| 70 | absl::optional<int> buffer_pool_size() const; |
| 71 | void set_buffer_pool_size(absl::optional<int> value); |
| 72 | |
| 73 | // When valid, user of the VideoDecoder interface shouldn't `Decode` |
| 74 | // encoded images with render resolution larger than width and height |
| 75 | // specified here. |
| 76 | RenderResolution max_render_resolution() const; |
| 77 | void set_max_render_resolution(RenderResolution value); |
| 78 | |
| 79 | // Maximum number of cpu cores the decoder is allowed to use in parallel. |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame] | 80 | // Must be positive. |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 81 | int number_of_cores() const { return number_of_cores_; } |
Danil Chapovalov | ba0a306 | 2021-08-13 18:15:55 +0200 | [diff] [blame] | 82 | void set_number_of_cores(int value); |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 83 | |
| 84 | // Codec of encoded images user of the VideoDecoder interface will `Decode`. |
| 85 | VideoCodecType codec_type() const { return codec_type_; } |
| 86 | void set_codec_type(VideoCodecType value) { codec_type_ = value; } |
| 87 | |
| 88 | private: |
| 89 | absl::optional<int> buffer_pool_size_; |
| 90 | RenderResolution max_resolution_; |
| 91 | int number_of_cores_ = 1; |
| 92 | VideoCodecType codec_type_ = kVideoCodecGeneric; |
| 93 | }; |
| 94 | |
| 95 | virtual ~VideoDecoder() = default; |
| 96 | |
| 97 | // Prepares decoder to handle incoming encoded frames. Can be called multiple |
| 98 | // times, in such case only latest `settings` are in effect. |
Danil Chapovalov | 00dd5ce | 2021-08-16 16:54:40 +0200 | [diff] [blame] | 99 | virtual bool Configure(const Settings& settings) = 0; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 100 | |
| 101 | virtual int32_t Decode(const EncodedImage& input_image, |
| 102 | bool missing_frames, |
Niels Möller | 5d34dcf | 2019-04-11 15:39:39 +0200 | [diff] [blame] | 103 | int64_t render_time_ms) = 0; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 104 | |
| 105 | virtual int32_t RegisterDecodeCompleteCallback( |
| 106 | DecodedImageCallback* callback) = 0; |
| 107 | |
| 108 | virtual int32_t Release() = 0; |
| 109 | |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 110 | virtual DecoderInfo GetDecoderInfo() const; |
| 111 | |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 112 | // Deprecated, use GetDecoderInfo().implementation_name instead. |
Niels Möller | be682d4 | 2018-03-27 08:31:45 +0200 | [diff] [blame] | 113 | virtual const char* ImplementationName() const; |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Danil Chapovalov | ecc46ef | 2021-08-09 15:30:47 +0200 | [diff] [blame] | 116 | inline absl::optional<int> VideoDecoder::Settings::buffer_pool_size() const { |
| 117 | return buffer_pool_size_; |
| 118 | } |
| 119 | |
| 120 | inline void VideoDecoder::Settings::set_buffer_pool_size( |
| 121 | absl::optional<int> value) { |
| 122 | buffer_pool_size_ = value; |
| 123 | } |
| 124 | |
| 125 | inline RenderResolution VideoDecoder::Settings::max_render_resolution() const { |
| 126 | return max_resolution_; |
| 127 | } |
| 128 | |
| 129 | inline void VideoDecoder::Settings::set_max_render_resolution( |
| 130 | RenderResolution value) { |
| 131 | max_resolution_ = value; |
| 132 | } |
| 133 | |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame] | 134 | } // namespace webrtc |
| 135 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 136 | #endif // API_VIDEO_CODECS_VIDEO_DECODER_H_ |