FFmpegKit iOS / macOS / tvOS API  4.4
ArchDetect.m
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 Public 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 Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #import <sys/types.h>
21 #import <sys/sysctl.h>
22 #import <mach/machine.h>
23 #import "ArchDetect.h"
24 #import "FFmpegKitConfig.h"
25 #import "FFmpegKit.h"
26 #import "FFprobeKit.h"
27 
28 @implementation ArchDetect
29 
30 + (void)initialize {
31  [FFmpegKit class];
32  [FFmpegKitConfig class];
33  [FFprobeKit class];
34 }
35 
36 + (NSString*)getCpuArch {
37  NSMutableString* cpu = [[NSMutableString alloc] init];
38  size_t size;
39  cpu_type_t type;
40  cpu_subtype_t subtype;
41  size = sizeof(type);
42  sysctlbyname("hw.cputype", &type, &size, nil, 0);
43 
44  size = sizeof(subtype);
45  sysctlbyname("hw.cpusubtype", &subtype, &size, nil, 0);
46 
47  if (type == CPU_TYPE_X86_64) {
48  [cpu appendString:@"x86_64"];
49 
50  } else if (type == CPU_TYPE_X86) {
51  [cpu appendString:@"x86"];
52 
53  switch(subtype) {
54  case CPU_SUBTYPE_X86_64_H:
55  [cpu appendString:@"_64h"];
56  break;
57  case CPU_SUBTYPE_X86_64_ALL:
58  [cpu appendString:@"_64all"];
59  break;
60  case CPU_SUBTYPE_X86_ARCH1:
61  [cpu appendString:@"_arch1"];
62  break;
63  }
64 
65  } else if (type == CPU_TYPE_I386) {
66  [cpu appendString:@"i386"];
67 
68  } else if (type == CPU_TYPE_ARM64) {
69  [cpu appendString:@"arm64"];
70 
71  switch(subtype) {
72  case CPU_SUBTYPE_ARM64_V8:
73  [cpu appendString:@"v8"];
74  break;
75 
76  #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120100
77  case CPU_SUBTYPE_ARM64E:
78  [cpu appendString:@"e"];
79  break;
80  #endif
81 
82  }
83 
84  } else if (type == CPU_TYPE_ARM) {
85  [cpu appendString:@"arm"];
86 
87  switch(subtype) {
88  case CPU_SUBTYPE_ARM_XSCALE:
89  [cpu appendString:@"xscale"];
90  break;
91  case CPU_SUBTYPE_ARM_V4T:
92  [cpu appendString:@"v4t"];
93  break;
94  case CPU_SUBTYPE_ARM_V5TEJ:
95  [cpu appendString:@"v5tej"];
96  break;
97  case CPU_SUBTYPE_ARM_V6:
98  [cpu appendString:@"v6"];
99  break;
100  case CPU_SUBTYPE_ARM_V6M:
101  [cpu appendString:@"v6m"];
102  break;
103  case CPU_SUBTYPE_ARM_V7:
104  [cpu appendString:@"v7"];
105  break;
106  case CPU_SUBTYPE_ARM_V7EM:
107  [cpu appendString:@"v7em"];
108  break;
109  case CPU_SUBTYPE_ARM_V7F:
110  [cpu appendString:@"v7f"];
111  break;
112  case CPU_SUBTYPE_ARM_V7K:
113  [cpu appendString:@"v7k"];
114  break;
115  case CPU_SUBTYPE_ARM_V7M:
116  [cpu appendString:@"v7m"];
117  break;
118  case CPU_SUBTYPE_ARM_V7S:
119  [cpu appendString:@"v7s"];
120  break;
121 #ifndef FFMPEG_KIT_LTS
122  case CPU_SUBTYPE_ARM_V8:
123  [cpu appendString:@"v8"];
124  break;
125 #endif
126  }
127 
128  #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120100
129  } else if (type == CPU_TYPE_ARM64_32) {
130  [cpu appendString:@"arm64_32"];
131 
132  switch(subtype) {
133  case CPU_SUBTYPE_ARM64_32_V8:
134  [cpu appendString:@"v8"];
135  break;
136  }
137  #endif
138 
139  } else {
140  [cpu appendString:[NSString stringWithFormat:@"%d", type]];
141  }
142 
143  return cpu;
144 }
145 
146 + (NSString*)getArch {
147  NSMutableString *arch = [[NSMutableString alloc] init];
148 
149 #ifdef FFMPEG_KIT_ARMV7
150  [arch appendString:@"armv7"];
151 #elif FFMPEG_KIT_ARMV7S
152  [arch appendString:@"armv7s"];
153 #elif FFMPEG_KIT_ARM64
154  [arch appendString:@"arm64"];
155 #elif FFMPEG_KIT_ARM64_MAC_CATALYST
156  [arch appendString:@"arm64_mac_catalyst"];
157 #elif FFMPEG_KIT_ARM64_SIMULATOR
158  [arch appendString:@"arm64_simulator"];
159 #elif FFMPEG_KIT_ARM64E
160  [arch appendString:@"arm64e"];
161 #elif FFMPEG_KIT_I386
162  [arch appendString:@"i386"];
163 #elif FFMPEG_KIT_X86_64
164  [arch appendString:@"x86_64"];
165 #elif FFMPEG_KIT_X86_64_MAC_CATALYST
166  [arch appendString:@"x86_64_mac_catalyst"];
167 #endif
168 
169  return arch;
170 }
171 
172 @end
NSString * getCpuArch()
Definition: ArchDetect.m:36
NSString * getArch()
Definition: ArchDetect.m:146
void initialize()
Definition: ArchDetect.m:30