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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_ |
| 13 | |
pbos@webrtc.org | a440732 | 2013-07-16 12:32:05 +0000 | [diff] [blame] | 14 | #include "webrtc/typedefs.h" |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | // Forward declarations |
| 19 | class VCMFrameBuffer; |
| 20 | class VCMPacket; |
| 21 | |
| 22 | class VCMDecodingState { |
| 23 | public: |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 24 | // The max number of bits used to reference back |
| 25 | // to a previous frame when using flexible mode. |
| 26 | static const uint16_t kNumRefBits = 7; |
| 27 | static const uint16_t kFrameDecodedLength = 1 << kNumRefBits; |
| 28 | |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 29 | VCMDecodingState(); |
| 30 | ~VCMDecodingState(); |
| 31 | // Check for old frame |
| 32 | bool IsOldFrame(const VCMFrameBuffer* frame) const; |
| 33 | // Check for old packet |
| 34 | bool IsOldPacket(const VCMPacket* packet) const; |
| 35 | // Check for frame continuity based on current decoded state. Use best method |
| 36 | // possible, i.e. temporal info, picture ID or sequence number. |
| 37 | bool ContinuousFrame(const VCMFrameBuffer* frame) const; |
| 38 | void SetState(const VCMFrameBuffer* frame); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 39 | void CopyFrom(const VCMDecodingState& state); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 40 | bool UpdateEmptyFrame(const VCMFrameBuffer* frame); |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 41 | // 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] | 42 | // sequence number is higher than the current one. This accounts for packets |
| 43 | // arriving late. |
| 44 | void UpdateOldPacket(const VCMPacket* packet); |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 45 | void SetSeqNum(uint16_t new_seq_num); |
| 46 | void Reset(); |
| 47 | uint32_t time_stamp() const; |
| 48 | uint16_t sequence_num() const; |
| 49 | // Return true if at initial state. |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 50 | bool in_initial_state() const; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 51 | // Return true when sync is on - decode all layers. |
| 52 | bool full_sync() const; |
| 53 | |
| 54 | private: |
| 55 | void UpdateSyncState(const VCMFrameBuffer* frame); |
| 56 | // Designated continuity functions |
| 57 | bool ContinuousPictureId(int picture_id) const; |
| 58 | bool ContinuousSeqNum(uint16_t seq_num) const; |
| 59 | bool ContinuousLayer(int temporal_id, int tl0_pic_id) const; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 60 | bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const; |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 61 | bool UsingPictureId(const VCMFrameBuffer* frame) const; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 62 | bool UsingFlexibleMode(const VCMFrameBuffer* frame) const; |
| 63 | bool AheadOfFramesDecodedClearedTo(uint16_t index) const; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 64 | |
| 65 | // Keep state of last decoded frame. |
| 66 | // TODO(mikhal/stefan): create designated classes to handle these types. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 67 | uint16_t sequence_num_; |
| 68 | uint32_t time_stamp_; |
| 69 | int picture_id_; |
| 70 | int temporal_id_; |
| 71 | int tl0_pic_id_; |
| 72 | bool full_sync_; // Sync flag when temporal layers are used. |
| 73 | bool in_initial_state_; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 74 | |
| 75 | // Used to check references in flexible mode. |
| 76 | bool frame_decoded_[kFrameDecodedLength]; |
| 77 | uint16_t frame_decoded_cleared_to_; |
mikhal@webrtc.org | 832caca | 2011-12-13 21:15:05 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace webrtc |
| 81 | |
| 82 | #endif // WEBRTC_MODULES_VIDEO_CODING_DECODING_STATE_H_ |