OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if (input_samples.empty()) | 68 if (input_samples.empty()) |
69 exit(1); | 69 exit(1); |
70 uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)]; | 70 uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)]; |
71 size_t payload_len = WebRtcPcm16b_Encode(input_samples.data(), | 71 size_t payload_len = WebRtcPcm16b_Encode(input_samples.data(), |
72 input_samples.size(), input_payload); | 72 input_samples.size(), input_payload); |
73 RTC_CHECK_EQ(sizeof(input_payload), payload_len); | 73 RTC_CHECK_EQ(sizeof(input_payload), payload_len); |
74 | 74 |
75 // Main loop. | 75 // Main loop. |
76 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); | 76 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); |
77 int64_t start_time_ms = clock->TimeInMilliseconds(); | 77 int64_t start_time_ms = clock->TimeInMilliseconds(); |
| 78 AudioFrame out_frame; |
78 while (time_now_ms < runtime_ms) { | 79 while (time_now_ms < runtime_ms) { |
79 while (packet_input_time_ms <= time_now_ms) { | 80 while (packet_input_time_ms <= time_now_ms) { |
80 // Drop every N packets, where N = FLAGS_lossrate. | 81 // Drop every N packets, where N = FLAGS_lossrate. |
81 bool lost = false; | 82 bool lost = false; |
82 if (lossrate > 0) { | 83 if (lossrate > 0) { |
83 lost = ((rtp_header.header.sequenceNumber - 1) % lossrate) == 0; | 84 lost = ((rtp_header.header.sequenceNumber - 1) % lossrate) == 0; |
84 } | 85 } |
85 if (!lost) { | 86 if (!lost) { |
86 // Insert packet. | 87 // Insert packet. |
87 int error = | 88 int error = |
88 neteq->InsertPacket(rtp_header, input_payload, | 89 neteq->InsertPacket(rtp_header, input_payload, |
89 packet_input_time_ms * kSampRateHz / 1000); | 90 packet_input_time_ms * kSampRateHz / 1000); |
90 if (error != NetEq::kOK) | 91 if (error != NetEq::kOK) |
91 return -1; | 92 return -1; |
92 } | 93 } |
93 | 94 |
94 // Get next packet. | 95 // Get next packet. |
95 packet_input_time_ms = rtp_gen.GetRtpHeader(kPayloadType, | 96 packet_input_time_ms = rtp_gen.GetRtpHeader(kPayloadType, |
96 kInputBlockSizeSamples, | 97 kInputBlockSizeSamples, |
97 &rtp_header); | 98 &rtp_header); |
98 input_samples = audio_loop.GetNextBlock(); | 99 input_samples = audio_loop.GetNextBlock(); |
99 if (input_samples.empty()) | 100 if (input_samples.empty()) |
100 return -1; | 101 return -1; |
101 payload_len = WebRtcPcm16b_Encode(input_samples.data(), | 102 payload_len = WebRtcPcm16b_Encode(input_samples.data(), |
102 input_samples.size(), input_payload); | 103 input_samples.size(), input_payload); |
103 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); | 104 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); |
104 } | 105 } |
105 | 106 |
106 // Get output audio, but don't do anything with it. | 107 // Get output audio, but don't do anything with it. |
107 AudioFrame out_frame; | |
108 int error = neteq->GetAudio(&out_frame); | 108 int error = neteq->GetAudio(&out_frame); |
109 if (error != NetEq::kOK) | 109 if (error != NetEq::kOK) |
110 return -1; | 110 return -1; |
111 | 111 |
112 assert(out_frame.samples_per_channel_ == | 112 assert(out_frame.samples_per_channel_ == |
113 static_cast<size_t>(kSampRateHz * 10 / 1000)); | 113 static_cast<size_t>(kSampRateHz * 10 / 1000)); |
114 | 114 |
115 static const int kOutputBlockSizeMs = 10; | 115 static const int kOutputBlockSizeMs = 10; |
116 time_now_ms += kOutputBlockSizeMs; | 116 time_now_ms += kOutputBlockSizeMs; |
117 if (time_now_ms >= runtime_ms / 2 && !drift_flipped) { | 117 if (time_now_ms >= runtime_ms / 2 && !drift_flipped) { |
118 // Apply negative drift second half of simulation. | 118 // Apply negative drift second half of simulation. |
119 rtp_gen.set_drift_factor(-drift_factor); | 119 rtp_gen.set_drift_factor(-drift_factor); |
120 drift_flipped = true; | 120 drift_flipped = true; |
121 } | 121 } |
122 } | 122 } |
123 int64_t end_time_ms = clock->TimeInMilliseconds(); | 123 int64_t end_time_ms = clock->TimeInMilliseconds(); |
124 delete neteq; | 124 delete neteq; |
125 return end_time_ms - start_time_ms; | 125 return end_time_ms - start_time_ms; |
126 } | 126 } |
127 | 127 |
128 } // namespace test | 128 } // namespace test |
129 } // namespace webrtc | 129 } // namespace webrtc |
OLD | NEW |