示例#1
0
// NOTE: Precalculate the header, coord, and box offsets.
// NOTE: There are currently NO checks for null for X, box, and T!
int Traj_AmberCoord::readFrame(int set, double *X, double *V, double *box, double *T) {
#ifdef TRAJDEBUG
  mprinterr("Reading frame %10i from %s\n",set,Filename().base());
#endif
  // If trajectory is not broken, seek to given frame.
  if (IsSeekable())
    file_.SeekToFrame( set ); 

  // Read frame into the char buffer
  if (file_.ReadFrame() == -1) return 1;

  // Get REMD Temperature if present
  if (hasREMD_ != 0) 
    file_.GetDoubleAtPosition(*T, 33, 41); 
  // Get Coordinates; offset is hasREMD (size in bytes of REMD header)
  file_.BufferBeginAt(hasREMD_);
  file_.BufferToDouble(X, natom3_);
  if (numBoxCoords_ != 0) { 
    file_.BufferToDouble(box, numBoxCoords_);
    // Set box angles to parmtop default if not read in
    if (numBoxCoords_==3) {
      box[3] = boxAngle_[0];
      box[4] = boxAngle_[1];
      box[5] = boxAngle_[2];
    }
  }
  return 0;
}
示例#2
0
	virtual	ssize_t				ReadAt(off_t position, void* buffer,
									size_t size)
	{
		CALLED();

		if (IsSeekable())
			return fPosition->ReadAt(position, buffer, size);

		off_t bufSize = 0;
		ssize_t ret = B_NOT_SUPPORTED;
		fFallbackBuffer->GetSize(&bufSize);

		if (fFallbackBuffer->Position() == position
				&& position+size > (size_t)bufSize) {
			// TODO: Possibly part of the data we have
			// to supply is cached.
			ret = fData->Read(buffer, size);
			if (ret > 0)
				fFallbackBuffer->Write(buffer, ret);

			return ret;
		}

		if (position+size <= (size_t)bufSize)
			return fFallbackBuffer->ReadAt(position, buffer, size);

		return ret;
	}
示例#3
0
wxFileOffset wxWrapperInputStream::OnSysSeek(wxFileOffset pos, wxSeekMode mode)
{
    wxCHECK_MSG(IsSeekable(), false, "Stream not seekable");

    wxON_BLOCK_EXIT_THIS0(wxWrapperInputStream::SynchronizeLastError);
    return m_parent_i_stream->SeekI (pos, mode);
}
示例#4
0
	void SourceObject::Pause ()
	{
		if (!IsSeekable ())
			Stop ();
		else
			gst_element_set_state (Path_->GetPipeline (), GST_STATE_PAUSED);
	}
示例#5
0
int Traj_AmberCoord::readVelocity(int set, double* V) {
  if (IsSeekable()) file_.SeekToFrame( set );
  // Read frame into the char buffer
  if (file_.ReadFrame() == -1) return 1;
  file_.BufferBeginAt(hasREMD_);
  file_.BufferToDouble(V, natom3_);
  return 0;
}
示例#6
0
	virtual off_t				Position() const
	{
		CALLED();

		if (IsSeekable())
			return fPosition->Position();

		return fFallbackBuffer->Position();
	}
示例#7
0
	virtual	bool				IsEndless() const
	{
		if (IsMedia())
			return fMedia->IsEndless();

		if (IsSeekable())
			return false;

		return true;
	}
示例#8
0
	virtual	off_t				Seek(off_t position, uint32 seekMode)
	{
		CALLED();

		if (IsSeekable())
			return fPosition->Seek(position, seekMode);

		off_t bufSize = 0;
		fFallbackBuffer->GetSize(&bufSize);
		if (position <= bufSize)
			return fFallbackBuffer->Seek(position, seekMode);

		return B_NOT_SUPPORTED;
	}
示例#9
0
	void SourceObject::Seek (qint64 pos)
	{
		if (!IsSeekable ())
			return;

		if (OldState_ == SourceState::Playing)
			IsSeeking_ = true;

		gst_element_seek (GST_ELEMENT (Dec_), 1.0, GST_FORMAT_TIME,
				GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, pos * GST_MSECOND,
				GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);

		LastCurrentTime_ = pos * GST_MSECOND;
	}
示例#10
0
	virtual	ssize_t				WriteAt(off_t position, const void* buffer,
									size_t size)
	{
		CALLED();

		if (IsSeekable())
			return fPosition->WriteAt(position, buffer, size);

		off_t bufSize = 0;
		fFallbackBuffer->GetSize(&bufSize);
		if (position == bufSize) {
			ssize_t ret = fData->Write(buffer, size);
			fFallbackBuffer->WriteAt(bufSize, buffer, size);
			return ret;
		}

		return B_NOT_SUPPORTED;
	}
示例#11
0
	BMediaIOWrapper(BDataIO* source)
		:
		fData(NULL),
		fPosition(NULL),
		fMedia(NULL),
		fFile(NULL),
		fFallbackBuffer(NULL),
		fErr(B_NO_ERROR)
	{
		CALLED();

		fPosition = dynamic_cast<BPositionIO*>(source);
		fMedia = dynamic_cast<BMediaIO*>(source);
		fFile = dynamic_cast<BFile*>(source);
		fData = source;

		// No need to do additional buffering if we have
		// a BBufferIO or a BMediaIO.
		if (dynamic_cast<BBufferIO *>(source) == NULL) {
			// Source needs to be at least a BPositionIO to wrap with a BBufferIO
			if (IsSeekable()) {
				fPosition = new(std::nothrow) BBufferIO(fPosition, 65536, true);
				if (fPosition == NULL) {
					fErr = B_NO_MEMORY;
					return;
				}
				// We have to reset our BDataIO reference too
				fData = dynamic_cast<BDataIO*>(fPosition);
			} else {
				// In this case we have to supply our own form
				// of pseudo-seekable object from a non-seekable
				// BDataIO.
				fFallbackBuffer = new BMallocIO();
				fFallbackBuffer->SetBlockSize(BLOCK_SIZE);
				TRACE("Unable to improve performance with a BufferIO\n");
			}
		}
	}
示例#12
0
wxFileOffset wxInputStream::SeekI(wxFileOffset pos, wxSeekMode mode)
{
    // RR: This code is duplicated in wxBufferedInputStream. This is
    // not really a good design, but buffered stream are different
    // from all others in that they handle two stream-related objects:
    // the stream buffer and parent stream.

    // I don't know whether it should be put as well in wxFileInputStream::OnSysSeek
    if (m_lasterror==wxSTREAM_EOF)
        m_lasterror=wxSTREAM_NO_ERROR;

    // avoid unnecessary seek operations (optimization)
    wxFileOffset currentPos = TellI(), size = GetLength();
    if ((mode == wxFromStart && currentPos == pos) ||
        (mode == wxFromCurrent && pos == 0) ||
        (mode == wxFromEnd && size != wxInvalidOffset && currentPos == size-pos))
        return currentPos;

    if (!IsSeekable() && mode == wxFromCurrent && pos > 0)
    {
        // rather than seeking, we can just read data and discard it;
        // this allows to forward-seek also non-seekable streams!
        char buf[BUF_TEMP_SIZE];
        size_t bytes_read;

        // read chunks of BUF_TEMP_SIZE bytes until we reach the new position
        for ( ; pos >= BUF_TEMP_SIZE; pos -= bytes_read)
        {
            bytes_read = Read(buf, WXSIZEOF(buf)).LastRead();
            if ( m_lasterror != wxSTREAM_NO_ERROR )
                return wxInvalidOffset;

            wxASSERT(bytes_read == WXSIZEOF(buf));
        }

        // read the last 'pos' bytes
        bytes_read = Read(buf, (size_t)pos).LastRead();
        if ( m_lasterror != wxSTREAM_NO_ERROR )
            return wxInvalidOffset;

        wxASSERT(bytes_read == (size_t)pos);

        // we should now have sought to the right position...
        return TellI();
    }

    /* RR: A call to SeekI() will automatically invalidate any previous
       call to Ungetch(), otherwise it would be possible to SeekI() to
       one position, unread some bytes there, SeekI() to another position
       and the data would be corrupted.

       GRG: Could add code here to try to navigate within the wback
       buffer if possible, but is it really needed? It would only work
       when seeking in wxFromCurrent mode, else it would invalidate
       anyway... */

    if (m_wback)
    {
        wxLogDebug( wxT("Seeking in stream which has data written back to it.") );

        free(m_wback);
        m_wback = NULL;
        m_wbacksize = 0;
        m_wbackcur = 0;
    }

    return OnSysSeek(pos, mode);
}