gstvaapidecoder_objects.h 8.72 KB
Newer Older
1 2 3 4
/*
 *  gstvaapidecoder_objects.h - VA decoder objects
 *
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6
 *  Copyright (C) 2011-2013 Intel Corporation
7
 *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

#ifndef GST_VAAPI_DECODER_OBJECTS_H
#define GST_VAAPI_DECODER_OBJECTS_H

#include <gst/vaapi/gstvaapicodec_objects.h>

G_BEGIN_DECLS

typedef struct _GstVaapiPicture         GstVaapiPicture;
typedef struct _GstVaapiSlice           GstVaapiSlice;

/* ------------------------------------------------------------------------- */
/* --- Pictures                                                          --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_PICTURE_CAST(obj) \
    ((GstVaapiPicture *)(obj))

42 43
#define GST_VAAPI_PICTURE(obj) \
    GST_VAAPI_PICTURE_CAST(obj)
44 45

#define GST_VAAPI_IS_PICTURE(obj) \
46
    (GST_VAAPI_PICTURE(obj) != NULL)
47

Philip Lorenz's avatar
Philip Lorenz committed
48
typedef enum {
49 50 51 52 53 54 55 56
    GST_VAAPI_PICTURE_TYPE_NONE = 0,        // Undefined
    GST_VAAPI_PICTURE_TYPE_I,               // Intra
    GST_VAAPI_PICTURE_TYPE_P,               // Predicted
    GST_VAAPI_PICTURE_TYPE_B,               // Bi-directional predicted
    GST_VAAPI_PICTURE_TYPE_S,               // S(GMC)-VOP (MPEG-4)
    GST_VAAPI_PICTURE_TYPE_SI,              // Switching Intra
    GST_VAAPI_PICTURE_TYPE_SP,              // Switching Predicted
    GST_VAAPI_PICTURE_TYPE_BI,              // BI type (VC-1)
Philip Lorenz's avatar
Philip Lorenz committed
57
} GstVaapiPictureType;
58 59

/**
60
 * GstVaapiPictureFlags:
61 62
 * @GST_VAAPI_PICTURE_FLAG_SKIPPED: skipped frame
 * @GST_VAAPI_PICTURE_FLAG_REFERENCE: reference frame
63
 * @GST_VAAPI_PICTURE_FLAG_OUTPUT: frame was output
64
 * @GST_VAAPI_PICTURE_FLAG_INTERLACED: interlaced frame
65
 * @GST_VAAPI_PICTURE_FLAG_FF: first-field
66
 * @GST_VAAPI_PICTURE_FLAG_TFF: top-field-first
67 68 69 70
 * @GST_VAAPI_PICTURE_FLAG_LAST: first flag that can be used by subclasses
 *
 * Enum values used for #GstVaapiPicture flags.
 */
71
typedef enum {
72 73 74 75
    GST_VAAPI_PICTURE_FLAG_SKIPPED    = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 0),
    GST_VAAPI_PICTURE_FLAG_REFERENCE  = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 1),
    GST_VAAPI_PICTURE_FLAG_OUTPUT     = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 2),
    GST_VAAPI_PICTURE_FLAG_INTERLACED = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 3),
76
    GST_VAAPI_PICTURE_FLAG_FF         = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 4),
77 78
    GST_VAAPI_PICTURE_FLAG_TFF        = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 5),
    GST_VAAPI_PICTURE_FLAG_LAST       = (GST_VAAPI_CODEC_OBJECT_FLAG_LAST << 6),
79
} GstVaapiPictureFlags;
80

81 82 83 84
#define GST_VAAPI_PICTURE_FLAGS         GST_VAAPI_MINI_OBJECT_FLAGS
#define GST_VAAPI_PICTURE_FLAG_IS_SET   GST_VAAPI_MINI_OBJECT_FLAG_IS_SET
#define GST_VAAPI_PICTURE_FLAG_SET      GST_VAAPI_MINI_OBJECT_FLAG_SET
#define GST_VAAPI_PICTURE_FLAG_UNSET    GST_VAAPI_MINI_OBJECT_FLAG_UNSET
85

86 87 88
#define GST_VAAPI_PICTURE_IS_SKIPPED(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_SKIPPED)

89 90 91
#define GST_VAAPI_PICTURE_IS_REFERENCE(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_REFERENCE)

92 93 94
#define GST_VAAPI_PICTURE_IS_OUTPUT(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_OUTPUT)

95 96
#define GST_VAAPI_PICTURE_IS_INTERLACED(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_INTERLACED)
97

98 99 100
#define GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_FF)

101 102
#define GST_VAAPI_PICTURE_IS_TFF(picture) \
    GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_TFF)
103

104 105 106 107 108 109 110
#define GST_VAAPI_PICTURE_IS_FRAME(picture) \
    (GST_VAAPI_PICTURE(picture)->structure == GST_VAAPI_PICTURE_STRUCTURE_FRAME)

#define GST_VAAPI_PICTURE_IS_COMPLETE(picture)          \
    (GST_VAAPI_PICTURE_IS_FRAME(picture) ||             \
     !GST_VAAPI_PICTURE_IS_FIRST_FIELD(picture))

111 112 113 114 115 116 117 118
/**
 * GstVaapiPicture:
 *
 * A #GstVaapiCodecObject holding a picture parameter.
 */
struct _GstVaapiPicture {
    /*< private >*/
    GstVaapiCodecObject         parent_instance;
119
    GstVaapiPicture            *parent_picture;
120
    GstVideoCodecFrame         *frame;
121
    GstVaapiSurface            *surface;
122
    GstVaapiSurfaceProxy       *proxy;
123
    VABufferID                  param_id;
124
    guint                       param_size;
125 126 127 128 129 130 131

    /*< public >*/
    GstVaapiPictureType         type;
    VASurfaceID                 surface_id;
    gpointer                    param;
    GPtrArray                  *slices;
    GstVaapiIqMatrix           *iq_matrix;
Wind Yuan's avatar
Wind Yuan committed
132
    GstVaapiHuffmanTable       *huf_table;
133 134
    GstVaapiBitPlane           *bitplane;
    GstClockTime                pts;
135
    gint32                      poc;
136
    guint                       structure;
137 138
    GstVaapiRectangle           crop_rect;
    guint                       has_crop_rect   : 1;
139 140
};

141 142 143
G_GNUC_INTERNAL
void
gst_vaapi_picture_destroy(GstVaapiPicture *picture);
144

145
G_GNUC_INTERNAL
146 147 148
gboolean
gst_vaapi_picture_create(GstVaapiPicture *picture,
    const GstVaapiCodecObjectConstructorArgs *args);
149

150
G_GNUC_INTERNAL
151 152 153 154 155
GstVaapiPicture *
gst_vaapi_picture_new(
    GstVaapiDecoder *decoder,
    gconstpointer    param,
    guint            param_size
156
);
157

158
G_GNUC_INTERNAL
159
GstVaapiPicture *
160
gst_vaapi_picture_new_field(GstVaapiPicture *picture);
161

162
G_GNUC_INTERNAL
163
void
164
gst_vaapi_picture_add_slice(GstVaapiPicture *picture, GstVaapiSlice *slice);
165

166
G_GNUC_INTERNAL
167
gboolean
168
gst_vaapi_picture_decode(GstVaapiPicture *picture);
169

170
G_GNUC_INTERNAL
171
gboolean
172
gst_vaapi_picture_output(GstVaapiPicture *picture);
173

174 175 176 177 178
G_GNUC_INTERNAL
void
gst_vaapi_picture_set_crop_rect(GstVaapiPicture *picture,
    const GstVaapiRectangle *crop_rect);

179 180 181
static inline gpointer
gst_vaapi_picture_ref(gpointer ptr)
{
182
    return gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(ptr));
183 184 185 186 187
}

static inline void
gst_vaapi_picture_unref(gpointer ptr)
{
188
    gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(ptr));
189 190
}

191 192 193
#define gst_vaapi_picture_replace(old_picture_p, new_picture)             \
    gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_picture_p), \
        (GstVaapiMiniObject *)(new_picture))
194 195 196 197 198 199 200 201

/* ------------------------------------------------------------------------- */
/* --- Slices                                                            --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_SLICE_CAST(obj) \
    ((GstVaapiSlice *)(obj))

202 203
#define GST_VAAPI_SLICE(obj) \
    GST_VAAPI_SLICE_CAST(obj)
204 205

#define GST_VAAPI_IS_SLICE(obj) \
206
    (GST_VAAPI_SLICE(obj) != NULL)
207 208 209 210 211 212 213 214 215 216 217 218 219 220

/**
 * GstVaapiSlice:
 *
 * A #GstVaapiCodecObject holding a slice parameter.
 */
struct _GstVaapiSlice {
    /*< private >*/
    GstVaapiCodecObject         parent_instance;

    /*< public >*/
    VABufferID                  param_id;
    VABufferID                  data_id;
    gpointer                    param;
221 222 223

    /* Per-slice overrides */
    GstVaapiHuffmanTable       *huf_table;
224 225
};

226 227 228
G_GNUC_INTERNAL
void
gst_vaapi_slice_destroy(GstVaapiSlice *slice);
229

230
G_GNUC_INTERNAL
231 232 233
gboolean
gst_vaapi_slice_create(GstVaapiSlice *slice,
    const GstVaapiCodecObjectConstructorArgs *args);
234

235
G_GNUC_INTERNAL
236 237 238 239 240 241 242
GstVaapiSlice *
gst_vaapi_slice_new(
    GstVaapiDecoder *decoder,
    gconstpointer    param,
    guint            param_size,
    const guchar    *data,
    guint            data_size
243
);
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

/* ------------------------------------------------------------------------- */
/* --- Helpers to create codec-dependent objects                         --- */
/* ------------------------------------------------------------------------- */

#define GST_VAAPI_PICTURE_NEW(codec, decoder)                           \
    gst_vaapi_picture_new(GST_VAAPI_DECODER_CAST(decoder),              \
                          NULL, sizeof(VAPictureParameterBuffer##codec))

#define GST_VAAPI_SLICE_NEW(codec, decoder, buf, buf_size)              \
    gst_vaapi_slice_new(GST_VAAPI_DECODER_CAST(decoder),                \
                        NULL, sizeof(VASliceParameterBuffer##codec),    \
                        buf, buf_size)

G_END_DECLS

#endif /* GST_VAAPI_DECODER_OBJECTS_H */