blob: aa7ee2430746c113933d7e3bb892aae84ee40427 [file] [log] [blame]
ilnikd60d06a2017-04-05 03:02:20 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_VIDEO_CODECS_VIDEO_DECODER_H_
12#define API_VIDEO_CODECS_VIDEO_DECODER_H_
ilnikd60d06a2017-04-05 03:02:20 -070013
14#include <memory>
15#include <string>
16#include <vector>
17
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020018#include "absl/types/optional.h"
Niels Möller4dc66c52018-10-05 14:17:58 +020019#include "api/video/encoded_image.h"
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020020#include "api/video/render_resolution.h"
21#include "api/video/video_codec_type.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "api/video/video_frame.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020023#include "rtc_base/system/rtc_export.h"
ilnikd60d06a2017-04-05 03:02:20 -070024
25namespace webrtc {
26
Mirko Bonadei977b46a2018-10-24 16:22:04 +020027class RTC_EXPORT DecodedImageCallback {
ilnikd60d06a2017-04-05 03:02:20 -070028 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öllerbe682d42018-03-27 08:31:45 +020036 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms);
37
ilnikd60d06a2017-04-05 03:02:20 -070038 // TODO(sakal): Remove other implementations when upstream projects have been
39 // updated.
40 virtual void Decoded(VideoFrame& decodedImage,
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020041 absl::optional<int32_t> decode_time_ms,
42 absl::optional<uint8_t> qp);
ilnikd60d06a2017-04-05 03:02:20 -070043};
44
Mirko Bonadei276827c2018-10-16 14:13:50 +020045class RTC_EXPORT VideoDecoder {
ilnikd60d06a2017-04-05 03:02:20 -070046 public:
Erik Språngc12f6252021-01-13 21:49:59 +010047 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 Chapovalovecc46ef2021-08-09 15:30:47 +020059 class Settings {
60 public:
61 Settings() = default;
62 Settings(const Settings&) = default;
63 Settings& operator=(const Settings&) = default;
64 ~Settings() = default;
ilnikd60d06a2017-04-05 03:02:20 -070065
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020066 // 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 Chapovalovba0a3062021-08-13 18:15:55 +020080 // Must be positive.
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020081 int number_of_cores() const { return number_of_cores_; }
Danil Chapovalovba0a3062021-08-13 18:15:55 +020082 void set_number_of_cores(int value);
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020083
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 Chapovalov00dd5ce2021-08-16 16:54:40 +020099 virtual bool Configure(const Settings& settings) = 0;
ilnikd60d06a2017-04-05 03:02:20 -0700100
101 virtual int32_t Decode(const EncodedImage& input_image,
102 bool missing_frames,
Niels Möller5d34dcf2019-04-11 15:39:39 +0200103 int64_t render_time_ms) = 0;
ilnikd60d06a2017-04-05 03:02:20 -0700104
105 virtual int32_t RegisterDecodeCompleteCallback(
106 DecodedImageCallback* callback) = 0;
107
108 virtual int32_t Release() = 0;
109
Erik Språngc12f6252021-01-13 21:49:59 +0100110 virtual DecoderInfo GetDecoderInfo() const;
111
Erik Språngc12f6252021-01-13 21:49:59 +0100112 // Deprecated, use GetDecoderInfo().implementation_name instead.
Niels Möllerbe682d42018-03-27 08:31:45 +0200113 virtual const char* ImplementationName() const;
ilnikd60d06a2017-04-05 03:02:20 -0700114};
115
Danil Chapovalovecc46ef2021-08-09 15:30:47 +0200116inline absl::optional<int> VideoDecoder::Settings::buffer_pool_size() const {
117 return buffer_pool_size_;
118}
119
120inline void VideoDecoder::Settings::set_buffer_pool_size(
121 absl::optional<int> value) {
122 buffer_pool_size_ = value;
123}
124
125inline RenderResolution VideoDecoder::Settings::max_render_resolution() const {
126 return max_resolution_;
127}
128
129inline void VideoDecoder::Settings::set_max_render_resolution(
130 RenderResolution value) {
131 max_resolution_ = value;
132}
133
ilnikd60d06a2017-04-05 03:02:20 -0700134} // namespace webrtc
135
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200136#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_