content/media/Latency.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef MOZILLA_LATENCY_H
michael@0 8 #define MOZILLA_LATENCY_H
michael@0 9
michael@0 10 #include "mozilla/TimeStamp.h"
michael@0 11 #include "prlog.h"
michael@0 12 #include "nsCOMPtr.h"
michael@0 13 #include "nsIThread.h"
michael@0 14 #include "mozilla/Monitor.h"
michael@0 15 #include "nsISupportsImpl.h"
michael@0 16 #include "nsIObserver.h"
michael@0 17
michael@0 18 class AsyncLatencyLogger;
michael@0 19 class LogEvent;
michael@0 20
michael@0 21 PRLogModuleInfo* GetLatencyLog();
michael@0 22
michael@0 23 // This class is a singleton. It is refcounted.
michael@0 24 class AsyncLatencyLogger : public nsIObserver
michael@0 25 {
michael@0 26 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 27 NS_DECL_NSIOBSERVER
michael@0 28
michael@0 29 public:
michael@0 30
michael@0 31 enum LatencyLogIndex {
michael@0 32 AudioMediaStreamTrack = 0,
michael@0 33 VideoMediaStreamTrack,
michael@0 34 Cubeb,
michael@0 35 AudioStream,
michael@0 36 NetEQ,
michael@0 37 AudioCaptureBase, // base time for capturing an audio stream
michael@0 38 AudioCapture, // records number of samples captured and the time
michael@0 39 AudioTrackInsertion, // # of samples inserted into a mediastreamtrack and the time
michael@0 40 MediaPipelineAudioInsertion, // Timestamp and time of timestamp
michael@0 41 AudioTransmit, // Timestamp and socket send time
michael@0 42 AudioReceive, // Timestamp and receive time
michael@0 43 MediaPipelineAudioPlayout, // Timestamp and playout into MST time
michael@0 44 MediaStreamCreate, // Source and TrackUnion streams
michael@0 45 AudioStreamCreate, // TrackUnion stream and AudioStream
michael@0 46 AudioSendRTP,
michael@0 47 AudioRecvRTP,
michael@0 48 _MAX_INDEX
michael@0 49 };
michael@0 50 // Log with a null timestamp
michael@0 51 void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue);
michael@0 52 // Log with a timestamp
michael@0 53 void Log(LatencyLogIndex index, uint64_t aID, int64_t aValue,
michael@0 54 mozilla::TimeStamp &aTime);
michael@0 55 // Write a log message to NSPR
michael@0 56 void WriteLog(LatencyLogIndex index, uint64_t aID, int64_t aValue,
michael@0 57 mozilla::TimeStamp timestamp);
michael@0 58 // Get the base time used by the logger for delta calculations
michael@0 59 void GetStartTime(mozilla::TimeStamp &aStart);
michael@0 60
michael@0 61 static AsyncLatencyLogger* Get(bool aStartTimer = false);
michael@0 62 static void InitializeStatics();
michael@0 63 // After this is called, the global log object may go away
michael@0 64 static void ShutdownLogger();
michael@0 65 private:
michael@0 66 AsyncLatencyLogger();
michael@0 67 virtual ~AsyncLatencyLogger();
michael@0 68 int64_t GetTimeStamp();
michael@0 69 void Init();
michael@0 70 // Shut down the thread associated with this, and make sure it doesn't
michael@0 71 // start up again.
michael@0 72 void Shutdown();
michael@0 73 // The thread on which the IO happens
michael@0 74 nsCOMPtr<nsIThread> mThread;
michael@0 75 // This can be initialized on multiple threads, but is protected by a
michael@0 76 // monitor. After the initialization phase, it is accessed on the log
michael@0 77 // thread only.
michael@0 78 mozilla::TimeStamp mStart;
michael@0 79 // This monitor protects mStart and mMediaLatencyLog for the
michael@0 80 // initialization sequence. It is initialized at layout startup, and
michael@0 81 // destroyed at layout shutdown.
michael@0 82 mozilla::Mutex mMutex;
michael@0 83 };
michael@0 84
michael@0 85 // need uint32_t versions for access from webrtc/trunk code
michael@0 86 // Log without a time delta
michael@0 87 void LogLatency(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
michael@0 88 void LogLatency(uint32_t index, uint64_t aID, int64_t aValue);
michael@0 89 // Log TimeStamp::Now() (as delta)
michael@0 90 void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue);
michael@0 91 void LogTime(uint32_t index, uint64_t aID, int64_t aValue);
michael@0 92 // Log the specified time (as delta)
michael@0 93 void LogTime(AsyncLatencyLogger::LatencyLogIndex index, uint64_t aID, int64_t aValue,
michael@0 94 mozilla::TimeStamp &aTime);
michael@0 95
michael@0 96 // For generating unique-ish ids for logged sources
michael@0 97 #define LATENCY_STREAM_ID(source, trackID) \
michael@0 98 ((((uint64_t) (source)) & ~0x0F) | (trackID))
michael@0 99
michael@0 100 #endif

mercurial