Chromium Code Reviews| Index: webrtc/call/rtc_event_log_helper_thread.h |
| diff --git a/webrtc/call/rtc_event_log_helper_thread.h b/webrtc/call/rtc_event_log_helper_thread.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02d1fe8208f009a227bcdab349a161d3295d7fba |
| --- /dev/null |
| +++ b/webrtc/call/rtc_event_log_helper_thread.h |
| @@ -0,0 +1,139 @@ |
| +/* |
| + * 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.
|
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ |
| +#define WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ |
| + |
| +#include <limits> |
| +#include <string> |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "webrtc/base/constructormagic.h" |
| +#include "webrtc/base/event.h" |
| +#include "webrtc/base/platform_thread.h" |
| +#include "webrtc/call/ringbuffer.h" |
| +#include "webrtc/common_audio/swap_queue.h" |
| +#include "webrtc/system_wrappers/include/clock.h" |
| +#include "webrtc/system_wrappers/include/file_wrapper.h" |
| + |
| +#ifdef ENABLE_RTC_EVENT_LOG |
| +// Files generated at build-time by the protobuf compiler. |
| +#ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| +#include "external/webrtc/webrtc/call/rtc_event_log.pb.h" |
| +#else |
| +#include "webrtc/call/rtc_event_log.pb.h" |
| +#endif |
| +#endif |
| + |
| +namespace webrtc { |
| + |
| +#ifdef ENABLE_RTC_EVENT_LOG |
| + |
| +struct EventLogMessage { |
|
the sun
2016/02/25 15:23:19
Move inside RtcEventLogHelperThread and rename to
terelius
2016/03/09 19:49:40
Done.
|
| + enum { START_FILE, STOP_FILE, TERMINATE_THREAD } message_type; |
| + |
| + rtc::scoped_ptr<FileWrapper> file; // Only used with START_FILE. |
| + int64_t max_size_bytes; // Only used with START_FILE. |
| + int64_t start_time; // Only used with START_FILE. |
| + int64_t stop_time; // Used with all 3 message types. |
| + |
| + 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.
|
| + using std::swap; |
| + swap(x.message_type, y.message_type); |
| + 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.
|
| + FileWrapper* yfile = y.file.release(); |
| + x.file.reset(yfile); |
| + y.file.reset(xfile); |
| + swap(x.max_size_bytes, y.max_size_bytes); |
| + swap(x.start_time, y.start_time); |
| + swap(x.stop_time, y.stop_time); |
| + } |
| +}; |
| + |
| +class RtcEventLogHelperThread { |
| + public: |
| + RtcEventLogHelperThread(SwapQueue<EventLogMessage>* message_queue, |
| + SwapQueue<rtclog::Event>* config_queue, |
| + SwapQueue<rtclog::Event>* rtp_queue, |
| + SwapQueue<rtclog::Event>* rtcp_queue, |
| + SwapQueue<rtclog::Event>* acm_playout_queue, |
| + SwapQueue<rtclog::Event>* bwe_loss_queue, |
| + rtc::Event* wake_up, |
| + rtc::Event* file_finished, |
| + const Clock* const clock); |
| + ~RtcEventLogHelperThread(); |
| + |
| + private: |
| + static bool ThreadOutputFunction(void* obj); |
| + |
| + void TerminateThread(); |
| + bool AppendEventToString(rtclog::Event* event); |
| + void AppendEventToHistory(const rtclog::Event& event); |
| + bool ProcessInOrder(bool memory, int64_t current_time); |
| + void LogToMemory(); |
| + void StartLogFile(); |
| + void LogToFile(); |
| + void StopLogFile(); |
| + void WriteLog(); |
| + |
| + // Message queues for passing events to the logging thread. |
| + SwapQueue<EventLogMessage>* message_queue_; |
| + SwapQueue<rtclog::Event>* config_queue_; |
| + SwapQueue<rtclog::Event>* rtp_queue_; |
| + SwapQueue<rtclog::Event>* rtcp_queue_; |
| + SwapQueue<rtclog::Event>* acm_playout_queue_; |
| + SwapQueue<rtclog::Event>* bwe_loss_queue_; |
| + |
| + // History containing the most recent events (~ 10 s). |
| + RingBuffer<rtclog::Event> history_; |
| + |
| + // History containing all past configuration events. |
| + std::vector<rtclog::Event> config_history_; |
| + |
| + bool log_to_memory_; |
| + rtc::scoped_ptr<FileWrapper> file_; |
| + rtc::PlatformThread thread_; |
| + |
| + int64_t max_size_bytes_; |
| + int64_t written_bytes_; |
| + int64_t start_time_; |
| + int64_t stop_time_; |
| + |
| + // We want to extract the elements from the buffers in timestamp order |
| + // and, because we can't peek into the SwapQueue, we need to keep the first |
| + // elements outside. |
| + rtclog::Event config_event_; |
| + rtclog::Event rtp_event_; |
| + rtclog::Event rtcp_event_; |
| + rtclog::Event playout_event_; |
| + rtclog::Event loss_event_; |
| + bool valid_config_event_; |
| + bool valid_rtp_event_; |
| + bool valid_rtcp_event_; |
| + bool valid_playout_event_; |
| + bool valid_loss_event_; |
| + |
| + // Temporary space for serializing profobuf data. |
| + std::string output_string_; |
| + |
| + rtc::Event* wake_up_; |
| + rtc::Event* stopped_; |
| + |
| + const Clock* const clock_; |
| + |
| + RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcEventLogHelperThread); |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // ENABLE_RTC_EVENT_LOG |
| + |
| +#endif // WEBRTC_CALL_RTC_EVENT_LOG_HELPER_THREAD_H_ |