2013-01-28 10:22:37 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_LATENCY_H
|
|
|
|
#define MOZILLA_LATENCY_H
|
|
|
|
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-01-02 00:14:52 -08:00
|
|
|
#include "prlog.h"
|
2013-01-28 10:22:37 -08:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIThread.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2014-04-14 12:04:27 -07:00
|
|
|
#include "nsIObserver.h"
|
2013-01-28 10:22:37 -08:00
|
|
|
|
|
|
|
class AsyncLatencyLogger;
|
|
|
|
class LogEvent;
|
|
|
|
|
|
|
|
PRLogModuleInfo* GetLatencyLog();
|
|
|
|
|
|
|
|
// This class is a singleton. It is refcounted.
|
2013-09-24 19:10:24 -07:00
|
|
|
class AsyncLatencyLogger : public nsIObserver
|
2013-01-28 10:22:37 -08:00
|
|
|
{
|
2013-09-24 19:10:24 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2013-01-28 10:22:37 -08:00
|
|
|
public:
|
2013-09-24 19:10:24 -07:00
|
|
|
|
2013-01-28 10:22:37 -08:00
|
|
|
enum LatencyLogIndex {
|
2013-10-25 15:13:42 -07:00
|
|
|
AudioMediaStreamTrack = 0,
|
2013-01-28 10:22:37 -08:00
|
|
|
VideoMediaStreamTrack,
|
|
|
|
Cubeb,
|
|
|
|
AudioStream,
|
|
|
|
NetEQ,
|
2013-10-25 15:13:42 -07:00
|
|
|
AudioCaptureBase, // base time for capturing an audio stream
|
|
|
|
AudioCapture, // records number of samples captured and the time
|
|
|
|
AudioTrackInsertion, // # of samples inserted into a mediastreamtrack and the time
|
|
|
|
MediaPipelineAudioInsertion, // Timestamp and time of timestamp
|
|
|
|
AudioTransmit, // Timestamp and socket send time
|
|
|
|
AudioReceive, // Timestamp and receive time
|
|
|
|
MediaPipelineAudioPlayout, // Timestamp and playout into MST time
|
|
|
|
MediaStreamCreate, // Source and TrackUnion streams
|
|
|
|
AudioStreamCreate, // TrackUnion stream and AudioStream
|
|
|
|
AudioSendRTP,
|
|
|
|
AudioRecvRTP,
|
2013-01-28 10:22:37 -08:00
|
|
|
_MAX_INDEX
|
|
|
|
};
|
2013-10-25 15:13:42 -07:00
|
|
|
// Log with a null timestamp
|
|
|
|
void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue);
|
|
|
|
// Log with a timestamp
|
|
|
|
void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue,
|
|
|
|
mozilla::TimeStamp &aTime);
|
|
|
|
// Write a log message to NSPR
|
|
|
|
void WriteLog(LatencyLogIndex index, uint64_t aID, int64_t aValue,
|
|
|
|
mozilla::TimeStamp timestamp);
|
|
|
|
// Get the base time used by the logger for delta calculations
|
|
|
|
void GetStartTime(mozilla::TimeStamp &aStart);
|
2013-01-28 10:22:37 -08:00
|
|
|
|
|
|
|
static AsyncLatencyLogger* Get(bool aStartTimer = false);
|
|
|
|
static void InitializeStatics();
|
2013-09-24 19:10:24 -07:00
|
|
|
// After this is called, the global log object may go away
|
|
|
|
static void ShutdownLogger();
|
2013-01-28 10:22:37 -08:00
|
|
|
private:
|
|
|
|
AsyncLatencyLogger();
|
2013-09-24 19:10:24 -07:00
|
|
|
virtual ~AsyncLatencyLogger();
|
2013-01-28 10:22:37 -08:00
|
|
|
int64_t GetTimeStamp();
|
|
|
|
void Init();
|
2013-09-24 19:10:24 -07:00
|
|
|
// Shut down the thread associated with this, and make sure it doesn't
|
|
|
|
// start up again.
|
|
|
|
void Shutdown();
|
2013-01-28 10:22:37 -08:00
|
|
|
// The thread on which the IO happens
|
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
// This can be initialized on multiple threads, but is protected by a
|
|
|
|
// monitor. After the initialization phase, it is accessed on the log
|
|
|
|
// thread only.
|
|
|
|
mozilla::TimeStamp mStart;
|
|
|
|
// This monitor protects mStart and mMediaLatencyLog for the
|
|
|
|
// initialization sequence. It is initialized at layout startup, and
|
|
|
|
// destroyed at layout shutdown.
|
|
|
|
mozilla::Mutex mMutex;
|
|
|
|
};
|
|
|
|
|
2013-10-25 15:13:42 -07:00
|
|
|
// need uint32_t versions for access from webrtc/trunk code
|
|
|
|
// Log without a time delta
|
|
|
|
void LogLatency(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
|
|
|
|
void LogLatency(uint32_t index, uint64_t aID, int64_t aValue);
|
|
|
|
// Log TimeStamp::Now() (as delta)
|
|
|
|
void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
|
|
|
|
void LogTime(uint32_t index, uint64_t aID, int64_t aValue);
|
|
|
|
// Log the specified time (as delta)
|
|
|
|
void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue,
|
|
|
|
mozilla::TimeStamp &aTime);
|
|
|
|
|
|
|
|
// For generating unique-ish ids for logged sources
|
|
|
|
#define LATENCY_STREAM_ID(source, trackID) \
|
|
|
|
((((uint64_t) (source)) & ~0x0F) | (trackID))
|
2013-01-28 10:22:37 -08:00
|
|
|
|
|
|
|
#endif
|