• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
11 #define MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
12 
13 #include <stdint.h>
14 
15 #include <list>
16 
17 #include "modules/video_coding/packet.h"
18 #include "rtc_base/constructor_magic.h"
19 
20 namespace webrtc {
21 
22 const unsigned int kDefaultBitrateKbps = 1000;
23 const unsigned int kDefaultFrameRate = 25;
24 const unsigned int kMaxPacketSize = 1500;
25 const unsigned int kFrameSize =
26     (kDefaultBitrateKbps + kDefaultFrameRate * 4) / (kDefaultFrameRate * 8);
27 const int kDefaultFramePeriodMs = 1000 / kDefaultFrameRate;
28 
29 class StreamGenerator {
30  public:
31   StreamGenerator(uint16_t start_seq_num, int64_t current_time);
32   void Init(uint16_t start_seq_num, int64_t current_time);
33 
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.
37   void GenerateFrame(VideoFrameType type,
38                      int num_media_packets,
39                      int num_empty_packets,
40                      int64_t time_ms);
41 
42   bool PopPacket(VCMPacket* packet, int index);
43   void DropLastPacket();
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:
54   VCMPacket GeneratePacket(uint16_t sequence_number,
55                            uint32_t timestamp,
56                            unsigned int size,
57                            bool first_packet,
58                            bool marker_bit,
59                            VideoFrameType type);
60 
61   std::list<VCMPacket>::iterator GetPacketIterator(int index);
62 
63   std::list<VCMPacket> packets_;
64   uint16_t sequence_number_;
65   int64_t start_time_;
66   uint8_t packet_buffer_[kMaxPacketSize];
67 
68   RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
69 };
70 
71 }  // namespace webrtc
72 
73 #endif  // MODULES_VIDEO_CODING_TEST_STREAM_GENERATOR_H_
74