OLD | NEW |
| (Empty) |
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 | |
11 #include "webrtc/modules/video_coding/main/source/test/stream_generator.h" | |
12 | |
13 #include <string.h> | |
14 | |
15 #include <list> | |
16 | |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 #include "webrtc/modules/video_coding/main/source/packet.h" | |
19 #include "webrtc/modules/video_coding/main/test/test_util.h" | |
20 #include "webrtc/system_wrappers/include/clock.h" | |
21 | |
22 namespace webrtc { | |
23 | |
24 StreamGenerator::StreamGenerator(uint16_t start_seq_num, int64_t current_time) | |
25 : packets_(), sequence_number_(start_seq_num), start_time_(current_time) { | |
26 } | |
27 | |
28 void StreamGenerator::Init(uint16_t start_seq_num, int64_t current_time) { | |
29 packets_.clear(); | |
30 sequence_number_ = start_seq_num; | |
31 start_time_ = current_time; | |
32 memset(packet_buffer_, 0, sizeof(packet_buffer_)); | |
33 } | |
34 | |
35 void StreamGenerator::GenerateFrame(FrameType type, | |
36 int num_media_packets, | |
37 int num_empty_packets, | |
38 int64_t time_ms) { | |
39 uint32_t timestamp = 90 * (time_ms - start_time_); | |
40 for (int i = 0; i < num_media_packets; ++i) { | |
41 const int packet_size = | |
42 (kFrameSize + num_media_packets / 2) / num_media_packets; | |
43 bool marker_bit = (i == num_media_packets - 1); | |
44 packets_.push_back(GeneratePacket( | |
45 sequence_number_, timestamp, packet_size, (i == 0), marker_bit, type)); | |
46 ++sequence_number_; | |
47 } | |
48 for (int i = 0; i < num_empty_packets; ++i) { | |
49 packets_.push_back(GeneratePacket(sequence_number_, timestamp, 0, false, | |
50 false, kEmptyFrame)); | |
51 ++sequence_number_; | |
52 } | |
53 } | |
54 | |
55 VCMPacket StreamGenerator::GeneratePacket(uint16_t sequence_number, | |
56 uint32_t timestamp, | |
57 unsigned int size, | |
58 bool first_packet, | |
59 bool marker_bit, | |
60 FrameType type) { | |
61 EXPECT_LT(size, kMaxPacketSize); | |
62 VCMPacket packet; | |
63 packet.seqNum = sequence_number; | |
64 packet.timestamp = timestamp; | |
65 packet.frameType = type; | |
66 packet.isFirstPacket = first_packet; | |
67 packet.markerBit = marker_bit; | |
68 packet.sizeBytes = size; | |
69 packet.dataPtr = packet_buffer_; | |
70 if (packet.isFirstPacket) | |
71 packet.completeNALU = kNaluStart; | |
72 else if (packet.markerBit) | |
73 packet.completeNALU = kNaluEnd; | |
74 else | |
75 packet.completeNALU = kNaluIncomplete; | |
76 return packet; | |
77 } | |
78 | |
79 bool StreamGenerator::PopPacket(VCMPacket* packet, int index) { | |
80 std::list<VCMPacket>::iterator it = GetPacketIterator(index); | |
81 if (it == packets_.end()) | |
82 return false; | |
83 if (packet) | |
84 *packet = (*it); | |
85 packets_.erase(it); | |
86 return true; | |
87 } | |
88 | |
89 bool StreamGenerator::GetPacket(VCMPacket* packet, int index) { | |
90 std::list<VCMPacket>::iterator it = GetPacketIterator(index); | |
91 if (it == packets_.end()) | |
92 return false; | |
93 if (packet) | |
94 *packet = (*it); | |
95 return true; | |
96 } | |
97 | |
98 bool StreamGenerator::NextPacket(VCMPacket* packet) { | |
99 if (packets_.empty()) | |
100 return false; | |
101 if (packet != NULL) | |
102 *packet = packets_.front(); | |
103 packets_.pop_front(); | |
104 return true; | |
105 } | |
106 | |
107 void StreamGenerator::DropLastPacket() { packets_.pop_back(); } | |
108 | |
109 uint16_t StreamGenerator::NextSequenceNumber() const { | |
110 if (packets_.empty()) | |
111 return sequence_number_; | |
112 return packets_.front().seqNum; | |
113 } | |
114 | |
115 int StreamGenerator::PacketsRemaining() const { return packets_.size(); } | |
116 | |
117 std::list<VCMPacket>::iterator StreamGenerator::GetPacketIterator(int index) { | |
118 std::list<VCMPacket>::iterator it = packets_.begin(); | |
119 for (int i = 0; i < index; ++i) { | |
120 ++it; | |
121 if (it == packets_.end()) | |
122 break; | |
123 } | |
124 return it; | |
125 } | |
126 | |
127 } // namespace webrtc | |
OLD | NEW |