Example #1
0
/*
 * NAME:
 * fmucs2geo
 *
 * PURPOSE:
 * Computes geographical latitude, longitude from UCS northings, eastings.
 *
 * REQUIREMENTS:
 *
 * INPUT:
 *
 * OUTPUT:
 *
 * NOTES:
 *
 * BUGS:
 *
 * AUTHOR:
 * Øystein Godøy, met.no/FOU, 10.01.2005 
 *
 * MODIFIED:
 * NA
 */
fmgeopos fmucs2geo(fmucspos xy, fmprojspec myproj) {
    fmgeopos ll;
    PJ *ref;
    projUV cnat;

    /*
     * Select predefined projection, and initialize interface to PROJ
     */
    if (myproj == MI) {
	if (!(ref=pj_init(sizeof(miproj)/sizeof(char *), miproj))) {
	    fprintf(stderr,"ERROR: PROJ initialization failed.\n");
	}
    } else if (myproj == MEOS) {
	if (!(ref=pj_init(sizeof(meosproj)/sizeof(char *), meosproj))) {
	    fprintf(stderr,"ERROR: PROJ initialization failed.\n");
	}
    } else {
	fprintf(stdout,"ERROR: Projection not supported\n");
    }

    /*
     * Estimate ll
     */
    cnat.u = xy.eastings;
    cnat.v = xy.northings;
    cnat = pj_inv(cnat,ref);
    ll.lon = cnat.u*RAD_TO_DEG;
    ll.lat = cnat.v*RAD_TO_DEG;
    if (cnat.u == HUGE_VAL) {
	fprintf(stderr, "ERROR: pj_inv conversion\n");
    }
    pj_free(ref);

    return(ll);
}
Example #2
0
File: t3.c Project: ushakov/mapsoft
int main(){

//  char *pr1[] = {"+proj=latlong", "+ellps=WGS84"};
  char *pr1[] = {"+proj=tmerc",   "+ellps=WGS84", "+lon_0=39",
                 "+scale=1", "+lat_0=0", "+x_0=500000"};
  char *pr2[] = {"+proj=tmerc",   "+ellps=krass", "+lon_0=39",
                 "+scale=1", "+lat_0=0", "+x_0=500000"};


  projPJ P1 = pj_init(6, pr1);
  projPJ P2 = pj_init(6, pr2);


  if (!P1) {
    fprintf(stderr, "can't create projection 1\n");
    exit(1);
  }

  if (!P2) {
    fprintf(stderr, "can't create projection 2\n");
    exit(1);
  }

  double x=39*M_PI/180 + ((double)rand()/RAND_MAX - 0.5) * M_PI/30; // 36..42
  double y=((double)rand()/RAND_MAX - 0.5) * M_PI;         // -90..+90
  double z=((double)rand()/RAND_MAX - 0.5) * 6000;         // +/- 3000m

  printf("%.12f %.12f %f\n",x*180/M_PI,y*180/M_PI,z);

  int i;
  for (i=0; i<1000000; i++){

//    z=0;
    int j = pj_transform(P1,P2, 1, 1, &x, &y, &z);

    if (j) {
      fprintf(stderr, "can't do transform\n");
      exit(1);
    }

//    z=0;
    j = pj_transform(P2,P1, 1, 1, &x, &y, &z);

    if (j) {
      fprintf(stderr, "can't do transform\n");
      exit(1);
    }
  }

  printf("%.12f %.12f %f\n",x*180/M_PI,y*180/M_PI,z);

  pj_free(P1);
  pj_free(P2);

}
Example #3
0
/**Creates a new projection object. See the intro for details.

   call-seq: new(String) -> Proj4::Projection
             new(Array) -> Proj4::Projection
             new(Hash) -> Proj4::Projection

 */
static VALUE proj_initialize(VALUE self, VALUE params){
  _wrap_pj* wpj;
  VALUE proj_params = rb_funcall(cProjection, idParseInitParameters, 1, params);
  int size = RARRAY_LEN(proj_params);
  char** c_params = (char **) malloc(size*sizeof(char *));
  int i;

  for (i=0; i < size; i++)
  {
    VALUE item = rb_ary_entry(proj_params, i);
    c_params[i]= StringValuePtr(item); 
  }

  Data_Get_Struct(self,_wrap_pj,wpj);
  wpj->pj = pj_init(size,c_params);
  free(c_params);
  if(wpj->pj == 0) {
    int pj_errno_ref = *pj_get_errno_ref();
    if (pj_errno_ref > 0) {
        rb_raise(rb_eSystemCallError, "Unknown system call error");
    } else {
        raise_error(pj_errno_ref);
    }
  }
  return self;
}
Example #4
0
	static void
set_zone(int in, struct IO_CON *io) {
	char tmp[20];

	if (io->hp) {
		io->t83 = 1;
		if (!(htab = nad_init(io->hp)))
			emess(1,"hp datum file: %s, failed: %s", io->hp,
				pj_strerrno(pj_errno));
	}
	if (io->zone > 0) {
		if (io->zone <= 60) { /* UTM zone */
			io->nprojc = 2; /* no other options allowed */
			io->projc[0] = "proj=utm";
			sprintf(tmp, "zone=%d", io->zone);
			io->projc[1] = io->t83 ? "ellps=GRS80" : "ellps=clrk66";
		} else /* SPCS zone */
			sprintf(tmp, "init=nad%s:%d", io->t83 ? "83" : "27", io->zone);
		io->projc[io->nprojc++] = tmp;
		io->projc[io->nprojc++] = "no_defs";
		if (!(io->cnv = pj_init(io->nprojc, io->projc)))
			emess(1,pj_strerrno(pj_errno));
		io->ll = 0;
	}
}
Example #5
0
static pj_status_t init_stack()
{
    pj_sockaddr addr;
    pjsip_inv_callback inv_cb;
    pj_status_t status;

    pj_log_set_level(5);

    status = pj_init();
    CHECK_STATUS();

    pj_log_set_level(3);

    status = pjlib_util_init();
    CHECK_STATUS();

    pj_caching_pool_init(&app.cp, NULL, 0);
    app.pool = pj_pool_create( &app.cp.factory, "sipecho", 512, 512, 0);

    status = pjsip_endpt_create(&app.cp.factory, NULL, &app.sip_endpt);
    CHECK_STATUS();

    pj_log_set_level(4);
    pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT);
    if (AF == pj_AF_INET()) {
	status = pjsip_udp_transport_start( app.sip_endpt, &addr.ipv4, NULL,
					    1, NULL);
    } else if (AF == pj_AF_INET6()) {
	status = pjsip_udp_transport_start6(app.sip_endpt, &addr.ipv6, NULL,
					    1, NULL);
    } else {
	status = PJ_EAFNOTSUP;
    }

    pj_log_set_level(3);
    CHECK_STATUS();

    status = pjsip_tsx_layer_init_module(app.sip_endpt) ||
	     pjsip_ua_init_module( app.sip_endpt, NULL );
    CHECK_STATUS();

    pj_bzero(&inv_cb, sizeof(inv_cb));
    inv_cb.on_state_changed = &call_on_state_changed;
    inv_cb.on_new_session = &call_on_forked;
    inv_cb.on_media_update = &call_on_media_update;
    inv_cb.on_rx_offer = &call_on_rx_offer;

    status = pjsip_inv_usage_init(app.sip_endpt, &inv_cb) ||
	     pjsip_100rel_init_module(app.sip_endpt) ||
	     pjsip_endpt_register_module( app.sip_endpt, &mod_sipecho) ||
	     pjsip_endpt_register_module( app.sip_endpt, &msg_logger) ||
	     //pjmedia_endpt_create(&app.cp.factory,
		//		  pjsip_endpt_get_ioqueue(app.sip_endpt),
		//		  0, &app.med_endpt) ||
             pj_thread_create(app.pool, "sipecho", &worker_proc, NULL, 0, 0,
                              &app.worker_thread);
    CHECK_STATUS();

    return PJ_SUCCESS;
}
int main(int argc, char *argv[])
{
    if (argc < 2) {
	usage(argv[0]);
	return 1;
    }

    pj_init();

    init();

    if (stricmp(argv[1], "record")==0) {
	record_file("FILE.PCM");
    } else if (stricmp(argv[1], "play")==0) {
	play_file("FILE.PCM");
    } else if (stricmp(argv[1], "send")==0) {
	create_ses_by_remote_sdp(4002, listener_sdp);
    } else if (stricmp(argv[1], "recv")==0) {
	create_ses_by_remote_sdp(4000, talker_sdp);
    } else {
	usage(argv[0]);
    }
    deinit();
    return 0;
}
Example #7
0
 static void SetUpTestCase()
 {
   pj_init();
   pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
   pjsip_endpt_create(&caching_pool.factory, NULL, &endpt);
   pool = pj_pool_create(&caching_pool.factory, "contact-filtering-test", 4000, 4000, NULL);
 };
Example #8
0
/*
 * main()
 */
int main(int argc, char *argv[])
{
    pj_caching_pool cp;
    pj_status_t status;

    if (argc < 2 || argc > 3) {
	puts("Usage: httpdemo URL [output-filename]");
	return 1;
    }

    pj_log_set_level(5);

    pj_init();
    pj_caching_pool_init(&cp, NULL, 0);
    mem = &cp.factory;
    pjlib_util_init();

    if (argc > 2)
	f = fopen(argv[2], "wb");
    else
	f = stdout;

    status = getURL(argv[1]);
    if (status != PJ_SUCCESS) {
        PJ_PERROR(1, (THIS_FILE, status, "Error"));
    }

    if (f != stdout)
	fclose(f);

    pj_caching_pool_destroy(&cp);
    pj_shutdown();
    return 0;
}
Example #9
0
int main() {
    pj_caching_pool cp;
    pj_pool_t *pool;
    pjmedia_endpt *ep;
    pjmedia_conf *conf;
    pjmedia_port *fp, *mp;
    pjmedia_snd_port *sp;
    pjmedia_snd_port *mic;
    unsigned slot;

    pj_init();
    pj_srand(12345);
    pj_caching_pool_init(&cp, NULL, 1024);
    pool = pj_pool_create(&cp.factory, "pool1", 1024, 1024, NULL);
    pjmedia_endpt_create(&cp.factory, NULL, 1, &ep);
    pjmedia_conf_create(pool, 3, 8000, 1, 
                        8000 * 1 * 20 / 1000, // Sample per frame = # of samples in 20 ms
                        16, PJMEDIA_CONF_NO_DEVICE, &conf);
    mp = pjmedia_conf_get_master_port(conf);
    CHECK(__FILE__, pjmedia_snd_port_create_player(pool, 1, 8000, 1, 160, 16, 0, &sp));
    printf("sp=%p - mp=%p\n", sp, mp);
    pjmedia_snd_port_connect(sp, mp);

    pjmedia_snd_port_create_rec(pool, 0, 8000, 1, 160, 16, 0, &mic);

    pjmedia_wav_player_port_create(pool, "NHP-mono-pcm-s16le.wav", 0, 0, 0, &fp);

    //pjmedia_wav_writer_port_create(pool, "vnt.wav", 8000, 1, 160, 16, 0, 0, &fp);

    fp = pjmedia_snd_port_get_port(mic);
    pjmedia_conf_add_port(conf, pool, fp, NULL, &slot);
    pjmedia_conf_connect_port(conf, slot, 0, 0);
    while (1) sleep(2);
}
Example #10
0
static int mericd_init(struct gpsnav *gpsnav, struct gps_map_provider *prov)
{
	struct mericd_data *data;
	char *projc[3];
	PJ *pj;

	data = malloc(sizeof(*data));
	if (data == NULL)
		return -ENOMEM;
	memset(data, 0, sizeof(*data));

	projc[0] = "ellps=WGS84";
	projc[1] = "proj=merc";
	projc[2] = "no_defs";
	pj = pj_init(3, projc);
	if (pj == NULL) {
		gps_error("Unable to initialize projection");
		free(data);
		return -1;
	}
	data->proj = pj;
	prov->data = data;

	return 0;
}
Example #11
0
/*
 * main()
 */
int main(int argc, char *argv[])
{
    pj_caching_pool cp;
    pjmedia_endpt *med_ept;
    pjsip_endpoint *sip_ept;
    char errmsg[PJ_ERR_MSG_SIZE];
    pj_status_t code;

    if (argc != 2) {
	puts("Usage: strerror ERRNUM");
	return 1;
    }

    pj_log_set_level(3);

    pj_init();
    pj_caching_pool_init(&cp, NULL, 0);
    pjlib_util_init();
    pjnath_init();
    pjmedia_endpt_create(&cp.factory, NULL, 0, &med_ept);
    pjsip_endpt_create(&cp.factory, "localhost", &sip_ept);
    pjsip_evsub_init_module(sip_ept);

    code = atoi(argv[1]);
    pj_strerror(code, errmsg, sizeof(errmsg));

    printf("Status %d: %s\n", code, errmsg);

    pj_shutdown();
    return 0;
}
Example #12
0
int main(int argc, char *argv[])
{
    ics_stream_t stream_data;
    char tmp[10];
    pj_status_t status;
    pj_caching_pool cp;
    pj_pool_t *pool;

    status = pj_init();
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
    pool = pj_pool_create(&cp.factory, "app", 4000, 4000, NULL);

    ics_stream_init(&stream_data, &cp, pool);
    ics_stream_create(&stream_data, 4321, "127.0.0.1:1234", "sink");
    ics_stream_connect_with_snd_sink(&stream_data);
    ics_stream_start(&stream_data);
    
    for (;;) {
        if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
            puts("EOF while reading stdin, will quit now..");
            break;
        }
        if (tmp[0] == 'q')
            break;
    }

    //Destroy and clean`
    ics_stream_clean(&stream_data);
    return 0;
}
Example #13
0
int main() {
    pj_sock_t sock;
    pj_sockaddr_in to_addr;
    char *s = "Cong hoa xa hoi chu nghia VietNam";

    char buffer[100];
    pj_ssize_t len;

    struct timeval tv_begin, tv_end, tv_diff;

    pj_log_set_level(3);
    CHECK(__FILE__, pj_init());
    pj_bzero(buffer, sizeof(buffer));
    CHECK_R( __FILE__, pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock) );
    //udp_socket(12345, &sock);
    setup_addr_with_host_and_port(&to_addr, "127.0.0.1", 33333);

    len = strlen(s);
    gettimeofday(&tv_begin, NULL);
    pj_sock_sendto(sock, s, &len, 0, &to_addr, sizeof(to_addr));
    
    PJ_LOG(3, (__FILE__, "Sent: %s", s));
    len = 100;
    pj_sock_recv(sock, buffer, &len, 0);
    gettimeofday(&tv_end, NULL);
    int diff = timeval_subtract(&tv_diff, &tv_end, &tv_begin);
    PJ_LOG(3, (__FILE__, "Received: %s %0.2f msec", buffer, diff*1.0/1000));
    pj_shutdown();
    return 0;
}
Example #14
0
File: test.c Project: Jopie64/pjsip
int test_main(void)
{
    int rc = 0;
    pj_caching_pool caching_pool;

    pj_init();
    pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);

    pj_log_set_decor(PJ_LOG_HAS_NEWLINE);
    pj_log_set_level(3);

    mem = &caching_pool.factory;

    DO_TEST(sdp_neg_test());
    //DO_TEST(sdp_test (&caching_pool.factory));
    //DO_TEST(rtp_test(&caching_pool.factory));
    //DO_TEST(session_test (&caching_pool.factory));
    DO_TEST(jbuf_main());
    DO_TEST(mips_test());
    DO_TEST(codec_test_vectors());

    PJ_LOG(3,(THIS_FILE," "));

on_return:
    if (rc != 0) {
	PJ_LOG(3,(THIS_FILE,"Test completed with error(s)!"));
    } else {
	PJ_LOG(3,(THIS_FILE,"Looks like everything is okay!"));
    }

    pj_caching_pool_destroy(&caching_pool);

    return rc;
}
/*
 * Create app
 */
static pj_status_t create_app(void)
{
    pj_status_t status;

    status = pj_init();
    if (status != PJ_SUCCESS) {
	app_perror(THIS_FILE, "Error initializing pjlib", status);
	return status;
    }

    /* init PJLIB-UTIL: */
    status = pjlib_util_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);

    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy, 
			 CACHING_POOL_SIZE);

    /* Create application pool for misc. */
    app.pool = pj_pool_create(&app.cp.factory, "app", 1000, 1000, NULL);

    /* Create the endpoint: */
    status = pjsip_endpt_create(&app.cp.factory, pj_gethostname()->ptr, 
				&app.sip_endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);


    return status;
}
Example #16
0
static	bool	TransformTiffCorner(GTIF * gtif, GTIFDefn * defn, double x, double y, double& outLon, double& outLat)
{
    /* Try to transform the coordinate into PCS space */
    if( !GTIFImageToPCS( gtif, &x, &y ) )
        return false;
	
    if( defn->Model == ModelTypeGeographic )
    {
    	outLon = x;
    	outLat = y;
    	return true;
    }
    else    
	{
        if( GTIFProj4ToLatLong( defn, 1, &x, &y ) )
        {
			outLon = x;
			outLat = y;
			return true;
		}

		int size = 0;
		tagtype_t type = TYPE_UNKNOWN;
		int key_count = GTIFKeyInfo(gtif, GTCitationGeoKey, &size, &type);
		
		if(key_count > 0 && key_count < 1024 && type == TYPE_ASCII && size == 1)
		{
			vector<char>	ascii(key_count);
			int r = GTIFKeyGet(gtif, GTCitationGeoKey, &ascii[0], 0, key_count);
			if(r == key_count)
			{
				DebugAssert(ascii.back() == 0);
				string citation = string(&ascii[0]);
				if(citation == "PCS Name = WGS_1984_Web_Mercator_Auxiliary_Sphere")
				{
					char ** args = CSLTokenizeStringComplex("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs", " +", TRUE, FALSE);
					PJ * psPJ = pj_init( CSLCount(args), args );
					CSLDestroy(args);
					if(psPJ)
					{
						projUV	sUV;

						sUV.u = x;
						sUV.v = y;

						sUV = pj_inv( sUV, psPJ );

						outLon = sUV.u * RAD_TO_DEG;
						outLat = sUV.v * RAD_TO_DEG;
						pj_free(psPJ);
						return true;
					}
				}
			}
		}
	}
	return false;
}
Example #17
0
int main(int argc, char *argv[])
{
    pj_caching_pool cp;
    pjmedia_endpt *med_endpt;
    pj_status_t status;

    /* Init pjlib */
    status = pj_init();
    PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);
    
    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);

    /* 
     * Initialize media endpoint.
     * This will implicitly initialize PJMEDIA too.
     */
    status = pjmedia_endpt_create(&cp.factory, NULL, 1, &med_endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    
    if (argc == 1) {
	enum_devices();
	return 0;
    } else if (argc == 6) {
	
	int dev_id;
	pjmedia_dir dir = PJMEDIA_DIR_NONE;
	int nchannel;
	int bits;

	dev_id = atoi(argv[1]);

	if (strcmp(argv[2], "rec")==0)
	    dir = PJMEDIA_DIR_CAPTURE;
	else if (strcmp(argv[2], "play")==0)
	    dir = PJMEDIA_DIR_PLAYBACK;
	else if (strcmp(argv[2], "both")==0)
	    dir = PJMEDIA_DIR_CAPTURE_PLAYBACK;

	clock_rate = atoi(argv[3]);
	nchannel = atoi(argv[4]);
	bits = atoi(argv[5]);

	return open_device(dev_id, dir, nchannel, bits);

    } else {
	puts("Error: invalid arguments");
	puts(desc);
	return 1;
    }

    /* Shutdown PJLIB */
    pj_shutdown();

    return 0;
}
Example #18
0
static int test_inner(void)
{
    pj_caching_pool caching_pool;
    int rc = 0;

    mem = &caching_pool.factory;

#if 1
    pj_log_set_level(3);
    pj_log_set_decor(param_log_decor);
    PJ_UNUSED_ARG(test_log_func);
#elif 1
    log_file = fopen("pjnath-test.log", "wt");
    pj_log_set_level(5);
    orig_log_func = pj_log_get_log_func();
    pj_log_set_log_func(&test_log_func);
#endif

    rc = pj_init();
    if (rc != 0) {
	app_perror("pj_init() error!!", rc);
	return rc;
    }

    pj_dump_config();
    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );

    pjlib_util_init();
    pjnath_init();

#if INCLUDE_STUN_TEST
    DO_TEST(stun_test());
    DO_TEST(sess_auth_test());
#endif

#if INCLUDE_ICE_TEST
    DO_TEST(ice_test());
#endif

#if INCLUDE_STUN_SOCK_TEST
    DO_TEST(stun_sock_test());
#endif

#if INCLUDE_TURN_SOCK_TEST
    DO_TEST(turn_sock_test());
#endif

#if INCLUDE_CONCUR_TEST
    DO_TEST(concur_test());
#endif

on_return:
    if (log_file)
	fclose(log_file);
    return rc;
}
Example #19
0
//-----------------------------------------------------------------------------------------
void Projection_libproj::setProjection(int code)
{
    const char *params[20];
	int nbpar=0;
	switch (code)
	{
		case PROJ_UTM :
			nbpar = 0;
            params[nbpar++] = "proj=utm";
			cylindrical = false;
			break;
		case PROJ_CENTRAL_CYL:
			nbpar = 0;
            params[nbpar++] = "proj=cc";
			cylindrical = true;
			break;
		case PROJ_EQU_CYL:
			nbpar = 0;
            params[nbpar++] = "proj=eqc";
			cylindrical = true;
			break;
		case PROJ_MILLER :
			// Miller
			nbpar = 0;
            params[nbpar++] = "proj=mill";
			cylindrical = true;
			break;
		case PROJ_LAMBERT_CONF_CON :
			// Lambert Conformal Conic
			nbpar = 0;
            params[nbpar++] = "proj=lcc";
            params[nbpar++] = "lat_1=80N";
            params[nbpar++] = "lat_2=20N";
            params[nbpar++] = "lon_0=0W";
			cylindrical = false;
			break;
		case PROJ_MERCATOR :
		default :
			// Mercator
			nbpar = 0;
            params[nbpar++] = "proj=merc";
			cylindrical = true;
			break;
	}
    params[nbpar++] = "ellps=WGS84";
    params[nbpar++] = "no_defs";
    params[nbpar++] = "over";	// allow longitude > 180°
    // XXX ouch pj_init
    libProj = pj_init(nbpar, (char **)params);
	if (!libProj)
		printf("proj error: %s\n", pj_strerrno(pj_errno));
	assert(libProj);
	currentProj = code;
//	libProj->over = 1;		// allow longitude > 180°
//printf("Projection: %s\n", libProj->descr);
}
Example #20
0
int main(int argc, char *argv[])
{
    pj_caching_pool cp;
    pj_time_val t0, t1;
    pj_status_t status;

    if (argc != 4) {
	puts(desc);
	return 1;
    }

    CHECK( pj_init() );
    
    pj_caching_pool_init(&cp, NULL, 0);

    CHECK( pjmedia_endpt_create(&cp.factory, NULL, 1, &mept) );

    /* Register all codecs */
#if PJMEDIA_HAS_G711_CODEC
    CHECK( pjmedia_codec_g711_init(mept) );
#endif
#if PJMEDIA_HAS_GSM_CODEC
    CHECK( pjmedia_codec_gsm_init(mept) );
#endif
#if PJMEDIA_HAS_ILBC_CODEC
    CHECK( pjmedia_codec_ilbc_init(mept, 30) );
#endif
#if PJMEDIA_HAS_SPEEX_CODEC
    CHECK( pjmedia_codec_speex_init(mept, 0, 5, 5) );
#endif
#if PJMEDIA_HAS_G722_CODEC
    CHECK( pjmedia_codec_g722_init(mept) );
#endif

    pj_gettimeofday(&t0);
    status = enc_dec_test(argv[1], argv[2], argv[3]);
    pj_gettimeofday(&t1);
    PJ_TIME_VAL_SUB(t1, t0);

    pjmedia_endpt_destroy(mept);
    pj_caching_pool_destroy(&cp);
    pj_shutdown();

    if (status == PJ_SUCCESS) {
	puts("");
	puts("Success");
	printf("Duration: %ds.%03d\n", file_msec_duration/1000, 
				       file_msec_duration%1000);
	printf("Time: %lds.%03ld\n", t1.sec, t1.msec);
    }

    return 0;
}
Example #21
0
/*
 * NAME:
 * fmgeo2ucs
 *
 * PURPOSE:
 * Computes User Coordinate Values (northings, eastings) from geographical
 * latitude, longitude.
 *
 * REQUIREMENTS:
 *
 * INPUT:
 *
 * OUTPUT:
 *
 * NOTES:
 *
 * BUGS:
 *
 * AUTHOR:
 * Øystein Godøy, met.no/FOU, 10.01.2005 
 *
 * MODIFIED:
 * NA
 */
fmucspos fmgeo2ucs(fmgeopos ll, fmprojspec myproj) {

    fmucspos xy;
    PJ *ref;
    projUV cnat;

    /*
     * Select predefined projection, and initialize interface to PROJ
     */
    if (myproj == MI) {
	if (!(ref=pj_init(sizeof(miproj)/sizeof(char *), miproj))) {
	    fprintf(stderr,"ERROR: PROJ initialization failed.\n");
	}
    } else if (myproj == MEOS) {
	if (!(ref=pj_init(sizeof(meosproj)/sizeof(char *), meosproj))) {
	    fprintf(stderr,"ERROR: PROJ initialization failed.\n");
	}
    } else {
	fprintf(stdout,"ERROR: Projection not supported\n");
    }

    /*
     * Estimate xy
     */
    cnat.u = (ll.lon)*DEG_TO_RAD;
    cnat.v = (ll.lat)*DEG_TO_RAD;
    cnat = pj_fwd(cnat,ref);
    xy.eastings = cnat.u;
    xy.northings = cnat.v;
    /*
    printf(" ll2xy (lat/lon): %.2f %.2f %.2f %.2f\n", 
	    ll.lat, ll.lon, xy.x, xy.y);
    */
    if (cnat.u == HUGE_VAL) {
	fprintf(stderr, "ERROR: pj_fwd conversion\n");
    }
    pj_free(ref);

    return(xy);
}
Example #22
0
int GTIFProj4ToLatLong( GTIFDefn * psDefn, int nPoints,
                        double *padfX, double *padfY )

{
    char	*pszProjection, **papszArgs;
    PJ		*psPJ;
    int		i;
    
/* -------------------------------------------------------------------- */
/*      Get a projection definition.                                    */
/* -------------------------------------------------------------------- */
    pszProjection = GTIFGetProj4Defn( psDefn );

    if( pszProjection == NULL )
        return FALSE;

/* -------------------------------------------------------------------- */
/*      Parse into tokens for pj_init(), and initialize the projection. */
/* -------------------------------------------------------------------- */
    
    papszArgs = CSLTokenizeStringComplex( pszProjection, " +", TRUE, FALSE );
    free( pszProjection );

    psPJ = pj_init( CSLCount(papszArgs), papszArgs );

    CSLDestroy( papszArgs );

    if( psPJ == NULL )
    {
        return FALSE;
    }

/* -------------------------------------------------------------------- */
/*      Process each of the points.                                     */
/* -------------------------------------------------------------------- */
    for( i = 0; i < nPoints; i++ )
    {
        UV	sUV;

        sUV.u = padfX[i];
        sUV.v = padfY[i];

        sUV = pj_inv( sUV, psPJ );

        padfX[i] = sUV.u * RAD_TO_DEG;
        padfY[i] = sUV.v * RAD_TO_DEG;
    }

    pj_free( psPJ );

    return TRUE;
}
Example #23
0
int main() {
    pj_caching_pool cp;
    pj_caching_pool_init(&cp, NULL, 4000);
    CHECK(__FILE__, pj_init());
    pjmedia_endpt *endpoint;
    pjmedia_endpt_create(&cp.factory, NULL, 1, &endpoint);
    //pjmedia_codec_register_audio_codecs(endpoint, NULL);
    pjmedia_codec_g711_init(endpoint);
    list_codecs(endpoint);
    pjmedia_codec_g711_deinit();
    list_codecs(endpoint);
    return 0;
}
Example #24
0
int main()
{
    pj_status_t rc;
    
    // Error handling is omited for clarity.
    
    rc = pj_init();

    rc = pj_exception_id_alloc("No Memory", &NO_MEMORY);
    rc = pj_exception_id_alloc("Other Exception", &OTHER_EXCEPTION);
    
    return test_exception();
}
Example #25
0
PJ *
pj_init_plus( const char *definition )

{
#define MAX_ARG 200
    char	*argv[MAX_ARG];
    char	*defn_copy;
    int		argc = 0, i;
    PJ	        *result;
    
    /* make a copy that we can manipulate */
    defn_copy = (char *) pj_malloc( strlen(definition)+1 );
    strcpy( defn_copy, definition );

    /* split into arguments based on '+' and trim white space */

    for( i = 0; defn_copy[i] != '\0'; i++ )
    {
        switch( defn_copy[i] )
        {
          case '+':
            if( i == 0 || defn_copy[i-1] == '\0' )
            {
                if( argc+1 == MAX_ARG )
                {
                    pj_errno = -44;
                    return NULL;
                }
                
                argv[argc++] = defn_copy + i + 1;
            }
            break;

          case ' ':
          case '\t':
          case '\n':
            defn_copy[i] = '\0';
            break;

          default:
            /* do nothing */;
        }
    }

    /* perform actual initialization */
    result = pj_init( argc, argv );

    pj_dalloc( defn_copy );

    return result;
}
Example #26
0
int main() {
    
    status = pj_init();
    pj_caching_pool_init(&cp, NULL, 1024);
    pool = pj_pool_create(&cp.factory, "pool", 6400, 6400, NULL);

    app_logging_init();
    PJ_LOG(3, (__FILE__, "zzzzzz %d", 5));
    PJ_LOG(4, (__FILE__, "mmmmmm"));

    app_logging_shutdown();   

    return 0;
}
Example #27
0
static pj_status_t init_stack(void)
{
    pj_status_t status;

    /* Must init PJLIB first: */
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);


    /* Then init PJLIB-UTIL: */
    status = pjlib_util_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);


    /* Must create a pool factory before we can allocate any memory. */
    pj_caching_pool_init(&global.cp, &pj_pool_factory_default_policy, 0);

    /* Create the endpoint: */
    status = pjsip_endpt_create(&global.cp.factory, NULL, &global.endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);

    /* Init transaction layer for stateful proxy only */
#if STATEFUL
    status = pjsip_tsx_layer_init_module(global.endpt);
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
#endif

    /* Create listening transport */
    {
        pj_sockaddr_in addr;

        addr.sin_family = pj_AF_INET();
        addr.sin_addr.s_addr = 0;
        addr.sin_port = pj_htons((pj_uint16_t)global.port);

        status = pjsip_udp_transport_start( global.endpt, &addr,
                                            NULL, 1, NULL);
        if (status != PJ_SUCCESS)
            return status;
    }

    /* Create pool for the application */
    global.pool = pj_pool_create(&global.cp.factory, "proxyapp",
                                 4000, 4000, NULL);

    /* Register the logger module */
    pjsip_endpt_register_module(global.endpt, &mod_msg_logger);

    return PJ_SUCCESS;
}
Example #28
0
static int test_inner(void)
{
    pj_caching_pool caching_pool;
    int rc = 0;

    mem = &caching_pool.factory;

    pj_log_set_level(3);
    pj_log_set_decor(param_log_decor);

    rc = pj_init();
    if (rc != 0) {
	app_perror("pj_init() error!!", rc);
	return rc;
    }

    rc = pjlib_util_init();
    pj_assert(rc == 0);

    pj_dump_config();
    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );

#if INCLUDE_XML_TEST
    DO_TEST(xml_test());
#endif

#if INCLUDE_JSON_TEST
    DO_TEST(json_test());
#endif

#if INCLUDE_ENCRYPTION_TEST
    DO_TEST(encryption_test());
    DO_TEST(encryption_benchmark());
#endif

#if INCLUDE_STUN_TEST
    DO_TEST(stun_test());
#endif

#if INCLUDE_RESOLVER_TEST
    DO_TEST(resolver_test());
#endif

#if INCLUDE_HTTP_CLIENT_TEST
    DO_TEST(http_client_test());
#endif

on_return:
    return rc;
}
Example #29
0
projPJ
lwproj_from_string(const char *str1)
{
	int t;
	char *params[1024];  /* one for each parameter */
	char *loc;
	char *str;
	size_t slen;
	projPJ result;


	if (str1 == NULL) return NULL;

	slen = strlen(str1);

	if (slen == 0) return NULL;

	str = lwalloc(slen+1);
	strcpy(str, str1);

	/*
	 * first we split the string into a bunch of smaller strings,
	 * based on the " " separator
	 */

	params[0] = str; /* 1st param, we'll null terminate at the " " soon */

	loc = str;
	t = 1;
	while  ((loc != NULL) && (*loc != 0) )
	{
		loc = strchr(loc, ' ');
		if (loc != NULL)
		{
			*loc = 0; /* null terminate */
			params[t] = loc+1;
			loc++; /* next char */
			t++; /*next param */
		}
	}

	if (!(result=pj_init(t, params)))
	{
		lwfree(str);
		return NULL;
	}
	lwfree(str);
	return result;
}
Example #30
0
int main()
{
    pj_turn_srv *srv;
    pj_turn_listener *listener;
    pj_status_t status;

    status = pj_init();
    if (status != PJ_SUCCESS)
	return err("pj_init() error", status);

    pjlib_util_init();
    pjnath_init();

    pj_caching_pool_init(&g_cp, NULL, 0);

    pj_turn_auth_init(REALM);

    status = pj_turn_srv_create(&g_cp.factory, &srv);
    if (status != PJ_SUCCESS)
	return err("Error creating server", status);

    status = pj_turn_listener_create_udp(srv, pj_AF_INET(), NULL, 
					 TURN_PORT, 1, 0, &listener);
    if (status != PJ_SUCCESS)
	return err("Error creating UDP listener", status);

#if PJ_HAS_TCP
    status = pj_turn_listener_create_tcp(srv, pj_AF_INET(), NULL, 
					 TURN_PORT, 1, 0, &listener);
    if (status != PJ_SUCCESS)
	return err("Error creating listener", status);
#endif

    status = pj_turn_srv_add_listener(srv, listener);
    if (status != PJ_SUCCESS)
	return err("Error adding listener", status);

    puts("Server is running");

    pj_log_set_level(LOG_LEVEL);

    console_main(srv);

    pj_turn_srv_destroy(srv);
    pj_caching_pool_destroy(&g_cp);
    pj_shutdown();

    return 0;
}