xref: /aosp_15_r20/external/webrtc/modules/video_coding/test/stream_generator.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2013 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 #ifndef MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
11 #define MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
12 
13 #include <stdint.h>
14 
15 #include <list>
16 
17 #include "modules/video_coding/packet.h"
18 
19 namespace webrtc {
20 
21 const unsigned int kDefaultBitrateKbps = 1000;
22 const unsigned int kDefaultFrameRate = 25;
23 const unsigned int kMaxPacketSize = 1500;
24 const unsigned int kFrameSize =
25     (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
26 const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
27 
28 class StreamGenerator {
29  public:
30   StreamGenerator(uint16_t start_seq_num, int64_t current_time);
31 
32   StreamGenerator(const StreamGenerator&) = delete;
33   StreamGenerator& operator=(const StreamGenerator&) = delete;
34 
35   void Init(uint16_t start_seq_num, int64_t current_time);
36 
37   // `time_ms` denotes the timestamp you want to put on the frame, and the unit
38   // is millisecond. GenerateFrame will translate `time_ms` into a 90kHz
39   // timestamp and put it on the frame.
40   void GenerateFrame(VideoFrameType type,
41                      int num_media_packets,
42                      int num_empty_packets,
43                      int64_t time_ms);
44 
45   bool PopPacket(VCMPacket* packet, int index);
46   void DropLastPacket();
47 
48   bool GetPacket(VCMPacket* packet, int index);
49 
50   bool NextPacket(VCMPacket* packet);
51 
52   uint16_t NextSequenceNumber() const;
53 
54   int PacketsRemaining() const;
55 
56  private:
57   VCMPacket GeneratePacket(uint16_t sequence_number,
58                            uint32_t timestamp,
59                            unsigned int size,
60                            bool first_packet,
61                            bool marker_bit,
62                            VideoFrameType type);
63 
64   std::list<VCMPacket>::iterator GetPacketIterator(int index);
65 
66   std::list<VCMPacket> packets_;
67   uint16_t sequence_number_;
68   int64_t start_time_;
69   uint8_t packet_buffer_[kMaxPacketSize];
70 };
71 
72 }  // namespace webrtc
73 
74 #endif  // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
75