2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
2016-04-24 18:33:04 +12:00
|
|
|
#if (!(defined(x64) || defined(__LP64__) || defined(LINUX)))
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Toonz stuff
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "tiio.h"
|
|
|
|
#include "timage_io.h"
|
|
|
|
#include "tlevel_io.h"
|
|
|
|
#include "trasterimage.h"
|
|
|
|
#include "traster.h"
|
|
|
|
#include "tstream.h"
|
|
|
|
#include "movsettings.h"
|
|
|
|
#include "tproperty.h"
|
|
|
|
#include "tsound.h"
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include "../image/3gp/tiio_3gp.h"
|
|
|
|
#elif MACOSX
|
|
|
|
#include "../image/3gp/tiio_3gpM.h"
|
|
|
|
#endif
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Qt stuff
|
2016-03-19 06:57:51 +13:00
|
|
|
#include <QString>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QSharedMemory>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <QDataStream>
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// tipc includes
|
2016-03-19 06:57:51 +13:00
|
|
|
#include "tipc.h"
|
|
|
|
#include "tipcmsg.h"
|
|
|
|
#include "tipcsrv.h"
|
|
|
|
#include "t32bitsrv_wrap.h"
|
|
|
|
|
|
|
|
#include "t323gpmsg.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
|
|
|
|
// Local namespace stuff
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace {
|
2016-03-19 06:57:51 +13:00
|
|
|
QHash<unsigned int, TLevelReaderP> readers;
|
|
|
|
QHash<unsigned int, TLevelWriterP> writers;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------
|
|
|
|
|
|
|
|
using namespace tipc;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace _3gp_io {
|
|
|
|
|
|
|
|
void addParsers(tipc::Server *srv) {
|
|
|
|
srv->addParser(new InitLW3gpParser);
|
|
|
|
srv->addParser(new LWSetFrameRateParser);
|
|
|
|
srv->addParser(new LWImageWriteParser);
|
|
|
|
srv->addParser(new LWSaveSoundTrackParser);
|
|
|
|
srv->addParser(new CloseLW3gpParser);
|
|
|
|
srv->addParser(new InitLR3gpParser);
|
|
|
|
srv->addParser(new LRLoadInfoParser);
|
|
|
|
srv->addParser(new LREnableRandomAccessReadParser);
|
|
|
|
srv->addParser(new LRImageReadParser);
|
|
|
|
srv->addParser(new CloseLR3gpParser);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// InitLWMov Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void InitLW3gpParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
QString fp, propsFp;
|
|
|
|
msg >> id >> fp >> propsFp >> clr;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath tfp(fp.toStdWString()), propsTFp(propsFp.toStdWString());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
try {
|
|
|
|
TPropertyGroup *props = 0;
|
|
|
|
if (!propsTFp.isEmpty()) {
|
|
|
|
props = new TPropertyGroup;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TIStream is(propsTFp);
|
|
|
|
props->loadData(is);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
writers.insert(id, TLevelWriterP(tfp, props));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("ok");
|
|
|
|
} catch (...) {
|
|
|
|
msg << QString("err");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LWsetFrameRate Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LWSetFrameRateParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
double fps;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg >> id >> fps >> clr;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
writers.find(id).value()->setFrameRate(fps);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("ok");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LWImageWrite Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LWImageWriteParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
int frameIdx, lx, ly;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg >> id >> frameIdx >> lx >> ly;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Read the data through a shared memory segment
|
|
|
|
TRaster32P ras(lx, ly);
|
|
|
|
t32bitsrv::RasterExchanger<TPixel32> exch(ras);
|
|
|
|
tipc::readShMemBuffer(*stream(), msg, &exch);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Save the image
|
|
|
|
try {
|
|
|
|
TImageWriterP iw(writers.find(id).value()->getFrameWriter(frameIdx + 1));
|
|
|
|
iw->save(TRasterImageP(ras));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("ok");
|
|
|
|
} catch (...) {
|
|
|
|
msg << QString("err");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LWSaveSoundTrack Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LWSaveSoundTrackParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
QString shMemId;
|
|
|
|
|
|
|
|
TUINT32 sampleRate;
|
|
|
|
TINT32 sCount;
|
|
|
|
int bps, chanCount;
|
|
|
|
bool signedSample;
|
|
|
|
|
|
|
|
msg >> id >> sampleRate >> bps >> chanCount >> sCount >> signedSample;
|
|
|
|
|
|
|
|
// Retrieve the soundtrack buffer
|
|
|
|
TSoundTrackP st =
|
|
|
|
TSoundTrack::create(sampleRate, bps, chanCount, sCount, signedSample);
|
|
|
|
t32bitsrv::BufferExchanger exch((UCHAR *)st->getRawData());
|
|
|
|
tipc::readShMemBuffer(*stream(), msg, &exch);
|
|
|
|
|
|
|
|
// Write the soundtrack
|
|
|
|
try {
|
|
|
|
writers.find(id).value()->saveSoundTrack(st.getPointer());
|
|
|
|
msg << QString("ok");
|
|
|
|
} catch (...) {
|
|
|
|
msg << QString("err");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// CloseLW3gp Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CloseLW3gpParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
msg >> id >> clr;
|
|
|
|
|
|
|
|
try {
|
|
|
|
writers.take(id);
|
|
|
|
msg << QString("ok");
|
|
|
|
} catch (...) {
|
|
|
|
msg << QString("err");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// InitLR3gp Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void InitLR3gpParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
QString fp, propsFp;
|
|
|
|
msg >> id >> fp >> clr;
|
|
|
|
assert(!fp.isEmpty());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFilePath tfp(fp.toStdWString());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
try {
|
|
|
|
TLevelReaderP lrm(tfp);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Extract some info to be returned
|
|
|
|
const TImageInfo *info = lrm->getImageInfo();
|
|
|
|
if (!info) throw TImageException(tfp, "Couldn't retrieve image properties");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
int lx = info->m_lx, ly = info->m_ly;
|
|
|
|
double frameRate = info->m_frameRate;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
readers.insert(id, lrm);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("ok") << lx << ly << frameRate;
|
|
|
|
} catch (...) {
|
|
|
|
msg << QString("err");
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LRLoadInfo Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LRLoadInfoParser::operator()(Message &msg) {
|
|
|
|
// Read command data
|
|
|
|
unsigned int id;
|
|
|
|
QString shMemId;
|
|
|
|
msg >> id >> shMemId >> clr;
|
|
|
|
|
|
|
|
QHash<unsigned int, TLevelReaderP>::iterator it = readers.find(id);
|
|
|
|
if (it == readers.end()) goto err;
|
|
|
|
|
|
|
|
// Read level infos
|
|
|
|
{
|
|
|
|
TLevelP level;
|
|
|
|
try {
|
|
|
|
level = it.value()->loadInfo();
|
|
|
|
} catch (...) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int frameCount = level->getFrameCount();
|
|
|
|
if (!shMemId.isEmpty()) {
|
|
|
|
// Create a shared memory segment to transfer the infos to
|
|
|
|
tipc::DefaultMessageParser<SHMEM_REQUEST> msgParser;
|
|
|
|
Message shMsg;
|
|
|
|
|
|
|
|
shMsg << shMemId << frameCount * (int)sizeof(int) << reset;
|
|
|
|
msgParser(shMsg);
|
|
|
|
|
|
|
|
QString str;
|
|
|
|
shMsg >> reset >> str;
|
|
|
|
if (str != QString("ok")) goto err;
|
|
|
|
|
|
|
|
// Copy level data to the shared memory segment
|
|
|
|
{
|
|
|
|
QSharedMemory shmem(shMemId);
|
|
|
|
shmem.attach();
|
|
|
|
shmem.lock();
|
|
|
|
|
|
|
|
TLevel::Table *table = level->getTable();
|
|
|
|
|
|
|
|
TLevel::Table::const_iterator jt;
|
|
|
|
int *f = (int *)shmem.data();
|
|
|
|
for (jt = table->begin(); jt != table->end(); ++jt, ++f)
|
|
|
|
*f = jt->first.getNumber();
|
|
|
|
|
|
|
|
shmem.unlock();
|
|
|
|
shmem.detach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg << QString("ok") << frameCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
err:
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("err");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LREnableRandomAccessRead Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LREnableRandomAccessReadParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
QString str;
|
|
|
|
msg >> id >> str >> clr;
|
|
|
|
bool enable = (str == "true");
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QHash<unsigned int, TLevelReaderP>::iterator it = readers.find(id);
|
|
|
|
if (it == readers.end()) {
|
|
|
|
msg << QString("err");
|
|
|
|
return;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
it.value()->enableRandomAccessRead(enable);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("ok");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// LRImageRead Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void LRImageReadParser::operator()(Message &msg) {
|
|
|
|
{
|
|
|
|
unsigned int id;
|
|
|
|
int lx, ly, pixSize, frameIdx, x, y, shrinkX, shrinkY;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg >> id >> lx >> ly >> pixSize >> frameIdx >> x >> y >> shrinkX >>
|
|
|
|
shrinkY >> clr;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
if (pixSize != 4) goto err;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
QHash<unsigned int, TLevelReaderP>::iterator it = readers.find(id);
|
|
|
|
if (it == readers.end()) goto err;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
// Load the raster
|
|
|
|
TRaster32P ras(lx, ly);
|
|
|
|
try {
|
|
|
|
TImageReaderP ir(it.value()->getFrameReader(frameIdx + 1));
|
|
|
|
ir->load(ras, TPoint(x, y), shrinkX, shrinkY);
|
|
|
|
} catch (...) {
|
|
|
|
goto err;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
t32bitsrv::RasterExchanger<TPixel32> exch(ras);
|
|
|
|
if (!tipc::writeShMemBuffer(*stream(), msg << clr,
|
|
|
|
lx * ly * sizeof(TPixel32), &exch))
|
|
|
|
goto err;
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
return;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
err:
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
msg << QString("err");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//************************************************************************
|
|
|
|
// CloseLRMov Parser
|
|
|
|
//************************************************************************
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void CloseLR3gpParser::operator()(Message &msg) {
|
|
|
|
unsigned int id;
|
|
|
|
msg >> id >> clr;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
readers.take(id);
|
|
|
|
msg << QString("ok");
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace mov_io
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // !x64 && !__LP64__
|