- Open/Save file
- Add CITP/MSEx menu
- Make Thumbs
- Init CITP/MSEx
This commit is contained in:
Santi Noreña 2013-02-11 17:52:36 +01:00
parent 62947ac256
commit ef52ae20d8
10 changed files with 278 additions and 265 deletions

View file

@ -37,7 +37,10 @@
#define PDPORTW_AUDIO 9197
#define PDPORTR_AUDIO 9198
#define SOCKET "/tmp/pmspipe"
#define SOCKET "/tmp/pmspipe" // Pipe wicho PD sends the files for preview in the GUI
#define CONF_FILE "lms.conf" // File when save/restore the configuration on exit/open
///////////////////////////////////////////////////////////////////
// Struct for the configuration files
@ -95,9 +98,6 @@ bool layer8Check_audio;
bool dmx_audio;
quint8 universe_audio;
bool audioCheck;
// Path to Media Files
QString path;
};
// Constructor
@ -137,10 +137,13 @@ libreMediaServer::libreMediaServer(QWidget *parent)
m_ola = new QProcess(this);
olastart();
// Conectamos los menus
connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(open()));
connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(save()));
connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(openFile()));
connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(ui.actionChange_Media_Path, SIGNAL(triggered()), this, SLOT(ChangeMediaPath()));
connect(ui.actionInitMSEX, SIGNAL(triggered()), this, SLOT(InitMSEX()));
// Load the configuration
open();
open_start();
// Connect MSEx
connect(m_msex,SIGNAL(frameRequest()), this, SLOT(sendFrame()));
}
@ -149,7 +152,7 @@ libreMediaServer::libreMediaServer(QWidget *parent)
libreMediaServer::~libreMediaServer()
{
save();
save_finish();
QFile socket(SOCKET);
socket.remove();
if (m_pd_write_video != NULL) {
@ -184,28 +187,100 @@ libreMediaServer::~libreMediaServer()
if (m_pd_write_audio != NULL)
{
m_pd_read_audio->close();
}
}
return;
}
///////////////////////////////////////////////////////////////////
// File Configuration Stuff
// open/save the last configuration known
///////////////////////////////////////////////////////////////////
// Load the last configuration from the file pms.conf
void libreMediaServer::open()
// Load the last configuration from the configuration file
void libreMediaServer::open_start()
{
QFile file("lms.conf");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<("Can not find the conf file");
QFile file(CONF_FILE);
open(&file);
}
// Save the last configuration to the conf file
void libreMediaServer::save_finish()
{
QFile file(CONF_FILE);
save(&file);
}
///////////////////////////////////////////////////////////////////
// Menu File
///////////////////////////////////////////////////////////////////
// Open a configuration File
void libreMediaServer::openFile()
{
QFileDialog dialog(this);
if (!dialog.exec())
return;
}
unsigned char * fileconf = new unsigned char[file.size()];
memset(fileconf, 0, file.size());
fileconf = file.map(0x00, file.size());
QStringList fileNames;
fileNames = dialog.selectedFiles();
QFile file(fileNames.at(0));
open(&file);
}
// Save configuration File
void libreMediaServer::saveFile()
{
QFileDialog dialog(this);
if (!dialog.exec())
return;
QStringList fileNames;
fileNames = dialog.selectedFiles();
QFile file(fileNames.at(0));
save(&file);
}
// Change Media path
void libreMediaServer::ChangeMediaPath()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
QStringList fileNames;
if (!dialog.exec())
return;
fileNames = dialog.selectedFiles();
QString file = fileNames.at(0);
m_pathmedia = file;
QString desc = tr("0000 0000 %1;").arg(file);
if (ui.video->checkState())
{
if (!sendPacket(desc.toAscii().constData(),desc.size()))
{
errorsending();
}
}
if (ui.audio->checkState())
{
if (!sendPacket_audio(desc.toAscii().constData(),desc.size()))
{
errorsending_audio();
}
}
desc = tr("Media Path Changed to: %1").arg(m_pathmedia);
ui.textEdit->appendPlainText(desc.toAscii());
}
///////////////////////////////////////////////////////////////////
// Open/save Subroutines. The real work.
///////////////////////////////////////////////////////////////////
void libreMediaServer::open(QFile *file)
{
if (!file->open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug()<<("Can not find the configuration file");
return;
}
int size = file->size();
unsigned char * fileconf = new unsigned char[size];
memset(fileconf, 0, size);
fileconf = file->map(0x00, size);
if (fileconf == 0){
qDebug()<<("Cannot map the file");
return;
@ -240,7 +315,6 @@ void libreMediaServer::open()
ui.ipAddress3->setValue(packet->ipadd3);
ui.ipAddress4->setValue(packet->ipadd4);
ui.video->setChecked(packet->videoCheck);
// Audio Configuration
ui.layer1Add_audio->setValue(packet->layer1Add_audio);
ui.layer1Check_audio->setChecked(packet->layer1Check_audio);
@ -261,29 +335,32 @@ void libreMediaServer::open()
ui.readDMX_audio->setChecked(packet->dmx_audio);
ui.universe_audio->setValue(packet->universe_audio);
ui.audio->setChecked(packet->audioCheck);
// Path to media
int offset = sizeof(struct conf) - 4;
int size = file.size() - offset;
// Path to media
int offset = sizeof(struct conf);
size = size - offset;
char * buffer = new char[size];
memset(buffer, 0, size);
memcpy(buffer, fileconf+offset, size);
m_pathmedia = buffer;
QString desc = tr("Media Path Changed to: %1").arg(m_pathmedia);
qDebug()<<(desc);
file.close();
file->close();
delete buffer;
// delete fileconf; // Comment due to Seg Fault
}
// Save the configuration to pms.conf file
void libreMediaServer::save()
void libreMediaServer::save(QFile *file)
{
if (!file->open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug()<<("Can not open file pms.conf");
return;
}
int bufferLen = sizeof(struct conf) + m_pathmedia.size();
unsigned char *buffer = new unsigned char[bufferLen];
memset(buffer, 0, bufferLen);
conf *packet = (conf *)buffer;
// Video Configuration
packet->window = ui.window->checkState();
packet->winpositionx = ui.winpositionx->value();
packet->winpositiony = ui.winpositiony->value();
@ -312,9 +389,7 @@ void libreMediaServer::save()
packet->ipadd3 = ui.ipAddress3->value();
packet->ipadd4 = ui.ipAddress4->value();
packet->videoCheck = ui.video->checkState();
// Audio Configuration
packet->layer1Add_audio = ui.layer1Add_audio->value();
packet->layer1Check_audio = ui.layer1Check_audio->checkState();
packet->layer2Add_audio = ui.layer2Add_audio->value();
@ -334,21 +409,13 @@ void libreMediaServer::save()
packet->dmx_audio = ui.readDMX_audio->checkState();
packet->universe_audio = ui.universe_audio->value();
packet->audioCheck = ui.audio->checkState();
// Path to media
int offset = sizeof (struct conf) - 4;
int offset = sizeof (struct conf);
memcpy(buffer+offset, m_pathmedia.toAscii().constData(), m_pathmedia.size());
QFile file("lms.conf");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
qDebug()<<("Can not open file pms.conf");
return;
}
int error = file.write((const char *)buffer, bufferLen);
int error = file->write((const char *)buffer, bufferLen);
QString errorstring = tr("Bytes Write to file %1").arg(error);
qDebug()<<"Saved file complete:"<<(errorstring);
file.close();
file->close();
delete buffer;
}
@ -367,51 +434,14 @@ void libreMediaServer::olastart()
* User Interface Stuff
*/
///////////////////////////////////////////////////////////////////
// Global Controls
///////////////////////////////////////////////////////////////////
// Change Media path
void libreMediaServer::on_ChangePath_clicked()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
QStringList fileNames;
if (!dialog.exec())
return;
fileNames = dialog.selectedFiles();
QString file = fileNames.at(0);
m_pathmedia = file;
QString desc = tr("0000 0000 %1;").arg(file);
if (ui.video->checkState())
{
if (!sendPacket(desc.toAscii().constData(),desc.size()))
{
errorsending();
}
}
if (ui.audio->checkState())
{
if (!sendPacket_audio(desc.toAscii().constData(),desc.size()))
{
errorsending_audio();
}
}
desc = tr("Media Path Changed to: %1").arg(m_pathmedia);
ui.textEdit->appendPlainText(desc.toAscii());
}
///////////////////////////////////////////////////////////////////
// Video Controls
// Menu CITP/MSEx
///////////////////////////////////////////////////////////////////
// Init the CITP/MSEx protocol.
// Begins the CITP/MSEx protocol
// ToDo: Include thumbs generation here
void libreMediaServer::on_updateButton_clicked()
void libreMediaServer::initMSEX()
{
// Chequeamos si existe el path a los medias
QDir dir(m_pathmedia);
@ -441,9 +471,21 @@ void libreMediaServer::on_updateButton_clicked()
ipadd = ipadd + i;
m_msex->startCitp(ipadd);
}
//void setIPAdd();
// Generates the thumbs to transmit by CITP/MSEx
void libreMediaServer::makeThumbs()
{
QProcess *script = new QProcess ();
QStringList arguments;
arguments << m_pathmedia;
script->execute("./scripts/make_thumbs.sh", arguments);
}
///////////////////////////////////////////////////////////////////
// Video Controls
///////////////////////////////////////////////////////////////////
// Window Configuration
void libreMediaServer::on_window_stateChanged(int state)
{
if ((state == 2)) {
@ -897,7 +939,7 @@ void libreMediaServer::pdrestart()
{
return;
}
save();
save_finish();
qDebug()<<"Restarting PD";
ui.textEdit->appendPlainText("PD Restarting...");
disconnect(m_pd_video, SIGNAL(finished(int)), this, SLOT(pdrestart()));
@ -926,7 +968,7 @@ void libreMediaServer::newmessage()
QByteArray byteArray;
byteArray.resize(m_read_vid->bytesAvailable());
byteArray = m_read_vid->readAll();
if (byteArray == NULL)
if (byteArray.isEmpty())
{
return;
}
@ -1424,7 +1466,7 @@ void libreMediaServer::stdout_audio() {
void libreMediaServer::pdrestart_audio()
{
save();
save_finish();
qDebug()<<"Restarting PD audio";
ui.textEdit->appendPlainText("PD audio Restarting...");
int state = m_pd_audio->state();
@ -1593,7 +1635,7 @@ void libreMediaServer::sendFrame()
qDebug()<<"sendFrame: Can not convert screen capture to image";
return;
}
image = image.scaledToWidth(88);http://palmadores.net/index.php
image = image.scaledToWidth(88);
image = image.convertToFormat(QImage::Format_RGB888);
int bufferLen = image.byteCount();
int bufferLenTot = sizeof(struct CITP_MSEX_10_StFr ) + bufferLen;

View file

@ -71,6 +71,10 @@ private:
bool sendPacket_audio(const char *buffer, int bufferLen);
void pdstart_audio();
void errorsending_audio();
void open_start();
void save_finish();
void open(QFile *file);
void save(QFile *file);
public slots:
@ -79,11 +83,7 @@ public slots:
private slots:
void olastart(); // Init the OLA daemon
void on_ChangePath_clicked();// Change the path to medias
// Video
void on_updateButton_clicked(); // Init the CITP/MSEx protocol
// Video
void newPeer();
void newmessage();
void newconexion();
@ -112,9 +112,7 @@ private slots:
void pdrestart();
void stdout();
void on_video_stateChanged(int state);
//Audio
void newPeer_audio();
void newmessage_audio();
void newconexion_audio();
@ -138,16 +136,16 @@ private slots:
void pdrestart_audio();
void stdout_audio();
void on_audio_stateChanged(int state);
// File configuration
void open();
void save();
// Previews
void previewMaster();
// Preview
void previewMaster();
// Menu File
void openFile();
void saveFile();
void ChangeMediaPath();// Change the path to medias
// Menu CITP/MSEx
void initMSEX(); // Init the CITP/MSEx protocol
// void setIPAdd();
void makeThumbs();
};
#endif // LIBREMEDIASERVER_H

View file

@ -7,8 +7,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>789</width>
<height>615</height>
<width>773</width>
<height>626</height>
</rect>
</property>
<property name="windowTitle">
@ -23,7 +23,7 @@
<rect>
<x>0</x>
<y>120</y>
<width>791</width>
<width>831</width>
<height>441</height>
</rect>
</property>
@ -37,7 +37,7 @@
<enum>QTabWidget::Rounded</enum>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<property name="usesScrollButtons">
<bool>false</bool>
@ -175,19 +175,6 @@
<number>512</number>
</property>
</widget>
<widget class="QPushButton" name="updateButton">
<property name="geometry">
<rect>
<x>490</x>
<y>190</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Init CITP/MSEx</string>
</property>
</widget>
<widget class="QSpinBox" name="layer3Add">
<property name="geometry">
<rect>
@ -645,22 +632,6 @@
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="ChangePath">
<property name="geometry">
<rect>
<x>470</x>
<y>150</y>
<width>150</width>
<height>28</height>
</rect>
</property>
<property name="whatsThis">
<string>Change the path to your media tree </string>
</property>
<property name="text">
<string>Change Media Path</string>
</property>
</widget>
<widget class="QLabel" name="masterPreview">
<property name="geometry">
<rect>
@ -693,7 +664,6 @@
<zorder>layer6Add</zorder>
<zorder>window</zorder>
<zorder>layer7Add</zorder>
<zorder>updateButton</zorder>
<zorder>layer3Add</zorder>
<zorder>layer8Check</zorder>
<zorder>layer2Add</zorder>
@ -721,7 +691,6 @@
<zorder>layer6Preview</zorder>
<zorder>layer7Preview</zorder>
<zorder>layer8Preview</zorder>
<zorder>ChangePath</zorder>
<zorder>masterPreview</zorder>
</widget>
<widget class="QWidget" name="Audio">
@ -1124,7 +1093,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>801</width>
<width>751</width>
<height>121</height>
</rect>
</property>
@ -1141,8 +1110,8 @@ This program comes with ABSOLUTELY NO WARRANTY</string>
<rect>
<x>0</x>
<y>0</y>
<width>789</width>
<height>25</height>
<width>773</width>
<height>29</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -1151,8 +1120,18 @@ This program comes with ABSOLUTELY NO WARRANTY</string>
</property>
<addaction name="actionOpen_conf"/>
<addaction name="actionSave_conf"/>
<addaction name="actionChange_Media_Path"/>
</widget>
<widget class="QMenu" name="menuCITP_MSEx">
<property name="title">
<string>CITP/MSEx</string>
</property>
<addaction name="actionInitMSEX"/>
<addaction name="actionIP_Address"/>
<addaction name="actionMake_Thumbs"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuCITP_MSEx"/>
</widget>
<action name="actionExit">
<property name="text">
@ -1161,12 +1140,35 @@ This program comes with ABSOLUTELY NO WARRANTY</string>
</action>
<action name="actionOpen_conf">
<property name="text">
<string>Open conf</string>
<string>Open Configuration</string>
</property>
</action>
<action name="actionSave_conf">
<property name="text">
<string>Save conf</string>
<string>Save Configuration</string>
</property>
</action>
<action name="actionChange_Media_Path">
<property name="text">
<string>Change Media Path</string>
</property>
</action>
<action name="actionInitMSEX">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Init</string>
</property>
</action>
<action name="actionIP_Address">
<property name="text">
<string>IP Address</string>
</property>
</action>
<action name="actionMake_Thumbs">
<property name="text">
<string>Make Thumbs</string>
</property>
</action>
</widget>