blob: b87fb2d0345c2e338102c914e919c5cef8b94369 [file] [log] [blame]
mikhal@webrtc.org832caca2011-12-13 21:15:05 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_DECODING_STATE_H_
12#define MODULES_VIDEO_CODING_DECODING_STATE_H_
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000013
stefana669a3a2016-10-06 05:04:52 -070014#include <map>
15#include <set>
16#include <vector>
17
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000018namespace webrtc {
19
20// Forward declarations
stefana669a3a2016-10-06 05:04:52 -070021struct NaluInfo;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000022class VCMFrameBuffer;
23class VCMPacket;
24
25class VCMDecodingState {
26 public:
philipelcfc319b2015-11-10 07:17:23 -080027 // The max number of bits used to reference back
28 // to a previous frame when using flexible mode.
29 static const uint16_t kNumRefBits = 7;
30 static const uint16_t kFrameDecodedLength = 1 << kNumRefBits;
31
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000032 VCMDecodingState();
33 ~VCMDecodingState();
34 // Check for old frame
35 bool IsOldFrame(const VCMFrameBuffer* frame) const;
36 // Check for old packet
37 bool IsOldPacket(const VCMPacket* packet) const;
38 // Check for frame continuity based on current decoded state. Use best method
39 // possible, i.e. temporal info, picture ID or sequence number.
40 bool ContinuousFrame(const VCMFrameBuffer* frame) const;
41 void SetState(const VCMFrameBuffer* frame);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000042 void CopyFrom(const VCMDecodingState& state);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000043 bool UpdateEmptyFrame(const VCMFrameBuffer* frame);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000044 // Update the sequence number if the timestamp matches current state and the
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +000045 // sequence number is higher than the current one. This accounts for packets
46 // arriving late.
47 void UpdateOldPacket(const VCMPacket* packet);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000048 void SetSeqNum(uint16_t new_seq_num);
49 void Reset();
50 uint32_t time_stamp() const;
51 uint16_t sequence_num() const;
52 // Return true if at initial state.
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000053 bool in_initial_state() const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000054 // Return true when sync is on - decode all layers.
55 bool full_sync() const;
56
57 private:
58 void UpdateSyncState(const VCMFrameBuffer* frame);
59 // Designated continuity functions
60 bool ContinuousPictureId(int picture_id) const;
61 bool ContinuousSeqNum(uint16_t seq_num) const;
62 bool ContinuousLayer(int temporal_id, int tl0_pic_id) const;
philipelcfc319b2015-11-10 07:17:23 -080063 bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +000064 bool UsingPictureId(const VCMFrameBuffer* frame) const;
philipelcfc319b2015-11-10 07:17:23 -080065 bool UsingFlexibleMode(const VCMFrameBuffer* frame) const;
66 bool AheadOfFramesDecodedClearedTo(uint16_t index) const;
stefana669a3a2016-10-06 05:04:52 -070067 bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000068
69 // Keep state of last decoded frame.
70 // TODO(mikhal/stefan): create designated classes to handle these types.
philipel9d3ab612015-12-21 04:12:39 -080071 uint16_t sequence_num_;
72 uint32_t time_stamp_;
73 int picture_id_;
74 int temporal_id_;
75 int tl0_pic_id_;
76 bool full_sync_; // Sync flag when temporal layers are used.
77 bool in_initial_state_;
philipelcfc319b2015-11-10 07:17:23 -080078
79 // Used to check references in flexible mode.
80 bool frame_decoded_[kFrameDecodedLength];
81 uint16_t frame_decoded_cleared_to_;
stefana669a3a2016-10-06 05:04:52 -070082 std::set<int> received_sps_;
83 std::map<int, int> received_pps_;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000084};
85
86} // namespace webrtc
87
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#endif // MODULES_VIDEO_CODING_DECODING_STATE_H_