1 /*
2 * Copyright (c) 2021 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 "logging/rtc_event_log/events/rtc_event_begin_log.h"
12
13 #include "absl/strings/string_view.h"
14
15 namespace webrtc {
16 constexpr RtcEvent::Type RtcEventBeginLog::kType;
17 constexpr EventParameters RtcEventBeginLog::event_params_;
18 constexpr FieldParameters RtcEventBeginLog::utc_start_time_params_;
19
RtcEventBeginLog(Timestamp timestamp,Timestamp utc_start_time)20 RtcEventBeginLog::RtcEventBeginLog(Timestamp timestamp,
21 Timestamp utc_start_time)
22 : RtcEvent(timestamp.us()), utc_start_time_ms_(utc_start_time.ms()) {}
23
RtcEventBeginLog(const RtcEventBeginLog & other)24 RtcEventBeginLog::RtcEventBeginLog(const RtcEventBeginLog& other)
25 : RtcEvent(other.timestamp_us_) {}
26
27 RtcEventBeginLog::~RtcEventBeginLog() = default;
28
Encode(rtc::ArrayView<const RtcEvent * > batch)29 std::string RtcEventBeginLog::Encode(rtc::ArrayView<const RtcEvent*> batch) {
30 EventEncoder encoder(event_params_, batch);
31
32 encoder.EncodeField(
33 utc_start_time_params_,
34 ExtractRtcEventMember(batch, &RtcEventBeginLog::utc_start_time_ms_));
35
36 return encoder.AsString();
37 }
38
Parse(absl::string_view encoded_bytes,bool batched,std::vector<LoggedStartEvent> & output)39 RtcEventLogParseStatus RtcEventBeginLog::Parse(
40 absl::string_view encoded_bytes,
41 bool batched,
42 std::vector<LoggedStartEvent>& output) {
43 EventParser parser;
44 auto status = parser.Initialize(encoded_bytes, batched);
45 if (!status.ok())
46 return status;
47
48 rtc::ArrayView<LoggedStartEvent> output_batch =
49 ExtendLoggedBatch(output, parser.NumEventsInBatch());
50
51 constexpr FieldParameters timestamp_params{
52 "timestamp_ms", FieldParameters::kTimestampField, FieldType::kVarInt, 64};
53 RtcEventLogParseStatusOr<rtc::ArrayView<uint64_t>> result =
54 parser.ParseNumericField(timestamp_params);
55 if (!result.ok())
56 return result.status();
57 status = PopulateRtcEventTimestamp(
58 result.value(), &LoggedStartEvent::timestamp, output_batch);
59 if (!status.ok())
60 return status;
61
62 result = parser.ParseNumericField(utc_start_time_params_);
63 if (!result.ok())
64 return result.status();
65 status = PopulateRtcEventTimestamp(
66 result.value(), &LoggedStartEvent::utc_start_time, output_batch);
67 if (!status.ok())
68 return status;
69
70 return RtcEventLogParseStatus::Success();
71 }
72
73 } // namespace webrtc
74