1 /* GStreamer
2 * Copyright (C) <2019> Seungha Yang <seungha.yang@navercorp.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * GstCudaBaseTransform:
22 *
23 * Base class for CUDA transformers
24 *
25 * Since: 1.20
26 */
27
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
32 #include "gstcudabasetransform.h"
33 #include "gstcudautils.h"
34
35 GST_DEBUG_CATEGORY_STATIC (gst_cuda_base_transform_debug);
36 #define GST_CAT_DEFAULT gst_cuda_base_transform_debug
37
38 enum
39 {
40 PROP_0,
41 PROP_DEVICE_ID,
42 };
43
44 #define DEFAULT_DEVICE_ID -1
45
46 #define gst_cuda_base_transform_parent_class parent_class
47 G_DEFINE_ABSTRACT_TYPE (GstCudaBaseTransform, gst_cuda_base_transform,
48 GST_TYPE_BASE_TRANSFORM);
49
50 static void gst_cuda_base_transform_set_property (GObject * object,
51 guint prop_id, const GValue * value, GParamSpec * pspec);
52 static void gst_cuda_base_transform_get_property (GObject * object,
53 guint prop_id, GValue * value, GParamSpec * pspec);
54 static void gst_cuda_base_transform_dispose (GObject * object);
55 static void gst_cuda_base_transform_set_context (GstElement * element,
56 GstContext * context);
57 static gboolean gst_cuda_base_transform_start (GstBaseTransform * trans);
58 static gboolean gst_cuda_base_transform_stop (GstBaseTransform * trans);
59 static gboolean gst_cuda_base_transform_set_caps (GstBaseTransform * trans,
60 GstCaps * incaps, GstCaps * outcaps);
61 static GstFlowReturn gst_cuda_base_transform_transform (GstBaseTransform *
62 trans, GstBuffer * inbuf, GstBuffer * outbuf);
63 static gboolean gst_cuda_base_transform_get_unit_size (GstBaseTransform * trans,
64 GstCaps * caps, gsize * size);
65 static gboolean gst_cuda_base_transform_propose_allocation (GstBaseTransform *
66 trans, GstQuery * decide_query, GstQuery * query);
67 static gboolean gst_cuda_base_transform_decide_allocation (GstBaseTransform *
68 trans, GstQuery * query);
69 static gboolean gst_cuda_base_transform_query (GstBaseTransform * trans,
70 GstPadDirection direction, GstQuery * query);
71 static GstFlowReturn
72 gst_cuda_base_transform_transform_frame_default (GstCudaBaseTransform * filter,
73 GstVideoFrame * in_frame, GstCudaMemory * in_cuda_mem,
74 GstVideoFrame * out_frame, GstCudaMemory * out_cuda_mem);
75
76 static void
gst_cuda_base_transform_class_init(GstCudaBaseTransformClass * klass)77 gst_cuda_base_transform_class_init (GstCudaBaseTransformClass * klass)
78 {
79 GObjectClass *gobject_class;
80 GstElementClass *element_class;
81 GstBaseTransformClass *trans_class;
82
83 gobject_class = G_OBJECT_CLASS (klass);
84 element_class = GST_ELEMENT_CLASS (klass);
85 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
86
87 gobject_class->set_property = gst_cuda_base_transform_set_property;
88 gobject_class->get_property = gst_cuda_base_transform_get_property;
89 gobject_class->dispose = gst_cuda_base_transform_dispose;
90
91 g_object_class_install_property (gobject_class, PROP_DEVICE_ID,
92 g_param_spec_int ("cuda-device-id",
93 "Cuda Device ID",
94 "Set the GPU device to use for operations (-1 = auto)",
95 -1, G_MAXINT, DEFAULT_DEVICE_ID,
96 G_PARAM_READWRITE | GST_PARAM_MUTABLE_READY |
97 G_PARAM_STATIC_STRINGS));
98
99 element_class->set_context =
100 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_set_context);
101
102 trans_class->passthrough_on_same_caps = TRUE;
103
104 trans_class->start = GST_DEBUG_FUNCPTR (gst_cuda_base_transform_start);
105 trans_class->stop = GST_DEBUG_FUNCPTR (gst_cuda_base_transform_stop);
106 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_cuda_base_transform_set_caps);
107 trans_class->transform =
108 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_transform);
109 trans_class->get_unit_size =
110 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_get_unit_size);
111 trans_class->propose_allocation =
112 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_propose_allocation);
113 trans_class->decide_allocation =
114 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_decide_allocation);
115 trans_class->query = GST_DEBUG_FUNCPTR (gst_cuda_base_transform_query);
116
117 klass->transform_frame =
118 GST_DEBUG_FUNCPTR (gst_cuda_base_transform_transform_frame_default);
119
120 GST_DEBUG_CATEGORY_INIT (gst_cuda_base_transform_debug,
121 "cudabasefilter", 0, "cudabasefilter Element");
122 }
123
124 static void
gst_cuda_base_transform_init(GstCudaBaseTransform * filter)125 gst_cuda_base_transform_init (GstCudaBaseTransform * filter)
126 {
127 filter->device_id = DEFAULT_DEVICE_ID;
128
129 filter->negotiated = FALSE;
130 }
131
132 static void
gst_cuda_base_transform_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)133 gst_cuda_base_transform_set_property (GObject * object, guint prop_id,
134 const GValue * value, GParamSpec * pspec)
135 {
136 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (object);
137
138 switch (prop_id) {
139 case PROP_DEVICE_ID:
140 filter->device_id = g_value_get_int (value);
141 break;
142 default:
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 break;
145 }
146 }
147
148 static void
gst_cuda_base_transform_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)149 gst_cuda_base_transform_get_property (GObject * object, guint prop_id,
150 GValue * value, GParamSpec * pspec)
151 {
152 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (object);
153
154 switch (prop_id) {
155 case PROP_DEVICE_ID:
156 g_value_set_int (value, filter->device_id);
157 break;
158 default:
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
160 break;
161 }
162 }
163
164 static void
gst_cuda_base_transform_dispose(GObject * object)165 gst_cuda_base_transform_dispose (GObject * object)
166 {
167 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (object);
168
169 gst_clear_object (&filter->context);
170
171 G_OBJECT_CLASS (parent_class)->dispose (object);
172 }
173
174 static void
gst_cuda_base_transform_set_context(GstElement * element,GstContext * context)175 gst_cuda_base_transform_set_context (GstElement * element, GstContext * context)
176 {
177 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (element);
178
179 gst_cuda_handle_set_context (element,
180 context, filter->device_id, &filter->context);
181
182 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
183 }
184
185 static gboolean
gst_cuda_base_transform_start(GstBaseTransform * trans)186 gst_cuda_base_transform_start (GstBaseTransform * trans)
187 {
188 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
189 CUresult cuda_ret;
190
191 if (!gst_cuda_ensure_element_context (GST_ELEMENT_CAST (filter),
192 filter->device_id, &filter->context)) {
193 GST_ERROR_OBJECT (filter, "Failed to get CUDA context");
194 return FALSE;
195 }
196
197 if (gst_cuda_context_push (filter->context)) {
198 cuda_ret = CuStreamCreate (&filter->cuda_stream, CU_STREAM_DEFAULT);
199 if (!gst_cuda_result (cuda_ret)) {
200 GST_WARNING_OBJECT (filter,
201 "Could not create cuda stream, will use default stream");
202 filter->cuda_stream = NULL;
203 }
204 gst_cuda_context_pop (NULL);
205 }
206
207 return TRUE;
208 }
209
210 static gboolean
gst_cuda_base_transform_stop(GstBaseTransform * trans)211 gst_cuda_base_transform_stop (GstBaseTransform * trans)
212 {
213 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
214
215 if (filter->context && filter->cuda_stream) {
216 if (gst_cuda_context_push (filter->context)) {
217 gst_cuda_result (CuStreamDestroy (filter->cuda_stream));
218 gst_cuda_context_pop (NULL);
219 }
220 }
221
222 gst_clear_object (&filter->context);
223 filter->cuda_stream = NULL;
224
225 return TRUE;
226 }
227
228 static gboolean
gst_cuda_base_transform_set_caps(GstBaseTransform * trans,GstCaps * incaps,GstCaps * outcaps)229 gst_cuda_base_transform_set_caps (GstBaseTransform * trans, GstCaps * incaps,
230 GstCaps * outcaps)
231 {
232 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
233 GstVideoInfo in_info, out_info;
234 GstCudaBaseTransformClass *klass;
235 gboolean res;
236
237 if (!filter->context) {
238 GST_ERROR_OBJECT (filter, "No available CUDA context");
239 return FALSE;
240 }
241
242 /* input caps */
243 if (!gst_video_info_from_caps (&in_info, incaps))
244 goto invalid_caps;
245
246 /* output caps */
247 if (!gst_video_info_from_caps (&out_info, outcaps))
248 goto invalid_caps;
249
250 klass = GST_CUDA_BASE_TRANSFORM_GET_CLASS (filter);
251 if (klass->set_info)
252 res = klass->set_info (filter, incaps, &in_info, outcaps, &out_info);
253 else
254 res = TRUE;
255
256 if (res) {
257 filter->in_info = in_info;
258 filter->out_info = out_info;
259 }
260
261 filter->negotiated = res;
262
263 return res;
264
265 /* ERRORS */
266 invalid_caps:
267 {
268 GST_ERROR_OBJECT (filter, "invalid caps");
269 filter->negotiated = FALSE;
270 return FALSE;
271 }
272 }
273
274 static gboolean
gst_cuda_base_transform_get_unit_size(GstBaseTransform * trans,GstCaps * caps,gsize * size)275 gst_cuda_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
276 gsize * size)
277 {
278 gboolean ret = FALSE;
279 GstVideoInfo info;
280
281 ret = gst_video_info_from_caps (&info, caps);
282 if (ret)
283 *size = GST_VIDEO_INFO_SIZE (&info);
284
285 return TRUE;
286 }
287
288 static GstFlowReturn
gst_cuda_base_transform_transform(GstBaseTransform * trans,GstBuffer * inbuf,GstBuffer * outbuf)289 gst_cuda_base_transform_transform (GstBaseTransform * trans,
290 GstBuffer * inbuf, GstBuffer * outbuf)
291 {
292 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
293 GstCudaBaseTransformClass *fclass =
294 GST_CUDA_BASE_TRANSFORM_GET_CLASS (filter);
295 GstVideoFrame in_frame, out_frame;
296 GstFlowReturn ret = GST_FLOW_OK;
297 GstMapFlags in_map_flags, out_map_flags;
298 GstMemory *mem;
299 GstCudaMemory *in_cuda_mem = NULL;
300 GstCudaMemory *out_cuda_mem = NULL;
301
302 if (G_UNLIKELY (!filter->negotiated))
303 goto unknown_format;
304
305 in_map_flags = GST_MAP_READ | GST_VIDEO_FRAME_MAP_FLAG_NO_REF;
306 out_map_flags = GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF;
307
308 in_cuda_mem = out_cuda_mem = FALSE;
309
310 if (gst_buffer_n_memory (inbuf) == 1 &&
311 (mem = gst_buffer_peek_memory (inbuf, 0)) && gst_is_cuda_memory (mem)) {
312 GstCudaMemory *cmem = GST_CUDA_MEMORY_CAST (mem);
313
314 if (cmem->context == filter->context ||
315 gst_cuda_context_get_handle (cmem->context) ==
316 gst_cuda_context_get_handle (filter->context) ||
317 (gst_cuda_context_can_access_peer (cmem->context, filter->context) &&
318 gst_cuda_context_can_access_peer (filter->context,
319 cmem->context))) {
320 in_map_flags |= GST_MAP_CUDA;
321 in_cuda_mem = cmem;
322 }
323 }
324
325 if (gst_buffer_n_memory (outbuf) == 1 &&
326 (mem = gst_buffer_peek_memory (outbuf, 0)) && gst_is_cuda_memory (mem)) {
327 GstCudaMemory *cmem = GST_CUDA_MEMORY_CAST (mem);
328
329 if (cmem->context == filter->context ||
330 gst_cuda_context_get_handle (cmem->context) ==
331 gst_cuda_context_get_handle (filter->context) ||
332 (gst_cuda_context_can_access_peer (cmem->context, filter->context) &&
333 gst_cuda_context_can_access_peer (filter->context,
334 cmem->context))) {
335 out_map_flags |= GST_MAP_CUDA;
336 out_cuda_mem = cmem;
337 }
338 }
339
340 if (!gst_video_frame_map (&in_frame, &filter->in_info, inbuf, in_map_flags))
341 goto invalid_buffer;
342
343 if (!gst_video_frame_map (&out_frame, &filter->out_info, outbuf,
344 out_map_flags)) {
345 gst_video_frame_unmap (&in_frame);
346 goto invalid_buffer;
347 }
348
349 ret = fclass->transform_frame (filter, &in_frame, in_cuda_mem, &out_frame,
350 out_cuda_mem);
351
352 gst_video_frame_unmap (&out_frame);
353 gst_video_frame_unmap (&in_frame);
354
355 return ret;
356
357 /* ERRORS */
358 unknown_format:
359 {
360 GST_ELEMENT_ERROR (filter, CORE, NOT_IMPLEMENTED, (NULL),
361 ("unknown format"));
362 return GST_FLOW_NOT_NEGOTIATED;
363 }
364 invalid_buffer:
365 {
366 GST_ELEMENT_WARNING (trans, CORE, NOT_IMPLEMENTED, (NULL),
367 ("invalid video buffer received"));
368 return GST_FLOW_OK;
369 }
370 }
371
372 static GstFlowReturn
gst_cuda_base_transform_transform_frame_default(GstCudaBaseTransform * filter,GstVideoFrame * in_frame,GstCudaMemory * in_cuda_mem,GstVideoFrame * out_frame,GstCudaMemory * out_cuda_mem)373 gst_cuda_base_transform_transform_frame_default (GstCudaBaseTransform * filter,
374 GstVideoFrame * in_frame, GstCudaMemory * in_cuda_mem,
375 GstVideoFrame * out_frame, GstCudaMemory * out_cuda_mem)
376 {
377 gint i;
378 GstFlowReturn ret = GST_FLOW_OK;
379
380 if (in_cuda_mem || out_cuda_mem) {
381 if (!gst_cuda_context_push (filter->context)) {
382 GST_ELEMENT_ERROR (filter, LIBRARY, FAILED, (NULL),
383 ("Cannot push CUDA context"));
384
385 return GST_FLOW_ERROR;
386 }
387
388 for (i = 0; i < GST_VIDEO_FRAME_N_PLANES (in_frame); i++) {
389 CUDA_MEMCPY2D param = { 0, };
390 guint width, height;
391
392 width = GST_VIDEO_FRAME_COMP_WIDTH (in_frame, i) *
393 GST_VIDEO_FRAME_COMP_PSTRIDE (in_frame, i);
394 height = GST_VIDEO_FRAME_COMP_HEIGHT (in_frame, i);
395
396 if (in_cuda_mem) {
397 param.srcMemoryType = CU_MEMORYTYPE_DEVICE;
398 param.srcDevice = in_cuda_mem->data + in_cuda_mem->offset[i];
399 param.srcPitch = in_cuda_mem->stride;
400 } else {
401 param.srcMemoryType = CU_MEMORYTYPE_HOST;
402 param.srcHost = GST_VIDEO_FRAME_PLANE_DATA (in_frame, i);
403 param.srcPitch = GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, i);
404 }
405
406 if (out_cuda_mem) {
407 param.dstMemoryType = CU_MEMORYTYPE_DEVICE;
408 param.dstDevice = out_cuda_mem->data + out_cuda_mem->offset[i];
409 param.dstPitch = out_cuda_mem->stride;
410 } else {
411 param.dstMemoryType = CU_MEMORYTYPE_HOST;
412 param.dstHost = GST_VIDEO_FRAME_PLANE_DATA (out_frame, i);
413 param.dstPitch = GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, i);
414 }
415
416 param.WidthInBytes = width;
417 param.Height = height;
418
419 if (!gst_cuda_result (CuMemcpy2DAsync (¶m, filter->cuda_stream))) {
420 gst_cuda_context_pop (NULL);
421 GST_ELEMENT_ERROR (filter, LIBRARY, FAILED, (NULL),
422 ("Cannot upload input video frame"));
423
424 return GST_FLOW_ERROR;
425 }
426 }
427
428 CuStreamSynchronize (filter->cuda_stream);
429
430 gst_cuda_context_pop (NULL);
431 } else {
432 for (i = 0; i < GST_VIDEO_FRAME_N_PLANES (in_frame); i++) {
433 if (!gst_video_frame_copy_plane (out_frame, in_frame, i)) {
434 GST_ERROR_OBJECT (filter, "Couldn't copy %dth plane", i);
435
436 return GST_FLOW_ERROR;
437 }
438 }
439 }
440
441 return ret;
442 }
443
444 static gboolean
gst_cuda_base_transform_propose_allocation(GstBaseTransform * trans,GstQuery * decide_query,GstQuery * query)445 gst_cuda_base_transform_propose_allocation (GstBaseTransform * trans,
446 GstQuery * decide_query, GstQuery * query)
447 {
448 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
449 GstVideoInfo info;
450 GstBufferPool *pool;
451 GstCaps *caps;
452 guint size;
453
454 if (!GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
455 decide_query, query))
456 return FALSE;
457
458 /* passthrough, we're done */
459 if (decide_query == NULL)
460 return TRUE;
461
462 gst_query_parse_allocation (query, &caps, NULL);
463
464 if (caps == NULL)
465 return FALSE;
466
467 if (!gst_video_info_from_caps (&info, caps))
468 return FALSE;
469
470 if (gst_query_get_n_allocation_pools (query) == 0) {
471 GstCapsFeatures *features;
472 GstStructure *config;
473 GstVideoAlignment align;
474 GstAllocationParams params = { 0, 31, 0, 0, };
475 GstAllocator *allocator = NULL;
476 gint i;
477
478 features = gst_caps_get_features (caps, 0);
479
480 if (features && gst_caps_features_contains (features,
481 GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY)) {
482 GST_DEBUG_OBJECT (filter, "upstream support CUDA memory");
483 pool = gst_cuda_buffer_pool_new (filter->context);
484 } else {
485 pool = gst_video_buffer_pool_new ();
486 }
487
488 config = gst_buffer_pool_get_config (pool);
489
490 gst_video_alignment_reset (&align);
491 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&info); i++) {
492 align.stride_align[i] = 31;
493 }
494 gst_video_info_align (&info, &align);
495
496 gst_buffer_pool_config_add_option (config,
497 GST_BUFFER_POOL_OPTION_VIDEO_META);
498 gst_buffer_pool_config_add_option (config,
499 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
500
501 gst_buffer_pool_config_set_video_alignment (config, &align);
502 size = GST_VIDEO_INFO_SIZE (&info);
503 gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
504
505 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
506 gst_query_add_allocation_pool (query, pool, size, 0, 0);
507
508 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms)) {
509 if (params.align < 31)
510 params.align = 31;
511
512 gst_query_add_allocation_param (query, allocator, ¶ms);
513 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
514 }
515
516 if (!gst_buffer_pool_set_config (pool, config))
517 goto config_failed;
518
519 gst_object_unref (pool);
520 }
521
522 return TRUE;
523
524 /* ERRORS */
525 config_failed:
526 {
527 GST_ERROR_OBJECT (filter, "failed to set config");
528 gst_object_unref (pool);
529 return FALSE;
530 }
531 }
532
533 static gboolean
gst_cuda_base_transform_decide_allocation(GstBaseTransform * trans,GstQuery * query)534 gst_cuda_base_transform_decide_allocation (GstBaseTransform * trans,
535 GstQuery * query)
536 {
537 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
538 GstCaps *outcaps = NULL;
539 GstBufferPool *pool = NULL;
540 guint size, min, max;
541 GstStructure *config;
542 gboolean update_pool = FALSE;
543 gboolean need_cuda = FALSE;
544 GstCapsFeatures *features;
545
546 gst_query_parse_allocation (query, &outcaps, NULL);
547
548 if (!outcaps)
549 return FALSE;
550
551 features = gst_caps_get_features (outcaps, 0);
552 if (features && gst_caps_features_contains (features,
553 GST_CAPS_FEATURE_MEMORY_CUDA_MEMORY)) {
554 need_cuda = TRUE;
555 }
556
557 if (gst_query_get_n_allocation_pools (query) > 0) {
558 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
559 if (need_cuda && pool && !GST_IS_CUDA_BUFFER_POOL (pool)) {
560 /* when cuda device memory is supported, but pool is not cudabufferpool */
561 gst_object_unref (pool);
562 pool = NULL;
563 }
564
565 update_pool = TRUE;
566 } else {
567 GstVideoInfo vinfo;
568 gst_video_info_from_caps (&vinfo, outcaps);
569 size = GST_VIDEO_INFO_SIZE (&vinfo);
570 min = max = 0;
571 }
572
573 if (!pool) {
574 GST_DEBUG_OBJECT (filter, "create our pool");
575
576 if (need_cuda)
577 pool = gst_cuda_buffer_pool_new (filter->context);
578 else
579 pool = gst_video_buffer_pool_new ();
580 }
581
582 config = gst_buffer_pool_get_config (pool);
583 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
584 gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
585 gst_buffer_pool_set_config (pool, config);
586 if (update_pool)
587 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
588 else
589 gst_query_add_allocation_pool (query, pool, size, min, max);
590
591 gst_object_unref (pool);
592
593 return GST_BASE_TRANSFORM_CLASS (parent_class)->decide_allocation (trans,
594 query);
595 }
596
597 static gboolean
gst_cuda_base_transform_query(GstBaseTransform * trans,GstPadDirection direction,GstQuery * query)598 gst_cuda_base_transform_query (GstBaseTransform * trans,
599 GstPadDirection direction, GstQuery * query)
600 {
601 GstCudaBaseTransform *filter = GST_CUDA_BASE_TRANSFORM (trans);
602
603 switch (GST_QUERY_TYPE (query)) {
604 case GST_QUERY_CONTEXT:
605 {
606 gboolean ret;
607 ret = gst_cuda_handle_context_query (GST_ELEMENT (filter), query,
608 filter->context);
609 if (ret)
610 return TRUE;
611 break;
612 }
613 default:
614 break;
615 }
616
617 return GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction,
618 query);
619 }
620