summaryrefslogtreecommitdiff
path: root/sys/mediafoundation/plugin.c
blob: 923f5b03edbe54eff59cdd10b0be70170c41a76d (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
/* GStreamer
 * Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
 * Copyright (C) 2020 Seungha Yang <seungha@centricular.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "gstmfconfig.h"

#include <winapifamily.h>

#include <gst/gst.h>
#include "gstmfvideosrc.h"
#include "gstmfdevice.h"
#include "gstmfutils.h"
#include "gstmfh264enc.h"
#include "gstmfh265enc.h"
#include "gstmfvp9enc.h"
#include "gstmfaacenc.h"
#include "gstmfmp3enc.h"

GST_DEBUG_CATEGORY (gst_mf_debug);
GST_DEBUG_CATEGORY (gst_mf_utils_debug);
GST_DEBUG_CATEGORY (gst_mf_source_object_debug);
GST_DEBUG_CATEGORY (gst_mf_transform_debug);

#define GST_CAT_DEFAULT gst_mf_debug

static void
plugin_deinit (gpointer data)
{
  MFShutdown ();
}

static gboolean
plugin_init (GstPlugin * plugin)
{
  HRESULT hr;
  GstRank rank = GST_RANK_SECONDARY;

  /**
   * plugin-mediafoundation:
   *
   * Since: 1.18
   */

  GST_DEBUG_CATEGORY_INIT (gst_mf_debug, "mf", 0, "media foundation");
  GST_DEBUG_CATEGORY_INIT (gst_mf_utils_debug,
      "mfutils", 0, "media foundation utility functions");
  GST_DEBUG_CATEGORY_INIT (gst_mf_source_object_debug,
      "mfsourceobject", 0, "mfsourceobject");
  GST_DEBUG_CATEGORY_INIT (gst_mf_transform_debug,
      "mftransform", 0, "mftransform");

  hr = MFStartup (MF_VERSION, MFSTARTUP_NOSOCKET);
  if (!gst_mf_result (hr)) {
    GST_WARNING ("MFStartup failure, hr: 0x%x", hr);
    return TRUE;
  }

  /* mfvideosrc should be primary rank for UWP */
#if (GST_MF_WINAPI_APP && !GST_MF_WINAPI_DESKTOP)
  rank = GST_RANK_PRIMARY + 1;
#endif

  gst_element_register (plugin, "mfvideosrc", rank, GST_TYPE_MF_VIDEO_SRC);
  gst_device_provider_register (plugin, "mfdeviceprovider",
      rank, GST_TYPE_MF_DEVICE_PROVIDER);

  gst_mf_h264_enc_plugin_init (plugin, GST_RANK_SECONDARY);
  gst_mf_h265_enc_plugin_init (plugin, GST_RANK_SECONDARY);
  gst_mf_vp9_enc_plugin_init (plugin, GST_RANK_SECONDARY);

  gst_mf_aac_enc_plugin_init (plugin, GST_RANK_SECONDARY);
  gst_mf_mp3_enc_plugin_init (plugin, GST_RANK_SECONDARY);

  /* So that call MFShutdown() when this plugin is no more used
   * (i.e., gst_deinit). Otherwise valgrind-like tools would complain
   * about un-released media foundation resources.
   *
   * NOTE: MFStartup and MFShutdown can be called multiple times, but the number
   * of each MFStartup and MFShutdown call should be identical. This rule is
   * simliar to that of CoInitialize/CoUninitialize pair */
  g_object_set_data_full (G_OBJECT (plugin),
      "plugin-mediafoundation-shutdown", "shutdown-data",
      (GDestroyNotify) plugin_deinit);

  return TRUE;
}

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    mediafoundation,
    "Microsoft Media Foundation plugin",
    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)