| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool ParsedRtcEventLog::ParseString(const std::string& s) { | 119 bool ParsedRtcEventLog::ParseString(const std::string& s) { |
| 120 std::istringstream stream(s, std::ios_base::in | std::ios_base::binary); | 120 std::istringstream stream(s, std::ios_base::in | std::ios_base::binary); |
| 121 return ParseStream(stream); | 121 return ParseStream(stream); |
| 122 } | 122 } |
| 123 | 123 |
| 124 bool ParsedRtcEventLog::ParseStream(std::istream& stream) { | 124 bool ParsedRtcEventLog::ParseStream(std::istream& stream) { |
| 125 events_.clear(); | 125 events_.clear(); |
| 126 const size_t kMaxEventSize = (1u << 16) - 1; | 126 const size_t kMaxEventSize = (1u << 16) - 1; |
| 127 char tmp_buffer[kMaxEventSize]; | 127 std::vector<char> tmp_buffer(kMaxEventSize); |
| 128 uint64_t tag; | 128 uint64_t tag; |
| 129 uint64_t message_length; | 129 uint64_t message_length; |
| 130 bool success; | 130 bool success; |
| 131 | 131 |
| 132 RTC_DCHECK(stream.good()); | 132 RTC_DCHECK(stream.good()); |
| 133 | 133 |
| 134 while (1) { | 134 while (1) { |
| 135 // Check whether we have reached end of file. | 135 // Check whether we have reached end of file. |
| 136 stream.peek(); | 136 stream.peek(); |
| 137 if (stream.eof()) { | 137 if (stream.eof()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 std::tie(message_length, success) = ParseVarInt(stream); | 155 std::tie(message_length, success) = ParseVarInt(stream); |
| 156 if (!success) { | 156 if (!success) { |
| 157 LOG(LS_WARNING) << "Missing message length after protobuf field tag."; | 157 LOG(LS_WARNING) << "Missing message length after protobuf field tag."; |
| 158 return false; | 158 return false; |
| 159 } else if (message_length > kMaxEventSize) { | 159 } else if (message_length > kMaxEventSize) { |
| 160 LOG(LS_WARNING) << "Protobuf message length is too large."; | 160 LOG(LS_WARNING) << "Protobuf message length is too large."; |
| 161 return false; | 161 return false; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Read the next protobuf event to a temporary char buffer. | 164 // Read the next protobuf event to a temporary char buffer. |
| 165 stream.read(tmp_buffer, message_length); | 165 stream.read(tmp_buffer.data(), message_length); |
| 166 if (stream.gcount() != static_cast<int>(message_length)) { | 166 if (stream.gcount() != static_cast<int>(message_length)) { |
| 167 LOG(LS_WARNING) << "Failed to read protobuf message from file."; | 167 LOG(LS_WARNING) << "Failed to read protobuf message from file."; |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Parse the protobuf event from the buffer. | 171 // Parse the protobuf event from the buffer. |
| 172 rtclog::Event event; | 172 rtclog::Event event; |
| 173 if (!event.ParseFromArray(tmp_buffer, message_length)) { | 173 if (!event.ParseFromArray(tmp_buffer.data(), message_length)) { |
| 174 LOG(LS_WARNING) << "Failed to parse protobuf message."; | 174 LOG(LS_WARNING) << "Failed to parse protobuf message."; |
| 175 return false; | 175 return false; |
| 176 } | 176 } |
| 177 events_.push_back(event); | 177 events_.push_back(event); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 size_t ParsedRtcEventLog::GetNumberOfEvents() const { | 181 size_t ParsedRtcEventLog::GetNumberOfEvents() const { |
| 182 return events_.size(); | 182 return events_.size(); |
| 183 } | 183 } |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 if (fraction_loss != nullptr) { | 407 if (fraction_loss != nullptr) { |
| 408 *fraction_loss = loss_event.fraction_loss(); | 408 *fraction_loss = loss_event.fraction_loss(); |
| 409 } | 409 } |
| 410 RTC_CHECK(loss_event.has_total_packets()); | 410 RTC_CHECK(loss_event.has_total_packets()); |
| 411 if (total_packets != nullptr) { | 411 if (total_packets != nullptr) { |
| 412 *total_packets = loss_event.total_packets(); | 412 *total_packets = loss_event.total_packets(); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 } // namespace webrtc | 416 } // namespace webrtc |
| OLD | NEW |