blob: 2999e9ad84d85a35d809597eb22b3cbdb33c5ca0 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:251/*
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 Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_VIDEO_CODING_SESSION_INFO_H_
12#define MODULES_VIDEO_CODING_SESSION_INFO_H_
niklase@google.com470e71d2011-07-07 08:21:2513
stefan@webrtc.org076fa6e2011-12-13 07:54:5614#include <list>
stefana669a3a2016-10-06 12:04:5215#include <vector>
niklase@google.com470e71d2011-07-07 08:21:2516
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/include/module_common_types.h"
18#include "modules/video_coding/include/video_coding.h"
19#include "modules/video_coding/packet.h"
Mirko Bonadei71207422017-09-15 11:58:0920#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:2521
stefan@webrtc.org076fa6e2011-12-13 07:54:5622namespace webrtc {
agalusza@google.comd818dcb2013-07-29 21:48:1123// Used to pass data from jitter buffer to session info.
24// This data is then used in determining whether a frame is decodable.
25struct FrameData {
pkasting@chromium.org16825b12015-01-12 21:51:2126 int64_t rtt_ms;
agalusza@google.comd818dcb2013-07-29 21:48:1127 float rolling_average_packets_per_frame;
28};
stefan@webrtc.orgc3d89102011-09-08 06:50:2829
stefan@webrtc.org076fa6e2011-12-13 07:54:5630class VCMSessionInfo {
31 public:
32 VCMSessionInfo();
niklase@google.com470e71d2011-07-07 08:21:2533
stefan@webrtc.orgb07aa402012-01-10 11:45:0534 void UpdateDataPointers(const uint8_t* old_base_ptr,
35 const uint8_t* new_base_ptr);
mikhal@webrtc.orgcd648862012-01-03 23:59:4236 // 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.orgbf535b92013-01-28 08:48:1340 int seq_num_list_length,
41 int nack_seq_nums_index);
niklase@google.com470e71d2011-07-07 08:21:2542
mikhal@webrtc.orgcd648862012-01-03 23:59:4243 // 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.orgbf535b92013-01-28 08:48:1347 int nack_seq_nums_index,
mikhal@webrtc.orgcd648862012-01-03 23:59:4248 int rtt_ms);
stefan@webrtc.org076fa6e2011-12-13 07:54:5649 void Reset();
50 int InsertPacket(const VCMPacket& packet,
51 uint8_t* frame_buffer,
agalusza@google.coma7e360e2013-08-01 03:15:0852 VCMDecodeErrorMode enable_decodable_state,
agalusza@google.comd818dcb2013-07-29 21:48:1153 const FrameData& frame_data);
stefan@webrtc.org076fa6e2011-12-13 07:54:5654 bool complete() const;
55 bool decodable() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:2856
stefan@webrtc.org076fa6e2011-12-13 07:54:5657 // 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.org4591fbd2014-11-20 22:28:1461 size_t MakeDecodable();
agalusza@google.comd177c102013-08-08 01:12:3362
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.orgdbf6a812013-08-21 20:40:4767 void SetNotDecodableIfIncomplete();
agalusza@google.comd177c102013-08-08 01:12:3368
pkasting@chromium.org4591fbd2014-11-20 22:28:1469 size_t SessionLength() const;
agalusza@google.comd818dcb2013-07-29 21:48:1170 int NumPackets() const;
stefan@webrtc.org885cd132013-04-16 09:38:2671 bool HaveFirstPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:5672 bool HaveLastPacket() const;
73 bool session_nack() const;
74 webrtc::FrameType FrameType() const { return frame_type_; }
75 int LowSequenceNumber() const;
niklase@google.com470e71d2011-07-07 08:21:2576
stefan@webrtc.org076fa6e2011-12-13 07:54:5677 // Returns highest sequence number, media or empty.
78 int HighSequenceNumber() const;
79 int PictureId() const;
80 int TemporalId() const;
henrik.lundin@webrtc.orgeda86dc2011-12-13 14:11:0681 bool LayerSync() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:5682 int Tl0PicId() const;
83 bool NonReference() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:2884
stefana669a3a2016-10-06 12:04:5285 std::vector<NaluInfo> GetNaluInfos() const;
86
asapersson9a4cd872015-10-23 07:27:1487 void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
88
stefan@webrtc.org076fa6e2011-12-13 07:54:5689 // The number of packets discarded because the decoder can't make use of
90 // them.
91 int packets_not_decodable() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:2892
stefan@webrtc.org076fa6e2011-12-13 07:54:5693 private:
94 enum { kMaxVP8Partitions = 9 };
niklase@google.com470e71d2011-07-07 08:21:2595
stefan@webrtc.org076fa6e2011-12-13 07:54:5696 typedef std::list<VCMPacket> PacketList;
97 typedef PacketList::iterator PacketIterator;
98 typedef PacketList::const_iterator PacketIteratorConst;
99 typedef PacketList::reverse_iterator ReversePacketIterator;
niklase@google.com470e71d2011-07-07 08:21:25100
stefan@webrtc.org076fa6e2011-12-13 07:54:56101 void InformOfEmptyPacket(uint16_t seq_num);
niklase@google.com470e71d2011-07-07 08:21:25102
stefan@webrtc.org076fa6e2011-12-13 07:54:56103 // 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.org2b810bf2013-09-03 19:09:49108 PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
niklase@google.com470e71d2011-07-07 08:21:25109
stefan@webrtc.org076fa6e2011-12-13 07:54:56110 // 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);
philipel9d3ab612015-12-21 12:12:39115 size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
stefan@webrtc.org2ec56062014-07-31 14:59:24116 size_t Insert(const uint8_t* buffer,
117 size_t length,
118 bool insert_start_code,
119 uint8_t* frame_buffer);
stefan@webrtc.org076fa6e2011-12-13 07:54:56120 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.
philipel9d3ab612015-12-21 12:12:39124 size_t DeletePacketData(PacketIterator start, PacketIterator end);
stefan@webrtc.org076fa6e2011-12-13 07:54:56125 void UpdateCompleteSession();
niklase@google.com470e71d2011-07-07 08:21:25126
stefan@webrtc.org076fa6e2011-12-13 07:54:56127 // When enabled, determine if session is decodable, i.e. incomplete but
128 // would be sent to the decoder.
agalusza@google.comd818dcb2013-07-29 21:48:11129 // 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.com470e71d2011-07-07 08:21:25144
stefan@webrtc.org076fa6e2011-12-13 07:54:56145 // 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.org076fa6e2011-12-13 07:54:56150 // Packets in this frame.
151 PacketList packets_;
152 int empty_seq_num_low_;
153 int empty_seq_num_high_;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11154
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.com470e71d2011-07-07 08:21:25162};
163
stefan@webrtc.org076fa6e2011-12-13 07:54:56164} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25165
Mirko Bonadei92ea95e2017-09-15 04:47:31166#endif // MODULES_VIDEO_CODING_SESSION_INFO_H_