packaging: add packaging folder and update submodule pkgs
[platform/upstream/gstreamer-vaapi.git] / tests / test-decode.c
1 /*
2  *  test-decode.c - Test GstVaapiDecoder
3  *
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  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24
25 #include "gst/vaapi/sysdeps.h"
26 #include <string.h>
27 #include <gst/vaapi/gstvaapisurface.h>
28 #include "decoder.h"
29 #include "output.h"
30
31 /* Set to 1 to check display cache works (shared VA display) */
32 #define CHECK_DISPLAY_CACHE 1
33
34 static inline void pause(void)
35 {
36     g_print("Press any key to continue...\n");
37     getchar();
38 }
39
40 static gchar *g_codec_str;
41 static gboolean g_use_pixmap;
42
43 static GOptionEntry g_options[] = {
44     { "codec", 'c',
45       0,
46       G_OPTION_ARG_STRING, &g_codec_str,
47       "codec to test", NULL },
48     { "pixmap", 0,
49       0,
50       G_OPTION_ARG_NONE, &g_use_pixmap,
51       "use render-to-pixmap", NULL },
52     { NULL, }
53 };
54
55 int
56 main(int argc, char *argv[])
57 {
58     GstVaapiDisplay      *display, *display2;
59     GstVaapiWindow       *window;
60     GstVaapiPixmap       *pixmap = NULL;
61     GstVaapiDecoder      *decoder;
62     GstVaapiSurfaceProxy *proxy;
63     GstVaapiSurface      *surface;
64     const GstVaapiRectangle *crop_rect;
65
66     static const guint win_width  = 640;
67     static const guint win_height = 480;
68
69     if (!video_output_init(&argc, argv, g_options))
70         g_error("failed to initialize video output subsystem");
71
72     g_print("Test decode\n");
73
74     display = video_output_create_display(NULL);
75     if (!display)
76         g_error("could not create VA display");
77
78     if (CHECK_DISPLAY_CACHE)
79         display2 = video_output_create_display(NULL);
80     else
81         display2 = gst_vaapi_display_ref(display);
82     if (!display2)
83         g_error("could not create second VA display");
84
85     window = video_output_create_window(display, win_width, win_height);
86     if (!window)
87         g_error("could not create window");
88
89     decoder = decoder_new(display, g_codec_str);
90     if (!decoder)
91         g_error("could not create decoder");
92
93     g_print("Decode %s sample frame\n", decoder_get_codec_name(decoder));
94
95     if (!decoder_put_buffers(decoder))
96         g_error("could not fill decoder with sample data");
97
98     proxy = decoder_get_surface(decoder);
99     if (!proxy)
100         g_error("could not get decoded surface");
101
102     surface = gst_vaapi_surface_proxy_get_surface(proxy);
103     crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
104
105     gst_vaapi_window_show(window);
106
107     if (g_use_pixmap) {
108         guint width, height;
109
110         if (crop_rect) {
111             width  = crop_rect->width;
112             height = crop_rect->height;
113         }
114         else
115             gst_vaapi_surface_get_size(surface, &width, &height);
116
117         pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
118             width, height);
119         if (!pixmap)
120             g_error("could not create pixmap");
121
122         if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
123                 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
124             g_error("could not render to pixmap");
125
126         if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
127             g_error("could not render pixmap");
128     }
129     else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
130             GST_VAAPI_PICTURE_STRUCTURE_FRAME))
131         g_error("could not render surface");
132
133     pause();
134
135     if (pixmap)
136         gst_vaapi_pixmap_unref(pixmap);
137     gst_vaapi_surface_proxy_unref(proxy);
138     gst_vaapi_decoder_unref(decoder);
139     gst_vaapi_window_unref(window);
140     gst_vaapi_display_unref(display);
141     gst_vaapi_display_unref(display2);
142     g_free(g_codec_str);
143     video_output_exit();
144     return 0;
145 }