haikuwebkit/Source/WTF/wtf/Algorithms.h

59 lines
2.0 KiB
C
Raw Permalink Normal View History

/*
* Copyright (C) 2017 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
namespace WTF {
template<typename ContainerType, typename ForEachFunction>
MediaPlayer should have mediaPlayerWaitingForKeyChanged() / bool waitingForKey() accessor https://bugs.webkit.org/show_bug.cgi?id=189951 Reviewed by Eric Carlson. Source/WebCore: In order to implement the "Resume Playback" section of EME, part 4, we need to be able to query whether the MediaPlayer is still waiting for a key after attemptToDecrypt() has been called. Currently this involves no behavioral changes, as all modern EME ports will still just notify the media element that they no longer need keys after one has been added, but future ports may be able to wait for multiple keys before reporting that it is no longer waiting for keys. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerWaitingForKeyChanged): (WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary): (WebCore::HTMLMediaElement::mediaPlayerWaitingForKey): Deleted. * html/HTMLMediaElement.h: * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::waitingForKeyChanged): (WebCore::MediaPlayer::waitingForKey const): (WebCore::MediaPlayer::waitingForKey): Deleted. * platform/graphics/MediaPlayer.h: (WebCore::MediaPlayerClient::mediaPlayerWaitingForKeyChanged): (WebCore::MediaPlayerClient::mediaPlayerWaitingForKey): Deleted. * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::waitingForKey const): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource): (WebCore::MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::attemptToDecryptWithInstance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKey const): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKeyChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::initializationDataEncountered): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID): (WebCore::SourceBufferPrivateAVFObjC::attemptToDecrypt): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::reportWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::setWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::waitingForKey const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (webkitMediaCommonEncryptionDecryptSinkEventHandler): Source/WTF: Templated functions should take r-value references, as they have perfect type deduction for all parameter types; references, l-value references, and r-value references in template function parameters have special type deduction semantics. See: <https://en.cppreference.com/w/cpp/language/reference#Forwarding_references> Previously, const reference parameters would be copied when passed into anyOf(), and containers of Ref<> would generate compile errors when passed into anyOf, as they cannot be copied. Now, with r-value reference types in template parameters, a const reference is mapped to a const reference, a non-const reference is mapped to a non-const reference, and a r-value reference is mapped to an r-value reference. * wtf/Algorithms.h: (WTF::forEach): (WTF::anyOf): (WTF::allOf): Canonical link: https://commits.webkit.org/205011@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236572 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-27 21:41:22 +00:00
void forEach(ContainerType&& container, ForEachFunction forEachFunction)
{
for (auto& value : container)
forEachFunction(value);
}
template<typename ContainerType, typename AnyOfFunction>
MediaPlayer should have mediaPlayerWaitingForKeyChanged() / bool waitingForKey() accessor https://bugs.webkit.org/show_bug.cgi?id=189951 Reviewed by Eric Carlson. Source/WebCore: In order to implement the "Resume Playback" section of EME, part 4, we need to be able to query whether the MediaPlayer is still waiting for a key after attemptToDecrypt() has been called. Currently this involves no behavioral changes, as all modern EME ports will still just notify the media element that they no longer need keys after one has been added, but future ports may be able to wait for multiple keys before reporting that it is no longer waiting for keys. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerWaitingForKeyChanged): (WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary): (WebCore::HTMLMediaElement::mediaPlayerWaitingForKey): Deleted. * html/HTMLMediaElement.h: * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::waitingForKeyChanged): (WebCore::MediaPlayer::waitingForKey const): (WebCore::MediaPlayer::waitingForKey): Deleted. * platform/graphics/MediaPlayer.h: (WebCore::MediaPlayerClient::mediaPlayerWaitingForKeyChanged): (WebCore::MediaPlayerClient::mediaPlayerWaitingForKey): Deleted. * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::waitingForKey const): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource): (WebCore::MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::attemptToDecryptWithInstance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKey const): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKeyChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::initializationDataEncountered): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID): (WebCore::SourceBufferPrivateAVFObjC::attemptToDecrypt): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::reportWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::setWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::waitingForKey const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (webkitMediaCommonEncryptionDecryptSinkEventHandler): Source/WTF: Templated functions should take r-value references, as they have perfect type deduction for all parameter types; references, l-value references, and r-value references in template function parameters have special type deduction semantics. See: <https://en.cppreference.com/w/cpp/language/reference#Forwarding_references> Previously, const reference parameters would be copied when passed into anyOf(), and containers of Ref<> would generate compile errors when passed into anyOf, as they cannot be copied. Now, with r-value reference types in template parameters, a const reference is mapped to a const reference, a non-const reference is mapped to a non-const reference, and a r-value reference is mapped to an r-value reference. * wtf/Algorithms.h: (WTF::forEach): (WTF::anyOf): (WTF::allOf): Canonical link: https://commits.webkit.org/205011@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236572 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-27 21:41:22 +00:00
bool anyOf(ContainerType&& container, AnyOfFunction anyOfFunction)
{
for (auto& value : container) {
if (anyOfFunction(value))
return true;
}
return false;
}
template<typename ContainerType, typename AllOfFunction>
MediaPlayer should have mediaPlayerWaitingForKeyChanged() / bool waitingForKey() accessor https://bugs.webkit.org/show_bug.cgi?id=189951 Reviewed by Eric Carlson. Source/WebCore: In order to implement the "Resume Playback" section of EME, part 4, we need to be able to query whether the MediaPlayer is still waiting for a key after attemptToDecrypt() has been called. Currently this involves no behavioral changes, as all modern EME ports will still just notify the media element that they no longer need keys after one has been added, but future ports may be able to wait for multiple keys before reporting that it is no longer waiting for keys. * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::mediaPlayerWaitingForKeyChanged): (WebCore::HTMLMediaElement::attemptToResumePlaybackIfNecessary): (WebCore::HTMLMediaElement::mediaPlayerWaitingForKey): Deleted. * html/HTMLMediaElement.h: * platform/graphics/MediaPlayer.cpp: (WebCore::MediaPlayer::waitingForKeyChanged): (WebCore::MediaPlayer::waitingForKey const): (WebCore::MediaPlayer::waitingForKey): Deleted. * platform/graphics/MediaPlayer.h: (WebCore::MediaPlayerClient::mediaPlayerWaitingForKeyChanged): (WebCore::MediaPlayerClient::mediaPlayerWaitingForKey): Deleted. * platform/graphics/MediaPlayerPrivate.h: (WebCore::MediaPlayerPrivateInterface::waitingForKey const): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (WebCore::MediaPlayerPrivateAVFoundationObjC::shouldWaitForLoadingOfResource): (WebCore::MediaPlayerPrivateAVFoundationObjC::attemptToDecryptWithInstance): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h: * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::attemptToDecryptWithInstance): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKey const): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::waitingForKeyChanged): (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::initializationDataEncountered): * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h: * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm: (WebCore::SourceBufferPrivateAVFObjC::didProvideContentKeyRequestInitializationDataForTrackID): (WebCore::SourceBufferPrivateAVFObjC::attemptToDecrypt): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::handleMessage): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: (WebCore::MediaPlayerPrivateGStreamerBase::reportWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::setWaitingForKey): (WebCore::MediaPlayerPrivateGStreamerBase::waitingForKey const): * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: * platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp: (webkitMediaCommonEncryptionDecryptSinkEventHandler): Source/WTF: Templated functions should take r-value references, as they have perfect type deduction for all parameter types; references, l-value references, and r-value references in template function parameters have special type deduction semantics. See: <https://en.cppreference.com/w/cpp/language/reference#Forwarding_references> Previously, const reference parameters would be copied when passed into anyOf(), and containers of Ref<> would generate compile errors when passed into anyOf, as they cannot be copied. Now, with r-value reference types in template parameters, a const reference is mapped to a const reference, a non-const reference is mapped to a non-const reference, and a r-value reference is mapped to an r-value reference. * wtf/Algorithms.h: (WTF::forEach): (WTF::anyOf): (WTF::allOf): Canonical link: https://commits.webkit.org/205011@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236572 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-09-27 21:41:22 +00:00
bool allOf(ContainerType&& container, AllOfFunction allOfFunction)
{
for (auto& value : container) {
if (!allOfFunction(value))
return false;
}
return true;
}
}