blob: 48e25196e93d74b3618792c64d70a8239b2c5231 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
mikhal@webrtc.orga2031d52012-07-31 15:53:442 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:253 *
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 07:31:5214#include "webrtc/modules/include/module_common_types.h"
Henrik Kjellander2557b862015-11-18 21:00:2115#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:2519
philipel9d3ab612015-12-21 12:12:3920namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:2521
22class VCMReceiveCallback;
23
24enum { kDecoderFrameMemoryLength = 10 };
25
philipel9d3ab612015-12-21 12:12:3926struct VCMFrameInformation {
27 int64_t renderTimeMs;
28 int64_t decodeStartTimeMs;
29 void* userData;
30 VideoRotation rotation;
niklase@google.com470e71d2011-07-07 08:21:2531};
32
philipel9d3ab612015-12-21 12:12:3933class VCMDecodedFrameCallback : public DecodedImageCallback {
34 public:
35 VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
niklase@google.com470e71d2011-07-07 08:21:2536 virtual ~VCMDecodedFrameCallback();
37 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
wuchengli@chromium.org0d94c2f2013-08-12 14:20:4938 VCMReceiveCallback* UserReceiveCallback();
niklase@google.com470e71d2011-07-07 08:21:2539
sakalcc452e12017-02-09 12:53:4540 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:2547
pbos@webrtc.org7b859cc2013-04-02 15:54:3848 uint64_t LastReceivedPictureID() const;
Peter Boströmb7d9a972015-12-18 15:01:1149 void OnDecoderImplementationName(const char* implementation_name);
niklase@google.com470e71d2011-07-07 08:21:2550
pbos1968d3f2015-09-28 15:52:1851 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
pbos@webrtc.org7b859cc2013-04-02 15:54:3852 int32_t Pop(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:2553
philipel9d3ab612015-12-21 12:12:3954 private:
fischman@webrtc.orge001b572013-06-04 03:29:3755 // Protect |_receiveCallback| and |_timestampMap|.
stefan@webrtc.org7889a9b2011-12-12 08:18:2456 CriticalSectionWrapper* _critSect;
stefan@webrtc.orga678a3b2013-01-21 07:42:1157 Clock* _clock;
Peter Boströmb7d9a972015-12-18 15:01:1158 VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect);
philipel9d3ab612015-12-21 12:12:3959 VCMTiming* _timing;
Peter Boströmb7d9a972015-12-18 15:01:1160 VCMTimestampMap _timestampMap GUARDED_BY(_critSect);
pbos@webrtc.org7b859cc2013-04-02 15:54:3861 uint64_t _lastReceivedPictureID;
niklase@google.com470e71d2011-07-07 08:21:2562};
63
philipel9d3ab612015-12-21 12:12:3964class VCMGenericDecoder {
65 friend class VCMCodecDataBase;
niklase@google.com470e71d2011-07-07 08:21:2566
philipel9d3ab612015-12-21 12:12:3967 public:
68 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
69 ~VCMGenericDecoder();
niklase@google.com470e71d2011-07-07 08:21:2570
philipel9d3ab612015-12-21 12:12:3971 /**
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:2575
philipel9d3ab612015-12-21 12:12:3976 /**
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:2582
philipel9d3ab612015-12-21 12:12:3983 /**
84 * Free the decoder memory
85 */
86 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:2587
philipel9d3ab612015-12-21 12:12:3988 /**
philipel9d3ab612015-12-21 12:12:3989 * Set decode callback. Deregistering while decoding is illegal.
90 */
91 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:2592
philipel9d3ab612015-12-21 12:12:3993 bool External() const;
94 bool PrefersLateDecoding() const;
niklase@google.com470e71d2011-07-07 08:21:2595
philipel9d3ab612015-12-21 12:12:3996 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:25104};
105
pbos@webrtc.orgd900e8b2013-07-03 15:12:26106} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25107
philipel9d3ab612015-12-21 12:12:39108#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_