C_RESULT vlib_stage_encoding_open(vlib_stage_encoding_config_t *cfg)
{
  video_codec_open( &cfg->controller, UVLC_CODEC );
  video_controller_set_mode( &cfg->controller, VIDEO_ENCODE );
  video_controller_set_format( &cfg->controller, cfg->width, cfg->height );
  video_controller_set_motion_estimation( &cfg->controller, FALSE );

  return C_OK;
}
C_RESULT vlib_stage_decoding_open(vlib_stage_decoding_config_t *cfg)
{
  // init video decoder with NULL_CODEC
  video_codec_open( &cfg->controller, NULL_CODEC );

  if(cfg->block_mode_enable)
  {
    vp_os_free( cfg->controller.in_stream.bytes );
  }
  else
  {
    stream.bytes  = (uint32_t*)vp_os_malloc(FRAME_MODE_BUFFER_SIZE*sizeof(uint32_t));
    stream.index  = 0;
    stream.used   = 0;
    stream.size   = FRAME_MODE_BUFFER_SIZE*sizeof(uint32_t);
  }

  cfg->num_picture_decoded = 0;

  return C_OK;
}
Beispiel #3
0
p264_state_t* p264_open(void)
{
  p264_state_t* s = (p264_state_t*) calloc(1, sizeof(p264_state_t));
  s->controller = (video_controller_t*) calloc(1, sizeof(video_controller_t));
  s->picture = (vp_api_picture_t*) calloc(1, sizeof(vp_api_picture_t));

  s->picturebuf = (char*) calloc(1, WIDTH*HEIGHT*2);

  s->picture->format = PIX_FMT_RGB565;
  s->picture->framerate = 15;
  s->picture->width = WIDTH;
  s->picture->height = HEIGHT;
  s->picture->y_buf = (uint8_t*)s->picturebuf;
  s->picture->y_line_size = s->picture->width * 2;
  s->picture->cr_buf = calloc(1, WIDTH*HEIGHT*2);
  s->picture->cr_line_size = 0;
  s->picture->cb_buf = calloc(1, WIDTH*HEIGHT*2);
  s->picture->cb_line_size = 0;

  stream.bytes  = (uint32_t*)malloc(FRAME_MODE_BUFFER_SIZE*sizeof(uint32_t));
  stream.index  = 0;
  stream.used   = 0;
  stream.size   = FRAME_MODE_BUFFER_SIZE*sizeof(uint32_t);

  if(video_codec_open(s->controller, P264_CODEC))
  {
    printf("FAILED!\n");
    return NULL;
  }

  s->picture->vision_complete = 0;
  s->picture->complete = 0;
  s->picture->blockline = 0;

  video_controller_set_motion_estimation( s->controller, FALSE );
  video_controller_set_format( s->controller, WIDTH, HEIGHT );

  return s;
}
Beispiel #4
0
void stream_run(void)
{
    C_RESULT status;

    if( stream_thread )
        return;

    memset(&controller, 0, sizeof(controller));
    memset(&picture, 0, sizeof(picture));
    memset(picture_buf, 0, VIDEO_BUFFER_SIZE);
    pictureBpp			  = 2;

    /// Picture configuration
    picture.format	      = PIX_FMT_RGB565;
    picture.width         = H_ACQ_WIDTH;
    picture.height        = H_ACQ_HEIGHT;
    picture.framerate     = 15;
    picture.y_line_size   = picture.width * pictureBpp;
    picture.cb_line_size  = 0;
    picture.cr_line_size  = 0;
    picture.y_buf         = (uint8_t *)picture_buf;
    picture.cb_buf	      = NULL;
    picture.cr_buf	      = NULL;

    status = video_codec_open( &controller, UVLC_CODEC );
    if (status) {
        INFO("video_codec_open() failed\n");
    }
    video_controller_set_motion_estimation(&controller, FALSE);
    video_controller_set_format( &controller, H_ACQ_WIDTH, H_ACQ_HEIGHT );

    if( pthread_create(&stream_thread, NULL, stream_loop, NULL) )
    {
        video_codec_close(&controller);
        INFO("pthread_create: %s\n", strerror(errno));
    }
}
C_RESULT vlib_stage_encoding_transform(vlib_stage_encoding_config_t *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
{
  static int32_t local_subsampl = 0;

  vp_os_mutex_lock(&out->lock);

  if( out->status == VP_API_STATUS_INIT )
  {
    out->numBuffers   = 1;
    out->buffers      = (uint8_t**)&cfg->controller.in_stream.bytes;
    out->indexBuffer  = 0;

    out->status = VP_API_STATUS_PROCESSING;

    cfg->current_size = 0;
  }

  if( local_subsampl == 0 && out->status == VP_API_STATUS_PROCESSING )
  {
    // check video_codec didn't change
    if (cfg->controller.codec_type != cfg->codec_type)
    {
      video_codec_open( &cfg->controller, cfg->codec_type );
      video_controller_set_mode( &cfg->controller, VIDEO_ENCODE );
      video_controller_set_format( &cfg->controller, cfg->width, cfg->height );
      video_controller_set_motion_estimation( &cfg->controller, FALSE );
    }

    // update target size
    video_controller_set_target_size( &cfg->controller, cfg->target_size );
    RTMON_USTART(VIDEO_VLIB_ENCODE_EVENT);
    if(cfg->block_mode_enable)
      video_encode_blockline( &cfg->controller, cfg->picture, cfg->picture->complete );
    else
      video_encode_picture( &cfg->controller, cfg->picture, (bool_t*)&cfg->picture->complete );
    RTMON_USTOP(VIDEO_VLIB_ENCODE_EVENT);

    if(cfg->picture->complete)
    {
      RTMON_UVAL(ENCODED_PICTURE_UVAL, cfg->controller.num_frames);
      local_subsampl++;
    }

    cfg->current_size = cfg->controller.in_stream.used;

    if( cfg->controller.in_stream.length != 32 )
    {
      // flush & reset internal stream
      video_write_data( &cfg->controller.in_stream, 0, cfg->controller.in_stream.length+1 );
      cfg->controller.in_stream.length = 32;
    }
    out->size = cfg->controller.in_stream.used;

    RTMON_UVAL(ENCODED_BLOCKLINE_SIZE_UVAL, out->size);

    cfg->controller.in_stream.used  = 0;
    cfg->controller.in_stream.index = 0;
  }
  else
  {
    out->size = 0;

    if( cfg->picture->complete )
    {
      local_subsampl++;
    }
  }

  if(local_subsampl >= (int32_t)cfg->subsampl)
    local_subsampl = 0;
  vp_os_mutex_unlock( &out->lock );

  return C_OK;
}
C_RESULT vlib_stage_encoding_open(vlib_stage_encoding_config_t *cfg)
{
  video_codec_open( &cfg->controller, NULL_CODEC );
  return C_OK;
}