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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |
| 13 | |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 14 | #include "webrtc/base/criticalsection.h" |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 15 | #include "webrtc/base/thread_checker.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 16 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 17 | #include "webrtc/modules/video_coding/encoded_frame.h" |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 18 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 19 | #include "webrtc/modules/video_coding/timestamp_map.h" |
| 20 | #include "webrtc/modules/video_coding/timing.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | class VCMReceiveCallback; |
| 25 | |
| 26 | enum { kDecoderFrameMemoryLength = 10 }; |
| 27 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 28 | struct VCMFrameInformation { |
| 29 | int64_t renderTimeMs; |
| 30 | int64_t decodeStartTimeMs; |
| 31 | void* userData; |
| 32 | VideoRotation rotation; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 35 | class VCMDecodedFrameCallback : public DecodedImageCallback { |
| 36 | public: |
| 37 | VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock); |
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, |
| 45 | rtc::Optional<int32_t> decode_time_ms, |
| 46 | rtc::Optional<uint8_t> qp) override; |
| 47 | int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override; |
| 48 | int32_t ReceivedDecodedFrame(const uint64_t pictureId) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 50 | uint64_t LastReceivedPictureID() const; |
| 51 | void OnDecoderImplementationName(const char* implementation_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 53 | void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); |
| 54 | int32_t Pop(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 56 | private: |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 57 | rtc::ThreadChecker construction_thread_; |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 58 | // Protect |_timestampMap|. |
tommi | d0a71ba | 2017-03-14 04:16:20 -0700 | [diff] [blame] | 59 | Clock* const _clock; |
| 60 | // This callback must be set before the decoder thread starts running |
| 61 | // and must only be unset when external threads (e.g decoder thread) |
| 62 | // have been stopped. Due to that, the variable should regarded as const |
| 63 | // while there are more than one threads involved, it must be set |
| 64 | // from the same thread, and therfore a lock is not required to access it. |
| 65 | VCMReceiveCallback* _receiveCallback = nullptr; |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 66 | VCMTiming* _timing; |
| 67 | rtc::CriticalSection lock_; |
| 68 | VCMTimestampMap _timestampMap GUARDED_BY(lock_); |
| 69 | uint64_t _lastReceivedPictureID; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 72 | class VCMGenericDecoder { |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 73 | friend class VCMCodecDataBase; |
| 74 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 75 | public: |
| 76 | explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); |
| 77 | ~VCMGenericDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Initialize the decoder with the information from the VideoCodec |
| 81 | */ |
| 82 | int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 83 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 84 | /** |
| 85 | * Decode to a raw I420 frame, |
| 86 | * |
| 87 | * inputVideoBuffer reference to encoded video frame |
| 88 | */ |
| 89 | int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); |
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 | /** |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 92 | * Free the decoder memory |
| 93 | */ |
| 94 | int32_t Release(); |
| 95 | |
| 96 | /** |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 97 | * Set decode callback. Deregistering while decoding is illegal. |
| 98 | */ |
| 99 | int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 101 | bool External() const; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 102 | bool PrefersLateDecoding() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 104 | private: |
guidou | c337258 | 2017-04-04 07:16:21 -0700 | [diff] [blame] | 105 | VCMDecodedFrameCallback* _callback; |
| 106 | VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; |
| 107 | uint32_t _nextFrameInfoIdx; |
| 108 | VideoDecoder* const _decoder; |
| 109 | VideoCodecType _codecType; |
| 110 | bool _isExternal; |
| 111 | bool _keyFrameDecoded; |
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 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 116 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |