pjsua.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. import py_pjsua
  2. status = py_pjsua.create()
  3. print "py status " + `status`
  4. #
  5. # Create configuration objects
  6. #
  7. ua_cfg = py_pjsua.config_default()
  8. log_cfg = py_pjsua.logging_config_default()
  9. media_cfg = py_pjsua.media_config_default()
  10. #
  11. # Logging callback.
  12. #
  13. def logging_cb1(level, str, len):
  14. print str,
  15. #
  16. # Configure logging
  17. #
  18. log_cfg.cb = logging_cb1
  19. log_cfg.console_level = 4
  20. #
  21. # Initialize pjsua!
  22. #
  23. status = py_pjsua.init(ua_cfg, log_cfg, media_cfg);
  24. print "py status after initialization :" + `status`
  25. #
  26. # Start pjsua!
  27. #
  28. status = py_pjsua.start()
  29. if status != 0:
  30. exit(1)
  31. message = py_pjsua.msg_data_init()
  32. print "identitas object message data :" + `message`
  33. sipaddr = 'sip:167.205.34.99'
  34. print "checking sip address [%s] : %d" % (sipaddr, py_pjsua.verify_sip_url(sipaddr))
  35. sipaddr = '167.205.34.99'
  36. print "checking invalid sip address [%s] : %d" % (sipaddr, py_pjsua.verify_sip_url(sipaddr))
  37. object = py_pjsua.get_pjsip_endpt()
  38. print "identitas Endpoint :" + `object` + ""
  39. mediaend = py_pjsua.get_pjmedia_endpt()
  40. print "identitas Media Endpoint :" + `mediaend` + ""
  41. pool = py_pjsua.get_pool_factory()
  42. print "identitas pool factory :" + `pool` + ""
  43. status = py_pjsua.handle_events(3000)
  44. print "py status after 3 second of blocking wait :" + `status`
  45. # end of new testrun
  46. #
  47. # lib transport
  48. stunc = py_pjsua.stun_config_default();
  49. tc = py_pjsua.transport_config_default();
  50. py_pjsua.normalize_stun_config(stunc);
  51. status, id = py_pjsua.transport_create(1, tc);
  52. print "py transport create status " + `status`
  53. ti = py_pjsua.Transport_Info();
  54. ti = py_pjsua.transport_get_info(id)
  55. print "py transport get info status " + `status`
  56. status = py_pjsua.transport_set_enable(id,1)
  57. print "py transport set enable status " + `status`
  58. if status != 0 :
  59. py_pjsua.perror("py_pjsua","set enable",status)
  60. status = py_pjsua.transport_close(id,1)
  61. print "py transport close status " + `status`
  62. if status != 0 :
  63. py_pjsua.perror("py_pjsua","close",status)
  64. # end of lib transport
  65. # lib account
  66. accfg = py_pjsua.acc_config_default()
  67. status, accid = py_pjsua.acc_add(accfg, 1)
  68. print "py acc add status " + `status`
  69. if status != 0 :
  70. py_pjsua.perror("py_pjsua","add acc",status)
  71. count = py_pjsua.acc_get_count()
  72. print "acc count " + `count`
  73. accid = py_pjsua.acc_get_default()
  74. print "acc id default " + `accid`
  75. # end of lib account
  76. #lib buddy
  77. bcfg = py_pjsua.Buddy_Config()
  78. status, id = py_pjsua.buddy_add(bcfg)
  79. acc_id = id
  80. print "py buddy add status " + `status` + " id " + `id`
  81. bool = py_pjsua.buddy_is_valid(id)
  82. print "py buddy is valid " + `bool`
  83. count = py_pjsua.get_buddy_count()
  84. print "buddy count " + `count`
  85. binfo = py_pjsua.buddy_get_info(id)
  86. ids = py_pjsua.enum_buddies()
  87. status = py_pjsua.buddy_del(id)
  88. print "py buddy del status " + `status`
  89. status = py_pjsua.buddy_subscribe_pres(id, 1)
  90. print "py buddy subscribe pres status " + `status`
  91. py_pjsua.pres_dump(1)
  92. status = py_pjsua.im_send(accid, "fahris@divusi.com", "", "hallo", message, 0)
  93. print "py im send status " + `status`
  94. status = py_pjsua.im_typing(accid, "fahris@divusi.com", 1, message)
  95. print "py im typing status " + `status`
  96. #print "binfo " + `binfo`
  97. #end of lib buddy
  98. #lib media
  99. count = py_pjsua.conf_get_max_ports()
  100. print "py media conf get max ports " + `count`
  101. count = py_pjsua.conf_get_active_ports()
  102. print "py media conf get active ports " + `count`
  103. ids = py_pjsua.enum_conf_ports()
  104. for id in ids:
  105. print "py media conf ports " + `id`
  106. cp_info = py_pjsua.conf_get_port_info(id)
  107. print "port info name " + cp_info.name
  108. pool = py_pjsua.PJ_Pool()
  109. port = py_pjsua.PJMedia_Port()
  110. status, id = py_pjsua.conf_add_port(pool,port)
  111. print "py media conf add port status " + `status` + " id " + `id`
  112. if status != 0 :
  113. py_pjsua.perror("py_pjsua","add port",status)
  114. status = py_pjsua.conf_remove_port(id)
  115. print "py media conf remove port status " + `status`
  116. if status != 0 :
  117. py_pjsua.perror("py_pjsua","remove port",status)
  118. status = py_pjsua.conf_connect(id, id)
  119. print "py media conf connect status " + `status`
  120. if status != 0 :
  121. py_pjsua.perror("py_pjsua","connect",status)
  122. status = py_pjsua.conf_disconnect(id, id)
  123. print "py media conf disconnect status " + `status`
  124. if status != 0 :
  125. py_pjsua.perror("py_pjsua","disconnect",status)
  126. status, id = py_pjsua.player_create("test.wav", 0)
  127. print "py media player create status " + `status` + " id " + `id`
  128. if status != 0 :
  129. py_pjsua.perror("py_pjsua","player create",status)
  130. c_id = py_pjsua.player_get_conf_port(id)
  131. print "py media player get conf port id " + `c_id`
  132. status = py_pjsua.player_set_pos(id, 10)
  133. if status != 0 :
  134. py_pjsua.perror("py_pjsua","player set pos",status)
  135. status = py_pjsua.player_destroy(id)
  136. if status != 0 :
  137. py_pjsua.perror("py_pjsua","player destroy",status)
  138. status, id = py_pjsua.recorder_create("rec.wav", 0, "None", 1000, 0)
  139. print "py media recorder create status " + `status` + " id " + `id`
  140. if status != 0 :
  141. py_pjsua.perror("py_pjsua","recorder create",status)
  142. status = py_pjsua.recorder_get_conf_port(id)
  143. print "py media recorder get conf port status " + `status`
  144. if status != 0 :
  145. py_pjsua.perror("py_pjsua","recorder get conf port",status)
  146. status = py_pjsua.recorder_destroy(id)
  147. print "py media recorder destroy status " + `status`
  148. if status != 0 :
  149. py_pjsua.perror("py_pjsua","recorder destroy",status)
  150. #cdev, pdev = py_pjsua.get_snd_dev()
  151. #print "py media get snd dev capture dev " + `cdev` + " playback dev " + `pdev`
  152. status = py_pjsua.set_snd_dev(0,1)
  153. print "py media set snd dev status " + `status`
  154. if status != 0 :
  155. py_pjsua.perror("py_pjsua","set snd dev",status)
  156. status = py_pjsua.set_null_snd_dev()
  157. print "py media set null snd dev status " + `status`
  158. if status != 0 :
  159. py_pjsua.perror("py_pjsua","set null snd dev",status)
  160. port = py_pjsua.set_no_snd_dev()
  161. status = py_pjsua.set_ec(0,0)
  162. print "py media set ec status " + `status`
  163. if status != 0 :
  164. py_pjsua.perror("py_pjsua","set ec",status)
  165. tail = py_pjsua.get_ec_tail()
  166. print "py media get ec tail " + `tail`
  167. infos = py_pjsua.enum_codecs()
  168. for info in infos:
  169. print "py media enum codecs " + `info`
  170. status = py_pjsua.codec_set_priority("coba", 0)
  171. print "py media codec set priority " + `status`
  172. if status != 0 :
  173. py_pjsua.perror("py_pjsua","codec set priority",status)
  174. c_param = py_pjsua.codec_get_param("coba")
  175. status = py_pjsua.codec_set_param("coba", c_param)
  176. print "py media codec set param " + `status`
  177. if status != 0 :
  178. py_pjsua.perror("py_pjsua","codec set param",status)
  179. #end of lib media
  180. #lib call
  181. count = py_pjsua.call_get_max_count()
  182. print "py call get max count " + `count`
  183. count = py_pjsua.call_get_count()
  184. print "py call get count " + `count`
  185. ids = py_pjsua.enum_calls()
  186. for id in ids:
  187. print "py enum calls id " + `id`
  188. msg_data = py_pjsua.Msg_Data()
  189. status, id = py_pjsua.call_make_call(-1, "sip:bulukucing1@iptel.org", 0, 0, msg_data)
  190. print "py call make call " + `status` + " id " + `id`
  191. if status != 0 :
  192. py_pjsua.perror("py_pjsua","call make call",status)
  193. bool = py_pjsua.call_is_active(id)
  194. print "py call is active " + `bool`
  195. bool = py_pjsua.call_has_media(id)
  196. print "py call has media " + `bool`
  197. cp_id = py_pjsua.call_get_conf_port(id)
  198. print "py call get conf port " + `cp_id`
  199. info = py_pjsua.call_get_info(id)
  200. if info != None :
  201. print "py info id " + `info.id`
  202. status = py_pjsua.call_set_user_data(id, 0)
  203. print "py call set user data status " + `status`
  204. if status != 0 :
  205. py_pjsua.perror("py_pjsua","set user data",status)
  206. user_data = py_pjsua.call_get_user_data(id)
  207. print "py call get user data " + `user_data`
  208. #end of lib call
  209. py_pjsua.perror("saya","hallo",70006)
  210. status = py_pjsua.destroy()
  211. print "py status " + `status`