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"
48 #include "gstmsdkallocator_libva.h"
51 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvpp_debug);
52 #define GST_CAT_DEFAULT gst_msdkvpp_debug
54 #if (MFX_VERSION >= 1028)
55 #define SUPPORTED_SYSTEM_FORMAT \
56 "{ NV12, YV12, I420, YUY2, UYVY, BGRA, BGRx, RGB16, P010_10LE }"
57 #define SUPPORTED_DMABUF_FORMAT \
58 "{ NV12, BGRA, YUY2, UYVY, RGB16, P010_10LE}"
60 #define SUPPORTED_SYSTEM_FORMAT \
61 "{ NV12, YV12, I420, YUY2, UYVY, BGRA, BGRx, P010_10LE }"
62 #define SUPPORTED_DMABUF_FORMAT \
63 "{ NV12, BGRA, YUY2, UYVY, P010_10LE}"
66 static GstStaticPadTemplate gst_msdkvpp_sink_factory =
67 GST_STATIC_PAD_TEMPLATE ("sink",
70 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (SUPPORTED_SYSTEM_FORMAT)
71 ", " "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
72 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
73 SUPPORTED_DMABUF_FORMAT)));
75 static GstStaticPadTemplate gst_msdkvpp_src_factory =
76 GST_STATIC_PAD_TEMPLATE ("src",
79 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
80 (GST_CAPS_FEATURE_MEMORY_DMABUF,
81 "{ BGRA, YUY2, UYVY, NV12, BGRx, P010_10LE}") ";"
82 GST_VIDEO_CAPS_MAKE ("{ BGRA, NV12, YUY2, UYVY, BGRx, P010_10LE }") ", "
83 "interlace-mode = (string){ progressive, interleaved, mixed }" ";"));
92 PROP_DEINTERLACE_MODE,
93 PROP_DEINTERLACE_METHOD,
101 PROP_FORCE_ASPECT_RATIO,
106 #define PROP_HARDWARE_DEFAULT TRUE
107 #define PROP_ASYNC_DEPTH_DEFAULT 1
108 #define PROP_DENOISE_DEFAULT 0
109 #define PROP_ROTATION_DEFAULT MFX_ANGLE_0
110 #define PROP_DEINTERLACE_MODE_DEFAULT GST_MSDKVPP_DEINTERLACE_MODE_AUTO
111 #define PROP_DEINTERLACE_METHOD_DEFAULT MFX_DEINTERLACING_BOB
112 #define PROP_HUE_DEFAULT 0
113 #define PROP_SATURATION_DEFAULT 1
114 #define PROP_BRIGHTNESS_DEFAULT 0
115 #define PROP_CONTRAST_DEFAULT 1
116 #define PROP_DETAIL_DEFAULT 0
117 #define PROP_MIRRORING_DEFAULT MFX_MIRRORING_DISABLED
118 #define PROP_SCALING_MODE_DEFAULT MFX_SCALING_MODE_DEFAULT
119 #define PROP_FORCE_ASPECT_RATIO_DEFAULT TRUE
120 #define PROP_FRC_ALGORITHM_DEFAULT _MFX_FRC_ALGORITHM_NONE
122 #define gst_msdkvpp_parent_class parent_class
123 G_DEFINE_TYPE (GstMsdkVPP, gst_msdkvpp, GST_TYPE_BASE_TRANSFORM);
127 mfxFrameSurface1 *surface;
132 free_msdk_surface (MsdkSurface * surface)
135 gst_buffer_unref (surface->buf);
136 g_slice_free (MsdkSurface, surface);
140 gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param)
142 if (thiz->num_extra_params < MAX_EXTRA_PARAMS) {
143 thiz->extra_params[thiz->num_extra_params] = param;
144 thiz->num_extra_params++;
149 ensure_context (GstBaseTransform * trans)
151 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
153 if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
154 GST_INFO_OBJECT (thiz, "Found context from neighbour %" GST_PTR_FORMAT,
157 if (gst_msdk_context_get_job_type (thiz->context) & GST_MSDK_JOB_VPP) {
158 GstMsdkContext *parent_context, *msdk_context;
160 parent_context = thiz->context;
161 msdk_context = gst_msdk_context_new_with_parent (parent_context);
164 GST_ERROR_OBJECT (thiz, "Context creation failed");
168 thiz->context = msdk_context;
169 gst_object_unref (parent_context);
171 GST_INFO_OBJECT (thiz,
172 "Creating new context %" GST_PTR_FORMAT " with joined session",
175 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
178 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
179 thiz->hardware, GST_MSDK_JOB_VPP))
181 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
185 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
191 create_output_buffer (GstMsdkVPP * thiz)
195 GstBufferPool *pool = thiz->srcpad_buffer_pool;
197 g_return_val_if_fail (pool != NULL, NULL);
199 if (!gst_buffer_pool_is_active (pool) &&
200 !gst_buffer_pool_set_active (pool, TRUE))
201 goto error_activate_pool;
204 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
205 if (ret != GST_FLOW_OK || !outbuf)
206 goto error_create_buffer;
213 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
218 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
224 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
225 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
227 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
229 if (gst_base_transform_is_passthrough (trans)) {
234 *outbuf_ptr = create_output_buffer (thiz);
235 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
238 static GstBufferPool *
239 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
240 GstCaps * caps, guint min_num_buffers)
242 GstBufferPool *pool = NULL;
243 GstStructure *config;
244 GstAllocator *allocator = NULL;
246 GstVideoInfo *pool_info = NULL;
247 GstVideoAlignment align;
248 GstAllocationParams params = { 0, 31, 0, 0, };
249 mfxFrameAllocResponse *alloc_resp = NULL;
250 gboolean use_dmabuf = FALSE;
252 if (direction == GST_PAD_SINK) {
253 alloc_resp = &thiz->in_alloc_resp;
254 pool_info = &thiz->sinkpad_buffer_pool_info;
255 use_dmabuf = thiz->use_sinkpad_dmabuf;
256 } else if (direction == GST_PAD_SRC) {
257 alloc_resp = &thiz->out_alloc_resp;
258 pool_info = &thiz->srcpad_buffer_pool_info;
259 use_dmabuf = thiz->use_srcpad_dmabuf;
262 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
266 if (!gst_video_info_from_caps (&info, caps))
267 goto error_no_video_info;
269 gst_msdk_set_video_alignment (&info, &align);
270 gst_video_info_align (&info, &align);
274 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
275 else if (thiz->use_video_memory)
276 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
278 allocator = gst_msdk_system_allocator_new (&info);
281 goto error_no_allocator;
283 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
284 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
287 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
288 gst_buffer_pool_config_add_option (config,
289 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
290 if (thiz->use_video_memory) {
291 gst_buffer_pool_config_add_option (config,
292 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
294 gst_buffer_pool_config_add_option (config,
295 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
298 gst_buffer_pool_config_set_video_alignment (config, &align);
299 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
300 gst_object_unref (allocator);
302 if (!gst_buffer_pool_set_config (pool, config))
303 goto error_pool_config;
305 /* Updating pool_info with algined info of allocator */
312 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
317 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
318 gst_object_unref (pool);
323 GST_INFO_OBJECT (thiz, "Failed to create allocator");
324 gst_object_unref (pool);
329 GST_INFO_OBJECT (thiz, "Failed to set config");
330 gst_object_unref (pool);
331 gst_object_unref (allocator);
337 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
341 for (i = 0; i < gst_caps_get_size (caps); i++) {
342 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
343 /* Skip ANY features, we need an exact match for correct evaluation */
344 if (gst_caps_features_is_any (features))
346 if (gst_caps_features_contains (features, feature))
353 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
355 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
357 GstBufferPool *pool = NULL;
358 GstStructure *config = NULL;
360 guint size = 0, min_buffers = 0, max_buffers = 0;
361 GstAllocator *allocator = NULL;
362 GstAllocationParams params;
363 gboolean update_pool = FALSE;
365 gst_query_parse_allocation (query, &caps, NULL);
367 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
370 if (!gst_video_info_from_caps (&info, caps)) {
371 GST_ERROR_OBJECT (thiz, "Failed to get video info");
374 /* if downstream allocation query supports dmabuf-capsfeatures,
375 * we do allocate dmabuf backed memory */
376 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
377 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
378 thiz->use_srcpad_dmabuf = TRUE;
381 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
382 thiz->add_video_meta = TRUE;
384 thiz->add_video_meta = FALSE;
386 /* Check whether the query has pool */
387 if (gst_query_get_n_allocation_pools (query) > 0)
390 /* increase the min_buffers with number of concurrent vpp operations */
391 min_buffers += thiz->async_depth;
393 /* invalidate the cached pool if there is an allocation_query */
394 if (thiz->srcpad_buffer_pool)
395 gst_object_unref (thiz->srcpad_buffer_pool);
397 /* Always create a pool for vpp out buffers. Each of the msdk element
398 * has to create it's own mfxsurfacepool which is an msdk contraint.
399 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
400 * Frame allocator for video-memory usage.So sharing the pool between
401 * gst-msdk elements might not be a good idea, rather each element
402 * can check the buffer type (whether it is from msdk-buffer pool)
403 * to make sure there is no copy. Since we share the context between
404 * msdk elements, using buffers from one sdk's framealloator in another
405 * sdk-components is perfectly fine */
406 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
407 thiz->srcpad_buffer_pool = pool;
409 /* get the configured pool properties inorder to set in query */
410 config = gst_buffer_pool_get_config (pool);
411 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
413 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
414 gst_query_add_allocation_param (query, allocator, ¶ms);
415 gst_structure_free (config);
418 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
421 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
423 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
425 /* Fixme if downstream doesn't have videometa support, msdkvpp should
426 * copy the output buffers */
432 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
433 GstQuery * decide_query, GstQuery * query)
435 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
437 GstBufferPool *pool = NULL;
438 GstAllocator *allocator = NULL;
440 GstStructure *config;
442 GstAllocationParams params;
444 guint min_buffers = thiz->async_depth + 1;
446 gst_query_parse_allocation (query, &caps, &need_pool);
448 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
452 if (!gst_video_info_from_caps (&info, caps)) {
453 GST_ERROR_OBJECT (thiz, "Failed to get video info");
457 /* if upstream allocation query supports dmabuf-capsfeatures,
458 * we do allocate dmabuf backed memory */
459 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
460 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
461 thiz->use_sinkpad_dmabuf = TRUE;
465 /* alwys provide a new pool for upstream to help re-negotiation
466 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
467 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
471 /* Update the internal pool if any allocation attribute changed */
472 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
473 gst_object_unref (thiz->sinkpad_buffer_pool);
474 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
475 GST_PAD_SINK, caps, min_buffers);
478 /* get the size and allocator params from configured pool and set it in query */
480 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
481 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
482 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
483 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
484 gst_query_add_allocation_param (query, allocator, ¶ms);
485 gst_structure_free (config);
487 /* if upstream does't have a pool requirement, set only
488 * size, min_buffers and max_buffers in query */
489 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
491 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
493 gst_object_unref (pool);
495 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
496 decide_query, query);
500 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
501 GstBufferPoolAcquireParams * params)
503 GstBuffer *new_buffer;
504 mfxFrameSurface1 *new_surface;
505 MsdkSurface *msdk_surface;
507 if (!gst_buffer_pool_is_active (pool) &&
508 !gst_buffer_pool_set_active (pool, TRUE)) {
509 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
513 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
514 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
518 if (gst_msdk_is_msdk_buffer (new_buffer))
519 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
521 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
525 msdk_surface = g_slice_new0 (MsdkSurface);
526 msdk_surface->surface = new_surface;
527 msdk_surface->buf = new_buffer;
534 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
535 MsdkSurface * msdk_surface)
537 GstMemory *mem = NULL;
540 GstMsdkMemoryID *msdk_mid = NULL;
541 mfxFrameSurface1 *mfx_surface = NULL;
544 mem = gst_buffer_peek_memory (buf, 0);
545 fd = gst_dmabuf_memory_get_fd (mem);
549 vinfo = thiz->sinkpad_info;
551 /* Update offset/stride/size if there is VideoMeta attached to
553 vmeta = gst_buffer_get_video_meta (buf);
555 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
556 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
557 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
558 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
559 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
560 "the negotiated width/height/format");
563 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
564 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
565 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
567 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
570 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
571 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
572 * Ideally, media-driver should accept what ever memory coming from other drivers
573 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
574 * For now, in order to avoid any crash we check the buffer size and fallback
575 * to copy frame method.
577 * See this: https://github.com/intel/media-driver/issues/169
579 if (GST_VIDEO_INFO_SIZE (&vinfo) <
580 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
583 mfx_surface = msdk_surface->surface;
584 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
586 /* release the internal memory storage of associated mfxSurface */
587 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
589 /* export dmabuf to vasurface */
590 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
599 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
601 GstVideoFrame src_frame, out_frame;
602 MsdkSurface *msdk_surface;
603 GstMemory *mem = NULL;
605 if (gst_msdk_is_msdk_buffer (inbuf)) {
606 msdk_surface = g_slice_new0 (MsdkSurface);
607 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
608 msdk_surface->buf = gst_buffer_ref (inbuf);
612 /* If upstream hasn't accpeted the proposed msdk bufferpool,
613 * just copy frame (if not dmabuf backed) to msdk buffer and
614 * take a surface from it. */
616 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
620 /************ dmabuf-import ************* */
621 /* if upstream provided a dmabuf backed memory, but not an msdk
622 * buffer, we could export the dmabuf to underlined vasurface */
623 mem = gst_buffer_peek_memory (inbuf, 0);
624 if (gst_is_dmabuf_memory (mem)) {
625 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
628 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
629 "to the msdk surface, fall back to the copy input frame method");
633 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
635 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
639 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
640 msdk_surface->buf, GST_MAP_WRITE)) {
641 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
642 gst_video_frame_unmap (&src_frame);
646 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
647 GST_ERROR_OBJECT (thiz, "failed to copy frame");
648 gst_video_frame_unmap (&out_frame);
649 gst_video_frame_unmap (&src_frame);
653 gst_video_frame_unmap (&out_frame);
654 gst_video_frame_unmap (&src_frame);
663 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
666 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
667 GstClockTime timestamp;
668 GstFlowReturn ret = GST_FLOW_OK;
670 mfxSyncPoint sync_point = NULL;
672 MsdkSurface *in_surface = NULL;
673 MsdkSurface *out_surface = NULL;
675 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
677 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
679 return GST_FLOW_ERROR;
681 if (gst_msdk_is_msdk_buffer (outbuf)) {
682 out_surface = g_slice_new0 (MsdkSurface);
683 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
685 GST_ERROR ("Failed to get msdk outsurface!");
686 return GST_FLOW_ERROR;
689 session = gst_msdk_context_get_session (thiz->context);
691 /* outer loop is for handling FrameRate Control and deinterlace use cases */
695 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
696 out_surface->surface, NULL, &sync_point);
697 if (status != MFX_WRN_DEVICE_BUSY)
699 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
703 if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
704 && status != MFX_ERR_MORE_SURFACE)
707 /* No output generated */
708 if (status == MFX_ERR_MORE_DATA)
709 goto error_more_data;
711 /* Wait for vpp operation to complete, the magic number 300000 below
712 * is used in MSDK samples
713 * #define MSDK_VPP_WAIT_INTERVAL 300000
716 MFXVideoCORE_SyncOperation (session, sync_point,
717 300000) != MFX_ERR_NONE)
718 GST_WARNING_OBJECT (thiz, "failed to do sync operation");
720 /* More than one output buffers are generated */
721 if (status == MFX_ERR_MORE_SURFACE) {
722 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
723 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
724 timestamp += thiz->buffer_duration;
725 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
726 if (ret != GST_FLOW_OK)
727 goto error_push_buffer;
728 outbuf = create_output_buffer (thiz);
730 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
731 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
733 } while (status == MFX_ERR_MORE_SURFACE);
735 free_msdk_surface (in_surface);
739 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
740 free_msdk_surface (in_surface);
741 free_msdk_surface (out_surface);
742 return GST_FLOW_ERROR;
745 GST_WARNING_OBJECT (thiz,
746 "MSDK Requries additional input for processing, "
747 "Retruning FLOW_DROPPED since no output buffer was generated");
748 free_msdk_surface (in_surface);
749 return GST_BASE_TRANSFORM_FLOW_DROPPED;
753 free_msdk_surface (in_surface);
754 free_msdk_surface (out_surface);
755 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
756 gst_flow_get_name (ret));
762 gst_msdkvpp_close (GstMsdkVPP * thiz)
769 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
770 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
771 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
772 GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
773 msdk_status_to_string (status));
777 gst_object_replace ((GstObject **) & thiz->context, NULL);
779 memset (&thiz->param, 0, sizeof (thiz->param));
781 if (thiz->sinkpad_buffer_pool)
782 gst_object_unref (thiz->sinkpad_buffer_pool);
783 thiz->sinkpad_buffer_pool = NULL;
784 if (thiz->srcpad_buffer_pool)
785 gst_object_unref (thiz->srcpad_buffer_pool);
786 thiz->srcpad_buffer_pool = NULL;
788 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
789 gst_video_info_init (&thiz->sinkpad_info);
790 gst_video_info_init (&thiz->srcpad_info);
794 ensure_filters (GstMsdkVPP * thiz)
798 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
799 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
800 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
801 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
802 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
803 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
807 if (thiz->flags & GST_MSDK_FLAG_ROTATION) {
808 mfxExtVPPRotation *mfx_rotation = &thiz->mfx_rotation;
809 mfx_rotation->Header.BufferId = MFX_EXTBUFF_VPP_ROTATION;
810 mfx_rotation->Header.BufferSz = sizeof (mfxExtVPPRotation);
811 mfx_rotation->Angle = thiz->rotation;
812 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_rotation);
816 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
817 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
818 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
819 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
820 mfx_deinterlace->Mode = thiz->deinterlace_method;
821 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
824 /* Colorbalance(ProcAmp) */
825 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
826 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
827 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
828 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
829 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
830 mfx_procamp->Hue = thiz->hue;
831 mfx_procamp->Saturation = thiz->saturation;
832 mfx_procamp->Brightness = thiz->brightness;
833 mfx_procamp->Contrast = thiz->contrast;
834 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
837 /* Detail/Edge enhancement */
838 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
839 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
840 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
841 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
842 mfx_detail->DetailFactor = thiz->detail;
843 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
847 if (thiz->flags & GST_MSDK_FLAG_MIRRORING) {
848 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
849 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
850 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
851 mfx_mirroring->Type = thiz->mirroring;
852 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
856 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
857 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
858 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
859 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
860 mfx_scaling->ScalingMode = thiz->scaling_mode;
861 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
865 if (thiz->flags & GST_MSDK_FLAG_FRC) {
866 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
867 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
868 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
869 mfx_frc->Algorithm = thiz->frc_algm;
870 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
875 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
877 gboolean passthrough = TRUE;
879 /* no passthrough if any of the filter algorithm is enabled */
883 /* vpp could be needed in some specific circumstances, for eg:
884 * input surface is dmabuf and output must be videomemory. So far
885 * the underline iHD driver doesn't seems to support dmabuf mapping,
886 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
887 * surfaces as output thourgh capsfileters */
891 /* no passthrough if there is change in out width,height or format */
892 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
893 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
894 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
895 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
896 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
897 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
900 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
904 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
908 mfxFrameAllocRequest request[2];
910 if (!thiz->context) {
911 GST_WARNING_OBJECT (thiz, "No MSDK Context");
915 GST_OBJECT_LOCK (thiz);
916 session = gst_msdk_context_get_session (thiz->context);
918 /* Close the current session if the session has been initialized,
919 * otherwise the subsequent function call of MFXVideoVPP_Init() will
922 if (thiz->initialized)
923 MFXVideoVPP_Close (session);
925 if (thiz->use_video_memory) {
926 gst_msdk_set_frame_allocator (thiz->context);
927 thiz->param.IOPattern =
928 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
930 thiz->param.IOPattern =
931 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
934 /* update input video attributes */
935 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
936 &thiz->sinkpad_info);
938 /* update output video attributes, only CSC and Scaling are supported for now */
939 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
942 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
943 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
944 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
945 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
946 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
947 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
948 thiz->flags |= GST_MSDK_FLAG_FRC;
949 /* So far this is the only algorithm which is working somewhat good */
950 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
953 /* work-around to avoid zero fps in msdk structure */
954 if (!thiz->param.vpp.In.FrameRateExtN)
955 thiz->param.vpp.In.FrameRateExtN = 30;
956 if (!thiz->param.vpp.Out.FrameRateExtN)
957 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
959 /* set vpp out picstruct as progressive if deinterlacing enabled */
960 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
961 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
963 /* Enable the required filters */
964 ensure_filters (thiz);
966 /* Add exteneded buffers */
967 if (thiz->num_extra_params) {
968 thiz->param.NumExtParam = thiz->num_extra_params;
969 thiz->param.ExtParam = thiz->extra_params;
972 /* validate parameters and allow the Media SDK to make adjustments */
973 status = MFXVideoVPP_Query (session, &thiz->param, &thiz->param);
974 if (status < MFX_ERR_NONE) {
975 GST_ERROR_OBJECT (thiz, "Video VPP Query failed (%s)",
976 msdk_status_to_string (status));
978 } else if (status > MFX_ERR_NONE) {
979 GST_WARNING_OBJECT (thiz, "Video VPP Query returned: %s",
980 msdk_status_to_string (status));
983 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
984 if (status < MFX_ERR_NONE) {
985 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
986 msdk_status_to_string (status));
988 } else if (status > MFX_ERR_NONE) {
989 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
990 msdk_status_to_string (status));
993 if (thiz->use_video_memory) {
994 /* Input surface pool pre-allocation */
995 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
996 if (thiz->use_sinkpad_dmabuf)
997 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
998 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
1000 /* Output surface pool pre-allocation */
1001 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1002 if (thiz->use_srcpad_dmabuf)
1003 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1004 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
1007 thiz->in_num_surfaces = request[0].NumFrameSuggested;
1008 thiz->out_num_surfaces = request[1].NumFrameSuggested;
1011 status = MFXVideoVPP_Init (session, &thiz->param);
1012 if (status < MFX_ERR_NONE) {
1013 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
1015 } else if (status > MFX_ERR_NONE) {
1016 GST_WARNING_OBJECT (thiz, "Init returned: %s",
1017 msdk_status_to_string (status));
1020 thiz->initialized = TRUE;
1021 GST_OBJECT_UNLOCK (thiz);
1025 GST_OBJECT_UNLOCK (thiz);
1027 gst_object_replace ((GstObject **) & thiz->context, NULL);
1032 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1035 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1036 GstVideoInfo in_info, out_info;
1037 gboolean sinkpad_info_changed = FALSE;
1038 gboolean srcpad_info_changed = FALSE;
1039 gboolean deinterlace;
1041 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1044 gst_video_info_from_caps (&in_info, caps);
1045 gst_video_info_from_caps (&out_info, out_caps);
1047 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1048 sinkpad_info_changed = TRUE;
1049 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1050 srcpad_info_changed = TRUE;
1052 if (!sinkpad_info_changed && !srcpad_info_changed && thiz->initialized)
1055 thiz->sinkpad_info = in_info;
1056 thiz->srcpad_info = out_info;
1058 thiz->use_video_memory = TRUE;
1060 thiz->use_video_memory = FALSE;
1063 /* check for deinterlace requirement */
1064 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1066 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1068 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1069 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1070 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1072 if (!gst_msdkvpp_initialize (thiz))
1075 /* set passthrough according to filter operation change */
1076 gst_msdkvpp_set_passthrough (thiz);
1078 /* Ensure sinkpad buffer pool */
1079 thiz->sinkpad_buffer_pool =
1080 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1081 thiz->in_num_surfaces);
1082 if (!thiz->sinkpad_buffer_pool) {
1083 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1086 /* Ensure a srcpad buffer pool */
1087 thiz->srcpad_buffer_pool =
1088 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1089 thiz->out_num_surfaces);
1090 if (!thiz->srcpad_buffer_pool) {
1091 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1099 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1101 gboolean ret = FALSE;
1102 GstCaps *caps, *out_caps;
1104 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1106 if (direction == GST_PAD_SRC)
1107 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1109 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1111 /* make a copy of filter caps since we need to alter the structure
1112 * by adding dmabuf-capsfeatures */
1113 caps = gst_caps_copy (filter);
1114 gst_caps_set_features (caps, 0,
1115 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1117 out_caps = gst_pad_peer_query_caps (pad, caps);
1121 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1122 || out_caps == caps)
1125 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1129 gst_caps_unref (caps);
1131 gst_caps_unref (out_caps);
1136 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1137 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1139 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1140 GstCaps *result = NULL;
1141 gboolean *use_dmabuf;
1143 if (direction == GST_PAD_SRC) {
1144 result = gst_caps_fixate (result);
1145 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1147 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1148 use_dmabuf = &thiz->use_srcpad_dmabuf;
1151 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1152 gst_caps_unref (othercaps);
1154 if (pad_can_dmabuf (thiz,
1155 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1156 gst_caps_set_features (result, 0,
1157 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1164 /* Generic code for now, requires changes in future when we
1165 * add hardware query for supported formats, Framerate control etc */
1167 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1168 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1172 GST_DEBUG_OBJECT (trans,
1173 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1174 (direction == GST_PAD_SINK) ? "sink" : "src");
1176 if (direction == GST_PAD_SRC)
1177 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1179 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1181 if (out_caps && filter) {
1182 GstCaps *intersection;
1184 intersection = gst_caps_intersect_full (out_caps, filter,
1185 GST_CAPS_INTERSECT_FIRST);
1186 gst_caps_unref (out_caps);
1187 out_caps = intersection;
1190 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1195 gst_msdkvpp_start (GstBaseTransform * trans)
1197 if (!ensure_context (trans))
1203 gst_msdkvpp_stop (GstBaseTransform * trans)
1205 gst_msdkvpp_close (GST_MSDKVPP (trans));
1210 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1211 const GValue * value, GParamSpec * pspec)
1213 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1217 thiz->hardware = g_value_get_boolean (value);
1219 case PROP_ASYNC_DEPTH:
1220 thiz->async_depth = g_value_get_uint (value);
1223 thiz->denoise_factor = g_value_get_uint (value);
1224 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1227 thiz->rotation = g_value_get_enum (value);
1228 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1230 case PROP_DEINTERLACE_MODE:
1231 thiz->deinterlace_mode = g_value_get_enum (value);
1233 case PROP_DEINTERLACE_METHOD:
1234 thiz->deinterlace_method = g_value_get_enum (value);
1237 thiz->hue = g_value_get_float (value);
1238 thiz->flags |= GST_MSDK_FLAG_HUE;
1240 case PROP_SATURATION:
1241 thiz->saturation = g_value_get_float (value);
1242 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1244 case PROP_BRIGHTNESS:
1245 thiz->brightness = g_value_get_float (value);
1246 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1249 thiz->contrast = g_value_get_float (value);
1250 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1253 thiz->detail = g_value_get_uint (value);
1254 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1256 case PROP_MIRRORING:
1257 thiz->mirroring = g_value_get_enum (value);
1258 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1260 case PROP_SCALING_MODE:
1261 thiz->scaling_mode = g_value_get_enum (value);
1262 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1264 case PROP_FORCE_ASPECT_RATIO:
1265 thiz->keep_aspect = g_value_get_boolean (value);
1267 case PROP_FRC_ALGORITHM:
1268 thiz->frc_algm = g_value_get_enum (value);
1271 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1277 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1278 GValue * value, GParamSpec * pspec)
1280 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1284 g_value_set_boolean (value, thiz->hardware);
1286 case PROP_ASYNC_DEPTH:
1287 g_value_set_uint (value, thiz->async_depth);
1290 g_value_set_uint (value, thiz->denoise_factor);
1293 g_value_set_enum (value, thiz->rotation);
1295 case PROP_DEINTERLACE_MODE:
1296 g_value_set_enum (value, thiz->deinterlace_mode);
1298 case PROP_DEINTERLACE_METHOD:
1299 g_value_set_enum (value, thiz->deinterlace_method);
1302 g_value_set_float (value, thiz->hue);
1304 case PROP_SATURATION:
1305 g_value_set_float (value, thiz->saturation);
1307 case PROP_BRIGHTNESS:
1308 g_value_set_float (value, thiz->brightness);
1311 g_value_set_float (value, thiz->contrast);
1314 g_value_set_uint (value, thiz->detail);
1316 case PROP_MIRRORING:
1317 g_value_set_enum (value, thiz->mirroring);
1319 case PROP_SCALING_MODE:
1320 g_value_set_enum (value, thiz->scaling_mode);
1322 case PROP_FORCE_ASPECT_RATIO:
1323 g_value_set_boolean (value, thiz->keep_aspect);
1325 case PROP_FRC_ALGORITHM:
1326 g_value_set_enum (value, thiz->frc_algm);
1329 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1335 gst_msdkvpp_finalize (GObject * object)
1337 G_OBJECT_CLASS (parent_class)->finalize (object);
1341 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1343 GstMsdkContext *msdk_context = NULL;
1344 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1346 if (gst_msdk_context_get_context (context, &msdk_context)) {
1347 gst_object_replace ((GstObject **) & thiz->context,
1348 (GstObject *) msdk_context);
1349 gst_object_unref (msdk_context);
1352 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1356 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1358 GObjectClass *gobject_class;
1359 GstElementClass *element_class;
1360 GstBaseTransformClass *trans_class;
1361 GParamSpec *obj_properties[PROP_N] = { NULL, };
1363 gobject_class = G_OBJECT_CLASS (klass);
1364 element_class = GST_ELEMENT_CLASS (klass);
1365 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1367 gobject_class->set_property = gst_msdkvpp_set_property;
1368 gobject_class->get_property = gst_msdkvpp_get_property;
1369 gobject_class->finalize = gst_msdkvpp_finalize;
1371 element_class->set_context = gst_msdkvpp_set_context;
1373 gst_element_class_add_static_pad_template (element_class,
1374 &gst_msdkvpp_src_factory);
1375 gst_element_class_add_static_pad_template (element_class,
1376 &gst_msdkvpp_sink_factory);
1378 gst_element_class_set_static_metadata (element_class,
1379 "MSDK Video Postprocessor",
1380 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1381 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1382 "A MediaSDK Video Postprocessing Filter",
1383 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1385 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1386 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1387 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1388 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1389 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1390 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1391 trans_class->propose_allocation =
1392 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1393 trans_class->decide_allocation =
1394 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1395 trans_class->prepare_output_buffer =
1396 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1398 obj_properties[PROP_HARDWARE] =
1399 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1400 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1402 obj_properties[PROP_ASYNC_DEPTH] =
1403 g_param_spec_uint ("async-depth", "Async Depth",
1404 "Depth of asynchronous pipeline",
1405 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1406 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1408 obj_properties[PROP_DENOISE] =
1409 g_param_spec_uint ("denoise", "Denoising factor",
1411 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1413 obj_properties[PROP_ROTATION] =
1414 g_param_spec_enum ("rotation", "Rotation",
1415 "Rotation Angle", gst_msdkvpp_rotation_get_type (),
1416 PROP_ROTATION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1418 obj_properties[PROP_DEINTERLACE_MODE] =
1419 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1420 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1421 PROP_DEINTERLACE_MODE_DEFAULT,
1422 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1424 obj_properties[PROP_DEINTERLACE_METHOD] =
1425 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1426 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1427 PROP_DEINTERLACE_METHOD_DEFAULT,
1428 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1430 obj_properties[PROP_HUE] =
1431 g_param_spec_float ("hue", "Hue",
1432 "The hue of the video",
1433 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1435 obj_properties[PROP_SATURATION] =
1436 g_param_spec_float ("saturation", "Saturation",
1437 "The Saturation of the video",
1438 0, 10, PROP_SATURATION_DEFAULT,
1439 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1441 obj_properties[PROP_BRIGHTNESS] =
1442 g_param_spec_float ("brightness", "Brightness",
1443 "The Brightness of the video",
1444 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1445 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1447 obj_properties[PROP_CONTRAST] =
1448 g_param_spec_float ("contrast", "Contrast",
1449 "The Contrast of the video",
1450 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1452 obj_properties[PROP_DETAIL] =
1453 g_param_spec_uint ("detail", "Detail",
1454 "The factor of detail/edge enhancement filter algorithm",
1455 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1457 obj_properties[PROP_MIRRORING] =
1458 g_param_spec_enum ("mirroring", "Mirroring",
1459 "The Mirroring type", gst_msdkvpp_mirroring_get_type (),
1460 PROP_MIRRORING_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1462 obj_properties[PROP_SCALING_MODE] =
1463 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1464 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1465 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1467 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1468 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1469 "When enabled, scaling will respect original aspect ratio",
1470 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1471 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1473 obj_properties[PROP_FRC_ALGORITHM] =
1474 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1475 "The Framerate Control Alogorithm to use",
1476 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1477 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1479 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1483 gst_msdkvpp_init (GstMsdkVPP * thiz)
1485 thiz->initialized = FALSE;
1486 thiz->hardware = PROP_HARDWARE_DEFAULT;
1487 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1488 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1489 thiz->rotation = PROP_ROTATION_DEFAULT;
1490 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1491 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1492 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1493 thiz->hue = PROP_HUE_DEFAULT;
1494 thiz->saturation = PROP_SATURATION_DEFAULT;
1495 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1496 thiz->contrast = PROP_CONTRAST_DEFAULT;
1497 thiz->detail = PROP_DETAIL_DEFAULT;
1498 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1499 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1500 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1501 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1502 gst_video_info_init (&thiz->sinkpad_info);
1503 gst_video_info_init (&thiz->srcpad_info);