Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Side by Side Diff: webrtc/modules/audio_coding/neteq/tools/encode_neteq_input.cc

Issue 2384423002: Relanding "Setting up an RTP input fuzzer for NetEq" (Closed)
Patch Set: Change EncodeNetEqInput to take a signal generator instead of a file Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 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/audio_coding/neteq/tools/encode_neteq_input.h"
12
13 #include <utility>
14
15 #include "webrtc/base/checks.h"
16
17 namespace webrtc {
18 namespace test {
19
20 EncodeNetEqInput::EncodeNetEqInput(std::unique_ptr<Generator> generator,
21 std::unique_ptr<AudioEncoder> encoder,
22 int64_t input_duration_ms)
23 : generator_(std::move(generator)),
24 encoder_(std::move(encoder)),
25 input_duration_ms_(input_duration_ms) {
26 CreatePacket();
27 }
28
29 rtc::Optional<int64_t> EncodeNetEqInput::NextPacketTime() const {
30 RTC_DCHECK(packet_data_);
31 return rtc::Optional<int64_t>(static_cast<int64_t>(packet_data_->time_ms));
32 }
33
34 rtc::Optional<int64_t> EncodeNetEqInput::NextOutputEventTime() const {
35 return rtc::Optional<int64_t>(next_output_event_ms_);
36 }
37
38 std::unique_ptr<NetEqInput::PacketData> EncodeNetEqInput::PopPacket() {
39 RTC_DCHECK(packet_data_);
40 // Grab the packet to return...
41 std::unique_ptr<PacketData> packet_to_return = std::move(packet_data_);
42 // ... and line up the next packet for future use.
43 CreatePacket();
44
45 return packet_to_return;
46 }
47
48 void EncodeNetEqInput::AdvanceOutputEvent() {
49 next_output_event_ms_ += kOutputPeriodMs;
50 }
51
52 rtc::Optional<RTPHeader> EncodeNetEqInput::NextHeader() const {
53 RTC_DCHECK(packet_data_);
54 return rtc::Optional<RTPHeader>(packet_data_->header.header);
55 }
56
57 void EncodeNetEqInput::CreatePacket() {
58 // Create a new PacketData object.
59 RTC_DCHECK(!packet_data_);
60 packet_data_.reset(new NetEqInput::PacketData);
61 RTC_DCHECK_EQ(packet_data_->payload.size(), 0u);
62
63 // Loop until we get a packet.
64 AudioEncoder::EncodedInfo info;
65 RTC_DCHECK(!info.send_even_if_empty);
66 int num_blocks = 0;
67 while (packet_data_->payload.size() == 0 && !info.send_even_if_empty) {
68 const size_t num_samples = rtc::CheckedDivExact(
69 static_cast<int>(encoder_->SampleRateHz() * kOutputPeriodMs), 1000);
70
71 info = encoder_->Encode(rtp_timestamp_, generator_->Generate(num_samples),
72 &packet_data_->payload);
73
74 rtp_timestamp_ +=
75 num_samples * encoder_->RtpTimestampRateHz() / encoder_->SampleRateHz();
76 ++num_blocks;
77 }
78 packet_data_->header.header.timestamp = info.encoded_timestamp;
79 packet_data_->header.header.payloadType = info.payload_type;
80 packet_data_->header.header.sequenceNumber = sequence_number_++;
81 packet_data_->time_ms = next_packet_time_ms_;
82 next_packet_time_ms_ += num_blocks * kOutputPeriodMs;
83 }
84
85 } // namespace test
86 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698