コード例 #1
0
void
AudioRtpSession::start(std::unique_ptr<IceSocket> rtp_sock, std::unique_ptr<IceSocket> rtcp_sock)
{
    std::lock_guard<std::recursive_mutex> lock(mutex_);

    if (not send_.enabled and not receive_.enabled) {
        stop();
        return;
    }

    try {
        if (rtp_sock and rtcp_sock)
            socketPair_.reset(new SocketPair(std::move(rtp_sock), std::move(rtcp_sock)));
        else
            socketPair_.reset(new SocketPair(getRemoteRtpUri().c_str(), receive_.addr.getPort()));

        if (send_.crypto and receive_.crypto) {
            socketPair_->createSRTP(receive_.crypto.getCryptoSuite().c_str(),
                                    receive_.crypto.getSrtpKeyInfo().c_str(),
                                    send_.crypto.getCryptoSuite().c_str(),
                                    send_.crypto.getSrtpKeyInfo().c_str());
        }
    } catch (const std::runtime_error& e) {
        RING_ERR("Socket creation failed: %s", e.what());
        return;
    }

    startSender();
    startReceiver();
}
コード例 #2
0
void
AudioRtpSession::restartReceiver()
{
    std::lock_guard<std::recursive_mutex> lock(mutex_);
    // ensure that start has been called before restart
    if (not socketPair_)
        return;

    startReceiver();
}
コード例 #3
0
ファイル: udp-receiver.c プロジェクト: elisescu/udpcast
int main(int argc, char **argv)
#endif
{
    int ret;
    char *ptr;
    struct net_config net_config;
    struct disk_config disk_config;
    struct stat_config stat_config;
    int c;
    int doWarn=0;
    char *ifName=NULL;

#ifdef LOSSTEST
    int seedSet = 0;
    int printSeed = 0;
#endif

#ifdef SIG_UNBLOCK
    atexit(signalForward);
#endif

    disk_config.fileName=NULL;
    disk_config.pipeName=NULL;
    disk_config.flags = 0;

    net_config.portBase = 9000;
    net_config.ttl = 1;
    net_config.flags = 0;
    net_config.mcastRdv = NULL;
    net_config.exitWait = 500;
    net_config.startTimeout = 0;
    net_config.receiveTimeout = 0;

    stat_config.statPeriod = DEFLT_STAT_PERIOD;
    stat_config.printUncompressedPos = -1;
    stat_config.noProgress = 0;

#ifdef WINDOWS
    /* windows is basically unusable with its default buffer size of 8k...*/
    net_config.requestedBufSize = 1024*1024;
#else
    net_config.requestedBufSize = 0;
#endif

    ptr = strrchr(argv[0], '/');
    if(!ptr)
	ptr = argv[0];
    else
	ptr++;
    
    net_config.net_if = NULL;
    if (strcmp(ptr, "init") == 0) {
	doWarn = 1;
	disk_config.pipeName = strdup("/bin/gzip -dc");
	disk_config.fileName = "/dev/hda";
    }
    while( (c=getopt_l(argc, argv, "b:f:p:P:i:l:M:s:t:w:x:z:dkLnyZ")) != EOF ) {
	switch(c) {
	    case 'f':
		disk_config.fileName=optarg;
		break;
	    case 'i':
		ifName=optarg;
		break;
	    case 'p':
		disk_config.pipeName=optarg;
		break;
	    case 'P':
		net_config.portBase = atoi(optarg);
		break;
	    case 'l':
		udpc_log = fopen(optarg, "a");
		break;
	    case 0x701:
		stat_config.noProgress = 1;
		break;
	    case 't': /* ttl */
		net_config.ttl = atoi(optarg);
		break;
	    case 'M':
		net_config.mcastRdv = strdup(optarg);
		break;

#ifdef BB_FEATURE_UDPCAST_FEC
	    case 'L':
		    fec_license();
		    break;
#endif

#ifdef LOSSTEST
	    case 0x601:
		setWriteLoss(optarg);
		break;
	    case 0x602:
		setReadLoss(optarg);
		break;
	    case 0x603:
		seedSet=1;
		srandom(strtoul(optarg,0,0));
		break;
	    case 0x604:
		printSeed=1;
		break;
	    case 0x605:
		setReadSwap(optarg);
		break;
#endif
	    case 'd': /* passive */
		net_config.flags|=FLAG_PASSIVE;
		break;
	    case 'n': /* nosync */
		disk_config.flags|=FLAG_NOSYNC;
		break;
	    case 'y': /* sync */
		disk_config.flags|=FLAG_SYNC;
		break;
	    case 'b': /* rcvbuf */
		net_config.requestedBufSize=parseSize(optarg);
		break;
	    case 'k': /* nokbd */
		net_config.flags |= FLAG_NOKBD;
		break;

	    case 'w': /* exit-wait */
		net_config.exitWait = atoi(optarg);
		break;

	    case 's': /* start-timeout */
		net_config.startTimeout = atoi(optarg);		
		break;

	    case 0x801: /* receive-timeout */
		net_config.receiveTimeout = atoi(optarg);
		break;

	    case 'z':
		stat_config.statPeriod = atoi(optarg) * 1000;
		break;
	    case 'x':
		stat_config.printUncompressedPos = atoi(optarg);
		break;

	    case 'Z':
		net_config.flags |= FLAG_IGNORE_LOST_DATA;
		break;

	    case '?':
#ifndef NO_BB
	        bb_show_usage();
#else
		usage(argv[0]);
#endif
	}
    }

    fprintf(stderr, "Udp-receiver %s\n", version);

#ifdef LOSSTEST
    if(!seedSet)
	srandomTime(printSeed);
#endif

    signal(SIGINT, intHandler);
#ifdef USE_SYSLOG
    openlog((const char *)"udpcast", LOG_NDELAY|LOG_PID, LOG_SYSLOG);
#endif
    
    ret= startReceiver(doWarn, &disk_config, &net_config, &stat_config, ifName);
    if(ret < 0) {
      fprintf(stderr, "Receiver error\n");
    }
    return ret;
}