Skip to content

Commit

Permalink
Merge pull request #583 from 64characters/pjsip-2-10
Browse files Browse the repository at this point in the history
PJSIP 2.10
  • Loading branch information
eofster authored Apr 15, 2020
2 parents 5ef8014 + 5d557b7 commit b848b86
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 5 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ Build and install:

Download:

$ curl -O https://www.pjsip.org/release/2.7.2/pjproject-2.7.2.tar.bz2
$ tar xzvf pjproject-2.7.2.tar.bz2
$ cd pjproject-2.7.2
$ curl -o pjproject-2.10.tar.gz https://codeload.github.com/pjsip/pjproject/tar.gz/2.10
$ tar xzvf pjproject-2.10.tar.gz
$ cd pjproject-2.10

Create `pjlib/include/pj/config_site.h`:

#define PJSIP_DONT_SWITCH_TO_TCP 1
#define PJSUA_MAX_ACC 32
#define PJMEDIA_RTP_PT_TELEPHONE_EVENTS 101
#define PJMEDIA_RTP_PT_TELEPHONE_EVENTS_STR "101"
#define PJ_DNS_MAX_IP_IN_A_REC 32
#define PJ_DNS_SRV_MAX_ADDR 32
#define PJSIP_MAX_RESOLVED_ADDRESSES 32
#define PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION 1
#define PJ_HAS_IPV6 1

Patch `pjlib/src/pj/sock_qos_darwin.c`:

$ patch -p0 -i /path/to/Telephone/ThirdParty/PJSIP/patches/sock_qos_darwin.patch
$ patch -p0 -i /path/to/Telephone/ThirdParty/PJSIP/patches/os_core_unix.patch

Build and install (remove `--with-opus` option if you don’t need Opus):

Expand Down
1 change: 1 addition & 0 deletions Telephone/AKSIPUserAgent.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ - (void)thread_startInAutoreleasePoolWithCompletion:(void (^ _Nonnull)(BOOL didS
mediaConfig.no_vad = ![self detectsVoiceActivity];
mediaConfig.enable_ice = [self usesICE];
mediaConfig.snd_auto_close_time = 1;
mediaConfig.ec_options = PJMEDIA_ECHO_USE_SW_ECHO;

if (self.usesQoS) {
transportConfig.qos_params.flags = PJ_QOS_PARAM_HAS_DSCP;
Expand Down
125 changes: 125 additions & 0 deletions ThirdParty/PJSIP/patches/os_core_unix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
diff --git pjlib/include/pj/compat/os_auto.h.in pjlib/include/pj/compat/os_auto.h.in
index 159d2bcf0..0669a5c9e 100644
--- pjlib/include/pj/compat/os_auto.h.in
+++ pjlib/include/pj/compat/os_auto.h.in
@@ -186,6 +186,8 @@
* pj_sockaddr_set_str_addr()
*/
# define PJ_SOCKADDR_USE_GETADDRINFO 1
+ /* Use dispatch semaphores */
+# define PJ_SEMAPHORE_USE_DISPATCH_SEM 1

# include "TargetConditionals.h"
# if TARGET_OS_IPHONE
diff --git pjlib/src/pj/os_core_unix.c pjlib/src/pj/os_core_unix.c
index c17ad4ef0..1c819343a 100644
--- pjlib/src/pj/os_core_unix.c
+++ pjlib/src/pj/os_core_unix.c
@@ -39,6 +39,10 @@
# include <semaphore.h>
#endif

+#if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+# include <dispatch/dispatch.h>
+#endif
+
#include <unistd.h> // getpid()
#include <errno.h> // errno

@@ -107,7 +111,11 @@ struct pj_mutex_t
#if defined(PJ_HAS_SEMAPHORE) && PJ_HAS_SEMAPHORE != 0
struct pj_sem_t
{
+#if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ dispatch_semaphore_t sem;
+#else
sem_t *sem;
+#endif
char obj_name[PJ_MAX_OBJ_NAME];
};
#endif /* PJ_HAS_SEMAPHORE */
@@ -1569,6 +1577,11 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
PJ_ASSERT_RETURN(sem, PJ_ENOMEM);

#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
+# if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ sem->sem = dispatch_semaphore_create(initial);
+ if (sem->sem == NULL)
+ return PJ_FALSE;
+# else
/* MacOS X doesn't support anonymous semaphore */
{
char sem_name[PJ_GUID_MAX_LENGTH+1];
@@ -1599,6 +1612,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
/* And immediately release the name as we don't need it */
sem_unlink(sem_name);
}
+# endif
#else
sem->sem = PJ_POOL_ALLOC_T(pool, sem_t);
if (sem_init( sem->sem, 0, initial) != 0)
@@ -1632,7 +1646,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool,
PJ_DEF(pj_status_t) pj_sem_wait(pj_sem_t *sem)
{
#if PJ_HAS_THREADS
- int result;
+ long result;

PJ_CHECK_STACK();
PJ_ASSERT_RETURN(sem, PJ_EINVAL);
@@ -1640,7 +1654,11 @@ PJ_DEF(pj_status_t) pj_sem_wait(pj_sem_t *sem)
PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting",
pj_thread_this()->obj_name));

+#if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ result = dispatch_semaphore_wait(sem->sem, DISPATCH_TIME_FOREVER);
+#else
result = sem_wait( sem->sem );
+#endif

if (result == 0) {
PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",
@@ -1666,12 +1684,16 @@ PJ_DEF(pj_status_t) pj_sem_wait(pj_sem_t *sem)
PJ_DEF(pj_status_t) pj_sem_trywait(pj_sem_t *sem)
{
#if PJ_HAS_THREADS
- int result;
+ long result;

PJ_CHECK_STACK();
PJ_ASSERT_RETURN(sem, PJ_EINVAL);

+#if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ result = dispatch_semaphore_wait(sem->sem, DISPATCH_TIME_NOW);
+#else
result = sem_trywait( sem->sem );
+#endif

if (result == 0) {
PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",
@@ -1696,7 +1718,12 @@ PJ_DEF(pj_status_t) pj_sem_post(pj_sem_t *sem)
int result;
PJ_LOG(6, (sem->obj_name, "Semaphore released by thread %s",
pj_thread_this()->obj_name));
+#if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ dispatch_semaphore_signal(sem->sem);
+ result = 0;
+#else
result = sem_post( sem->sem );
+#endif

if (result == 0)
return PJ_SUCCESS;
@@ -1722,7 +1749,12 @@ PJ_DEF(pj_status_t) pj_sem_destroy(pj_sem_t *sem)
PJ_LOG(6, (sem->obj_name, "Semaphore destroyed by thread %s",
pj_thread_this()->obj_name));
#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0
+# if defined(PJ_SEMAPHORE_USE_DISPATCH_SEM) && PJ_SEMAPHORE_USE_DISPATCH_SEM != 0
+ dispatch_release(sem->sem);
+ result = 0;
+# else
result = sem_close( sem->sem );
+# endif
#else
result = sem_destroy( sem->sem );
#endif

0 comments on commit b848b86

Please sign in to comment.