diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture-private.h new file mode 100644 index 0000000000..ebb43ff7da --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture-private.h @@ -0,0 +1,29 @@ +/* GStreamer + * Copyright (C) 2023 Seungha Yang + * + * 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 +#include + +G_BEGIN_DECLS + +void gst_codec_picture_free (GstCodecPicture * picture); + +G_END_DECLS diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.c b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.c new file mode 100644 index 0000000000..e07e8e7aa8 --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.c @@ -0,0 +1,104 @@ +/* GStreamer + * Copyright (C) 2023 Seungha Yang + * + * 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 +#endif + +#include "gstcodecpicture.h" +#include "gstcodecpicture-private.h" + +void +gst_codec_picture_free (GstCodecPicture * picture) +{ + if (picture->notify) + picture->notify (picture->user_data); + + if (picture->discont_state) + gst_video_codec_state_unref (picture->discont_state); + + g_free (picture); +} + +/** + * gst_codec_picture_set_user_data: + * @picture: a #GstCodecPicture + * @user_data: (nullable): private data + * @notify: (closure user_data): a #GDestroyNotify + * + * Sets @user_data on the picture and the #GDestroyNotify that will be called when + * the picture is freed. + * + * If a @user_data was previously set, then the previous set @notify will be called + * before the @user_data is replaced. + * + * Since: 1.24 + */ +void +gst_codec_picture_set_user_data (GstCodecPicture * picture, gpointer user_data, + GDestroyNotify notify) +{ + g_return_if_fail (picture); + + if (picture->notify) + picture->notify (picture->user_data); + + picture->notify = notify; + picture->user_data = user_data; +} + +/** + * gst_codec_picture_get_user_data: + * @picture: a #GstCodecPicture + * + * Gets private data set on the picture via + * gst_codec_picture_set_user_data() previously. + * + * Returns: (transfer none) (nullable): The previously set user_data + * + * Since: 1.24 + */ +gpointer +gst_codec_picture_get_user_data (GstCodecPicture * picture) +{ + g_return_val_if_fail (picture, NULL); + + return picture->user_data; +} + +/** + * gst_codec_picture_set_discont_state: + * @picture: a #GstCodecPicture + * @discont_state: (transfer none) (allow-none): a #GstVideoCodecState + * + * Sets @discont_state to @picture + * + * Since: 1.24 + */ +void +gst_codec_picture_set_discont_state (GstCodecPicture * picture, + GstVideoCodecState * discont_state) +{ + g_return_if_fail (picture); + + g_clear_pointer (&picture->discont_state, gst_video_codec_state_unref); + + if (discont_state) + picture->discont_state = gst_video_codec_state_ref (discont_state); +} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.h b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.h new file mode 100644 index 0000000000..e566368c70 --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/gstcodecpicture.h @@ -0,0 +1,107 @@ +/* GStreamer + * Copyright (C) 2023 Seungha Yang + * + * 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 +#include +#include + +G_BEGIN_DECLS + +typedef struct _GstCodecPicture GstCodecPicture; +#define GST_CODEC_PICTURE(p) ((GstCodecPicture *) p) + +/** + * GST_CODEC_PICTURE_FRAME_NUMBER: + * @picture: a #GstCodecPicture + * + * Gets access to the system_frame_number field of @picture + * + * Since: 1.24 + */ +#define GST_CODEC_PICTURE_FRAME_NUMBER(picture) \ + GST_CODEC_PICTURE(picture)->system_frame_number + +/** + * GST_CODEC_PICTURE_COPY_FRAME_NUMBER: + * @dst: a #GstCodecPicture + * @src: a #GstCodecPicture + * + * Copy system_frame_number of @src to @dst + * + * Since: 1.24 + */ +#define GST_CODEC_PICTURE_COPY_FRAME_NUMBER(dst,src) G_STMT_START { \ + GST_CODEC_PICTURE(dst)->system_frame_number = \ + GST_CODEC_PICTURE(src)->system_frame_number; \ +} G_STMT_END + +/** + * GstCodecPicture: + * + * Base struct for coded picture representation + * + * Since: 1.24 + */ +struct _GstCodecPicture +{ + /*< private >*/ + GstMiniObject parent; + + guint32 system_frame_number; + GstVideoCodecState *discont_state; + + gpointer user_data; + GDestroyNotify notify; + + gpointer _gst_reserved[GST_PADDING]; +}; + +GST_CODECS_API +void gst_codec_picture_set_user_data (GstCodecPicture * picture, + gpointer user_data, + GDestroyNotify notify); + +GST_CODECS_API +gpointer gst_codec_picture_get_user_data (GstCodecPicture * picture); + +GST_CODECS_API +void gst_codec_picture_set_discont_state (GstCodecPicture * picture, + GstVideoCodecState * discont_state); + +static inline GstCodecPicture * +gst_codec_picture_ref (GstCodecPicture * picture) +{ + return (GstCodecPicture *) gst_mini_object_ref ((GstMiniObject *) picture); +} + +static inline void +gst_codec_picture_unref (GstCodecPicture * picture) +{ + gst_mini_object_unref ((GstMiniObject *) picture); +} + +static inline void +gst_clear_codec_picture (GstCodecPicture ** picture) +{ + gst_clear_mini_object ((GstMiniObject **) picture); +} + +G_END_DECLS diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/meson.build b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/meson.build index 406a99e6ae..a4a980bb43 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/codecs/meson.build +++ b/subprojects/gst-plugins-bad/gst-libs/gst/codecs/meson.build @@ -12,6 +12,7 @@ codecs_sources = files( 'gstav1decoder.c', 'gstav1picture.c', 'gstvp9statefulparser.c', + 'gstcodecpicture.c', ) codecs_headers = files( @@ -28,6 +29,7 @@ codecs_headers = files( 'gstav1decoder.h', 'gstav1picture.h', 'gstvp9statefulparser.h', + 'gstcodecpicture.h', ) cp_args = [