gstmsdkdec.c 45.1 KB
Newer Older
Scott D Phillips's avatar
Scott D Phillips committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* GStreamer Intel MSDK plugin
 * Copyright (c) 2016, Intel Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdlib.h>

#include "gstmsdkdec.h"
Hyunjun Ko's avatar
Hyunjun Ko committed
39
40
41
#include "gstmsdkbufferpool.h"
#include "gstmsdkvideomemory.h"
#include "gstmsdksystemmemory.h"
42
#include "gstmsdkcontextutil.h"
Scott D Phillips's avatar
Scott D Phillips committed
43
44
45
46
47
48
49
50
51
52
53

GST_DEBUG_CATEGORY_EXTERN (gst_msdkdec_debug);
#define GST_CAT_DEFAULT gst_msdkdec_debug

static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("video/x-raw, "
        "format = (string) { NV12 }, "
        "framerate = (fraction) [0, MAX], "
        "width = (int) [ 16, MAX ], height = (int) [ 16, MAX ],"
Hyunjun Ko's avatar
Hyunjun Ko committed
54
55
56
        "interlace-mode = (string) progressive;"
        GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
            "{ NV12 }") ";")
Scott D Phillips's avatar
Scott D Phillips committed
57
58
59
    );

#define PROP_HARDWARE_DEFAULT            TRUE
60
#define PROP_ASYNC_DEPTH_DEFAULT         1
Scott D Phillips's avatar
Scott D Phillips committed
61

62
63
#define IS_ALIGNED(i, n) (((i) & ((n)-1)) == 0)

Scott D Phillips's avatar
Scott D Phillips committed
64
65
66
67
68
#define gst_msdkdec_parent_class parent_class
G_DEFINE_TYPE (GstMsdkDec, gst_msdkdec, GST_TYPE_VIDEO_DECODER);

typedef struct _MsdkSurface
{
Hyunjun Ko's avatar
Hyunjun Ko committed
69
70
  mfxFrameSurface1 *surface;
  GstBuffer *buf;
Scott D Phillips's avatar
Scott D Phillips committed
71
72
73
74
  GstVideoFrame data;
  GstVideoFrame copy;
} MsdkSurface;

75
static gboolean gst_msdkdec_drain (GstVideoDecoder * decoder);
76
static gboolean gst_msdkdec_flush (GstVideoDecoder * decoder);
77
static gboolean gst_msdkdec_negotiate (GstMsdkDec * thiz, gboolean hard_reset);
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
static GstVideoCodecFrame *
gst_msdkdec_get_oldest_frame (GstVideoDecoder * decoder)
{
  GstVideoCodecFrame *frame = NULL, *old_frame = NULL;
  GList *frames, *l;
  gint count = 0;

  frames = gst_video_decoder_get_frames (decoder);

  for (l = frames; l != NULL; l = l->next) {
    GstVideoCodecFrame *f = l->data;

    if (!GST_CLOCK_TIME_IS_VALID (f->pts)) {
      GST_INFO
          ("Frame doesn't have a valid pts yet, Use gst_video_decoder_get_oldest_frame()"
          "with out considering the PTS for selecting the frame to be finished");
      old_frame = gst_video_decoder_get_oldest_frame (decoder);
      break;
    }

    if (!frame || frame->pts > f->pts)
      frame = f;

    count++;
  }

  if (old_frame)
    frame = old_frame;

  if (frame) {
    GST_LOG_OBJECT (decoder,
        "Oldest frame is %d %" GST_TIME_FORMAT " and %d frames left",
        frame->system_frame_number, GST_TIME_ARGS (frame->pts), count - 1);
    gst_video_codec_frame_ref (frame);
  }

  if (old_frame)
    gst_video_codec_frame_unref (old_frame);

  g_list_free_full (frames, (GDestroyNotify) gst_video_codec_frame_unref);

  return frame;
}

123
124
125
126
127
128
129
static GstFlowReturn
allocate_output_buffer (GstMsdkDec * thiz, GstBuffer ** buffer)
{
  GstFlowReturn flow;
  GstVideoCodecFrame *frame;
  GstVideoDecoder *decoder = GST_VIDEO_DECODER (thiz);

130
  frame = gst_msdkdec_get_oldest_frame (decoder);
131
132
133
134
135
136
  if (!frame) {
    if (GST_PAD_IS_FLUSHING (decoder->srcpad))
      return GST_FLOW_FLUSHING;
    else
      return GST_FLOW_ERROR;
  }
Hyunjun Ko's avatar
Hyunjun Ko committed
137

138
139
140
141
142
143
144
  if (!frame->output_buffer) {
    flow = gst_video_decoder_allocate_output_frame (decoder, frame);
    if (flow != GST_FLOW_OK) {
      gst_video_codec_frame_unref (frame);
      return flow;
    }
  }
Hyunjun Ko's avatar
Hyunjun Ko committed
145

146
147
148
149
150
151
  *buffer = gst_buffer_ref (frame->output_buffer);
  gst_buffer_replace (&frame->output_buffer, NULL);
  gst_video_codec_frame_unref (frame);
  return GST_FLOW_OK;
}

Scott D Phillips's avatar
Scott D Phillips committed
152
static void
Hyunjun Ko's avatar
Hyunjun Ko committed
153
free_surface (GstMsdkDec * thiz, MsdkSurface * s)
Scott D Phillips's avatar
Scott D Phillips committed
154
155
156
157
158
159
{
  if (s->copy.buffer) {
    gst_video_frame_unmap (&s->copy);
    gst_buffer_unref (s->copy.buffer);
  }

Hyunjun Ko's avatar
Hyunjun Ko committed
160
  if (s->data.buffer)
Scott D Phillips's avatar
Scott D Phillips committed
161
162
    gst_video_frame_unmap (&s->data);

Hyunjun Ko's avatar
Hyunjun Ko committed
163
164
165
166
  gst_buffer_unref (s->buf);

  g_slice_free (MsdkSurface, s);
  thiz->decoded_msdk_surfaces = g_list_remove (thiz->decoded_msdk_surfaces, s);
167
168
}

Scott D Phillips's avatar
Scott D Phillips committed
169
static MsdkSurface *
170
get_surface (GstMsdkDec * thiz, GstBuffer * buffer)
Scott D Phillips's avatar
Scott D Phillips committed
171
172
173
{
  MsdkSurface *i;

Hyunjun Ko's avatar
Hyunjun Ko committed
174
  i = g_slice_new0 (MsdkSurface);
Scott D Phillips's avatar
Scott D Phillips committed
175

Hyunjun Ko's avatar
Hyunjun Ko committed
176
177
178
  if (gst_msdk_is_msdk_buffer (buffer)) {
    i->surface = gst_msdk_get_surface_from_buffer (buffer);
    i->buf = buffer;
Scott D Phillips's avatar
Scott D Phillips committed
179
  } else {
Hyunjun Ko's avatar
Hyunjun Ko committed
180
181
182
183
184
185
186
    /* Confirm to activate the side pool */
    if (!gst_buffer_pool_is_active (thiz->pool) &&
        !gst_buffer_pool_set_active (thiz->pool, TRUE)) {
      g_slice_free (MsdkSurface, i);
      return NULL;
    }

187
    if (!gst_video_frame_map (&i->copy, &thiz->non_msdk_pool_info, buffer,
Scott D Phillips's avatar
Scott D Phillips committed
188
189
            GST_MAP_WRITE))
      goto failed_unref_buffer;
Hyunjun Ko's avatar
Hyunjun Ko committed
190

Scott D Phillips's avatar
Scott D Phillips committed
191
192
193
    if (gst_buffer_pool_acquire_buffer (thiz->pool, &buffer,
            NULL) != GST_FLOW_OK)
      goto failed_unmap_copy;
Hyunjun Ko's avatar
Hyunjun Ko committed
194

195
196
    i->surface = gst_msdk_get_surface_from_buffer (buffer);
    i->buf = buffer;
Hyunjun Ko's avatar
Hyunjun Ko committed
197

198
    if (!gst_video_frame_map (&i->data, &thiz->output_info, buffer,
Scott D Phillips's avatar
Scott D Phillips committed
199
200
201
202
            GST_MAP_READWRITE))
      goto failed_unref_buffer2;
  }

Hyunjun Ko's avatar
Hyunjun Ko committed
203
  thiz->decoded_msdk_surfaces = g_list_append (thiz->decoded_msdk_surfaces, i);
Scott D Phillips's avatar
Scott D Phillips committed
204
205
206
207
208
209
210
211
212
  return i;

failed_unref_buffer2:
  gst_buffer_unref (buffer);
  buffer = i->data.buffer;
failed_unmap_copy:
  gst_video_frame_unmap (&i->copy);
failed_unref_buffer:
  gst_buffer_unref (buffer);
Hyunjun Ko's avatar
Hyunjun Ko committed
213
  g_slice_free (MsdkSurface, i);
Scott D Phillips's avatar
Scott D Phillips committed
214

Hyunjun Ko's avatar
Hyunjun Ko committed
215
  GST_ERROR_OBJECT (thiz, "failed to handle buffer");
Scott D Phillips's avatar
Scott D Phillips committed
216
217
218
219
  return NULL;
}

static void
220
gst_msdkdec_close_decoder (GstMsdkDec * thiz, gboolean reset_param)
Scott D Phillips's avatar
Scott D Phillips committed
221
222
223
{
  mfxStatus status;

224
  if (!thiz->context || !thiz->initialized)
Scott D Phillips's avatar
Scott D Phillips committed
225
226
    return;

227
228
  GST_DEBUG_OBJECT (thiz, "Closing decoder with context %" GST_PTR_FORMAT,
      thiz->context);
Scott D Phillips's avatar
Scott D Phillips committed
229

Hyunjun Ko's avatar
Hyunjun Ko committed
230
231
232
  if (thiz->use_video_memory)
    gst_msdk_frame_free (thiz->context, &thiz->alloc_resp);

Hyunjun Ko's avatar
Hyunjun Ko committed
233
  status = MFXVideoDECODE_Close (gst_msdk_context_get_session (thiz->context));
Scott D Phillips's avatar
Scott D Phillips committed
234
235
236
237
238
239
240
  if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
    GST_WARNING_OBJECT (thiz, "Decoder close failed (%s)",
        msdk_status_to_string (status));
  }

  g_array_set_size (thiz->tasks, 0);

241
242
243
  if (reset_param)
    memset (&thiz->param, 0, sizeof (thiz->param));

244
  thiz->initialized = FALSE;
245
  gst_adapter_clear (thiz->adapter);
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
}

static void
gst_msdkdec_set_context (GstElement * element, GstContext * context)
{
  GstMsdkContext *msdk_context = NULL;
  GstMsdkDec *thiz = GST_MSDKDEC (element);

  if (gst_msdk_context_get_context (context, &msdk_context)) {
    gst_object_replace ((GstObject **) & thiz->context,
        (GstObject *) msdk_context);
    gst_object_unref (msdk_context);
  }

  GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
Scott D Phillips's avatar
Scott D Phillips committed
261
262
263
264
265
266
267
268
269
270
}

static gboolean
gst_msdkdec_init_decoder (GstMsdkDec * thiz)
{
  GstVideoInfo *info;
  mfxSession session;
  mfxStatus status;
  mfxFrameAllocRequest request;

271
272
273
274
275
  if (thiz->initialized)
    return TRUE;

  if (!thiz->context) {
    GST_WARNING_OBJECT (thiz, "No MSDK Context");
Scott D Phillips's avatar
Scott D Phillips committed
276
277
278
    return FALSE;
  }

279
280
  if (!thiz->input_state) {
    GST_DEBUG_OBJECT (thiz, "Have no input state yet");
Scott D Phillips's avatar
Scott D Phillips committed
281
282
    return FALSE;
  }
283
  info = &thiz->input_state->info;
Scott D Phillips's avatar
Scott D Phillips committed
284
285
286

  GST_OBJECT_LOCK (thiz);

Hyunjun Ko's avatar
Hyunjun Ko committed
287
288
289
290
291
292
  if (thiz->use_video_memory) {
    gst_msdk_set_frame_allocator (thiz->context);
    thiz->param.IOPattern = MFX_IOPATTERN_OUT_VIDEO_MEMORY;
  } else {
    thiz->param.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
  }
Scott D Phillips's avatar
Scott D Phillips committed
293

Hyunjun Ko's avatar
Hyunjun Ko committed
294
295
296
297
  GST_INFO_OBJECT (thiz, "This MSDK decoder uses %s memory",
      thiz->use_video_memory ? "video" : "system");

  thiz->param.AsyncDepth = thiz->async_depth;
298

299
300
301
302
303
304
305
306
  /* We expect msdk to fill the width and height values */
  g_return_val_if_fail (thiz->param.mfx.FrameInfo.Width
      && thiz->param.mfx.FrameInfo.Height, FALSE);

  /* Force 32 bit rounding to avoid messing up of memory alignment when
   * dealing with different allocators */
  /* Fixme: msdk sometimes only requires 16 bit rounding, optimization possible */
  thiz->param.mfx.FrameInfo.Width =
307
      GST_ROUND_UP_16 (thiz->param.mfx.FrameInfo.Width);
308
309
  thiz->param.mfx.FrameInfo.Height =
      GST_ROUND_UP_32 (thiz->param.mfx.FrameInfo.Height);
310
  /* Set framerate only if provided.
311
312
313
314
315
   * If not, framerate will be assumed inside the driver.
   * Also we respect the upstream provided fps values */
  if (info->fps_n > 0 && info->fps_d > 0
      && info->fps_n != thiz->param.mfx.FrameInfo.FrameRateExtN
      && info->fps_d != thiz->param.mfx.FrameInfo.FrameRateExtD) {
316
317
318
    thiz->param.mfx.FrameInfo.FrameRateExtN = info->fps_n;
    thiz->param.mfx.FrameInfo.FrameRateExtD = info->fps_d;
  }
Scott D Phillips's avatar
Scott D Phillips committed
319

320
321
322
323
  if (info->par_n && info->par_d && !thiz->param.mfx.FrameInfo.AspectRatioW
      && !thiz->param.mfx.FrameInfo.AspectRatioH) {
    thiz->param.mfx.FrameInfo.AspectRatioW = info->par_n;
    thiz->param.mfx.FrameInfo.AspectRatioH = info->par_d;
Scott D Phillips's avatar
Scott D Phillips committed
324
325
  }

326
327
328
329
330
331
332
333
334
335
  thiz->param.mfx.FrameInfo.PicStruct =
      thiz->param.mfx.FrameInfo.PicStruct ? thiz->param.mfx.
      FrameInfo.PicStruct : MFX_PICSTRUCT_PROGRESSIVE;
  thiz->param.mfx.FrameInfo.FourCC =
      thiz->param.mfx.FrameInfo.FourCC ? thiz->param.mfx.
      FrameInfo.FourCC : MFX_FOURCC_NV12;
  thiz->param.mfx.FrameInfo.ChromaFormat =
      thiz->param.mfx.FrameInfo.ChromaFormat ? thiz->param.mfx.
      FrameInfo.ChromaFormat : MFX_CHROMAFORMAT_YUV420;

Hyunjun Ko's avatar
Hyunjun Ko committed
336
  session = gst_msdk_context_get_session (thiz->context);
Scott D Phillips's avatar
Scott D Phillips committed
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
  /* validate parameters and allow the Media SDK to make adjustments */
  status = MFXVideoDECODE_Query (session, &thiz->param, &thiz->param);
  if (status < MFX_ERR_NONE) {
    GST_ERROR_OBJECT (thiz, "Video Decode Query failed (%s)",
        msdk_status_to_string (status));
    goto failed;
  } else if (status > MFX_ERR_NONE) {
    GST_WARNING_OBJECT (thiz, "Video Decode Query returned: %s",
        msdk_status_to_string (status));
  }

  status = MFXVideoDECODE_QueryIOSurf (session, &thiz->param, &request);
  if (status < MFX_ERR_NONE) {
    GST_ERROR_OBJECT (thiz, "Query IO surfaces failed (%s)",
        msdk_status_to_string (status));
    goto failed;
  } else if (status > MFX_ERR_NONE) {
    GST_WARNING_OBJECT (thiz, "Query IO surfaces returned: %s",
        msdk_status_to_string (status));
  }

  if (request.NumFrameSuggested < thiz->param.AsyncDepth) {
    GST_ERROR_OBJECT (thiz, "Required %d surfaces (%d suggested), async %d",
        request.NumFrameMin, request.NumFrameSuggested, thiz->param.AsyncDepth);
    goto failed;
  }

364
365
366
367
368
369
370
371
  /* account the downstream requirement */
  if (G_LIKELY (thiz->min_prealloc_buffers))
    request.NumFrameSuggested += thiz->min_prealloc_buffers;
  else
    GST_WARNING_OBJECT (thiz,
        "Allocating resources without considering the downstream requirement"
        "or extra scratch surface count");

Hyunjun Ko's avatar
Hyunjun Ko committed
372
  if (thiz->use_video_memory) {
373
374
375
376
377
378
    gint shared_async_depth;

    shared_async_depth =
        gst_msdk_context_get_shared_async_depth (thiz->context);
    request.NumFrameSuggested += shared_async_depth;

Hyunjun Ko's avatar
Hyunjun Ko committed
379
    request.Type |= MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
Hyunjun Ko's avatar
Hyunjun Ko committed
380
381
    if (thiz->use_dmabuf)
      request.Type |= MFX_MEMTYPE_EXPORT_FRAME;
Hyunjun Ko's avatar
Hyunjun Ko committed
382
    gst_msdk_frame_alloc (thiz->context, &request, &thiz->alloc_resp);
Scott D Phillips's avatar
Scott D Phillips committed
383
384
  }

385
386
387
388
  /* update the prealloc_buffer count which will be used later
   * as GstBufferPool min_buffers */
  thiz->min_prealloc_buffers = request.NumFrameSuggested;

Hyunjun Ko's avatar
Hyunjun Ko committed
389
390
  GST_DEBUG_OBJECT (thiz, "Required %d surfaces (%d suggested)",
      request.NumFrameMin, request.NumFrameSuggested);
Scott D Phillips's avatar
Scott D Phillips committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416

  status = MFXVideoDECODE_Init (session, &thiz->param);
  if (status < MFX_ERR_NONE) {
    GST_ERROR_OBJECT (thiz, "Init failed (%s)", msdk_status_to_string (status));
    goto failed;
  } else if (status > MFX_ERR_NONE) {
    GST_WARNING_OBJECT (thiz, "Init returned: %s",
        msdk_status_to_string (status));
  }

  status = MFXVideoDECODE_GetVideoParam (session, &thiz->param);
  if (status < MFX_ERR_NONE) {
    GST_ERROR_OBJECT (thiz, "Get Video Parameters failed (%s)",
        msdk_status_to_string (status));
    goto failed;
  } else if (status > MFX_ERR_NONE) {
    GST_WARNING_OBJECT (thiz, "Get Video Parameters returned: %s",
        msdk_status_to_string (status));
  }

  g_array_set_size (thiz->tasks, 0);
  g_array_set_size (thiz->tasks, thiz->param.AsyncDepth);
  thiz->next_task = 0;

  GST_OBJECT_UNLOCK (thiz);

417
  thiz->initialized = TRUE;
Scott D Phillips's avatar
Scott D Phillips committed
418
419
420
421
422
423
424
  return TRUE;

failed:
  GST_OBJECT_UNLOCK (thiz);
  return FALSE;
}

Hyunjun Ko's avatar
Hyunjun Ko committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

static gboolean
_gst_caps_has_feature (const GstCaps * caps, const gchar * feature)
{
  guint i;

  for (i = 0; i < gst_caps_get_size (caps); i++) {
    GstCapsFeatures *const features = gst_caps_get_features (caps, i);
    /* Skip ANY features, we need an exact match for correct evaluation */
    if (gst_caps_features_is_any (features))
      continue;
    if (gst_caps_features_contains (features, feature))
      return TRUE;
  }

  return FALSE;
}

static gboolean
444
srcpad_can_dmabuf (GstMsdkDec * thiz)
Hyunjun Ko's avatar
Hyunjun Ko committed
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
{
  gboolean ret = FALSE;
  GstCaps *caps, *out_caps;
  GstPad *srcpad;

  srcpad = GST_VIDEO_DECODER_SRC_PAD (thiz);
  caps = gst_pad_get_pad_template_caps (srcpad);

  out_caps = gst_pad_peer_query_caps (srcpad, caps);
  if (!out_caps)
    goto done;

  if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)
      || out_caps == caps)
    goto done;

461
  if (_gst_caps_has_feature (out_caps, GST_CAPS_FEATURE_MEMORY_DMABUF))
Hyunjun Ko's avatar
Hyunjun Ko committed
462
463
464
465
466
467
468
469
470
471
    ret = TRUE;

done:
  if (caps)
    gst_caps_unref (caps);
  if (out_caps)
    gst_caps_unref (out_caps);
  return ret;
}

Scott D Phillips's avatar
Scott D Phillips committed
472
static gboolean
473
gst_msdkdec_set_src_caps (GstMsdkDec * thiz, gboolean need_allocation)
Scott D Phillips's avatar
Scott D Phillips committed
474
475
{
  GstVideoCodecState *output_state;
476
  GstVideoInfo *vinfo;
Scott D Phillips's avatar
Scott D Phillips committed
477
  GstVideoAlignment align;
478
  GstCaps *allocation_caps = NULL;
Scott D Phillips's avatar
Scott D Phillips committed
479
  guint width, height;
480
481
482
483
484
485
486
487
488
489
  const gchar *format_str;

  /* use display width and display height in output state which
   * will be using for caps negotiation */
  width =
      thiz->param.mfx.FrameInfo.CropW ? thiz->param.mfx.
      FrameInfo.CropW : GST_VIDEO_INFO_WIDTH (&thiz->input_state->info);
  height =
      thiz->param.mfx.FrameInfo.CropH ? thiz->param.mfx.
      FrameInfo.CropH : GST_VIDEO_INFO_HEIGHT (&thiz->input_state->info);
Scott D Phillips's avatar
Scott D Phillips committed
490
491
492
  output_state =
      gst_video_decoder_set_output_state (GST_VIDEO_DECODER (thiz),
      GST_VIDEO_FORMAT_NV12, width, height, thiz->input_state);
493
494
  if (!output_state)
    return FALSE;
Scott D Phillips's avatar
Scott D Phillips committed
495

496
497
498
499
500
501
  /* Ensure output_state->caps and info has same width and height
   * Also mandate the 32 bit alignment */
  vinfo = &output_state->info;
  gst_msdk_set_video_alignment (vinfo, &align);
  gst_video_info_align (vinfo, &align);
  output_state->caps = gst_video_info_to_caps (vinfo);
502
  if (srcpad_can_dmabuf (thiz))
Hyunjun Ko's avatar
Hyunjun Ko committed
503
504
    gst_caps_set_features (output_state->caps, 0,
        gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_DMABUF, NULL));
505
  thiz->output_info = output_state->info;
Hyunjun Ko's avatar
Hyunjun Ko committed
506

507
508
509
  if (need_allocation) {
    /* Find allocation width and height */
    width =
510
        GST_ROUND_UP_16 (thiz->param.mfx.FrameInfo.Width ? thiz->param.mfx.
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
        FrameInfo.Width : GST_VIDEO_INFO_WIDTH (&output_state->info));
    height =
        GST_ROUND_UP_32 (thiz->param.mfx.FrameInfo.Height ? thiz->param.mfx.
        FrameInfo.Height : GST_VIDEO_INFO_HEIGHT (&output_state->info));

    /* set allocation width and height in allocation_caps
     * which may or may not be similar to the output_state caps */
    allocation_caps = gst_caps_copy (output_state->caps);
    format_str =
        gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&thiz->output_info));
    gst_caps_set_simple (allocation_caps, "width", G_TYPE_INT, width, "height",
        G_TYPE_INT, height, "format", G_TYPE_STRING, format_str, NULL);
    GST_INFO_OBJECT (thiz, "new alloc caps = %" GST_PTR_FORMAT,
        allocation_caps);
    gst_caps_replace (&thiz->allocation_caps, allocation_caps);
  } else {
    /* We keep the allocation parameters as it is to avoid pool renegotiation.
     * For codecs like VP9, dynamic resolution change doesn't requires allocation
     * reset if the new video frame resolution is lower than the
     * already configured one */
    allocation_caps = gst_caps_copy (thiz->allocation_caps);
  }
Scott D Phillips's avatar
Scott D Phillips committed
533

534
535
536
537
538
  gst_caps_replace (&output_state->allocation_caps, allocation_caps);
  if (allocation_caps)
    gst_caps_unref (allocation_caps);

  gst_video_codec_state_unref (output_state);
Scott D Phillips's avatar
Scott D Phillips committed
539
540
541
542
543
544
545
546
547
548
  return TRUE;
}

static void
gst_msdkdec_set_latency (GstMsdkDec * thiz)
{
  GstVideoInfo *info = &thiz->input_state->info;
  gint min_delayed_frames;
  GstClockTime latency;

549
  min_delayed_frames = thiz->async_depth;
Scott D Phillips's avatar
Scott D Phillips committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568

  if (info->fps_n) {
    latency = gst_util_uint64_scale_ceil (GST_SECOND * info->fps_d,
        min_delayed_frames, info->fps_n);
  } else {
    /* FIXME: Assume 25fps. This is better than reporting no latency at
     * all and then later failing in live pipelines
     */
    latency = gst_util_uint64_scale_ceil (GST_SECOND * 1,
        min_delayed_frames, 25);
  }

  GST_INFO_OBJECT (thiz,
      "Updating latency to %" GST_TIME_FORMAT " (%d frames)",
      GST_TIME_ARGS (latency), min_delayed_frames);

  gst_video_decoder_set_latency (GST_VIDEO_DECODER (thiz), latency, latency);
}

Hyunjun Ko's avatar
Hyunjun Ko committed
569
570
571
572
573
574
575
576
577
static gint
_find_msdk_surface (gconstpointer msdk_surface, gconstpointer comp_surface)
{
  MsdkSurface *cached_surface = (MsdkSurface *) msdk_surface;
  mfxFrameSurface1 *_surface = (mfxFrameSurface1 *) comp_surface;

  return cached_surface ? cached_surface->surface != _surface : -1;
}

578
static GstFlowReturn
Scott D Phillips's avatar
Scott D Phillips committed
579
580
581
gst_msdkdec_finish_task (GstMsdkDec * thiz, MsdkDecTask * task)
{
  GstVideoDecoder *decoder = GST_VIDEO_DECODER (thiz);
582
  GstFlowReturn flow;
Scott D Phillips's avatar
Scott D Phillips committed
583
584
585
  GstVideoCodecFrame *frame;
  MsdkSurface *surface;
  mfxStatus status;
Hyunjun Ko's avatar
Hyunjun Ko committed
586
  GList *l;
Scott D Phillips's avatar
Scott D Phillips committed
587
588
589

  if (G_LIKELY (task->sync_point)) {
    status =
Hyunjun Ko's avatar
Hyunjun Ko committed
590
        MFXVideoCORE_SyncOperation (gst_msdk_context_get_session
Hyunjun Ko's avatar
Hyunjun Ko committed
591
592
593
        (thiz->context), task->sync_point, 300000);
    if (status != MFX_ERR_NONE) {
      GST_ERROR_OBJECT (thiz, "failed to do sync operation");
594
      return GST_FLOW_ERROR;
Hyunjun Ko's avatar
Hyunjun Ko committed
595
    }
Scott D Phillips's avatar
Scott D Phillips committed
596

597
    frame = gst_msdkdec_get_oldest_frame (decoder);
Scott D Phillips's avatar
Scott D Phillips committed
598
    task->sync_point = NULL;
Hyunjun Ko's avatar
Hyunjun Ko committed
599
600
601
602
603
604
605
606
607

    l = g_list_find_custom (thiz->decoded_msdk_surfaces, task->surface,
        _find_msdk_surface);
    if (l) {
      surface = l->data;
    } else {
      GST_ERROR_OBJECT (thiz, "Couldn't find the cached MSDK surface");
      return GST_FLOW_ERROR;
    }
608
609
610

    if (G_LIKELY (frame)) {
      if (G_LIKELY (surface->copy.buffer == NULL)) {
Hyunjun Ko's avatar
Hyunjun Ko committed
611
        frame->output_buffer = gst_buffer_ref (surface->buf);
612
613
614
615
      } else {
        gst_video_frame_copy (&surface->copy, &surface->data);
        frame->output_buffer = gst_buffer_ref (surface->copy.buffer);
      }
Scott D Phillips's avatar
Scott D Phillips committed
616
    }
617

Hyunjun Ko's avatar
Hyunjun Ko committed
618
    free_surface (thiz, surface);
Scott D Phillips's avatar
Scott D Phillips committed
619

620
621
    if (!frame)
      return GST_FLOW_FLUSHING;
Scott D Phillips's avatar
Scott D Phillips committed
622
    gst_video_codec_frame_unref (frame);
Hyunjun Ko's avatar
Hyunjun Ko committed
623
624

    flow = gst_video_decoder_finish_frame (decoder, frame);
625
    return flow;
Scott D Phillips's avatar
Scott D Phillips committed
626
  }
627
  return GST_FLOW_OK;
Scott D Phillips's avatar
Scott D Phillips committed
628
629
}

630
631
632
633
634
635
636
637
static gboolean
gst_msdkdec_start (GstVideoDecoder * decoder)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);

  if (gst_msdk_context_prepare (GST_ELEMENT_CAST (thiz), &thiz->context)) {
    GST_INFO_OBJECT (thiz, "Found context %" GST_PTR_FORMAT " from neighbour",
        thiz->context);
638
    thiz->use_video_memory = TRUE;
639
640
641
642
643
644

    if (gst_msdk_context_get_job_type (thiz->context) & GST_MSDK_JOB_DECODER) {
      GstMsdkContext *parent_context;

      parent_context = thiz->context;
      thiz->context = gst_msdk_context_new_with_parent (parent_context);
645
646
647

      gst_msdk_context_add_shared_async_depth (thiz->context,
          gst_msdk_context_get_shared_async_depth (parent_context));
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
      gst_object_unref (parent_context);

      GST_INFO_OBJECT (thiz,
          "Creating new context %" GST_PTR_FORMAT " with joined session",
          thiz->context);
    } else {
      gst_msdk_context_add_job_type (thiz->context, GST_MSDK_JOB_DECODER);
    }
  } else {
    gst_msdk_context_ensure_context (GST_ELEMENT_CAST (thiz), thiz->hardware,
        GST_MSDK_JOB_DECODER);
    GST_INFO_OBJECT (thiz, "Creating new context %" GST_PTR_FORMAT,
        thiz->context);
  }

663
664
  gst_msdk_context_add_shared_async_depth (thiz->context, thiz->async_depth);

665
666
667
  return TRUE;
}

Scott D Phillips's avatar
Scott D Phillips committed
668
669
670
671
static gboolean
gst_msdkdec_close (GstVideoDecoder * decoder)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);
Hyunjun Ko's avatar
Hyunjun Ko committed
672
673
674
675

  if (thiz->context)
    gst_object_replace ((GstObject **) & thiz->context, NULL);

Scott D Phillips's avatar
Scott D Phillips committed
676
677
678
679
680
681
682
  return TRUE;
}

static gboolean
gst_msdkdec_stop (GstVideoDecoder * decoder)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);
683
684
685

  gst_msdkdec_flush (decoder);

Scott D Phillips's avatar
Scott D Phillips committed
686
687
688
689
690
691
  if (thiz->input_state) {
    gst_video_codec_state_unref (thiz->input_state);
    thiz->input_state = NULL;
  }
  if (thiz->pool) {
    gst_object_unref (thiz->pool);
Hyunjun Ko's avatar
Hyunjun Ko committed
692
    thiz->pool = NULL;
Scott D Phillips's avatar
Scott D Phillips committed
693
694
  }
  gst_video_info_init (&thiz->output_info);
695
  gst_video_info_init (&thiz->non_msdk_pool_info);
696

697
  gst_msdkdec_close_decoder (thiz, TRUE);
Scott D Phillips's avatar
Scott D Phillips committed
698
699
700
701
702
703
704
705
  return TRUE;
}

static gboolean
gst_msdkdec_set_format (GstVideoDecoder * decoder, GstVideoCodecState * state)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);

706
707
708
709
710
711
712
  if (thiz->input_state) {
    /* mark for re-negotiation if display resolution changes */
    if ((GST_VIDEO_INFO_WIDTH (&thiz->input_state->info) !=
            GST_VIDEO_INFO_WIDTH (&state->info)) ||
        GST_VIDEO_INFO_HEIGHT (&thiz->input_state->info) !=
        GST_VIDEO_INFO_HEIGHT (&state->info))
      thiz->do_renego = TRUE;
Scott D Phillips's avatar
Scott D Phillips committed
713
    gst_video_codec_state_unref (thiz->input_state);
714
  }
Scott D Phillips's avatar
Scott D Phillips committed
715
716
  thiz->input_state = gst_video_codec_state_ref (state);

717
718
719
720
  /* we don't set output state here to avoid caching of mismatched
   * video information if there is dynamic resolution change in the stream.
   * All negotiation code is consolidated in gst_msdkdec_negotiate() and
   * this will be invoked from handle_frame() */
Scott D Phillips's avatar
Scott D Phillips committed
721
722
723
724
725

  gst_msdkdec_set_latency (thiz);
  return TRUE;
}

Hyunjun Ko's avatar
Hyunjun Ko committed
726
727
728
729
730
731
732
733
734
735
736
737
static void
release_msdk_surfaces (GstMsdkDec * thiz)
{
  GList *l;
  MsdkSurface *surface;

  for (l = thiz->decoded_msdk_surfaces; l; l = l->next) {
    surface = l->data;
    free_surface (thiz, surface);
  }
}

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
/* This will get invoked in the following situations:
 * 1: begining of the stream, which requires initialization (== complete reset)
 * 2: upstream notified a resolution change and set do_renego to TRUE.
 *    new resoulution may or may not requires full reset
 * 3: upstream failed to notify the resoulution change but
 *    msdk detected the change (eg: vp9 stream in ivf elementary form
 *     with varying resolution frames).
 *
 * for any input configuration change, we deal with notification
 * from upstream and also use msdk apis to handle the parameter initialization
 * efficiently
 */
static gboolean
gst_msdkdec_negotiate (GstMsdkDec * thiz, gboolean hard_reset)
{
  GstVideoDecoder *decoder = GST_VIDEO_DECODER (thiz);
  GST_DEBUG_OBJECT (thiz,
      "Start Negotiating caps, pool and Init the msdk decdoer subsystem");

  if (hard_reset) {
    /* Retrieve any pending frames and push them downstream */
    if (gst_msdkdec_drain (GST_VIDEO_DECODER (thiz)) != GST_FLOW_OK)
      goto error_drain;

    /* This will initiate the allocation query which will help to flush
     * all the pending buffers in the pipeline so that we can stop
     * the active bufferpool and safely invoke gst_msdk_frame_free() */
    if (thiz->initialized) {
      GstCaps *caps = gst_pad_get_current_caps (decoder->srcpad);
      GstQuery *query = NULL;
      if (caps) {
        query = gst_query_new_allocation (caps, FALSE);
        gst_pad_peer_query (decoder->srcpad, query);
        gst_query_unref (query);
        gst_caps_unref (caps);
      }
    }

    /* De-initialize the decoder if it is already active */
    /* Not resetting the mfxVideoParam since it already
     * possessing the required parameters for new session decode */
    gst_msdkdec_close_decoder (thiz, FALSE);

    /* request for pool renegotiation by setting do_realloc */
    thiz->do_realloc = TRUE;
  }

  /* At this point all pending frames(if there is any) are pushed downsteram
   * and we are ready to negotiate the output caps */
  if (!gst_msdkdec_set_src_caps (thiz, hard_reset))
    return FALSE;

  /* this will initiate the allocation query, we create the
   * bufferpool in decide_allocation inorder to account
   * the downstream min_buffer requirement
   * Required initializations for MediaSDK operations
   * will all be inited from decide_allocation after considering
   * some of the downstream requirements */
  if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (thiz)))
    goto error_negotiate;

  thiz->do_renego = FALSE;
  thiz->do_realloc = FALSE;

  return TRUE;

error_drain:
  GST_ERROR_OBJECT (thiz, "Failed to Drain the queued decoded frames");
  return FALSE;

error_negotiate:
  GST_ERROR_OBJECT (thiz, "Failed to renegotiation");
  return FALSE;
}

Scott D Phillips's avatar
Scott D Phillips committed
813
814
815
816
static GstFlowReturn
gst_msdkdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);
817
  GstMsdkDecClass *klass = GST_MSDKDEC_GET_CLASS (thiz);
818
819
  GstFlowReturn flow;
  GstBuffer *buffer;
820
  GstVideoInfo alloc_info;
Scott D Phillips's avatar
Scott D Phillips committed
821
822
  MsdkDecTask *task = NULL;
  mfxBitstream bitstream;
Hyunjun Ko's avatar
Hyunjun Ko committed
823
  MsdkSurface *surface = NULL;
Scott D Phillips's avatar
Scott D Phillips committed
824
825
826
827
  mfxSession session;
  mfxStatus status;
  GstMapInfo map_info;
  guint i;
828
  gsize data_size;
829
  gboolean hard_reset = FALSE;
830

831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
  /* configure the subclss inorder to fill the CodecID field of mfxVideoParam
   * and also to load the PluginID for some of the codecs which is mandatory
   * to invoke the MFXVideoDECODE_DecodeHeader API.
   *
   * For non packetized formats (currently only vc1), there
   * could be headers received as codec_data which are not available
   * instream and in that case subclass implementation will
   * push it to the internal adapter. We invoke the subclass configure
   * well early to make sure the codec_data received has been correctly
   * pushed to the adapter by the subclasses before doing
   * the DecodeHeader() later on
   */
  if (!thiz->initialized || thiz->do_renego) {
    /* Clear the internal adapter in renegotiation for non-packetized
     * formats */
    if (!thiz->is_packetized)
      gst_adapter_clear (thiz->adapter);

    if (!klass->configure || !klass->configure (thiz)) {
      flow = GST_FLOW_OK;
      goto error;
    }
  }

Scott D Phillips's avatar
Scott D Phillips committed
855
856
  if (!gst_buffer_map (frame->input_buffer, &map_info, GST_MAP_READ))
    return GST_FLOW_ERROR;
Hyunjun Ko's avatar
Hyunjun Ko committed
857

Scott D Phillips's avatar
Scott D Phillips committed
858
  memset (&bitstream, 0, sizeof (bitstream));
859
860
861
862
863
864
865

  if (thiz->is_packetized) {
    /* Packetized stream: We prefer to have a parser as connected upstream
     * element to the decoder */
    bitstream.Data = map_info.data;
    bitstream.DataLength = map_info.size;
    bitstream.MaxLength = map_info.size;
866
    bitstream.DataFlag = MFX_BITSTREAM_COMPLETE_FRAME;
867
868
869
870
871
872
873
874
875
876
877
878
  } else {
    /* Non packetized streams: eg: vc1 advanced profile with per buffer bdu */
    gst_adapter_push (thiz->adapter, gst_buffer_ref (frame->input_buffer));
    data_size = gst_adapter_available (thiz->adapter);

    bitstream.Data = (mfxU8 *) gst_adapter_map (thiz->adapter, data_size);
    bitstream.DataLength = (mfxU32) data_size;
    bitstream.MaxLength = bitstream.DataLength;
  }
  GST_INFO_OBJECT (thiz,
      "mfxBitStream=> DataLength:%d DataOffset:%d MaxLength:%d",
      bitstream.DataLength, bitstream.DataOffset, bitstream.MaxLength);
Scott D Phillips's avatar
Scott D Phillips committed
879

Hyunjun Ko's avatar
Hyunjun Ko committed
880
  session = gst_msdk_context_get_session (thiz->context);
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895

  if (!thiz->initialized || thiz->do_renego) {

    /* gstreamer caps will not bring all the necessary parameters
     * required for optimal decode configuration. For eg: the required numbers
     * of surfaces to be allocated can be calculated based on H264 SEI header
     * and this information can't be retrieved from the negotiated caps.
     * So instead of introducing the codecparser dependency to parse the headers
     * inside msdk plugin, we simply use the mfx apis to extract header information */
    status = MFXVideoDECODE_DecodeHeader (session, &bitstream, &thiz->param);
    if (status == MFX_ERR_MORE_DATA) {
      flow = GST_FLOW_OK;
      goto done;
    }

896
897
898
    if (!thiz->initialized)
      hard_reset = TRUE;
    else if (thiz->allocation_caps) {
899
900
      gst_video_info_from_caps (&alloc_info, thiz->allocation_caps);

901
902
903
904
905
906
      /* Check whether we need complete reset for dynamic resolution change */
      if (thiz->param.mfx.FrameInfo.Width > GST_VIDEO_INFO_WIDTH (&alloc_info)
          || thiz->param.mfx.FrameInfo.Height >
          GST_VIDEO_INFO_HEIGHT (&alloc_info))
        hard_reset = TRUE;
    }
907
908
909
910
911

    /* if subclass requested for the force reset */
    if (thiz->force_reset_on_res_change)
      hard_reset = TRUE;

912
913
914
915
916
917
    /* Config changed dynamically and we are going to do a full reset,
     * this will unref the input frame which has the new configuration.
     * Keep a ref to the input_frame to keep it alive */
    if (thiz->initialized && thiz->do_renego)
      gst_video_codec_frame_ref (frame);

918
919
920
    gst_msdkdec_negotiate (thiz, hard_reset);
  }

Scott D Phillips's avatar
Scott D Phillips committed
921
922
  for (;;) {
    task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
923
924
    flow = gst_msdkdec_finish_task (thiz, task);
    if (flow != GST_FLOW_OK)
925
      goto error;
Scott D Phillips's avatar
Scott D Phillips committed
926
    if (!surface) {
927
928
      flow = allocate_output_buffer (thiz, &buffer);
      if (flow != GST_FLOW_OK)
929
        goto error;
930
      surface = get_surface (thiz, buffer);
Scott D Phillips's avatar
Scott D Phillips committed
931
932
933
934
935
936
      if (!surface) {
        /* Can't get a surface for some reason, finish tasks to see if
           a surface becomes available. */
        for (i = 0; i < thiz->tasks->len - 1; i++) {
          thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
          task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
937
938
          flow = gst_msdkdec_finish_task (thiz, task);
          if (flow != GST_FLOW_OK)
939
            goto error;
940
          surface = get_surface (thiz, buffer);
Scott D Phillips's avatar
Scott D Phillips committed
941
942
943
944
945
          if (surface)
            break;
        }
        if (!surface) {
          GST_ERROR_OBJECT (thiz, "Couldn't get a surface");
946
          flow = GST_FLOW_ERROR;
947
          goto error;
Scott D Phillips's avatar
Scott D Phillips committed
948
949
950
951
952
        }
      }
    }

    status =
Hyunjun Ko's avatar
Hyunjun Ko committed
953
        MFXVideoDECODE_DecodeFrameAsync (session, &bitstream, surface->surface,
Scott D Phillips's avatar
Scott D Phillips committed
954
        &task->surface, &task->sync_point);
955
956
957
958
959
960
961
962
963
964
965
966
967
968

    /* media-sdk requires complete reset since the surface is inadaquate to
     * do further decoding */
    if (status == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
      /* Requires memory re-allocation ,initiate hard reset */
      if (!gst_msdkdec_negotiate (thiz, TRUE))
        goto error;
      status =
          MFXVideoDECODE_DecodeFrameAsync (session, &bitstream,
          surface->surface, &task->surface, &task->sync_point);
    }

    if (G_LIKELY (status == MFX_ERR_NONE)
        || (status == MFX_WRN_VIDEO_PARAM_CHANGED)) {
Scott D Phillips's avatar
Scott D Phillips committed
969
      thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
Hyunjun Ko's avatar
Hyunjun Ko committed
970
971
972
973

      if (surface->surface->Data.Locked > 0 || !thiz->use_video_memory)
        surface = NULL;

Scott D Phillips's avatar
Scott D Phillips committed
974
      if (bitstream.DataLength == 0) {
975
        flow = GST_FLOW_OK;
Scott D Phillips's avatar
Scott D Phillips committed
976
977
978
        break;
      }
    } else if (status == MFX_ERR_MORE_DATA) {
Hyunjun Ko's avatar
Hyunjun Ko committed
979
980
      if (surface->surface->Data.Locked > 0)
        surface = NULL;
981
      flow = GST_FLOW_OK;
Scott D Phillips's avatar
Scott D Phillips committed
982
983
984
985
      break;
    } else if (status == MFX_ERR_MORE_SURFACE) {
      surface = NULL;
      continue;
Hyunjun Ko's avatar
Hyunjun Ko committed
986
    } else if (status == MFX_WRN_DEVICE_BUSY) {
Scott D Phillips's avatar
Scott D Phillips committed
987
988
      /* If device is busy, wait 1ms and retry, as per MSDK's recomendation */
      g_usleep (1000);
Hyunjun Ko's avatar
Hyunjun Ko committed
989
990
991
992
993
994

      /* If the current surface is still busy, we should do sync oepration
       * then tries to decode again
       */
      thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
    } else if (status < MFX_ERR_NONE) {
Scott D Phillips's avatar
Scott D Phillips committed
995
996
      GST_ERROR_OBJECT (thiz, "DecodeFrameAsync failed (%s)",
          msdk_status_to_string (status));
997
      flow = GST_FLOW_ERROR;
Scott D Phillips's avatar
Scott D Phillips committed
998
999
1000
1001
      break;
    }
  }

1002
1003
1004
1005
1006
1007
  if (!thiz->is_packetized) {
    /* flush out the data which is already consumed by msdk */
    gst_adapter_flush (thiz->adapter, bitstream.DataOffset);
    flow = GST_FLOW_OK;
  }

1008
done:
Scott D Phillips's avatar
Scott D Phillips committed
1009
  if (surface)
Hyunjun Ko's avatar
Hyunjun Ko committed
1010
    free_surface (thiz, surface);
Scott D Phillips's avatar
Scott D Phillips committed
1011
1012

  gst_buffer_unmap (frame->input_buffer, &map_info);
1013
  return flow;
1014
1015
1016
1017
1018
1019

error:
  gst_buffer_unmap (frame->input_buffer, &map_info);
  gst_video_decoder_drop_frame (decoder, frame);

  return flow;
Scott D Phillips's avatar
Scott D Phillips committed
1020
1021
}

1022

Hyunjun Ko's avatar
Hyunjun Ko committed
1023
static GstBufferPool *
1024
gst_msdkdec_create_buffer_pool (GstMsdkDec * thiz, GstVideoInfo * info,
Hyunjun Ko's avatar
Hyunjun Ko committed
1025
1026
1027
1028
1029
1030
    guint num_buffers)
{
  GstBufferPool *pool = NULL;
  GstStructure *config;
  GstAllocator *allocator = NULL;
  GstVideoAlignment align;
1031
  GstCaps *caps = NULL;
Hyunjun Ko's avatar
Hyunjun Ko committed
1032
1033
1034
  GstAllocationParams params = { 0, 31, 0, 0, };
  mfxFrameAllocResponse *alloc_resp = NULL;

1035
1036
1037
1038
  g_return_val_if_fail (info, NULL);
  g_return_val_if_fail (GST_VIDEO_INFO_WIDTH (info)
      && GST_VIDEO_INFO_HEIGHT (info), NULL);

Hyunjun Ko's avatar
Hyunjun Ko committed
1039
1040
1041
1042
1043
1044
  alloc_resp = &thiz->alloc_resp;

  pool = gst_msdk_buffer_pool_new (thiz->context, alloc_resp);
  if (!pool)
    goto error_no_pool;

1045
  if (G_UNLIKELY (!IS_ALIGNED (GST_VIDEO_INFO_WIDTH (info), 16)
1046
1047
1048
          || !IS_ALIGNED (GST_VIDEO_INFO_HEIGHT (info), 32))) {
    gst_msdk_set_video_alignment (info, &align);
    gst_video_info_align (info, &align);
Hyunjun Ko's avatar
Hyunjun Ko committed
1049
1050
  }

1051
  caps = gst_video_info_to_caps (info);
Hyunjun Ko's avatar
Hyunjun Ko committed
1052

1053
1054
  /* allocators should use the same width/height/stride/height_alignment of
   * negotiated output caps which is what we configure in msdk_allocator */
Hyunjun Ko's avatar
Hyunjun Ko committed
1055
  if (thiz->use_dmabuf)
1056
    allocator = gst_msdk_dmabuf_allocator_new (thiz->context, info, alloc_resp);
Hyunjun Ko's avatar
Hyunjun Ko committed
1057
  else if (thiz->use_video_memory)
1058
    allocator = gst_msdk_video_allocator_new (thiz->context, info, alloc_resp);
Hyunjun Ko's avatar
Hyunjun Ko committed
1059
  else
1060
    allocator = gst_msdk_system_allocator_new (info);
Hyunjun Ko's avatar
Hyunjun Ko committed
1061
1062
1063
1064
1065

  if (!allocator)
    goto error_no_allocator;

  config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
1066
1067
  gst_buffer_pool_config_set_params (config, caps,
      GST_VIDEO_INFO_SIZE (info), num_buffers, 0);
Hyunjun Ko's avatar
Hyunjun Ko committed
1068
1069
1070
1071
  gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
  gst_buffer_pool_config_add_option (config,
      GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);

Hyunjun Ko's avatar
Hyunjun Ko committed
1072
  if (thiz->use_video_memory) {
Hyunjun Ko's avatar
Hyunjun Ko committed
1073
1074
    gst_buffer_pool_config_add_option (config,
        GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY);
Hyunjun Ko's avatar
Hyunjun Ko committed
1075
1076
1077
1078
    if (thiz->use_dmabuf)
      gst_buffer_pool_config_add_option (config,
          GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF);
  }
Hyunjun Ko's avatar
Hyunjun Ko committed
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105

  gst_buffer_pool_config_set_video_alignment (config, &align);
  gst_buffer_pool_config_set_allocator (config, allocator, &params);
  gst_object_unref (allocator);

  if (!gst_buffer_pool_set_config (pool, config))
    goto error_pool_config;

  return pool;

error_no_pool:
  {
    GST_INFO_OBJECT (thiz, "failed to create bufferpool");
    return NULL;
  }
error_no_allocator:
  {
    GST_INFO_OBJECT (thiz, "failed to create allocator");
    return NULL;
  }
error_pool_config:
  {
    GST_INFO_OBJECT (thiz, "failed to set config");
    return NULL;
  }
}

Scott D Phillips's avatar
Scott D Phillips committed
1106
1107
1108
1109
1110
1111
static gboolean
gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);
  GstBufferPool *pool = NULL;
  GstStructure *pool_config = NULL;
1112
  GstCaps *pool_caps /*, *negotiated_caps */ ;
Scott D Phillips's avatar
Scott D Phillips committed
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
  guint size, min_buffers, max_buffers;

  if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
          query))
    return FALSE;

  /* Get the buffer pool config decided by the base class. The base
     class ensures that there will always be at least a 0th pool in
     the query. */
  gst_query_parse_nth_allocation_pool (query, 0, &pool, NULL, NULL, NULL);
  pool_config = gst_buffer_pool_get_config (pool);

Hyunjun Ko's avatar
Hyunjun Ko committed
1125
1126
  /* Get the caps of pool and increase the min and max buffers by async_depth,
   * we will always have that number of decode operations in-flight */
Scott D Phillips's avatar
Scott D Phillips committed
1127
1128
1129
1130
1131
1132
  gst_buffer_pool_config_get_params (pool_config, &pool_caps, &size,
      &min_buffers, &max_buffers);
  min_buffers += thiz->async_depth;
  if (max_buffers)
    max_buffers += thiz->async_depth;

1133
1134
1135
1136
1137
1138
  /* increase the min_buffers by 1 for smooth display in render pipeline */
  min_buffers += 1;

  /* this will get updated with msdk requirement */
  thiz->min_prealloc_buffers = min_buffers;

Hyunjun Ko's avatar
Hyunjun Ko committed
1139
1140
1141
1142
1143
  if (_gst_caps_has_feature (pool_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) {
    GST_INFO_OBJECT (decoder, "This MSDK decoder uses DMABuf memory");
    thiz->use_video_memory = thiz->use_dmabuf = TRUE;
  }

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
  /* Initialize MSDK decoder before new bufferpool tries to alloc each buffer,
   * which requires information of frame allocation.
   * No effect if already initialized.
   */
  if (!gst_msdkdec_init_decoder (thiz))
    return FALSE;

  /* get the updated min_buffers which account the msdk requirement too */
  min_buffers = thiz->min_prealloc_buffers;

  /* Decoder always use its own pool. So we create a pool if msdk apis
   * previously requested for allocation (do_realloc = TRUE) */
  if (thiz->do_realloc || !thiz->pool) {
    if (thiz->pool)
      gst_object_replace ((GstObject **) & thiz->pool, NULL);
    GST_INFO_OBJECT (decoder, "create new MSDK bufferpool");
    thiz->pool =
        gst_msdkdec_create_buffer_pool (thiz, &thiz->output_info, min_buffers);
    if (!thiz->pool)
      goto failed_to_create_pool;
  }

Hyunjun Ko's avatar
Hyunjun Ko committed
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
  if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)
      && gst_buffer_pool_has_option (pool,
          GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT)) {
    GstStructure *config;
    GstAllocator *allocator;

    /* If downstream supports video meta and video alignment,
     * we can replace our own msdk bufferpool and use it
     */
    /* Remove downstream's pool */
    gst_structure_free (pool_config);
    gst_object_unref (pool);

    pool = gst_object_ref (thiz->pool);

    /* Set the allocator of new msdk bufferpool */
    config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));

    if (gst_buffer_pool_config_get_allocator (config, &allocator, NULL))
      gst_query_set_nth_allocation_param (query, 0, allocator, NULL);
    gst_structure_free (config);
  } else {
1188
1189
1190
    /* Unfortunately, dowstream doesn't have videometa or alignment support,
     * we keep msdk pool as a side-pool that will be decoded into and
     * then copied from.
Hyunjun Ko's avatar
Hyunjun Ko committed
1191
     */
1192
    GST_INFO_OBJECT (decoder, "Keep MSDK bufferpool as a side-pool");
Hyunjun Ko's avatar
Hyunjun Ko committed
1193
1194

    /* Update params to downstream's pool */
Scott D Phillips's avatar
Scott D Phillips committed
1195
1196
    gst_buffer_pool_config_set_params (pool_config, pool_caps, size,
        min_buffers, max_buffers);
Hyunjun Ko's avatar
Hyunjun Ko committed
1197
1198
    if (!gst_buffer_pool_set_config (pool, pool_config))
      goto error_set_config;
1199
    gst_video_info_from_caps (&thiz->non_msdk_pool_info, pool_caps);
Scott D Phillips's avatar
Scott D Phillips committed
1200

1201
1202
1203
1204
1205
    /* update width and height with actual negotiated values */
    GST_VIDEO_INFO_WIDTH (&thiz->non_msdk_pool_info) =
        GST_VIDEO_INFO_WIDTH (&thiz->output_info);
    GST_VIDEO_INFO_HEIGHT (&thiz->non_msdk_pool_info) =
        GST_VIDEO_INFO_HEIGHT (&thiz->output_info);
Scott D Phillips's avatar
Scott D Phillips committed
1206
1207
1208
1209
1210
  }

  gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
      max_buffers);

1211
1212
1213
  if (pool)
    gst_object_unref (pool);

1214

Scott D Phillips's avatar
Scott D Phillips committed
1215
  return TRUE;
1216

Hyunjun Ko's avatar
Hyunjun Ko committed
1217
failed_to_create_pool:
1218
1219
1220
1221
  GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
  if (pool)
    gst_object_unref (pool);
  return FALSE;
1222

Hyunjun Ko's avatar
Hyunjun Ko committed
1223
1224
1225
1226
1227
error_set_config:
  GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
  if (pool)
    gst_object_unref (pool);
  return FALSE;
1228
1229
}

Scott D Phillips's avatar
Scott D Phillips committed
1230
1231
1232
1233
static GstFlowReturn
gst_msdkdec_drain (GstVideoDecoder * decoder)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);
1234
1235
  GstFlowReturn flow;
  GstBuffer *buffer;
Scott D Phillips's avatar
Scott D Phillips committed
1236
1237
1238
1239
1240
1241
  MsdkDecTask *task;
  MsdkSurface *surface = NULL;
  mfxSession session;
  mfxStatus status;
  guint i;

1242
  if (!thiz->initialized)
Scott D Phillips's avatar
Scott D Phillips committed
1243
    return GST_FLOW_OK;
Hyunjun Ko's avatar
Hyunjun Ko committed
1244
  session = gst_msdk_context_get_session (thiz->context);
Scott D Phillips's avatar
Scott D Phillips committed
1245
1246
1247

  for (;;) {
    task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
Hyunjun Ko's avatar
Hyunjun Ko committed
1248
1249
1250
1251
1252
    if ((flow = gst_msdkdec_finish_task (thiz, task)) != GST_FLOW_OK) {
      if (flow != GST_FLOW_FLUSHING)
        GST_WARNING_OBJECT (decoder,
            "failed to finish the task %p, but keep draining for the remaining frames",
            task);
1253
    }
1254

Scott D Phillips's avatar
Scott D Phillips committed
1255
    if (!surface) {
1256
1257
1258
1259
      flow = allocate_output_buffer (thiz, &buffer);
      if (flow != GST_FLOW_OK)
        return flow;
      surface = get_surface (thiz, buffer);
Scott D Phillips's avatar
Scott D Phillips committed
1260
1261
1262
1263
1264
      if (!surface)
        return GST_FLOW_ERROR;
    }

    status =
Hyunjun Ko's avatar
Hyunjun Ko committed
1265
        MFXVideoDECODE_DecodeFrameAsync (session, NULL, surface->surface,
Scott D Phillips's avatar
Scott D Phillips committed
1266
1267
1268
        &task->surface, &task->sync_point);
    if (G_LIKELY (status == MFX_ERR_NONE)) {
      thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
Hyunjun Ko's avatar
Hyunjun Ko committed
1269
1270
1271

      if (surface->surface->Data.Locked == 0)
        free_surface (thiz, surface);
Scott D Phillips's avatar
Scott D Phillips committed
1272
      surface = NULL;
Hyunjun Ko's avatar
Hyunjun Ko committed
1273
    } else if (status == MFX_WRN_VIDEO_PARAM_CHANGED) {
Scott D Phillips's avatar
Scott D Phillips committed
1274
      continue;
Hyunjun Ko's avatar
Hyunjun Ko committed
1275
    } else if (status == MFX_WRN_DEVICE_BUSY) {
Scott D Phillips's avatar
Scott D Phillips committed
1276
1277
      /* If device is busy, wait 1ms and retry, as per MSDK's recomendation */
      g_usleep (1000);
Hyunjun Ko's avatar
Hyunjun Ko committed
1278
1279
1280
1281
1282
1283

      /* If the current surface is still busy, we should do sync oepration
       * then tries to decode again
       */
      thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
    } else if (status == MFX_ERR_MORE_DATA) {
Scott D Phillips's avatar
Scott D Phillips committed
1284
      break;
Hyunjun Ko's avatar
Hyunjun Ko committed
1285
1286
1287
1288
    } else if (status == MFX_ERR_MORE_SURFACE) {
      surface = NULL;
      continue;
    } else if (status < MFX_ERR_NONE)
Scott D Phillips's avatar
Scott D Phillips committed
1289
1290
1291
      return GST_FLOW_ERROR;
  }
  if (surface)
Hyunjun Ko's avatar
Hyunjun Ko committed
1292
    free_surface (thiz, surface);
Scott D Phillips's avatar
Scott D Phillips committed
1293
1294
1295

  for (i = 0; i < thiz->tasks->len; i++) {
    task = &g_array_index (thiz->tasks, MsdkDecTask, thiz->next_task);
1296
    gst_msdkdec_finish_task (thiz, task);
Scott D Phillips's avatar
Scott D Phillips committed
1297
1298
    thiz->next_task = (thiz->next_task + 1) % thiz->tasks->len;
  }
Hyunjun Ko's avatar
Hyunjun Ko committed
1299
1300
1301

  release_msdk_surfaces (thiz);

Scott D Phillips's avatar
Scott D Phillips committed
1302
1303
1304
  return GST_FLOW_OK;
}

Hyunjun Ko's avatar
Hyunjun Ko committed
1305
1306
1307
1308
1309
1310
1311
1312
static gboolean
gst_msdkdec_flush (GstVideoDecoder * decoder)
{
  GstMsdkDec *thiz = GST_MSDKDEC (decoder);

  return gst_msdkdec_drain (GST_VIDEO_DECODER_CAST (thiz));
}

Scott D Phillips's avatar
Scott D Phillips committed
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
static GstFlowReturn
gst_msdkdec_finish (GstVideoDecoder * decoder)
{
  return gst_msdkdec_drain (decoder);
}

static void
gst_msdkdec_set_property (GObject * object, guint prop_id, const GValue * value,
    GParamSpec * pspec)
{
  GstMsdkDec *thiz = GST_MSDKDEC (object);
  GstState state;

  GST_OBJECT_LOCK (thiz);

  state = GST_STATE (thiz);
  if ((state != GST_STATE_READY && state != GST_STATE_NULL) &&
      !(pspec->flags & GST_PARAM_MUTABLE_PLAYING))
    goto wrong_state;

  switch (prop_id) {
1334
    case GST_MSDKDEC_PROP_HARDWARE:
Scott D Phillips's avatar
Scott D Phillips committed
1335
1336
      thiz->hardware = g_value_get_boolean (value);
      break;
1337
    case GST_MSDKDEC_PROP_ASYNC_DEPTH:
Scott D Phillips's avatar
Scott D Phillips committed
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
      thiz->async_depth = g_value_get_uint (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
  GST_OBJECT_UNLOCK (thiz);
  return;

  /* ERROR */
wrong_state:
  {
    GST_WARNING_OBJECT (thiz, "setting property in wrong state");
    GST_OBJECT_UNLOCK (thiz);
  }
}

static void
gst_msdkdec_get_property (GObject * object, guint prop_id, GValue * value,
    GParamSpec * pspec)
{
  GstMsdkDec *thiz = GST_MSDKDEC (object);

  GST_OBJECT_LOCK (thiz);
  switch (prop_id) {
1363
    case GST_MSDKDEC_PROP_HARDWARE:
Scott D Phillips's avatar
Scott D Phillips committed
1364
1365
      g_value_set_boolean (value, thiz->hardware);
      break;
1366
    case GST_MSDKDEC_PROP_ASYNC_DEPTH:
Scott D Phillips's avatar
Scott D Phillips committed
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
      g_value_set_uint (value, thiz->async_depth);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
  GST_OBJECT_UNLOCK (thiz);
}

static void
gst_msdkdec_finalize (GObject * object)
{
  GstMsdkDec *thiz = GST_MSDKDEC (object);

  g_array_unref (thiz->tasks);
1382
  g_object_unref (thiz->adapter);
Scott D Phillips's avatar
Scott D Phillips committed
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
}

static void
gst_msdkdec_class_init (GstMsdkDecClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *element_class;
  GstVideoDecoderClass *decoder_class;

  gobject_class = G_OBJECT_CLASS (klass);
  element_class = GST_ELEMENT_CLASS (klass);
  decoder_class = GST_VIDEO_DECODER_CLASS (klass);

  gobject_class->set_property = gst_msdkdec_set_property;
  gobject_class->get_property = gst_msdkdec_get_property;
  gobject_class->finalize = gst_msdkdec_finalize;

1400
1401
  element_class->set_context = gst_msdkdec_set_context;

Scott D Phillips's avatar
Scott D Phillips committed
1402
  decoder_class->close = GST_DEBUG_FUNCPTR (gst_msdkdec_close);
1403
  decoder_class->start = GST_DEBUG_FUNCPTR (gst_msdkdec_start);
Scott D Phillips's avatar
Scott D Phillips committed
1404
1405
1406
1407
1408
1409
  decoder_class->stop = GST_DEBUG_FUNCPTR (gst_msdkdec_stop);
  decoder_class->set_format = GST_DEBUG_FUNCPTR (gst_msdkdec_set_format);
  decoder_class->finish = GST_DEBUG_FUNCPTR (gst_msdkdec_finish);
  decoder_class->handle_frame = GST_DEBUG_FUNCPTR (gst_msdkdec_handle_frame);
  decoder_class->decide_allocation =
      GST_DEBUG_FUNCPTR (gst_msdkdec_decide_allocation);
1410
  decoder_class->flush = GST_DEBUG_FUNCPTR (gst_msdkdec_flush);
Scott D Phillips's avatar
Scott D Phillips committed
1411
1412
  decoder_class->drain = GST_DEBUG_FUNCPTR (gst_msdkdec_drain);

1413
  g_object_class_install_property (gobject_class, GST_MSDKDEC_PROP_HARDWARE,
Scott D Phillips's avatar
Scott D Phillips committed
1414
1415
1416
      g_param_spec_boolean ("hardware", "Hardware", "Enable hardware decoders",
          PROP_HARDWARE_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

1417
  g_object_class_install_property (gobject_class, GST_MSDKDEC_PROP_ASYNC_DEPTH,
Scott D Phillips's avatar
Scott D Phillips committed
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
      g_param_spec_uint ("async-depth", "Async Depth",
          "Depth of asynchronous pipeline",
          1, 20, PROP_ASYNC_DEPTH_DEFAULT,
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

  gst_element_class_add_static_pad_template (element_class, &src_factory);
}

static void
gst_msdkdec_init (GstMsdkDec * thiz)
{
  gst_video_info_init (&thiz->output_info);
1430
  gst_video_info_init (&thiz->non_msdk_pool_info);
Scott D Phillips's avatar
Scott D Phillips committed
1431
1432
1433
  thiz->tasks = g_array_new (FALSE, TRUE, sizeof (