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 }")
60 ", " "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
61 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
62 "{ NV12, BGRA, YUY2}")));
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, NV12}") ";"
71 GST_VIDEO_CAPS_MAKE ("{ NV12, YUY2, BGRA, BGRx }") ", "
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;
149 parent_context = thiz->context;
150 thiz->context = gst_msdk_context_new_with_parent (parent_context);
151 gst_object_unref (parent_context);
153 GST_INFO_OBJECT (thiz,
154 "Creating new context %" GST_PTR_FORMAT " with joined session",
157 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
160 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
161 thiz->hardware, GST_MSDK_JOB_VPP))
163 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
167 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
173 create_output_buffer (GstMsdkVPP * thiz)
177 GstBufferPool *pool = thiz->srcpad_buffer_pool;
179 g_return_val_if_fail (pool != NULL, NULL);
181 if (!gst_buffer_pool_is_active (pool) &&
182 !gst_buffer_pool_set_active (pool, TRUE))
183 goto error_activate_pool;
186 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
187 if (ret != GST_FLOW_OK || !outbuf)
188 goto error_create_buffer;
195 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
200 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
206 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
207 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
209 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
211 if (gst_base_transform_is_passthrough (trans)) {
216 *outbuf_ptr = create_output_buffer (thiz);
217 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
220 static GstBufferPool *
221 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
222 GstCaps * caps, guint min_num_buffers)
224 GstBufferPool *pool = NULL;
225 GstStructure *config;
226 GstAllocator *allocator = NULL;
228 GstVideoInfo *pool_info = NULL;
229 GstVideoAlignment align;
230 GstAllocationParams params = { 0, 31, 0, 0, };
231 mfxFrameAllocResponse *alloc_resp = NULL;
232 gboolean use_dmabuf = FALSE;
234 if (direction == GST_PAD_SINK) {
235 alloc_resp = &thiz->in_alloc_resp;
236 pool_info = &thiz->sinkpad_buffer_pool_info;
237 use_dmabuf = thiz->use_sinkpad_dmabuf;
238 } else if (direction == GST_PAD_SRC) {
239 alloc_resp = &thiz->out_alloc_resp;
240 pool_info = &thiz->srcpad_buffer_pool_info;
241 use_dmabuf = thiz->use_srcpad_dmabuf;
244 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
248 if (!gst_video_info_from_caps (&info, caps))
249 goto error_no_video_info;
251 gst_msdk_set_video_alignment (&info, &align);
252 gst_video_info_align (&info, &align);
256 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
257 else if (thiz->use_video_memory)
258 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
260 allocator = gst_msdk_system_allocator_new (&info);
263 goto error_no_allocator;
265 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
266 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
269 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
270 gst_buffer_pool_config_add_option (config,
271 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
272 if (thiz->use_video_memory) {
273 gst_buffer_pool_config_add_option (config,
274 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
276 gst_buffer_pool_config_add_option (config,
277 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
280 gst_buffer_pool_config_set_video_alignment (config, &align);
281 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
282 gst_object_unref (allocator);
284 if (!gst_buffer_pool_set_config (pool, config))
285 goto error_pool_config;
287 /* Updating pool_info with algined info of allocator */
294 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
299 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
304 GST_INFO_OBJECT (thiz, "Failed to create allocator");
306 gst_object_unref (pool);
311 GST_INFO_OBJECT (thiz, "Failed to set config");
313 gst_object_unref (pool);
315 gst_object_unref (allocator);
321 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
325 for (i = 0; i < gst_caps_get_size (caps); i++) {
326 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
327 /* Skip ANY features, we need an exact match for correct evaluation */
328 if (gst_caps_features_is_any (features))
330 if (gst_caps_features_contains (features, feature))
337 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
339 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
341 GstBufferPool *pool = NULL;
342 GstStructure *config = NULL;
344 guint size = 0, min_buffers = 0, max_buffers = 0;
345 GstAllocator *allocator = NULL;
346 GstAllocationParams params;
347 gboolean update_pool = FALSE;
349 gst_query_parse_allocation (query, &caps, NULL);
351 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
354 if (!gst_video_info_from_caps (&info, caps)) {
355 GST_ERROR_OBJECT (thiz, "Failed to get video info");
358 /* if downstream allocation query supports dmabuf-capsfeatures,
359 * we do allocate dmabuf backed memory */
360 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
361 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
362 thiz->use_srcpad_dmabuf = TRUE;
365 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
366 thiz->add_video_meta = TRUE;
368 thiz->add_video_meta = FALSE;
370 /* Check whether the query has pool */
371 if (gst_query_get_n_allocation_pools (query) > 0)
374 /* increase the min_buffers with number of concurrent vpp operations */
375 min_buffers += thiz->async_depth;
377 /* invalidate the cached pool if there is an allocation_query */
378 if (thiz->srcpad_buffer_pool)
379 gst_object_unref (thiz->srcpad_buffer_pool);
381 /* Always create a pool for vpp out buffers. Each of the msdk element
382 * has to create it's own mfxsurfacepool which is an msdk contraint.
383 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
384 * Frame allocator for video-memory usage.So sharing the pool between
385 * gst-msdk elements might not be a good idea, rather each element
386 * can check the buffer type (whether it is from msdk-buffer pool)
387 * to make sure there is no copy. Since we share the context between
388 * msdk elements, using buffers from one sdk's framealloator in another
389 * sdk-components is perfectly fine */
390 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
391 thiz->srcpad_buffer_pool = pool;
393 /* get the configured pool properties inorder to set in query */
394 config = gst_buffer_pool_get_config (pool);
395 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
397 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
398 gst_query_add_allocation_param (query, allocator, ¶ms);
399 gst_structure_free (config);
402 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
405 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
407 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
409 /* Fixme if downstream doesn't have videometa support, msdkvpp should
410 * copy the output buffers */
416 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
417 GstQuery * decide_query, GstQuery * query)
419 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
421 GstBufferPool *pool = NULL;
422 GstAllocator *allocator = NULL;
424 GstStructure *config;
426 GstAllocationParams params;
428 guint min_buffers = thiz->async_depth + 1;
430 gst_query_parse_allocation (query, &caps, &need_pool);
432 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
436 if (!gst_video_info_from_caps (&info, caps)) {
437 GST_ERROR_OBJECT (thiz, "Failed to get video info");
441 /* if upstream allocation query supports dmabuf-capsfeatures,
442 * we do allocate dmabuf backed memory */
443 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
444 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
445 thiz->use_sinkpad_dmabuf = TRUE;
449 /* alwys provide a new pool for upstream to help re-negotiation
450 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
451 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
455 /* Update the internal pool if any allocation attribute changed */
456 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
457 gst_object_unref (thiz->sinkpad_buffer_pool);
458 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
459 GST_PAD_SINK, caps, min_buffers);
462 /* get the size and allocator params from configured pool and set it in query */
464 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
465 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
466 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
467 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
468 gst_query_add_allocation_param (query, allocator, ¶ms);
469 gst_structure_free (config);
471 /* if upstream does't have a pool requirement, set only
472 * size, min_buffers and max_buffers in query */
473 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
475 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
477 gst_object_unref (pool);
479 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
480 decide_query, query);
484 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
485 GstBufferPoolAcquireParams * params)
487 GstBuffer *new_buffer;
488 mfxFrameSurface1 *new_surface;
489 MsdkSurface *msdk_surface;
491 if (!gst_buffer_pool_is_active (pool) &&
492 !gst_buffer_pool_set_active (pool, TRUE)) {
493 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
497 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
498 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
502 if (gst_msdk_is_msdk_buffer (new_buffer))
503 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
505 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
509 msdk_surface = g_slice_new0 (MsdkSurface);
510 msdk_surface->surface = new_surface;
511 msdk_surface->buf = new_buffer;
518 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
519 MsdkSurface * msdk_surface)
521 GstMemory *mem = NULL;
524 GstMsdkMemoryID *msdk_mid = NULL;
525 mfxFrameSurface1 *mfx_surface = NULL;
528 mem = gst_buffer_peek_memory (buf, 0);
529 fd = gst_dmabuf_memory_get_fd (mem);
533 vinfo = thiz->sinkpad_info;
535 /* Update offset/stride/size if there is VideoMeta attached to
537 vmeta = gst_buffer_get_video_meta (buf);
539 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
540 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
541 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
542 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
543 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
544 "the negotiated width/height/format");
547 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
548 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
549 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
551 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
554 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
555 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
556 * Ideally, media-driver should accept what ever memory coming from other drivers
557 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
558 * For now, in order to avoid any crash we check the buffer size and fallback
559 * to copy frame method.
561 * See this: https://github.com/intel/media-driver/issues/169
563 if (GST_VIDEO_INFO_SIZE (&vinfo) <
564 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
567 mfx_surface = msdk_surface->surface;
568 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
570 /* release the internal memory storage of associated mfxSurface */
571 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
573 /* export dmabuf to vasurface */
574 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
583 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
585 GstVideoFrame src_frame, out_frame;
586 MsdkSurface *msdk_surface;
587 GstMemory *mem = NULL;
589 if (gst_msdk_is_msdk_buffer (inbuf)) {
590 msdk_surface = g_slice_new0 (MsdkSurface);
591 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
592 msdk_surface->buf = gst_buffer_ref (inbuf);
596 /* If upstream hasn't accpeted the proposed msdk bufferpool,
597 * just copy frame (if not dmabuf backed) to msdk buffer and
598 * take a surface from it. */
600 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
604 /************ dmabuf-import ************* */
605 /* if upstream provided a dmabuf backed memory, but not an msdk
606 * buffer, we could export the dmabuf to underlined vasurface */
607 mem = gst_buffer_peek_memory (inbuf, 0);
608 if (gst_is_dmabuf_memory (mem)) {
609 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
612 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
613 "to the msdk surface, fall back to the copy input frame method");
617 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
619 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
623 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
624 msdk_surface->buf, GST_MAP_WRITE)) {
625 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
626 gst_video_frame_unmap (&src_frame);
630 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
631 GST_ERROR_OBJECT (thiz, "failed to copy frame");
632 gst_video_frame_unmap (&out_frame);
633 gst_video_frame_unmap (&src_frame);
637 gst_video_frame_unmap (&out_frame);
638 gst_video_frame_unmap (&src_frame);
647 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
650 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
651 GstClockTime timestamp;
652 GstFlowReturn ret = GST_FLOW_OK;
654 mfxSyncPoint sync_point = NULL;
656 MsdkSurface *in_surface = NULL;
657 MsdkSurface *out_surface = NULL;
659 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
661 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
663 return GST_FLOW_ERROR;
665 if (gst_msdk_is_msdk_buffer (outbuf)) {
666 out_surface = g_slice_new0 (MsdkSurface);
667 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
669 GST_ERROR ("Failed to get msdk outsurface!");
670 return GST_FLOW_ERROR;
673 session = gst_msdk_context_get_session (thiz->context);
675 /* outer loop is for handling FrameRate Control and deinterlace use cases */
679 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
680 out_surface->surface, NULL, &sync_point);
681 if (status != MFX_WRN_DEVICE_BUSY)
683 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
687 if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
688 && status != MFX_ERR_MORE_SURFACE)
691 /* No output generated */
692 if (status == MFX_ERR_MORE_DATA)
693 goto error_more_data;
696 MFXVideoCORE_SyncOperation (session, sync_point, 10000);
698 /* More than one output buffers are generated */
699 if (status == MFX_ERR_MORE_SURFACE) {
700 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
701 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
702 timestamp += thiz->buffer_duration;
703 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
704 if (ret != GST_FLOW_OK)
705 goto error_push_buffer;
706 outbuf = create_output_buffer (thiz);
708 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
709 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
711 } while (status == MFX_ERR_MORE_SURFACE);
713 free_msdk_surface (in_surface);
717 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
718 free_msdk_surface (in_surface);
719 free_msdk_surface (out_surface);
720 return GST_FLOW_ERROR;
723 GST_WARNING_OBJECT (thiz,
724 "MSDK Requries additional input for processing, "
725 "Retruning FLOW_DROPPED since no output buffer was generated");
726 free_msdk_surface (in_surface);
727 return GST_BASE_TRANSFORM_FLOW_DROPPED;
731 free_msdk_surface (in_surface);
732 free_msdk_surface (out_surface);
733 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
734 gst_flow_get_name (ret));
740 gst_msdkvpp_close (GstMsdkVPP * thiz)
747 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
748 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
749 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
750 GST_WARNING_OBJECT (thiz, "Encoder close failed (%s)",
751 msdk_status_to_string (status));
755 gst_object_replace ((GstObject **) & thiz->context, NULL);
757 memset (&thiz->param, 0, sizeof (thiz->param));
759 if (thiz->sinkpad_buffer_pool)
760 gst_object_unref (thiz->sinkpad_buffer_pool);
761 thiz->sinkpad_buffer_pool = NULL;
762 if (thiz->srcpad_buffer_pool)
763 gst_object_unref (thiz->srcpad_buffer_pool);
764 thiz->srcpad_buffer_pool = NULL;
766 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
767 gst_video_info_init (&thiz->sinkpad_info);
768 gst_video_info_init (&thiz->srcpad_info);
772 ensure_filters (GstMsdkVPP * thiz)
776 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
777 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
778 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
779 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
780 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
781 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
785 if (thiz->flags & GST_MSDK_FLAG_ROTATION) {
786 mfxExtVPPRotation *mfx_rotation = &thiz->mfx_rotation;
787 mfx_rotation->Header.BufferId = MFX_EXTBUFF_VPP_ROTATION;
788 mfx_rotation->Header.BufferSz = sizeof (mfxExtVPPRotation);
789 mfx_rotation->Angle = thiz->rotation;
790 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_rotation);
794 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
795 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
796 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
797 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
798 mfx_deinterlace->Mode = thiz->deinterlace_method;
799 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
802 /* Colorbalance(ProcAmp) */
803 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
804 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
805 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
806 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
807 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
808 mfx_procamp->Hue = thiz->hue;
809 mfx_procamp->Saturation = thiz->saturation;
810 mfx_procamp->Brightness = thiz->brightness;
811 mfx_procamp->Contrast = thiz->contrast;
812 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
815 /* Detail/Edge enhancement */
816 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
817 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
818 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
819 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
820 mfx_detail->DetailFactor = thiz->detail;
821 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
825 if (thiz->flags & GST_MSDK_FLAG_MIRRORING) {
826 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
827 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
828 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
829 mfx_mirroring->Type = thiz->mirroring;
830 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
834 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
835 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
836 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
837 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
838 mfx_scaling->ScalingMode = thiz->scaling_mode;
839 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
843 if (thiz->flags & GST_MSDK_FLAG_FRC) {
844 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
845 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
846 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
847 mfx_frc->Algorithm = thiz->frc_algm;
848 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
853 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
855 gboolean passthrough = TRUE;
857 /* no passthrough if any of the filter algorithm is enabled */
861 /* vpp could be needed in some specific circumstances, for eg:
862 * input surface is dmabuf and output must be videomemory. So far
863 * the underline iHD driver doesn't seems to support dmabuf mapping,
864 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
865 * surfaces as output thourgh capsfileters */
869 /* no passthrough if there is change in out width,height or format */
870 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
871 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
872 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
873 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
874 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
875 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
878 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
882 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
886 mfxFrameAllocRequest request[2];
888 if (!thiz->context) {
889 GST_WARNING_OBJECT (thiz, "No MSDK Context");
893 GST_OBJECT_LOCK (thiz);
894 session = gst_msdk_context_get_session (thiz->context);
896 if (thiz->use_video_memory) {
897 gst_msdk_set_frame_allocator (thiz->context);
898 thiz->param.IOPattern =
899 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
901 thiz->param.IOPattern =
902 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
905 /* update input video attributes */
906 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
907 &thiz->sinkpad_info);
909 /* update output video attributes, only CSC and Scaling are supported for now */
910 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
913 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
914 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
915 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
916 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
917 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
918 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
919 thiz->flags |= GST_MSDK_FLAG_FRC;
920 /* So far this is the only algorithm which is working somewhat good */
921 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
924 /* work-around to avoid zero fps in msdk structure */
925 if (!thiz->param.vpp.In.FrameRateExtN)
926 thiz->param.vpp.In.FrameRateExtN = 30;
927 if (!thiz->param.vpp.Out.FrameRateExtN)
928 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
930 /* set vpp out picstruct as progressive if deinterlacing enabled */
931 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
932 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
934 /* Enable the required filters */
935 ensure_filters (thiz);
937 /* Add exteneded buffers */
938 if (thiz->num_extra_params) {
939 thiz->param.NumExtParam = thiz->num_extra_params;
940 thiz->param.ExtParam = thiz->extra_params;
943 /* validate parameters and allow the Media SDK to make adjustments */
944 status = MFXVideoVPP_Query (session, &thiz->param, &thiz->param);
945 if (status < MFX_ERR_NONE) {
946 GST_ERROR_OBJECT (thiz, "Video VPP Query failed (%s)",
947 msdk_status_to_string (status));
949 } else if (status > MFX_ERR_NONE) {
950 GST_WARNING_OBJECT (thiz, "Video VPP Query returned: %s",
951 msdk_status_to_string (status));
954 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
955 if (status < MFX_ERR_NONE) {
956 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
957 msdk_status_to_string (status));
959 } else if (status > MFX_ERR_NONE) {
960 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
961 msdk_status_to_string (status));
964 if (thiz->use_video_memory) {
965 /* Input surface pool pre-allocation */
966 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
967 if (thiz->use_sinkpad_dmabuf)
968 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
969 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
971 /* Output surface pool pre-allocation */
972 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
973 if (thiz->use_srcpad_dmabuf)
974 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
975 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
978 thiz->in_num_surfaces = request[0].NumFrameSuggested;
979 thiz->out_num_surfaces = request[1].NumFrameSuggested;
982 status = MFXVideoVPP_Init (session, &thiz->param);
983 if (status < MFX_ERR_NONE) {
984 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
986 } else if (status > MFX_ERR_NONE) {
987 GST_WARNING_OBJECT (thiz, "Init returned: %s",
988 msdk_status_to_string (status));
991 thiz->initialized = TRUE;
992 GST_OBJECT_UNLOCK (thiz);
996 GST_OBJECT_UNLOCK (thiz);
998 gst_object_replace ((GstObject **) & thiz->context, NULL);
1003 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1006 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1007 GstVideoInfo in_info, out_info;
1008 gboolean sinkpad_info_changed = FALSE;
1009 gboolean srcpad_info_changed = FALSE;
1010 gboolean deinterlace;
1012 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1015 gst_video_info_from_caps (&in_info, caps);
1016 gst_video_info_from_caps (&out_info, out_caps);
1018 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1019 sinkpad_info_changed = TRUE;
1020 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1021 srcpad_info_changed = TRUE;
1023 thiz->sinkpad_info = in_info;
1024 thiz->srcpad_info = out_info;
1026 thiz->use_video_memory = TRUE;
1028 thiz->use_video_memory = FALSE;
1031 if (!sinkpad_info_changed && !srcpad_info_changed && thiz->initialized)
1034 /* check for deinterlace requirement */
1035 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1037 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1039 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1040 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1041 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1043 if (!gst_msdkvpp_initialize (thiz))
1046 /* set passthrough according to filter operation change */
1047 gst_msdkvpp_set_passthrough (thiz);
1049 /* Ensure sinkpad buffer pool */
1050 thiz->sinkpad_buffer_pool =
1051 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1052 thiz->in_num_surfaces);
1053 if (!thiz->sinkpad_buffer_pool) {
1054 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1057 /* Ensure a srcpad buffer pool */
1058 thiz->srcpad_buffer_pool =
1059 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1060 thiz->out_num_surfaces);
1061 if (!thiz->srcpad_buffer_pool) {
1062 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1070 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1072 gboolean ret = FALSE;
1073 GstCaps *caps, *out_caps;
1075 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1077 if (direction == GST_PAD_SRC)
1078 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1080 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1082 /* make a copy of filter caps since we need to alter the structure
1083 * by adding dmabuf-capsfeatures */
1084 caps = gst_caps_copy (filter);
1085 gst_caps_set_features (caps, 0,
1086 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1088 out_caps = gst_pad_peer_query_caps (pad, caps);
1092 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1093 || out_caps == caps)
1096 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1100 gst_caps_unref (caps);
1102 gst_caps_unref (out_caps);
1107 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1108 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1110 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1111 GstCaps *result = NULL;
1112 gboolean *use_dmabuf;
1114 if (direction == GST_PAD_SRC) {
1115 result = gst_caps_fixate (result);
1116 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1118 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1119 use_dmabuf = &thiz->use_srcpad_dmabuf;
1122 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1123 gst_caps_unref (othercaps);
1125 if (pad_can_dmabuf (thiz,
1126 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1127 gst_caps_set_features (result, 0,
1128 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1135 /* Generic code for now, requires changes in future when we
1136 * add hardware query for supported formats, Framerate control etc */
1138 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1139 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1143 GST_DEBUG_OBJECT (trans,
1144 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1145 (direction == GST_PAD_SINK) ? "sink" : "src");
1147 if (direction == GST_PAD_SRC)
1148 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1150 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1152 if (out_caps && filter) {
1153 GstCaps *intersection;
1155 intersection = gst_caps_intersect_full (out_caps, filter,
1156 GST_CAPS_INTERSECT_FIRST);
1157 gst_caps_unref (out_caps);
1158 out_caps = intersection;
1161 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1166 gst_msdkvpp_start (GstBaseTransform * trans)
1168 if (!ensure_context (trans))
1174 gst_msdkvpp_stop (GstBaseTransform * trans)
1176 gst_msdkvpp_close (GST_MSDKVPP (trans));
1181 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1182 const GValue * value, GParamSpec * pspec)
1184 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1188 thiz->hardware = g_value_get_boolean (value);
1190 case PROP_ASYNC_DEPTH:
1191 thiz->async_depth = g_value_get_uint (value);
1194 thiz->denoise_factor = g_value_get_uint (value);
1195 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1198 thiz->rotation = g_value_get_enum (value);
1199 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1201 case PROP_DEINTERLACE_MODE:
1202 thiz->deinterlace_mode = g_value_get_enum (value);
1204 case PROP_DEINTERLACE_METHOD:
1205 thiz->deinterlace_method = g_value_get_enum (value);
1208 thiz->hue = g_value_get_float (value);
1209 thiz->flags |= GST_MSDK_FLAG_HUE;
1211 case PROP_SATURATION:
1212 thiz->saturation = g_value_get_float (value);
1213 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1215 case PROP_BRIGHTNESS:
1216 thiz->brightness = g_value_get_float (value);
1217 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1220 thiz->contrast = g_value_get_float (value);
1221 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1224 thiz->detail = g_value_get_uint (value);
1225 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1227 case PROP_MIRRORING:
1228 thiz->mirroring = g_value_get_enum (value);
1229 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1231 case PROP_SCALING_MODE:
1232 thiz->scaling_mode = g_value_get_enum (value);
1233 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1235 case PROP_FORCE_ASPECT_RATIO:
1236 thiz->keep_aspect = g_value_get_boolean (value);
1238 case PROP_FRC_ALGORITHM:
1239 thiz->frc_algm = g_value_get_enum (value);
1242 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1248 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1249 GValue * value, GParamSpec * pspec)
1251 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1255 g_value_set_boolean (value, thiz->hardware);
1257 case PROP_ASYNC_DEPTH:
1258 g_value_set_uint (value, thiz->async_depth);
1261 g_value_set_uint (value, thiz->denoise_factor);
1264 g_value_set_enum (value, thiz->rotation);
1266 case PROP_DEINTERLACE_MODE:
1267 g_value_set_enum (value, thiz->deinterlace_mode);
1269 case PROP_DEINTERLACE_METHOD:
1270 g_value_set_enum (value, thiz->deinterlace_method);
1273 g_value_set_float (value, thiz->hue);
1275 case PROP_SATURATION:
1276 g_value_set_float (value, thiz->saturation);
1278 case PROP_BRIGHTNESS:
1279 g_value_set_float (value, thiz->brightness);
1282 g_value_set_float (value, thiz->contrast);
1285 g_value_set_uint (value, thiz->detail);
1287 case PROP_MIRRORING:
1288 g_value_set_enum (value, thiz->mirroring);
1290 case PROP_SCALING_MODE:
1291 g_value_set_enum (value, thiz->scaling_mode);
1293 case PROP_FORCE_ASPECT_RATIO:
1294 g_value_set_boolean (value, thiz->keep_aspect);
1296 case PROP_FRC_ALGORITHM:
1297 g_value_set_enum (value, thiz->frc_algm);
1300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1306 gst_msdkvpp_finalize (GObject * object)
1308 G_OBJECT_CLASS (parent_class)->finalize (object);
1312 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1314 GstMsdkContext *msdk_context = NULL;
1315 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1317 if (gst_msdk_context_get_context (context, &msdk_context)) {
1318 gst_object_replace ((GstObject **) & thiz->context,
1319 (GstObject *) msdk_context);
1320 gst_object_unref (msdk_context);
1323 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1327 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1329 GObjectClass *gobject_class;
1330 GstElementClass *element_class;
1331 GstBaseTransformClass *trans_class;
1332 GParamSpec *obj_properties[PROP_N] = { NULL, };
1334 gobject_class = G_OBJECT_CLASS (klass);
1335 element_class = GST_ELEMENT_CLASS (klass);
1336 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1338 gobject_class->set_property = gst_msdkvpp_set_property;
1339 gobject_class->get_property = gst_msdkvpp_get_property;
1340 gobject_class->finalize = gst_msdkvpp_finalize;
1342 element_class->set_context = gst_msdkvpp_set_context;
1344 gst_element_class_add_static_pad_template (element_class,
1345 &gst_msdkvpp_src_factory);
1346 gst_element_class_add_static_pad_template (element_class,
1347 &gst_msdkvpp_sink_factory);
1349 gst_element_class_set_static_metadata (element_class,
1350 "MSDK Video Postprocessor",
1351 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1352 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1353 "A MediaSDK Video Postprocessing Filter",
1354 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1356 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1357 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1358 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1359 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1360 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1361 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1362 trans_class->propose_allocation =
1363 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1364 trans_class->decide_allocation =
1365 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1366 trans_class->prepare_output_buffer =
1367 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1369 obj_properties[PROP_HARDWARE] =
1370 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1371 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1373 obj_properties[PROP_ASYNC_DEPTH] =
1374 g_param_spec_uint ("async-depth", "Async Depth",
1375 "Depth of asynchronous pipeline",
1376 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1379 obj_properties[PROP_DENOISE] =
1380 g_param_spec_uint ("denoise", "Denoising factor",
1382 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1384 obj_properties[PROP_ROTATION] =
1385 g_param_spec_enum ("rotation", "Rotation",
1386 "Rotation Angle", gst_msdkvpp_rotation_get_type (),
1387 PROP_ROTATION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1389 obj_properties[PROP_DEINTERLACE_MODE] =
1390 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1391 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1392 PROP_DEINTERLACE_MODE_DEFAULT,
1393 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1395 obj_properties[PROP_DEINTERLACE_METHOD] =
1396 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1397 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1398 PROP_DEINTERLACE_METHOD_DEFAULT,
1399 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1401 obj_properties[PROP_HUE] =
1402 g_param_spec_float ("hue", "Hue",
1403 "The hue of the video",
1404 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1406 obj_properties[PROP_SATURATION] =
1407 g_param_spec_float ("saturation", "Saturation",
1408 "The Saturation of the video",
1409 0, 10, PROP_SATURATION_DEFAULT,
1410 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1412 obj_properties[PROP_BRIGHTNESS] =
1413 g_param_spec_float ("brightness", "Brightness",
1414 "The Brightness of the video",
1415 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1416 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1418 obj_properties[PROP_CONTRAST] =
1419 g_param_spec_float ("contrast", "Contrast",
1420 "The Contrast of the video",
1421 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1423 obj_properties[PROP_DETAIL] =
1424 g_param_spec_uint ("detail", "Detail",
1425 "The factor of detail/edge enhancement filter algorithm",
1426 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1428 obj_properties[PROP_MIRRORING] =
1429 g_param_spec_enum ("mirroring", "Mirroring",
1430 "The Mirroring type", gst_msdkvpp_mirroring_get_type (),
1431 PROP_MIRRORING_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1433 obj_properties[PROP_SCALING_MODE] =
1434 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1435 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1436 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1438 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1439 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1440 "When enabled, scaling will respect original aspect ratio",
1441 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1442 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1444 obj_properties[PROP_FRC_ALGORITHM] =
1445 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1446 "The Framerate Control Alogorithm to use",
1447 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1448 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1450 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1454 gst_msdkvpp_init (GstMsdkVPP * thiz)
1456 thiz->initialized = FALSE;
1457 thiz->hardware = PROP_HARDWARE_DEFAULT;
1458 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1459 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1460 thiz->rotation = PROP_ROTATION_DEFAULT;
1461 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1462 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1463 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1464 thiz->hue = PROP_HUE_DEFAULT;
1465 thiz->saturation = PROP_SATURATION_DEFAULT;
1466 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1467 thiz->contrast = PROP_CONTRAST_DEFAULT;
1468 thiz->detail = PROP_DETAIL_DEFAULT;
1469 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1470 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1471 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1472 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1473 gst_video_info_init (&thiz->sinkpad_info);
1474 gst_video_info_init (&thiz->srcpad_info);