2022-03-25 13:48:05 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2022 Intel Corporation
|
|
|
|
* Author: 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 the0
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "gstvadevice.h"
|
|
|
|
#include "gstvaencoder.h"
|
|
|
|
#include "gstvaprofile.h"
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
|
|
|
#define GST_TYPE_VA_BASE_ENC (gst_va_base_enc_get_type())
|
|
|
|
#define GST_VA_BASE_ENC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_VA_BASE_ENC, GstVaBaseEnc))
|
|
|
|
#define GST_IS_VA_BASE_ENC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_VA_BASE_ENC))
|
|
|
|
#define GST_VA_BASE_ENC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_VA_BASE_ENC, GstVaBaseEncClass))
|
|
|
|
#define GST_IS_VA_BASE_ENC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_VA_BASE_ENC))
|
|
|
|
#define GST_VA_BASE_ENC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_VA_BASE_ENC, GstVaBaseEncClass))
|
|
|
|
|
2022-09-20 13:00:15 +00:00
|
|
|
#define GST_VA_BASE_ENC_ENTRYPOINT(obj) (GST_VA_BASE_ENC_GET_CLASS(obj)->entrypoint)
|
|
|
|
|
2023-04-06 11:33:02 +00:00
|
|
|
typedef struct _GstVaEncFrame GstVaEncFrame;
|
2022-03-25 13:48:05 +00:00
|
|
|
typedef struct _GstVaBaseEnc GstVaBaseEnc;
|
|
|
|
typedef struct _GstVaBaseEncClass GstVaBaseEncClass;
|
|
|
|
typedef struct _GstVaBaseEncPrivate GstVaBaseEncPrivate;
|
|
|
|
|
2023-04-06 11:33:02 +00:00
|
|
|
struct _GstVaEncFrame
|
|
|
|
{
|
|
|
|
GstVaEncodePicture *picture;
|
|
|
|
};
|
|
|
|
|
2022-03-25 13:48:05 +00:00
|
|
|
struct _GstVaBaseEnc
|
|
|
|
{
|
|
|
|
GstVideoEncoder parent_instance;
|
|
|
|
|
|
|
|
GstVaDisplay *display;
|
|
|
|
GstVaEncoder *encoder;
|
|
|
|
|
2022-10-20 09:13:19 +00:00
|
|
|
gboolean reconf;
|
|
|
|
|
2023-04-24 08:56:16 +00:00
|
|
|
gboolean is_live;
|
|
|
|
|
2022-03-25 13:48:05 +00:00
|
|
|
VAProfile profile;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
guint rt_format;
|
|
|
|
guint codedbuf_size;
|
2024-05-16 00:35:30 +00:00
|
|
|
/* The min buffer number required for reorder and output delay. */
|
|
|
|
guint min_buffers;
|
2022-03-25 13:48:05 +00:00
|
|
|
|
|
|
|
GstClockTime start_pts;
|
|
|
|
GstClockTime frame_duration;
|
|
|
|
|
|
|
|
GQueue reorder_list;
|
|
|
|
GQueue ref_list;
|
|
|
|
GQueue output_list;
|
2024-04-18 14:07:25 +00:00
|
|
|
GstVecDeque *dts_queue;
|
2024-04-04 13:25:51 +00:00
|
|
|
guint preferred_output_delay;
|
2022-03-25 13:48:05 +00:00
|
|
|
|
|
|
|
GstVideoCodecState *input_state;
|
2023-11-08 12:59:44 +00:00
|
|
|
union {
|
|
|
|
GstVideoInfo in_info;
|
|
|
|
GstVideoInfoDmaDrm in_drm_info;
|
|
|
|
};
|
2022-03-25 13:48:05 +00:00
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
GstVaBaseEncPrivate *priv;
|
|
|
|
|
|
|
|
gpointer _padding[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstVaBaseEncClass
|
|
|
|
{
|
|
|
|
GstVideoEncoderClass parent_class;
|
|
|
|
|
2022-05-25 11:57:18 +00:00
|
|
|
void (*reset_state) (GstVaBaseEnc * encoder);
|
2022-03-25 13:48:05 +00:00
|
|
|
gboolean (*reconfig) (GstVaBaseEnc * encoder);
|
|
|
|
gboolean (*new_frame) (GstVaBaseEnc * encoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
|
|
|
gboolean (*reorder_frame) (GstVaBaseEnc * base,
|
|
|
|
GstVideoCodecFrame * frame,
|
|
|
|
gboolean bump_all,
|
|
|
|
GstVideoCodecFrame ** out_frame);
|
2023-03-05 11:01:44 +00:00
|
|
|
GstFlowReturn (*encode_frame) (GstVaBaseEnc * encoder,
|
|
|
|
GstVideoCodecFrame * frame,
|
|
|
|
gboolean is_last);
|
2022-11-10 09:00:28 +00:00
|
|
|
gboolean (*prepare_output) (GstVaBaseEnc * encoder,
|
|
|
|
GstVideoCodecFrame * frame,
|
|
|
|
gboolean * complete);
|
2022-03-25 13:48:05 +00:00
|
|
|
|
|
|
|
GstVaCodecs codec;
|
2022-05-23 12:58:47 +00:00
|
|
|
VAEntrypoint entrypoint;
|
2022-03-25 13:48:05 +00:00
|
|
|
gchar *render_device_path;
|
|
|
|
|
|
|
|
gpointer _padding[GST_PADDING];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CData
|
|
|
|
{
|
2022-05-23 12:58:47 +00:00
|
|
|
VAEntrypoint entrypoint;
|
2022-03-25 13:48:05 +00:00
|
|
|
gchar *render_device_path;
|
|
|
|
gchar *description;
|
|
|
|
GstCaps *sink_caps;
|
|
|
|
GstCaps *src_caps;
|
|
|
|
};
|
|
|
|
|
2022-08-04 10:00:58 +00:00
|
|
|
GType gst_va_base_enc_get_type (void);
|
2022-03-25 13:48:05 +00:00
|
|
|
|
|
|
|
gboolean gst_va_base_enc_add_rate_control_parameter (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture,
|
|
|
|
guint32 rc_mode,
|
|
|
|
guint max_bitrate_bits,
|
|
|
|
guint target_percentage,
|
|
|
|
guint32 qp_i,
|
|
|
|
guint32 min_qp,
|
|
|
|
guint32 max_qp,
|
|
|
|
guint32 mbbrc);
|
|
|
|
gboolean gst_va_base_enc_add_quality_level_parameter (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture,
|
2022-08-04 10:00:58 +00:00
|
|
|
guint target_usage);
|
2022-03-25 13:48:05 +00:00
|
|
|
gboolean gst_va_base_enc_add_frame_rate_parameter (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture);
|
2022-08-04 10:00:58 +00:00
|
|
|
gboolean gst_va_base_enc_add_hrd_parameter (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture,
|
|
|
|
guint32 rc_mode,
|
|
|
|
guint cpb_length_bits);
|
2022-03-25 13:48:05 +00:00
|
|
|
gboolean gst_va_base_enc_add_trellis_parameter (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture,
|
|
|
|
gboolean use_trellis);
|
2022-08-04 10:00:58 +00:00
|
|
|
void gst_va_base_enc_add_codec_tag (GstVaBaseEnc * base,
|
|
|
|
const gchar * codec_name);
|
2022-09-16 10:50:33 +00:00
|
|
|
void gst_va_base_enc_reset_state (GstVaBaseEnc * base);
|
2022-11-10 09:00:28 +00:00
|
|
|
GstBuffer * gst_va_base_enc_create_output_buffer (GstVaBaseEnc * base,
|
2023-06-11 12:17:19 +00:00
|
|
|
GstVaEncodePicture * picture,
|
|
|
|
const guint8 * prefix_data,
|
|
|
|
guint prefix_data_len);
|
2022-11-10 12:36:05 +00:00
|
|
|
gint gst_va_base_enc_copy_output_data (GstVaBaseEnc * base,
|
|
|
|
GstVaEncodePicture * picture,
|
|
|
|
guint8 * data,
|
|
|
|
gint size);
|
2024-05-02 06:18:16 +00:00
|
|
|
void gst_va_base_enc_push_dts (GstVaBaseEnc * base,
|
|
|
|
GstVideoCodecFrame * frame,
|
|
|
|
guint max_reorder_num);
|
|
|
|
GstClockTime gst_va_base_enc_pop_dts (GstVaBaseEnc * base);
|
2022-08-03 15:52:25 +00:00
|
|
|
void gst_va_base_enc_update_property_uint (GstVaBaseEnc * base,
|
|
|
|
guint32 * old_val,
|
|
|
|
guint32 new_val,
|
|
|
|
GParamSpec * pspec);
|
|
|
|
void gst_va_base_enc_update_property_bool (GstVaBaseEnc * base,
|
|
|
|
gboolean * old_val,
|
|
|
|
gboolean new_val,
|
|
|
|
GParamSpec * pspec);
|
|
|
|
|
2023-04-06 11:33:02 +00:00
|
|
|
static inline gpointer
|
|
|
|
gst_va_get_enc_frame (GstVideoCodecFrame * frame)
|
|
|
|
{
|
|
|
|
GstVaEncFrame *enc_frame = gst_video_codec_frame_get_user_data (frame);
|
|
|
|
g_assert (enc_frame);
|
|
|
|
|
|
|
|
return enc_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
gst_va_set_enc_frame (GstVideoCodecFrame * frame,
|
|
|
|
GstVaEncFrame * frame_in, GDestroyNotify notify)
|
|
|
|
{
|
|
|
|
gst_video_codec_frame_set_user_data (frame, frame_in, notify);
|
|
|
|
}
|
|
|
|
|
2022-03-25 13:48:05 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVaBaseEnc, gst_object_unref)
|
|
|
|
|
|
|
|
G_END_DECLS
|