1 /* 2 * Copyright (c) 2017 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 "modules/audio_coding/neteq/tools/neteq_input.h" 12 13 #include "rtc_base/strings/string_builder.h" 14 15 namespace webrtc { 16 namespace test { 17 18 NetEqInput::PacketData::PacketData() = default; 19 NetEqInput::PacketData::~PacketData() = default; 20 ToString() const21std::string NetEqInput::PacketData::ToString() const { 22 rtc::StringBuilder ss; 23 ss << "{" 24 "time_ms: " 25 << static_cast<int64_t>(time_ms) 26 << ", " 27 "header: {" 28 "pt: " 29 << static_cast<int>(header.payloadType) 30 << ", " 31 "sn: " 32 << header.sequenceNumber 33 << ", " 34 "ts: " 35 << header.timestamp 36 << ", " 37 "ssrc: " 38 << header.ssrc 39 << "}, " 40 "payload bytes: " 41 << payload.size() << "}"; 42 return ss.Release(); 43 } 44 TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input,int64_t duration_ms)45TimeLimitedNetEqInput::TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input, 46 int64_t duration_ms) 47 : input_(std::move(input)), 48 start_time_ms_(input_->NextEventTime()), 49 duration_ms_(duration_ms) {} 50 51 TimeLimitedNetEqInput::~TimeLimitedNetEqInput() = default; 52 NextPacketTime() const53absl::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const { 54 return ended_ ? absl::nullopt : input_->NextPacketTime(); 55 } 56 NextOutputEventTime() const57absl::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const { 58 return ended_ ? absl::nullopt : input_->NextOutputEventTime(); 59 } 60 PopPacket()61std::unique_ptr<NetEqInput::PacketData> TimeLimitedNetEqInput::PopPacket() { 62 if (ended_) { 63 return std::unique_ptr<PacketData>(); 64 } 65 auto packet = input_->PopPacket(); 66 MaybeSetEnded(); 67 return packet; 68 } 69 AdvanceOutputEvent()70void TimeLimitedNetEqInput::AdvanceOutputEvent() { 71 if (!ended_) { 72 input_->AdvanceOutputEvent(); 73 MaybeSetEnded(); 74 } 75 } 76 ended() const77bool TimeLimitedNetEqInput::ended() const { 78 return ended_ || input_->ended(); 79 } 80 NextHeader() const81absl::optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const { 82 return ended_ ? absl::nullopt : input_->NextHeader(); 83 } 84 MaybeSetEnded()85void TimeLimitedNetEqInput::MaybeSetEnded() { 86 if (NextEventTime() && start_time_ms_ && 87 *NextEventTime() - *start_time_ms_ > duration_ms_) { 88 ended_ = true; 89 } 90 } 91 92 } // namespace test 93 } // namespace webrtc 94