OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_coding/test/stream_generator.h" | 11 #include "webrtc/modules/video_coding/test/stream_generator.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <list> | 15 #include <list> |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/modules/video_coding/packet.h" | 18 #include "webrtc/modules/video_coding/packet.h" |
19 #include "webrtc/modules/video_coding/test/test_util.h" | 19 #include "webrtc/modules/video_coding/test/test_util.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 | 23 |
24 StreamGenerator::StreamGenerator(uint16_t start_seq_num, int64_t current_time) | 24 StreamGenerator::StreamGenerator(uint16_t start_seq_num, int64_t current_time) |
25 : packets_(), sequence_number_(start_seq_num), start_time_(current_time) { | 25 : packets_(), sequence_number_(start_seq_num), start_time_(current_time) {} |
26 } | |
27 | 26 |
28 void StreamGenerator::Init(uint16_t start_seq_num, int64_t current_time) { | 27 void StreamGenerator::Init(uint16_t start_seq_num, int64_t current_time) { |
29 packets_.clear(); | 28 packets_.clear(); |
30 sequence_number_ = start_seq_num; | 29 sequence_number_ = start_seq_num; |
31 start_time_ = current_time; | 30 start_time_ = current_time; |
32 memset(packet_buffer_, 0, sizeof(packet_buffer_)); | 31 memset(packet_buffer_, 0, sizeof(packet_buffer_)); |
33 } | 32 } |
34 | 33 |
35 void StreamGenerator::GenerateFrame(FrameType type, | 34 void StreamGenerator::GenerateFrame(FrameType type, |
36 int num_media_packets, | 35 int num_media_packets, |
37 int num_empty_packets, | 36 int num_empty_packets, |
38 int64_t time_ms) { | 37 int64_t time_ms) { |
39 uint32_t timestamp = 90 * (time_ms - start_time_); | 38 uint32_t timestamp = 90 * (time_ms - start_time_); |
40 for (int i = 0; i < num_media_packets; ++i) { | 39 for (int i = 0; i < num_media_packets; ++i) { |
41 const int packet_size = | 40 const int packet_size = |
42 (kFrameSize + num_media_packets / 2) / num_media_packets; | 41 (kFrameSize + num_media_packets / 2) / num_media_packets; |
43 bool marker_bit = (i == num_media_packets - 1); | 42 bool marker_bit = (i == num_media_packets - 1); |
44 packets_.push_back(GeneratePacket( | 43 packets_.push_back(GeneratePacket(sequence_number_, timestamp, packet_size, |
45 sequence_number_, timestamp, packet_size, (i == 0), marker_bit, type)); | 44 (i == 0), marker_bit, type)); |
46 ++sequence_number_; | 45 ++sequence_number_; |
47 } | 46 } |
48 for (int i = 0; i < num_empty_packets; ++i) { | 47 for (int i = 0; i < num_empty_packets; ++i) { |
49 packets_.push_back(GeneratePacket(sequence_number_, timestamp, 0, false, | 48 packets_.push_back(GeneratePacket(sequence_number_, timestamp, 0, false, |
50 false, kEmptyFrame)); | 49 false, kEmptyFrame)); |
51 ++sequence_number_; | 50 ++sequence_number_; |
52 } | 51 } |
53 } | 52 } |
54 | 53 |
55 VCMPacket StreamGenerator::GeneratePacket(uint16_t sequence_number, | 54 VCMPacket StreamGenerator::GeneratePacket(uint16_t sequence_number, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 96 |
98 bool StreamGenerator::NextPacket(VCMPacket* packet) { | 97 bool StreamGenerator::NextPacket(VCMPacket* packet) { |
99 if (packets_.empty()) | 98 if (packets_.empty()) |
100 return false; | 99 return false; |
101 if (packet != NULL) | 100 if (packet != NULL) |
102 *packet = packets_.front(); | 101 *packet = packets_.front(); |
103 packets_.pop_front(); | 102 packets_.pop_front(); |
104 return true; | 103 return true; |
105 } | 104 } |
106 | 105 |
107 void StreamGenerator::DropLastPacket() { packets_.pop_back(); } | 106 void StreamGenerator::DropLastPacket() { |
| 107 packets_.pop_back(); |
| 108 } |
108 | 109 |
109 uint16_t StreamGenerator::NextSequenceNumber() const { | 110 uint16_t StreamGenerator::NextSequenceNumber() const { |
110 if (packets_.empty()) | 111 if (packets_.empty()) |
111 return sequence_number_; | 112 return sequence_number_; |
112 return packets_.front().seqNum; | 113 return packets_.front().seqNum; |
113 } | 114 } |
114 | 115 |
115 int StreamGenerator::PacketsRemaining() const { return packets_.size(); } | 116 int StreamGenerator::PacketsRemaining() const { |
| 117 return packets_.size(); |
| 118 } |
116 | 119 |
117 std::list<VCMPacket>::iterator StreamGenerator::GetPacketIterator(int index) { | 120 std::list<VCMPacket>::iterator StreamGenerator::GetPacketIterator(int index) { |
118 std::list<VCMPacket>::iterator it = packets_.begin(); | 121 std::list<VCMPacket>::iterator it = packets_.begin(); |
119 for (int i = 0; i < index; ++i) { | 122 for (int i = 0; i < index; ++i) { |
120 ++it; | 123 ++it; |
121 if (it == packets_.end()) | 124 if (it == packets_.end()) |
122 break; | 125 break; |
123 } | 126 } |
124 return it; | 127 return it; |
125 } | 128 } |
126 | 129 |
127 } // namespace webrtc | 130 } // namespace webrtc |
OLD | NEW |