Add initial VA display abstraction.
[profile/ivi/gstreamer-vaapi.git] / gst-libs / gst / vaapi / vaapi_utils.c
1 /*
2  *  vaapi_utils.c - VA-API utilities
3  *
4  *  gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19  */
20
21 #include "vaapi_utils.h"
22 #include <stdio.h>
23 #include <stdarg.h>
24
25 /* Debug output */
26 void vaapi_dprintf(const char *format, ...)
27 {
28     va_list args;
29     va_start(args, format);
30     fprintf(stdout, "[GstVaapi] ");
31     vfprintf(stdout, format, args);
32     va_end(args);
33 }
34
35 /* Check VA status for success or print out an error */
36 int vaapi_check_status(VAStatus status, const char *msg)
37 {
38     if (status != VA_STATUS_SUCCESS) {
39         vaapi_dprintf("%s: %s\n", msg, vaErrorStr(status));
40         return 0;
41     }
42     return 1;
43 }
44
45 /* Return a string representation of a FOURCC */
46 const char *string_of_FOURCC(guint32 fourcc)
47 {
48     static int buf;
49     static char str[2][5]; // XXX: 2 buffers should be enough for most purposes
50
51     buf ^= 1;
52     str[buf][0] = fourcc;
53     str[buf][1] = fourcc >> 8;
54     str[buf][2] = fourcc >> 16;
55     str[buf][3] = fourcc >> 24;
56     str[buf][4] = '\0';
57     return str[buf];
58 }
59
60 /* Return a string representation of a VAProfile */
61 const char *string_of_VAProfile(VAProfile profile)
62 {
63     switch (profile) {
64 #define PROFILE(profile) \
65         case VAProfile##profile: return "VAProfile" #profile
66         PROFILE(MPEG2Simple);
67         PROFILE(MPEG2Main);
68         PROFILE(MPEG4Simple);
69         PROFILE(MPEG4AdvancedSimple);
70         PROFILE(MPEG4Main);
71         PROFILE(H264Baseline);
72         PROFILE(H264Main);
73         PROFILE(H264High);
74         PROFILE(VC1Simple);
75         PROFILE(VC1Main);
76         PROFILE(VC1Advanced);
77 #undef PROFILE
78     default: break;
79     }
80     return "<unknown>";
81 }
82
83 /* Return a string representation of a VAEntrypoint */
84 const char *string_of_VAEntrypoint(VAEntrypoint entrypoint)
85 {
86     switch (entrypoint) {
87 #define ENTRYPOINT(entrypoint) \
88         case VAEntrypoint##entrypoint: return "VAEntrypoint" #entrypoint
89         ENTRYPOINT(VLD);
90         ENTRYPOINT(IZZ);
91         ENTRYPOINT(IDCT);
92         ENTRYPOINT(MoComp);
93         ENTRYPOINT(Deblocking);
94 #undef ENTRYPOINT
95     default: break;
96     }
97     return "<unknown>";
98 }