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 */
10#ifndef WEBRTC_MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
11#define WEBRTC_MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
12
13#include <list>
14
15#include "webrtc/modules/video_coding/packet.h"
16#include "webrtc/modules/video_coding/test/test_util.h"
17#include "webrtc/typedefs.h"
18
19namespace webrtc {
20
21const unsigned int kDefaultBitrateKbps = 1000;
22const unsigned int kDefaultFrameRate = 25;
23const unsigned int kMaxPacketSize = 1500;
24const unsigned int kFrameSize =
25    (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
26const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
27
28class StreamGenerator {
29 public:
30  StreamGenerator(uint16_t start_seq_num, int64_t current_time);
31  void Init(uint16_t start_seq_num, int64_t current_time);
32
33  // |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.
36  void GenerateFrame(FrameType type,
37                     int num_media_packets,
38                     int num_empty_packets,
39                     int64_t time_ms);
40
41  bool PopPacket(VCMPacket* packet, int index);
42  void DropLastPacket();
43
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:
53  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
60  std::list<VCMPacket>::iterator GetPacketIterator(int index);
61
62  std::list<VCMPacket> packets_;
63  uint16_t sequence_number_;
64  int64_t start_time_;
65  uint8_t packet_buffer_[kMaxPacketSize];
66
67  RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
68};
69
70}  // namespace webrtc
71
72#endif  // WEBRTC_MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
73