Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Implement EncodedVideoChunk
https://bugs.webkit.org/show_bug.cgi?id=245665 rdar://problem/100401981 Reviewed by Eric Carlson. Add WEB_CODECS compilation guard and runtime flag. Implement WebCodecsEncodedVideoChunk and expose EncodedVideoChunk as per https://w3c.github.io/webcodecs/#encodedvideochunk-interface. We do not support yet Transferable/Serializable. * LayoutTests/imported/w3c/web-platform-tests/webcodecs/chunk-serialization.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/webcodecs/encoded-video-chunk.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/webcodecs/encoded-video-chunk.any.worker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/webcodecs/encoded-video-chunk.crossOriginIsolated.https.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/webcodecs/encoded-video-chunk.crossOriginIsolated.https.any.worker-expected.txt: * Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml: * Source/WTF/wtf/PlatformEnableCocoa.h: * Source/WebCore/CMakeLists.txt: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Modules/webcodecs/WebCodecsEncodedVideoChunk.cpp: Added. (WebCore::WebCodecsEncodedVideoChunk::WebCodecsEncodedVideoChunk): (WebCore::WebCodecsEncodedVideoChunk::copyTo): * Source/WebCore/Modules/webcodecs/WebCodecsEncodedVideoChunk.h: Added. (WebCore::WebCodecsEncodedVideoChunk::create): (WebCore::WebCodecsEncodedVideoChunk::type const): (WebCore::WebCodecsEncodedVideoChunk::timestamp const): (WebCore::WebCodecsEncodedVideoChunk::duration const): (WebCore::WebCodecsEncodedVideoChunk::byteLength const): * Source/WebCore/Modules/webcodecs/WebCodecsEncodedVideoChunk.idl: Added. * Source/WebCore/Modules/webcodecs/WebCodecsEncodedVideoChunkType.h: Added. * Source/WebCore/Modules/webcodecs/WebCodecsEncodedVideoChunkType.idl: Added. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/bindings/js/WebCoreBuiltinNames.h: Canonical link: https://commits.webkit.org/254953@main
- Loading branch information
Showing
19 changed files
with
308 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL Verify EncodedAudioChunk is serializable. Can't find variable: EncodedAudioChunk | ||
FAIL Verify EncodedVideoChunk is serializable. Can't find variable: EncodedVideoChunk | ||
FAIL Verify EncodedVideoChunk is serializable. The object can not be cloned. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL Test we can construct an EncodedVideoChunk. Can't find variable: EncodedVideoChunk | ||
FAIL Test copyTo() exception if destiation invalid Can't find variable: EncodedVideoChunk | ||
PASS Test we can construct an EncodedVideoChunk. | ||
PASS Test copyTo() exception if destiation invalid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL Test we can construct an EncodedVideoChunk. Can't find variable: EncodedVideoChunk | ||
FAIL Test copyTo() exception if destiation invalid Can't find variable: EncodedVideoChunk | ||
PASS Test we can construct an EncodedVideoChunk. | ||
PASS Test copyTo() exception if destiation invalid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL Test construction and copyTo() using a SharedArrayBuffer Can't find variable: EncodedVideoChunk | ||
FAIL Test construction and copyTo() using a Uint8Array(SharedArrayBuffer) Can't find variable: EncodedVideoChunk | ||
FAIL Test construction and copyTo() using a SharedArrayBuffer Type error | ||
FAIL Test construction and copyTo() using a Uint8Array(SharedArrayBuffer) Type error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
FAIL Test construction and copyTo() using a SharedArrayBuffer Can't find variable: EncodedVideoChunk | ||
FAIL Test construction and copyTo() using a Uint8Array(SharedArrayBuffer) Can't find variable: EncodedVideoChunk | ||
FAIL Test construction and copyTo() using a SharedArrayBuffer Type error | ||
FAIL Test construction and copyTo() using a Uint8Array(SharedArrayBuffer) Type error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2022 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 "WebCodecsEncodedVideoChunk.h" | ||
|
||
#if ENABLE(WEB_CODECS) | ||
|
||
#include "ExceptionOr.h" | ||
|
||
namespace WebCore { | ||
|
||
WebCodecsEncodedVideoChunk::WebCodecsEncodedVideoChunk(Init&& init) | ||
: m_type(init.type) | ||
, m_timestamp(init.timestamp) | ||
, m_duration(init.duration) | ||
, m_data(Span<const uint8_t> { init.data.data(), init.data.length() }) | ||
{ | ||
} | ||
|
||
ExceptionOr<void> WebCodecsEncodedVideoChunk::copyTo(BufferSource&& source) | ||
{ | ||
if (source.length() < m_data.size()) | ||
return Exception { TypeError, "buffer is too small"_s }; | ||
|
||
std::memcpy(source.mutableData(), m_data.data(), m_data.size()); | ||
return { }; | ||
} | ||
|
||
} // namespace WebCore | ||
|
||
#endif // ENABLE(WEB_CODECS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2022 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if ENABLE(WEB_CODECS) | ||
|
||
#include "BufferSource.h" | ||
#include "ExceptionOr.h" | ||
#include "WebCodecsEncodedVideoChunkType.h" | ||
#include <wtf/Vector.h> | ||
|
||
namespace WebCore { | ||
|
||
class WebCodecsEncodedVideoChunk : public RefCounted<WebCodecsEncodedVideoChunk> { | ||
public: | ||
~WebCodecsEncodedVideoChunk() = default; | ||
|
||
struct Init { | ||
WebCodecsEncodedVideoChunkType type { WebCodecsEncodedVideoChunkType::Key }; | ||
int64_t timestamp { 0 }; | ||
std::optional<uint64_t> duration; | ||
BufferSource data; | ||
}; | ||
|
||
static Ref<WebCodecsEncodedVideoChunk> create(Init&& init) { return adoptRef(*new WebCodecsEncodedVideoChunk(WTFMove(init))); } | ||
|
||
WebCodecsEncodedVideoChunkType type() const { return m_type; }; | ||
int64_t timestamp() const { return m_timestamp; } | ||
std::optional<uint64_t> duration() const { return m_duration; } | ||
size_t byteLength() const { return m_data.capacity(); } | ||
|
||
ExceptionOr<void> copyTo(BufferSource&&); | ||
|
||
private: | ||
explicit WebCodecsEncodedVideoChunk(Init&&); | ||
|
||
WebCodecsEncodedVideoChunkType m_type { WebCodecsEncodedVideoChunkType::Key }; | ||
int64_t m_timestamp { 0 }; | ||
std::optional<uint64_t> m_duration { 0 }; | ||
Vector<uint8_t> m_data; | ||
}; | ||
|
||
} | ||
|
||
#endif // ENABLE(WEB_CODECS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2022 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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. | ||
*/ | ||
|
||
// FIXME: Support Serializable and Transferable. | ||
[ | ||
Conditional=WEB_CODECS, | ||
EnabledBySetting=WebCodecsEnabled, | ||
Exposed=(Window,DedicatedWorker), | ||
InterfaceName=EncodedVideoChunk, | ||
] interface WebCodecsEncodedVideoChunk { | ||
constructor(WebCodecsEncodedVideoChunkInit init); | ||
readonly attribute WebCodecsEncodedVideoChunkType type; | ||
readonly attribute long long timestamp; | ||
readonly attribute unsigned long long? duration; | ||
readonly attribute unsigned long byteLength; | ||
|
||
undefined copyTo([AllowShared] BufferSource destination); | ||
}; | ||
|
||
typedef [EnforceRange] long long WebCodecsEncodedVideoChunkInitTimestamp; | ||
typedef [EnforceRange] unsigned long long WebCodecsEncodedVideoChunkInitDuration; | ||
|
||
[ | ||
Conditional=WEB_CODECS | ||
] dictionary WebCodecsEncodedVideoChunkInit { | ||
required WebCodecsEncodedVideoChunkType type; | ||
WebCodecsEncodedVideoChunkInitTimestamp timestamp; | ||
WebCodecsEncodedVideoChunkInitDuration duration; | ||
required BufferSource data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2022 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if ENABLE(WEB_CODECS) | ||
|
||
namespace WebCore { | ||
|
||
enum class WebCodecsEncodedVideoChunkType { | ||
Key, | ||
Delta | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2022 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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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. | ||
*/ | ||
|
||
[ | ||
Conditional=WEB_CODECS | ||
] enum WebCodecsEncodedVideoChunkType { | ||
"key", | ||
"delta", | ||
}; |
Oops, something went wrong.