1 /*
2 * gst-plugins-bad
3 * Copyright (C) 2012 Edward Hervey <edward@collabora.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "gstvdputils.h"
27
28 typedef struct
29 {
30 VdpChromaType chroma_type;
31 VdpYCbCrFormat format;
32 GstVideoFormat vformat;
33 } GstVdpVideoBufferFormats;
34
35 static const GstVdpVideoBufferFormats yuv_formats[] = {
36 {VDP_CHROMA_TYPE_420, VDP_YCBCR_FORMAT_YV12, GST_VIDEO_FORMAT_YV12},
37 {VDP_CHROMA_TYPE_420, VDP_YCBCR_FORMAT_NV12, GST_VIDEO_FORMAT_NV12},
38 {VDP_CHROMA_TYPE_422, VDP_YCBCR_FORMAT_UYVY, GST_VIDEO_FORMAT_UYVY},
39 {VDP_CHROMA_TYPE_444, VDP_YCBCR_FORMAT_V8U8Y8A8, GST_VIDEO_FORMAT_AYUV},
40 /* { */
41 /* VDP_CHROMA_TYPE_444, */
42 /* VDP_YCBCR_FORMAT_Y8U8V8A8, */
43 /* GST_MAKE_FOURCC ('A', 'V', 'U', 'Y') */
44 /* }, */
45 {VDP_CHROMA_TYPE_422, VDP_YCBCR_FORMAT_YUYV, GST_VIDEO_FORMAT_YUY2}
46 };
47
48 VdpYCbCrFormat
gst_video_format_to_vdp_ycbcr(GstVideoFormat format)49 gst_video_format_to_vdp_ycbcr (GstVideoFormat format)
50 {
51 int i;
52
53 for (i = 0; i < G_N_ELEMENTS (yuv_formats); i++) {
54 if (yuv_formats[i].vformat == format)
55 return yuv_formats[i].format;
56 }
57
58 return -1;
59 }
60
61 VdpChromaType
gst_video_info_to_vdp_chroma_type(GstVideoInfo * info)62 gst_video_info_to_vdp_chroma_type (GstVideoInfo * info)
63 {
64 const GstVideoFormatInfo *finfo = info->finfo;
65 VdpChromaType ret = -1;
66
67 /* Check subsampling of second plane (first is always non-subsampled) */
68 switch (GST_VIDEO_FORMAT_INFO_W_SUB (finfo, 1)) {
69 case 0:
70 /* Not subsampled in width for second plane */
71 if (GST_VIDEO_FORMAT_INFO_W_SUB (finfo, 2))
72 /* Not subsampled at all (4:4:4) */
73 ret = VDP_CHROMA_TYPE_444;
74 break;
75 case 1:
76 /* Subsampled horizontally once */
77 if (GST_VIDEO_FORMAT_INFO_H_SUB (finfo, 2) == 0)
78 /* Not subsampled vertically (4:2:2) */
79 ret = VDP_CHROMA_TYPE_422;
80 else if (GST_VIDEO_FORMAT_INFO_H_SUB (finfo, 2) == 1)
81 /* Subsampled vertically once (4:2:0) */
82 ret = VDP_CHROMA_TYPE_420;
83 break;
84 default:
85 break;
86 }
87
88 return ret;
89 }
90