Esempio n. 1
0
void VideoProgress::onLoadResource() {
  const size_t numRes = sp.size();
  if (sp[resourceLoadIndex].bind == ShaderParameter::BindTextureSampler) {
    QImage image = QImage(sp[resourceLoadIndex].texture.c_str());
    renderSurface->addTexture(sp[resourceLoadIndex].name, image);
  }
  if (++resourceLoadIndex == numRes) {
    bar->setValue(0);
    onNextFrame();
  } else {
    bar->setValue(resourceLoadIndex/float(numRes)*100);
    QTimer::singleShot(0, this, SLOT(onLoadResource()));
  }
}
Esempio n. 2
0
VideoProgress::VideoProgress(const VideoParameters& videoParameters,  const ShaderParameters& shaderParameters, QWidget* parent) : QWidget(parent), vp(videoParameters), sp(shaderParameters), renderSurface(0) {
  setWindowTitle("Export");

  QWidget* central = this;//new QWidget(this);
  //setCentralWidget(central);
  QVBoxLayout* renderLayout = new QVBoxLayout(central);
  renderLayout->addStretch();

  frame = new QLabel(this);
  frame->setAlignment(Qt::AlignCenter);
  frame->setText("Loading...");

  renderLayout->addWidget(frame);
  renderLayout->addStretch();

  bar = new QProgressBar(this);
  renderLayout->addWidget(bar);

  //renderLayout->addStretch();
  QHBoxLayout* hlayout = new QHBoxLayout(this);
  renderLayout->addLayout(hlayout);
  button = new QPushButton("Cancel", this);
  connect(button, SIGNAL(pressed()), this, SLOT(onFinalPress()));
  hlayout->addStretch();
  hlayout->addWidget(button);
  //hlayout->addStretch();

  finalFrame = false;
  captureDone = false;
  renderSurface = new RenderSurface(vp.width, vp.height);
  if (!renderSurface->setShaderCode(vp.code)) {
    finishCapture("An error occured during capture: Shader error:\n\n" + renderSurface->getShaderError());
    return;
  }

  renderSurface->setShaderParameters(sp);
  encoder = new VideoEncoder(vp.path, vp.fps, vp.bitrate);
  frameCount = 0;
  durationSeconds = vp.duration;

  if (!sp.size()) {
    onNextFrame();
  } else { /* stuff to load */
    resourceLoadIndex = 0;
    onLoadResource();
  }
}
Esempio n. 3
0
PhMediaPanel::PhMediaPanel(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::PhMediaPanel),
	_clock(NULL),
	_firstFrame(0),
	_mediaLength(0)
{
	ui->setupUi(this);

	//Buttons Init

	ui->_playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
	connect(ui->_playButton, SIGNAL(clicked()), this, SLOT(onPlayPause()));

	ui->_fastForwardButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekForward));
	connect(ui->_fastForwardButton, SIGNAL(clicked()), this, SLOT(onFastForward()));

	ui->_fastRewindButton->setIcon(style()->standardIcon(QStyle::SP_MediaSeekBackward));
	connect(ui->_fastRewindButton, SIGNAL(clicked()), this, SLOT(onRewind()));

	ui->_backButton->setIcon(style()->standardIcon(QStyle::SP_MediaSkipBackward));
	connect(ui->_backButton, SIGNAL(clicked()), this, SLOT(onBack()));

	ui->_nextFrameButton->setIcon(style()->standardIcon(QStyle::SP_ArrowForward));
	connect(ui->_nextFrameButton, SIGNAL(clicked()), this, SLOT(onNextFrame()));

	ui->_previousFrameButton->setIcon(style()->standardIcon(QStyle::SP_ArrowBack));
	connect(ui->_previousFrameButton, SIGNAL(clicked()), this, SLOT(onPreviousFrame()));

	connect(ui->_slider, SIGNAL(sliderMoved(int)), this, SLOT(onSliderChanged(int)));

	//Combobox Init

	ui->_rateSelectionBox->addItem("23.98 fps");
	ui->_rateSelectionBox->addItem("24 fps");
	ui->_rateSelectionBox->addItem("25 fps");
	ui->_rateSelectionBox->addItem("29.97 fps");

	connect(ui->_rateSelectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onTCTypeComboChanged()));

	ui->_playButton->setDefault(true);
}
void ConnectionAutomaton::onNext(Payload frame) {
  auto streamIdPtr = FrameHeader::peekStreamId(*frame);
  if (!streamIdPtr) {
    // Failed to deserialize the frame.
    // TODO(stupaq): handle connection-level error
    assert(false);
    return;
  }
  auto streamId = *streamIdPtr;
  if (streamId == 0) {
    onConnectionFrame(std::move(frame));
    return;
  }
  auto it = streams_.find(streamId);
  if (it == streams_.end()) {
    handleUnknownStream(streamId, std::move(frame));
    return;
  }
  auto automaton = it->second;
  // Can deliver the frame.
  automaton->onNextFrame(std::move(frame));
}
Esempio n. 5
0
void VideoProgress::onNextFrame() {
  size_t maxFrames = encoder->fpsValue() * durationSeconds;

  renderSurface->renderNow(frameCount/float(encoder->fpsValue()));
  QImage image = renderSurface->getImage();

  //if (!frameCount || frameCount % 3 == 0) {
    QImage preview = image.scaled(320,200,Qt::KeepAspectRatio,Qt::FastTransformation);
    frame->setPixmap(QPixmap::fromImage(preview));
  //}

  image = image.convertToFormat(QImage::Format_RGB888);

  vpx_image_t* vpxImage = vpx_img_alloc(NULL, VPX_IMG_FMT_RGB24, renderSurface->width(), renderSurface->height(), 1);
  if (!vpxImage) {
    finishCapture("An error occured during capture: Out of memory.");
    return;
  }

  size_t size = renderSurface->width() * renderSurface->height() * 3;
  if (size != size_t(image.byteCount())) {
    finishCapture("An error occured during capture: Image size error.");
    vpx_img_free(vpxImage);
    return;
  }

  memcpy(vpxImage->img_data, image.bits(), size);

  if (!encoder->writeFrame(vpxImage)) {
    finishCapture("An error occured during capture: Frame write error.");
    vpx_img_free(vpxImage);
    return;
  }

  if (vpxImage) {
    vpx_img_free(vpxImage);
  }

  bool complete = false;
  if (++frameCount == maxFrames) {
    finalFrame = true;
    complete = true;
  } else {
    bar->setValue(frameCount/float(maxFrames)*100);
  }

  if (finalFrame) {
    bar->setValue(100);
    encoder->finish();
    delete encoder;
    if (complete) {
      finishCapture("The capture is complete.");
    } else {
      finishCapture("The capture was canceled.");
    }
  }

  if (!finalFrame) {
    QTimer::singleShot(0, this, SLOT(onNextFrame()));
  }
}
medTimeLineToolBox::medTimeLineToolBox(QWidget *parent) : medToolBox(parent), d(new medTimeLineToolBoxPrivate)
{
    QWidget *box = new QWidget (this);
    d->labelmin = new QLabel(this);
    d->labelmax = new QLabel(this);
    d->labelcurr = new QLabel(this);
    d->labelspeed = new QLabel(this);
    d->labelspeed->setText("Speed %: ");
    d->timeSlider = new QSlider (Qt::Horizontal, this);
    d->timeSlider->setRange (0, 100);
    d->timeSlider->setValue (0);
    d->timeSlider->setTracking( false );
    d->timeSlider->setToolTip(tr("Follow The Sequence"));

    QStringList validDataTypes;
    validDataTypes << "itkDataImageChar4"
                   << "itkDataImageUChar4"
                   << "itkDataImageShort4"
                   << "itkDataImageUShort4"
                   << "itkDataImageInt4"
                   << "itkDataImageUInt4"
                   << "itkDataImageLong4"
                   << "itkDataImageULong4"
                   << "itkDataImageFloat4"
                   << "itkDataImageDouble4"
                   << "vtkDataMesh4D";

    setValidDataTypes(validDataTypes);

    d->playIcon = QPixmap(":/icons/play.png");

    d->playSequencesButton = new medButton(this,d->playIcon,
                                           tr("Play Sequence"));

    d->nextFrameButton = new medButton(this,":/icons/forward.png",
                                       tr("Next Frame"));

    d->previousFrameButton = new medButton(this,":/icons/backward.png",
                                           tr("Previous Frame"));

    d->stopButton = new medButton(this,":/icons/stop.png",
                                  tr("Stop Sequence"));

    d->timeLine = new QTimeLine(1000, this);
    d->timeLine->setLoopCount(0);
    d->timeLine->setCurveShape (QTimeLine::LinearCurve);

    d->spinBox = new QSpinBox(this);
    d->spinBox->setRange(1,5000);
    d->spinBox->setSingleStep(10);
    d->spinBox->setValue(100);
    d->spinBox->setToolTip(tr("Control the display speed"));

    connect(d->timeLine, SIGNAL(frameChanged(int)), d->timeSlider, SLOT(setValue(int)));

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addWidget( d->previousFrameButton,1,Qt::AlignHCenter);
    buttonLayout->addWidget (d->playSequencesButton,1,Qt::AlignHCenter);
    buttonLayout->addWidget( d->nextFrameButton,1,Qt::AlignHCenter);


    buttonLayout->addWidget( d->stopButton,1,Qt::AlignHCenter);

    QHBoxLayout *labelLayout = new QHBoxLayout();
    labelLayout->addWidget( d->labelmin);
    labelLayout->addStretch();
    labelLayout->addWidget( d->labelcurr);
    labelLayout->addStretch();
    labelLayout->addWidget( d->labelmax);

    QHBoxLayout *topLayout = new QHBoxLayout();

    topLayout->addStretch();
    topLayout->addWidget(d->labelspeed);
    topLayout->addWidget(d->spinBox);

    QVBoxLayout* boxlayout = new QVBoxLayout ();
    boxlayout->addLayout(topLayout);
    boxlayout->addLayout( buttonLayout );
    boxlayout->addWidget (d->timeSlider);
    boxlayout->addLayout(labelLayout);

    d->actionlist.insert(0,new QAction("1",this));
    d->actionlist.insert(1,new QAction("5",this));
    d->actionlist.insert(2,new QAction("10",this));
    d->actionlist.insert(3,new QAction("25",this));
    d->actionlist.insert(4,new QAction("50",this));

    connect(d->timeSlider, SIGNAL(sliderMoved(int)), this, SLOT(onTimeChanged(int)));
    connect(d->timeSlider, SIGNAL(valueChanged(int)), this, SLOT(onTimeChanged(int)));
    connect(d->playSequencesButton, SIGNAL(triggered()), this, SLOT(onPlaySequences()));

    connect(d->nextFrameButton, SIGNAL(triggered()), this, SLOT(onNextFrame()));
    connect(d->previousFrameButton, SIGNAL(triggered()), this, SLOT(onPreviousFrame()));
    connect(d->spinBox, SIGNAL(valueChanged(int)),this, SLOT(onSpinBoxChanged(int)));
    connect(d->stopButton, SIGNAL(triggered()),this, SLOT(onStopButton()));

    this->setTitle(tr("Time Management"));
    box->setLayout (boxlayout);
    this->addWidget (box);

    d->minTime = 0.0;
    d->minTimeStep = 1.0;
    d->maxTime = 0.0;

    this->isViewAdded = false;

    this->hide();
}
void ConnectionAutomaton::onNextFrame(Frame& frame) {
  onNextFrame(frame.serializeOut());
}