Merge "Fix memory leak for the image_util_frame_h by using image_util_frame_create...
[platform/core/api/image-util.git] / test / image_util_test.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <glib.h>
18 #include <glib/gprintf.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <image_util.h>
23 #include <image_util_type.h>
24
25 #define MAX_STRING_LEN 128
26 #define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
27 #define IMAGE_TEST_MAX_REPEAT_COUNT 100
28
29 #define IMAGE_UTIL_SAFE_FREE(src)      { if (src) {free(src); src = NULL; } }
30
31
32 GMainLoop *g_loop = NULL;
33 transformation_h g_handle = NULL;
34 media_packet_h g_src = NULL;
35 char *g_path = NULL;
36 unsigned int g_width = 0;
37 unsigned int g_height = 0;
38 int g_format = -1;
39
40 GCond g_thread_cond;
41 GMutex g_thread_mutex;
42
43 enum {
44         CURRENT_STATE_MAIN_MENU,
45         CURRENT_STATE_SET_IMAGE_MENU,
46 };
47
48 enum {
49         CURRENT_STATE_SET_IMAGE_NONE,
50         CURRENT_STATE_SET_IMAGE_PATH,
51         CURRENT_STATE_SET_IMAGE_WIDTH,
52         CURRENT_STATE_SET_IMAGE_HEIGHT,
53         CURRENT_STATE_SET_IMAGE_FORMAT,
54 };
55
56 int g_menu_state = CURRENT_STATE_MAIN_MENU;
57 int g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
58
59 void _wait()
60 {
61         g_mutex_lock(&g_thread_mutex);
62         g_printf("waiting... untill finishing transform \n");
63         g_cond_wait(&g_thread_cond, &g_thread_mutex);
64         g_printf("<=== get signal from callback \n");
65         g_mutex_unlock(&g_thread_mutex);
66 }
67
68 void _signal()
69 {
70         g_mutex_lock(&g_thread_mutex);
71         g_cond_signal(&g_thread_cond);
72         g_printf("===> send signal to test proc \n");
73         g_mutex_unlock(&g_thread_mutex);
74 }
75
76 media_format_mimetype_e
77 _image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace)
78 {
79         media_format_mimetype_e mimetype = -1;
80
81         switch (colorspace) {
82         case IMAGE_UTIL_COLORSPACE_NV12:
83                 mimetype = MEDIA_FORMAT_NV12;
84                 break;
85         case IMAGE_UTIL_COLORSPACE_NV16:
86                 mimetype = MEDIA_FORMAT_NV16;
87                 break;
88         case IMAGE_UTIL_COLORSPACE_YUYV:
89                 mimetype = MEDIA_FORMAT_YUYV;
90                 break;
91         case IMAGE_UTIL_COLORSPACE_UYVY:
92                 mimetype = MEDIA_FORMAT_UYVY;
93                 break;
94         case IMAGE_UTIL_COLORSPACE_YUV422:
95                 mimetype = MEDIA_FORMAT_422P;
96                 break;
97         case IMAGE_UTIL_COLORSPACE_I420:
98                 mimetype = MEDIA_FORMAT_I420;
99                 break;
100         case IMAGE_UTIL_COLORSPACE_NV21:
101                 mimetype = MEDIA_FORMAT_YV12;
102                 break;
103         case IMAGE_UTIL_COLORSPACE_RGB565:
104                 mimetype = MEDIA_FORMAT_RGB565;
105                 break;
106         case IMAGE_UTIL_COLORSPACE_RGB888:
107                 mimetype = MEDIA_FORMAT_RGB888;
108                 break;
109         case IMAGE_UTIL_COLORSPACE_RGBA8888:
110                 mimetype = MEDIA_FORMAT_RGBA;
111                 break;
112         case IMAGE_UTIL_COLORSPACE_ARGB8888:
113                 mimetype = MEDIA_FORMAT_ARGB;
114                 break;
115         case IMAGE_UTIL_COLORSPACE_BGRA8888:
116         case IMAGE_UTIL_COLORSPACE_BGRX8888:
117         case IMAGE_UTIL_COLORSPACE_NV61:
118         default:
119                 mimetype = -1;
120                 g_printf("Not Supported Format");
121                 break;
122         }
123
124         g_printf("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype);
125         return mimetype;
126 }
127
128 bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e error, void *user_data)
129 {
130         uint64_t size = 0;
131         char output_file[25] = {};
132
133         media_format_h dst_fmt;
134         media_format_mimetype_e dst_mimetype;
135         int dst_width, dst_height, dst_avg_bps, dst_max_bps;
136         char *output_fmt = NULL;
137
138         g_printf("test_transform_completed_cb============= [%d] \n", error);
139         if (error == IMAGE_UTIL_ERROR_NONE) {
140                 g_printf("<<<<< SUCCESS >>>>>");
141                 output_fmt = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
142                 if (output_fmt) {
143                         if (media_packet_get_format(*packet, &dst_fmt) != MEDIA_PACKET_ERROR_NONE) {
144                                 g_printf("Imedia_packet_get_format");
145                                 _signal();
146                                 return FALSE;
147                         }
148
149                         if (media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
150                                 memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
151                                 if (dst_mimetype  == MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P || dst_mimetype == MEDIA_FORMAT_I420
152                                     || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY || dst_mimetype == MEDIA_FORMAT_YUYV) {
153                                         strncpy(output_fmt, "yuv", strlen("yuv"));
154                                 } else {
155                                         strncpy(output_fmt, "rgb", strlen("rgb"));
156                                 }
157                                 g_printf("[mimetype: %d] W x H : %d x %d \n", dst_mimetype, dst_width, dst_height);
158                                 snprintf(output_file, 25, "result_%dx%d.%s", dst_width, dst_height, output_fmt);
159                         }
160                 }
161
162                 FILE *fpout = fopen(output_file, "w");
163                 if (fpout) {
164                         media_packet_get_buffer_size(*packet, &size);
165                         void *dst = NULL;
166                         if (media_packet_get_buffer_data_ptr(*packet, &dst) != MEDIA_PACKET_ERROR_NONE) {
167                                 IMAGE_UTIL_SAFE_FREE(dst);
168                                 IMAGE_UTIL_SAFE_FREE(output_fmt);
169                                 fclose(fpout);
170                                 g_printf("[dst] media_packet_get_extra \n");
171                                 _signal();
172                                 return FALSE;
173                         }
174                         //g_printf("dst: %p [%llu] \n", dst, size);
175                         fwrite(dst, 1, size, fpout);
176                         g_printf("FREE \n");
177                         fclose(fpout);
178                 }
179
180                 g_printf("write result \n");
181                 g_printf("Free (output_fmt) \n");
182                 IMAGE_UTIL_SAFE_FREE(output_fmt);
183         } else {
184                 g_printf("<<<<< ERROR >>>>> complete cb");
185                 _signal();
186                 return FALSE;
187         }
188
189         media_packet_destroy(*packet);
190
191         _signal();
192
193         return TRUE;
194 }
195
196 static int
197 create_media_packet()
198 {
199         int ret = 0;
200         media_format_h fmt;
201         void *src;
202         void *ptr;
203         if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
204                 if (media_format_set_video_mime(fmt, _image_util_mapping_imgp_format_to_mime(g_format)) != MEDIA_FORMAT_ERROR_NONE) {
205                         media_format_unref(fmt);
206                         g_printf("[Error] Set - video mime\n");
207                         return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
208                 }
209
210                 if (media_format_set_video_width(fmt, g_width) != MEDIA_FORMAT_ERROR_NONE) {
211                         media_format_unref(fmt);
212                         g_printf("[Error] Set - video width\n");
213                         return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
214                 }
215
216                 if (media_format_set_video_height(fmt, g_height) != MEDIA_FORMAT_ERROR_NONE) {
217                         media_format_unref(fmt);
218                         g_printf("[Error] Set - video heigh\nt");
219                         return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
220                 }
221
222                 if (media_format_set_video_avg_bps(fmt, 2000000) != MEDIA_FORMAT_ERROR_NONE) {
223                         media_format_unref(fmt);
224                         g_printf("[Error] Set - video avg bps\n");
225                         return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
226                 }
227
228                 if (media_format_set_video_max_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
229                         media_format_unref(fmt);
230                         g_printf("[Error] Set - video max bps\n");
231                         return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
232                 }
233
234                 g_printf("media_format_set_video_info success! file:%s, w:%d, h:%d, %d\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format));
235         } else {
236                 g_printf("media_format_create failed...");
237         }
238
239         ret = media_packet_create_alloc(fmt, NULL, NULL, &g_src);
240         if (ret == MEDIA_PACKET_ERROR_NONE) {
241                 g_printf("Success - media_packet_create_alloc\n");
242                 uint64_t size = 0;
243                 if (media_packet_get_buffer_size(g_src, &size) == MEDIA_PACKET_ERROR_NONE) {
244                         ptr = malloc(size);
245                         if (ptr == NULL) {
246                                 g_printf("\tmemory allocation failed\n");
247                                 return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
248                         }
249                         if (media_packet_get_buffer_data_ptr(g_src, &ptr) == MEDIA_PACKET_ERROR_NONE) {
250                                 FILE *fp = fopen(g_path, "r");
251                                 if (fp == NULL) {
252                                         g_printf("\tfile open failed %d\n", errno);
253                                         return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
254                                 }
255                                 src = malloc(size);
256                                 if (src == NULL) {
257                                         g_printf("\tmemory allocation failed\n");
258                                         fclose(fp);
259                                         return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
260                                 }
261                                 if (fread(src, 1, (int)size, fp) == size) {
262                                         g_printf("#Success# fread\n");
263                                         memcpy(ptr, src, (int)size);
264                                         g_printf("memcpy\n");
265                                 } else {
266                                         g_printf("#Error# fread\n");
267                                 }
268                                 fclose(fp);
269                         }
270                 }
271         } else {
272                 media_format_unref(fmt);
273                 g_printf("ERROR - media_packet_create_alloc");
274                 return ret;
275         }
276         media_format_unref(fmt);
277         return ret;
278 }
279
280 static void _create()
281 {
282         int ret = 0;
283         if (g_handle != NULL) {
284                 ret = image_util_transform_destroy(g_handle);
285                 if (ret != IMAGE_UTIL_ERROR_NONE)
286                         g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
287                 else
288                         g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
289         }
290         ret = image_util_transform_create(&g_handle);
291         if (ret != IMAGE_UTIL_ERROR_NONE)
292                 g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
293         else
294                 g_printf("[%d]Success image_util_transform_create [%d]\n", __LINE__, ret);
295 }
296
297 static void _set_image()
298 {
299         int ret = 0;
300         if (g_src) {
301                 media_packet_destroy(g_src);
302                 g_printf("[%d]Success source packet is destroyed \n", __LINE__);
303         }
304         ret = create_media_packet();
305         if (ret == MEDIA_PACKET_ERROR_NONE)
306                 g_printf("Success - Create_media_packet\n");
307         else
308                 g_printf("Error - Create_media_packet\n");
309 }
310
311 static void _destroy()
312 {
313         int ret = 0;
314
315         if (g_handle) {
316                 ret = image_util_transform_destroy(g_handle);
317                 if (ret != IMAGE_UTIL_ERROR_NONE)
318                         g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
319                 else
320                         g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
321         } else {
322                 g_printf("[%d]Error handle was already destroyed \n", __LINE__);
323         }
324         g_handle = NULL;
325 }
326
327 static void _transform(const char *cmd)
328 {
329         int ret = 0;
330         unsigned int width = 0;
331         unsigned int height = 0;
332         image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
333         image_util_rotation_e angle;
334         int start_x;
335         int start_y;
336         int end_x;
337         int end_y;
338
339         if (!strcmp("convert", cmd)) {
340                 colorspace = IMAGE_UTIL_COLORSPACE_I420;
341
342                 ret = image_util_transform_set_colorspace(g_handle, colorspace);
343                 if (ret != IMAGE_UTIL_ERROR_NONE) {
344                         g_printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret);
345                         return;
346                 }
347         }
348
349         if (!strcmp("resize", cmd)) {
350                 width = g_width/2;
351                 height = g_height/2;
352
353                 ret = image_util_transform_set_resolution(g_handle, width, height);
354                 if (ret != IMAGE_UTIL_ERROR_NONE) {
355                         g_printf("[%d]Error image_util_set resolution [%d]\n", __LINE__, ret);
356                         return;
357                 }
358         }
359
360         if (!strcmp("rotate", cmd)) {
361                 angle = 1;
362
363                 ret = image_util_transform_set_rotation(g_handle, angle);
364                 if (ret != IMAGE_UTIL_ERROR_NONE) {
365                         g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
366                         return;
367                 }
368         }
369
370         if (!strcmp("crop", cmd)) {
371                 start_x = 500;
372                 start_y = 500;
373                 end_x = 700;
374                 end_y = 700;
375
376                 ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y);
377                 if (ret != IMAGE_UTIL_ERROR_NONE) {
378                         g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret);
379                         return;
380                 }
381         }
382
383         if (!strcmp("run", cmd)) {
384                 ret = image_util_transform_run(g_handle, g_src, (image_util_transform_completed_cb)test_transform_completed_cb, NULL);
385                 if (ret != IMAGE_UTIL_ERROR_NONE) {
386                         g_printf("[%d]Error image_util_transform [%d]\n", __LINE__, ret);
387                         return;
388                 }
389                 _wait();
390         }
391
392 }
393
394 static void _loop_test(const int count)
395 {
396         int i = 0;
397         for (i = 0; i < count; i++) {
398                 _transform("run");
399                 _set_image();
400                 g_printf("<<<<< %03d >>>>>\n", i);
401         }
402 }
403
404 void quit(void)
405 {
406         if (g_loop)
407                 g_main_loop_quit(g_loop);
408 }
409
410 void reset_current_menu_state()
411 {
412         g_menu_state = CURRENT_STATE_MAIN_MENU;
413         return;
414 }
415
416 static void display_set_image_menu(void)
417 {
418         g_print("\n");
419         g_print("====================================================\n");
420         g_print("    image-util Core-API test: Main menu v0.2\n");
421         g_print("----------------------------------------------------\n");
422         g_print("1. set image path \n");
423         g_print("2. set image width \n");
424         g_print("3. set image height \n");
425         g_print("4. set image format \n");
426         g_print("0. back \n");
427         g_print("----------------------------------------------------\n");
428         g_print("====================================================\n");
429
430 }
431
432 static void display_menu(void)
433 {
434         g_print("\n");
435         g_print("====================================================\n");
436         g_print("   image-util Core-API test: Main menu v0.2\n");
437         g_print("----------------------------------------------------\n");
438         g_print("1. create handle \n");
439         g_print("2. set image \n");
440         g_print("3. set convert \n");
441         g_print("4. set crop \n");
442         g_print("5. set resize \n");
443         g_print("6. set rotate \n");
444         g_print("7. run \n");
445         g_print("8. run repeatly \n");
446         g_print("9. destroy handle \n");
447         g_print("0. quit \n");
448         g_print("----------------------------------------------------\n");
449         g_print("====================================================\n");
450
451 }
452
453 static void interpret_set_image_cmd(char *cmd)
454 {
455         int len = strlen(cmd);
456         if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_NONE) {
457                 if (len == 1) {
458                         if (!strncmp(cmd, "1", len)) {
459                                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_PATH;
460                                 g_print("Path: ");
461                         } else if (!strncmp(cmd, "2", len)) {
462                                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_WIDTH;
463                                 g_print("Width: ");
464                         } else if (!strncmp(cmd, "3", len)) {
465                                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_HEIGHT;
466                                 g_print("height: ");
467                         } else if (!strncmp(cmd, "4", len)) {
468                                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_FORMAT;
469                                 g_print("Format: ");
470                         } else if (!strncmp(cmd, "0", len)) {
471                                 _set_image();
472                                 reset_current_menu_state();
473                                 display_menu();
474                         }
475                 } else {
476                         g_print("wrong command\n");
477                         display_set_image_menu();
478                 }
479         } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_PATH) {
480                 IMAGE_UTIL_SAFE_FREE(g_path);
481                 g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
482                 memset(g_path, 0x00, MAX_STRING_LEN);
483                 snprintf(g_path, MAX_STRING_LEN, "%s", cmd);
484                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
485                 display_set_image_menu();
486         } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_WIDTH) {
487                 g_width = atoi(cmd);
488                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
489                 display_set_image_menu();
490         } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_HEIGHT) {
491                 g_height = atoi(cmd);
492                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
493                 display_set_image_menu();
494         } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_FORMAT) {
495                 g_format = atoi(cmd);
496                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
497                 display_set_image_menu();
498         }
499 }
500
501 static void interpret_cmd(char *cmd)
502 {
503         int len = strlen(cmd);
504         if (g_menu_state == CURRENT_STATE_MAIN_MENU) {
505                 if (len == 1) {
506                         if (!strncmp(cmd, "1", len)) {
507                                 _create();
508                         } else if (!strncmp(cmd, "2", len)) {
509                                 g_menu_state = CURRENT_STATE_SET_IMAGE_MENU;
510                                 g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE;
511                                 display_set_image_menu();
512                                 return;
513                         } else if (!strncmp(cmd, "3", len)) {
514                                 _transform("convert");
515                         } else if (!strncmp(cmd, "4", len)) {
516                                 _transform("crop");
517                         } else if (!strncmp(cmd, "5", len)) {
518                                 _transform("resize");
519                         } else if (!strncmp(cmd, "6", len)) {
520                                 _transform("rotate");
521                         } else if (!strncmp(cmd, "7", len)) {
522                                 _transform("run");
523                         } else if (!strncmp(cmd, "8", len)) {
524                                 _loop_test(IMAGE_TEST_MAX_REPEAT_COUNT);
525                         } else if (!strncmp(cmd, "9", len)) {
526                                 _destroy();
527                         } else if (!strncmp(cmd, "0", len)) {
528                                 quit();
529                         }
530                 } else {
531                         g_print("wrong command\n");
532                 }
533
534                 display_menu();
535         } else if (g_menu_state == CURRENT_STATE_SET_IMAGE_MENU) {
536                 interpret_set_image_cmd(cmd);
537         } else {
538                 g_print("wrong menu state\n");
539         }
540 }
541
542 gboolean input(GIOChannel *channel)
543 {
544         gchar buf[MAX_STRING_LEN];
545         gsize read;
546         GError *error = NULL;
547
548         g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
549
550         buf[read] = '\0';
551         g_strstrip(buf);
552         interpret_cmd(buf);
553
554         return TRUE;
555 }
556
557 int main(int argc, char **argv)
558 {
559         int ret = IMAGE_UTIL_ERROR_NONE;
560
561         GIOChannel *stdin_channel = NULL;
562         stdin_channel = g_io_channel_unix_new(0);
563         g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
564         g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
565
566         if (argc < 4) {
567                 g_printf("Usage: image_utl_test filename width height format \n");
568                 return ret;
569         }
570
571         g_handle = NULL;
572         g_src = NULL;
573         g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *));
574         memset(g_path, 0x00, MAX_STRING_LEN);
575         snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]);
576         g_width = atoi(argv[2]);
577         g_height = atoi(argv[3]);
578         g_format = atoi(argv[4]);
579
580         g_mutex_init(&g_thread_mutex);
581         g_cond_init(&g_thread_cond);
582
583         ret = image_util_transform_create(&g_handle);
584         if (ret != IMAGE_UTIL_ERROR_NONE) {
585                 g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
586                 goto Exit;
587         }
588
589         ret = create_media_packet();
590         if (ret == MEDIA_PACKET_ERROR_NONE) {
591                 g_printf("Success - Create_media_packet\n");
592         } else {
593                 g_printf("Error - Create_media_packet\n");
594                 goto Exit;
595         }
596
597         ret = image_util_transform_set_hardware_acceleration(g_handle, FALSE);
598         if (ret != IMAGE_UTIL_ERROR_NONE) {
599                 g_printf("[%d]Error image_util_transform_set_hardware_acceleration condition [%d]\n", __LINE__, ret);
600                 goto Exit;
601         }
602
603         display_menu();
604
605         g_loop = g_main_loop_new(NULL, FALSE);
606
607         g_main_loop_run(g_loop);
608         g_main_loop_unref(g_loop);
609
610 Exit:
611         g_mutex_clear(&g_thread_mutex);
612         g_cond_clear(&g_thread_cond);
613         if (g_path) {
614                 IMAGE_UTIL_SAFE_FREE(g_path);
615                 g_printf("[%d]Success file path is destroyed \n", __LINE__);
616         } else {
617                 g_printf("[%d]Error file path was already destroyed \n", __LINE__);
618         }
619         if (g_src) {
620                 media_packet_destroy(g_src);
621                 g_printf("[%d]Success source packet is destroyed \n", __LINE__);
622         } else {
623                 g_printf("[%d]Error source packet was already destroyed \n", __LINE__);
624         }
625         _destroy();
626
627         return 0;
628 }