msdkh265enc: add the missing comma
[platform/upstream/gstreamer.git] / sys / msdk / gstmsdkh265enc.c
1 /* GStreamer Intel MSDK plugin
2  * Copyright (c) 2016, Oblong Industries, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  *
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.
14  *
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.
18  *
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.
30  */
31
32 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #include <gst/allocators/gstdmabuf.h>
37
38 #include "gstmsdkh265enc.h"
39
40 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265enc_debug);
41 #define GST_CAT_DEFAULT gst_msdkh265enc_debug
42
43 enum
44 {
45 #ifndef GST_REMOVE_DEPRECATED
46   PROP_LOW_POWER = GST_MSDKENC_PROP_MAX,
47   PROP_TILE_ROW,
48 #else
49   PROP_TILE_ROW = GST_MSDKENC_PROP_MAX,
50 #endif
51   PROP_TILE_COL,
52   PROP_MAX_SLICE_SIZE,
53   PROP_TUNE_MODE,
54 };
55
56 enum
57 {
58   GST_MSDK_FLAG_LOW_POWER = 1 << 0,
59   GST_MSDK_FLAG_TUNE_MODE = 1 << 1,
60 };
61
62 #define PROP_LOWPOWER_DEFAULT           FALSE
63 #define PROP_TILE_ROW_DEFAULT           1
64 #define PROP_TILE_COL_DEFAULT           1
65 #define PROP_MAX_SLICE_SIZE_DEFAULT     0
66 #define PROP_TUNE_MODE_DEFAULT          MFX_CODINGOPTION_UNKNOWN
67
68 #define RAW_FORMATS "NV12, I420, YV12, YUY2, UYVY, BGRA, P010_10LE, VUYA"
69 #define PROFILES    "main, main-10, main-444"
70 #define COMMON_FORMAT "{ " RAW_FORMATS " }"
71 #define PRFOLIE_STR   "{ " PROFILES " }"
72
73
74 #if (MFX_VERSION >= 1027)
75 #undef  COMMON_FORMAT
76 #undef  PRFOLIE_STR
77 #define FORMATS_1027    RAW_FORMATS ", Y410, Y210"
78 #define PROFILES_1027   PROFILES ", main-444-10, main-422-10"
79 #define COMMON_FORMAT   "{ " FORMATS_1027 " }"
80 #define PRFOLIE_STR     "{ " PROFILES_1027 " }"
81 #endif
82
83 #if (MFX_VERSION >= 1031)
84 #undef  COMMON_FORMAT
85 #undef  PRFOLIE_STR
86 #define FORMATS_1031    FORMATS_1027 ", P012_LE"
87 #define PROFILES_1031   PROFILES_1027  ", main-12"
88 #define COMMON_FORMAT   "{ " FORMATS_1031 " }"
89 #define PRFOLIE_STR     "{ " PROFILES_1031 " }"
90 #endif
91
92 #if (MFX_VERSION >= 1032)
93 #undef  COMMON_FORMAT
94 #undef  PRFOLIE_STR
95 #define FORMATS_1032    FORMATS_1031
96 #define PROFILES_1032   PROFILES_1031  ", screen-extended-main, " \
97   "screen-extended-main-10, screen-extended-main-444, " \
98   "screen-extended-main-444-10"
99 #define COMMON_FORMAT   "{ " FORMATS_1032 " }"
100 #define PRFOLIE_STR     "{ " PROFILES_1032 " }"
101 #endif
102
103 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
104     GST_PAD_SINK,
105     GST_PAD_ALWAYS,
106     GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT,
107             "{ NV12, P010_10LE }")));
108
109 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
110     GST_PAD_SRC,
111     GST_PAD_ALWAYS,
112     GST_STATIC_CAPS ("video/x-h265, "
113         "framerate = (fraction) [0/1, MAX], "
114         "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
115         "stream-format = (string) byte-stream , alignment = (string) au , "
116         "profile = (string) " PRFOLIE_STR)
117     );
118
119 #define gst_msdkh265enc_parent_class parent_class
120 G_DEFINE_TYPE (GstMsdkH265Enc, gst_msdkh265enc, GST_TYPE_MSDKENC);
121
122 static void
123 gst_msdkh265enc_insert_sei (GstMsdkH265Enc * thiz, GstVideoCodecFrame * frame,
124     GstMemory * sei_mem)
125 {
126   GstBuffer *new_buffer;
127
128   if (!thiz->parser)
129     thiz->parser = gst_h265_parser_new ();
130
131   new_buffer = gst_h265_parser_insert_sei (thiz->parser,
132       frame->output_buffer, sei_mem);
133
134   if (!new_buffer) {
135     GST_WARNING_OBJECT (thiz, "Cannot insert SEI nal into AU buffer");
136     return;
137   }
138
139   gst_buffer_unref (frame->output_buffer);
140   frame->output_buffer = new_buffer;
141 }
142
143 static void
144 gst_msdkh265enc_add_cc (GstMsdkH265Enc * thiz, GstVideoCodecFrame * frame)
145 {
146   GstVideoCaptionMeta *cc_meta;
147   gpointer iter = NULL;
148   GstBuffer *in_buf = frame->input_buffer;
149   GstMemory *mem = NULL;
150
151   if (thiz->cc_sei_array)
152     g_array_set_size (thiz->cc_sei_array, 0);
153
154   while ((cc_meta =
155           (GstVideoCaptionMeta *) gst_buffer_iterate_meta_filtered (in_buf,
156               &iter, GST_VIDEO_CAPTION_META_API_TYPE))) {
157     GstH265SEIMessage sei;
158     GstH265RegisteredUserData *rud;
159     guint8 *data;
160
161     if (cc_meta->caption_type != GST_VIDEO_CAPTION_TYPE_CEA708_RAW)
162       continue;
163
164     memset (&sei, 0, sizeof (GstH265SEIMessage));
165     sei.payloadType = GST_H265_SEI_REGISTERED_USER_DATA;
166     rud = &sei.payload.registered_user_data;
167
168     rud->country_code = 181;
169     rud->size = cc_meta->size + 10;
170
171     data = g_malloc (rud->size);
172     memcpy (data + 9, cc_meta->data, cc_meta->size);
173
174     data[0] = 0;                /* 16-bits itu_t_t35_provider_code */
175     data[1] = 49;
176     data[2] = 'G';              /* 32-bits ATSC_user_identifier */
177     data[3] = 'A';
178     data[4] = '9';
179     data[5] = '4';
180     data[6] = 3;                /* 8-bits ATSC1_data_user_data_type_code */
181     /* 8-bits:
182      * 1 bit process_em_data_flag (0)
183      * 1 bit process_cc_data_flag (1)
184      * 1 bit additional_data_flag (0)
185      * 5-bits cc_count
186      */
187     data[7] = ((cc_meta->size / 3) & 0x1f) | 0x40;
188     data[8] = 255;              /* 8 bits em_data, unused */
189     data[cc_meta->size + 9] = 255;      /* 8 marker bits */
190
191     rud->data = data;
192
193     if (!thiz->cc_sei_array) {
194       thiz->cc_sei_array =
195           g_array_new (FALSE, FALSE, sizeof (GstH265SEIMessage));
196       g_array_set_clear_func (thiz->cc_sei_array,
197           (GDestroyNotify) gst_h265_sei_free);
198     }
199
200     g_array_append_val (thiz->cc_sei_array, sei);
201   }
202
203   if (!thiz->cc_sei_array || !thiz->cc_sei_array->len)
204     return;
205
206   /* layer_id and temporal_id will be updated by parser later */
207   mem = gst_h265_create_sei_memory (0, 1, 4, thiz->cc_sei_array);
208
209   if (!mem) {
210     GST_WARNING_OBJECT (thiz, "Cannot create SEI nal unit");
211     return;
212   }
213
214   GST_DEBUG_OBJECT (thiz,
215       "Inserting %d closed caption SEI message(s)", thiz->cc_sei_array->len);
216
217   gst_msdkh265enc_insert_sei (thiz, frame, mem);
218   gst_memory_unref (mem);
219 }
220
221 static GstFlowReturn
222 gst_msdkh265enc_pre_push (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
223 {
224   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (encoder);
225
226   gst_msdkh265enc_add_cc (thiz, frame);
227
228   return GST_FLOW_OK;
229 }
230
231 static gboolean
232 gst_msdkh265enc_set_format (GstMsdkEnc * encoder)
233 {
234   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (encoder);
235   GstCaps *template_caps, *allowed_caps;
236
237   g_free (thiz->profile_name);
238   thiz->profile_name = NULL;
239
240   allowed_caps = gst_pad_get_allowed_caps (GST_VIDEO_ENCODER_SRC_PAD (encoder));
241
242   if (!allowed_caps || gst_caps_is_empty (allowed_caps)) {
243     if (allowed_caps)
244       gst_caps_unref (allowed_caps);
245     return FALSE;
246   }
247
248   template_caps = gst_static_pad_template_get_caps (&src_factory);
249
250   if (gst_caps_is_equal (allowed_caps, template_caps)) {
251     GST_INFO_OBJECT (thiz,
252         "downstream have the same caps, profile set to auto");
253   } else {
254     GstStructure *s;
255     const gchar *profile;
256
257     allowed_caps = gst_caps_make_writable (allowed_caps);
258     allowed_caps = gst_caps_fixate (allowed_caps);
259     s = gst_caps_get_structure (allowed_caps, 0);
260     profile = gst_structure_get_string (s, "profile");
261
262     if (profile) {
263       thiz->profile_name = g_strdup (profile);
264     }
265   }
266
267   gst_caps_unref (allowed_caps);
268   gst_caps_unref (template_caps);
269
270   return TRUE;
271 }
272
273 static gboolean
274 gst_msdkh265enc_configure (GstMsdkEnc * encoder)
275 {
276   GstMsdkH265Enc *h265enc = GST_MSDKH265ENC (encoder);
277   mfxSession session;
278   const mfxPluginUID *uid;
279
280   session = gst_msdk_context_get_session (encoder->context);
281
282   if (encoder->hardware)
283     uid = &MFX_PLUGINID_HEVCE_HW;
284   else
285     uid = &MFX_PLUGINID_HEVCE_SW;
286
287   if (!gst_msdk_load_plugin (session, uid, 1, "msdkh265enc"))
288     return FALSE;
289
290   encoder->param.mfx.CodecId = MFX_CODEC_HEVC;
291
292   if (h265enc->profile_name) {
293     encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN;
294
295     if (!strcmp (h265enc->profile_name, "main-10"))
296       encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN10;
297     else if (!strcmp (h265enc->profile_name, "main-444") ||
298         !strcmp (h265enc->profile_name, "main-422-10") ||
299         !strcmp (h265enc->profile_name, "main-444-10") ||
300         !strcmp (h265enc->profile_name, "main-12"))
301       encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_REXT;
302
303 #if (MFX_VERSION >= 1032)
304     else if (!strcmp (h265enc->profile_name, "screen-extended-main") ||
305         !strcmp (h265enc->profile_name, "screen-extended-main-10") ||
306         !strcmp (h265enc->profile_name, "screen-extended-main-444") ||
307         !strcmp (h265enc->profile_name, "screen-extended-main-444-10"))
308       encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_SCC;
309 #endif
310   } else {
311     switch (encoder->param.mfx.FrameInfo.FourCC) {
312       case MFX_FOURCC_P010:
313         encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN10;
314         break;
315       case MFX_FOURCC_AYUV:
316       case MFX_FOURCC_YUY2:
317 #if (MFX_VERSION >= 1027)
318       case MFX_FOURCC_Y410:
319       case MFX_FOURCC_Y210:
320 #endif
321 #if (MFX_VERSION >= 1031)
322       case MFX_FOURCC_P016:
323 #endif
324         encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_REXT;
325         break;
326       default:
327         encoder->param.mfx.CodecProfile = MFX_PROFILE_HEVC_MAIN;
328     }
329   }
330
331   /* IdrInterval field of MediaSDK HEVC encoder behaves differently
332    * than other encoders. IdrInteval == 1 indicate every
333    * I-frame should be an IDR, IdrInteval == 2 means every other
334    * I-frame is an IDR etc. So we generalize the behaviour of property
335    * "i-frames" by incrementing the value by one in each case*/
336   encoder->param.mfx.IdrInterval += 1;
337
338   /* Enable Extended coding options */
339   encoder->option2.MaxSliceSize = h265enc->max_slice_size;
340   gst_msdkenc_ensure_extended_coding_options (encoder);
341
342   if (h265enc->num_tile_rows > 1 || h265enc->num_tile_cols > 1) {
343     h265enc->ext_tiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
344     h265enc->ext_tiles.Header.BufferSz = sizeof (h265enc->ext_tiles);
345     h265enc->ext_tiles.NumTileRows = h265enc->num_tile_rows;
346     h265enc->ext_tiles.NumTileColumns = h265enc->num_tile_cols;
347
348     gst_msdkenc_add_extra_param (encoder,
349         (mfxExtBuffer *) & h265enc->ext_tiles);
350
351     /* Set a valid value to NumSlice */
352     if (encoder->param.mfx.NumSlice == 0)
353       encoder->param.mfx.NumSlice =
354           h265enc->num_tile_rows * h265enc->num_tile_cols;
355   }
356
357   encoder->param.mfx.LowPower = h265enc->tune_mode;
358
359   return TRUE;
360 }
361
362 static inline const gchar *
363 level_to_string (gint level)
364 {
365   switch (level) {
366     case MFX_LEVEL_HEVC_1:
367       return "1";
368     case MFX_LEVEL_HEVC_2:
369       return "2";
370     case MFX_LEVEL_HEVC_21:
371       return "2.1";
372     case MFX_LEVEL_HEVC_3:
373       return "3";
374     case MFX_LEVEL_HEVC_31:
375       return "3.1";
376     case MFX_LEVEL_HEVC_4:
377       return "4";
378     case MFX_LEVEL_HEVC_41:
379       return "4.1";
380     case MFX_LEVEL_HEVC_5:
381       return "5";
382     case MFX_LEVEL_HEVC_51:
383       return "5.1";
384     case MFX_LEVEL_HEVC_52:
385       return "5.2";
386     case MFX_LEVEL_HEVC_6:
387       return "6";
388     case MFX_LEVEL_HEVC_61:
389       return "6.1";
390     case MFX_LEVEL_HEVC_62:
391       return "6.2";
392     default:
393       break;
394   }
395
396   return NULL;
397 }
398
399 static GstCaps *
400 gst_msdkh265enc_set_src_caps (GstMsdkEnc * encoder)
401 {
402   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (encoder);
403   GstCaps *caps;
404   GstStructure *structure;
405   const gchar *level;
406
407   caps = gst_caps_new_empty_simple ("video/x-h265");
408   structure = gst_caps_get_structure (caps, 0);
409
410   gst_structure_set (structure, "stream-format", G_TYPE_STRING, "byte-stream",
411       NULL);
412
413   gst_structure_set (structure, "alignment", G_TYPE_STRING, "au", NULL);
414
415   if (thiz->profile_name)
416     gst_structure_set (structure, "profile", G_TYPE_STRING, thiz->profile_name,
417         NULL);
418   else {
419     switch (encoder->param.mfx.FrameInfo.FourCC) {
420       case MFX_FOURCC_P010:
421         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-10",
422             NULL);
423         break;
424       case MFX_FOURCC_AYUV:
425         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-444",
426             NULL);
427         break;
428       case MFX_FOURCC_YUY2:
429         /* The profile is main-422-10 for 8-bit 422 */
430         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-422-10",
431             NULL);
432         break;
433 #if (MFX_VERSION >= 1027)
434       case MFX_FOURCC_Y410:
435         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-444-10",
436             NULL);
437         break;
438       case MFX_FOURCC_Y210:
439         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-422-10",
440             NULL);
441         break;
442 #endif
443 #if (MFX_VERSION >= 1031)
444       case MFX_FOURCC_P016:
445         gst_structure_set (structure, "profile", G_TYPE_STRING, "main-12",
446             NULL);
447         break;
448 #endif
449       default:
450         gst_structure_set (structure, "profile", G_TYPE_STRING, "main", NULL);
451         break;
452     }
453   }
454
455   level = level_to_string (encoder->param.mfx.CodecLevel);
456   if (level)
457     gst_structure_set (structure, "level", G_TYPE_STRING, level, NULL);
458
459   return caps;
460 }
461
462 static void
463 gst_msdkh265enc_finalize (GObject * object)
464 {
465   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (object);
466
467   if (thiz->parser)
468     gst_h265_parser_free (thiz->parser);
469   if (thiz->cc_sei_array)
470     g_array_unref (thiz->cc_sei_array);
471
472   g_free (thiz->profile_name);
473
474   G_OBJECT_CLASS (parent_class)->finalize (object);
475 }
476
477 static void
478 gst_msdkh265enc_set_property (GObject * object, guint prop_id,
479     const GValue * value, GParamSpec * pspec)
480 {
481   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (object);
482
483   if (gst_msdkenc_set_common_property (object, prop_id, value, pspec))
484     return;
485
486   GST_OBJECT_LOCK (thiz);
487
488   switch (prop_id) {
489 #ifndef GST_REMOVE_DEPRECATED
490     case PROP_LOW_POWER:
491       thiz->lowpower = g_value_get_boolean (value);
492       thiz->prop_flag |= GST_MSDK_FLAG_LOW_POWER;
493
494       /* Ignore it if user set tune mode explicitly */
495       if (!(thiz->prop_flag & GST_MSDK_FLAG_TUNE_MODE))
496         thiz->tune_mode =
497             thiz->lowpower ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
498
499       break;
500 #endif
501
502     case PROP_TILE_ROW:
503       thiz->num_tile_rows = g_value_get_uint (value);
504       break;
505
506     case PROP_TILE_COL:
507       thiz->num_tile_cols = g_value_get_uint (value);
508       break;
509
510     case PROP_MAX_SLICE_SIZE:
511       thiz->max_slice_size = g_value_get_uint (value);
512       break;
513
514     case PROP_TUNE_MODE:
515       thiz->tune_mode = g_value_get_enum (value);
516       thiz->prop_flag |= GST_MSDK_FLAG_TUNE_MODE;
517       break;
518
519     default:
520       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
521       break;
522   }
523   GST_OBJECT_UNLOCK (thiz);
524 }
525
526 static void
527 gst_msdkh265enc_get_property (GObject * object, guint prop_id, GValue * value,
528     GParamSpec * pspec)
529 {
530   GstMsdkH265Enc *thiz = GST_MSDKH265ENC (object);
531
532   if (gst_msdkenc_get_common_property (object, prop_id, value, pspec))
533     return;
534
535   GST_OBJECT_LOCK (thiz);
536   switch (prop_id) {
537 #ifndef GST_REMOVE_DEPRECATED
538     case PROP_LOW_POWER:
539       g_value_set_boolean (value, thiz->lowpower);
540       break;
541 #endif
542
543     case PROP_TILE_ROW:
544       g_value_set_uint (value, thiz->num_tile_rows);
545       break;
546
547     case PROP_TILE_COL:
548       g_value_set_uint (value, thiz->num_tile_cols);
549       break;
550
551     case PROP_MAX_SLICE_SIZE:
552       g_value_set_uint (value, thiz->max_slice_size);
553       break;
554
555     case PROP_TUNE_MODE:
556       g_value_set_enum (value, thiz->tune_mode);
557       break;
558
559     default:
560       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
561       break;
562   }
563   GST_OBJECT_UNLOCK (thiz);
564 }
565
566 static gboolean
567 gst_msdkh265enc_need_reconfig (GstMsdkEnc * encoder, GstVideoCodecFrame * frame)
568 {
569   GstMsdkH265Enc *h265enc = GST_MSDKH265ENC (encoder);
570
571   return gst_msdkenc_get_roi_params (encoder, frame, h265enc->roi);
572 }
573
574 static void
575 gst_msdkh265enc_set_extra_params (GstMsdkEnc * encoder,
576     GstVideoCodecFrame * frame)
577 {
578   GstMsdkH265Enc *h265enc = GST_MSDKH265ENC (encoder);
579
580   if (h265enc->roi[0].NumROI)
581     gst_msdkenc_add_extra_param (encoder, (mfxExtBuffer *) & h265enc->roi[0]);
582 }
583
584 static gboolean
585 gst_msdkh265enc_need_conversion (GstMsdkEnc * encoder, GstVideoInfo * info,
586     GstVideoFormat * out_format)
587 {
588   GstMsdkH265Enc *h265enc = GST_MSDKH265ENC (encoder);
589
590   switch (GST_VIDEO_INFO_FORMAT (info)) {
591     case GST_VIDEO_FORMAT_NV12:
592     case GST_VIDEO_FORMAT_P010_10LE:
593     case GST_VIDEO_FORMAT_VUYA:
594 #if (MFX_VERSION >= 1027)
595     case GST_VIDEO_FORMAT_Y410:
596     case GST_VIDEO_FORMAT_Y210:
597 #endif
598 #if (MFX_VERSION >= 1031)
599     case GST_VIDEO_FORMAT_P012_LE:
600 #endif
601       return FALSE;
602
603     case GST_VIDEO_FORMAT_YUY2:
604 #if (MFX_VERSION >= 1027)
605       if (encoder->codename >= MFX_PLATFORM_ICELAKE &&
606           h265enc->tune_mode == MFX_CODINGOPTION_OFF)
607         return FALSE;
608 #endif
609     default:
610       if (GST_VIDEO_INFO_COMP_DEPTH (info, 0) == 10)
611         *out_format = GST_VIDEO_FORMAT_P010_10LE;
612       else
613         *out_format = GST_VIDEO_FORMAT_NV12;
614       return TRUE;
615   }
616 }
617
618 static void
619 gst_msdkh265enc_class_init (GstMsdkH265EncClass * klass)
620 {
621   GObjectClass *gobject_class;
622   GstElementClass *element_class;
623   GstVideoEncoderClass *videoencoder_class;
624   GstMsdkEncClass *encoder_class;
625
626   gobject_class = G_OBJECT_CLASS (klass);
627   element_class = GST_ELEMENT_CLASS (klass);
628   videoencoder_class = GST_VIDEO_ENCODER_CLASS (klass);
629   encoder_class = GST_MSDKENC_CLASS (klass);
630
631   gobject_class->finalize = gst_msdkh265enc_finalize;
632   gobject_class->set_property = gst_msdkh265enc_set_property;
633   gobject_class->get_property = gst_msdkh265enc_get_property;
634
635   videoencoder_class->pre_push = gst_msdkh265enc_pre_push;
636
637   encoder_class->set_format = gst_msdkh265enc_set_format;
638   encoder_class->configure = gst_msdkh265enc_configure;
639   encoder_class->set_src_caps = gst_msdkh265enc_set_src_caps;
640   encoder_class->need_reconfig = gst_msdkh265enc_need_reconfig;
641   encoder_class->set_extra_params = gst_msdkh265enc_set_extra_params;
642   encoder_class->need_conversion = gst_msdkh265enc_need_conversion;
643
644   gst_msdkenc_install_common_properties (encoder_class);
645
646 #ifndef GST_REMOVE_DEPRECATED
647   g_object_class_install_property (gobject_class, PROP_LOW_POWER,
648       g_param_spec_boolean ("low-power", "Low power",
649           "Enable low power mode (DEPRECATED, use tune instead)",
650           PROP_LOWPOWER_DEFAULT,
651           G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
652 #endif
653
654   g_object_class_install_property (gobject_class, PROP_TILE_ROW,
655       g_param_spec_uint ("num-tile-rows", "number of rows for tiled encoding",
656           "number of rows for tiled encoding",
657           1, 8192, PROP_TILE_ROW_DEFAULT,
658           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
659
660   g_object_class_install_property (gobject_class, PROP_TILE_COL,
661       g_param_spec_uint ("num-tile-cols",
662           "number of columns for tiled encoding",
663           "number of columns for tiled encoding", 1, 8192,
664           PROP_TILE_COL_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
665
666   g_object_class_install_property (gobject_class, PROP_MAX_SLICE_SIZE,
667       g_param_spec_uint ("max-slice-size", "Max Slice Size",
668           "Maximum slice size in bytes (if enabled MSDK will ignore the control over num-slices)",
669           0, G_MAXUINT32, PROP_MAX_SLICE_SIZE_DEFAULT,
670           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
671
672   g_object_class_install_property (gobject_class, PROP_TUNE_MODE,
673       g_param_spec_enum ("tune", "Encoder tuning",
674           "Encoder tuning option",
675           gst_msdkenc_tune_mode_get_type (), PROP_TUNE_MODE_DEFAULT,
676           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
677
678   gst_element_class_set_static_metadata (element_class,
679       "Intel MSDK H265 encoder",
680       "Codec/Encoder/Video/Hardware",
681       "H265 video encoder based on Intel Media SDK",
682       "Josep Torra <jtorra@oblong.com>");
683
684   gst_element_class_add_static_pad_template (element_class, &sink_factory);
685   gst_element_class_add_static_pad_template (element_class, &src_factory);
686 }
687
688 static void
689 gst_msdkh265enc_init (GstMsdkH265Enc * thiz)
690 {
691   GstMsdkEnc *msdk_enc = (GstMsdkEnc *) thiz;
692   thiz->lowpower = PROP_LOWPOWER_DEFAULT;
693   thiz->num_tile_rows = PROP_TILE_ROW_DEFAULT;
694   thiz->num_tile_cols = PROP_TILE_COL_DEFAULT;
695   thiz->max_slice_size = PROP_MAX_SLICE_SIZE_DEFAULT;
696   thiz->tune_mode = PROP_TUNE_MODE_DEFAULT;
697   msdk_enc->num_extra_frames = 1;
698 }