taglist, plugins: fix compiler warnings with GLib >= 2.76
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / msdk / gstmsdkallocator_d3d.c
1 /* GStreamer Intel MSDK plugin
2  * Copyright (c) 2018, Intel Corporation
3  * Copyright (c) 2018, Igalia S.L.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
29  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include <gst/d3d11/gstd3d11.h>
34 #include "gstmsdkallocator.h"
35
36 #define GST_MSDK_FRAME_SURFACE gst_msdk_frame_surface_quark_get ()
37 static GQuark
38 gst_msdk_frame_surface_quark_get (void)
39 {
40   static gsize g_quark;
41
42   if (g_once_init_enter (&g_quark)) {
43     gsize quark = (gsize) g_quark_from_static_string ("GstMsdkFrameSurface");
44     g_once_init_leave (&g_quark, quark);
45   }
46   return g_quark;
47 }
48
49 mfxStatus
50 gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
51     mfxFrameAllocResponse * resp)
52 {
53   return MFX_ERR_NONE;
54 }
55
56 mfxStatus
57 gst_msdk_frame_free (mfxHDL pthis, mfxFrameAllocResponse * resp)
58 {
59   return MFX_ERR_NONE;
60 }
61
62 mfxStatus
63 gst_msdk_frame_lock (mfxHDL pthis, mfxMemId mid, mfxFrameData * data)
64 {
65   return MFX_ERR_NONE;
66 }
67
68 mfxStatus
69 gst_msdk_frame_unlock (mfxHDL pthis, mfxMemId mid, mfxFrameData * ptr)
70 {
71   return MFX_ERR_NONE;
72 }
73
74 mfxStatus
75 gst_msdk_frame_get_hdl (mfxHDL pthis, mfxMemId mid, mfxHDL * hdl)
76 {
77   GstMsdkMemoryID *mem_id;
78   mfxHDLPair *pair;
79
80   if (!hdl || !mid)
81     return MFX_ERR_INVALID_HANDLE;
82
83   mem_id = (GstMsdkMemoryID *) mid;
84   pair = (mfxHDLPair *) hdl;
85   pair->first = (mfxHDL) mem_id->texture;
86   pair->second = (mfxHDL) GUINT_TO_POINTER (mem_id->subresource_index);
87
88   return MFX_ERR_NONE;
89 }
90
91 GstMsdkSurface *
92 gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context,
93     GstVideoInfo * vinfo, guint map_flag)
94 {
95   GstMemory *mem = NULL;
96   mfxFrameInfo frame_info = { 0, };
97   GstMsdkSurface *msdk_surface = NULL;
98   mfxFrameSurface1 *mfx_surface = NULL;
99   GstMsdkMemoryID *msdk_mid = NULL;
100   GstMapInfo map_info;
101
102   mem = gst_buffer_peek_memory (buf, 0);
103   msdk_surface = g_slice_new0 (GstMsdkSurface);
104
105   if (!gst_is_d3d11_memory (mem) || gst_buffer_n_memory (buf) > 1) {
106     /* d3d11 buffer should hold single memory object */
107     g_slice_free (GstMsdkSurface, msdk_surface);
108     return NULL;
109   }
110
111   if (!gst_buffer_map (buf, &map_info, map_flag | GST_MAP_D3D11)) {
112     GST_ERROR ("Failed to map buffer");
113     g_slice_free (GstMsdkSurface, msdk_surface);
114     return NULL;
115   }
116
117   /* If buffer has qdata pointing to mfxFrameSurface1, directly extract it */
118   if ((mfx_surface = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (mem),
119               GST_MSDK_FRAME_SURFACE))) {
120     msdk_surface->from_qdata = TRUE;
121     msdk_surface->surface = mfx_surface;
122     gst_buffer_unmap (buf, &map_info);
123     return msdk_surface;
124   }
125
126   mfx_surface = g_slice_new0 (mfxFrameSurface1);
127   msdk_mid = g_slice_new0 (GstMsdkMemoryID);
128   mfx_surface->Data.MemId = (mfxMemId) msdk_mid;
129
130   msdk_mid->texture = (ID3D11Texture2D *) (gpointer) map_info.data;
131   msdk_mid->subresource_index = GPOINTER_TO_UINT (map_info.user_data[0]);
132
133   gst_buffer_unmap (buf, &map_info);
134
135   gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, vinfo);
136   mfx_surface->Info = frame_info;
137
138   /* Set mfxFrameSurface1 as qdata in buffer */
139   gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem),
140       GST_MSDK_FRAME_SURFACE, mfx_surface, NULL);
141
142   msdk_surface->surface = mfx_surface;
143
144   return msdk_surface;
145 }
146
147 void
148 gst_msdk_set_frame_allocator (GstMsdkContext * context)
149 {
150   mfxFrameAllocator gst_msdk_frame_allocator = {
151     .pthis = context,
152     .Alloc = gst_msdk_frame_alloc,
153     .Lock = gst_msdk_frame_lock,
154     .Unlock = gst_msdk_frame_unlock,
155     .GetHDL = gst_msdk_frame_get_hdl,
156     .Free = gst_msdk_frame_free,
157   };
158
159   gst_msdk_context_set_frame_allocator (context, &gst_msdk_frame_allocator);
160 }