Skip to content

Commit 162ea57

Browse files
Computed AVF channel layouts
1 parent 9f93fe8 commit 162ea57

File tree

10 files changed

+285
-219
lines changed

10 files changed

+285
-219
lines changed
Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010

1111
# MARK: Constants -------------------------------------------------------------------------------------
1212

13+
# Architectures
14+
export architectures=("x86_64" "arm64")
15+
16+
# Deployment target for Aural Player.
17+
export deploymentTarget="11.0"
18+
19+
# Points to the latest MacOS SDK installed.
20+
export sdk="/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
21+
1322
# FFmpeg release version
1423
export ffmpegVersion="7.0.1"
1524

@@ -56,12 +65,7 @@ function runBuild {
5665

5766
cleanXCFrameworksDir
5867
buildFFmpeg
59-
60-
if [[ "$createFatLibs" == "true" ]]
61-
then
6268
createFatLibs
63-
fi
64-
6569
copyHeaders
6670
}
6771

@@ -72,12 +76,17 @@ function cleanXCFrameworksDir {
7276
fi
7377
}
7478

75-
function buildFFmpeg {
79+
function extractSources {
7680

7781
# Extract source code from archive.
7882
if [ ! -d ${srcDirName} ]; then
7983
tar xjf ${srcArchiveName}
8084
fi
85+
}
86+
87+
function buildFFmpeg {
88+
89+
extractSources
8190

8291
# Run all builds in parallel and wait till they all finish.
8392
for arch in ${architectures[@]}; do
@@ -105,6 +114,27 @@ function buildFFmpegForArch {
105114
fixInstallNames $arch
106115
}
107116

117+
# Determine compiler / linker flags based on architecture.
118+
function setCompilerAndLinkerFlags {
119+
120+
arch=$1
121+
122+
export compiler="/usr/bin/clang"
123+
124+
# Architecture of the host machine running this build.
125+
hostArchitecture=$(uname -m)
126+
127+
if [[ "$arch" != "$hostArchitecture" ]]
128+
then
129+
archInFlags="-arch ${arch} "
130+
export crossCompileOption="--enable-cross-compile"
131+
export archOption="--arch=${arch}"
132+
fi
133+
134+
export extraCompilerFlags="${archInFlags}-mmacosx-version-min=${deploymentTarget} -isysroot ${sdk}"
135+
export extraLinkerFlags=${extraCompilerFlags}
136+
}
137+
108138
function configureFFmpeg {
109139

110140
arch=$1
@@ -229,6 +259,19 @@ function createFatLibs {
229259
cd ..
230260
}
231261

262+
function copyHeaders {
263+
264+
mkdir "headers"
265+
266+
srcBaseDir="src/arm64"
267+
headersBaseDir="headers"
268+
269+
copyHeadersForLib $srcBaseDir $avcodecLibName $headersBaseDir "${avcodecHeaderNames[@]}"
270+
copyHeadersForLib $srcBaseDir $avformatLibName $headersBaseDir "${avformatHeaderNames[@]}"
271+
copyHeadersForLib $srcBaseDir $avutilLibName $headersBaseDir "${avutilHeaderNames[@]}"
272+
copyHeadersForLib $srcBaseDir $swresampleLibName $headersBaseDir "${swresampleHeaderNames[@]}"
273+
}
274+
232275
function copyHeadersForLib {
233276

234277
srcBaseDir=$1
@@ -261,10 +304,26 @@ function createXCFrameworks {
261304
createXCFrameworkForLib ${swresampleLibName} ${swresampleLib}
262305
}
263306

307+
function createXCFrameworkForLib {
308+
309+
libName=$1
310+
lib=$2
311+
312+
xcrun xcodebuild -create-xcframework \
313+
-library "dylibs/${lib}" -headers "headers/${libName}" \
314+
-output "xcframeworks/${libName}.xcframework"
315+
}
316+
264317
function cleanUp {
265318

266319
rm -rf ${srcDirName}
267320
rm -rf src
268321
rm -rf dylibs
269322
rm -rf headers
270323
}
324+
325+
runBuild
326+
createXCFrameworks
327+
cleanUp
328+
329+
echo "\nAll done !\n"

FFmpegBuild/build.sh

Lines changed: 0 additions & 87 deletions
This file was deleted.

FFmpegPlayer.xcodeproj/project.pbxproj

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
3E1B587A2C58198E0097ABBF /* build.sh in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58722C58198E0097ABBF /* build.sh */; };
11-
3E1B587C2C58198E0097ABBF /* common.sh in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58742C58198E0097ABBF /* common.sh */; };
10+
3E1B587C2C58198E0097ABBF /* build-ffmpeg.sh in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58742C58198E0097ABBF /* build-ffmpeg.sh */; };
1211
3E1B58802C58198E0097ABBF /* README.txt in Resources */ = {isa = PBXBuildFile; fileRef = 3E1B58782C58198E0097ABBF /* README.txt */; };
1312
3E1B58842C583F210097ABBF /* FFmpegChannelLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E1B58832C583F210097ABBF /* FFmpegChannelLayout.swift */; };
1413
3E7B652D291199B600FDB51F /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E7B6481291199B600FDB51F /* Constants.swift */; };
@@ -60,6 +59,8 @@
6059
3E7B659829119ADA00FDB51F /* libavutil.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3E7B658A291199C700FDB51F /* libavutil.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6160
3E7B659929119ADB00FDB51F /* libswresample.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E7B658C291199C700FDB51F /* libswresample.xcframework */; };
6261
3E7B659A29119ADB00FDB51F /* libswresample.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3E7B658C291199C700FDB51F /* libswresample.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
62+
3E7F6E022C58FCE30085EDF2 /* AVChannel+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E7F6E012C58FCE30085EDF2 /* AVChannel+Extensions.swift */; };
63+
3EF020442C595EBA005A841B /* AVChannelLayout+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EF020432C595EBA005A841B /* AVChannelLayout+Extensions.swift */; };
6364
/* End PBXBuildFile section */
6465

6566
/* Begin PBXCopyFilesBuildPhase section */
@@ -80,8 +81,7 @@
8081
/* End PBXCopyFilesBuildPhase section */
8182

8283
/* Begin PBXFileReference section */
83-
3E1B58722C58198E0097ABBF /* build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build.sh; sourceTree = "<group>"; };
84-
3E1B58742C58198E0097ABBF /* common.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = common.sh; sourceTree = "<group>"; };
84+
3E1B58742C58198E0097ABBF /* build-ffmpeg.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "build-ffmpeg.sh"; sourceTree = "<group>"; };
8585
3E1B58782C58198E0097ABBF /* README.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.txt; sourceTree = "<group>"; };
8686
3E1B58832C583F210097ABBF /* FFmpegChannelLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFmpegChannelLayout.swift; sourceTree = "<group>"; };
8787
3E7B64702911993300FDB51F /* FFmpegPlayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FFmpegPlayer.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -133,6 +133,8 @@
133133
3E7B658A291199C700FDB51F /* libavutil.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = libavutil.xcframework; sourceTree = "<group>"; };
134134
3E7B658B291199C700FDB51F /* libavcodec.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = libavcodec.xcframework; sourceTree = "<group>"; };
135135
3E7B658C291199C700FDB51F /* libswresample.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; path = libswresample.xcframework; sourceTree = "<group>"; };
136+
3E7F6E012C58FCE30085EDF2 /* AVChannel+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVChannel+Extensions.swift"; sourceTree = "<group>"; };
137+
3EF020432C595EBA005A841B /* AVChannelLayout+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVChannelLayout+Extensions.swift"; sourceTree = "<group>"; };
136138
3EF9C61629119E3B002DEC4B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
137139
3EF9C6182911A1EB002DEC4B /* FFmpegPlayer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FFmpegPlayer.entitlements; sourceTree = "<group>"; };
138140
/* End PBXFileReference section */
@@ -155,8 +157,7 @@
155157
3E1B58792C58198E0097ABBF /* FFmpegBuild */ = {
156158
isa = PBXGroup;
157159
children = (
158-
3E1B58722C58198E0097ABBF /* build.sh */,
159-
3E1B58742C58198E0097ABBF /* common.sh */,
160+
3E1B58742C58198E0097ABBF /* build-ffmpeg.sh */,
160161
3E1B58782C58198E0097ABBF /* README.txt */,
161162
);
162163
path = FFmpegBuild;
@@ -214,6 +215,7 @@
214215
children = (
215216
3E7B6498291199B600FDB51F /* ffmpeg.h */,
216217
3E7B648A291199B600FDB51F /* Wrappers */,
218+
3EF020422C595EA0005A841B /* Support */,
217219
3E7B6499291199B600FDB51F /* Utils */,
218220
);
219221
path = FFmpeg;
@@ -325,6 +327,15 @@
325327
path = Frameworks;
326328
sourceTree = "<group>";
327329
};
330+
3EF020422C595EA0005A841B /* Support */ = {
331+
isa = PBXGroup;
332+
children = (
333+
3E7F6E012C58FCE30085EDF2 /* AVChannel+Extensions.swift */,
334+
3EF020432C595EBA005A841B /* AVChannelLayout+Extensions.swift */,
335+
);
336+
path = Support;
337+
sourceTree = "<group>";
338+
};
328339
/* End PBXGroup section */
329340

330341
/* Begin PBXNativeTarget section */
@@ -384,10 +395,9 @@
384395
isa = PBXResourcesBuildPhase;
385396
buildActionMask = 2147483647;
386397
files = (
387-
3E1B587C2C58198E0097ABBF /* common.sh in Resources */,
398+
3E1B587C2C58198E0097ABBF /* build-ffmpeg.sh in Resources */,
388399
3E1B58802C58198E0097ABBF /* README.txt in Resources */,
389400
3E7B6585291199BF00FDB51F /* Assets.xcassets in Resources */,
390-
3E1B587A2C58198E0097ABBF /* build.sh in Resources */,
391401
3E7B6531291199B600FDB51F /* MainMenu.xib in Resources */,
392402
);
393403
runOnlyForDeploymentPostprocessing = 0;
@@ -416,8 +426,10 @@
416426
3E7B6549291199B600FDB51F /* UtilsExtensions.swift in Sources */,
417427
3E7B6554291199B600FDB51F /* AVFUtils.swift in Sources */,
418428
3E7B6537291199B600FDB51F /* FFmpegSampleFormat.swift in Sources */,
429+
3E7F6E022C58FCE30085EDF2 /* AVChannel+Extensions.swift in Sources */,
419430
3E7B6552291199B600FDB51F /* TrackInfo.swift in Sources */,
420431
3E7B654C291199B600FDB51F /* AtomicCounter.swift in Sources */,
432+
3EF020442C595EBA005A841B /* AVChannelLayout+Extensions.swift in Sources */,
421433
3E7B6530291199B600FDB51F /* PlayerViewController.swift in Sources */,
422434
3E7B653D291199B600FDB51F /* FFmpegFormatContext.swift in Sources */,
423435
3E7B6539291199B600FDB51F /* FFmpegImageStream.swift in Sources */,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// AVChannel+Extensions.swift
3+
// FFmpegPlayer
4+
//
5+
// Created by Kartik Venugopal on 30.07.24.
6+
//
7+
8+
import AVFoundation
9+
10+
extension AVChannel: Hashable {
11+
12+
public func hash(into hasher: inout Hasher) {
13+
hasher.combine(self.rawValue)
14+
}
15+
}
16+
17+
extension AVChannel {
18+
19+
var avfChannel: AudioChannelBitmap? {
20+
Self.channelMapping[self]
21+
}
22+
23+
private static let channelMapping: [AVChannel: AudioChannelBitmap] = [
24+
25+
AV_CHAN_FRONT_LEFT: .bit_Left,
26+
AV_CHAN_FRONT_RIGHT: .bit_Right,
27+
AV_CHAN_FRONT_CENTER: .bit_Center,
28+
AV_CHAN_LOW_FREQUENCY: .bit_LFEScreen,
29+
AV_CHAN_BACK_LEFT: .bit_LeftSurround,
30+
AV_CHAN_BACK_RIGHT: .bit_RightSurround,
31+
AV_CHAN_FRONT_LEFT_OF_CENTER: .bit_LeftCenter,
32+
AV_CHAN_FRONT_RIGHT_OF_CENTER: .bit_RightCenter,
33+
AV_CHAN_BACK_CENTER: .bit_CenterSurround,
34+
AV_CHAN_SIDE_LEFT: .bit_LeftSurround,
35+
AV_CHAN_SIDE_RIGHT: .bit_RightSurround,
36+
AV_CHAN_TOP_CENTER: .bit_CenterTopFront,
37+
AV_CHAN_TOP_FRONT_LEFT: .bit_LeftTopFront,
38+
AV_CHAN_TOP_FRONT_CENTER: .bit_CenterTopFront,
39+
AV_CHAN_TOP_FRONT_RIGHT: .bit_RightTopFront,
40+
AV_CHAN_TOP_BACK_LEFT: .bit_TopBackLeft,
41+
AV_CHAN_TOP_BACK_CENTER: .bit_TopBackCenter,
42+
AV_CHAN_TOP_BACK_RIGHT: .bit_TopBackRight,
43+
AV_CHAN_STEREO_LEFT: .bit_Left,
44+
AV_CHAN_STEREO_RIGHT: .bit_Right,
45+
AV_CHAN_WIDE_LEFT: .bit_Left,
46+
AV_CHAN_WIDE_RIGHT: .bit_Right,
47+
AV_CHAN_SURROUND_DIRECT_LEFT: .bit_LeftSurroundDirect,
48+
AV_CHAN_SURROUND_DIRECT_RIGHT: .bit_RightSurroundDirect,
49+
AV_CHAN_LOW_FREQUENCY_2: .bit_LFEScreen,
50+
AV_CHAN_TOP_SIDE_LEFT: .bit_LeftTopMiddle,
51+
AV_CHAN_TOP_SIDE_RIGHT: .bit_RightTopMiddle,
52+
AV_CHAN_BOTTOM_FRONT_CENTER: .bit_Center,
53+
AV_CHAN_BOTTOM_FRONT_LEFT: .bit_Left,
54+
AV_CHAN_BOTTOM_FRONT_RIGHT: .bit_Right
55+
]
56+
}

0 commit comments

Comments
 (0)