blob: 02c423661e19574209af7b819d619f94563719ad [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 "modules/video_coding/codecs/h264/include/h264_globals.h"
20#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/video_coding/include/video_coding.h"
22#include "modules/video_coding/packet.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000024namespace webrtc {
agalusza@google.comd818dcb2013-07-29 21:48:11 +000025// Used to pass data from jitter buffer to session info.
26// This data is then used in determining whether a frame is decodable.
27struct FrameData {
pkasting@chromium.org16825b12015-01-12 21:51:21 +000028 int64_t rtt_ms;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000029 float rolling_average_packets_per_frame;
30};
stefan@webrtc.orgc3d89102011-09-08 06:50:28 +000031
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000032class VCMSessionInfo {
33 public:
34 VCMSessionInfo();
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020035 ~VCMSessionInfo();
niklase@google.com470e71d2011-07-07 08:21:25 +000036
stefan@webrtc.orgb07aa402012-01-10 11:45:05 +000037 void UpdateDataPointers(const uint8_t* old_base_ptr,
38 const uint8_t* new_base_ptr);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000039 void Reset();
40 int InsertPacket(const VCMPacket& packet,
41 uint8_t* frame_buffer,
agalusza@google.comd818dcb2013-07-29 21:48:11 +000042 const FrameData& frame_data);
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000043 bool complete() 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;
Niels Möller87e2d782019-03-07 10:18:23 +010056 webrtc::VideoFrameType FrameType() const { return frame_type_; }
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +000057 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 bool complete_;
Niels Möller87e2d782019-03-07 10:18:23 +0100105 webrtc::VideoFrameType frame_type_;
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000106 // Packets in this frame.
107 PacketList packets_;
108 int empty_seq_num_low_;
109 int empty_seq_num_high_;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000110
111 // The following two variables correspond to the first and last media packets
112 // in a session defined by the first packet flag and the marker bit.
113 // They are not necessarily equal to the front and back packets, as packets
114 // may enter out of order.
115 // TODO(mikhal): Refactor the list to use a map.
116 int first_packet_seq_num_;
117 int last_packet_seq_num_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118};
119
stefan@webrtc.org076fa6e2011-12-13 07:54:56 +0000120} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200122#endif // MODULES_VIDEO_CODING_SESSION_INFO_H_