OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 "webrtc/modules/audio_coding/neteq/tools/neteq_packet_source_input.h" |
| 12 |
| 13 #include <algorithm> |
| 14 #include <limits> |
| 15 |
| 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/modules/audio_coding/neteq/tools/rtc_event_log_source.h" |
| 18 #include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h" |
| 19 |
| 20 namespace webrtc { |
| 21 namespace test { |
| 22 |
| 23 NetEqPacketSourceInput::NetEqPacketSourceInput() : next_output_event_ms_(0) {} |
| 24 |
| 25 rtc::Optional<int64_t> NetEqPacketSourceInput::NextPacketTime() const { |
| 26 return packet_ |
| 27 ? rtc::Optional<int64_t>(static_cast<int64_t>(packet_->time_ms())) |
| 28 : rtc::Optional<int64_t>(); |
| 29 } |
| 30 |
| 31 rtc::Optional<RTPHeader> NetEqPacketSourceInput::NextHeader() const { |
| 32 return packet_ ? rtc::Optional<RTPHeader>(packet_->header()) |
| 33 : rtc::Optional<RTPHeader>(); |
| 34 } |
| 35 |
| 36 void NetEqPacketSourceInput::LoadNextPacket() { |
| 37 packet_ = source()->NextPacket(); |
| 38 } |
| 39 |
| 40 std::unique_ptr<NetEqInput::PacketData> NetEqPacketSourceInput::PopPacket() { |
| 41 if (!packet_) { |
| 42 return std::unique_ptr<PacketData>(); |
| 43 } |
| 44 std::unique_ptr<PacketData> packet_data(new PacketData); |
| 45 packet_->ConvertHeader(&packet_data->header); |
| 46 packet_data->payload.SetData(packet_->payload(), |
| 47 packet_->payload_length_bytes()); |
| 48 packet_data->time_ms = packet_->time_ms(); |
| 49 |
| 50 LoadNextPacket(); |
| 51 |
| 52 return packet_data; |
| 53 } |
| 54 |
| 55 NetEqRtpDumpInput::NetEqRtpDumpInput(const std::string& file_name) |
| 56 : source_(RtpFileSource::Create(file_name)) { |
| 57 LoadNextPacket(); |
| 58 } |
| 59 |
| 60 rtc::Optional<int64_t> NetEqRtpDumpInput::NextOutputEventTime() const { |
| 61 return next_output_event_ms_; |
| 62 } |
| 63 |
| 64 void NetEqRtpDumpInput::AdvanceOutputEvent() { |
| 65 if (next_output_event_ms_) { |
| 66 *next_output_event_ms_ += kOutputPeriodMs; |
| 67 } |
| 68 if (!NextPacketTime()) { |
| 69 next_output_event_ms_ = rtc::Optional<int64_t>(); |
| 70 } |
| 71 } |
| 72 |
| 73 PacketSource* NetEqRtpDumpInput::source() { |
| 74 return source_.get(); |
| 75 } |
| 76 |
| 77 NetEqEventLogInput::NetEqEventLogInput(const std::string& file_name) |
| 78 : source_(RtcEventLogSource::Create(file_name)) { |
| 79 LoadNextPacket(); |
| 80 AdvanceOutputEvent(); |
| 81 } |
| 82 |
| 83 rtc::Optional<int64_t> NetEqEventLogInput::NextOutputEventTime() const { |
| 84 return rtc::Optional<int64_t>(next_output_event_ms_); |
| 85 } |
| 86 |
| 87 void NetEqEventLogInput::AdvanceOutputEvent() { |
| 88 next_output_event_ms_ = |
| 89 rtc::Optional<int64_t>(source_->NextAudioOutputEventMs()); |
| 90 if (*next_output_event_ms_ == std::numeric_limits<int64_t>::max()) { |
| 91 next_output_event_ms_ = rtc::Optional<int64_t>(); |
| 92 } |
| 93 } |
| 94 |
| 95 PacketSource* NetEqEventLogInput::source() { |
| 96 return source_.get(); |
| 97 } |
| 98 |
| 99 } // namespace test |
| 100 } // namespace webrtc |
OLD | NEW |