@@ -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