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