int64_t
JavaURLProtocolHandler :: url_seek(int64_t position,
    int whence)
{
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return -1;

  int64_t retval = -1;

  try
  {
    JavaURLProtocolHandler_CheckException(env);
    retval = env->CallLongMethod(mJavaProtoHandler, mJavaUrlSeek_mid, position,
      whence);
    JavaURLProtocolHandler_CheckException(env);
  }
  catch (std::exception & e)
  {
    VS_LOG_TRACE("%s", e.what());
    retval = -1;
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
    retval = -1;
  }
  return retval;
}
int
JavaURLProtocolHandler :: url_open(const char *url, int flags)
{
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return -1;
  int retval = -1;
  jstring jUrl = 0;
  try
  {
    JavaURLProtocolHandler_CheckException(env);
    jUrl = env->NewStringUTF(url);
    JavaURLProtocolHandler_CheckException(env);
    retval = env->CallIntMethod(mJavaProtoHandler, mJavaUrlOpen_mid, jUrl,
        flags);
    JavaURLProtocolHandler_CheckException(env);
    // delete your local refs, as this is a running inside another library that likely
    // is not returning to Java soon.
  }
  catch (std::exception & e)
  {
    VS_LOG_TRACE("%s", e.what());
    retval = -1;
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
    retval = -1;
  }
  if (jUrl)
    env->DeleteLocalRef(jUrl);

  return retval;
}
int
JavaURLProtocolHandler :: url_close()
{
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return -1;

  int retval = -1;
  try
  {
    JavaURLProtocolHandler_CheckException(env);
    retval = env->CallIntMethod(mJavaProtoHandler, mJavaUrlClose_mid);
    JavaURLProtocolHandler_CheckException(env);
  }
  catch (std::exception & e)
  {
    VS_LOG_TRACE("%s", e.what());
    retval = -1;
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
    retval = -1;
  }
  return retval;
}
Ejemplo n.º 4
0
 int32_t
 Stream :: release()
 {
   int retval = 0;
   retval = RefCounted::release();
   VS_LOG_TRACE("Released %p: %d", this, retval);
   return retval;
 }
Ejemplo n.º 5
0
 int32_t
 Stream :: acquire()
 {
   int retval = 0;
   retval = RefCounted::acquire();
   VS_LOG_TRACE("Acquired %p: %d", this, retval);
   return retval;
 }
Ejemplo n.º 6
0
int64_t
Container::url_seek(void*h, int64_t position, int whence) {
  int64_t retval = -1;
  try {
    URLProtocolHandler* handler = (URLProtocolHandler*) h;
    if (handler) retval = handler->url_seek(position, whence);
  } catch (...) {
    retval = -1;
  }
  VS_LOG_TRACE("URLProtocolHandler[%p]->url_seek(%p, %lld) ==> %d", h, position,
      whence, retval);
  return retval;
}
Ejemplo n.º 7
0
int
Container::url_write(void*h, unsigned char* buf, int size) {
  int retval = -1;
  try {
    URLProtocolHandler* handler = (URLProtocolHandler*) h;
    if (handler) retval = handler->url_write(buf, size);
  } catch (...) {
    retval = -1;
  }
  VS_LOG_TRACE("URLProtocolHandler[%p]->url_write(%p, %d) ==> %d", h, buf, size,
      retval);
  return retval;
}
Ejemplo n.º 8
0
  int32_t
  Property :: setProperty(void *aContext, const char* aName, const char *aValue)
  {
    int32_t retval = -1;

    try
    {
      if (!aContext)
        throw std::runtime_error("no context passed in");
      
      if (!aName  || !*aName)
        throw std::runtime_error("empty property name passed to setProperty");

      void * target=0;
      const AVOption *o = av_opt_find2(aContext, aName, 0, PROPERTY_SEARCH_CHILDREN, 1, &target);
      if (o) {
        AVClass *c = *(AVClass**)target;
        (void) c;
        VS_LOG_TRACE("Found option \"%s\" with help: %s; in unit: %s; object type: %s; instance name: %s",
          o->name,
          o->help,
          o->unit,
          c->class_name,
          c->item_name(aContext));
      }
      VS_LOG_TRACE("Setting %s to %s", aName, aValue);
      retval = av_opt_set(aContext, aName, aValue, PROPERTY_SEARCH_CHILDREN);
    }
    catch (std::exception & e)
    {
      VS_LOG_DEBUG("Error: %s", e.what());
      retval = -1;
    }

    return retval;
  }
Ejemplo n.º 9
0
IndexEntryImpl*
IndexEntryImpl::make(int64_t position, int64_t timeStamp,
    int32_t flags, int32_t size, int32_t minDistance)
{
  VS_LOG_TRACE("Making index entry");
  IndexEntryImpl* retval = make();
  if (retval) {
    retval->mEntry.pos = position;
    retval->mEntry.timestamp = timeStamp;
    retval->mEntry.flags = flags;
    retval->mEntry.size = size;
    retval->mEntry.min_distance = minDistance;
  }
  return retval;
}
Ejemplo n.º 10
0
int
JavaURLProtocolHandler :: url_write(const unsigned char* buf, int size)
{
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return -1;

  int retval = -1;
  jbyteArray byteArray = 0;

  try
  {
    JavaURLProtocolHandler_CheckException(env);
    byteArray = env->NewByteArray(size);
    JavaURLProtocolHandler_CheckException(env);

    // copy the data passed into the new java byteArray
    if (byteArray)
    {
      env->SetByteArrayRegion(byteArray, 0, size, (jbyte*)buf);
      JavaURLProtocolHandler_CheckException(env);

      // write from the Java byte array
      retval = env->CallIntMethod(mJavaProtoHandler, mJavaUrlWrite_mid,
          byteArray, size);
      JavaURLProtocolHandler_CheckException(env);
    }
  }
  catch (std::exception & e)
  {
    VS_LOG_TRACE("%s", e.what());
    retval = -1;
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
    retval = -1;
  }

  // delete your local refs, as this is a running inside another library that likely
  // is not returning to Java soon.
  if (byteArray)
    env->DeleteLocalRef(byteArray);
  return retval;
}
Ejemplo n.º 11
0
int
JavaURLProtocolHandler :: url_read(unsigned char* buf, int size)
{
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return -1;

  int retval = -1;
  jbyteArray byteArray = 0;
  
  try
  {
    JavaURLProtocolHandler_CheckException(env);
    byteArray = env->NewByteArray(size);
    JavaURLProtocolHandler_CheckException(env);
    // read into the Java byte array
    if (byteArray)
    {
      retval = env->CallIntMethod(mJavaProtoHandler, mJavaUrlRead_mid,
          byteArray, size);
      JavaURLProtocolHandler_CheckException(env);
    }
    // now, copy into the C array, but only up to retval.
    if (retval > 0)
    {
      env->GetByteArrayRegion(byteArray, 0, retval, (jbyte*)buf);
      JavaURLProtocolHandler_CheckException(env);
    }
  }
  catch (std::exception& e)
  {
    VS_LOG_TRACE("%s", e.what());
    retval = -1;
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
    retval = -1;
  }
  // delete your local refs, as this is a running inside another library that likely
  // is not returning to Java soon.
  if (byteArray)
    env->DeleteLocalRef(byteArray);
  return retval;
}
Ejemplo n.º 12
0
URLProtocolHandler::SeekableFlags
JavaURLProtocolHandler :: url_seekflags( const char* url, int flags)
{
  URLProtocolHandler::SeekableFlags retFlags = SK_NOT_SEEKABLE;
  JNIEnv *env = JNIHelper::sGetEnv();
  if (!env)
    return SK_NOT_SEEKABLE;
  jboolean url_streaming;
  jstring jUrl = 0;
  try
  {
    JavaURLProtocolHandler_CheckException(env);
    jUrl = env->NewStringUTF(url);
    JavaURLProtocolHandler_CheckException(env);
    // delete your local refs, as this is a running inside another library that likely
    // is not returning to Java soon.
    url_streaming = env->CallBooleanMethod(mJavaProtoHandler,
        mJavaUrlIsStreamed_mid, jUrl, flags);
    JavaURLProtocolHandler_CheckException(env);
    if (!url_streaming)
      retFlags = SK_SEEKABLE_NORMAL;

  }
  catch (std::exception & e)
  {
    VS_LOG_TRACE("%s", e.what());
  }
  catch (...)
  {
    VS_LOG_DEBUG("Got unknown exception");
  }
  if (jUrl)
    env->DeleteLocalRef(jUrl);

  return retFlags;
}
Ejemplo n.º 13
0
MediaPictureImpl*
MediaPictureImpl::make(Buffer* buffer, int32_t width, int32_t height,
    PixelFormat::Type format) {
  if (width <= 0) {
    VS_THROW(HumbleInvalidArgument("width must be > 0"));
  }

  if (height <= 0) {
    VS_THROW(HumbleInvalidArgument("height must be > 0"));
  }

  if (format == PixelFormat::PIX_FMT_NONE) {
    VS_THROW(HumbleInvalidArgument("pixel format must be specifie"));
  }

  if (!buffer) {
    VS_THROW(HumbleInvalidArgument("must pass non null buffer"));
  }

  // let's figure out how big of a buffer we need
  int32_t bufSize = PixelFormat::getBufferSizeNeeded(width, height, format);
  if (bufSize < buffer->getBufferSize()) {
    VS_THROW(
        HumbleInvalidArgument(
            "passed in buffer too small to fit requested image parameters"));
  }

  RefPointer<MediaPictureImpl> retval = make();
  AVFrame* frame = retval->mFrame;
  frame->width = width;
  frame->height = height;
  frame->format = format;

  // buffer is large enough; let's fill the data pointers
  uint8_t* data = (uint8_t*) buffer->getBytes(0, bufSize);

  int32_t imgSize = av_image_fill_arrays(frame->data, frame->linesize, data,
      (enum AVPixelFormat) frame->format, frame->width, frame->height, 1);
  if (imgSize != bufSize) {
    VS_ASSERT(imgSize == bufSize, "these should always be equal");
    VS_THROW(HumbleRuntimeError("could not fill image with data"));
  }

  // now, set up the reference buffers
  frame->extended_data = frame->data;
  for (int32_t i = 0; i < AV_NUM_DATA_POINTERS; i++) {
    if (frame->data[i])
      frame->buf[i] = AVBufferSupport::wrapBuffer(buffer, frame->data[i], frame->linesize[0]*frame->height+16);
  }
  // now fill in the AVBufferRefs where we pass of to FFmpeg care
  // of our buffer. Be kind FFmpeg.  Be kind.
  RefPointer<PixelFormatDescriptor> desc = PixelFormat::getDescriptor((PixelFormat::Type)frame->format);

  if (!desc) {
    VS_THROW(HumbleRuntimeError("could not get format descriptor"));
  }
  if (desc->getFlag(PixelFormatDescriptor::PIX_FMT_FLAG_PAL) ||
      desc->getFlag(PixelFormatDescriptor::PIX_FMT_FLAG_PSEUDOPAL)) {
    av_buffer_unref(&frame->buf[1]);
    frame->buf[1] = AVBufferSupport::wrapBuffer(Buffer::make(retval.value(), 1024));
    if (!frame->buf[1]) {
      VS_THROW(HumbleRuntimeError("memory failure"));
    }

    frame->data[1] = frame->buf[1]->data;
  }

  int32_t n = retval->getNumDataPlanes();
  (void) n;
  VS_LOG_TRACE("Created MediaPicture: %d x %d (%d). [%d, %d, %d, %d]",
      retval->getWidth(),
      retval->getHeight(),
      retval->getFormat(),
      n < 1 ? 0 : retval->getDataPlaneSize(0),
      n < 2 ? 0 : retval->getDataPlaneSize(1),
      n < 3 ? 0 : retval->getDataPlaneSize(2),
      n < 4 ? 0 : retval->getDataPlaneSize(3)
      );

  // and we're done.
  return retval.get();
}