Update ipjsua swift sample app (#3342)
This commit is contained in:
parent
935453830e
commit
0e89bbe0e3
|
@ -35,19 +35,15 @@
|
|||
|
||||
#if (defined(PJ_DARWINOS) && PJ_DARWINOS != 0 && TARGET_OS_IPHONE)
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
# define DEFAULT_WIDTH 352
|
||||
# define DEFAULT_HEIGHT 288
|
||||
#else
|
||||
# define DEFAULT_WIDTH 720
|
||||
# define DEFAULT_HEIGHT 480
|
||||
#endif
|
||||
|
||||
#define DEFAULT_WIDTH 720
|
||||
#define DEFAULT_HEIGHT 480
|
||||
#define DEFAULT_FPS 15
|
||||
#define DEFAULT_AVG_BITRATE 256000
|
||||
#define DEFAULT_MAX_BITRATE 256000
|
||||
#define DEFAULT_AVG_BITRATE 384000
|
||||
#define DEFAULT_MAX_BITRATE 512000
|
||||
|
||||
#define MAX_RX_WIDTH 1200
|
||||
#define MAX_RX_WIDTH 1280
|
||||
#define MAX_RX_HEIGHT 800
|
||||
|
||||
#define SPS_PPS_BUF_SIZE 32
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1420"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "3A6FC61725CBD4540065F472"
|
||||
BuildableName = "ipjsua-swift.app"
|
||||
BlueprintName = "ipjsua-swift"
|
||||
ReferencedContainer = "container:ipjsua-swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
enableGPUValidationMode = "1"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "3A6FC61725CBD4540065F472"
|
||||
BuildableName = "ipjsua-swift.app"
|
||||
BlueprintName = "ipjsua-swift"
|
||||
ReferencedContainer = "container:ipjsua-swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "3A6FC61725CBD4540065F472"
|
||||
BuildableName = "ipjsua-swift.app"
|
||||
BlueprintName = "ipjsua-swift"
|
||||
ReferencedContainer = "container:ipjsua-swift.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
|
@ -19,7 +19,7 @@
|
|||
import SwiftUI
|
||||
|
||||
struct VidView: UIViewRepresentable {
|
||||
@Binding var vidWin: UIView?
|
||||
@Binding var vid_view: UIView?
|
||||
|
||||
func makeUIView(context: Context) -> UIView {
|
||||
let view = UIView();
|
||||
|
@ -28,29 +28,18 @@ struct VidView: UIViewRepresentable {
|
|||
}
|
||||
|
||||
func updateUIView(_ uiView: UIView, context: Context) {
|
||||
if let vid_win = vidWin {
|
||||
if let vid_win = vid_view {
|
||||
/* Add the video window as subview */
|
||||
if (!vid_win.isDescendant(of: uiView)) {
|
||||
uiView.addSubview(vid_win)
|
||||
/* Resize it to fit width */
|
||||
vid_win.bounds = CGRect(x:0, y:0, width:uiView.bounds.size.width,
|
||||
height:(uiView.bounds.size.height *
|
||||
1.0 * uiView.bounds.size.width /
|
||||
vid_win.bounds.size.width));
|
||||
/* Center it horizontally */
|
||||
vid_win.center = CGPoint(x:uiView.bounds.size.width / 2.0,
|
||||
y:vid_win.bounds.size.height / 2.0);
|
||||
uiView.addSubview(vid_win);
|
||||
vid_win.center = uiView.center;
|
||||
vid_win.frame = uiView.bounds;
|
||||
vid_win.contentMode = .scaleAspectFit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PjsipVars: ObservableObject {
|
||||
@Published var calling = false
|
||||
var dest: String = "sip:test@pjsip.org"
|
||||
var call_id: pjsua_call_id = PJSUA_INVALID_ID.rawValue
|
||||
}
|
||||
|
||||
private func call_func(user_data: UnsafeMutableRawPointer?) {
|
||||
let pjsip_vars = Unmanaged<PjsipVars>.fromOpaque(user_data!).takeUnretainedValue()
|
||||
if (!pjsip_vars.calling) {
|
||||
|
@ -81,8 +70,7 @@ private func call_func(user_data: UnsafeMutableRawPointer?) {
|
|||
}
|
||||
|
||||
struct ContentView: View {
|
||||
@StateObject var pjsip_vars = PjsipVars()
|
||||
@EnvironmentObject var vinfo: VidInfo;
|
||||
@EnvironmentObject var pjsip_vars: PjsipVars;
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
|
@ -121,7 +109,7 @@ struct ContentView: View {
|
|||
.padding(.all, 8.0)
|
||||
.background(Color.green);
|
||||
|
||||
VidView(vidWin: $vinfo.vid_win)
|
||||
VidView(vid_view: $pjsip_vars.vid_win)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,14 +22,17 @@
|
|||
|
||||
import SwiftUI
|
||||
|
||||
class VidInfo: ObservableObject {
|
||||
class PjsipVars: ObservableObject {
|
||||
@Published var calling = false
|
||||
var dest: String = "sip:test@sip.pjsip.org"
|
||||
var call_id: pjsua_call_id = PJSUA_INVALID_ID.rawValue
|
||||
/* Video window */
|
||||
@Published var vid_win:UIView? = nil
|
||||
}
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
static let Shared = AppDelegate()
|
||||
var vinfo = VidInfo()
|
||||
var pjsip_vars = PjsipVars()
|
||||
}
|
||||
|
||||
@main
|
||||
|
@ -66,11 +69,11 @@ struct ipjsua_swiftApp: App {
|
|||
&tcp_cfg, &transport_id);
|
||||
|
||||
/* Init account config */
|
||||
let id = strdup("Test<sip:test@pjsip.org>");
|
||||
let id = strdup("Test<sip:test@sip.pjsip.org>");
|
||||
let username = strdup("test");
|
||||
let passwd = strdup("pwd");
|
||||
let realm = strdup("*");
|
||||
let registrar = strdup("sip:pjsip.org");
|
||||
let registrar = strdup("sip:sip.pjsip.org");
|
||||
let proxy = strdup("sip:sip.pjsip.org;transport=tcp");
|
||||
|
||||
var acc_cfg = pjsua_acc_config();
|
||||
|
@ -100,19 +103,22 @@ struct ipjsua_swiftApp: App {
|
|||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
.environmentObject(AppDelegate.Shared.vinfo)
|
||||
.environmentObject(AppDelegate.Shared.pjsip_vars)
|
||||
.preferredColorScheme(.light)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func on_call_state(call_id: pjsua_call_id, e: UnsafeMutablePointer<pjsip_event>?) {
|
||||
private func on_call_state(call_id: pjsua_call_id,
|
||||
e: UnsafeMutablePointer<pjsip_event>?)
|
||||
{
|
||||
var ci = pjsua_call_info();
|
||||
pjsua_call_get_info(call_id, &ci);
|
||||
if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
|
||||
/* UIView update must be done in the main thread */
|
||||
DispatchQueue.main.sync {
|
||||
AppDelegate.Shared.vinfo.vid_win = nil;
|
||||
AppDelegate.Shared.pjsip_vars.vid_win = nil;
|
||||
AppDelegate.Shared.pjsip_vars.calling = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,13 +130,13 @@ private func tupleToArray<Tuple, Value>(tuple: Tuple) -> [Value] {
|
|||
}
|
||||
}
|
||||
|
||||
private func on_call_media_state(call_id: pjsua_call_id) {
|
||||
private func on_call_media_state(call_id: pjsua_call_id)
|
||||
{
|
||||
var ci = pjsua_call_info();
|
||||
pjsua_call_get_info(call_id, &ci);
|
||||
let media: [pjsua_call_media_info] = tupleToArray(tuple: ci.media);
|
||||
|
||||
for mi in 0...ci.media_cnt {
|
||||
let media: [pjsua_call_media_info] = tupleToArray(tuple: ci.media);
|
||||
|
||||
if (media[Int(mi)].status == PJSUA_CALL_MEDIA_ACTIVE ||
|
||||
media[Int(mi)].status == PJSUA_CALL_MEDIA_REMOTE_HOLD)
|
||||
{
|
||||
|
@ -153,7 +159,7 @@ private func on_call_media_state(call_id: pjsua_call_id) {
|
|||
|
||||
/* UIView update must be done in the main thread */
|
||||
DispatchQueue.main.sync {
|
||||
AppDelegate.Shared.vinfo.vid_win = vid_win;
|
||||
AppDelegate.Shared.pjsip_vars.vid_win = vid_win;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue