RemoteMediaPlayerMIMETypeCache.cpp [plain text]
#include "config.h"
#include "RemoteMediaPlayerMIMETypeCache.h"
#if ENABLE(GPU_PROCESS)
#include "RemoteMediaPlayerManager.h"
#include "RemoteMediaPlayerManagerProxyMessages.h"
#include <wtf/Vector.h>
namespace WebKit {
using namespace WebCore;
RemoteMediaPlayerMIMETypeCache::RemoteMediaPlayerMIMETypeCache(RemoteMediaPlayerManager& manager, MediaPlayerEnums::MediaEngineIdentifier engineIdentifier)
: m_manager(manager)
, m_engineIdentifier(engineIdentifier)
{
}
void RemoteMediaPlayerMIMETypeCache::addSupportedTypes(const Vector<String>& newTypes)
{
if (!m_supportedTypesCache)
m_supportedTypesCache = HashSet<String, ASCIICaseInsensitiveHash> { };
for (auto& type : newTypes)
m_supportedTypesCache->add(type);
}
bool RemoteMediaPlayerMIMETypeCache::isEmpty() const
{
return m_supportedTypesCache && m_supportedTypesCache->isEmpty();
}
HashSet<String, ASCIICaseInsensitiveHash>& RemoteMediaPlayerMIMETypeCache::supportedTypes()
{
if (m_supportedTypesCache)
return *m_supportedTypesCache;
Vector<String> types;
if (m_manager.gpuProcessConnection().connection().sendSync(Messages::RemoteMediaPlayerManagerProxy::GetSupportedTypes(m_engineIdentifier), Messages::RemoteMediaPlayerManagerProxy::GetSupportedTypes::Reply(types), 0))
addSupportedTypes(types);
return *m_supportedTypesCache;
}
MediaPlayerEnums::SupportsType RemoteMediaPlayerMIMETypeCache::supportsTypeAndCodecs(const MediaEngineSupportParameters& parameters)
{
if (parameters.type.raw().isEmpty())
return MediaPlayerEnums::SupportsType::MayBeSupported;
if (m_supportsTypeAndCodecsCache) {
auto it = m_supportsTypeAndCodecsCache->find(parameters.type.raw());
if (it != m_supportsTypeAndCodecsCache->end())
return it->value;
}
if (!m_supportsTypeAndCodecsCache)
m_supportsTypeAndCodecsCache = HashMap<String, MediaPlayerEnums::SupportsType, ASCIICaseInsensitiveHash> { };
MediaPlayerEnums::SupportsType result = MediaPlayerEnums::SupportsType::IsNotSupported;
if (m_manager.gpuProcessConnection().connection().sendSync(Messages::RemoteMediaPlayerManagerProxy::SupportsTypeAndCodecs(m_engineIdentifier, parameters), Messages::RemoteMediaPlayerManagerProxy::SupportsTypeAndCodecs::Reply(result), 0))
m_supportsTypeAndCodecsCache->add(parameters.type.raw(), result);
return result;
}
}
#endif // ENABLE(GPU_PROCESS)