blob: d79b5e59f22213995942d0cdbc86cc6abf95fb30 [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
20namespace webrtc
21{
22
23class VCMReceiveCallback;
24
25enum { kDecoderFrameMemoryLength = 10 };
26
27struct VCMFrameInformation
28{
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000029 int64_t renderTimeMs;
30 int64_t decodeStartTimeMs;
niklase@google.com470e71d2011-07-07 08:21:25 +000031 void* userData;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000032 VideoRotation rotation;
niklase@google.com470e71d2011-07-07 08:21:25 +000033};
34
35class VCMDecodedFrameCallback : public DecodedImageCallback
36{
37public:
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000038 VCMDecodedFrameCallback(VCMTiming& timing, Clock* clock);
niklase@google.com470e71d2011-07-07 08:21:25 +000039 virtual ~VCMDecodedFrameCallback();
40 void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
wuchengli@chromium.org0d94c2f2013-08-12 14:20:49 +000041 VCMReceiveCallback* UserReceiveCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +000042
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070043 virtual int32_t Decoded(VideoFrame& decodedImage);
Per327d8ba2015-11-10 14:00:27 +010044 virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000045 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId);
46 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId);
niklase@google.com470e71d2011-07-07 08:21:25 +000047
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000048 uint64_t LastReceivedPictureID() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000049
pbos1968d3f2015-09-28 08:52:18 -070050 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000051 int32_t Pop(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +000052
53private:
fischman@webrtc.orge001b572013-06-04 03:29:37 +000054 // Protect |_receiveCallback| and |_timestampMap|.
stefan@webrtc.org7889a9b2011-12-12 08:18:24 +000055 CriticalSectionWrapper* _critSect;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000056 Clock* _clock;
fischman@webrtc.orge001b572013-06-04 03:29:37 +000057 VCMReceiveCallback* _receiveCallback; // Guarded by |_critSect|.
stefan@webrtc.org7889a9b2011-12-12 08:18:24 +000058 VCMTiming& _timing;
fischman@webrtc.orge001b572013-06-04 03:29:37 +000059 VCMTimestampMap _timestampMap; // Guarded by |_critSect|.
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000060 uint64_t _lastReceivedPictureID;
niklase@google.com470e71d2011-07-07 08:21:25 +000061};
62
63
64class VCMGenericDecoder
65{
66 friend class VCMCodecDataBase;
67public:
kjellanderec192bd2015-11-30 23:14:33 -080068 VCMGenericDecoder(VideoDecoder& decoder, bool isExternal = false);
niklase@google.com470e71d2011-07-07 08:21:25 +000069 ~VCMGenericDecoder();
70
71 /**
Henrik Kjellander2557b862015-11-18 22:00:21 +010072 * Initialize the decoder with the information from the VideoCodec
niklase@google.com470e71d2011-07-07 08:21:25 +000073 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000074 int32_t InitDecode(const VideoCodec* settings,
mikhal@webrtc.orgb2c28c32013-08-23 21:54:50 +000075 int32_t numberOfCores);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
77 /**
Henrik Kjellander2557b862015-11-18 22:00:21 +010078 * Decode to a raw I420 frame,
niklase@google.com470e71d2011-07-07 08:21:25 +000079 *
Henrik Kjellander2557b862015-11-18 22:00:21 +010080 * inputVideoBuffer reference to encoded video frame
niklase@google.com470e71d2011-07-07 08:21:25 +000081 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000082 int32_t Decode(const VCMEncodedFrame& inputFrame, int64_t nowMs);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
84 /**
Henrik Kjellander2557b862015-11-18 22:00:21 +010085 * Free the decoder memory
niklase@google.com470e71d2011-07-07 08:21:25 +000086 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000087 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000088
89 /**
Henrik Kjellander2557b862015-11-18 22:00:21 +010090 * Reset the decoder state, prepare for a new call
niklase@google.com470e71d2011-07-07 08:21:25 +000091 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000092 int32_t Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +000093
94 /**
fischman@webrtc.orge001b572013-06-04 03:29:37 +000095 * Set decode callback. Deregistering while decoding is illegal.
96 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000097 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000098
99 bool External() const;
100
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000101private:
niklase@google.com470e71d2011-07-07 08:21:25 +0000102 VCMDecodedFrameCallback* _callback;
103 VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength];
stefan@webrtc.org34c5da62014-04-11 14:08:35 +0000104 uint32_t _nextFrameInfoIdx;
kjellanderec192bd2015-11-30 23:14:33 -0800105 VideoDecoder& _decoder;
niklase@google.com470e71d2011-07-07 08:21:25 +0000106 VideoCodecType _codecType;
107 bool _isExternal;
niklase@google.com470e71d2011-07-07 08:21:25 +0000108 bool _keyFrameDecoded;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109};
110
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000111} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
113#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_