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/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 { | |
the sun
2016/03/11 13:21:57
Enclose the whole contents with "#if ENABLE_RTC_EV
terelius
2016/03/18 14:03:25
Done.
| |
37 | |
38 #ifdef ENABLE_RTC_EVENT_LOG | |
39 | |
40 class RtcEventLogHelperThread { | |
41 public: | |
42 struct ControlMessage { | |
43 enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type; | |
44 | |
45 rtc::scoped_ptr<FileWrapper> file; // Only used with START_FILE. | |
46 int64_t max_size_bytes; // Only used with START_FILE. | |
the sun
2016/03/11 13:21:57
Add default initialization
terelius
2016/03/18 14:03:25
Not sure why, but done.
| |
47 int64_t start_time; // Only used with START_FILE. | |
48 int64_t stop_time; // Used with all 3 message types. | |
49 | |
50 friend void swap(ControlMessage& lhs, ControlMessage& rhs) { | |
51 using std::swap; | |
52 swap(lhs.message_type, rhs.message_type); | |
53 lhs.file.swap(rhs.file); | |
54 swap(lhs.max_size_bytes, rhs.max_size_bytes); | |
55 swap(lhs.start_time, rhs.start_time); | |
56 swap(lhs.stop_time, rhs.stop_time); | |
57 } | |
58 }; | |
59 | |
60 RtcEventLogHelperThread(SwapQueue<ControlMessage>* message_queue, | |
61 SwapQueue<rtclog::Event>* config_queue, | |
62 SwapQueue<rtclog::Event>* rtp_queue, | |
63 SwapQueue<rtclog::Event>* rtcp_queue, | |
64 SwapQueue<rtclog::Event>* acm_playout_queue, | |
65 SwapQueue<rtclog::Event>* bwe_loss_queue, | |
66 rtc::Event* wake_up, | |
67 rtc::Event* file_finished, | |
68 const Clock* const clock); | |
69 ~RtcEventLogHelperThread(); | |
70 | |
71 private: | |
72 static bool ThreadOutputFunction(void* obj); | |
73 | |
74 void TerminateThread(); | |
75 bool AppendEventToString(rtclog::Event* event); | |
76 void AppendEventToHistory(const rtclog::Event& event); | |
77 bool ProcessInOrder(bool memory, int64_t current_time); | |
78 void LogToMemory(); | |
79 void StartLogFile(); | |
80 void LogToFile(); | |
81 void StopLogFile(); | |
82 void WriteLog(); | |
83 | |
84 // Message queues for passing events to the logging thread. | |
85 SwapQueue<ControlMessage>* message_queue_; | |
86 SwapQueue<rtclog::Event>* config_queue_; | |
87 SwapQueue<rtclog::Event>* rtp_queue_; | |
88 SwapQueue<rtclog::Event>* rtcp_queue_; | |
89 SwapQueue<rtclog::Event>* acm_playout_queue_; | |
90 SwapQueue<rtclog::Event>* bwe_loss_queue_; | |
91 | |
92 // History containing the most recent events (~ 10 s). | |
93 RingBuffer<rtclog::Event> history_; | |
the sun
2016/03/11 13:21:57
How about using a std::queue instead of the RingBu
terelius
2016/03/18 14:03:25
A space based limit is more efficient and more nat
| |
94 | |
95 // History containing all past configuration events. | |
96 std::vector<rtclog::Event> config_history_; | |
97 | |
98 rtc::scoped_ptr<FileWrapper> file_; | |
99 rtc::PlatformThread thread_; | |
100 | |
101 int64_t max_size_bytes_; | |
the sun
2016/03/11 13:21:57
Use non-static member initialization. It is not as
terelius
2016/03/18 14:03:25
I think the general consensus in the video team is
| |
102 int64_t written_bytes_; | |
103 int64_t start_time_; | |
104 int64_t stop_time_; | |
105 | |
106 // We want to extract the elements from the buffers in timestamp order | |
107 // and, because we can't peek into the SwapQueue, we need to keep the first | |
108 // elements outside. | |
109 rtclog::Event config_event_; | |
110 rtclog::Event rtp_event_; | |
111 rtclog::Event rtcp_event_; | |
112 rtclog::Event playout_event_; | |
113 rtclog::Event loss_event_; | |
114 bool valid_config_event_; | |
115 bool valid_rtp_event_; | |
116 bool valid_rtcp_event_; | |
117 bool valid_playout_event_; | |
118 bool valid_loss_event_; | |
119 | |
120 // Temporary space for serializing profobuf data. | |
121 std::string output_string_; | |
122 | |
123 rtc::Event* wake_up_; | |
124 rtc::Event* stopped_; | |
125 | |
126 const Clock* const clock_; | |
127 | |
128 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); | |
129 }; | |
130 | |
131 } // namespace webrtc | |
132 | |
133 #endif // ENABLE_RTC_EVENT_LOG | |
134 | |
135 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
OLD | NEW |