bool
I420ColorConverterHelper::ensureLoaded()
{
  {
    RWLock::AutoRLock arl(mLock);
    // Check whether the library has been loaded or not.
    if (loadedLocked()) {
      return true;
    }
  }

  {
    RWLock::AutoWLock awl(mLock);
    // Check whether the library has been loaded or not on other threads.
    if (loadedLocked()) {
      return true;
    }

    // Reload the library
    unloadLocked();
    if (loadLocked()) {
      return true;
    }

    // Reset the library
    unloadLocked();
  }

  return false;
}
Esempio n. 2
0
File: reqresp.cpp Progetto: abh/pdns
 void Request::load(std::istream &is) {
   AsyncRequestLoader arl(this);
   while(is.good()) {
     char buf[1024];
     is.read(buf, 1024);
     if (is.gcount()) { // did we actually read anything
       is.clear();
       if (arl.feed(std::string(buf, is.gcount())) == true) return; // completed
     }
   }
 };
int
I420ColorConverterHelper::getEncoderInputFormat()
{
  if (!ensureLoaded()) {
    return -1;
  }

  RWLock::AutoRLock arl(mLock);
  if (mConverter.getEncoderInputFormat != nullptr) {
    return mConverter.getEncoderInputFormat();
  }
  return -1;
}
int
I420ColorConverterHelper::convertDecoderOutputToI420(
    void* decoderBits, int decoderWidth, int decoderHeight,
    ARect decoderRect, void* dstBits)
{
  if (!ensureLoaded()) {
    return -1;
  }

  RWLock::AutoRLock arl(mLock);
  if (mConverter.convertDecoderOutputToI420 != nullptr) {
    return mConverter.convertDecoderOutputToI420(decoderBits,
        decoderWidth, decoderHeight, decoderRect, dstBits);
  }
  return -1;
}
int
I420ColorConverterHelper::getEncoderInputBufferInfo(int aSrcWidth,
                                                    int aSrcHeight,
                                                    int* aEncoderWidth,
                                                    int* aEncoderHeight,
                                                    ARect* aEncoderRect,
                                                    int* aEncoderBufferSize)
{
  if (!ensureLoaded()) {
    return -1;
  }

  RWLock::AutoRLock arl(mLock);
  if (mConverter.getEncoderInputBufferInfo != nullptr) {
    return mConverter.getEncoderInputBufferInfo(aSrcWidth, aSrcHeight,
        aEncoderWidth, aEncoderHeight, aEncoderRect, aEncoderBufferSize);
  }
  return -1;
}
int
I420ColorConverterHelper::convertI420ToEncoderInput(void* aSrcBits,
                                                    int aSrcWidth,
                                                    int aSrcHeight,
                                                    int aEncoderWidth,
                                                    int aEncoderHeight,
                                                    ARect aEncoderRect,
                                                    void* aEncoderBits)
{
  if (!ensureLoaded()) {
    return -1;
  }

  RWLock::AutoRLock arl(mLock);
  if (mConverter.convertI420ToEncoderInput != nullptr) {
    return mConverter.convertI420ToEncoderInput(aSrcBits, aSrcWidth, aSrcHeight,
        aEncoderWidth, aEncoderHeight, aEncoderRect, aEncoderBits);
  }
  return -1;
}