mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-07 17:32:20 +02:00
2017-08-18 Fred Gleason <fredg@paravelsystems.com>
* Added rdrender(1) in 'utils/rdrender/'.
This commit is contained in:
parent
040efdd3f0
commit
2b389602ba
1
.gitignore
vendored
1
.gitignore
vendored
@ -107,6 +107,7 @@ utils/rdcollect/rdcollect
|
||||
utils/rdexport/rdexport
|
||||
utils/rdmaint/rdmaint
|
||||
utils/rdgen/rdgen
|
||||
utils/rdrender/rdrender
|
||||
utils/rdrevert/rdrevert
|
||||
utils/sas_shim/sas_shim
|
||||
web/rdfeed/rdfeed.xml
|
||||
|
@ -15960,3 +15960,5 @@
|
||||
* Added fixup code in 'rdadmin/createdb.cpp' to recalculate
|
||||
voice track counts.
|
||||
* Incremented the database version to 266.
|
||||
2017-08-18 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added rdrender(1) in 'utils/rdrender/'.
|
||||
|
@ -489,6 +489,7 @@ AC_CONFIG_FILES([rivendell.spec \
|
||||
utils/rdmarkerset/Makefile \
|
||||
utils/rdpopup/Makefile \
|
||||
utils/rdpurgecasts/Makefile \
|
||||
utils/rdrender/Makefile \
|
||||
utils/rdrevert/Makefile \
|
||||
utils/rdsoftkeys/Makefile \
|
||||
utils/rmlsend/Makefile \
|
||||
|
@ -244,6 +244,7 @@ rm -rf $RPM_BUILD_ROOT
|
||||
@LOCAL_PREFIX@/bin/rd_backup
|
||||
@LOCAL_PREFIX@/bin/rdchunk
|
||||
@LOCAL_PREFIX@/bin/rdmemcheck.sh
|
||||
@LOCAL_PREFIX@/bin/rdrender
|
||||
%attr(4755,root,root)@LOCAL_PREFIX@/bin/ripcd
|
||||
@LOCAL_PREFIX@/sbin/sas_shim
|
||||
@LOCAL_PREFIX@/sbin/rddbcheck
|
||||
|
@ -46,6 +46,7 @@ SUBDIRS = $(ALSACONFIG_RD_OPT)\
|
||||
rdmarkerset\
|
||||
rdpopup\
|
||||
rdpurgecasts\
|
||||
rdrender\
|
||||
rdrevert\
|
||||
rdsoftkeys\
|
||||
rmlsend\
|
||||
|
49
utils/rdrender/Makefile.am
Normal file
49
utils/rdrender/Makefile.am
Normal file
@ -0,0 +1,49 @@
|
||||
## automake.am
|
||||
##
|
||||
## Automake.am for rivendell/utils/rdrender
|
||||
##
|
||||
## (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify
|
||||
## it under the terms of the GNU General Public License version 2 as
|
||||
## published by the Free Software Foundation.
|
||||
##
|
||||
## 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, write to the Free Software
|
||||
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
##
|
||||
## Use automake to process this into a Makefile.in
|
||||
|
||||
AM_CPPFLAGS = -Wall -DPREFIX=\"$(prefix)\" -DQTDIR=\"@QT_DIR@\" @QT_CXXFLAGS@ -I$(top_srcdir)/lib
|
||||
LIBS = @QT_LIBS@ -L$(top_srcdir)/lib
|
||||
MOC = @QT_MOC@
|
||||
|
||||
# The dependency for qt's Meta Object Compiler (moc)
|
||||
moc_%.cpp: %.h
|
||||
$(MOC) $< -o $@
|
||||
|
||||
bin_PROGRAMS = rdrender
|
||||
|
||||
dist_rdrender_SOURCES = mainloop.cpp\
|
||||
rdrender.cpp rdrender.h
|
||||
|
||||
nodist_rdrender_SOURCES = moc_rdrender.cpp
|
||||
|
||||
rdrender_LDADD = @LIB_RDLIBS@ @LIBVORBIS@
|
||||
|
||||
CLEANFILES = *~\
|
||||
*.idb\
|
||||
*ilk\
|
||||
*.obj\
|
||||
*.pdb\
|
||||
*.qm\
|
||||
moc_*
|
||||
|
||||
MAINTAINERCLEANFILES = *~\
|
||||
Makefile.in\
|
||||
moc_*
|
103
utils/rdrender/mainloop.cpp
Normal file
103
utils/rdrender/mainloop.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
// mainloop.cpp
|
||||
//
|
||||
// Render a Rivendell log.
|
||||
//
|
||||
// (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include <rdcart.h>
|
||||
#include <rdcut.h>
|
||||
#include <rdlog.h>
|
||||
#include <rdlog_event.h>
|
||||
#include <rdlog_line.h>
|
||||
|
||||
#include "rdrender.h"
|
||||
|
||||
int MainObject::MainLoop()
|
||||
{
|
||||
static float pcm[16384];
|
||||
QTime current_time=render_start_time;
|
||||
// QDate current_date=render_start_date;
|
||||
|
||||
//
|
||||
// Open Endpoints
|
||||
//
|
||||
RDLog *log=new RDLog(render_logname);
|
||||
if(!log->exists()) {
|
||||
fprintf(stderr,"rdrender: no such log\n");
|
||||
return 1;
|
||||
}
|
||||
RDLogEvent *log_event=new RDLogEvent(RDLog::tableName(render_logname));
|
||||
log_event->load();
|
||||
|
||||
SF_INFO sf_info;
|
||||
memset(&sf_info,0,sizeof(sf_info));
|
||||
sf_info.samplerate=render_system->sampleRate();
|
||||
sf_info.channels=render_channels;
|
||||
sf_info.format=SF_FORMAT_WAV|SF_FORMAT_PCM_16;
|
||||
SNDFILE *sf_out=sf_open(render_output_filename,SFM_WRITE,&sf_info);
|
||||
if(sf_out==NULL) {
|
||||
fprintf(stderr,"rdrender: unable to open output file [%s]\n",
|
||||
sf_strerror(sf_out));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Iterate through the log
|
||||
//
|
||||
for(int i=0;i<log_event->size();i++) {
|
||||
RDLogLine *ll=log_event->logLine(i);
|
||||
if(ll->type()==RDLogLine::Cart) {
|
||||
RDCart *cart=new RDCart(ll->cartNumber());
|
||||
if(cart->exists()&&(cart->type()==RDCart::Audio)) {
|
||||
QString cutname;
|
||||
if(cart->selectCut(&cutname,current_time)) {
|
||||
RDCut *cut=new RDCut(cutname);
|
||||
//
|
||||
// FIXME: This breaks on setups where caed(8) has been delegated
|
||||
// to a different host!
|
||||
//
|
||||
// FIXME: This breaks with MPEG audio stores!
|
||||
//
|
||||
QString filename;
|
||||
if(GetCutFile(cutname,cut->startPoint(),cut->endPoint(),&filename)) {
|
||||
SNDFILE *sf_in=sf_open(filename,SFM_READ,&sf_info);
|
||||
int n;
|
||||
if(sf_in!=NULL) {
|
||||
DeleteCutFile(filename);
|
||||
while((n=sf_readf_float(sf_in,pcm,8192))>0) {
|
||||
sf_writef_float(sf_out,pcm,n);
|
||||
}
|
||||
sf_close(sf_in);
|
||||
}
|
||||
}
|
||||
delete cut;
|
||||
}
|
||||
}
|
||||
delete cart;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Clean up
|
||||
//
|
||||
sf_close(sf_out);
|
||||
return 0;
|
||||
}
|
234
utils/rdrender/rdrender.cpp
Normal file
234
utils/rdrender/rdrender.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
// rdrender.cpp
|
||||
//
|
||||
// Render a Rivendell log.
|
||||
//
|
||||
// (C) Copyright 2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
#include <qdir.h>
|
||||
#include <qfile.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdaudioexport.h>
|
||||
#include <rdcart.h>
|
||||
#include <rdcmd_switch.h>
|
||||
#include <rdconf.h>
|
||||
#include <rdescape_string.h>
|
||||
#include <rddbheartbeat.h>
|
||||
#include <rdsettings.h>
|
||||
|
||||
#include "rdrender.h"
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
render_verbose=false;
|
||||
render_channels=RDRENDER_DEFAULT_CHANNELS;
|
||||
render_start_date=QDate::currentDate();
|
||||
render_start_time=QTime::currentTime();
|
||||
|
||||
//
|
||||
// Read Command Options
|
||||
//
|
||||
RDCmdSwitch *cmd=
|
||||
new RDCmdSwitch(qApp->argc(),qApp->argv(),"rdimport",RDRENDER_USAGE);
|
||||
if(cmd->keys()<1) {
|
||||
fprintf(stderr,
|
||||
"rdrender: you must specify a logname and output filename\n");
|
||||
exit(256);
|
||||
}
|
||||
if(cmd->keys()<2) {
|
||||
fprintf(stderr,
|
||||
"rdrender: you must specify an output filename\n");
|
||||
exit(256);
|
||||
}
|
||||
for(int i=0;i<(int)cmd->keys()-2;i++) {
|
||||
bool ok=false;
|
||||
if(cmd->key(i)=="--verbose") {
|
||||
render_verbose=true;
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--channels") {
|
||||
render_channels=cmd->value(i).toUInt(&ok);
|
||||
if((!ok)||(render_channels>2)) {
|
||||
fprintf(stderr,"rdrender: invalid --channels argument\n");
|
||||
exit(1);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--start-date") {
|
||||
render_start_date=QDate::fromString(cmd->value(i),Qt::ISODate);
|
||||
if(!render_start_date.isValid()) {
|
||||
fprintf(stderr,"rdrender: invalid --start-date\n");
|
||||
exit(1);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--start-time") {
|
||||
render_start_time=QTime::fromString(cmd->value(i));
|
||||
if(!render_start_time.isValid()) {
|
||||
fprintf(stderr,"rdrender: invalid --start-time\n");
|
||||
exit(1);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(!cmd->processed(i)) {
|
||||
fprintf(stderr,"rdrender: unrecognized option\n");
|
||||
qApp->exit(256);
|
||||
}
|
||||
}
|
||||
render_logname=cmd->key(cmd->keys()-2);
|
||||
render_output_filename=cmd->key(cmd->keys()-1);
|
||||
|
||||
//
|
||||
// Read Configuration
|
||||
//
|
||||
render_config=new RDConfig();
|
||||
render_config->load();
|
||||
|
||||
//
|
||||
// Open Database
|
||||
//
|
||||
QSqlDatabase *db=QSqlDatabase::addDatabase(render_config->mysqlDriver());
|
||||
if(!db) {
|
||||
fprintf(stderr,"rdrender: unable to initialize connection to database\n");
|
||||
exit(256);
|
||||
}
|
||||
db->setDatabaseName(render_config->mysqlDbname());
|
||||
db->setUserName(render_config->mysqlUsername());
|
||||
db->setPassword(render_config->mysqlPassword());
|
||||
db->setHostName(render_config->mysqlHostname());
|
||||
if(!db->open()) {
|
||||
fprintf(stderr,"rdimport: unable to connect to database\n");
|
||||
db->removeDatabase(render_config->mysqlDbname());
|
||||
exit(256);
|
||||
}
|
||||
new RDDbHeartbeat(render_config->mysqlHeartbeatInterval(),this);
|
||||
|
||||
//
|
||||
// RIPC Connection
|
||||
//
|
||||
render_ripc=new RDRipc(render_config->stationName());
|
||||
connect(render_ripc,SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
render_ripc->
|
||||
connectHost("localhost",RIPCD_TCP_PORT,render_config->password());
|
||||
|
||||
//
|
||||
// System Configuration
|
||||
//
|
||||
render_system=new RDSystem();
|
||||
|
||||
//
|
||||
// Station Configuration
|
||||
//
|
||||
render_station=new RDStation(render_config->stationName());
|
||||
|
||||
//
|
||||
// User
|
||||
//
|
||||
render_user=NULL;
|
||||
}
|
||||
|
||||
|
||||
void MainObject::userData()
|
||||
{
|
||||
//
|
||||
// Get User Context
|
||||
//
|
||||
disconnect(render_ripc,SIGNAL(userChanged()),this,SLOT(userData()));
|
||||
if(render_user!=NULL) {
|
||||
delete render_user;
|
||||
}
|
||||
render_user=new RDUser(render_ripc->user());
|
||||
|
||||
exit(MainLoop());
|
||||
}
|
||||
|
||||
|
||||
uint64_t MainObject::FramesFromMsec(uint64_t msec)
|
||||
{
|
||||
return msec*render_system->sampleRate()/1000;
|
||||
}
|
||||
|
||||
|
||||
void MainObject::Verbose(const QString &msg)
|
||||
{
|
||||
if(render_verbose) {
|
||||
fprintf(stderr,"%s\n",(const char *)msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MainObject::GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const
|
||||
{
|
||||
bool ret=false;
|
||||
RDAudioConvert::ErrorCode conv_err;
|
||||
RDAudioExport::ErrorCode export_err;
|
||||
char tempdir[PATH_MAX];
|
||||
|
||||
strncpy(tempdir,RDTempDir()+"/rdrenderXXXXXX",PATH_MAX);
|
||||
*dest_filename=QString(mkdtemp(tempdir))+"/"+cutname+".wav";
|
||||
RDAudioExport *conv=new RDAudioExport(render_station,render_config);
|
||||
conv->setDestinationFile(*dest_filename);
|
||||
conv->setCartNumber(RDCut::cartNumber(cutname));
|
||||
conv->setCutNumber(RDCut::cutNumber(cutname));
|
||||
RDSettings s;
|
||||
s.setFormat(RDSettings::Pcm16);
|
||||
s.setSampleRate(render_system->sampleRate());
|
||||
s.setChannels(render_channels);
|
||||
s.setNormalizationLevel(0);
|
||||
conv->setDestinationSettings(&s);
|
||||
conv->setRange(start_pt,end_pt);
|
||||
conv->setEnableMetadata(false);
|
||||
switch(export_err=conv->runExport(render_user->name(),
|
||||
render_user->password(),&conv_err)) {
|
||||
case RDAudioExport::ErrorOk:
|
||||
ret=true;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret=false;
|
||||
printf("export err %d [%s]\n",export_err,
|
||||
(const char *)RDAudioExport::errorText(export_err,conv_err));
|
||||
break;
|
||||
}
|
||||
|
||||
delete conv;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void MainObject::DeleteCutFile(const QString &dest_filename) const
|
||||
{
|
||||
unlink(dest_filename);
|
||||
QStringList f0=f0.split("/",dest_filename);
|
||||
f0.erase(f0.fromLast());
|
||||
rmdir("/"+f0.join("/"));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
QApplication a(argc,argv,false);
|
||||
new MainObject();
|
||||
return a.exec();
|
||||
}
|
69
utils/rdrender/rdrender.h
Normal file
69
utils/rdrender/rdrender.h
Normal file
@ -0,0 +1,69 @@
|
||||
// rdrender.h
|
||||
//
|
||||
// Render a Rivendell log.
|
||||
//
|
||||
// (C) Copyright 2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// 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, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef RDRENDER_H
|
||||
#define RDRENDER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <qdatetime.h>
|
||||
#include <qobject.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
#include <rddb.h>
|
||||
#include <rdripc.h>
|
||||
#include <rdstation.h>
|
||||
#include <rdsystem.h>
|
||||
#include <rduser.h>
|
||||
|
||||
#define RDRENDER_DEFAULT_CHANNELS 2
|
||||
#define RDRENDER_USAGE "[options] <logname> <output-file>\n"
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
Q_OBJECT;
|
||||
public:
|
||||
MainObject(QObject *parent=0);
|
||||
|
||||
private slots:
|
||||
void userData();
|
||||
|
||||
private:
|
||||
int MainLoop();
|
||||
uint64_t FramesFromMsec(uint64_t msec);
|
||||
void Verbose(const QString &msg);
|
||||
bool GetCutFile(const QString &cutname,int start_pt,int end_pt,
|
||||
QString *dest_filename) const;
|
||||
void DeleteCutFile(const QString &dest_filename) const;
|
||||
bool render_verbose;
|
||||
QString render_logname;
|
||||
QString render_output_filename;
|
||||
unsigned render_channels;
|
||||
QDate render_start_date;
|
||||
QTime render_start_time;
|
||||
RDRipc *render_ripc;
|
||||
RDStation *render_station;
|
||||
RDSystem *render_system;
|
||||
RDUser *render_user;
|
||||
RDConfig *render_config;
|
||||
};
|
||||
|
||||
|
||||
#endif // RDRENDER_H
|
Loading…
x
Reference in New Issue
Block a user