mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_DECODING_STATE_H_ |
| 12 | #define MODULES_VIDEO_CODING_DECODING_STATE_H_ |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 13 | |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 14 | #include <map> |
| 15 | #include <set> |
| 16 | #include <vector> |
| 17 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 18 | #include "typedefs.h" // NOLINT(build/include) |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | // Forward declarations |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 23 | struct NaluInfo; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 24 | class VCMFrameBuffer; |
| 25 | class VCMPacket; |
| 26 | |
| 27 | class VCMDecodingState { |
| 28 | public: |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 29 | // 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.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 34 | 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.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 44 | void CopyFrom(const VCMDecodingState& state); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 45 | bool UpdateEmptyFrame(const VCMFrameBuffer* frame); |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 46 | // Update the sequence number if the timestamp matches current state and the |
mikhal@webrtc.org | 77c425b | 2012-01-03 20:35:25 +0000 | [diff] [blame] | 47 | // sequence number is higher than the current one. This accounts for packets |
| 48 | // arriving late. |
| 49 | void UpdateOldPacket(const VCMPacket* packet); |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 50 | 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.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 55 | bool in_initial_state() const; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 56 | // 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; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 65 | bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const; |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 66 | bool UsingPictureId(const VCMFrameBuffer* frame) const; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 67 | bool UsingFlexibleMode(const VCMFrameBuffer* frame) const; |
| 68 | bool AheadOfFramesDecodedClearedTo(uint16_t index) const; |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 69 | bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 70 | |
| 71 | // Keep state of last decoded frame. |
| 72 | // TODO(mikhal/stefan): create designated classes to handle these types. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 73 | 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_; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 80 | |
| 81 | // Used to check references in flexible mode. |
| 82 | bool frame_decoded_[kFrameDecodedLength]; |
| 83 | uint16_t frame_decoded_cleared_to_; |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 84 | std::set<int> received_sps_; |
| 85 | std::map<int, int> received_pps_; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // namespace webrtc |
| 89 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 90 | #endif // MODULES_VIDEO_CODING_DECODING_STATE_H_ |