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