codecs: Add the H266/VVC decoder base class
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5865>
This commit is contained in:
parent
68f964a635
commit
0ce5fe3cc9
1652
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266decoder.c
Normal file
1652
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266decoder.c
Normal file
File diff suppressed because it is too large
Load Diff
197
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266decoder.h
Normal file
197
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266decoder.h
Normal file
@ -0,0 +1,197 @@
|
||||
/* GStreamer
|
||||
* Copyright (C) 2023 He Junyan <junyan.he@intel.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gst/codecs/codecs-prelude.h>
|
||||
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/codecparsers/gsth266parser.h>
|
||||
#include <gst/codecs/gsth266picture.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_H266_DECODER (gst_h266_decoder_get_type())
|
||||
#define GST_H266_DECODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_H266_DECODER,GstH266Decoder))
|
||||
#define GST_H266_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_H266_DECODER,GstH266DecoderClass))
|
||||
#define GST_H266_DECODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_H266_DECODER,GstH266DecoderClass))
|
||||
#define GST_IS_H266_DECODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_H266_DECODER))
|
||||
#define GST_IS_H266_DECODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_H266_DECODER))
|
||||
|
||||
typedef struct _GstH266Decoder GstH266Decoder;
|
||||
typedef struct _GstH266DecoderClass GstH266DecoderClass;
|
||||
typedef struct _GstH266DecoderPrivate GstH266DecoderPrivate;
|
||||
|
||||
/**
|
||||
* GstH266Decoder:
|
||||
*
|
||||
* The opaque #GstH266Decoder data structure.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
struct _GstH266Decoder
|
||||
{
|
||||
/*< private > */
|
||||
GstVideoDecoder parent;
|
||||
|
||||
/*< protected > */
|
||||
GstVideoCodecState *input_state;
|
||||
|
||||
GArray *aps_list[GST_H266_APS_TYPE_MAX];
|
||||
/* Do not hold the reference. */
|
||||
GstH266Picture *RefPicList[2][GST_H266_MAX_REF_ENTRIES];
|
||||
guint NumRefIdxActive[2];
|
||||
gint RefPicPocList[2][GST_H266_MAX_REF_ENTRIES];
|
||||
gint RefPicLtPocList[2][GST_H266_MAX_REF_ENTRIES];
|
||||
gboolean inter_layer_ref[2][GST_H266_MAX_REF_ENTRIES];
|
||||
/* For inter layer refs */
|
||||
guint RefPicScale[2][GST_H266_MAX_REF_ENTRIES][2];
|
||||
gboolean RprConstraintsActiveFlag[2][GST_H266_MAX_REF_ENTRIES];
|
||||
|
||||
/*< private > */
|
||||
GstH266DecoderPrivate *priv;
|
||||
gpointer padding[GST_PADDING_LARGE];
|
||||
};
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass:
|
||||
*
|
||||
* The opaque #GstH266DecoderClass data structure.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
struct _GstH266DecoderClass
|
||||
{
|
||||
GstVideoDecoderClass parent_class;
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::new_sequence:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @sps: a #GstH266SPS
|
||||
* @max_dpb_size: the size of dpb including preferred output delay
|
||||
* by subclass reported via get_preferred_output_delay method.
|
||||
*
|
||||
* Notifies subclass of video sequence update
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*new_sequence) (GstH266Decoder * decoder,
|
||||
const GstH266SPS * sps,
|
||||
gint max_dpb_size);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::new_picture:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @frame: (transfer none): a #GstVideoCodecFrame
|
||||
* @picture: (transfer none): a #GstH266Picture
|
||||
*
|
||||
* Optional. Called whenever new #GstH266Picture is created.
|
||||
* Subclass can set implementation specific user data
|
||||
* on the #GstH266Picture via gst_h266_picture_set_user_data
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*new_picture) (GstH266Decoder * decoder,
|
||||
GstVideoCodecFrame * frame,
|
||||
GstH266Picture * picture);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::start_picture:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @picture: (transfer none): a #GstH266Picture
|
||||
* @slice: (transfer none): a #GstH266Slice
|
||||
* @dpb: (transfer none): a #GstH266Dpb
|
||||
*
|
||||
* Optional. Called per one #GstH266Picture to notify subclass to prepare
|
||||
* decoding process for the #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*start_picture) (GstH266Decoder * decoder,
|
||||
GstH266Picture * picture,
|
||||
GstH266Slice * slice,
|
||||
GstH266Dpb * dpb);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::decode_slice:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @picture: (transfer none): a #GstH266Picture
|
||||
* @slice: (transfer none): a #GstH266Slice
|
||||
*
|
||||
* Provides per slice data with parsed slice header and required raw bitstream
|
||||
* for subclass to decode it.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*decode_slice) (GstH266Decoder * decoder,
|
||||
GstH266Picture * picture,
|
||||
GstH266Slice * slice);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::end_picture:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @picture: (transfer none): a #GstH266Picture
|
||||
*
|
||||
* Optional. Called per one #GstH266Picture to notify subclass to finish
|
||||
* decoding process for the #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*end_picture) (GstH266Decoder * decoder,
|
||||
GstH266Picture * picture);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass:output_picture:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @frame: (transfer full): a #GstVideoCodecFrame
|
||||
* @picture: (transfer full): a #GstH266Picture
|
||||
*
|
||||
* Called with a #GstH266Picture which is required to be outputted.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstFlowReturn (*output_picture) (GstH266Decoder * decoder,
|
||||
GstVideoCodecFrame * frame,
|
||||
GstH266Picture * picture);
|
||||
|
||||
/**
|
||||
* GstH266DecoderClass::get_preferred_output_delay:
|
||||
* @decoder: a #GstH266Decoder
|
||||
* @live: whether upstream is live or not
|
||||
*
|
||||
* Optional. Called by baseclass to query whether delaying output is
|
||||
* preferred by subclass or not.
|
||||
*
|
||||
* Returns: the number of perferred delayed output frame
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
guint (*get_preferred_output_delay) (GstH266Decoder * decoder,
|
||||
gboolean live);
|
||||
|
||||
/*< private > */
|
||||
gpointer padding[GST_PADDING_LARGE];
|
||||
};
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstH266Decoder, gst_object_unref)
|
||||
|
||||
GST_CODECS_API
|
||||
GType gst_h266_decoder_get_type (void);
|
||||
|
||||
G_END_DECLS
|
551
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266picture.c
Normal file
551
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266picture.c
Normal file
@ -0,0 +1,551 @@
|
||||
/* GStreamer
|
||||
* Copyright (C) 2023 He Junyan <junyan.he@intel.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "gsth266picture.h"
|
||||
#include "gstcodecpicture-private.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_h266_decoder_debug);
|
||||
#define GST_CAT_DEFAULT gst_h266_decoder_debug
|
||||
|
||||
GST_DEFINE_MINI_OBJECT_TYPE (GstH266Picture, gst_h266_picture);
|
||||
|
||||
/**
|
||||
* gst_h266_picture_new:
|
||||
*
|
||||
* Create new #GstH266Picture
|
||||
*
|
||||
* Returns: a new #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstH266Picture *
|
||||
gst_h266_picture_new (void)
|
||||
{
|
||||
GstH266Picture *pic;
|
||||
|
||||
pic = g_new0 (GstH266Picture, 1);
|
||||
|
||||
pic->ff_info.field_pic_flag = 0;
|
||||
pic->ff_info.display_fields_from_frame_flag = 0;
|
||||
/* 0: interlaced, 1: progressive, 2: unspecified, 3: reserved, can be
|
||||
* interpreted as 2 */
|
||||
pic->ff_info.source_scan_type = 2;
|
||||
pic->ff_info.duplicate_flag = 0;
|
||||
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (pic), 0,
|
||||
GST_TYPE_H266_PICTURE, NULL, NULL,
|
||||
(GstMiniObjectFreeFunction) gst_codec_picture_free);
|
||||
|
||||
return pic;
|
||||
}
|
||||
|
||||
/**
|
||||
* GstH266Dpb:
|
||||
*
|
||||
* The #GstH266Dpb represents the dpb for decoding.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
struct _GstH266Dpb
|
||||
{
|
||||
GArray *pic_list;
|
||||
gint max_num_pics;
|
||||
gint num_output_needed;
|
||||
};
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_new: (skip)
|
||||
*
|
||||
* Create new #GstH266Dpb
|
||||
*
|
||||
* Returns: a new #GstH266Dpb
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstH266Dpb *
|
||||
gst_h266_dpb_new (void)
|
||||
{
|
||||
GstH266Dpb *dpb;
|
||||
|
||||
dpb = g_new0 (GstH266Dpb, 1);
|
||||
|
||||
dpb->pic_list = g_array_sized_new (FALSE, TRUE, sizeof (GstH266Picture *),
|
||||
GST_H266_MAX_DPB_SIZE);
|
||||
g_array_set_clear_func (dpb->pic_list,
|
||||
(GDestroyNotify) gst_clear_h266_picture);
|
||||
|
||||
return dpb;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_set_max_num_pics:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @max_num_pics: the maximum number of picture
|
||||
*
|
||||
* Set the number of maximum allowed pictures to store
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_set_max_num_pics (GstH266Dpb * dpb, gint max_num_pics)
|
||||
{
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
dpb->max_num_pics = max_num_pics;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_get_max_num_pics:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Returns: the number of maximum pictures
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
gint
|
||||
gst_h266_dpb_get_max_num_pics (GstH266Dpb * dpb)
|
||||
{
|
||||
g_return_val_if_fail (dpb != NULL, 0);
|
||||
|
||||
return dpb->max_num_pics;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_free:
|
||||
* @dpb: a #GstH266Dpb to free
|
||||
*
|
||||
* Free the @dpb
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_free (GstH266Dpb * dpb)
|
||||
{
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
gst_h266_dpb_clear (dpb);
|
||||
g_array_unref (dpb->pic_list);
|
||||
g_free (dpb);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_clear:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Clear all stored #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_clear (GstH266Dpb * dpb)
|
||||
{
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
g_array_set_size (dpb->pic_list, 0);
|
||||
dpb->num_output_needed = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_add:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @picture: (transfer full): a #GstH266Picture
|
||||
*
|
||||
* Store the @picture and perform increase pic_latency_cnt as defined in
|
||||
* "C.5.2.3 Additional bumping" process
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_add (GstH266Dpb * dpb, GstH266Picture * picture)
|
||||
{
|
||||
g_return_if_fail (dpb != NULL);
|
||||
g_return_if_fail (GST_IS_H266_PICTURE (picture));
|
||||
|
||||
if (picture->output_flag) {
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *other =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (other->needed_for_output)
|
||||
other->pic_latency_cnt++;
|
||||
}
|
||||
|
||||
dpb->num_output_needed++;
|
||||
picture->needed_for_output = TRUE;
|
||||
} else {
|
||||
picture->needed_for_output = FALSE;
|
||||
}
|
||||
|
||||
/* C.3.4 */
|
||||
picture->ref = TRUE;
|
||||
picture->long_term = FALSE;
|
||||
|
||||
g_array_append_val (dpb->pic_list, picture);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_delete_unused:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Delete unneeded pictures from dpb as defined in "C.5.2.2 Output and
|
||||
* removal of pictures from the DPB".
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_delete_unused (GstH266Dpb * dpb)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (!picture->needed_for_output && !picture->ref) {
|
||||
GST_TRACE ("remove picture %p (poc %d) from dpb",
|
||||
picture, picture->pic_order_cnt);
|
||||
g_array_remove_index (dpb->pic_list, i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_num_ref_pictures:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Returns: The number of referenced pictures in dpb.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
gint
|
||||
gst_h266_dpb_num_ref_pictures (GstH266Dpb * dpb)
|
||||
{
|
||||
gint i;
|
||||
gint ret = 0;
|
||||
|
||||
g_return_val_if_fail (dpb != NULL, -1);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (picture->ref)
|
||||
ret++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_h266_dpb_check_latency_count (GstH266Dpb * dpb, guint32 max_latency)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (!picture->needed_for_output)
|
||||
continue;
|
||||
|
||||
if (picture->pic_latency_cnt >= max_latency)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_needs_bump:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @max_num_reorder_pics: dpb_max_num_reorder_pics[HighestTid]
|
||||
* @max_latency_increase: MaxLatencyPictures[HighestTid]
|
||||
* @max_dec_pic_buffering: dpb_max_dec_pic_buffering_minus1[HighestTid] + 1
|
||||
* or zero if this shouldn't be used for bumping decision.
|
||||
*
|
||||
* Returns: %TRUE if bumping is required
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
gboolean
|
||||
gst_h266_dpb_needs_bump (GstH266Dpb * dpb, guint max_num_reorder_pics,
|
||||
guint max_latency_increase, guint max_dec_pic_buffering)
|
||||
{
|
||||
g_return_val_if_fail (dpb != NULL, FALSE);
|
||||
g_assert (dpb->num_output_needed >= 0);
|
||||
|
||||
/* If DPB is full and there is no empty space to store current picture,
|
||||
* need bumping.
|
||||
* NOTE: current picture was added already by our decoding flow, so we
|
||||
* need to do bumping until dpb->pic_list->len == dpb->max_num_pic
|
||||
*/
|
||||
if (dpb->pic_list->len > dpb->max_num_pics) {
|
||||
GST_TRACE ("No empty frame buffer, need bumping");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* C.5.2.3 */
|
||||
if (dpb->num_output_needed > max_num_reorder_pics) {
|
||||
GST_TRACE ("num_output_needed (%d) > max_num_reorder_pics (%d)",
|
||||
dpb->num_output_needed, max_num_reorder_pics);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (dpb->num_output_needed && max_latency_increase &&
|
||||
gst_h266_dpb_check_latency_count (dpb, max_latency_increase)) {
|
||||
GST_TRACE ("has late picture, max_latency_increase: %d",
|
||||
max_latency_increase);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* C.5.2.2 */
|
||||
if (max_dec_pic_buffering && dpb->pic_list->len >= max_dec_pic_buffering) {
|
||||
GST_TRACE ("dpb size (%d) >= max_dec_pic_buffering (%d)",
|
||||
dpb->pic_list->len, max_dec_pic_buffering);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
gst_h266_dpb_get_lowest_output_needed_picture (GstH266Dpb * dpb,
|
||||
GstH266Picture ** picture)
|
||||
{
|
||||
gint i;
|
||||
GstH266Picture *lowest = NULL;
|
||||
gint index = -1;
|
||||
|
||||
*picture = NULL;
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (!picture->needed_for_output)
|
||||
continue;
|
||||
|
||||
if (!lowest) {
|
||||
lowest = picture;
|
||||
index = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (picture->pic_order_cnt < lowest->pic_order_cnt) {
|
||||
lowest = picture;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (lowest)
|
||||
*picture = gst_h266_picture_ref (lowest);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_bump:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @drain: whether draining or not
|
||||
*
|
||||
* Perform bumping process as defined in C.5.2.4 "Bumping" process.
|
||||
* If @drain is %TRUE, @dpb will remove a #GstH266Picture from internal array
|
||||
* so that returned #GstH266Picture could hold the last reference of it.
|
||||
*
|
||||
* Returns: (nullable) (transfer full): a #GstH266Picture which is needed to be
|
||||
* outputted
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstH266Picture *
|
||||
gst_h266_dpb_bump (GstH266Dpb * dpb, gboolean drain)
|
||||
{
|
||||
GstH266Picture *picture;
|
||||
gint index;
|
||||
|
||||
g_return_val_if_fail (dpb != NULL, NULL);
|
||||
|
||||
/* C.5.2.4 "Bumping" process */
|
||||
index = gst_h266_dpb_get_lowest_output_needed_picture (dpb, &picture);
|
||||
|
||||
if (!picture || index < 0)
|
||||
return NULL;
|
||||
|
||||
picture->needed_for_output = FALSE;
|
||||
|
||||
dpb->num_output_needed--;
|
||||
g_assert (dpb->num_output_needed >= 0);
|
||||
|
||||
if (!picture->ref || drain)
|
||||
g_array_remove_index_fast (dpb->pic_list, index);
|
||||
|
||||
return picture;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_mark_all_non_ref:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Mark all pictures are not referenced
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_mark_all_non_ref (GstH266Dpb * dpb)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
picture->ref = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_mark_all_non_output:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Mark all pictures are no needed for output
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
void
|
||||
gst_h266_dpb_mark_all_non_output (GstH266Dpb * dpb)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (dpb != NULL);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
picture->needed_for_output = FALSE;
|
||||
}
|
||||
|
||||
dpb->num_output_needed = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_get_size:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Return: the length of stored dpb array
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
gint
|
||||
gst_h266_dpb_get_size (GstH266Dpb * dpb)
|
||||
{
|
||||
g_return_val_if_fail (dpb != NULL, -1);
|
||||
|
||||
return dpb->pic_list->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_get_picture_by_poc_lsb:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @poc_lsb: a picture order count lsb
|
||||
*
|
||||
* Find a picture which has matching poc_lsb
|
||||
*
|
||||
* Returns: (nullable) (transfer full): a #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstH266Picture *
|
||||
gst_h266_dpb_get_picture_by_poc_lsb (GstH266Dpb * dpb, gint poc_lsb)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (dpb != NULL, NULL);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (picture->pic_order_cnt_lsb == poc_lsb)
|
||||
return gst_h266_picture_ref (picture);
|
||||
}
|
||||
|
||||
GST_DEBUG ("No reference picture for poc lsb %d", poc_lsb);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_get_picture_by_poc:
|
||||
* @dpb: a #GstH266Dpb
|
||||
* @poc: a picture order count
|
||||
*
|
||||
* Find a picture which has matching poc
|
||||
*
|
||||
* Returns: (nullable) (transfer full): a #GstH266Picture
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GstH266Picture *
|
||||
gst_h266_dpb_get_picture_by_poc (GstH266Dpb * dpb, gint poc)
|
||||
{
|
||||
gint i;
|
||||
|
||||
g_return_val_if_fail (dpb != NULL, NULL);
|
||||
|
||||
for (i = 0; i < dpb->pic_list->len; i++) {
|
||||
GstH266Picture *picture =
|
||||
g_array_index (dpb->pic_list, GstH266Picture *, i);
|
||||
|
||||
if (picture->pic_order_cnt == poc)
|
||||
return gst_h266_picture_ref (picture);
|
||||
}
|
||||
|
||||
GST_DEBUG ("No picture for poc %d", poc);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_h266_dpb_get_pictures_all:
|
||||
* @dpb: a #GstH266Dpb
|
||||
*
|
||||
* Return: (element-type GstH266Picture) (transfer full): a #GArray of
|
||||
* #GstH266Picture stored in @dpb
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
GArray *
|
||||
gst_h266_dpb_get_pictures_all (GstH266Dpb * dpb)
|
||||
{
|
||||
g_return_val_if_fail (dpb != NULL, NULL);
|
||||
|
||||
return g_array_ref (dpb->pic_list);
|
||||
}
|
218
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266picture.h
Normal file
218
subprojects/gst-plugins-bad/gst-libs/gst/codecs/gsth266picture.h
Normal file
@ -0,0 +1,218 @@
|
||||
/* GStreamer
|
||||
* Copyright (C) 2023 He Junyan <junyan.he@intel.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef GST_USE_UNSTABLE_API
|
||||
#warning "The CODECs library is unstable API and may change in future."
|
||||
#warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/codecs/codecs-prelude.h>
|
||||
#include <gst/codecs/gstcodecpicture.h>
|
||||
#include <gst/codecparsers/gsth266parser.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_H266_PICTURE (gst_h266_picture_get_type())
|
||||
#define GST_IS_H266_PICTURE(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_H266_PICTURE))
|
||||
#define GST_H266_PICTURE(obj) ((GstH266Picture *)obj)
|
||||
|
||||
typedef struct _GstH266Slice GstH266Slice;
|
||||
typedef struct _GstH266Picture GstH266Picture;
|
||||
typedef struct _GstH266Dpb GstH266Dpb;
|
||||
|
||||
/**
|
||||
* GstH266Slice:
|
||||
*
|
||||
* The #GstH266Slice represents a slice for decoding.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
struct _GstH266Slice
|
||||
{
|
||||
GstH266SliceHdr header;
|
||||
|
||||
/* parsed nal unit (doesn't take ownership of raw data) */
|
||||
GstH266NalUnit nalu;
|
||||
|
||||
/*< private > */
|
||||
gboolean no_output_before_recovery_flag;
|
||||
gboolean no_output_of_prior_pics_flag;
|
||||
/* The first slice of the picture. */
|
||||
gboolean first_slice;
|
||||
gboolean clear_dpb;
|
||||
};
|
||||
|
||||
/**
|
||||
* GstH266Picture:
|
||||
*
|
||||
* The #GstH266Picture represents a picture for decoding.
|
||||
*
|
||||
* Since: 1.26
|
||||
*/
|
||||
struct _GstH266Picture
|
||||
{
|
||||
/*< private > */
|
||||
GstCodecPicture parent;
|
||||
|
||||
GstH266SliceType type;
|
||||
|
||||
gint pic_order_cnt;
|
||||
gint pic_order_cnt_msb;
|
||||
gint pic_order_cnt_lsb;
|
||||
|
||||
guint pic_latency_cnt;
|
||||
|
||||
gboolean output_flag;
|
||||
gboolean NoOutputOfPriorPicsFlag;
|
||||
gboolean NoOutputBeforeRecoveryFlag;
|
||||
|
||||
/* PPS resolution may be smaller than SPS resolution. */
|
||||
gint pps_width, pps_height;
|
||||
gboolean pps_conformance_window_flag;
|
||||
gint pps_crop_rect_width, pps_crop_rect_height;
|
||||
gint pps_crop_rect_x, pps_crop_rect_y;
|
||||
|
||||
/* Never be a ref in RPL, except the first time adding to DPB. */
|
||||
gboolean non_ref;
|
||||
gboolean ref;
|
||||
gboolean long_term;
|
||||
gboolean inter_layer_ref;
|
||||
gboolean needed_for_output;
|
||||
|
||||
GstH266FrameFieldInfo ff_info;
|
||||
|
||||
GstVideoBufferFlags buffer_flags;
|
||||
};
|
||||
|
||||
GST_CODECS_API
|
||||
GType gst_h266_picture_get_type (void);
|
||||
|
||||
GST_CODECS_API
|
||||
GstH266Picture *gst_h266_picture_new (void);
|
||||
|
||||
static inline GstH266Picture *
|
||||
gst_h266_picture_ref (GstH266Picture * picture)
|
||||
{
|
||||
return (GstH266Picture *)
|
||||
gst_mini_object_ref (GST_MINI_OBJECT_CAST (picture));
|
||||
}
|
||||
|
||||
static inline void
|
||||
gst_h266_picture_unref (GstH266Picture * picture)
|
||||
{
|
||||
gst_mini_object_unref (GST_MINI_OBJECT_CAST (picture));
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gst_h266_picture_replace (GstH266Picture ** old_picture,
|
||||
GstH266Picture * new_picture)
|
||||
{
|
||||
return gst_mini_object_replace ((GstMiniObject **) old_picture,
|
||||
(GstMiniObject *) new_picture);
|
||||
}
|
||||
|
||||
static inline void
|
||||
gst_clear_h266_picture (GstH266Picture ** picture)
|
||||
{
|
||||
if (picture && *picture) {
|
||||
gst_h266_picture_unref (*picture);
|
||||
*picture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
gst_h266_picture_set_user_data (GstH266Picture * picture, gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
gst_codec_picture_set_user_data (GST_CODEC_PICTURE (picture),
|
||||
user_data, notify);
|
||||
}
|
||||
|
||||
static inline gpointer
|
||||
gst_h266_picture_get_user_data (GstH266Picture * picture)
|
||||
{
|
||||
return gst_codec_picture_get_user_data (GST_CODEC_PICTURE (picture));
|
||||
}
|
||||
|
||||
static inline void
|
||||
gst_h266_picture_set_discont_state (GstH266Picture * picture,
|
||||
GstVideoCodecState * discont_state)
|
||||
{
|
||||
gst_codec_picture_set_discont_state (GST_CODEC_PICTURE (picture),
|
||||
discont_state);
|
||||
}
|
||||
|
||||
GST_CODECS_API
|
||||
GstH266Dpb *gst_h266_dpb_new (void);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_free (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_clear (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_set_max_num_pics (GstH266Dpb * dpb,
|
||||
gint max_num_pics);
|
||||
|
||||
GST_CODECS_API
|
||||
gint gst_h266_dpb_get_max_num_pics (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_add (GstH266Dpb * dpb, GstH266Picture * picture);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_delete_unused (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
gint gst_h266_dpb_num_ref_pictures (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
gint gst_h266_dpb_get_size (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
gboolean gst_h266_dpb_needs_bump (GstH266Dpb * dpb, guint max_num_reorder_pics,
|
||||
guint max_latency_increase, guint max_dec_pic_buffering);
|
||||
|
||||
GST_CODECS_API
|
||||
GstH266Picture *gst_h266_dpb_bump (GstH266Dpb * dpb, gboolean drain);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_mark_all_non_ref (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
void gst_h266_dpb_mark_all_non_output (GstH266Dpb * dpb);
|
||||
|
||||
GST_CODECS_API
|
||||
GstH266Picture *gst_h266_dpb_get_picture_by_poc_lsb (GstH266Dpb * dpb,
|
||||
gint poc_lsb);
|
||||
|
||||
GST_CODECS_API
|
||||
GstH266Picture *gst_h266_dpb_get_picture_by_poc (GstH266Dpb * dpb, gint poc);
|
||||
|
||||
GST_CODECS_API
|
||||
GArray *gst_h266_dpb_get_pictures_all (GstH266Dpb * dpb);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstH266Picture, gst_h266_picture_unref)
|
||||
|
||||
G_END_DECLS
|
@ -3,6 +3,8 @@ codecs_sources = files(
|
||||
'gsth264picture.c',
|
||||
'gsth265decoder.c',
|
||||
'gsth265picture.c',
|
||||
'gsth266decoder.c',
|
||||
'gsth266picture.c',
|
||||
'gstvp9decoder.c',
|
||||
'gstvp9picture.c',
|
||||
'gstvp8decoder.c',
|
||||
@ -20,6 +22,8 @@ codecs_headers = files(
|
||||
'gsth264picture.h',
|
||||
'gsth265decoder.h',
|
||||
'gsth265picture.h',
|
||||
'gsth266decoder.h',
|
||||
'gsth266picture.h',
|
||||
'gstvp9decoder.h',
|
||||
'gstvp9picture.h',
|
||||
'gstvp8decoder.h',
|
||||
|
Loading…
x
Reference in New Issue
Block a user