remove unused logging macros.
[platform/adaptation/emulator/gst-plugins-emulator.git] / src / gstmaru.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) 2013 Samsung Electronics Co., Ltd.
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /* First, include the header file for the plugin, to bring in the
22  * object definition and other useful things.
23  */
24
25 /* Modifications by Samsung Electronics Co., Ltd.
26  * 1. Get available Video/Audio Codecs from Qemu
27  */
28
29 #include "gstmaru.h"
30 #include "gstmaruutils.h"
31 #include "gstmaruinterface.h"
32
33 GST_DEBUG_CATEGORY (maru_debug);
34
35 #define GST_TYPE_MARUDEC \
36   (gst_maru_dec_get_type())
37 #define GST_MARUDEC(obj) \
38   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MARUDEC,GstMaruDec))
39 #define GST_MARUDEC_CLASS(klass) \
40   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MARUDEC,GstMaruDecClass))
41 #define GST_IS_MARUDEC(obj) \
42   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MARUDEC))
43 #define GST_IS_MARUDEC_CLASS(klass) \
44   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MARUDEC))
45
46 gboolean gst_marudec_register (GstPlugin *plugin, GList *element);
47 gboolean gst_maruenc_register (GstPlugin *plugin, GList *element);
48
49 static GList *elements = NULL;
50 static gboolean codec_element_init = FALSE;
51 static GMutex gst_maru_mutex;
52
53 int device_version;
54
55 static gboolean
56 gst_maru_codec_element_init ()
57 {
58   int fd = 0, ret = TRUE;
59   void *buffer = MAP_FAILED;
60
61   codec_element_init = TRUE;
62
63   fd = open (CODEC_DEV, O_RDWR);
64   if (fd < 0) {
65     perror ("[gst-maru] failed to open codec device");
66     GST_ERROR ("failed to open codec device");
67     ret = FALSE;
68     goto out;
69   }
70
71   // get device version
72   // if version 3
73   device_version = interface_version_3->get_device_version(fd);
74   if (device_version < 0) {
75     // if version 2
76     device_version = interface_version_2->get_device_version(fd);
77   }
78   if (device_version < 0) {
79     perror ("[gst-maru] Incompatible device version");
80     GST_ERROR ("Incompatible device version");
81     ret = FALSE;
82     goto out;
83   }
84
85   // interface mapping
86   if (device_version < 3) {
87     interface = interface_version_2;
88   } else if (device_version >= 3 && device_version < 4) {
89     interface = interface_version_3;
90   } else {
91     perror ("[gst-maru] Incompatible device version");
92     GST_ERROR ("Incompatible device version");
93     ret = FALSE;
94     goto out;
95   }
96
97   // prepare elements
98   if ((elements = interface->prepare_elements(fd)) == NULL) {
99     perror ("[gst-maru] cannot prepare elements");
100     GST_ERROR ("cannot prepare elements");
101     ret = FALSE;
102     goto out;
103   }
104
105   // try to mmap device memory
106   buffer = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
107   if (buffer == MAP_FAILED) {
108     perror ("[gst-maru] memory mapping failure");
109     GST_ERROR ("memory mapping failure");
110     ret = FALSE;
111   }
112
113 out:
114   if (buffer != MAP_FAILED) {
115     munmap (buffer, 4096);
116   }
117   if (fd >= 0) {
118     close (fd);
119   }
120
121   return ret;
122 }
123
124 static gboolean
125 plugin_init (GstPlugin *plugin)
126 {
127   GST_DEBUG_CATEGORY_INIT (maru_debug,
128       "tizen-emul", 0, "Tizen Emulator Codec Elements");
129
130   gst_maru_init_pix_fmt_info ();
131
132   g_mutex_lock (&gst_maru_mutex);
133   if (!codec_element_init) {
134     if (!gst_maru_codec_element_init ()) {
135       g_mutex_unlock (&gst_maru_mutex);
136
137       GST_ERROR ("failed to get codec elements from QEMU");
138       return FALSE;
139     }
140   }
141   g_mutex_unlock (&gst_maru_mutex);
142
143   if (!gst_marudec_register (plugin, elements)) {
144     GST_ERROR ("failed to register decoder elements");
145     return FALSE;
146   }
147   if (!gst_maruenc_register (plugin, elements)) {
148     GST_ERROR ("failed to register encoder elements");
149     return FALSE;
150   }
151
152   return TRUE;
153 }
154
155 #ifndef PACKAGE
156 #define PACKAGE "gst-plugins-emulator"
157 #endif
158
159 GST_PLUGIN_DEFINE (
160   GST_VERSION_MAJOR,
161   GST_VERSION_MINOR,
162   "tizen-emul",
163   "Codecs for Tizen Emulator",
164   plugin_init,
165   "0.3.0",
166   "LGPL",
167   "gst-plugins-emulator",
168   "http://www.tizen.org"
169 )