Modify stride color to make new stride buffer.
[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
31 static GstFlowReturn
32 _mm_sink_sample(GstElement * appsink, gpointer user_data)
33 {
34         GstBuffer *_buf = NULL;
35         GstSample *_sample = NULL;
36         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
37         _sample = gst_app_sink_pull_sample((GstAppSink*)appsink);
38         if (_sample) {
39                 _buf = gst_sample_get_buffer(_sample);
40
41                 pGstreamer_s->output_buffer = _buf;
42
43                 if (pGstreamer_s->output_buffer != NULL) {
44                         GstMapInfo mapinfo = GST_MAP_INFO_INIT;
45                         gst_buffer_map(pGstreamer_s->output_buffer, &mapinfo, GST_MAP_READ);
46                         gstcs_debug("Create Output Buffer: GST_BUFFER_DATA: %p\t GST_BUFFER_SIZE: %d", mapinfo.data, mapinfo.size);
47                         gst_buffer_unmap(pGstreamer_s->output_buffer, &mapinfo);
48                 } else {
49                         gstcs_error("ERROR -Input Prepare Buffer! Check createoutput buffer function");
50                 }
51         }
52
53         gst_buffer_ref(pGstreamer_s->output_buffer); /* when you want to avoid flushing */
54         gst_sample_unref(_sample);
55
56         return GST_FLOW_OK;
57 }
58
59 static gboolean
60 _mm_on_src_message(GstBus * bus, GstMessage * message, gpointer user_data)
61 {
62         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
63         switch (GST_MESSAGE_TYPE(message)) {
64         case GST_MESSAGE_EOS: {
65                 gstcs_debug("The source got dry");
66                 gst_app_src_end_of_stream(GST_APP_SRC(pGstreamer_s->appsrc));
67                 g_main_context_pop_thread_default(pGstreamer_s->context);
68                 g_main_loop_quit(pGstreamer_s->loop);
69                 break;
70                 }
71         case GST_MESSAGE_ERROR: {
72                 GError *err = NULL;
73                 gchar *dbg_info = NULL;
74
75                 gst_message_parse_error(message, &err, &dbg_info);
76                 gstcs_error("ERROR from element %s: %s\n", GST_OBJECT_NAME(message->src), err->message);
77                 gstcs_error("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
78                 g_error_free(err);
79                 g_free(dbg_info);
80                 g_main_context_pop_thread_default(pGstreamer_s->context);
81                 g_main_loop_quit(pGstreamer_s->loop);
82                 gstcs_debug("Quit GST_CS\n");
83                 break;
84                 }
85         default:
86                 break;
87         }
88         return TRUE;
89 }
90
91 static int
92 _mm_get_byte_per_pixcel(const char *__format_label)
93 {
94         int byte_per_pixcel = 1;
95         if (strcmp(__format_label, "RGB565") == 0) {
96                 byte_per_pixcel = 2;
97         } else if (strcmp(__format_label, "RGB888") == 0 ||
98                 strcmp(__format_label, "BGR888") == 0) {
99                 byte_per_pixcel = 3;
100         } else if (strcmp(__format_label, "RGBA8888") == 0 ||
101                 strcmp(__format_label, "ARGB8888") == 0 ||
102                 strcmp(__format_label, "BGRA8888") == 0 ||
103                 strcmp(__format_label, "ABGR8888") == 0 ||
104                 strcmp(__format_label, "RGBX") == 0 ||
105                 strcmp(__format_label, "XRGB") == 0 ||
106                 strcmp(__format_label, "BGRX") == 0 ||
107                 strcmp(__format_label, "XBGR") == 0) {
108                 byte_per_pixcel = 4;
109         }
110
111         gstcs_debug("byte per pixcel : %d", byte_per_pixcel);
112
113         return byte_per_pixcel;
114 }
115
116 static int _mm_create_pipeline(gstreamer_s* pGstreamer_s)
117 {
118         int ret = GSTCS_ERROR_NONE;
119         pGstreamer_s->pipeline = gst_pipeline_new("pipeline");
120         if (!pGstreamer_s->pipeline) {
121                 gstcs_error("pipeline could not be created. Exiting.\n");
122                 ret = GSTCS_ERROR_INVALID_PARAMETER;
123         }
124         pGstreamer_s->appsrc = gst_element_factory_make("appsrc" , "appsrc");
125         if (!pGstreamer_s->appsrc) {
126                 gstcs_error("appsrc could not be created. Exiting.\n");
127                 ret = GSTCS_ERROR_INVALID_PARAMETER;
128         }
129         pGstreamer_s->colorspace = gst_element_factory_make("videoconvert" , "convert");
130         if (!pGstreamer_s->colorspace) {
131                 gstcs_error("colorspace could not be created. Exiting.\n");
132                 ret = GSTCS_ERROR_INVALID_PARAMETER;
133         }
134         pGstreamer_s->videoscale = gst_element_factory_make("videoscale", "scale");
135         if (!pGstreamer_s->videoscale) {
136                 gstcs_error("videoscale could not be created. Exiting.\n");
137                 ret = GSTCS_ERROR_INVALID_PARAMETER;
138         }
139         pGstreamer_s->videoflip = gst_element_factory_make("videoflip", "flip");
140         if (!pGstreamer_s->videoflip) {
141                 gstcs_error("videoflip could not be created. Exiting.\n");
142                 ret = GSTCS_ERROR_INVALID_PARAMETER;
143         }
144         pGstreamer_s->appsink = gst_element_factory_make("appsink" , "appsink");
145         if (!pGstreamer_s->appsink) {
146                 gstcs_error("appsink could not be created. Exiting.\n");
147                 ret = GSTCS_ERROR_INVALID_PARAMETER;
148         }
149         return ret;
150 }
151
152 static void _mm_destroy_notify(gpointer data)
153 {
154         unsigned char *_data = (unsigned char *)data;
155         if (_data != NULL) {
156                 free(_data);
157                 _data = NULL;
158         }
159 }
160
161 static void
162 _mm_check_caps_format(GstCaps* caps)
163 {
164         GstStructure *caps_structure = gst_caps_get_structure(caps, 0);
165         const gchar* formatInfo = gst_structure_get_string(caps_structure, "format");
166         gstcs_debug("[%d] caps: %s", GST_IS_CAPS(caps), formatInfo);
167 }
168
169 static void
170 _mm_link_pipeline(gstreamer_s* pGstreamer_s, image_format_s* input_format, image_format_s* output_format, int value)
171 {
172         /* set property */
173         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);
174         if (!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL))
175                 gstcs_error("Fail to link pipeline");
176         else
177                 gstcs_debug("Success to link pipeline");
178
179         g_object_set(G_OBJECT(pGstreamer_s->appsrc), "stream-type", 0, "format", GST_FORMAT_TIME, NULL);
180         g_object_set(pGstreamer_s->appsrc, "num-buffers", 1, NULL);
181         g_object_set(pGstreamer_s->appsrc, "is-live", TRUE, NULL); /* add because of gstreamer_s time issue */
182
183         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 */
184
185         /*g_object_set(pGstreamer_s->appsink, "drop", TRUE, NULL);*/
186         g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
187 }
188
189 static void
190 _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
191 {
192         char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
193         GstVideoFormat videoFormat;
194         int _bpp = 0;
195         int _depth = 0;
196         int _red_mask = 0;
197         int _green_mask = 0;
198         int _blue_mask = 0;
199         int _alpha_mask = 0;
200         int _endianness = 0;
201
202         if (__format == NULL) {
203                 gstcs_error("Image format is NULL\n");
204                 return;
205         }
206
207         gstcs_debug("colorspace: %s(%d)\n", __format->colorspace, strlen(__format->colorspace));
208         memset(_format_name, 0, sizeof(_format_name));
209
210         if (strcmp(__format->colorspace, "YUV") == 0) {
211                 if (strcmp(__format->format_label, "I420") == 0
212                 || strcmp(__format->format_label, "Y42B") == 0
213                 || strcmp(__format->format_label, "Y444") == 0
214                 || strcmp(__format->format_label, "YV12") == 0
215                 || strcmp(__format->format_label, "NV12") == 0
216                 || strcmp(__format->format_label, "UYVY") == 0) {
217                         strncpy(_format_name, __format->format_label, sizeof(GST_VIDEO_FORMATS_ALL)-1);
218                 } else if (strcmp(__format->format_label, "YUYV") == 0) {
219                         strncpy(_format_name, "YVYU", sizeof(GST_VIDEO_FORMATS_ALL)-1);
220                 }
221                 gstcs_debug("Chosen video format: %s", _format_name);
222                 __format->caps = gst_caps_new_simple("video/x-raw",
223                         "format", G_TYPE_STRING, _format_name,
224                         "framerate", GST_TYPE_FRACTION, 25, 1,
225                         "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
226                         "width", G_TYPE_INT, __format->width,
227                         "height", G_TYPE_INT, __format->height,
228                         "framerate", GST_TYPE_FRACTION, 1, 1,
229                         NULL);
230         }
231
232         else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
233                 if (strcmp(__format->format_label, "RGB888") == 0) {
234                         _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
235                 } else if (strcmp(__format->format_label, "BGR888") == 0) {
236                         _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
237                 } else if (strcmp(__format->format_label, "RGB565") == 0) {
238                         _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
239                 } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
240                         _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
241                 }
242
243                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
244                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
245
246                 __format->caps = gst_caps_new_simple("video/x-raw",
247                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
248                         "width", G_TYPE_INT, __format->stride,
249                         "height", G_TYPE_INT, __format->elevation,
250                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
251         }
252
253         else if (strcmp(__format->colorspace, "RGBA") == 0) {
254                 if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
255                         gstcs_debug("ARGB8888");
256                         _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
257                 } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
258                         gstcs_debug("BGRA8888");
259                         _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
260                 } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
261                         gstcs_debug("RGBA8888");
262                         _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
263                 } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
264                         gstcs_debug("ABGR8888");
265                         _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
266                 } else {
267                         gstcs_error("***Wrong format cs type***\n");
268                 }
269
270                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
271                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
272
273                 __format->caps = gst_caps_new_simple("video/x-raw",
274                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
275                         "width", G_TYPE_INT, __format->width,
276                         "height", G_TYPE_INT, __format->elevation,
277                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
278         }
279
280         if (__format->caps) {
281                 gstcs_debug("###__format->caps is not NULL###, %p", __format->caps);
282                 _mm_check_caps_format(__format->caps);
283         } else {
284                 gstcs_error("__format->caps is NULL");
285         }
286 }
287
288 static void
289 _mm_set_image_output_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
290 {
291         char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
292         GstVideoFormat videoFormat;
293         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;
294
295         if (__format == NULL) {
296                 gstcs_error("Image format is NULL\n");
297                 return;
298         }
299
300         gstcs_debug("colorspace: %s(%d), w: %d, h: %d\n", __format->colorspace, strlen(__format->colorspace), __format->width, __format->height);
301         memset(_format_name, 0, sizeof(_format_name));
302
303         if (strcmp(__format->colorspace, "YUV") == 0) {
304                 if (strcmp(__format->format_label, "I420") == 0
305                 || strcmp(__format->format_label, "Y42B") == 0
306                 || strcmp(__format->format_label, "Y444") == 0
307                 || strcmp(__format->format_label, "YV12") == 0
308                 || strcmp(__format->format_label, "NV12") == 0
309                 || strcmp(__format->format_label, "UYVY") == 0) {
310                         strncpy(_format_name, __format->format_label, sizeof(GST_VIDEO_FORMATS_ALL)-1);
311                 } else if (strcmp(__format->format_label, "YUYV") == 0) {
312                         strncpy(_format_name, "YVYU", sizeof(GST_VIDEO_FORMATS_ALL)-1);
313                 }
314                 gstcs_debug("Chosen video format: %s", _format_name);
315                 __format->caps = gst_caps_new_simple("video/x-raw",
316                         "format", G_TYPE_STRING, _format_name,
317                         "width", G_TYPE_INT, __format->width,
318                         "height", G_TYPE_INT, __format->height,
319                         "framerate", GST_TYPE_FRACTION, 1, 1,
320                         NULL);
321         }
322
323         else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
324                 if (strcmp(__format->format_label, "RGB888") == 0) {
325                         _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
326                 } else if (strcmp(__format->format_label, "BGR888") == 0) {
327                         _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
328                 } else if (strcmp(__format->format_label, "RGB565") == 0) {
329                         _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
330                 } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
331                         _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
332                 }
333
334                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
335                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
336
337                 __format->caps = gst_caps_new_simple("video/x-raw",
338                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
339                         "width", G_TYPE_INT, __format->width,
340                         "height", G_TYPE_INT, __format->height,
341                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
342         }
343
344         else if (strcmp(__format->colorspace, "RGBA") == 0) {
345                 if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
346                         gstcs_debug("ARGB8888");
347                         _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
348                 } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
349                         gstcs_debug("BGRA8888");
350                         _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
351                 } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
352                         gstcs_debug("RGBA8888");
353                         _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
354                 } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
355                         gstcs_debug("ABGR8888");
356                         _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
357                 } else {
358                         gstcs_error("***Wrong format cs type***\n");
359                 }
360
361                 videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
362                 gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
363
364                 __format->caps = gst_caps_new_simple("video/x-raw",
365                         "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
366                         "width", G_TYPE_INT, __format->width,
367                         "height", G_TYPE_INT, __format->height,
368                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
369         }
370
371         if (__format->caps) {
372                 gstcs_debug("###__format->caps is not NULL###, %p", __format->caps);
373                 _mm_check_caps_format(__format->caps);
374         } else {
375                 gstcs_error("__format->caps is NULL");
376         }
377 }
378
379 static void
380 _mm_set_image_colorspace(image_format_s* __format)
381 {
382         gstcs_debug("format_label: %s\n", __format->format_label);
383
384         __format->colorspace = (char*)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
385         if (__format->colorspace == NULL) {
386                 gstcs_error("memory allocation failed");
387                 return;
388         }
389         memset(__format->colorspace, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
390         if ((strcmp(__format->format_label, "I420") == 0) || (strcmp(__format->format_label, "Y42B") == 0) || (strcmp(__format->format_label, "Y444") == 0)
391                 || (strcmp(__format->format_label, "YV12") == 0) || (strcmp(__format->format_label, "NV12") == 0) || (strcmp(__format->format_label, "UYVY") == 0) || (strcmp(__format->format_label, "YUYV") == 0)) {
392                 strncpy(__format->colorspace, "YUV", IMAGE_FORMAT_LABEL_BUFFER_SIZE-1);
393         } else if ((strcmp(__format->format_label, "RGB888") == 0) || (strcmp(__format->format_label, "BGR888") == 0) || (strcmp(__format->format_label, "RGB565") == 0)) {
394                 strncpy(__format->colorspace, "RGB", IMAGE_FORMAT_LABEL_BUFFER_SIZE-1);
395         } 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)) {
396                 strncpy(__format->colorspace, "RGBA", IMAGE_FORMAT_LABEL_BUFFER_SIZE-1);
397         } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
398                 strncpy(__format->colorspace, "BGRX", IMAGE_FORMAT_LABEL_BUFFER_SIZE-1);
399         } else {
400                 gstcs_error("Check your colorspace format label");
401                 GSTCS_FREE(__format->colorspace);
402         }
403 }
404
405 static int _gstcs_create_image_format(image_format_s **format)
406 {
407         int ret = GSTCS_ERROR_NONE;
408         image_format_s *_format = NULL;
409
410         if (format == NULL) {
411                 gstcs_error("format is wrong value");
412                 return GSTCS_ERROR_INVALID_OPERATION;
413         }
414
415         _format = (image_format_s*)malloc(sizeof(image_format_s));
416         if (_format == NULL) {
417                 gstcs_error("memory allocation failed");
418                 return GSTCS_ERROR_OUT_OF_MEMORY;
419         }
420         memset(_format, 0, sizeof(image_format_s));
421         *format = _format;
422
423         return ret;
424 }
425
426 static void _gstcs_destroy_image_format(image_format_s *format)
427 {
428         if (format != NULL) {
429                 gst_caps_unref(format->caps);
430                 GSTCS_FREE(format->format_label);
431                 GSTCS_FREE(format->colorspace);
432                 GSTCS_FREE(format);
433         }
434 }
435
436 static void
437 _mm_round_up_input_image_widh_height(image_format_s* pFormat)
438 {
439         if (strcmp(pFormat->colorspace, "YUV") == 0) {
440                 pFormat->stride = MM_UTIL_ROUND_UP_8(pFormat->width);
441                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
442         } else if (strcmp(pFormat->colorspace, "RGB") == 0) {
443                 pFormat->stride = MM_UTIL_ROUND_UP_4(pFormat->width);
444                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
445         } else if (strcmp(pFormat->colorspace, "RGBA") == 0) {
446                 pFormat->stride = pFormat->width;
447                 pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
448         }
449         gstcs_debug("input_format stride: %d, elevation: %d", pFormat->stride, pFormat->elevation);
450 }
451
452 static image_format_s*
453 _mm_set_input_image_format_s_struct(imgp_info_s* pImgp_info) /* char* __format_label, int __width, int __height) */
454 {
455         int ret = GSTCS_ERROR_NONE;
456         image_format_s* __format = NULL;
457
458         ret = _gstcs_create_image_format(&__format);
459         if (ret != GSTCS_ERROR_NONE) {
460                 gstcs_debug("Error: _gstcs_create_image_format is failed (%d)\n", ret);
461                 return NULL;
462         }
463
464         __format->format_label = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
465         if (__format->format_label == NULL) {
466                 gstcs_error("memory allocation failed");
467                 _gstcs_destroy_image_format(__format);
468                 return NULL;
469         }
470         memset(__format->format_label, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
471         strncpy(__format->format_label, pImgp_info->input_format_label, strlen(pImgp_info->input_format_label));
472         gstcs_debug("input_format_label: %s\n", pImgp_info->input_format_label);
473         _mm_set_image_colorspace(__format);
474
475         __format->width = pImgp_info->src_width;
476         __format->height = pImgp_info->src_height;
477         _mm_round_up_input_image_widh_height(__format);
478
479         __format->blocksize = mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
480         gstcs_debug("blocksize: %d\n", __format->blocksize);
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) {
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         strncpy(__format->format_label, pImgp_info->output_format_label, strlen(pImgp_info->output_format_label));
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         __format->blocksize = mm_setup_image_size(pImgp_info->output_format_label, pImgp_info->dst_width, pImgp_info->dst_height);
537         gstcs_debug("output_format_label: %s", pImgp_info->output_format_label);
538         _mm_set_image_output_format_s_capabilities(__format);
539         return __format;
540 }
541
542 static int
543 _mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, unsigned char *src, gstreamer_s * pGstreamer_s)
544 {
545         int ret = GSTCS_ERROR_NONE;
546
547         if (pGstreamer_s->pipeline == NULL) {
548                 gstcs_error("pipeline is NULL\n");
549                 return GSTCS_ERROR_INVALID_PARAMETER;
550         }
551
552         gsize data_size = mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
553         GstBuffer* gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
554
555         if (gst_buf == NULL) {
556                 gstcs_error("buffer is NULL\n");
557                 return GSTCS_ERROR_INVALID_PARAMETER;
558         }
559
560         gst_app_src_push_buffer(GST_APP_SRC(pGstreamer_s->appsrc), gst_buf); /* push buffer to pipeline */
561         return ret;
562 }
563
564 static int
565 _mm_push_buffer_into_pipeline_new(image_format_s *input_format, image_format_s *output_format, unsigned char *src, gstreamer_s * pGstreamer_s)
566 {
567         int ret = GSTCS_ERROR_NONE;
568         GstBuffer *gst_buf = NULL;
569         unsigned int src_size = 0;
570         unsigned char *data = NULL;
571         unsigned int stride = input_format->stride;
572         unsigned int elevation = input_format->elevation;
573
574         if (pGstreamer_s->pipeline == NULL) {
575                 gstcs_error("pipeline is NULL\n");
576                 return GSTCS_ERROR_INVALID_PARAMETER;
577         }
578
579         gstcs_debug("stride: %d, elevation: %d", stride, elevation);
580         src_size = mm_setup_image_size(input_format->format_label, stride, elevation);
581         gstcs_debug("buffer size (src): %d", src_size);
582
583         int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->format_label);
584         unsigned int src_row = input_format->width * byte_per_pixcel;
585         unsigned int stride_row = stride * byte_per_pixcel;
586         unsigned int i = 0, y = 0;
587         gstcs_debug("padding will be inserted to buffer");
588         data = (unsigned char *) malloc(src_size);
589         if (data == NULL) {
590                 gstcs_error("app_buffer is NULL\n");
591                 return GSTCS_ERROR_INVALID_PARAMETER;
592         }
593         for (y = 0; y < (unsigned int)(input_format->height); y++) {
594                 guint8 *pLine = (guint8 *) &(src[src_row * y]);
595                 for (i = 0; i < src_row; i++)
596                         data[y * stride_row + i] = pLine[i];
597                 guint8 stride_row_color = pLine[i - 1];
598                 for (i = src_row; i < stride_row; i++)
599                         data[y * stride_row + i] = stride_row_color;
600         }
601         for (y = (unsigned int)(input_format->height); y < (unsigned int)(input_format->elevation); y++) {
602                 for (i = 0; i < stride_row; i++)
603                         data[y * stride_row + i] = data[(y - 1) * stride_row + i];
604         }
605         gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, data, src_size, 0, src_size, data, _mm_destroy_notify);
606
607         if (gst_buf == NULL) {
608                 gstcs_error("buffer is NULL\n");
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, output_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, input_format, output_format, 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: 0x%2x\n", pGstreamer_s->output_buffer);
714                         memcpy(dst, mapinfo.data, buffer_size);
715                         pImgp_info->buffer_size = buffer_size;
716                         gst_buffer_unmap(pGstreamer_s->output_buffer, &mapinfo);
717                 } else {
718                         gstcs_debug("pGstreamer_s->output_buffer is NULL");
719                 }
720         }
721         gstcs_debug("unref output buffer");
722         gst_buffer_unref(pGstreamer_s->output_buffer);
723         gst_object_unref(pGstreamer_s->pipeline);
724         pGstreamer_s->output_buffer = NULL;
725
726         gstcs_debug("End gstreamer processing");
727         gstcs_debug("dst: %p", dst);
728         return ret;
729 }
730
731
732 static int
733 mm_setup_image_size(const char* _format_label, int width, int height)
734 {
735         int size = 0;
736
737         if (strcmp(_format_label, "I420") == 0) {
738                 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; */
739         } else if (strcmp(_format_label, "Y42B") == 0) {
740                 size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
741         } else if (strcmp(_format_label, "YUV422") == 0) {
742                 size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
743         } else if (strcmp(_format_label, "Y444") == 0) {
744                 size = (MM_UTIL_ROUND_UP_4(width) * height * 3); /* width * height *3; */
745         } else if (strcmp(_format_label, "YV12") == 0) {
746                 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; */
747         } else if (strcmp(_format_label, "NV12") == 0) {
748                 size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) * 1.5); /* width * height *1.5; */
749         } else if (strcmp(_format_label, "RGB565") == 0) {
750                 size = (MM_UTIL_ROUND_UP_4(width) * 2 * height); /* width * height *2; */
751         } else if (strcmp(_format_label, "RGB888") == 0) {
752                 size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
753         } else if (strcmp(_format_label, "BGR888") == 0) {
754                 size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
755         } else if (strcmp(_format_label, "UYVY") == 0) {
756                 size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
757         } else if (strcmp(_format_label, "YUYV") == 0) {
758                 size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
759         } else if (strcmp(_format_label, "ARGB8888") == 0) {
760                 size = width * height *4;
761         } else if (strcmp(_format_label, "BGRA8888") == 0) {
762                 size = width * height *4;
763         } else if (strcmp(_format_label, "RGBA8888") == 0) {
764                 size = width * height *4;
765         } else if (strcmp(_format_label, "ABGR8888") == 0) {
766                 size = width * height *4;
767         } else if (strcmp(_format_label, "BGRX") == 0) {
768                 size = width * height *4;
769         }
770
771         gstcs_debug("file_size: %d\n", size);
772
773         return size;
774 }
775
776 static int _gstcs_create_default_thread(gstreamer_s *gstreamer)
777 {
778         if (gstreamer == NULL) {
779                 gstcs_error("ERROR - gstreamer is null ");
780                 return GSTCS_ERROR_INVALID_OPERATION;
781         }
782
783         gstreamer->context = g_main_context_new();
784         if (gstreamer->context == NULL) {
785                 gstcs_error("ERROR - g_main_context_new ");
786                 return GSTCS_ERROR_INVALID_OPERATION;
787         }
788         gstreamer->loop = g_main_loop_new(gstreamer->context, FALSE);
789         if (gstreamer->loop == NULL) {
790                 gstcs_error("ERROR - g_main_loop_new ");
791                 g_main_context_unref(gstreamer->context);
792                 return GSTCS_ERROR_INVALID_OPERATION;
793         }
794
795         g_main_context_push_thread_default(gstreamer->context);
796         return GSTCS_ERROR_NONE;
797 }
798
799 static int _gstcs_destroy_default_thread(gstreamer_s *gstreamer)
800 {
801         if (gstreamer == NULL) {
802                 gstcs_error("ERROR - gstreamer is null ");
803                 return GSTCS_ERROR_INVALID_OPERATION;
804         }
805
806         if (gstreamer->loop != NULL)
807                 g_main_loop_unref(gstreamer->loop);
808
809         if (gstreamer->context != NULL)
810                 g_main_context_unref(gstreamer->context);
811
812         return GSTCS_ERROR_NONE;
813 }
814
815 static int _gstcs_init(gstreamer_s** gstreamer)
816 {
817         static const int max_argc = 50;
818         gint argc = 0;
819         gchar** argv = NULL;
820         int i = 0;
821         int ret = GSTCS_ERROR_NONE;
822
823         argv = malloc(sizeof(gchar*) * max_argc);
824
825         if (!argv) {
826                 gstcs_error("argv is not allocated");
827                 return GSTCS_ERROR_OUT_OF_MEMORY;
828         }
829         memset(argv, 0, sizeof(gchar*) * max_argc);
830
831         argv[argc] = g_strdup("mmutil_gstcs");
832         if (argv[argc] == NULL) {
833                 gstcs_error("argv[%d] is not allocated", argc);
834                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
835         }
836         argc++;
837         /* check disable registry scan */
838         argv[argc] = g_strdup("--gst-disable-registry-update");
839         if (argv[argc] == NULL) {
840                 gstcs_error("argv[%d] is not allocated", argc);
841                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
842         }
843         argc++;
844         if (ret != GSTCS_ERROR_NONE) {
845                 for (i = 0; i < argc; i++)
846                         GSTCS_FREE(argv[i]);
847
848                 GSTCS_FREE(argv);
849                 return ret;
850         }
851
852         gst_init(&argc, &argv);
853
854         *gstreamer = g_new0(gstreamer_s, 1);
855         if (*gstreamer == NULL) {
856                 gstcs_error("gstreamer structure is not allocated");
857                 ret = GSTCS_ERROR_OUT_OF_MEMORY;
858         }
859
860         for (i = 0; i < argc; i++)
861                 GSTCS_FREE(argv[i]);
862
863         GSTCS_FREE(argv);
864         return ret;
865 }
866
867 static int _mm_imgp_gstcs(imgp_info_s* pImgp_info, unsigned char *src, unsigned char *dst)
868 {
869         image_format_s* input_format = NULL, *output_format = NULL;
870         gstreamer_s* pGstreamer_s;
871         int ret = GSTCS_ERROR_NONE;
872
873         /* Print debug message for inout structure */
874         gstcs_debug("[input] format label : %s width: %d height: %d\t[output] format label: %s width: %d height: %d rotation vaule: %d",
875         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);
876
877         /* Initialize gstreamer */
878         ret = _gstcs_init(&pGstreamer_s);
879         if (ret != GSTCS_ERROR_NONE) {
880                 gstcs_error("Error: _gstcs_new is failed");
881                 return ret;
882         }
883
884         /* Create input/output format for gstreamer processing */
885         input_format = _mm_set_input_image_format_s_struct(pImgp_info);
886         if (input_format == NULL) {
887                 gstcs_error("Error: memory allocation failed");
888                 GSTCS_FREE(pGstreamer_s);
889                 return GSTCS_ERROR_OUT_OF_MEMORY;
890         }
891
892         output_format = _mm_set_output_image_format_s_struct(pImgp_info, input_format);
893         if (output_format == NULL) {
894                 gstcs_error("Error: memory allocation failed");
895                 _gstcs_destroy_image_format(input_format);
896                 GSTCS_FREE(pGstreamer_s);
897                 return GSTCS_ERROR_OUT_OF_MEMORY;
898         }
899
900         /* Create default thread for async behavior */
901         ret = _gstcs_create_default_thread(pGstreamer_s);
902         if (ret != GSTCS_ERROR_NONE) {
903                 gstcs_error("Error: _gstcs_create_default_thread is failed");
904                 _gstcs_destroy_image_format(input_format);
905                 _gstcs_destroy_image_format(output_format);
906                 GSTCS_FREE(pGstreamer_s);
907                 return ret;
908         }
909
910         /* Do gstreamer processing */
911         gstcs_debug("Start _mm_imgp_gstcs_processing ");
912         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 */
913
914         if (ret == GSTCS_ERROR_NONE)
915                 gstcs_debug("End _mm_imgp_gstcs_processing [dst: %p]", dst);
916         else if (ret != GSTCS_ERROR_NONE)
917                 gstcs_error("ERROR - _mm_imgp_gstcs_processing");
918
919         /* Free resouces */
920         ret = _gstcs_destroy_default_thread(pGstreamer_s);
921         if (ret != GSTCS_ERROR_NONE)
922                 gstcs_error("Error: _gstcs_create_default_thread is failed");
923
924         _gstcs_destroy_image_format(input_format);
925         _gstcs_destroy_image_format(output_format);
926         GSTCS_FREE(pGstreamer_s);
927
928         return ret;
929 }
930
931 int mm_imgp(imgp_info_s* pImgp_info, unsigned char *src, unsigned char *dst, imgp_type_e _imgp_type)
932 {
933         if (pImgp_info == NULL) {
934                 gstcs_error("Error: input vaule is NULL");
935                 return GSTCS_ERROR_INVALID_PARAMETER;
936         }
937
938         if (src == NULL || dst == NULL) {
939                 gstcs_error("Error: src | dst is NULL");
940                 return GSTCS_ERROR_INVALID_PARAMETER;
941         }
942
943         if (_imgp_type < 0 || _imgp_type > IMGP_MAX) {
944                 gstcs_error("Error: imgp_type is wrong");
945                 return GSTCS_ERROR_INVALID_PARAMETER;
946         }
947
948         gstcs_debug("[src %p] [dst %p]", src, dst);
949
950         return _mm_imgp_gstcs(pImgp_info, src, dst);
951 }