Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 MuseScore Limited
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include <optional>
26 : #include <vector>
27 :
28 : #include "io/path.h"
29 :
30 : #include "../mediatypes.h"
31 :
32 : namespace muse::media {
33 : static const FFmpegVersion FFMPEG_V9 = 9;
34 : static const FFmpegVersion FFMPEG_V8 = 8;
35 : static const FFmpegVersion FFMPEG_V7 = 7;
36 : static const FFmpegVersion FFMPEG_V6 = 6;
37 : static const FFmpegVersion FFMPEG_V5 = 5;
38 : static const FFmpegVersion FFMPEG_V4 = 4;
39 :
40 : struct FFmpegVersionInfo {
41 : int avFormatVersion = -1;
42 : int avUtilVersion = -1;
43 : int avCodecVersion = -1;
44 : int swScaleVersion = -1;
45 : int swResampleVersion = -1;
46 :
47 72 : bool isValid() const
48 : {
49 72 : return avFormatVersion != -1 && avUtilVersion != -1 && avCodecVersion != -1 && swScaleVersion != -1 && swResampleVersion != -1;
50 : }
51 : };
52 :
53 : static const std::vector<std::pair<int, FFmpegVersionInfo> > FFMPEG_COMPONENTS_VERSIONS = {
54 : // ffmpeg avFormat avUtil avCodec swScale swResample
55 : { FFMPEG_V9, { 63, 61, 63, 10, 7 } },
56 : { FFMPEG_V8, { 62, 60, 62, 9, 6 } },
57 : { FFMPEG_V7, { 61, 59, 61, 8, 5 } },
58 : { FFMPEG_V6, { 60, 58, 60, 7, 4 } },
59 : { FFMPEG_V5, { 59, 57, 59, 6, 4 } },
60 : { FFMPEG_V4, { 58, 56, 58, 5, 3 } },
61 : };
62 :
63 : enum class FFmpegCandidateOrigin {
64 : Automatic,
65 : Configured
66 : };
67 :
68 : struct FFmpegLibPaths {
69 : FFmpegVersion ffmpegVersion = FFMPEG_INVALID_VERSION;
70 : FFmpegCandidateOrigin origin = FFmpegCandidateOrigin::Automatic;
71 : io::path_t searchDir;
72 : io::path_t avUtilPath;
73 : io::path_t avCodecPath;
74 : io::path_t avFormatPath;
75 : io::path_t swScalePath;
76 : io::path_t swResamplePath;
77 : };
78 :
79 : using FFmpegLibPathsList = std::vector<FFmpegLibPaths>;
80 :
81 : io::paths_t defaultSearchPaths();
82 :
83 : FFmpegLibPathsList findLibraryPaths(const io::path_t& ffmpegLibsDir);
84 : FFmpegLibPathsList findLibraryPaths(const io::path_t& ffmpegLibsDir, const io::paths_t& defaultPaths);
85 : std::optional<io::path_t> configuredPathToPersist(const io::path_t& requestedPath, const FFmpegLibPaths& loadedCandidate);
86 : FFmpegVersion versionFromAVFormatPath(const io::path_t& path);
87 : }
|