Commit aa1808ca authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

cleanup + handle drop event

parent 8e82cca4
......@@ -25,20 +25,19 @@ class VideoFrameGrabber : public QAbstractVideoSurface
public:
VideoFrameGrabber(QObject *parent = 0);
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
bool isFormatSupported(const QVideoSurfaceFormat &format) const;
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const;
bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
bool start(const QVideoSurfaceFormat &format);
void stop();
bool start(const QVideoSurfaceFormat &format) override;
void stop() override;
bool present(const QVideoFrame &frame);
bool present(const QVideoFrame &frame) override;
private:
QImage::Format imageFormat;
QRect targetRect;
QSize imageSize;
QRect sourceRect;
QSize imageSize;
QVideoFrame currentFrame;
signals:
......@@ -101,25 +100,25 @@ bool VideoFrameGrabber::start(const QVideoSurfaceFormat &format)
{
const QImage::Format imageFormat = QVideoFrame::imageFormatFromPixelFormat(format.pixelFormat());
const QSize size = format.frameSize();
if ((imageFormat != QImage::Format_Invalid ||
format.pixelFormat() == QVideoFrame::Format_YUV420P ||
format.pixelFormat() == QVideoFrame::Format_AYUV444 ) &&
!size.isEmpty()) {
this->imageFormat = imageFormat;
imageSize = size;
sourceRect = format.viewport();
QAbstractVideoSurface::start(format);
return true;
} else {
if ((imageFormat == QImage::Format_Invalid &&
format.pixelFormat() != QVideoFrame::Format_YUV420P &&
format.pixelFormat() != QVideoFrame::Format_AYUV444 ) ||
size.isEmpty()) {
return false;
}
this->imageFormat = imageFormat;
this->imageSize = size;
this->sourceRect = format.viewport();
QAbstractVideoSurface::start(format);
return true;
}
void VideoFrameGrabber::stop()
{
currentFrame = QVideoFrame();
targetRect = QRect();
this->currentFrame = QVideoFrame();
this->targetRect = QRect();
QAbstractVideoSurface::stop();
}
......@@ -134,11 +133,11 @@ bool VideoFrameGrabber::present(const QVideoFrame &input_frame)
if (frame.pixelFormat() == QVideoFrame::Format_YUV420P ||
frame.pixelFormat() == QVideoFrame::Format_AYUV444
) { // Need to convert YUV to RGB because imageFormatFromPixelFormat does not handle YUV
QImage tmp_image=qt_imageFromVideoFrame(frame);
QImage image = tmp_image.convertToFormat(QImage::Format_RGBA8888, Qt::AutoColor);
QImage tmp_img = qt_imageFromVideoFrame(frame);
QImage image = tmp_img.convertToFormat(QImage::Format_RGBA8888, Qt::AutoColor);
emit frameAvailable(image);
frame.unmap();
currentFrame = input_frame;
this->currentFrame = input_frame;
return true;
} else {
......@@ -154,13 +153,12 @@ bool VideoFrameGrabber::present(const QVideoFrame &input_frame)
if (surfaceFormat().pixelFormat() != input_frame.pixelFormat()
|| surfaceFormat().frameSize() != input_frame.size()) {
setError(IncorrectFormatError);
stop();
this->setError(IncorrectFormatError);
this->stop();
return false;
}
currentFrame = input_frame;
this->currentFrame = input_frame;
return true;
}
......@@ -172,9 +170,9 @@ public:
public:
dtkVisualizationWidgetsVideoControls *controls = nullptr;
QMediaPlayer * player = nullptr;
QVideoProbe *probe =nullptr;
VideoFrameGrabber *grabber =nullptr;
QMediaPlayer *player = nullptr;
QVideoProbe *probe = nullptr;
VideoFrameGrabber *grabber = nullptr;
public:
dtkWidgetsOverlayPane *overlay = nullptr;
......@@ -192,11 +190,6 @@ dtkVisualizationViewVideoPlayerPrivate::dtkVisualizationViewVideoPlayerPrivate(Q
this->player = new QMediaPlayer(parent);
this->player->setAudioRole(QAudio::VideoRole); // ?
this->player->setVideoOutput(this->grabber);
QObject::connect(this->grabber, &VideoFrameGrabber::frameAvailable,
[=](QImage image) {
q->setImage(image);
});
}
dtkVisualizationViewVideoPlayerPrivate::~dtkVisualizationViewVideoPlayerPrivate(void)
......@@ -216,6 +209,7 @@ dtkVisualizationViewVideoPlayer::dtkVisualizationViewVideoPlayer(QWidget *parent
QLineEdit *text_edit = new QLineEdit("TODO Settings");
dtkWidgetsOverlayPaneItem *display_settings_item = new dtkWidgetsOverlayPaneItem(this->widget());
display_settings_item->setTitle("Display Settings");
display_settings_item->layout()->setContentsMargins(0, 0, 0, 0);
display_settings_item->addWidget(text_edit);
......@@ -241,23 +235,24 @@ dtkVisualizationViewVideoPlayer::dtkVisualizationViewVideoPlayer(QWidget *parent
connect(d->player, &QMediaPlayer::durationChanged, d->controls, &dtkVisualizationWidgetsVideoControls::setDuration);
connect(d->player, &QMediaPlayer::positionChanged, d->controls, &dtkVisualizationWidgetsVideoControls::setPosition);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::pause, d->player, &QMediaPlayer::pause);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::play, d->player, &QMediaPlayer::play);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::pause, d->player, &QMediaPlayer::pause);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::play, d->player, &QMediaPlayer::play);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::seekTo, d->player, &QMediaPlayer::setPosition);
connect(d->controls, &dtkVisualizationWidgetsVideoControls::fullscreen, [=](bool is_full){
connect(d->controls, &dtkVisualizationWidgetsVideoControls::fullscreen, [=](bool is_full) {
if (is_full) {
this->widget()->window()->showFullScreen();
} else {
this->widget()->window()->showNormal();
}
}
);
});
connect(d->controls, &dtkVisualizationWidgetsVideoControls::restart,[=] () {
d->player->setPosition(0);
d->player->play();
d->controls->toggle();
});
connect(d->grabber, &VideoFrameGrabber::frameAvailable, this, &ViewVideo::setImage);
this->setAcceptDrops(true); // ?
this->setMouseTracking(true); // ??
}
......@@ -273,11 +268,14 @@ void dtkVisualizationViewVideoPlayer::open(void)
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setWindowTitle(tr("Open Files"));
QStringList supportedMimeTypes = d->player->supportedMimeTypes();
if (!supportedMimeTypes.isEmpty()) {
supportedMimeTypes.append("video/x-mp4"); //FIXME ?
fileDialog.setMimeTypeFilters(supportedMimeTypes);
}
fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MoviesLocation).value(0, QDir::homePath()));
if (fileDialog.exec() == QDialog::Accepted) {
d->controls->reset();
d->player->setMedia(fileDialog.selectedUrls().first());
......@@ -326,10 +324,12 @@ void dtkVisualizationViewVideoPlayer::dropEvent(QDropEvent *event)
if(!path.startsWith("file://"))
return;
path.remove("file://");
// path.remove("file://");
// if (path.endsWith(".vti"))
// this->importVTI(path);
d->controls->reset();
d->player->setMedia(QUrl(path));
d->controls->setVisible(true);
d->controls->toggle();
event->accept();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment