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

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: Floating point literal in double precision 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 #include "webrtc/base/safe_conversions.h"
17
18 namespace webrtc {
19 namespace test {
20
21 EncodeNetEqInput::EncodeNetEqInput(std::unique_ptr<Generator> generator,
22 std::unique_ptr<AudioEncoder> encoder,
23 int64_t input_duration_ms)
24 : generator_(std::move(generator)),
25 encoder_(std::move(encoder)),
26 input_duration_ms_(input_duration_ms) {
27 CreatePacket();
28 }
29
30 rtc::Optional<int64_t> EncodeNetEqInput::NextPacketTime() const {
31 RTC_DCHECK(packet_data_);
32 return rtc::Optional<int64_t>(static_cast<int64_t>(packet_data_->time_ms));
33 }
34
35 rtc::Optional<int64_t> EncodeNetEqInput::NextOutputEventTime() const {
36 return rtc::Optional<int64_t>(next_output_event_ms_);
37 }
38
39 std::unique_ptr<NetEqInput::PacketData> EncodeNetEqInput::PopPacket() {
40 RTC_DCHECK(packet_data_);
41 // Grab the packet to return...
42 std::unique_ptr<PacketData> packet_to_return = std::move(packet_data_);
43 // ... and line up the next packet for future use.
44 CreatePacket();
45
46 return packet_to_return;
47 }
48
49 void EncodeNetEqInput::AdvanceOutputEvent() {
50 next_output_event_ms_ += kOutputPeriodMs;
51 }
52
53 rtc::Optional<RTPHeader> EncodeNetEqInput::NextHeader() const {
54 RTC_DCHECK(packet_data_);
55 return rtc::Optional<RTPHeader>(packet_data_->header.header);
56 }
57
58 void EncodeNetEqInput::CreatePacket() {
59 // Create a new PacketData object.
60 RTC_DCHECK(!packet_data_);
61 packet_data_.reset(new NetEqInput::PacketData);
62 RTC_DCHECK_EQ(packet_data_->payload.size(), 0u);
63
64 // Loop until we get a packet.
65 AudioEncoder::EncodedInfo info;
66 RTC_DCHECK(!info.send_even_if_empty);
67 int num_blocks = 0;
68 while (packet_data_->payload.size() == 0 && !info.send_even_if_empty) {
69 const size_t num_samples = rtc::CheckedDivExact(
70 static_cast<int>(encoder_->SampleRateHz() * kOutputPeriodMs), 1000);
71
72 info = encoder_->Encode(rtp_timestamp_, generator_->Generate(num_samples),
73 &packet_data_->payload);
74
75 rtp_timestamp_ += rtc::checked_cast<uint32_t>(
76 num_samples * encoder_->RtpTimestampRateHz() /
77 encoder_->SampleRateHz());
78 ++num_blocks;
79 }
80 packet_data_->header.header.timestamp = info.encoded_timestamp;
81 packet_data_->header.header.payloadType = info.payload_type;
82 packet_data_->header.header.sequenceNumber = sequence_number_++;
83 packet_data_->time_ms = next_packet_time_ms_;
84 next_packet_time_ms_ += num_blocks * kOutputPeriodMs;
85 }
86
87 } // namespace test
88 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/tools/encode_neteq_input.h ('k') | webrtc/modules/audio_coding/neteq/tools/neteq_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698