Пример #1
0
bool CEncoderVorbis::Close()
{
  int eos = 0;
  // tell vorbis we are encoding the end of the stream
  m_VorbisDll.vorbis_analysis_wrote(&m_sVorbisDspState, 0);
  while (m_VorbisDll.vorbis_analysis_blockout(&m_sVorbisDspState, &m_sVorbisBlock) == 1)
  {
    /* analysis, assume we want to use bitrate management */
    m_VorbisDll.vorbis_analysis(&m_sVorbisBlock, NULL);
    m_VorbisDll.vorbis_bitrate_addblock(&m_sVorbisBlock);

    while (m_VorbisDll.vorbis_bitrate_flushpacket(&m_sVorbisDspState, &m_sOggPacket))
    {
      /* weld the packet into the bitstream */
      m_OggDll.ogg_stream_packetin(&m_sOggStreamState, &m_sOggPacket);

      /* write out pages (if any) */
      while (!eos)
      {
        int result = m_OggDll.ogg_stream_pageout(&m_sOggStreamState, &m_sOggPage);
        if (result == 0)break;
        WriteStream(m_sOggPage.header, m_sOggPage.header_len);
        WriteStream(m_sOggPage.body, m_sOggPage.body_len);

        /* this could be set above, but for illustrative purposes, I do
        it here (to show that vorbis does know where the stream ends) */
        if (m_OggDll.ogg_page_eos(&m_sOggPage)) eos = 1;
      }
    }
  }

  /* clean up and exit.  vorbis_info_clear() must be called last */
  m_OggDll.ogg_stream_clear(&m_sOggStreamState);
  m_VorbisDll.vorbis_block_clear(&m_sVorbisBlock);
  m_VorbisDll.vorbis_dsp_clear(&m_sVorbisDspState);
  m_VorbisDll.vorbis_comment_clear(&m_sVorbisComment);
  m_VorbisDll.vorbis_info_clear(&m_sVorbisInfo);

  /* ogg_page and ogg_packet structs always point to storage in
     libvorbis.  They're never freed or manipulated directly */
  FlushStream();
  FileClose();

  delete []m_pBuffer;
  m_pBuffer = NULL;

  m_VorbisEncDll.Unload();

  m_OggDll.Unload();

  m_VorbisDll.Unload();

  return true;
}
Пример #2
0
LONG WriteStreamLong (struct IFFHandle *iff,
    APTR valptr,
    struct IFFParseBase_intern *IFFParseBase)
{
    LONG val;
#if AROS_BIG_ENDIAN
#   define bytes valptr
#else
    UBYTE bytes[4];
    val = *(LONG *)valptr;

    bytes[0] = val >> 24;
    bytes[1] = val >> 16;
    bytes[2] = val >> 8;
    bytes[3] = val;
#endif

    D(bug("WriteStreamLong(iff=%p valptr=%p)\n", iff, valptr));

    val = WriteStream (iff, bytes, sizeof(LONG), IFFParseBase);

    D(bug("WriteStreamLong: val %ld\n", val));

    if (val < 0)
	return val;
    else if (val != sizeof(LONG))
	return IFFERR_EOF;

    return sizeof(LONG);
} /* WriteStreamLong */
Пример #3
0
BOOL CCLITerminal::RemoteDoOption(CLISESSION *pSession, int nOption, BOOL bEnable, BOOL bRemote)
{
	BOOL	doFlag = bEnable;

	if (pSession->nRemoteOptions[nOption] == bEnable)
		return TRUE;

	switch(nOption) {
	  case TELOPT_BINARY :
	  case TELOPT_ECHO :
		   SetOption(pSession, nOption, bEnable);
		   break;
	  case TELOPT_SGA :
		   break;
	  default :
		   doFlag = FALSE;
		   break;
	}

	if ((pSession->nRemoteOptions[nOption] != doFlag) || bRemote)
	{
		unsigned char	msg[3];

		msg[0]	= IAC;
		msg[1]	= doFlag ? DO : DONT;
		msg[2]	= nOption;

		WriteStream(pSession, (char *)msg, 3);
		pSession->nRemoteOptions[nOption] = doFlag;
	}

	return (doFlag == bEnable) ? TRUE : FALSE;
}
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
    const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
{
  if (!_outBuf)
  {
    _outBuf = (Byte *)::MidAlloc(kBufSize);
    if (!_outBuf)
      return E_OUTOFMEMORY;
  }
  
  _inStream.Stream = inStream;
  SetOutStreamSize(outSize);

  do
  {
    const UInt64 startPos = _processedSize;
    HRESULT res = CodeSpec(_outBuf, kBufSize);
    size_t processed = (size_t)(_processedSize - startPos);
    RINOK(WriteStream(outStream, _outBuf, processed));
    RINOK(res);
    if (_status == kStatus_Finished)
      break;
    if (progress)
    {
      UInt64 inSize = _inStream.GetProcessed();
      RINOK(progress->SetRatioInfo(&inSize, &_processedSize));
    }
  }
  while (!_outSizeDefined || _processedSize < _outSize);
  return S_OK;
}
Пример #5
0
bool RealSoundOgg::ServiceBuffer()
{
	if( m_bMute ) return true;
	if (m_pDSB == NULL) return false;

	DWORD pos = 0;
	m_pDSB->GetCurrentPosition(&pos, NULL);
	m_nCurSection = ((int)pos < m_nBufSize) ? 0:1;

	if (m_nCurSection != m_nLastSection)
	{
		if (m_bDone && !m_bLoop) 
		{
			if (m_bOpened)
			{
				if (m_bPlaying)
				{
					ov_pcm_seek(&m_vf, 0);
					m_pDSB->Stop();
					m_bPlaying = false;
				}
			}

			return false;
		}
		if (m_bAlmostDone && !m_bLoop) m_bDone = true;

		WriteStream(m_nBufSize);
	}

	return true;
}
Пример #6
0
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
  Byte props[LZMA_PROPS_SIZE];
  size_t size = LZMA_PROPS_SIZE;
  RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));
  return WriteStream(outStream, props, size);
}
Пример #7
0
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
    ISequentialOutStream *outStream,
    const UInt64 * /* inSize */, const UInt64 *outSize,
    ICompressProgressInfo *progress)
{
  if (_buffer == 0)
  {
    _buffer = (Byte *)::MidAlloc(kBufferSize);
    if (_buffer == 0)
      return E_OUTOFMEMORY;
  }

  TotalSize = 0;
  for (;;)
  {
    UInt32 size = kBufferSize;
    if (outSize != 0)
      if (size > *outSize - TotalSize)
        size = (UInt32)(*outSize - TotalSize);
    RINOK(inStream->Read(_buffer, size, &size));
    if (size == 0)
      break;
    if (outStream)
    {
      RINOK(WriteStream(outStream, _buffer, size));
    }
    TotalSize += size;
    if (progress != NULL)
    {
      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
    }
  }
  return S_OK;
}
Пример #8
0
BOOL CCLITerminal::LocalDoOption(CLISESSION *pSession, int nOption, BOOL bEnable, BOOL bRemote)
{
	BOOL	bWill = bEnable;
	
	if (pSession->nLocalOptions[nOption] == bEnable)
		return TRUE;

	switch(nOption) {
	  case TELOPT_BINARY :
	  case TELOPT_ECHO :
		   SetOption(pSession, nOption, bEnable);
		   break;
	  case TELOPT_SGA :
		   break;
	  default :
		   bWill = FALSE;
		   break;
	}

	if ((pSession->nLocalOptions[nOption] != bWill) || bRemote)
	{
		unsigned char	msg[3];

		msg[0]	= IAC;
		msg[1]	= bWill ? WILL : WONT;
		msg[2]	= nOption;

		WriteStream(pSession, (char *)msg, 3);
		pSession->nLocalOptions[nOption] = bWill;
	}

	return (bWill == bEnable) ? TRUE : FALSE;
}
Пример #9
0
static size_t MyWrite(void *object, const void *data, size_t size)
{
  CSeqOutStream *p = (CSeqOutStream *)object;
  p->Res = WriteStream(p->RealStream, data, size);
  if (p->Res != 0)
    return 0;
  return size;
}
Пример #10
0
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
{
  const UInt32 kPropSize = 5;
  Byte props[kPropSize];
  props[0] = (Byte)_props.Order;
  SetUi32(props + 1, _props.MemSize);
  return WriteStream(outStream, props, kPropSize);
}
Пример #11
0
void CCLITerminal::DisplaySplash(CLISESSION *pSession)
{
	char	szVersion[128];

	if (pSession->nMode == CLIMODE_USER)
	{
	  	DisplayUserMenu(pSession);
		return;
	}

    WriteStream(pSession, "\033[H\033[J");
    sprintf(szVersion, "AIMIR Management Console (%s)\xd\xa", m_pMcuVersionString);
    WriteStream(pSession, szVersion);
    WriteStream(pSession, COPYRIGHT "\xd\xa");
    WriteStream(pSession, "\xd\xa");

	DisplayPrompt(pSession);
}
Пример #12
0
BOOL CCLITerminal::ExecuteBackspace(CLISESSION *pSession)
{
	if (pSession->nCmdLength == 0)
		return FALSE;

	pSession->nCmdLength--;
	WriteStream(pSession, "\x8 \x8");
	return TRUE;
}
Пример #13
0
HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream, UInt32 crc)
{
  Byte h[kHeaderSize];
  g_RandomGenerator.Generate(h, kHeaderSize - 2);
  h[kHeaderSize - 1] = (Byte)(crc >> 24);
  h[kHeaderSize - 2] = (Byte)(crc >> 16);
  RestoreKeys();
  Filter(h, kHeaderSize);
  return WriteStream(outStream, h, kHeaderSize);
}
Пример #14
0
int CCLITerminal::DisplayAllParameter(CLISESSION *pSession, CLIHANDLER *pHandler, int nIndex)
{
	CLIPARAMCHECKER	*pChecker;
	int		i, n, nCount = 0;
	char	szTag[32];
	char	szName[64];
	char	szBuffer[1024];

	if (!pHandler)
		return -1;

	WriteStream(pSession, "\xd\xa");
	if (!pHandler->pszParam)
		return 0;

	for(i=0; pHandler->pszParam[i]; i++)
	{
		if (pHandler->pszParam[i] == '*')
		{
			WriteStream(pSession, "    <enter>\xd\xa");
		}
		else if (pHandler->pszParam[i] == '%')
		{
			n = UntilCopy(szTag, const_cast<char *>(&pHandler->pszParam[i+1]), 32);
			pChecker = FindParamHandler(szTag);
			if (pChecker != NULL)
			{
				sprintf(szName, "<%s>", pChecker->pszLabel);
				sprintf(szBuffer, "    %-20s %s\xd\xa", szName, pChecker->pszDescr);
				WriteStream(pSession, szBuffer);  			
			}
			else
			{
				sprintf(szBuffer, "  '%s'\xd\xa", szTag);
				WriteStream(pSession, szBuffer);
			}
			i += n;
			nCount++;
		}
	}	
	return nCount;	
}
Пример #15
0
void LogPut( const char *str )
{
    int   len;

    if( LogHndl == NIL_HANDLE )
        return;
    len = strlen( str );
    if( WriteStream( LogHndl, str, len ) != len ) {
        LogFini();
    }
}
Пример #16
0
HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
{
  Byte header[kHeaderSize];
  g_RandomGenerator.Generate(header, kHeaderSize - 2);

  header[kHeaderSize - 1] = Byte(_crc >> 24);
  header[kHeaderSize - 2] = Byte(_crc >> 16);

  _cipher.EncryptHeader(header);
  return WriteStream(outStream, header, kHeaderSize);
}
Пример #17
0
HRESULT CByteOutBufWrap::Flush()
{
  if (Res == S_OK)
  {
    size_t size = (Cur - Buf);
    Res = WriteStream(Stream, Buf, size);
    if (Res == S_OK)
      Processed += size;
    Cur = Buf;
  }
  return Res;
}
Пример #18
0
HRESULT CFilterCoder::WriteWithLimit(ISequentialOutStream *outStream, UInt32 size)
{
  if (_outSizeIsDefined)
  {
    UInt64 remSize = _outSize - _nowPos64;
    if (size > remSize)
      size = (UInt32)remSize;
  }
  RINOK(WriteStream(outStream, _buffer, size));
  _nowPos64 += size;
  return S_OK;
}
Пример #19
0
void CCLITerminal::ReplaceCommand(CLISESSION *pSession, const char *pszCommand)
{
	char	szWhite[256];
    char * pszCmd = NULL;

	if (pszCommand == NULL)
		pszCmd = const_cast<char*>("");
    else 
        pszCmd = const_cast<char*>(pszCommand);

	strcpy(pSession->szCommand, pszCmd);
	pSession->nCmdLength = strlen(pszCmd);

	WriteStream(pSession, "\xd");
	memset(szWhite, ' ', 79);
	szWhite[79] = 0;
	WriteStream(pSession, szWhite);
	WriteStream(pSession, "\xd");
	DisplayPrompt(pSession);
	WriteStream(pSession, pSession->szCommand);
}
Пример #20
0
void CCLITerminal::DisplayUserMenu(CLISESSION *pSession)
{
	WriteStream(pSession, "\xd\xa");
	WriteStream(pSession, "FIRMWARE DOWNLOAD MENU\xd\xa");
	WriteStream(pSession, "\xd\xa");
	WriteStream(pSession, "1. Download\xd\xa");
	WriteStream(pSession, "2. Run\xd\xa");
	WriteStream(pSession, "\xd\xa");
	WriteStream(pSession, "SELECT> ");
}
Пример #21
0
inline HRESULT write_int(ISequentialOutStream *outStream, long long data_size, UInt64 *outSizeProcessed)
{
  do {
    unsigned char b = data_size & 0x7F;
    data_size >>= 7;
    if (data_size > 0)
      b |= 0x80;
    RINOK(WriteStream(outStream, &b, 1));
    *outSizeProcessed += 1;
  } while (data_size != 0);
  return S_OK;
}
Пример #22
0
int CCLITerminal::DisplayWideParameter(CLISESSION *pSession, CLIHANDLER *pHandler)
{
	CLIPARAMCHECKER	*pChecker;
	int		i, n, nCount = 0;
	char	szTag[32];
	char	szBuffer[64];

	if (!pHandler)
		return -1;

	if (!pHandler->pszParam)
		return 0;

	for(i=0; pHandler->pszParam[i]; i++)
	{
		if (pHandler->pszParam[i] == '*')
			continue;
		
		if (pHandler->pszParam[i] == '%')
		{
			n = UntilCopy(szTag, const_cast<char *>(&pHandler->pszParam[i+1]), 32);
			pChecker = FindParamHandler(szTag);
			if (pChecker != NULL)
			{
				sprintf(szBuffer, "<%s> ", pChecker->pszLabel);
				WriteStream(pSession, szBuffer);  			
			}
			else
			{
				sprintf(szBuffer, "'%s' ", szTag);
				WriteStream(pSession, szBuffer);
			}
			i += n;
			nCount++;
		}
	}	
	return nCount;	
}
Пример #23
0
static size_t MyWrite(void *object, const void *data, size_t size)
{
  CSeqOutStreamWrap *p = (CSeqOutStreamWrap *)object;
  if (p->Stream)
  {
    p->Res = WriteStream(p->Stream, data, size);
    if (p->Res != 0)
      return 0;
  }
  else
    p->Res = S_OK;
  p->Processed += size;
  return size;
}
Пример #24
0
HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
{
  Byte header[kHeaderSize];
  g_RandomGenerator.Generate(header, kHeaderSize - 2);

  header[kHeaderSize - 1] = Byte(_crc >> 24);
  header[kHeaderSize - 2] = Byte(_crc >> 16);

  UInt32 processedSize;
  _cipher.EncryptHeader(header);
  RINOK(WriteStream(outStream, header, kHeaderSize, &processedSize));
  if (processedSize != kHeaderSize)
    return E_FAIL;
  return S_OK;
}
Пример #25
0
bool CEncoder::CloseEncode()
{
  int iBytes = m_impl->Flush(m_buffer);
  if (iBytes < 0)
  {
    CLog::Log(LOGERROR, "Internal encoder error: %i", iBytes);
    return false;
  }

  WriteStream(m_buffer, iBytes);
  FlushStream();
  FileClose();

  return m_impl->Close();
}
Пример #26
0
bool WriteStream( const std::string &strdata, const std::string &strpath )
{
std::ofstream stream;

stream.open( strpath.data() );

if ( stream.is_open() )
        {
        WriteStream( stream, strdata );

        stream.close();

        return true;
        }

return false;
}
Пример #27
0
  void BaseConnection::EventWrite() {
    if (state_ != STATE_CONNECTED) {
      return;
    }

    if (outgoing_.empty()) {
      handler_->GetPoll()->RemoveWrite(this);
      return;
    }

    std::list<OutgoingMessage::sptr> outgoing;
    outgoing.swap(outgoing_);

    for (std::list<OutgoingMessage::sptr>::const_iterator i = outgoing.begin(); i != outgoing.end(); ++i) {
      if (state_ != STATE_CONNECTED) {
        return;
      }

      const OutgoingMessage::sptr& message = *i;
      const char* response = message->GetSerializedMessage();

      try {
        while (WriteStream(response, message->GetLength()) == 0) {
          threads::Yield();
        }
      }
      catch (const sockets::SocketException& e) {
        GetLogger_().warnStream() << "WriteStream failed with error: " << e.why();
        Close();
        break;
      }
      catch (const std::exception& e) {
        GetLogger_().warnStream() << "WriteStream failed with error: " << e.what();
        Close();
        break;
      }

      AfterEventWrite_(message);

      if (!message->IsPersistent()) {
        Close();
        break;
      }
    }
  }
Пример #28
0
int CEncoder::Encode(int nNumBytesRead, uint8_t* pbtStream)
{
  int iBytes = m_impl->Encode(nNumBytesRead, pbtStream, m_buffer);

  if (iBytes < 0)
  {
    CLog::Log(LOGERROR, "Internal encoder error: %i", iBytes);
    return 0;
  }

  if (WriteStream(m_buffer, iBytes) != iBytes)
  {
    CLog::Log(LOGERROR, "Error writing buffer to file");
    return 0;
  }

  return 1;
}
Пример #29
0
BOOL CCLITerminal::SetupTerminal(CLISESSION *pSession)
{
/*
    struct termios new_settings;
    struct termios stored_settings;

    // Change Local Echo Option
    tcgetattr(pSession->sSocket, &stored_settings);
    new_settings = stored_settings;
    new_settings.c_lflag &= (~ECHO);
    new_settings.c_lflag &= (~ICANON);
    tcsetattr(pSession->sSocket,TCSANOW, &new_settings);
*/
	if (pSession->nType != CLITYPE_SERIAL)
    	WriteStream(pSession, (char *)kludge_telopt, 31);
//  LocalDoOption(pTerminal, TELOPT_ECHO, FALSE, FALSE);

	return TRUE;
}
Пример #30
0
    DynamicArray<uint8>  MeshDatabase::BuildNativeVertexBuffer(const NativeVBLayout& outputLayout) const
    {
            //
            //      Write the data into the vertex buffer
            //
        auto size = outputLayout._vertexStride * _unifiedVertexCount;
        auto finalVertexBuffer = std::make_unique<uint8[]>(size);
        XlSetMemory(finalVertexBuffer.get(), 0, size);

        for (unsigned elementIndex = 0; elementIndex <_streams.size(); ++elementIndex) {
            const auto& nativeElement     = outputLayout._elements[elementIndex];
            const auto& stream            = _streams[elementIndex];
            WriteStream(
                stream, PtrAdd(finalVertexBuffer.get(), nativeElement._alignedByteOffset),
                nativeElement._nativeFormat, outputLayout._vertexStride,
                size - nativeElement._alignedByteOffset);
        }

        return DynamicArray<uint8>(std::move(finalVertexBuffer), size);
    }