OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | |
stefan-webrtc
2016/03/01 09:44:16
2016 perhaps?
terelius
2016/03/09 19:49:40
Done.
| |
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/call/ringbuffer.h" | |
23 #include "webrtc/common_audio/swap_queue.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 namespace webrtc { | |
37 | |
38 #ifdef ENABLE_RTC_EVENT_LOG | |
39 | |
40 struct EventLogMessage { | |
the sun
2016/02/25 15:23:19
Move inside RtcEventLogHelperThread and rename to
terelius
2016/03/09 19:49:40
Done.
| |
41 enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type; | |
42 | |
43 rtc::scoped_ptr<FileWrapper> file; // Only used with START_FILE. | |
44 int64_t max_size_bytes; // Only used with START_FILE. | |
45 int64_t start_time; // Only used with START_FILE. | |
46 int64_t stop_time; // Used with all 3 message types. | |
47 | |
48 friend void swap(EventLogMessage& x, EventLogMessage& y) { | |
the sun
2016/02/25 15:23:19
it's common to use rhs and lhs for the arguments i
terelius
2016/03/09 19:49:39
Done.
| |
49 using std::swap; | |
50 swap(x.message_type, y.message_type); | |
51 FileWrapper* xfile = x.file.release(); | |
the sun
2016/02/25 15:23:19
scoped_ptr supports swap(). Just x.file.swap(y.fil
terelius
2016/03/09 19:49:40
Done.
| |
52 FileWrapper* yfile = y.file.release(); | |
53 x.file.reset(yfile); | |
54 y.file.reset(xfile); | |
55 swap(x.max_size_bytes, y.max_size_bytes); | |
56 swap(x.start_time, y.start_time); | |
57 swap(x.stop_time, y.stop_time); | |
58 } | |
59 }; | |
60 | |
61 class RtcEventLogHelperThread { | |
62 public: | |
63 RtcEventLogHelperThread(SwapQueue<EventLogMessage>* message_queue, | |
64 SwapQueue<rtclog::Event>* config_queue, | |
65 SwapQueue<rtclog::Event>* rtp_queue, | |
66 SwapQueue<rtclog::Event>* rtcp_queue, | |
67 SwapQueue<rtclog::Event>* acm_playout_queue, | |
68 SwapQueue<rtclog::Event>* bwe_loss_queue, | |
69 rtc::Event* wake_up, | |
70 rtc::Event* file_finished, | |
71 const Clock* const clock); | |
72 ~RtcEventLogHelperThread(); | |
73 | |
74 private: | |
75 static bool ThreadOutputFunction(void* obj); | |
76 | |
77 void TerminateThread(); | |
78 bool AppendEventToString(rtclog::Event* event); | |
79 void AppendEventToHistory(const rtclog::Event& event); | |
80 bool ProcessInOrder(bool memory, int64_t current_time); | |
81 void LogToMemory(); | |
82 void StartLogFile(); | |
83 void LogToFile(); | |
84 void StopLogFile(); | |
85 void WriteLog(); | |
86 | |
87 // Message queues for passing events to the logging thread. | |
88 SwapQueue<EventLogMessage>* message_queue_; | |
89 SwapQueue<rtclog::Event>* config_queue_; | |
90 SwapQueue<rtclog::Event>* rtp_queue_; | |
91 SwapQueue<rtclog::Event>* rtcp_queue_; | |
92 SwapQueue<rtclog::Event>* acm_playout_queue_; | |
93 SwapQueue<rtclog::Event>* bwe_loss_queue_; | |
94 | |
95 // History containing the most recent events (~ 10 s). | |
96 RingBuffer<rtclog::Event> history_; | |
97 | |
98 // History containing all past configuration events. | |
99 std::vector<rtclog::Event> config_history_; | |
100 | |
101 bool log_to_memory_; | |
102 rtc::scoped_ptr<FileWrapper> file_; | |
103 rtc::PlatformThread thread_; | |
104 | |
105 int64_t max_size_bytes_; | |
106 int64_t written_bytes_; | |
107 int64_t start_time_; | |
108 int64_t stop_time_; | |
109 | |
110 // We want to extract the elements from the buffers in timestamp order | |
111 // and, because we can't peek into the SwapQueue, we need to keep the first | |
112 // elements outside. | |
113 rtclog::Event config_event_; | |
114 rtclog::Event rtp_event_; | |
115 rtclog::Event rtcp_event_; | |
116 rtclog::Event playout_event_; | |
117 rtclog::Event loss_event_; | |
118 bool valid_config_event_; | |
119 bool valid_rtp_event_; | |
120 bool valid_rtcp_event_; | |
121 bool valid_playout_event_; | |
122 bool valid_loss_event_; | |
123 | |
124 // Temporary space for serializing profobuf data. | |
125 std::string output_string_; | |
126 | |
127 rtc::Event* wake_up_; | |
128 rtc::Event* stopped_; | |
129 | |
130 const Clock* const clock_; | |
131 | |
132 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); | |
133 }; | |
134 | |
135 } // namespace webrtc | |
136 | |
137 #endif // ENABLE_RTC_EVENT_LOG | |
138 | |
139 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
OLD | NEW |