blob: ddb23ebb76c76ca7821b83f366d0f56b3c568ade [file] [log] [blame]
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +00001/*
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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
11#define MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000015#include <list>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/packet.h"
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000018
19namespace webrtc {
20
21const unsigned int kDefaultBitrateKbps = 1000;
pbos@webrtc.org3004c792013-05-07 12:36:21 +000022const unsigned int kDefaultFrameRate = 25;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000023const unsigned int kMaxPacketSize = 1500;
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000024const unsigned int kFrameSize =
25 (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
stefan@webrtc.orgef144882013-05-07 19:16:33 +000026const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000027
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000028class StreamGenerator {
29 public:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070030 StreamGenerator(uint16_t start_seq_num, int64_t current_time);
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090031
32 StreamGenerator(const StreamGenerator&) = delete;
33 StreamGenerator& operator=(const StreamGenerator&) = delete;
34
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070035 void Init(uint16_t start_seq_num, int64_t current_time);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000036
Artem Titovdcd7fc72021-08-09 13:02:57 +020037 // `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
Qiang Chend4cec152015-06-19 09:17:00 -070039 // timestamp and put it on the frame.
Niels Möller87e2d782019-03-07 10:18:23 +010040 void GenerateFrame(VideoFrameType type,
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000041 int num_media_packets,
42 int num_empty_packets,
Qiang Chend4cec152015-06-19 09:17:00 -070043 int64_t time_ms);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000044
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000045 bool PopPacket(VCMPacket* packet, int index);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000046 void DropLastPacket();
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000047
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:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070057 VCMPacket GeneratePacket(uint16_t sequence_number,
58 uint32_t timestamp,
59 unsigned int size,
60 bool first_packet,
61 bool marker_bit,
Niels Möller87e2d782019-03-07 10:18:23 +010062 VideoFrameType type);
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070063
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000064 std::list<VCMPacket>::iterator GetPacketIterator(int index);
65
66 std::list<VCMPacket> packets_;
67 uint16_t sequence_number_;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000068 int64_t start_time_;
Wan-Teh Chang55b6acb2015-06-05 15:02:36 -070069 uint8_t packet_buffer_[kMaxPacketSize];
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000070};
71
72} // namespace webrtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_