• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
11 #ifndef LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_AUDIO_PLAYOUT_H_
12 #define LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_AUDIO_PLAYOUT_H_
13 
14 #include <stdint.h>
15 
16 #include <map>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include "absl/strings/string_view.h"
22 #include "api/rtc_event_log/rtc_event.h"
23 #include "api/units/timestamp.h"
24 #include "logging/rtc_event_log/events/rtc_event_definition.h"
25 
26 namespace webrtc {
27 
28 struct LoggedAudioPlayoutEvent {
29   LoggedAudioPlayoutEvent() = default;
LoggedAudioPlayoutEventLoggedAudioPlayoutEvent30   LoggedAudioPlayoutEvent(Timestamp timestamp, uint32_t ssrc)
31       : timestamp(timestamp), ssrc(ssrc) {}
32 
log_time_usLoggedAudioPlayoutEvent33   int64_t log_time_us() const { return timestamp.us(); }
log_time_msLoggedAudioPlayoutEvent34   int64_t log_time_ms() const { return timestamp.ms(); }
log_timeLoggedAudioPlayoutEvent35   Timestamp log_time() const { return timestamp; }
36 
37   Timestamp timestamp = Timestamp::MinusInfinity();
38   uint32_t ssrc;
39 };
40 
41 class RtcEventAudioPlayout final : public RtcEvent {
42  public:
43   static constexpr Type kType = Type::AudioPlayout;
44 
45   explicit RtcEventAudioPlayout(uint32_t ssrc);
46   ~RtcEventAudioPlayout() override = default;
47 
GetType()48   Type GetType() const override { return kType; }
IsConfigEvent()49   bool IsConfigEvent() const override { return false; }
50 
51   std::unique_ptr<RtcEventAudioPlayout> Copy() const;
52 
ssrc()53   uint32_t ssrc() const { return ssrc_; }
54 
Encode(rtc::ArrayView<const RtcEvent * > batch)55   static std::string Encode(rtc::ArrayView<const RtcEvent*> batch) {
56     return RtcEventAudioPlayout::definition_.EncodeBatch(batch);
57   }
58 
Parse(absl::string_view encoded_bytes,bool batched,std::map<uint32_t,std::vector<LoggedAudioPlayoutEvent>> & output)59   static RtcEventLogParseStatus Parse(
60       absl::string_view encoded_bytes,
61       bool batched,
62       std::map<uint32_t, std::vector<LoggedAudioPlayoutEvent>>& output) {
63     std::vector<LoggedAudioPlayoutEvent> temp_output;
64     auto status = RtcEventAudioPlayout::definition_.ParseBatch(
65         encoded_bytes, batched, temp_output);
66     for (const LoggedAudioPlayoutEvent& event : temp_output) {
67       output[event.ssrc].push_back(event);
68     }
69     return status;
70   }
71 
72  private:
73   RtcEventAudioPlayout(const RtcEventAudioPlayout& other);
74 
75   const uint32_t ssrc_;
76 
77   static constexpr RtcEventDefinition<RtcEventAudioPlayout,
78                                       LoggedAudioPlayoutEvent,
79                                       uint32_t>
80       definition_{{"AudioPlayout", RtcEventAudioPlayout::kType},
81                   {&RtcEventAudioPlayout::ssrc_,
82                    &LoggedAudioPlayoutEvent::ssrc,
83                    {"ssrc", /*id=*/1, FieldType::kFixed32, /*width=*/32}}};
84 };
85 
86 }  // namespace webrtc
87 
88 #endif  // LOGGING_RTC_EVENT_LOG_EVENTS_RTC_EVENT_AUDIO_PLAYOUT_H_
89