mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
nvcodec: Add H264 stateless codec implementation
Introduce GstH264Decoder based Nvidia H.264 decoder element. Similar the element factory name of to v4l2 stateless codec, this element can be configured with factory name "gstnvh264sldec". Note that "sl" in the name stands for "stateless" For now, existing nvh264dec covers more profile and formats (e.g., interlaced stream) than this implementation. However, this implementation allows us to control lower level parameters such as decoded picture buffer management and therefore we can get a chance to improve performance in terms of latency. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1198>
This commit is contained in:
parent
62d1a3a143
commit
9c21923f04
8 changed files with 2360 additions and 381 deletions
|
@ -1514,9 +1514,6 @@ gst_nvdec_subclass_register (GstPlugin * plugin, GType type,
|
|||
cdata->codec_type = codec_type;
|
||||
cdata->codec = g_strdup (codec);
|
||||
cdata->cuda_device_id = device_id;
|
||||
/* class data will be leaked if the element never gets instantiated */
|
||||
GST_MINI_OBJECT_FLAG_SET (sink_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
||||
GST_MINI_OBJECT_FLAG_SET (src_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
|
||||
|
||||
g_type_query (type, &type_query);
|
||||
memset (&type_info, 0, sizeof (type_info));
|
||||
|
@ -1546,380 +1543,11 @@ gst_nvdec_subclass_register (GstPlugin * plugin, GType type,
|
|||
g_free (type_name);
|
||||
}
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GST_NVDEC_FORMAT_FLAG_NONE = (1 << 0),
|
||||
GST_NVDEC_FORMAT_FLAG_420_8BITS = (1 << 1),
|
||||
GST_NVDEC_FORMAT_FLAG_420_10BITS = (1 << 2),
|
||||
GST_NVDEC_FORMAT_FLAG_420_12BITS = (1 << 3),
|
||||
GST_NVDEC_FORMAT_FLAG_444_8BITS = (1 << 4),
|
||||
GST_NVDEC_FORMAT_FLAG_444_10BITS = (1 << 5),
|
||||
GST_NVDEC_FORMAT_FLAG_444_12BITS = (1 << 6),
|
||||
} GstNvDecFormatFlags;
|
||||
|
||||
static gboolean
|
||||
gst_nvdec_get_supported_codec_profiles (GValue * profiles,
|
||||
cudaVideoCodec codec_type, GstNvDecFormatFlags flags)
|
||||
{
|
||||
GValue val = G_VALUE_INIT;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
g_value_init (&val, G_TYPE_STRING);
|
||||
|
||||
switch (codec_type) {
|
||||
case cudaVideoCodec_H264:
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_8BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_8BITS) {
|
||||
g_value_set_static_string (&val, "constrained-baseline");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
|
||||
g_value_set_static_string (&val, "baseline");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
|
||||
g_value_set_static_string (&val, "main");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
|
||||
g_value_set_static_string (&val, "high");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
/* NVDEC supports only 4:2:0 8bits h264 decoding.
|
||||
* following conditions are for the future enhancement */
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_10BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_10BITS) {
|
||||
g_value_set_static_string (&val, "high-10");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_12BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_12BITS ||
|
||||
(flags & GST_NVDEC_FORMAT_FLAG_444_8BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_8BITS ||
|
||||
(flags & GST_NVDEC_FORMAT_FLAG_444_10BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_10BITS ||
|
||||
(flags & GST_NVDEC_FORMAT_FLAG_444_12BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_12BITS) {
|
||||
g_value_set_static_string (&val, "high-4:4:4");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
break;
|
||||
case cudaVideoCodec_HEVC:
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_8BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_8BITS) {
|
||||
g_value_set_static_string (&val, "main");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_10BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_10BITS) {
|
||||
g_value_set_static_string (&val, "main-10");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_420_12BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_420_12BITS) {
|
||||
g_value_set_static_string (&val, "main-12");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_444_8BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_8BITS) {
|
||||
g_value_set_static_string (&val, "main-444");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_444_10BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_10BITS) {
|
||||
g_value_set_static_string (&val, "main-444-10");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
if ((flags & GST_NVDEC_FORMAT_FLAG_444_12BITS) ==
|
||||
GST_NVDEC_FORMAT_FLAG_444_12BITS) {
|
||||
g_value_set_static_string (&val, "main-444-12");
|
||||
gst_value_list_append_value (profiles, &val);
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
g_value_unset (&val);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
guint idx;
|
||||
cudaVideoChromaFormat format;
|
||||
} GstNvdecChromaMap;
|
||||
|
||||
static void
|
||||
gst_nvdec_register (GstPlugin * plugin, GType type, cudaVideoCodec codec_type,
|
||||
const gchar * codec, const gchar * sink_caps_string, guint rank,
|
||||
gint device_idx, CUcontext cuda_ctx)
|
||||
{
|
||||
{
|
||||
CUresult cuda_ret;
|
||||
gint max_width = 0, min_width = G_MAXINT;
|
||||
gint max_height = 0, min_height = G_MAXINT;
|
||||
GstCaps *sink_templ = NULL;
|
||||
GstCaps *src_templ = NULL;
|
||||
/* FIXME: support 12bits format */
|
||||
guint bitdepth_minus8[3] = { 0, 2, 4 };
|
||||
GstNvDecFormatFlags format_flags = 0;
|
||||
gint c_idx, b_idx;
|
||||
guint num_support = 0;
|
||||
cudaVideoChromaFormat chroma_list[] = {
|
||||
#if 0
|
||||
/* FIXME: support monochrome */
|
||||
cudaVideoChromaFormat_Monochrome,
|
||||
/* FIXME: Can our OpenGL support NV16 and its 10/12bits variant?? */
|
||||
cudaVideoChromaFormat_422,
|
||||
#endif
|
||||
cudaVideoChromaFormat_420,
|
||||
cudaVideoChromaFormat_444,
|
||||
};
|
||||
GValue format_list = G_VALUE_INIT;
|
||||
GValue format = G_VALUE_INIT;
|
||||
GValue profile_list = G_VALUE_INIT;
|
||||
|
||||
g_value_init (&format_list, GST_TYPE_LIST);
|
||||
g_value_init (&format, G_TYPE_STRING);
|
||||
g_value_init (&profile_list, GST_TYPE_LIST);
|
||||
|
||||
if (CuCtxPushCurrent (cuda_ctx) != CUDA_SUCCESS)
|
||||
goto done;
|
||||
|
||||
for (c_idx = 0; c_idx < G_N_ELEMENTS (chroma_list); c_idx++) {
|
||||
for (b_idx = 0; b_idx < G_N_ELEMENTS (bitdepth_minus8); b_idx++) {
|
||||
CUVIDDECODECAPS decoder_caps = { 0, };
|
||||
GstNvDecFormatFlags cur_flag = 0;
|
||||
|
||||
decoder_caps.eCodecType = codec_type;
|
||||
decoder_caps.eChromaFormat = chroma_list[c_idx];
|
||||
decoder_caps.nBitDepthMinus8 = bitdepth_minus8[b_idx];
|
||||
|
||||
cuda_ret = CuvidGetDecoderCaps (&decoder_caps);
|
||||
if (cuda_ret != CUDA_SUCCESS) {
|
||||
GST_INFO ("could not query %s decoder capability, ret %d",
|
||||
codec, cuda_ret);
|
||||
continue;
|
||||
} else if (!decoder_caps.bIsSupported) {
|
||||
GST_LOG ("%s bit-depth %d with chroma format %d is not supported",
|
||||
codec, bitdepth_minus8[b_idx] + 8, c_idx);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (min_width > decoder_caps.nMinWidth)
|
||||
min_width = decoder_caps.nMinWidth;
|
||||
if (min_height > decoder_caps.nMinHeight)
|
||||
min_height = decoder_caps.nMinHeight;
|
||||
if (max_width < decoder_caps.nMaxWidth)
|
||||
max_width = decoder_caps.nMaxWidth;
|
||||
if (max_height < decoder_caps.nMaxHeight)
|
||||
max_height = decoder_caps.nMaxHeight;
|
||||
|
||||
if (chroma_list[c_idx] == cudaVideoChromaFormat_420)
|
||||
cur_flag = GST_NVDEC_FORMAT_FLAG_420_8BITS;
|
||||
else
|
||||
cur_flag = GST_NVDEC_FORMAT_FLAG_444_8BITS;
|
||||
|
||||
format_flags |= (cur_flag << (bitdepth_minus8[b_idx] / 2));
|
||||
|
||||
GST_INFO ("%s bit-depth %d with chroma format %d [%d - %d] x [%d - %d]",
|
||||
codec, bitdepth_minus8[b_idx] + 8, c_idx, min_width, max_width,
|
||||
min_height, max_height);
|
||||
|
||||
switch (chroma_list[c_idx]) {
|
||||
case cudaVideoChromaFormat_420:
|
||||
if (bitdepth_minus8[b_idx] == 0) {
|
||||
g_value_set_string (&format, "NV12");
|
||||
} else if (bitdepth_minus8[b_idx] == 2) {
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
g_value_set_string (&format, "P010_10LE");
|
||||
#else
|
||||
g_value_set_string (&format, "P010_10BE");
|
||||
#endif
|
||||
} else if (bitdepth_minus8[b_idx] == 4) {
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
g_value_set_string (&format, "P016_LE");
|
||||
#else
|
||||
g_value_set_string (&format, "P016_BE");
|
||||
#endif
|
||||
} else {
|
||||
GST_WARNING ("unhandled bitdepth %d", bitdepth_minus8[b_idx] + 8);
|
||||
break;
|
||||
}
|
||||
num_support++;
|
||||
gst_value_list_append_value (&format_list, &format);
|
||||
break;
|
||||
case cudaVideoChromaFormat_444:
|
||||
if (cudaVideoCodec_JPEG == codec_type) {
|
||||
/* NVDEC jpeg decoder can decode 4:4:4 format
|
||||
* but it produces 4:2:0 frame */
|
||||
break;
|
||||
}
|
||||
|
||||
if (bitdepth_minus8[b_idx] == 0) {
|
||||
g_value_set_string (&format, "Y444");
|
||||
} else if (bitdepth_minus8[b_idx] == 2 ||
|
||||
bitdepth_minus8[b_idx] == 4) {
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
g_value_set_string (&format, "Y444_16LE");
|
||||
#else
|
||||
g_value_set_string (&format, "Y444_16BE");
|
||||
#endif
|
||||
} else {
|
||||
GST_WARNING ("unhandled bitdepth %d", bitdepth_minus8[b_idx] + 8);
|
||||
break;
|
||||
}
|
||||
num_support++;
|
||||
gst_value_list_append_value (&format_list, &format);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (num_support == 0) {
|
||||
GST_INFO ("device can not support %s", codec);
|
||||
goto done;
|
||||
}
|
||||
|
||||
src_templ = gst_caps_new_simple ("video/x-raw",
|
||||
"width", GST_TYPE_INT_RANGE, min_width, max_width,
|
||||
"height", GST_TYPE_INT_RANGE, min_height, max_height,
|
||||
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
|
||||
|
||||
gst_caps_set_value (src_templ, "format", &format_list);
|
||||
|
||||
/* OpenGL specific */
|
||||
#if HAVE_NVCODEC_GST_GL
|
||||
{
|
||||
GstCaps *gl_caps = gst_caps_copy (src_templ);
|
||||
gst_caps_set_features_simple (gl_caps,
|
||||
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
|
||||
gst_caps_append (src_templ, gl_caps);
|
||||
}
|
||||
#endif
|
||||
|
||||
sink_templ = gst_caps_from_string (sink_caps_string);
|
||||
gst_caps_set_simple (sink_templ,
|
||||
"width", GST_TYPE_INT_RANGE, min_width, max_width,
|
||||
"height", GST_TYPE_INT_RANGE, min_height, max_height, NULL);
|
||||
|
||||
if (gst_nvdec_get_supported_codec_profiles (&profile_list, codec_type,
|
||||
format_flags)) {
|
||||
gst_caps_set_value (sink_templ, "profile", &profile_list);
|
||||
}
|
||||
|
||||
GST_DEBUG ("sink template caps %" GST_PTR_FORMAT, sink_templ);
|
||||
GST_DEBUG ("src template caps %" GST_PTR_FORMAT, src_templ);
|
||||
|
||||
CuCtxPopCurrent (NULL);
|
||||
|
||||
done:
|
||||
g_value_unset (&format_list);
|
||||
g_value_unset (&format);
|
||||
g_value_unset (&profile_list);
|
||||
|
||||
if (sink_templ && src_templ) {
|
||||
gst_nvdec_subclass_register (plugin, type, codec_type, codec, device_idx,
|
||||
rank, sink_templ, src_templ);
|
||||
}
|
||||
|
||||
gst_clear_caps (&sink_templ);
|
||||
gst_clear_caps (&src_templ);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
cudaVideoCodec codec;
|
||||
const gchar *codec_name;
|
||||
const gchar *sink_caps_string;
|
||||
} GstNvCodecMap;
|
||||
|
||||
const GstNvCodecMap codec_map[] = {
|
||||
{cudaVideoCodec_MPEG1, "mpegvideo",
|
||||
"video/mpeg, mpegversion = (int) 1, systemstream = (boolean) false"},
|
||||
{cudaVideoCodec_MPEG2, "mpeg2video",
|
||||
"video/mpeg, mpegversion = (int) 2, systemstream = (boolean) false"},
|
||||
{cudaVideoCodec_MPEG4, "mpeg4video",
|
||||
"video/mpeg, mpegversion = (int) 4, systemstream = (boolean) false"},
|
||||
#if 0
|
||||
/* FIXME: need verification */
|
||||
{cudaVideoCodec_VC1, "vc1"},
|
||||
#endif
|
||||
/* NOTE: common supported h264 profiles for all GPU architecture
|
||||
* 4:2:0, baseline, main, and high profiles
|
||||
*/
|
||||
{cudaVideoCodec_H264, "h264",
|
||||
"video/x-h264, stream-format = (string) byte-stream"
|
||||
", alignment = (string) au"
|
||||
", profile = (string) { constrained-baseline, baseline, main, high }"},
|
||||
{cudaVideoCodec_JPEG, "jpeg", "image/jpeg"},
|
||||
#if 0
|
||||
/* FIXME: need verification */
|
||||
{cudaVideoCodec_H264_SVC, "h264svc"},
|
||||
{cudaVideoCodec_H264_MVC, "h264mvc"},
|
||||
#endif
|
||||
{cudaVideoCodec_HEVC, "h265",
|
||||
"video/x-h265, stream-format = (string) byte-stream"
|
||||
", alignment = (string) au, profile = (string) { main }"},
|
||||
{cudaVideoCodec_VP8, "vp8", "video/x-vp8"},
|
||||
{cudaVideoCodec_VP9, "vp9", "video/x-vp9"}
|
||||
};
|
||||
|
||||
void
|
||||
gst_nvdec_plugin_init (GstPlugin * plugin, guint device_index,
|
||||
CUcontext cuda_ctx)
|
||||
cudaVideoCodec codec, const gchar * codec_name, GstCaps * sink_template,
|
||||
GstCaps * src_template)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (!gst_cuvid_can_get_decoder_caps ()) {
|
||||
GstCaps *src_templ;
|
||||
|
||||
GST_INFO ("Too old nvidia driver to query decoder capability");
|
||||
|
||||
src_templ = gst_caps_from_string (GST_VIDEO_CAPS_MAKE ("NV12"));
|
||||
|
||||
#if HAVE_NVCODEC_GST_GL
|
||||
{
|
||||
GstCaps *gl_caps = gst_caps_copy (src_templ);
|
||||
gst_caps_set_features_simple (gl_caps,
|
||||
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_GL_MEMORY));
|
||||
gst_caps_append (src_templ, gl_caps);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (codec_map); i++) {
|
||||
GstCaps *sink_templ;
|
||||
|
||||
sink_templ = gst_caps_from_string (codec_map[i].sink_caps_string);
|
||||
|
||||
gst_nvdec_subclass_register (plugin, GST_TYPE_NVDEC, codec_map[i].codec,
|
||||
codec_map[i].codec_name, device_index, GST_RANK_PRIMARY,
|
||||
sink_templ, src_templ);
|
||||
|
||||
gst_clear_caps (&sink_templ);
|
||||
}
|
||||
|
||||
gst_clear_caps (&src_templ);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (codec_map); i++) {
|
||||
gst_nvdec_register (plugin, GST_TYPE_NVDEC, codec_map[i].codec,
|
||||
codec_map[i].codec_name, codec_map[i].sink_caps_string,
|
||||
GST_RANK_PRIMARY, device_index, cuda_ctx);
|
||||
}
|
||||
gst_nvdec_subclass_register (plugin, GST_TYPE_NVDEC, codec,
|
||||
codec_name, device_index, GST_RANK_PRIMARY, sink_template, src_template);
|
||||
}
|
||||
|
|
|
@ -104,7 +104,10 @@ GType gst_nvdec_get_type (void);
|
|||
|
||||
void gst_nvdec_plugin_init (GstPlugin * plugin,
|
||||
guint device_index,
|
||||
CUcontext cuda_ctx);
|
||||
cudaVideoCodec codec,
|
||||
const gchar * codec_name,
|
||||
GstCaps *sink_template,
|
||||
GstCaps *src_template);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
1102
sys/nvcodec/gstnvdecoder.c
Normal file
1102
sys/nvcodec/gstnvdecoder.c
Normal file
File diff suppressed because it is too large
Load diff
89
sys/nvcodec/gstnvdecoder.h
Normal file
89
sys/nvcodec/gstnvdecoder.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef __GST_NV_DECODER_H__
|
||||
#define __GST_NV_DECODER_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include "gstcudautils.h"
|
||||
#include "gstcuvidloader.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_NV_DECODER (gst_nv_decoder_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GstNvDecoder,
|
||||
gst_nv_decoder, GST, NV_DECODER, GstObject);
|
||||
|
||||
typedef struct _GstNvDecoderFrame
|
||||
{
|
||||
/* CUVIDPICPARAMS::CurrPicIdx */
|
||||
gint index;
|
||||
guintptr devptr;
|
||||
guint pitch;
|
||||
|
||||
gboolean mapped;
|
||||
|
||||
/*< private >*/
|
||||
GstNvDecoder *decoder;
|
||||
} GstNvDecoderFrame;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GST_NV_DECOCER_OUTPUT_TYPE_SYSTEM = 0,
|
||||
GST_NV_DECOCER_OUTPUT_TYPE_GL,
|
||||
/* FIXME: add support CUDA, D3D11 memory */
|
||||
} GstNvDecoderOutputType;
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GstNvDecoder * gst_nv_decoder_new (GstCudaContext * context,
|
||||
cudaVideoCodec codec,
|
||||
GstVideoInfo * info,
|
||||
guint pool_size);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GstNvDecoderFrame * gst_nv_decoder_new_frame (GstNvDecoder * decoder);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void gst_nv_decoder_frame_free (GstNvDecoderFrame * frame);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean gst_nv_decoder_decode_picture (GstNvDecoder * decoder,
|
||||
CUVIDPICPARAMS * params);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gboolean gst_nv_decoder_finish_frame (GstNvDecoder * decoder,
|
||||
GstNvDecoderOutputType output_type,
|
||||
GstObject * graphics_context,
|
||||
GstNvDecoderFrame *frame,
|
||||
GstBuffer *buffer);
|
||||
|
||||
/* utils for class registration */
|
||||
G_GNUC_INTERNAL
|
||||
gboolean gst_nv_decoder_check_device_caps (CUcontext cuda_ctx,
|
||||
cudaVideoCodec codec,
|
||||
GstCaps **sink_template,
|
||||
GstCaps **src_template);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
const gchar * gst_cuda_video_codec_to_string (cudaVideoCodec codec);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_NV_DECODER_H__ */
|
1076
sys/nvcodec/gstnvh264dec.c
Normal file
1076
sys/nvcodec/gstnvh264dec.c
Normal file
File diff suppressed because it is too large
Load diff
48
sys/nvcodec/gstnvh264dec.h
Normal file
48
sys/nvcodec/gstnvh264dec.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2020 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.
|
||||
*/
|
||||
|
||||
#ifndef __GST_NV_H264_DEC_H__
|
||||
#define __GST_NV_H264_DEC_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/codecs/gsth264decoder.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_NV_H264_DEC (gst_nv_h264_dec_get_type())
|
||||
#define GST_NV_H264_DEC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_NV_H264_DEC, GstNvH264Dec))
|
||||
#define GST_NV_H264_DEC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_NV_H264_DEC, GstNvH264DecClass))
|
||||
#define GST_NV_H264_DEC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_NV_H264_DEC, GstNvH264DecClass))
|
||||
|
||||
typedef struct _GstNvH264Dec GstNvH264Dec;
|
||||
typedef struct _GstNvH264DecClass GstNvH264DecClass;
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GType gst_nv_h264_dec_get_type (void);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
void gst_nv_h264_dec_register (GstPlugin * plugin,
|
||||
guint device_id,
|
||||
guint rank,
|
||||
GstCaps * sink_caps,
|
||||
GstCaps * src_caps);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_NV_H264_DEC_H__ */
|
|
@ -9,6 +9,8 @@ nvcodec_sources = [
|
|||
'gstcuvidloader.c',
|
||||
'gstcudacontext.c',
|
||||
'gstcudautils.c',
|
||||
'gstnvdecoder.c',
|
||||
'gstnvh264dec.c',
|
||||
]
|
||||
|
||||
if get_option('nvcodec').disabled()
|
||||
|
@ -16,7 +18,7 @@ if get_option('nvcodec').disabled()
|
|||
endif
|
||||
|
||||
plugin_incdirs = [configinc, include_directories('./stub')]
|
||||
extra_c_args = []
|
||||
extra_c_args = ['-DGST_USE_UNSTABLE_API']
|
||||
|
||||
if gstgl_dep.found()
|
||||
extra_c_args += ['-DHAVE_NVCODEC_GST_GL=1']
|
||||
|
@ -26,7 +28,7 @@ gstnvcodec = library('gstnvcodec',
|
|||
nvcodec_sources,
|
||||
c_args : gst_plugins_bad_args + extra_c_args,
|
||||
include_directories : plugin_incdirs,
|
||||
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, gmodule_dep],
|
||||
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, gmodule_dep, gstcodecs_dep],
|
||||
install : true,
|
||||
install_dir : plugins_install_dir,
|
||||
)
|
||||
|
|
|
@ -31,10 +31,13 @@
|
|||
|
||||
#include "gstnvdec.h"
|
||||
#include "gstnvenc.h"
|
||||
#include "gstnvh264dec.h"
|
||||
#include "gstnvdecoder.h"
|
||||
|
||||
GST_DEBUG_CATEGORY (gst_nvcodec_debug);
|
||||
GST_DEBUG_CATEGORY (gst_nvdec_debug);
|
||||
GST_DEBUG_CATEGORY (gst_nvenc_debug);
|
||||
GST_DEBUG_CATEGORY (gst_nv_decoder_debug);
|
||||
|
||||
#define GST_CAT_DEFAULT gst_nvcodec_debug
|
||||
|
||||
|
@ -53,6 +56,7 @@ plugin_init (GstPlugin * plugin)
|
|||
GST_DEBUG_CATEGORY_INIT (gst_nvcodec_debug, "nvcodec", 0, "nvcodec");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_nvdec_debug, "nvdec", 0, "nvdec");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_nvenc_debug, "nvenc", 0, "nvenc");
|
||||
GST_DEBUG_CATEGORY_INIT (gst_nv_decoder_debug, "nvdecoder", 0, "nvdecoder");
|
||||
|
||||
if (!gst_cuda_load_library ()) {
|
||||
GST_WARNING ("Failed to load cuda library");
|
||||
|
@ -104,8 +108,35 @@ plugin_init (GstPlugin * plugin)
|
|||
|
||||
CuCtxPopCurrent (NULL);
|
||||
|
||||
if (nvdec_available)
|
||||
gst_nvdec_plugin_init (plugin, i, cuda_ctx);
|
||||
if (nvdec_available) {
|
||||
gint j;
|
||||
|
||||
for (j = 0; j < cudaVideoCodec_NumCodecs; j++) {
|
||||
GstCaps *sink_template = NULL;
|
||||
GstCaps *src_template = NULL;
|
||||
cudaVideoCodec codec = (cudaVideoCodec) j;
|
||||
|
||||
if (gst_nv_decoder_check_device_caps (cuda_ctx,
|
||||
codec, &sink_template, &src_template)) {
|
||||
const gchar *codec_name = gst_cuda_video_codec_to_string (codec);
|
||||
|
||||
GST_INFO ("CUDA video codec %s, sink template %" GST_PTR_FORMAT
|
||||
"src template %" GST_PTR_FORMAT, codec_name,
|
||||
sink_template, src_template);
|
||||
|
||||
gst_nvdec_plugin_init (plugin,
|
||||
i, codec, codec_name, sink_template, src_template);
|
||||
|
||||
if (codec == cudaVideoCodec_H264) {
|
||||
gst_nv_h264_dec_register (plugin,
|
||||
i, GST_RANK_SECONDARY, sink_template, src_template);
|
||||
}
|
||||
|
||||
gst_caps_unref (sink_template);
|
||||
gst_caps_unref (src_template);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nvenc_available)
|
||||
gst_nvenc_plugin_init (plugin, i, cuda_ctx);
|
||||
|
|
Loading…
Reference in a new issue