1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2016, Oblong Industries, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 # include <mfx/mfxplugin.h>
39 # include "mfxplugin.h"
42 #include "gstmsdkh265enc.h"
44 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265enc_debug);
45 #define GST_CAT_DEFAULT gst_msdkh265enc_debug
47 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
50 GST_STATIC_CAPS ("video/x-h265, "
51 "framerate = (fraction) [0/1, MAX], "
52 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
53 "stream-format = (string) byte-stream , alignment = (string) au , "
54 "profile = (string) main")
57 #define gst_msdkh265enc_parent_class parent_class
58 G_DEFINE_TYPE (GstMsdkH265Enc, gst_msdkh265enc, GST_TYPE_MSDKENC);
61 gst_msdkh265enc_set_format (GstMsdkEnc * encoder)
67 gst_msdkh265enc_configure (GstMsdkEnc * encoder)
69 GstMsdkH265Enc *h265enc = GST_MSDKH265ENC (encoder);
72 const mfxPluginUID *uid;
74 session = gst_msdk_context_get_session (encoder->context);
76 if (encoder->hardware)
77 uid = &MFX_PLUGINID_HEVCE_HW;
79 uid = &MFX_PLUGINID_HEVCE_SW;
81 status = MFXVideoUSER_Load (session, uid, 1);
82 if (status < MFX_ERR_NONE) {
83 GST_ERROR_OBJECT (h265enc, "Media SDK Plugin load failed (%s)",
84 msdk_status_to_string (status));
86 } else if (status > MFX_ERR_NONE) {
87 GST_WARNING_OBJECT (h265enc, "Media SDK Plugin load warning: %s",
88 msdk_status_to_string (status));
91 encoder->param.mfx.CodecId = MFX_CODEC_HEVC;
92 encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN;
97 static inline const gchar *
98 level_to_string (gint level)
101 case MFX_LEVEL_HEVC_1:
103 case MFX_LEVEL_HEVC_2:
105 case MFX_LEVEL_HEVC_21:
107 case MFX_LEVEL_HEVC_3:
109 case MFX_LEVEL_HEVC_31:
111 case MFX_LEVEL_HEVC_4:
113 case MFX_LEVEL_HEVC_41:
115 case MFX_LEVEL_HEVC_5:
117 case MFX_LEVEL_HEVC_51:
119 case MFX_LEVEL_HEVC_52:
121 case MFX_LEVEL_HEVC_6:
123 case MFX_LEVEL_HEVC_61:
125 case MFX_LEVEL_HEVC_62:
135 gst_msdkh265enc_set_src_caps (GstMsdkEnc * encoder)
138 GstStructure *structure;
141 caps = gst_caps_new_empty_simple ("video/x-h265");
142 structure = gst_caps_get_structure (caps, 0);
144 gst_structure_set (structure, "stream-format", G_TYPE_STRING, "byte-stream",
147 gst_structure_set (structure, "alignment", G_TYPE_STRING, "au", NULL);
149 gst_structure_set (structure, "profile", G_TYPE_STRING, "main", NULL);
151 level = level_to_string (encoder->param.mfx.CodecLevel);
153 gst_structure_set (structure, "level", G_TYPE_STRING, level, NULL);
159 gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass)
161 GstElementClass *element_class;
162 GstMsdkEncClass *encoder_class;
164 element_class = GST_ELEMENT_CLASS (klass);
165 encoder_class = GST_MSDKENC_CLASS (klass);
167 encoder_class->set_format = gst_msdkh265enc_set_format;
168 encoder_class->configure = gst_msdkh265enc_configure;
169 encoder_class->set_src_caps = gst_msdkh265enc_set_src_caps;
171 gst_element_class_set_static_metadata (element_class,
172 "Intel MSDK H265 encoder",
173 "Codec/Encoder/Video",
174 "H265 video encoder based on Intel Media SDK",
175 "Josep Torra <jtorra@oblong.com>");
177 gst_element_class_add_static_pad_template (element_class, &src_factory);
181 gst_msdkh265enc_init (GstMsdkH265Enc * thiz)