nuiAudioDevice_DirectSound::nuiAudioDevice_DirectSound(GUID IGuid, GUID OGuid, const nglString& rInName, const nglString& rOutName, const nglString& rInModule, const nglString& rOutModule)
: nuiAudioDevice()
{
  mInName = rInName;
  mOutName = rOutName;
  if (rOutName.IsEmpty())
    mName = rInName;
  else
    mName = rOutName;

  mManufacturer = rOutModule;
  mIsPresent = false;
  mHasInput = false;
  mHasOutput = false;

  mIDeviceID = IGuid;
  mODeviceID = OGuid;

  mpDirectSound = NULL;
  mpDirectSoundCapture = NULL;

  mAPIName = API_NAME;

  mpRingBuffer = NULL;
  mpInputBuffer = NULL;
  mpOutputBuffer = NULL;

  mpProcessingTh = NULL;
  mpOutputTh = NULL;

  mNotifInputEvent[0] = NULL;
  mNotifInputEvent[1] = NULL;
  mNotifOutputEvent[0] = NULL;
  mNotifOutputEvent[1] = NULL;

  HRESULT hr;
  // Get Input device caps:
  hr = DirectSoundCaptureCreate(&mIDeviceID, &mpDirectSoundCapture, NULL);
  if (hr != S_OK || !mpDirectSoundCapture)
  {
    NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_INFO, _T("constructor ERROR : could not create DirectSoundCapture object!\n"));
  }

  // Get Output device caps:
  hr = DirectSoundCreate(&mODeviceID, &mpDirectSound, NULL);
  if (hr != S_OK || !mpDirectSound)
  {
    NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("constructor ERROR : could not create DirectSound object!\n")); // if there is no output, consider the device as not valid
    return;
  }


  Init();
}
Esempio n. 2
0
bool nuiHTML::Load(nglIStream& rStream, nglTextEncoding OverrideContentsEncoding, const nglString& rSourceURL)
{
  if (!rSourceURL.IsEmpty())
    SetSourceURL(rSourceURL);
  
  int res = -1;
  nglTextEncoding encoding = eUTF8;
  TidyDoc tdoc = NULL;
  {
    HTMLStream strm(rStream);
    tdoc = tidyCreate();
    tidyOptSetBool(tdoc, TidyShowMarkup, no);
    tidyOptSetBool(tdoc, TidyShowWarnings, no);
    tidyOptSetInt(tdoc, TidyShowErrors, 0);
    tidyOptSetBool(tdoc, TidyQuiet, yes);
    tidySetCharEncoding(tdoc, "utf8");
    
    TidyInputSource source;
    tidyInitSource( &source, &strm, &HTMLStream::TidyGetByte, &HTMLStream::TidyUngetByte, &HTMLStream::TidyEOF);
    res = tidyParseSource(tdoc, &source);
    
    if ( res >= 0 )
      res = tidyCleanAndRepair(tdoc);               // Tidy it up!
    if ( res >= 0 )
      res = tidyRunDiagnostics(tdoc);               // Kvetch
  
    if (OverrideContentsEncoding == eEncodingUnknown)
    {
      nglString encoding_string(GetEncodingString(tidyGetRoot(tdoc)));
      
      //ascii, latin1, raw, utf8, iso2022, mac, win1252, utf16le, utf16be, utf16, big5 shiftjis
      encoding = nuiGetTextEncodingFromString(encoding_string);
    }
    else
    {
      encoding = OverrideContentsEncoding;
    }
  }
  
  char* pStr = NULL;

  if (encoding != eUTF8)
  {
    // Release the doc to create a new one
    tidyRelease(tdoc);
    
    nglOMemory omem;
    rStream.SetPos(0, eStreamFromStart);
    rStream.PipeTo(omem);
    nglString decoded;
    decoded.Import(omem.GetBufferData(), omem.GetSize(), encoding);
    pStr = decoded.Export(eUTF8);
    nglIMemory imem(pStr, strlen(pStr));
    
    HTMLStream strm(imem);
    tdoc = tidyCreate();
    tidySetCharEncoding(tdoc, "utf8");

    TidyInputSource source;
    tidyInitSource( &source, &strm, &HTMLStream::TidyGetByte, &HTMLStream::TidyUngetByte, &HTMLStream::TidyEOF);
    res = tidyParseSource(tdoc, &source);
    if ( res >= 0 )
      res = tidyCleanAndRepair(tdoc);               // Tidy it up!
    if ( res >= 0 )
      res = tidyRunDiagnostics(tdoc);               // Kvetch
  }    
    
  BuildTree(tdoc, tidyGetRoot(tdoc), eUTF8, mComputeStyle);
  
  tidyRelease(tdoc);
  
  if (pStr)
    free(pStr);
  
  return res < 2;
}
Esempio n. 3
0
int64 nglOStream::WriteText (const nglString& rData)
{
  if (rData.IsEmpty() ||
    ((GetState() != eStreamReady) && (GetState() != eStreamEnd)))
    return 0;

  // Make sure we have a text conversion context
  if (!GetOConv())
    return 0;

  char buffer[BUFFER_SIZE];
  int64 written = 0;
  int32 out_offset = 0;

  do
  {
    int64 bytes;
    const char* data;
    int64 todo;
    int32 buffer_free = BUFFER_SIZE;

    // FIXME!!!!!!!!!!!
    rData.Export(out_offset, buffer, buffer_free, *mpConv);
    switch (mpConv->GetState())
    {
    case eStringConv_OK:
    case eStringConv_NeedOutput:
      break;

    default:
      //SetError() FIXME
      return written;
    }

    data = buffer;
    todo = BUFFER_SIZE - buffer_free;

    // Now write data[0 .. todo-1] with line-ending conversion if necessary
    if (mTextFormat == eTextNone)
    {
      bytes = Write(data, todo, 1);
      if (bytes > 0) written += bytes;
      if (bytes < todo) return written;
    }
    else
    {
      int64 done = 0;
      int64 last_ending, ending = -1;

      while (ending < todo)
      {
        last_ending = ending;
        do
        {
          ending++;
        }
        while ((ending < todo) && (data[ending] != '\n'));

        int64 line_size = ending - last_ending - 1;
        bytes = Write(&(data[last_ending + 1]), line_size, 1);
        if (bytes > 0)
        {
          done += bytes;
          written += bytes;
        }
        if (bytes < line_size) return written;

        if (done < todo)
        {
          switch (mTextFormat)
          {
          case eTextDOS : bytes = Write("\r\n", 1, 2) * 2; break;
          case eTextUnix: bytes = Write("\n", 1, 1); break;
          case eTextMac : bytes = Write("\r", 1, 1); break;
          case eTextZero: bytes = Write("\0", 1, 1); break;
          case eTextNone: break;
          }
          if (bytes > 0)
          {
            done++;
            written += bytes;
          }
          if (bytes < 1) return written;
        }
      }
    }
  }
  while (mpConv->GetState() == eStringConv_NeedOutput);

  return written;
}
Esempio n. 4
0
bool nuiZipWriter::AddFile(const nglPath& rPath, const nglString& rPathInZip, const nglString& rComment)
{
  return AddFile(rPath.OpenRead(), rPathInZip.IsEmpty() ? rPath.GetPathName() : rPathInZip, rComment, true);
}