blob: 48e25196e93d74b3618792c64d70a8239b2c5231 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mikhal@webrtc.orga2031d52012-07-31 15:53:44 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Kjellanderff761fb2015-11-04 08:31:52 +010014#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander2557b862015-11-18 22:00:21 +010015#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.com470e71d2011-07-07 08:21:25 +000019
philipel9d3ab612015-12-21 04:12:39 -080020namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000021
22class VCMReceiveCallback;
23
24enum { kDecoderFrameMemoryLength = 10 };
25
philipel9d3ab612015-12-21 04:12:39 -080026struct VCMFrameInformation {
27 int64_t renderTimeMs;
28 int64_t decodeStartTimeMs;
29 void* userData;
30 VideoRotation rotation;
niklase@google.com470e71d2011-07-07 08:21:25 +000031};
32
philipel9d3ab612015-12-21 04:12:39 -080033class VCMDecodedFrameCallback : public DecodedImageCallback {
34 public:
35 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
niklase@google.com470e71d2011-07-07 08:21:25 +000036 virtual ~VCMDecodedFrameCallback();
37 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
wuchengli@chromium.org0d94c2f2013-08-12 14:20:49 +000038 VCMReceiveCallback* UserReceiveCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +000039
sakalcc452e12017-02-09 04:53:45 -080040 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.com470e71d2011-07-07 08:21:25 +000047
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000048 uint64_t LastReceivedPictureID() const;
Peter Boströmb7d9a972015-12-18 16:01:11 +010049 void OnDecoderImplementationName(const char* implementation_name);
niklase@google.com470e71d2011-07-07 08:21:25 +000050
pbos1968d3f2015-09-28 08:52:18 -070051 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000052 int32_t Pop(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +000053
philipel9d3ab612015-12-21 04:12:39 -080054 private:
fischman@webrtc.orge001b572013-06-04 03:29:37 +000055 // Protect |_receiveCallback| and |_timestampMap|.
stefan@webrtc.org7889a9b2011-12-12 08:18:24 +000056 CriticalSectionWrapper* _critSect;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000057 Clock* _clock;
Peter Boströmb7d9a972015-12-18 16:01:11 +010058 VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect);
philipel9d3ab612015-12-21 04:12:39 -080059 VCMTiming* _timing;
Peter Boströmb7d9a972015-12-18 16:01:11 +010060 VCMTimestampMap _timestampMap GUARDED_BY(_critSect);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000061 uint64_t _lastReceivedPictureID;
niklase@google.com470e71d2011-07-07 08:21:25 +000062};
63
philipel9d3ab612015-12-21 04:12:39 -080064class VCMGenericDecoder {
65 friend class VCMCodecDataBase;
niklase@google.com470e71d2011-07-07 08:21:25 +000066
philipel9d3ab612015-12-21 04:12:39 -080067 public:
68 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
69 ~VCMGenericDecoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000070
philipel9d3ab612015-12-21 04:12:39 -080071 /**
72 * Initialize the decoder with the information from the VideoCodec
73 */
74 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
philipel9d3ab612015-12-21 04:12:39 -080076 /**
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.com470e71d2011-07-07 08:21:25 +000082
philipel9d3ab612015-12-21 04:12:39 -080083 /**
84 * Free the decoder memory
85 */
86 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000087
philipel9d3ab612015-12-21 04:12:39 -080088 /**
philipel9d3ab612015-12-21 04:12:39 -080089 * Set decode callback. Deregistering while decoding is illegal.
90 */
91 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000092
philipel9d3ab612015-12-21 04:12:39 -080093 bool External() const;
94 bool PrefersLateDecoding() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000095
philipel9d3ab612015-12-21 04:12:39 -080096 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.com470e71d2011-07-07 08:21:25 +0000104};
105
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000106} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
philipel9d3ab612015-12-21 04:12:39 -0800108#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_