Update latest
[framework/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 <mm_debug.h>
23 #include <gst/check/gstcheck.h>
24 #include <mm_error.h>
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 setup_image_size_I420(width, height) { \
31         int size=0; \
32         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); \
33         return size; \
34 }
35
36 #define setup_image_size_Y42B(width, height)  { \
37         int size=0; \
38         size = (MM_UTIL_ROUND_UP_4 (width) * height + MM_UTIL_ROUND_UP_8 (width)  * height); \
39         return size; \
40 }
41
42 #define setup_image_size_Y444(width, height) { \
43         int size=0; \
44         size = (MM_UTIL_ROUND_UP_4 (width) * height  * 3); \
45         return size; \
46 }
47
48 #define setup_image_size_UYVY(width, height) { \
49         int size=0; \
50         size = (MM_UTIL_ROUND_UP_2 (width) * 2 * height); \
51         return size; \
52 }
53
54 #define setup_image_size_YUYV(width, height)  { \
55         int size=0; \
56         size = (MM_UTIL_ROUND_UP_2 (width) * 2 * height); \
57         return size; \
58 }
59
60 #define setup_image_size_YV12(width, height) { \
61         int size=0; \
62         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); \
63         return size; \
64 }
65
66 #define setup_image_size_NV12(width, height) { \
67         int size=0; \
68         size = (MM_UTIL_ROUND_UP_4 (width) * MM_UTIL_ROUND_UP_2 (height) *1.5); \
69         return size; \
70 }
71
72 #define setup_image_size_RGB565(width, height)  { \
73         int size=0; \
74         size = (MM_UTIL_ROUND_UP_4 (width * 2) *height); \
75         return size; \
76 }
77
78 #define setup_image_size_RGB888(width, height)  { \
79         int size=0; \
80         size = (MM_UTIL_ROUND_UP_4 (width*3) * height); \
81         return size; \
82 }
83
84 #define setup_image_size_BGR888(width, height)  { \
85         int size=0; \
86         size = (MM_UTIL_ROUND_UP_4 (width*3) * height); \
87         return size; \
88 }
89 /*########################################################################################*/
90
91 static void
92 _mm_sink_buffer (GstElement * appsink, gpointer  user_data)
93 {
94         GstBuffer *_buf=NULL;
95         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
96         _buf = gst_app_sink_pull_buffer((GstAppSink*)appsink);
97
98         pGstreamer_s->output_buffer = _buf;
99
100         if(pGstreamer_s->output_buffer != NULL) {
101                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Create Output Buffer: GST_BUFFER_DATA: %p\t GST_BUFFER_SIZE: %d\n", __func__, __LINE__, GST_BUFFER_DATA(pGstreamer_s->output_buffer),  GST_BUFFER_SIZE (pGstreamer_s->output_buffer));
102         }else {
103                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] ERROR -Input Prepare Buffer!  Check createoutput buffer function", __func__, __LINE__);
104         }
105         gst_buffer_unref (_buf); //we don't need the appsink buffer anymore
106         gst_buffer_ref  (pGstreamer_s->output_buffer); //when you want to avoid flushing
107 }
108
109 static void
110 _mm_sink_preroll (GstElement * appsink, gpointer  user_data)
111 {
112         GstBuffer *_buf=NULL;
113         gstreamer_s * pGstreamer_s = (gstreamer_s*) user_data;
114         _buf = gst_app_sink_pull_preroll((GstAppSink*)appsink);
115
116         pGstreamer_s->output_buffer = _buf;
117         //pGstreamer_s->output_image_format_s->caps =  GST_BUFFER_CAPS(_buf);
118         if(pGstreamer_s->output_buffer != NULL) {
119                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Create Output Buffer: GST_BUFFER_DATA: %p\t GST_BUFFER_SIZE: %d\n", __func__, __LINE__,
120                         GST_BUFFER_DATA(pGstreamer_s->output_buffer),  GST_BUFFER_SIZE (pGstreamer_s->output_buffer));
121         }else {
122                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] ERROR -Input Prepare Buffer!  Check createoutput buffer function", __func__, __LINE__);
123         }
124
125         gst_buffer_unref (_buf); // we don't need the appsink buffer anymore
126         gst_buffer_ref  (pGstreamer_s->output_buffer); //when you want to avoid flushings
127 }
128
129 static gboolean
130 _mm_on_sink_message  (GstBus * bus, GstMessage * message, gstreamer_s * pGstreamer_s)
131 {
132         switch (GST_MESSAGE_TYPE (message)) {
133                 case GST_MESSAGE_EOS:
134                         mmf_debug(MMF_DEBUG_LOG,"Finished playback\n"); //g_main_loop_quit (pGstreamer_s->loop);
135                         break;
136                 case GST_MESSAGE_ERROR:
137                         mmf_debug(MMF_DEBUG_ERROR,"Received error\n"); //g_main_loop_quit (pGstreamer_s->loop);
138                         break;
139                 case GST_MESSAGE_STATE_CHANGED:
140                         mmf_debug(MMF_DEBUG_LOG, " [%s] %s(%d) \n", GST_MESSAGE_SRC_NAME(message), GST_MESSAGE_TYPE_NAME(message), GST_MESSAGE_TYPE(message));
141                         break;
142                 case GST_MESSAGE_STREAM_STATUS:
143                         mmf_debug(MMF_DEBUG_LOG, " [%s] %s(%d) \n", GST_MESSAGE_SRC_NAME(message),  GST_MESSAGE_TYPE_NAME(message), GST_MESSAGE_TYPE(message));
144                         break;
145                 default:
146                         mmf_debug(MMF_DEBUG_LOG, " [%s] %s(%d) \n", GST_MESSAGE_SRC_NAME(message), GST_MESSAGE_TYPE_NAME(message), GST_MESSAGE_TYPE(message));
147                         break;
148         }
149         return TRUE;
150 }
151
152
153 static int
154 _mm_create_pipeline( gstreamer_s* pGstreamer_s)
155 {
156         int ret = MM_ERROR_NONE;
157         pGstreamer_s->pipeline= gst_pipeline_new ("ffmpegcolorsapce");
158         pGstreamer_s->appsrc= gst_element_factory_make("appsrc","appsrc");
159         pGstreamer_s->colorspace=gst_element_factory_make("ffmpegcolorspace","colorconverter");
160
161         pGstreamer_s->videoscale=gst_element_factory_make("videoscale", "scale");
162         pGstreamer_s->videoflip=gst_element_factory_make( "videoflip", "flip" );
163
164         pGstreamer_s->appsink=gst_element_factory_make("appsink","appsink");
165
166         if (!pGstreamer_s->pipeline || !pGstreamer_s->appsrc||!pGstreamer_s->colorspace || !pGstreamer_s->appsink) {
167                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] One element could not be created. Exiting.\n", __func__, __LINE__);
168                 ret = MM_ERROR_IMAGE_INVALID_VALUE;
169         }
170         return ret;
171 }
172
173 static gboolean
174 _mm_check_resize_format(int src_width, int src_height, int dst_width, int dst_height)
175 {
176         gboolean _bool=FALSE;
177
178         if( (src_width != dst_width) || (src_height != dst_height) ) {
179                 _bool = TRUE;
180         }
181
182         return _bool;
183 }
184
185 static gboolean
186 _mm_check_rotate_format(int GstVideoFlipMethod)
187 {
188         gboolean _bool=FALSE;
189
190         if((GstVideoFlipMethod >= 1) && ( GstVideoFlipMethod<= 7)) {
191                 _bool = TRUE;
192         }
193
194         return _bool;
195 }
196
197 static gboolean
198 _mm_check_resize_format_label(char* __format_label)
199 {
200         gboolean _bool = FALSE;
201
202         if(strcmp(__format_label, "AYUV") == 0
203                 || strcmp(__format_label, "UYVY") == 0 ||strcmp(__format_label, "Y800") == 0 || strcmp(__format_label, "I420") == 0  || strcmp(__format_label, "YV12") == 0
204                 || strcmp(__format_label, "RGB888") == 0  || strcmp(__format_label, "RGB565") == 0 || strcmp(__format_label, "BGR888") == 0  || strcmp(__format_label, "RGBA8888") == 0
205                 || strcmp(__format_label, "ARGB8888") == 0 ||strcmp(__format_label, "BGRA8888") == 0 ||strcmp(__format_label, "ABGR8888") == 0 ||strcmp(__format_label, "RGBX") == 0
206                 ||strcmp(__format_label, "XRGB") == 0 ||strcmp(__format_label, "BGRX") == 0 ||strcmp(__format_label, "XBGR") == 0 ||strcmp(__format_label, "Y444") == 0
207                 ||strcmp(__format_label, "Y42B") == 0 ||strcmp(__format_label, "YUY2") == 0 ||strcmp(__format_label, "YUYV") == 0 ||strcmp(__format_label, "UYVY") == 0
208                 ||strcmp(__format_label, "Y41B") == 0 ||strcmp(__format_label, "Y16") == 0 ||strcmp(__format_label, "Y800") == 0 ||strcmp(__format_label, "Y8") == 0
209                 ||strcmp(__format_label, "GREY") == 0 ||strcmp(__format_label, "AY64") == 0 || strcmp(__format_label, "YUV422") == 0) {
210
211                 _bool=TRUE;
212         }
213
214         return _bool;
215 }
216
217 static gboolean
218 _mm_check_rotate_format_label(const char* __format_label)
219 {
220         gboolean _bool = FALSE;
221
222         if(strcmp(__format_label, "I420") == 0 ||strcmp(__format_label, "YV12") == 0 || strcmp(__format_label, "IYUV") == 0) {
223                 _bool=TRUE;
224         }
225
226         return _bool;
227 }
228
229 static void
230 _mm_link_pipeline_order_csc_rsz(gstreamer_s* pGstreamer_s, image_format_s*  input_format, image_format_s* output_format)
231 {
232         if(_mm_check_resize_format(input_format->width,input_format->height, output_format->width, output_format->height))      {
233                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] check_for_resize", __func__, __LINE__);
234                 gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc, pGstreamer_s->videoscale, pGstreamer_s->colorspace, pGstreamer_s->appsink,  NULL);
235                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] gst_bin_add_many", __func__, __LINE__);
236                 if(_mm_check_resize_format_label( input_format->format_label)) {
237                         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d]  input_format->format_label: %s", __func__, __LINE__,  input_format->format_label);
238                         if(!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->videoscale,  pGstreamer_s->colorspace,  pGstreamer_s->appsink, NULL)) {
239                                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Fail to link b/w ffmpeg and appsink except rot\n", __func__, __LINE__);
240                         }
241                 }else if(_mm_check_resize_format_label(output_format->format_label)) {
242                         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d]  output_format->format_label: %s", __func__, __LINE__,  output_format->format_label);
243                         if(!gst_element_link_many(pGstreamer_s->appsrc,  pGstreamer_s->colorspace, pGstreamer_s->videoscale, pGstreamer_s->appsink, NULL)) {
244                                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Fail to link b/w ffmpeg and appsink except rot\n", __func__, __LINE__);
245                         }
246                 }
247         }else {
248                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] check_for_convert", __func__, __LINE__);
249                 gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc, pGstreamer_s->colorspace, pGstreamer_s->appsink,  NULL);
250                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] gst_bin_add_many", __func__, __LINE__);
251                 if(!gst_element_link_many(pGstreamer_s->appsrc,  pGstreamer_s->colorspace, pGstreamer_s->appsink, NULL)) {
252                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Fail to link b/w ffmpeg and appsink except rsz & rot\n", __func__, __LINE__);
253                 }
254         }
255 }
256
257 static void
258 _mm_link_pipeline_order_csc_rsz_rot(gstreamer_s* pGstreamer_s, image_format_s*  input_format, image_format_s* output_format)
259 {
260         if(_mm_check_rotate_format_label(input_format->format_label)) {
261                 gst_bin_add_many(GST_BIN(pGstreamer_s->pipeline), pGstreamer_s->appsrc,  pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->colorspace, pGstreamer_s->appsink,  NULL);
262                 if(!gst_element_link_many(pGstreamer_s->appsrc, pGstreamer_s->videoscale,  pGstreamer_s->videoflip,  pGstreamer_s->colorspace,  pGstreamer_s->appsink, NULL))   {
263                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Fail to link b/w appsrc and ffmpeg in rotate\n", __func__, __LINE__);
264                 }
265         }else if(_mm_check_rotate_format_label(output_format->format_label)) {
266                 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);
267                 if(!gst_element_link_many(pGstreamer_s->appsrc,  pGstreamer_s->colorspace,  pGstreamer_s->videoscale, pGstreamer_s->videoflip, pGstreamer_s->appsink, NULL)) {
268                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d]] Fail to link b/w ffmpeg and appsink in rotate\n", __func__, __LINE__);
269                 }
270         }
271 }
272
273
274 static void
275 _mm_link_pipeline( gstreamer_s* pGstreamer_s, image_format_s* input_format, image_format_s* output_format, int _valuepGstreamer_sVideoFlipMethod)
276 {
277         /* set property */
278         gst_app_src_set_caps(GST_APP_SRC(pGstreamer_s->appsrc), input_format->caps); //g_object_set(pGstreamer_s->appsrc, "caps", input_format->caps, NULL);  //  you can use appsrc'cap property
279         g_object_set(pGstreamer_s->appsrc, "num-buffers", 1, NULL);
280         g_object_set(pGstreamer_s->appsrc, "is-live", TRUE, NULL); // add because of gstreamer_s time issue
281         g_object_set (pGstreamer_s->appsrc, "format", GST_FORMAT_TIME, NULL);
282         g_object_set(pGstreamer_s->appsrc, "stream-type", 0 /*stream*/, NULL);
283
284         g_object_set(pGstreamer_s->videoflip, "method", _valuepGstreamer_sVideoFlipMethod, 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
285
286         gst_app_sink_set_caps(GST_APP_SINK(pGstreamer_s->appsink), output_format->caps); //g_object_set(pGstreamer_s->appsink, "caps", output_format->caps, NULL);
287         g_object_set(pGstreamer_s->appsink,  "drop", TRUE, NULL);
288         g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
289
290         if(_mm_check_rotate_format(_valuepGstreamer_sVideoFlipMethod)) { // when you want to rotate image
291                 /*  because IYUV, I420, YV12 format can use vidoeflip*/
292                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d]  set_link_pipeline_order_csc_rsz_rot", __func__, __LINE__);
293                 _mm_link_pipeline_order_csc_rsz_rot(pGstreamer_s,  input_format, output_format);
294         }else {
295                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d]  set_link_pipeline_order_csc_rsz", __func__, __LINE__);
296                 _mm_link_pipeline_order_csc_rsz(pGstreamer_s, input_format,  output_format);
297         }
298         /* Conecting to the new-buffer signal emited by the appsink*/ 
299         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start  G_CALLBACK (mm_sink_buffer)", __func__, __LINE__);
300         g_signal_connect (pGstreamer_s->appsink, "new-buffer",  G_CALLBACK (_mm_sink_buffer), pGstreamer_s);
301         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End  G_CALLBACK (mm_sink_buffer)", __func__, __LINE__)
302 }
303
304
305
306 static void
307 _mm_set_image_format_s_capabilities(image_format_s* __format)//_format_label: I420 _colorsapace: YUV
308 {
309         char _a='A', _b='A', _c='A', _d='A';
310         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;
311
312         if(__format == NULL) {
313                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Image format is NULL\n", __func__, __LINE__);
314         }
315         __format->caps = NULL;
316
317         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] colorspace: %s\n", __func__, __LINE__, __format->colorspace);
318
319         if(strcmp(__format->colorspace,"YUV") == 0) {
320                 if(strcmp(__format->format_label,"I420") == 0) {
321                         _a='I'; _b='4', _c='2', _d='0';
322                 }else if(strcmp(__format->format_label,"Y42B") == 0) {
323                         _a='Y'; _b='4', _c='2', _d='B';
324                 }else if(strcmp(__format->format_label,"Y444") == 0) {
325                         _a='Y'; _b='4', _c='4', _d='4';
326                 }else if(strcmp(__format->format_label,"YV12") == 0) {
327                         _a='Y'; _b='V', _c='1', _d='2'; //GStreamer-CRITICAL **: gst_mini_object_ref: assertion `mini_object != NULL' failed
328                 }else if(strcmp(__format->format_label,"NV12") == 0) {
329                         _a='N'; _b='V', _c='1', _d='2';
330                 }else if(strcmp(__format->format_label,"UYVY") == 0) {
331                         _a='U'; _b='Y', _c='V', _d='Y';
332                 }else if(strcmp(__format->format_label,"YUYV") == 0) {
333                         _a='Y'; _b='U', _c='Y', _d='2';
334                 }
335
336                 __format->caps =  gst_caps_new_simple ("video/x-raw-yuv",
337                         "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC (_a, _b, _c, _d), //'I', '4', '2', '0'),
338                         "framerate", GST_TYPE_FRACTION, 25, 1,
339                         "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
340                         "width", G_TYPE_INT, __format->width,
341                         "height", G_TYPE_INT, __format->height,
342                         "framerate", GST_TYPE_FRACTION, 1, 1,
343                         NULL);
344         }
345
346         else if(strcmp(__format->colorspace,"RGB") ==0 || strcmp(__format->colorspace,"BGRX") ==0) {
347                 if(strcmp(__format->format_label,"RGB888") == 0) {
348                         _bpp=24; _depth=24;  _red_mask=16711680; _green_mask=65280; _blue_mask=255; _endianness=4321;
349                 }else if(strcmp(__format->format_label,"BGR888") == 0) {
350                         _bpp=24; _depth=24;  _red_mask=255; _green_mask=65280; _blue_mask=16711680; _endianness=4321;
351                 }else if(strcmp(__format->format_label,"RGB565") == 0) {
352                         _bpp=16; _depth=16;  _red_mask=63488; _green_mask=2016; _blue_mask=31; _endianness=1234;
353                 }else if( (strcmp(__format->format_label, "BGRX") == 0)) {
354                         _bpp=32; _depth=24;  _red_mask=65280; _green_mask=16711680; _blue_mask=-16777216; _endianness=4321;
355                 }
356                 __format->caps  =  gst_caps_new_simple ("video/x-raw-rgb",
357                         "bpp", G_TYPE_INT, _bpp,
358                         "depth", G_TYPE_INT, _depth,
359                         "red_mask", G_TYPE_INT, _red_mask,
360                         "green_mask", G_TYPE_INT, _green_mask,
361                         "blue_mask", G_TYPE_INT, _blue_mask,
362                         "width", G_TYPE_INT, __format->width,
363                         "height", G_TYPE_INT, __format->height,
364                         "endianness", G_TYPE_INT, _endianness,
365                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
366         }
367
368         else if(strcmp(__format->colorspace,"RGBA") ==0)
369         {
370                 if(strcmp(__format->format_label,"ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
371                         _bpp=32; _depth=32;  _red_mask=16711680; _green_mask=65280; _blue_mask=255; _alpha_mask=-16777216; _endianness=4321;
372                 }else if(strcmp(__format->format_label,"BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
373                 _bpp=32; _depth=32;  _red_mask=65280; _green_mask=16711680; _blue_mask=-16777216; _alpha_mask=255; _endianness=4321;
374                 }else if(strcmp(__format->format_label,"RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
375                         _bpp=32; _depth=32;  _red_mask=-16777216; _green_mask=16711680; _blue_mask=65280; _alpha_mask=255; _endianness=4321;
376                 }else if(strcmp(__format->format_label,"ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
377                 _bpp=32; _depth=32;  _red_mask=255; _green_mask=65280; _blue_mask=16711680; _alpha_mask=-16777216; _endianness=4321;
378                 }else {
379                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] ***Wrong format cs type***\n", __func__, __LINE__);
380                 }
381
382                 __format->caps =  gst_caps_new_simple ("video/x-raw-rgb",
383                         "bpp", G_TYPE_INT, _bpp,
384                         "depth", G_TYPE_INT, _depth,
385                         "red_mask", G_TYPE_INT, _red_mask,
386                         "green_mask", G_TYPE_INT, _green_mask,
387                         "blue_mask", G_TYPE_INT, _blue_mask,
388                         "width", G_TYPE_INT, __format->width,
389                         "height", G_TYPE_INT, __format->height,
390                         "alpha_mask", G_TYPE_INT,_alpha_mask,
391                         "endianness", G_TYPE_INT, _endianness,
392                         "framerate", GST_TYPE_FRACTION, 1, 1, NULL);
393         }
394         if(__format->caps) {
395                 mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] ###__format->caps is not  NULL###, %p", __func__, __LINE__, __format->caps);
396         }else {
397                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] __format->caps is NULL", __func__, __LINE__);
398         }
399 }
400
401 static void
402 _mm_set_image_colorspace( image_format_s* __format)
403 {
404         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] format_label: %s\n", __func__, __LINE__, __format->format_label);
405         if( (strcmp(__format->format_label, "I420") == 0) ||(strcmp(__format->format_label, "Y42B") == 0) || (strcmp(__format->format_label, "Y444") == 0)
406                 || (strcmp(__format->format_label, "YV12") == 0) ||(strcmp(__format->format_label, "NV12") == 0)  ||(strcmp(__format->format_label, "UYVY") == 0) ||(strcmp(__format->format_label, "YUYV") == 0)) {
407                 strncpy(__format->colorspace, "YUV", sizeof("__format->colorspace"));
408         }else if( (strcmp(__format->format_label, "RGB888") == 0) ||(strcmp(__format->format_label, "BGR888") == 0) ||(strcmp(__format->format_label, "RGB565") == 0)) {
409                 strncpy(__format->colorspace, "RGB",  sizeof("__format->colorspace"));
410         }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)) {
411                 strncpy(__format->colorspace, "RGBA",  sizeof("__format->colorspace"));
412         }else if( (strcmp(__format->format_label, "BGRX") == 0)) {
413                 strncpy(__format->colorspace, "BGRX",  sizeof("__format->colorspace"));
414         }else {
415                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] Check your colorspace format label", __func__, __LINE__);
416         }
417 }
418
419 static image_format_s*
420 _mm_set_input_image_format_s_struct(imgp_info_s* pImgp_info) //char* __format_label, int __width, int __height)
421 {
422         image_format_s* __format = NULL;
423
424         __format=(image_format_s*)malloc(sizeof(image_format_s));
425         strncpy(__format->format_label, pImgp_info->input_format_label, sizeof(__format->format_label));
426         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] input_format_label: %s\n", __func__, __LINE__, pImgp_info->input_format_label);
427         _mm_set_image_colorspace(__format);
428
429         __format->width=pImgp_info->src_width;
430         __format->height=pImgp_info->src_height;
431
432         __format->blocksize = mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
433         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] input_format_label: %s\n", __func__, __LINE__, pImgp_info->input_format_label);
434         _mm_set_image_format_s_capabilities(__format);
435
436         return __format;
437 }
438
439 static void
440 _mm_round_up_output_image_widh_height(char* __colorsapce, imgp_info_s* pImgp_info) //char* __colorspace, int __width, int __height)
441 {
442         if(strcmp(__colorsapce,"YUV") ==0) {
443                 pImgp_info->src_width =GST_ROUND_UP_8(pImgp_info->src_width); // because the result of image size is multiples of 8
444                 pImgp_info->src_height=GST_ROUND_UP_8(pImgp_info->src_height);
445         }else if(strcmp(__colorsapce, "RGB") ==0) {
446                 pImgp_info->src_width=GST_ROUND_UP_4(pImgp_info->src_width);
447         }
448 }
449
450 static image_format_s*
451 _mm_set_output_image_format_s_struct(imgp_info_s* pImgp_info)
452 {
453         image_format_s* __format = NULL;
454
455         __format=(image_format_s*)malloc(sizeof(image_format_s));
456         strncpy(__format->format_label, pImgp_info->output_format_label, sizeof(__format->format_label));
457         _mm_set_image_colorspace(__format);
458         _mm_round_up_output_image_widh_height(__format->colorspace, pImgp_info);
459         __format->width=pImgp_info->dst_width;
460         __format->height=pImgp_info->dst_height;
461
462         __format->blocksize = mm_setup_image_size(pImgp_info->output_format_label, pImgp_info->dst_width, pImgp_info->dst_height);
463         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] output_format_label: %s", __func__, __LINE__, pImgp_info->output_format_label);
464         _mm_set_image_format_s_capabilities(__format);
465         mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] pImgp_info->dst: %p", __func__, __LINE__, pImgp_info->dst);
466         return __format;
467 }
468
469 static gboolean
470 __mm_check_resize_format( char* _in_format_label, int _in_w, int _in_h, char* _out_format_label, int _out_w, int _out_h)
471 {
472         gboolean _bool=TRUE;
473         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] input image format: %s input image width: %d input image height: %d output image format: %s output image width: %d output image height: %d\n",
474         __func__, __LINE__,_in_format_label, _in_w,_in_h, _out_format_label, _out_w, _out_h);
475         if(_mm_check_resize_format(_in_w, _in_h, _out_w, _out_h)) {
476                 if( !( _mm_check_resize_format_label(_in_format_label) ||_mm_check_resize_format_label(_out_format_label) ) ) {
477                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] ERROR-%s | %s  Resize  Only [AYUV] [YUY2] [YVYU] [UYVY] [Y800] [I420][YV12]  format can use vidoeflip ERROR- Resize!!!#####\n", __func__, __LINE__, _in_format_label, _out_format_label);
478                         _bool = FALSE;
479                 }
480         }
481         return _bool;
482 }
483
484 static gboolean
485 __mm_check_rotate_format(int angle, const char* input_format_label, const char* output_format_label)
486 {
487         gboolean _bool=TRUE;
488         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] rotate value: %d  input_format_label: %s output_format_label: %s\n",
489         __func__, __LINE__, angle, input_format_label, output_format_label);
490         if(_mm_check_rotate_format(angle)) {
491                 if(!(_mm_check_rotate_format_label(input_format_label) || _mm_check_rotate_format_label(output_format_label))) {
492                         mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] ERROR- %s  | %s  Rotate  Only IYUV, I420, YV12 format can use vidoeflip ERROR -Rotate", __func__, __LINE__, input_format_label, output_format_label);
493                         _bool = FALSE;
494                 }
495         }
496         return _bool;
497 }
498
499 static int
500 _mm_push_buffer_into_pipeline(imgp_info_s* pImgp_info, gstreamer_s * pGstreamer_s, GstCaps*_caps)
501 {
502         int ret = MM_ERROR_NONE;
503         if(_caps==NULL) {
504                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] caps is NULL\n", __func__, __LINE__);
505                 return MM_ERROR_IMAGE_INVALID_VALUE;
506         }
507
508         if(pGstreamer_s->pipeline == NULL) {
509                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] pipeline is NULL\n", __func__, __LINE__);
510                 return MM_ERROR_IMAGE_INVALID_VALUE;
511         }
512
513         GstBuffer* gst_buf = (GstBuffer *) gst_mini_object_new (GST_TYPE_BUFFER);
514
515         if(gst_buf==NULL)       {
516                 mmf_debug(MMF_DEBUG_ERROR,"[%s][%05d] buffer is NULL\n", __func__, __LINE__);
517                 return MM_ERROR_IMAGE_INVALID_VALUE;
518         }
519         GST_BUFFER_DATA (gst_buf) = (guint8 *) pImgp_info->src;
520         GST_BUFFER_SIZE (gst_buf) = mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
521         GST_BUFFER_FLAG_SET (gst_buf, GST_BUFFER_FLAG_READONLY);
522
523         gst_buffer_set_caps (gst_buf, _caps);
524         gst_app_src_push_buffer (GST_APP_SRC (pGstreamer_s->appsrc), gst_buf); //push buffer to pipeline
525         g_free(GST_BUFFER_MALLOCDATA(gst_buf)); gst_buf = NULL; //gst_buffer_finalize(gst_buf) { buffer->free_func (buffer->malloc_data); }
526         mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] #g_free#gst_buf: 0x%2x\n", __func__, __LINE__, gst_buf);
527         return ret;
528 }
529
530
531 static int
532 _mm_imgp_gstcs_processing( gstreamer_s* pGstreamer_s, image_format_s* input_format, image_format_s* output_format, imgp_info_s* pImgp_info)
533 {
534         GstBus *bus = NULL;
535         GstStateChangeReturn ret_state;
536         int ret = MM_ERROR_NONE;
537         /*create pipeline*/
538         ret =  _mm_create_pipeline(pGstreamer_s);
539         if(ret != MM_ERROR_NONE)        {
540                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] ERROR - mm_create_pipeline ", __func__, __LINE__);
541         }
542
543
544         /*  Make appsink emit the "new-preroll" and "new-buffer" signals. This  option is by default disabled because  signal emission is expensive and unneeded when the application prefers  to operate in pull mode.   */
545          gst_app_sink_set_emit_signals ((GstAppSink*)pGstreamer_s->appsink, TRUE);
546
547         bus = gst_pipeline_get_bus (GST_PIPELINE (pGstreamer_s->pipeline)); //GST_PIPELINE (pipeline));
548         gst_bus_add_watch (bus, (GstBusFunc) _mm_on_sink_message , pGstreamer_s); // thow to  appplicaton
549         gst_object_unref(bus);
550
551         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start mm_push_buffer_into_pipeline", __func__, __LINE__);
552         ret = _mm_push_buffer_into_pipeline(pImgp_info, pGstreamer_s, input_format->caps);
553         if(ret != MM_ERROR_NONE)        {
554                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] ERROR - mm_push_buffer_into_pipeline ", __func__, __LINE__);
555         }
556         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End mm_push_buffer_into_pipeline", __func__, __LINE__);
557
558         /*link pipeline*/
559         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start mm_link_pipeline", __func__, __LINE__);
560         _mm_link_pipeline( pGstreamer_s, input_format,  output_format, pImgp_info->angle);
561         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End mm_link_pipeline", __func__, __LINE__);
562
563         /* Conecting to the new-buffer signal emited by the appsink*/ 
564         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start  G_CALLBACK (_mm_sink_preroll)", __func__, __LINE__);
565         g_signal_connect (pGstreamer_s->appsink, "new-preroll",  G_CALLBACK (_mm_sink_preroll), pGstreamer_s);
566         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End  G_CALLBACK (mm_sink_preroll)", __func__, __LINE__);
567
568         /* GST_STATE_PLAYING*/
569         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start GST_STATE_PLAYING", __func__, __LINE__);
570         ret_state = gst_element_set_state (pGstreamer_s->pipeline, GST_STATE_PLAYING);
571         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End GST_STATE_PLAYING ret_state: %d", __func__, __LINE__, ret_state);
572         ret_state = gst_element_get_state (pGstreamer_s->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
573         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Success Get GST_STATE_PLAYING ret_state: %d", __func__, __LINE__, ret_state);
574         #if 0
575         /* Conecting to the new-buffer signal emited by the appsink*/ 
576         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] Start  G_CALLBACK (mm_sink_buffer)", __func__, __LINE__);
577         g_signal_connect (pGstreamer_s->appsink, "new-buffer",  G_CALLBACK (_mm_sink_buffer), pGstreamer_s);
578         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End  G_CALLBACK (mm_sink_buffer)", __func__, __LINE__);
579         #endif
580         if(ret_state  == 1)     {
581                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] GST_STATE_PLAYING ret = %d( GST_STATE_CHANGE_SUCCESS)", __func__, __LINE__, ret_state);
582         }else if( ret_state == 2) {
583                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] GST_STATE_PLAYING ret = %d( GST_STATE_CHANGE_ASYNC)", __func__, __LINE__, ret_state);
584         }
585
586         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] Sucess GST_STATE_CHANGE", __func__, __LINE__);
587
588         /* error */
589         if (ret_state == 0)     {
590                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] GST_STATE_CHANGE_FAILURE", __func__, __LINE__); //  GST_STATE_CHANGE_SUCCESS = 1,  GST_STATE_CHANGE_ASYNC  = 2,   GST_STATE_CHANGE_NO_PREROLL= 3
591                 return MM_ERROR_IMAGE_INVALID_VALUE;
592         }else {
593                 #if 0
594                         g_main_loop_run (pGstreamer_s->loop);
595                 #endif
596                 mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] Set GST_STATE_NULL", __func__, __LINE__);
597
598                 /*GST_STATE_NULL*/
599                 gst_element_set_state (pGstreamer_s->pipeline, GST_STATE_NULL);
600                 mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] End GST_STATE_NULL", __func__, __LINE__);
601                 
602                 mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] ###pGstreamer_s->output_buffer### : %p", __func__, __LINE__, pGstreamer_s->output_buffer);
603
604                 ret_state = gst_element_get_state (pGstreamer_s->pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
605
606                 if(ret_state  == 1)     {
607                         mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] GST_STATE_NULL ret_state = %d (GST_STATE_CHANGE_SUCCESS)\n", __func__, __LINE__, ret_state);
608                 }else if( ret_state == 2) {
609                         mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] GST_STATE_NULL ret_state = %d (GST_STATE_CHANGE_ASYNC)\n", __func__, __LINE__, ret_state);
610                 }
611
612                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] Success gst_element_get_state\n", __func__, __LINE__);
613
614                 if (ret_state == 0)     {
615                         mmf_debug(MMF_DEBUG_ERROR, "GST_STATE_CHANGE_FAILURE"); //  GST_STATE_CHANGE_SUCCESS = 1,  GST_STATE_CHANGE_ASYNC  = 2,   GST_STATE_CHANGE_NO_PREROLL= 3 
616                 }else {
617                         if(pGstreamer_s->output_buffer != NULL) {
618                                 int buffer_size  = GST_BUFFER_SIZE(pGstreamer_s->output_buffer);
619                                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] buffer size: %d\n", __func__, __LINE__, buffer_size);
620                                 if( buffer_size !=  mm_setup_image_size(pImgp_info->output_format_label, pImgp_info->output_stride, pImgp_info->output_elevation)) {
621                                         mmf_debug (MMF_DEBUG_ERROR, "[%s][%05d] Buffer size is different\n", __func__, __LINE__);
622                                 }
623                                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] pGstreamer_s->output_buffer: 0x%2x\n", __func__, __LINE__, pGstreamer_s->output_buffer);
624                                 memcpy( pImgp_info->dst, (char*)GST_BUFFER_DATA(pGstreamer_s->output_buffer), buffer_size);
625                         }else {
626                                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] pGstreamer_s->output_buffer is NULL", __func__, __LINE__);
627                         }
628                 }
629                 gst_object_unref (pGstreamer_s->pipeline);
630                 g_free(GST_BUFFER_MALLOCDATA(pGstreamer_s->output_buffer));
631                 pGstreamer_s->output_buffer = NULL;
632                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] #g_free# pGstreamer_s->output_buffer: 0x%2x\n", __func__, __LINE__, pGstreamer_s->output_buffer);
633
634                 g_free (pGstreamer_s);
635                 mmf_debug (MMF_DEBUG_LOG, "[%s][%05d] pGstreamer_s: 0x%2x\n", __func__, __LINE__, pGstreamer_s);
636
637                 mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] End mm_convert_colorspace \n", __func__, __LINE__);
638         }
639         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] pImgp_info->dst: %p", __func__, __LINE__, pImgp_info->dst);
640         return ret;
641 }
642
643
644 static int
645 mm_setup_image_size(const char* _format_label, int width, int height)
646 {
647         int size=0;
648
649         if(strcmp(_format_label, "I420") == 0) {
650                 setup_image_size_I420(width, height); //width * height *1.5;
651         }else if(strcmp(_format_label, "Y42B") == 0) {
652                 setup_image_size_Y42B(width, height); //width * height *2;
653         }else if(strcmp(_format_label, "YUV422") == 0) {
654                 setup_image_size_Y42B(width, height); //width * height *2;
655         }else if(strcmp(_format_label, "Y444") == 0) {
656                 setup_image_size_Y444(width, height); //width * height *3;
657         }else if(strcmp(_format_label, "YV12") == 0) {
658                 setup_image_size_YV12(width, height); //width * height *1;
659         }else if(strcmp(_format_label, "NV12") == 0) {
660                 setup_image_size_NV12(width, height); //width * height *1.5;
661         }else if(strcmp(_format_label, "RGB565") == 0) {
662                 setup_image_size_RGB565(width, height); //width * height *2;
663         }else if(strcmp(_format_label, "RGB888") == 0) {
664                 setup_image_size_RGB888(width, height); //width * height *3;
665         }else if(strcmp(_format_label, "BGR888") == 0) {
666                 setup_image_size_BGR888(width, height); //width * height *3;
667         }else if(strcmp(_format_label, "UYVY") == 0) {
668                 setup_image_size_UYVY(width, height); //width * height *2;
669         }else if(strcmp(_format_label, "YUYV") == 0) {
670                 setup_image_size_YUYV(width, height); //width * height *2;
671         }else if(strcmp(_format_label, "ARGB8888") == 0) {
672         size = width * height *4; mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] file_size: %d\n", __func__, __LINE__, size);
673         }else if(strcmp(_format_label, "BGRA8888") == 0) {
674                 size = width * height *4; mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] file_size: %d\n", __func__, __LINE__, size);
675         }else if(strcmp(_format_label, "RGBA8888") == 0) {
676                 size = width * height *4; mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] file_size: %d\n", __func__, __LINE__, size);
677         }else if(strcmp(_format_label, "ABGR8888") == 0) {
678                 size = width * height *4; mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] file_size: %d\n", __func__, __LINE__, size);
679         }else if(strcmp(_format_label, "BGRX") == 0) {
680                 size = width * height *4; mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] file_size: %d\n", __func__, __LINE__, size);
681         }
682
683         return size;
684 }
685
686 static int
687 _mm_imgp_gstcs(imgp_info_s* pImgp_info)
688 {
689         image_format_s* input_format=NULL, *output_format=NULL;
690         gstreamer_s* pGstreamer_s;
691         int ret = MM_ERROR_NONE;
692         g_type_init();
693         if(pImgp_info == NULL) {
694                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] imgp_info_s is NULL", __func__, __LINE__);
695         }
696
697         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] [input] format label : %s width: %d height: %d\t[output] format label: %s width: %d height: %d rotation vaule: %d dst: 0x%2x", __func__, __LINE__,
698                 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, pImgp_info->dst);
699
700         pImgp_info->output_stride = pImgp_info->dst_width;
701         pImgp_info->output_elevation = pImgp_info->dst_height;
702         if(pImgp_info->dst == NULL) {
703                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] imgp_info_s->dst is NULL", __func__, __LINE__);
704         }
705         input_format= _mm_set_input_image_format_s_struct(pImgp_info);
706         output_format= _mm_set_output_image_format_s_struct(pImgp_info);
707
708         mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] mm_check_resize_format&&mm_check_rotate_format ", __func__, __LINE__);
709
710         if(__mm_check_resize_format(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height, pImgp_info->output_format_label, pImgp_info->output_stride, pImgp_info->output_elevation)
711                 && __mm_check_rotate_format(pImgp_info->angle, pImgp_info->input_format_label, pImgp_info->output_format_label) ) {
712                 #if 0 // def GST_EXT_TIME_ANALYSIS
713                         MMTA_INIT();
714                 #endif
715                 gst_init (NULL, NULL);
716
717                 pGstreamer_s = g_new0 (gstreamer_s, 1);
718
719                 #if 0 // def GST_EXT_TIME_ANALYSIS
720                          MMTA_ACUM_ITEM_BEGIN("ffmpegcolorspace", 0);
721                 #endif
722                 /* _format_label : I420, RGB888 etc*/
723                 mmf_debug(MMF_DEBUG_LOG,"[%s][%05d] Start mm_convert_colorspace ", __func__, __LINE__);
724                 ret =_mm_imgp_gstcs_processing(pGstreamer_s, 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
725
726                 if(ret == MM_ERROR_NONE) {
727                         mmf_debug(MMF_DEBUG_LOG, "[%s][%05d] End mm_convert_colorspace [pImgp_info->dst: %p]", __func__, __LINE__, pImgp_info->dst);
728                 }else if (ret != MM_ERROR_NONE) {
729                         mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] ERROR -mm_convert_colorspace", __func__, __LINE__);
730                 }
731                 #if 0 //def GST_EXT_TIME_ANALYSIS 
732                         MMTA_ACUM_ITEM_END("ffmpegcolorspace", 0);
733                         MMTA_ACUM_ITEM_SHOW_RESULT();
734                         MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_FILE);
735                         MMTA_RELEASE ();
736                 #endif
737         }else {
738                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] Error - Check your input / ouput image input_format_label: %s src_width: %d src_height: %d output_format_label: %s output_stride: %d output_elevation: %d  angle: %d ",__func__, __LINE__,
739                 pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height, pImgp_info->output_format_label, pImgp_info->output_stride, pImgp_info->output_elevation, pImgp_info->angle);
740                 return MM_ERROR_IMAGE_INVALID_VALUE;
741         }
742         if(input_format) {
743                 free(input_format); input_format = NULL;
744         }
745         if(output_format) {
746                 free(output_format); output_format  = NULL;
747         }
748         return ret;
749 }
750
751 int
752 mm_imgp(imgp_info_s* pImgp_info, imgp_type_e _imgp_type)
753 {
754         if (pImgp_info == NULL) {
755                 mmf_debug(MMF_DEBUG_ERROR, "[%s][%05d] input vaule is error", __func__, __LINE__);
756         }
757         return _mm_imgp_gstcs(pImgp_info);
758 }