1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/Latency.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef MOZILLA_LATENCY_H 1.11 +#define MOZILLA_LATENCY_H 1.12 + 1.13 +#include "mozilla/TimeStamp.h" 1.14 +#include "prlog.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsIThread.h" 1.17 +#include "mozilla/Monitor.h" 1.18 +#include "nsISupportsImpl.h" 1.19 +#include "nsIObserver.h" 1.20 + 1.21 +class AsyncLatencyLogger; 1.22 +class LogEvent; 1.23 + 1.24 +PRLogModuleInfo* GetLatencyLog(); 1.25 + 1.26 +// This class is a singleton. It is refcounted. 1.27 +class AsyncLatencyLogger : public nsIObserver 1.28 +{ 1.29 + NS_DECL_THREADSAFE_ISUPPORTS 1.30 + NS_DECL_NSIOBSERVER 1.31 + 1.32 +public: 1.33 + 1.34 + enum LatencyLogIndex { 1.35 + AudioMediaStreamTrack = 0, 1.36 + VideoMediaStreamTrack, 1.37 + Cubeb, 1.38 + AudioStream, 1.39 + NetEQ, 1.40 + AudioCaptureBase, // base time for capturing an audio stream 1.41 + AudioCapture, // records number of samples captured and the time 1.42 + AudioTrackInsertion, // # of samples inserted into a mediastreamtrack and the time 1.43 + MediaPipelineAudioInsertion, // Timestamp and time of timestamp 1.44 + AudioTransmit, // Timestamp and socket send time 1.45 + AudioReceive, // Timestamp and receive time 1.46 + MediaPipelineAudioPlayout, // Timestamp and playout into MST time 1.47 + MediaStreamCreate, // Source and TrackUnion streams 1.48 + AudioStreamCreate, // TrackUnion stream and AudioStream 1.49 + AudioSendRTP, 1.50 + AudioRecvRTP, 1.51 + _MAX_INDEX 1.52 + }; 1.53 + // Log with a null timestamp 1.54 + void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue); 1.55 + // Log with a timestamp 1.56 + void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue, 1.57 + mozilla::TimeStamp &aTime); 1.58 + // Write a log message to NSPR 1.59 + void WriteLog(LatencyLogIndex index, uint64_t aID, int64_t aValue, 1.60 + mozilla::TimeStamp timestamp); 1.61 + // Get the base time used by the logger for delta calculations 1.62 + void GetStartTime(mozilla::TimeStamp &aStart); 1.63 + 1.64 + static AsyncLatencyLogger* Get(bool aStartTimer = false); 1.65 + static void InitializeStatics(); 1.66 + // After this is called, the global log object may go away 1.67 + static void ShutdownLogger(); 1.68 +private: 1.69 + AsyncLatencyLogger(); 1.70 + virtual ~AsyncLatencyLogger(); 1.71 + int64_t GetTimeStamp(); 1.72 + void Init(); 1.73 + // Shut down the thread associated with this, and make sure it doesn't 1.74 + // start up again. 1.75 + void Shutdown(); 1.76 + // The thread on which the IO happens 1.77 + nsCOMPtr<nsIThread> mThread; 1.78 + // This can be initialized on multiple threads, but is protected by a 1.79 + // monitor. After the initialization phase, it is accessed on the log 1.80 + // thread only. 1.81 + mozilla::TimeStamp mStart; 1.82 + // This monitor protects mStart and mMediaLatencyLog for the 1.83 + // initialization sequence. It is initialized at layout startup, and 1.84 + // destroyed at layout shutdown. 1.85 + mozilla::Mutex mMutex; 1.86 +}; 1.87 + 1.88 +// need uint32_t versions for access from webrtc/trunk code 1.89 +// Log without a time delta 1.90 +void LogLatency(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue); 1.91 +void LogLatency(uint32_t index, uint64_t aID, int64_t aValue); 1.92 +// Log TimeStamp::Now() (as delta) 1.93 +void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue); 1.94 +void LogTime(uint32_t index, uint64_t aID, int64_t aValue); 1.95 +// Log the specified time (as delta) 1.96 +void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue, 1.97 + mozilla::TimeStamp &aTime); 1.98 + 1.99 +// For generating unique-ish ids for logged sources 1.100 +#define LATENCY_STREAM_ID(source, trackID) \ 1.101 + ((((uint64_t) (source)) & ~0x0F) | (trackID)) 1.102 + 1.103 +#endif