blob: e26488e40a7e3b66eb34b73f38a3e66fe3f93f4b [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"
Niels Möller802506c2018-05-31 10:44:51 +020023#include "api/video_codecs/video_codec.h"
Mirko Bonadei276827c2018-10-16 14:13:50 +020024#include "rtc_base/system/rtc_export.h"
ilnikd60d06a2017-04-05 03:02:20 -070025
26namespace webrtc {
27
Mirko Bonadei977b46a2018-10-24 16:22:04 +020028class RTC_EXPORT DecodedImageCallback {
ilnikd60d06a2017-04-05 03:02:20 -070029 public:
30 virtual ~DecodedImageCallback() {}
31
32 virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
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.
Niels Möllerbe682d42018-03-27 08:31:45 +020037 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms);
38
ilnikd60d06a2017-04-05 03:02:20 -070039 // TODO(sakal): Remove other implementations when upstream projects have been
40 // updated.
41 virtual void Decoded(VideoFrame& decodedImage,
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020042 absl::optional<int32_t> decode_time_ms,
43 absl::optional<uint8_t> qp);
ilnikd60d06a2017-04-05 03:02:20 -070044};
45
Mirko Bonadei276827c2018-10-16 14:13:50 +020046class RTC_EXPORT VideoDecoder {
ilnikd60d06a2017-04-05 03:02:20 -070047 public:
Erik Språngc12f6252021-01-13 21:49:59 +010048 struct DecoderInfo {
49 // Descriptive name of the decoder implementation.
50 std::string implementation_name;
51
52 // True if the decoder is backed by hardware acceleration.
53 bool is_hardware_accelerated = false;
54
55 std::string ToString() const;
56 bool operator==(const DecoderInfo& rhs) const;
57 bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); }
58 };
59
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020060 class Settings {
61 public:
62 Settings() = default;
63 Settings(const Settings&) = default;
64 Settings& operator=(const Settings&) = default;
65 ~Settings() = default;
ilnikd60d06a2017-04-05 03:02:20 -070066
Danil Chapovalovecc46ef2021-08-09 15:30:47 +020067 // The size of pool which is used to store video frame buffers inside
68 // decoder. If value isn't present some codec-default value will be used. If
69 // value is present and decoder doesn't have buffer pool the value will be
70 // ignored.
71 absl::optional<int> buffer_pool_size() const;
72 void set_buffer_pool_size(absl::optional<int> value);
73
74 // When valid, user of the VideoDecoder interface shouldn't `Decode`
75 // encoded images with render resolution larger than width and height
76 // specified here.
77 RenderResolution max_render_resolution() const;
78 void set_max_render_resolution(RenderResolution value);
79
80 // Maximum number of cpu cores the decoder is allowed to use in parallel.
81 int number_of_cores() const { return number_of_cores_; }
82 void set_number_of_cores(int value) { number_of_cores_ = value; }
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.
99 // TODO(bugs.webrtc.org/13045): Make pure virtual when implemented by all
100 // derived classes.
101 virtual bool Configure(const Settings& settings);
102
103 // TODO(bugs.webrtc.org/13045): Delete in favor of the Configure function
104 // above.
ilnikd60d06a2017-04-05 03:02:20 -0700105 virtual int32_t InitDecode(const VideoCodec* codec_settings,
Danil Chapovalovecc46ef2021-08-09 15:30:47 +0200106 int32_t number_of_cores);
ilnikd60d06a2017-04-05 03:02:20 -0700107
108 virtual int32_t Decode(const EncodedImage& input_image,
109 bool missing_frames,
Niels Möller5d34dcf2019-04-11 15:39:39 +0200110 int64_t render_time_ms) = 0;
ilnikd60d06a2017-04-05 03:02:20 -0700111
112 virtual int32_t RegisterDecodeCompleteCallback(
113 DecodedImageCallback* callback) = 0;
114
115 virtual int32_t Release() = 0;
116
Erik Språngc12f6252021-01-13 21:49:59 +0100117 virtual DecoderInfo GetDecoderInfo() const;
118
Erik Språngc12f6252021-01-13 21:49:59 +0100119 // Deprecated, use GetDecoderInfo().implementation_name instead.
Niels Möllerbe682d42018-03-27 08:31:45 +0200120 virtual const char* ImplementationName() const;
ilnikd60d06a2017-04-05 03:02:20 -0700121};
122
Danil Chapovalovecc46ef2021-08-09 15:30:47 +0200123inline absl::optional<int> VideoDecoder::Settings::buffer_pool_size() const {
124 return buffer_pool_size_;
125}
126
127inline void VideoDecoder::Settings::set_buffer_pool_size(
128 absl::optional<int> value) {
129 buffer_pool_size_ = value;
130}
131
132inline RenderResolution VideoDecoder::Settings::max_render_resolution() const {
133 return max_resolution_;
134}
135
136inline void VideoDecoder::Settings::set_max_render_resolution(
137 RenderResolution value) {
138 max_resolution_ = value;
139}
140
ilnikd60d06a2017-04-05 03:02:20 -0700141} // namespace webrtc
142
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200143#endif // API_VIDEO_CODECS_VIDEO_DECODER_H_