Index: webrtc/modules/include/module_common_types.h |
diff --git a/webrtc/modules/include/module_common_types.h b/webrtc/modules/include/module_common_types.h |
index a3ac2bbc56adb2cd13960d71431eb06fd82b4c96..b4305b79ef470702f35fc8909acc4a154d903309 100644 |
--- a/webrtc/modules/include/module_common_types.h |
+++ b/webrtc/modules/include/module_common_types.h |
@@ -26,6 +26,7 @@ |
#include "webrtc/rtc_base/constructormagic.h" |
#include "webrtc/rtc_base/deprecation.h" |
#include "webrtc/rtc_base/safe_conversions.h" |
+#include "webrtc/rtc_base/timeutils.h" |
#include "webrtc/typedefs.h" |
namespace webrtc { |
@@ -336,6 +337,16 @@ class AudioFrame { |
void CopyFrom(const AudioFrame& src); |
+ // Sets a wall-time clock timestamp in milliseconds to be used for profiling |
+ // of time between two points in the audio chain. |
+ // Example: |
+ // t0: UpdateProfileTime() |
+ // t1: TimeSinceLastProfile() => t1 - t0 [msec] |
+ void UpdateProfileTime(); |
hlundin-webrtc
2017/09/14 13:34:33
Suggest UpdateProfileTimestamp to match variable n
henrika_webrtc
2017/09/15 13:33:57
Done.
|
+ // Returns the time difference between now and when UpdateProfileTime() was |
+ // last called. Returns -1 if UpdateProfileTime() has not yet been called. |
+ int64_t TimeSinceLastProfile() const; |
hlundin-webrtc
2017/09/14 13:34:34
Suggest ElapsedProfileTimeMs().
henrika_webrtc
2017/09/15 13:33:57
Done.
|
+ |
// data() returns a zeroed static buffer if the frame is muted. |
// mutable_frame() always returns a non-static buffer; the first call to |
// mutable_frame() zeros the non-static buffer and marks the frame unmuted. |
@@ -368,6 +379,12 @@ class AudioFrame { |
size_t num_channels_ = 0; |
SpeechType speech_type_ = kUndefined; |
VADActivity vad_activity_ = kVadUnknown; |
+ // Monotonically increasing timestamp intended for profiling of audio frames. |
+ // Typically used for measuring elapsed time between two different points in |
+ // the audio path. No lock is used to save resources and we are thread safe |
+ // by design. Also, rtc::Optional is not used since it will cause a "complex |
hlundin-webrtc
2017/09/14 13:45:39
+kwiberg@, would you consider this reason enough t
henrika_webrtc
2017/09/15 13:33:57
IMHO, adding a cc-file for this functionality only
kwiberg-webrtc
2017/09/15 17:52:29
If build targets are set up properly (as they shou
|
+ // class/struct needs an explicit out-of-line destructor" build error. |
+ int64_t profile_time_stamp_ms_ = 0; |
hlundin-webrtc
2017/09/14 13:34:33
The convention in this file is to write timestamp
henrika_webrtc
2017/09/15 13:33:57
Done.
|
private: |
// A permamently zeroed out buffer to represent muted frames. This is a |
@@ -407,6 +424,7 @@ inline void AudioFrame::ResetWithoutMuting() { |
num_channels_ = 0; |
speech_type_ = kUndefined; |
vad_activity_ = kVadUnknown; |
+ profile_time_stamp_ms_ = 0; |
} |
inline void AudioFrame::UpdateFrame(int id, |
@@ -457,6 +475,20 @@ inline void AudioFrame::CopyFrom(const AudioFrame& src) { |
} |
} |
+inline void AudioFrame::UpdateProfileTime() { |
+ { |
hlundin-webrtc
2017/09/14 13:34:33
Why the extra braces?
henrika_webrtc
2017/09/15 13:33:57
My bad
|
+ profile_time_stamp_ms_ = rtc::TimeMillis() ; |
hlundin-webrtc
2017/09/14 13:34:33
Delete space before ;
henrika_webrtc
2017/09/15 13:33:57
Done.
|
+ } |
+} |
+ |
+inline int64_t AudioFrame::TimeSinceLastProfile() const { |
+ if (profile_time_stamp_ms_ == 0) { |
+ // Profiling has not been activated. |
+ return -1; |
+ } |
+ return rtc::TimeSince(profile_time_stamp_ms_); |
+} |
+ |
inline const int16_t* AudioFrame::data() const { |
return muted_ ? empty_data() : data_; |
} |