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