blob: d66101c95f4760526d2cd7e2d9f3e32c7c91fe12 [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.comd818dcb2013-07-29 21:48:11 +000043 const FrameData& frame_data);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000044 bool complete() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000045
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000046 // 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.org4591fbd2014-11-20 22:28:14 +000050 size_t MakeDecodable();
agalusza@google.comd177c102013-08-08 01:12:33 +000051
Niels Möller425f7132018-06-08 15:17:41 +020052 // TODO(nisse): Used by tests only.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000053 size_t SessionLength() const;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000054 int NumPackets() const;
stefan@webrtc.org885cd132013-04-16 09:38:26 +000055 bool HaveFirstPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000056 bool HaveLastPacket() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000057 webrtc::FrameType FrameType() const { return frame_type_; }
58 int LowSequenceNumber() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000059
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000060 // Returns highest sequence number, media or empty.
61 int HighSequenceNumber() const;
62 int PictureId() const;
63 int TemporalId() const;
henrik.lundin@webrtc.orgeda86dc2011-12-13 14:11:06 +000064 bool LayerSync() const;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000065 int Tl0PicId() const;
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000066
stefana669a3a2016-10-06 05:04:52 -070067 std::vector<NaluInfo> GetNaluInfos() const;
68
asapersson9a4cd872015-10-23 00:27:14 -070069 void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
70
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000071 private:
72 enum { kMaxVP8Partitions = 9 };
niklase@google.com470e71d2011-07-07 08:21:25 +000073
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000074 typedef std::list<VCMPacket> PacketList;
75 typedef PacketList::iterator PacketIterator;
76 typedef PacketList::const_iterator PacketIteratorConst;
77 typedef PacketList::reverse_iterator ReversePacketIterator;
niklase@google.com470e71d2011-07-07 08:21:25 +000078
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000079 void InformOfEmptyPacket(uint16_t seq_num);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000081 // 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.org2b810bf2013-09-03 19:09:49 +000086 PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
niklase@google.com470e71d2011-07-07 08:21:25 +000087
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000088 // 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);
philipel9d3ab612015-12-21 04:12:39 -080093 size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
stefan@webrtc.org2ec56062014-07-31 14:59:24 +000094 size_t Insert(const uint8_t* buffer,
95 size_t length,
96 bool insert_start_code,
97 uint8_t* frame_buffer);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000098 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.
philipel9d3ab612015-12-21 04:12:39 -0800102 size_t DeletePacketData(PacketIterator start, PacketIterator end);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000103 void UpdateCompleteSession();
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000105 bool complete_;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000106 webrtc::FrameType frame_type_;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000107 // Packets in this frame.
108 PacketList packets_;
109 int empty_seq_num_low_;
110 int empty_seq_num_high_;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000111
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.com470e71d2011-07-07 08:21:25 +0000119};
120
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000121} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200123#endif // MODULES_VIDEO_CODING_SESSION_INFO_H_