niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mikhal@webrtc.org | a2031d5 | 2012-07-31 15:53:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |
| 12 | #define MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Ilya Nikolaevskiy | 43c108b | 2020-05-15 12:24:29 +0200 | [diff] [blame] | 14 | #include <string> |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 15 | |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame^] | 16 | #include "api/field_trials_view.h" |
Artem Titov | d15a575 | 2021-02-10 14:31:24 +0100 | [diff] [blame] | 17 | #include "api/sequence_checker.h" |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 18 | #include "api/units/time_delta.h" |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 19 | #include "api/video_codecs/video_decoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/video_coding/encoded_frame.h" |
| 21 | #include "modules/video_coding/include/video_codec_interface.h" |
| 22 | #include "modules/video_coding/timestamp_map.h" |
| 23 | #include "modules/video_coding/timing.h" |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 24 | #include "rtc_base/experiments/field_trial_parser.h" |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 25 | #include "rtc_base/synchronization/mutex.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 27 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
| 29 | class VCMReceiveCallback; |
| 30 | |
| 31 | enum { kDecoderFrameMemoryLength = 10 }; |
| 32 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 33 | class VCMDecodedFrameCallback : public DecodedImageCallback { |
| 34 | public: |
Jonas Oreland | e02f9ee | 2022-03-25 12:43:14 +0100 | [diff] [blame] | 35 | VCMDecodedFrameCallback(VCMTiming* timing, |
| 36 | Clock* clock, |
Jonas Oreland | e62c2f2 | 2022-03-29 11:04:48 +0200 | [diff] [blame^] | 37 | const FieldTrialsView& field_trials); |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 38 | ~VCMDecodedFrameCallback() override; |
| 39 | void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); |
| 40 | VCMReceiveCallback* UserReceiveCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 42 | int32_t Decoded(VideoFrame& decodedImage) override; |
| 43 | int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; |
| 44 | void Decoded(VideoFrame& decodedImage, |
Danil Chapovalov | 0040b66 | 2018-06-18 10:48:16 +0200 | [diff] [blame] | 45 | absl::optional<int32_t> decode_time_ms, |
| 46 | absl::optional<uint8_t> qp) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 48 | void OnDecoderImplementationName(const char* implementation_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
Johannes Kron | b6b782d | 2021-03-03 14:39:44 +0100 | [diff] [blame] | 50 | void Map(uint32_t timestamp, const VCMFrameInformation& frameInfo); |
Johannes Kron | fc5d276 | 2021-04-09 16:03:22 +0200 | [diff] [blame] | 51 | void ClearTimestampMap(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 53 | private: |
Artem Titov | c8421c4 | 2021-02-02 10:57:19 +0100 | [diff] [blame] | 54 | SequenceChecker construction_thread_; |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 55 | // Protect `_timestampMap`. |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 56 | Clock* const _clock; |
| 57 | // This callback must be set before the decoder thread starts running |
| 58 | // and must only be unset when external threads (e.g decoder thread) |
| 59 | // have been stopped. Due to that, the variable should regarded as const |
| 60 | // while there are more than one threads involved, it must be set |
| 61 | // from the same thread, and therfore a lock is not required to access it. |
| 62 | VCMReceiveCallback* _receiveCallback = nullptr; |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 63 | VCMTiming* _timing; |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 64 | Mutex lock_; |
Lu Liu | 352314a | 2018-02-21 19:38:59 +0000 | [diff] [blame] | 65 | VCMTimestampMap _timestampMap RTC_GUARDED_BY(lock_); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 66 | int64_t ntp_offset_; |
Johannes Kron | 7ddea57 | 2019-09-11 12:00:22 +0200 | [diff] [blame] | 67 | // Set by the field trial WebRTC-SlowDownDecoder to simulate a slow decoder. |
| 68 | FieldTrialOptional<TimeDelta> _extra_decode_time; |
Johannes Kron | 111e981 | 2020-10-26 13:54:40 +0100 | [diff] [blame] | 69 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 70 | // Set by the field trial WebRTC-LowLatencyRenderer. The parameter `enabled` |
Johannes Kron | 111e981 | 2020-10-26 13:54:40 +0100 | [diff] [blame] | 71 | // determines if the low-latency renderer algorithm should be used for the |
| 72 | // case min playout delay=0 and max playout delay>0. |
| 73 | FieldTrialParameter<bool> low_latency_renderer_enabled_; |
| 74 | // Set by the field trial WebRTC-LowLatencyRenderer. The parameter |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 75 | // `include_predecode_buffer` determines if the predecode buffer should be |
Johannes Kron | 111e981 | 2020-10-26 13:54:40 +0100 | [diff] [blame] | 76 | // taken into account when calculating maximum number of frames in composition |
| 77 | // queue. |
| 78 | FieldTrialParameter<bool> low_latency_renderer_include_predecode_buffer_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 81 | class VCMGenericDecoder { |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 82 | public: |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 83 | explicit VCMGenericDecoder(VideoDecoder* decoder); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 84 | ~VCMGenericDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 85 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 86 | /** |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 87 | * Initialize the decoder with the information from the `settings` |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 88 | */ |
Danil Chapovalov | 355b8d2 | 2021-08-13 16:50:37 +0200 | [diff] [blame] | 89 | bool Configure(const VideoDecoder::Settings& settings); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 90 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 91 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 92 | * Decode to a raw I420 frame, |
| 93 | * |
| 94 | * inputVideoBuffer reference to encoded video frame |
| 95 | */ |
Johannes Kron | 05f8487 | 2020-01-16 14:09:33 +0100 | [diff] [blame] | 96 | int32_t Decode(const VCMEncodedFrame& inputFrame, Timestamp now); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 98 | /** |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | * Set decode callback. Deregistering while decoding is illegal. |
| 100 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 101 | int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 103 | bool IsSameDecoder(VideoDecoder* decoder) const { |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 104 | return decoder_ == decoder; |
tommi | 5b7fc8c | 2017-07-05 16:45:57 -0700 | [diff] [blame] | 105 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 107 | private: |
Danil Chapovalov | 7b78a31 | 2021-08-06 12:30:02 +0200 | [diff] [blame] | 108 | VCMDecodedFrameCallback* _callback = nullptr; |
| 109 | VideoDecoder* const decoder_; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 110 | VideoContentType _last_keyframe_content_type; |
Erik Språng | c12f625 | 2021-01-13 21:49:59 +0100 | [diff] [blame] | 111 | VideoDecoder::DecoderInfo decoder_info_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 114 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 116 | #endif // MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |