blob: 02a932b80b38cdea338628906880b72b248f0fb6 [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
Mirko Bonadei71207422017-09-15 13:58:09 +020018#include "typedefs.h" // NOLINT(build/include)
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000019
20namespace webrtc {
21
22// Forward declarations
stefana669a3a2016-10-06 05:04:52 -070023struct NaluInfo;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000024class VCMFrameBuffer;
25class VCMPacket;
26
27class VCMDecodingState {
28 public:
philipelcfc319b2015-11-10 07:17:23 -080029 // The max number of bits used to reference back
30 // to a previous frame when using flexible mode.
31 static const uint16_t kNumRefBits = 7;
32 static const uint16_t kFrameDecodedLength = 1 << kNumRefBits;
33
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000034 VCMDecodingState();
35 ~VCMDecodingState();
36 // Check for old frame
37 bool IsOldFrame(const VCMFrameBuffer* frame) const;
38 // Check for old packet
39 bool IsOldPacket(const VCMPacket* packet) const;
40 // Check for frame continuity based on current decoded state. Use best method
41 // possible, i.e. temporal info, picture ID or sequence number.
42 bool ContinuousFrame(const VCMFrameBuffer* frame) const;
43 void SetState(const VCMFrameBuffer* frame);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000044 void CopyFrom(const VCMDecodingState& state);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000045 bool UpdateEmptyFrame(const VCMFrameBuffer* frame);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000046 // Update the sequence number if the timestamp matches current state and the
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +000047 // sequence number is higher than the current one. This accounts for packets
48 // arriving late.
49 void UpdateOldPacket(const VCMPacket* packet);
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000050 void SetSeqNum(uint16_t new_seq_num);
51 void Reset();
52 uint32_t time_stamp() const;
53 uint16_t sequence_num() const;
54 // Return true if at initial state.
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000055 bool in_initial_state() const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000056 // Return true when sync is on - decode all layers.
57 bool full_sync() const;
58
59 private:
60 void UpdateSyncState(const VCMFrameBuffer* frame);
61 // Designated continuity functions
62 bool ContinuousPictureId(int picture_id) const;
63 bool ContinuousSeqNum(uint16_t seq_num) const;
64 bool ContinuousLayer(int temporal_id, int tl0_pic_id) const;
philipelcfc319b2015-11-10 07:17:23 -080065 bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +000066 bool UsingPictureId(const VCMFrameBuffer* frame) const;
philipelcfc319b2015-11-10 07:17:23 -080067 bool UsingFlexibleMode(const VCMFrameBuffer* frame) const;
68 bool AheadOfFramesDecodedClearedTo(uint16_t index) const;
stefana669a3a2016-10-06 05:04:52 -070069 bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000070
71 // Keep state of last decoded frame.
72 // TODO(mikhal/stefan): create designated classes to handle these types.
philipel9d3ab612015-12-21 04:12:39 -080073 uint16_t sequence_num_;
74 uint32_t time_stamp_;
75 int picture_id_;
76 int temporal_id_;
77 int tl0_pic_id_;
78 bool full_sync_; // Sync flag when temporal layers are used.
79 bool in_initial_state_;
philipelcfc319b2015-11-10 07:17:23 -080080
81 // Used to check references in flexible mode.
82 bool frame_decoded_[kFrameDecodedLength];
83 uint16_t frame_decoded_cleared_to_;
stefana669a3a2016-10-06 05:04:52 -070084 std::set<int> received_sps_;
85 std::map<int, int> received_pps_;
mikhal@webrtc.org832caca2011-12-13 21:15:05 +000086};
87
88} // namespace webrtc
89
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020090#endif // MODULES_VIDEO_CODING_DECODING_STATE_H_