Chromium Code Reviews| 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 { | |
| 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. | |
| 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( | |
| 67 SwapQueue<ControlMessage>* message_queue, | |
| 68 SwapQueue<std::unique_ptr<rtclog::Event>>* event_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<ControlMessage>* message_queue_; | |
| 89 SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue_; | |
| 90 | |
| 91 // History containing the most recent events (~ 10 s). | |
| 92 RingBuffer<std::unique_ptr<rtclog::Event>> history_; | |
| 93 | |
| 94 // History containing all past configuration events. | |
| 95 std::vector<std::unique_ptr<rtclog::Event>> config_history_; | |
| 96 | |
| 97 rtc::scoped_ptr<FileWrapper> file_; | |
|
the sun
2016/04/20 11:30:15
unique_ptr
terelius
2016/04/21 08:10:41
Done.
| |
| 98 rtc::PlatformThread thread_; | |
| 99 | |
| 100 int64_t max_size_bytes_; | |
| 101 int64_t written_bytes_; | |
| 102 int64_t start_time_; | |
| 103 int64_t stop_time_; | |
| 104 | |
| 105 bool has_recent_event_; | |
| 106 std::unique_ptr<rtclog::Event> most_recent_event_; | |
| 107 | |
| 108 // Temporary space for serializing profobuf data. | |
| 109 std::string output_string_; | |
| 110 | |
| 111 rtc::Event* wake_up_; | |
| 112 rtc::Event* stopped_; | |
| 113 | |
| 114 const Clock* const clock_; | |
| 115 | |
| 116 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); | |
| 117 }; | |
| 118 | |
| 119 } // namespace webrtc | |
| 120 | |
| 121 #endif // ENABLE_RTC_EVENT_LOG | |
| 122 | |
| 123 #endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ | |
| OLD | NEW |