sip事件
//与摄像头进行消息交换的主线程
static void *MsgProcess(gb28181_context *gc)
{
struct eXosip_t * excontext = gc->eCtx; //监听5060端口的对象
gc->running = 1;
eXosip_event_t *je = NULL;//event //监听并回复摄像头消息
osip_message_t *answer = NULL;
osip_message_t *ack = NULL;
int result = OSIP_SUCCESS;
while (gc->running)
{
//处理事件
je = eXosip_event_wait(excontext, 0, 200);
if (je == NULL)
{
continue;
}
switch (je->type)
{
case EXOSIP_MESSAGE_NEW:
if (MSG_IS_REGISTER(je->request))
{
osip_contact_t* contact = NULL;
osip_to_t *to = NULL;
osip_message_get_contact(je->request, 0, &contact);
to = osip_message_get_to(je->request);
if (contact != NULL && to != NULL)
{
printf("=======================REGISTER==============================\n");
printf("REGISTER:from: <sip: %s@%s:%s>\n", je->request->from->url->username, je->request->from->url->host, je->request->from->url->port);
printf("REGISTER:to: <sip: %s@%s:%s>\n", to->url->username, to->url->host, to->url->port);
printf("REGISTER:contact: <sip: %s@%s:%s>\n", contact->url->username, contact->url->host, contact->url->port);
printf("=======================REGISTER==============================\n");
//按照规则,需要回复OK信息
eXosip_message_build_answer(excontext, je->tid, 200, &answer);
eXosip_message_send_answer(excontext, je->tid, 200, answer);
//将注册上来的摄像头添加到map中
//Sub_Platform* Camera = new Sub_Platform();
//Global_CameraMap.insert(make_pair(je->request->from->url->username, Camera));
//现在是直接请求摄像头数据,后面实现点播。
sendInvitePlay(contact->url->username, contact->url->host, contact->url->port, gc->revVideoPort, gc);
}
else
{
return NULL;
}
}
else if (MSG_IS_MESSAGE(je->request))
{
{
osip_body_t *body;
osip_message_get_body(je->request, 0, &body);
//printf("I get the msg is: %s\n", body->body);
//printf ("the cid is %s, did is %s\n", je->did, je->cid);
}
//按照规则,需要回复OK信息
eXosip_lock(excontext);
eXosip_message_build_answer(excontext, je->tid, 200, &answer);
eXosip_message_send_answer(excontext, je->tid, 200, answer);
eXosip_unlock(excontext);
}
break;
case EXOSIP_CALL_PROCEEDING: //收到100 trying消息,表示请求正在处理中
{
std::printf("recv EXOSIP_CALL_PROCEEDING\n");
//RegisterSuccess(peCtx, je);
eXosip_lock(excontext);
eXosip_message_build_answer(excontext, je->tid, 200, &answer);
eXosip_message_send_answer(excontext, je->tid, 200, answer);
eXosip_unlock(excontext);
break;
}
case EXOSIP_CALL_RINGING: //收到180 Ringing应答,表示接收到INVITE请求的UAS正在向被叫用户振铃
{
printf("ringing!\n");
//printf("EXOSIP_CALL_RINGING tid %d,call_id is %d,dialog_id is %d \n", je->tid, je->cid, je->did);
break;
}
case EXOSIP_CALL_ACK:
printf("ACK recieved!\n");
// printf ("the cid is %s, did is %s/n", je->did, je->cid);
break;
case EXOSIP_CALL_ANSWERED://收到200 OK,表示请求已经被成功接受,摄像头应答
//printf("the cid is %s, did is %s/n", je->did, je->cid);
eXosip_lock(excontext);
eXosip_call_build_ack(excontext, je->did, &ack);//回应ack应答
eXosip_call_send_ack(excontext, je->did, ack);
eXosip_unlock(excontext);
printf("EXOSIP_CALL_ANSWERED t_id %d call_id is %d,dialog_id is %d \n", je->tid, je->cid, je->did);
break;
case EXOSIP_CALL_CLOSED:
printf("the remote close the session!\n");
result = eXosip_call_build_answer(excontext, je->tid, 200, &answer);
if (result != OSIP_SUCCESS)
{
printf("This request msg is invalid!Cann't response!\n");
eXosip_call_send_answer(excontext, je->tid, 400, NULL);
}
else
{
eXosip_call_send_answer(excontext, je->tid, 200, answer);
printf("bye send 200 over!\n");
}
break;
case EXOSIP_CALL_MESSAGE_NEW:
printf(" EXOSIP_CALL_MESSAGE_NEW\n");
if (MSG_IS_INFO(je->request)) //如果传输的是INFO方法
{
eXosip_lock(excontext);
result = eXosip_call_build_answer(excontext, je->tid, 200, &answer);
if (result == OSIP_SUCCESS)
{
eXosip_call_send_answer(excontext, je->tid, 200, answer);
}
eXosip_unlock(excontext);
{
osip_body_t *body;
osip_message_get_body(je->request, 0, &body);
//printf("the body is %s\n", body->body);
}
}
break;
default:
osip_body_t *body;
osip_message_get_body(je->request, 0, &body);
printf("Could not parse the msg!\n"); //程序异常退出
printf("%s",body->body);
eXosip_lock(excontext);
eXosip_message_build_answer(excontext, je->tid, 200, &answer);
eXosip_message_send_answer(excontext, je->tid, 200, answer);
eXosip_unlock(excontext);
}
eXosip_event_free(je);
je = NULL;
}
return NULL;
}