xref: /aosp_15_r20/external/webrtc/modules/video_coding/decoding_state.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
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 
11 #ifndef MODULES_VIDEO_CODING_DECODING_STATE_H_
12 #define MODULES_VIDEO_CODING_DECODING_STATE_H_
13 
14 #include <cstdint>
15 #include <map>
16 #include <set>
17 #include <vector>
18 
19 namespace webrtc {
20 
21 // Forward declarations
22 struct NaluInfo;
23 class VCMFrameBuffer;
24 class VCMPacket;
25 
26 class VCMDecodingState {
27  public:
28   // 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 
33   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);
43   void CopyFrom(const VCMDecodingState& state);
44   bool UpdateEmptyFrame(const VCMFrameBuffer* frame);
45   // Update the sequence number if the timestamp matches current state and the
46   // sequence number is higher than the current one. This accounts for packets
47   // arriving late.
48   void UpdateOldPacket(const VCMPacket* packet);
49   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.
54   bool in_initial_state() const;
55   // 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;
64   bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const;
65   bool UsingPictureId(const VCMFrameBuffer* frame) const;
66   bool UsingFlexibleMode(const VCMFrameBuffer* frame) const;
67   bool AheadOfFramesDecodedClearedTo(uint16_t index) const;
68   bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const;
69 
70   // Keep state of last decoded frame.
71   // TODO(mikhal/stefan): create designated classes to handle these types.
72   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_;
79 
80   // Used to check references in flexible mode.
81   bool frame_decoded_[kFrameDecodedLength];
82   uint16_t frame_decoded_cleared_to_;
83   std::set<int> received_sps_;
84   std::map<int, int> received_pps_;
85 };
86 
87 }  // namespace webrtc
88 
89 #endif  // MODULES_VIDEO_CODING_DECODING_STATE_H_
90