blob: 172d0929f7e0da169ecf4d8f832a80bad6792822 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_SESSION_INFO_H_
12#define MODULES_VIDEO_CODING_SESSION_INFO_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000016#include <list>
stefana669a3a2016-10-06 05:04:52 -070017#include <vector>
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Yves Gerey3e707812018-11-28 16:47:49 +010019#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 Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/video_coding/include/video_coding.h"
23#include "modules/video_coding/packet.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000025namespace webrtc {
agalusza@google.comd818dcb2013-07-29 21:48:11 +000026// Used to pass data from jitter buffer to session info.
27// This data is then used in determining whether a frame is decodable.
28struct FrameData {
pkasting@chromium.org16825b12015-01-12 21:51:21 +000029 int64_t rtt_ms;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000030 float rolling_average_packets_per_frame;
31};
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000032
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000033class VCMSessionInfo {
34 public:
35 VCMSessionInfo();
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020036 ~VCMSessionInfo();
niklase@google.com470e71d2011-07-07 08:21:25 +000037
stefan@webrtc.orgb07aa402012-01-10 11:45:05 +000038 void UpdateDataPointers(const uint8_t* old_base_ptr,
39 const uint8_t* new_base_ptr);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000040 void Reset();
41 int InsertPacket(const VCMPacket& packet,
42 uint8_t* frame_buffer,
agalusza@google.coma7e360e2013-08-01 03:15:08 +000043 VCMDecodeErrorMode enable_decodable_state,
agalusza@google.comd818dcb2013-07-29 21:48:11 +000044 const FrameData& frame_data);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000045 bool complete() const;
46 bool decodable() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000047
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000048 // Makes the frame decodable. I.e., only contain decodable NALUs. All
49 // non-decodable NALUs will be deleted and packets will be moved to in
50 // memory to remove any empty space.
51 // Returns the number of bytes deleted from the session.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000052 size_t MakeDecodable();
agalusza@google.comd177c102013-08-08 01:12:33 +000053
Niels Möller425f7132018-06-08 15:17:41 +020054 // TODO(nisse): Used by tests only.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000055 size_t SessionLength() const;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000056 int NumPackets() const;
stefan@webrtc.org885cd132013-04-16 09:38:26 +000057 bool HaveFirstPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000058 bool HaveLastPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000059 webrtc::FrameType FrameType() const { return frame_type_; }
60 int LowSequenceNumber() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000062 // Returns highest sequence number, media or empty.
63 int HighSequenceNumber() const;
64 int PictureId() const;
65 int TemporalId() const;
henrik.lundin@webrtc.orgeda86dc2011-12-13 14:11:06 +000066 bool LayerSync() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000067 int Tl0PicId() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000068
stefana669a3a2016-10-06 05:04:52 -070069 std::vector<NaluInfo> GetNaluInfos() const;
70
asapersson9a4cd872015-10-23 00:27:14 -070071 void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
72
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000073 private:
74 enum { kMaxVP8Partitions = 9 };
niklase@google.com470e71d2011-07-07 08:21:25 +000075
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000076 typedef std::list<VCMPacket> PacketList;
77 typedef PacketList::iterator PacketIterator;
78 typedef PacketList::const_iterator PacketIteratorConst;
79 typedef PacketList::reverse_iterator ReversePacketIterator;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000081 void InformOfEmptyPacket(uint16_t seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000083 // Finds the packet of the beginning of the next VP8 partition. If
84 // none is found the returned iterator points to |packets_.end()|.
85 // |it| is expected to point to the last packet of the previous partition,
86 // or to the first packet of the frame. |packets_skipped| is incremented
87 // for each packet found which doesn't have the beginning bit set.
mikhal@webrtc.org2b810bf2013-09-03 19:09:49 +000088 PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000089
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000090 // Returns an iterator pointing to the last packet of the partition pointed to
91 // by |it|.
92 PacketIterator FindPartitionEnd(PacketIterator it) const;
93 static bool InSequence(const PacketIterator& it,
94 const PacketIterator& prev_it);
philipel9d3ab612015-12-21 04:12:39 -080095 size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000096 size_t Insert(const uint8_t* buffer,
97 size_t length,
98 bool insert_start_code,
99 uint8_t* frame_buffer);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000100 void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift);
101 PacketIterator FindNaluEnd(PacketIterator packet_iter) const;
102 // Deletes the data of all packets between |start| and |end|, inclusively.
103 // Note that this function doesn't delete the actual packets.
philipel9d3ab612015-12-21 04:12:39 -0800104 size_t DeletePacketData(PacketIterator start, PacketIterator end);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000105 void UpdateCompleteSession();
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000107 // When enabled, determine if session is decodable, i.e. incomplete but
108 // would be sent to the decoder.
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000109 // Note: definition assumes random loss.
110 // A frame is defined to be decodable when:
111 // Round trip time is higher than threshold
112 // It is not a key frame
113 // It has the first packet: In VP8 the first packet contains all or part of
114 // the first partition, which consists of the most relevant information for
115 // decoding.
116 // Either more than the upper threshold of the average number of packets per
117 // frame is present
118 // or less than the lower threshold of the average number of packets per
119 // frame is present: suggests a small frame. Such a frame is unlikely
120 // to contain many motion vectors, so having the first packet will
121 // likely suffice. Once we have more than the lower threshold of the
122 // frame, we know that the frame is medium or large-sized.
123 void UpdateDecodableSession(const FrameData& frame_data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000125 bool complete_;
126 bool decodable_;
127 webrtc::FrameType frame_type_;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000128 // Packets in this frame.
129 PacketList packets_;
130 int empty_seq_num_low_;
131 int empty_seq_num_high_;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000132
133 // The following two variables correspond to the first and last media packets
134 // in a session defined by the first packet flag and the marker bit.
135 // They are not necessarily equal to the front and back packets, as packets
136 // may enter out of order.
137 // TODO(mikhal): Refactor the list to use a map.
138 int first_packet_seq_num_;
139 int last_packet_seq_num_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000140};
141
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000142} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000143
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200144#endif // MODULES_VIDEO_CODING_SESSION_INFO_H_