Remove unused parameters
[platform/core/multimedia/libmm-imgp-gstcs.git] / gstcs / mm_util_gstcs.c
1 /*
2  * libmm-imgp-gstcs
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: YoungHun Kim <yh8004.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include "mm_util_gstcs_internal.h"
22 #include <gst/check/gstcheck.h>
23 #include <gst/video/video-format.h>
24
25 #define MM_UTIL_ROUND_UP_2(num) (((num)+1)&~1)
26 #define MM_UTIL_ROUND_UP_4(num) (((num)+3)&~3)
27 #define MM_UTIL_ROUND_UP_8(num) (((num)+7)&~7)
28 #define MM_UTIL_ROUND_UP_16(num) (((num)+15)&~15)
29
30 #define SAFE_STRCPY(dst, src, n)        g_strlcpy(dst, src, n)
31
32
33 static GstFlowReturn
34 _mm_sink_sample(GstElement * appsink, gpointer user_data)
35 {
36         GstBuffer *_buf = NULL;
37         GstSample *_sample = NULL;
38         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
39         _sample = gst_app_sink_pull_sample((GstAppSink*)appsink);
40         if (_sample) {
41                 _buf = gst_sample_get_buffer(_sample);
42
43                 pGstreamer_s->output_buffer = _buf;
44
45                 if (pGstreamer_s->output_buffer != NULL) {
46                         GstMapInfo mapinfo = GST_MAP_INFO_INIT;
47                         gst_buffer_map(pGstreamer_s->output_buffer, &mapinfo, GST_MAP_READ);
48                         gstcs_debug("Create Output Buffer: GST_BUFFER_DATA: %p\t GST_BUFFER_SIZE: %d", mapinfo.data, mapinfo.size);
49                         gst_buffer_unmap(pGstreamer_s->output_buffer, &mapinfo);
50                 } else {
51                         gstcs_error("ERROR -Input Prepare Buffer! Check createoutput buffer function");
52                 }
53         }
54
55         gst_buffer_ref(pGstreamer_s->output_buffer); /* when you want to avoid flushing */
56         gst_sample_unref(_sample);
57
58         return GST_FLOW_OK;
59 }
60
61 static gboolean
62 _mm_on_src_message(GstBus * bus, GstMessage * message, gpointer user_data)
63 {
64         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
65         switch (GST_MESSAGE_TYPE(message)) {
66         case GST_MESSAGE_EOS: {
67                 gstcs_debug("The source got dry");
68                 gst_app_src_end_of_stream(GST_APP_SRC(pGstreamer_s->appsrc));
69                 g_main_context_pop_thread_default(pGstreamer_s->context);
70                 g_main_loop_quit(pGstreamer_s->loop);
71                 break;
72                 }
73         case GST_MESSAGE_ERROR: {
74                 GError *err = NULL;
75                 gchar *dbg_info = NULL;
76
77                 gst_message_parse_error(message, &err, &dbg_info);
78                 gstcs_error("ERROR from element %s: %s\n", GST_OBJECT_NAME(message->src), err->message);
79                 gstcs_error("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
80                 g_error_free(err);
81                 g_free(dbg_info);
82                 g_main_context_pop_thread_default(pGstreamer_s->context);
83                 g_main_loop_quit(pGstreamer_s->loop);
84                 gstcs_debug("Quit GST_CS\n");
85                 break;
86                 }
87         default:
88                 break;
89         }
90         return TRUE;
91 }
92
93 static int
94 _mm_get_byte_per_pixcel(const char *__format_label)
95 {
96         int byte_per_pixcel = 1;
97         if (strcmp(__format_label, "RGB565") == 0) {
98                 byte_per_pixcel = 2;
99         } else if (strcmp(__format_label, "RGB888") == 0 ||
100                 strcmp(__format_label, "BGR888") == 0) {
101                 byte_per_pixcel = 3;
102         } else if (strcmp(__format_label, "RGBA8888") == 0 ||
103                 strcmp(__format_label, "ARGB8888") == 0 ||
104                 strcmp(__format_label, "BGRA8888") == 0 ||
105                 strcmp(__format_label, "ABGR8888") == 0 ||
106                 strcmp(__format_label, "RGBX") == 0 ||
107                 strcmp(__format_label, "XRGB") == 0 ||
108                 strcmp(__format_label, "BGRX") == 0 ||
109                 strcmp(__format_label, "XBGR") == 0) {
110                 byte_per_pixcel = 4;
111         }
112
113         gstcs_debug("byte per pixcel : %d", byte_per_pixcel);
114
115         return byte_per_pixcel;
116 }
117
118 static int _mm_create_pipeline(gstreamer_s* pGstreamer_s)
119 {
120         int ret = GSTCS_ERROR_NONE;
121         pGstreamer_s->pipeline = gst_pipeline_new("pipeline");
122         if (!pGstreamer_s->pipeline) {
123                 gstcs_error("pipeline could not be created. Exiting.\n");
124                 ret = GSTCS_ERROR_INVALID_PARAMETER;
125         }
126         pGstreamer_s->appsrc = gst_element_factory_make("appsrc" , "appsrc");
127         if (!pGstreamer_s->appsrc) {
128                 gstcs_error("appsrc could not be created. Exiting.\n");
129                 ret = GSTCS_ERROR_INVALID_PARAMETER;
130         }
131         pGstreamer_s->colorspace = gst_element_factory_make("videoconvert" , "convert");
132         if (!pGstreamer_s->colorspace) {
133                 gstcs_error("colorspace could not be created. Exiting.\n");
134                 ret = GSTCS_ERROR_INVALID_PARAMETER;
135         }
136         pGstreamer_s->videoscale = gst_element_factory_make("videoscale", "scale");
137         if (!pGstreamer_s->videoscale) {
138                 gstcs_error("videoscale could not be created. Exiting.\n");
139                 ret = GSTCS_ERROR_INVALID_PARAMETER;
140         }
141         pGstreamer_s->videoflip = gst_element_factory_make("videoflip", "flip");
142         if (!pGstreamer_s->videoflip) {
143                 gstcs_error("videoflip could not be created. Exiting.\n");
144                 ret = GSTCS_ERROR_INVALID_PARAMETER;
145         }
146         pGstreamer_s->appsink = gst_element_factory_make("appsink" , "appsink");
147         if (!pGstreamer_s->appsink) {
148                 gstcs_error("appsink could not be created. Exiting.\n");
149                 ret = GSTCS_ERROR_INVALID_PARAMETER;
150         }
151         return ret;
152 }
153
154 static void _mm_destroy_notify(gpointer data)
155 {
156         unsigned char *_data = (unsigned char *)data;
157         if (_data != NULL) {
158                 free(_data);
159                 _data = NULL;
160         }
161 }
162
163 static void
164 _mm_check_caps_format(GstCaps* caps)
165 {
166         GstStructure *caps_structure = gst_caps_get_structure(caps, 0);
167         const gchar* formatInfo = gst_structure_get_string(caps_structure, "format");
168         gstcs_debug("[%d] caps: %s", GST_IS_CAPS(caps), formatInfo);
169 }
170
171 static void
172 _mm_link_pipeline(gstreamer_s* pGstreamer_s, int value)
173 {
174         /* set property */
175         gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL);
176         if (!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL))
177                 gstcs_error("Fail to link pipeline");
178         else
179                 gstcs_debug("Success to link pipeline");
180
181         g_object_set(G_OBJECT(pGstreamer_s->appsrc), "stream-type", 0, "format", GST_FORMAT_TIME, NULL);
182         g_object_set(pGstreamer_s->appsrc, "num-buffers", 1, NULL);
183         g_object_set(pGstreamer_s->appsrc, "is-live", TRUE, NULL); /* add because of gstreamer_s time issue */
184
185         g_object_set(pGstreamer_s->videoflip, "method", value, NULL); /* GST_VIDEO_FLIP_METHOD_IDENTITY (0): none- Identity (no rotation) (1): clockwise - Rotate clockwise 90 degrees (2): rotate-180 - Rotate 180 degrees (3): counterclockwise - Rotate counter-clockwise 90 degrees (4): horizontal-flip - Flip horizontally (5): vertical-flip - Flip vertically (6): upper-left-diagonal - Flip across upper left/lower right diagonal (7): upper-right-diagonal - Flip across upper right/lower left diagonal */
186
187         /*g_object_set(pGstreamer_s->appsink, "drop", TRUE, NULL);*/
188         g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
189 }
190
191 static void
192 _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
193 {
194         char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
195         GstVideoFormat videoFormat;
196         int _bpp = 0;
197         int _depth = 0;
198         int _red_mask = 0;
199         int _green_mask = 0;
200         int _blue_mask = 0;
201         int _alpha_mask = 0;
202         int _endianness = 0;
203
204         if (__format == NULL) {
205                 gstcs_error("Image format is NULL\n");
206                 return;
207         }
208
209         gstcs_debug("colorspace: %s(%d)\n", __format->colorspace, strlen(__format->colorspace));
210         memset(_format_name, 0, sizeof(_format_name));
211
212         if (strcmp(__format->colorspace, "YUV") == 0) {
213                 if (strcmp(__format->format_label, "I420") == 0
214                 || strcmp(__format->format_label, "Y42B") == 0
215                 || strcmp(__format->format_label, "Y444") == 0
216                 || strcmp(__format->format_label, "YV12") == 0
217                 || strcmp(__format->format_label, "NV12") == 0
218                 || strcmp(__format->format_label, "UYVY") == 0) {
219                         SAFE_STRCPY(_format_name, __format->format_label, sizeof(_format_name));
220                 } else if (strcmp(__format->format_label, "YUYV") == 0) {
221                         SAFE_STRCPY(_format_name, "YVYU", sizeof(_format_name));
222                 }
223                 gstcs_debug("Chosen video format: %s", _format_name);
224                 __format->caps = gst_caps_new_simple("video/x-raw",
225                         "format", G_TYPE_STRING, _format_name,
226                         "framerate", GST_TYPE_FRACTION, 25, 1,
227                         "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
228                         "width", G_TYPE_INT, __format->width,
229                         "height", G_TYPE_INT, __format->height,
230                         "framerate", GST_TYPE_FRACTION, 1, 1,
231                         NULL);
232         }
233
234         else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
235                 if (strcmp(__format->format_label, "RGB888") == 0) {
236                         _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
237                 } else if (strcmp(__format->format_label, "BGR888") == 0) {
238                         _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
239                 } else if (strcmp(__format->format_label, "RGB565") == 0) {
240                         _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
241                 } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
242                         _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
243                 }
244
245                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
246                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
247
248                 __format->caps = gst_caps_new_simple("video/x-raw",
249                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
250                         "width", G_TYPE_INT, __format->stride,
251                         "height", G_TYPE_INT, __format->elevation,
252                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
253         }
254
255         else if (strcmp(__format->colorspace, "RGBA") == 0) {
256                 if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
257                         gstcs_debug("ARGB8888");
258                         _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
259                 } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
260                         gstcs_debug("BGRA8888");
261                         _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
262                 } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
263                         gstcs_debug("RGBA8888");
264                         _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
265                 } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
266                         gstcs_debug("ABGR8888");
267                         _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
268                 } else {
269                         gstcs_error("***Wrong format cs type***\n");
270                 }
271
272                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
273                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
274
275                 __format->caps = gst_caps_new_simple("video/x-raw",
276                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
277                         "width", G_TYPE_INT, __format->width,
278                         "height", G_TYPE_INT, __format->elevation,
279                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
280         }
281
282         if (__format->caps) {
283                 gstcs_debug("###__format->caps is not NULL###, %p", __format->caps);
284                 _mm_check_caps_format(__format->caps);
285         } else {
286                 gstcs_error("__format->caps is NULL");
287         }
288 }
289
290 static void
291 _mm_set_image_output_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
292 {
293         char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
294         GstVideoFormat videoFormat;
295         int _bpp = 0; int _depth = 0; int _red_mask = 0; int _green_mask = 0; int _blue_mask = 0; int _alpha_mask = 0; int _endianness = 0;
296
297         if (__format == NULL) {
298                 gstcs_error("Image format is NULL\n");
299                 return;
300         }
301
302         gstcs_debug("colorspace: %s(%d), w: %d, h: %d\n", __format->colorspace, strlen(__format->colorspace), __format->width, __format->height);
303         memset(_format_name, 0, sizeof(_format_name));
304
305         if (strcmp(__format->colorspace, "YUV") == 0) {
306                 if (strcmp(__format->format_label, "I420") == 0
307                 || strcmp(__format->format_label, "Y42B") == 0
308                 || strcmp(__format->format_label, "Y444") == 0
309                 || strcmp(__format->format_label, "YV12") == 0
310                 || strcmp(__format->format_label, "NV12") == 0
311                 || strcmp(__format->format_label, "UYVY") == 0) {
312                         SAFE_STRCPY(_format_name, __format->format_label, sizeof(_format_name));
313                 } else if (strcmp(__format->format_label, "YUYV") == 0) {
314                         SAFE_STRCPY(_format_name, "YVYU", sizeof(_format_name));
315                 }
316                 gstcs_debug("Chosen video format: %s", _format_name);
317                 __format->caps = gst_caps_new_simple("video/x-raw",
318                         "format", G_TYPE_STRING, _format_name,
319                         "width", G_TYPE_INT, __format->width,
320                         "height", G_TYPE_INT, __format->height,
321                         "framerate", GST_TYPE_FRACTION, 1, 1,
322                         NULL);
323         }
324
325         else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
326                 if (strcmp(__format->format_label, "RGB888") == 0) {
327                         _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
328                 } else if (strcmp(__format->format_label, "BGR888") == 0) {
329                         _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
330                 } else if (strcmp(__format->format_label, "RGB565") == 0) {
331                         _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
332                 } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
333                         _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
334                 }
335
336                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
337                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
338
339                 __format->caps = gst_caps_new_simple("video/x-raw",
340                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
341                         "width", G_TYPE_INT, __format->width,
342                         "height", G_TYPE_INT, __format->height,
343                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
344         }
345
346         else if (strcmp(__format->colorspace, "RGBA") == 0) {
347                 if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
348                         gstcs_debug("ARGB8888");
349                         _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
350                 } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
351                         gstcs_debug("BGRA8888");
352                         _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
353                 } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
354                         gstcs_debug("RGBA8888");
355                         _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
356                 } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
357                         gstcs_debug("ABGR8888");
358                         _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
359                 } else {
360                         gstcs_error("***Wrong format cs type***\n");
361                 }
362
363                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
364                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
365
366                 __format->caps = gst_caps_new_simple("video/x-raw",
367                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
368                         "width", G_TYPE_INT, __format->width,
369                         "height", G_TYPE_INT, __format->height,
370                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
371         }
372
373         if (__format->caps) {
374                 gstcs_debug("###__format->caps is not NULL###, %p", __format->caps);
375                 _mm_check_caps_format(__format->caps);
376         } else {
377                 gstcs_error("__format->caps is NULL");
378         }
379 }
380
381 static void
382 _mm_set_image_colorspace(image_format_s* __format)
383 {
384         gstcs_debug("format_label: %s\n", __format->format_label);
385
386         __format->colorspace = (char*)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
387         if (__format->colorspace == NULL) {
388                 gstcs_error("memory allocation failed");
389                 return;
390         }
391         memset(__format->colorspace, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
392         if ((strcmp(__format->format_label, "I420") == 0) || (strcmp(__format->format_label, "Y42B") == 0) || (strcmp(__format->format_label, "Y444") == 0)
393                 || (strcmp(__format->format_label, "YV12") == 0) || (strcmp(__format->format_label, "NV12") == 0) || (strcmp(__format->format_label, "UYVY") == 0) || (strcmp(__format->format_label, "YUYV") == 0)) {
394                 SAFE_STRCPY(__format->colorspace, "YUV", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
395         } else if ((strcmp(__format->format_label, "RGB888") == 0) || (strcmp(__format->format_label, "BGR888") == 0) || (strcmp(__format->format_label, "RGB565") == 0)) {
396                 SAFE_STRCPY(__format->colorspace, "RGB", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
397         } else if ((strcmp(__format->format_label, "ARGB8888") == 0) || (strcmp(__format->format_label, "BGRA8888") == 0) || (strcmp(__format->format_label, "RGBA8888") == 0)  || (strcmp(__format->format_label, "ABGR8888") == 0)) {
398                 SAFE_STRCPY(__format->colorspace, "RGBA", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
399         } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
400                 SAFE_STRCPY(__format->colorspace, "BGRX", IMAGE_FORMAT_LABEL_BUFFER_SIZE);
401         } else {
402                 gstcs_error("Check your colorspace format label");
403                 GSTCS_FREE(__format->colorspace);
404         }
405 }
406
407 static int _gstcs_create_image_format(image_format_s **format)
408 {
409         int ret = GSTCS_ERROR_NONE;
410         image_format_s *_format = NULL;
411
412         if (format == NULL) {
413                 gstcs_error("format is wrong value");
414                 return GSTCS_ERROR_INVALID_OPERATION;
415         }
416
417         _format = (image_format_s*)malloc(sizeof(image_format_s));
418         if (_format == NULL) {
419                 gstcs_error("memory allocation failed");
420                 return GSTCS_ERROR_OUT_OF_MEMORY;
421         }
422         memset(_format, 0, sizeof(image_format_s));
423         *format = _format;
424
425         return ret;
426 }
427
428 static void _gstcs_destroy_image_format(image_format_s *format)
429 {
430         if (format != NULL) {
431                 gst_caps_unref(format->caps);
432                 GSTCS_FREE(format->format_label);
433                 GSTCS_FREE(format->colorspace);
434                 GSTCS_FREE(format);
435         }
436 }
437
438 static void
439 _mm_round_up_input_image_widh_height(image_format_s* pFormat)
440 {
441         if (strcmp(pFormat->colorspace, "YUV") == 0) {
442                 pFormat->stride = MM_UTIL_ROUND_UP_8(pFormat->width);
443                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
444         } else if (strcmp(pFormat->colorspace, "RGB") == 0) {
445                 pFormat->stride = MM_UTIL_ROUND_UP_4(pFormat->width);
446                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
447         } else if ((strcmp(pFormat->colorspace, "RGBA") == 0) || (strcmp(pFormat->colorspace, "BGRX") == 0)) {
448                 pFormat->stride = pFormat->width;
449                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
450         }
451         gstcs_debug("input_format stride: %d, elevation: %d", pFormat->stride, pFormat->elevation);
452 }
453
454 static image_format_s*
455 _mm_set_input_image_format_s_struct(imgp_info_s* pImgp_info) /* char* __format_label, int __width, int __height) */
456 {
457         int ret = GSTCS_ERROR_NONE;
458         image_format_s* __format = NULL;
459
460         ret = _gstcs_create_image_format(&__format);
461         if (ret != GSTCS_ERROR_NONE) {
462                 gstcs_debug("Error: _gstcs_create_image_format is failed (%d)\n", ret);
463                 return NULL;
464         }
465
466         __format->format_label = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
467         if (__format->format_label == NULL) {
468                 gstcs_error("memory allocation failed");
469                 _gstcs_destroy_image_format(__format);
470                 return NULL;
471         }
472         memset(__format->format_label, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
473         SAFE_STRCPY(__format->format_label, pImgp_info->input_format_label, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
474         gstcs_debug("input_format_label: %s\n", pImgp_info->input_format_label);
475         _mm_set_image_colorspace(__format);
476
477         __format->width = pImgp_info->src_width;
478         __format->height = pImgp_info->src_height;
479         _mm_round_up_input_image_widh_height(__format);
480
481         _mm_set_image_input_format_s_capabilities(__format);
482
483         return __format;
484 }
485
486 static void
487 _mm_round_up_output_image_widh_height(image_format_s* pFormat, const image_format_s *input_format)
488 {
489         if (strcmp(pFormat->colorspace, "YUV") == 0) {
490                 pFormat->stride = MM_UTIL_ROUND_UP_8(pFormat->width);
491                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
492         } else if (strcmp(pFormat->colorspace, "RGB") == 0) {
493                 pFormat->stride = MM_UTIL_ROUND_UP_4(pFormat->width);
494                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
495                 pFormat->width = pFormat->stride;
496                 if (input_format->height != input_format->elevation)
497                         pFormat->height = pFormat->elevation;
498         } else if ((strcmp(pFormat->colorspace, "RGBA") == 0) || (strcmp(pFormat->colorspace, "BGRX") == 0)) {
499                 pFormat->stride = pFormat->width;
500                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
501                 if (input_format->height != input_format->elevation)
502                         pFormat->height = pFormat->elevation;
503         }
504         gstcs_debug("output_format stride: %d, elevation: %d", pFormat->stride, pFormat->elevation);
505 }
506
507 static image_format_s*
508 _mm_set_output_image_format_s_struct(imgp_info_s* pImgp_info, const image_format_s *input_format)
509 {
510         int ret = GSTCS_ERROR_NONE;
511         image_format_s* __format = NULL;
512
513         ret = _gstcs_create_image_format(&__format);
514         if (ret != GSTCS_ERROR_NONE) {
515                 gstcs_debug("Error: _gstcs_create_image_format is failed (%d)\n", ret);
516                 return NULL;
517         }
518
519         __format->format_label = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
520         if (__format->format_label == NULL) {
521                 gstcs_error("memory allocation failed");
522                 _gstcs_destroy_image_format(__format);
523                 return NULL;
524         }
525         memset(__format->format_label, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
526         SAFE_STRCPY(__format->format_label, pImgp_info->output_format_label, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
527         _mm_set_image_colorspace(__format);
528
529         __format->width = pImgp_info->dst_width;
530         __format->height = pImgp_info->dst_height;
531         _mm_round_up_output_image_widh_height(__format, input_format);
532
533         pImgp_info->output_stride = __format->stride;
534         pImgp_info->output_elevation = __format->elevation;
535
536         gstcs_debug("output_format_label: %s", pImgp_info->output_format_label);
537         _mm_set_image_output_format_s_capabilities(__format);
538         return __format;
539 }
540
541 static int
542 _mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
543 {
544         int ret = GSTCS_ERROR_NONE;
545
546         if (pGstreamer_s->pipeline == NULL) {
547                 gstcs_error("pipeline is NULL\n");
548                 return GSTCS_ERROR_INVALID_PARAMETER;
549         }
550
551         gsize data_size = mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
552         GstBuffer* gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
553
554         if (gst_buf == NULL) {
555                 gstcs_error("buffer is NULL\n");
556                 return GSTCS_ERROR_INVALID_PARAMETER;
557         }
558
559         gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
560         return ret;
561 }
562
563 static int
564 _mm_push_buffer_into_pipeline_new(image_format_s *input_format, unsigned char *src, gstreamer_s * pGstreamer_s)
565 {
566         int ret = GSTCS_ERROR_NONE;
567         GstBuffer *gst_buf = NULL;
568         unsigned int src_size = 0;
569         unsigned char *data = NULL;
570         unsigned int stride = input_format->stride;
571         unsigned int elevation = input_format->elevation;
572
573         if (pGstreamer_s->pipeline == NULL) {
574                 gstcs_error("pipeline is NULL\n");
575                 return GSTCS_ERROR_INVALID_PARAMETER;
576         }
577
578         gstcs_debug("stride: %d, elevation: %d", stride, elevation);
579         src_size = mm_setup_image_size(input_format->format_label, stride, elevation);
580         gstcs_debug("buffer size (src): %d", src_size);
581
582         int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->format_label);
583         unsigned int src_row = input_format->width * byte_per_pixcel;
584         unsigned int stride_row = stride * byte_per_pixcel;
585         unsigned int i = 0, y = 0;
586         gstcs_debug("padding will be inserted to buffer");
587         data = (unsigned char *) malloc(src_size);
588         if (data == NULL) {
589                 gstcs_error("app_buffer is NULL\n");
590                 return GSTCS_ERROR_INVALID_PARAMETER;
591         }
592         for (y = 0; y < (unsigned int)(input_format->height); y++) {
593                 guint8 *pLine = (guint8 *) &(src[src_row * y]);
594                 for (i = 0; i < src_row; i++)
595                         data[y * stride_row + i] = pLine[i];
596                 guint8 stride_row_color = pLine[i - 1];
597                 for (i = src_row; i < stride_row; i++)
598                         data[y * stride_row + i] = stride_row_color;
599         }
600         for (y = (unsigned int)(input_format->height); y < (unsigned int)(input_format->elevation); y++) {
601                 for (i = 0; i < stride_row; i++)
602                         data[y * stride_row + i] = data[(y - 1) * stride_row + i];
603         }
604         gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, data, src_size, 0, src_size, data, _mm_destroy_notify);
605
606         if (gst_buf == NULL) {
607                 gstcs_error("buffer is NULL\n");
608                 GSTCS_FREE(data);
609                 return GSTCS_ERROR_INVALID_PARAMETER;
610         }
611
612         gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
613         return ret;
614 }
615
616 static int
617 _mm_imgp_gstcs_processing(gstreamer_s* pGstreamer_s, unsigned char *src, unsigned char **dst, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
618 {
619         GstBus *bus = NULL;
620         GstStateChangeReturn ret_state;
621         int ret = GSTCS_ERROR_NONE;
622
623         /*create pipeline*/
624         ret = _mm_create_pipeline(pGstreamer_s);
625         if (ret != GSTCS_ERROR_NONE)
626                 gstcs_error("ERROR - mm_create_pipeline ");
627
628         /* Make appsink emit the "new-preroll" and "new-sample" signals. This option is by default disabled because signal emission is expensive and unneeded when the application prefers to operate in pull mode. */
629         gst_app_sink_set_emit_signals((GstAppSink*)pGstreamer_s->appsink, TRUE);
630
631         bus = gst_pipeline_get_bus(GST_PIPELINE(pGstreamer_s->pipeline));
632         gst_bus_add_watch(bus, (GstBusFunc) _mm_on_src_message, pGstreamer_s);
633         gst_object_unref(bus);
634
635         gst_app_src_set_caps(GST_APP_SRC(pGstreamer_s->appsrc), input_format->caps);
636         gst_app_sink_set_caps(GST_APP_SINK(pGstreamer_s->appsink), output_format->caps);
637
638         if (((input_format->width != input_format->stride) || (input_format->height != input_format->elevation)) &&
639                 ((strcmp(input_format->colorspace, "RGB") == 0) || (strcmp(input_format->colorspace, "RGBA") == 0))) {
640                 gstcs_debug("Start _mm_push_buffer_into_pipeline_new");
641                 ret = _mm_push_buffer_into_pipeline_new(input_format, src, pGstreamer_s);
642         } else {
643                 gstcs_debug("Start mm_push_buffer_into_pipeline");
644                 ret = _mm_push_buffer_into_pipeline(pImgp_info, src, pGstreamer_s);
645         }
646         if (ret != GSTCS_ERROR_NONE) {
647                 gstcs_error("ERROR - mm_push_buffer_into_pipeline ");
648                 gst_object_unref(pGstreamer_s->pipeline);
649                 return ret;
650         }
651         gstcs_debug("End mm_push_buffer_into_pipeline");
652
653         /*link pipeline*/
654         gstcs_debug("Start mm_link_pipeline");
655         _mm_link_pipeline(pGstreamer_s, pImgp_info->angle);
656         gstcs_debug("End mm_link_pipeline");
657
658         /* Conecting to the new-sample signal emited by the appsink*/
659         gstcs_debug("Start G_CALLBACK(_mm_sink_sample)");
660         g_signal_connect(pGstreamer_s->appsink, "new-sample", G_CALLBACK(_mm_sink_sample), pGstreamer_s);
661         gstcs_debug("End G_CALLBACK(_mm_sink_sample)");
662
663         /* GST_STATE_PLAYING*/
664         gstcs_debug("Start GST_STATE_PLAYING");
665         ret_state = gst_element_set_state(pGstreamer_s->pipeline, GST_STATE_PLAYING);
666         gstcs_debug("End GST_STATE_PLAYING ret_state: %d", ret_state);
667
668         /*g_main_loop_run*/
669         gstcs_debug("g_main_loop_run");
670         g_main_loop_run(pGstreamer_s->loop);
671
672         gstcs_debug("Sucess GST_STATE_CHANGE");
673
674         /*GST_STATE_NULL*/
675         gst_element_set_state(pGstreamer_s->pipeline, GST_STATE_NULL);
676         gstcs_debug("End GST_STATE_NULL");
677
678         gstcs_debug("###pGstreamer_s->output_buffer### : %p", pGstreamer_s->output_buffer);
679
680         ret_state = gst_element_get_state(pGstreamer_s->pipeline, NULL, NULL, 1*GST_SECOND);
681
682         if (ret_state == GST_STATE_CHANGE_SUCCESS)
683                 gstcs_debug("GST_STATE_NULL ret_state = %d (GST_STATE_CHANGE_SUCCESS)\n", ret_state);
684         else if (ret_state == GST_STATE_CHANGE_ASYNC)
685                 gstcs_debug("GST_STATE_NULL ret_state = %d (GST_STATE_CHANGE_ASYNC)\n", ret_state);
686
687         gstcs_debug("Success gst_element_get_state\n");
688
689         if (ret_state == GST_STATE_CHANGE_FAILURE) {
690                 gstcs_error("GST_STATE_CHANGE_FAILURE");
691         } else {
692                 if (pGstreamer_s->output_buffer != NULL) {
693                         GstMapInfo mapinfo = GST_MAP_INFO_INIT;
694                         gst_buffer_map(pGstreamer_s->output_buffer, &mapinfo, GST_MAP_READ);
695                         int buffer_size = mapinfo.size;
696                         int calc_buffer_size = 0;
697                         if (((pImgp_info->dst_width != (unsigned int)(output_format->width)) || (pImgp_info->dst_height != (unsigned int)(output_format->height))) &&
698                                 ((strcmp(input_format->colorspace, "RGB") == 0) || (strcmp(input_format->colorspace, "RGBA") == 0))) {
699                                 gstcs_debug("calculate image size with stride & elevation");
700                                 calc_buffer_size = mm_setup_image_size(pImgp_info->output_format_label, output_format->width, output_format->height);
701                         } else {
702                                 calc_buffer_size = mm_setup_image_size(pImgp_info->output_format_label, pImgp_info->dst_width, pImgp_info->dst_height);
703                         }
704                         gstcs_debug("buffer size: %d, calc: %d\n", buffer_size, calc_buffer_size);
705                         if (buffer_size != calc_buffer_size) {
706                                 gstcs_debug("Buffer size is different \n");
707                                 gstcs_debug("unref output buffer");
708                                 gst_buffer_unref(pGstreamer_s->output_buffer);
709                                 gst_object_unref(pGstreamer_s->pipeline);
710                                 pGstreamer_s->output_buffer = NULL;
711                                 return GSTCS_ERROR_INVALID_OPERATION;
712                         }
713                         gstcs_debug("pGstreamer_s->output_buffer: %p\n", pGstreamer_s->output_buffer);
714                         *dst = calloc(1, buffer_size);
715                         if (*dst == NULL) {
716                                 gstcs_error("ERROR - calloc ");
717                                 gst_buffer_unref(pGstreamer_s->output_buffer);
718                                 gst_object_unref(pGstreamer_s->pipeline);
719                                 pGstreamer_s->output_buffer = NULL;
720                                 return GSTCS_ERROR_INVALID_OPERATION;
721                         }
722
723                         memcpy(*dst, mapinfo.data, buffer_size);
724                         pImgp_info->buffer_size = buffer_size;
725                         gst_buffer_unmap(pGstreamer_s->output_buffer, &mapinfo);
726                 } else {
727                         gstcs_debug("pGstreamer_s->output_buffer is NULL");
728                 }
729         }
730         gstcs_debug("unref output buffer");
731         gst_buffer_unref(pGstreamer_s->output_buffer);
732         gst_object_unref(pGstreamer_s->pipeline);
733         pGstreamer_s->output_buffer = NULL;
734
735         gstcs_debug("End gstreamer processing");
736         gstcs_debug("dst: %p", *dst);
737         return ret;
738 }
739
740
741 static int
742 mm_setup_image_size(const char* _format_label, int width, int height)
743 {
744         int size = 0;
745
746         if (strcmp(_format_label, "I420") == 0)
747                 size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) + MM_UTIL_ROUND_UP_8(width) * MM_UTIL_ROUND_UP_2(height) /2); /*width * height *1.5; */
748         else if (strcmp(_format_label, "Y42B") == 0)
749                 size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
750         else if (strcmp(_format_label, "YUV422") == 0)
751                 size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
752         else if (strcmp(_format_label, "Y444") == 0)
753                 size = (MM_UTIL_ROUND_UP_4(width) * height * 3); /* width * height *3; */
754         else if (strcmp(_format_label, "YV12") == 0)
755                 size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) + MM_UTIL_ROUND_UP_8(width) * MM_UTIL_ROUND_UP_2(height) / 2); /* width * height *1; */
756         else if (strcmp(_format_label, "NV12") == 0)
757                 size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) * 1.5); /* width * height *1.5; */
758         else if (strcmp(_format_label, "RGB565") == 0)
759                 size = (MM_UTIL_ROUND_UP_4(width) * 2 * height); /* width * height *2; */
760         else if (strcmp(_format_label, "RGB888") == 0)
761                 size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
762         else if (strcmp(_format_label, "BGR888") == 0)
763                 size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
764         else if (strcmp(_format_label, "UYVY") == 0)
765                 size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
766         else if (strcmp(_format_label, "YUYV") == 0)
767                 size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
768         else if (strcmp(_format_label, "ARGB8888") == 0)
769                 size = width * height *4;
770         else if (strcmp(_format_label, "BGRA8888") == 0)
771                 size = width * height *4;
772         else if (strcmp(_format_label, "RGBA8888") == 0)
773                 size = width * height *4;
774         else if (strcmp(_format_label, "ABGR8888") == 0)
775                 size = width * height *4;
776         else if (strcmp(_format_label, "BGRX") == 0)
777                 size = width * height *4;
778
779         gstcs_debug("file_size: %d\n", size);
780
781         return size;
782 }
783
784 static int _gstcs_create_default_thread(gstreamer_s *gstreamer)
785 {
786         if (gstreamer == NULL) {
787                 gstcs_error("ERROR - gstreamer is null ");
788                 return GSTCS_ERROR_INVALID_OPERATION;
789         }
790
791         gstreamer->context = g_main_context_new();
792         if (gstreamer->context == NULL) {
793                 gstcs_error("ERROR - g_main_context_new ");
794                 return GSTCS_ERROR_INVALID_OPERATION;
795         }
796         gstreamer->loop = g_main_loop_new(gstreamer->context, FALSE);
797         if (gstreamer->loop == NULL) {
798                 gstcs_error("ERROR - g_main_loop_new ");
799                 g_main_context_unref(gstreamer->context);
800                 return GSTCS_ERROR_INVALID_OPERATION;
801         }
802
803         g_main_context_push_thread_default(gstreamer->context);
804         return GSTCS_ERROR_NONE;
805 }
806
807 static int _gstcs_destroy_default_thread(gstreamer_s *gstreamer)
808 {
809         if (gstreamer == NULL) {
810                 gstcs_error("ERROR - gstreamer is null ");
811                 return GSTCS_ERROR_INVALID_OPERATION;
812         }
813
814         if (gstreamer->loop != NULL)
815                 g_main_loop_unref(gstreamer->loop);
816
817         if (gstreamer->context != NULL)
818                 g_main_context_unref(gstreamer->context);
819
820         return GSTCS_ERROR_NONE;
821 }
822
823 static int _gstcs_init(gstreamer_s** gstreamer)
824 {
825         static const int max_argc = 50;
826         gint argc = 0;
827         gchar** argv = NULL;
828         int i = 0;
829         int ret = GSTCS_ERROR_NONE;
830
831         argv = malloc(sizeof(gchar*) * max_argc);
832
833         if (!argv) {
834                 gstcs_error("argv is not allocated");
835                 return GSTCS_ERROR_OUT_OF_MEMORY;
836         }
837         memset(argv, 0, sizeof(gchar*) * max_argc);
838
839         argv[argc] = g_strdup("mmutil_gstcs");
840         if (argv[argc] == NULL) {
841                 gstcs_error("argv[%d] is not allocated", argc);
842                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
843         }
844         argc++;
845         /* check disable registry scan */
846         argv[argc] = g_strdup("--gst-disable-registry-update");
847         if (argv[argc] == NULL) {
848                 gstcs_error("argv[%d] is not allocated", argc);
849                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
850         }
851         argc++;
852         if (ret != GSTCS_ERROR_NONE) {
853                 for (i = 0; i < argc; i++)
854                         GSTCS_FREE(argv[i]);
855
856                 GSTCS_FREE(argv);
857                 return ret;
858         }
859
860         gst_init(&argc, &argv);
861
862         *gstreamer = g_new0(gstreamer_s, 1);
863         if (*gstreamer == NULL) {
864                 gstcs_error("gstreamer structure is not allocated");
865                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
866         }
867
868         for (i = 0; i < argc; i++)
869                 GSTCS_FREE(argv[i]);
870
871         GSTCS_FREE(argv);
872         return ret;
873 }
874
875 static int _mm_imgp_gstcs(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst)
876 {
877         image_format_s* input_format = NULL, *output_format = NULL;
878         gstreamer_s* pGstreamer_s;
879         int ret = GSTCS_ERROR_NONE;
880
881         /* Print debug message for inout structure */
882         gstcs_debug("[input] format label : %s width: %d height: %d\t[output] format label: %s width: %d height: %d rotation vaule: %d",
883         pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height, pImgp_info->output_format_label, pImgp_info->dst_width, pImgp_info->dst_height, pImgp_info->angle);
884
885         /* Initialize gstreamer */
886         ret = _gstcs_init(&pGstreamer_s);
887         if (ret != GSTCS_ERROR_NONE) {
888                 gstcs_error("Error: _gstcs_new is failed");
889                 return ret;
890         }
891
892         /* Create input/output format for gstreamer processing */
893         input_format = _mm_set_input_image_format_s_struct(pImgp_info);
894         if (input_format == NULL) {
895                 gstcs_error("Error: memory allocation failed");
896                 GSTCS_FREE(pGstreamer_s);
897                 return GSTCS_ERROR_OUT_OF_MEMORY;
898         }
899
900         output_format = _mm_set_output_image_format_s_struct(pImgp_info, input_format);
901         if (output_format == NULL) {
902                 gstcs_error("Error: memory allocation failed");
903                 _gstcs_destroy_image_format(input_format);
904                 GSTCS_FREE(pGstreamer_s);
905                 return GSTCS_ERROR_OUT_OF_MEMORY;
906         }
907
908         /* Create default thread for async behavior */
909         ret = _gstcs_create_default_thread(pGstreamer_s);
910         if (ret != GSTCS_ERROR_NONE) {
911                 gstcs_error("Error: _gstcs_create_default_thread is failed");
912                 _gstcs_destroy_image_format(input_format);
913                 _gstcs_destroy_image_format(output_format);
914                 GSTCS_FREE(pGstreamer_s);
915                 return ret;
916         }
917
918         /* Do gstreamer processing */
919         gstcs_debug("Start _mm_imgp_gstcs_processing ");
920         ret = _mm_imgp_gstcs_processing(pGstreamer_s, src, dst, input_format, output_format, pImgp_info); /* input: buffer pointer for input image , input image format, input image width, input image height, output: buffer porinter for output image */
921
922         if (ret == GSTCS_ERROR_NONE)
923                 gstcs_debug("End _mm_imgp_gstcs_processing [dst: %p]", *dst);
924         else if (ret != GSTCS_ERROR_NONE)
925                 gstcs_error("ERROR - _mm_imgp_gstcs_processing");
926
927         /* Free resouces */
928         ret = _gstcs_destroy_default_thread(pGstreamer_s);
929         if (ret != GSTCS_ERROR_NONE)
930                 gstcs_error("Error: _gstcs_create_default_thread is failed");
931
932         _gstcs_destroy_image_format(input_format);
933         _gstcs_destroy_image_format(output_format);
934         GSTCS_FREE(pGstreamer_s);
935
936         return ret;
937 }
938
939 int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char **dst, imgp_type_e _imgp_type)
940 {
941         if (pImgp_info == NULL) {
942                 gstcs_error("Error: input vaule is NULL");
943                 return GSTCS_ERROR_INVALID_PARAMETER;
944         }
945
946         if (src == NULL || dst == NULL) {
947                 gstcs_error("Error: src | dst is NULL");
948                 return GSTCS_ERROR_INVALID_PARAMETER;
949         }
950
951         if (_imgp_type < 0 || _imgp_type > IMGP_MAX) {
952                 gstcs_error("Error: imgp_type is wrong");
953                 return GSTCS_ERROR_INVALID_PARAMETER;
954         }
955
956         gstcs_debug("[src %p] [dst %p]", src, dst);
957
958         return _mm_imgp_gstcs(pImgp_info, src, dst);
959 }