Commit 249d9c49 by 景炳强

ui setting

parent 4a8e44bb
......@@ -41,7 +41,7 @@
<x>10</x>
<y>20</y>
<width>361</width>
<height>541</height>
<height>600</height>
</rect>
</property>
<property name="currentIndex">
......@@ -53,7 +53,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -66,20 +66,20 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
<string>Input 2: None</string>
</attribute>
</widget>
<widget class="DeckLinkInputPage" name="devicePage3">
<!--<widget class="DeckLinkInputPage" name="devicePage3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -92,7 +92,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -105,7 +105,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -118,20 +118,20 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
<string>Output 2: None</string>
</attribute>
</widget>
</widget>-->
<widget class="DeckLinkOutputPage" name="deviceOutputPage3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -144,7 +144,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -157,7 +157,7 @@
<x>0</x>
<y>0</y>
<width>361</width>
<height>289</height>
<height>393</height>
</rect>
</property>
<attribute name="label">
......@@ -167,7 +167,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<y>40</y>
<width>171</width>
<height>20</height>
</rect>
......@@ -180,7 +180,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<y>50</y>
<width>87</width>
<height>20</height>
</rect>
......@@ -189,30 +189,118 @@
<string>Timecode</string>
</property>
</widget>
<widget class="QCheckBox" name="previewCheckBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>87</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>一键预览</string>
</property>
</widget>
<widget class="QComboBox" name="audioChannelCombo">
<property name="geometry">
<rect>
<x>100</x>
<y>190</y>
<width>100</width>
<height>22</height>
</rect>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string/>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="maxVisibleItems">
<number>34</number>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>141</width>
<y>190</y>
<width>90</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>延迟时间(单位:秒)</string>
<string>音频通道</string>
</property>
</widget>
<widget class="QLineEdit" name="deleyTimeEdit">
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>160</x>
<y>70</y>
<width>41</width>
<height>21</height>
<x>10</x>
<y>130</y>
<width>360</width>
<height>3</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>300</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>6</pointsize>
</font>
</property>
<property name="text">
<string>以下参数需要设置完成后需要重启程序才能生效</string>
</property>
</widget>
<widget class="QComboBox" name="outputModeCombo">
<property name="geometry">
<rect>
<x>100</x>
<y>150</y>
<width>100</width>
<height>22</height>
</rect>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="currentText">
<string/>
</property>
<property name="currentIndex">
<number>-1</number>
</property>
<property name="maxVisibleItems">
<number>34</number>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>90</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>5</string>
<string>输出格式</string>
</property>
</widget>
</widget>
......
......@@ -42,7 +42,9 @@ public slots:
void InputDeviceChanged(int selectedDeviceIndex);
void InputConnectionChanged(int selectedConnectionIndex);
void VideoFormatChanged(int selectedVideoFormatIndex);
void AudioChannelChanged(int selectIndex);
void AutoDetectChanged(int autoDetectState);
void PrewChanged(int state);
void RequestedDeviceGranted(ComPtr<IDeckLink>& device);
signals:
......@@ -71,8 +73,11 @@ private:
QComboBox* DeviceListCombo;
QComboBox* InputConnectionCombo;
QComboBox* VideoFormatCombo;
QComboBox* AudioChannelCombo;
QCheckBox* AutoDetectCheckBox;
QLabel* NDINameLabel;
QCheckBox* PrewCheckBox;
int Index;
qint32 PrewState;
};
\ No newline at end of file
......@@ -15,14 +15,14 @@ class DeckLinkOpenGLWidget : public QOpenGLWidget
Q_OBJECT
public:
DeckLinkOpenGLWidget(QWidget* parent = nullptr);
DeckLinkOpenGLWidget(qint32 prewState, QWidget* parent = nullptr);
virtual ~DeckLinkOpenGLWidget();
IDeckLinkScreenPreviewCallback* GetDelegate();
DeckLinkPreviewOverlay* GetOverlay();
void Clear();
void SetPrewState(qint32 state);
protected:
// QOpenGLWidget
void initializeGL() override;
......@@ -36,6 +36,8 @@ private:
ComPtr<ScreenPreviewCallback> Delegate;
ComPtr<IDeckLinkGLScreenPreviewHelper> DeckLinkScreenPreviewHelper;
DeckLinkOpenGLOverlayWidget* OverlayWidget;
qint32 PrewState;
uint8_t* BlackBuffer;
};
class DeckLinkOpenGLOverlayWidget : public QWidget
......
......@@ -29,7 +29,7 @@ class DeckLinkOutputDevice : public QObject, public IDeckLinkVideoOutputCallback
using ScheduledFramesList = std::list<ComPtr<DeckLinkOutputVideoFrame>>;
public:
DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int videoPrerollSize,int index);
DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int videoPrerollSize,int index,qint32 deleyTime);
virtual ~DeckLinkOutputDevice() = default;
// IUnknown interface
......@@ -55,7 +55,7 @@ public:
ComPtr<IDeckLink> GetDeckLinkInstance(void) const { return deckLink; }
ComPtr<IDeckLinkOutput> getDeckLinkOutput(void) const { return deckLinkOutput; }
void SetDeleyTime(qint32& deleyTime);
public slots:
void AddAudioFrame(std::shared_ptr<AudioPacket> audio_packet);
void AddFrame(std::shared_ptr<Image> image);
......@@ -105,6 +105,8 @@ private:
qint32 Device_id;
qint32 output_deley_ms;//
qint32 audio_max_size;
qint32 queue_max_size;
BMDDisplayMode outputDisplayMode;
int m_fps;
uint64_t m_lastRecvTS;
......
......@@ -39,6 +39,8 @@ public:
BindingInputPage = inputPage;
Process = process;
Index = index;
Process->SetOutputDeleyTime(DeleyTime);
Process->SetBlackBottomHeight(BlackBottomHeight);
}
......@@ -50,7 +52,11 @@ public slots:
void ObjectNameChanged(const QString& newName);
void FormatChanged(BMDDisplayMode displayMode);
void DeleyTimeChanged(QString text);
void DeleyTimeFinish();
void BlackHeightFinish();
void VerifyClicked();
void PrewChanged(int state);
signals:
void RequestDeckLink(ComPtr<IDeckLink>& device);
......@@ -75,4 +81,17 @@ private:
QComboBox* VideoFormatCombo;
QComboBox* VideoPixelFormatCombo;
QLineEdit* PortNumLineEdit;
QLineEdit* DeleyTimeEdit;
QLineEdit* BlackHeightEdit;
qint32 DeleyTime;
qint32 BlackBottomHeight;
QCheckBox* PrewCheckBox;
QPushButton* VerifyBtn;
BMDDisplayMode DisplayMode;
BMDPixelFormat PixelFormat;
bool firstFmtChanged;
qint32 PrewState;
};
\ No newline at end of file
......@@ -18,8 +18,10 @@ public:
void Clear();
void SetDeviceLabel(const QString& label);
void SetDeleyTime(const qint32& deleyTime);
void EnableTimeCode(bool enable);
void EnableDeviceLabel(bool enable);
void EnableDeleyTime(bool enable);
bool IsSignalValid(void);
void Paint(QPaintDevice* paintDevice);
......@@ -35,4 +37,7 @@ private:
bool bEnableTimeCode;
bool bEnableDeviceLabel;
bool bEnableDeleyTime;
qint32 DeleyTime;
};
\ No newline at end of file
......@@ -55,6 +55,9 @@ private slots:
void DeviceLabelEnableChanged(bool enabled);
void TimecodeEnableChanged(bool enabled);
void DeleyTimeTextChanged(const QString&);
void PrewEnableChanged(bool enabled);
void OutputModeChanged(int selectIndex);
void AudioChannelChanged(int selectIndex);
private:
void ReadSettings();
private:
......@@ -66,7 +69,11 @@ private:
ProfileCallback* pProfileCallback;
QLineEdit* DeleyTimeEdit;
QComboBox* AudioChannelCombo;
QComboBox* OutputModeCombo;
QCheckBox* OutputModeCheck;
QCheckBox* TimecodeCheck;
QCheckBox* DeviceCheck;
std::array<DeckLinkInputPage*, kPreviewDevicesCount> InputDevicePages;
std::array<DeckLinkOutputPage*, kPreviewDevicesCount> OutputDevicePages;
std::array<std::shared_ptr<ProcessThread>, kPreviewDevicesCount> ProcessThreads;
......
......@@ -177,7 +177,9 @@ public slots:
signals:
void PushFrame(std::shared_ptr<Image> image);
public:
void SetOutputDeleyTime(qint32 deleyTime) { output_deley_time = deleyTime; }
void SetBlackBottomHeight(qint32 blackHeight) { BlackBottomHeight = blackHeight; }
protected:
void run() override;
private:
......@@ -214,6 +216,7 @@ private:
int minTaskImageQueueSize;
bool firstMinSize = false;
qint32 BlackBottomHeight;
int m_fps;
uint64_t m_lastRecvTS;
......
......@@ -308,6 +308,8 @@ void DeckLinkInputDevice::StopCapture()
DeckLinkInput->StopStreams();
DeckLinkInput->DisableVideoInput();
DeckLinkInput->DisableAudioInput();
// Delete the callbacks
DeckLinkInput->SetScreenPreviewCallback(nullptr);
DeckLinkInput->SetCallback(nullptr);
......
......@@ -20,6 +20,8 @@ namespace
std::make_pair(bmdVideoConnectionSVideo, QString("S-Video")),
};
const std::vector<QString> AudioChannels = {"1","2","3","4"};
template<class T>
T* findParent(QWidget* widget)
{
......@@ -53,6 +55,16 @@ DeckLinkInputPage::DeckLinkInputPage() : SelectedDevice(nullptr), NDIOutput(null
VideoFormatCombo->setEnabled(false);
FormLayout->addRow("Video Format:", VideoFormatCombo);
AudioChannelCombo = new QComboBox();
AudioChannelCombo->setMinimumWidth(kComboMinimumWidth);
AudioChannelCombo->setEnabled(true);
for(auto channel : AudioChannels)
{
AudioChannelCombo->addItem(channel);
}
AudioChannelCombo->setCurrentIndex(1);
//FormLayout->addRow("Audio Channel:", AudioChannelCombo);
AutoDetectCheckBox = new QCheckBox();
AutoDetectCheckBox->setEnabled(false);
FormLayout->addRow("Auto-Detect Format:", AutoDetectCheckBox);
......@@ -60,7 +72,13 @@ DeckLinkInputPage::DeckLinkInputPage() : SelectedDevice(nullptr), NDIOutput(null
NDINameLabel = new QLabel();
FormLayout->addRow("NDIOutputLabel:", NDINameLabel);
PreviewView = new DeckLinkOpenGLWidget(dynamic_cast<QWidget*>(this));
PrewCheckBox = new QCheckBox();
PrewCheckBox->setChecked(false);
PrewCheckBox->setMinimumWidth(kComboMinimumWidth);
FormLayout->addRow(QString::fromWCharArray(L"Ԥ"), PrewCheckBox);
PrewState = PrewCheckBox->isChecked();
PreviewView = new DeckLinkOpenGLWidget(PrewState,dynamic_cast<QWidget*>(this));
PreviewView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
NDIOutput = std::make_unique<NDIOutputThread>("NDIOutput", 1920, 1080);
......@@ -72,6 +90,10 @@ DeckLinkInputPage::DeckLinkInputPage() : SelectedDevice(nullptr), NDIOutput(null
connect(VideoFormatCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DeckLinkInputPage::VideoFormatChanged);
connect(AutoDetectCheckBox, &QCheckBox::stateChanged, this, &DeckLinkInputPage::AutoDetectChanged);
connect(this, &QObject::objectNameChanged, this, &DeckLinkInputPage::ObjectNameChanged);
connect(PrewCheckBox, &QCheckBox::stateChanged, this, &DeckLinkInputPage::PrewChanged);
connect(AudioChannelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DeckLinkInputPage::AudioChannelChanged);
AudioChannelCombo->setHidden(true);
}
DeckLinkInputPage::~DeckLinkInputPage()
......@@ -210,6 +232,19 @@ bool DeckLinkInputPage::ReleaseDeviceIfSelected(ComPtr<IDeckLink>& deckLink)
return false;
}
void DeckLinkInputPage::AudioChannelChanged(int selectIndex)
{
if (selectIndex == -1) return;
auto value = AudioChannelCombo->currentText();
qDebug() << "audio channels select:" << value << "\n";
QString exe_dir = QCoreApplication::applicationDirPath();
QString ini_path = exe_dir + "/settings.ini";
QSettings settings(ini_path, QSettings::IniFormat);
settings.beginGroup("DELEYTIME");
settings.setValue("AUDIO_CHANNEL", value);
settings.endGroup();
}
void DeckLinkInputPage::InputDeviceChanged(int selectedDeviceIndex)
{
START_SLOT_TIME_COUNTER
......@@ -299,6 +334,12 @@ void DeckLinkInputPage::AutoDetectChanged(int autoDetectState)
END_SLOT_TIME_COUNTER
}
void DeckLinkInputPage::PrewChanged(int state)
{
PrewState = state;
PreviewView->SetPrewState(PrewState);
}
void DeckLinkInputPage::DetectedVideoFormatChanged(BMDDisplayMode displayMode)
{
// Update videoFormatPopup with auto-detected display name
......
......@@ -10,7 +10,7 @@
/// DeckLinkOpenGLOverlay
///
extern int PrvwFlag;
//extern int PrvwFlag;
DeckLinkOpenGLOverlayWidget::DeckLinkOpenGLOverlayWidget(QWidget* parent) : QWidget(parent)
{
......@@ -32,12 +32,12 @@ void DeckLinkOpenGLOverlayWidget::paintEvent(QPaintEvent* event)
/// DeckLinkOpenGLWidget
///
DeckLinkOpenGLWidget::DeckLinkOpenGLWidget(QWidget* parent) : QOpenGLWidget(parent)
DeckLinkOpenGLWidget::DeckLinkOpenGLWidget(qint32 prewState,QWidget* parent) : PrewState(prewState),QOpenGLWidget(parent), BlackBuffer(NULL)
{
GetDeckLinkOpenGLScreenPreviewHelper(DeckLinkScreenPreviewHelper);
Delegate = MakeComPtr<ScreenPreviewCallback>();
if(PrvwFlag) connect(Delegate.Get(), &ScreenPreviewCallback::FrameArrived, this, &DeckLinkOpenGLWidget::SetFrame, Qt::QueuedConnection);
connect(Delegate.Get(), &ScreenPreviewCallback::FrameArrived, this, &DeckLinkOpenGLWidget::SetFrame, Qt::QueuedConnection);
OverlayWidget = new DeckLinkOpenGLOverlayWidget(this);
}
......@@ -60,7 +60,7 @@ void DeckLinkOpenGLWidget::initializeGL()
void DeckLinkOpenGLWidget::paintGL()
{
START_GL_TIME_COUNTER
if(DeckLinkScreenPreviewHelper)
if(DeckLinkScreenPreviewHelper && PrewState)
{
DeckLinkScreenPreviewHelper->PaintGL();
}
......@@ -98,7 +98,8 @@ void DeckLinkOpenGLWidget::Clear()
void DeckLinkOpenGLWidget::SetFrame(ComPtr<IDeckLinkVideoFrame> frame)
{
START_SLOT_TIME_COUNTER
if(DeckLinkScreenPreviewHelper)
if(DeckLinkScreenPreviewHelper && PrewState)
{
DeckLinkScreenPreviewHelper->SetFrame(frame.Get());
GetOverlay()->SetFrame(frame);
......@@ -108,3 +109,15 @@ void DeckLinkOpenGLWidget::SetFrame(ComPtr<IDeckLinkVideoFrame> frame)
}
END_SLOT_TIME_COUNTER
}
void DeckLinkOpenGLWidget::SetPrewState(qint32 state)
{
if (PrewState == state) return;
PrewState = state;
if (!PrewState)
{
DeckLinkScreenPreviewHelper->SetFrame(nullptr);
Clear();
update();
OverlayWidget->update();
}
}
......@@ -5,16 +5,16 @@
#include "BlackMagicDesign/ScreenPreviewCallback.h"
#include "BlackMagicDesign/ReferenceTime.h"
extern int OutputDeleyTime;
//extern int OutputDeleyTime;
extern int OutputPlayMode;
extern int AudioChannel;
extern std::map<qint32, qint32> map_output_delay;
//extern std::map<qint32, qint32> map_output_delay;
#define OUTPUT_1080 1
#define AUDIOMAXSIZE (OutputDeleyTime + 3) * 50
DeckLinkOutputDevice::DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int videoPrerollSize,int index)
DeckLinkOutputDevice::DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int videoPrerollSize,int index,qint32 deleyTime)
: RefCount(1),
state(PlaybackState::Idle),
deckLink(decklink),
......@@ -25,6 +25,7 @@ DeckLinkOutputDevice::DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int vide
scheduledFrameCompletedCallback(nullptr),
first_sleep(false),
Index(index),
output_deley_ms(deleyTime),
m_fps(0),
m_lastRecvTS(TimeMilliSecond())
{
......@@ -32,8 +33,8 @@ DeckLinkOutputDevice::DeckLinkOutputDevice(ComPtr<IDeckLink>& decklink, int vide
if (!deckLinkOutput)
throw std::runtime_error("DeckLink device does not have an output interface.");
//current_sleep_ms = OutputDeleyTime * 1000;
InitResource();
queue_max_size = (output_deley_ms / 1000 + 3) * 50;
//InitResource();
}
// IUnknown methods
......@@ -343,7 +344,8 @@ bool DeckLinkOutputDevice::getReferenceSignalMode(BMDDisplayMode* mode)
while(true)
{
START_WAIT_TIME_COUNTER
if (state == PlaybackState::Stopping) break;
std::shared_ptr<Image> outputImage;
if(outputVideoFrameQueue.WaitFor(outputImage))
......@@ -386,6 +388,8 @@ bool DeckLinkOutputDevice::getReferenceSignalMode(BMDDisplayMode* mode)
else if (ret == E_FAIL)
{
qDebug() << "Failure." << "\n";
deckLinkOutput->DisableVideoOutput();
deckLinkOutput->EnableVideoOutput(outputDisplayMode, bmdVideoOutputFlagDefault);
}
else
{
......@@ -435,6 +439,7 @@ bool DeckLinkOutputDevice::getReferenceSignalMode(BMDDisplayMode* mode)
{
while (true)
{
if (state == PlaybackState::Stopping) break;
std::shared_ptr<AudioPacket> audio_packet;
if (outputAudioFrameQueue.WaitFor(audio_packet))
{
......@@ -473,6 +478,7 @@ bool DeckLinkOutputDevice::getReferenceSignalMode(BMDDisplayMode* mode)
{
while (true)
{
if (state == PlaybackState::Stopping) break;
std::shared_ptr<AudioPacket> audio_packet;
if (outputAudioFrameQueue.WaitFor(audio_packet))
{
......@@ -562,7 +568,7 @@ void DeckLinkOutputDevice::AddFrame(std::shared_ptr<Image> image)
//if (outputVideoFrameQueue.Size() >= 4)
// qDebug() << "DeckLinkOutputDevice::AddFrame video---qsize:" << "\t" << outputVideoFrameQueue.Size() << "\n";
if (outputVideoFrameQueue.Size() > audio_max_size)
if (outputVideoFrameQueue.Size() > queue_max_size)
{
outputVideoFrameQueue.Reset();
}
......@@ -575,7 +581,7 @@ void DeckLinkOutputDevice::AddAudioFrame(std::shared_ptr<AudioPacket> audio_pack
//if (outputAudioFrameQueue.Size() >= 4)
//qDebug() << "index:" << Index << "DeckLinkOutputDevice::AddAudioFrame audio---qsize:" << "\t" << outputAudioFrameQueue.Size() << "\n";
if (outputAudioFrameQueue.Size() > audio_max_size)
if (outputAudioFrameQueue.Size() > queue_max_size)
{
outputAudioFrameQueue.Reset();
}
......@@ -588,7 +594,7 @@ void DeckLinkOutputDevice::AddAudioFrame(std::shared_ptr<AudioPacket> audio_pack
void DeckLinkOutputDevice::InitResource()
{
if (deckLink)
/*if (deckLink)
{
dlstring_t displayName;
QString deviceName;
......@@ -617,5 +623,11 @@ void DeckLinkOutputDevice::InitResource()
audio_max_size = (output_deley_ms / 1000 + 3) * 50;
}
}
}
}
\ No newline at end of file
}*/
}
void DeckLinkOutputDevice::SetDeleyTime(qint32& deleyTime)
{
output_deley_ms = deleyTime;
queue_max_size = (output_deley_ms / 1000 + 3) * 50;
}
......@@ -3,13 +3,14 @@
#include <QToolBox>
#include <QMessageBox>
#include <QLineEdit>
#include <qpushbutton.h>
#include "MomentaMedia.h"
#include "BlackMagicDesign/DeckLinkOutputPage.h"
#include "Utils/Platform.h"
namespace
{
const int kComboMinimumWidth = 185;
const int kComboMinimumWidth = 180;
const std::vector<std::pair<BMDVideoConnection, QString>> kVideoOutputConnections = {
std::make_pair(bmdVideoConnectionSDI, QString("SDI")),
......@@ -46,7 +47,7 @@ namespace
}
DeckLinkOutputPage::DeckLinkOutputPage() : SelectedDevice(nullptr), Process(nullptr)
DeckLinkOutputPage::DeckLinkOutputPage() : SelectedDevice(nullptr), Process(nullptr), firstFmtChanged(true)
{
FormLayout = new QFormLayout(this);
......@@ -65,17 +66,48 @@ DeckLinkOutputPage::DeckLinkOutputPage() : SelectedDevice(nullptr), Process(null
VideoPixelFormatCombo->setEnabled(false);
FormLayout->addRow("Video Pixel Format:", VideoPixelFormatCombo);
PreviewView = new DeckLinkOpenGLWidget(dynamic_cast<QWidget*>(this));
PreviewView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
PortNumLineEdit = new QLineEdit();
PortNumLineEdit->setMinimumWidth(kComboMinimumWidth);
FormLayout->addRow("PortNum", PortNumLineEdit);
DeleyTimeEdit = new QLineEdit();
DeleyTimeEdit->setMinimumWidth(kComboMinimumWidth);
DeleyTimeEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
DeleyTimeEdit->setText("3000");
FormLayout->addRow(QString::fromWCharArray(L"延迟时间(毫秒)"), DeleyTimeEdit);
BlackHeightEdit = new QLineEdit();
BlackHeightEdit->setMinimumWidth(kComboMinimumWidth);
BlackHeightEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
BlackHeightEdit->setText("0");
FormLayout->addRow(QString::fromWCharArray(L"黑边高度"), BlackHeightEdit);
PrewCheckBox = new QCheckBox();
PrewCheckBox->setChecked(false);
PrewCheckBox->setMinimumWidth(kComboMinimumWidth);
FormLayout->addRow(QString::fromWCharArray(L"预览"), PrewCheckBox);
PrewState = PrewCheckBox->isChecked();
PreviewView = new DeckLinkOpenGLWidget(PrewState, dynamic_cast<QWidget*>(this));
PreviewView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
VerifyBtn = new QPushButton(QString::fromWCharArray(L"确认"));
VerifyBtn->setMinimumWidth(kComboMinimumWidth);
FormLayout->addRow(VerifyBtn);
DeleyTime = DeleyTimeEdit->text().toInt();
BlackBottomHeight = BlackHeightEdit->text().toInt();
PreviewView->GetOverlay()->SetDeleyTime(DeleyTime);
connect(DeviceListCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DeckLinkOutputPage::OutputDeviceChanged);
connect(VideoFormatCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DeckLinkOutputPage::VideoFormatChanged);
connect(VideoPixelFormatCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DeckLinkOutputPage::VideoPixelFormatChanged);
connect(this, &QObject::objectNameChanged, this, &DeckLinkOutputPage::ObjectNameChanged);
connect(DeleyTimeEdit, &QLineEdit::editingFinished,this, &DeckLinkOutputPage::DeleyTimeFinish);
connect(BlackHeightEdit, &QLineEdit::editingFinished, this, &DeckLinkOutputPage::BlackHeightFinish);
connect(VerifyBtn, &QPushButton::clicked, this, &DeckLinkOutputPage::VerifyClicked);
connect(PrewCheckBox, &QCheckBox::stateChanged, this, &DeckLinkOutputPage::PrewChanged);
}
DeckLinkOutputPage::~DeckLinkOutputPage()
......@@ -113,6 +145,9 @@ void DeckLinkOutputPage::customEvent(QEvent* event)
void DeckLinkOutputPage::StartOutput()
{
if (!SelectedDevice || firstFmtChanged)
return;
FormatChanged(DisplayMode);
/*
if (!SelectedDevice)
return;
......@@ -245,7 +280,7 @@ void DeckLinkOutputPage::RequestedDeviceGranted(ComPtr<IDeckLink>& device)
{
START_SLOT_TIME_COUNTER
SelectedDevice = MakeComPtr<DeckLinkOutputDevice>(device, 1,Index);
SelectedDevice = MakeComPtr<DeckLinkOutputDevice>(device, 1,Index,DeleyTime);
// Register profile callback with newly selected device`s profile manager
......@@ -259,7 +294,8 @@ void DeckLinkOutputPage::RequestedDeviceGranted(ComPtr<IDeckLink>& device)
if(Process->isRunning())
Process->exit();
Process->SetUpUDP("127.0.0.1", PortNumLineEdit->text());
//Process->SetUpUDP("127.0.0.1", PortNumLineEdit->text());
Process->SetUpUDP("0.0.0.0", PortNumLineEdit->text());
Process->start();
......@@ -274,13 +310,75 @@ void DeckLinkOutputPage::RequestedDeviceGranted(ComPtr<IDeckLink>& device)
void DeckLinkOutputPage::FormatChanged(BMDDisplayMode displayMode)
{
BMDDisplayMode displayMode_ = displayMode;
if (firstFmtChanged) firstFmtChanged = false;
DisplayMode = displayMode;
//BMDPixelFormat pixelFormat = bmdFormat10BitYUV;
BMDPixelFormat pixelFormat = bmdFormat8BitBGRA;
PixelFormat = bmdFormat8BitBGRA;
SelectedDevice->StartPlayback(DisplayMode, false, PixelFormat, false, PreviewView->GetDelegate());
int indexToSelect = DeviceListCombo->findData(QVariant::fromValue((void*)SelectedDevice->GetDeckLinkInstance().Get()));
bool active = SelectedDevice->isPlaybackActive();
QToolBox* toolBox = findParent<QToolBox>(this);
int pageIndex = toolBox->indexOf(this);
QString title = QString("Output %1: %2%3").arg(pageIndex + 1).arg(DeviceListCombo->itemText(indexToSelect)).arg(active ? "" : " [inactive]");
toolBox->setItemText(pageIndex, title);
PreviewView->GetOverlay()->SetDeviceLabel(title);
}
SelectedDevice->StartPlayback(displayMode_, false, pixelFormat, false, PreviewView->GetDelegate());
void DeckLinkOutputPage::PrewChanged(int state)
{
PrewState = state;
PreviewView->SetPrewState(PrewState);
}
void DeckLinkOutputPage::VerifyClicked()
{
QString text = BlackHeightEdit->text();
auto height = text.toInt();
if (BlackBottomHeight != height)
{
BlackBottomHeight = height;
qDebug() << "index:" << Index << " BlackBottomHeight:" << BlackBottomHeight << "\n";
Process->SetBlackBottomHeight(BlackBottomHeight);
}
text = DeleyTimeEdit->text();
auto time = text.toInt();
if (DeleyTime != time)
{
DeleyTime = time;
qDebug() << "index:" << Index << " deley time:" << DeleyTime << "\n";
SelectedDevice->SetDeleyTime(DeleyTime);
Process->SetOutputDeleyTime(DeleyTime);
PreviewView->GetOverlay()->SetDeleyTime(DeleyTime);
}
}
void DeckLinkOutputPage::BlackHeightFinish()
{
/*QString text = BlackHeightEdit->text();
BlackBottomHeight = text.toInt();
qDebug() << "index:" << Index << " BlackBottomHeight:" << BlackBottomHeight << "\n";
Process->SetBlackBottomHeight(BlackBottomHeight);*/
}
void DeckLinkOutputPage::DeleyTimeFinish()
{
/*QString text = DeleyTimeEdit->text();
DeleyTime = text.toInt();
qDebug() <<"index:"<< Index << " deley time:" << DeleyTime << "\n";
SelectedDevice->SetDeleyTime(DeleyTime);
Process->SetOutputDeleyTime(DeleyTime);*/
}
void DeckLinkOutputPage::DeleyTimeChanged(QString text)
{
qDebug() << "deley time:" << text << "\n";
}
void DeckLinkOutputPage::ObjectNameChanged(const QString& newName)
{
......
......@@ -8,7 +8,7 @@
#include "BlackMagicDesign/DeckLinkPreviewVideoFrame.h"
#include "BlackMagicDesign/DeckLinkPreviewOverlay.h"
DeckLinkPreviewOverlay::DeckLinkPreviewOverlay(QObject* parent) : QObject(parent), bEnableTimeCode(false), bEnableDeviceLabel(false)
DeckLinkPreviewOverlay::DeckLinkPreviewOverlay(QObject* parent) : QObject(parent), bEnableTimeCode(false), bEnableDeviceLabel(false),bEnableDeleyTime(false),DeleyTime(0)
{
}
......@@ -69,6 +69,21 @@ void DeckLinkPreviewOverlay::SetDeviceLabel(const QString& label)
emit UpdatePreview();
}
void DeckLinkPreviewOverlay::SetDeleyTime(const qint32& deleyTime)
{
{
std::lock_guard<std::mutex> lock(Mutex);
if (DeleyTime != deleyTime)
{
DeleyTime = deleyTime;
emit UpdatePreview();
}
}
/*if (bEnableDeleyTime)
emit UpdatePreview();*/
}
void DeckLinkPreviewOverlay::EnableTimeCode(bool enable)
{
{
......@@ -89,6 +104,16 @@ void DeckLinkPreviewOverlay::EnableDeviceLabel(bool enable)
emit UpdatePreview();
}
void DeckLinkPreviewOverlay::EnableDeleyTime(bool enable)
{
{
std::lock_guard<std::mutex> lock(Mutex);
bEnableDeleyTime = enable;
}
emit UpdatePreview();
}
bool DeckLinkPreviewOverlay::IsSignalValid()
{
std::lock_guard<std::mutex> lock(Mutex);
......@@ -118,14 +143,30 @@ void DeckLinkPreviewOverlay::Paint(QPaintDevice* paintDevice)
if(bEnableDeviceLabel)
{
font.setPixelSize(paintDevice->height() / 16);
int size = paintDevice->height() / 16;
font.setPixelSize(15);
QFontMetrics metrics(font, paintDevice);
QRect box(0, 0, paintDevice->width(), metrics.height() + 4);
painter.fillRect(box, brush);
painter.setPen(QColor(Qt::white));
painter.setFont(font);
painter.drawText((paintDevice->width() - metrics.width(DeviceLabel)) / 2, box.top() + 2 + metrics.ascent(), DeviceLabel);
//painter.setFont(QFont("Arial", 10));
int x = (paintDevice->width() - metrics.width(DeviceLabel)) / 2;
int y = box.top() + 2 + metrics.ascent();
painter.drawText(x, y, DeviceLabel);
if (DeleyTime)
{
QRect box(0, metrics.height() + 4, paintDevice->width(), metrics.height() + 4);
painter.fillRect(box, brush);
painter.setPen(QColor(Qt::white));
painter.setFont(font);
QString str = "DeleyTime:" + QString::number(DeleyTime);
int x = (paintDevice->width() - metrics.width(str)) / 2;
int y = box.top() + 2 + metrics.ascent();
painter.drawText(x, y, str);
}
}
if(bEnableTimeCode)
......
......@@ -13,21 +13,26 @@
#include "Utils/Common.h"
int OutputDeleyTime = 5;
//int OutputDeleyTime = 5;
int FrontDeleyTime = 1;
int FrameRate = 50;
int PrvwFlag = 0;
//int PrvwFlag = 0;
int OutputPlayMode = 0;
int BlackBottomHeight = 240;
//int BlackBottomHeight = 240;
int AudioChannel = 2;
int ScaleMode = 0;
qint64 StartTimeStamp = 0;
std::map<qint32, qint32> map_output_delay;
//std::map<qint32, qint32> map_output_delay;
std::map<qint32, qint32> map_scale_mode;
int main_ver = 1;
int mid_ver = 0;
int small_ver = 2;
int small_ver = 5;
namespace
{
const std::vector<QString> AudioChannels = { "1","2","3","4"};
}
MomentaMedia::MomentaMedia(QWidget *parent)
: QMainWindow(parent)
......@@ -45,8 +50,8 @@ MomentaMedia::MomentaMedia(QWidget *parent)
InputDevicePages[1] = ui.devicePage2;
//InputDevicePages[2] = ui.devicePage3;
//InputDevicePages[3] = ui.devicePage4;
OutputDevicePages[0] = ui.deviceOutputPage1;
OutputDevicePages[1] = ui.deviceOutputPage2;
OutputDevicePages[0] = ui.deviceOutputPage3;
OutputDevicePages[1] = ui.deviceOutputPage4;
//OutputDevicePages[2] = ui.deviceOutputPage3;
//OutputDevicePages[3] = ui.deviceOutputPage4;
ProcessThreads[0] = std::make_shared<ProcessThread>();
......@@ -54,12 +59,12 @@ MomentaMedia::MomentaMedia(QWidget *parent)
//ProcessThreads[2] = std::make_shared<ProcessThread>();
// ProcessThreads[3] = std::make_shared<ProcessThread>();
DeleyTimeEdit = ui.deleyTimeEdit;
/*DeleyTimeEdit = ui.deleyTimeEdit;
QIntValidator* intValidator = new QIntValidator;
intValidator->setRange(0, 20);
DeleyTimeEdit->setValidator(intValidator);
connect(DeleyTimeEdit,&QLineEdit::textChanged,this,&MomentaMedia::DeleyTimeTextChanged);
connect(DeleyTimeEdit,&QLineEdit::textChanged,this,&MomentaMedia::DeleyTimeTextChanged);*/
......@@ -95,9 +100,41 @@ MomentaMedia::MomentaMedia(QWidget *parent)
connect(OutputDevicePages[i], &DeckLinkOutputPage::RequestDeckLinkIfAvailable, std::bind(&MomentaMedia::RequestOutputDeviceIfAvailable, this, OutputDevicePages[i], std::placeholders::_1));
connect(OutputDevicePages[i], &DeckLinkOutputPage::RelinquishDeckLink, this, &MomentaMedia::RelinquishOutputDevice);
}
OutputModeCombo = ui.outputModeCombo;
AudioChannelCombo = ui.audioChannelCombo;
DeviceCheck = ui.deviceLabelCheckBox;
TimecodeCheck = ui.timecodeCheckBox;
TimecodeCheck->setHidden(true);
DeviceCheck->setHidden(true);
connect(ui.deviceLabelCheckBox, &QCheckBox::stateChanged, this, &MomentaMedia::DeviceLabelEnableChanged);
connect(ui.timecodeCheckBox, &QCheckBox::stateChanged, this, &MomentaMedia::TimecodeEnableChanged);
connect(ui.previewCheckBox, &QCheckBox::stateChanged, this, &MomentaMedia::PrewEnableChanged);
QString exe_dir = QCoreApplication::applicationDirPath();
QString ini_path = exe_dir + "/settings.ini";
QSettings settings(ini_path, QSettings::IniFormat);
settings.beginGroup("DELEYTIME");
int mode = settings.value("OUTPUT_PLAY_MODE", "").toInt();
int channel = settings.value("AUDIO_CHANNEL").toInt();
settings.endGroup();
//OutputModeCheck->setChecked(mode);
for(auto channel : AudioChannels)
{
AudioChannelCombo->addItem(channel);
}
AudioChannelCombo->setCurrentIndex(channel - 1);
connect(AudioChannelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MomentaMedia::AudioChannelChanged);
OutputModeCombo->addItem(QString::fromWCharArray(L"跟随输入格式"));
OutputModeCombo->addItem("1080 50I");
OutputModeCombo->setCurrentIndex(mode);
connect(OutputModeCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MomentaMedia::OutputModeChanged);
show();
......@@ -501,6 +538,19 @@ void MomentaMedia::RelinquishOutputDevice(ComPtr<IDeckLink>& device)
END_SLOT_TIME_COUNTER
}
void MomentaMedia::AudioChannelChanged(int selectIndex)
{
if (selectIndex == -1) return;
auto value = AudioChannelCombo->currentText();
//qDebug() << "audio channels select:" << value << "\n";
QString exe_dir = QCoreApplication::applicationDirPath();
QString ini_path = exe_dir + "/settings.ini";
QSettings settings(ini_path, QSettings::IniFormat);
settings.beginGroup("DELEYTIME");
settings.setValue("AUDIO_CHANNEL", value);
settings.endGroup();
}
void MomentaMedia::DeviceLabelEnableChanged(bool enabled)
{
START_SLOT_TIME_COUNTER
......@@ -513,6 +563,33 @@ void MomentaMedia::DeviceLabelEnableChanged(bool enabled)
END_SLOT_TIME_COUNTER
}
void MomentaMedia::OutputModeChanged(int selectIndex)
{
int value = selectIndex;
QString exe_dir = QCoreApplication::applicationDirPath();
QString ini_path = exe_dir + "/settings.ini";
QSettings settings(ini_path, QSettings::IniFormat);
settings.beginGroup("DELEYTIME");
settings.setValue("OUTPUT_PLAY_MODE", value);
settings.endGroup();
}
void MomentaMedia::PrewEnableChanged(bool enabled)
{
START_SLOT_TIME_COUNTER
DeviceCheck->setChecked(enabled);
for (int i = 0; i < PreviewLayout->count(); ++i)
{
DeckLinkOpenGLWidget* widget = qobject_cast<DeckLinkOpenGLWidget*>(PreviewLayout->itemAt(i)->widget());
if (widget)
widget->SetPrewState(enabled);
}
END_SLOT_TIME_COUNTER
}
void MomentaMedia::TimecodeEnableChanged(bool enabled)
{
START_SLOT_TIME_COUNTER
......@@ -540,34 +617,34 @@ void MomentaMedia::ReadSettings()
QString ini_path = exe_dir + "/settings.ini";
QSettings settings(ini_path, QSettings::IniFormat);
settings.beginGroup("DELEYTIME");
OutputDeleyTime = settings.value("DELEY_TIME", "").toInt();
/*OutputDeleyTime = settings.value("DELEY_TIME", "").toInt();
if (OutputDeleyTime < 1 * 1000) OutputDeleyTime = 1 * 1000;
else if (OutputDeleyTime > 20 * 1000) OutputDeleyTime = 20 * 1000;
else if (OutputDeleyTime > 20 * 1000) OutputDeleyTime = 20 * 1000;*/
FrontDeleyTime = settings.value("FRONT_DELEY_TIME", "").toInt();
if (FrontDeleyTime < 1 || FrontDeleyTime > OutputDeleyTime) FrontDeleyTime = 1;
if (FrontDeleyTime < 1 ) FrontDeleyTime = 1;
FrameRate = settings.value("FRAME_RATE", "").toInt();
if (FrameRate < 25) FrameRate = 25;
BlackBottomHeight = settings.value("BLACK_BOTTOM_HEIGHT").toInt();
/*BlackBottomHeight = settings.value("BLACK_BOTTOM_HEIGHT").toInt();
if (BlackBottomHeight < 0) BlackBottomHeight = 0;
else if (BlackBottomHeight > 480) BlackBottomHeight = 480;
else if (BlackBottomHeight > 480) BlackBottomHeight = 480;*/
AudioChannel = settings.value("AUDIO_CHANNEL").toInt();
if (AudioChannel <= 0 || AudioChannel > 20) AudioChannel = 2;
PrvwFlag = settings.value("PRVW_FLAG", "").toInt();
//PrvwFlag = settings.value("PRVW_FLAG", "").toInt();
OutputPlayMode = settings.value("OUTPUT_PLAY_MODE", "").toInt();
for(int i = 1;i <= 4;i++)
{
std::string key = "DELEY_TIME_" + std::to_string(i);
int value = settings.value(QString::fromStdString(key), "").toInt();
if (value < 1 * 1000) value = 1 * 1000;
//else if (value > 60 * 1000) value = 60 * 1000;
map_output_delay[i] = value;
}
//for(int i = 1;i <= 4;i++)
//{
// std::string key = "DELEY_TIME_" + std::to_string(i);
// int value = settings.value(QString::fromStdString(key), "").toInt();
// if (value < 1 * 1000) value = 1 * 1000;
// //else if (value > 60 * 1000) value = 60 * 1000;
// map_output_delay[i] = value;
//}
ScaleMode = settings.value("SCALE_MODE", "").toInt();
if (ScaleMode < 0) ScaleMode = 0;
......
......@@ -6,12 +6,12 @@
#define CUTBUFFERMAXSIZE 125*2
int ProcessThread::s_count = 0;
extern int OutputDeleyTime;
//extern int OutputDeleyTime;
extern int FrameRate;
extern int FrontDeleyTime;
extern int BlackBottomHeight;
//extern int BlackBottomHeight;
//extern int ScaleMode;
extern std::map<qint32, qint32> map_output_delay;
//extern std::map<qint32, qint32> map_output_delay;
extern std::map<qint32, qint32> map_scale_mode;
ProcessThread::ProcessThread()
......@@ -25,7 +25,7 @@ ProcessThread::ProcessThread()
{
idx = s_count++;
int key = idx + 1;
output_deley_time = map_output_delay[key];
//output_deley_time = map_output_delay[key];
minTaskImageQueueSize = FrontDeleyTime * FrameRate;
}
......
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