xref: /aosp_15_r20/external/webrtc/modules/video_coding/session_info.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef MODULES_VIDEO_CODING_SESSION_INFO_H_
12*d9f75844SAndroid Build Coastguard Worker #define MODULES_VIDEO_CODING_SESSION_INFO_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <stddef.h>
15*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include <list>
18*d9f75844SAndroid Build Coastguard Worker #include <vector>
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/codecs/h264/include/h264_globals.h"
21*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
22*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/include/video_coding.h"
23*d9f75844SAndroid Build Coastguard Worker #include "modules/video_coding/packet.h"
24*d9f75844SAndroid Build Coastguard Worker 
25*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
26*d9f75844SAndroid Build Coastguard Worker // Used to pass data from jitter buffer to session info.
27*d9f75844SAndroid Build Coastguard Worker // This data is then used in determining whether a frame is decodable.
28*d9f75844SAndroid Build Coastguard Worker struct FrameData {
29*d9f75844SAndroid Build Coastguard Worker   int64_t rtt_ms;
30*d9f75844SAndroid Build Coastguard Worker   float rolling_average_packets_per_frame;
31*d9f75844SAndroid Build Coastguard Worker };
32*d9f75844SAndroid Build Coastguard Worker 
33*d9f75844SAndroid Build Coastguard Worker class VCMSessionInfo {
34*d9f75844SAndroid Build Coastguard Worker  public:
35*d9f75844SAndroid Build Coastguard Worker   VCMSessionInfo();
36*d9f75844SAndroid Build Coastguard Worker   ~VCMSessionInfo();
37*d9f75844SAndroid Build Coastguard Worker 
38*d9f75844SAndroid Build Coastguard Worker   void UpdateDataPointers(const uint8_t* old_base_ptr,
39*d9f75844SAndroid Build Coastguard Worker                           const uint8_t* new_base_ptr);
40*d9f75844SAndroid Build Coastguard Worker   void Reset();
41*d9f75844SAndroid Build Coastguard Worker   int InsertPacket(const VCMPacket& packet,
42*d9f75844SAndroid Build Coastguard Worker                    uint8_t* frame_buffer,
43*d9f75844SAndroid Build Coastguard Worker                    const FrameData& frame_data);
44*d9f75844SAndroid Build Coastguard Worker   bool complete() const;
45*d9f75844SAndroid Build Coastguard Worker 
46*d9f75844SAndroid Build Coastguard Worker   // Makes the frame decodable. I.e., only contain decodable NALUs. All
47*d9f75844SAndroid Build Coastguard Worker   // non-decodable NALUs will be deleted and packets will be moved to in
48*d9f75844SAndroid Build Coastguard Worker   // memory to remove any empty space.
49*d9f75844SAndroid Build Coastguard Worker   // Returns the number of bytes deleted from the session.
50*d9f75844SAndroid Build Coastguard Worker   size_t MakeDecodable();
51*d9f75844SAndroid Build Coastguard Worker 
52*d9f75844SAndroid Build Coastguard Worker   size_t SessionLength() const;
53*d9f75844SAndroid Build Coastguard Worker   int NumPackets() const;
54*d9f75844SAndroid Build Coastguard Worker   bool HaveFirstPacket() const;
55*d9f75844SAndroid Build Coastguard Worker   bool HaveLastPacket() const;
FrameType()56*d9f75844SAndroid Build Coastguard Worker   webrtc::VideoFrameType FrameType() const { return frame_type_; }
57*d9f75844SAndroid Build Coastguard Worker   int LowSequenceNumber() const;
58*d9f75844SAndroid Build Coastguard Worker 
59*d9f75844SAndroid Build Coastguard Worker   // Returns highest sequence number, media or empty.
60*d9f75844SAndroid Build Coastguard Worker   int HighSequenceNumber() const;
61*d9f75844SAndroid Build Coastguard Worker   int PictureId() const;
62*d9f75844SAndroid Build Coastguard Worker   int TemporalId() const;
63*d9f75844SAndroid Build Coastguard Worker   bool LayerSync() const;
64*d9f75844SAndroid Build Coastguard Worker   int Tl0PicId() const;
65*d9f75844SAndroid Build Coastguard Worker 
66*d9f75844SAndroid Build Coastguard Worker   std::vector<NaluInfo> GetNaluInfos() const;
67*d9f75844SAndroid Build Coastguard Worker 
68*d9f75844SAndroid Build Coastguard Worker   void SetGofInfo(const GofInfoVP9& gof_info, size_t idx);
69*d9f75844SAndroid Build Coastguard Worker 
70*d9f75844SAndroid Build Coastguard Worker  private:
71*d9f75844SAndroid Build Coastguard Worker   enum { kMaxVP8Partitions = 9 };
72*d9f75844SAndroid Build Coastguard Worker 
73*d9f75844SAndroid Build Coastguard Worker   typedef std::list<VCMPacket> PacketList;
74*d9f75844SAndroid Build Coastguard Worker   typedef PacketList::iterator PacketIterator;
75*d9f75844SAndroid Build Coastguard Worker   typedef PacketList::const_iterator PacketIteratorConst;
76*d9f75844SAndroid Build Coastguard Worker   typedef PacketList::reverse_iterator ReversePacketIterator;
77*d9f75844SAndroid Build Coastguard Worker 
78*d9f75844SAndroid Build Coastguard Worker   void InformOfEmptyPacket(uint16_t seq_num);
79*d9f75844SAndroid Build Coastguard Worker 
80*d9f75844SAndroid Build Coastguard Worker   // Finds the packet of the beginning of the next VP8 partition. If
81*d9f75844SAndroid Build Coastguard Worker   // none is found the returned iterator points to `packets_.end()`.
82*d9f75844SAndroid Build Coastguard Worker   // `it` is expected to point to the last packet of the previous partition,
83*d9f75844SAndroid Build Coastguard Worker   // or to the first packet of the frame. `packets_skipped` is incremented
84*d9f75844SAndroid Build Coastguard Worker   // for each packet found which doesn't have the beginning bit set.
85*d9f75844SAndroid Build Coastguard Worker   PacketIterator FindNextPartitionBeginning(PacketIterator it) const;
86*d9f75844SAndroid Build Coastguard Worker 
87*d9f75844SAndroid Build Coastguard Worker   // Returns an iterator pointing to the last packet of the partition pointed to
88*d9f75844SAndroid Build Coastguard Worker   // by `it`.
89*d9f75844SAndroid Build Coastguard Worker   PacketIterator FindPartitionEnd(PacketIterator it) const;
90*d9f75844SAndroid Build Coastguard Worker   static bool InSequence(const PacketIterator& it,
91*d9f75844SAndroid Build Coastguard Worker                          const PacketIterator& prev_it);
92*d9f75844SAndroid Build Coastguard Worker   size_t InsertBuffer(uint8_t* frame_buffer, PacketIterator packetIterator);
93*d9f75844SAndroid Build Coastguard Worker   size_t Insert(const uint8_t* buffer,
94*d9f75844SAndroid Build Coastguard Worker                 size_t length,
95*d9f75844SAndroid Build Coastguard Worker                 bool insert_start_code,
96*d9f75844SAndroid Build Coastguard Worker                 uint8_t* frame_buffer);
97*d9f75844SAndroid Build Coastguard Worker   void ShiftSubsequentPackets(PacketIterator it, int steps_to_shift);
98*d9f75844SAndroid Build Coastguard Worker   PacketIterator FindNaluEnd(PacketIterator packet_iter) const;
99*d9f75844SAndroid Build Coastguard Worker   // Deletes the data of all packets between `start` and `end`, inclusively.
100*d9f75844SAndroid Build Coastguard Worker   // Note that this function doesn't delete the actual packets.
101*d9f75844SAndroid Build Coastguard Worker   size_t DeletePacketData(PacketIterator start, PacketIterator end);
102*d9f75844SAndroid Build Coastguard Worker   void UpdateCompleteSession();
103*d9f75844SAndroid Build Coastguard Worker 
104*d9f75844SAndroid Build Coastguard Worker   bool complete_;
105*d9f75844SAndroid Build Coastguard Worker   webrtc::VideoFrameType frame_type_;
106*d9f75844SAndroid Build Coastguard Worker   // Packets in this frame.
107*d9f75844SAndroid Build Coastguard Worker   PacketList packets_;
108*d9f75844SAndroid Build Coastguard Worker   int empty_seq_num_low_;
109*d9f75844SAndroid Build Coastguard Worker   int empty_seq_num_high_;
110*d9f75844SAndroid Build Coastguard Worker 
111*d9f75844SAndroid Build Coastguard Worker   // The following two variables correspond to the first and last media packets
112*d9f75844SAndroid Build Coastguard Worker   // in a session defined by the first packet flag and the marker bit.
113*d9f75844SAndroid Build Coastguard Worker   // They are not necessarily equal to the front and back packets, as packets
114*d9f75844SAndroid Build Coastguard Worker   // may enter out of order.
115*d9f75844SAndroid Build Coastguard Worker   // TODO(mikhal): Refactor the list to use a map.
116*d9f75844SAndroid Build Coastguard Worker   int first_packet_seq_num_;
117*d9f75844SAndroid Build Coastguard Worker   int last_packet_seq_num_;
118*d9f75844SAndroid Build Coastguard Worker };
119*d9f75844SAndroid Build Coastguard Worker 
120*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
121*d9f75844SAndroid Build Coastguard Worker 
122*d9f75844SAndroid Build Coastguard Worker #endif  // MODULES_VIDEO_CODING_SESSION_INFO_H_
123