blob: de416348f1d5171ef1b4581c4768be44dc7e570a [file] [log] [blame]
henrik.lundin7a38fd22017-04-28 01:35:53 -07001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_coding/neteq/tools/neteq_input.h"
henrik.lundin7a38fd22017-04-28 01:35:53 -070012
Jonas Olsson366a50c2018-09-06 13:41:30 +020013#include "rtc_base/strings/string_builder.h"
henrik.lundin7a38fd22017-04-28 01:35:53 -070014
15namespace webrtc {
16namespace test {
17
Mirko Bonadei682aac52018-07-20 13:59:20 +020018NetEqInput::PacketData::PacketData() = default;
19NetEqInput::PacketData::~PacketData() = default;
20
henrik.lundin7a38fd22017-04-28 01:35:53 -070021std::string NetEqInput::PacketData::ToString() const {
Jonas Olsson366a50c2018-09-06 13:41:30 +020022 rtc::StringBuilder ss;
henrik.lundin7a38fd22017-04-28 01:35:53 -070023 ss << "{"
Jonas Olssonb2b20312020-01-14 12:11:31 +010024 "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() << "}";
Jonas Olsson84df1c72018-09-14 16:59:32 +020042 return ss.Release();
henrik.lundin7a38fd22017-04-28 01:35:53 -070043}
44
Henrik Lundin7687ad52018-07-02 10:14:46 +020045TimeLimitedNetEqInput::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
Mirko Bonadei682aac52018-07-20 13:59:20 +020051TimeLimitedNetEqInput::~TimeLimitedNetEqInput() = default;
52
Danil Chapovalov065a52a2018-07-09 10:58:54 +020053absl::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const {
54 return ended_ ? absl::nullopt : input_->NextPacketTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020055}
56
Danil Chapovalov065a52a2018-07-09 10:58:54 +020057absl::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const {
58 return ended_ ? absl::nullopt : input_->NextOutputEventTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020059}
60
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
70void TimeLimitedNetEqInput::AdvanceOutputEvent() {
71 if (!ended_) {
72 input_->AdvanceOutputEvent();
73 MaybeSetEnded();
74 }
75}
76
77bool TimeLimitedNetEqInput::ended() const {
78 return ended_ || input_->ended();
79}
80
Danil Chapovalov065a52a2018-07-09 10:58:54 +020081absl::optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const {
82 return ended_ ? absl::nullopt : input_->NextHeader();
Henrik Lundin7687ad52018-07-02 10:14:46 +020083}
84
85void TimeLimitedNetEqInput::MaybeSetEnded() {
86 if (NextEventTime() && start_time_ms_ &&
87 *NextEventTime() - *start_time_ms_ > duration_ms_) {
88 ended_ = true;
89 }
90}
91
henrik.lundin7a38fd22017-04-28 01:35:53 -070092} // namespace test
93} // namespace webrtc