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 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 14 | #include "webrtc/modules/include/module_common_types.h" |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 15 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 16 | #include "webrtc/modules/video_coding/encoded_frame.h" |
| 17 | #include "webrtc/modules/video_coding/timestamp_map.h" |
| 18 | #include "webrtc/modules/video_coding/timing.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
| 22 | class VCMReceiveCallback; |
| 23 | |
| 24 | enum { kDecoderFrameMemoryLength = 10 }; |
| 25 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 26 | struct VCMFrameInformation { |
| 27 | int64_t renderTimeMs; |
| 28 | int64_t decodeStartTimeMs; |
| 29 | void* userData; |
| 30 | VideoRotation rotation; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 33 | class VCMDecodedFrameCallback : public DecodedImageCallback { |
| 34 | public: |
| 35 | VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | virtual ~VCMDecodedFrameCallback(); |
| 37 | void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); |
wuchengli@chromium.org | 0d94c2f | 2013-08-12 14:20:49 +0000 | [diff] [blame] | 38 | VCMReceiveCallback* UserReceiveCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | |
sakal | ff0e72f | 2017-02-07 07:15:17 -0800 | [diff] [blame^] | 40 | int32_t Decoded(VideoFrame& decodedImage) override; |
| 41 | int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override; |
| 42 | void Decoded(VideoFrame& decodedImage, |
| 43 | rtc::Optional<int32_t> decode_time_ms, |
| 44 | rtc::Optional<uint8_t> qp) override; |
| 45 | int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override; |
| 46 | int32_t ReceivedDecodedFrame(const uint64_t pictureId) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 48 | uint64_t LastReceivedPictureID() const; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 49 | void OnDecoderImplementationName(const char* implementation_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | |
pbos | 1968d3f | 2015-09-28 08:52:18 -0700 | [diff] [blame] | 51 | void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 52 | int32_t Pop(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 54 | private: |
fischman@webrtc.org | e001b57 | 2013-06-04 03:29:37 +0000 | [diff] [blame] | 55 | // Protect |_receiveCallback| and |_timestampMap|. |
stefan@webrtc.org | 7889a9b | 2011-12-12 08:18:24 +0000 | [diff] [blame] | 56 | CriticalSectionWrapper* _critSect; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 57 | Clock* _clock; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 58 | VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 59 | VCMTiming* _timing; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 60 | VCMTimestampMap _timestampMap GUARDED_BY(_critSect); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 61 | uint64_t _lastReceivedPictureID; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 64 | class VCMGenericDecoder { |
| 65 | friend class VCMCodecDataBase; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 67 | public: |
| 68 | explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); |
| 69 | ~VCMGenericDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 71 | /** |
| 72 | * Initialize the decoder with the information from the VideoCodec |
| 73 | */ |
| 74 | int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 76 | /** |
| 77 | * Decode to a raw I420 frame, |
| 78 | * |
| 79 | * inputVideoBuffer reference to encoded video frame |
| 80 | */ |
| 81 | int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 83 | /** |
| 84 | * Free the decoder memory |
| 85 | */ |
| 86 | int32_t Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 88 | /** |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 89 | * Set decode callback. Deregistering while decoding is illegal. |
| 90 | */ |
| 91 | int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 93 | bool External() const; |
| 94 | bool PrefersLateDecoding() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 96 | private: |
| 97 | VCMDecodedFrameCallback* _callback; |
| 98 | VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; |
| 99 | uint32_t _nextFrameInfoIdx; |
| 100 | VideoDecoder* const _decoder; |
| 101 | VideoCodecType _codecType; |
| 102 | bool _isExternal; |
| 103 | bool _keyFrameDecoded; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | }; |
| 105 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 106 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 108 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |