2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
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.
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.
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., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 /* First, include the header file for the plugin, to bring in the
22 * object definition and other useful things.
25 /* Modifications by Samsung Electronics Co., Ltd.
26 * 1. Get available Video/Audio Codecs from Qemu
30 #include "gstmaruutils.h"
32 GST_DEBUG_CATEGORY (maru_debug);
34 #define GST_TYPE_MARUDEC \
35 (gst_maru_dec_get_type())
36 #define GST_MARUDEC(obj) \
37 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MARUDEC,GstMaruDec))
38 #define GST_MARUDEC_CLASS(klass) \
39 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MARUDEC,GstMaruDecClass))
40 #define GST_IS_MARUDEC(obj) \
41 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MARUDEC))
42 #define GST_IS_MARUDEC_CLASS(klass) \
43 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MARUDEC))
45 gboolean gst_marudec_register (GstPlugin *plugin, GList *element);
46 gboolean gst_maruenc_register (GstPlugin *plugin, GList *element);
48 static GList *codec_element = NULL;
49 static gboolean codec_element_init = FALSE;
50 static GMutex gst_maru_mutex;
55 gst_maru_codec_element_init ()
59 uint32_t data_length = 0;
60 void *buffer = MAP_FAILED;
61 CodecElement *elem = NULL;
63 CODEC_LOG (DEBUG, "enter: %s\n", __func__);
65 codec_element_init = TRUE;
67 fd = open (CODEC_DEV, O_RDWR);
69 perror ("[gst-maru] failed to open codec device");
70 GST_ERROR ("failed to open codec device");
74 ioctl (fd, CODEC_CMD_GET_VERSION, &device_version);
75 GST_LOG ("pluigin version is [%u]", CODEC_VER);
76 GST_LOG ("device version is [%u]", device_version);
77 // FIXME: check version
79 if (device_version < CODEC_VER) {
80 GST_ERROR ("plugin version [%u] is not support device version [%u]", CODEC_VER, device_version);
86 buffer = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
87 if (buffer == MAP_FAILED) {
88 perror ("[gst-maru] memory mapping failure");
89 GST_ERROR ("memory mapping failure");
94 GST_DEBUG ("request a device to get codec element");
95 if (ioctl(fd, CODEC_CMD_GET_ELEMENT, &data_length) < 0) {
96 perror ("[gst-maru] failed to get codec elements");
97 GST_ERROR ("failed to get codec elements");
98 munmap (buffer, 4096);
103 GST_DEBUG ("total size of codec elements %d", data_length);
104 elem = g_malloc0 (data_length);
106 GST_ERROR ("failed to allocate memory for codec elements");
107 munmap (buffer, 4096);
112 if (ioctl(fd, CODEC_CMD_GET_ELEMENT_DATA, elem) < 0) {
113 GST_ERROR ("failed to get codec elements");
114 munmap (buffer, 4096);
119 elem_cnt = data_length / sizeof(CodecElement);
120 for (i = 0; i < elem_cnt; i++) {
121 codec_element = g_list_append (codec_element, &elem[i]);
124 munmap (buffer, 4096);
127 CODEC_LOG (DEBUG, "leave: %s\n", __func__);
133 plugin_init (GstPlugin *plugin)
135 GST_DEBUG_CATEGORY_INIT (maru_debug,
136 "tizen-emul", 0, "Tizen Emulator Codec Elements");
138 gst_maru_init_pix_fmt_info ();
140 g_mutex_lock (&gst_maru_mutex);
141 if (!codec_element_init) {
142 if (!gst_maru_codec_element_init ()) {
143 g_mutex_unlock (&gst_maru_mutex);
145 GST_ERROR ("failed to get codec elements from QEMU");
149 g_mutex_unlock (&gst_maru_mutex);
151 if (!gst_marudec_register (plugin, codec_element)) {
152 GST_ERROR ("failed to register decoder elements");
155 if (!gst_maruenc_register (plugin, codec_element)) {
156 GST_ERROR ("failed to register encoder elements");
161 while ((codec_element = g_list_next (codec_element))) {
162 g_list_free (codec_element);
170 #define PACKAGE "gst-plugins-emulator"
177 "Codecs for Tizen Emulator",
181 "gst-plugins-emulator",
182 "http://www.tizen.org"