2 * Copyright (C) 2007-2009 Nokia Corporation.
4 * Author: Felipe Contreras <felipe.contreras@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <gst/gststructure.h>
29 #include "gstomx_dummy.h"
30 #include "gstomx_mpeg4dec.h"
31 #include "gstomx_h263dec.h"
32 #include "gstomx_h264dec.h"
33 #include "gstomx_wmvdec.h"
34 #include "gstomx_mpeg4enc.h"
35 #include "gstomx_h264enc.h"
36 #include "gstomx_h263enc.h"
37 #include "gstomx_vorbisdec.h"
38 #include "gstomx_mp3dec.h"
40 #include "gstomx_mp2dec.h"
41 #include "gstomx_aacdec.h"
42 #include "gstomx_aacenc.h"
43 #include "gstomx_amrnbdec.h"
44 #include "gstomx_amrnbenc.h"
45 #include "gstomx_amrwbdec.h"
46 #include "gstomx_amrwbenc.h"
47 #include "gstomx_adpcmdec.h"
48 #include "gstomx_adpcmenc.h"
49 #include "gstomx_g711dec.h"
50 #include "gstomx_g711enc.h"
51 #include "gstomx_g729dec.h"
52 #include "gstomx_g729enc.h"
53 #include "gstomx_ilbcdec.h"
54 #include "gstomx_ilbcenc.h"
55 #include "gstomx_jpegenc.h"
56 #endif /* EXPERIMENTAL */
57 #include "gstomx_audiosink.h"
59 #include "gstomx_videosink.h"
60 #include "gstomx_filereadersrc.h"
61 #endif /* EXPERIMENTAL */
62 #include "gstomx_volume.h"
64 GST_DEBUG_CATEGORY (gstomx_debug);
66 static const GstStructure *element_table;
67 static GQuark element_name_quark;
69 extern const gchar *default_config;
71 static GType (*get_type[]) (void) = {
72 gst_omx_dummy_get_type,
73 gst_omx_mpeg4dec_get_type,
74 gst_omx_h264dec_get_type,
75 gst_omx_h263dec_get_type,
76 gst_omx_wmvdec_get_type,
77 gst_omx_mpeg4enc_get_type,
78 gst_omx_h264enc_get_type,
79 gst_omx_h263enc_get_type,
80 gst_omx_vorbisdec_get_type, gst_omx_mp3dec_get_type,
82 gst_omx_mp2dec_get_type,
83 gst_omx_amrnbdec_get_type,
84 gst_omx_amrnbenc_get_type,
85 gst_omx_amrwbdec_get_type,
86 gst_omx_amrwbenc_get_type,
87 gst_omx_aacdec_get_type,
88 gst_omx_aacenc_get_type,
89 gst_omx_adpcmdec_get_type,
90 gst_omx_adpcmenc_get_type,
91 gst_omx_g711dec_get_type,
92 gst_omx_g711enc_get_type,
93 gst_omx_g729dec_get_type,
94 gst_omx_g729enc_get_type,
95 gst_omx_ilbcdec_get_type,
96 gst_omx_ilbcenc_get_type, gst_omx_jpegenc_get_type,
97 #endif /* EXPERIMENTAL */
98 gst_omx_audiosink_get_type,
100 gst_omx_videosink_get_type, gst_omx_filereadersrc_get_type,
101 #endif /* EXPERIMENTAL */
102 gst_omx_volume_get_type,};
105 get_config_path (void)
108 #if 1 /* Fix_config_path */
109 return g_build_filename (OMX_CONFIG_DIRPATH, OMX_CONFIG_FILENAME, NULL);
112 const gchar *const *dirs;
115 path = g_strdup (g_getenv ("OMX_CONFIG"));
120 dirs = g_get_system_config_dirs ();
121 for (i = 0; dirs[i]; i++) {
123 g_build_filename (dirs[i], "gstreamer-0.10", "gst-openmax.conf", NULL);
124 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
129 return g_build_filename (g_get_user_config_dir (), "gst-openmax.conf", NULL);
134 fetch_element_table (GstPlugin * plugin)
138 GstStructure *tmp, *element;
140 element_table = gst_plugin_get_cache_data (plugin);
145 path = get_config_path ();
147 if (!g_file_get_contents (path, &config, NULL, NULL)) {
148 g_warning ("could not find config file '%s'.. using defaults!", path);
149 config = (gchar *) default_config;
152 gst_plugin_add_dependency_simple (plugin, "ONX_CONFIG", path, NULL,
153 GST_PLUGIN_DEPENDENCY_FLAG_NONE);
157 GST_DEBUG ("parsing config:\n%s", config);
159 tmp = gst_structure_empty_new ("element_table");
163 while ((element = gst_structure_from_string (s, &s))) {
164 const gchar *element_name = gst_structure_get_name (element);
165 gst_structure_set (tmp, element_name, GST_TYPE_STRUCTURE, element, NULL);
168 if (config != default_config)
171 GST_DEBUG ("element_table=%" GST_PTR_FORMAT, tmp);
173 gst_plugin_set_cache_data (plugin, tmp);
178 static GstStructure *
179 get_element_entry (const gchar * element_name)
181 GstStructure *element;
183 if (!gst_structure_get ((GstStructure *) element_table, element_name,
184 GST_TYPE_STRUCTURE, &element, NULL)) {
188 /* This assert should never fail, because plugin elements are registered
189 * based on the entries in this table. Someone would have to manually
190 * override the type qdata for this to fail.
197 /* register a new dynamic sub-class with the name 'type_name'.. this gives us
198 * a way to use the same (for example) GstOmxMp3Dec element mapping to
199 * multiple different element names with different OMX library implementations
200 * and/or component names
203 create_subtype (GType parent_type, const gchar * type_name)
206 GTypeInfo i = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
211 g_type_query (parent_type, &q);
213 i.class_size = q.class_size;
214 i.instance_size = q.instance_size;
216 return g_type_register_static (parent_type, type_name, &i, 0);
220 plugin_init (GstPlugin * plugin)
224 GST_DEBUG_CATEGORY_INIT (gstomx_debug, "omx", 0, "gst-openmax");
225 GST_DEBUG_CATEGORY_INIT (gstomx_util_debug, "omx_util", 0,
226 "gst-openmax utility");
228 element_name_quark = g_quark_from_static_string ("element-name");
231 * First, call all the _get_type() functions to ensure the types are
234 for (i = 0; i < G_N_ELEMENTS (get_type); i++)
237 fetch_element_table (plugin);
241 cnt = gst_structure_n_fields (element_table);
242 for (i = 0; i < cnt; i++) {
243 const gchar *element_name = gst_structure_nth_field_name (element_table, i);
244 GstStructure *element = get_element_entry (element_name);
245 const gchar *type_name, *parent_type_name;
246 const gchar *component_name, *library_name;
247 // const gchar *component_role;
251 GST_DEBUG ("element_name=%s, element=%" GST_PTR_FORMAT, element_name,
254 parent_type_name = gst_structure_get_string (element, "parent-type");
255 type_name = gst_structure_get_string (element, "type");
256 component_name = gst_structure_get_string (element, "component-name");
257 // component_role = gst_structure_get_string (element, "component-role");
258 library_name = gst_structure_get_string (element, "library-name");
260 if (!type_name || !component_name || !library_name) {
261 g_warning ("malformed config file: missing required fields for %s",
266 if (parent_type_name) {
267 type = g_type_from_name (parent_type_name);
269 type = create_subtype (type, type_name);
271 g_warning ("malformed config file: invalid parent-type '%s' for %s",
272 parent_type_name, element_name);
276 type = g_type_from_name (type_name);
280 g_warning ("malformed config file: invalid type '%s' for %s",
281 type_name, element_name);
285 g_type_set_qdata (type, element_name_quark, (gpointer) element_name);
287 if (!gst_structure_get_int (element, "rank", &rank)) {
288 /* use default rank: */
289 rank = GST_RANK_NONE;
292 if (!gst_element_register (plugin, element_name, rank, type)) {
293 g_warning ("failed registering '%s'", element_name);
302 gstomx_get_component_info (void *core, GType type)
304 GOmxCore *rcore = core;
305 const gchar *element_name;
306 GstStructure *element;
309 element_name = g_type_get_qdata (type, element_name_quark);
310 element = get_element_entry (element_name);
315 str = gst_structure_get_string (element, "library-name");
316 rcore->library_name = g_strdup (str);
318 str = gst_structure_get_string (element, "component-name");
319 rcore->component_name = g_strdup (str);
321 str = gst_structure_get_string (element, "component-role");
322 rcore->component_role = g_strdup (str);
328 gstomx_core_new (void *object, GType type)
330 GOmxCore *core = g_omx_core_new (object);
331 gstomx_get_component_info (core, type);
332 g_omx_core_init (core);
337 gstomx_template_caps (GType type, const gchar * pad_name)
339 const gchar *element_name;
340 GstStructure *element;
341 const gchar *caps_str;
343 element_name = g_type_get_qdata (type, element_name_quark);
344 element = get_element_entry (element_name);
347 /* this shouldn't really happen.. */
351 caps_str = gst_structure_get_string (element, pad_name);
353 GST_DEBUG ("%s: %s", element_name, caps_str);
355 /* default to ANY.. at least for now.. maybe when everything is converted
356 * over, we should treat missing caps as a more serious condition?
359 g_warning ("%s is missing required field: %s", element_name, pad_name);
363 return gst_caps_from_string (caps_str);
367 gstomx_install_property_helper (GObjectClass * gobject_class)
370 g_object_class_install_property (gobject_class, ARG_COMPONENT_NAME,
371 g_param_spec_string ("component-name", "Component name",
372 "Name of the OpenMAX IL component to use",
373 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
375 g_object_class_install_property (gobject_class, ARG_COMPONENT_ROLE,
376 g_param_spec_string ("component-role", "Component role",
377 "Role of the OpenMAX IL component",
378 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
380 g_object_class_install_property (gobject_class, ARG_LIBRARY_NAME,
381 g_param_spec_string ("library-name", "Library name",
382 "Name of the OpenMAX IL implementation library to use",
383 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
387 gstomx_get_property_helper (void *core, guint prop_id, GValue * value)
389 GOmxCore *gomx = core;
391 case ARG_COMPONENT_NAME:
392 g_value_set_string (value, gomx->component_name);
394 case ARG_COMPONENT_ROLE:
395 g_value_set_string (value, gomx->component_role);
397 case ARG_LIBRARY_NAME:
398 g_value_set_string (value, gomx->library_name);
405 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
410 PACKAGE_VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)