Chromium Code Reviews| OLD | NEW |
|---|---|
| (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<InputAudioFile> input, | |
| 21 std::unique_ptr<AudioEncoder> encoder, | |
| 22 int64_t input_duration_ms) | |
| 23 : input_(std::move(input)), | |
| 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 packet_data_->payload.Clear(); | |
|
ivoc
2016/09/07 11:19:25
Is this really needed, considering that packet_dat
hlundin-webrtc
2016/09/07 11:43:08
Done.
| |
| 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 = | |
| 70 rtc::CheckedDivExact(encoder_->SampleRateHz(), 100); | |
|
ivoc
2016/09/07 11:19:25
I think we could replace the 100 with 1000/kOutput
hlundin-webrtc
2016/09/07 11:43:08
Done.
| |
| 71 std::unique_ptr<int16_t[]> audio(new int16_t[num_samples]); | |
| 72 RTC_CHECK(input_->Read(num_samples, audio.get())); | |
| 73 | |
| 74 info = encoder_->Encode( | |
| 75 rtp_timestamp_, rtc::ArrayView<const int16_t>(audio.get(), num_samples), | |
| 76 &packet_data_->payload); | |
| 77 | |
| 78 rtp_timestamp_ += | |
| 79 num_samples * encoder_->RtpTimestampRateHz() / encoder_->SampleRateHz(); | |
| 80 ++num_blocks; | |
| 81 } | |
| 82 packet_data_->header.header.timestamp = info.encoded_timestamp; | |
| 83 packet_data_->header.header.payloadType = info.payload_type; | |
| 84 packet_data_->header.header.sequenceNumber = sequence_number_++; | |
| 85 packet_data_->time_ms = next_packet_time_ms_; | |
| 86 next_packet_time_ms_ += num_blocks * 10; | |
|
ivoc
2016/09/07 11:19:25
Seems like another good place to use kOutputPeriod
hlundin-webrtc
2016/09/07 11:43:08
Done.
| |
| 87 } | |
| 88 | |
| 89 } // namespace test | |
| 90 } // namespace webrtc | |
| OLD | NEW |