blob: 67ceabfc5382278ad83bd6c4bde31ec6ab8433ff [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
philipel9d3ab612015-12-21 04:12:39 -080040 virtual int32_t Decoded(VideoFrame& decodedImage); // NOLINT
41 virtual int32_t Decoded(VideoFrame& decodedImage, // NOLINT
42 int64_t decode_time_ms);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000043 virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId);
44 virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId);
niklase@google.com470e71d2011-07-07 08:21:25 +000045
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000046 uint64_t LastReceivedPictureID() const;
Peter Boströmb7d9a972015-12-18 16:01:11 +010047 void OnDecoderImplementationName(const char* implementation_name);
niklase@google.com470e71d2011-07-07 08:21:25 +000048
pbos1968d3f2015-09-28 08:52:18 -070049 void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000050 int32_t Pop(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +000051
philipel9d3ab612015-12-21 04:12:39 -080052 private:
fischman@webrtc.orge001b572013-06-04 03:29:37 +000053 // Protect |_receiveCallback| and |_timestampMap|.
stefan@webrtc.org7889a9b2011-12-12 08:18:24 +000054 CriticalSectionWrapper* _critSect;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000055 Clock* _clock;
Peter Boströmb7d9a972015-12-18 16:01:11 +010056 VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect);
philipel9d3ab612015-12-21 04:12:39 -080057 VCMTiming* _timing;
Peter Boströmb7d9a972015-12-18 16:01:11 +010058 VCMTimestampMap _timestampMap GUARDED_BY(_critSect);
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000059 uint64_t _lastReceivedPictureID;
niklase@google.com470e71d2011-07-07 08:21:25 +000060};
61
philipel9d3ab612015-12-21 04:12:39 -080062class VCMGenericDecoder {
63 friend class VCMCodecDataBase;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
philipel9d3ab612015-12-21 04:12:39 -080065 public:
66 explicit VCMGenericDecoder(VideoDecoder* decoder, bool isExternal = false);
67 ~VCMGenericDecoder();
niklase@google.com470e71d2011-07-07 08:21:25 +000068
philipel9d3ab612015-12-21 04:12:39 -080069 /**
70 * Initialize the decoder with the information from the VideoCodec
71 */
72 int32_t InitDecode(const VideoCodec* settings, int32_t numberOfCores);
niklase@google.com470e71d2011-07-07 08:21:25 +000073
philipel9d3ab612015-12-21 04:12:39 -080074 /**
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.com470e71d2011-07-07 08:21:25 +000080
philipel9d3ab612015-12-21 04:12:39 -080081 /**
82 * Free the decoder memory
83 */
84 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000085
philipel9d3ab612015-12-21 04:12:39 -080086 /**
87 * Reset the decoder state, prepare for a new call
88 */
89 int32_t Reset();
niklase@google.com470e71d2011-07-07 08:21:25 +000090
philipel9d3ab612015-12-21 04:12:39 -080091 /**
92 * Set decode callback. Deregistering while decoding is illegal.
93 */
94 int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000095
philipel9d3ab612015-12-21 04:12:39 -080096 bool External() const;
97 bool PrefersLateDecoding() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000098
philipel9d3ab612015-12-21 04:12:39 -080099 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.com470e71d2011-07-07 08:21:25 +0000107};
108
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000109} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000110
philipel9d3ab612015-12-21 04:12:39 -0800111#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_