mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-04-29 23:41:19 -06:00
Some checks failed
Build and Release / reuse (push) Has been cancelled
Build and Release / clang-format (push) Has been cancelled
Build and Release / get-info (push) Has been cancelled
Build and Release / windows-sdl (push) Has been cancelled
Build and Release / macos-sdl (push) Has been cancelled
Build and Release / linux-sdl (push) Has been cancelled
Build and Release / linux-sdl-gcc (push) Has been cancelled
Build and Release / pre-release (push) Has been cancelled
* improved path detection * clang is pretty * improved * improved? * finished?
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include <algorithm> // std::equal
|
|
#include <cctype> // std::tolower
|
|
|
|
#include "core/libraries/avplayer/avplayer.h"
|
|
#include "core/libraries/avplayer/avplayer_common.h"
|
|
|
|
namespace Libraries::AvPlayer {
|
|
|
|
static bool iequals(std::string_view l, std::string_view r) {
|
|
return std::ranges::equal(l, r, [](u8 a, u8 b) { return std::tolower(a) == std::tolower(b); });
|
|
}
|
|
|
|
AvPlayerSourceType GetSourceType(std::string_view path) {
|
|
if (path.empty()) {
|
|
return AvPlayerSourceType::Unknown;
|
|
}
|
|
|
|
std::string_view name = path;
|
|
if (path.find("://") != std::string_view::npos) {
|
|
// This path is a URI. Strip HTTP parameters from it.
|
|
// schema://server.domain/path/file.ext/and/beyond?param=value#paragraph ->
|
|
// -> schema://server.domain/path/to/file.ext/and/beyond
|
|
name = path.substr(0, path.find_first_of("?#"));
|
|
if (name.empty()) {
|
|
return AvPlayerSourceType::Unknown;
|
|
}
|
|
}
|
|
|
|
// schema://server.domain/path/to/file.ext/and/beyond -> .ext/and/beyond
|
|
|
|
// Find extension dot
|
|
auto dot_pos = name.rfind('.');
|
|
if (dot_pos == std::string_view::npos) {
|
|
return AvPlayerSourceType::Unknown;
|
|
}
|
|
|
|
// Extract extension (".ext/anything" or ".ext")
|
|
auto ext = name.substr(dot_pos);
|
|
if (ext.empty()) {
|
|
return AvPlayerSourceType::Unknown;
|
|
}
|
|
|
|
// .ext/and/beyond -> .ext
|
|
ext = ext.substr(0, ext.find('/'));
|
|
|
|
if (iequals(ext, ".mp4") || iequals(ext, ".m4v") || iequals(ext, ".m3d") ||
|
|
iequals(ext, ".m4a") || iequals(ext, ".mov")) {
|
|
return AvPlayerSourceType::FileMp4;
|
|
}
|
|
|
|
if (iequals(ext, ".m3u8")) {
|
|
return AvPlayerSourceType::Hls;
|
|
}
|
|
|
|
return AvPlayerSourceType::Unknown;
|
|
}
|
|
|
|
} // namespace Libraries::AvPlayer
|