neteq_input.cc (2880B)
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 <cstdint> 14 #include <memory> 15 #include <optional> 16 #include <string> 17 #include <utility> 18 19 #include "modules/rtp_rtcp/source/rtp_packet_received.h" 20 #include "rtc_base/strings/string_builder.h" 21 22 namespace webrtc { 23 namespace test { 24 25 std::string NetEqInput::ToString(const RtpPacketReceived& packet) { 26 StringBuilder ss; 27 ss << "{" 28 "time_ms: " 29 << packet.arrival_time().ms() 30 << ", " 31 "header: {" 32 "pt: " 33 << static_cast<int>(packet.PayloadType()) 34 << ", " 35 "sn: " 36 << packet.SequenceNumber() 37 << ", " 38 "ts: " 39 << packet.Timestamp() 40 << ", " 41 "ssrc: " 42 << packet.Ssrc() 43 << "}, " 44 "payload bytes: " 45 << packet.payload_size() << "}"; 46 return ss.Release(); 47 } 48 49 TimeLimitedNetEqInput::TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input, 50 int64_t duration_ms) 51 : input_(std::move(input)), 52 start_time_ms_(input_->NextEventTime()), 53 duration_ms_(duration_ms) {} 54 55 TimeLimitedNetEqInput::~TimeLimitedNetEqInput() = default; 56 57 std::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const { 58 return ended_ ? std::nullopt : input_->NextPacketTime(); 59 } 60 61 std::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const { 62 return ended_ ? std::nullopt : input_->NextOutputEventTime(); 63 } 64 65 std::optional<NetEqInput::SetMinimumDelayInfo> 66 TimeLimitedNetEqInput::NextSetMinimumDelayInfo() const { 67 return ended_ ? std::nullopt : input_->NextSetMinimumDelayInfo(); 68 } 69 70 std::unique_ptr<RtpPacketReceived> TimeLimitedNetEqInput::PopPacket() { 71 if (ended_) { 72 return nullptr; 73 } 74 auto packet = input_->PopPacket(); 75 MaybeSetEnded(); 76 return packet; 77 } 78 79 void TimeLimitedNetEqInput::AdvanceOutputEvent() { 80 if (!ended_) { 81 input_->AdvanceOutputEvent(); 82 MaybeSetEnded(); 83 } 84 } 85 86 void TimeLimitedNetEqInput::AdvanceSetMinimumDelay() { 87 if (!ended_) { 88 input_->AdvanceSetMinimumDelay(); 89 MaybeSetEnded(); 90 } 91 } 92 93 bool TimeLimitedNetEqInput::ended() const { 94 return ended_ || input_->ended(); 95 } 96 97 const RtpPacketReceived* TimeLimitedNetEqInput::NextPacket() const { 98 return ended_ ? nullptr : input_->NextPacket(); 99 } 100 101 void TimeLimitedNetEqInput::MaybeSetEnded() { 102 if (NextEventTime() && start_time_ms_ && 103 *NextEventTime() - *start_time_ms_ > duration_ms_) { 104 ended_ = true; 105 } 106 } 107 108 } // namespace test 109 } // namespace webrtc