• ortp 发送RTP实例


    参考源代码目录src/tests/rtpsend.c

    
        ortp_init();
        ortp_scheduler_init();
        ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
        session=rtp_session_new(RTP_SESSION_SENDONLY);
        rtp_session_set_local_addr(session,"192.168.1.16",10000,10001);
        rtp_session_set_scheduling_mode(session,1);
        rtp_session_set_blocking_mode(session,1);
        //rtp_session_set_connected_mode(session,TRUE);
        rtp_session_set_connected_mode(session,0);
        rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
        rtp_session_set_payload_type(session,8);
    
        ssrc=getenv("SSRC");
        if (ssrc!=NULL) {
            printf("using SSRC=%i.
    ",atoi(ssrc));
            rtp_session_set_ssrc(session,atoi(ssrc));
        }
        rtp_session_set_ssrc(session,0);
    
        infile=fopen(argv[1],"r");
        if (infile==NULL) {
            perror("Cannot open file");
            return -1;
        }
    
        signal(SIGINT,stophandler);
        while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
        {
            rtp_session_send_with_ts(session,buffer,i,user_ts);
            user_ts+=160;
            if (clockslide!=0 && user_ts%(160*50)==0){
                ortp_message("Clock sliding of %i miliseconds now",clockslide);
                rtp_session_make_time_distorsion(session,clockslide);
            }
            /*this will simulate a burst of late packets */
            if (jitter && (user_ts%(8000)==0)) {
                struct timespec pausetime, remtime;
                ortp_message("Simulating late packets now (%i milliseconds)",jitter);
                pausetime.tv_sec=jitter/1000;
                pausetime.tv_nsec=(jitter%1000)*1000000;
                while(nanosleep(&pausetime,&remtime)==-1 && errno==EINTR){
                    pausetime=remtime;
                }
            }
        }
    
        fclose(infile);
        rtp_session_destroy(session);
        ortp_exit();
        ortp_global_stats_display();
    
    

    代码解读:

    1、如果不手动调用rtp_session_set_local_addr设置本地RTP IP/PORT和RTCP PORT,ortp会自动选择可用端口;

    2、rtp_session_set_connected_mode设置连接模式,如果为1,会根据RTCP判断是否连接上;

    3、上述代码是发送PCM A/U律代码,rtp_session_set_payload_type设置编码格式;

    4、支持多线程;

  • 相关阅读:
    eclipse fail to create java virtual machine
    sas软件连接Oracle数据库的办法
    JAVA中数据的读取与写入,不同类型数据的转换
    二维数组的在函数中的传递
    【转】值传递与引用传递
    【转】深拷贝与浅拷贝
    (转)JS报表控件highcharts应用
    highstocks.js使用指南
    (转)Highcharts使用指南(出处:http://liuhaorain.cnblogs.com )
    jQuery实现checkbox全选,反选
  • 原文地址:https://www.cnblogs.com/cqvoip/p/8078944.html
Copyright © 2020-2023  润新知