Bug 1415556 - P10. Make functions const where needed. r?padenot draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 10 Nov 2017 20:01:27 +0100
changeset 696818 66923405222aeb9befb7e6f1065705fd025bc74c
parent 696817 bc90a2065ed85faad79d802c0a10ad173c481820
child 696819 8eff9f177b86fabd1cada3d7c48f0f951285d541
push id88795
push userbmo:jyavenard@mozilla.com
push dateSat, 11 Nov 2017 15:24:04 +0000
reviewerspadenot
bugs1415556
milestone58.0a1
Bug 1415556 - P10. Make functions const where needed. r?padenot MozReview-Commit-ID: EBEgDVCTewa
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
dom/media/MediaStreamGraphImpl.h
dom/media/StreamTracks.cpp
dom/media/StreamTracks.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -318,18 +318,18 @@ MediaStreamGraphImpl::ExtractPendingInpu
     aStream->mHasCurrentData = true;
   }
   if (finished) {
     FinishStream(aStream);
   }
 }
 
 StreamTime
-MediaStreamGraphImpl::GraphTimeToStreamTimeWithBlocking(MediaStream* aStream,
-                                                        GraphTime aTime)
+MediaStreamGraphImpl::GraphTimeToStreamTimeWithBlocking(const MediaStream* aStream,
+                                                        GraphTime aTime) const
 {
   MOZ_ASSERT(aTime <= mStateComputedTime,
              "Don't ask about times where we haven't made blocking decisions yet");
   return std::max<StreamTime>(0,
       std::min(aTime, aStream->mStartBlocking) - aStream->mTracksStartTime);
 }
 
 GraphTime
@@ -2032,16 +2032,22 @@ MediaStream::DecrementSuspendCount()
 }
 
 MediaStreamGraphImpl*
 MediaStream::GraphImpl()
 {
   return mGraph;
 }
 
+const MediaStreamGraphImpl*
+MediaStream::GraphImpl() const
+{
+  return mGraph;
+}
+
 MediaStreamGraph*
 MediaStream::Graph()
 {
   return mGraph;
 }
 
 void
 MediaStream::SetGraphImpl(MediaStreamGraphImpl* aGraph)
@@ -2054,47 +2060,47 @@ MediaStream::SetGraphImpl(MediaStreamGra
 void
 MediaStream::SetGraphImpl(MediaStreamGraph* aGraph)
 {
   MediaStreamGraphImpl* graph = static_cast<MediaStreamGraphImpl*>(aGraph);
   SetGraphImpl(graph);
 }
 
 StreamTime
-MediaStream::GraphTimeToStreamTime(GraphTime aTime)
+MediaStream::GraphTimeToStreamTime(GraphTime aTime) const
 {
   NS_ASSERTION(mStartBlocking == GraphImpl()->mStateComputedTime ||
                aTime <= mStartBlocking,
                "Incorrectly ignoring blocking!");
   return aTime - mTracksStartTime;
 }
 
 GraphTime
-MediaStream::StreamTimeToGraphTime(StreamTime aTime)
+MediaStream::StreamTimeToGraphTime(StreamTime aTime) const
 {
   NS_ASSERTION(mStartBlocking == GraphImpl()->mStateComputedTime ||
                aTime + mTracksStartTime <= mStartBlocking,
                "Incorrectly ignoring blocking!");
   return aTime + mTracksStartTime;
 }
 
 StreamTime
-MediaStream::GraphTimeToStreamTimeWithBlocking(GraphTime aTime)
+MediaStream::GraphTimeToStreamTimeWithBlocking(GraphTime aTime) const
 {
   return GraphImpl()->GraphTimeToStreamTimeWithBlocking(this, aTime);
 }
 
 void
 MediaStream::FinishOnGraphThread()
 {
   GraphImpl()->FinishStream(this);
 }
 
 StreamTracks::Track*
-MediaStream::FindTrack(TrackID aID)
+MediaStream::FindTrack(TrackID aID) const
 {
   return mTracks.FindTrack(aID);
 }
 
 StreamTracks::Track*
 MediaStream::EnsureTrack(TrackID aTrackId)
 {
   StreamTracks::Track* track = mTracks.FindTrack(aTrackId);
@@ -3263,17 +3269,17 @@ MediaInputPort::Disconnect()
   mDest->RemoveInput(this);
   mSource = nullptr;
   mDest = nullptr;
 
   GraphImpl()->SetStreamOrderDirty();
 }
 
 MediaInputPort::InputInterval
-MediaInputPort::GetNextInputInterval(GraphTime aTime)
+MediaInputPort::GetNextInputInterval(GraphTime aTime) const
 {
   InputInterval result = { GRAPH_TIME_MAX, GRAPH_TIME_MAX, false };
   if (aTime >= mDest->mStartBlocking) {
     return result;
   }
   result.mStart = aTime;
   result.mEnd = mDest->mStartBlocking;
   result.mInputIsBlocked = aTime >= mSource->mStartBlocking;
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -258,27 +258,28 @@ protected:
   // Protected destructor, to discourage deletion outside of Release():
   virtual ~MediaStream();
 
 public:
   /**
    * Returns the graph that owns this stream.
    */
   MediaStreamGraphImpl* GraphImpl();
+  const MediaStreamGraphImpl* GraphImpl() const;
   MediaStreamGraph* Graph();
   /**
    * Sets the graph that owns this stream.  Should only be called once.
    */
   void SetGraphImpl(MediaStreamGraphImpl* aGraph);
   void SetGraphImpl(MediaStreamGraph* aGraph);
 
   /**
    * Returns sample rate of the graph.
    */
-  TrackRate GraphRate() { return mTracks.GraphRate(); }
+  TrackRate GraphRate() const { return mTracks.GraphRate(); }
 
   // Control API.
   // Since a stream can be played multiple ways, we need to combine independent
   // volume settings. The aKey parameter is used to keep volume settings
   // separate. Since the stream is always playing the same contents, only
   // a single audio output stream is used; the volumes are combined.
   // Currently only the first enabled audio track is played.
   // XXX change this so all enabled audio tracks are mixed and played.
@@ -370,29 +371,29 @@ public:
   // multiple clients using a MediaStream.
   void RegisterUser();
   // Signal that a client no longer needs this MediaStream. When the number of
   // clients using this MediaStream reaches 0, it will be destroyed.
   void UnregisterUser();
 
   // Returns the main-thread's view of how much data has been processed by
   // this stream.
-  StreamTime GetCurrentTime()
+  StreamTime GetCurrentTime() const
   {
     NS_ASSERTION(NS_IsMainThread(), "Call only on main thread");
     return mMainThreadCurrentTime;
   }
   // Return the main thread's view of whether this stream has finished.
-  bool IsFinished()
+  bool IsFinished() const
   {
     NS_ASSERTION(NS_IsMainThread(), "Call only on main thread");
     return mMainThreadFinished;
   }
 
-  bool IsDestroyed()
+  bool IsDestroyed() const
   {
     NS_ASSERTION(NS_IsMainThread(), "Call only on main thread");
     return mMainThreadDestroyed;
   }
 
   friend class MediaStreamGraphImpl;
   friend class MediaInputPort;
   friend class AudioNodeExternalInputStream;
@@ -404,24 +405,24 @@ public:
 
   // These Impl methods perform the core functionality of the control methods
   // above, on the media graph thread.
   /**
    * Stop all stream activity and disconnect it from all inputs and outputs.
    * This must be idempotent.
    */
   virtual void DestroyImpl();
-  StreamTime GetTracksEnd() { return mTracks.GetEnd(); }
+  StreamTime GetTracksEnd() const { return mTracks.GetEnd(); }
 #ifdef DEBUG
-  void DumpTrackInfo() { return mTracks.DumpTrackInfo(); }
+  void DumpTrackInfo() const { return mTracks.DumpTrackInfo(); }
 #endif
   void SetAudioOutputVolumeImpl(void* aKey, float aVolume);
   void AddAudioOutputImpl(void* aKey);
   // Returns true if this stream has an audio output.
-  bool HasAudioOutput()
+  bool HasAudioOutput() const
   {
     return !mAudioOutputs.IsEmpty();
   }
   void RemoveAudioOutputImpl(void* aKey);
   void AddVideoOutputImpl(already_AddRefed<MediaStreamVideoSink> aSink,
                           TrackID aID);
   void RemoveVideoOutputImpl(MediaStreamVideoSink* aSink, TrackID aID);
   void AddListenerImpl(already_AddRefed<MediaStreamListener> aListener);
@@ -441,96 +442,97 @@ public:
   void AddConsumer(MediaInputPort* aPort)
   {
     mConsumers.AppendElement(aPort);
   }
   void RemoveConsumer(MediaInputPort* aPort)
   {
     mConsumers.RemoveElement(aPort);
   }
-  uint32_t ConsumerCount()
+  uint32_t ConsumerCount() const
   {
     return mConsumers.Length();
   }
   StreamTracks& GetStreamTracks() { return mTracks; }
-  GraphTime GetStreamTracksStartTime() { return mTracksStartTime; }
+  GraphTime GetStreamTracksStartTime() const { return mTracksStartTime; }
 
-  double StreamTimeToSeconds(StreamTime aTime)
+  double StreamTimeToSeconds(StreamTime aTime) const
   {
     NS_ASSERTION(0 <= aTime && aTime <= STREAM_TIME_MAX, "Bad time");
     return static_cast<double>(aTime)/mTracks.GraphRate();
   }
-  int64_t StreamTimeToMicroseconds(StreamTime aTime)
+  int64_t StreamTimeToMicroseconds(StreamTime aTime) const
   {
     NS_ASSERTION(0 <= aTime && aTime <= STREAM_TIME_MAX, "Bad time");
-    return (aTime*1000000)/mTracks.GraphRate();
+    return (aTime*1000000) / mTracks.GraphRate();
   }
-  StreamTime SecondsToNearestStreamTime(double aSeconds)
+  StreamTime SecondsToNearestStreamTime(double aSeconds) const
   {
     NS_ASSERTION(0 <= aSeconds && aSeconds <= TRACK_TICKS_MAX/TRACK_RATE_MAX,
                  "Bad seconds");
     return mTracks.GraphRate() * aSeconds + 0.5;
   }
-  StreamTime MicrosecondsToStreamTimeRoundDown(int64_t aMicroseconds) {
+  StreamTime MicrosecondsToStreamTimeRoundDown(int64_t aMicroseconds) const
+  {
     return (aMicroseconds*mTracks.GraphRate())/1000000;
   }
 
-  TrackTicks TimeToTicksRoundUp(TrackRate aRate, StreamTime aTime)
+  TrackTicks TimeToTicksRoundUp(TrackRate aRate, StreamTime aTime) const
   {
     return RateConvertTicksRoundUp(aRate, mTracks.GraphRate(), aTime);
   }
-  StreamTime TicksToTimeRoundDown(TrackRate aRate, TrackTicks aTicks)
+  StreamTime TicksToTimeRoundDown(TrackRate aRate, TrackTicks aTicks) const
   {
     return RateConvertTicksRoundDown(mTracks.GraphRate(), aRate, aTicks);
   }
   /**
    * Convert graph time to stream time. aTime must be <= mStateComputedTime
    * to ensure we know exactly how much time this stream will be blocked during
    * the interval.
    */
-  StreamTime GraphTimeToStreamTimeWithBlocking(GraphTime aTime);
+  StreamTime GraphTimeToStreamTimeWithBlocking(GraphTime aTime) const;
   /**
    * Convert graph time to stream time. This assumes there is no blocking time
    * to take account of, which is always true except between a stream
    * having its blocking time calculated in UpdateGraph and its blocking time
    * taken account of in UpdateCurrentTimeForStreams.
    */
-  StreamTime GraphTimeToStreamTime(GraphTime aTime);
+  StreamTime GraphTimeToStreamTime(GraphTime aTime) const;
   /**
    * Convert stream time to graph time. This assumes there is no blocking time
    * to take account of, which is always true except between a stream
    * having its blocking time calculated in UpdateGraph and its blocking time
    * taken account of in UpdateCurrentTimeForStreams.
    */
-  GraphTime StreamTimeToGraphTime(StreamTime aTime);
+  GraphTime StreamTimeToGraphTime(StreamTime aTime) const;
 
-  bool IsFinishedOnGraphThread() { return mFinished; }
+  bool IsFinishedOnGraphThread() const { return mFinished; }
   void FinishOnGraphThread();
 
-  bool HasCurrentData() { return mHasCurrentData; }
+  bool HasCurrentData() const { return mHasCurrentData; }
 
   /**
    * Find track by track id.
    */
-  StreamTracks::Track* FindTrack(TrackID aID);
+  StreamTracks::Track* FindTrack(TrackID aID) const;
 
   StreamTracks::Track* EnsureTrack(TrackID aTrack);
 
   virtual void ApplyTrackDisabling(TrackID aTrackID, MediaSegment* aSegment, MediaSegment* aRawSegment = nullptr);
 
   // Return true if the main thread needs to observe updates from this stream.
   virtual bool MainThreadNeedsUpdates() const
   {
     return true;
   }
 
   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 
-  bool IsSuspended() { return mSuspendedCount > 0; }
+  bool IsSuspended() const { return mSuspendedCount > 0; }
   void IncrementSuspendCount();
   void DecrementSuspendCount();
 
 protected:
   // |AdvanceTimeVaryingValuesToCurrentTime| will be override in SourceMediaStream.
   virtual void AdvanceTimeVaryingValuesToCurrentTime(GraphTime aCurrentTime,
                                                      GraphTime aBlockedTime)
   {
@@ -794,17 +796,18 @@ public:
 
   /**
    * Returns true if this SourceMediaStream contains at least one audio track
    * that is in pending state.
    * This is thread safe, and takes the SourceMediaStream mutex.
    */
   bool HasPendingAudioTrack();
 
-  TimeStamp GetStreamTracksStrartTimeStamp() {
+  TimeStamp GetStreamTracksStrartTimeStamp()
+  {
     MutexAutoLock lock(mMutex);
     return mStreamTracksStartTimeStamp;
   }
 
   bool OpenNewAudioCallbackDriver(AudioDataListener *aListener);
 
   // XXX need a Reset API
 
@@ -987,51 +990,53 @@ public:
   // Control API
   /**
    * Disconnects and destroys the port. The caller must not reference this
    * object again.
    */
   void Destroy();
 
   // Any thread
-  MediaStream* GetSource() { return mSource; }
-  TrackID GetSourceTrackId() { return mSourceTrack; }
-  ProcessedMediaStream* GetDestination() { return mDest; }
-  TrackID GetDestinationTrackId() { return mDestTrack; }
+  MediaStream* GetSource() const { return mSource; }
+  TrackID GetSourceTrackId() const { return mSourceTrack; }
+  ProcessedMediaStream* GetDestination() const { return mDest; }
+  TrackID GetDestinationTrackId() const { return mDestTrack; }
 
   /**
    * Block aTrackId in the source stream from being passed through the port.
    * Consumers will interpret this track as ended.
    * Returns a pledge that resolves on the main thread after the track block has
    * been applied by the MSG.
    */
   already_AddRefed<media::Pledge<bool, nsresult>> BlockSourceTrackId(TrackID aTrackId,
                                                                      BlockingMode aBlockingMode);
 private:
   void BlockSourceTrackIdImpl(TrackID aTrackId, BlockingMode aBlockingMode);
 
 public:
   // Returns true if aTrackId has not been blocked for any reason and this port
   // has not been locked to another track.
-  bool PassTrackThrough(TrackID aTrackId) {
+  bool PassTrackThrough(TrackID aTrackId) const
+  {
     bool blocked = false;
     for (auto pair : mBlockedTracks) {
       if (pair.first() == aTrackId &&
           (pair.second() == BlockingMode::CREATION ||
            pair.second() == BlockingMode::END_EXISTING)) {
         blocked = true;
         break;
       }
     }
     return !blocked && (mSourceTrack == TRACK_ANY || mSourceTrack == aTrackId);
   }
 
   // Returns true if aTrackId has not been blocked for track creation and this
   // port has not been locked to another track.
-  bool AllowCreationOf(TrackID aTrackId) {
+  bool AllowCreationOf(TrackID aTrackId) const
+  {
     bool blocked = false;
     for (auto pair : mBlockedTracks) {
       if (pair.first() == aTrackId &&
           pair.second() == BlockingMode::CREATION) {
         blocked = true;
         break;
       }
     }
@@ -1044,17 +1049,17 @@ public:
   // Call on graph manager thread
   struct InputInterval {
     GraphTime mStart;
     GraphTime mEnd;
     bool mInputIsBlocked;
   };
   // Find the next time interval starting at or after aTime during which
   // mDest is not blocked and mSource's blocking status does not change.
-  InputInterval GetNextInputInterval(GraphTime aTime);
+  InputInterval GetNextInputInterval(GraphTime aTime) const;
 
   /**
    * Returns the graph that owns this port.
    */
   MediaStreamGraphImpl* GraphImpl();
   MediaStreamGraph* Graph();
 
   /**
@@ -1168,21 +1173,21 @@ public:
   friend class MediaStreamGraphImpl;
 
   // Do not call these from outside MediaStreamGraph.cpp!
   virtual void AddInput(MediaInputPort* aPort);
   virtual void RemoveInput(MediaInputPort* aPort)
   {
     mInputs.RemoveElement(aPort) || mSuspendedInputs.RemoveElement(aPort);
   }
-  bool HasInputPort(MediaInputPort* aPort)
+  bool HasInputPort(MediaInputPort* aPort) const
   {
     return mInputs.Contains(aPort) || mSuspendedInputs.Contains(aPort);
   }
-  uint32_t InputPortCount()
+  uint32_t InputPortCount() const
   {
     return mInputs.Length() + mSuspendedInputs.Length();
   }
   void InputSuspended(MediaInputPort* aPort);
   void InputResumed(MediaInputPort* aPort);
   virtual MediaStream* GetInputStreamFor(TrackID aTrackID) { return nullptr; }
   virtual TrackID GetInputTrackIDFor(TrackID aTrackID) { return TRACK_NONE; }
   void DestroyImpl() override;
@@ -1280,17 +1285,18 @@ public:
   // Return the correct main thread for this graph. This always returns
   // something that is valid. Thread safe.
   AbstractThread* AbstractMainThread();
 
   // Idempotent
   static void DestroyNonRealtimeInstance(MediaStreamGraph* aGraph);
 
   virtual nsresult OpenAudioInput(int aID,
-                                  AudioDataListener *aListener) {
+                                  AudioDataListener *aListener)
+  {
     return NS_ERROR_FAILURE;
   }
   virtual void CloseAudioInput(AudioDataListener *aListener) {}
 
   // Control API.
   /**
    * Create a stream that a media decoder (or some other source of
    * media data, such as a camera) can write to.
--- a/dom/media/MediaStreamGraphImpl.h
+++ b/dom/media/MediaStreamGraphImpl.h
@@ -353,17 +353,17 @@ public:
    * aEndBlockingDecisions.
    */
   GraphTime WillUnderrun(MediaStream* aStream, GraphTime aEndBlockingDecisions);
 
   /**
    * Given a graph time aTime, convert it to a stream time taking into
    * account the time during which aStream is scheduled to be blocked.
    */
-  StreamTime GraphTimeToStreamTimeWithBlocking(MediaStream* aStream, GraphTime aTime);
+  StreamTime GraphTimeToStreamTimeWithBlocking(const MediaStream* aStream, GraphTime aTime) const;
 
   /**
    * Call NotifyHaveCurrentData on aStream's listeners.
    */
   void NotifyHasCurrentData(MediaStream* aStream);
   /**
    * If aStream needs an audio stream but doesn't have one, create it.
    * If aStream doesn't need an audio stream but has one, destroy it.
--- a/dom/media/StreamTracks.cpp
+++ b/dom/media/StreamTracks.cpp
@@ -57,17 +57,17 @@ StreamTracks::GetAllTracksEnd() const
       return STREAM_TIME_MAX;
     }
     t = std::max(t, track->GetEnd());
   }
   return t;
 }
 
 StreamTracks::Track*
-StreamTracks::FindTrack(TrackID aID)
+StreamTracks::FindTrack(TrackID aID) const
 {
   if (aID == TRACK_NONE || mTracks.IsEmpty()) {
     return nullptr;
   }
 
   // The tracks are sorted by ID. We can use a binary search.
 
   uint32_t left = 0, right = mTracks.Length() - 1;
--- a/dom/media/StreamTracks.h
+++ b/dom/media/StreamTracks.h
@@ -236,38 +236,38 @@ public:
    * or STREAM_TIME_MAX if there is no such time.
    */
   StreamTime GetAllTracksEnd() const;
 
 #ifdef DEBUG
   void DumpTrackInfo() const;
 #endif
 
-  Track* FindTrack(TrackID aID);
+  Track* FindTrack(TrackID aID) const;
 
   class MOZ_STACK_CLASS TrackIter final
   {
   public:
     /**
      * Iterate through the tracks of aBuffer in order of ID.
      */
     explicit TrackIter(const StreamTracks& aBuffer) :
       mBuffer(&aBuffer.mTracks), mIndex(0), mMatchType(false) {}
     /**
      * Iterate through the tracks of aBuffer with type aType, in order of ID.
      */
     TrackIter(const StreamTracks& aBuffer, MediaSegment::Type aType) :
       mBuffer(&aBuffer.mTracks), mIndex(0), mType(aType), mMatchType(true) { FindMatch(); }
-    bool IsEnded() { return mIndex >= mBuffer->Length(); }
+    bool IsEnded() const { return mIndex >= mBuffer->Length(); }
     void Next()
     {
       ++mIndex;
       FindMatch();
     }
-    Track* get() { return mBuffer->ElementAt(mIndex); }
+    Track* get() const { return mBuffer->ElementAt(mIndex); }
     Track& operator*() { return *mBuffer->ElementAt(mIndex); }
     Track* operator->() { return mBuffer->ElementAt(mIndex); }
   private:
     void FindMatch()
     {
       if (!mMatchType)
         return;
       while (mIndex < mBuffer->Length() &&
@@ -292,17 +292,17 @@ public:
   /**
    * Clears out all Tracks and the data they are holding.
    * MediaStreamGraph calls this during forced shutdown.
    */
   void Clear();
   /**
    * Returns the latest time passed to ForgetUpTo.
    */
-  StreamTime GetForgottenDuration()
+  StreamTime GetForgottenDuration() const
   {
     return mForgottenTime;
   }
 
   bool GetAndResetTracksDirty()
   {
     if (!mTracksDirty) {
       return false;