Bug 1538113 - Fix dom/media/webrtc static-analysis warnings. r=jib
authorAndreas Pehrson <apehrson@mozilla.com>
Mon, 25 Mar 2019 18:52:57 +0000
changeset 465993 d56e561be43f7494a3f5362a427589947b4345f2
parent 465992 946a9c169fb4c366369e37dbd8a372868e6216f7
child 465994 ad6e8a453d67fb690c8ad9aa4737e9440f7c9302
push id112550
push userrgurzau@mozilla.com
push dateTue, 26 Mar 2019 09:57:15 +0000
treeherdermozilla-inbound@b8be99473610 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1538113, 142013
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1538113 - Fix dom/media/webrtc static-analysis warnings. r=jib Initially indicated by: https://phabricator.services.mozilla.com/D22910#inline-142013 Rest found by: ./mach static-analysis check dom/media/webrtc Differential Revision: https://phabricator.services.mozilla.com/D24511
dom/media/webrtc/MediaEngine.h
dom/media/webrtc/MediaEngineDefault.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
dom/media/webrtc/MediaEngineRemoteVideoSource.h
dom/media/webrtc/MediaEngineSource.h
dom/media/webrtc/MediaEngineTabVideoSource.cpp
dom/media/webrtc/MediaEngineTabVideoSource.h
dom/media/webrtc/MediaEngineWebRTCAudio.h
dom/media/webrtc/MediaTrackConstraints.cpp
dom/media/webrtc/MediaTrackConstraints.h
dom/media/webrtc/PeerIdentity.h
dom/media/webrtc/RTCIdentityProviderRegistrar.cpp
--- a/dom/media/webrtc/MediaEngine.h
+++ b/dom/media/webrtc/MediaEngine.h
@@ -46,14 +46,14 @@ class MediaEngine : public DeviceChangeC
                                 nsTArray<RefPtr<MediaDevice>>*) = 0;
 
   virtual void ReleaseResourcesForWindow(uint64_t aWindowId) = 0;
   virtual void Shutdown() = 0;
 
   virtual void SetFakeDeviceChangeEvents() {}
 
  protected:
-  virtual ~MediaEngine() {}
+  virtual ~MediaEngine() = default;
 };
 
 }  // namespace mozilla
 
 #endif /* MEDIAENGINE_H_ */
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -59,17 +59,17 @@ static nsString DefaultVideoName() {
 /**
  * Default video source.
  */
 
 MediaEngineDefaultVideoSource::MediaEngineDefaultVideoSource()
     : mTimer(nullptr),
       mName(DefaultVideoName()) {}
 
-MediaEngineDefaultVideoSource::~MediaEngineDefaultVideoSource() {}
+MediaEngineDefaultVideoSource::~MediaEngineDefaultVideoSource() = default;
 
 nsString MediaEngineDefaultVideoSource::GetName() const { return mName; }
 
 nsCString MediaEngineDefaultVideoSource::GetUUID() const {
   return NS_LITERAL_CSTRING("1041FCBD-3F12-4F7B-9E9B-1EC556DD5676");
 }
 
 nsString MediaEngineDefaultVideoSource::GetGroupId() const {
@@ -338,17 +338,17 @@ void MediaEngineDefaultVideoSource::Pull
 
 /**
  * Default audio source.
  */
 
 MediaEngineDefaultAudioSource::MediaEngineDefaultAudioSource()
     : mMutex("MediaEngineDefaultAudioSource::mMutex") {}
 
-MediaEngineDefaultAudioSource::~MediaEngineDefaultAudioSource() {}
+MediaEngineDefaultAudioSource::~MediaEngineDefaultAudioSource() = default;
 
 nsString MediaEngineDefaultAudioSource::GetName() const {
   return NS_LITERAL_STRING(u"Default Audio Device");
 }
 
 nsCString MediaEngineDefaultAudioSource::GetUUID() const {
   return NS_LITERAL_CSTRING("B7CBD7C1-53EF-42F9-8353-73F61C70C092");
 }
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp
@@ -867,17 +867,17 @@ bool MediaEngineRemoteVideoSource::Choos
         // We'll adjust the width too so the aspect ratio is retained.
         cap.width = cap.height * prefWidth / prefHeight;
       }
 
       if (candidateSet.Contains(cap, CapabilityComparator())) {
         continue;
       }
       LogCapability("Hardcoded capability", cap, 0);
-      candidateSet.AppendElement(CapabilityCandidate(std::move(cap)));
+      candidateSet.AppendElement(cap);
     }
   }
 
   // First, filter capabilities by required constraints (min, max, exact).
 
   for (size_t i = 0; i < candidateSet.Length();) {
     auto& candidate = candidateSet[i];
     candidate.mDistance =
--- a/dom/media/webrtc/MediaEngineRemoteVideoSource.h
+++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.h
@@ -61,20 +61,19 @@ enum DistanceCalculation { kFitness, kFe
 /**
  * The WebRTC implementation of the MediaEngine interface.
  */
 class MediaEngineRemoteVideoSource : public MediaEngineSource,
                                      public camera::FrameRelay {
   ~MediaEngineRemoteVideoSource();
 
   struct CapabilityCandidate {
-    explicit CapabilityCandidate(webrtc::CaptureCapability&& aCapability,
+    explicit CapabilityCandidate(webrtc::CaptureCapability aCapability,
                                  uint32_t aDistance = 0)
-        : mCapability(std::forward<webrtc::CaptureCapability>(aCapability)),
-          mDistance(aDistance) {}
+        : mCapability(aCapability), mDistance(aDistance) {}
 
     const webrtc::CaptureCapability mCapability;
     uint32_t mDistance;
   };
 
   class CapabilityComparator {
    public:
     bool Equals(const CapabilityCandidate& aCandidate,
@@ -108,18 +107,18 @@ class MediaEngineRemoteVideoSource : pub
       const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
       const nsString& aDeviceId) const override;
 
  public:
   MediaEngineRemoteVideoSource(int aIndex, camera::CaptureEngine aCapEngine,
                                bool aScary);
 
   // ExternalRenderer
-  int DeliverFrame(uint8_t* buffer,
-                   const camera::VideoFrameProperties& properties) override;
+  int DeliverFrame(uint8_t* aBuffer,
+                   const camera::VideoFrameProperties& aProps) override;
 
   // MediaEngineSource
   dom::MediaSourceEnum GetMediaSource() const override;
   nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
                     const MediaEnginePrefs& aPrefs, const nsString& aDeviceId,
                     const ipc::PrincipalInfo& aPrincipalInfo,
                     AllocationHandle** aOutHandle,
                     const char** aOutBadConstraint) override;
--- a/dom/media/webrtc/MediaEngineSource.h
+++ b/dom/media/webrtc/MediaEngineSource.h
@@ -43,17 +43,17 @@ class MediaEnginePhotoCallback {
   // aBlob is the image captured by MediaEngineSource. It is
   // called on main thread.
   virtual nsresult PhotoComplete(already_AddRefed<dom::Blob> aBlob) = 0;
 
   // It is called on main thread. aRv is the error code.
   virtual nsresult PhotoError(nsresult aRv) = 0;
 
  protected:
-  virtual ~MediaEnginePhotoCallback() {}
+  virtual ~MediaEnginePhotoCallback() = default;
 };
 
 /**
  * Lifecycle state of MediaEngineSource.
  */
 enum MediaEngineSourceState {
   kAllocated,  // Allocated, not yet started.
   kStarted,    // Previously allocated or stopped, then started.
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -28,17 +28,17 @@
 #include "nsIPrefService.h"
 #include "MediaTrackConstraints.h"
 #include "Tracing.h"
 
 namespace mozilla {
 
 using namespace mozilla::gfx;
 
-MediaEngineTabVideoSource::MediaEngineTabVideoSource() {}
+MediaEngineTabVideoSource::MediaEngineTabVideoSource() = default;
 
 nsresult MediaEngineTabVideoSource::StartRunnable::Run() {
   MOZ_ASSERT(NS_IsMainThread());
   mVideoSource->mStreamMain = mStream;
   mVideoSource->mTrackIDMain = mTrackID;
   mVideoSource->mPrincipalHandleMain = mPrincipal;
   mVideoSource->Draw();
   mVideoSource->mTimer->InitWithNamedFuncCallback(
@@ -90,17 +90,19 @@ nsresult MediaEngineTabVideoSource::Init
     nsresult rv;
     mVideoSource->mTabSource =
         do_GetService(NS_TABSOURCESERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<mozIDOMWindowProxy> win;
     rv = mVideoSource->mTabSource->GetTabToStream(getter_AddRefs(win));
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!win) return NS_OK;
+    if (!win) {
+      return NS_OK;
+    }
 
     mVideoSource->mWindow = nsPIDOMWindowOuter::From(win);
     MOZ_ASSERT(mVideoSource->mWindow);
   }
   mVideoSource->mTimer = NS_NewTimer();
   nsCOMPtr<nsIRunnable> start(
       new StartRunnable(mVideoSource, mStream, mTrackID, mPrincipal));
   start->Run();
--- a/dom/media/webrtc/MediaEngineTabVideoSource.h
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.h
@@ -109,24 +109,24 @@ class MediaEngineTabVideoSource : public
     explicit DestroyRunnable(MediaEngineTabVideoSource* videoSource)
         : Runnable("MediaEngineTabVideoSource::DestroyRunnable"),
           mVideoSource(videoSource) {}
     NS_IMETHOD Run() override;
     const RefPtr<MediaEngineTabVideoSource> mVideoSource;
   };
 
  protected:
-  ~MediaEngineTabVideoSource() {}
+  ~MediaEngineTabVideoSource() = default;
 
  private:
   // These are accessed only on main thread.
   int32_t mBufWidthMax = 0;
   int32_t mBufHeightMax = 0;
   int64_t mWindowId = 0;
-  bool mScrollWithPage = 0;
+  bool mScrollWithPage = false;
   int32_t mViewportOffsetX = 0;
   int32_t mViewportOffsetY = 0;
   int32_t mViewportWidth = 0;
   int32_t mViewportHeight = 0;
   int32_t mTimePerFrame = 0;
   RefPtr<layers::ImageContainer> mImageContainer;
 
   nsCOMPtr<nsPIDOMWindowOuter> mWindow;
--- a/dom/media/webrtc/MediaEngineWebRTCAudio.h
+++ b/dom/media/webrtc/MediaEngineWebRTCAudio.h
@@ -23,19 +23,19 @@ class AudioInputProcessing;
 //   the main thread and then the MSG thread so that it can be used as part of
 //   the graph processing. On destruction, similarly, a message is sent to the
 //   graph so that it stops using it, and then it is deleted.
 // - mSettings is created on the MediaManager thread is always ever accessed on
 //   the Main Thread. It is const.
 class MediaEngineWebRTCMicrophoneSource : public MediaEngineSource {
  public:
   MediaEngineWebRTCMicrophoneSource(RefPtr<AudioDeviceInfo> aInfo,
-                                    const nsString& aName,
-                                    const nsCString& aUuid,
-                                    const nsString& aGroupId,
+                                    const nsString& aDeviceName,
+                                    const nsCString& aDeviceUUID,
+                                    const nsString& aDeviceGroup,
                                     uint32_t aMaxChannelCount,
                                     bool aDelayAgnostic, bool aExtendedFilter);
 
   bool RequiresSharing() const override { return false; }
 
   nsString GetName() const override;
   nsCString GetUUID() const override;
   nsString GetGroupId() const override;
--- a/dom/media/webrtc/MediaTrackConstraints.cpp
+++ b/dom/media/webrtc/MediaTrackConstraints.cpp
@@ -383,17 +383,17 @@ uint32_t MediaConstraintsHelper::Feasibi
                      (std::abs(aN - aRange.mIdeal.value()) * 1000) /
                      std::max(std::abs(aN), std::abs(aRange.mIdeal.value()))));
 }
 
 // Fitness distance returned as integer math * 1000. Infinity = UINT32_MAX
 
 /* static */
 uint32_t MediaConstraintsHelper::FitnessDistance(
-    nsString aN, const NormalizedConstraintSet::StringRange& aParams) {
+    const nsString& aN, const NormalizedConstraintSet::StringRange& aParams) {
   if (!aParams.mExact.empty() &&
       aParams.mExact.find(aN) == aParams.mExact.end()) {
     return UINT32_MAX;
   }
   if (!aParams.mIdeal.empty() &&
       aParams.mIdeal.find(aN) == aParams.mIdeal.end()) {
     return 1000;
   }
@@ -435,18 +435,18 @@ uint32_t MediaConstraintsHelper::Fitness
   // Order devices by shortest distance
   for (auto& ordinal : ordered) {
     aDevices.RemoveElement(ordinal.second);
     aDevices.AppendElement(ordinal.second);
   }
 
   // Then apply advanced constraints.
 
-  for (int i = 0; i < int(c.mAdvanced.size()); i++) {
-    aggregateConstraints.AppendElement(&c.mAdvanced[i]);
+  for (const auto& advanced : c.mAdvanced) {
+    aggregateConstraints.AppendElement(&advanced);
     nsTArray<RefPtr<MediaDevice>> rejects;
     for (uint32_t j = 0; j < aDevices.Length();) {
       uint32_t distance =
           aDevices[j]->GetBestFitnessDistance(aggregateConstraints, aIsChrome);
       if (distance == UINT32_MAX) {
         rejects.AppendElement(std::move(aDevices[j]));
         aDevices.RemoveElementAt(j);
       } else {
@@ -522,22 +522,22 @@ uint32_t MediaConstraintsHelper::Fitness
       aMediaEngineSource->GetGroupId(), NS_LITERAL_STRING("")));
   return FindBadConstraint(aConstraints, devices);
 }
 
 static void LogConstraintStringRange(
     const NormalizedConstraintSet::StringRange& aRange) {
   if (aRange.mExact.size() <= 1 && aRange.mIdeal.size() <= 1) {
     LOG("  %s: { exact: [%s], ideal: [%s] }", aRange.mName,
-        (aRange.mExact.size()
-             ? NS_ConvertUTF16toUTF8(*aRange.mExact.begin()).get()
-             : ""),
-        (aRange.mIdeal.size()
-             ? NS_ConvertUTF16toUTF8(*aRange.mIdeal.begin()).get()
-             : ""));
+        (aRange.mExact.empty()
+             ? ""
+             : NS_ConvertUTF16toUTF8(*aRange.mExact.begin()).get()),
+        (aRange.mIdeal.empty()
+             ? ""
+             : NS_ConvertUTF16toUTF8(*aRange.mIdeal.begin()).get()));
   } else {
     LOG("  %s: { exact: [", aRange.mName);
     for (auto& entry : aRange.mExact) {
       LOG("      %s,", NS_ConvertUTF16toUTF8(entry).get());
     }
     LOG("    ], ideal: [");
     for (auto& entry : aRange.mIdeal) {
       LOG("      %s,", NS_ConvertUTF16toUTF8(entry).get());
--- a/dom/media/webrtc/MediaTrackConstraints.h
+++ b/dom/media/webrtc/MediaTrackConstraints.h
@@ -47,17 +47,17 @@ class NormalizedConstraintSet {
 
     BaseRange(MemberPtrType aMemberPtr, const char* aName,
               nsTArray<MemberPtrType>* aList)
         : mName(aName) {
       if (aList) {
         aList->AppendElement(aMemberPtr);
       }
     }
-    virtual ~BaseRange() {}
+    virtual ~BaseRange() = default;
 
    public:
     virtual bool Merge(const BaseRange& aOther) = 0;
     virtual void FinalizeMerge() = 0;
 
     const char* mName;
   };
 
@@ -71,17 +71,17 @@ class NormalizedConstraintSet {
     Maybe<ValueType> mIdeal;
 
     Range(MemberPtrType aMemberPtr, const char* aName, ValueType aMin,
           ValueType aMax, nsTArray<MemberPtrType>* aList)
         : BaseRange(aMemberPtr, aName, aList),
           mMin(aMin),
           mMax(aMax),
           mMergeDenominator(0) {}
-    virtual ~Range(){};
+    virtual ~Range() = default;
 
     template <class ConstrainRange>
     void SetFrom(const ConstrainRange& aOther);
     ValueType Clamp(ValueType n) const {
       return std::max(mMin, std::min(n, mMax));
     }
     ValueType Get(ValueType defaultValue) const {
       return Clamp(mIdeal.valueOr(defaultValue));
@@ -201,17 +201,17 @@ class NormalizedConstraintSet {
         bool advanced, nsTArray<MemberPtrType>* aList);
 
     StringRange(StringPtrType aMemberPtr, const char* aName,
                 const nsString& aOther, nsTArray<MemberPtrType>* aList)
         : BaseRange((MemberPtrType)aMemberPtr, aName, aList) {
       mIdeal.insert(aOther);
     }
 
-    ~StringRange() {}
+    ~StringRange() = default;
 
     void SetFrom(const dom::ConstrainDOMStringParameters& aOther);
     ValueType Clamp(const ValueType& n) const;
     ValueType Get(const ValueType& defaultValue) const {
       return Clamp(mIdeal.empty() ? defaultValue : mIdeal);
     }
     bool Intersects(const StringRange& aOther) const;
     void Intersect(const StringRange& aOther);
@@ -306,17 +306,17 @@ struct FlattenedConstraints : public Nor
 class MediaConstraintsHelper {
  public:
   template <class ValueType, class NormalizedRange>
   static uint32_t FitnessDistance(ValueType aN, const NormalizedRange& aRange);
   template <class ValueType, class NormalizedRange>
   static uint32_t FeasibilityDistance(ValueType aN,
                                       const NormalizedRange& aRange);
   static uint32_t FitnessDistance(
-      nsString aN, const NormalizedConstraintSet::StringRange& aConstraint);
+      const nsString& aN, const NormalizedConstraintSet::StringRange& aParams);
 
  protected:
   static bool SomeSettingsFit(const NormalizedConstraints& aConstraints,
                               const nsTArray<RefPtr<MediaDevice>>& aDevices);
 
  public:
   static uint32_t GetMinimumFitnessDistance(
       const NormalizedConstraintSet& aConstraints, const nsString& aDeviceId);
--- a/dom/media/webrtc/PeerIdentity.h
+++ b/dom/media/webrtc/PeerIdentity.h
@@ -26,17 +26,17 @@ namespace mozilla {
  * http://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-09#section-5.6.5.3.3.1
  */
 class PeerIdentity final : public RefCounted<PeerIdentity> {
  public:
   MOZ_DECLARE_REFCOUNTED_TYPENAME(PeerIdentity)
 
   explicit PeerIdentity(const nsAString& aPeerIdentity)
       : mPeerIdentity(aPeerIdentity) {}
-  ~PeerIdentity() {}
+  ~PeerIdentity() = default;
 
   bool Equals(const PeerIdentity& aOther) const;
   bool Equals(const nsAString& aOtherString) const;
   const nsString& ToString() const { return mPeerIdentity; }
 
  private:
   static void GetUser(const nsAString& aPeerIdentity, nsAString& aUser);
   static void GetHost(const nsAString& aPeerIdentity, nsAString& aHost);
--- a/dom/media/webrtc/RTCIdentityProviderRegistrar.cpp
+++ b/dom/media/webrtc/RTCIdentityProviderRegistrar.cpp
@@ -23,17 +23,17 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(RT
                                       mValidateAssertionCallback)
 
 RTCIdentityProviderRegistrar::RTCIdentityProviderRegistrar(
     nsIGlobalObject* aGlobal)
     : mGlobal(aGlobal),
       mGenerateAssertionCallback(nullptr),
       mValidateAssertionCallback(nullptr) {}
 
-RTCIdentityProviderRegistrar::~RTCIdentityProviderRegistrar() {}
+RTCIdentityProviderRegistrar::~RTCIdentityProviderRegistrar() = default;
 
 nsIGlobalObject* RTCIdentityProviderRegistrar::GetParentObject() const {
   return mGlobal;
 }
 
 JSObject* RTCIdentityProviderRegistrar::WrapObject(
     JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
   return RTCIdentityProviderRegistrar_Binding::Wrap(aCx, this, aGivenProto);