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 typedef struct _GstMsdkDec GstMsdkDec;
58 typedef struct _GstMsdkDecClass GstMsdkDecClass;
59 typedef struct _MsdkDecTask MsdkDecTask;
60 
61 struct _GstMsdkDec
62 {
63   GstVideoDecoder element;
64 
65   /* input description */
66   GstVideoCodecState *input_state;
67   /* aligned msdk pool info */
68   GstVideoInfo output_info;
69   GstBufferPool *pool;
70   GstCaps *allocation_caps;
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   gboolean is_packetized;
81   /* cap negotiation needed, allocation may or may not be required*/
82   gboolean do_renego;
83   /* re-allocation is mandatory if enabled */
84   gboolean do_realloc;
85   /* force reset on resolution change */
86   gboolean force_reset_on_res_change;
87   /* minimum number of buffers to be allocated, this should
88    * include downstream requirement, msdk suggestion and extra
89    * surface allocation for smooth display in render pipeline */
90   guint min_prealloc_buffers;
91 
92   /* MFX context */
93   GstMsdkContext *context;
94   mfxVideoParam param;
95   GArray *tasks;
96   guint next_task;
97 
98   GList *decoded_msdk_surfaces;
99 
100   /* element properties */
101   gboolean hardware;
102   guint async_depth;
103 };
104 
105 struct _GstMsdkDecClass
106 {
107   GstVideoDecoderClass parent_class;
108 
109   gboolean (*configure) (GstMsdkDec * decoder);
110 
111   /* reset mfx parameters per codec */
112   gboolean (*preinit_decoder) (GstMsdkDec * decoder);
113   /* adjust mfx parameters per codec */
114   gboolean (*postinit_decoder) (GstMsdkDec * decoder);
115 };
116 
117 struct _MsdkDecTask
118 {
119   mfxFrameSurface1 *surface;
120   mfxSyncPoint sync_point;
121 
122   gboolean decode_only;
123 };
124 
125 GType gst_msdkdec_get_type (void);
126 
127 G_END_DECLS
128 
129 #endif /* __GST_MSDKDEC_H__ */
130