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 ("{ NV12, YUY2, BGRA, BGRx }") ", "
69 "interlace-mode = (string){ progressive, interleaved, mixed }" ";"
70 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
71 "{ NV12, BGRA, YUY2}")));
80 PROP_DEINTERLACE_MODE,
81 PROP_DEINTERLACE_METHOD,
89 PROP_FORCE_ASPECT_RATIO,
94 #define PROP_HARDWARE_DEFAULT TRUE
95 #define PROP_ASYNC_DEPTH_DEFAULT 1
96 #define PROP_DENOISE_DEFAULT 0
97 #define PROP_ROTATION_DEFAULT MFX_ANGLE_0
98 #define PROP_DEINTERLACE_MODE_DEFAULT GST_MSDKVPP_DEINTERLACE_MODE_AUTO
99 #define PROP_DEINTERLACE_METHOD_DEFAULT MFX_DEINTERLACING_BOB
100 #define PROP_HUE_DEFAULT 0
101 #define PROP_SATURATION_DEFAULT 1
102 #define PROP_BRIGHTNESS_DEFAULT 0
103 #define PROP_CONTRAST_DEFAULT 1
104 #define PROP_DETAIL_DEFAULT 0
105 #define PROP_MIRRORING_DEFAULT MFX_MIRRORING_DISABLED
106 #define PROP_SCALING_MODE_DEFAULT MFX_SCALING_MODE_DEFAULT
107 #define PROP_FORCE_ASPECT_RATIO_DEFAULT TRUE
108 #define PROP_FRC_ALGORITHM_DEFAULT _MFX_FRC_ALGORITHM_NONE
110 #define gst_msdkvpp_parent_class parent_class
111 G_DEFINE_TYPE (GstMsdkVPP, gst_msdkvpp, GST_TYPE_BASE_TRANSFORM);
115 mfxFrameSurface1 *surface;
120 free_msdk_surface (MsdkSurface * surface)
123 gst_buffer_unref (surface->buf);
124 g_slice_free (MsdkSurface, surface);
128 gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param)
130 if (thiz->num_extra_params < MAX_EXTRA_PARAMS) {
131 thiz->extra_params[thiz->num_extra_params] = param;
132 thiz->num_extra_params++;
137 ensure_context (GstBaseTransform * trans)
139 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
141 if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
142 GST_INFO_OBJECT (thiz, "Found context from neighbour %" GST_PTR_FORMAT,
145 if (gst_msdk_context_get_job_type (thiz->context) & GST_MSDK_JOB_VPP) {
146 GstMsdkContext *parent_context;
148 parent_context = thiz->context;
149 thiz->context = gst_msdk_context_new_with_parent (parent_context);
150 gst_object_unref (parent_context);
152 GST_INFO_OBJECT (thiz,
153 "Creating new context %" GST_PTR_FORMAT " with joined session",
156 gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_VPP);
159 if (!gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz),
160 thiz->hardware, GST_MSDK_JOB_VPP))
162 GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
166 gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);
172 create_output_buffer (GstMsdkVPP * thiz)
176 GstBufferPool *pool = thiz->srcpad_buffer_pool;
178 g_return_val_if_fail (pool != NULL, NULL);
180 if (!gst_buffer_pool_is_active (pool) &&
181 !gst_buffer_pool_set_active (pool, TRUE))
182 goto error_activate_pool;
185 ret = gst_buffer_pool_acquire_buffer (pool, &outbuf, NULL);
186 if (ret != GST_FLOW_OK || !outbuf)
187 goto error_create_buffer;
194 GST_ERROR_OBJECT (thiz, "failed to activate output video buffer pool");
199 GST_ERROR_OBJECT (thiz, "failed to create output video buffer");
205 gst_msdkvpp_prepare_output_buffer (GstBaseTransform * trans,
206 GstBuffer * inbuf, GstBuffer ** outbuf_ptr)
208 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
210 if (gst_base_transform_is_passthrough (trans)) {
215 *outbuf_ptr = create_output_buffer (thiz);
216 return *outbuf_ptr ? GST_FLOW_OK : GST_FLOW_ERROR;
219 static GstBufferPool *
220 gst_msdkvpp_create_buffer_pool (GstMsdkVPP * thiz, GstPadDirection direction,
221 GstCaps * caps, guint min_num_buffers)
223 GstBufferPool *pool = NULL;
224 GstStructure *config;
225 GstAllocator *allocator = NULL;
227 GstVideoInfo *pool_info = NULL;
228 GstVideoAlignment align;
229 GstAllocationParams params = { 0, 31, 0, 0, };
230 mfxFrameAllocResponse *alloc_resp = NULL;
231 gboolean use_dmabuf = FALSE;
233 if (direction == GST_PAD_SINK) {
234 alloc_resp = &thiz->in_alloc_resp;
235 pool_info = &thiz->sinkpad_buffer_pool_info;
236 use_dmabuf = thiz->use_sinkpad_dmabuf;
237 } else if (direction == GST_PAD_SRC) {
238 alloc_resp = &thiz->out_alloc_resp;
239 pool_info = &thiz->srcpad_buffer_pool_info;
240 use_dmabuf = thiz->use_srcpad_dmabuf;
243 pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
247 if (!gst_video_info_from_caps (&info, caps))
248 goto error_no_video_info;
250 gst_msdk_set_video_alignment (&info, &align);
251 gst_video_info_align (&info, &align);
255 gst_msdk_dmabuf_allocator_new (thiz->context, &info, alloc_resp);
256 else if (thiz->use_video_memory)
257 allocator = gst_msdk_video_allocator_new (thiz->context, &info, alloc_resp);
259 allocator = gst_msdk_system_allocator_new (&info);
262 goto error_no_allocator;
264 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
265 gst_buffer_pool_config_set_params (config, caps, info.size, min_num_buffers,
268 gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
269 gst_buffer_pool_config_add_option (config,
270 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
271 if (thiz->use_video_memory) {
272 gst_buffer_pool_config_add_option (config,
273 GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
275 gst_buffer_pool_config_add_option (config,
276 GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
279 gst_buffer_pool_config_set_video_alignment (config, &align);
280 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
281 gst_object_unref (allocator);
283 if (!gst_buffer_pool_set_config (pool, config))
284 goto error_pool_config;
286 /* Updating pool_info with algined info of allocator */
293 GST_INFO_OBJECT (thiz, "Failed to create bufferpool");
298 GST_INFO_OBJECT (thiz, "Failed to get Video info from caps");
303 GST_INFO_OBJECT (thiz, "Failed to create allocator");
305 gst_object_unref (pool);
310 GST_INFO_OBJECT (thiz, "Failed to set config");
312 gst_object_unref (pool);
314 gst_object_unref (allocator);
320 _gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
324 for (i = 0; i < gst_caps_get_size (caps); i++) {
325 GstCapsFeatures *const features = gst_caps_get_features (caps, i);
326 /* Skip ANY features, we need an exact match for correct evaluation */
327 if (gst_caps_features_is_any (features))
329 if (gst_caps_features_contains (features, feature))
336 gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query)
338 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
340 GstBufferPool *pool = NULL;
341 GstStructure *config = NULL;
343 guint size = 0, min_buffers = 0, max_buffers = 0;
344 GstAllocator *allocator = NULL;
345 GstAllocationParams params;
346 gboolean update_pool = FALSE;
348 gst_query_parse_allocation (query, &caps, NULL);
350 GST_ERROR_OBJECT (thiz, "Failed to parse the decide_allocation caps");
353 if (!gst_video_info_from_caps (&info, caps)) {
354 GST_ERROR_OBJECT (thiz, "Failed to get video info");
357 /* if downstream allocation query supports dmabuf-capsfeatures,
358 * we do allocate dmabuf backed memory */
359 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
360 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
361 thiz->use_srcpad_dmabuf = TRUE;
364 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL))
365 thiz->add_video_meta = TRUE;
367 thiz->add_video_meta = FALSE;
369 /* Check whether the query has pool */
370 if (gst_query_get_n_allocation_pools (query) > 0)
373 /* increase the min_buffers with number of concurrent vpp operations */
374 min_buffers += thiz->async_depth;
376 /* invalidate the cached pool if there is an allocation_query */
377 if (thiz->srcpad_buffer_pool)
378 gst_object_unref (thiz->srcpad_buffer_pool);
380 /* Always create a pool for vpp out buffers. Each of the msdk element
381 * has to create it's own mfxsurfacepool which is an msdk contraint.
382 * For eg: Each Msdk component (vpp, dec and enc) will invoke the external
383 * Frame allocator for video-memory usage.So sharing the pool between
384 * gst-msdk elements might not be a good idea, rather each element
385 * can check the buffer type (whether it is from msdk-buffer pool)
386 * to make sure there is no copy. Since we share the context between
387 * msdk elements, using buffers from one sdk's framealloator in another
388 * sdk-components is perfectly fine */
389 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, caps, min_buffers);
390 thiz->srcpad_buffer_pool = pool;
392 /* get the configured pool properties inorder to set in query */
393 config = gst_buffer_pool_get_config (pool);
394 gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
396 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
397 gst_query_add_allocation_param (query, allocator, ¶ms);
398 gst_structure_free (config);
401 gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
404 gst_query_add_allocation_pool (query, pool, size, min_buffers, max_buffers);
406 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
408 /* Fixme if downstream doesn't have videometa support, msdkvpp should
409 * copy the output buffers */
415 gst_msdkvpp_propose_allocation (GstBaseTransform * trans,
416 GstQuery * decide_query, GstQuery * query)
418 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
420 GstBufferPool *pool = NULL;
421 GstAllocator *allocator = NULL;
423 GstStructure *config;
425 GstAllocationParams params;
427 guint min_buffers = thiz->async_depth + 1;
429 gst_query_parse_allocation (query, &caps, &need_pool);
431 GST_ERROR_OBJECT (thiz, "Failed to parse the allocation caps");
435 if (!gst_video_info_from_caps (&info, caps)) {
436 GST_ERROR_OBJECT (thiz, "Failed to get video info");
440 /* if upstream allocation query supports dmabuf-capsfeatures,
441 * we do allocate dmabuf backed memory */
442 if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
443 GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory");
444 thiz->use_sinkpad_dmabuf = TRUE;
448 /* alwys provide a new pool for upstream to help re-negotiation
449 * more info here: https://bugzilla.gnome.org/show_bug.cgi?id=748344 */
450 pool = gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
454 /* Update the internal pool if any allocation attribute changed */
455 if (!gst_video_info_is_equal (&thiz->sinkpad_buffer_pool_info, &info)) {
456 gst_object_unref (thiz->sinkpad_buffer_pool);
457 thiz->sinkpad_buffer_pool = gst_msdkvpp_create_buffer_pool (thiz,
458 GST_PAD_SINK, caps, min_buffers);
461 /* get the size and allocator params from configured pool and set it in query */
463 pool = gst_object_ref (thiz->sinkpad_buffer_pool);
464 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
465 gst_buffer_pool_config_get_params (config, NULL, &size, NULL, NULL);
466 if (gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
467 gst_query_add_allocation_param (query, allocator, ¶ms);
468 gst_structure_free (config);
470 /* if upstream does't have a pool requirement, set only
471 * size, min_buffers and max_buffers in query */
472 gst_query_add_allocation_pool (query, need_pool ? pool : NULL, size,
474 gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
476 gst_object_unref (pool);
478 return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
479 decide_query, query);
483 get_surface_from_pool (GstMsdkVPP * thiz, GstBufferPool * pool,
484 GstBufferPoolAcquireParams * params)
486 GstBuffer *new_buffer;
487 mfxFrameSurface1 *new_surface;
488 MsdkSurface *msdk_surface;
490 if (!gst_buffer_pool_is_active (pool) &&
491 !gst_buffer_pool_set_active (pool, TRUE)) {
492 GST_ERROR_OBJECT (pool, "failed to activate buffer pool");
496 if (gst_buffer_pool_acquire_buffer (pool, &new_buffer, params) != GST_FLOW_OK) {
497 GST_ERROR_OBJECT (pool, "failed to acquire a buffer from pool");
501 if (gst_msdk_is_msdk_buffer (new_buffer))
502 new_surface = gst_msdk_get_surface_from_buffer (new_buffer);
504 GST_ERROR_OBJECT (pool, "the acquired memory is not MSDK memory");
508 msdk_surface = g_slice_new0 (MsdkSurface);
509 msdk_surface->surface = new_surface;
510 msdk_surface->buf = new_buffer;
516 import_dmabuf_to_msdk_surface (GstMsdkVPP * thiz, GstBuffer * buf,
517 MsdkSurface * msdk_surface)
519 GstMemory *mem = NULL;
522 GstMsdkMemoryID *msdk_mid = NULL;
523 mfxFrameSurface1 *mfx_surface = NULL;
526 mem = gst_buffer_peek_memory (buf, 0);
527 fd = gst_dmabuf_memory_get_fd (mem);
531 vinfo = thiz->sinkpad_info;
533 /* Update offset/stride/size if there is VideoMeta attached to
535 vmeta = gst_buffer_get_video_meta (buf);
537 if (GST_VIDEO_INFO_FORMAT (&vinfo) != vmeta->format ||
538 GST_VIDEO_INFO_WIDTH (&vinfo) != vmeta->width ||
539 GST_VIDEO_INFO_HEIGHT (&vinfo) != vmeta->height ||
540 GST_VIDEO_INFO_N_PLANES (&vinfo) != vmeta->n_planes) {
541 GST_ERROR_OBJECT (thiz, "VideoMeta attached to buffer is not matching"
542 "the negotiated width/height/format");
545 for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&vinfo); ++i) {
546 GST_VIDEO_INFO_PLANE_OFFSET (&vinfo, i) = vmeta->offset[i];
547 GST_VIDEO_INFO_PLANE_STRIDE (&vinfo, i) = vmeta->stride[i];
549 GST_VIDEO_INFO_SIZE (&vinfo) = gst_buffer_get_size (buf);
552 /* Upstream neither accepted the msdk pool nor the msdk buffer size restrictions.
553 * Current media-driver and GMMLib will fail due to strict memory size restrictions.
554 * Ideally, media-driver should accept what ever memory coming from other drivers
555 * in case of dmabuf-import and this is how the intel-vaapi-driver works.
556 * For now, in order to avoid any crash we check the buffer size and fallback
557 * to copy frame method.
559 * See this: https://github.com/intel/media-driver/issues/169
561 if (GST_VIDEO_INFO_SIZE (&vinfo) <
562 GST_VIDEO_INFO_SIZE (&thiz->sinkpad_buffer_pool_info))
565 mfx_surface = msdk_surface->surface;
566 msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
568 /* release the internal memory storage of associated mfxSurface */
569 gst_msdk_replace_mfx_memid (thiz->context, mfx_surface, VA_INVALID_ID);
571 /* export dmabuf to vasurface */
572 if (!gst_msdk_export_dmabuf_to_vasurface (thiz->context, &vinfo, fd,
580 get_msdk_surface_from_input_buffer (GstMsdkVPP * thiz, GstBuffer * inbuf)
582 GstVideoFrame src_frame, out_frame;
583 MsdkSurface *msdk_surface;
584 GstMemory *mem = NULL;
586 if (gst_msdk_is_msdk_buffer (inbuf)) {
587 msdk_surface = g_slice_new0 (MsdkSurface);
588 msdk_surface->surface = gst_msdk_get_surface_from_buffer (inbuf);
589 msdk_surface->buf = gst_buffer_ref (inbuf);
593 /* If upstream hasn't accpeted the proposed msdk bufferpool,
594 * just copy frame (if not dmabuf backed) to msdk buffer and
595 * take a surface from it. */
597 get_surface_from_pool (thiz, thiz->sinkpad_buffer_pool, NULL)))
601 /************ dmabuf-import ************* */
602 /* if upstream provided a dmabuf backed memory, but not an msdk
603 * buffer, we could export the dmabuf to underlined vasurface */
604 mem = gst_buffer_peek_memory (inbuf, 0);
605 if (gst_is_dmabuf_memory (mem)) {
606 if (import_dmabuf_to_msdk_surface (thiz, inbuf, msdk_surface))
609 GST_INFO_OBJECT (thiz, "Upstream dmabuf-backed memory is not imported"
610 "to the msdk surface, fall back to the copy input frame method");
614 if (!gst_video_frame_map (&src_frame, &thiz->sinkpad_info, inbuf,
616 GST_ERROR_OBJECT (thiz, "failed to map the frame for source");
620 if (!gst_video_frame_map (&out_frame, &thiz->sinkpad_buffer_pool_info,
621 msdk_surface->buf, GST_MAP_WRITE)) {
622 GST_ERROR_OBJECT (thiz, "failed to map the frame for destination");
623 gst_video_frame_unmap (&src_frame);
627 if (!gst_video_frame_copy (&out_frame, &src_frame)) {
628 GST_ERROR_OBJECT (thiz, "failed to copy frame");
629 gst_video_frame_unmap (&out_frame);
630 gst_video_frame_unmap (&src_frame);
634 gst_video_frame_unmap (&out_frame);
635 gst_video_frame_unmap (&src_frame);
644 gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf,
647 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
648 GstClockTime timestamp;
649 GstFlowReturn ret = GST_FLOW_OK;
651 mfxSyncPoint sync_point = NULL;
653 MsdkSurface *in_surface = NULL;
654 MsdkSurface *out_surface = NULL;
656 timestamp = GST_BUFFER_TIMESTAMP (inbuf);
658 in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf);
660 return GST_FLOW_ERROR;
662 if (gst_msdk_is_msdk_buffer (outbuf)) {
663 out_surface = g_slice_new0 (MsdkSurface);
664 out_surface->surface = gst_msdk_get_surface_from_buffer (outbuf);
666 GST_ERROR ("Failed to get msdk outsurface!");
667 return GST_FLOW_ERROR;
670 session = gst_msdk_context_get_session (thiz->context);
672 /* outer loop is for handling FrameRate Control and deinterlace use cases */
676 MFXVideoVPP_RunFrameVPPAsync (session, in_surface->surface,
677 out_surface->surface, NULL, &sync_point);
678 if (status != MFX_WRN_DEVICE_BUSY)
680 /* If device is busy, wait 1ms and retry, as per MSDK's recommendation */
684 if (status != MFX_ERR_NONE && status != MFX_ERR_MORE_DATA
685 && status != MFX_ERR_MORE_SURFACE)
688 /* No output generated */
689 if (status == MFX_ERR_MORE_DATA)
690 goto error_more_data;
693 MFXVideoCORE_SyncOperation (session, sync_point, 10000);
695 /* More than one output buffers are generated */
696 if (status == MFX_ERR_MORE_SURFACE) {
697 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
698 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
699 timestamp += thiz->buffer_duration;
700 ret = gst_pad_push (GST_BASE_TRANSFORM_SRC_PAD (trans), outbuf);
701 if (ret != GST_FLOW_OK)
702 goto error_push_buffer;
703 outbuf = create_output_buffer (thiz);
705 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
706 GST_BUFFER_DURATION (outbuf) = thiz->buffer_duration;
708 } while (status == MFX_ERR_MORE_SURFACE);
710 free_msdk_surface (in_surface);
714 GST_ERROR_OBJECT (thiz, "MSDK Failed to do VPP");
715 free_msdk_surface (in_surface);
716 free_msdk_surface (out_surface);
717 return GST_FLOW_ERROR;
720 GST_WARNING_OBJECT (thiz,
721 "MSDK Requries additional input for processing, "
722 "Retruning FLOW_DROPPED since no output buffer was generated");
723 free_msdk_surface (in_surface);
724 return GST_BASE_TRANSFORM_FLOW_DROPPED;
728 free_msdk_surface (in_surface);
729 free_msdk_surface (out_surface);
730 GST_DEBUG_OBJECT (thiz, "failed to push output buffer: %s",
731 gst_flow_get_name (ret));
737 gst_msdkvpp_close (GstMsdkVPP * thiz)
744 GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
745 status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
746 if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
747 GST_WARNING_OBJECT (thiz, "Encoder close failed (%s)",
748 msdk_status_to_string (status));
752 gst_object_replace ((GstObject **) & thiz->context, NULL);
754 memset (&thiz->param, 0, sizeof (thiz->param));
756 if (thiz->sinkpad_buffer_pool)
757 gst_object_unref (thiz->sinkpad_buffer_pool);
758 thiz->sinkpad_buffer_pool = NULL;
759 if (thiz->srcpad_buffer_pool)
760 gst_object_unref (thiz->srcpad_buffer_pool);
761 thiz->srcpad_buffer_pool = NULL;
763 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
764 gst_video_info_init (&thiz->sinkpad_info);
765 gst_video_info_init (&thiz->srcpad_info);
769 ensure_filters (GstMsdkVPP * thiz)
774 if (thiz->flags & GST_MSDK_FLAG_DENOISE) {
775 mfxExtVPPDenoise *mfx_denoise = &thiz->mfx_denoise;
776 mfx_denoise->Header.BufferId = MFX_EXTBUFF_VPP_DENOISE;
777 mfx_denoise->Header.BufferSz = sizeof (mfxExtVPPDenoise);
778 mfx_denoise->DenoiseFactor = thiz->denoise_factor;
779 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_denoise);
780 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_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);
791 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_ROTATION;
796 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE) {
797 mfxExtVPPDeinterlacing *mfx_deinterlace = &thiz->mfx_deinterlace;
798 mfx_deinterlace->Header.BufferId = MFX_EXTBUFF_VPP_DEINTERLACING;
799 mfx_deinterlace->Header.BufferSz = sizeof (mfxExtVPPDeinterlacing);
800 mfx_deinterlace->Mode = thiz->deinterlace_method;
801 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_deinterlace);
802 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_DEINTERLACING;
806 /* Colorbalance(ProcAmp) */
807 if (thiz->flags & (GST_MSDK_FLAG_HUE | GST_MSDK_FLAG_SATURATION |
808 GST_MSDK_FLAG_BRIGHTNESS | GST_MSDK_FLAG_CONTRAST)) {
809 mfxExtVPPProcAmp *mfx_procamp = &thiz->mfx_procamp;
810 mfx_procamp->Header.BufferId = MFX_EXTBUFF_VPP_PROCAMP;
811 mfx_procamp->Header.BufferSz = sizeof (mfxExtVPPProcAmp);
812 mfx_procamp->Hue = thiz->hue;
813 mfx_procamp->Saturation = thiz->saturation;
814 mfx_procamp->Brightness = thiz->brightness;
815 mfx_procamp->Contrast = thiz->contrast;
816 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_procamp);
817 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_PROCAMP;
821 /* Detail/Edge enhancement */
822 if (thiz->flags & GST_MSDK_FLAG_DETAIL) {
823 mfxExtVPPDetail *mfx_detail = &thiz->mfx_detail;
824 mfx_detail->Header.BufferId = MFX_EXTBUFF_VPP_DETAIL;
825 mfx_detail->Header.BufferSz = sizeof (mfxExtVPPDetail);
826 mfx_detail->DetailFactor = thiz->detail;
827 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_detail);
828 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_DETAIL;
834 mfxExtVPPDoUse *mfx_vpp_douse = &thiz->mfx_vpp_douse;
835 mfx_vpp_douse->Header.BufferId = MFX_EXTBUFF_VPP_DOUSE;
836 mfx_vpp_douse->Header.BufferSz = sizeof (mfxExtVPPDoUse);
837 mfx_vpp_douse->NumAlg = n_filters;
838 mfx_vpp_douse->AlgList = thiz->max_filter_algorithms;
839 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_vpp_douse);
843 if (thiz->flags & GST_MSDK_FLAG_MIRRORING) {
844 mfxExtVPPMirroring *mfx_mirroring = &thiz->mfx_mirroring;
845 mfx_mirroring->Header.BufferId = MFX_EXTBUFF_VPP_MIRRORING;
846 mfx_mirroring->Header.BufferSz = sizeof (mfxExtVPPMirroring);
847 mfx_mirroring->Type = thiz->mirroring;
848 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_mirroring);
849 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_MIRRORING;
854 if (thiz->flags & GST_MSDK_FLAG_SCALING_MODE) {
855 mfxExtVPPScaling *mfx_scaling = &thiz->mfx_scaling;
856 mfx_scaling->Header.BufferId = MFX_EXTBUFF_VPP_SCALING;
857 mfx_scaling->Header.BufferSz = sizeof (mfxExtVPPScaling);
858 mfx_scaling->ScalingMode = thiz->scaling_mode;
859 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_scaling);
860 thiz->max_filter_algorithms[n_filters] = MFX_EXTBUFF_VPP_SCALING;
865 if (thiz->flags & GST_MSDK_FLAG_FRC) {
866 mfxExtVPPFrameRateConversion *mfx_frc = &thiz->mfx_frc;
867 mfx_frc->Header.BufferId = MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
868 mfx_frc->Header.BufferSz = sizeof (mfxExtVPPFrameRateConversion);
869 mfx_frc->Algorithm = thiz->frc_algm;
870 gst_msdkvpp_add_extra_param (thiz, (mfxExtBuffer *) mfx_frc);
871 thiz->max_filter_algorithms[n_filters] =
872 MFX_EXTBUFF_VPP_FRAME_RATE_CONVERSION;
878 gst_msdkvpp_set_passthrough (GstMsdkVPP * thiz)
880 gboolean passthrough = TRUE;
882 /* no passthrough if any of the filter algorithm is enabled */
886 /* vpp could be needed in some specific circumstances, for eg:
887 * input surface is dmabuf and output must be videomemory. So far
888 * the underline iHD driver doesn't seems to support dmabuf mapping,
889 * so we could explicitly ask msdkvpp to provide non-dambuf videomemory
890 * surfaces as output thourgh capsfileters */
894 /* no passthrough if there is change in out width,height or format */
895 if (GST_VIDEO_INFO_WIDTH (&thiz->sinkpad_info) !=
896 GST_VIDEO_INFO_WIDTH (&thiz->srcpad_info)
897 || GST_VIDEO_INFO_HEIGHT (&thiz->sinkpad_info) !=
898 GST_VIDEO_INFO_HEIGHT (&thiz->srcpad_info)
899 || GST_VIDEO_INFO_FORMAT (&thiz->sinkpad_info) !=
900 GST_VIDEO_INFO_FORMAT (&thiz->srcpad_info))
903 GST_OBJECT_UNLOCK (thiz);
904 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (thiz), passthrough);
905 GST_OBJECT_LOCK (thiz);
909 gst_msdkvpp_initialize (GstMsdkVPP * thiz)
913 mfxFrameAllocRequest request[2];
915 if (!thiz->context) {
916 GST_WARNING_OBJECT (thiz, "No MSDK Context");
920 GST_OBJECT_LOCK (thiz);
921 session = gst_msdk_context_get_session (thiz->context);
923 if (thiz->use_video_memory) {
924 gst_msdk_set_frame_allocator (thiz->context);
925 thiz->param.IOPattern =
926 MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
928 thiz->param.IOPattern =
929 MFX_IOPATTERN_IN_SYSTEM_MEMORY | MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
932 /* update input video attributes */
933 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.In,
934 &thiz->sinkpad_info);
936 /* update output video attributes, only CSC and Scaling are supported for now */
937 gst_msdk_set_mfx_frame_info_from_video_info (&thiz->param.vpp.Out,
940 /* use msdk frame rarte control if there is a mismatch in In & OUt fps */
941 if (GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info) &&
942 (GST_VIDEO_INFO_FPS_N (&thiz->sinkpad_info) !=
943 GST_VIDEO_INFO_FPS_N (&thiz->srcpad_info)
944 || GST_VIDEO_INFO_FPS_D (&thiz->sinkpad_info) !=
945 GST_VIDEO_INFO_FPS_D (&thiz->srcpad_info))) {
946 thiz->flags |= GST_MSDK_FLAG_FRC;
947 /* So far this is the only algorithm which is working somewhat good */
948 thiz->frc_algm = MFX_FRCALGM_PRESERVE_TIMESTAMP;
951 /* work-around to avoid zero fps in msdk structure */
952 if (!thiz->param.vpp.In.FrameRateExtN)
953 thiz->param.vpp.In.FrameRateExtN = 30;
954 if (!thiz->param.vpp.Out.FrameRateExtN)
955 thiz->param.vpp.Out.FrameRateExtN = thiz->param.vpp.In.FrameRateExtN;
957 /* set vpp out picstruct as progressive if deinterlacing enabled */
958 if (thiz->flags & GST_MSDK_FLAG_DEINTERLACE)
959 thiz->param.vpp.Out.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
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 /* Enable the required filters */
973 ensure_filters (thiz);
975 /* set passthrough according to filter operation change */
976 gst_msdkvpp_set_passthrough (thiz);
978 /* Add exteneded buffers */
979 if (thiz->num_extra_params) {
980 thiz->param.NumExtParam = thiz->num_extra_params;
981 thiz->param.ExtParam = thiz->extra_params;
984 status = MFXVideoVPP_QueryIOSurf (session, &thiz->param, request);
985 if (status < MFX_ERR_NONE) {
986 GST_ERROR_OBJECT (thiz, "VPP Query IO surfaces failed (%s)",
987 msdk_status_to_string (status));
989 } else if (status > MFX_ERR_NONE) {
990 GST_WARNING_OBJECT (thiz, "VPP Query IO surfaces returned: %s",
991 msdk_status_to_string (status));
994 if (thiz->use_video_memory) {
995 /* Input surface pool pre-allocation */
996 request[0].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
997 if (thiz->use_sinkpad_dmabuf)
998 request[0].Type |= MFX_MEMTYPE_EXPORT_FRAME;
999 gst_msdk_frame_alloc (thiz->context, &(request[0]), &thiz->in_alloc_resp);
1001 /* Output surface pool pre-allocation */
1002 request[1].Type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET;
1003 if (thiz->use_srcpad_dmabuf)
1004 request[1].Type |= MFX_MEMTYPE_EXPORT_FRAME;
1005 gst_msdk_frame_alloc (thiz->context, &(request[1]), &thiz->out_alloc_resp);
1008 thiz->in_num_surfaces = request[0].NumFrameSuggested;
1009 thiz->out_num_surfaces = request[1].NumFrameSuggested;
1012 status = MFXVideoVPP_Init (session, &thiz->param);
1013 if (status < MFX_ERR_NONE) {
1014 GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
1016 } else if (status > MFX_ERR_NONE) {
1017 GST_WARNING_OBJECT (thiz, "Init returned: %s",
1018 msdk_status_to_string (status));
1021 GST_OBJECT_UNLOCK (thiz);
1025 GST_OBJECT_UNLOCK (thiz);
1027 gst_object_replace ((GstObject **) & thiz->context, NULL);
1032 gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
1035 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1036 GstVideoInfo in_info, out_info;
1037 gboolean sinkpad_info_changed = FALSE;
1038 gboolean srcpad_info_changed = FALSE;
1039 gboolean deinterlace;
1041 if (gst_caps_get_features (caps, 0) != gst_caps_get_features (out_caps, 0))
1044 gst_video_info_from_caps (&in_info, caps);
1045 gst_video_info_from_caps (&out_info, out_caps);
1047 if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
1048 sinkpad_info_changed = TRUE;
1049 if (!gst_video_info_is_equal (&out_info, &thiz->srcpad_info))
1050 srcpad_info_changed = TRUE;
1052 thiz->sinkpad_info = in_info;
1053 thiz->srcpad_info = out_info;
1055 thiz->use_video_memory = TRUE;
1057 thiz->use_video_memory = FALSE;
1060 if (!sinkpad_info_changed && !srcpad_info_changed)
1063 /* check for deinterlace requirement */
1064 deinterlace = gst_msdkvpp_is_deinterlace_enabled (thiz, &in_info);
1066 thiz->flags |= GST_MSDK_FLAG_DEINTERLACE;
1068 thiz->buffer_duration = GST_VIDEO_INFO_FPS_N (&out_info) > 0 ?
1069 gst_util_uint64_scale (GST_SECOND, GST_VIDEO_INFO_FPS_D (&out_info),
1070 GST_VIDEO_INFO_FPS_N (&out_info)) : 0;
1072 if (!gst_msdkvpp_initialize (thiz))
1075 /* Ensure sinkpad buffer pool */
1076 thiz->sinkpad_buffer_pool =
1077 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SINK, caps,
1078 thiz->in_num_surfaces);
1079 if (!thiz->sinkpad_buffer_pool) {
1080 GST_ERROR_OBJECT (thiz, "Failed to ensure the sinkpad buffer pool");
1083 /* Ensure a srcpad buffer pool */
1084 thiz->srcpad_buffer_pool =
1085 gst_msdkvpp_create_buffer_pool (thiz, GST_PAD_SRC, out_caps,
1086 thiz->out_num_surfaces);
1087 if (!thiz->srcpad_buffer_pool) {
1088 GST_ERROR_OBJECT (thiz, "Failed to ensure the srcpad buffer pool");
1096 pad_can_dmabuf (GstMsdkVPP * thiz, GstPadDirection direction, GstCaps * filter)
1098 gboolean ret = FALSE;
1099 GstCaps *caps, *out_caps;
1101 GstBaseTransform *trans = GST_BASE_TRANSFORM (thiz);
1103 if (direction == GST_PAD_SRC)
1104 pad = GST_BASE_TRANSFORM_SRC_PAD (trans);
1106 pad = GST_BASE_TRANSFORM_SINK_PAD (trans);
1108 /* make a copy of filter caps since we need to alter the structure
1109 * by adding dmabuf-capsfeatures */
1110 caps = gst_caps_copy (filter);
1111 gst_caps_set_features (caps, 0,
1112 gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_DMABUF));
1114 out_caps = gst_pad_peer_query_caps (pad, caps);
1118 if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
1119 || out_caps == caps)
1122 if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
1126 gst_caps_unref (caps);
1128 gst_caps_unref (out_caps);
1133 gst_msdkvpp_fixate_caps (GstBaseTransform * trans,
1134 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps)
1136 GstMsdkVPP *thiz = GST_MSDKVPP (trans);
1137 GstCaps *result = NULL;
1138 gboolean *use_dmabuf;
1140 if (direction == GST_PAD_SRC) {
1141 result = gst_caps_fixate (result);
1142 use_dmabuf = &thiz->use_sinkpad_dmabuf;
1144 result = gst_msdkvpp_fixate_srccaps (thiz, caps, othercaps);
1145 use_dmabuf = &thiz->use_srcpad_dmabuf;
1148 GST_DEBUG_OBJECT (trans, "fixated to %" GST_PTR_FORMAT, result);
1149 gst_caps_unref (othercaps);
1151 if (pad_can_dmabuf (thiz,
1152 direction == GST_PAD_SRC ? GST_PAD_SINK : GST_PAD_SRC, result)) {
1153 gst_caps_set_features (result, 0,
1154 gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
1161 /* Generic code for now, requires changes in future when we
1162 * add hardware query for supported formats, Framerate control etc */
1164 gst_msdkvpp_transform_caps (GstBaseTransform * trans,
1165 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
1169 GST_DEBUG_OBJECT (trans,
1170 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
1171 (direction == GST_PAD_SINK) ? "sink" : "src");
1173 if (direction == GST_PAD_SRC)
1174 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_sink_factory);
1176 out_caps = gst_static_pad_template_get_caps (&gst_msdkvpp_src_factory);
1178 if (out_caps && filter) {
1179 GstCaps *intersection;
1181 intersection = gst_caps_intersect_full (out_caps, filter,
1182 GST_CAPS_INTERSECT_FIRST);
1183 gst_caps_unref (out_caps);
1184 out_caps = intersection;
1187 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, out_caps);
1192 gst_msdkvpp_start (GstBaseTransform * trans)
1194 if (!ensure_context (trans))
1200 gst_msdkvpp_stop (GstBaseTransform * trans)
1202 gst_msdkvpp_close (GST_MSDKVPP (trans));
1207 gst_msdkvpp_set_property (GObject * object, guint prop_id,
1208 const GValue * value, GParamSpec * pspec)
1210 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1214 thiz->hardware = g_value_get_boolean (value);
1216 case PROP_ASYNC_DEPTH:
1217 thiz->async_depth = g_value_get_uint (value);
1220 thiz->denoise_factor = g_value_get_uint (value);
1221 thiz->flags |= GST_MSDK_FLAG_DENOISE;
1224 thiz->rotation = g_value_get_enum (value);
1225 thiz->flags |= GST_MSDK_FLAG_ROTATION;
1227 case PROP_DEINTERLACE_MODE:
1228 thiz->deinterlace_mode = g_value_get_enum (value);
1230 case PROP_DEINTERLACE_METHOD:
1231 thiz->deinterlace_method = g_value_get_enum (value);
1234 thiz->hue = g_value_get_float (value);
1235 thiz->flags |= GST_MSDK_FLAG_HUE;
1237 case PROP_SATURATION:
1238 thiz->saturation = g_value_get_float (value);
1239 thiz->flags |= GST_MSDK_FLAG_SATURATION;
1241 case PROP_BRIGHTNESS:
1242 thiz->brightness = g_value_get_float (value);
1243 thiz->flags |= GST_MSDK_FLAG_BRIGHTNESS;
1246 thiz->contrast = g_value_get_float (value);
1247 thiz->flags |= GST_MSDK_FLAG_CONTRAST;
1250 thiz->detail = g_value_get_uint (value);
1251 thiz->flags |= GST_MSDK_FLAG_DETAIL;
1253 case PROP_MIRRORING:
1254 thiz->mirroring = g_value_get_enum (value);
1255 thiz->flags |= GST_MSDK_FLAG_MIRRORING;
1257 case PROP_SCALING_MODE:
1258 thiz->scaling_mode = g_value_get_enum (value);
1259 thiz->flags |= GST_MSDK_FLAG_SCALING_MODE;
1261 case PROP_FORCE_ASPECT_RATIO:
1262 thiz->keep_aspect = g_value_get_boolean (value);
1264 case PROP_FRC_ALGORITHM:
1265 thiz->frc_algm = g_value_get_enum (value);
1268 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1274 gst_msdkvpp_get_property (GObject * object, guint prop_id,
1275 GValue * value, GParamSpec * pspec)
1277 GstMsdkVPP *thiz = GST_MSDKVPP (object);
1281 g_value_set_boolean (value, thiz->hardware);
1283 case PROP_ASYNC_DEPTH:
1284 g_value_set_uint (value, thiz->async_depth);
1287 g_value_set_uint (value, thiz->denoise_factor);
1290 g_value_set_enum (value, thiz->rotation);
1292 case PROP_DEINTERLACE_MODE:
1293 g_value_set_enum (value, thiz->deinterlace_mode);
1295 case PROP_DEINTERLACE_METHOD:
1296 g_value_set_enum (value, thiz->deinterlace_method);
1299 g_value_set_float (value, thiz->hue);
1301 case PROP_SATURATION:
1302 g_value_set_float (value, thiz->saturation);
1304 case PROP_BRIGHTNESS:
1305 g_value_set_float (value, thiz->brightness);
1308 g_value_set_float (value, thiz->contrast);
1311 g_value_set_uint (value, thiz->detail);
1313 case PROP_MIRRORING:
1314 g_value_set_enum (value, thiz->mirroring);
1316 case PROP_SCALING_MODE:
1317 g_value_set_enum (value, thiz->scaling_mode);
1319 case PROP_FORCE_ASPECT_RATIO:
1320 g_value_set_boolean (value, thiz->keep_aspect);
1322 case PROP_FRC_ALGORITHM:
1323 g_value_set_enum (value, thiz->frc_algm);
1326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1332 gst_msdkvpp_finalize (GObject * object)
1334 G_OBJECT_CLASS (parent_class)->finalize (object);
1338 gst_msdkvpp_set_context (GstElement * element, GstContext * context)
1340 GstMsdkContext *msdk_context = NULL;
1341 GstMsdkVPP *thiz = GST_MSDKVPP (element);
1343 if (gst_msdk_context_get_context (context, &msdk_context)) {
1344 gst_object_replace ((GstObject **) & thiz->context,
1345 (GstObject *) msdk_context);
1346 gst_object_unref (msdk_context);
1349 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
1353 gst_msdkvpp_class_init (GstMsdkVPPClass * klass)
1355 GObjectClass *gobject_class;
1356 GstElementClass *element_class;
1357 GstBaseTransformClass *trans_class;
1358 GParamSpec *obj_properties[PROP_N] = { NULL, };
1360 gobject_class = G_OBJECT_CLASS (klass);
1361 element_class = GST_ELEMENT_CLASS (klass);
1362 trans_class = GST_BASE_TRANSFORM_CLASS (klass);
1364 gobject_class->set_property = gst_msdkvpp_set_property;
1365 gobject_class->get_property = gst_msdkvpp_get_property;
1366 gobject_class->finalize = gst_msdkvpp_finalize;
1368 element_class->set_context = gst_msdkvpp_set_context;
1370 gst_element_class_add_static_pad_template (element_class,
1371 &gst_msdkvpp_src_factory);
1372 gst_element_class_add_static_pad_template (element_class,
1373 &gst_msdkvpp_sink_factory);
1375 gst_element_class_set_static_metadata (element_class,
1376 "MSDK Video Postprocessor",
1377 "Filter/Converter/Video;Filter/Converter/Video/Scaler;"
1378 "Filter/Effect/Video;Filter/Effect/Video/Deinterlace",
1379 "A MediaSDK Video Postprocessing Filter",
1380 "Sreerenj Balachandrn <sreerenj.balachandran@intel.com>");
1382 trans_class->start = GST_DEBUG_FUNCPTR (gst_msdkvpp_start);
1383 trans_class->stop = GST_DEBUG_FUNCPTR (gst_msdkvpp_stop);
1384 trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform_caps);
1385 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_fixate_caps);
1386 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_msdkvpp_set_caps);
1387 trans_class->transform = GST_DEBUG_FUNCPTR (gst_msdkvpp_transform);
1388 trans_class->propose_allocation =
1389 GST_DEBUG_FUNCPTR (gst_msdkvpp_propose_allocation);
1390 trans_class->decide_allocation =
1391 GST_DEBUG_FUNCPTR (gst_msdkvpp_decide_allocation);
1392 trans_class->prepare_output_buffer =
1393 GST_DEBUG_FUNCPTR (gst_msdkvpp_prepare_output_buffer);
1395 obj_properties[PROP_HARDWARE] =
1396 g_param_spec_boolean ("hardware", "Hardware", "Enable hardware VPP",
1397 PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1399 obj_properties[PROP_ASYNC_DEPTH] =
1400 g_param_spec_uint ("async-depth", "Async Depth",
1401 "Depth of asynchronous pipeline",
1402 1, 1, PROP_ASYNC_DEPTH_DEFAULT,
1403 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1405 obj_properties[PROP_DENOISE] =
1406 g_param_spec_uint ("denoise", "Denoising factor",
1408 0, 100, PROP_DENOISE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1410 obj_properties[PROP_ROTATION] =
1411 g_param_spec_enum ("rotation", "Rotation",
1412 "Rotation Angle", gst_msdkvpp_rotation_get_type (),
1413 PROP_ROTATION_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1415 obj_properties[PROP_DEINTERLACE_MODE] =
1416 g_param_spec_enum ("deinterlace-mode", "Deinterlace Mode",
1417 "Deinterlace mode to use", gst_msdkvpp_deinterlace_mode_get_type (),
1418 PROP_DEINTERLACE_MODE_DEFAULT,
1419 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1421 obj_properties[PROP_DEINTERLACE_METHOD] =
1422 g_param_spec_enum ("deinterlace-method", "Deinterlace Method",
1423 "Deinterlace method to use", gst_msdkvpp_deinterlace_method_get_type (),
1424 PROP_DEINTERLACE_METHOD_DEFAULT,
1425 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1427 obj_properties[PROP_HUE] =
1428 g_param_spec_float ("hue", "Hue",
1429 "The hue of the video",
1430 -180, 180, PROP_HUE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1432 obj_properties[PROP_SATURATION] =
1433 g_param_spec_float ("saturation", "Saturation",
1434 "The Saturation of the video",
1435 0, 10, PROP_SATURATION_DEFAULT,
1436 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1438 obj_properties[PROP_BRIGHTNESS] =
1439 g_param_spec_float ("brightness", "Brightness",
1440 "The Brightness of the video",
1441 -100, 100, PROP_BRIGHTNESS_DEFAULT,
1442 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1444 obj_properties[PROP_CONTRAST] =
1445 g_param_spec_float ("contrast", "Contrast",
1446 "The Contrast of the video",
1447 0, 10, PROP_CONTRAST_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1449 obj_properties[PROP_DETAIL] =
1450 g_param_spec_uint ("detail", "Detail",
1451 "The factor of detail/edge enhancement filter algorithm",
1452 0, 100, PROP_DETAIL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1454 obj_properties[PROP_MIRRORING] =
1455 g_param_spec_enum ("mirroring", "Mirroring",
1456 "The Mirroring type", gst_msdkvpp_mirroring_get_type (),
1457 PROP_MIRRORING_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1459 obj_properties[PROP_SCALING_MODE] =
1460 g_param_spec_enum ("scaling-mode", "Scaling Mode",
1461 "The Scaling mode to use", gst_msdkvpp_scaling_mode_get_type (),
1462 PROP_SCALING_MODE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1464 obj_properties[PROP_FORCE_ASPECT_RATIO] =
1465 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
1466 "When enabled, scaling will respect original aspect ratio",
1467 PROP_FORCE_ASPECT_RATIO_DEFAULT,
1468 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1470 obj_properties[PROP_FRC_ALGORITHM] =
1471 g_param_spec_enum ("frc-algorithm", "FrameRateControl Algorithm",
1472 "The Framerate Control Alogorithm to use",
1473 gst_msdkvpp_frc_algorithm_get_type (), PROP_FRC_ALGORITHM_DEFAULT,
1474 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
1476 g_object_class_install_properties (gobject_class, PROP_N, obj_properties);
1480 gst_msdkvpp_init (GstMsdkVPP * thiz)
1482 thiz->hardware = PROP_HARDWARE_DEFAULT;
1483 thiz->async_depth = PROP_ASYNC_DEPTH_DEFAULT;
1484 thiz->denoise_factor = PROP_DENOISE_DEFAULT;
1485 thiz->rotation = PROP_ROTATION_DEFAULT;
1486 thiz->deinterlace_mode = PROP_DEINTERLACE_MODE_DEFAULT;
1487 thiz->deinterlace_method = PROP_DEINTERLACE_METHOD_DEFAULT;
1488 thiz->buffer_duration = GST_CLOCK_TIME_NONE;
1489 thiz->hue = PROP_HUE_DEFAULT;
1490 thiz->saturation = PROP_SATURATION_DEFAULT;
1491 thiz->brightness = PROP_BRIGHTNESS_DEFAULT;
1492 thiz->contrast = PROP_CONTRAST_DEFAULT;
1493 thiz->detail = PROP_DETAIL_DEFAULT;
1494 thiz->mirroring = PROP_MIRRORING_DEFAULT;
1495 thiz->scaling_mode = PROP_SCALING_MODE_DEFAULT;
1496 thiz->keep_aspect = PROP_FORCE_ASPECT_RATIO_DEFAULT;
1497 thiz->frc_algm = PROP_FRC_ALGORITHM_DEFAULT;
1498 gst_video_info_init (&thiz->sinkpad_info);
1499 gst_video_info_init (&thiz->srcpad_info);