Bug 1208371 - Introduce MediaStreamTrack logs. r?roc,jib draft
authorAndreas Pehrson <pehrsons@gmail.com>
Tue, 05 Jan 2016 10:16:21 +0800
changeset 342086 5c5be90b49be2fed66db3655a6915b469c955b2e
parent 342085 b19a04268ea8227a5532dd56fc021dfb6b1b4c5f
child 342087 d04a7967e8bc5547432f36374e9f678875f7b7c8
push id13352
push userpehrsons@gmail.com
push dateFri, 18 Mar 2016 13:49:47 +0000
reviewersroc, jib
bugs1208371
milestone47.0a1
Bug 1208371 - Introduce MediaStreamTrack logs. r?roc,jib MozReview-Commit-ID: d1Fogpb6MO
dom/media/MediaStreamTrack.cpp
--- a/dom/media/MediaStreamTrack.cpp
+++ b/dom/media/MediaStreamTrack.cpp
@@ -4,23 +4,34 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MediaStreamTrack.h"
 
 #include "DOMMediaStream.h"
 #include "nsIUUIDGenerator.h"
 #include "nsServiceManagerUtils.h"
 
+#ifdef LOG
+#undef LOG
+#endif
+
+static PRLogModuleInfo* gMediaStreamTrackLog;
+#define LOG(type, msg) MOZ_LOG(gMediaStreamTrackLog, type, msg)
+
 namespace mozilla {
 namespace dom {
 
 MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID, const nsString& aLabel)
   : mOwningStream(aStream), mTrackID(aTrackID), mLabel(aLabel), mEnded(false), mEnabled(true)
 {
 
+  if (!gMediaStreamTrackLog) {
+    gMediaStreamTrackLog = PR_NewLogModule("MediaStreamTrack");
+  }
+
   nsresult rv;
   nsCOMPtr<nsIUUIDGenerator> uuidgen =
     do_GetService("@mozilla.org/uuid-generator;1", &rv);
 
   nsID uuid;
   memset(&uuid, 0, sizeof(uuid));
   if (uuidgen) {
     uuidgen->GenerateUUIDInPlace(&uuid);
@@ -47,27 +58,40 @@ void
 MediaStreamTrack::GetId(nsAString& aID) const
 {
   aID = mID;
 }
 
 void
 MediaStreamTrack::SetEnabled(bool aEnabled)
 {
+  LOG(LogLevel::Info, ("MediaStreamTrack %p %s",
+                       this, aEnabled ? "Enabled" : "Disabled"));
+
   mEnabled = aEnabled;
   mOwningStream->SetTrackEnabled(mTrackID, aEnabled);
 }
 
 void
 MediaStreamTrack::Stop()
 {
+  LOG(LogLevel::Info, ("MediaStreamTrack %p Stop()", this));
+
   mOwningStream->StopTrack(mTrackID);
 }
 
 already_AddRefed<Promise>
 MediaStreamTrack::ApplyConstraints(const MediaTrackConstraints& aConstraints,
                                    ErrorResult &aRv)
 {
+  if (MOZ_LOG_TEST(gMediaStreamTrackLog, LogLevel::Info)) {
+    nsString str;
+    aConstraints.ToJSON(str);
+
+    LOG(LogLevel::Info, ("MediaStreamTrack %p ApplyConstraints() with "
+                         "constraints %s", this, NS_ConvertUTF16toUTF8(str).get()));
+  }
+
   return GetStream()->ApplyConstraintsToTrack(mTrackID, aConstraints, aRv);
 }
 
 } // namespace dom
 } // namespace mozilla