mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_ |
| 11 | #define MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_ |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 15 | #include <list> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/packet.h" |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | const unsigned int kDefaultBitrateKbps = 1000; |
pbos@webrtc.org | 3004c79 | 2013-05-07 12:36:21 +0000 | [diff] [blame] | 22 | const unsigned int kDefaultFrameRate = 25; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 23 | const unsigned int kMaxPacketSize = 1500; |
andresp@webrtc.org | 1f09dbe | 2013-09-13 19:17:54 +0000 | [diff] [blame] | 24 | const unsigned int kFrameSize = |
| 25 | (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8); |
stefan@webrtc.org | ef14488 | 2013-05-07 19:16:33 +0000 | [diff] [blame] | 26 | const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 27 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 28 | class StreamGenerator { |
| 29 | public: |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 30 | StreamGenerator(uint16_t start_seq_num, int64_t current_time); |
Byoungchan Lee | 604fd2f | 2022-01-21 09:49:39 +0900 | [diff] [blame] | 31 | |
| 32 | StreamGenerator(const StreamGenerator&) = delete; |
| 33 | StreamGenerator& operator=(const StreamGenerator&) = delete; |
| 34 | |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 35 | void Init(uint16_t start_seq_num, int64_t current_time); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 36 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 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 |
Qiang Chen | d4cec15 | 2015-06-19 09:17:00 -0700 | [diff] [blame] | 39 | // timestamp and put it on the frame. |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 40 | void GenerateFrame(VideoFrameType type, |
andresp@webrtc.org | 1f09dbe | 2013-09-13 19:17:54 +0000 | [diff] [blame] | 41 | int num_media_packets, |
| 42 | int num_empty_packets, |
Qiang Chen | d4cec15 | 2015-06-19 09:17:00 -0700 | [diff] [blame] | 43 | int64_t time_ms); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 44 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 45 | bool PopPacket(VCMPacket* packet, int index); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 46 | void DropLastPacket(); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 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: |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 57 | VCMPacket GeneratePacket(uint16_t sequence_number, |
| 58 | uint32_t timestamp, |
| 59 | unsigned int size, |
| 60 | bool first_packet, |
| 61 | bool marker_bit, |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 62 | VideoFrameType type); |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 63 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 64 | std::list<VCMPacket>::iterator GetPacketIterator(int index); |
| 65 | |
| 66 | std::list<VCMPacket> packets_; |
| 67 | uint16_t sequence_number_; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 68 | int64_t start_time_; |
Wan-Teh Chang | 55b6acb | 2015-06-05 15:02:36 -0700 | [diff] [blame] | 69 | uint8_t packet_buffer_[kMaxPacketSize]; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } // namespace webrtc |
| 73 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 74 | #endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_ |