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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 int32_t time_now_ms = 0; | 55 int32_t time_now_ms = 0; |
56 | 56 |
57 // Get first input packet. | 57 // Get first input packet. |
58 WebRtcRTPHeader rtp_header; | 58 WebRtcRTPHeader rtp_header; |
59 RtpGenerator rtp_gen(kSampRateHz / 1000); | 59 RtpGenerator rtp_gen(kSampRateHz / 1000); |
60 // Start with positive drift first half of simulation. | 60 // Start with positive drift first half of simulation. |
61 rtp_gen.set_drift_factor(drift_factor); | 61 rtp_gen.set_drift_factor(drift_factor); |
62 bool drift_flipped = false; | 62 bool drift_flipped = false; |
63 int32_t packet_input_time_ms = | 63 int32_t packet_input_time_ms = |
64 rtp_gen.GetRtpHeader(kPayloadType, kInputBlockSizeSamples, &rtp_header); | 64 rtp_gen.GetRtpHeader(kPayloadType, kInputBlockSizeSamples, &rtp_header); |
65 const int16_t* input_samples = audio_loop.GetNextBlock(); | 65 auto input_samples = audio_loop.GetNextBlock(); |
66 if (!input_samples) exit(1); | 66 if (input_samples.empty()) |
| 67 exit(1); |
67 uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)]; | 68 uint8_t input_payload[kInputBlockSizeSamples * sizeof(int16_t)]; |
68 size_t payload_len = | 69 size_t payload_len = WebRtcPcm16b_Encode(input_samples.data(), |
69 WebRtcPcm16b_Encode(input_samples, kInputBlockSizeSamples, input_payload); | 70 input_samples.size(), input_payload); |
70 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); | 71 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); |
71 | 72 |
72 // Main loop. | 73 // Main loop. |
73 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); | 74 webrtc::Clock* clock = webrtc::Clock::GetRealTimeClock(); |
74 int64_t start_time_ms = clock->TimeInMilliseconds(); | 75 int64_t start_time_ms = clock->TimeInMilliseconds(); |
75 while (time_now_ms < runtime_ms) { | 76 while (time_now_ms < runtime_ms) { |
76 while (packet_input_time_ms <= time_now_ms) { | 77 while (packet_input_time_ms <= time_now_ms) { |
77 // Drop every N packets, where N = FLAGS_lossrate. | 78 // Drop every N packets, where N = FLAGS_lossrate. |
78 bool lost = false; | 79 bool lost = false; |
79 if (lossrate > 0) { | 80 if (lossrate > 0) { |
80 lost = ((rtp_header.header.sequenceNumber - 1) % lossrate) == 0; | 81 lost = ((rtp_header.header.sequenceNumber - 1) % lossrate) == 0; |
81 } | 82 } |
82 if (!lost) { | 83 if (!lost) { |
83 // Insert packet. | 84 // Insert packet. |
84 int error = neteq->InsertPacket( | 85 int error = neteq->InsertPacket( |
85 rtp_header, input_payload, payload_len, | 86 rtp_header, input_payload, payload_len, |
86 packet_input_time_ms * kSampRateHz / 1000); | 87 packet_input_time_ms * kSampRateHz / 1000); |
87 if (error != NetEq::kOK) | 88 if (error != NetEq::kOK) |
88 return -1; | 89 return -1; |
89 } | 90 } |
90 | 91 |
91 // Get next packet. | 92 // Get next packet. |
92 packet_input_time_ms = rtp_gen.GetRtpHeader(kPayloadType, | 93 packet_input_time_ms = rtp_gen.GetRtpHeader(kPayloadType, |
93 kInputBlockSizeSamples, | 94 kInputBlockSizeSamples, |
94 &rtp_header); | 95 &rtp_header); |
95 input_samples = audio_loop.GetNextBlock(); | 96 input_samples = audio_loop.GetNextBlock(); |
96 if (!input_samples) return -1; | 97 if (input_samples.empty()) |
97 payload_len = WebRtcPcm16b_Encode(const_cast<int16_t*>(input_samples), | 98 return -1; |
98 kInputBlockSizeSamples, | 99 payload_len = WebRtcPcm16b_Encode(input_samples.data(), |
99 input_payload); | 100 input_samples.size(), input_payload); |
100 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); | 101 assert(payload_len == kInputBlockSizeSamples * sizeof(int16_t)); |
101 } | 102 } |
102 | 103 |
103 // Get output audio, but don't do anything with it. | 104 // Get output audio, but don't do anything with it. |
104 static const int kMaxChannels = 1; | 105 static const int kMaxChannels = 1; |
105 static const size_t kMaxSamplesPerMs = 48000 / 1000; | 106 static const size_t kMaxSamplesPerMs = 48000 / 1000; |
106 static const int kOutputBlockSizeMs = 10; | 107 static const int kOutputBlockSizeMs = 10; |
107 static const size_t kOutDataLen = | 108 static const size_t kOutDataLen = |
108 kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels; | 109 kOutputBlockSizeMs * kMaxSamplesPerMs * kMaxChannels; |
109 int16_t out_data[kOutDataLen]; | 110 int16_t out_data[kOutDataLen]; |
(...skipping 13 matching lines...) Expand all Loading... |
123 drift_flipped = true; | 124 drift_flipped = true; |
124 } | 125 } |
125 } | 126 } |
126 int64_t end_time_ms = clock->TimeInMilliseconds(); | 127 int64_t end_time_ms = clock->TimeInMilliseconds(); |
127 delete neteq; | 128 delete neteq; |
128 return end_time_ms - start_time_ms; | 129 return end_time_ms - start_time_ms; |
129 } | 130 } |
130 | 131 |
131 } // namespace test | 132 } // namespace test |
132 } // namespace webrtc | 133 } // namespace webrtc |
OLD | NEW |