• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2020 Collabora Ltd.
3  *   Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include "gstv4l2codecdevice.h"
26 #include "gstv4l2codech264dec.h"
27 #include "gstv4l2codecmpeg2dec.h"
28 #include "gstv4l2codecvp8dec.h"
29 #include "gstv4l2codecvp9dec.h"
30 #include "gstv4l2decoder.h"
31 #include "linux/v4l2-controls.h"
32 #include "linux/media.h"
33 
34 #define GST_CAT_DEFAULT gstv4l2codecs_debug
35 GST_DEBUG_CATEGORY (gstv4l2codecs_debug);
36 
37 static void
register_video_decoder(GstPlugin * plugin,GstV4l2CodecDevice * device)38 register_video_decoder (GstPlugin * plugin, GstV4l2CodecDevice * device)
39 {
40   GstV4l2Decoder *decoder = gst_v4l2_decoder_new (device);
41   gint i;
42   guint32 fmt;
43 
44   if (!gst_v4l2_decoder_open (decoder)) {
45     g_object_unref (decoder);
46     return;
47   }
48 
49   for (i = 0; gst_v4l2_decoder_enum_sink_fmt (decoder, i, &fmt); i++) {
50     switch (fmt) {
51       case V4L2_PIX_FMT_H264_SLICE:
52         GST_INFO_OBJECT (decoder, "Registering %s as H264 Decoder",
53             device->name);
54         gst_v4l2_codec_h264_dec_register (plugin, decoder, device,
55             GST_RANK_PRIMARY + 1);
56         break;
57       case V4L2_PIX_FMT_VP8_FRAME:
58         GST_INFO_OBJECT (decoder, "Registering %s as VP8 Decoder",
59             device->name);
60         gst_v4l2_codec_vp8_dec_register (plugin, decoder, device,
61             GST_RANK_PRIMARY + 1);
62         break;
63       case V4L2_PIX_FMT_MPEG2_SLICE:
64         GST_INFO_OBJECT (decoder, "Registering %s as Mpeg2 Decoder",
65             device->name);
66         gst_v4l2_codec_mpeg2_dec_register (plugin, decoder, device,
67             GST_RANK_PRIMARY + 1);
68         break;
69       case V4L2_PIX_FMT_VP9_FRAME:
70         GST_INFO_OBJECT (decoder, "Registering %s as VP9 Decoder",
71             device->name);
72         gst_v4l2_codec_vp9_dec_register (plugin, decoder, device,
73             GST_RANK_PRIMARY + 1);
74         break;
75 
76       default:
77         GST_FIXME_OBJECT (decoder, "%" GST_FOURCC_FORMAT " is not supported.",
78             GST_FOURCC_ARGS (fmt));
79         break;
80     }
81   }
82 
83   g_object_unref (decoder);
84 }
85 
86 static gboolean
plugin_init(GstPlugin * plugin)87 plugin_init (GstPlugin * plugin)
88 {
89   GList *devices, *d;
90   const gchar *paths[] = { "/dev", NULL };
91   const gchar *names[] = { "media", NULL };
92 
93   GST_DEBUG_CATEGORY_INIT (gstv4l2codecs_debug, "v4l2codecs", 0,
94       "V4L2 CODECs general debug");
95 
96   /* Add some dependency, so the dynamic features get updated upon changes in
97    * /dev/media* */
98   gst_plugin_add_dependency (plugin,
99       NULL, paths, names, GST_PLUGIN_DEPENDENCY_FLAG_FILE_NAME_IS_PREFIX);
100 
101   devices = gst_v4l2_codec_find_devices ();
102   for (d = devices; d; d = g_list_next (d)) {
103     GstV4l2CodecDevice *device = d->data;
104 
105     if (device->function == MEDIA_ENT_F_PROC_VIDEO_DECODER)
106       register_video_decoder (plugin, device);
107   }
108 
109   gst_v4l2_codec_device_list_free (devices);
110   return TRUE;
111 }
112 
113 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
114     GST_VERSION_MINOR,
115     v4l2codecs,
116     "V4L2 CODEC Accelerators plugin",
117     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
118