Skip to content

Commit

Permalink
Add DirectShow to Open Other dialog on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Oct 22, 2014
1 parent 6b477d5 commit 566fd68
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/docks/encodedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ void EncodeDock::encode(const QString& target)
if (p && p->is_valid()) {
for (int i = 0; i < p->count(); i++)
MLT.consumer()->set(QString("1.%1").arg(p->get_name(i)).toLatin1().constData(), p->get(i));
#ifdef Q_OS_WIN
// p is using C numeric locale on Windows and copied above as a string.
// Convert aspect to double and set it as such on MLT.consumer(),
// which be using a different locale.
MLT.consumer()->set("1.aspect", p->get_double("aspect"));
#endif
}
delete p;
if (ui->formatCombo->currentIndex() == 0 &&
Expand Down
3 changes: 3 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "widgets/colorbarswidget.h"
#include "widgets/colorproducerwidget.h"
#include "widgets/decklinkproducerwidget.h"
#include "widgets/directshowvideowidget.h"
#include "widgets/isingwidget.h"
#include "widgets/jackproducerwidget.h"
#include "widgets/lissajouswidget.h"
Expand Down Expand Up @@ -1708,6 +1709,8 @@ QWidget *MainWindow::loadProducerWidget(Mlt::Producer* producer)
w = new JackProducerWidget(this);
else if (resource.startsWith("alsa:"))
w = new AlsaWidget(this);
else if (resource.startsWith("dshow:"))
w = new DirectShowVideoWidget(this);
else if (resource.startsWith("x11grab:"))
w = new X11grabWidget(this);
else if (service.startsWith("avformat"))
Expand Down
7 changes: 7 additions & 0 deletions src/openotherdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ OpenOtherDialog::OpenOtherDialog(QWidget *parent) :
item->setData(0, Qt::UserRole, ui->alsaTab->objectName());
item = new QTreeWidgetItem(group, QStringList(tr("Screen")));
item->setData(0, Qt::UserRole, ui->x11grabTab->objectName());
#elif defined(Q_OS_WIN)
QTreeWidgetItem* item = new QTreeWidgetItem(group, QStringList(tr("DirectShow")));
item->setData(0, Qt::UserRole, ui->dshowVideoTab->objectName());
#endif

// populate the generators
Expand Down Expand Up @@ -110,6 +113,8 @@ void OpenOtherDialog::load(Mlt::Producer* producer)
selectTreeWidget(tr("JACK Audio"));
else if (resource.startsWith("alsa:"))
selectTreeWidget(tr("ALSA Audio"));
else if (resource.startsWith("dshow:"))
selectTreeWidget(tr("DirectShow"));
else if (resource.startsWith("x11grab:"))
selectTreeWidget(tr("Screen"));
else if (service.startsWith("avformat"))
Expand Down Expand Up @@ -180,6 +185,8 @@ void OpenOtherDialog::on_treeWidget_currentItemChanged(QTreeWidgetItem *current,
m_current = ui->alsaWidget;
else if (w == ui->x11grabTab)
m_current = ui->x11grabWidget;
else if (w == ui->dshowVideoTab)
m_current = ui->dshowVideoWidget;
break;
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/openotherdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</widget>
<widget class="QStackedWidget" name="methodTabWidget">
<property name="currentIndex">
<number>5</number>
<number>2</number>
</property>
<widget class="QWidget" name="networkTab">
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand All @@ -62,6 +62,13 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="dshowVideoTab">
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="DirectShowVideoWidget" name="dshowVideoWidget" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="colorTab">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
Expand Down Expand Up @@ -239,6 +246,12 @@
<header>widgets/x11grabwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>DirectShowVideoWidget</class>
<extends>QWidget</extends>
<header>widgets/directshowvideowidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
Expand Down
10 changes: 7 additions & 3 deletions src/src.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG += link_prl

QT += widgets opengl xml network printsupport qml quick sql webkitwidgets
QT += multimedia

TARGET = shotcut
TEMPLATE = app
Expand Down Expand Up @@ -79,7 +80,8 @@ SOURCES += main.cpp\
util.cpp \
widgets/lumamixtransition.cpp \
mltxmlgpuchecker.cpp \
autosavefile.cpp
autosavefile.cpp \
widgets/directshowvideowidget.cpp

HEADERS += mainwindow.h \
mltcontroller.h \
Expand Down Expand Up @@ -151,7 +153,8 @@ HEADERS += mainwindow.h \
util.h \
widgets/lumamixtransition.h \
mltxmlgpuchecker.h \
autosavefile.h
autosavefile.h \
widgets/directshowvideowidget.h

FORMS += mainwindow.ui \
openotherdialog.ui \
Expand Down Expand Up @@ -186,7 +189,8 @@ FORMS += mainwindow.ui \
htmleditor/inserthtmldialog.ui \
widgets/webvfxproducer.ui \
docks/timelinedock.ui \
widgets/lumamixtransition.ui
widgets/lumamixtransition.ui \
widgets/directshowvideowidget.ui

RESOURCES += \
../icons/resources.qrc \
Expand Down
165 changes: 165 additions & 0 deletions src/widgets/directshowvideowidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) 2014 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "directshowvideowidget.h"
#include "ui_directshowvideowidget.h"
#include "mltcontroller.h"
#include <QCamera>
#include <QString>
#include <QAudioDeviceInfo>

DirectShowVideoWidget::DirectShowVideoWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DirectShowVideoWidget)
{
ui->setupUi(this);
foreach (const QByteArray &deviceName, QCamera::availableDevices())
ui->videoCombo->addItem(QCamera::deviceDescription(deviceName));
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
ui->audioCombo->addItem(deviceInfo.deviceName());
}

DirectShowVideoWidget::~DirectShowVideoWidget()
{
delete ui;
}

Mlt::Producer *DirectShowVideoWidget::producer(Mlt::Profile& profile)
{
#if 0
if (!profile.is_explicit()) {
Mlt::Profile ntscProfile("dv_ntsc");
Mlt::Profile palProfile("dv_pal");
if (ui->v4lWidthSpinBox->value() == ntscProfile.width() && ui->v4lHeightSpinBox->value() == ntscProfile.height()) {
profile.set_sample_aspect(ntscProfile.sample_aspect_num(), ntscProfile.sample_aspect_den());
profile.set_progressive(ntscProfile.progressive());
profile.set_colorspace(ntscProfile.colorspace());
profile.set_frame_rate(ntscProfile.frame_rate_num(), ntscProfile.frame_rate_den());
} else if (ui->v4lWidthSpinBox->value() == palProfile.width() && ui->v4lHeightSpinBox->value() == palProfile.height()) {
profile.set_sample_aspect(palProfile.sample_aspect_num(), palProfile.sample_aspect_den());
profile.set_progressive(palProfile.progressive());
profile.set_colorspace(palProfile.colorspace());
profile.set_frame_rate(palProfile.frame_rate_num(), palProfile.frame_rate_den());
} else {
profile.set_width(ui->v4lWidthSpinBox->value());
profile.set_height(ui->v4lHeightSpinBox->value());
profile.set_sample_aspect(1, 1);
profile.set_progressive(1);
profile.set_colorspace(601);
profile.set_frame_rate(ui->v4lFramerateSpinBox->value() * 10000, 10000);
}
}
#endif
Mlt::Producer* p = 0;
if (ui->videoCombo->currentIndex() > 0) {
p = new Mlt::Producer(profile, QString("dshow:video=%1")
.arg(ui->videoCombo->currentText())
.toLatin1().constData());
}
if (ui->audioCombo->currentIndex() > 0) {
Mlt::Producer* audio = new Mlt::Producer(profile,
QString("dshow:audio=%1").arg(ui->audioCombo->currentText())
.toLatin1().constData());
if (p && p->is_valid() && audio->is_valid()) {
Mlt::Tractor* tractor = new Mlt::Tractor;
tractor->set("_profile", profile.get_profile(), 0);
tractor->set("resource", p->get("resource"));
tractor->set("resource2", audio->get("resource"));
tractor->set_track(*p, 0);
delete p;
tractor->set_track(*audio, 1);
delete audio;
p = tractor;
} else {
p = audio;
}
}
if (!p || !p->is_valid()) {
delete p;
p = new Mlt::Producer(profile, "color:");
if (ui->videoCombo->currentIndex() > 0) {
p->set("resource", QString("dshow:video=%1")
.arg(ui->videoCombo->currentText())
.toLatin1().constData());
}
if (ui->audioCombo->currentIndex() > 0) {
QString resource = QString("dshow:audio=%1").arg(ui->audioCombo->currentText());
if (ui->videoCombo->currentIndex() > 0) {
p->set("resource2", resource.toLatin1().constData());
} else {
p->set("resource", resource.toLatin1().constData());
}
}
p->set("error", 1);
}
p->set("force_seekable", 0);
return p;
}

void DirectShowVideoWidget::setProducer(Mlt::Producer *producer)
{
QString resource = QString(producer->get("resource"));
QString resource2 = QString(producer->get("resource2"));
const char* videoDevice = "dshow:video=";
const char* audioDevice = "dshow:audio=";
if (resource.startsWith(videoDevice)) {
QStringRef name = resource.midRef(qstrlen(videoDevice));
for (int i = 1; i < ui->videoCombo->count(); i++) {
if (ui->videoCombo->itemText(i) == name) {
ui->videoCombo->setCurrentIndex(i);
break;
}
}
} else if (resource.startsWith(audioDevice)) {
QStringRef name = resource.midRef(qstrlen(audioDevice));
for (int i = 1; i < ui->audioCombo->count(); i++) {
if (ui->audioCombo->itemText(i) == name) {
ui->audioCombo->setCurrentIndex(i);
break;
}
}
}
if (resource2.startsWith(audioDevice)) {
QStringRef name = resource2.midRef(qstrlen(audioDevice));
for (int i = 1; i < ui->audioCombo->count(); i++) {
if (ui->audioCombo->itemText(i) == name) {
ui->audioCombo->setCurrentIndex(i);
break;
}
}
}
AbstractProducerWidget::setProducer(producer);
}

void DirectShowVideoWidget::on_videoCombo_activated(int index)
{
Q_UNUSED(index)
if (m_producer) {
MLT.pause();
delete m_producer;
m_producer = new Mlt::Producer(producer(MLT.profile()));
MLT.setProducer(m_producer);
MLT.play();
emit producerChanged();
}
}

void DirectShowVideoWidget::on_audioCombo_activated(int index)
{
on_videoCombo_activated(index);
}
52 changes: 52 additions & 0 deletions src/widgets/directshowvideowidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2014 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DIRECTSHOWVIDEOWIDGET_H
#define DIRECTSHOWVIDEOWIDGET_H

#include <QWidget>
#include "abstractproducerwidget.h"

namespace Ui {
class DirectShowVideoWidget;
}

class DirectShowVideoWidget : public QWidget, public AbstractProducerWidget
{
Q_OBJECT

public:
explicit DirectShowVideoWidget(QWidget *parent = 0);
~DirectShowVideoWidget();

// AbstractProducerWidget overrides
Mlt::Producer* producer(Mlt::Profile& profile);
void setProducer(Mlt::Producer* producer);

signals:
void producerChanged();

private slots:
void on_videoCombo_activated(int index);
void on_audioCombo_activated(int index);

private:
Ui::DirectShowVideoWidget *ui;
};

#endif // DIRECTSHOWVIDEOWIDGET_H

0 comments on commit 566fd68

Please sign in to comment.