2
* Copyright (C) 2019 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
27
#include "RemoteMediaPlayerManagerProxy.h"
29
#if ENABLE(GPU_PROCESS)
31
#include "GPUConnectionToWebProcess.h"
33
#include "RemoteMediaPlayerConfiguration.h"
34
#include "RemoteMediaPlayerManagerProxyMessages.h"
35
#include "RemoteMediaPlayerProxy.h"
36
#include "RemoteMediaPlayerProxyConfiguration.h"
37
#include "WebCoreArgumentCoders.h"
38
#include <WebCore/MediaPlayer.h>
39
#include <WebCore/MediaPlayerPrivate.h>
40
#include <wtf/UniqueRef.h>
43
#include <WebCore/AVAssetMIMETypeCache.h>
48
using namespace WebCore;
50
RemoteMediaPlayerManagerProxy::RemoteMediaPlayerManagerProxy(GPUConnectionToWebProcess& connection)
51
: m_gpuConnectionToWebProcess(connection)
52
#if !RELEASE_LOG_DISABLED
53
, m_logIdentifier(WTF::LoggerHelper::uniqueLogIdentifier())
58
RemoteMediaPlayerManagerProxy::~RemoteMediaPlayerManagerProxy()
62
void RemoteMediaPlayerManagerProxy::createMediaPlayer(MediaPlayerPrivateRemoteIdentifier id, MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, RemoteMediaPlayerProxyConfiguration&& proxyConfiguration, CompletionHandler<void(RemoteMediaPlayerConfiguration&)>&& completionHandler)
64
ASSERT(!m_proxies.contains(id));
66
RemoteMediaPlayerConfiguration playerConfiguration;
68
auto proxy = makeUnique<RemoteMediaPlayerProxy>(*this, id, m_gpuConnectionToWebProcess.connection(), engineIdentifier, WTFMove(proxyConfiguration));
69
proxy->getConfiguration(playerConfiguration);
70
m_proxies.add(id, WTFMove(proxy));
72
completionHandler(playerConfiguration);
75
void RemoteMediaPlayerManagerProxy::deleteMediaPlayer(MediaPlayerPrivateRemoteIdentifier id)
77
if (auto proxy = m_proxies.take(id))
81
void RemoteMediaPlayerManagerProxy::getSupportedTypes(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
83
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
85
WTFLogAlways("Failed to find media engine.");
86
completionHandler({ });
90
HashSet<String, ASCIICaseInsensitiveHash> engineTypes;
91
engine->getSupportedTypes(engineTypes);
93
auto result = WTF::map(engineTypes, [] (auto& type) {
97
completionHandler(WTFMove(result));
100
void RemoteMediaPlayerManagerProxy::supportsTypeAndCodecs(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const WebCore::MediaEngineSupportParameters&& parameters, CompletionHandler<void(MediaPlayer::SupportsType)>&& completionHandler)
102
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
104
WTFLogAlways("Failed to find media engine.");
105
completionHandler(MediaPlayer::SupportsType::IsNotSupported);
109
auto result = engine->supportsTypeAndCodecs(parameters);
110
completionHandler(result);
113
void RemoteMediaPlayerManagerProxy::canDecodeExtendedType(WebCore::MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& mimeType, CompletionHandler<void(bool)>&& completionHandler)
115
bool supported = false;
117
switch (engineIdentifier) {
118
case MediaPlayerEnums::MediaEngineIdentifier::AVFoundation:
120
supported = AVAssetMIMETypeCache::singleton().canDecodeType(mimeType) == MediaPlayerEnums::SupportsType::IsSupported;
124
case MediaPlayerEnums::MediaEngineIdentifier::AVFoundationMSE:
125
case MediaPlayerEnums::MediaEngineIdentifier::AVFoundationMediaStream:
126
case MediaPlayerEnums::MediaEngineIdentifier::AVFoundationCF:
127
case MediaPlayerEnums::MediaEngineIdentifier::GStreamer:
128
case MediaPlayerEnums::MediaEngineIdentifier::GStreamerMSE:
129
case MediaPlayerEnums::MediaEngineIdentifier::HolePunch:
130
case MediaPlayerEnums::MediaEngineIdentifier::MediaFoundation:
131
case MediaPlayerEnums::MediaEngineIdentifier::MockMSE:
132
ASSERT_NOT_REACHED();
136
completionHandler(supported);
139
void RemoteMediaPlayerManagerProxy::originsInMediaCache(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& path, CompletionHandler<void(Vector<WebCore::SecurityOriginData>&&)>&& completionHandler)
141
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
143
WTFLogAlways("Failed to find media engine.");
144
completionHandler({ });
148
auto origins = engine->originsInMediaCache(path);
150
Vector<WebCore::SecurityOriginData> result;
151
for (auto& origin : origins)
152
result.append(origin->data());
154
completionHandler(WTFMove(result));
157
void RemoteMediaPlayerManagerProxy::clearMediaCache(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&&path, WallTime modifiedSince)
159
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
161
WTFLogAlways("Failed to find media engine.");
165
engine->clearMediaCache(path, modifiedSince);
168
void RemoteMediaPlayerManagerProxy::clearMediaCacheForOrigins(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& path, Vector<WebCore::SecurityOriginData>&& originData)
170
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
172
WTFLogAlways("Failed to find media engine.");
176
HashSet<RefPtr<SecurityOrigin>> origins;
177
for (auto& data : originData)
178
origins.add(data.securityOrigin());
180
engine->clearMediaCacheForOrigins(path, origins);
183
void RemoteMediaPlayerManagerProxy::supportsKeySystem(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& keySystem, const String&& mimeType, CompletionHandler<void(bool)>&& completionHandler)
185
auto engine = MediaPlayer::mediaEngine(engineIdentifier);
187
WTFLogAlways("Failed to find media engine.");
191
auto result = engine->supportsKeySystem(keySystem, mimeType);
192
completionHandler(result);
195
void RemoteMediaPlayerManagerProxy::didReceivePlayerMessage(IPC::Connection& connection, IPC::Decoder& decoder)
197
if (auto* player = m_proxies.get(makeObjectIdentifier<MediaPlayerPrivateRemoteIdentifierType>(decoder.destinationID())))
198
player->didReceiveMessage(connection, decoder);
201
#if !RELEASE_LOG_DISABLED
202
const Logger& RemoteMediaPlayerManagerProxy::logger() const
204
return m_gpuConnectionToWebProcess.logger();
207
WTFLogChannel& RemoteMediaPlayerManagerProxy::logChannel() const
209
return WebKit2LogMedia;
213
} // namespace WebKit