• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2018 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_event_log_input.h"
12 
13 #include <limits>
14 #include <memory>
15 
16 #include "absl/strings/string_view.h"
17 #include "modules/audio_coding/neteq/tools/rtc_event_log_source.h"
18 #include "rtc_base/checks.h"
19 
20 namespace webrtc {
21 namespace test {
22 
CreateFromFile(absl::string_view file_name,absl::optional<uint32_t> ssrc_filter)23 NetEqEventLogInput* NetEqEventLogInput::CreateFromFile(
24     absl::string_view file_name,
25     absl::optional<uint32_t> ssrc_filter) {
26   auto event_log_src =
27       RtcEventLogSource::CreateFromFile(file_name, ssrc_filter);
28   if (!event_log_src) {
29     return nullptr;
30   }
31   return new NetEqEventLogInput(std::move(event_log_src));
32 }
33 
CreateFromString(absl::string_view file_contents,absl::optional<uint32_t> ssrc_filter)34 NetEqEventLogInput* NetEqEventLogInput::CreateFromString(
35     absl::string_view file_contents,
36     absl::optional<uint32_t> ssrc_filter) {
37   auto event_log_src =
38       RtcEventLogSource::CreateFromString(file_contents, ssrc_filter);
39   if (!event_log_src) {
40     return nullptr;
41   }
42   return new NetEqEventLogInput(std::move(event_log_src));
43 }
44 
NextOutputEventTime() const45 absl::optional<int64_t> NetEqEventLogInput::NextOutputEventTime() const {
46   return next_output_event_ms_;
47 }
48 
AdvanceOutputEvent()49 void NetEqEventLogInput::AdvanceOutputEvent() {
50   next_output_event_ms_ = source_->NextAudioOutputEventMs();
51   if (*next_output_event_ms_ == std::numeric_limits<int64_t>::max()) {
52     next_output_event_ms_ = absl::nullopt;
53   }
54 }
55 
source()56 PacketSource* NetEqEventLogInput::source() {
57   return source_.get();
58 }
59 
NetEqEventLogInput(std::unique_ptr<RtcEventLogSource> source)60 NetEqEventLogInput::NetEqEventLogInput(
61     std::unique_ptr<RtcEventLogSource> source)
62     : source_(std::move(source)) {
63   LoadNextPacket();
64   AdvanceOutputEvent();
65 }
66 
67 }  // namespace test
68 }  // namespace webrtc
69