blob: b845ffb54648715c52dae2e2f10db8e754ec12cd [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
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000014#include <list>
stefana669a3a2016-10-06 05:04:52 -070015#include <vector>
niklase@google.com470e71d2011-07-07 08:21:25 +000016
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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 13:58:09 +020020#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000021
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000022namespace webrtc {
agalusza@google.comd818dcb2013-07-29 21:48:11 +000023// 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:21 +000026 int64_t rtt_ms;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000027 float rolling_average_packets_per_frame;
28};
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000029
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000030class VCMSessionInfo {
31 public:
32 VCMSessionInfo();
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020033 ~VCMSessionInfo();
niklase@google.com470e71d2011-07-07 08:21:25 +000034
stefan@webrtc.orgb07aa402012-01-10 11:45:05 +000035 void UpdateDataPointers(const uint8_t* old_base_ptr,
36 const uint8_t* new_base_ptr);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000037 void Reset();
38 int InsertPacket(const VCMPacket& packet,
39 uint8_t* frame_buffer,
agalusza@google.coma7e360e2013-08-01 03:15:08 +000040 VCMDecodeErrorMode enable_decodable_state,
agalusza@google.comd818dcb2013-07-29 21:48:11 +000041 const FrameData& frame_data);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000042 bool complete() const;
43 bool decodable() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000044
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000045 // Makes the frame decodable. I.e., only contain decodable NALUs. All
46 // non-decodable NALUs will be deleted and packets will be moved to in
47 // memory to remove any empty space.
48 // Returns the number of bytes deleted from the session.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000049 size_t MakeDecodable();
agalusza@google.comd177c102013-08-08 01:12:33 +000050
Niels Möller425f7132018-06-08 15:17:41 +020051 // TODO(nisse): Used by tests only.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000052 size_t SessionLength() const;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000053 int NumPackets() const;
stefan@webrtc.org885cd132013-04-16 09:38:26 +000054 bool HaveFirstPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000055 bool HaveLastPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000056 webrtc::FrameType FrameType() const { return frame_type_; }
57 int LowSequenceNumber() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000059 // Returns highest sequence number, media or empty.
60 int HighSequenceNumber() const;
61 int PictureId() const;
62 int TemporalId() const;
henrik.lundin@webrtc.orgeda86dc2011-12-13 14:11:06 +000063 bool LayerSync() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000064 int Tl0PicId() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000065
stefana669a3a2016-10-06 05:04:52 -070066 std::vector<NaluInfo> GetNaluInfos() const;
67
asapersson9a4cd872015-10-23 00:27:14 -070068 void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
69
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000070 private:
71 enum { kMaxVP8Partitions = 9 };
niklase@google.com470e71d2011-07-07 08:21:25 +000072
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000073 typedef std::list<VCMPacket> PacketList;
74 typedef PacketList::iterator PacketIterator;
75 typedef PacketList::const_iterator PacketIteratorConst;
76 typedef PacketList::reverse_iterator ReversePacketIterator;
niklase@google.com470e71d2011-07-07 08:21:25 +000077
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000078 void InformOfEmptyPacket(uint16_t seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +000079
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000080 // Finds the packet of the beginning of the next VP8 partition. If
81 // none is found the returned iterator points to |packets_.end()|.
82 // |it| is expected to point to the last packet of the previous partition,
83 // or to the first packet of the frame. |packets_skipped| is incremented
84 // for each packet found which doesn't have the beginning bit set.
mikhal@webrtc.org2b810bf2013-09-03 19:09:49 +000085 PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000087 // Returns an iterator pointing to the last packet of the partition pointed to
88 // by |it|.
89 PacketIterator FindPartitionEnd(PacketIterator it) const;
90 static bool InSequence(const PacketIterator& it,
91 const PacketIterator& prev_it);
philipel9d3ab612015-12-21 04:12:39 -080092 size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000093 size_t Insert(const uint8_t* buffer,
94 size_t length,
95 bool insert_start_code,
96 uint8_t* frame_buffer);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000097 void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift);
98 PacketIterator FindNaluEnd(PacketIterator packet_iter) const;
99 // Deletes the data of all packets between |start| and |end|, inclusively.
100 // Note that this function doesn't delete the actual packets.
philipel9d3ab612015-12-21 04:12:39 -0800101 size_t DeletePacketData(PacketIterator start, PacketIterator end);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000102 void UpdateCompleteSession();
niklase@google.com470e71d2011-07-07 08:21:25 +0000103
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000104 // When enabled, determine if session is decodable, i.e. incomplete but
105 // would be sent to the decoder.
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000106 // Note: definition assumes random loss.
107 // A frame is defined to be decodable when:
108 // Round trip time is higher than threshold
109 // It is not a key frame
110 // It has the first packet: In VP8 the first packet contains all or part of
111 // the first partition, which consists of the most relevant information for
112 // decoding.
113 // Either more than the upper threshold of the average number of packets per
114 // frame is present
115 // or less than the lower threshold of the average number of packets per
116 // frame is present: suggests a small frame. Such a frame is unlikely
117 // to contain many motion vectors, so having the first packet will
118 // likely suffice. Once we have more than the lower threshold of the
119 // frame, we know that the frame is medium or large-sized.
120 void UpdateDecodableSession(const FrameData& frame_data);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000122 bool complete_;
123 bool decodable_;
124 webrtc::FrameType frame_type_;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000125 // Packets in this frame.
126 PacketList packets_;
127 int empty_seq_num_low_;
128 int empty_seq_num_high_;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000129
130 // The following two variables correspond to the first and last media packets
131 // in a session defined by the first packet flag and the marker bit.
132 // They are not necessarily equal to the front and back packets, as packets
133 // may enter out of order.
134 // TODO(mikhal): Refactor the list to use a map.
135 int first_packet_seq_num_;
136 int last_packet_seq_num_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000137};
138
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000139} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000140
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200141#endif // MODULES_VIDEO_CODING_SESSION_INFO_H_