session_info.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_SESSION_INFO_H_
  11. #define MODULES_VIDEO_CODING_SESSION_INFO_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <list>
  15. #include <vector>
  16. #include "modules/video_coding/codecs/h264/include/h264_globals.h"
  17. #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
  18. #include "modules/video_coding/include/video_coding.h"
  19. #include "modules/video_coding/packet.h"
  20. namespace webrtc {
  21. // Used to pass data from jitter buffer to session info.
  22. // This data is then used in determining whether a frame is decodable.
  23. struct FrameData {
  24. int64_t rtt_ms;
  25. float rolling_average_packets_per_frame;
  26. };
  27. class VCMSessionInfo {
  28. public:
  29. VCMSessionInfo();
  30. ~VCMSessionInfo();
  31. void UpdateDataPointers(const uint8_t* old_base_ptr,
  32. const uint8_t* new_base_ptr);
  33. void Reset();
  34. int InsertPacket(const VCMPacket& packet,
  35. uint8_t* frame_buffer,
  36. const FrameData& frame_data);
  37. bool complete() const;
  38. // Makes the frame decodable. I.e., only contain decodable NALUs. All
  39. // non-decodable NALUs will be deleted and packets will be moved to in
  40. // memory to remove any empty space.
  41. // Returns the number of bytes deleted from the session.
  42. size_t MakeDecodable();
  43. // TODO(nisse): Used by tests only.
  44. size_t SessionLength() const;
  45. int NumPackets() const;
  46. bool HaveFirstPacket() const;
  47. bool HaveLastPacket() const;
  48. webrtc::VideoFrameType FrameType() const { return frame_type_; }
  49. int LowSequenceNumber() const;
  50. // Returns highest sequence number, media or empty.
  51. int HighSequenceNumber() const;
  52. int PictureId() const;
  53. int TemporalId() const;
  54. bool LayerSync() const;
  55. int Tl0PicId() const;
  56. std::vector<NaluInfo> GetNaluInfos() const;
  57. void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
  58. private:
  59. enum { kMaxVP8Partitions = 9 };
  60. typedef std::list<VCMPacket> PacketList;
  61. typedef PacketList::iterator PacketIterator;
  62. typedef PacketList::const_iterator PacketIteratorConst;
  63. typedef PacketList::reverse_iterator ReversePacketIterator;
  64. void InformOfEmptyPacket(uint16_t seq_num);
  65. // Finds the packet of the beginning of the next VP8 partition. If
  66. // none is found the returned iterator points to |packets_.end()|.
  67. // |it| is expected to point to the last packet of the previous partition,
  68. // or to the first packet of the frame. |packets_skipped| is incremented
  69. // for each packet found which doesn't have the beginning bit set.
  70. PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
  71. // Returns an iterator pointing to the last packet of the partition pointed to
  72. // by |it|.
  73. PacketIterator FindPartitionEnd(PacketIterator it) const;
  74. static bool InSequence(const PacketIterator& it,
  75. const PacketIterator& prev_it);
  76. size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
  77. size_t Insert(const uint8_t* buffer,
  78. size_t length,
  79. bool insert_start_code,
  80. uint8_t* frame_buffer);
  81. void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift);
  82. PacketIterator FindNaluEnd(PacketIterator packet_iter) const;
  83. // Deletes the data of all packets between |start| and |end|, inclusively.
  84. // Note that this function doesn't delete the actual packets.
  85. size_t DeletePacketData(PacketIterator start, PacketIterator end);
  86. void UpdateCompleteSession();
  87. bool complete_;
  88. webrtc::VideoFrameType frame_type_;
  89. // Packets in this frame.
  90. PacketList packets_;
  91. int empty_seq_num_low_;
  92. int empty_seq_num_high_;
  93. // The following two variables correspond to the first and last media packets
  94. // in a session defined by the first packet flag and the marker bit.
  95. // They are not necessarily equal to the front and back packets, as packets
  96. // may enter out of order.
  97. // TODO(mikhal): Refactor the list to use a map.
  98. int first_packet_seq_num_;
  99. int last_packet_seq_num_;
  100. };
  101. } // namespace webrtc
  102. #endif // MODULES_VIDEO_CODING_SESSION_INFO_H_