blob: 74f066d575ac86439dc62039f82467818eb16e30 [file] [log] [blame]
tereliusd5c1a0b2016-05-13 00:42:59 -07001/*
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#ifndef WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_
11#define WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_
12
13#include <string>
14#include <vector>
15
16#include "webrtc/call/rtc_event_log.h"
17#include "webrtc/video_receive_stream.h"
18#include "webrtc/video_send_stream.h"
19
20// Files generated at build-time by the protobuf compiler.
21#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
22#include "external/webrtc/webrtc/call/rtc_event_log.pb.h"
23#else
24#include "webrtc/call/rtc_event_log.pb.h"
25#endif
26
27namespace webrtc {
28
29enum class MediaType;
30
31class ParsedRtcEventLog {
32 friend class RtcEventLogTestHelper;
33
34 public:
35 enum EventType {
36 UNKNOWN_EVENT = 0,
37 LOG_START = 1,
38 LOG_END = 2,
39 RTP_EVENT = 3,
40 RTCP_EVENT = 4,
41 AUDIO_PLAYOUT_EVENT = 5,
42 BWE_PACKET_LOSS_EVENT = 6,
43 BWE_PACKET_DELAY_EVENT = 7,
44 VIDEO_RECEIVER_CONFIG_EVENT = 8,
45 VIDEO_SENDER_CONFIG_EVENT = 9,
46 AUDIO_RECEIVER_CONFIG_EVENT = 10,
47 AUDIO_SENDER_CONFIG_EVENT = 11
48 };
49
50 // Reads an RtcEventLog file and returns true if parsing was successful.
51 bool ParseFile(const std::string& file_name);
52
terelius8c165202016-08-22 11:35:47 -070053 // Reads an RtcEventLog from a string and returns true if successful.
54 bool ParseString(const std::string& s);
55
56 // Reads an RtcEventLog from an istream and returns true if successful.
57 bool ParseStream(std::istream& stream);
58
tereliusd5c1a0b2016-05-13 00:42:59 -070059 // Returns the number of events in an EventStream.
60 size_t GetNumberOfEvents() const;
61
62 // Reads the arrival timestamp (in microseconds) from a rtclog::Event.
63 int64_t GetTimestamp(size_t index) const;
64
65 // Reads the event type of the rtclog::Event at |index|.
66 EventType GetEventType(size_t index) const;
67
68 // Reads the header, direction, media type, header length and packet length
69 // from the RTP event at |index|, and stores the values in the corresponding
70 // output parameters. The output parameters can be set to nullptr if those
71 // values aren't needed.
72 // NB: The header must have space for at least IP_PACKET_SIZE bytes.
73 void GetRtpHeader(size_t index,
74 PacketDirection* incoming,
75 MediaType* media_type,
76 uint8_t* header,
77 size_t* header_length,
78 size_t* total_length) const;
79
80 // Reads packet, direction, media type and packet length from the RTCP event
81 // at |index|, and stores the values in the corresponding output parameters.
82 // The output parameters can be set to nullptr if those values aren't needed.
83 // NB: The packet must have space for at least IP_PACKET_SIZE bytes.
84 void GetRtcpPacket(size_t index,
85 PacketDirection* incoming,
86 MediaType* media_type,
87 uint8_t* packet,
88 size_t* length) const;
89
90 // Reads a config event to a (non-NULL) VideoReceiveStream::Config struct.
91 // Only the fields that are stored in the protobuf will be written.
92 void GetVideoReceiveConfig(size_t index,
93 VideoReceiveStream::Config* config) const;
94
95 // Reads a config event to a (non-NULL) VideoSendStream::Config struct.
96 // Only the fields that are stored in the protobuf will be written.
97 void GetVideoSendConfig(size_t index, VideoSendStream::Config* config) const;
98
99 // Reads the SSRC from the audio playout event at |index|. The SSRC is stored
100 // in the output parameter ssrc. The output parameter can be set to nullptr
101 // and in that case the function only asserts that the event is well formed.
102 void GetAudioPlayout(size_t index, uint32_t* ssrc) const;
103
104 // Reads bitrate, fraction loss (as defined in RFC 1889) and total number of
105 // expected packets from the BWE event at |index| and stores the values in
106 // the corresponding output parameters. The output parameters can be set to
107 // nullptr if those values aren't needed.
108 // NB: The packet must have space for at least IP_PACKET_SIZE bytes.
109 void GetBwePacketLossEvent(size_t index,
110 int32_t* bitrate,
111 uint8_t* fraction_loss,
112 int32_t* total_packets) const;
113
114 private:
terelius8c165202016-08-22 11:35:47 -0700115 std::vector<rtclog::Event> events_;
tereliusd5c1a0b2016-05-13 00:42:59 -0700116};
117
118} // namespace webrtc
119
120#endif // WEBRTC_CALL_RTC_EVENT_LOG_PARSER_H_