Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Campbell Barton deffae
#if (defined(x64) || defined(__LP64__) || defined(LINUX))
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Toonz includes
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "trasterimage.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "timageinfo.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tsound.h"
shun-iwasawa 2fb6b9
#include "tmsgcore.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// tipc includes
Toshihiro Shimizu 890ddd
#include "tipc.h"
Toshihiro Shimizu 890ddd
#include "t32bitsrv_wrap.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Qt includes
Toshihiro Shimizu 890ddd
#include <qsharedmemory></qsharedmemory>
Toshihiro Shimizu 890ddd
#include <qmutexlocker></qmutexlocker>
Toshihiro Shimizu 890ddd
#include <qdatastream></qdatastream>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tiio_3gp_proxy.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  For a list of supported commands through the 32-bit background server,
Toshihiro Shimizu 890ddd
  see the related "t32libserver" project.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    Generic stuff implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*NOT PRESENT: Inherits the MOV stuff*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    TImageWriter3gp Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TImageWriter3gpProxy final : public TImageWriter {
Shinya Kitaoka 120a6e
  TLevelWriter3gp *m_lw;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  int m_frameIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageWriter3gpProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                       TLevelWriter3gp *lw);
Shinya Kitaoka 120a6e
  ~TImageWriter3gpProxy();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool is64bitOutputSupported() { return false; }
Shinya Kitaoka 120a6e
  void save(const TImageP &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TImageWriter3gpProxy(const TImageWriter3gpProxy &);
Shinya Kitaoka 120a6e
  TImageWriter3gpProxy &operator=(const TImageWriter3gpProxy &src);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageWriter3gpProxy::TImageWriter3gpProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                                           TLevelWriter3gp *lw)
Shinya Kitaoka 120a6e
    : TImageWriter(fp), m_lw(lw), m_frameIndex(frameIndex) {
Shinya Kitaoka 120a6e
  m_lw->addRef();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageWriter3gpProxy::~TImageWriter3gpProxy() { m_lw->release(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TImageWriter3gpProxy::save(const TImageP &img) {
Shinya Kitaoka 120a6e
  m_lw->save(img, m_frameIndex);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    TLevelWriter3gp Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevelWriter3gp::TLevelWriter3gp(const TFilePath &path, TPropertyGroup *winfo)
Shinya Kitaoka 120a6e
    : TLevelWriter(path, winfo) {
Shinya Kitaoka 120a6e
  static TAtomicVar count;
Shinya Kitaoka 120a6e
  unsigned int currCount = ++count;
Shinya Kitaoka 120a6e
  m_id                   = currCount;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString res, propsFp;
Shinya Kitaoka 120a6e
  if (winfo) {
Shinya Kitaoka 120a6e
    // Request a temporary file to store the infos to
Shinya Kitaoka 120a6e
    stream << (msg << QString("$tmpfile_request")
Shinya Kitaoka 120a6e
                   << QString("initLW3") + QString::number(currCount));
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    msg >> propsFp >> tipc::clr;
Shinya Kitaoka 120a6e
    assert(!propsFp.isEmpty());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TFilePath propsTfp(propsFp.toStdWString());
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TOStream os(propsTfp);
Shinya Kitaoka 120a6e
      winfo->saveData(os);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Pass fp to the server
Shinya Kitaoka 120a6e
  stream << (msg << QString("$initLW3gp") << m_id
Shinya Kitaoka 120a6e
                 << QString::fromStdWString(path.getWideString()) << propsFp);
Shinya Kitaoka 120a6e
  if (tipc::readMessage(stream, msg) != "ok") goto err;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (winfo) {
Shinya Kitaoka 120a6e
    stream << (msg << tipc::clr << QString("$tmpfile_release")
Shinya Kitaoka 120a6e
                   << QString("initLW3gp") + QString::number(currCount));
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  throw TException("Unable to write file");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelWriter3gp::~TLevelWriter3gp() {
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Shinya Kitaoka 120a6e
  QString res;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$closeLW3gp") << m_id);
shun-iwasawa 2fb6b9
  if (tipc::readMessage(stream, msg) != "ok")
shun-iwasawa 2fb6b9
    DVGui::warning("Unable to write file");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelWriter3gp::setFrameRate(double fps) {
Shinya Kitaoka 120a6e
  TLevelWriter::setFrameRate(fps);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Shinya Kitaoka 120a6e
  QString res;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$LW3gpSetFrameRate") << m_id << fps);
Shinya Kitaoka 120a6e
  if (tipc::readMessage(stream, msg) != "ok")
Shinya Kitaoka 120a6e
    throw TException("Unexpected error");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageWriterP TLevelWriter3gp::getFrameWriter(TFrameId fid) {
Shinya Kitaoka 120a6e
  if (fid.getLetter() != 0) return TImageWriterP(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int index = fid.getNumber() - 1;
Shinya Kitaoka 120a6e
  return new TImageWriter3gpProxy(m_path, index, this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelWriter3gp::save(const TImageP &img, int frameIndex) {
Shinya Kitaoka 120a6e
  TRasterImageP ri(img);
Shinya Kitaoka 120a6e
  if (!img) throw TImageException(getFilePath(), "Unsupported image type");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterP ras(ri->getRaster());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int lx = ras->getLx(), ly = ras->getLy(), pixSize = ras->getPixelSize();
Shinya Kitaoka 120a6e
  if (pixSize != 4)
Shinya Kitaoka 120a6e
    throw TImageException(getFilePath(), "Unsupported pixel type");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int size = lx * ly * pixSize;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Send messages
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Send the write message.
Shinya Kitaoka 120a6e
  stream << (msg << QString("$LW3gpImageWrite") << m_id << frameIndex << lx
Shinya Kitaoka 120a6e
                 << ly);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Send the data through a shared memory segment
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    t32bitsrv::RasterExchanger<tpixel32> exch(ras);</tpixel32>
Shinya Kitaoka 120a6e
    tipc::writeShMemBuffer(stream, msg << tipc::clr, size, &exch);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (tipc::readMessage(stream, msg) != "ok")
Shinya Kitaoka 120a6e
    throw TImageException(getFilePath(), "Couln't save image");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelWriter3gp::saveSoundTrack(TSoundTrack *st) {
Shinya Kitaoka 120a6e
  if (st == 0) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Prepare connection
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  unsigned int size = st->getSampleSize() * st->getSampleCount();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Send the saveSoundTract command to the server
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$LW3gpSaveSoundTrack") << m_id
Shinya Kitaoka 120a6e
                 << st->getSampleRate() << st->getBitPerSample()
Shinya Kitaoka 120a6e
                 << st->getChannelCount() << st->getSampleCount()
Shinya Kitaoka 120a6e
                 << st->getFormat().m_signedSample);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  t32bitsrv::BufferExchanger exch((UCHAR *)st->getRawData());
Shinya Kitaoka 120a6e
  tipc::writeShMemBuffer(stream, msg << tipc::clr, size, &exch);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QString res(tipc::readMessage(stream, msg));
Shinya Kitaoka 120a6e
  assert(res == "ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    TImageReaderMov Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TImageReader3gpProxy final : public TImageReader {
Shinya Kitaoka 120a6e
  TLevelReader3gp *m_lr;
Shinya Kitaoka 120a6e
  TImageInfo *m_info;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  int m_frameIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TImageReader3gpProxy(const TFilePath &fp, int frameIndex, TLevelReader3gp *lr,
Shinya Kitaoka 120a6e
                       TImageInfo *info);
Shinya Kitaoka 120a6e
  ~TImageReader3gpProxy() { m_lr->release(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TImageP load();
Shinya Kitaoka 120a6e
  void load(const TRasterP &rasP, const TPoint &pos = TPoint(0, 0),
Shinya Kitaoka 120a6e
            int shrinkX = 1, int shrinkY = 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDimension getSize() const { return m_lr->getSize(); }
Shinya Kitaoka 120a6e
  TRect getBBox() const { return m_lr->getBBox(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const TImageInfo *getImageInfo() const { return m_info; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  TImageReader3gpProxy(const TImageReader3gpProxy &);
Shinya Kitaoka 120a6e
  TImageReader3gpProxy &operator=(const TImageReader3gpProxy &src);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TImageReader3gpProxy::TImageReader3gpProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                                           TLevelReader3gp *lr,
Shinya Kitaoka 120a6e
                                           TImageInfo *info)
Shinya Kitaoka 120a6e
    : TImageReader(fp), m_lr(lr), m_frameIndex(frameIndex), m_info(info) {
Shinya Kitaoka 120a6e
  m_lr->addRef();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageP TImageReader3gpProxy::load() {
Shinya Kitaoka 120a6e
  TRaster32P ras(m_lr->getSize());
Shinya Kitaoka 120a6e
  m_lr->load(ras, m_frameIndex, TPointI(), 1, 1);
Shinya Kitaoka 120a6e
  return TRasterImageP(ras);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TImageReader3gpProxy::load(const TRasterP &rasP, const TPoint &pos,
Shinya Kitaoka 120a6e
                                int shrinkX, int shrinkY) {
Shinya Kitaoka 120a6e
  // NOTE: The original implementation is different. But is also does not make
Shinya Kitaoka 120a6e
  // sense...
Shinya Kitaoka 120a6e
  // I've substituted it with the lrm plain call.
Shinya Kitaoka 120a6e
  m_lr->load(rasP, m_frameIndex, pos, shrinkX, shrinkY);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    TLevelReader3gp Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelReader3gp::TLevelReader3gp(const TFilePath &path) : TLevelReader(path) {
Shinya Kitaoka 120a6e
  static TAtomicVar count;
Shinya Kitaoka 120a6e
  unsigned int currCount = ++count;
Shinya Kitaoka 120a6e
  m_id                   = currCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$initLR3gp") << m_id
Shinya Kitaoka 120a6e
                 << QString::fromStdWString(path.getWideString()));
Shinya Kitaoka 120a6e
  if (tipc::readMessage(stream, msg) != "ok")
Shinya Kitaoka 120a6e
    throw TImageException(path, "Couldn't open file");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  double frameRate;
Shinya Kitaoka 120a6e
  msg >> m_lx >> m_ly >> frameRate >> tipc::clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_info              = new TImageInfo;
Shinya Kitaoka 120a6e
  m_info->m_lx        = m_lx;
Shinya Kitaoka 120a6e
  m_info->m_ly        = m_ly;
Shinya Kitaoka 120a6e
  m_info->m_frameRate = frameRate;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelReader3gp::~TLevelReader3gp() {
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$closeLR3gp") << m_id);
Shinya Kitaoka 120a6e
  QString res(tipc::readMessage(stream, msg));
Shinya Kitaoka 120a6e
  assert(res == "ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageReaderP TLevelReader3gp::getFrameReader(TFrameId fid) {
Shinya Kitaoka 120a6e
  if (fid.getLetter() != 0) return TImageReaderP(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int index = fid.getNumber() - 1;
Shinya Kitaoka 120a6e
  return new TImageReader3gpProxy(m_path, index, this, m_info);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelP TLevelReader3gp::loadInfo() {
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TLevelP level;
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    QString shMemId(tipc::uniqueId());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Send the appropriate command
Shinya Kitaoka 120a6e
    stream << (msg << QString("$LR3gpLoadInfo") << m_id << shMemId);
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    int frameCount;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    msg >> frameCount >> tipc::clr;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Read the data in the shared memory segment
Shinya Kitaoka 120a6e
    QSharedMemory shmem(shMemId);
Shinya Kitaoka 120a6e
    shmem.attach();
Shinya Kitaoka 120a6e
    shmem.lock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    int *f, *fBegin = (int *)shmem.data(), *fEnd = fBegin + frameCount;
Shinya Kitaoka 120a6e
    assert(fBegin);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (f = fBegin; f < fEnd; ++f) level->setFrame(*f, TImageP());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    shmem.unlock();
Shinya Kitaoka 120a6e
    shmem.detach();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Release the shared memory segment
Shinya Kitaoka 120a6e
    stream << (msg << QString("$shmem_release") << shMemId);
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return level;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
err:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  throw TException("Couldn't read movie data");
Shinya Kitaoka 120a6e
  return TLevelP();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelReader3gp::enableRandomAccessRead(bool enable) {
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  stream << (msg << QString("$LR3gpEnableRandomAccessRead") << m_id
Shinya Kitaoka 120a6e
                 << QString(enable ? "true" : "false"));
Shinya Kitaoka 120a6e
  QString res(tipc::readMessage(stream, msg));
Shinya Kitaoka 120a6e
  assert(res == "ok");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelReader3gp::load(const TRasterP &ras, int frameIndex,
Shinya Kitaoka 120a6e
                           const TPoint &pos, int shrinkX, int shrinkY) {
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), -1,
Shinya Kitaoka 120a6e
                             t32bitsrv::srvCmdline());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  unsigned int size = ras->getLx() * ras->getLy() * ras->getPixelSize();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Send the appropriate command to the 32-bit server
Shinya Kitaoka 120a6e
  stream << (msg << QString("$LR3gpImageRead") << m_id << ras->getLx()
Shinya Kitaoka 120a6e
                 << ras->getLy() << ras->getPixelSize() << frameIndex << pos.x
Shinya Kitaoka 120a6e
                 << pos.y << shrinkX << shrinkY);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  t32bitsrv::RasterExchanger<tpixel32> exch(ras);</tpixel32>
Shinya Kitaoka 120a6e
  if (!tipc::readShMemBuffer(stream, msg << tipc::clr, &exch))
Shinya Kitaoka 120a6e
    throw TException("Couldn't load image");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // x64