blob: fed3eccea7ccde26509ba02f0a3de874661a4c22 [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
18std::string NetEqInput::PacketData::ToString() const {
19 std::stringstream ss;
20 ss << "{"
21 << "time_ms: " << static_cast<int64_t>(time_ms) << ", "
22 << "header: {"
23 << "pt: " << static_cast<int>(header.payloadType) << ", "
24 << "sn: " << header.sequenceNumber << ", "
25 << "ts: " << header.timestamp << ", "
26 << "ssrc: " << header.ssrc << "}, "
27 << "payload bytes: " << payload.size() << "}";
28 return ss.str();
29}
30
Henrik Lundin7687ad52018-07-02 10:14:46 +020031TimeLimitedNetEqInput::TimeLimitedNetEqInput(std::unique_ptr<NetEqInput> input,
32 int64_t duration_ms)
33 : input_(std::move(input)),
34 start_time_ms_(input_->NextEventTime()),
35 duration_ms_(duration_ms) {}
36
Danil Chapovalov065a52a2018-07-09 10:58:54 +020037absl::optional<int64_t> TimeLimitedNetEqInput::NextPacketTime() const {
38 return ended_ ? absl::nullopt : input_->NextPacketTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020039}
40
Danil Chapovalov065a52a2018-07-09 10:58:54 +020041absl::optional<int64_t> TimeLimitedNetEqInput::NextOutputEventTime() const {
42 return ended_ ? absl::nullopt : input_->NextOutputEventTime();
Henrik Lundin7687ad52018-07-02 10:14:46 +020043}
44
45std::unique_ptr<NetEqInput::PacketData> TimeLimitedNetEqInput::PopPacket() {
46 if (ended_) {
47 return std::unique_ptr<PacketData>();
48 }
49 auto packet = input_->PopPacket();
50 MaybeSetEnded();
51 return packet;
52}
53
54void TimeLimitedNetEqInput::AdvanceOutputEvent() {
55 if (!ended_) {
56 input_->AdvanceOutputEvent();
57 MaybeSetEnded();
58 }
59}
60
61bool TimeLimitedNetEqInput::ended() const {
62 return ended_ || input_->ended();
63}
64
Danil Chapovalov065a52a2018-07-09 10:58:54 +020065absl::optional<RTPHeader> TimeLimitedNetEqInput::NextHeader() const {
66 return ended_ ? absl::nullopt : input_->NextHeader();
Henrik Lundin7687ad52018-07-02 10:14:46 +020067}
68
69void TimeLimitedNetEqInput::MaybeSetEnded() {
70 if (NextEventTime() && start_time_ms_ &&
71 *NextEventTime() - *start_time_ms_ > duration_ms_) {
72 ended_ = true;
73 }
74}
75
henrik.lundin7a38fd22017-04-28 01:35:53 -070076} // namespace test
77} // namespace webrtc