2 * GStreamer Intel MSDK plugin
3 * Copyright (c) 2022 Intel Corporation. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "gstmsdkallocator.h"
35 map_data (GstBuffer * buffer, mfxFrameSurface1 * mfx_surface, GstVideoInfo info)
40 if (!gst_video_frame_map (&frame, &info, buffer, GST_MAP_READWRITE))
43 stride = GST_VIDEO_FRAME_PLANE_STRIDE (&frame, 0);
45 switch (GST_VIDEO_INFO_FORMAT (&info)) {
46 case GST_VIDEO_FORMAT_NV12:
47 case GST_VIDEO_FORMAT_P010_10LE:
48 case GST_VIDEO_FORMAT_P012_LE:
49 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
50 mfx_surface->Data.UV = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 1);
51 mfx_surface->Data.Pitch = (mfxU16) stride;
53 case GST_VIDEO_FORMAT_YV12:
54 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
55 mfx_surface->Data.U = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 2);
56 mfx_surface->Data.V = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 1);
57 mfx_surface->Data.Pitch = (mfxU16) stride;
59 case GST_VIDEO_FORMAT_I420:
60 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
61 mfx_surface->Data.U = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 1);
62 mfx_surface->Data.V = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 2);
63 mfx_surface->Data.Pitch = (mfxU16) stride;
65 case GST_VIDEO_FORMAT_YUY2:
66 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
67 mfx_surface->Data.U = mfx_surface->Data.Y + 1;
68 mfx_surface->Data.V = mfx_surface->Data.Y + 3;
69 mfx_surface->Data.Pitch = (mfxU16) stride;
71 case GST_VIDEO_FORMAT_UYVY:
72 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
73 mfx_surface->Data.U = mfx_surface->Data.Y;
74 mfx_surface->Data.V = mfx_surface->Data.U + 2;
75 mfx_surface->Data.Pitch = (mfxU16) stride;
77 case GST_VIDEO_FORMAT_VUYA:
78 mfx_surface->Data.V = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
79 mfx_surface->Data.U = mfx_surface->Data.V + 1;
80 mfx_surface->Data.Y = mfx_surface->Data.V + 2;
81 mfx_surface->Data.A = mfx_surface->Data.V + 3;
82 mfx_surface->Data.PitchHigh = (mfxU16) (stride / (1 << 16));
83 mfx_surface->Data.PitchLow = (mfxU16) (stride % (1 << 16));
85 case GST_VIDEO_FORMAT_BGRA:
86 case GST_VIDEO_FORMAT_BGRx:
87 mfx_surface->Data.B = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
88 mfx_surface->Data.G = mfx_surface->Data.B + 1;
89 mfx_surface->Data.R = mfx_surface->Data.B + 2;
90 mfx_surface->Data.A = mfx_surface->Data.B + 3;
91 mfx_surface->Data.Pitch = (mfxU16) stride;
93 case GST_VIDEO_FORMAT_Y210:
94 case GST_VIDEO_FORMAT_Y212_LE:
95 mfx_surface->Data.Y = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
96 mfx_surface->Data.U = mfx_surface->Data.Y + 2;
97 mfx_surface->Data.V = mfx_surface->Data.Y + 6;
98 mfx_surface->Data.Pitch = (mfxU16) stride;
100 case GST_VIDEO_FORMAT_Y410:
101 mfx_surface->Data.Y410 =
102 (mfxY410 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
103 mfx_surface->Data.Pitch = stride;
105 case GST_VIDEO_FORMAT_Y412_LE:
106 mfx_surface->Data.U = (mfxU8 *) GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
107 mfx_surface->Data.Y = mfx_surface->Data.Y + 2;
108 mfx_surface->Data.V = mfx_surface->Data.Y + 4;
109 mfx_surface->Data.A = mfx_surface->Data.Y + 6;
110 mfx_surface->Data.Pitch = (mfxU16) stride;
113 g_assert_not_reached ();
117 gst_video_frame_unmap (&frame);
122 gst_msdk_import_sys_mem_to_msdk_surface (GstBuffer * buf, GstVideoInfo info)
124 GstMsdkSurface *msdk_surface = NULL;
126 mfxFrameInfo frame_info = { 0, };
127 mfxFrameSurface1 *mfx_surface = NULL;
129 if (!gst_buffer_map (buf, &map_info, GST_MAP_READ)) {
130 GST_ERROR ("Failed to map buffer");
134 mfx_surface = g_slice_new0 (mfxFrameSurface1);
135 mfx_surface->Data.MemId = (mfxMemId) map_info.data;
137 if (!map_data (buf, mfx_surface, info)) {
138 g_slice_free (mfxFrameSurface1, mfx_surface);
142 gst_buffer_unmap (buf, &map_info);
144 gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, &info);
145 mfx_surface->Info = frame_info;
147 msdk_surface = g_slice_new0 (GstMsdkSurface);
148 msdk_surface->surface = mfx_surface;