blob: ec972949d891933ed717413675873e4c07c4763d [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
Aaron Clauson5d6abbd2021-03-14 15:37:35 +000014#include <cstdint>
stefana669a3a2016-10-06 05:04:52 -070015#include <map>
16#include <set>
17#include <vector>
18
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000019namespace webrtc {
20
21// Forward declarations
stefana669a3a2016-10-06 05:04:52 -070022struct NaluInfo;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000023class VCMFrameBuffer;
24class VCMPacket;
25
26class VCMDecodingState {
27 public:
philipelcfc319b2015-11-10 07:17:23 -080028 // The max number of bits used to reference back
29 // to a previous frame when using flexible mode.
30 static const uint16_t kNumRefBits = 7;
31 static const uint16_t kFrameDecodedLength = 1 << kNumRefBits;
32
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000033 VCMDecodingState();
34 ~VCMDecodingState();
35 // Check for old frame
36 bool IsOldFrame(const VCMFrameBuffer* frame) const;
37 // Check for old packet
38 bool IsOldPacket(const VCMPacket* packet) const;
39 // Check for frame continuity based on current decoded state. Use best method
40 // possible, i.e. temporal info, picture ID or sequence number.
41 bool ContinuousFrame(const VCMFrameBuffer* frame) const;
42 void SetState(const VCMFrameBuffer* frame);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000043 void CopyFrom(const VCMDecodingState& state);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000044 bool UpdateEmptyFrame(const VCMFrameBuffer* frame);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000045 // Update the sequence number if the timestamp matches current state and the
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +000046 // sequence number is higher than the current one. This accounts for packets
47 // arriving late.
48 void UpdateOldPacket(const VCMPacket* packet);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000049 void SetSeqNum(uint16_t new_seq_num);
50 void Reset();
51 uint32_t time_stamp() const;
52 uint16_t sequence_num() const;
53 // Return true if at initial state.
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000054 bool in_initial_state() const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000055 // Return true when sync is on - decode all layers.
56 bool full_sync() const;
57
58 private:
59 void UpdateSyncState(const VCMFrameBuffer* frame);
60 // Designated continuity functions
61 bool ContinuousPictureId(int picture_id) const;
62 bool ContinuousSeqNum(uint16_t seq_num) const;
63 bool ContinuousLayer(int temporal_id, int tl0_pic_id) const;
philipelcfc319b2015-11-10 07:17:23 -080064 bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +000065 bool UsingPictureId(const VCMFrameBuffer* frame) const;
philipelcfc319b2015-11-10 07:17:23 -080066 bool UsingFlexibleMode(const VCMFrameBuffer* frame) const;
67 bool AheadOfFramesDecodedClearedTo(uint16_t index) const;
stefana669a3a2016-10-06 05:04:52 -070068 bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000069
70 // Keep state of last decoded frame.
71 // TODO(mikhal/stefan): create designated classes to handle these types.
philipel9d3ab612015-12-21 04:12:39 -080072 uint16_t sequence_num_;
73 uint32_t time_stamp_;
74 int picture_id_;
75 int temporal_id_;
76 int tl0_pic_id_;
77 bool full_sync_; // Sync flag when temporal layers are used.
78 bool in_initial_state_;
philipelcfc319b2015-11-10 07:17:23 -080079
80 // Used to check references in flexible mode.
81 bool frame_decoded_[kFrameDecodedLength];
82 uint16_t frame_decoded_cleared_to_;
stefana669a3a2016-10-06 05:04:52 -070083 std::set<int> received_sps_;
84 std::map<int, int> received_pps_;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000085};
86
87} // namespace webrtc
88
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#endif // MODULES_VIDEO_CODING_DECODING_STATE_H_