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 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; FrameType()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 69 void SetGofInfo(const GofInfoVP9& gof_info, size_t idx); 70 71 private: 72 enum { kMaxVP8Partitions = 9 }; 73 74 typedef std::list<VCMPacket> PacketList; 75 typedef PacketList::iterator PacketIterator; 76 typedef PacketList::const_iterator PacketIteratorConst; 77 typedef PacketList::reverse_iterator ReversePacketIterator; 78 79 void InformOfEmptyPacket(uint16_t seq_num); 80 81 // Finds the packet of the beginning of the next VP8 partition. If 82 // none is found the returned iterator points to |packets_.end()|. 83 // |it| is expected to point to the last packet of the previous partition, 84 // or to the first packet of the frame. |packets_skipped| is incremented 85 // for each packet found which doesn't have the beginning bit set. 86 PacketIterator FindNextPartitionBeginning(PacketIterator it) const; 87 88 // Returns an iterator pointing to the last packet of the partition pointed to 89 // by |it|. 90 PacketIterator FindPartitionEnd(PacketIterator it) const; 91 static bool InSequence(const PacketIterator& it, 92 const PacketIterator& prev_it); 93 size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator); 94 size_t Insert(const uint8_t* buffer, 95 size_t length, 96 bool insert_start_code, 97 uint8_t* frame_buffer); 98 void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift); 99 PacketIterator FindNaluEnd(PacketIterator packet_iter) const; 100 // Deletes the data of all packets between |start| and |end|, inclusively. 101 // Note that this function doesn't delete the actual packets. 102 size_t DeletePacketData(PacketIterator start, PacketIterator end); 103 void UpdateCompleteSession(); 104 105 bool complete_; 106 webrtc::VideoFrameType frame_type_; 107 // Packets in this frame. 108 PacketList packets_; 109 int empty_seq_num_low_; 110 int empty_seq_num_high_; 111 112 // The following two variables correspond to the first and last media packets 113 // in a session defined by the first packet flag and the marker bit. 114 // They are not necessarily equal to the front and back packets, as packets 115 // may enter out of order. 116 // TODO(mikhal): Refactor the list to use a map. 117 int first_packet_seq_num_; 118 int last_packet_seq_num_; 119 }; 120 121 } // namespace webrtc 122 123 #endif // MODULES_VIDEO_CODING_SESSION_INFO_H_ 124