~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2019 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "RemoteMediaPlayerManagerProxy.h"
 
28
 
 
29
#if ENABLE(GPU_PROCESS)
 
30
 
 
31
#include "GPUConnectionToWebProcess.h"
 
32
#include "Logging.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>
 
41
 
 
42
#if PLATFORM(COCOA)
 
43
#include <WebCore/AVAssetMIMETypeCache.h>
 
44
#endif
 
45
 
 
46
namespace WebKit {
 
47
 
 
48
using namespace WebCore;
 
49
 
 
50
RemoteMediaPlayerManagerProxy::RemoteMediaPlayerManagerProxy(GPUConnectionToWebProcess& connection)
 
51
    : m_gpuConnectionToWebProcess(connection)
 
52
#if !RELEASE_LOG_DISABLED
 
53
    , m_logIdentifier(WTF::LoggerHelper::uniqueLogIdentifier())
 
54
#endif
 
55
{
 
56
}
 
57
 
 
58
RemoteMediaPlayerManagerProxy::~RemoteMediaPlayerManagerProxy()
 
59
{
 
60
}
 
61
 
 
62
void RemoteMediaPlayerManagerProxy::createMediaPlayer(MediaPlayerPrivateRemoteIdentifier id, MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, RemoteMediaPlayerProxyConfiguration&& proxyConfiguration, CompletionHandler<void(RemoteMediaPlayerConfiguration&)>&& completionHandler)
 
63
{
 
64
    ASSERT(!m_proxies.contains(id));
 
65
 
 
66
    RemoteMediaPlayerConfiguration playerConfiguration;
 
67
 
 
68
    auto proxy = makeUnique<RemoteMediaPlayerProxy>(*this, id, m_gpuConnectionToWebProcess.connection(), engineIdentifier, WTFMove(proxyConfiguration));
 
69
    proxy->getConfiguration(playerConfiguration);
 
70
    m_proxies.add(id, WTFMove(proxy));
 
71
 
 
72
    completionHandler(playerConfiguration);
 
73
}
 
74
 
 
75
void RemoteMediaPlayerManagerProxy::deleteMediaPlayer(MediaPlayerPrivateRemoteIdentifier id)
 
76
{
 
77
    if (auto proxy = m_proxies.take(id))
 
78
        proxy->invalidate();
 
79
}
 
80
 
 
81
void RemoteMediaPlayerManagerProxy::getSupportedTypes(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
 
82
{
 
83
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
84
    if (!engine) {
 
85
        WTFLogAlways("Failed to find media engine.");
 
86
        completionHandler({ });
 
87
        return;
 
88
    }
 
89
 
 
90
    HashSet<String, ASCIICaseInsensitiveHash> engineTypes;
 
91
    engine->getSupportedTypes(engineTypes);
 
92
 
 
93
    auto result = WTF::map(engineTypes, [] (auto& type) {
 
94
        return type;
 
95
    });
 
96
 
 
97
    completionHandler(WTFMove(result));
 
98
}
 
99
 
 
100
void RemoteMediaPlayerManagerProxy::supportsTypeAndCodecs(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const WebCore::MediaEngineSupportParameters&& parameters, CompletionHandler<void(MediaPlayer::SupportsType)>&& completionHandler)
 
101
{
 
102
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
103
    if (!engine) {
 
104
        WTFLogAlways("Failed to find media engine.");
 
105
        completionHandler(MediaPlayer::SupportsType::IsNotSupported);
 
106
        return;
 
107
    }
 
108
 
 
109
    auto result = engine->supportsTypeAndCodecs(parameters);
 
110
    completionHandler(result);
 
111
}
 
112
 
 
113
void RemoteMediaPlayerManagerProxy::canDecodeExtendedType(WebCore::MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& mimeType, CompletionHandler<void(bool)>&& completionHandler)
 
114
{
 
115
    bool supported = false;
 
116
 
 
117
    switch (engineIdentifier) {
 
118
    case MediaPlayerEnums::MediaEngineIdentifier::AVFoundation:
 
119
#if PLATFORM(COCOA)
 
120
        supported = AVAssetMIMETypeCache::singleton().canDecodeType(mimeType) == MediaPlayerEnums::SupportsType::IsSupported;
 
121
        break;
 
122
#endif
 
123
 
 
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();
 
133
        break;
 
134
    }
 
135
 
 
136
    completionHandler(supported);
 
137
}
 
138
 
 
139
void RemoteMediaPlayerManagerProxy::originsInMediaCache(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& path, CompletionHandler<void(Vector<WebCore::SecurityOriginData>&&)>&& completionHandler)
 
140
{
 
141
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
142
    if (!engine) {
 
143
        WTFLogAlways("Failed to find media engine.");
 
144
        completionHandler({ });
 
145
        return;
 
146
    }
 
147
 
 
148
    auto origins = engine->originsInMediaCache(path);
 
149
 
 
150
    Vector<WebCore::SecurityOriginData> result;
 
151
    for (auto& origin : origins)
 
152
        result.append(origin->data());
 
153
 
 
154
    completionHandler(WTFMove(result));
 
155
}
 
156
 
 
157
void RemoteMediaPlayerManagerProxy::clearMediaCache(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&&path, WallTime modifiedSince)
 
158
{
 
159
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
160
    if (!engine) {
 
161
        WTFLogAlways("Failed to find media engine.");
 
162
        return;
 
163
    }
 
164
 
 
165
    engine->clearMediaCache(path, modifiedSince);
 
166
}
 
167
 
 
168
void RemoteMediaPlayerManagerProxy::clearMediaCacheForOrigins(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& path, Vector<WebCore::SecurityOriginData>&& originData)
 
169
{
 
170
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
171
    if (!engine) {
 
172
        WTFLogAlways("Failed to find media engine.");
 
173
        return;
 
174
    }
 
175
 
 
176
    HashSet<RefPtr<SecurityOrigin>> origins;
 
177
    for (auto& data : originData)
 
178
        origins.add(data.securityOrigin());
 
179
 
 
180
    engine->clearMediaCacheForOrigins(path, origins);
 
181
}
 
182
 
 
183
void RemoteMediaPlayerManagerProxy::supportsKeySystem(MediaPlayerEnums::MediaEngineIdentifier engineIdentifier, const String&& keySystem, const String&& mimeType, CompletionHandler<void(bool)>&& completionHandler)
 
184
{
 
185
    auto engine = MediaPlayer::mediaEngine(engineIdentifier);
 
186
    if (!engine) {
 
187
        WTFLogAlways("Failed to find media engine.");
 
188
        return;
 
189
    }
 
190
 
 
191
    auto result = engine->supportsKeySystem(keySystem, mimeType);
 
192
    completionHandler(result);
 
193
}
 
194
 
 
195
void RemoteMediaPlayerManagerProxy::didReceivePlayerMessage(IPC::Connection& connection, IPC::Decoder& decoder)
 
196
{
 
197
    if (auto* player = m_proxies.get(makeObjectIdentifier<MediaPlayerPrivateRemoteIdentifierType>(decoder.destinationID())))
 
198
        player->didReceiveMessage(connection, decoder);
 
199
}
 
200
 
 
201
#if !RELEASE_LOG_DISABLED
 
202
const Logger& RemoteMediaPlayerManagerProxy::logger() const
 
203
{
 
204
    return m_gpuConnectionToWebProcess.logger();
 
205
}
 
206
 
 
207
WTFLogChannel& RemoteMediaPlayerManagerProxy::logChannel() const
 
208
{
 
209
    return WebKit2LogMedia;
 
210
}
 
211
#endif
 
212
 
 
213
} // namespace WebKit
 
214
 
 
215
#endif