summaryrefslogtreecommitdiff
path: root/src/mm_evas_renderer.c
blob: 983e2b7413e7f288c46d29b5127453395cef0eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib.h>

#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>
#include <dlog.h>
#include <mm_error.h>
#include <sys/syscall.h>
#include "mm_evas_renderer.h"

#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "MM_EVAS_RENDER"

#define MM_CHECK_NULL( x_var ) \
if ( ! x_var ) \
{ \
	LOGE("[%s] is NULL\n", #x_var ); \
	return MM_ERROR_INVALID_ARGUMENT; \
}

#define SET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object, x_usr_data ) \
	do \
	{ \
		if (x_evas_image_object) { \
			LOGD("object callback add"); \
			evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_DEL, _evas_del_cb, x_usr_data); \
			evas_object_event_callback_add (x_evas_image_object, EVAS_CALLBACK_RESIZE, _evas_resize_cb, x_usr_data); \
		} \
	} while(0)

#define UNSET_EVAS_OBJECT_EVENT_CALLBACK( x_evas_image_object ) \
	do \
	{ \
		if (x_evas_image_object) { \
			LOGD("object callback del"); \
			evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_DEL, _evas_del_cb); \
			evas_object_event_callback_del (x_evas_image_object, EVAS_CALLBACK_RESIZE, _evas_resize_cb); \
		} \
	} while(0)

#define SET_EVAS_EVENT_CALLBACK( x_evas, x_usr_data ) \
	do \
	{ \
		if (x_evas) { \
			LOGD("callback add... evas_callback_render_pre.. evas : %p evas_info : %p", x_evas, x_usr_data); \
			evas_event_callback_add (x_evas, EVAS_CALLBACK_RENDER_PRE, _evas_render_pre_cb, x_usr_data); \
		} \
	} while(0)

#define UNSET_EVAS_EVENT_CALLBACK( x_evas ) \
	do \
	{ \
		if (x_evas) { \
			LOGD("callback del... evas_callback_render_pre %p", x_evas); \
			evas_event_callback_del (x_evas, EVAS_CALLBACK_RENDER_PRE, _evas_render_pre_cb); \
		} \
	} while(0)

enum {
	DISP_GEO_METHOD_LETTER_BOX = 0,
	DISP_GEO_METHOD_ORIGIN_SIZE,
	DISP_GEO_METHOD_FULL_SCREEN,
	DISP_GEO_METHOD_CROPPED_FULL_SCREEN,
	DISP_GEO_METHOD_ORIGIN_SIZE_OR_LETTER_BOX,
	DISP_GEO_METHOD_NUM,
};

enum {
	DEGREE_0 = 0,
	DEGREE_90,
	DEGREE_180,
	DEGREE_270,
	DEGREE_NUM,
};

enum {
	FLIP_NONE = 0,
	FLIP_HORIZONTAL,
	FLIP_VERTICAL,
	FLIP_BOTH,
	FLIP_NUM,
};

/* internal */
#ifdef _DEBUG_INDEX
void __print_idx(mm_evas_info *evas_info);
#endif
void _free_previous_packets(mm_evas_info *evas_info);
int _flush_packets(mm_evas_info *evas_info);
int _mm_evas_renderer_create(mm_evas_info **evas_info);
int _mm_evas_renderer_destroy(mm_evas_info **evas_info);
int _mm_evas_renderer_set_info(mm_evas_info *evas_info, Evas_Object *eo);
int _mm_evas_renderer_reset(mm_evas_info *evas_info);
void _mm_evas_renderer_update_geometry(mm_evas_info *evas_info, rect_info *result);
int _mm_evas_renderer_apply_geometry(mm_evas_info *evas_info);
int _mm_evas_renderer_retrieve_all_packets(mm_evas_info *evas_info, bool keep_screen);
int _mm_evas_renderer_make_flush_buffer(mm_evas_info *evas_info);
void _mm_evas_renderer_release_flush_buffer(mm_evas_info *evas_info);
static void _mm_evas_renderer_set_callback(mm_evas_info *evas_info);
static void _mm_evas_renderer_unset_callback(mm_evas_info *evas_info);

static void _evas_resize_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
	int x, y, w, h, ret;
	x = y = w = h = 0;

	mm_evas_info *evas_info = data;
	LOGD("[ENTER]");

	if (!evas_info || !evas_info->eo) {
		return;
	}

	evas_object_geometry_get(evas_info->eo, &x, &y, &w, &h);
	if (!w || !h) {
		LOGW("evas object size (w:%d,h:%d) was not set", w, h);
	} else {
		evas_info->eo_size.x = x;
		evas_info->eo_size.y = y;
		evas_info->eo_size.w = w;
		evas_info->eo_size.h = h;
		LOGW("resize (x:%d, y:%d, w:%d, h:%d)", x, y, w, h);
		ret = _mm_evas_renderer_apply_geometry(evas_info);
		if (ret != MM_ERROR_NONE)
			LOGW("fail to apply geometry info");
	}
	LOGD("[LEAVE]");
}

static void _evas_render_pre_cb(void *data, Evas *e, void *event_info)
{
	mm_evas_info *evas_info = data;

	if (!evas_info || !evas_info->eo) {
		LOGW("there is no esink info.... esink : %p, or eo is NULL returning", evas_info);
		return;
	}

	/* flush will be executed in this callback normally, */
	/* because native_surface_set must be called in main thread */
	if (evas_info->retrieve_packet) {
		if (_flush_packets(evas_info) != MM_ERROR_NONE)
			LOGE("flushing packets are failed");
	}
}

static void _evas_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
	mm_evas_info *evas_info = data;
	LOGD("[ENTER]");
	if (!evas_info || !evas_info->eo) {
		return;
	}
	if (evas_info->eo) {
		_mm_evas_renderer_unset_callback(evas_info);
		evas_object_image_data_set(evas_info->eo, NULL);
		evas_info->eo = NULL;
	}
	LOGD("[LEAVE]");
}

void _evas_pipe_cb(void *data, void *buffer, update_info info)
{
	mm_evas_info *evas_info = data;

	LOGD("[ENTER]");

	if (!evas_info) {
		LOGW("evas_info is NULL", evas_info);
		return;
	}

	g_mutex_lock(&evas_info->mp_lock);

	if (!evas_info->eo) {
		LOGW("evas_info %p", evas_info);
		g_mutex_unlock(&evas_info->mp_lock);
		return;
	}

	LOGD("evas_info : %p, evas_info->eo : %p", evas_info, evas_info->eo);
	if (info == UPDATE_VISIBILITY) {
		if (evas_info->visible == VISIBLE_FALSE) {
			evas_object_hide(evas_info->eo);
			LOGI("object hide..");
		} else {
			evas_object_show(evas_info->eo);
			LOGI("object show.. %d", evas_info->visible);
		}
		LOGD("[LEAVE]");
		g_mutex_unlock(&evas_info->mp_lock);
		return;
	}

	if (info != UPDATE_TBM_SURF) {
		LOGW("invalid info type : %d", info);
		g_mutex_unlock(&evas_info->mp_lock);
		return;
	}

	if (evas_info->cur_idx==-1 || !evas_info->pkt_info[evas_info->cur_idx].tbm_surf) {
		LOGW("cur_idx %d, tbm_surf may be NULL", evas_info->cur_idx);
		g_mutex_unlock(&evas_info->mp_lock);
		return;
	}
	g_mutex_lock(&evas_info->idx_lock);
	/* index */
	gint cur_idx = evas_info->cur_idx;
	gint prev_idx = evas_info->pkt_info[cur_idx].prev;

	LOGD("received (idx %d, packet %p)", cur_idx, evas_info->pkt_info[cur_idx].packet);

	tbm_format tbm_fmt = tbm_surface_get_format(evas_info->pkt_info[cur_idx].tbm_surf);
	switch (tbm_fmt) {
	case TBM_FORMAT_NV12:
		LOGD("tbm_surface format : TBM_FORMAT_NV12");
		break;
	case TBM_FORMAT_YUV420:
		LOGD("tbm_surface format : TBM_FORMAT_YUV420");
		break;
	default:
		LOGW("tbm_surface format : unknown %d", tbm_fmt);
		break;
	}
	/* it is needed to skip setting when state is pause */
	Evas_Native_Surface surf;
	surf.type = EVAS_NATIVE_SURFACE_TBM;
	surf.version = EVAS_NATIVE_SURFACE_VERSION;
	surf.data.tbm.buffer = evas_info->pkt_info[cur_idx].tbm_surf;
//  surf.data.tbm.rot = evas_info->rotate_angle;
//  surf.data.tbm.flip = evas_info->flip;

	rect_info result = { 0 };

	evas_object_geometry_get(evas_info->eo, &evas_info->eo_size.x, &evas_info->eo_size.y, &evas_info->eo_size.w, &evas_info->eo_size.h);
	if (!evas_info->eo_size.w || !evas_info->eo_size.h) {
		LOGE("there is no information for evas object size");
		goto ERROR;
	}
	_mm_evas_renderer_update_geometry(evas_info, &result);
	if (!result.w || !result.h) {
		LOGE("no information about geometry (%d, %d)", result.w, result.h);
		goto ERROR;
	}

	if (evas_info->use_ratio) {
//      surf.data.tbm.ratio = (float) evas_info->w / evas_info->h;
		LOGD("set ratio for letter mode");
	}
	evas_object_size_hint_align_set(evas_info->eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_size_hint_weight_set(evas_info->eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	if (evas_info->w > 0 && evas_info->h > 0)
		evas_object_image_size_set(evas_info->eo, evas_info->w, evas_info->h);

	evas_object_image_native_surface_set(evas_info->eo, &surf);
	LOGD("native surface set finish");

	if (result.x || result.y)
		LOGD("coordinate x, y (%d, %d) for locating video to center", result.x, result.y);
	evas_object_image_fill_set(evas_info->eo, result.x, result.y, result.w, result.h);

	evas_object_image_pixels_dirty_set(evas_info->eo, EINA_TRUE);
	LOGD("GEO_METHOD : src(%dx%d), dst(%dx%d), dst_x(%d), dst_y(%d), rotate(%d), flip(%d)", evas_info->w, evas_info->h, evas_info->eo_size.w, evas_info->eo_size.h, evas_info->eo_size.x, evas_info->eo_size.y, evas_info->rotate_angle, evas_info->flip);

	/* when _evas_pipe_cb is called sequentially, previous packet and current packet will be the same */
	if ((prev_idx != -1) && evas_info->pkt_info[prev_idx].packet && (prev_idx != cur_idx))
		_free_previous_packets(evas_info);

	LOGD("[LEAVE]");
	g_mutex_unlock(&evas_info->idx_lock);
	g_mutex_unlock(&evas_info->mp_lock);

	return;

 ERROR:
	if ((prev_idx != -1) && evas_info->pkt_info[prev_idx].packet) {
		LOGI("cant render");
		_free_previous_packets(evas_info);
	}
	g_mutex_unlock(&evas_info->idx_lock);
	g_mutex_unlock(&evas_info->mp_lock);
}

#ifdef _DEBUG_INDEX
void __print_idx(mm_evas_info *evas_info)
{
	gint prev_idx = evas_info->pkt_info[evas_info->cur_idx].prev;
	LOGE("***** start cur_idx : %d -> prev_idx : %d", evas_info->cur_idx, prev_idx);
	while(prev_idx != -1)
	{
		LOGE("***** cur_idx : %d -> prev_idx : %d", prev_idx, evas_info->pkt_info[prev_idx].prev);
		prev_idx = evas_info->pkt_info[prev_idx].prev;
	}
	LOGE("***** end");
	return;
}
#endif

void _free_previous_packets(mm_evas_info *evas_info)
{
	gint index = evas_info->cur_idx;
	gint prev_idx = evas_info->pkt_info[index].prev;

	while(prev_idx != -1)
	{
		LOGD("destroy previous packet [%p] idx %d", evas_info->pkt_info[prev_idx].packet, prev_idx);
		if (media_packet_destroy(evas_info->pkt_info[prev_idx].packet) != MEDIA_PACKET_ERROR_NONE)
			LOGE("media_packet_destroy failed %p", evas_info->pkt_info[prev_idx].packet);
		evas_info->pkt_info[prev_idx].packet = NULL;
		evas_info->pkt_info[prev_idx].tbm_surf = NULL;
		evas_info->pkt_info[index].prev = -1;
		evas_info->sent_buffer_cnt--;

		/* move index to previous index */
		index= prev_idx;
		prev_idx = evas_info->pkt_info[prev_idx].prev;
		LOGD("sent packet %d", evas_info->sent_buffer_cnt);
	}
	return;
}

static int _get_video_size(media_packet_h packet, mm_evas_info *evas_info)
{
	media_format_h fmt;
	if (media_packet_get_format(packet, &fmt) == MEDIA_PACKET_ERROR_NONE) {
		int w, h;
		if (media_format_get_video_info(fmt, NULL, &w, &h, NULL, NULL) == MEDIA_PACKET_ERROR_NONE) {
			LOGD("video width = %d, height =%d", w, h);
			evas_info->w = w;
			evas_info->h = h;
			return true;
		} else
			LOGW("media_format_get_video_info is failed");
		if (media_format_unref(fmt) != MEDIA_PACKET_ERROR_NONE)	/* because of media_packet_get_format */
			LOGW("media_format_unref is failed");
	} else {
		LOGW("media_packet_get_format is failed");
	}
	return false;
}

int _find_empty_index(mm_evas_info *evas_info)
{
	int i;
	for (i = 0; i < MAX_PACKET_NUM; i++) {
		if (!evas_info->pkt_info[i].packet) {
			LOGD("selected idx %d", i);
			return i;
		}
	}
	LOGE("there is no empty idx");

	return -1;
}

int _flush_packets(mm_evas_info *evas_info)
{
	int ret = MM_ERROR_NONE;
	int ret_mp = MEDIA_PACKET_ERROR_NONE;
	int i = 0;

	if (!evas_info) {
		LOGW("there is no esink info");
		return MM_ERROR_INVALID_ARGUMENT;
	}
	/* update the screen only if visible is ture */
	if (evas_info->keep_screen && (evas_info->visible != VISIBLE_FALSE)) {
		Evas_Native_Surface surf;
		rect_info result = { 0 };
		evas_object_geometry_get(evas_info->eo, &evas_info->eo_size.x, &evas_info->eo_size.y, &evas_info->eo_size.w, &evas_info->eo_size.h);
		if (!evas_info->eo_size.w || !evas_info->eo_size.h) {
			LOGE("there is no information for evas object size");
			return MM_ERROR_INVALID_ARGUMENT;
		}
		_mm_evas_renderer_update_geometry(evas_info, &result);
		if (!result.w || !result.h) {
			LOGE("no information about geometry (%d, %d)", result.w, result.h);
			return MM_ERROR_INVALID_ARGUMENT;
		}

		if (evas_info->use_ratio) {
	//      surf.data.tbm.ratio = (float) evas_info->w / evas_info->h;
			LOGD("set ratio for letter mode");
		}
		evas_object_size_hint_align_set(evas_info->eo, EVAS_HINT_FILL, EVAS_HINT_FILL);
		evas_object_size_hint_weight_set(evas_info->eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
		if (evas_info->w > 0 && evas_info->h > 0)
			evas_object_image_size_set(evas_info->eo, evas_info->w, evas_info->h);

		if (result.x || result.y)
			LOGD("coordinate x, y (%d, %d) for locating video to center", result.x, result.y);
		evas_object_image_fill_set(evas_info->eo, result.x, result.y, result.w, result.h);

		/* set flush buffer */
		surf.type = EVAS_NATIVE_SURFACE_TBM;
		surf.version = EVAS_NATIVE_SURFACE_VERSION;
		surf.data.tbm.buffer = evas_info->flush_buffer->tbm_surf;
//		surf.data.tbm.rot = evas_info->rotate_angle;
//		surf.data.tbm.flip = evas_info->flip;
		evas_object_image_native_surface_set(evas_info->eo, &surf);

		LOGD("flush_buffer surf(%p), rotate(%d), flip(%d)", evas_info->flush_buffer->tbm_surf, evas_info->rotate_angle, evas_info->flip);
	} else {
		/* unset evas native surface for displaying black screen */
		evas_object_image_native_surface_set (evas_info->eo, NULL);
		evas_object_image_data_set (evas_info->eo, NULL);
	}
	/* destroy all packets */
	g_mutex_lock(&evas_info->mp_lock);
	for (i = 0; i < MAX_PACKET_NUM; i++) {
		if (evas_info->pkt_info[i].packet) {
			LOGD("destroy packet [%p]", evas_info->pkt_info[i].packet);
			ret_mp = media_packet_destroy(evas_info->pkt_info[i].packet);
			if (ret_mp != MEDIA_PACKET_ERROR_NONE) {
				LOGW("media_packet_destroy failed %p", evas_info->pkt_info[i].packet);
				ret = MM_ERROR_UNKNOWN;
			}
			else
				evas_info->sent_buffer_cnt--;
			evas_info->pkt_info[i].packet = NULL;
			evas_info->pkt_info[i].tbm_surf = NULL;
			evas_info->pkt_info[i].prev = -1;
		}
	}

	if (evas_info->sent_buffer_cnt != 0)
		LOGE("it should be 0 --> [%d]", evas_info->sent_buffer_cnt);
	evas_info->sent_buffer_cnt = 0;
	evas_info->cur_idx = -1;
	g_mutex_unlock(&evas_info->mp_lock);

	evas_object_image_pixels_dirty_set (evas_info->eo, EINA_TRUE);
	evas_info->retrieve_packet = FALSE;

	return ret;
}

#if 0
int _reset_pipe(mm_evas_info *evas_info)
{
	int i = 0;
	int ret = MM_ERROR_NONE;
	int ret_mp = MEDIA_PACKET_ERROR_NONE;

	/* delete old pipe */
	if (evas_info->epipe) {
		LOGD("pipe %p will be deleted", evas_info->epipe);
		ecore_pipe_del(evas_info->epipe);
		evas_info->epipe = NULL;
	}

	for (i = 0; i < MAX_PACKET_NUM; i++) {
		if (evas_info->pkt_info[i].packet) {
			/* destroy all packets */
			LOGD("destroy packet [%p]", evas_info->pkt_info[i].packet);
			ret_mp = media_packet_destroy(evas_info->pkt_info[i].packet);
			if (ret_mp != MEDIA_PACKET_ERROR_NONE) {
				LOGW("media_packet_destroy failed %p", evas_info->pkt_info[i].packet);
				ret = MM_ERROR_UNKNOWN;
			}
			else
				evas_info->sent_buffer_cnt--;
			evas_info->pkt_info[i].packet = NULL;
			evas_info->pkt_info[i].tbm_surf = NULL;
			evas_info->pkt_info[i].prev = -1;
		}
	}

	if (evas_info->sent_buffer_cnt != 0)
		LOGE("it should be 0 --> [%d]", evas_info->sent_buffer_cnt);
	evas_info->sent_buffer_cnt = 0;
	evas_info->cur_idx = -1;

	/* make new pipe */
	if (!evas_info->epipe) {
		evas_info->epipe = ecore_pipe_add((Ecore_Pipe_Cb) _evas_pipe_cb, evas_info);
		if (!evas_info->epipe) {
			LOGE("pipe is not created");
			ret = MM_ERROR_UNKNOWN;
		}
		LOGD("created pipe %p", evas_info->epipe);
	}

	return ret;
}
#endif

static void _mm_evas_renderer_set_callback(mm_evas_info *evas_info)
{
	if (evas_info->eo) {
		SET_EVAS_OBJECT_EVENT_CALLBACK(evas_info->eo, evas_info);
		SET_EVAS_EVENT_CALLBACK(evas_object_evas_get(evas_info->eo), evas_info);
	}
}

static void _mm_evas_renderer_unset_callback(mm_evas_info *evas_info)
{
	if (evas_info->eo) {
		UNSET_EVAS_OBJECT_EVENT_CALLBACK(evas_info->eo);
		UNSET_EVAS_EVENT_CALLBACK(evas_object_evas_get(evas_info->eo));
	}
}

int _mm_evas_renderer_create(mm_evas_info **evas_info)
{
	mm_evas_info *ptr = NULL;
	ptr = g_malloc0(sizeof(mm_evas_info));

	if (!ptr) {
		LOGE("Cannot allocate memory for evas_info\n");
		goto ERROR;
	} else {
		*evas_info = ptr;
		LOGD("Success create evas_info(%p)", *evas_info);
	}
	g_mutex_init(&ptr->mp_lock);
	g_mutex_init(&ptr->idx_lock);

	return MM_ERROR_NONE;

 ERROR:
	*evas_info = NULL;
	return MM_ERROR_OUT_OF_STORAGE;
}

int _mm_evas_renderer_destroy(mm_evas_info **evas_info)
{
	mm_evas_info *ptr = (mm_evas_info *)*evas_info;
	MM_CHECK_NULL(ptr);
	int ret = MM_ERROR_NONE;

	LOGD("finalize evas_info %p", ptr);

	ret = _mm_evas_renderer_reset(ptr);
	g_mutex_clear(&ptr->mp_lock);
	g_mutex_clear(&ptr->idx_lock);

	g_free(ptr);
	ptr = NULL;

	return ret;
}

int _mm_evas_renderer_set_info(mm_evas_info *evas_info, Evas_Object *eo)
{
	MM_CHECK_NULL(evas_info);
	MM_CHECK_NULL(eo);
	g_mutex_lock(&evas_info->idx_lock);

	LOGD("set evas_info");
	int i;
	for (i = 0; i < MAX_PACKET_NUM; i++) {
		evas_info->pkt_info[i].packet = NULL;
		evas_info->pkt_info[i].tbm_surf = NULL;
		evas_info->pkt_info[i].prev = -1;
	}

	evas_info->cur_idx = -1;
	evas_info->eo = eo;
	evas_info->epipe = ecore_pipe_add((Ecore_Pipe_Cb) _evas_pipe_cb, evas_info);
	if (!evas_info->epipe) {
		LOGE("pipe is not created");
		g_mutex_unlock(&evas_info->idx_lock);
		return MM_ERROR_UNKNOWN;
	}
	LOGD("created pipe %p", evas_info->epipe);
	_mm_evas_renderer_set_callback(evas_info);

	evas_object_geometry_get(evas_info->eo, &evas_info->eo_size.x, &evas_info->eo_size.y, &evas_info->eo_size.w, &evas_info->eo_size.h);
	LOGI("evas object %p (%d, %d, %d, %d)", evas_info->eo, evas_info->eo_size.x, evas_info->eo_size.y, evas_info->eo_size.w, evas_info->eo_size.h);

	g_mutex_unlock(&evas_info->idx_lock);

	return MM_ERROR_NONE;
}

int _mm_evas_renderer_reset(mm_evas_info *evas_info)
{
	MM_CHECK_NULL(evas_info);
	g_mutex_lock(&evas_info->idx_lock);

	int i;
	int ret = MM_ERROR_NONE;
	int ret_mp = MEDIA_PACKET_ERROR_NONE;

	if (evas_info->eo) {
		_mm_evas_renderer_unset_callback(evas_info);
		evas_object_image_data_set(evas_info->eo, NULL);
		evas_info->eo = NULL;
	}
	if (evas_info->epipe) {
		LOGD("pipe %p will be deleted", evas_info->epipe);
		ecore_pipe_del(evas_info->epipe);
		evas_info->epipe = NULL;
	}

	evas_info->eo_size.x = evas_info->eo_size.y = evas_info->eo_size.w = evas_info->eo_size.h = 0;
	evas_info->w = evas_info->h = 0;

	if (evas_info->flush_buffer)
		_mm_evas_renderer_release_flush_buffer(evas_info);

	g_mutex_lock(&evas_info->mp_lock);
	for (i = 0; i < MAX_PACKET_NUM; i++) {
		if (evas_info->pkt_info[i].packet) {
			/* destroy all packets */
			LOGD("destroy packet [%p]", evas_info->pkt_info[i].packet);
			ret_mp = media_packet_destroy(evas_info->pkt_info[i].packet);
			if (ret_mp != MEDIA_PACKET_ERROR_NONE) {
				LOGW("media_packet_destroy failed %p", evas_info->pkt_info[i].packet);
				ret = MM_ERROR_UNKNOWN;
			}
			else
				evas_info->sent_buffer_cnt--;
			evas_info->pkt_info[i].packet = NULL;
			evas_info->pkt_info[i].tbm_surf = NULL;
			evas_info->pkt_info[i].prev = -1;
		}
	}
	g_mutex_unlock(&evas_info->mp_lock);
	if (evas_info->sent_buffer_cnt != 0)
		LOGE("it should be 0 --> [%d]", evas_info->sent_buffer_cnt);
	evas_info->sent_buffer_cnt = 0;
	evas_info->cur_idx = -1;

	g_mutex_unlock(&evas_info->idx_lock);

	return ret;
}

void _mm_evas_renderer_update_geometry(mm_evas_info *evas_info, rect_info *result)
{
	if (!evas_info || !evas_info->eo) {
		LOGW("there is no evas_info or evas object");
		return;
	}
	if (!result) {
		LOGW("there is no rect info");
		return;
	}

	result->x = 0;
	result->y = 0;

	switch (evas_info->display_geometry_method) {
	case DISP_GEO_METHOD_LETTER_BOX:
		/* set black padding for letter box mode */
		LOGD("letter box mode");
		evas_info->use_ratio = TRUE;
		result->w = evas_info->eo_size.w;
		result->h = evas_info->eo_size.h;
		break;
	case DISP_GEO_METHOD_ORIGIN_SIZE:
		LOGD("origin size mode");
		evas_info->use_ratio = FALSE;
		/* set coordinate for each case */
		result->x = (evas_info->eo_size.w - evas_info->w) / 2;
		result->y = (evas_info->eo_size.h - evas_info->h) / 2;
		result->w = evas_info->w;
		result->h = evas_info->h;
		break;
	case DISP_GEO_METHOD_FULL_SCREEN:
		LOGD("full screen mode");
		evas_info->use_ratio = FALSE;
		result->w = evas_info->eo_size.w;
		result->h = evas_info->eo_size.h;
		break;
	case DISP_GEO_METHOD_CROPPED_FULL_SCREEN:
		LOGD("cropped full screen mode");
		evas_info->use_ratio = FALSE;
		/* compare evas object's ratio with video's */
		if ((evas_info->eo_size.w / evas_info->eo_size.h) > (evas_info->w / evas_info->h)) {
			result->w = evas_info->eo_size.w;
			result->h = evas_info->eo_size.w * evas_info->h / evas_info->w;
			result->y = -(result->h - evas_info->eo_size.h) / 2;
		} else {
			result->w = evas_info->eo_size.h * evas_info->w / evas_info->h;
			result->h = evas_info->eo_size.h;
			result->x = -(result->w - evas_info->eo_size.w) / 2;
		}
		break;
	case DISP_GEO_METHOD_ORIGIN_SIZE_OR_LETTER_BOX:
		LOGD("origin size or letter box mode");
		/* if video size is smaller than evas object's, it will be set to origin size mode */
		if ((evas_info->eo_size.w > evas_info->w) && (evas_info->eo_size.h > evas_info->h)) {
			LOGD("origin size mode");
			evas_info->use_ratio = FALSE;
			/* set coordinate for each case */
			result->x = (evas_info->eo_size.w - evas_info->w) / 2;
			result->y = (evas_info->eo_size.h - evas_info->h) / 2;
			result->w = evas_info->w;
			result->h = evas_info->h;
		} else {
			LOGD("letter box mode");
			evas_info->use_ratio = TRUE;
			result->w = evas_info->eo_size.w;
			result->h = evas_info->eo_size.h;
		}
		break;
	default:
		LOGW("unsupported mode.");
		break;
	}
	LOGD("geometry result [%d, %d, %d, %d]", result->x, result->y, result->w, result->h);
}

int _mm_evas_renderer_apply_geometry(mm_evas_info *evas_info)
{
	if (!evas_info || !evas_info->eo) {
		LOGW("there is no evas_info or evas object");
		return MM_ERROR_NONE;
	}

	Evas_Native_Surface *surf = evas_object_image_native_surface_get(evas_info->eo);
	rect_info result = { 0 };

	if (surf) {
		LOGD("native surface exists");
//      surf->data.tbm.rot = evas_info->rotate_angle;
//      surf->data.tbm.flip = evas_info->flip;
		evas_object_image_native_surface_set(evas_info->eo, surf);

		_mm_evas_renderer_update_geometry(evas_info, &result);

		if (evas_info->use_ratio) {
//          surf->data.tbm.ratio = (float) evas_info->w / evas_info->h;
			LOGD("set ratio for letter mode");
		}

		if (result.x || result.y)
			LOGD("coordinate x, y (%d, %d) for locating video to center", result.x, result.y);

		evas_object_image_fill_set(evas_info->eo, result.x, result.y, result.w, result.h);
		return MM_ERROR_NONE;
	} else
		LOGW("there is no surf");
	/* FIXME: before pipe_cb is invoked, apply_geometry can be called. */
	return MM_ERROR_NONE;
}

int _mm_evas_renderer_retrieve_all_packets(mm_evas_info *evas_info, bool keep_screen)
{
	MM_CHECK_NULL(evas_info);

	int ret = MM_ERROR_NONE;
	pid_t pid = getpid();
	pid_t tid = syscall(SYS_gettid);

	/* make flush buffer */
	if (keep_screen)
		ret = _mm_evas_renderer_make_flush_buffer(evas_info);
	evas_info->keep_screen = keep_screen;

	LOGD("pid [%d], tid [%d]", pid, tid);
	if (pid == tid) {
		/* in this case, we deem it is main thread */
		if (_flush_packets(evas_info) != MM_ERROR_NONE) {
			LOGE("flushing packets are failed");
			ret = MM_ERROR_UNKNOWN;
		}
	} else {
		/* it will be executed to write flush buffer and destroy media packets in pre_cb */
		evas_info->retrieve_packet = TRUE;
	}

	return ret;
}

/* make buffer for copying */
int _mm_evas_renderer_make_flush_buffer (mm_evas_info *evas_info)
{
	if (evas_info->cur_idx == -1) {
		LOGW("there is no remained buffer");
		return MM_ERROR_INVALID_ARGUMENT;
	}
	media_packet_h packet = evas_info->pkt_info[evas_info->cur_idx].packet;
	MM_CHECK_NULL(packet);

	flush_info *flush_buffer = NULL;
	tbm_bo src_bo = NULL;
	tbm_surface_h src_tbm_surf = NULL;
	int src_size = 0;
	int size = 0;
	tbm_bo bo = NULL;
	tbm_format tbm_fmt;
	tbm_bo_handle vaddr_src = {0};
	tbm_bo_handle vaddr_dst = {0};
	int ret = MM_ERROR_NONE;

	if (evas_info->flush_buffer)
		_mm_evas_renderer_release_flush_buffer(evas_info);

	/* malloc buffer */
	flush_buffer = (flush_info *)malloc(sizeof(flush_info));
	if (flush_buffer == NULL) {
		LOGE("malloc is failed");
		return FALSE;
	}
	memset(flush_buffer, 0x0, sizeof(flush_info));

	/* @@@ lock is needed, because write and this API can be called at the same time */
	ret = media_packet_get_tbm_surface(packet, &src_tbm_surf);
	if (ret != MEDIA_PACKET_ERROR_NONE || !src_tbm_surf) {
		LOGW("get_tbm_surface is failed");
		goto ERROR;
	}

	/* get src buffer info */
	tbm_fmt = tbm_surface_get_format(src_tbm_surf);
	src_bo = tbm_surface_internal_get_bo(src_tbm_surf, 0); //@@@ 0??
	src_size = tbm_bo_size(src_bo);
	if (!src_bo || !src_size) {
		LOGE("bo(%p), size(%d)", src_bo, src_size);
		goto ERROR;
	}

	/* create tbm surface */
	flush_buffer->tbm_surf = tbm_surface_create(evas_info->w, evas_info->h, tbm_fmt);
	if (!flush_buffer->tbm_surf)
	{
		LOGE("tbm_surf is NULL!!");
		goto ERROR;
	}

	/* get bo and size */
	bo = tbm_surface_internal_get_bo(flush_buffer->tbm_surf, 0); //@@@ 0??
	size = tbm_bo_size(bo);
	if (!bo || !size)
	{
		LOGE("bo(%p), size(%d)", bo, size);
		goto ERROR;
	}
	flush_buffer->bo = bo;

	vaddr_src = tbm_bo_map(src_bo, TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
	vaddr_dst = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
	if (!vaddr_src.ptr || !vaddr_dst.ptr) {
		LOGW("get vaddr failed src %p, dst %p", vaddr_src.ptr, vaddr_dst.ptr);
		if (vaddr_src.ptr) {
			tbm_bo_unmap(src_bo);
		}
		if (vaddr_dst.ptr) {
			tbm_bo_unmap(bo);
		}
		goto ERROR;
	} else {
		memset (vaddr_dst.ptr, 0x0, size);
		LOGW ("tbm_bo_map(vaddr) is finished, bo(%p), vaddr(%p)", bo, vaddr_dst.ptr);
	}

	/* copy buffer */
	memcpy(vaddr_dst.ptr, vaddr_src.ptr, src_size);

	tbm_bo_unmap(src_bo);
	tbm_bo_unmap(bo);
	LOGW("copy is done. tbm surface : %p src_size : %d", flush_buffer->tbm_surf, src_size);

	evas_info->flush_buffer = flush_buffer;

	return MM_ERROR_NONE;

ERROR:
	if (flush_buffer) {
		if(flush_buffer->tbm_surf)
		{
			tbm_surface_destroy(flush_buffer->tbm_surf);
			flush_buffer->tbm_surf = NULL;
		}

		free(flush_buffer);
		flush_buffer = NULL;
	}
	return MM_ERROR_UNKNOWN;
}

/* release flush buffer */
void _mm_evas_renderer_release_flush_buffer (mm_evas_info *evas_info)
{
	LOGW("release FLUSH BUFFER start");
	if (evas_info->flush_buffer->bo) {
		evas_info->flush_buffer->bo = NULL;
	}
	if (evas_info->flush_buffer->tbm_surf) {
		tbm_surface_destroy(evas_info->flush_buffer->tbm_surf);
		evas_info->flush_buffer->tbm_surf = NULL;
	}

	LOGW("release FLUSH BUFFER done");

	free(evas_info->flush_buffer);
	evas_info->flush_buffer = NULL;

	return;
}

void mm_evas_renderer_write(media_packet_h packet, void *data)
{
	if (!packet) {
		LOGE("packet %p is NULL", packet);
		return;
	}
	mm_evas_info *handle = (mm_evas_info *)data;
	int ret = MEDIA_PACKET_ERROR_NONE;
	bool has;
	tbm_surface_h tbm_surf;
	gint index;

	LOGD("packet [%p]", packet);

	if (!data || !handle) {
		LOGE("handle %p or evas_info %p is NULL", data, handle);
		goto INVALID_PARAM;
	}
	g_mutex_lock(&handle->idx_lock);

	ret = media_packet_has_tbm_surface_buffer(packet, &has);
	if (ret != MEDIA_PACKET_ERROR_NONE) {
		LOGW("has_tbm_surface is failed");
		goto ERROR;
	}
	/* FIXME: when setCaps occurs, _get_video_size should be called */
	/* currently we are always checking it */
	if (has && _get_video_size(packet, handle)) {
		/* Attention! if this error occurs, we need to consider managing buffer */
		if (handle->sent_buffer_cnt > 4) {
			LOGE("too many buffers are not released %d", handle->sent_buffer_cnt);
			goto ERROR;
#if 0
			/* FIXME: fix this logic */
			/* destroy all media packets and reset pipe at present */
			/* Attention! it might free buffer that is being rendered */
			g_mutex_lock(&handle->mp_lock);
			_reset_pipe(handle);
			g_mutex_unlock(&handle->mp_lock);
#endif
		}
		ret = media_packet_get_tbm_surface(packet, &tbm_surf);
		if (ret != MEDIA_PACKET_ERROR_NONE || !tbm_surf) {
			LOGW("get_tbm_surface is failed");
			goto ERROR;
		}

		/* find new index for current packet */
		index = _find_empty_index(handle);
		if (index == -1) {
			goto ERROR;
		}

		/* save previous index */
		handle->pkt_info[index].prev = handle->cur_idx;
		handle->pkt_info[index].packet = packet;
		handle->pkt_info[index].tbm_surf = tbm_surf;
		handle->cur_idx = index;
		handle->sent_buffer_cnt++;
		LOGD("sent packet %d", handle->sent_buffer_cnt);

		ret = ecore_pipe_write(handle->epipe, handle, UPDATE_TBM_SURF);
		if (!ret) {
			handle->pkt_info[index].packet = NULL;
			handle->pkt_info[index].tbm_surf = NULL;
			handle->pkt_info[index].prev = -1;
			handle->cur_idx = handle->pkt_info[index].prev;
			handle->sent_buffer_cnt--;
			LOGW("Failed to ecore_pipe_write() for updating tbm surf\n");
			goto ERROR;
		}
	} else {
		LOGW("no tbm_surf");
		goto ERROR;
	}
	g_mutex_unlock(&handle->idx_lock);

	return;
ERROR:
	g_mutex_unlock(&handle->idx_lock);
INVALID_PARAM:
	/* destroy media_packet immediately */
	if (packet) {
		g_mutex_lock(&handle->mp_lock);
		LOGD("cant write. destroy packet [%p]", packet);
		if (media_packet_destroy(packet) != MEDIA_PACKET_ERROR_NONE)
			LOGE("media_packet_destroy failed %p", packet);
		packet = NULL;
		g_mutex_unlock(&handle->mp_lock);
	}
	return;
}

int mm_evas_renderer_update_param(MMHandleType handle)
{
	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type.");
		return ret;
	}

	/* when handle is realized, we need to update all properties */
	if (evas_info) {
		LOGD("set video param : evas-object %x, method %d", evas_info->eo, evas_info->display_geometry_method);
		LOGD("set video param : visible %d", evas_info->visible);
		LOGD("set video param : rotate %d", evas_info->rotate_angle);

		ret = _mm_evas_renderer_apply_geometry(evas_info);
		if (ret != MM_ERROR_NONE)
			return ret;

		if (evas_info->epipe) {
			ret = ecore_pipe_write(evas_info->epipe, &evas_info->visible, UPDATE_VISIBILITY);
			if (!ret) {
				LOGW("fail to ecore_pipe_write() for updating visibility\n");
				ret = MM_ERROR_UNKNOWN;
			} else {
				ret = MM_ERROR_NONE;
			}
		}
	}

	return ret;
}

int mm_evas_renderer_create(MMHandleType *handle, Evas_Object *eo)
{
	MM_CHECK_NULL(handle);

	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = NULL;

	ret = _mm_evas_renderer_create(&evas_info);
	if (ret != MM_ERROR_NONE) {
		LOGE("fail to create evas_info");
		return ret;
	}
	ret = _mm_evas_renderer_set_info(evas_info, eo);
	if (ret != MM_ERROR_NONE) {
		LOGE("fail to init evas_info");
		if (_mm_evas_renderer_destroy(&evas_info) != MM_ERROR_NONE)
			LOGE("fail to destroy evas_info");
		return ret;
	}

	*handle = (MMHandleType)evas_info;

	return MM_ERROR_NONE;
}

int mm_evas_renderer_destroy(MMHandleType *handle)
{
	MM_CHECK_NULL(handle);

	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info *)*handle;

	if (!evas_info) {
		LOGD("skip it. it is not evas surface type.");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}

	ret = _mm_evas_renderer_destroy(&evas_info);
	if (ret != MM_ERROR_NONE) {
		LOGE("fail to destroy evas_info");
		return ret;
	}
	*handle = NULL;

	return MM_ERROR_NONE;
}

int mm_evas_renderer_set_visible(MMHandleType handle, bool visible)
{
	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}

	if (visible)
		evas_info->visible = VISIBLE_TRUE;
	else
		evas_info->visible = VISIBLE_FALSE;

	if (evas_info->epipe) {
		ret = ecore_pipe_write(evas_info->epipe, &visible, UPDATE_VISIBILITY);
		if (!ret) {
			LOGW("fail to ecore_pipe_write() for updating visibility\n");
			ret = MM_ERROR_UNKNOWN;
		} else {
			ret = MM_ERROR_NONE;
		}
	} else {
		LOGW("there is no epipe. we cant update it");
	}

	return ret;
}

int mm_evas_renderer_get_visible(MMHandleType handle, bool *visible)
{
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}

	if (evas_info->visible == VISIBLE_FALSE)
		*visible = FALSE;
	else
		*visible = TRUE;

	return MM_ERROR_NONE;
}

int mm_evas_renderer_set_rotation(MMHandleType handle, int rotate)
{
	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}

	evas_info->rotate_angle = rotate;
	ret = _mm_evas_renderer_apply_geometry(evas_info);

	return ret;
}

int mm_evas_renderer_get_rotation(MMHandleType handle, int *rotate)
{
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}
	*rotate = evas_info->rotate_angle;

	return MM_ERROR_NONE;
}

int mm_evas_renderer_set_geometry(MMHandleType handle, int mode)
{
	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}

	evas_info->display_geometry_method = mode;
	ret = _mm_evas_renderer_apply_geometry(evas_info);

	return ret;
}

int mm_evas_renderer_get_geometry(MMHandleType handle, int *mode)
{
	mm_evas_info *evas_info = (mm_evas_info *)handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or handle is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}
	*mode = evas_info->display_geometry_method;

	return MM_ERROR_NONE;
}

int mm_evas_renderer_retrieve_all_packets (MMHandleType handle, bool keep_screen)
{
	int ret = MM_ERROR_NONE;
	mm_evas_info *evas_info = (mm_evas_info*) handle;

	if (!evas_info) {
		LOGW("skip it. it is not evas surface type or player is not prepared");
		return MM_ERROR_RESOURCE_NOT_INITIALIZED;
	}
	ret = _mm_evas_renderer_retrieve_all_packets(evas_info, keep_screen);

	return ret;
}