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 | |
| 20 | namespace webrtc |
| 21 | { |
| 22 | |
| 23 | class VCMReceiveCallback; |
| 24 | |
| 25 | enum { kDecoderFrameMemoryLength = 10 }; |
| 26 | |
| 27 | struct VCMFrameInformation |
| 28 | { |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 29 | int64_t renderTimeMs; |
| 30 | int64_t decodeStartTimeMs; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | void* userData; |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 32 | VideoRotation rotation; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | class VCMDecodedFrameCallback : public DecodedImageCallback |
| 36 | { |
| 37 | public: |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 38 | VCMDecodedFrameCallback(VCMTiming& timing, Clock* clock); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 39 | virtual ~VCMDecodedFrameCallback(); |
| 40 | void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback); |
wuchengli@chromium.org | 0d94c2f | 2013-08-12 14:20:49 +0000 | [diff] [blame] | 41 | VCMReceiveCallback* UserReceiveCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 43 | virtual int32_t Decoded(VideoFrame& decodedImage); |
Per | 327d8ba | 2015-11-10 14:00:27 +0100 | [diff] [blame] | 44 | virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms); |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 45 | virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId); |
| 46 | virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId); |
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 | |
| 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); |
stefan@webrtc.org | 7889a9b | 2011-12-12 08:18:24 +0000 | [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 | |
| 64 | |
| 65 | class VCMGenericDecoder |
| 66 | { |
| 67 | friend class VCMCodecDataBase; |
| 68 | public: |
Peter Boström | 187db63 | 2015-12-01 17:20:01 +0100 | [diff] [blame] | 69 | VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | ~VCMGenericDecoder(); |
| 71 | |
| 72 | /** |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 73 | * Initialize the decoder with the information from the VideoCodec |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 75 | int32_t InitDecode(const VideoCodec* settings, |
mikhal@webrtc.org | b2c28c3 | 2013-08-23 21:54:50 +0000 | [diff] [blame] | 76 | int32_t numberOfCores); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
| 78 | /** |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 79 | * Decode to a raw I420 frame, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | * |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 81 | * inputVideoBuffer reference to encoded video frame |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 83 | int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
| 85 | /** |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 86 | * Free the decoder memory |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 88 | int32_t Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | |
| 90 | /** |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 91 | * Reset the decoder state, prepare for a new call |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 93 | int32_t Reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
fischman@webrtc.org | e001b57 | 2013-06-04 03:29:37 +0000 | [diff] [blame] | 96 | * Set decode callback. Deregistering while decoding is illegal. |
| 97 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 98 | int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | |
| 100 | bool External() const; |
perkj | 796cfaf | 2015-12-10 09:27:38 -0800 | [diff] [blame] | 101 | bool PrefersLateDecoding() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 102 | |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 103 | private: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | VCMDecodedFrameCallback* _callback; |
| 105 | VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength]; |
stefan@webrtc.org | 34c5da6 | 2014-04-11 14:08:35 +0000 | [diff] [blame] | 106 | uint32_t _nextFrameInfoIdx; |
Peter Boström | 187db63 | 2015-12-01 17:20:01 +0100 | [diff] [blame] | 107 | VideoDecoder* const _decoder; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | VideoCodecType _codecType; |
| 109 | bool _isExternal; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 110 | bool _keyFrameDecoded; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 113 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
| 115 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_ |