decoding_state.h 3.0 KB

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