Revision cfea12a9 plugins/janus_sip.c

View differences:

plugins/janus_sip.c
2380 2380
			JANUS_LOG(LOG_VERB, "[%s][%s]: %d %s\n", session->account.username, nua_event_name(event), status, phrase ? phrase : "??");
2381 2381
			
2382 2382
			if(status < 200) {
2383
				if (status == 183 || status == 180){
2384
					/* SIP/SDP Offer/Answer can get very complex depending on your specific scenario
2385
					 * This fix for early media considers Use case #1 and #2. Refer to URL below.
2386
					 * http://sofia-sip.sourceforge.net/refdocs/soa/soa_sdp_oa_use_cases.html
2387
					 */
2388

  
2389
					if(ssip == NULL) {
2390
						break;
2391
					}
2392
					sdp_parser_t *parser = sdp_parse(ssip->s_home, sip->sip_payload->pl_data, sip->sip_payload->pl_len, 0);
2393
					if(!sdp_session(parser)) {
2394
						sdp_parser_free(parser);
2395
						break;
2396
					}
2397
					
2398
					/* Parse SDP */
2399
					JANUS_LOG(LOG_VERB, "Sending early media:\n%s", sip->sip_payload->pl_data);
2400
					
2401
					char *fixed_sdp = g_strdup(sip->sip_payload->pl_data);
2402
					sdp_session_t *sdp = sdp_session(parser);
2403
					janus_sip_sdp_process(session, sdp);
2404
					/* If we asked for SRTP and are not getting it, fail */
2405
					if(session->media.require_srtp && !session->media.has_srtp_remote) {
2406
						JANUS_LOG(LOG_ERR, "\tWe asked for mandatory SRTP but didn't get any in the reply, ignoring until status 200.\n");
2407
						sdp_parser_free(parser);
2408
						g_free(fixed_sdp);
2409
						break;
2410
					}
2411
					session->media.ready = 1;	/* FIXME Maybe we need a better way to signal this */
2412
					GError *error = NULL;
2413
					g_thread_try_new("Early media janus rtp handler", janus_sip_relay_thread, session, &error);
2414
					if(error != NULL) {
2415
						JANUS_LOG(LOG_ERR, "Early media got error %d (%s) trying to launch the RTP/RTCP thread...\n", error->code, error->message ? error->message : "??");
2416
					}
2417
					/* Send SDP to the browser */
2418
					json_t *call = json_object();
2419
					json_object_set_new(call, "sip", json_string("event"));
2420
					json_t *calling = json_object();
2421
					json_object_set_new(calling, "event", json_string("ringing"));
2422
					json_object_set_new(calling, "username", json_string(session->callee));
2423
					json_object_set_new(call, "result", calling);
2424
					char *call_text = json_dumps(call, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
2425
					json_decref(call);
2426
					JANUS_LOG(LOG_VERB, "Early media pushing event to peer: %s\n", call_text);
2427
					int ret = gateway->push_event(session->handle, &janus_sip_plugin, session->transaction, call_text, "answer", fixed_sdp);
2428
					JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
2429
					g_free(call_text);
2430
					g_free(fixed_sdp);
2431
				}
2432

  
2383
				/* Not ready yet (FIXME May this be pranswer?? we don't handle it yet...) */
2433 2384
				break;
2434 2385
			} else if(status == 401 || status == 407) {
2435 2386
				char auth[256];

Also available in: Unified diff