Add a compile-time-checked string literal initializer for FourCC.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 19:06:53 +0000 (19:06 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Nov 2017 19:06:53 +0000 (19:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179706

Reviewed by Alex Christensen.

Add a contexpr constructor for FourCC that takes a string literal and static_asserts that it
is exactly 4 chars long. Use this string literal constructor everywhere instead of multi-
character literals.

* platform/graphics/FourCC.h:
(WebCore::FourCC::FourCC):
* platform/graphics/iso/ISOBox.cpp:
(WebCore::ISOBox::parse):
* platform/graphics/iso/ISOOriginalFormatBox.h:
(WebCore::ISOOriginalFormatBox::boxTypeName):
* platform/graphics/iso/ISOProtectionSchemeInfoBox.h:
(WebCore::ISOProtectionSchemeInfoBox::boxTypeName):
* platform/graphics/iso/ISOSchemeInformationBox.h:
(WebCore::ISOSchemeInformationBox::boxTypeName):
* platform/graphics/iso/ISOSchemeTypeBox.h:
(WebCore::ISOSchemeTypeBox::boxTypeName):
* platform/graphics/iso/ISOTrackEncryptionBox.h:
(WebCore::ISOTrackEncryptionBox::boxTypeName):
* platform/graphics/iso/ISOVTTCue.h:
(WebCore::ISOWebVTTCue::boxTypeName):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/FourCC.h
Source/WebCore/platform/graphics/iso/ISOBox.cpp
Source/WebCore/platform/graphics/iso/ISOOriginalFormatBox.h
Source/WebCore/platform/graphics/iso/ISOProtectionSchemeInfoBox.h
Source/WebCore/platform/graphics/iso/ISOSchemeInformationBox.h
Source/WebCore/platform/graphics/iso/ISOSchemeTypeBox.h
Source/WebCore/platform/graphics/iso/ISOTrackEncryptionBox.h
Source/WebCore/platform/graphics/iso/ISOVTTCue.cpp
Source/WebCore/platform/graphics/iso/ISOVTTCue.h

index ead935a..652c8e7 100644 (file)
@@ -1,3 +1,31 @@
+2017-11-15  Jer Noble  <jer.noble@apple.com>
+
+        Add a compile-time-checked string literal initializer for FourCC.
+        https://bugs.webkit.org/show_bug.cgi?id=179706
+
+        Reviewed by Alex Christensen.
+
+        Add a contexpr constructor for FourCC that takes a string literal and static_asserts that it
+        is exactly 4 chars long. Use this string literal constructor everywhere instead of multi-
+        character literals.
+
+        * platform/graphics/FourCC.h:
+        (WebCore::FourCC::FourCC):
+        * platform/graphics/iso/ISOBox.cpp:
+        (WebCore::ISOBox::parse):
+        * platform/graphics/iso/ISOOriginalFormatBox.h:
+        (WebCore::ISOOriginalFormatBox::boxTypeName):
+        * platform/graphics/iso/ISOProtectionSchemeInfoBox.h:
+        (WebCore::ISOProtectionSchemeInfoBox::boxTypeName):
+        * platform/graphics/iso/ISOSchemeInformationBox.h:
+        (WebCore::ISOSchemeInformationBox::boxTypeName):
+        * platform/graphics/iso/ISOSchemeTypeBox.h:
+        (WebCore::ISOSchemeTypeBox::boxTypeName):
+        * platform/graphics/iso/ISOTrackEncryptionBox.h:
+        (WebCore::ISOTrackEncryptionBox::boxTypeName):
+        * platform/graphics/iso/ISOVTTCue.h:
+        (WebCore::ISOWebVTTCue::boxTypeName):
+
 2017-11-15  Adrian Perez de Castro  <aperez@igalia.com>
 
         [Cairo] Clang warns about mismatched declaration type tag for GraphicsContextState
index ba8fd2d..e12ee52 100644 (file)
@@ -32,6 +32,13 @@ namespace WebCore {
 struct FourCC {
     WEBCORE_EXPORT FourCC(uint32_t value) : value(value) { }
 
+    template<std::size_t N>
+    constexpr FourCC(const char (&data)[N])
+    {
+        static_assert((N - 1) == 4, "FourCC literals must be exactly 4 characters long");
+        value = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+    }
+
     String toString() const;
     WEBCORE_EXPORT static std::optional<FourCC> fromString(const String&);
 
index 171f3f5..f616f43 100644 (file)
@@ -75,7 +75,7 @@ bool ISOBox::parse(DataView& view, unsigned& offset)
     if (m_size == 1 && !checkedRead<uint64_t>(m_size, view, offset, BigEndian))
         return false;
 
-    if (m_boxType.value == 'uuid') {
+    if (m_boxType == "uuid") {
         struct ExtendedType {
             uint8_t value[16];
         } extendedTypeStruct;
index e444a19..e90e76c 100644 (file)
@@ -31,7 +31,7 @@ namespace WebCore {
 
 class ISOOriginalFormatBox : public ISOBox {
 public:
-    static FourCC boxTypeName() { return 'frma'; }
+    static FourCC boxTypeName() { return "frma"; }
 
     FourCC dataFormat() const { return m_dataFormat; }
 
index 4b56be7..87068a8 100644 (file)
@@ -34,7 +34,7 @@ class ISOSchemeInformationBox;
 
 class ISOProtectionSchemeInfoBox : public ISOFullBox {
 public:
-    static FourCC boxTypeName() { return 'sinf'; }
+    static FourCC boxTypeName() { return "sinf"; }
 
     const ISOSchemeTypeBox* schemeTypeBox() const { return m_schemeTypeBox.get(); }
     const ISOSchemeInformationBox* schemeInformationBox() const { return m_schemeInformationBox.get(); }
index f47a7f0..d270975 100644 (file)
@@ -31,7 +31,7 @@ namespace WebCore {
 
 class ISOSchemeInformationBox : public ISOBox {
 public:
-    static FourCC boxTypeName() { return 'schi'; }
+    static FourCC boxTypeName() { return "schi"; }
 
     const ISOBox* schemeSpecificData() const { return m_schemeSpecificData.get(); }
 
index 0261181..66a9ca0 100644 (file)
@@ -31,7 +31,7 @@ namespace WebCore {
 
 class ISOSchemeTypeBox : public ISOFullBox {
 public:
-    static FourCC boxTypeName() { return 'schm'; }
+    static FourCC boxTypeName() { return "schm"; }
 
     FourCC schemeType() const { return m_schemeType; }
     uint32_t schemeVersion() const { return m_schemeVersion; }
index cbb5bfc..d1ecd21 100644 (file)
@@ -31,7 +31,7 @@ namespace WebCore {
 
 class ISOTrackEncryptionBox : public ISOFullBox {
 public:
-    static FourCC boxTypeName() { return 'tenc'; }
+    static FourCC boxTypeName() { return "tenc"; }
 
     std::optional<int8_t> defaultCryptByteBlock() const { return m_defaultCryptByteBlock; }
     std::optional<int8_t> defaultSkipByteBlock() const { return m_defaultSkipByteBlock; }
index 49a25e0..b920f14 100644 (file)
@@ -73,11 +73,11 @@ protected:
     String m_contents;
 };
 
-static FourCC vttIdBoxType() { return 'iden'; }
-static FourCC vttSettingsBoxType() { return 'sttg'; }
-static FourCC vttPayloadBoxType() { return 'payl'; }
-static FourCC vttCurrentTimeBoxType() { return 'ctim'; }
-static FourCC vttCueSourceIDBoxType() { return 'vsid'; }
+static FourCC vttIdBoxType() { return "iden"; }
+static FourCC vttSettingsBoxType() { return "sttg"; }
+static FourCC vttPayloadBoxType() { return "payl"; }
+static FourCC vttCurrentTimeBoxType() { return "ctim"; }
+static FourCC vttCueSourceIDBoxType() { return "vsid"; }
 
 ISOWebVTTCue::ISOWebVTTCue(const MediaTime& presentationTime, const MediaTime& duration)
     : m_presentationTime(presentationTime)
index 3dd313b..eb1e0d6 100644 (file)
@@ -42,7 +42,7 @@ class ISOWebVTTCue : public ISOBox {
 public:
     ISOWebVTTCue(const MediaTime& presentationTime, const MediaTime& duration);
 
-    static FourCC boxTypeName() { return 'vtcc'; }
+    static FourCC boxTypeName() { return "vtcc"; }
 
     const MediaTime& presentationTime() const { return m_presentationTime; }
     const MediaTime& duration() const { return m_duration; }