Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions pjmedia/src/pjmedia-codec/vid_toolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
28 changes: 8 additions & 20 deletions pjsip-apps/src/pjsua/ios-swift/ipjsua-swift/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:[email protected]"
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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions pjsip-apps/src/pjsua/ios-swift/ipjsua-swift/ipjsua_swiftApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

import SwiftUI

class VidInfo: ObservableObject {
class PjsipVars: ObservableObject {
@Published var calling = false
var dest: String = "sip:[email protected]"
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
Expand Down Expand Up @@ -66,11 +69,11 @@ struct ipjsua_swiftApp: App {
&tcp_cfg, &transport_id);

/* Init account config */
let id = strdup("Test<sip:[email protected]>");
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();
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down