OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 | |
11 #ifndef WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
12 #define WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
13 | |
14 #include <limits> | |
15 #include <string> | |
16 #include <utility> | |
17 #include <vector> | |
18 | |
19 #include "webrtc/base/constructormagic.h" | |
20 #include "webrtc/base/event.h" | |
21 #include "webrtc/base/platform_thread.h" | |
22 #include "webrtc/base/swap_queue.h" | |
23 #include "webrtc/call/ringbuffer.h" | |
24 #include "webrtc/system_wrappers/include/clock.h" | |
25 #include "webrtc/system_wrappers/include/file_wrapper.h" | |
26 | |
27 #ifdef ENABLE_RTC_EVENT_LOG | |
28 // Files generated at build-time by the protobuf compiler. | |
29 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | |
30 #include "external/webrtc/webrtc/call/rtc_event_log.pb.h" | |
31 #else | |
32 #include "webrtc/call/rtc_event_log.pb.h" | |
33 #endif | |
34 #endif | |
35 | |
36 #ifdef ENABLE_RTC_EVENT_LOG | |
37 | |
38 namespace webrtc { | |
39 | |
40 class RtcEventLogHelperThread { | |
the sun
2016/03/24 13:49:43
final
terelius
2016/04/21 08:10:40
Done.
| |
41 public: | |
42 struct ControlMessage { | |
43 ControlMessage() | |
44 : message_type(STOP_FILE), | |
45 file(nullptr), | |
46 max_size_bytes(0), | |
47 start_time(0), | |
48 stop_time(0) {} | |
49 enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type; | |
50 | |
51 rtc::scoped_ptr<FileWrapper> file; // Only used with START_FILE. | |
the sun
2016/03/24 13:49:43
unique_ptr
the sun
2016/04/20 11:30:15
Still want this.
terelius
2016/04/21 08:10:40
Done.
| |
52 int64_t max_size_bytes; // Only used with START_FILE. | |
53 int64_t start_time; // Only used with START_FILE. | |
54 int64_t stop_time; // Used with all 3 message types. | |
55 | |
56 friend void swap(ControlMessage& lhs, ControlMessage& rhs) { | |
57 using std::swap; | |
58 swap(lhs.message_type, rhs.message_type); | |
59 lhs.file.swap(rhs.file); | |
60 swap(lhs.max_size_bytes, rhs.max_size_bytes); | |
61 swap(lhs.start_time, rhs.start_time); | |
62 swap(lhs.stop_time, rhs.stop_time); | |
63 } | |
64 }; | |
65 | |
66 RtcEventLogHelperThread(SwapQueue<ControlMessage>* message_queue, | |
67 SwapQueue<rtclog::Event>* config_queue, | |
68 SwapQueue<rtclog::Event>* rtp_queue, | |
69 SwapQueue<rtclog::Event>* rtcp_queue, | |
70 SwapQueue<rtclog::Event>* acm_playout_queue, | |
71 SwapQueue<rtclog::Event>* bwe_loss_queue, | |
72 rtc::Event* wake_up, | |
73 rtc::Event* file_finished, | |
74 const Clock* const clock); | |
75 ~RtcEventLogHelperThread(); | |
76 | |
77 private: | |
78 static bool ThreadOutputFunction(void* obj); | |
79 | |
80 void TerminateThread(); | |
81 bool AppendEventToString(rtclog::Event* event); | |
82 void AppendEventToHistory(const rtclog::Event& event); | |
83 bool ProcessInOrder(bool memory, int64_t current_time); | |
84 void LogToMemory(); | |
85 void StartLogFile(); | |
86 void LogToFile(); | |
87 void StopLogFile(); | |
88 void WriteLog(); | |
89 | |
90 // Message queues for passing events to the logging thread. | |
91 SwapQueue<ControlMessage>* message_queue_; | |
92 SwapQueue<rtclog::Event>* config_queue_; | |
93 SwapQueue<rtclog::Event>* rtp_queue_; | |
94 SwapQueue<rtclog::Event>* rtcp_queue_; | |
95 SwapQueue<rtclog::Event>* acm_playout_queue_; | |
96 SwapQueue<rtclog::Event>* bwe_loss_queue_; | |
97 | |
98 // History containing the most recent events (~ 10 s). | |
99 RingBuffer<rtclog::Event> history_; | |
the sun
2016/03/24 13:49:43
I realize we've been at this before, but using a b
terelius
2016/03/29 09:38:32
As discussed in a previous comment, I would like t
the sun
2016/03/30 09:12:39
One custom ring buffer for another custom ring buf
stefan-webrtc
2016/03/30 09:23:55
I would very much prefer landing something sooner
terelius
2016/03/30 10:36:59
The point is that the ringbuffer for serialized ev
stefan-webrtc
2016/04/01 13:46:25
Sounds like a reasonable trade-off to me for the f
| |
100 | |
101 // History containing all past configuration events. | |
102 std::vector<rtclog::Event> config_history_; | |
103 | |
104 rtc::scoped_ptr<FileWrapper> file_; | |
105 rtc::PlatformThread thread_; | |
106 | |
107 int64_t max_size_bytes_; | |
108 int64_t written_bytes_; | |
109 int64_t start_time_; | |
110 int64_t stop_time_; | |
111 | |
112 // We want to extract the elements from the buffers in timestamp order | |
113 // and, because we can't peek into the SwapQueue, we need to keep the first | |
114 // elements outside. | |
115 rtclog::Event config_event_; | |
116 rtclog::Event rtp_event_; | |
117 rtclog::Event rtcp_event_; | |
118 rtclog::Event playout_event_; | |
119 rtclog::Event loss_event_; | |
120 bool valid_config_event_; | |
121 bool valid_rtp_event_; | |
122 bool valid_rtcp_event_; | |
123 bool valid_playout_event_; | |
124 bool valid_loss_event_; | |
125 | |
126 // Temporary space for serializing profobuf data. | |
127 std::string output_string_; | |
128 | |
129 rtc::Event* wake_up_; | |
130 rtc::Event* stopped_; | |
131 | |
132 const Clock* const clock_; | |
133 | |
134 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); | |
135 }; | |
136 | |
137 } // namespace webrtc | |
138 | |
139 #endif // ENABLE_RTC_EVENT_LOG | |
140 | |
141 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
OLD | NEW |