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