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