Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
shun-iwasawa ef0f8b
#if defined(x64) || defined(__LP64__) || defined(LINUX) || defined(FREEBSD) || \
shun-iwasawa ef0f8b
    (defined(_WIN32) && defined(__GNUC__))
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_mov_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
Shinya Kitaoka 120a6e
bool IsQuickTimeInstalled() {
Toshihiro Shimizu 890ddd
#if !defined(__OSX__)
Shinya Kitaoka 120a6e
  // NOTE: This is *NOT* the same function as Tiio::isQuickTimeInstalled !!
Shinya Kitaoka 120a6e
  // There actually are 2 distinct functions with essentially the same name, one
Shinya Kitaoka 120a6e
  // in tnzcore lib, the other in image. The core version is currently NEVER
Shinya Kitaoka 120a6e
  // USED
Shinya Kitaoka 120a6e
  // throughout Toonz, even if it's EXPORT-defined.
Shinya Kitaoka 120a6e
  QLocalSocket socket;
Shinya Kitaoka 120a6e
  if (!tipc::startSlaveConnection(&socket, t32bitsrv::srvName(), 3000,
Shinya Kitaoka 120a6e
                                  t32bitsrv::srvCmdline()))
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tipc::Stream stream(&socket);
Shinya Kitaoka 120a6e
  tipc::Message msg;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  stream << (msg << QString("$isQTInstalled"));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (tipc::readMessage(stream, msg) != "yes") return false;
Shinya Kitaoka 120a6e
  return true;
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Tiio::MovWriterProperties::MovWriterProperties() {
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
  // Retrieve a temporary file to pass the data
Shinya Kitaoka 120a6e
  QString fp;
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    stream << (msg << QString("$tmpfile_request") << QString("MovWriterProps"));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    msg >> fp;
Shinya Kitaoka 120a6e
    assert(!fp.isEmpty());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Make the server write the data to the file
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    stream << (msg << tipc::clr << QString("$defaultMovProps") << fp);
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") goto err;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // Load the data
Shinya Kitaoka 120a6e
    TFilePath tfp(fp.toStdWString());
Shinya Kitaoka 120a6e
    TIStream is(tfp);
Shinya Kitaoka 120a6e
    loadData(is);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Release the temporary file
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    stream << (msg << tipc::clr << QString("$tmpfile_release")
Shinya Kitaoka 120a6e
                   << QString("MovWriterProps"));
Shinya Kitaoka 120a6e
    if (tipc::readMessage(stream, msg) != "ok") 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
  throw TException("Server error");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
//    TImageWriterMov Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TImageWriterMovProxy final : public TImageWriter {
Shinya Kitaoka 120a6e
  TLevelWriterMov *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
  TImageWriterMovProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                       TLevelWriterMov *lw);
Shinya Kitaoka 120a6e
  ~TImageWriterMovProxy();
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
  TImageWriterMovProxy(const TImageWriterMovProxy &);
Shinya Kitaoka 120a6e
  TImageWriterMovProxy &operator=(const TImageWriterMovProxy &src);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TImageWriterMovProxy::TImageWriterMovProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                                           TLevelWriterMov *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
TImageWriterMovProxy::~TImageWriterMovProxy() { m_lw->release(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TImageWriterMovProxy::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
//    TLevelWriterMov Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevelWriterMov::TLevelWriterMov(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("initLWMov") + 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("$initLWMov") << 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("initLWMov") + 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
TLevelWriterMov::~TLevelWriterMov() {
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("$closeLWMov") << 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 TLevelWriterMov::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("$LWMovSetFrameRate") << 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 TLevelWriterMov::getFrameWriter(TFrameId fid) {
shun-iwasawa ef0f8b
  if (!fid.getLetter().isEmpty()) return TImageWriterP(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int index = fid.getNumber() - 1;
Shinya Kitaoka 120a6e
  return new TImageWriterMovProxy(m_path, index, this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelWriterMov::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("$LWMovImageWrite") << 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")
luz paz 67b4e9
    throw TImageException(getFilePath(), "Couldn't save image");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TLevelWriterMov::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("$LWMovSaveSoundTrack") << m_id
Shinya Kitaoka 120a6e
                 << st->getSampleRate() << st->getBitPerSample()
Shinya Kitaoka 120a6e
                 << st->getChannelCount() << st->getSampleCount()
justburner 9369f1
                 << (st->getFormat().m_sampleType != TSound::UINT));
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 TImageReaderMovProxy final : public TImageReader {
Shinya Kitaoka 120a6e
  TLevelReaderMov *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
  TImageReaderMovProxy(const TFilePath &fp, int frameIndex, TLevelReaderMov *lr,
Shinya Kitaoka 120a6e
                       TImageInfo *info);
Shinya Kitaoka 120a6e
  ~TImageReaderMovProxy() { 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
  TImageReaderMovProxy(const TImageReaderMovProxy &);
Shinya Kitaoka 120a6e
  TImageReaderMovProxy &operator=(const TImageReaderMovProxy &src);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TImageReaderMovProxy::TImageReaderMovProxy(const TFilePath &fp, int frameIndex,
Shinya Kitaoka 120a6e
                                           TLevelReaderMov *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 TImageReaderMovProxy::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 TImageReaderMovProxy::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
//    TLevelReaderMov Proxy implementation
Toshihiro Shimizu 890ddd
//******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelReaderMov::TLevelReaderMov(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("$initLRMov") << 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
TLevelReaderMov::~TLevelReaderMov() {
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("$closeLRMov") << 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 TLevelReaderMov::getFrameReader(TFrameId fid) {
shun-iwasawa ef0f8b
  if (!fid.getLetter().isEmpty()) return TImageReaderP(0);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int index = fid.getNumber() - 1;
Shinya Kitaoka 120a6e
  return new TImageReaderMovProxy(m_path, index, this, m_info);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelP TLevelReaderMov::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("$LRMovLoadInfo") << 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 TLevelReaderMov::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("$LRMovEnableRandomAccessRead") << 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 TLevelReaderMov::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("$LRMovImageRead") << 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