2012-12-05 09:51:41 +00:00
|
|
|
/*
|
2013-04-16 11:23:41 +00:00
|
|
|
* gstvaapiparser_frame.c - VA parser frame
|
2012-12-05 09:51:41 +00:00
|
|
|
*
|
2013-01-29 13:14:45 +00:00
|
|
|
* Copyright (C) 2012-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2012-12-05 09:51:41 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-04-16 11:23:41 +00:00
|
|
|
* SECTION:gstvaapiparser_frame
|
2012-12-05 09:51:41 +00:00
|
|
|
* @short_description: VA decoder frame
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
2013-04-16 11:23:41 +00:00
|
|
|
#include "gstvaapiparser_frame.h"
|
2012-12-05 09:51:41 +00:00
|
|
|
|
|
|
|
static inline const GstVaapiMiniObjectClass *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_parser_frame_class (void)
|
2012-12-05 09:51:41 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
static const GstVaapiMiniObjectClass GstVaapiParserFrameClass = {
|
|
|
|
sizeof (GstVaapiParserFrame),
|
|
|
|
(GDestroyNotify) gst_vaapi_parser_frame_free
|
|
|
|
};
|
|
|
|
return &GstVaapiParserFrameClass;
|
2012-12-05 09:51:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-07 12:41:59 +00:00
|
|
|
static inline gboolean
|
2016-02-03 10:50:13 +00:00
|
|
|
alloc_units (GArray ** units_ptr, guint size)
|
2013-01-07 12:41:59 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GArray *units;
|
2013-01-07 12:41:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
units = g_array_sized_new (FALSE, FALSE, sizeof (GstVaapiDecoderUnit), size);
|
|
|
|
*units_ptr = units;
|
|
|
|
return units != NULL;
|
2013-01-07 12:41:59 +00:00
|
|
|
}
|
|
|
|
|
2012-12-27 17:52:43 +00:00
|
|
|
static inline void
|
2016-02-03 10:50:13 +00:00
|
|
|
free_units (GArray ** units_ptr)
|
2012-12-27 17:52:43 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GArray *const units = *units_ptr;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (units) {
|
|
|
|
for (i = 0; i < units->len; i++) {
|
|
|
|
GstVaapiDecoderUnit *const unit =
|
|
|
|
&g_array_index (units, GstVaapiDecoderUnit, i);
|
|
|
|
gst_vaapi_decoder_unit_clear (unit);
|
2012-12-27 17:52:43 +00:00
|
|
|
}
|
2016-02-03 10:50:13 +00:00
|
|
|
g_array_free (units, TRUE);
|
|
|
|
*units_ptr = NULL;
|
|
|
|
}
|
2012-12-27 17:52:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 09:51:41 +00:00
|
|
|
/**
|
2013-04-16 11:23:41 +00:00
|
|
|
* gst_vaapi_parser_frame_new:
|
2013-01-07 12:59:07 +00:00
|
|
|
* @width: frame width in pixels
|
|
|
|
* @height: frame height in pixels
|
2012-12-05 09:51:41 +00:00
|
|
|
*
|
2013-04-16 11:23:41 +00:00
|
|
|
* Creates a new #GstVaapiParserFrame object.
|
2012-12-05 09:51:41 +00:00
|
|
|
*
|
2013-04-16 11:23:41 +00:00
|
|
|
* Returns: The newly allocated #GstVaapiParserFrame
|
2012-12-05 09:51:41 +00:00
|
|
|
*/
|
2013-04-16 11:23:41 +00:00
|
|
|
GstVaapiParserFrame *
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_parser_frame_new (guint width, guint height)
|
2012-12-05 09:51:41 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GstVaapiParserFrame *frame;
|
|
|
|
guint num_slices;
|
2013-01-07 12:41:59 +00:00
|
|
|
|
2016-02-03 10:50:13 +00:00
|
|
|
frame = (GstVaapiParserFrame *)
|
|
|
|
gst_vaapi_mini_object_new (gst_vaapi_parser_frame_class ());
|
|
|
|
if (!frame)
|
2013-01-07 12:41:59 +00:00
|
|
|
return NULL;
|
2016-02-03 10:50:13 +00:00
|
|
|
|
|
|
|
if (!height)
|
|
|
|
height = 1088;
|
|
|
|
num_slices = (height + 15) / 16;
|
|
|
|
|
|
|
|
if (!alloc_units (&frame->pre_units, 16))
|
|
|
|
goto error;
|
|
|
|
if (!alloc_units (&frame->units, num_slices))
|
|
|
|
goto error;
|
|
|
|
if (!alloc_units (&frame->post_units, 1))
|
|
|
|
goto error;
|
|
|
|
frame->output_offset = 0;
|
|
|
|
return frame;
|
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2016-02-03 10:50:13 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
|
|
|
gst_vaapi_parser_frame_unref (frame);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-12-05 09:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-16 11:23:41 +00:00
|
|
|
* gst_vaapi_parser_frame_free:
|
|
|
|
* @frame: a #GstVaapiParserFrame
|
2012-12-05 09:51:41 +00:00
|
|
|
*
|
|
|
|
* Deallocates any internal resources bound to the supplied decoder
|
|
|
|
* @frame.
|
|
|
|
*
|
|
|
|
* @note This is an internal function used to implement lightweight
|
|
|
|
* sub-classes.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_parser_frame_free (GstVaapiParserFrame * frame)
|
2012-12-05 09:51:41 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
free_units (&frame->units);
|
|
|
|
free_units (&frame->pre_units);
|
|
|
|
free_units (&frame->post_units);
|
2012-12-05 09:51:41 +00:00
|
|
|
}
|
2013-01-07 12:41:59 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-16 11:23:41 +00:00
|
|
|
* gst_vaapi_parser_frame_append_unit:
|
|
|
|
* @frame: a #GstVaapiParserFrame
|
2013-01-07 12:41:59 +00:00
|
|
|
* @unit: a #GstVaapiDecoderUnit
|
|
|
|
*
|
|
|
|
* Appends unit to the @frame.
|
|
|
|
*/
|
|
|
|
void
|
2016-02-03 10:50:13 +00:00
|
|
|
gst_vaapi_parser_frame_append_unit (GstVaapiParserFrame * frame,
|
|
|
|
GstVaapiDecoderUnit * unit)
|
2013-01-07 12:41:59 +00:00
|
|
|
{
|
2016-02-03 10:50:13 +00:00
|
|
|
GArray **unit_array_ptr;
|
|
|
|
|
|
|
|
unit->offset = frame->output_offset;
|
|
|
|
frame->output_offset += unit->size;
|
|
|
|
|
|
|
|
if (GST_VAAPI_DECODER_UNIT_IS_SLICE (unit))
|
|
|
|
unit_array_ptr = &frame->units;
|
|
|
|
else if (GST_VAAPI_DECODER_UNIT_IS_FRAME_END (unit))
|
|
|
|
unit_array_ptr = &frame->post_units;
|
|
|
|
else
|
|
|
|
unit_array_ptr = &frame->pre_units;
|
|
|
|
g_array_append_val (*unit_array_ptr, *unit);
|
2013-01-07 12:41:59 +00:00
|
|
|
}
|