Log media time range as JSON
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 21:39:24 +0000 (21:39 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 21:39:24 +0000 (21:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185321
<rdar://problem/39986746>

Reviewed by Youenn Fablet.

Source/WebCore:

No new tests, tested manually.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::addPlayedRange): Log as time range.
(WebCore::HTMLMediaElement::visibilityStateChanged): Cleanup.

* platform/graphics/MediaPlayer.h:
(WTF::LogArgument<MediaTime>::toString):
(WTF::LogArgument<MediaTimeRange>::toString):

* platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
(WebCore::InbandTextTrackPrivateAVF::processAttributedStrings): Log error as time range.

Source/WTF:

* wtf/MediaTime.cpp:
(WTF::toJSONStringInternal): Extract guts of MediaTime::toJSONString to this static function
so it can be used by MediaTimeRange::toJSONString as well.
(WTF::MediaTime::toJSONString const):
(WTF::MediaTimeRange::toJSONString const):
* wtf/MediaTime.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231382 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/MediaTime.cpp
Source/WTF/wtf/MediaTime.h
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp

index d7509eb..12a4c3c 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-04  Eric Carlson  <eric.carlson@apple.com>
+
+        Log media time range as JSON
+        https://bugs.webkit.org/show_bug.cgi?id=185321
+        <rdar://problem/39986746>
+
+        Reviewed by Youenn Fablet.
+
+        * wtf/MediaTime.cpp:
+        (WTF::toJSONStringInternal): Extract guts of MediaTime::toJSONString to this static function
+        so it can be used by MediaTimeRange::toJSONString as well.
+        (WTF::MediaTime::toJSONString const):
+        (WTF::MediaTimeRange::toJSONString const):
+        * wtf/MediaTime.h:
+
 2018-05-04  Antti Koivisto  <antti@apple.com>
 
         OptionsSet initializer list constructor should be constexpr
index 03050b5..9a28ab0 100644 (file)
@@ -577,28 +577,33 @@ String MediaTime::toString() const
     return builder.toString();
 }
 
-String MediaTime::toJSONString() const
+static Ref<JSON::Object> toJSONStringInternal(const MediaTime& time)
 {
     auto object = JSON::Object::create();
 
-    if (hasDoubleValue())
-        object->setDouble(ASCIILiteral("value"), toDouble());
+    if (time.hasDoubleValue())
+        object->setDouble(ASCIILiteral("value"), time.toDouble());
     else {
-        if (isInvalid() || isIndefinite())
+        if (time.isInvalid() || time.isIndefinite())
             object->setString(ASCIILiteral("value"), ASCIILiteral("NaN"));
-        else if (isPositiveInfinite())
+        else if (time.isPositiveInfinite())
             object->setString(ASCIILiteral("value"), ASCIILiteral("POSITIVE_INFINITY"));
-        else if (isNegativeInfinite())
+        else if (time.isNegativeInfinite())
             object->setString(ASCIILiteral("value"), ASCIILiteral("NEGATIVE_INFINITY"));
         else
-            object->setDouble(ASCIILiteral("value"), toDouble());
+            object->setDouble(ASCIILiteral("value"), time.toDouble());
 
-        object->setInteger(ASCIILiteral("numerator"), static_cast<int>(m_timeValue));
-        object->setInteger(ASCIILiteral("denominator"), m_timeScale);
-        object->setInteger(ASCIILiteral("flags"), m_timeFlags);
+        object->setInteger(ASCIILiteral("numerator"), static_cast<int>(time.timeValue()));
+        object->setInteger(ASCIILiteral("denominator"), time.timeScale());
+        object->setInteger(ASCIILiteral("flags"), time.timeFlags());
     }
 
-    return object->toJSONString();
+    return object;
+}
+
+String MediaTime::toJSONString() const
+{
+    return toJSONStringInternal(*this)->toJSONString();
 }
 
 MediaTime abs(const MediaTime& rhs)
@@ -615,5 +620,14 @@ MediaTime abs(const MediaTime& rhs)
     return val;
 }
 
+String MediaTimeRange::toJSONString() const
+{
+    auto object = JSON::Object::create();
+
+    object->setObject(ASCIILiteral("start"), toJSONStringInternal(start));
+    object->setObject(ASCIILiteral("end"), toJSONStringInternal(end));
+
+    return object->toJSONString();
 }
 
+}
index 337fefe..4aded37 100644 (file)
@@ -98,6 +98,7 @@ public:
     bool isNegativeInfinite() const { return m_timeFlags & NegativeInfinite; }
     bool isIndefinite() const { return m_timeFlags & Indefinite; }
     bool hasDoubleValue() const { return m_timeFlags & DoubleValue; }
+    uint8_t timeFlags() const { return m_timeFlags; }
 
     static const MediaTime& zeroTime();
     static const MediaTime& invalidTime();
@@ -151,6 +152,13 @@ inline MediaTime operator*(int32_t lhs, const MediaTime& rhs) { return rhs.opera
 
 WTF_EXPORT_PRIVATE extern MediaTime abs(const MediaTime& rhs);
 
+struct WTF_EXPORT_PRIVATE MediaTimeRange {
+    String toJSONString() const;
+
+    const MediaTime start;
+    const MediaTime end;
+};
+
 template<class Encoder>
 void MediaTime::encode(Encoder& encoder) const
 {
@@ -168,6 +176,7 @@ bool MediaTime::decode(Decoder& decoder, MediaTime& time)
 }
 
 using WTF::MediaTime;
+using WTF::MediaTimeRange;
 using WTF::abs;
 
 #endif
index 9723cf4..bd128f9 100644 (file)
@@ -1,3 +1,24 @@
+2018-05-04  Eric Carlson  <eric.carlson@apple.com>
+
+        Log media time range as JSON
+        https://bugs.webkit.org/show_bug.cgi?id=185321
+        <rdar://problem/39986746>
+
+        Reviewed by Youenn Fablet.
+
+        No new tests, tested manually.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::addPlayedRange): Log as time range.
+        (WebCore::HTMLMediaElement::visibilityStateChanged): Cleanup.
+
+        * platform/graphics/MediaPlayer.h:
+        (WTF::LogArgument<MediaTime>::toString):
+        (WTF::LogArgument<MediaTimeRange>::toString):
+
+        * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:
+        (WebCore::InbandTextTrackPrivateAVF::processAttributedStrings): Log error as time range.
+
 2018-05-04  Zalan Bujtas  <zalan@apple.com>
 
         Use the containing block to compute the pagination gap when the container is inline.
index 521fca2..9078ae5 100644 (file)
@@ -2842,7 +2842,7 @@ void HTMLMediaElement::returnToRealtime()
 
 void HTMLMediaElement::addPlayedRange(const MediaTime& start, const MediaTime& end)
 {
-    DEBUG_LOG(LOGIDENTIFIER, "[", start, ", ", end, "]");
+    DEBUG_LOG(LOGIDENTIFIER, MediaTimeRange { start, end });
     if (!m_playedTimeRanges)
         m_playedTimeRanges = TimeRanges::create();
     m_playedTimeRanges->ranges().add(start, end);
@@ -5633,10 +5633,10 @@ void HTMLMediaElement::visibilityStateChanged()
     bool isPlayingAudio = isPlaying() && hasAudio() && !muted() && volume();
     if (!isPlayingAudio) {
         if (m_elementIsHidden) {
-            ALWAYS_LOG(LOGIDENTIFIER, "visibilityStateChanged() Suspending playback after going to the background");
+            ALWAYS_LOG(LOGIDENTIFIER, "Suspending playback after going to the background");
             m_mediaSession->beginInterruption(PlatformMediaSession::EnteringBackground);
         } else {
-            ALWAYS_LOG(LOGIDENTIFIER, "visibilityStateChanged() Resuming playback after entering foreground");
+            ALWAYS_LOG(LOGIDENTIFIER, "Resuming playback after entering foreground");
             m_mediaSession->endInterruption(PlatformMediaSession::MayResumePlaying);
         }
     }
index c64ed91..f6a1dc3 100644 (file)
@@ -694,9 +694,18 @@ template <>
 struct LogArgument<MediaTime> {
     static String toString(const MediaTime& time)
     {
-        return time.toString();
+        return time.toJSONString();
     }
 };
+
+template <>
+struct LogArgument<MediaTimeRange> {
+    static String toString(const MediaTimeRange& range)
+    {
+        return range.toJSONString();
+    }
+};
+
 }
 
 #endif // ENABLE(VIDEO)
index 6f2b387..74c417a 100644 (file)
@@ -383,7 +383,7 @@ void InbandTextTrackPrivateAVF::processAttributedStrings(CFArrayRef attributedSt
                 }
             }
         } else
-            ERROR_LOG(LOGIDENTIFIER, "negative length cue(s): start ", m_currentCueStartTime, ", end ", m_currentCueEndTime);
+            ERROR_LOG(LOGIDENTIFIER, "negative length cue(s): ", MediaTimeRange { m_currentCueStartTime, m_currentCueEndTime });
 
         removeCompletedCues();
     }