• 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、支持多线程;

  • 相关阅读:
    Unity3D读取assetbundle
    Unity3D 发布成exe之后黑屏
    Unity3D优化总结
    Unity3D中中 rect[2] == rt->GetGLWidth() && rect[3] == rt->GetGLHeight()错误的原因及解决方法
    C# mysql 插入数据,中文乱码的解决方法
    WPF Canvas做自动缩放时获取控件的实际高度
    面向对象
    常用模块介绍
    python异常处理,多线程,多进程
    python生成器,递归调用
  • 原文地址:https://www.cnblogs.com/cqvoip/p/8078944.html
Copyright © 2020-2023  润新知