1 /* 2 * Copyright (C) 2017 Ericsson AB. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef __GST_NVDEC_H__ 29 #define __GST_NVDEC_H__ 30 31 #ifdef HAVE_NVCODEC_GST_GL 32 #include <gst/gl/gl.h> 33 #include <gst/gl/gstglfuncs.h> 34 #endif 35 36 #include <gst/video/video.h> 37 #include <gst/codecparsers/gsth264parser.h> 38 #include <gst/codecparsers/gsth265parser.h> 39 #include "gstcuvidloader.h" 40 #include "gstcudaloader.h" 41 #include "gstcudacontext.h" 42 43 G_BEGIN_DECLS 44 45 #define GST_TYPE_NVDEC (gst_nvdec_get_type()) 46 #define GST_NVDEC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_NVDEC, GstNvDec)) 47 #define GST_NVDEC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_NVDEC, GstNvDecClass)) 48 #define GST_NVDEC_GET_CLASS(obj)(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_NVDEC,GstNvDecClass)) 49 #define GST_IS_NVDEC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_NVDEC)) 50 #define GST_IS_NVDEC_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_NVDEC)) 51 52 typedef struct _GstNvDec GstNvDec; 53 typedef struct _GstNvDecClass GstNvDecClass; 54 55 typedef enum 56 { 57 GST_NVDEC_STATE_INIT = 0, 58 GST_NVDEC_STATE_PARSE, 59 GST_NVDEC_STATE_DECODE, 60 } GstNvDecState; 61 62 typedef enum 63 { 64 GST_NVDEC_MEM_TYPE_SYSTEM = 0, 65 GST_NVDEC_MEM_TYPE_GL, 66 GST_NVDEC_MEM_TYPE_CUDA, 67 /* FIXME: add support D3D11 memory */ 68 } GstNvDecMemType; 69 70 struct _GstNvDec 71 { 72 GstVideoDecoder parent; 73 74 #ifdef HAVE_NVCODEC_GST_GL 75 GstGLDisplay *gl_display; 76 GstGLContext *gl_context; 77 GstGLContext *other_gl_context; 78 #endif 79 80 guint num_decode_surface; 81 gint max_display_delay; 82 gboolean is_live; 83 84 CUvideoparser parser; 85 CUvideodecoder decoder; 86 GstCudaContext *cuda_ctx; 87 CUstream cuda_stream; 88 89 GstVideoInfo out_info; 90 GstClockTime min_latency; 91 GstVideoCodecState *input_state; 92 GstVideoCodecState *output_state; 93 94 GstFlowReturn last_ret; 95 GstNvDecState state; 96 GstNvDecMemType mem_type; 97 98 GstBuffer *codec_data; 99 gboolean recv_complete_picture; 100 101 GstH264NalParser *h264_parser; 102 GstH265Parser *h265_parser; 103 GstBuffer *vps_nals[GST_H265_MAX_VPS_COUNT]; 104 GstBuffer *sps_nals[GST_H264_MAX_SPS_COUNT]; 105 GstBuffer *pps_nals[GST_H264_MAX_PPS_COUNT]; 106 107 gboolean need_codec_data; 108 }; 109 110 struct _GstNvDecClass 111 { 112 GstVideoDecoderClass parent_class; 113 114 cudaVideoCodec codec_type; 115 guint cuda_device_id; 116 }; 117 118 GType gst_nvdec_get_type (void); 119 120 void gst_nvdec_plugin_init (GstPlugin * plugin, 121 guint device_index, 122 cudaVideoCodec codec, 123 const gchar * codec_name, 124 GstCaps *sink_template, 125 GstCaps *src_template); 126 127 G_END_DECLS 128 129 #endif /* __GST_NVDEC_H__ */ 130