1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2018, Intel Corporation
5 * Author: Sreerenj Balachaandran <sreerenj.balachandran@intel.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "gstmsdkvpp.h"
41 #include "gstmsdkbufferpool.h"
42 #include "gstmsdkvideomemory.h"
43 #include "gstmsdksystemmemory.h"
44 #include "gstmsdkcontextutil.h"
45 #include "gstmsdkvpputil.h"
47 #define EXT_FORMATS ""
50 #include "gstmsdkallocator_libva.h"
51 #if VA_CHECK_VERSION(1, 4, 1)
53 #define EXT_FORMATS ", BGR10A2_LE"
57 #if (MFX_VERSION >= 1028)
58 #define EXT_SINK_FORMATS ", RGB16, Y410, Y210"
59 #define EXT_SRC_FORMATS ", Y410, Y210"
60 #elif (MFX_VERSION >= 1027)
61 #define EXT_SINK_FORMATS ", Y410, Y210"
62 #define EXT_SRC_FORMATS ", Y410, Y210"
64 #define EXT_SINK_FORMATS ""
65 #define EXT_SRC_FORMATS ""
68 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvpp_debug);
69 #define GST_CAT_DEFAULT gst_msdkvpp_debug
71 #define SUPPORTED_SYSTEM_FORMAT \
72 "{ NV12, YV12, I420, YUY2, UYVY, VUYA, BGRA, BGRx, P010_10LE" EXT_SINK_FORMATS "}"
73 #define SUPPORTED_DMABUF_FORMAT \
74 "{ NV12, BGRA, YUY2, UYVY, VUYA, P010_10LE" EXT_SINK_FORMATS "}"
75 #define SRC_SYSTEM_FORMAT \
76 "{ BGRA, NV12, YUY2, UYVY, VUYA, BGRx, P010_10LE" EXT_FORMATS EXT_SRC_FORMATS "}"
77 #define SRC_DMABUF_FORMAT \
78 "{ BGRA, YUY2, UYVY, NV12, VUYA, BGRx, P010_10LE" EXT_FORMATS EXT_SRC_FORMATS "}"
81 #define DMABUF_SINK_CAPS_STR \
82 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, \
83 SUPPORTED_DMABUF_FORMAT)
85 #define DMABUF_SINK_CAPS_STR ""
89 #define DMABUF_SRC_CAPS_STR \
90 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF, \
91 SRC_DMABUF_FORMAT) ";"
93 #define DMABUF_SRC_CAPS_STR ""
97 static GstStaticPadTemplate gst_msdkvpp_sink_factory =
98 GST_STATIC_PAD_TEMPLATE ("sink",
101 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (SUPPORTED_SYSTEM_FORMAT)
102 ", " "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
103 DMABUF_SINK_CAPS_STR));
105 static GstStaticPadTemplate gst_msdkvpp_src_factory =
106 GST_STATIC_PAD_TEMPLATE ("src",
109 GST_STATIC_CAPS (DMABUF_SRC_CAPS_STR
110 GST_VIDEO_CAPS_MAKE (SRC_SYSTEM_FORMAT) ", "
111 "interlace-mode = (string){ progressive, interleaved, mixed }" ";"));
119 #ifndef GST_REMOVE_DEPRECATED
122 PROP_DEINTERLACE_MODE,
123 PROP_DEINTERLACE_METHOD,
129 #ifndef GST_REMOVE_DEPRECATED
133 PROP_FORCE_ASPECT_RATIO,
135 PROP_VIDEO_DIRECTION,
143 #define PROP_HARDWARE_DEFAULT TRUE
144 #define PROP_ASYNC_DEPTH_DEFAULT 1
145 #define PROP_DENOISE_DEFAULT 0
146 #ifndef GST_REMOVE_DEPRECATED
147 #define PROP_ROTATION_DEFAULT MFX_ANGLE_0
148 #define PROP_MIRRORING_DEFAULT MFX_MIRRORING_DISABLED
150 #define PROP_DEINTERLACE_MODE_DEFAULT GST_MSDKVPP_DEINTERLACE_MODE_AUTO
151 #define PROP_DEINTERLACE_METHOD_DEFAULT MFX_DEINTERLACING_BOB
152 #define PROP_HUE_DEFAULT 0
153 #define PROP_SATURATION_DEFAULT 1
154 #define PROP_BRIGHTNESS_DEFAULT 0
155 #define PROP_CONTRAST_DEFAULT 1
156 #define PROP_DETAIL_DEFAULT 0
157 #define PROP_SCALING_MODE_DEFAULT MFX_SCALING_MODE_DEFAULT
158 #define PROP_FORCE_ASPECT_RATIO_DEFAULT TRUE
159 #define PROP_FRC_ALGORITHM_DEFAULT _MFX_FRC_ALGORITHM_NONE
160 #define PROP_VIDEO_DIRECTION_DEFAULT GST_VIDEO_ORIENTATION_IDENTITY
161 #define PROP_CROP_LEFT_DEFAULT 0
162 #define PROP_CROP_RIGHT_DEFAULT 0
163 #define PROP_CROP_TOP_DEFAULT 0
164 #define PROP_CROP_BOTTOM_DEFAULT 0
166 #define gst_msdkvpp_parent_class parent_class
167 G_DEFINE_TYPE (GstMsdkVPP, gst_msdkvpp, GST_TYPE_BASE_TRANSFORM);
171 mfxFrameSurface1 *surface;
176 free_msdk_surface (MsdkSurface * surface)
179 gst_buffer_unref (surface->buf);
180 g_slice_free (MsdkSurface, surface);
184 gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param)
186 if (thiz->num_extra_params < MAX_EXTRA_PARAMS) {
187 thiz->extra_params[thiz->num_extra_params] = param;
188 thiz->num_extra_params++;
193 ensure_context (GstBaseTransform * trans)
195 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
197 if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
198 GST_INFO_OBJECT (thiz, "Found context from neighbour %" GST_PTR_FORMAT,
201 /* Check GST_MSDK_JOB_VPP and GST_MSDK_JOB_ENCODER together to avoid sharing context
202 * between VPP and ENCODER
204 * gst-launch-1.0 videotestsrc ! msdkvpp ! video/x-raw,format=YUY2 ! msdkh264enc ! fakesink
206 if (gst_msdk_context_get_job_type (thiz->context) & (GST_MSDK_JOB_ENCODER |
208 GstMsdkContext *parent_context, *msdk_context;
210 parent_context = thiz->context;
211 msdk_context = gst_msdk_context_new_with_parent (parent_context);
214 GST_ERROR_OBJECT (thiz, "Context creation failed");
218 thiz->context = msdk_context;
219 gst_object_unref (parent_context);
221 GST_INFO_OBJECT (thiz,
222 "Creating new context %" GST_PTR_FORMAT " with joined session",
225 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
228 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
229 thiz->hardware, GST_MSDK_JOB_VPP))
231 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
235 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
241 create_output_buffer (GstMsdkVPP * thiz)
245 GstBufferPool *pool = thiz->srcpad_buffer_pool;
247 g_return_val_if_fail (pool != NULL, NULL);
249 if (!gst_buffer_pool_is_active (pool) &&
250 !gst_buffer_pool_set_active (pool, TRUE))
251 goto error_activate_pool;
254 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
255 if (ret != GST_FLOW_OK || !outbuf)
256 goto error_create_buffer;
263 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
268 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
274 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
275 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
277 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
279 if (gst_base_transform_is_passthrough (trans)) {
284 *outbuf_ptr = create_output_buffer (thiz);
285 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
288 static GstBufferPool *
289 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
290 GstCaps * caps, guint min_num_buffers)
292 GstBufferPool *pool = NULL;
293 GstStructure *config;
294 GstAllocator *allocator = NULL;
296 GstVideoInfo *pool_info = NULL;
297 GstVideoAlignment align;
298 GstAllocationParams params = { 0, 31, 0, 0, };
299 mfxFrameAllocResponse *alloc_resp = NULL;
300 gboolean use_dmabuf = FALSE;
302 if (direction == GST_PAD_SINK) {
303 alloc_resp = &thiz->in_alloc_resp;
304 pool_info = &thiz->sinkpad_buffer_pool_info;
305 use_dmabuf = thiz->use_sinkpad_dmabuf;
306 } else if (direction == GST_PAD_SRC) {
307 alloc_resp = &thiz->out_alloc_resp;
308 pool_info = &thiz->srcpad_buffer_pool_info;
309 use_dmabuf = thiz->use_srcpad_dmabuf;
312 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
316 if (!gst_video_info_from_caps (&info, caps))
317 goto error_no_video_info;
319 gst_msdk_set_video_alignment (&info, 0, 0, &align);
320 gst_video_info_align (&info, &align);
324 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
325 else if (thiz->use_video_memory)
326 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
328 allocator = gst_msdk_system_allocator_new (&info);
331 goto error_no_allocator;
333 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
334 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
337 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
338 gst_buffer_pool_config_add_option (config,
339 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
340 if (thiz->use_video_memory) {
341 gst_buffer_pool_config_add_option (config,
342 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
344 gst_buffer_pool_config_add_option (config,
345 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
348 gst_buffer_pool_config_set_video_alignment (config, &align);
349 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
350 gst_object_unref (allocator);
352 if (!gst_buffer_pool_set_config (pool, config))
353 goto error_pool_config;
355 /* Updating pool_info with algined info of allocator */
362 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
367 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
368 gst_object_unref (pool);
373 GST_INFO_OBJECT (thiz, "Failed to create allocator");
374 gst_object_unref (pool);
379 GST_INFO_OBJECT (thiz, "Failed to set config");
380 gst_object_unref (pool);
381 gst_object_unref (allocator);
387 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
391 for (i = 0; i < gst_caps_get_size (caps); i++) {
392 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
393 /* Skip ANY features, we need an exact match for correct evaluation */
394 if (gst_caps_features_is_any (features))
396 if (gst_caps_features_contains (features, feature))
403 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
405 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
407 GstBufferPool *pool = NULL;
408 GstStructure *config = NULL;
410 guint size = 0, min_buffers = 0, max_buffers = 0;
411 GstAllocator *allocator = NULL;
412 GstAllocationParams params;
413 gboolean update_pool = FALSE;
415 gst_query_parse_allocation (query, &caps, NULL);
417 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
420 if (!gst_video_info_from_caps (&info, caps)) {
421 GST_ERROR_OBJECT (thiz, "Failed to get video info");
424 /* if downstream allocation query supports dmabuf-capsfeatures,
425 * we do allocate dmabuf backed memory */
426 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
427 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
428 thiz->use_srcpad_dmabuf = TRUE;
431 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
432 thiz->add_video_meta = TRUE;
434 thiz->add_video_meta = FALSE;
436 /* Check whether the query has pool */
437 if (gst_query_get_n_allocation_pools (query) > 0)
440 /* increase the min_buffers with number of concurrent vpp operations */
441 min_buffers += thiz->async_depth;
443 /* invalidate the cached pool if there is an allocation_query */
444 if (thiz->srcpad_buffer_pool)
445 gst_object_unref (thiz->srcpad_buffer_pool);
447 /* Always create a pool for vpp out buffers. Each of the msdk element
448 * has to create it's own mfxsurfacepool which is an msdk contraint.
449 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
450 * Frame allocator for video-memory usage.So sharing the pool between
451 * gst-msdk elements might not be a good idea, rather each element
452 * can check the buffer type (whether it is from msdk-buffer pool)
453 * to make sure there is no copy. Since we share the context between
454 * msdk elements, using buffers from one sdk's framealloator in another
455 * sdk-components is perfectly fine */
456 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
457 thiz->srcpad_buffer_pool = pool;
459 /* get the configured pool properties inorder to set in query */
460 config = gst_buffer_pool_get_config (pool);
461 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
463 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
464 gst_query_add_allocation_param (query, allocator, ¶ms);
465 gst_structure_free (config);
468 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
471 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
473 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
475 /* Fixme if downstream doesn't have videometa support, msdkvpp should
476 * copy the output buffers */
482 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
483 GstQuery * decide_query, GstQuery * query)
485 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
487 GstBufferPool *pool = NULL;
488 GstAllocator *allocator = NULL;
490 GstStructure *config;
492 GstAllocationParams params;
494 guint min_buffers = thiz->async_depth + 1;
496 gst_query_parse_allocation (query, &caps, &need_pool);
498 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
502 if (!gst_video_info_from_caps (&info, caps)) {
503 GST_ERROR_OBJECT (thiz, "Failed to get video info");
507 /* if upstream allocation query supports dmabuf-capsfeatures,
508 * we do allocate dmabuf backed memory */
509 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
510 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
511 thiz->use_sinkpad_dmabuf = TRUE;
515 /* alwys provide a new pool for upstream to help re-negotiation
516 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
517 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
521 /* Update the internal pool if any allocation attribute changed */
522 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
523 gst_object_unref (thiz->sinkpad_buffer_pool);
524 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
525 GST_PAD_SINK, caps, min_buffers);
528 /* get the size and allocator params from configured pool and set it in query */
530 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
531 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
532 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
533 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
534 gst_query_add_allocation_param (query, allocator, ¶ms);
535 gst_structure_free (config);
537 /* if upstream does't have a pool requirement, set only
538 * size, min_buffers and max_buffers in query */
539 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
541 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
543 gst_object_unref (pool);
545 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
546 decide_query, query);
550 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
551 GstBufferPoolAcquireParams * params)
553 GstBuffer *new_buffer;
554 mfxFrameSurface1 *new_surface;
555 MsdkSurface *msdk_surface;
557 if (!gst_buffer_pool_is_active (pool) &&
558 !gst_buffer_pool_set_active (pool, TRUE)) {
559 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
563 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
564 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
568 if (gst_msdk_is_msdk_buffer (new_buffer))
569 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
571 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
575 msdk_surface = g_slice_new0 (MsdkSurface);
576 msdk_surface->surface = new_surface;
577 msdk_surface->buf = new_buffer;
584 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
585 MsdkSurface * msdk_surface)
587 GstMemory *mem = NULL;
590 GstMsdkMemoryID *msdk_mid = NULL;
591 mfxFrameSurface1 *mfx_surface = NULL;
594 mem = gst_buffer_peek_memory (buf, 0);
595 fd = gst_dmabuf_memory_get_fd (mem);
599 vinfo = thiz->sinkpad_info;
601 /* Update offset/stride/size if there is VideoMeta attached to
603 vmeta = gst_buffer_get_video_meta (buf);
605 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
606 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
607 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
608 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
609 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
610 "the negotiated width/height/format");
613 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
614 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
615 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
617 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
620 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
621 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
622 * Ideally, media-driver should accept what ever memory coming from other drivers
623 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
624 * For now, in order to avoid any crash we check the buffer size and fallback
625 * to copy frame method.
627 * See this: https://github.com/intel/media-driver/issues/169
629 if (GST_VIDEO_INFO_SIZE (&vinfo) <
630 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
633 mfx_surface = msdk_surface->surface;
634 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
636 /* release the internal memory storage of associated mfxSurface */
637 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
639 /* export dmabuf to vasurface */
640 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
649 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
651 GstVideoFrame src_frame, out_frame;
652 MsdkSurface *msdk_surface;
653 GstMemory *mem = NULL;
655 if (gst_msdk_is_msdk_buffer (inbuf)) {
656 msdk_surface = g_slice_new0 (MsdkSurface);
657 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
658 msdk_surface->buf = gst_buffer_ref (inbuf);
662 /* If upstream hasn't accpeted the proposed msdk bufferpool,
663 * just copy frame (if not dmabuf backed) to msdk buffer and
664 * take a surface from it. */
666 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
670 /************ dmabuf-import ************* */
671 /* if upstream provided a dmabuf backed memory, but not an msdk
672 * buffer, we could export the dmabuf to underlined vasurface */
673 mem = gst_buffer_peek_memory (inbuf, 0);
674 if (gst_is_dmabuf_memory (mem)) {
675 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
678 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
679 "to the msdk surface, fall back to the copy input frame method");
683 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
685 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
689 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
690 msdk_surface->buf, GST_MAP_WRITE)) {
691 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
692 gst_video_frame_unmap (&src_frame);
696 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
697 GST_ERROR_OBJECT (thiz, "failed to copy frame");
698 gst_video_frame_unmap (&out_frame);
699 gst_video_frame_unmap (&src_frame);
703 gst_video_frame_unmap (&out_frame);
704 gst_video_frame_unmap (&src_frame);
713 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
716 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
717 GstClockTime timestamp;
718 GstFlowReturn ret = GST_FLOW_OK;
720 mfxSyncPoint sync_point = NULL;
722 mfxFrameInfo *in_info = NULL;
723 MsdkSurface *in_surface = NULL;
724 MsdkSurface *out_surface = NULL;
726 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
728 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
730 return GST_FLOW_ERROR;
732 if (gst_msdk_is_msdk_buffer (outbuf)) {
733 out_surface = g_slice_new0 (MsdkSurface);
734 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
736 GST_ERROR ("Failed to get msdk outsurface!");
737 free_msdk_surface (in_surface);
738 return GST_FLOW_ERROR;
741 /* update surface crop info (NOTE: msdk min frame size is 2x2) */
742 in_info = &in_surface->surface->Info;
743 if ((thiz->crop_left + thiz->crop_right >= in_info->CropW - 1)
744 || (thiz->crop_top + thiz->crop_bottom >= in_info->CropH - 1)) {
745 GST_WARNING_OBJECT (thiz, "ignoring crop... cropping too much!");
747 in_info->CropX = thiz->crop_left;
748 in_info->CropY = thiz->crop_top;
749 in_info->CropW -= thiz->crop_left + thiz->crop_right;
750 in_info->CropH -= thiz->crop_top + thiz->crop_bottom;
753 session = gst_msdk_context_get_session (thiz->context);
755 /* outer loop is for handling FrameRate Control and deinterlace use cases */
759 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
760 out_surface->surface, NULL, &sync_point);
761 if (status != MFX_WRN_DEVICE_BUSY)
763 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
767 if (status == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM)
768 GST_WARNING_OBJECT (thiz, "VPP returned: %s",
769 msdk_status_to_string (status));
770 else if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
771 && status != MFX_ERR_MORE_SURFACE)
774 /* No output generated */
775 if (status == MFX_ERR_MORE_DATA)
776 goto error_more_data;
778 /* Wait for vpp operation to complete, the magic number 300000 below
779 * is used in MSDK samples
780 * #define MSDK_VPP_WAIT_INTERVAL 300000
783 MFXVideoCORE_SyncOperation (session, sync_point,
784 300000) != MFX_ERR_NONE)
785 GST_WARNING_OBJECT (thiz, "failed to do sync operation");
787 /* More than one output buffers are generated */
788 if (status == MFX_ERR_MORE_SURFACE) {
789 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
790 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
791 timestamp += thiz->buffer_duration;
792 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
793 if (ret != GST_FLOW_OK)
794 goto error_push_buffer;
795 outbuf = create_output_buffer (thiz);
797 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
798 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
800 } while (status == MFX_ERR_MORE_SURFACE);
805 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
806 ret = GST_FLOW_ERROR;
810 GST_WARNING_OBJECT (thiz,
811 "MSDK Requries additional input for processing, "
812 "Retruning FLOW_DROPPED since no output buffer was generated");
813 ret = GST_BASE_TRANSFORM_FLOW_DROPPED;
817 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
818 gst_flow_get_name (ret));
821 free_msdk_surface (in_surface);
822 free_msdk_surface (out_surface);
828 gst_msdkvpp_close (GstMsdkVPP * thiz)
835 if (thiz->use_video_memory) {
836 gst_msdk_frame_free (thiz->context, &thiz->in_alloc_resp);
837 gst_msdk_frame_free (thiz->context, &thiz->out_alloc_resp);
840 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
841 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
842 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
843 GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
844 msdk_status_to_string (status));
848 gst_object_replace ((GstObject **) & thiz->context, NULL);
850 memset (&thiz->param, 0, sizeof (thiz->param));
852 if (thiz->sinkpad_buffer_pool)
853 gst_object_unref (thiz->sinkpad_buffer_pool);
854 thiz->sinkpad_buffer_pool = NULL;
855 if (thiz->srcpad_buffer_pool)
856 gst_object_unref (thiz->srcpad_buffer_pool);
857 thiz->srcpad_buffer_pool = NULL;
859 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
860 gst_video_info_init (&thiz->sinkpad_info);
861 gst_video_info_init (&thiz->srcpad_info);
865 ensure_filters (GstMsdkVPP * thiz)
868 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
869 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
870 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
871 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
872 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
873 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
877 if (thiz->rotation != MFX_ANGLE_0) {
878 mfxExtVPPRotation *mfx_rotation = &thiz->mfx_rotation;
879 mfx_rotation->Header.BufferId = MFX_EXTBUFF_VPP_ROTATION;
880 mfx_rotation->Header.BufferSz = sizeof (mfxExtVPPRotation);
881 mfx_rotation->Angle = thiz->rotation;
882 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_rotation);
886 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
887 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
888 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
889 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
890 mfx_deinterlace->Mode = thiz->deinterlace_method;
891 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
894 /* Colorbalance(ProcAmp) */
895 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
896 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
897 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
898 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
899 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
900 mfx_procamp->Hue = thiz->hue;
901 mfx_procamp->Saturation = thiz->saturation;
902 mfx_procamp->Brightness = thiz->brightness;
903 mfx_procamp->Contrast = thiz->contrast;
904 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
907 /* Detail/Edge enhancement */
908 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
909 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
910 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
911 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
912 mfx_detail->DetailFactor = thiz->detail;
913 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
917 if (thiz->mirroring != MFX_MIRRORING_DISABLED) {
918 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
919 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
920 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
921 mfx_mirroring->Type = thiz->mirroring;
922 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
926 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
927 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
928 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
929 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
930 mfx_scaling->ScalingMode = thiz->scaling_mode;
931 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
935 if (thiz->flags & GST_MSDK_FLAG_FRC) {
936 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
937 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
938 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
939 mfx_frc->Algorithm = thiz->frc_algm;
940 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
945 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
947 gboolean passthrough = TRUE;
949 /* no passthrough if any of the filter algorithm is enabled */
953 /* vpp could be needed in some specific circumstances, for eg:
954 * input surface is dmabuf and output must be videomemory. So far
955 * the underline iHD driver doesn't seems to support dmabuf mapping,
956 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
957 * surfaces as output thourgh capsfileters */
961 /* no passthrough if there is change in out width,height or format */
962 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
963 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
964 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
965 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
966 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
967 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
970 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
974 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
978 mfxFrameAllocRequest request[2];
980 if (!thiz->context) {
981 GST_WARNING_OBJECT (thiz, "No MSDK Context");
985 GST_OBJECT_LOCK (thiz);
986 session = gst_msdk_context_get_session (thiz->context);
988 /* Close the current session if the session has been initialized,
989 * otherwise the subsequent function call of MFXVideoVPP_Init() will
992 if (thiz->initialized) {
993 if (thiz->use_video_memory) {
994 gst_msdk_frame_free (thiz->context, &thiz->in_alloc_resp);
995 gst_msdk_frame_free (thiz->context, &thiz->out_alloc_resp);
998 MFXVideoVPP_Close (session);
1001 if (thiz->use_video_memory) {
1002 gst_msdk_set_frame_allocator (thiz->context);
1003 thiz->param.IOPattern =
1004 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
1006 thiz->param.IOPattern =
1007 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
1010 /* update input video attributes */
1011 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
1012 &thiz->sinkpad_info);
1014 /* update output video attributes, only CSC and Scaling are supported for now */
1015 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
1016 &thiz->srcpad_info);
1018 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
1019 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
1020 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
1021 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
1022 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
1023 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
1024 thiz->flags |= GST_MSDK_FLAG_FRC;
1025 /* So far this is the only algorithm which is working somewhat good */
1026 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
1029 /* work-around to avoid zero fps in msdk structure */
1030 if (!thiz->param.vpp.In.FrameRateExtN)
1031 thiz->param.vpp.In.FrameRateExtN = 30;
1032 if (!thiz->param.vpp.Out.FrameRateExtN)
1033 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
1035 /* set vpp out picstruct as progressive if deinterlacing enabled */
1036 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
1037 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
1039 /* Enable the required filters */
1040 ensure_filters (thiz);
1042 /* Add exteneded buffers */
1043 if (thiz->num_extra_params) {
1044 thiz->param.NumExtParam = thiz->num_extra_params;
1045 thiz->param.ExtParam = thiz->extra_params;
1048 /* validate parameters and allow the Media SDK to make adjustments */
1049 status = MFXVideoVPP_Query (session, &thiz->param, &thiz->param);
1050 if (status < MFX_ERR_NONE) {
1051 GST_ERROR_OBJECT (thiz, "Video VPP Query failed (%s)",
1052 msdk_status_to_string (status));
1054 } else if (status > MFX_ERR_NONE) {
1055 GST_WARNING_OBJECT (thiz, "Video VPP Query returned: %s",
1056 msdk_status_to_string (status));
1059 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
1060 if (status < MFX_ERR_NONE) {
1061 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
1062 msdk_status_to_string (status));
1064 } else if (status > MFX_ERR_NONE) {
1065 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
1066 msdk_status_to_string (status));
1069 if (thiz->use_video_memory) {
1070 /* Input surface pool pre-allocation */
1071 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1072 if (thiz->use_sinkpad_dmabuf)
1073 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1074 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
1076 /* Output surface pool pre-allocation */
1077 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1078 if (thiz->use_srcpad_dmabuf)
1079 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1080 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
1083 thiz->in_num_surfaces = request[0].NumFrameSuggested;
1084 thiz->out_num_surfaces = request[1].NumFrameSuggested;
1087 status = MFXVideoVPP_Init (session, &thiz->param);
1088 if (status < MFX_ERR_NONE) {
1089 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
1091 } else if (status > MFX_ERR_NONE) {
1092 GST_WARNING_OBJECT (thiz, "Init returned: %s",
1093 msdk_status_to_string (status));
1096 thiz->initialized = TRUE;
1097 GST_OBJECT_UNLOCK (thiz);
1101 GST_OBJECT_UNLOCK (thiz);
1103 gst_object_replace ((GstObject **) & thiz->context, NULL);
1108 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1111 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1112 GstVideoInfo in_info, out_info;
1113 gboolean sinkpad_info_changed = FALSE;
1114 gboolean srcpad_info_changed = FALSE;
1115 gboolean deinterlace;
1117 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1120 gst_video_info_from_caps (&in_info, caps);
1121 gst_video_info_from_caps (&out_info, out_caps);
1123 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1124 sinkpad_info_changed = TRUE;
1125 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1126 srcpad_info_changed = TRUE;
1128 if (!sinkpad_info_changed && !srcpad_info_changed && thiz->initialized)
1131 thiz->sinkpad_info = in_info;
1132 thiz->srcpad_info = out_info;
1134 thiz->use_video_memory = TRUE;
1136 thiz->use_video_memory = FALSE;
1139 /* check for deinterlace requirement */
1140 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1142 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1144 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1145 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1146 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1148 if (!gst_msdkvpp_initialize (thiz))
1151 /* set passthrough according to filter operation change */
1152 gst_msdkvpp_set_passthrough (thiz);
1154 /* Ensure sinkpad buffer pool */
1155 if (thiz->sinkpad_buffer_pool)
1156 gst_object_unref (thiz->sinkpad_buffer_pool);
1158 thiz->sinkpad_buffer_pool =
1159 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1160 thiz->in_num_surfaces);
1161 if (!thiz->sinkpad_buffer_pool) {
1162 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1165 /* Ensure a srcpad buffer pool */
1166 if (thiz->srcpad_buffer_pool)
1167 gst_object_unref (thiz->srcpad_buffer_pool);
1169 thiz->srcpad_buffer_pool =
1170 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1171 thiz->out_num_surfaces);
1172 if (!thiz->srcpad_buffer_pool) {
1173 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1181 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1183 gboolean ret = FALSE;
1184 GstCaps *caps, *out_caps;
1186 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1188 if (direction == GST_PAD_SRC)
1189 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1191 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1193 /* make a copy of filter caps since we need to alter the structure
1194 * by adding dmabuf-capsfeatures */
1195 caps = gst_caps_copy (filter);
1196 gst_caps_set_features (caps, 0,
1197 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1199 out_caps = gst_pad_peer_query_caps (pad, caps);
1203 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1204 || out_caps == caps)
1207 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1211 gst_caps_unref (caps);
1213 gst_caps_unref (out_caps);
1218 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1219 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1221 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1222 GstCaps *result = NULL;
1223 gboolean *use_dmabuf;
1225 if (direction == GST_PAD_SRC) {
1226 result = gst_caps_fixate (result);
1227 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1230 * Override mirroring & rotation properties once video-direction
1233 if (thiz->flags & GST_MSDK_FLAG_VIDEO_DIRECTION)
1234 gst_msdk_get_mfx_video_orientation_from_video_direction
1235 (thiz->video_direction, &thiz->mirroring, &thiz->rotation);
1237 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1238 use_dmabuf = &thiz->use_srcpad_dmabuf;
1241 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1242 gst_caps_unref (othercaps);
1244 if (pad_can_dmabuf (thiz,
1245 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1246 gst_caps_set_features (result, 0,
1247 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1254 /* Generic code for now, requires changes in future when we
1255 * add hardware query for supported formats, Framerate control etc */
1257 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1258 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1262 GST_DEBUG_OBJECT (trans,
1263 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1264 (direction == GST_PAD_SINK) ? "sink" : "src");
1266 if (direction == GST_PAD_SRC)
1267 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1269 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1271 if (out_caps && filter) {
1272 GstCaps *intersection;
1274 intersection = gst_caps_intersect_full (out_caps, filter,
1275 GST_CAPS_INTERSECT_FIRST);
1276 gst_caps_unref (out_caps);
1277 out_caps = intersection;
1280 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1285 gst_msdkvpp_start (GstBaseTransform * trans)
1287 if (!ensure_context (trans))
1293 gst_msdkvpp_stop (GstBaseTransform * trans)
1295 gst_msdkvpp_close (GST_MSDKVPP (trans));
1300 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1301 const GValue * value, GParamSpec * pspec)
1303 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1307 thiz->hardware = g_value_get_boolean (value);
1309 case PROP_ASYNC_DEPTH:
1310 thiz->async_depth = g_value_get_uint (value);
1313 thiz->denoise_factor = g_value_get_uint (value);
1314 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1316 #ifndef GST_REMOVE_DEPRECATED
1318 thiz->rotation = g_value_get_enum (value);
1319 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1321 case PROP_MIRRORING:
1322 thiz->mirroring = g_value_get_enum (value);
1323 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1326 case PROP_DEINTERLACE_MODE:
1327 thiz->deinterlace_mode = g_value_get_enum (value);
1329 case PROP_DEINTERLACE_METHOD:
1330 thiz->deinterlace_method = g_value_get_enum (value);
1333 thiz->hue = g_value_get_float (value);
1334 thiz->flags |= GST_MSDK_FLAG_HUE;
1336 case PROP_SATURATION:
1337 thiz->saturation = g_value_get_float (value);
1338 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1340 case PROP_BRIGHTNESS:
1341 thiz->brightness = g_value_get_float (value);
1342 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1345 thiz->contrast = g_value_get_float (value);
1346 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1349 thiz->detail = g_value_get_uint (value);
1350 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1352 case PROP_SCALING_MODE:
1353 thiz->scaling_mode = g_value_get_enum (value);
1354 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1356 case PROP_FORCE_ASPECT_RATIO:
1357 thiz->keep_aspect = g_value_get_boolean (value);
1359 case PROP_FRC_ALGORITHM:
1360 thiz->frc_algm = g_value_get_enum (value);
1362 case PROP_VIDEO_DIRECTION:
1363 thiz->video_direction = g_value_get_enum (value);
1364 thiz->flags |= GST_MSDK_FLAG_VIDEO_DIRECTION;
1366 case PROP_CROP_LEFT:
1367 thiz->crop_left = g_value_get_uint (value);
1369 case PROP_CROP_RIGHT:
1370 thiz->crop_right = g_value_get_uint (value);
1373 thiz->crop_top = g_value_get_uint (value);
1375 case PROP_CROP_BOTTOM:
1376 thiz->crop_bottom = g_value_get_uint (value);
1379 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1385 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1386 GValue * value, GParamSpec * pspec)
1388 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1392 g_value_set_boolean (value, thiz->hardware);
1394 case PROP_ASYNC_DEPTH:
1395 g_value_set_uint (value, thiz->async_depth);
1398 g_value_set_uint (value, thiz->denoise_factor);
1400 #ifndef GST_REMOVE_DEPRECATED
1402 g_value_set_enum (value, thiz->rotation);
1404 case PROP_MIRRORING:
1405 g_value_set_enum (value, thiz->mirroring);
1408 case PROP_DEINTERLACE_MODE:
1409 g_value_set_enum (value, thiz->deinterlace_mode);
1411 case PROP_DEINTERLACE_METHOD:
1412 g_value_set_enum (value, thiz->deinterlace_method);
1415 g_value_set_float (value, thiz->hue);
1417 case PROP_SATURATION:
1418 g_value_set_float (value, thiz->saturation);
1420 case PROP_BRIGHTNESS:
1421 g_value_set_float (value, thiz->brightness);
1424 g_value_set_float (value, thiz->contrast);
1427 g_value_set_uint (value, thiz->detail);
1429 case PROP_SCALING_MODE:
1430 g_value_set_enum (value, thiz->scaling_mode);
1432 case PROP_FORCE_ASPECT_RATIO:
1433 g_value_set_boolean (value, thiz->keep_aspect);
1435 case PROP_FRC_ALGORITHM:
1436 g_value_set_enum (value, thiz->frc_algm);
1438 case PROP_VIDEO_DIRECTION:
1439 g_value_set_enum (value, thiz->video_direction);
1441 case PROP_CROP_LEFT:
1442 g_value_set_uint (value, thiz->crop_left);
1444 case PROP_CROP_RIGHT:
1445 g_value_set_uint (value, thiz->crop_right);
1448 g_value_set_uint (value, thiz->crop_top);
1450 case PROP_CROP_BOTTOM:
1451 g_value_set_uint (value, thiz->crop_bottom);
1454 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1460 gst_msdkvpp_finalize (GObject * object)
1462 G_OBJECT_CLASS (parent_class)->finalize (object);
1466 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1468 GstMsdkContext *msdk_context = NULL;
1469 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1471 if (gst_msdk_context_get_context (context, &msdk_context)) {
1472 gst_object_replace ((GstObject **) & thiz->context,
1473 (GstObject *) msdk_context);
1474 gst_object_unref (msdk_context);
1477 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1481 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1483 GObjectClass *gobject_class;
1484 GstElementClass *element_class;
1485 GstBaseTransformClass *trans_class;
1486 GParamSpec *obj_properties[PROP_N] = { NULL, };
1488 gobject_class = G_OBJECT_CLASS (klass);
1489 element_class = GST_ELEMENT_CLASS (klass);
1490 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1492 gobject_class->set_property = gst_msdkvpp_set_property;
1493 gobject_class->get_property = gst_msdkvpp_get_property;
1494 gobject_class->finalize = gst_msdkvpp_finalize;
1496 element_class->set_context = gst_msdkvpp_set_context;
1498 gst_element_class_add_static_pad_template (element_class,
1499 &gst_msdkvpp_src_factory);
1500 gst_element_class_add_static_pad_template (element_class,
1501 &gst_msdkvpp_sink_factory);
1503 gst_element_class_set_static_metadata (element_class,
1504 "MSDK Video Postprocessor",
1505 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1506 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1507 "A MediaSDK Video Postprocessing Filter",
1508 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1510 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1511 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1512 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1513 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1514 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1515 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1516 trans_class->propose_allocation =
1517 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1518 trans_class->decide_allocation =
1519 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1520 trans_class->prepare_output_buffer =
1521 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1523 obj_properties[PROP_HARDWARE] =
1524 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1525 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1527 obj_properties[PROP_ASYNC_DEPTH] =
1528 g_param_spec_uint ("async-depth", "Async Depth",
1529 "Depth of asynchronous pipeline",
1530 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1531 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1533 obj_properties[PROP_DENOISE] =
1534 g_param_spec_uint ("denoise", "Denoising factor",
1536 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1538 #ifndef GST_REMOVE_DEPRECATED
1539 obj_properties[PROP_ROTATION] =
1540 g_param_spec_enum ("rotation", "Rotation",
1541 "Rotation Angle (DEPRECATED, use video-direction instead)",
1542 gst_msdkvpp_rotation_get_type (), PROP_ROTATION_DEFAULT,
1543 G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1545 obj_properties[PROP_MIRRORING] =
1546 g_param_spec_enum ("mirroring", "Mirroring",
1547 "The Mirroring type (DEPRECATED, use video-direction instead)",
1548 gst_msdkvpp_mirroring_get_type (), PROP_MIRRORING_DEFAULT,
1549 G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1553 obj_properties[PROP_DEINTERLACE_MODE] =
1554 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1555 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1556 PROP_DEINTERLACE_MODE_DEFAULT,
1557 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1559 obj_properties[PROP_DEINTERLACE_METHOD] =
1560 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1561 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1562 PROP_DEINTERLACE_METHOD_DEFAULT,
1563 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1565 obj_properties[PROP_HUE] =
1566 g_param_spec_float ("hue", "Hue",
1567 "The hue of the video",
1568 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1570 obj_properties[PROP_SATURATION] =
1571 g_param_spec_float ("saturation", "Saturation",
1572 "The Saturation of the video",
1573 0, 10, PROP_SATURATION_DEFAULT,
1574 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1576 obj_properties[PROP_BRIGHTNESS] =
1577 g_param_spec_float ("brightness", "Brightness",
1578 "The Brightness of the video",
1579 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1580 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1582 obj_properties[PROP_CONTRAST] =
1583 g_param_spec_float ("contrast", "Contrast",
1584 "The Contrast of the video",
1585 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1587 obj_properties[PROP_DETAIL] =
1588 g_param_spec_uint ("detail", "Detail",
1589 "The factor of detail/edge enhancement filter algorithm",
1590 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1592 obj_properties[PROP_SCALING_MODE] =
1593 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1594 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1595 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1597 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1598 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1599 "When enabled, scaling will respect original aspect ratio",
1600 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1601 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1603 obj_properties[PROP_FRC_ALGORITHM] =
1604 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1605 "The Framerate Control Alogorithm to use",
1606 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1607 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1610 * The video-direction to use, expressed as an enum value. See
1611 * #GstVideoOrientationMethod.
1613 obj_properties[PROP_VIDEO_DIRECTION] = g_param_spec_enum ("video-direction",
1614 "Video Direction", "Video direction: rotation and flipping"
1615 #ifndef GST_REMOVE_DEPRECATED
1616 ", it will override both mirroring & rotation properties if set explicitly"
1619 GST_TYPE_VIDEO_ORIENTATION_METHOD,
1620 PROP_VIDEO_DIRECTION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1622 obj_properties[PROP_CROP_LEFT] = g_param_spec_uint ("crop-left",
1623 "Crop Left", "Pixels to crop at left",
1624 0, G_MAXUINT16, PROP_CROP_LEFT_DEFAULT,
1625 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1627 obj_properties[PROP_CROP_RIGHT] = g_param_spec_uint ("crop-right",
1628 "Crop Right", "Pixels to crop at right",
1629 0, G_MAXUINT16, PROP_CROP_RIGHT_DEFAULT,
1630 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1632 obj_properties[PROP_CROP_TOP] = g_param_spec_uint ("crop-top",
1633 "Crop Top", "Pixels to crop at top",
1634 0, G_MAXUINT16, PROP_CROP_TOP_DEFAULT,
1635 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1637 obj_properties[PROP_CROP_BOTTOM] = g_param_spec_uint ("crop-bottom",
1638 "Crop Bottom", "Pixels to crop at bottom",
1639 0, G_MAXUINT16, PROP_CROP_BOTTOM_DEFAULT,
1640 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1642 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1646 gst_msdkvpp_init (GstMsdkVPP * thiz)
1648 thiz->initialized = FALSE;
1649 thiz->hardware = PROP_HARDWARE_DEFAULT;
1650 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1651 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1652 #ifndef GST_REMOVE_DEPRECATED
1653 thiz->rotation = PROP_ROTATION_DEFAULT;
1654 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1656 thiz->rotation = MFX_ANGLE_0;
1657 thiz->mirroring = MFX_MIRRORING_DISABLED;
1659 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1660 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1661 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1662 thiz->hue = PROP_HUE_DEFAULT;
1663 thiz->saturation = PROP_SATURATION_DEFAULT;
1664 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1665 thiz->contrast = PROP_CONTRAST_DEFAULT;
1666 thiz->detail = PROP_DETAIL_DEFAULT;
1667 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1668 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1669 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1670 thiz->video_direction = PROP_VIDEO_DIRECTION_DEFAULT;
1671 thiz->crop_left = PROP_CROP_LEFT_DEFAULT;
1672 thiz->crop_right = PROP_CROP_RIGHT_DEFAULT;
1673 thiz->crop_top = PROP_CROP_TOP_DEFAULT;
1674 thiz->crop_bottom = PROP_CROP_BOTTOM_DEFAULT;
1676 gst_video_info_init (&thiz->sinkpad_info);
1677 gst_video_info_init (&thiz->srcpad_info);