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 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 40 | virtual int32_t Decoded(VideoFrame& decodedImage); // NOLINT |
| 41 | virtual int32_t Decoded(VideoFrame& decodedImage, // NOLINT |
| 42 | int64_t decode_time_ms); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 43 | virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId); |
| 44 | virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 46 | uint64_t LastReceivedPictureID() const; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 47 | void OnDecoderImplementationName(const char* implementation_name); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 48 | |
pbos | 1968d3f | 2015-09-28 08:52:18 -0700 | [diff] [blame] | 49 | void Map(uint32_t timestamp, VCMFrameInformation* frameInfo); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 50 | int32_t Pop(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 52 | private: |
fischman@webrtc.org | e001b57 | 2013-06-04 03:29:37 +0000 | [diff] [blame] | 53 | // Protect |_receiveCallback| and |_timestampMap|. |
stefan@webrtc.org | 7889a9b | 2011-12-12 08:18:24 +0000 | [diff] [blame] | 54 | CriticalSectionWrapper* _critSect; |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 55 | Clock* _clock; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 56 | VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 57 | VCMTiming* _timing; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 58 | VCMTimestampMap _timestampMap GUARDED_BY(_critSect); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 59 | uint64_t _lastReceivedPictureID; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 62 | class VCMGenericDecoder { |
| 63 | friend class VCMCodecDataBase; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 64 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 65 | public: |
| 66 | explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); |
| 67 | ~VCMGenericDecoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 69 | /** |
| 70 | * Initialize the decoder with the information from the VideoCodec |
| 71 | */ |
| 72 | int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 74 | /** |
| 75 | * Decode to a raw I420 frame, |
| 76 | * |
| 77 | * inputVideoBuffer reference to encoded video frame |
| 78 | */ |
| 79 | int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 81 | /** |
| 82 | * Free the decoder memory |
| 83 | */ |
| 84 | int32_t Release(); |
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 | /** |
| 87 | * Reset the decoder state, prepare for a new call |
| 88 | */ |
| 89 | int32_t Reset(); |
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 | /** |
| 92 | * Set decode callback. Deregistering while decoding is illegal. |
| 93 | */ |
| 94 | int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
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 | bool External() const; |
| 97 | bool PrefersLateDecoding() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 99 | private: |
| 100 | VCMDecodedFrameCallback* _callback; |
| 101 | VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; |
| 102 | uint32_t _nextFrameInfoIdx; |
| 103 | VideoDecoder* const _decoder; |
| 104 | VideoCodecType _codecType; |
| 105 | bool _isExternal; |
| 106 | bool _keyFrameDecoded; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 109 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame^] | 111 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |