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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pjsip-apps/src/swig/java/android/app/src/main/jniLibs/

# SWIG CSharp/Xamarin stuff
pjsip-apps/src/swig/csharp/pjsua2xamarin/
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/pjsua2
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/obj
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/*.user

# SWIG Python stuff
pjsip-apps/src/swig/python/build/
Expand Down
74 changes: 47 additions & 27 deletions pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/PjSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@ namespace pjsua2xamarin
{
public class MyAccount : Account
{
~MyAccount()
{
~MyAccount()
{
Debug.WriteLine("*** MyAccount is being deleted");
}
}

override public void onRegState(OnRegStateParam prm)
{
AccountInfo ai = getInfo();
Debug.WriteLine("***" + (ai.regIsActive? "": "Un") +
"Register: code=" + prm.code);
AccountInfo ai = getInfo();
Debug.WriteLine("***" + (ai.regIsActive ? "" : "Un") +
"Register: code=" + prm.code);
}

override public void onIncomingCall(OnIncomingCallParam iprm)
{
Call call = new Call(this, iprm.callId);
CallInfo ci = call.getInfo();
CallOpParam prm = new CallOpParam();

Debug.WriteLine("*** Incoming Call: " + ci.remoteUri + " [" +
ci.stateText + "]");

prm.statusCode = (pjsip_status_code)200;
call.answer(prm);
}
}

Expand All @@ -61,8 +74,8 @@ public class PjSample
public static MyLogWriter writer = new MyLogWriter();
public static MyAccount acc = new MyAccount();

/* Preview of Colorbar */
private static VideoPreview vp = new VideoPreview(2);
/* Preview of default capture video device */
private static VideoPreview vp = new VideoPreview(-1);

public PjSample()
{
Expand All @@ -83,7 +96,13 @@ public void start()
// Init library
EpConfig epConfig = new EpConfig();
epConfig.logConfig.writer = writer;
epConfig.logConfig.decor &= ~(uint)pj_log_decoration.PJ_LOG_HAS_NEWLINE;
//epConfig.logConfig.filename = "PjSample.log";
if (epConfig.logConfig.filename.Length == 0)
{
// Omit newlines for logging to console/debug-output
epConfig.logConfig.decor &=
~(uint)pj_log_decoration.PJ_LOG_HAS_NEWLINE;
}
ep.libInit(epConfig);

// Create transport
Expand Down Expand Up @@ -131,31 +150,32 @@ public void stop()
}

new Thread(() =>
{
try
{
try
{
checkThread("pjsua2.stop.2");

Debug.WriteLine("*** DESTROYING PJSUA2 ***");
ep.libDestroy();
ep.Dispose();
Debug.WriteLine("*** PJSUA2 DESTROYED ***");
}
catch (Exception err)
{
Debug.WriteLine("Exception: " + err.Message);
}
}).Start();
checkThread("pjsua2.stop.2");

Debug.WriteLine("*** DESTROYING PJSUA2 ***");
ep.libDestroy();
ep.Dispose();
Debug.WriteLine("*** PJSUA2 DESTROYED ***");
}
catch (Exception err)
{
Debug.WriteLine("Exception: " + err.Message);
}
}).Start();
}

public void startPreview(IntPtr hwnd)
{
try
{
VideoPreviewOpParam param = new VideoPreviewOpParam();
param.window.handle.setWindow(hwnd.ToInt64());
param.window.handle.window = hwnd;
param.format.init(Convert.ToUInt32(pjmedia_format_id.PJMEDIA_FORMAT_I420), 350, 250, 30);

// Video render operation needs to be invoked from non-main-thread.
// Video render operation needs to be invoked from non-main-thread.
new Thread(() =>
{
try
Expand All @@ -169,7 +189,7 @@ public void startPreview(IntPtr hwnd)
{
Debug.WriteLine("Exception: " + err.Message);
}
}).Start();
}).Start();

}
catch (Exception err)
Expand All @@ -190,7 +210,7 @@ public void updatePreviewWindow(IntPtr hwnd)
checkThread("pjsua2.updatePreviewWindow");

VideoWindowHandle handle = new VideoWindowHandle();
handle.handle.setWindow(hwnd.ToInt64());
handle.handle.window = hwnd;

VideoWindow window = vp.getVideoWindow();
window.setWindow(handle);
Expand Down
Loading