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 static GstStaticPadTemplate gst_msdkvpp_sink_factory =
55 GST_STATIC_PAD_TEMPLATE ("sink",
58 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
59 ("{ NV12, YV12, I420, YUY2, UYVY, BGRA, BGRx, P010_10LE }")
60 ", " "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
61 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
62 "{ NV12, BGRA, YUY2, P010_10LE}")));
64 static GstStaticPadTemplate gst_msdkvpp_src_factory =
65 GST_STATIC_PAD_TEMPLATE ("src",
68 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
69 (GST_CAPS_FEATURE_MEMORY_DMABUF,
70 "{ BGRA, YUY2, UYVY, NV12, BGRx, P010_10LE}") ";"
71 GST_VIDEO_CAPS_MAKE ("{ BGRA, NV12, YUY2, UYVY, BGRx, P010_10LE }") ", "
72 "interlace-mode = (string){ progressive, interleaved, mixed }" ";"));
81 PROP_DEINTERLACE_MODE,
82 PROP_DEINTERLACE_METHOD,
90 PROP_FORCE_ASPECT_RATIO,
95 #define PROP_HARDWARE_DEFAULT TRUE
96 #define PROP_ASYNC_DEPTH_DEFAULT 1
97 #define PROP_DENOISE_DEFAULT 0
98 #define PROP_ROTATION_DEFAULT MFX_ANGLE_0
99 #define PROP_DEINTERLACE_MODE_DEFAULT GST_MSDKVPP_DEINTERLACE_MODE_AUTO
100 #define PROP_DEINTERLACE_METHOD_DEFAULT MFX_DEINTERLACING_BOB
101 #define PROP_HUE_DEFAULT 0
102 #define PROP_SATURATION_DEFAULT 1
103 #define PROP_BRIGHTNESS_DEFAULT 0
104 #define PROP_CONTRAST_DEFAULT 1
105 #define PROP_DETAIL_DEFAULT 0
106 #define PROP_MIRRORING_DEFAULT MFX_MIRRORING_DISABLED
107 #define PROP_SCALING_MODE_DEFAULT MFX_SCALING_MODE_DEFAULT
108 #define PROP_FORCE_ASPECT_RATIO_DEFAULT TRUE
109 #define PROP_FRC_ALGORITHM_DEFAULT _MFX_FRC_ALGORITHM_NONE
111 #define gst_msdkvpp_parent_class parent_class
112 G_DEFINE_TYPE (GstMsdkVPP, gst_msdkvpp, GST_TYPE_BASE_TRANSFORM);
116 mfxFrameSurface1 *surface;
121 free_msdk_surface (MsdkSurface * surface)
124 gst_buffer_unref (surface->buf);
125 g_slice_free (MsdkSurface, surface);
129 gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param)
131 if (thiz->num_extra_params < MAX_EXTRA_PARAMS) {
132 thiz->extra_params[thiz->num_extra_params] = param;
133 thiz->num_extra_params++;
138 ensure_context (GstBaseTransform * trans)
140 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
142 if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
143 GST_INFO_OBJECT (thiz, "Found context from neighbour %" GST_PTR_FORMAT,
146 if (gst_msdk_context_get_job_type (thiz->context) & GST_MSDK_JOB_VPP) {
147 GstMsdkContext *parent_context, *msdk_context;
149 parent_context = thiz->context;
150 msdk_context = gst_msdk_context_new_with_parent (parent_context);
153 GST_ERROR_OBJECT (thiz, "Context creation failed");
157 thiz->context = msdk_context;
158 gst_object_unref (parent_context);
160 GST_INFO_OBJECT (thiz,
161 "Creating new context %" GST_PTR_FORMAT " with joined session",
164 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
167 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
168 thiz->hardware, GST_MSDK_JOB_VPP))
170 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
174 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
180 create_output_buffer (GstMsdkVPP * thiz)
184 GstBufferPool *pool = thiz->srcpad_buffer_pool;
186 g_return_val_if_fail (pool != NULL, NULL);
188 if (!gst_buffer_pool_is_active (pool) &&
189 !gst_buffer_pool_set_active (pool, TRUE))
190 goto error_activate_pool;
193 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
194 if (ret != GST_FLOW_OK || !outbuf)
195 goto error_create_buffer;
202 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
207 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
213 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
214 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
216 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
218 if (gst_base_transform_is_passthrough (trans)) {
223 *outbuf_ptr = create_output_buffer (thiz);
224 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
227 static GstBufferPool *
228 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
229 GstCaps * caps, guint min_num_buffers)
231 GstBufferPool *pool = NULL;
232 GstStructure *config;
233 GstAllocator *allocator = NULL;
235 GstVideoInfo *pool_info = NULL;
236 GstVideoAlignment align;
237 GstAllocationParams params = { 0, 31, 0, 0, };
238 mfxFrameAllocResponse *alloc_resp = NULL;
239 gboolean use_dmabuf = FALSE;
241 if (direction == GST_PAD_SINK) {
242 alloc_resp = &thiz->in_alloc_resp;
243 pool_info = &thiz->sinkpad_buffer_pool_info;
244 use_dmabuf = thiz->use_sinkpad_dmabuf;
245 } else if (direction == GST_PAD_SRC) {
246 alloc_resp = &thiz->out_alloc_resp;
247 pool_info = &thiz->srcpad_buffer_pool_info;
248 use_dmabuf = thiz->use_srcpad_dmabuf;
251 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
255 if (!gst_video_info_from_caps (&info, caps))
256 goto error_no_video_info;
258 gst_msdk_set_video_alignment (&info, &align);
259 gst_video_info_align (&info, &align);
263 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
264 else if (thiz->use_video_memory)
265 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
267 allocator = gst_msdk_system_allocator_new (&info);
270 goto error_no_allocator;
272 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
273 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
276 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
277 gst_buffer_pool_config_add_option (config,
278 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
279 if (thiz->use_video_memory) {
280 gst_buffer_pool_config_add_option (config,
281 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
283 gst_buffer_pool_config_add_option (config,
284 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
287 gst_buffer_pool_config_set_video_alignment (config, &align);
288 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
289 gst_object_unref (allocator);
291 if (!gst_buffer_pool_set_config (pool, config))
292 goto error_pool_config;
294 /* Updating pool_info with algined info of allocator */
301 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
306 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
307 gst_object_unref (pool);
312 GST_INFO_OBJECT (thiz, "Failed to create allocator");
313 gst_object_unref (pool);
318 GST_INFO_OBJECT (thiz, "Failed to set config");
319 gst_object_unref (pool);
320 gst_object_unref (allocator);
326 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
330 for (i = 0; i < gst_caps_get_size (caps); i++) {
331 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
332 /* Skip ANY features, we need an exact match for correct evaluation */
333 if (gst_caps_features_is_any (features))
335 if (gst_caps_features_contains (features, feature))
342 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
344 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
346 GstBufferPool *pool = NULL;
347 GstStructure *config = NULL;
349 guint size = 0, min_buffers = 0, max_buffers = 0;
350 GstAllocator *allocator = NULL;
351 GstAllocationParams params;
352 gboolean update_pool = FALSE;
354 gst_query_parse_allocation (query, &caps, NULL);
356 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
359 if (!gst_video_info_from_caps (&info, caps)) {
360 GST_ERROR_OBJECT (thiz, "Failed to get video info");
363 /* if downstream allocation query supports dmabuf-capsfeatures,
364 * we do allocate dmabuf backed memory */
365 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
366 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
367 thiz->use_srcpad_dmabuf = TRUE;
370 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
371 thiz->add_video_meta = TRUE;
373 thiz->add_video_meta = FALSE;
375 /* Check whether the query has pool */
376 if (gst_query_get_n_allocation_pools (query) > 0)
379 /* increase the min_buffers with number of concurrent vpp operations */
380 min_buffers += thiz->async_depth;
382 /* invalidate the cached pool if there is an allocation_query */
383 if (thiz->srcpad_buffer_pool)
384 gst_object_unref (thiz->srcpad_buffer_pool);
386 /* Always create a pool for vpp out buffers. Each of the msdk element
387 * has to create it's own mfxsurfacepool which is an msdk contraint.
388 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
389 * Frame allocator for video-memory usage.So sharing the pool between
390 * gst-msdk elements might not be a good idea, rather each element
391 * can check the buffer type (whether it is from msdk-buffer pool)
392 * to make sure there is no copy. Since we share the context between
393 * msdk elements, using buffers from one sdk's framealloator in another
394 * sdk-components is perfectly fine */
395 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
396 thiz->srcpad_buffer_pool = pool;
398 /* get the configured pool properties inorder to set in query */
399 config = gst_buffer_pool_get_config (pool);
400 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
402 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
403 gst_query_add_allocation_param (query, allocator, ¶ms);
404 gst_structure_free (config);
407 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
410 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
412 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
414 /* Fixme if downstream doesn't have videometa support, msdkvpp should
415 * copy the output buffers */
421 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
422 GstQuery * decide_query, GstQuery * query)
424 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
426 GstBufferPool *pool = NULL;
427 GstAllocator *allocator = NULL;
429 GstStructure *config;
431 GstAllocationParams params;
433 guint min_buffers = thiz->async_depth + 1;
435 gst_query_parse_allocation (query, &caps, &need_pool);
437 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
441 if (!gst_video_info_from_caps (&info, caps)) {
442 GST_ERROR_OBJECT (thiz, "Failed to get video info");
446 /* if upstream allocation query supports dmabuf-capsfeatures,
447 * we do allocate dmabuf backed memory */
448 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
449 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
450 thiz->use_sinkpad_dmabuf = TRUE;
454 /* alwys provide a new pool for upstream to help re-negotiation
455 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
456 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
460 /* Update the internal pool if any allocation attribute changed */
461 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
462 gst_object_unref (thiz->sinkpad_buffer_pool);
463 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
464 GST_PAD_SINK, caps, min_buffers);
467 /* get the size and allocator params from configured pool and set it in query */
469 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
470 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
471 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
472 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
473 gst_query_add_allocation_param (query, allocator, ¶ms);
474 gst_structure_free (config);
476 /* if upstream does't have a pool requirement, set only
477 * size, min_buffers and max_buffers in query */
478 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
480 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
482 gst_object_unref (pool);
484 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
485 decide_query, query);
489 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
490 GstBufferPoolAcquireParams * params)
492 GstBuffer *new_buffer;
493 mfxFrameSurface1 *new_surface;
494 MsdkSurface *msdk_surface;
496 if (!gst_buffer_pool_is_active (pool) &&
497 !gst_buffer_pool_set_active (pool, TRUE)) {
498 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
502 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
503 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
507 if (gst_msdk_is_msdk_buffer (new_buffer))
508 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
510 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
514 msdk_surface = g_slice_new0 (MsdkSurface);
515 msdk_surface->surface = new_surface;
516 msdk_surface->buf = new_buffer;
523 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
524 MsdkSurface * msdk_surface)
526 GstMemory *mem = NULL;
529 GstMsdkMemoryID *msdk_mid = NULL;
530 mfxFrameSurface1 *mfx_surface = NULL;
533 mem = gst_buffer_peek_memory (buf, 0);
534 fd = gst_dmabuf_memory_get_fd (mem);
538 vinfo = thiz->sinkpad_info;
540 /* Update offset/stride/size if there is VideoMeta attached to
542 vmeta = gst_buffer_get_video_meta (buf);
544 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
545 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
546 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
547 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
548 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
549 "the negotiated width/height/format");
552 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
553 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
554 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
556 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
559 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
560 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
561 * Ideally, media-driver should accept what ever memory coming from other drivers
562 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
563 * For now, in order to avoid any crash we check the buffer size and fallback
564 * to copy frame method.
566 * See this: https://github.com/intel/media-driver/issues/169
568 if (GST_VIDEO_INFO_SIZE (&vinfo) <
569 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
572 mfx_surface = msdk_surface->surface;
573 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
575 /* release the internal memory storage of associated mfxSurface */
576 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
578 /* export dmabuf to vasurface */
579 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
588 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
590 GstVideoFrame src_frame, out_frame;
591 MsdkSurface *msdk_surface;
592 GstMemory *mem = NULL;
594 if (gst_msdk_is_msdk_buffer (inbuf)) {
595 msdk_surface = g_slice_new0 (MsdkSurface);
596 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
597 msdk_surface->buf = gst_buffer_ref (inbuf);
601 /* If upstream hasn't accpeted the proposed msdk bufferpool,
602 * just copy frame (if not dmabuf backed) to msdk buffer and
603 * take a surface from it. */
605 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
609 /************ dmabuf-import ************* */
610 /* if upstream provided a dmabuf backed memory, but not an msdk
611 * buffer, we could export the dmabuf to underlined vasurface */
612 mem = gst_buffer_peek_memory (inbuf, 0);
613 if (gst_is_dmabuf_memory (mem)) {
614 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
617 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
618 "to the msdk surface, fall back to the copy input frame method");
622 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
624 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
628 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
629 msdk_surface->buf, GST_MAP_WRITE)) {
630 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
631 gst_video_frame_unmap (&src_frame);
635 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
636 GST_ERROR_OBJECT (thiz, "failed to copy frame");
637 gst_video_frame_unmap (&out_frame);
638 gst_video_frame_unmap (&src_frame);
642 gst_video_frame_unmap (&out_frame);
643 gst_video_frame_unmap (&src_frame);
652 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
655 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
656 GstClockTime timestamp;
657 GstFlowReturn ret = GST_FLOW_OK;
659 mfxSyncPoint sync_point = NULL;
661 MsdkSurface *in_surface = NULL;
662 MsdkSurface *out_surface = NULL;
664 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
666 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
668 return GST_FLOW_ERROR;
670 if (gst_msdk_is_msdk_buffer (outbuf)) {
671 out_surface = g_slice_new0 (MsdkSurface);
672 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
674 GST_ERROR ("Failed to get msdk outsurface!");
675 return GST_FLOW_ERROR;
678 session = gst_msdk_context_get_session (thiz->context);
680 /* outer loop is for handling FrameRate Control and deinterlace use cases */
684 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
685 out_surface->surface, NULL, &sync_point);
686 if (status != MFX_WRN_DEVICE_BUSY)
688 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
692 if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
693 && status != MFX_ERR_MORE_SURFACE)
696 /* No output generated */
697 if (status == MFX_ERR_MORE_DATA)
698 goto error_more_data;
700 /* Wait for vpp operation to complete, the magic number 300000 below
701 * is used in MSDK samples
702 * #define MSDK_VPP_WAIT_INTERVAL 300000
705 MFXVideoCORE_SyncOperation (session, sync_point,
706 300000) != MFX_ERR_NONE)
707 GST_WARNING_OBJECT (thiz, "failed to do sync operation");
709 /* More than one output buffers are generated */
710 if (status == MFX_ERR_MORE_SURFACE) {
711 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
712 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
713 timestamp += thiz->buffer_duration;
714 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
715 if (ret != GST_FLOW_OK)
716 goto error_push_buffer;
717 outbuf = create_output_buffer (thiz);
719 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
720 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
722 } while (status == MFX_ERR_MORE_SURFACE);
724 free_msdk_surface (in_surface);
728 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
729 free_msdk_surface (in_surface);
730 free_msdk_surface (out_surface);
731 return GST_FLOW_ERROR;
734 GST_WARNING_OBJECT (thiz,
735 "MSDK Requries additional input for processing, "
736 "Retruning FLOW_DROPPED since no output buffer was generated");
737 free_msdk_surface (in_surface);
738 return GST_BASE_TRANSFORM_FLOW_DROPPED;
742 free_msdk_surface (in_surface);
743 free_msdk_surface (out_surface);
744 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
745 gst_flow_get_name (ret));
751 gst_msdkvpp_close (GstMsdkVPP * thiz)
758 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
759 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
760 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
761 GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
762 msdk_status_to_string (status));
766 gst_object_replace ((GstObject **) & thiz->context, NULL);
768 memset (&thiz->param, 0, sizeof (thiz->param));
770 if (thiz->sinkpad_buffer_pool)
771 gst_object_unref (thiz->sinkpad_buffer_pool);
772 thiz->sinkpad_buffer_pool = NULL;
773 if (thiz->srcpad_buffer_pool)
774 gst_object_unref (thiz->srcpad_buffer_pool);
775 thiz->srcpad_buffer_pool = NULL;
777 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
778 gst_video_info_init (&thiz->sinkpad_info);
779 gst_video_info_init (&thiz->srcpad_info);
783 ensure_filters (GstMsdkVPP * thiz)
787 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
788 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
789 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
790 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
791 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
792 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
796 if (thiz->flags & GST_MSDK_FLAG_ROTATION) {
797 mfxExtVPPRotation *mfx_rotation = &thiz->mfx_rotation;
798 mfx_rotation->Header.BufferId = MFX_EXTBUFF_VPP_ROTATION;
799 mfx_rotation->Header.BufferSz = sizeof (mfxExtVPPRotation);
800 mfx_rotation->Angle = thiz->rotation;
801 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_rotation);
805 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
806 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
807 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
808 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
809 mfx_deinterlace->Mode = thiz->deinterlace_method;
810 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
813 /* Colorbalance(ProcAmp) */
814 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
815 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
816 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
817 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
818 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
819 mfx_procamp->Hue = thiz->hue;
820 mfx_procamp->Saturation = thiz->saturation;
821 mfx_procamp->Brightness = thiz->brightness;
822 mfx_procamp->Contrast = thiz->contrast;
823 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
826 /* Detail/Edge enhancement */
827 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
828 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
829 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
830 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
831 mfx_detail->DetailFactor = thiz->detail;
832 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
836 if (thiz->flags & GST_MSDK_FLAG_MIRRORING) {
837 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
838 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
839 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
840 mfx_mirroring->Type = thiz->mirroring;
841 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
845 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
846 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
847 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
848 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
849 mfx_scaling->ScalingMode = thiz->scaling_mode;
850 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
854 if (thiz->flags & GST_MSDK_FLAG_FRC) {
855 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
856 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
857 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
858 mfx_frc->Algorithm = thiz->frc_algm;
859 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
864 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
866 gboolean passthrough = TRUE;
868 /* no passthrough if any of the filter algorithm is enabled */
872 /* vpp could be needed in some specific circumstances, for eg:
873 * input surface is dmabuf and output must be videomemory. So far
874 * the underline iHD driver doesn't seems to support dmabuf mapping,
875 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
876 * surfaces as output thourgh capsfileters */
880 /* no passthrough if there is change in out width,height or format */
881 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
882 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
883 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
884 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
885 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
886 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
889 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
893 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
897 mfxFrameAllocRequest request[2];
899 if (!thiz->context) {
900 GST_WARNING_OBJECT (thiz, "No MSDK Context");
904 GST_OBJECT_LOCK (thiz);
905 session = gst_msdk_context_get_session (thiz->context);
907 /* Close the current session if the session has been initialized,
908 * otherwise the subsequent function call of MFXVideoVPP_Init() will
911 if (thiz->initialized)
912 MFXVideoVPP_Close (session);
914 if (thiz->use_video_memory) {
915 gst_msdk_set_frame_allocator (thiz->context);
916 thiz->param.IOPattern =
917 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
919 thiz->param.IOPattern =
920 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
923 /* update input video attributes */
924 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
925 &thiz->sinkpad_info);
927 /* update output video attributes, only CSC and Scaling are supported for now */
928 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
931 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
932 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
933 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
934 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
935 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
936 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
937 thiz->flags |= GST_MSDK_FLAG_FRC;
938 /* So far this is the only algorithm which is working somewhat good */
939 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
942 /* work-around to avoid zero fps in msdk structure */
943 if (!thiz->param.vpp.In.FrameRateExtN)
944 thiz->param.vpp.In.FrameRateExtN = 30;
945 if (!thiz->param.vpp.Out.FrameRateExtN)
946 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
948 /* set vpp out picstruct as progressive if deinterlacing enabled */
949 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
950 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
952 /* Enable the required filters */
953 ensure_filters (thiz);
955 /* Add exteneded buffers */
956 if (thiz->num_extra_params) {
957 thiz->param.NumExtParam = thiz->num_extra_params;
958 thiz->param.ExtParam = thiz->extra_params;
961 /* validate parameters and allow the Media SDK to make adjustments */
962 status = MFXVideoVPP_Query (session, &thiz->param, &thiz->param);
963 if (status < MFX_ERR_NONE) {
964 GST_ERROR_OBJECT (thiz, "Video VPP Query failed (%s)",
965 msdk_status_to_string (status));
967 } else if (status > MFX_ERR_NONE) {
968 GST_WARNING_OBJECT (thiz, "Video VPP Query returned: %s",
969 msdk_status_to_string (status));
972 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
973 if (status < MFX_ERR_NONE) {
974 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
975 msdk_status_to_string (status));
977 } else if (status > MFX_ERR_NONE) {
978 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
979 msdk_status_to_string (status));
982 if (thiz->use_video_memory) {
983 /* Input surface pool pre-allocation */
984 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
985 if (thiz->use_sinkpad_dmabuf)
986 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
987 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
989 /* Output surface pool pre-allocation */
990 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
991 if (thiz->use_srcpad_dmabuf)
992 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
993 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
996 thiz->in_num_surfaces = request[0].NumFrameSuggested;
997 thiz->out_num_surfaces = request[1].NumFrameSuggested;
1000 status = MFXVideoVPP_Init (session, &thiz->param);
1001 if (status < MFX_ERR_NONE) {
1002 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
1004 } else if (status > MFX_ERR_NONE) {
1005 GST_WARNING_OBJECT (thiz, "Init returned: %s",
1006 msdk_status_to_string (status));
1009 thiz->initialized = TRUE;
1010 GST_OBJECT_UNLOCK (thiz);
1014 GST_OBJECT_UNLOCK (thiz);
1016 gst_object_replace ((GstObject **) & thiz->context, NULL);
1021 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1024 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1025 GstVideoInfo in_info, out_info;
1026 gboolean sinkpad_info_changed = FALSE;
1027 gboolean srcpad_info_changed = FALSE;
1028 gboolean deinterlace;
1030 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1033 gst_video_info_from_caps (&in_info, caps);
1034 gst_video_info_from_caps (&out_info, out_caps);
1036 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1037 sinkpad_info_changed = TRUE;
1038 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1039 srcpad_info_changed = TRUE;
1041 if (!sinkpad_info_changed && !srcpad_info_changed && thiz->initialized)
1044 thiz->sinkpad_info = in_info;
1045 thiz->srcpad_info = out_info;
1047 thiz->use_video_memory = TRUE;
1049 thiz->use_video_memory = FALSE;
1052 /* check for deinterlace requirement */
1053 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1055 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1057 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1058 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1059 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1061 if (!gst_msdkvpp_initialize (thiz))
1064 /* set passthrough according to filter operation change */
1065 gst_msdkvpp_set_passthrough (thiz);
1067 /* Ensure sinkpad buffer pool */
1068 thiz->sinkpad_buffer_pool =
1069 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1070 thiz->in_num_surfaces);
1071 if (!thiz->sinkpad_buffer_pool) {
1072 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1075 /* Ensure a srcpad buffer pool */
1076 thiz->srcpad_buffer_pool =
1077 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1078 thiz->out_num_surfaces);
1079 if (!thiz->srcpad_buffer_pool) {
1080 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1088 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1090 gboolean ret = FALSE;
1091 GstCaps *caps, *out_caps;
1093 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1095 if (direction == GST_PAD_SRC)
1096 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1098 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1100 /* make a copy of filter caps since we need to alter the structure
1101 * by adding dmabuf-capsfeatures */
1102 caps = gst_caps_copy (filter);
1103 gst_caps_set_features (caps, 0,
1104 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1106 out_caps = gst_pad_peer_query_caps (pad, caps);
1110 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1111 || out_caps == caps)
1114 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1118 gst_caps_unref (caps);
1120 gst_caps_unref (out_caps);
1125 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1126 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1128 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1129 GstCaps *result = NULL;
1130 gboolean *use_dmabuf;
1132 if (direction == GST_PAD_SRC) {
1133 result = gst_caps_fixate (result);
1134 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1136 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1137 use_dmabuf = &thiz->use_srcpad_dmabuf;
1140 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1141 gst_caps_unref (othercaps);
1143 if (pad_can_dmabuf (thiz,
1144 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1145 gst_caps_set_features (result, 0,
1146 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1153 /* Generic code for now, requires changes in future when we
1154 * add hardware query for supported formats, Framerate control etc */
1156 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1157 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1161 GST_DEBUG_OBJECT (trans,
1162 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1163 (direction == GST_PAD_SINK) ? "sink" : "src");
1165 if (direction == GST_PAD_SRC)
1166 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1168 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1170 if (out_caps && filter) {
1171 GstCaps *intersection;
1173 intersection = gst_caps_intersect_full (out_caps, filter,
1174 GST_CAPS_INTERSECT_FIRST);
1175 gst_caps_unref (out_caps);
1176 out_caps = intersection;
1179 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1184 gst_msdkvpp_start (GstBaseTransform * trans)
1186 if (!ensure_context (trans))
1192 gst_msdkvpp_stop (GstBaseTransform * trans)
1194 gst_msdkvpp_close (GST_MSDKVPP (trans));
1199 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1200 const GValue * value, GParamSpec * pspec)
1202 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1206 thiz->hardware = g_value_get_boolean (value);
1208 case PROP_ASYNC_DEPTH:
1209 thiz->async_depth = g_value_get_uint (value);
1212 thiz->denoise_factor = g_value_get_uint (value);
1213 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1216 thiz->rotation = g_value_get_enum (value);
1217 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1219 case PROP_DEINTERLACE_MODE:
1220 thiz->deinterlace_mode = g_value_get_enum (value);
1222 case PROP_DEINTERLACE_METHOD:
1223 thiz->deinterlace_method = g_value_get_enum (value);
1226 thiz->hue = g_value_get_float (value);
1227 thiz->flags |= GST_MSDK_FLAG_HUE;
1229 case PROP_SATURATION:
1230 thiz->saturation = g_value_get_float (value);
1231 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1233 case PROP_BRIGHTNESS:
1234 thiz->brightness = g_value_get_float (value);
1235 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1238 thiz->contrast = g_value_get_float (value);
1239 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1242 thiz->detail = g_value_get_uint (value);
1243 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1245 case PROP_MIRRORING:
1246 thiz->mirroring = g_value_get_enum (value);
1247 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1249 case PROP_SCALING_MODE:
1250 thiz->scaling_mode = g_value_get_enum (value);
1251 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1253 case PROP_FORCE_ASPECT_RATIO:
1254 thiz->keep_aspect = g_value_get_boolean (value);
1256 case PROP_FRC_ALGORITHM:
1257 thiz->frc_algm = g_value_get_enum (value);
1260 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1266 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1267 GValue * value, GParamSpec * pspec)
1269 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1273 g_value_set_boolean (value, thiz->hardware);
1275 case PROP_ASYNC_DEPTH:
1276 g_value_set_uint (value, thiz->async_depth);
1279 g_value_set_uint (value, thiz->denoise_factor);
1282 g_value_set_enum (value, thiz->rotation);
1284 case PROP_DEINTERLACE_MODE:
1285 g_value_set_enum (value, thiz->deinterlace_mode);
1287 case PROP_DEINTERLACE_METHOD:
1288 g_value_set_enum (value, thiz->deinterlace_method);
1291 g_value_set_float (value, thiz->hue);
1293 case PROP_SATURATION:
1294 g_value_set_float (value, thiz->saturation);
1296 case PROP_BRIGHTNESS:
1297 g_value_set_float (value, thiz->brightness);
1300 g_value_set_float (value, thiz->contrast);
1303 g_value_set_uint (value, thiz->detail);
1305 case PROP_MIRRORING:
1306 g_value_set_enum (value, thiz->mirroring);
1308 case PROP_SCALING_MODE:
1309 g_value_set_enum (value, thiz->scaling_mode);
1311 case PROP_FORCE_ASPECT_RATIO:
1312 g_value_set_boolean (value, thiz->keep_aspect);
1314 case PROP_FRC_ALGORITHM:
1315 g_value_set_enum (value, thiz->frc_algm);
1318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1324 gst_msdkvpp_finalize (GObject * object)
1326 G_OBJECT_CLASS (parent_class)->finalize (object);
1330 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1332 GstMsdkContext *msdk_context = NULL;
1333 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1335 if (gst_msdk_context_get_context (context, &msdk_context)) {
1336 gst_object_replace ((GstObject **) & thiz->context,
1337 (GstObject *) msdk_context);
1338 gst_object_unref (msdk_context);
1341 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1345 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1347 GObjectClass *gobject_class;
1348 GstElementClass *element_class;
1349 GstBaseTransformClass *trans_class;
1350 GParamSpec *obj_properties[PROP_N] = { NULL, };
1352 gobject_class = G_OBJECT_CLASS (klass);
1353 element_class = GST_ELEMENT_CLASS (klass);
1354 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1356 gobject_class->set_property = gst_msdkvpp_set_property;
1357 gobject_class->get_property = gst_msdkvpp_get_property;
1358 gobject_class->finalize = gst_msdkvpp_finalize;
1360 element_class->set_context = gst_msdkvpp_set_context;
1362 gst_element_class_add_static_pad_template (element_class,
1363 &gst_msdkvpp_src_factory);
1364 gst_element_class_add_static_pad_template (element_class,
1365 &gst_msdkvpp_sink_factory);
1367 gst_element_class_set_static_metadata (element_class,
1368 "MSDK Video Postprocessor",
1369 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1370 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1371 "A MediaSDK Video Postprocessing Filter",
1372 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1374 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1375 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1376 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1377 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1378 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1379 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1380 trans_class->propose_allocation =
1381 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1382 trans_class->decide_allocation =
1383 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1384 trans_class->prepare_output_buffer =
1385 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1387 obj_properties[PROP_HARDWARE] =
1388 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1389 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1391 obj_properties[PROP_ASYNC_DEPTH] =
1392 g_param_spec_uint ("async-depth", "Async Depth",
1393 "Depth of asynchronous pipeline",
1394 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1395 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1397 obj_properties[PROP_DENOISE] =
1398 g_param_spec_uint ("denoise", "Denoising factor",
1400 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1402 obj_properties[PROP_ROTATION] =
1403 g_param_spec_enum ("rotation", "Rotation",
1404 "Rotation Angle", gst_msdkvpp_rotation_get_type (),
1405 PROP_ROTATION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1407 obj_properties[PROP_DEINTERLACE_MODE] =
1408 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1409 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1410 PROP_DEINTERLACE_MODE_DEFAULT,
1411 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1413 obj_properties[PROP_DEINTERLACE_METHOD] =
1414 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1415 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1416 PROP_DEINTERLACE_METHOD_DEFAULT,
1417 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1419 obj_properties[PROP_HUE] =
1420 g_param_spec_float ("hue", "Hue",
1421 "The hue of the video",
1422 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1424 obj_properties[PROP_SATURATION] =
1425 g_param_spec_float ("saturation", "Saturation",
1426 "The Saturation of the video",
1427 0, 10, PROP_SATURATION_DEFAULT,
1428 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1430 obj_properties[PROP_BRIGHTNESS] =
1431 g_param_spec_float ("brightness", "Brightness",
1432 "The Brightness of the video",
1433 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1434 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1436 obj_properties[PROP_CONTRAST] =
1437 g_param_spec_float ("contrast", "Contrast",
1438 "The Contrast of the video",
1439 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1441 obj_properties[PROP_DETAIL] =
1442 g_param_spec_uint ("detail", "Detail",
1443 "The factor of detail/edge enhancement filter algorithm",
1444 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1446 obj_properties[PROP_MIRRORING] =
1447 g_param_spec_enum ("mirroring", "Mirroring",
1448 "The Mirroring type", gst_msdkvpp_mirroring_get_type (),
1449 PROP_MIRRORING_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1451 obj_properties[PROP_SCALING_MODE] =
1452 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1453 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1454 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1456 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1457 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1458 "When enabled, scaling will respect original aspect ratio",
1459 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1460 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1462 obj_properties[PROP_FRC_ALGORITHM] =
1463 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1464 "The Framerate Control Alogorithm to use",
1465 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1466 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1468 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1472 gst_msdkvpp_init (GstMsdkVPP * thiz)
1474 thiz->initialized = FALSE;
1475 thiz->hardware = PROP_HARDWARE_DEFAULT;
1476 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1477 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1478 thiz->rotation = PROP_ROTATION_DEFAULT;
1479 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1480 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1481 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1482 thiz->hue = PROP_HUE_DEFAULT;
1483 thiz->saturation = PROP_SATURATION_DEFAULT;
1484 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1485 thiz->contrast = PROP_CONTRAST_DEFAULT;
1486 thiz->detail = PROP_DETAIL_DEFAULT;
1487 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1488 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1489 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1490 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1491 gst_video_info_init (&thiz->sinkpad_info);
1492 gst_video_info_init (&thiz->srcpad_info);