Beispiel #1
0
static int 
platform_cleanup_service(struct service_template *self)
{
    plt_service_basic_t *plt_basic;
    NMP_ASSERT(self);

    plt_basic = (plt_service_basic_t*)self;
    destory_2lp_net_object(plt_basic->_2lp_net);
    nmp_del(plt_basic->pack_opt, packet_opt_t, 1);
    plt_basic->pack_opt = NULL;
    rtsp_server_free(plt_basic->rtsp_srv);
    talk_server_free(plt_basic->talk_srv);
    return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	struct event_base *base = NULL;

	struct event *sigint_event = NULL;
	struct event *sigterm_event = NULL;
	
	struct rtsp_server_param rs_param;
	struct rtsp_server *rs = NULL;

    slog_init(SLOG_DEBUG);

	/* create event base */
	base = event_base_new();
	if (!base) {
		SLOG(SLOG_ERROR, "failed to create event base");
		return -1;
	}
	
	/* install signal handle */
	sigint_event = evsignal_new(base, SIGINT, signal_quit_cb, (void *)base);
	if (!sigint_event) {
		SLOG(SLOG_ERROR, "failed to create sigint event");
		goto failed;
	}
	sigterm_event = evsignal_new(base, SIGTERM, signal_quit_cb, (void *)base);
	if (!sigterm_event) {
		SLOG(SLOG_ERROR, "failed to create sigterm event");
		goto failed;
	}
	event_add(sigint_event, NULL);
	event_add(sigterm_event, NULL);

	/* init rtsp-server param */
	rs_param.port = 8554;
	rs_param.enable_http_tunnel = 1;
	rs_param.http_tunnel_port = 8080;
	rs_param.udp_port_range[0] = 20000;
	rs_param.udp_port_range[1] = 30000;
	rs_param.max_sessions = 10;

	/* start up rtsp-server */
	rs = rtsp_server_new(base, &rs_param);
	if (!rs) {
		SLOG(SLOG_ERROR, "failed to create rtsp server");
		goto failed;
	}
	
	/* start eventloop */
	event_base_dispatch(base);
	/* fall throught when normal exit */

    SLOG(SLOG_NOTICE, "server exit");
failed:
	if (rs)
		rtsp_server_free(rs);
	
	/* uninstall signal handler */
	if (sigterm_event)
		evsignal_del(sigterm_event);
	if (sigint_event)
		evsignal_del(sigint_event);
	
	if (base)
		event_base_free(base);

	return 0;
}
Beispiel #3
0
static int 
platform_init_service(struct service_template *self)
{
    proxy_config_t cfg;
    plt_service_basic_t *plt_basic;
    NMP_ASSERT(self);

    plt_basic = (plt_service_basic_t*)self;

    plt_basic->_2lp_net = create_2lp_net_object(establish_io, finalize_io);
    if (!plt_basic->_2lp_net)
        goto NET_ERROR;

    plt_basic->pack_opt = nmp_new(packet_opt_t, 1);
    if (plt_basic->pack_opt)
    {
        memcpy((void*)plt_basic->pack_opt, &pkt_opt, sizeof(pkt_opt));
        plt_basic->pack_opt->proto.init_data = (void*)plt_basic;//Here, it's for establish_io, but never dispatch.
    }
    else
        goto PACKE_ERROR;

    plt_basic->rtsp_srv = rtsp_server_new();
    if (plt_basic->rtsp_srv)
    {
        get_proxy_config(&cfg);
        register_stream_operations(&strm_api);
        rtsp_server_set_port(plt_basic->rtsp_srv, (gint)cfg.rtsp_port);

        if (rtsp_server_bind_port(plt_basic->rtsp_srv))
        {
            show_warn("rtsp_server_bind_port fail!\n");
            rtsp_server_free(plt_basic->rtsp_srv);
            goto RTSP_ERROR;
        }
    }
    else
        goto RTSP_ERROR;

    plt_basic->talk_srv = talk_server_new();
    if(plt_basic->talk_srv)
    {
        register_talk_ops(&talk_api);
        if (0 > talk_server_start(plt_basic->talk_srv, TALK_PORT))
        {
            show_warn("talk_server_start fail!\n");
            talk_server_free(plt_basic->talk_srv);
            goto TALK_ERROR;
        }
    }
    else
        goto TALK_ERROR;

    plt_basic->plt_me = create_msg_engine(FALSE, 16);
    register_all_msg_handlers(plt_basic->plt_me);
    return 0;

NET_ERROR:
    return -1;

PACKE_ERROR:
    destory_2lp_net_object(plt_basic->_2lp_net);
    return -1;

RTSP_ERROR:
    destory_2lp_net_object(plt_basic->_2lp_net);
    nmp_del(plt_basic->pack_opt, packet_opt_t, 1);
    plt_basic->pack_opt = NULL;
    return -1;

TALK_ERROR:
    destory_2lp_net_object(plt_basic->_2lp_net);
    nmp_del(plt_basic->pack_opt, packet_opt_t, 1);
    plt_basic->pack_opt = NULL;
    rtsp_server_free(plt_basic->rtsp_srv);
    return -1;
}