blob: 22c9f11315740156e1f5e586205f578c7f74e11a [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>
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000014#include <list>
15
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "common_types.h" // NOLINT(build/include)
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/video_coding/packet.h"
18#include "rtc_base/constructormagic.h"
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000019
20namespace webrtc {
21
22const unsigned int kDefaultBitrateKbps = 1000;
pbos@webrtc.org3004c792013-05-07 12:36:21 +000023const unsigned int kDefaultFrameRate = 25;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000024const unsigned int kMaxPacketSize = 1500;
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000025const unsigned int kFrameSize =
26 (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
stefan@webrtc.orgef144882013-05-07 19:16:33 +000027const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000028
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000029class StreamGenerator {
30 public:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070031 StreamGenerator(uint16_t start_seq_num, int64_t current_time);
32 void Init(uint16_t start_seq_num, int64_t current_time);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000033
Qiang Chend4cec152015-06-19 09:17:00 -070034 // |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.
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000037 void GenerateFrame(FrameType type,
38 int num_media_packets,
39 int num_empty_packets,
Qiang Chend4cec152015-06-19 09:17:00 -070040 int64_t time_ms);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000041
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000042 bool PopPacket(VCMPacket* packet, int index);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000043 void DropLastPacket();
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000044
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 Chang349c2bb2015-06-05 14:45:05 -070054 VCMPacket GeneratePacket(uint16_t sequence_number,
55 uint32_t timestamp,
56 unsigned int size,
57 bool first_packet,
58 bool marker_bit,
59 FrameType type);
60
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000061 std::list<VCMPacket>::iterator GetPacketIterator(int index);
62
63 std::list<VCMPacket> packets_;
64 uint16_t sequence_number_;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000065 int64_t start_time_;
Wan-Teh Chang55b6acb2015-06-05 15:02:36 -070066 uint8_t packet_buffer_[kMaxPacketSize];
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000067
henrikg3c089d72015-09-16 05:37:44 -070068 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000069};
70
71} // namespace webrtc
72
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020073#endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_