niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_SESSION_INFO_H_ |
| 12 | #define MODULES_VIDEO_CODING_SESSION_INFO_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 13 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 14 | #include <list> |
stefan | a669a3a | 2016-10-06 12:04:52 | [diff] [blame] | 15 | #include <vector> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "modules/include/module_common_types.h" |
| 18 | #include "modules/video_coding/include/video_coding.h" |
| 19 | #include "modules/video_coding/packet.h" |
Mirko Bonadei | 7120742 | 2017-09-15 11:58:09 | [diff] [blame] | 20 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 21 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 22 | namespace webrtc { |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 | [diff] [blame] | 23 | // Used to pass data from jitter buffer to session info. |
| 24 | // This data is then used in determining whether a frame is decodable. |
| 25 | struct FrameData { |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 | [diff] [blame] | 26 | int64_t rtt_ms; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 | [diff] [blame] | 27 | float rolling_average_packets_per_frame; |
| 28 | }; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 | [diff] [blame] | 29 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 30 | class VCMSessionInfo { |
| 31 | public: |
| 32 | VCMSessionInfo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 33 | |
stefan@webrtc.org | b07aa40 | 2012-01-10 11:45:05 | [diff] [blame] | 34 | void UpdateDataPointers(const uint8_t* old_base_ptr, |
| 35 | const uint8_t* new_base_ptr); |
mikhal@webrtc.org | cd64886 | 2012-01-03 23:59:42 | [diff] [blame] | 36 | // NACK - Building the NACK lists. |
| 37 | // Build hard NACK list: Zero out all entries in list up to and including |
| 38 | // _lowSeqNum. |
| 39 | int BuildHardNackList(int* seq_num_list, |
stefan@webrtc.org | bf535b9 | 2013-01-28 08:48:13 | [diff] [blame] | 40 | int seq_num_list_length, |
| 41 | int nack_seq_nums_index); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 42 | |
mikhal@webrtc.org | cd64886 | 2012-01-03 23:59:42 | [diff] [blame] | 43 | // Build soft NACK list: Zero out only a subset of the packets, discard |
| 44 | // empty packets. |
| 45 | int BuildSoftNackList(int* seq_num_list, |
| 46 | int seq_num_list_length, |
stefan@webrtc.org | bf535b9 | 2013-01-28 08:48:13 | [diff] [blame] | 47 | int nack_seq_nums_index, |
mikhal@webrtc.org | cd64886 | 2012-01-03 23:59:42 | [diff] [blame] | 48 | int rtt_ms); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 49 | void Reset(); |
| 50 | int InsertPacket(const VCMPacket& packet, |
| 51 | uint8_t* frame_buffer, |
agalusza@google.com | a7e360e | 2013-08-01 03:15:08 | [diff] [blame] | 52 | VCMDecodeErrorMode enable_decodable_state, |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 | [diff] [blame] | 53 | const FrameData& frame_data); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 54 | bool complete() const; |
| 55 | bool decodable() const; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 | [diff] [blame] | 56 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 57 | // Makes the frame decodable. I.e., only contain decodable NALUs. All |
| 58 | // non-decodable NALUs will be deleted and packets will be moved to in |
| 59 | // memory to remove any empty space. |
| 60 | // Returns the number of bytes deleted from the session. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 61 | size_t MakeDecodable(); |
agalusza@google.com | d177c10 | 2013-08-08 01:12:33 | [diff] [blame] | 62 | |
| 63 | // Sets decodable_ to false. |
| 64 | // Used by the dual decoder. After the mode is changed to kNoErrors from |
| 65 | // kWithErrors or kSelective errors, any states that have been marked |
| 66 | // decodable and are not complete are marked as non-decodable. |
mikhal@webrtc.org | dbf6a81 | 2013-08-21 20:40:47 | [diff] [blame] | 67 | void SetNotDecodableIfIncomplete(); |
agalusza@google.com | d177c10 | 2013-08-08 01:12:33 | [diff] [blame] | 68 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 | [diff] [blame] | 69 | size_t SessionLength() const; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 | [diff] [blame] | 70 | int NumPackets() const; |
stefan@webrtc.org | 885cd13 | 2013-04-16 09:38:26 | [diff] [blame] | 71 | bool HaveFirstPacket() const; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 72 | bool HaveLastPacket() const; |
| 73 | bool session_nack() const; |
| 74 | webrtc::FrameType FrameType() const { return frame_type_; } |
| 75 | int LowSequenceNumber() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 76 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 77 | // Returns highest sequence number, media or empty. |
| 78 | int HighSequenceNumber() const; |
| 79 | int PictureId() const; |
| 80 | int TemporalId() const; |
henrik.lundin@webrtc.org | eda86dc | 2011-12-13 14:11:06 | [diff] [blame] | 81 | bool LayerSync() const; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 82 | int Tl0PicId() const; |
| 83 | bool NonReference() const; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 | [diff] [blame] | 84 | |
stefan | a669a3a | 2016-10-06 12:04:52 | [diff] [blame] | 85 | std::vector<NaluInfo> GetNaluInfos() const; |
| 86 | |
asapersson | 9a4cd87 | 2015-10-23 07:27:14 | [diff] [blame] | 87 | void SetGofInfo(const GofInfoVP9& gof_info, size_t idx); |
| 88 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 89 | // The number of packets discarded because the decoder can't make use of |
| 90 | // them. |
| 91 | int packets_not_decodable() const; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 | [diff] [blame] | 92 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 93 | private: |
| 94 | enum { kMaxVP8Partitions = 9 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 95 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 96 | typedef std::list<VCMPacket> PacketList; |
| 97 | typedef PacketList::iterator PacketIterator; |
| 98 | typedef PacketList::const_iterator PacketIteratorConst; |
| 99 | typedef PacketList::reverse_iterator ReversePacketIterator; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 100 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 101 | void InformOfEmptyPacket(uint16_t seq_num); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 102 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 103 | // Finds the packet of the beginning of the next VP8 partition. If |
| 104 | // none is found the returned iterator points to |packets_.end()|. |
| 105 | // |it| is expected to point to the last packet of the previous partition, |
| 106 | // or to the first packet of the frame. |packets_skipped| is incremented |
| 107 | // for each packet found which doesn't have the beginning bit set. |
mikhal@webrtc.org | 2b810bf | 2013-09-03 19:09:49 | [diff] [blame] | 108 | PacketIterator FindNextPartitionBeginning(PacketIterator it) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 109 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 110 | // Returns an iterator pointing to the last packet of the partition pointed to |
| 111 | // by |it|. |
| 112 | PacketIterator FindPartitionEnd(PacketIterator it) const; |
| 113 | static bool InSequence(const PacketIterator& it, |
| 114 | const PacketIterator& prev_it); |
philipel | 9d3ab61 | 2015-12-21 12:12:39 | [diff] [blame] | 115 | size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 | [diff] [blame] | 116 | size_t Insert(const uint8_t* buffer, |
| 117 | size_t length, |
| 118 | bool insert_start_code, |
| 119 | uint8_t* frame_buffer); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 120 | void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift); |
| 121 | PacketIterator FindNaluEnd(PacketIterator packet_iter) const; |
| 122 | // Deletes the data of all packets between |start| and |end|, inclusively. |
| 123 | // Note that this function doesn't delete the actual packets. |
philipel | 9d3ab61 | 2015-12-21 12:12:39 | [diff] [blame] | 124 | size_t DeletePacketData(PacketIterator start, PacketIterator end); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 125 | void UpdateCompleteSession(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 126 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 127 | // When enabled, determine if session is decodable, i.e. incomplete but |
| 128 | // would be sent to the decoder. |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 | [diff] [blame] | 129 | // Note: definition assumes random loss. |
| 130 | // A frame is defined to be decodable when: |
| 131 | // Round trip time is higher than threshold |
| 132 | // It is not a key frame |
| 133 | // It has the first packet: In VP8 the first packet contains all or part of |
| 134 | // the first partition, which consists of the most relevant information for |
| 135 | // decoding. |
| 136 | // Either more than the upper threshold of the average number of packets per |
| 137 | // frame is present |
| 138 | // or less than the lower threshold of the average number of packets per |
| 139 | // frame is present: suggests a small frame. Such a frame is unlikely |
| 140 | // to contain many motion vectors, so having the first packet will |
| 141 | // likely suffice. Once we have more than the lower threshold of the |
| 142 | // frame, we know that the frame is medium or large-sized. |
| 143 | void UpdateDecodableSession(const FrameData& frame_data); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 144 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 145 | // If this session has been NACKed by the jitter buffer. |
| 146 | bool session_nack_; |
| 147 | bool complete_; |
| 148 | bool decodable_; |
| 149 | webrtc::FrameType frame_type_; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 150 | // Packets in this frame. |
| 151 | PacketList packets_; |
| 152 | int empty_seq_num_low_; |
| 153 | int empty_seq_num_high_; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 | [diff] [blame] | 154 | |
| 155 | // The following two variables correspond to the first and last media packets |
| 156 | // in a session defined by the first packet flag and the marker bit. |
| 157 | // They are not necessarily equal to the front and back packets, as packets |
| 158 | // may enter out of order. |
| 159 | // TODO(mikhal): Refactor the list to use a map. |
| 160 | int first_packet_seq_num_; |
| 161 | int last_packet_seq_num_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 162 | }; |
| 163 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 | [diff] [blame] | 164 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 165 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 166 | #endif // MODULES_VIDEO_CODING_SESSION_INFO_H_ |