Example #1
0
int video_init (dtvideo_context_t * vctx)
{
    int ret = 0;
    dt_info (TAG, "[%s:%d] dtvideo_mgt start init\n", __FUNCTION__, __LINE__);
    //call init
    vctx->video_status = VIDEO_STATUS_INITING;
    vctx->current_pts = vctx->last_valid_pts = -1;

    dtvideo_decoder_t *video_dec = &vctx->video_dec;
    dtvideo_filter_t *video_filt = &vctx->video_filt;
    dtvideo_output_t *video_out = &vctx->video_out;
    
    //vf ctx init
    //vf will init in vd but used in vo
    memset (video_filt, 0, sizeof (dtvideo_filter_t));
    memcpy (&video_filt->para, &vctx->video_para, sizeof (dtvideo_para_t));
    video_filt->parent = vctx;

    //vd ctx init 
    memset (video_dec, 0, sizeof (dtvideo_decoder_t));
    memcpy (&video_dec->para, &vctx->video_para, sizeof (dtvideo_para_t));
    video_dec->parent = vctx;
    ret = video_decoder_init (video_dec);
    if (ret < 0)
        goto err1;
    dt_info (TAG, "[%s:%d] vdecoder init ok\n", __FUNCTION__, __LINE__);

    //vo ctx init
    memset (video_out, 0, sizeof (dtvideo_output_t));
    memcpy (&(video_out->para), &(vctx->video_para), sizeof (dtvideo_para_t));
    video_out->parent = vctx;
    ret = video_output_init (video_out, vctx->video_para.video_output);
    if (ret < 0)
        goto err2;

    vctx->video_status = VIDEO_STATUS_INITED;
    dt_info (TAG, "dtvideo init ok,status:%d \n", vctx->video_status);
    return 0;
  err1:
    dt_info (TAG, "[%s:%d]video decoder init failed \n", __FUNCTION__, __LINE__);
    return -1;
  err2:
    video_decoder_stop (video_dec);
    dt_info (TAG, "[%s:%d]video output init failed \n", __FUNCTION__, __LINE__);
    return -3;
}
int
main (int argc, char *argv[])
{
  App *app;
  gint ret;

  if (!video_output_init (&argc, argv, g_options))
    g_error ("failed to initialize video output subsystem");

  app = app_new ();
  if (!app)
    g_error ("failed to create application context");

  ret = !app_run (app, argc, argv);

  app_free (app);
  g_free (g_codec_str);
  video_output_exit ();
  return ret;
}
int
main (int argc, char *argv[])
{
  GstVaapiDisplay *display;
  GstVaapiSurface *surface;
  GstVaapiID surface_id;
  GstVaapiSurface *surfaces[MAX_SURFACES];
  GstVaapiVideoPool *pool;
  gint i;

  static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
  static const guint width = 320;
  static const guint height = 240;

  if (!video_output_init (&argc, argv, NULL))
    g_error ("failed to initialize video output subsystem");

  display = video_output_create_display (NULL);
  if (!display)
    g_error ("could not create Gst/VA display");

  surface = gst_vaapi_surface_new (display, chroma_type, width, height);
  if (!surface)
    g_error ("could not create Gst/VA surface");

  surface_id = gst_vaapi_surface_get_id (surface);
  g_print ("created surface %" GST_VAAPI_ID_FORMAT "\n",
      GST_VAAPI_ID_ARGS (surface_id));

  gst_vaapi_object_unref (surface);

  pool = gst_vaapi_surface_pool_new (display, GST_VIDEO_FORMAT_ENCODED,
      width, height);
  if (!pool)
    g_error ("could not create Gst/VA surface pool");

  for (i = 0; i < MAX_SURFACES; i++) {
    surface = gst_vaapi_video_pool_get_object (pool);
    if (!surface)
      g_error ("could not allocate Gst/VA surface from pool");
    g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
        GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surface)));
    surfaces[i] = surface;
  }

  /* Check the pool doesn't return the last free'd surface */
  surface = gst_vaapi_object_ref (surfaces[1]);

  for (i = 0; i < 2; i++)
    gst_vaapi_video_pool_put_object (pool, surfaces[i]);

  for (i = 0; i < 2; i++) {
    surfaces[i] = gst_vaapi_video_pool_get_object (pool);
    if (!surfaces[i])
      g_error ("could not re-allocate Gst/VA surface%d from pool", i);
    g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
        GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surfaces[i])));
  }

  if (surface == surfaces[0])
    g_error ("Gst/VA pool doesn't queue free surfaces");

  for (i = MAX_SURFACES - 1; i >= 0; i--) {
    if (!surfaces[i])
      continue;
    gst_vaapi_video_pool_put_object (pool, surfaces[i]);
    surfaces[i] = NULL;
  }

  /* Unref in random order to check objects are correctly refcounted */
  gst_vaapi_display_unref (display);
  gst_vaapi_video_pool_unref (pool);
  gst_vaapi_object_unref (surface);
  video_output_exit ();
  return 0;
}