123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef VIDEO_JBUFFER_DECODING_STATE_H_
- #define VIDEO_JBUFFER_DECODING_STATE_H_
- #include <map>
- #include <set>
- #include <vector>
- #include <limits>
- #include "stdint.h"
- #include "../adaptive_jitter_buffer/video_jbuff_frame.h"
- namespace AJB {
- template <typename U>
- inline bool IsNewer(U value, U prev_value) {
- //static_assert(!std::numeric_limits<U>::is_signed, "U must be unsigned");
- // kBreakpoint is the half-way mark for the type U. For instance, for a
- // uint16_t it will be 0x8000, and for a uint32_t, it will be 0x8000000.
- const U kBreakpoint = (std::numeric_limits<U>::max() >> 1) + 1;
- // Distinguish between elements that are exactly kBreakpoint apart.
- // If t1>t2 and |t1-t2| = kBreakpoint: IsNewer(t1,t2)=true,
- // IsNewer(t2,t1)=false
- // rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false.
- if (value - prev_value == kBreakpoint) {
- return value > prev_value;
- }
- return value != prev_value &&
- static_cast<U>(value - prev_value) < kBreakpoint;
- }
- inline bool IsNewerSequenceNumber(uint16_t sequence_number,
- uint16_t prev_sequence_number) {
- return IsNewer(sequence_number, prev_sequence_number);
- }
- // NB: Doesn't fulfill strict weak ordering requirements.
- // Mustn't be used as std::map Compare function.
- inline bool IsNewerTimestamp(uint32_t timestamp, uint32_t prev_timestamp) {
- return IsNewer(timestamp, prev_timestamp);
- }
- inline uint16_t LatestSequenceNumber(uint16_t sequence_number1,
- uint16_t sequence_number2) {
- return IsNewerSequenceNumber(sequence_number1, sequence_number2)
- ? sequence_number1
- : sequence_number2;
- }
- inline uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2) {
- return IsNewerTimestamp(timestamp1, timestamp2) ? timestamp1 : timestamp2;
- }
- class DecodingState {
- public:
- DecodingState();
- ~DecodingState();
- // Check for old frame
- bool IsOldFrame(const Frame* frame);
- // Check for old packet
- bool IsOldPacket(const Packet* packet);
- // Check for frame continuity based on current decoded state. Use best method
- // possible, i.e. temporal info, picture ID or sequence number.
- bool ContinuousFrame(const Frame* frame);
- void SetState(const Frame* frame);
- void CopyFrom(const DecodingState& state);
- // Update the sequence number if the timestamp matches current state and the
- // sequence number is higher than the current one. This accounts for packets
- // arriving late.
- void UpdateOldPacket(const Packet* packet);
- void SetSeqNum(uint16_t new_seq_num);
- void Reset();
- uint32_t time_stamp() const;
- uint16_t sequence_num() const;
- // Return true if at initial state.
- bool in_initial_state() const;
- private:
- // Designated continuity functions
- bool ContinuousSeqNum(uint16_t seq_num);
- // Keep state of last decoded frame.
- // TODO(mikhal/stefan): create designated classes to handle these types.
- uint16_t sequence_num_;
- uint32_t time_stamp_;
-
- bool in_initial_state_;
- };
- } // namespace AJB
- #endif // VIDEO_JBUFFER_DECODING_STATE_H_
|