blob: 38ca92d76340513f1cf07008267c4475ec521fda [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
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000013#include <list>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "modules/video_coding/packet.h"
16#include "rtc_base/constructormagic.h"
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000017
18namespace webrtc {
19
20const unsigned int kDefaultBitrateKbps = 1000;
pbos@webrtc.org3004c792013-05-07 12:36:21 +000021const unsigned int kDefaultFrameRate = 25;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000022const unsigned int kMaxPacketSize = 1500;
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000023const unsigned int kFrameSize =
24 (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
stefan@webrtc.orgef144882013-05-07 19:16:33 +000025const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000026
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000027class StreamGenerator {
28 public:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070029 StreamGenerator(uint16_t start_seq_num, int64_t current_time);
30 void Init(uint16_t start_seq_num, int64_t current_time);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000031
Qiang Chend4cec152015-06-19 09:17:00 -070032 // |time_ms| denotes the timestamp you want to put on the frame, and the unit
33 // is millisecond. GenerateFrame will translate |time_ms| into a 90kHz
34 // timestamp and put it on the frame.
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000035 void GenerateFrame(FrameType type,
36 int num_media_packets,
37 int num_empty_packets,
Qiang Chend4cec152015-06-19 09:17:00 -070038 int64_t time_ms);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000039
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000040 bool PopPacket(VCMPacket* packet, int index);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000041 void DropLastPacket();
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000042
43 bool GetPacket(VCMPacket* packet, int index);
44
45 bool NextPacket(VCMPacket* packet);
46
47 uint16_t NextSequenceNumber() const;
48
49 int PacketsRemaining() const;
50
51 private:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070052 VCMPacket GeneratePacket(uint16_t sequence_number,
53 uint32_t timestamp,
54 unsigned int size,
55 bool first_packet,
56 bool marker_bit,
57 FrameType type);
58
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000059 std::list<VCMPacket>::iterator GetPacketIterator(int index);
60
61 std::list<VCMPacket> packets_;
62 uint16_t sequence_number_;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000063 int64_t start_time_;
Wan-Teh Chang55b6acb2015-06-05 15:02:36 -070064 uint8_t packet_buffer_[kMaxPacketSize];
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000065
henrikg3c089d72015-09-16 05:37:44 -070066 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000067};
68
69} // namespace webrtc
70
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020071#endif // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_