Instead of holding all headers in an external array and add them into the bitstream buffer before the encoding operation, adding extra memory and extra copy operations, the encoder picture should specify the offset where the Vulkan will start to add the bitstream slices/frame, because the element has written already the headers until that offset. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8007>
183 lines
6.7 KiB
C
183 lines
6.7 KiB
C
/*
|
|
* GStreamer
|
|
* Copyright (C) 2023 Igalia, S.L.
|
|
*
|
|
* 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/vulkan/vulkan.h>
|
|
|
|
#define GST_TYPE_VULKAN_ENCODER (gst_vulkan_encoder_get_type())
|
|
#define GST_VULKAN_ENCODER(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_VULKAN_ENCODER, GstVulkanEncoder))
|
|
#define GST_VULKAN_ENCODER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GST_TYPE_VULKAN_ENCODER, GstVulkanEncoderClass))
|
|
#define GST_IS_VULKAN_ENCODER(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_VULKAN_ENCODER))
|
|
#define GST_IS_VULKAN_ENCODER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_VULKAN_ENCODER))
|
|
#define GST_VULKAN_ENCODER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_VULKAN_ENCODER, GstVulkanEncoderClass))
|
|
GST_VULKAN_API
|
|
GType gst_vulkan_encoder_get_type (void);
|
|
|
|
typedef struct _GstVulkanEncoder GstVulkanEncoder;
|
|
typedef struct _GstVulkanEncoderClass GstVulkanEncoderClass;
|
|
typedef union _GstVulkanEncoderParameters GstVulkanEncoderParameters;
|
|
typedef union _GstVulkanEncoderParametersOverrides GstVulkanEncoderParametersOverrides;
|
|
typedef union _GstVulkanEncoderParametersFeedback GstVulkanEncoderParametersFeedback;
|
|
typedef struct _GstVulkanEncoderPicture GstVulkanEncoderPicture;
|
|
|
|
/**
|
|
* GstVulkanEncoderPicture:
|
|
* @slotIndex: slot index
|
|
* @offset: headers offset
|
|
* @width: picture width
|
|
* @height: picture height
|
|
* @fps_n: fps numerator
|
|
* @fps_d: fps denominator
|
|
* @in_buffer: input buffer
|
|
* @out_buffer: output buffer
|
|
*
|
|
* It contains the whole state for encoding a single picture.
|
|
*
|
|
* Since: 1.24
|
|
*/
|
|
struct _GstVulkanEncoderPicture
|
|
{
|
|
gint slotIndex;
|
|
|
|
guint64 offset;
|
|
|
|
gint width;
|
|
gint height;
|
|
|
|
gint fps_n;
|
|
gint fps_d;
|
|
|
|
GstBuffer *in_buffer;
|
|
GstBuffer *dpb_buffer;
|
|
GstBuffer *out_buffer;
|
|
|
|
/* Input frame */
|
|
GstVulkanImageView *img_view;
|
|
GstVulkanImageView *dpb_view;
|
|
|
|
VkVideoPictureResourceInfoKHR dpb;
|
|
|
|
gpointer codec_rc_info;
|
|
gpointer codec_pic_info;
|
|
gpointer codec_rc_layer_info;
|
|
gpointer codec_dpb_slot_info;
|
|
gpointer codec_quality_level;
|
|
};
|
|
|
|
/**
|
|
* GstVulkanEncoder:
|
|
* @parent: the parent #GstObject
|
|
* @queue: the #GstVulkanQueue to command buffers will be allocated from
|
|
*
|
|
* Since: 1.24
|
|
**/
|
|
struct _GstVulkanEncoder
|
|
{
|
|
GstObject parent;
|
|
|
|
GstVulkanQueue *queue;
|
|
|
|
guint codec;
|
|
|
|
/* <private> */
|
|
gpointer _reserved [GST_PADDING];
|
|
};
|
|
|
|
/**
|
|
* GstVulkanEncoderClass:
|
|
* @parent_class: the parent #GstObjectClass
|
|
*
|
|
* Since: 1.24
|
|
*/
|
|
struct _GstVulkanEncoderClass
|
|
{
|
|
GstObjectClass parent;
|
|
/* <private> */
|
|
gpointer _reserved [GST_PADDING];
|
|
};
|
|
|
|
union _GstVulkanEncoderParameters
|
|
{
|
|
/*< private >*/
|
|
VkVideoEncodeH264SessionParametersCreateInfoKHR h264;
|
|
VkVideoEncodeH265SessionParametersCreateInfoKHR h265;
|
|
};
|
|
|
|
union _GstVulkanEncoderParametersOverrides
|
|
{
|
|
/*< private >*/
|
|
VkVideoEncodeH264SessionParametersGetInfoKHR h264;
|
|
VkVideoEncodeH265SessionParametersGetInfoKHR h265;
|
|
};
|
|
|
|
union _GstVulkanEncoderParametersFeedback
|
|
{
|
|
VkVideoEncodeH264SessionParametersFeedbackInfoKHR h264;
|
|
VkVideoEncodeH265SessionParametersFeedbackInfoKHR h265;
|
|
};
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstVulkanEncoder, gst_object_unref)
|
|
|
|
GST_VULKAN_API
|
|
GstVulkanEncoder * gst_vulkan_encoder_create_from_queue (GstVulkanQueue * queue,
|
|
guint codec);
|
|
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_start (GstVulkanEncoder * self,
|
|
GstVulkanVideoProfile * profile,
|
|
GError ** error);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_stop (GstVulkanEncoder * self);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_update_video_session_parameters
|
|
(GstVulkanEncoder * self,
|
|
GstVulkanEncoderParameters *enc_params,
|
|
GError ** error);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_video_session_parameters_overrides
|
|
(GstVulkanEncoder * self,
|
|
GstVulkanEncoderParametersOverrides * params,
|
|
GstVulkanEncoderParametersFeedback * feedback,
|
|
gsize * data_size,
|
|
gpointer * data,
|
|
GError ** error);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_create_dpb_pool (GstVulkanEncoder * self,
|
|
GstCaps * caps);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_encode (GstVulkanEncoder * self,
|
|
GstVulkanEncoderPicture * pic,
|
|
guint nb_refs,
|
|
GstVulkanEncoderPicture ** ref_pics);
|
|
GST_VULKAN_API
|
|
gboolean gst_vulkan_encoder_caps (GstVulkanEncoder * self,
|
|
GstVulkanVideoCapabilities * caps);
|
|
GST_VULKAN_API
|
|
GstCaps * gst_vulkan_encoder_profile_caps (GstVulkanEncoder * self);
|
|
GST_VULKAN_API
|
|
GstVulkanEncoderPicture* gst_vulkan_encoder_picture_new (GstVulkanEncoder * self,
|
|
GstBuffer * in_buffer,
|
|
gint width,
|
|
gint height,
|
|
gsize size);
|
|
GST_VULKAN_API
|
|
void gst_vulkan_encoder_picture_free (GstVulkanEncoderPicture * pic);
|