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 <gst/vaapi/gstvaapisurface.h>
27 #include "decoder.h"
28 #include "output.h"
29 
30 /* Set to 1 to check display cache works (shared VA display) */
31 #define CHECK_DISPLAY_CACHE 1
32 
33 static inline void
pause(void)34 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
main(int argc,char * argv[])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_object_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     } else
114       gst_vaapi_surface_get_size (surface, &width, &height);
115 
116     pixmap = video_output_create_pixmap (display, GST_VIDEO_FORMAT_xRGB,
117         width, height);
118     if (!pixmap)
119       g_error ("could not create pixmap");
120 
121     if (!gst_vaapi_pixmap_put_surface (pixmap, surface, crop_rect,
122             GST_VAAPI_PICTURE_STRUCTURE_FRAME))
123       g_error ("could not render to pixmap");
124 
125     if (!gst_vaapi_window_put_pixmap (window, pixmap, NULL, NULL))
126       g_error ("could not render pixmap");
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_object_unref (decoder);
137   gst_object_unref (window);
138   gst_object_unref (display);
139   gst_object_unref (display2);
140   g_free (g_codec_str);
141   video_output_exit ();
142   return 0;
143 }
144