blob: bb2a01e0e17554848648f4a6e2c8483bfc132c1a [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
13#include <sstream>
14
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 {
22 std::stringstream ss;
23 ss << "{"
24 << "time_ms: " << static_cast<int64_t>(time_ms) << ", "
25 << "header: {"
26 << "pt: " << static_cast<int>(header.payloadType) << ", "
27 << "sn: " << header.sequenceNumber << ", "
28 << "ts: " << header.timestamp << ", "
29 << "ssrc: " << header.ssrc << "}, "
30 << "payload bytes: " << payload.size() << "}";
31 return ss.str();
32}
33
Henrik Lundin7687ad52018-07-02 10:14:46 +020034TimeLimitedNetEqInput::TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input,
35 int64_t duration_ms)
36 : input_(std::move(input)),
37 start_time_ms_(input_->NextEventTime()),
38 duration_ms_(duration_ms) {}
39
Mirko Bonadei682aac52018-07-20 13:59:20 +020040TimeLimitedNetEqInput::~TimeLimitedNetEqInput() = default;
41
Danil Chapovalov065a52a2018-07-09 10:58:54 +020042absl::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const {
43 return ended_ ? absl::nullopt : input_->NextPacketTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020044}
45
Danil Chapovalov065a52a2018-07-09 10:58:54 +020046absl::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const {
47 return ended_ ? absl::nullopt : input_->NextOutputEventTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020048}
49
50std::unique_ptr<NetEqInput::PacketData> TimeLimitedNetEqInput::PopPacket() {
51 if (ended_) {
52 return std::unique_ptr<PacketData>();
53 }
54 auto packet = input_->PopPacket();
55 MaybeSetEnded();
56 return packet;
57}
58
59void TimeLimitedNetEqInput::AdvanceOutputEvent() {
60 if (!ended_) {
61 input_->AdvanceOutputEvent();
62 MaybeSetEnded();
63 }
64}
65
66bool TimeLimitedNetEqInput::ended() const {
67 return ended_ || input_->ended();
68}
69
Danil Chapovalov065a52a2018-07-09 10:58:54 +020070absl::optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const {
71 return ended_ ? absl::nullopt : input_->NextHeader();
Henrik Lundin7687ad52018-07-02 10:14:46 +020072}
73
74void TimeLimitedNetEqInput::MaybeSetEnded() {
75 if (NextEventTime() && start_time_ms_ &&
76 *NextEventTime() - *start_time_ms_ > duration_ms_) {
77 ended_ = true;
78 }
79}
80
henrik.lundin7a38fd22017-04-28 01:35:53 -070081} // namespace test
82} // namespace webrtc