test-decode.c 4.16 KB
Newer Older
1 2 3
/*
 *  test-decode.c - Test GstVaapiDecoder
 *
4
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6
 *  Copyright (C) 2011-2013 Intel Corporation
7
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8
 *
warly's avatar
warly committed
9 10 11 12
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
13
 *
warly's avatar
warly committed
14
 *  This library is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
warly's avatar
warly committed
16 17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
18
 *
warly's avatar
warly committed
19 20 21 22
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
23
 */
24

25
#include "gst/vaapi/sysdeps.h"
26 27
#include <string.h>
#include <gst/vaapi/gstvaapisurface.h>
28
#include "decoder.h"
29
#include "output.h"
30

31 32 33
/* Set to 1 to check display cache works (shared VA display) */
#define CHECK_DISPLAY_CACHE 1

34 35
static inline void
pause (void)
36
{
37 38
  g_print ("Press any key to continue...\n");
  getchar ();
39 40 41
}

static gchar *g_codec_str;
42
static gboolean g_use_pixmap;
43 44

static GOptionEntry g_options[] = {
45 46 47 48 49 50 51 52 53
  {"codec", 'c',
        0,
        G_OPTION_ARG_STRING, &g_codec_str,
      "codec to test", NULL},
  {"pixmap", 0,
        0,
        G_OPTION_ARG_NONE, &g_use_pixmap,
      "use render-to-pixmap", NULL},
  {NULL,}
54 55 56
};

int
57
main (int argc, char *argv[])
58
{
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  GstVaapiDisplay *display, *display2;
  GstVaapiWindow *window;
  GstVaapiPixmap *pixmap = NULL;
  GstVaapiDecoder *decoder;
  GstVaapiSurfaceProxy *proxy;
  GstVaapiSurface *surface;
  const GstVaapiRectangle *crop_rect;

  static const guint win_width = 640;
  static const guint win_height = 480;

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

  g_print ("Test decode\n");

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

  if (CHECK_DISPLAY_CACHE)
    display2 = video_output_create_display (NULL);
  else
    display2 = gst_vaapi_display_ref (display);
  if (!display2)
    g_error ("could not create second VA display");

  window = video_output_create_window (display, win_width, win_height);
  if (!window)
    g_error ("could not create window");

  decoder = decoder_new (display, g_codec_str);
  if (!decoder)
    g_error ("could not create decoder");

  g_print ("Decode %s sample frame\n", decoder_get_codec_name (decoder));

  if (!decoder_put_buffers (decoder))
    g_error ("could not fill decoder with sample data");

  proxy = decoder_get_surface (decoder);
  if (!proxy)
    g_error ("could not get decoded surface");

  surface = gst_vaapi_surface_proxy_get_surface (proxy);
  crop_rect = gst_vaapi_surface_proxy_get_crop_rect (proxy);

  gst_vaapi_window_show (window);

  if (g_use_pixmap) {
    guint width, height;

    if (crop_rect) {
      width = crop_rect->width;
      height = crop_rect->height;
    } else
      gst_vaapi_surface_get_size (surface, &width, &height);

    pixmap = video_output_create_pixmap (display, GST_VIDEO_FORMAT_xRGB,
        width, height);
    if (!pixmap)
      g_error ("could not create pixmap");

    if (!gst_vaapi_pixmap_put_surface (pixmap, surface, crop_rect,
123
            GST_VAAPI_PICTURE_STRUCTURE_FRAME))
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
      g_error ("could not render to pixmap");

    if (!gst_vaapi_window_put_pixmap (window, pixmap, NULL, NULL))
      g_error ("could not render pixmap");
  } else if (!gst_vaapi_window_put_surface (window, surface, crop_rect, NULL,
          GST_VAAPI_PICTURE_STRUCTURE_FRAME))
    g_error ("could not render surface");

  pause ();

  if (pixmap)
    gst_vaapi_pixmap_unref (pixmap);
  gst_vaapi_surface_proxy_unref (proxy);
  gst_vaapi_decoder_unref (decoder);
  gst_vaapi_window_unref (window);
  gst_vaapi_display_unref (display);
  gst_vaapi_display_unref (display2);
  g_free (g_codec_str);
  video_output_exit ();
  return 0;
144
}