[Mac] Add helper methods to convert CMTime <--> MediaTime
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Oct 2013 07:07:07 +0000 (07:07 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Oct 2013 07:07:07 +0000 (07:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123285

Reviewed by Eric Carlson.

Source/WebCore:

Add utility methods to convert between CMTime (a rational time class) and MediaTime.
Once there, PlatformClockCM can now vend and accept MediaTimes for currentTime.

* platform/mac/MediaTimeMac.h:
* platform/mac/MediaTimeMac.cpp:
(WebCore::toMediaTime): Added conversion utility method.
(WebCore::toCMTime): Ditto.

* platform/mac/PlatformClockCM.h:
* platform/mac/PlatformClockCM.mm:
(PlatformClockCM::setCurrentMediaTime): Added.
(PlatformClockCM::currentMediaTime): Added.

* WebCore.xcodeproj/project.pbxproj: Add new files to project.

Source/WTF:

Add a #ifdef header_h protector.

* wtf/MediaTime.h:

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

Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/WTF/ChangeLog
Source/WTF/wtf/MediaTime.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/mac/MediaTimeMac.cpp [new file with mode: 0644]
Source/WebCore/platform/mac/MediaTimeMac.h [new file with mode: 0644]
Source/WebCore/platform/mac/PlatformClockCM.h
Source/WebCore/platform/mac/PlatformClockCM.mm

index 65c59f254c7aaf632782e24a9f2be31b4db0c65b..5cb22d0eebba5c1161c1555c7223354fa7c6ef46 100644 (file)
                C2F0F2D016BAEEE900187C19 /* StructureRareData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructureRareData.cpp; sourceTree = "<group>"; };
                C2FC9BD216644DFB00810D33 /* CopiedBlockInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CopiedBlockInlines.h; sourceTree = "<group>"; };
                C2FE18A316BAEC4000AF3061 /* StructureRareData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructureRareData.h; sourceTree = "<group>"; };
-               FEE7D5A00D99AC04005351F6 /* iOS.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = iOS.xcconfig; sourceTree = "<group>"; };
                D21202280AD4310C00ED79B6 /* DateConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = DateConversion.cpp; sourceTree = "<group>"; };
                D21202290AD4310C00ED79B6 /* DateConversion.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DateConversion.h; sourceTree = "<group>"; };
                DDF7ABD211F60ED200108E36 /* GCActivityCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCActivityCallback.h; sourceTree = "<group>"; };
                FED94F2B171E3E2300BE77A4 /* Watchdog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Watchdog.cpp; sourceTree = "<group>"; };
                FED94F2C171E3E2300BE77A4 /* Watchdog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Watchdog.h; sourceTree = "<group>"; };
                FED94F2D171E3E2300BE77A4 /* WatchdogMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WatchdogMac.cpp; sourceTree = "<group>"; };
+               FEE7D5A00D99AC04005351F6 /* iOS.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = iOS.xcconfig; sourceTree = "<group>"; };
                FEF6835A174343CC00A32E25 /* JITStubsARM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITStubsARM.h; sourceTree = "<group>"; };
                FEF6835B174343CC00A32E25 /* JITStubsARMv7.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITStubsARMv7.h; sourceTree = "<group>"; };
                FEF6835C174343CC00A32E25 /* JITStubsX86_64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITStubsX86_64.h; sourceTree = "<group>"; };
index ece41799090b74d2e4991295efc1cd605d9f3e4b..b3c57db50b81d402d7cbc43913d2989114bc676b 100644 (file)
@@ -1,3 +1,14 @@
+2013-10-24  Jer Noble  <jer.noble@apple.com>
+
+        [Mac] Add helper methods to convert CMTime <--> MediaTime
+        https://bugs.webkit.org/show_bug.cgi?id=123285
+
+        Reviewed by Eric Carlson.
+
+        Add a #ifdef header_h protector.
+
+        * wtf/MediaTime.h:
+
 2013-10-24  Mark Rowe  <mrowe@apple.com>
 
         Remove references to OS X 10.7 from Xcode configuration settings.
index ef723ff9b03ed4a742790e80d60225a33a7151c0..48af164d985c36195b57195e2179264d7f839fed 100644 (file)
@@ -26,6 +26,9 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef MediaTime_h
+#define MediaTime_h
+
 #include <wtf/FastMalloc.h>
 
 #include <cmath>
@@ -107,3 +110,5 @@ WTF_EXPORT_PRIVATE extern MediaTime abs(const MediaTime& rhs);
 
 using WTF::MediaTime;
 using WTF::abs;
+
+#endif
index 70090ab098f5f352e9a85a1cdeb6101e7f85e43b..49c3cc8307a89867f06381d4f24083b9685235eb 100644 (file)
@@ -1,3 +1,25 @@
+2013-10-24  Jer Noble  <jer.noble@apple.com>
+
+        [Mac] Add helper methods to convert CMTime <--> MediaTime
+        https://bugs.webkit.org/show_bug.cgi?id=123285
+
+        Reviewed by Eric Carlson.
+
+        Add utility methods to convert between CMTime (a rational time class) and MediaTime.
+        Once there, PlatformClockCM can now vend and accept MediaTimes for currentTime.
+
+        * platform/mac/MediaTimeMac.h:
+        * platform/mac/MediaTimeMac.cpp:
+        (WebCore::toMediaTime): Added conversion utility method.
+        (WebCore::toCMTime): Ditto.
+
+        * platform/mac/PlatformClockCM.h:
+        * platform/mac/PlatformClockCM.mm:
+        (PlatformClockCM::setCurrentMediaTime): Added.
+        (PlatformClockCM::currentMediaTime): Added.
+
+        * WebCore.xcodeproj/project.pbxproj: Add new files to project.
+
 2013-10-24  Mark Rowe  <mrowe@apple.com>
 
         Remove references to OS X 10.7 from Xcode configuration settings.
index d9e24c7ff64a73fb962799ce842d7b240ba34079..e531ea31bd08e6e09205856686415ffe5deadaa5 100644 (file)
                CD61FE851794CC59004101EB /* JSWebKitSourceBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = CD61FE811794CC59004101EB /* JSWebKitSourceBuffer.h */; };
                CD61FE861794CC59004101EB /* JSWebKitSourceBufferList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD61FE821794CC59004101EB /* JSWebKitSourceBufferList.cpp */; };
                CD61FE871794CC59004101EB /* JSWebKitSourceBufferList.h in Headers */ = {isa = PBXBuildFile; fileRef = CD61FE831794CC59004101EB /* JSWebKitSourceBufferList.h */; };
+               CD641EBF1819B36000EE4C41 /* MediaTimeMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD641EBD1819B35900EE4C41 /* MediaTimeMac.cpp */; };
+               CD641EC01819B36000EE4C41 /* MediaTimeMac.h in Headers */ = {isa = PBXBuildFile; fileRef = CD641EBE1819B35900EE4C41 /* MediaTimeMac.h */; };
                CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */; };
                CD82030A1395AB6A00F956C6 /* WebVideoFullscreenController.h in Headers */ = {isa = PBXBuildFile; fileRef = CD8203061395AB6A00F956C6 /* WebVideoFullscreenController.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD82030B1395AB6A00F956C6 /* WebVideoFullscreenController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD8203071395AB6A00F956C6 /* WebVideoFullscreenController.mm */; settings = {COMPILER_FLAGS = "-Wno-undef -Wno-deprecated-declarations"; }; };
                CD61FE811794CC59004101EB /* JSWebKitSourceBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitSourceBuffer.h; sourceTree = "<group>"; };
                CD61FE821794CC59004101EB /* JSWebKitSourceBufferList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebKitSourceBufferList.cpp; sourceTree = "<group>"; };
                CD61FE831794CC59004101EB /* JSWebKitSourceBufferList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebKitSourceBufferList.h; sourceTree = "<group>"; };
+               CD641EBD1819B35900EE4C41 /* MediaTimeMac.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MediaTimeMac.cpp; sourceTree = "<group>"; };
+               CD641EBE1819B35900EE4C41 /* MediaTimeMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaTimeMac.h; sourceTree = "<group>"; };
                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WebCoreAVFResourceLoader.h; path = objc/WebCoreAVFResourceLoader.h; sourceTree = "<group>"; };
                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreAVFResourceLoader.mm; path = objc/WebCoreAVFResourceLoader.mm; sourceTree = "<group>"; };
                CD8203061395AB6A00F956C6 /* WebVideoFullscreenController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVideoFullscreenController.h; sourceTree = "<group>"; };
                                06E81EEB0AB5DA9700C87837 /* LocalCurrentGraphicsContext.mm */,
                                BC25B528131C6D3900180E10 /* LocalizedStringsMac.cpp */,
                                1402645D0AFDC19B005919E2 /* LoggingMac.mm */,
+                               CD641EBD1819B35900EE4C41 /* MediaTimeMac.cpp */,
+                               CD641EBE1819B35900EE4C41 /* MediaTimeMac.h */,
                                657EDA0A1385CBD8004E0645 /* MemoryPressureHandlerMac.mm */,
                                BC772C5D0C4EB3440083285F /* MIMETypeRegistryMac.mm */,
                                93500F3113FDE3BE0099EC24 /* NSScrollerImpDetails.h */,
                                1A71D57C0F33819000F9CE4E /* IdentifierRep.h in Headers */,
                                5913A24213D49EBA00F5B05C /* IdentifiersFactory.h in Headers */,
                                49E911C50EF86D47009D0CAF /* IdentityTransformOperation.h in Headers */,
+                               CD641EC01819B36000EE4C41 /* MediaTimeMac.h in Headers */,
                                C0C054CD1118C8E400CE2636 /* IDLParser.pm in Headers */,
                                C3CF17A515B0063F00276D39 /* IdTargetObserver.h in Headers */,
                                C3CF17A715B0063F00276D39 /* IdTargetObserverRegistry.h in Headers */,
                                CDA98E0616039E1F00FEA3B1 /* JSMediaKeySession.cpp in Sources */,
                                BC3C39B60C0D3D8D005F4D7A /* JSMediaList.cpp in Sources */,
                                D3A94A46122DC40F00A37BBC /* JSMediaQueryList.cpp in Sources */,
+                               CD641EBF1819B36000EE4C41 /* MediaTimeMac.cpp in Sources */,
                                FDBD480C159BC6870093EB4F /* JSMediaStreamAudioSourceNode.cpp in Sources */,
                                E107400D0E77BDC00033AF24 /* JSMessageChannel.cpp in Sources */,
                                E1A5F99B0E7EAA2500AF85EA /* JSMessageChannelCustom.cpp in Sources */,
diff --git a/Source/WebCore/platform/mac/MediaTimeMac.cpp b/Source/WebCore/platform/mac/MediaTimeMac.cpp
new file mode 100644 (file)
index 0000000..6b2221c
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "MediaTimeMac.h"
+
+#if USE(COREMEDIA)
+
+namespace WebCore {
+
+MediaTime toMediaTime(const CMTime& cmTime)
+{
+    uint32_t flags = 0;
+    if (CMTIME_IS_VALID(cmTime))
+        flags |= MediaTime::Valid;
+    if (CMTIME_HAS_BEEN_ROUNDED(cmTime))
+        flags |= MediaTime::HasBeenRounded;
+    if (CMTIME_IS_POSITIVE_INFINITY(cmTime))
+        flags |= MediaTime::PositiveInfinite;
+    if (CMTIME_IS_NEGATIVE_INFINITY(cmTime))
+        flags |= MediaTime::NegativeInfinite;
+    if (CMTIME_IS_INDEFINITE(cmTime))
+        flags |= MediaTime::Indefinite;
+
+    return MediaTime(cmTime.value, cmTime.timescale, flags);
+}
+
+CMTime toCMTime(const MediaTime& mediaTime)
+{
+    CMTime time = {mediaTime.timeValue(), mediaTime.timeScale(), 0, 0};
+
+    if (mediaTime.isValid())
+        time.flags |= kCMTimeFlags_Valid;
+    if (mediaTime.hasBeenRounded())
+        time.flags |= kCMTimeFlags_HasBeenRounded;
+    if (mediaTime.isPositiveInfinite())
+        time.flags |= kCMTimeFlags_PositiveInfinity;
+    if (mediaTime.isNegativeInfinite())
+        time.flags |= kCMTimeFlags_NegativeInfinity;
+
+    return time;
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/mac/MediaTimeMac.h b/Source/WebCore/platform/mac/MediaTimeMac.h
new file mode 100644 (file)
index 0000000..241120d
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef MediaTimeMac_h
+#define MediaTimeMac_h
+
+#if USE(COREMEDIA)
+
+#include <CoreMedia/CMTime.h>
+#include <wtf/MediaTime.h>
+
+namespace WebCore {
+
+CMTime toCMTime(const MediaTime&);
+MediaTime toMediaTime(const CMTime&);
+
+}
+
+#endif
+
+#endif
index f36250c221d582a77aad937f6113101192565a7b..9ee49a76afc98b30b96fc9074ac5d5c67377cd07 100644 (file)
@@ -29,6 +29,7 @@
 #if USE(COREMEDIA)
 
 #include "Clock.h"
+#include <wtf/MediaTime.h>
 #include <wtf/RetainPtr.h>
 
 typedef struct OpaqueCMTimebase* CMTimebaseRef;
@@ -41,12 +42,12 @@ public:
     PlatformClockCM();
     PlatformClockCM(CMClockRef);
 
-private:
-    void initializeWithTimingSource(CMClockRef);
-
     virtual void setCurrentTime(double) OVERRIDE;
     virtual double currentTime() const OVERRIDE;
 
+    void setCurrentMediaTime(const MediaTime&);
+    MediaTime currentMediaTime() const;
+
     virtual void setPlayRate(double) OVERRIDE;
     virtual double playRate() const OVERRIDE { return m_rate; }
 
@@ -54,6 +55,9 @@ private:
     virtual void stop() OVERRIDE;
     virtual bool isRunning() const OVERRIDE { return m_running; }
 
+private:
+    void initializeWithTimingSource(CMClockRef);
+
     RetainPtr<CMTimebaseRef> m_timebase;
     double m_rate;
     bool m_running;
index 117514a23d48ce3086149d1ad4a0397ecf015f6d..33f54c9a14f30e4a252eb5b820b4eaaa65c7e035 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "PlatformClockCM.h"
 
+#import "MediaTimeMac.h"
 #import "SoftLinking.h"
 #import <CoreMedia/CMAudioDeviceClock.h>
 
@@ -84,6 +85,16 @@ double PlatformClockCM::currentTime() const
     return CMTimeGetSeconds(cmTime);
 }
 
+void PlatformClockCM::setCurrentMediaTime(const MediaTime& time)
+{
+    CMTimebaseSetTime(m_timebase.get(), toCMTime(time));
+}
+
+MediaTime PlatformClockCM::currentMediaTime() const
+{
+    return toMediaTime(CMTimebaseGetTime(m_timebase.get()));
+}
+
 void PlatformClockCM::setPlayRate(double rate)
 {
     if (m_rate == rate)