mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 18:21:04 +00:00
60735deded
Adding new encoder elements nvd3d11{h264,h265}enc for Direct3D11 input support and re-written nvcuda{h264,h265}enc elements. Newly writeen elements have some differences compared with old nv{h264,h265}enc including non-backward compatible changes. * RGBA is not a supported input format any more: New elements will support only YUV formats to avoid implicit conversion done by hardware. Ideally it should be done by upstream element in order to have more control on it. Moreover, RGBA support can cause redundant RGBA -> YUV conversion if multiple encoders are used for the same RGBA input * Subsampled planar format support is dropped: I420 and YV12 format are not supported formats for Direct3D11. Although it's supported in CUDA mode, it's not a hardware friendly memory layout and it will waste GPU memory since UV planes will have large padding due to the memory layout requirement of NVENC. * GL support is dropped: Similar to the RGBA case, GL support in encoder would be suboptimal if GL input is used by multiple encoders, because each encoder will copy GL memory into CUDA memory. Upstream cudaupload element can be used for GL <-> CUDA interop instead. * No more pre-allocation of encoder input surfaces. New implementation will use input CUDA memory without copy (zero-copy) or will copy into a NVENC's input buffer struct in case of system memory input. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1997>
173 lines
No EOL
5.4 KiB
C
173 lines
No EOL
5.4 KiB
C
/* GStreamer
|
|
* Copyright (C) 2022 Seungha Yang <seungha@centricular.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/gst.h>
|
|
#include <gst/video/video.h>
|
|
|
|
#ifdef HAVE_NVCODEC_GST_D3D11
|
|
#include <gst/d3d11/gstd3d11.h>
|
|
#endif
|
|
|
|
#include <string.h>
|
|
|
|
#include "nvEncodeAPI.h"
|
|
#include "gstnvenc.h"
|
|
#include "gstcudamemory.h"
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
#define GST_TYPE_NV_ENCODER (gst_nv_encoder_get_type())
|
|
#define GST_NV_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_NV_ENCODER, GstNvEncoder))
|
|
#define GST_NV_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_NV_ENCODER, GstNvEncoderClass))
|
|
#define GST_IS_NV_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_NV_ENCODER))
|
|
#define GST_IS_NV_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_NV_ENCODER))
|
|
#define GST_NV_ENCODER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_NV_ENCODER, GstNvEncoderClass))
|
|
#define GST_NV_ENCODER_CAST(obj) ((GstNvEncoder *)obj)
|
|
|
|
typedef struct _GstNvEncoder GstNvEncoder;
|
|
typedef struct _GstNvEncoderClass GstNvEncoderClass;
|
|
typedef struct _GstNvEncoderPrivate GstNvEncoderPrivate;
|
|
|
|
typedef enum
|
|
{
|
|
GST_NV_ENCODER_RECONFIGURE_NONE,
|
|
GST_NV_ENCODER_RECONFIGURE_BITRATE,
|
|
GST_NV_ENCODER_RECONFIGURE_FULL,
|
|
} GstNvEncoderReconfigure;
|
|
|
|
#define GST_TYPE_NV_ENCODER_PRESET (gst_nv_encoder_preset_get_type())
|
|
GType gst_nv_encoder_preset_get_type (void);
|
|
typedef enum
|
|
{
|
|
GST_NV_ENCODER_PRESET_DEFAULT,
|
|
GST_NV_ENCODER_PRESET_HP,
|
|
GST_NV_ENCODER_PRESET_HQ,
|
|
GST_NV_ENCODER_PRESET_LOW_LATENCY_DEFAULT,
|
|
GST_NV_ENCODER_PRESET_LOW_LATENCY_HQ,
|
|
GST_NV_ENCODER_PRESET_LOW_LATENCY_HP,
|
|
GST_NV_ENCODER_PRESET_LOSSLESS_DEFAULT,
|
|
GST_NV_ENCODER_PRESET_LOSSLESS_HP,
|
|
} GstNvEncoderPreset;
|
|
|
|
#define GST_TYPE_NV_ENCODER_RC_MODE (gst_nv_encoder_rc_mode_get_type())
|
|
GType gst_nv_encoder_rc_mode_get_type (void);
|
|
|
|
typedef enum
|
|
{
|
|
GST_NV_ENCODER_RC_MODE_DEFAULT,
|
|
GST_NV_ENCODER_RC_MODE_CONSTQP,
|
|
GST_NV_ENCODER_RC_MODE_VBR,
|
|
GST_NV_ENCODER_RC_MODE_CBR,
|
|
GST_NV_ENCODER_RC_MODE_CBR_LOWDELAY_HQ,
|
|
GST_NV_ENCODER_RC_MODE_CBR_HQ,
|
|
GST_NV_ENCODER_RC_MODE_VBR_HQ,
|
|
} GstNvEncoderRCMode;
|
|
|
|
typedef struct
|
|
{
|
|
/* without ref */
|
|
GstNvEncoder *encoder;
|
|
|
|
/* Holds ownership */
|
|
GstBuffer *buffer;
|
|
GstMapInfo map_info;
|
|
|
|
NV_ENC_REGISTER_RESOURCE register_resource;
|
|
NV_ENC_MAP_INPUT_RESOURCE mapped_resource;
|
|
|
|
/* Used when input resource cannot be registered */
|
|
NV_ENC_CREATE_INPUT_BUFFER input_buffer;
|
|
NV_ENC_LOCK_INPUT_BUFFER lk_input_buffer;
|
|
|
|
NV_ENC_OUTPUT_PTR output_ptr;
|
|
gpointer event_handle;
|
|
gboolean is_eos;
|
|
} GstNvEncoderTask;
|
|
|
|
struct _GstNvEncoder
|
|
{
|
|
GstVideoEncoder parent;
|
|
|
|
GstNvEncoderPrivate *priv;
|
|
};
|
|
|
|
struct _GstNvEncoderClass
|
|
{
|
|
GstVideoEncoderClass parent_class;
|
|
|
|
gboolean (*set_format) (GstNvEncoder * encoder,
|
|
GstVideoCodecState * state,
|
|
gpointer session,
|
|
NV_ENC_INITIALIZE_PARAMS * init_params,
|
|
NV_ENC_CONFIG * config);
|
|
|
|
gboolean (*set_output_state) (GstNvEncoder * encoder,
|
|
GstVideoCodecState * state,
|
|
gpointer session);
|
|
|
|
GstBuffer * (*create_output_buffer) (GstNvEncoder * encoder,
|
|
NV_ENC_LOCK_BITSTREAM * bitstream);
|
|
|
|
GstNvEncoderReconfigure (*check_reconfigure) (GstNvEncoder * encoder,
|
|
NV_ENC_CONFIG * config);
|
|
};
|
|
|
|
GType gst_nv_encoder_get_type (void);
|
|
|
|
guint gst_nv_encoder_get_task_size (GstNvEncoder * encoder);
|
|
|
|
const gchar * gst_nv_encoder_status_to_string (NVENCSTATUS status);
|
|
#define GST_NVENC_STATUS_FORMAT "s (%d)"
|
|
#define GST_NVENC_STATUS_ARGS(s) gst_nv_encoder_status_to_string (s), s
|
|
|
|
void gst_nv_encoder_preset_to_guid (GstNvEncoderPreset preset,
|
|
GUID * guid);
|
|
|
|
NV_ENC_PARAMS_RC_MODE gst_nv_encoder_rc_mode_to_native (GstNvEncoderRCMode rc_mode);
|
|
|
|
void gst_nv_encoder_set_cuda_device_id (GstNvEncoder * encoder,
|
|
guint device_id);
|
|
|
|
void gst_nv_encoder_set_dxgi_adapter_luid (GstNvEncoder * encoder,
|
|
gint64 adapter_luid);
|
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstNvEncoder, gst_object_unref)
|
|
|
|
G_END_DECLS
|
|
|
|
#ifdef __cplusplus
|
|
#ifndef G_OS_WIN32
|
|
inline bool is_equal_guid(const GUID & lhs, const GUID & rhs)
|
|
{
|
|
return !!memcmp(&lhs, &rhs, sizeof (GUID));
|
|
}
|
|
|
|
inline bool operator==(const GUID & lhs, const GUID & rhs)
|
|
{
|
|
return is_equal_guid(lhs, rhs);
|
|
}
|
|
|
|
inline bool operator!=(const GUID & lhs, const GUID & rhs)
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
#endif /* G_OS_WIN32 */
|
|
#endif /* __cplusplus */ |