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> |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 14 | #include <list> |
| 15 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/packet.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "rtc_base/constructor_magic.h" |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | const unsigned int kDefaultBitrateKbps = 1000; |
pbos@webrtc.org | 3004c79 | 2013-05-07 12:36:21 +0000 | [diff] [blame] | 23 | const unsigned int kDefaultFrameRate = 25; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 24 | const unsigned int kMaxPacketSize = 1500; |
andresp@webrtc.org | 1f09dbe | 2013-09-13 19:17:54 +0000 | [diff] [blame] | 25 | const unsigned int kFrameSize = |
| 26 | (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8); |
stefan@webrtc.org | ef14488 | 2013-05-07 19:16:33 +0000 | [diff] [blame] | 27 | const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 28 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 29 | class StreamGenerator { |
| 30 | public: |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 31 | StreamGenerator(uint16_t start_seq_num, int64_t current_time); |
| 32 | void Init(uint16_t start_seq_num, int64_t current_time); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 33 | |
Qiang Chen | d4cec15 | 2015-06-19 09:17:00 -0700 | [diff] [blame] | 34 | // |time_ms| denotes the timestamp you want to put on the frame, and the unit |
| 35 | // is millisecond. GenerateFrame will translate |time_ms| into a 90kHz |
| 36 | // timestamp and put it on the frame. |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame^] | 37 | void GenerateFrame(VideoFrameType type, |
andresp@webrtc.org | 1f09dbe | 2013-09-13 19:17:54 +0000 | [diff] [blame] | 38 | int num_media_packets, |
| 39 | int num_empty_packets, |
Qiang Chen | d4cec15 | 2015-06-19 09:17:00 -0700 | [diff] [blame] | 40 | int64_t time_ms); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 41 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 42 | bool PopPacket(VCMPacket* packet, int index); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 43 | void DropLastPacket(); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 44 | |
| 45 | bool GetPacket(VCMPacket* packet, int index); |
| 46 | |
| 47 | bool NextPacket(VCMPacket* packet); |
| 48 | |
| 49 | uint16_t NextSequenceNumber() const; |
| 50 | |
| 51 | int PacketsRemaining() const; |
| 52 | |
| 53 | private: |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 54 | VCMPacket GeneratePacket(uint16_t sequence_number, |
| 55 | uint32_t timestamp, |
| 56 | unsigned int size, |
| 57 | bool first_packet, |
| 58 | bool marker_bit, |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame^] | 59 | VideoFrameType type); |
Wan-Teh Chang | 349c2bb | 2015-06-05 14:45:05 -0700 | [diff] [blame] | 60 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 61 | std::list<VCMPacket>::iterator GetPacketIterator(int index); |
| 62 | |
| 63 | std::list<VCMPacket> packets_; |
| 64 | uint16_t sequence_number_; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 65 | int64_t start_time_; |
Wan-Teh Chang | 55b6acb | 2015-06-05 15:02:36 -0700 | [diff] [blame] | 66 | uint8_t packet_buffer_[kMaxPacketSize]; |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 67 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 68 | RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator); |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace webrtc |
| 72 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 73 | #endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_ |