blob: eded9f49ff9f29401ae7cbf2adf0d19958c3e620 [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 */
Henrik Kjellander2557b862015-11-18 22:00:21 +010010#ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
11#define WEBRTC_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
Henrik Kjellander2557b862015-11-18 22:00:21 +010015#include "webrtc/modules/video_coding/packet.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020016#include "webrtc/rtc_base/constructormagic.h"
Wan-Teh Chang55b6acb2015-06-05 15:02:36 -070017#include "webrtc/typedefs.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);
31 void Init(uint16_t start_seq_num, int64_t current_time);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000032
Qiang Chend4cec152015-06-19 09:17:00 -070033 // |time_ms| denotes the timestamp you want to put on the frame, and the unit
34 // is millisecond. GenerateFrame will translate |time_ms| into a 90kHz
35 // timestamp and put it on the frame.
andresp@webrtc.org1f09dbe2013-09-13 19:17:54 +000036 void GenerateFrame(FrameType type,
37 int num_media_packets,
38 int num_empty_packets,
Qiang Chend4cec152015-06-19 09:17:00 -070039 int64_t time_ms);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000040
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000041 bool PopPacket(VCMPacket* packet, int index);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000042 void DropLastPacket();
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000043
44 bool GetPacket(VCMPacket* packet, int index);
45
46 bool NextPacket(VCMPacket* packet);
47
48 uint16_t NextSequenceNumber() const;
49
50 int PacketsRemaining() const;
51
52 private:
Wan-Teh Chang349c2bb2015-06-05 14:45:05 -070053 VCMPacket GeneratePacket(uint16_t sequence_number,
54 uint32_t timestamp,
55 unsigned int size,
56 bool first_packet,
57 bool marker_bit,
58 FrameType type);
59
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000060 std::list<VCMPacket>::iterator GetPacketIterator(int index);
61
62 std::list<VCMPacket> packets_;
63 uint16_t sequence_number_;
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000064 int64_t start_time_;
Wan-Teh Chang55b6acb2015-06-05 15:02:36 -070065 uint8_t packet_buffer_[kMaxPacketSize];
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000066
henrikg3c089d72015-09-16 05:37:44 -070067 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +000068};
69
70} // namespace webrtc
71
Henrik Kjellander2557b862015-11-18 22:00:21 +010072#endif // WEBRTC_MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_