FFmpegKit iOS / macOS / tvOS API  4.4
Packages.m
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Taner Sener
3  *
4  * This file is part of FFmpegKit.
5  *
6  * FFmpegKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpegKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General License
17  * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #import "config.h"
21 #import "libavutil/ffversion.h"
22 #import "FFmpegKitConfig.h"
23 #import "Packages.h"
24 
25 static NSMutableArray *supportedExternalLibraries;
26 
27 @implementation Packages
28 
29 + (void)initialize {
30  supportedExternalLibraries = [[NSMutableArray alloc] init];
31  [supportedExternalLibraries addObject:@"dav1d"];
32  [supportedExternalLibraries addObject:@"fontconfig"];
33  [supportedExternalLibraries addObject:@"freetype"];
34  [supportedExternalLibraries addObject:@"fribidi"];
35  [supportedExternalLibraries addObject:@"gmp"];
36  [supportedExternalLibraries addObject:@"gnutls"];
37  [supportedExternalLibraries addObject:@"kvazaar"];
38  [supportedExternalLibraries addObject:@"mp3lame"];
39  [supportedExternalLibraries addObject:@"libaom"];
40  [supportedExternalLibraries addObject:@"libass"];
41  [supportedExternalLibraries addObject:@"iconv"];
42  [supportedExternalLibraries addObject:@"libilbc"];
43  [supportedExternalLibraries addObject:@"libtheora"];
44  [supportedExternalLibraries addObject:@"libvidstab"];
45  [supportedExternalLibraries addObject:@"libvorbis"];
46  [supportedExternalLibraries addObject:@"libvpx"];
47  [supportedExternalLibraries addObject:@"libwebp"];
48  [supportedExternalLibraries addObject:@"libxml2"];
49  [supportedExternalLibraries addObject:@"opencore-amr"];
50  [supportedExternalLibraries addObject:@"openh264"];
51  [supportedExternalLibraries addObject:@"opus"];
52  [supportedExternalLibraries addObject:@"rubberband"];
53  [supportedExternalLibraries addObject:@"sdl2"];
54  [supportedExternalLibraries addObject:@"shine"];
55  [supportedExternalLibraries addObject:@"snappy"];
56  [supportedExternalLibraries addObject:@"soxr"];
57  [supportedExternalLibraries addObject:@"speex"];
58  [supportedExternalLibraries addObject:@"tesseract"];
59  [supportedExternalLibraries addObject:@"twolame"];
60  [supportedExternalLibraries addObject:@"x264"];
61  [supportedExternalLibraries addObject:@"x265"];
62  [supportedExternalLibraries addObject:@"xvid"];
63 }
64 
65 + (NSString*)getBuildConf {
66  return [NSString stringWithUTF8String:FFMPEG_CONFIGURATION];
67 }
68 
69 + (NSString*)getPackageName {
70  NSArray *enabledLibraryArray = [Packages getExternalLibraries];
71  Boolean speex = [enabledLibraryArray containsObject:@"speex"];
72  Boolean fribidi = [enabledLibraryArray containsObject:@"fribidi"];
73  Boolean gnutls = [enabledLibraryArray containsObject:@"gnutls"];
74  Boolean xvid = [enabledLibraryArray containsObject:@"xvid"];
75 
76  Boolean min = false;
77  Boolean minGpl = false;
78  Boolean https = false;
79  Boolean httpsGpl = false;
80  Boolean audio = false;
81  Boolean video = false;
82  Boolean full = false;
83  Boolean fullGpl = false;
84 
85  if (speex && fribidi) {
86  if (xvid) {
87  fullGpl = true;
88  } else {
89  full = true;
90  }
91  } else if (speex) {
92  audio = true;
93  } else if (fribidi) {
94  video = true;
95  } else if (xvid) {
96  if (gnutls) {
97  httpsGpl = true;
98  } else {
99  minGpl = true;
100  }
101  } else {
102  if (gnutls) {
103  https = true;
104  } else {
105  min = true;
106  }
107  }
108 
109  if (fullGpl) {
110  if ([enabledLibraryArray containsObject:@"dav1d"] &&
111  [enabledLibraryArray containsObject:@"fontconfig"] &&
112  [enabledLibraryArray containsObject:@"freetype"] &&
113  [enabledLibraryArray containsObject:@"fribidi"] &&
114  [enabledLibraryArray containsObject:@"gmp"] &&
115  [enabledLibraryArray containsObject:@"gnutls"] &&
116  [enabledLibraryArray containsObject:@"kvazaar"] &&
117  [enabledLibraryArray containsObject:@"mp3lame"] &&
118  [enabledLibraryArray containsObject:@"libass"] &&
119  [enabledLibraryArray containsObject:@"iconv"] &&
120  [enabledLibraryArray containsObject:@"libilbc"] &&
121  [enabledLibraryArray containsObject:@"libtheora"] &&
122  [enabledLibraryArray containsObject:@"libvidstab"] &&
123  [enabledLibraryArray containsObject:@"libvorbis"] &&
124  [enabledLibraryArray containsObject:@"libvpx"] &&
125  [enabledLibraryArray containsObject:@"libwebp"] &&
126  [enabledLibraryArray containsObject:@"libxml2"] &&
127  [enabledLibraryArray containsObject:@"opencore-amr"] &&
128  [enabledLibraryArray containsObject:@"opus"] &&
129  [enabledLibraryArray containsObject:@"shine"] &&
130  [enabledLibraryArray containsObject:@"snappy"] &&
131  [enabledLibraryArray containsObject:@"soxr"] &&
132  [enabledLibraryArray containsObject:@"speex"] &&
133  [enabledLibraryArray containsObject:@"twolame"] &&
134  [enabledLibraryArray containsObject:@"x264"] &&
135  [enabledLibraryArray containsObject:@"x265"] &&
136  [enabledLibraryArray containsObject:@"xvid"]) {
137  return @"full-gpl";
138  } else {
139  return @"custom";
140  }
141  }
142 
143  if (full) {
144  if ([enabledLibraryArray containsObject:@"dav1d"] &&
145  [enabledLibraryArray containsObject:@"fontconfig"] &&
146  [enabledLibraryArray containsObject:@"freetype"] &&
147  [enabledLibraryArray containsObject:@"fribidi"] &&
148  [enabledLibraryArray containsObject:@"gmp"] &&
149  [enabledLibraryArray containsObject:@"gnutls"] &&
150  [enabledLibraryArray containsObject:@"kvazaar"] &&
151  [enabledLibraryArray containsObject:@"mp3lame"] &&
152  [enabledLibraryArray containsObject:@"libass"] &&
153  [enabledLibraryArray containsObject:@"iconv"] &&
154  [enabledLibraryArray containsObject:@"libilbc"] &&
155  [enabledLibraryArray containsObject:@"libtheora"] &&
156  [enabledLibraryArray containsObject:@"libvorbis"] &&
157  [enabledLibraryArray containsObject:@"libvpx"] &&
158  [enabledLibraryArray containsObject:@"libwebp"] &&
159  [enabledLibraryArray containsObject:@"libxml2"] &&
160  [enabledLibraryArray containsObject:@"opencore-amr"] &&
161  [enabledLibraryArray containsObject:@"opus"] &&
162  [enabledLibraryArray containsObject:@"shine"] &&
163  [enabledLibraryArray containsObject:@"snappy"] &&
164  [enabledLibraryArray containsObject:@"soxr"] &&
165  [enabledLibraryArray containsObject:@"speex"] &&
166  [enabledLibraryArray containsObject:@"twolame"]) {
167  return @"full";
168  } else {
169  return @"custom";
170  }
171  }
172 
173  if (video) {
174  if ([enabledLibraryArray containsObject:@"dav1d"] &&
175  [enabledLibraryArray containsObject:@"fontconfig"] &&
176  [enabledLibraryArray containsObject:@"freetype"] &&
177  [enabledLibraryArray containsObject:@"fribidi"] &&
178  [enabledLibraryArray containsObject:@"kvazaar"] &&
179  [enabledLibraryArray containsObject:@"libass"] &&
180  [enabledLibraryArray containsObject:@"iconv"] &&
181  [enabledLibraryArray containsObject:@"libtheora"] &&
182  [enabledLibraryArray containsObject:@"libvpx"] &&
183  [enabledLibraryArray containsObject:@"libwebp"] &&
184  [enabledLibraryArray containsObject:@"snappy"]) {
185  return @"video";
186  } else {
187  return @"custom";
188  }
189  }
190 
191  if (audio) {
192  if ([enabledLibraryArray containsObject:@"mp3lame"] &&
193  [enabledLibraryArray containsObject:@"libilbc"] &&
194  [enabledLibraryArray containsObject:@"libvorbis"] &&
195  [enabledLibraryArray containsObject:@"opencore-amr"] &&
196  [enabledLibraryArray containsObject:@"opus"] &&
197  [enabledLibraryArray containsObject:@"shine"] &&
198  [enabledLibraryArray containsObject:@"soxr"] &&
199  [enabledLibraryArray containsObject:@"speex"] &&
200  [enabledLibraryArray containsObject:@"twolame"]) {
201  return @"audio";
202  } else {
203  return @"custom";
204  }
205  }
206 
207  if (httpsGpl) {
208  if ([enabledLibraryArray containsObject:@"gmp"] &&
209  [enabledLibraryArray containsObject:@"gnutls"] &&
210  [enabledLibraryArray containsObject:@"libvidstab"] &&
211  [enabledLibraryArray containsObject:@"x264"] &&
212  [enabledLibraryArray containsObject:@"x265"] &&
213  [enabledLibraryArray containsObject:@"xvid"]) {
214  return @"https-gpl";
215  } else {
216  return @"custom";
217  }
218  }
219 
220  if (https) {
221  if ([enabledLibraryArray containsObject:@"gmp"] &&
222  [enabledLibraryArray containsObject:@"gnutls"]) {
223  return @"https";
224  } else {
225  return @"custom";
226  }
227  }
228 
229  if (minGpl) {
230  if ([enabledLibraryArray containsObject:@"libvidstab"] &&
231  [enabledLibraryArray containsObject:@"x264"] &&
232  [enabledLibraryArray containsObject:@"x265"] &&
233  [enabledLibraryArray containsObject:@"xvid"]) {
234  return @"min-gpl";
235  } else {
236  return @"custom";
237  }
238  }
239 
240  return @"min";
241 }
242 
243 + (NSArray*)getExternalLibraries {
244  NSString *buildConfiguration = [Packages getBuildConf];
245  NSMutableArray *enabledLibraryArray = [[NSMutableArray alloc] init];
246 
247  for (int i=0; i < [supportedExternalLibraries count]; i++) {
248  NSString *supportedExternalLibrary = [supportedExternalLibraries objectAtIndex:i];
249 
250  NSString *libraryName1 = [NSString stringWithFormat:@"enable-%@", supportedExternalLibrary];
251  NSString *libraryName2 = [NSString stringWithFormat:@"enable-lib%@", supportedExternalLibrary];
252 
253  if ([buildConfiguration rangeOfString:libraryName1].location != NSNotFound || [buildConfiguration rangeOfString:libraryName2].location != NSNotFound) {
254  [enabledLibraryArray addObject:supportedExternalLibrary];
255  }
256  }
257 
258  [enabledLibraryArray sortUsingSelector:@selector(compare:)];
259 
260  return enabledLibraryArray;
261 }
262 
263 @end
static NSMutableArray * supportedExternalLibraries
Definition: Packages.m:25
void initialize()
Definition: Packages.m:29
NSString * getPackageName()
Definition: Packages.m:69
NSString * getBuildConf()
Definition: Packages.m:65
NSArray * getExternalLibraries()
Definition: Packages.m:243