Skip to content

Commit 4de1bb8

Browse files
authored
Various fixes/updates in pjsua2 C# sample app SimplePjsua2CS (#4510)
- Fix compile error due to removal of VideoPreviewOpParam.window.handle.setWindow() in #4273. - Fix truncated captured video by matching video renderer's format size to the video renderer size. - Minor updates such as: use default video capture device (was colorbar/2), optional logging to file, add incoming call handling, indentations. - Update gitignore for intermediate files of this project.
1 parent ce81bb6 commit 4de1bb8

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pjsip-apps/src/swig/java/android/app/src/main/jniLibs/
5555

5656
# SWIG CSharp/Xamarin stuff
5757
pjsip-apps/src/swig/csharp/pjsua2xamarin/
58+
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/pjsua2
59+
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/obj
60+
pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/*.user
5861

5962
# SWIG Python stuff
6063
pjsip-apps/src/swig/python/build/

pjsip-apps/src/swig/csharp/sample/SimplePjsua2CS/PjSample.cs

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,29 @@ namespace pjsua2xamarin
2525
{
2626
public class MyAccount : Account
2727
{
28-
~MyAccount()
29-
{
28+
~MyAccount()
29+
{
3030
Debug.WriteLine("*** MyAccount is being deleted");
31-
}
31+
}
3232

3333
override public void onRegState(OnRegStateParam prm)
3434
{
35-
AccountInfo ai = getInfo();
36-
Debug.WriteLine("***" + (ai.regIsActive? "": "Un") +
37-
"Register: code=" + prm.code);
35+
AccountInfo ai = getInfo();
36+
Debug.WriteLine("***" + (ai.regIsActive ? "" : "Un") +
37+
"Register: code=" + prm.code);
38+
}
39+
40+
override public void onIncomingCall(OnIncomingCallParam iprm)
41+
{
42+
Call call = new Call(this, iprm.callId);
43+
CallInfo ci = call.getInfo();
44+
CallOpParam prm = new CallOpParam();
45+
46+
Debug.WriteLine("*** Incoming Call: " + ci.remoteUri + " [" +
47+
ci.stateText + "]");
48+
49+
prm.statusCode = (pjsip_status_code)200;
50+
call.answer(prm);
3851
}
3952
}
4053

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

64-
/* Preview of Colorbar */
65-
private static VideoPreview vp = new VideoPreview(2);
77+
/* Preview of default capture video device */
78+
private static VideoPreview vp = new VideoPreview(-1);
6679

6780
public PjSample()
6881
{
@@ -83,7 +96,13 @@ public void start()
8396
// Init library
8497
EpConfig epConfig = new EpConfig();
8598
epConfig.logConfig.writer = writer;
86-
epConfig.logConfig.decor &= ~(uint)pj_log_decoration.PJ_LOG_HAS_NEWLINE;
99+
//epConfig.logConfig.filename = "PjSample.log";
100+
if (epConfig.logConfig.filename.Length == 0)
101+
{
102+
// Omit newlines for logging to console/debug-output
103+
epConfig.logConfig.decor &=
104+
~(uint)pj_log_decoration.PJ_LOG_HAS_NEWLINE;
105+
}
87106
ep.libInit(epConfig);
88107

89108
// Create transport
@@ -131,31 +150,32 @@ public void stop()
131150
}
132151

133152
new Thread(() =>
153+
{
154+
try
134155
{
135-
try
136-
{
137-
checkThread("pjsua2.stop.2");
138-
139-
Debug.WriteLine("*** DESTROYING PJSUA2 ***");
140-
ep.libDestroy();
141-
ep.Dispose();
142-
Debug.WriteLine("*** PJSUA2 DESTROYED ***");
143-
}
144-
catch (Exception err)
145-
{
146-
Debug.WriteLine("Exception: " + err.Message);
147-
}
148-
}).Start();
156+
checkThread("pjsua2.stop.2");
157+
158+
Debug.WriteLine("*** DESTROYING PJSUA2 ***");
159+
ep.libDestroy();
160+
ep.Dispose();
161+
Debug.WriteLine("*** PJSUA2 DESTROYED ***");
162+
}
163+
catch (Exception err)
164+
{
165+
Debug.WriteLine("Exception: " + err.Message);
166+
}
167+
}).Start();
149168
}
150169

151170
public void startPreview(IntPtr hwnd)
152171
{
153172
try
154173
{
155174
VideoPreviewOpParam param = new VideoPreviewOpParam();
156-
param.window.handle.setWindow(hwnd.ToInt64());
175+
param.window.handle.window = hwnd;
176+
param.format.init(Convert.ToUInt32(pjmedia_format_id.PJMEDIA_FORMAT_I420), 350, 250, 30);
157177

158-
// Video render operation needs to be invoked from non-main-thread.
178+
// Video render operation needs to be invoked from non-main-thread.
159179
new Thread(() =>
160180
{
161181
try
@@ -169,7 +189,7 @@ public void startPreview(IntPtr hwnd)
169189
{
170190
Debug.WriteLine("Exception: " + err.Message);
171191
}
172-
}).Start();
192+
}).Start();
173193

174194
}
175195
catch (Exception err)
@@ -190,7 +210,7 @@ public void updatePreviewWindow(IntPtr hwnd)
190210
checkThread("pjsua2.updatePreviewWindow");
191211

192212
VideoWindowHandle handle = new VideoWindowHandle();
193-
handle.handle.setWindow(hwnd.ToInt64());
213+
handle.handle.window = hwnd;
194214

195215
VideoWindow window = vp.getVideoWindow();
196216
window.setWindow(handle);

0 commit comments

Comments
 (0)