| 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 <map> |
| 15 | #include <set> |
| 16 | #include <vector> |
| 17 |
| 18 | namespace webrtc { |
| 19 |
| 20 | // Forward declarations |
| 21 | struct NaluInfo; |
| 22 | class VCMFrameBuffer; |
| 23 | class VCMPacket; |
| 24 |
| 25 | class VCMDecodingState { |
| 26 | public: |
| 27 | // The max number of bits used to reference back |
| 28 | // to a previous frame when using flexible mode. |
| 29 | static const uint16_t kNumRefBits = 7; |
| 30 | static const uint16_t kFrameDecodedLength = 1 << kNumRefBits; |
| 31 |
| 32 | VCMDecodingState(); |
| 33 | ~VCMDecodingState(); |
| 34 | // Check for old frame |
| 35 | bool IsOldFrame(const VCMFrameBuffer* frame) const; |
| 36 | // Check for old packet |
| 37 | bool IsOldPacket(const VCMPacket* packet) const; |
| 38 | // Check for frame continuity based on current decoded state. Use best method |
| 39 | // possible, i.e. temporal info, picture ID or sequence number. |
| 40 | bool ContinuousFrame(const VCMFrameBuffer* frame) const; |
| 41 | void SetState(const VCMFrameBuffer* frame); |
| 42 | void CopyFrom(const VCMDecodingState& state); |
| 43 | bool UpdateEmptyFrame(const VCMFrameBuffer* frame); |
| 44 | // Update the sequence number if the timestamp matches current state and the |
| 45 | // sequence number is higher than the current one. This accounts for packets |
| 46 | // arriving late. |
| 47 | void UpdateOldPacket(const VCMPacket* packet); |
| 48 | void SetSeqNum(uint16_t new_seq_num); |
| 49 | void Reset(); |
| 50 | uint32_t time_stamp() const; |
| 51 | uint16_t sequence_num() const; |
| 52 | // Return true if at initial state. |
| 53 | bool in_initial_state() const; |
| 54 | // Return true when sync is on - decode all layers. |
| 55 | bool full_sync() const; |
| 56 |
| 57 | private: |
| 58 | void UpdateSyncState(const VCMFrameBuffer* frame); |
| 59 | // Designated continuity functions |
| 60 | bool ContinuousPictureId(int picture_id) const; |
| 61 | bool ContinuousSeqNum(uint16_t seq_num) const; |
| 62 | bool ContinuousLayer(int temporal_id, int tl0_pic_id) const; |
| 63 | bool ContinuousFrameRefs(const VCMFrameBuffer* frame) const; |
| 64 | bool UsingPictureId(const VCMFrameBuffer* frame) const; |
| 65 | bool UsingFlexibleMode(const VCMFrameBuffer* frame) const; |
| 66 | bool AheadOfFramesDecodedClearedTo(uint16_t index) const; |
| 67 | bool HaveSpsAndPps(const std::vector<NaluInfo>& nalus) const; |
| 68 |
| 69 | // Keep state of last decoded frame. |
| 70 | // TODO(mikhal/stefan): create designated classes to handle these types. |
| 71 | uint16_t sequence_num_; |
| 72 | uint32_t time_stamp_; |
| 73 | int picture_id_; |
| 74 | int temporal_id_; |
| 75 | int tl0_pic_id_; |
| 76 | bool full_sync_; // Sync flag when temporal layers are used. |
| 77 | bool in_initial_state_; |
| 78 |
| 79 | // Used to check references in flexible mode. |
| 80 | bool frame_decoded_[kFrameDecodedLength]; |
| 81 | uint16_t frame_decoded_cleared_to_; |
| 82 | std::set<int> received_sps_; |
| 83 | std::map<int, int> received_pps_; |
| 84 | }; |
| 85 |
| 86 | } // namespace webrtc |
| 87 |
| 88 | #endif // MODULES_VIDEO_CODING_DECODING_STATE_H_ |
| 89 |