Пример #1
0
void onDidConnect(RTSPCubemapSourceClient* client, CubemapSource* cubemapSource)
{
    if (typeid(cubemapSource) == typeid(H264CubemapSource))
    {
        H264CubemapSource* h264CubemapSource = (H264CubemapSource*)cubemapSource;
        
        h264CubemapSource->setOnReceivedNALU       (boost::bind(&onReceivedNALU,        _1, _2, _3, _4));
        h264CubemapSource->setOnReceivedFrame      (boost::bind(&onReceivedFrame,       _1, _2, _3, _4));
        h264CubemapSource->setOnDecodedFrame       (boost::bind(&onDecodedFrame,        _1, _2, _3, _4));
        h264CubemapSource->setOnColorConvertedFrame(boost::bind(&onColorConvertedFrame, _1, _2, _3, _4));
    }
    
    stats.autoSummary(boost::chrono::seconds(10),
					  AlloReceiver::statValsMaker,
					  AlloReceiver::postProcessorMaker,
					  AlloReceiver::formatStringMaker);
    
    ::cubemapSource = cubemapSource;
    
    barrier.wait();
}
Пример #2
0
int main(int argc, char* argv[])
{
	try
	{
		if (argc < 5)
		{
			std::cerr << "Usage: receiver <listen_address> <multicast_address> <stats interval> <port>+" << std::endl;
			return 1;
		}

		std::vector<short> ports;
		for (int i = 4; i < argc; i++)
		{
			ports.push_back(atoi(argv[i]));
		}

		boost::asio::ip::address listen_address    = boost::asio::ip::address::from_string(argv[1]);
		boost::asio::ip::address multicast_address = boost::asio::ip::address::from_string(argv[2]);
		size_t statsInterval = atoi(argv[3]);

		std::stringstream ss;
		std::copy(ports.begin(), ports.end(), std::ostream_iterator<short>(ss, ", "));

		std::cout << "Monitoring packets from " << multicast_address.to_string() <<
			" with port(s) " << ss.str().substr(0, ss.str().length() - 2) <<
			" on interface address " << listen_address.to_string() << std::endl;

		std::vector<receiver*> receivers;
		std::vector<boost::asio::io_service*> io_services;

		for (int i = 0; i < ports.size(); i++)
		{
			io_services.push_back(new boost::asio::io_service());
			receivers.push_back(new receiver(*io_services[i],
				                         boost::asio::ip::address::from_string(argv[1]),
				                         boost::asio::ip::address::from_string(argv[2]),
				                         ports[i],
				                         i));
		}

		stats.autoSummary(boost::chrono::seconds(statsInterval),
			              AlloReceiver::statValsMaker,
						  AlloReceiver::postProcessorMaker,
						  AlloReceiver::formatStringMaker);

		std::vector<boost::thread> io_threads;

		for (boost::asio::io_service* io_service : io_services)
		{
			io_threads.push_back(boost::thread(boost::bind(&boost::asio::io_service::run, io_service)));
		}

		for (boost::thread& io_thread : io_threads)
		{
			io_thread.join();
		}
	}
	catch (std::exception& e)
	{
		std::cerr << "Exception: " << e.what() << "\n";
	}

	return 0;
}
Пример #3
0
int main(int argc, char* argv[])
{
    boost::program_options::options_description desc("");
	desc.add_options()
		("multicast-address", boost::program_options::value<std::string>(),     "")
		("interface",         boost::program_options::value<std::string>(),     "")
		("rtsp-port",         boost::program_options::value<boost::uint16_t>(), "")
		("avg-bit-rate",      boost::program_options::value<int>(),             "")
		("buffer-size",       boost::program_options::value<size_t>(),          "")
	    ("stats-interval",    boost::program_options::value<size_t>(),          "");
		
    
    boost::program_options::variables_map vm;
    boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
    boost::program_options::notify(vm);

    if (vm.count("interface"))
    {
        std::string interfaceAddress = vm["interface"].as<std::string>();
        NetAddressList addresses(interfaceAddress.c_str());
        if (addresses.numAddresses() == 0)
        {
            std::cout << "Failed to find network address for \"" << interfaceAddress << "\"" << std::endl;
            return -1;
        }
        ReceivingInterfaceAddr = *(unsigned*)(addresses.firstAddress()->data());
    }
    
    char sourceAddressStr[INET_ADDRSTRLEN];
    inet_ntop(AF_INET, &(ReceivingInterfaceAddr), sourceAddressStr, sizeof(sourceAddressStr));
    std::cout << "Using source address " << sourceAddressStr << std::endl;
    
    if (vm.count("rtsp-port"))
    {
        rtspPort = vm["rtsp-port"].as<boost::uint16_t>();
    }
    else
    {
        rtspPort = 8555;
    }
    std::cout << "Using RTSP port " << rtspPort << std::endl;
    
    // Create 'groupsocks' for RTP and RTCP:
    if(vm.count("multicast-address"))
    {
        inet_pton(AF_INET, vm["multicast-address"].as<std::string>().c_str(), &(destinationAddress.s_addr));
    }
    else
    {
        inet_pton(AF_INET, "224.0.67.67", &(destinationAddress.s_addr));
    }

	if (vm.count("avg-bit-rate"))
	{
		avgBitRate = vm["avg-bit-rate"].as<int>();
	}
	else
	{
		avgBitRate = DEFAULT_AVG_BIT_RATE;
	}
    std::string bitRateString = to_human_readable_byte_count(avgBitRate, true, false);
	std::cout << "Using an average encoding bit rate of " << bitRateString << "/s per face" << std::endl;

	if (vm.count("buffer-size"))
	{
		bufferSize = vm["buffer-size"].as<size_t>();
	}
	else
	{
		bufferSize = DEFAULT_BUFFER_SIZE;
	}
	std::string bufferSizeString = to_human_readable_byte_count(bufferSize, false, false);
	std::cout << "Using a buffer size of " << bufferSizeString << std::endl;

	size_t statsInterval;
	if (vm.count("stats-interval"))
	{
		statsInterval = vm["stats-interval"].as<size_t>();
	}
	else
	{
		statsInterval = DEFAULT_STATS_INTERVAL;
	}

    av_log_set_level(AV_LOG_WARNING);
    avcodec_register_all();
    setupRTSP();
    boost::thread networkThread = boost::thread(&networkLoop);

	

    Process unityProcess(CUBEMAPEXTRACTIONPLUGIN_ID, false);
	Process thisProcess(ALLOSERVER_ID, true);

    while (true)
    {
        std::cout << "Waiting for Unity ..." << std::endl;
        unityProcess.waitForBirth();
        std::cout << "Connected to Unity :)" << std::endl;
        startStreaming();
		stats.autoSummary(boost::chrono::seconds(statsInterval),
			              AlloReceiver::statValsMaker,
						  AlloReceiver::postProcessorMaker,
						  AlloReceiver::formatStringMaker);
        unityProcess.join();
        std::cout << "Lost connection to Unity :(" << std::endl;
        stopStreaming();
		stats.stopAutoSummary();
    }

    return 0;
}