MjpegStreamerClient::MjpegStreamerClient(QQuickPaintedItem *parent) :
    QQuickPaintedItem(parent)
{
    this->setRenderTarget(QQuickPaintedItem::FramebufferObject);
    this->setPerformanceHint(QQuickPaintedItem::FastFBOResizing, true);
    this->setAntialiasing(false);

    m_url = "";
    m_fps = 0.0;
    m_running = false;
    m_frameCount = 0;
    m_timestamp = 0.0;
    m_componentCompleted = false;
    m_updateSocket = NULL;

    m_framerateTimer = new QTimer(this);
    connect(m_framerateTimer, SIGNAL(timeout()),
            this, SLOT(updateFramerate()));
    m_framerateTimer->setInterval(1000);

    m_streamBufferTimer = new QTimer(this);
    connect(m_streamBufferTimer, SIGNAL(timeout()),
            this, SLOT(updateStreamBuffer()));
    m_streamBufferTimer->setSingleShot(true);

    m_context = createDefaultContext(this);
}
void Basic2DWindowOpenGLDisplayPlugin::activate() {
    _framerateActions.clear();
    CONTAINER->addMenuItem(MENU_PATH(), FULLSCREEN,
        [this](bool clicked) {
            if (clicked) {
                CONTAINER->setFullscreen(getFullscreenTarget());
            } else {
                CONTAINER->unsetFullscreen();
            }
        }, true, false);
    CONTAINER->addMenu(FRAMERATE);
    _framerateActions.push_back(
        CONTAINER->addMenuItem(FRAMERATE, FRAMERATE_UNLIMITED,
            [this](bool) { updateFramerate(); }, true, true, FRAMERATE));
    _framerateActions.push_back(
        CONTAINER->addMenuItem(FRAMERATE, FRAMERATE_60,
            [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
    _framerateActions.push_back(
        CONTAINER->addMenuItem(FRAMERATE, FRAMERATE_50,
            [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
    _framerateActions.push_back(
        CONTAINER->addMenuItem(FRAMERATE, FRAMERATE_40,
            [this](bool) { updateFramerate(); }, true, false, FRAMERATE));
    _framerateActions.push_back(
        CONTAINER->addMenuItem(FRAMERATE, FRAMERATE_30,
            [this](bool) { updateFramerate(); }, true, false, FRAMERATE));

    WindowOpenGLDisplayPlugin::activate();

    // Vsync detection happens in the parent class activate, so we need to check after that
    if (_vsyncSupported) {
        _vsyncAction = CONTAINER->addMenuItem(MENU_PATH(), VSYNC_ON, [this](bool) {}, true, true);
    } else {
        _vsyncAction = nullptr;
    }

    updateFramerate();
}
Beispiel #3
0
void GuiManager::processMainWindowEvents(sf::RenderWindow *window,
    GfxManager *gfxManager, int viewWidth, int viewHeight) {
  sf::Event event;
  bool resized = false;
  while (window->pollEvent(event)) {
    bool modifierDown = (event.key.system || event.key.control);

#ifdef __WXOSX__
    // For some reason, the dash key (between 0 and =) generates no KeyPressed
    // event on Mac OS X, but it does generate a TextEntered event. Also, as of
    // Yosemite + SFML 2.3, we no longer receive the dash key at all when cmd or
    // ctrl is pressed. So on OS X, just look for +, -, and 0 keys with no
    // modifier, to be consistent.
    if (event.type == sf::Event::TextEntered && event.text.unicode == 45) {
      gfxManager->decreaseWindowSize(window, viewWidth, viewHeight);
    }
    modifierDown = true;
#endif

    if (event.type == sf::Event::Closed) {
      window->close();
      quit();
    }
    if (event.type == sf::Event::MouseWheelMoved) {
      sf::Event::MouseWheelEvent wheelEvent = event.mouseWheel;
      gfxManager->processMouseWheel(wheelEvent.x, wheelEvent.y,
                                    wheelEvent.delta);
    }
    if (event.type == sf::Event::Resized && !resized) {
      resized = true;
      gfxManager->onResize(window, viewWidth, viewHeight);
    }
    if (event.type == sf::Event::MouseButtonPressed) {
      gfxManager->processMouseDown(event.mouseButton.x, event.mouseButton.y);
    }
    if (event.type == sf::Event::MouseButtonReleased) {
      gfxManager->processMouseUp(event.mouseButton.x, event.mouseButton.y);
    }
    if (event.type == sf::Event::MouseMoved
        || event.type == sf::Event::MouseEntered) {
      gfxManager->processMouseMoved(event.mouseMove.x, event.mouseMove.y);
    }
    if (event.type == sf::Event::MouseLeft) {
      gfxManager->processMouseMoved(-1, -1);
    }
    if (event.type == sf::Event::KeyPressed) {
      switch (event.key.code) {
        case sf::Keyboard::Space:
          togglePause();
          break;
        case sf::Keyboard::BackSpace:
          restartMatch();
          break;
        case sf::Keyboard::Escape:
          showNewMatchDialog();
          break;
#ifdef __WXOSX__
        case sf::Keyboard::LSystem:
        case sf::Keyboard::RSystem:
          gfxManager->showKeyboardShortcuts();
          break;
#else
        case sf::Keyboard::LAlt:
        case sf::Keyboard::RAlt:
          gfxManager->showKeyboardShortcuts();
          break;
#endif
        case sf::Keyboard::N:
          showNewMatchDialog();
          break;
        case sf::Keyboard::P:
          showPackageShipDialog();
          break;
        case sf::Keyboard::T:
          showPackageStageDialog();
          break;
        case sf::Keyboard::G:
          showGameRunnerDialog();
          break;
        case sf::Keyboard::Equal:
        case sf::Keyboard::Add:
          if (modifierDown) {
            gfxManager->increaseWindowSize(window, viewWidth, viewHeight);
          }
          break;
        case sf::Keyboard::Dash:
        case sf::Keyboard::Subtract:
          if (modifierDown) {
            gfxManager->decreaseWindowSize(window, viewWidth, viewHeight);
          }
          break;
        case sf::Keyboard::Num0:
          if (modifierDown) {
            gfxManager->defaultWindowSize(window, viewWidth, viewHeight);
          }
          break;
        case sf::Keyboard::LBracket:
          gfxManager->decreaseGameSpeed();
          break;
        case sf::Keyboard::RBracket:
          gfxManager->increaseGameSpeed();
          break;
        default:
          break;
      }
    }

    if (event.type == sf::Event::KeyReleased) {
      switch (event.key.code) {
#ifdef __WXOSX__
        case sf::Keyboard::LSystem:
        case sf::Keyboard::RSystem:
          gfxManager->hideKeyboardShortcuts();
          break;
#else
        case sf::Keyboard::LAlt:
        case sf::Keyboard::RAlt:
          gfxManager->hideKeyboardShortcuts();
          break;
#endif
        default:
          break;
      }
    }

    // On Mac/Cocoa, when using a different Space, the rest of the OS UI slows
    // to a crawl unless you have a frame rate limit set. But the frame rate is
    // smoother if we use vsync instead of a fixed frame rate, so do that when
    // we have focus.
    // TODO: Determine if this is necessary/preferable on Linux/Windows.
    // TODO: Might be better to restrict this to the Spaces case specifically,
    //       or when window isn't visible to user.
    if (event.type == sf::Event::LostFocus) {
      window->setVerticalSyncEnabled(false);
      window->setFramerateLimit(paused_ ? 5 : 60);
    } else if (event.type == sf::Event::GainedFocus) {
      updateFramerate();
    }
  }

  // On Linux/GTK and Windows, the wxWidgets windows don't get events while
  // this thread has control unless we wxYield each frame. Seems to be
  // unnecessary on Mac/Cocoa.
#ifndef __WXOSX__
  wxYield();
#endif
}
Beispiel #4
0
void GuiManager::setTpsFactor(double tpsFactor) {
  tpsFactor_ = round(tpsFactor, 3);
  paused_ = (tpsFactor_ < 0.005);
  updateFramerate();
}
Beispiel #5
0
int SDLApp::run() {

#ifdef USE_X11
    SDLApp::initX11ClipboardEventFilter();
#endif

    Uint32 msec=0, last_msec=0, buffer_msec=0, total_msec = 0;

    frame_count = 0;
    fps_updater = 0;

    if(!appFinished) init();

    msec = SDL_GetTicks();
    last_msec = msec;

    while(!appFinished) {
        last_msec = msec;
        msec      = SDL_GetTicks();

        Uint32 delta_msec = msec - last_msec;

        // cant have delta ticks be less than 8ms
        buffer_msec += delta_msec;
        if(buffer_msec < min_delta_msec) {
            SDL_Delay(1);
            continue;
        }

        delta_msec = buffer_msec;
        buffer_msec =0;

        //determine time elapsed since last time we were here
        total_msec += delta_msec;

        float t  = total_msec / 1000.0f;
        float dt = delta_msec / 1000.0f;

        fps_updater += delta_msec;

        //update framerate if a second has passed
        if (fps_updater >= 1000) {
            updateFramerate();
        }

        //process new events
        SDL_Event event;
        while ( SDL_PollEvent(&event) ) {

            switch(event.type) {
                case SDL_QUIT:
                    quit();
                    break;

                case SDL_MOUSEMOTION:
                    mouseMove(&event.motion);
                    break;

#if SDL_VERSION_ATLEAST(1,3,0)
                case SDL_MOUSEWHEEL:
                    mouseWheel(&event.wheel);
                    break;

		case SDL_WINDOWEVENT:
		    if(event.window.event == SDL_WINDOWEVENT_RESIZED) {
			resize(event.window.data1, event.window.data2);
		    }
                    break;
#else
                case SDL_VIDEORESIZE:
                    resize(event.resize.w, event.resize.h);
                    break;
#endif

                case SDL_MOUSEBUTTONDOWN:
                    mouseClick(&event.button);
                    break;

                case SDL_MOUSEBUTTONUP:
                    mouseClick(&event.button);
                    break;

                case SDL_KEYDOWN:
                    keyPress(&event.key);
                    break;

                case SDL_KEYUP:
                    keyPress(&event.key);
                    break;

                default:
                    break;
            }
        }

        update(t, dt);

        //update display
        display.update();
        frame_count++;
    }

    return return_code;
}
Beispiel #6
0
int SDLApp::run() {

    Uint32 msec=0, last_msec=0, buffer_msec=0, total_msec = 0;

    frame_count = 0;
    fps_updater = 0;

    if(!appFinished) init();

    msec = SDL_GetTicks();
    last_msec = msec;

    while(!appFinished) {
        last_msec = msec;
        msec      = SDL_GetTicks();

        Uint32 delta_msec = msec - last_msec;

        // cant have delta ticks be 0
        buffer_msec += delta_msec;
        if(buffer_msec < 1) {
            SDL_Delay(1);
            continue;
        }

        delta_msec = buffer_msec;
        buffer_msec =0;

        //determine time elapsed since last time we were here
        total_msec += delta_msec;

        float t  = total_msec / 1000.0f;
        float dt = delta_msec / 1000.0f;

        fps_updater += delta_msec;

        //update framerate if a second has passed
        if (fps_updater >= 1000) {
            updateFramerate();
        }

        //process new events
        SDL_Event event;
        while ( SDL_PollEvent(&event) ) {

            switch(event.type) {
                case SDL_QUIT:
                    appFinished=true;
                    break;

                case SDL_MOUSEMOTION:
                    mouseMove(&event.motion);
                    break;

                case SDL_MOUSEBUTTONDOWN:
                    mouseClick(&event.button);
                    break;

                case SDL_MOUSEBUTTONUP:
                    mouseClick(&event.button);
                    break;

                case SDL_KEYDOWN:
                    keyPress(&event.key);
                    break;

                case SDL_KEYUP:
                    keyPress(&event.key);
                    break;

                default:
                    break;
            }
        }

        update(t, dt);

        //update display
        display.update();
        frame_count++;
    }

    return return_code;
}