File: plugin.c

package info (click to toggle)
gst-plugins-bad1.0 1.26.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,996 kB
  • sloc: ansic: 722,568; cpp: 278,154; objc: 3,556; xml: 3,351; sh: 1,095; python: 508; makefile: 175; java: 75
file content (153 lines) | stat: -rw-r--r-- 5,199 bytes parent folder | download | duplicates (2)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* GStreamer
 * Copyright (C) 2020 Collabora Ltd.
 *   Author: Nicolas Dufresne <nicolas.dufresne@collabora.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.
 */

/**
 * plugin-v4l2codecs:
 * @title: V4L2 Stateless codec
 * @short_description: V4L2 plugin to support Statless codec drivers
 *
 * This plugin provides support for Video4Linux2 drivers implementing stateless
 * video codecs. The plugin will generate elements based on the system
 * capabilities. For this reason, this documentation may differ from output
 * of running `gst-inspect-1.0` on your target.
 *
 * If you are having issues getting any elementis to be registered, you may want
 * to verify that your user have adequate permissions to access media and video
 * devices. These Linux devices are usually found in `/dev/media*` and
 * `/dev/video*`.
 *
 * This documentation as been generated with the use of the environment variable
 * `GST_V4L2_CODEC_GEN_DOC=1`. Using tis environment outside of the documentation
 * generation will render your codecs unusable.
 *
 * Since: 1.18
 */

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

#include "gstv4l2codecav1dec.h"
#include "gstv4l2codecdevice.h"
#include "gstv4l2codech264dec.h"
#include "gstv4l2codech265dec.h"
#include "gstv4l2codecmpeg2dec.h"
#include "gstv4l2codecvp8dec.h"
#include "gstv4l2codecvp9dec.h"
#include "gstv4l2decoder.h"
#include "linux/v4l2-controls.h"
#include "linux/media.h"

#define GST_CAT_DEFAULT gstv4l2codecs_debug
GST_DEBUG_CATEGORY (gstv4l2codecs_debug);

static void
register_video_decoder (GstPlugin * plugin, GstV4l2CodecDevice * device)
{
  GstV4l2Decoder *decoder = gst_v4l2_decoder_new (device);
  gint i;
  guint32 fmt;

  if (!gst_v4l2_decoder_open (decoder)) {
    g_object_unref (decoder);
    return;
  }

  for (i = 0; gst_v4l2_decoder_enum_sink_fmt (decoder, i, &fmt); i++) {
    switch (fmt) {
      case V4L2_PIX_FMT_H264_SLICE:
        GST_INFO_OBJECT (decoder, "Registering %s as H264 Decoder",
            device->name);
        gst_v4l2_codec_h264_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;
      case V4L2_PIX_FMT_HEVC_SLICE:
        GST_INFO_OBJECT (decoder, "Registering %s as H265 Decoder",
            device->name);
        gst_v4l2_codec_h265_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;

      case V4L2_PIX_FMT_VP8_FRAME:
        GST_INFO_OBJECT (decoder, "Registering %s as VP8 Decoder",
            device->name);
        gst_v4l2_codec_vp8_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;
      case V4L2_PIX_FMT_MPEG2_SLICE:
        GST_INFO_OBJECT (decoder, "Registering %s as Mpeg2 Decoder",
            device->name);
        gst_v4l2_codec_mpeg2_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;
      case V4L2_PIX_FMT_VP9_FRAME:
        GST_INFO_OBJECT (decoder, "Registering %s as VP9 Decoder",
            device->name);
        gst_v4l2_codec_vp9_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;
      case V4L2_PIX_FMT_AV1_FRAME:
        GST_INFO_OBJECT (decoder, "Registering %s as AV1 Decoder",
            device->name);
        gst_v4l2_codec_av1_dec_register (plugin, decoder, device,
            GST_RANK_PRIMARY + 1);
        break;
      default:
        GST_FIXME_OBJECT (decoder, "%" GST_FOURCC_FORMAT " is not supported.",
            GST_FOURCC_ARGS (fmt));
        break;
    }
  }

  g_object_unref (decoder);
}

static gboolean
plugin_init (GstPlugin * plugin)
{
  GList *devices, *d;
  const gchar *paths[] = { "/dev", NULL };
  const gchar *names[] = { "media", NULL };

  GST_DEBUG_CATEGORY_INIT (gstv4l2codecs_debug, "v4l2codecs", 0,
      "V4L2 CODECs general debug");

  /* Add some dependency, so the dynamic features get updated upon changes in
   * /dev/media* */
  gst_plugin_add_dependency (plugin,
      NULL, paths, names, GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX);

  devices = gst_v4l2_codec_find_devices ();
  for (d = devices; d; d = g_list_next (d)) {
    GstV4l2CodecDevice *device = d->data;

    if (device->function == MEDIA_ENT_F_PROC_VIDEO_DECODER)
      register_video_decoder (plugin, device);
  }

  gst_v4l2_codec_device_list_free (devices);
  return TRUE;
}

GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
    GST_VERSION_MINOR,
    v4l2codecs,
    "V4L2 CODEC Accelerators plugin",
    plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)