1 /* GStreamer Intel MSDK plugin 2 * Copyright (c) 2016, Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef __GST_MSDKDEC_H__ 33 #define __GST_MSDKDEC_H__ 34 35 #include <gst/gst.h> 36 #include <gst/video/video.h> 37 #include "msdk.h" 38 #include "gstmsdkcontext.h" 39 #include "msdk-enums.h" 40 #include "gstmsdkdecproputil.h" 41 42 G_BEGIN_DECLS 43 44 #define GST_TYPE_MSDKDEC \ 45 (gst_msdkdec_get_type()) 46 #define GST_MSDKDEC(obj) \ 47 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKDEC,GstMsdkDec)) 48 #define GST_MSDKDEC_CLASS(klass) \ 49 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKDEC,GstMsdkDecClass)) 50 #define GST_MSDKDEC_GET_CLASS(obj) \ 51 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_MSDKDEC,GstMsdkDecClass)) 52 #define GST_IS_MSDKDEC(obj) \ 53 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKDEC)) 54 #define GST_IS_MSDKDEC_CLASS(klass) \ 55 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKDEC)) 56 57 #define MAX_BS_EXTRA_PARAMS 8 58 59 typedef struct _GstMsdkDec GstMsdkDec; 60 typedef struct _GstMsdkDecClass GstMsdkDecClass; 61 typedef struct _MsdkDecTask MsdkDecTask; 62 63 struct _GstMsdkDec 64 { 65 GstVideoDecoder element; 66 67 /* input description */ 68 GstVideoCodecState *input_state; 69 /* aligned msdk pool info */ 70 GstBufferPool *pool; 71 /* downstream pool info based on allocation query */ 72 GstVideoInfo non_msdk_pool_info; 73 mfxFrameAllocResponse alloc_resp; 74 gboolean use_video_memory; 75 gboolean use_dmabuf; 76 gboolean initialized; 77 78 /* for packetization */ 79 GstAdapter *adapter; 80 /* cap negotiation needed, allocation may or may not be required*/ 81 gboolean do_renego; 82 /* re-allocation is mandatory if enabled */ 83 gboolean do_realloc; 84 /* force reset on resolution change */ 85 gboolean force_reset_on_res_change; 86 /* minimum number of buffers to be allocated, this should 87 * include downstream requirement, msdk suggestion and extra 88 * surface allocation for smooth display in render pipeline */ 89 guint min_prealloc_buffers; 90 91 /* MFX context */ 92 GstMsdkContext *context; 93 GstMsdkContext *old_context; 94 mfxVideoParam param; 95 GArray *tasks; 96 guint next_task; 97 98 GList *locked_msdk_surfaces; 99 100 /* element properties */ 101 gboolean hardware; 102 gboolean report_error; 103 guint async_depth; 104 105 mfxExtBuffer *bs_extra_params[MAX_BS_EXTRA_PARAMS]; 106 guint num_bs_extra_params; 107 108 #if (MFX_VERSION >= 1025) 109 mfxExtDecodeErrorReport error_report; 110 #endif 111 }; 112 113 struct _GstMsdkDecClass 114 { 115 GstVideoDecoderClass parent_class; 116 117 gboolean (*configure) (GstMsdkDec * decoder); 118 119 /* adjust mfx parameters per codec after decode header */ 120 gboolean (*post_configure) (GstMsdkDec * decoder); 121 122 /* reset mfx parameters per codec */ 123 gboolean (*preinit_decoder) (GstMsdkDec * decoder); 124 /* adjust mfx parameters per codec */ 125 gboolean (*postinit_decoder) (GstMsdkDec * decoder); 126 }; 127 128 GType gst_msdkdec_get_type (void); 129 130 void 131 gst_msdkdec_add_bs_extra_param (GstMsdkDec * thiz, mfxExtBuffer * param); 132 133 G_END_DECLS 134 135 #endif /* __GST_MSDKDEC_H__ */ 136