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 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvpp_debug);
58 #define GST_CAT_DEFAULT gst_msdkvpp_debug
60 #if (MFX_VERSION >= 1028)
61 #define SUPPORTED_SYSTEM_FORMAT \
62 "{ NV12, YV12, I420, YUY2, UYVY, VUYA, BGRA, BGRx, RGB16, P010_10LE }"
63 #define SUPPORTED_DMABUF_FORMAT \
64 "{ NV12, BGRA, YUY2, UYVY, VUYA, RGB16, P010_10LE}"
66 #define SUPPORTED_SYSTEM_FORMAT \
67 "{ NV12, YV12, I420, YUY2, UYVY, VUYA, BGRA, BGRx, P010_10LE }"
68 #define SUPPORTED_DMABUF_FORMAT \
69 "{ NV12, BGRA, YUY2, UYVY, VUYA, P010_10LE}"
72 static GstStaticPadTemplate gst_msdkvpp_sink_factory =
73 GST_STATIC_PAD_TEMPLATE ("sink",
76 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (SUPPORTED_SYSTEM_FORMAT)
77 ", " "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
78 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
79 SUPPORTED_DMABUF_FORMAT)));
81 static GstStaticPadTemplate gst_msdkvpp_src_factory =
82 GST_STATIC_PAD_TEMPLATE ("src",
85 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
86 (GST_CAPS_FEATURE_MEMORY_DMABUF,
87 "{ BGRA, YUY2, UYVY, NV12, VUYA, BGRx, P010_10LE" EXT_FORMATS "}")
89 GST_VIDEO_CAPS_MAKE ("{ BGRA, NV12, YUY2, UYVY, VUYA, BGRx, P010_10LE"
91 "interlace-mode = (string){ progressive, interleaved, mixed }" ";"));
100 PROP_DEINTERLACE_MODE,
101 PROP_DEINTERLACE_METHOD,
109 PROP_FORCE_ASPECT_RATIO,
114 #define PROP_HARDWARE_DEFAULT TRUE
115 #define PROP_ASYNC_DEPTH_DEFAULT 1
116 #define PROP_DENOISE_DEFAULT 0
117 #define PROP_ROTATION_DEFAULT MFX_ANGLE_0
118 #define PROP_DEINTERLACE_MODE_DEFAULT GST_MSDKVPP_DEINTERLACE_MODE_AUTO
119 #define PROP_DEINTERLACE_METHOD_DEFAULT MFX_DEINTERLACING_BOB
120 #define PROP_HUE_DEFAULT 0
121 #define PROP_SATURATION_DEFAULT 1
122 #define PROP_BRIGHTNESS_DEFAULT 0
123 #define PROP_CONTRAST_DEFAULT 1
124 #define PROP_DETAIL_DEFAULT 0
125 #define PROP_MIRRORING_DEFAULT MFX_MIRRORING_DISABLED
126 #define PROP_SCALING_MODE_DEFAULT MFX_SCALING_MODE_DEFAULT
127 #define PROP_FORCE_ASPECT_RATIO_DEFAULT TRUE
128 #define PROP_FRC_ALGORITHM_DEFAULT _MFX_FRC_ALGORITHM_NONE
130 #define gst_msdkvpp_parent_class parent_class
131 G_DEFINE_TYPE (GstMsdkVPP, gst_msdkvpp, GST_TYPE_BASE_TRANSFORM);
135 mfxFrameSurface1 *surface;
140 free_msdk_surface (MsdkSurface * surface)
143 gst_buffer_unref (surface->buf);
144 g_slice_free (MsdkSurface, surface);
148 gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param)
150 if (thiz->num_extra_params < MAX_EXTRA_PARAMS) {
151 thiz->extra_params[thiz->num_extra_params] = param;
152 thiz->num_extra_params++;
157 ensure_context (GstBaseTransform * trans)
159 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
161 if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
162 GST_INFO_OBJECT (thiz, "Found context from neighbour %" GST_PTR_FORMAT,
165 /* Check GST_MSDK_JOB_VPP and GST_MSDK_JOB_ENCODER together to avoid sharing context
166 * between VPP and ENCODER
168 * gst-launch-1.0 videotestsrc ! msdkvpp ! video/x-raw,format=YUY2 ! msdkh264enc ! fakesink
170 if (gst_msdk_context_get_job_type (thiz->context) & (GST_MSDK_JOB_ENCODER |
172 GstMsdkContext *parent_context, *msdk_context;
174 parent_context = thiz->context;
175 msdk_context = gst_msdk_context_new_with_parent (parent_context);
178 GST_ERROR_OBJECT (thiz, "Context creation failed");
182 thiz->context = msdk_context;
183 gst_object_unref (parent_context);
185 GST_INFO_OBJECT (thiz,
186 "Creating new context %" GST_PTR_FORMAT " with joined session",
189 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
192 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
193 thiz->hardware, GST_MSDK_JOB_VPP))
195 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
199 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
205 create_output_buffer (GstMsdkVPP * thiz)
209 GstBufferPool *pool = thiz->srcpad_buffer_pool;
211 g_return_val_if_fail (pool != NULL, NULL);
213 if (!gst_buffer_pool_is_active (pool) &&
214 !gst_buffer_pool_set_active (pool, TRUE))
215 goto error_activate_pool;
218 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
219 if (ret != GST_FLOW_OK || !outbuf)
220 goto error_create_buffer;
227 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
232 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
238 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
239 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
241 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
243 if (gst_base_transform_is_passthrough (trans)) {
248 *outbuf_ptr = create_output_buffer (thiz);
249 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
252 static GstBufferPool *
253 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
254 GstCaps * caps, guint min_num_buffers)
256 GstBufferPool *pool = NULL;
257 GstStructure *config;
258 GstAllocator *allocator = NULL;
260 GstVideoInfo *pool_info = NULL;
261 GstVideoAlignment align;
262 GstAllocationParams params = { 0, 31, 0, 0, };
263 mfxFrameAllocResponse *alloc_resp = NULL;
264 gboolean use_dmabuf = FALSE;
266 if (direction == GST_PAD_SINK) {
267 alloc_resp = &thiz->in_alloc_resp;
268 pool_info = &thiz->sinkpad_buffer_pool_info;
269 use_dmabuf = thiz->use_sinkpad_dmabuf;
270 } else if (direction == GST_PAD_SRC) {
271 alloc_resp = &thiz->out_alloc_resp;
272 pool_info = &thiz->srcpad_buffer_pool_info;
273 use_dmabuf = thiz->use_srcpad_dmabuf;
276 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
280 if (!gst_video_info_from_caps (&info, caps))
281 goto error_no_video_info;
283 gst_msdk_set_video_alignment (&info, &align);
284 gst_video_info_align (&info, &align);
288 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
289 else if (thiz->use_video_memory)
290 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
292 allocator = gst_msdk_system_allocator_new (&info);
295 goto error_no_allocator;
297 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
298 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
301 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
302 gst_buffer_pool_config_add_option (config,
303 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
304 if (thiz->use_video_memory) {
305 gst_buffer_pool_config_add_option (config,
306 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
308 gst_buffer_pool_config_add_option (config,
309 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
312 gst_buffer_pool_config_set_video_alignment (config, &align);
313 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
314 gst_object_unref (allocator);
316 if (!gst_buffer_pool_set_config (pool, config))
317 goto error_pool_config;
319 /* Updating pool_info with algined info of allocator */
326 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
331 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
332 gst_object_unref (pool);
337 GST_INFO_OBJECT (thiz, "Failed to create allocator");
338 gst_object_unref (pool);
343 GST_INFO_OBJECT (thiz, "Failed to set config");
344 gst_object_unref (pool);
345 gst_object_unref (allocator);
351 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
355 for (i = 0; i < gst_caps_get_size (caps); i++) {
356 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
357 /* Skip ANY features, we need an exact match for correct evaluation */
358 if (gst_caps_features_is_any (features))
360 if (gst_caps_features_contains (features, feature))
367 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
369 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
371 GstBufferPool *pool = NULL;
372 GstStructure *config = NULL;
374 guint size = 0, min_buffers = 0, max_buffers = 0;
375 GstAllocator *allocator = NULL;
376 GstAllocationParams params;
377 gboolean update_pool = FALSE;
379 gst_query_parse_allocation (query, &caps, NULL);
381 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
384 if (!gst_video_info_from_caps (&info, caps)) {
385 GST_ERROR_OBJECT (thiz, "Failed to get video info");
388 /* if downstream allocation query supports dmabuf-capsfeatures,
389 * we do allocate dmabuf backed memory */
390 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
391 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
392 thiz->use_srcpad_dmabuf = TRUE;
395 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
396 thiz->add_video_meta = TRUE;
398 thiz->add_video_meta = FALSE;
400 /* Check whether the query has pool */
401 if (gst_query_get_n_allocation_pools (query) > 0)
404 /* increase the min_buffers with number of concurrent vpp operations */
405 min_buffers += thiz->async_depth;
407 /* invalidate the cached pool if there is an allocation_query */
408 if (thiz->srcpad_buffer_pool)
409 gst_object_unref (thiz->srcpad_buffer_pool);
411 /* Always create a pool for vpp out buffers. Each of the msdk element
412 * has to create it's own mfxsurfacepool which is an msdk contraint.
413 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
414 * Frame allocator for video-memory usage.So sharing the pool between
415 * gst-msdk elements might not be a good idea, rather each element
416 * can check the buffer type (whether it is from msdk-buffer pool)
417 * to make sure there is no copy. Since we share the context between
418 * msdk elements, using buffers from one sdk's framealloator in another
419 * sdk-components is perfectly fine */
420 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
421 thiz->srcpad_buffer_pool = pool;
423 /* get the configured pool properties inorder to set in query */
424 config = gst_buffer_pool_get_config (pool);
425 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
427 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
428 gst_query_add_allocation_param (query, allocator, ¶ms);
429 gst_structure_free (config);
432 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
435 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
437 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
439 /* Fixme if downstream doesn't have videometa support, msdkvpp should
440 * copy the output buffers */
446 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
447 GstQuery * decide_query, GstQuery * query)
449 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
451 GstBufferPool *pool = NULL;
452 GstAllocator *allocator = NULL;
454 GstStructure *config;
456 GstAllocationParams params;
458 guint min_buffers = thiz->async_depth + 1;
460 gst_query_parse_allocation (query, &caps, &need_pool);
462 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
466 if (!gst_video_info_from_caps (&info, caps)) {
467 GST_ERROR_OBJECT (thiz, "Failed to get video info");
471 /* if upstream allocation query supports dmabuf-capsfeatures,
472 * we do allocate dmabuf backed memory */
473 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
474 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
475 thiz->use_sinkpad_dmabuf = TRUE;
479 /* alwys provide a new pool for upstream to help re-negotiation
480 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
481 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
485 /* Update the internal pool if any allocation attribute changed */
486 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
487 gst_object_unref (thiz->sinkpad_buffer_pool);
488 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
489 GST_PAD_SINK, caps, min_buffers);
492 /* get the size and allocator params from configured pool and set it in query */
494 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
495 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
496 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
497 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
498 gst_query_add_allocation_param (query, allocator, ¶ms);
499 gst_structure_free (config);
501 /* if upstream does't have a pool requirement, set only
502 * size, min_buffers and max_buffers in query */
503 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
505 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
507 gst_object_unref (pool);
509 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
510 decide_query, query);
514 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
515 GstBufferPoolAcquireParams * params)
517 GstBuffer *new_buffer;
518 mfxFrameSurface1 *new_surface;
519 MsdkSurface *msdk_surface;
521 if (!gst_buffer_pool_is_active (pool) &&
522 !gst_buffer_pool_set_active (pool, TRUE)) {
523 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
527 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
528 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
532 if (gst_msdk_is_msdk_buffer (new_buffer))
533 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
535 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
539 msdk_surface = g_slice_new0 (MsdkSurface);
540 msdk_surface->surface = new_surface;
541 msdk_surface->buf = new_buffer;
548 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
549 MsdkSurface * msdk_surface)
551 GstMemory *mem = NULL;
554 GstMsdkMemoryID *msdk_mid = NULL;
555 mfxFrameSurface1 *mfx_surface = NULL;
558 mem = gst_buffer_peek_memory (buf, 0);
559 fd = gst_dmabuf_memory_get_fd (mem);
563 vinfo = thiz->sinkpad_info;
565 /* Update offset/stride/size if there is VideoMeta attached to
567 vmeta = gst_buffer_get_video_meta (buf);
569 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
570 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
571 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
572 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
573 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
574 "the negotiated width/height/format");
577 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
578 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
579 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
581 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
584 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
585 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
586 * Ideally, media-driver should accept what ever memory coming from other drivers
587 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
588 * For now, in order to avoid any crash we check the buffer size and fallback
589 * to copy frame method.
591 * See this: https://github.com/intel/media-driver/issues/169
593 if (GST_VIDEO_INFO_SIZE (&vinfo) <
594 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
597 mfx_surface = msdk_surface->surface;
598 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
600 /* release the internal memory storage of associated mfxSurface */
601 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
603 /* export dmabuf to vasurface */
604 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
613 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
615 GstVideoFrame src_frame, out_frame;
616 MsdkSurface *msdk_surface;
617 GstMemory *mem = NULL;
619 if (gst_msdk_is_msdk_buffer (inbuf)) {
620 msdk_surface = g_slice_new0 (MsdkSurface);
621 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
622 msdk_surface->buf = gst_buffer_ref (inbuf);
626 /* If upstream hasn't accpeted the proposed msdk bufferpool,
627 * just copy frame (if not dmabuf backed) to msdk buffer and
628 * take a surface from it. */
630 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
634 /************ dmabuf-import ************* */
635 /* if upstream provided a dmabuf backed memory, but not an msdk
636 * buffer, we could export the dmabuf to underlined vasurface */
637 mem = gst_buffer_peek_memory (inbuf, 0);
638 if (gst_is_dmabuf_memory (mem)) {
639 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
642 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
643 "to the msdk surface, fall back to the copy input frame method");
647 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
649 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
653 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
654 msdk_surface->buf, GST_MAP_WRITE)) {
655 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
656 gst_video_frame_unmap (&src_frame);
660 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
661 GST_ERROR_OBJECT (thiz, "failed to copy frame");
662 gst_video_frame_unmap (&out_frame);
663 gst_video_frame_unmap (&src_frame);
667 gst_video_frame_unmap (&out_frame);
668 gst_video_frame_unmap (&src_frame);
677 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
680 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
681 GstClockTime timestamp;
682 GstFlowReturn ret = GST_FLOW_OK;
684 mfxSyncPoint sync_point = NULL;
686 MsdkSurface *in_surface = NULL;
687 MsdkSurface *out_surface = NULL;
689 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
691 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
693 return GST_FLOW_ERROR;
695 if (gst_msdk_is_msdk_buffer (outbuf)) {
696 out_surface = g_slice_new0 (MsdkSurface);
697 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
699 GST_ERROR ("Failed to get msdk outsurface!");
700 return GST_FLOW_ERROR;
703 session = gst_msdk_context_get_session (thiz->context);
705 /* outer loop is for handling FrameRate Control and deinterlace use cases */
709 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
710 out_surface->surface, NULL, &sync_point);
711 if (status != MFX_WRN_DEVICE_BUSY)
713 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
717 if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
718 && status != MFX_ERR_MORE_SURFACE)
721 /* No output generated */
722 if (status == MFX_ERR_MORE_DATA)
723 goto error_more_data;
725 /* Wait for vpp operation to complete, the magic number 300000 below
726 * is used in MSDK samples
727 * #define MSDK_VPP_WAIT_INTERVAL 300000
730 MFXVideoCORE_SyncOperation (session, sync_point,
731 300000) != MFX_ERR_NONE)
732 GST_WARNING_OBJECT (thiz, "failed to do sync operation");
734 /* More than one output buffers are generated */
735 if (status == MFX_ERR_MORE_SURFACE) {
736 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
737 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
738 timestamp += thiz->buffer_duration;
739 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
740 if (ret != GST_FLOW_OK)
741 goto error_push_buffer;
742 outbuf = create_output_buffer (thiz);
744 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
745 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
747 } while (status == MFX_ERR_MORE_SURFACE);
749 free_msdk_surface (in_surface);
753 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
754 free_msdk_surface (in_surface);
755 free_msdk_surface (out_surface);
756 return GST_FLOW_ERROR;
759 GST_WARNING_OBJECT (thiz,
760 "MSDK Requries additional input for processing, "
761 "Retruning FLOW_DROPPED since no output buffer was generated");
762 free_msdk_surface (in_surface);
763 return GST_BASE_TRANSFORM_FLOW_DROPPED;
767 free_msdk_surface (in_surface);
768 free_msdk_surface (out_surface);
769 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
770 gst_flow_get_name (ret));
776 gst_msdkvpp_close (GstMsdkVPP * thiz)
783 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
784 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
785 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
786 GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
787 msdk_status_to_string (status));
791 gst_object_replace ((GstObject **) & thiz->context, NULL);
793 memset (&thiz->param, 0, sizeof (thiz->param));
795 if (thiz->sinkpad_buffer_pool)
796 gst_object_unref (thiz->sinkpad_buffer_pool);
797 thiz->sinkpad_buffer_pool = NULL;
798 if (thiz->srcpad_buffer_pool)
799 gst_object_unref (thiz->srcpad_buffer_pool);
800 thiz->srcpad_buffer_pool = NULL;
802 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
803 gst_video_info_init (&thiz->sinkpad_info);
804 gst_video_info_init (&thiz->srcpad_info);
808 ensure_filters (GstMsdkVPP * thiz)
812 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
813 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
814 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
815 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
816 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
817 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
821 if (thiz->flags & GST_MSDK_FLAG_ROTATION) {
822 mfxExtVPPRotation *mfx_rotation = &thiz->mfx_rotation;
823 mfx_rotation->Header.BufferId = MFX_EXTBUFF_VPP_ROTATION;
824 mfx_rotation->Header.BufferSz = sizeof (mfxExtVPPRotation);
825 mfx_rotation->Angle = thiz->rotation;
826 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_rotation);
830 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
831 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
832 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
833 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
834 mfx_deinterlace->Mode = thiz->deinterlace_method;
835 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
838 /* Colorbalance(ProcAmp) */
839 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
840 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
841 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
842 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
843 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
844 mfx_procamp->Hue = thiz->hue;
845 mfx_procamp->Saturation = thiz->saturation;
846 mfx_procamp->Brightness = thiz->brightness;
847 mfx_procamp->Contrast = thiz->contrast;
848 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
851 /* Detail/Edge enhancement */
852 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
853 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
854 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
855 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
856 mfx_detail->DetailFactor = thiz->detail;
857 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
861 if (thiz->flags & GST_MSDK_FLAG_MIRRORING) {
862 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
863 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
864 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
865 mfx_mirroring->Type = thiz->mirroring;
866 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
870 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
871 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
872 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
873 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
874 mfx_scaling->ScalingMode = thiz->scaling_mode;
875 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
879 if (thiz->flags & GST_MSDK_FLAG_FRC) {
880 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
881 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
882 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
883 mfx_frc->Algorithm = thiz->frc_algm;
884 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
889 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
891 gboolean passthrough = TRUE;
893 /* no passthrough if any of the filter algorithm is enabled */
897 /* vpp could be needed in some specific circumstances, for eg:
898 * input surface is dmabuf and output must be videomemory. So far
899 * the underline iHD driver doesn't seems to support dmabuf mapping,
900 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
901 * surfaces as output thourgh capsfileters */
905 /* no passthrough if there is change in out width,height or format */
906 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
907 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
908 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
909 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
910 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
911 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
914 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
918 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
922 mfxFrameAllocRequest request[2];
924 if (!thiz->context) {
925 GST_WARNING_OBJECT (thiz, "No MSDK Context");
929 GST_OBJECT_LOCK (thiz);
930 session = gst_msdk_context_get_session (thiz->context);
932 /* Close the current session if the session has been initialized,
933 * otherwise the subsequent function call of MFXVideoVPP_Init() will
936 if (thiz->initialized)
937 MFXVideoVPP_Close (session);
939 if (thiz->use_video_memory) {
940 gst_msdk_set_frame_allocator (thiz->context);
941 thiz->param.IOPattern =
942 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
944 thiz->param.IOPattern =
945 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
948 /* update input video attributes */
949 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
950 &thiz->sinkpad_info);
952 /* update output video attributes, only CSC and Scaling are supported for now */
953 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
956 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
957 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
958 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
959 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
960 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
961 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
962 thiz->flags |= GST_MSDK_FLAG_FRC;
963 /* So far this is the only algorithm which is working somewhat good */
964 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
967 /* work-around to avoid zero fps in msdk structure */
968 if (!thiz->param.vpp.In.FrameRateExtN)
969 thiz->param.vpp.In.FrameRateExtN = 30;
970 if (!thiz->param.vpp.Out.FrameRateExtN)
971 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
973 /* set vpp out picstruct as progressive if deinterlacing enabled */
974 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
975 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
977 /* Enable the required filters */
978 ensure_filters (thiz);
980 /* Add exteneded buffers */
981 if (thiz->num_extra_params) {
982 thiz->param.NumExtParam = thiz->num_extra_params;
983 thiz->param.ExtParam = thiz->extra_params;
986 /* validate parameters and allow the Media SDK to make adjustments */
987 status = MFXVideoVPP_Query (session, &thiz->param, &thiz->param);
988 if (status < MFX_ERR_NONE) {
989 GST_ERROR_OBJECT (thiz, "Video VPP Query failed (%s)",
990 msdk_status_to_string (status));
992 } else if (status > MFX_ERR_NONE) {
993 GST_WARNING_OBJECT (thiz, "Video VPP Query returned: %s",
994 msdk_status_to_string (status));
997 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
998 if (status < MFX_ERR_NONE) {
999 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
1000 msdk_status_to_string (status));
1002 } else if (status > MFX_ERR_NONE) {
1003 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
1004 msdk_status_to_string (status));
1007 if (thiz->use_video_memory) {
1008 /* Input surface pool pre-allocation */
1009 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1010 if (thiz->use_sinkpad_dmabuf)
1011 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1012 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
1014 /* Output surface pool pre-allocation */
1015 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1016 if (thiz->use_srcpad_dmabuf)
1017 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1018 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
1021 thiz->in_num_surfaces = request[0].NumFrameSuggested;
1022 thiz->out_num_surfaces = request[1].NumFrameSuggested;
1025 status = MFXVideoVPP_Init (session, &thiz->param);
1026 if (status < MFX_ERR_NONE) {
1027 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
1029 } else if (status > MFX_ERR_NONE) {
1030 GST_WARNING_OBJECT (thiz, "Init returned: %s",
1031 msdk_status_to_string (status));
1034 thiz->initialized = TRUE;
1035 GST_OBJECT_UNLOCK (thiz);
1039 GST_OBJECT_UNLOCK (thiz);
1041 gst_object_replace ((GstObject **) & thiz->context, NULL);
1046 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1049 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1050 GstVideoInfo in_info, out_info;
1051 gboolean sinkpad_info_changed = FALSE;
1052 gboolean srcpad_info_changed = FALSE;
1053 gboolean deinterlace;
1055 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1058 gst_video_info_from_caps (&in_info, caps);
1059 gst_video_info_from_caps (&out_info, out_caps);
1061 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1062 sinkpad_info_changed = TRUE;
1063 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1064 srcpad_info_changed = TRUE;
1066 if (!sinkpad_info_changed && !srcpad_info_changed && thiz->initialized)
1069 thiz->sinkpad_info = in_info;
1070 thiz->srcpad_info = out_info;
1072 thiz->use_video_memory = TRUE;
1074 thiz->use_video_memory = FALSE;
1077 /* check for deinterlace requirement */
1078 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1080 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1082 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1083 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1084 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1086 if (!gst_msdkvpp_initialize (thiz))
1089 /* set passthrough according to filter operation change */
1090 gst_msdkvpp_set_passthrough (thiz);
1092 /* Ensure sinkpad buffer pool */
1093 thiz->sinkpad_buffer_pool =
1094 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1095 thiz->in_num_surfaces);
1096 if (!thiz->sinkpad_buffer_pool) {
1097 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1100 /* Ensure a srcpad buffer pool */
1101 thiz->srcpad_buffer_pool =
1102 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1103 thiz->out_num_surfaces);
1104 if (!thiz->srcpad_buffer_pool) {
1105 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1113 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1115 gboolean ret = FALSE;
1116 GstCaps *caps, *out_caps;
1118 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1120 if (direction == GST_PAD_SRC)
1121 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1123 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1125 /* make a copy of filter caps since we need to alter the structure
1126 * by adding dmabuf-capsfeatures */
1127 caps = gst_caps_copy (filter);
1128 gst_caps_set_features (caps, 0,
1129 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1131 out_caps = gst_pad_peer_query_caps (pad, caps);
1135 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1136 || out_caps == caps)
1139 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1143 gst_caps_unref (caps);
1145 gst_caps_unref (out_caps);
1150 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1151 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1153 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1154 GstCaps *result = NULL;
1155 gboolean *use_dmabuf;
1157 if (direction == GST_PAD_SRC) {
1158 result = gst_caps_fixate (result);
1159 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1161 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1162 use_dmabuf = &thiz->use_srcpad_dmabuf;
1165 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1166 gst_caps_unref (othercaps);
1168 if (pad_can_dmabuf (thiz,
1169 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1170 gst_caps_set_features (result, 0,
1171 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1178 /* Generic code for now, requires changes in future when we
1179 * add hardware query for supported formats, Framerate control etc */
1181 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1182 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1186 GST_DEBUG_OBJECT (trans,
1187 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1188 (direction == GST_PAD_SINK) ? "sink" : "src");
1190 if (direction == GST_PAD_SRC)
1191 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1193 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1195 if (out_caps && filter) {
1196 GstCaps *intersection;
1198 intersection = gst_caps_intersect_full (out_caps, filter,
1199 GST_CAPS_INTERSECT_FIRST);
1200 gst_caps_unref (out_caps);
1201 out_caps = intersection;
1204 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1209 gst_msdkvpp_start (GstBaseTransform * trans)
1211 if (!ensure_context (trans))
1217 gst_msdkvpp_stop (GstBaseTransform * trans)
1219 gst_msdkvpp_close (GST_MSDKVPP (trans));
1224 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1225 const GValue * value, GParamSpec * pspec)
1227 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1231 thiz->hardware = g_value_get_boolean (value);
1233 case PROP_ASYNC_DEPTH:
1234 thiz->async_depth = g_value_get_uint (value);
1237 thiz->denoise_factor = g_value_get_uint (value);
1238 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1241 thiz->rotation = g_value_get_enum (value);
1242 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1244 case PROP_DEINTERLACE_MODE:
1245 thiz->deinterlace_mode = g_value_get_enum (value);
1247 case PROP_DEINTERLACE_METHOD:
1248 thiz->deinterlace_method = g_value_get_enum (value);
1251 thiz->hue = g_value_get_float (value);
1252 thiz->flags |= GST_MSDK_FLAG_HUE;
1254 case PROP_SATURATION:
1255 thiz->saturation = g_value_get_float (value);
1256 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1258 case PROP_BRIGHTNESS:
1259 thiz->brightness = g_value_get_float (value);
1260 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1263 thiz->contrast = g_value_get_float (value);
1264 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1267 thiz->detail = g_value_get_uint (value);
1268 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1270 case PROP_MIRRORING:
1271 thiz->mirroring = g_value_get_enum (value);
1272 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1274 case PROP_SCALING_MODE:
1275 thiz->scaling_mode = g_value_get_enum (value);
1276 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1278 case PROP_FORCE_ASPECT_RATIO:
1279 thiz->keep_aspect = g_value_get_boolean (value);
1281 case PROP_FRC_ALGORITHM:
1282 thiz->frc_algm = g_value_get_enum (value);
1285 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1291 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1292 GValue * value, GParamSpec * pspec)
1294 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1298 g_value_set_boolean (value, thiz->hardware);
1300 case PROP_ASYNC_DEPTH:
1301 g_value_set_uint (value, thiz->async_depth);
1304 g_value_set_uint (value, thiz->denoise_factor);
1307 g_value_set_enum (value, thiz->rotation);
1309 case PROP_DEINTERLACE_MODE:
1310 g_value_set_enum (value, thiz->deinterlace_mode);
1312 case PROP_DEINTERLACE_METHOD:
1313 g_value_set_enum (value, thiz->deinterlace_method);
1316 g_value_set_float (value, thiz->hue);
1318 case PROP_SATURATION:
1319 g_value_set_float (value, thiz->saturation);
1321 case PROP_BRIGHTNESS:
1322 g_value_set_float (value, thiz->brightness);
1325 g_value_set_float (value, thiz->contrast);
1328 g_value_set_uint (value, thiz->detail);
1330 case PROP_MIRRORING:
1331 g_value_set_enum (value, thiz->mirroring);
1333 case PROP_SCALING_MODE:
1334 g_value_set_enum (value, thiz->scaling_mode);
1336 case PROP_FORCE_ASPECT_RATIO:
1337 g_value_set_boolean (value, thiz->keep_aspect);
1339 case PROP_FRC_ALGORITHM:
1340 g_value_set_enum (value, thiz->frc_algm);
1343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1349 gst_msdkvpp_finalize (GObject * object)
1351 G_OBJECT_CLASS (parent_class)->finalize (object);
1355 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1357 GstMsdkContext *msdk_context = NULL;
1358 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1360 if (gst_msdk_context_get_context (context, &msdk_context)) {
1361 gst_object_replace ((GstObject **) & thiz->context,
1362 (GstObject *) msdk_context);
1363 gst_object_unref (msdk_context);
1366 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1370 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1372 GObjectClass *gobject_class;
1373 GstElementClass *element_class;
1374 GstBaseTransformClass *trans_class;
1375 GParamSpec *obj_properties[PROP_N] = { NULL, };
1377 gobject_class = G_OBJECT_CLASS (klass);
1378 element_class = GST_ELEMENT_CLASS (klass);
1379 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1381 gobject_class->set_property = gst_msdkvpp_set_property;
1382 gobject_class->get_property = gst_msdkvpp_get_property;
1383 gobject_class->finalize = gst_msdkvpp_finalize;
1385 element_class->set_context = gst_msdkvpp_set_context;
1387 gst_element_class_add_static_pad_template (element_class,
1388 &gst_msdkvpp_src_factory);
1389 gst_element_class_add_static_pad_template (element_class,
1390 &gst_msdkvpp_sink_factory);
1392 gst_element_class_set_static_metadata (element_class,
1393 "MSDK Video Postprocessor",
1394 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1395 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1396 "A MediaSDK Video Postprocessing Filter",
1397 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1399 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1400 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1401 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1402 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1403 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1404 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1405 trans_class->propose_allocation =
1406 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1407 trans_class->decide_allocation =
1408 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1409 trans_class->prepare_output_buffer =
1410 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1412 obj_properties[PROP_HARDWARE] =
1413 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1414 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1416 obj_properties[PROP_ASYNC_DEPTH] =
1417 g_param_spec_uint ("async-depth", "Async Depth",
1418 "Depth of asynchronous pipeline",
1419 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1420 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1422 obj_properties[PROP_DENOISE] =
1423 g_param_spec_uint ("denoise", "Denoising factor",
1425 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1427 obj_properties[PROP_ROTATION] =
1428 g_param_spec_enum ("rotation", "Rotation",
1429 "Rotation Angle", gst_msdkvpp_rotation_get_type (),
1430 PROP_ROTATION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1432 obj_properties[PROP_DEINTERLACE_MODE] =
1433 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1434 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1435 PROP_DEINTERLACE_MODE_DEFAULT,
1436 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1438 obj_properties[PROP_DEINTERLACE_METHOD] =
1439 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1440 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1441 PROP_DEINTERLACE_METHOD_DEFAULT,
1442 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1444 obj_properties[PROP_HUE] =
1445 g_param_spec_float ("hue", "Hue",
1446 "The hue of the video",
1447 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1449 obj_properties[PROP_SATURATION] =
1450 g_param_spec_float ("saturation", "Saturation",
1451 "The Saturation of the video",
1452 0, 10, PROP_SATURATION_DEFAULT,
1453 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1455 obj_properties[PROP_BRIGHTNESS] =
1456 g_param_spec_float ("brightness", "Brightness",
1457 "The Brightness of the video",
1458 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1459 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1461 obj_properties[PROP_CONTRAST] =
1462 g_param_spec_float ("contrast", "Contrast",
1463 "The Contrast of the video",
1464 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1466 obj_properties[PROP_DETAIL] =
1467 g_param_spec_uint ("detail", "Detail",
1468 "The factor of detail/edge enhancement filter algorithm",
1469 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1471 obj_properties[PROP_MIRRORING] =
1472 g_param_spec_enum ("mirroring", "Mirroring",
1473 "The Mirroring type", gst_msdkvpp_mirroring_get_type (),
1474 PROP_MIRRORING_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1476 obj_properties[PROP_SCALING_MODE] =
1477 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1478 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1479 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1481 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1482 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1483 "When enabled, scaling will respect original aspect ratio",
1484 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1485 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1487 obj_properties[PROP_FRC_ALGORITHM] =
1488 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1489 "The Framerate Control Alogorithm to use",
1490 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1491 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1493 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1497 gst_msdkvpp_init (GstMsdkVPP * thiz)
1499 thiz->initialized = FALSE;
1500 thiz->hardware = PROP_HARDWARE_DEFAULT;
1501 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1502 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1503 thiz->rotation = PROP_ROTATION_DEFAULT;
1504 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1505 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1506 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1507 thiz->hue = PROP_HUE_DEFAULT;
1508 thiz->saturation = PROP_SATURATION_DEFAULT;
1509 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1510 thiz->contrast = PROP_CONTRAST_DEFAULT;
1511 thiz->detail = PROP_DETAIL_DEFAULT;
1512 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1513 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1514 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1515 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1516 gst_video_info_init (&thiz->sinkpad_info);
1517 gst_video_info_init (&thiz->srcpad_info);