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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [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 +0000 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 16 | #include <list> |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 17 | #include <vector> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include "common_types.h" // NOLINT(build/include) |
| 20 | #include "modules/video_coding/codecs/h264/include/h264_globals.h" |
| 21 | #include "modules/video_coding/codecs/vp9/include/vp9_globals.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/video_coding/include/video_coding.h" |
| 23 | #include "modules/video_coding/packet.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 25 | namespace webrtc { |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 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 { |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 29 | int64_t rtt_ms; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 30 | float rolling_average_packets_per_frame; |
| 31 | }; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 32 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 33 | class VCMSessionInfo { |
| 34 | public: |
| 35 | VCMSessionInfo(); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 36 | ~VCMSessionInfo(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | |
stefan@webrtc.org | b07aa40 | 2012-01-10 11:45:05 +0000 | [diff] [blame] | 38 | void UpdateDataPointers(const uint8_t* old_base_ptr, |
| 39 | const uint8_t* new_base_ptr); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 40 | void Reset(); |
| 41 | int InsertPacket(const VCMPacket& packet, |
| 42 | uint8_t* frame_buffer, |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 43 | const FrameData& frame_data); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 44 | bool complete() const; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 45 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 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. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 50 | size_t MakeDecodable(); |
agalusza@google.com | d177c10 | 2013-08-08 01:12:33 +0000 | [diff] [blame] | 51 | |
Niels Möller | 425f713 | 2018-06-08 15:17:41 +0200 | [diff] [blame] | 52 | // TODO(nisse): Used by tests only. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 53 | size_t SessionLength() const; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 54 | int NumPackets() const; |
stefan@webrtc.org | 885cd13 | 2013-04-16 09:38:26 +0000 | [diff] [blame] | 55 | bool HaveFirstPacket() const; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 56 | bool HaveLastPacket() const; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 57 | webrtc::FrameType FrameType() const { return frame_type_; } |
| 58 | int LowSequenceNumber() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 60 | // Returns highest sequence number, media or empty. |
| 61 | int HighSequenceNumber() const; |
| 62 | int PictureId() const; |
| 63 | int TemporalId() const; |
henrik.lundin@webrtc.org | eda86dc | 2011-12-13 14:11:06 +0000 | [diff] [blame] | 64 | bool LayerSync() const; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 65 | int Tl0PicId() const; |
stefan@webrtc.org | c3d8910 | 2011-09-08 06:50:28 +0000 | [diff] [blame] | 66 | |
stefan | a669a3a | 2016-10-06 05:04:52 -0700 | [diff] [blame] | 67 | std::vector<NaluInfo> GetNaluInfos() const; |
| 68 | |
asapersson | 9a4cd87 | 2015-10-23 00:27:14 -0700 | [diff] [blame] | 69 | void SetGofInfo(const GofInfoVP9& gof_info, size_t idx); |
| 70 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 71 | private: |
| 72 | enum { kMaxVP8Partitions = 9 }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 74 | typedef std::list<VCMPacket> PacketList; |
| 75 | typedef PacketList::iterator PacketIterator; |
| 76 | typedef PacketList::const_iterator PacketIteratorConst; |
| 77 | typedef PacketList::reverse_iterator ReversePacketIterator; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 79 | void InformOfEmptyPacket(uint16_t seq_num); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 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. |
mikhal@webrtc.org | 2b810bf | 2013-09-03 19:09:49 +0000 | [diff] [blame] | 86 | PacketIterator FindNextPartitionBeginning(PacketIterator it) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 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); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 93 | size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator); |
stefan@webrtc.org | 2ec5606 | 2014-07-31 14:59:24 +0000 | [diff] [blame] | 94 | size_t Insert(const uint8_t* buffer, |
| 95 | size_t length, |
| 96 | bool insert_start_code, |
| 97 | uint8_t* frame_buffer); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 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. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 102 | size_t DeletePacketData(PacketIterator start, PacketIterator end); |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 103 | void UpdateCompleteSession(); |
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 | bool complete_; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 106 | webrtc::FrameType frame_type_; |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 107 | // Packets in this frame. |
| 108 | PacketList packets_; |
| 109 | int empty_seq_num_low_; |
| 110 | int empty_seq_num_high_; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 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_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | }; |
| 120 | |
stefan@webrtc.org | 076fa6e | 2011-12-13 07:54:56 +0000 | [diff] [blame] | 121 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 123 | #endif // MODULES_VIDEO_CODING_SESSION_INFO_H_ |