Example #1
0
void CNetCacheServerListener::OnInit(CObject* api_impl,
    CConfig* config, const string& config_section)
{
    SNetCacheAPIImpl* nc_impl = static_cast<SNetCacheAPIImpl*>(api_impl);

    m_Auth = nc_impl->m_Service->MakeAuthString();

    if (nc_impl->m_Service->m_ServerPool->m_ClientName.length() < 3) {
        NCBI_THROW(CNetCacheException,
            eAuthenticationError, "Client name is too short or empty");
    }

    const string default_temp_dir(".");

    if (config != NULL) {
        string temp_dir = config->GetString(config_section,
            "tmp_dir", CConfig::eErr_NoThrow, kEmptyStr);

        if (temp_dir.empty())
            temp_dir = config->GetString(config_section,
                "tmp_path", CConfig::eErr_NoThrow, default_temp_dir);

        nc_impl->m_TempDir = temp_dir.empty() ? default_temp_dir : temp_dir;

        nc_impl->m_CacheInput = config->GetBool(config_section,
            "cache_input", CConfig::eErr_NoThrow, false);

        nc_impl->m_CacheOutput = config->GetBool(config_section,
            "cache_output", CConfig::eErr_NoThrow, false);

        string enable_mirroring(config->GetString(config_section,
                "enable_mirroring", CConfig::eErr_NoThrow, kEmptyStr));

        if (enable_mirroring.empty() ||
                NStr::CompareNocase(enable_mirroring, "if_key_mirrored") == 0 ||
                NStr::CompareNocase(enable_mirroring, "on_read") == 0 ||
                NStr::CompareNocase(enable_mirroring, "onread") == 0)
            nc_impl->m_MirroringMode = CNetCacheAPI::eIfKeyMirrored;
        else
            nc_impl->m_MirroringMode = NStr::StringToBool(enable_mirroring) ?
                    CNetCacheAPI::eMirroringEnabled :
                    CNetCacheAPI::eMirroringDisabled;
    } else {
        nc_impl->m_TempDir = default_temp_dir;
        nc_impl->m_CacheInput = false;
        nc_impl->m_CacheOutput = false;
        nc_impl->m_MirroringMode = CNetCacheAPI::eIfKeyMirrored;
    }
}
Example #2
0
int main(int argc, char** argv)
{
    astra::initialize();

    set_key_handler();

#ifdef _WIN32
    auto fullscreenStyle = sf::Style::None;
#else
    auto fullscreenStyle = sf::Style::Fullscreen;
#endif

    const sf::VideoMode fullScreenMode = sf::VideoMode::getFullscreenModes()[0];
    const sf::VideoMode windowedMode(1800, 675);

    bool isFullScreen = false;
    sf::RenderWindow window(windowedMode, "Stream Viewer");

    astra::StreamSet streamSet;
    astra::StreamReader reader = streamSet.create_reader();

    reader.stream<astra::PointStream>().start();

    auto depthStream = configure_depth(reader);
    depthStream.start();

    auto colorStream = configure_color(reader);
    colorStream.start();

    auto irStream = configure_ir(reader, false);

    MultiFrameListener listener;
    listener.set_mode(MODE_COLOR);

    reader.add_listener(listener);

    while (window.isOpen())
    {
        astra_temp_update();

        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
            case sf::Event::Closed:
                window.close();
                break;
            case sf::Event::KeyPressed:
                {
                    switch (event.key.code)
                    {
                    case sf::Keyboard::Escape:
                        window.close();
                        break;
                    case sf::Keyboard::F:
                        if (isFullScreen)
                        {
                            isFullScreen = false;
                            window.create(windowedMode, "Stream Viewer", sf::Style::Default);
                        }
                        else
                        {
                            isFullScreen = true;
                            window.create(fullScreenMode, "Stream Viewer", fullscreenStyle);
                        }
                        break;
                    case sf::Keyboard::R:
                        depthStream.enable_registration(!depthStream.registration_enabled());
                        break;
                    case sf::Keyboard::M:
                        {
                            const bool newMirroring = !depthStream.mirroring_enabled();
                            depthStream.enable_mirroring(newMirroring);
                            colorStream.enable_mirroring(newMirroring);
                            irStream.enable_mirroring(newMirroring);
                        }
                        break;
                    case sf::Keyboard::G:
                        colorStream.stop();
                        configure_ir(reader, false);
                        listener.set_mode(MODE_IR_16);
                        irStream.start();
                        break;
                    case sf::Keyboard::I:
                        colorStream.stop();
                        configure_ir(reader, true);
                        listener.set_mode(MODE_IR_RGB);
                        irStream.start();
                        break;
                    case sf::Keyboard::O:
                        listener.toggle_depth_overlay();
                        if (listener.get_overlay_depth())
                        {
                            depthStream.enable_registration(true);
                        }
                        break;
                    case sf::Keyboard::P:
                        listener.toggle_paused();
                        break;
                    case sf::Keyboard::C:
                        if (event.key.control)
                        {
                            window.close();
                        }
                        else
                        {
                            irStream.stop();
                            listener.set_mode(MODE_COLOR);
                            colorStream.start();
                        }
                        break;
                    default:
                        break;
                    }
                    break;
                }
            default:
                break;
            }
        }

        // clear the window with black color
        window.clear(sf::Color::Black);
        listener.draw_to(window, sf::Vector2f(0.f, 0.f), sf::Vector2f(window.getSize().x, window.getSize().y));
        window.display();

        if (!shouldContinue)
        {
            window.close();
        }
    }

    astra::terminate();
    return 0;
}