summaryrefslogtreecommitdiff
path: root/src/mm_player_gst.c
blob: 205c1cf757bf1bcab3229c5e2123a800914998f4 (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
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
/*
 * libmm-player
 *
 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YeJin Cho <cho.yejin@samsung.com>,
 * Seungbae Shin <seungbae.shin@samsung.com>, YoungHwan An <younghwan_.an@samsung.com>
 *
 * 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.
 *
 */

/*===========================================================================================
|																							|
|  INCLUDE FILES																			|
|																							|
========================================================================================== */
#include <dlog.h>
#include <mm_error.h>
#include <gst/app/gstappsrc.h>

#include "mm_player_gst.h"
#include "mm_player_priv.h"
#include "mm_player_attrs.h"
#include "mm_player_utils.h"
#include "mm_player_tracks.h"

/*===========================================================================================
|																							|
|  LOCAL DEFINITIONS AND DECLARATIONS FOR MODULE											|
|																							|
========================================================================================== */

/*---------------------------------------------------------------------------
|    GLOBAL CONSTANT DEFINITIONS:											|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    IMPORTED VARIABLE DECLARATIONS:										|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    IMPORTED FUNCTION DECLARATIONS:										|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    LOCAL #defines:														|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    LOCAL CONSTANT DEFINITIONS:											|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    LOCAL DATA TYPE DEFINITIONS:											|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    GLOBAL VARIABLE DEFINITIONS:											|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    LOCAL VARIABLE DEFINITIONS:											|
---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
|    LOCAL FUNCTION PROTOTYPES:												|
---------------------------------------------------------------------------*/

/*===========================================================================================
|																							|
|  FUNCTION DEFINITIONS																		|
|																							|
========================================================================================== */
#ifdef __DEBUG__
static void
print_tag(const GstTagList *list, const gchar *tag, gpointer unused)
{
	gint i, count;

	count = gst_tag_list_get_tag_size(list, tag);

	LOGD("count = %d", count);

	for (i = 0; i < count; i++) {
		gchar *str;

		if (gst_tag_get_type(tag) == G_TYPE_STRING) {
			if (!gst_tag_list_get_string_index(list, tag, i, &str))
				g_assert_not_reached();
		} else {
			str = g_strdup_value_contents(gst_tag_list_get_value_index(list, tag, i));
		}

		if (i == 0)
			g_print("  %15s: %s", gst_tag_get_nick(tag), str);
		else
			g_print("                 : %s", str);

		g_free(str);
	}
}
#endif

static gboolean
__mmplayer_check_error_posted_from_activated_track(mmplayer_t *player, gchar *src_element_name)
{
	/* check whether the error is posted from not-activated track or not */
	int msg_src_pos = 0;
	gint active_pad_index = 0;

	MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->mainbin[MMPLAYER_M_A_INPUT_SELECTOR].gst, TRUE);

	active_pad_index = player->selector[MM_PLAYER_TRACK_TYPE_AUDIO].active_pad_index;
	LOGD("current  active pad index  -%d", active_pad_index);

	if  (src_element_name) {
		int idx = 0;

		if (player->audio_decoders) {
			GList *adec = player->audio_decoders;
			for (; adec ; adec = g_list_next(adec)) {
				gchar *name = adec->data;

				LOGD("found audio decoder name  = %s", name);
				if (g_strrstr(name, src_element_name)) {
					msg_src_pos = idx;
					break;
				}
				idx++;
			}
		}
		LOGD("active pad = %d, error src index = %d", active_pad_index,  msg_src_pos);
	}

	if (active_pad_index != msg_src_pos) {
		LOGD("skip error because error is posted from no activated track");
		return FALSE;
	}

	return TRUE;
}

static int
__mmplayer_gst_transform_error_decode(mmplayer_t *player, const char *klass)
{
	/* Demuxer can't parse one track because it's corrupted.
	 * So, the decoder for it is not linked.
	 * But, it has one playable track.
	 */
	if (g_strrstr(klass, "Demux")) {
		if (player->can_support_codec == FOUND_PLUGIN_VIDEO) {
			return MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND;
		} else if (player->can_support_codec == FOUND_PLUGIN_AUDIO) {
			return MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND;
		} else {
			if (player->pipeline->audiobin) { // PCM
				return MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND;
			} else {
				LOGD("not found any available codec. Player should be destroyed.");
				return MM_ERROR_PLAYER_CODEC_NOT_FOUND;
			}
		}
	}

	return MM_ERROR_PLAYER_INVALID_STREAM;
}

static int
__mmplayer_gst_transform_error_type(mmplayer_t *player, GstElement *src_element)
{
	if (src_element == player->pipeline->mainbin[MMPLAYER_M_SUBPARSE].gst) {
		LOGE("Not supported subtitle.");
		return MM_ERROR_PLAYER_NOT_SUPPORTED_SUBTITLE;
	}
	return MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT;
}

static int
__mmplayer_gst_transform_error_failed(mmplayer_t *player, const char *klass, GError *error)
{
	/* Decoder Custom Message */
	if (!strstr(error->message, "ongoing"))
		return MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT;

	if (strncasecmp(klass, "audio", 5)) {
		if ((player->can_support_codec & FOUND_PLUGIN_VIDEO)) {
			LOGD("Video can keep playing.");
			return MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND;
		}
	} else if (strncasecmp(klass, "video", 5)) {
		if ((player->can_support_codec & FOUND_PLUGIN_AUDIO)) {
			LOGD("Audio can keep playing.");
			return MM_ERROR_PLAYER_VIDEO_CODEC_NOT_FOUND;
		}
	}

	LOGD("not found any available codec. Player should be destroyed.");
	return MM_ERROR_PLAYER_CODEC_NOT_FOUND;
}

static int
__mmplayer_gst_transform_error_decrypt(mmplayer_t *player, GError *error)
{
	if (strstr(error->message, "rights expired"))
		return MM_ERROR_PLAYER_DRM_EXPIRED;
	else if (strstr(error->message, "no rights"))
		return MM_ERROR_PLAYER_DRM_NO_LICENSE;
	else if (strstr(error->message, "has future rights"))
		return MM_ERROR_PLAYER_DRM_FUTURE_USE;
	else if (strstr(error->message, "opl violation"))
		return MM_ERROR_PLAYER_DRM_OUTPUT_PROTECTION;

	return MM_ERROR_PLAYER_DRM_NOT_AUTHORIZED;
}

/* NOTE : decide gstreamer state whether there is some playable track or not. */
static gint
__mmplayer_gst_transform_gsterror(mmplayer_t *player, GstMessage *message, GError *error)
{
	gchar *src_element_name = NULL;
	GstElement *src_element = NULL;
	GstElementFactory *factory = NULL;
	const gchar *klass = NULL;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(message, MM_ERROR_INVALID_ARGUMENT);
	MMPLAYER_RETURN_VAL_IF_FAIL(message->src, MM_ERROR_INVALID_ARGUMENT);
	MMPLAYER_RETURN_VAL_IF_FAIL(error, MM_ERROR_INVALID_ARGUMENT);
	MMPLAYER_RETURN_VAL_IF_FAIL(player &&
								player->pipeline &&
								player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	src_element = GST_ELEMENT_CAST(message->src);
	if (!src_element)
		return MM_ERROR_PLAYER_INTERNAL;

	src_element_name = GST_ELEMENT_NAME(src_element);
	if (!src_element_name)
		return MM_ERROR_PLAYER_INTERNAL;

	factory = gst_element_get_factory(src_element);
	if (!factory)
		return MM_ERROR_PLAYER_INTERNAL;

	klass = gst_element_factory_get_metadata(factory, GST_ELEMENT_METADATA_KLASS);
	if (!klass)
		return MM_ERROR_PLAYER_INTERNAL;

	LOGD("error code=%d, msg=%s, src element=%s, class=%s",
			error->code, error->message, src_element_name, klass);

	if (!__mmplayer_check_error_posted_from_activated_track(player, src_element_name))
		return MM_ERROR_NONE;

	switch (error->code) {
	case GST_STREAM_ERROR_DECODE:
		return __mmplayer_gst_transform_error_decode(player, klass);
	case GST_STREAM_ERROR_CODEC_NOT_FOUND:
	case GST_STREAM_ERROR_TYPE_NOT_FOUND:
	case GST_STREAM_ERROR_WRONG_TYPE:
		return __mmplayer_gst_transform_error_type(player, src_element);
	case GST_STREAM_ERROR_FAILED:
		return __mmplayer_gst_transform_error_failed(player, klass, error);
	case GST_STREAM_ERROR_DECRYPT:
	case GST_STREAM_ERROR_DECRYPT_NOKEY:
		LOGE("decryption error, [%s] failed, reason : [%s]", src_element_name, error->message);
		return __mmplayer_gst_transform_error_decrypt(player, error);
	default:
		break;
	}

	MMPLAYER_FLEAVE();

	return MM_ERROR_PLAYER_INVALID_STREAM;
}

gint
__mmplayer_gst_handle_core_error(mmplayer_t *player, int code)
{
	gint trans_err = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);

	switch (code) {
	case GST_CORE_ERROR_MISSING_PLUGIN:
		return MM_ERROR_PLAYER_NOT_SUPPORTED_FORMAT;
	case GST_CORE_ERROR_STATE_CHANGE:
	case GST_CORE_ERROR_SEEK:
	case GST_CORE_ERROR_NOT_IMPLEMENTED:
	case GST_CORE_ERROR_FAILED:
	case GST_CORE_ERROR_TOO_LAZY:
	case GST_CORE_ERROR_PAD:
	case GST_CORE_ERROR_THREAD:
	case GST_CORE_ERROR_NEGOTIATION:
	case GST_CORE_ERROR_EVENT:
	case GST_CORE_ERROR_CAPS:
	case GST_CORE_ERROR_TAG:
	case GST_CORE_ERROR_CLOCK:
	case GST_CORE_ERROR_DISABLED:
	default:
		trans_err = MM_ERROR_PLAYER_INVALID_STREAM;
		break;
	}

	MMPLAYER_FLEAVE();

	return trans_err;
}

gint
__mmplayer_gst_handle_library_error(mmplayer_t *player, int code)
{
	gint trans_err = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);

	switch (code) {
	case GST_LIBRARY_ERROR_FAILED:
	case GST_LIBRARY_ERROR_TOO_LAZY:
	case GST_LIBRARY_ERROR_INIT:
	case GST_LIBRARY_ERROR_SHUTDOWN:
	case GST_LIBRARY_ERROR_SETTINGS:
	case GST_LIBRARY_ERROR_ENCODE:
	default:
		trans_err =  MM_ERROR_PLAYER_INVALID_STREAM;
		break;
	}

	MMPLAYER_FLEAVE();

	return trans_err;
}

gint
__mmplayer_gst_handle_resource_error(mmplayer_t *player, int code, GstMessage *message)
{
	gint trans_err = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);

	switch (code) {
	case GST_RESOURCE_ERROR_NO_SPACE_LEFT:
		trans_err = MM_ERROR_PLAYER_NO_FREE_SPACE;
		break;
	case GST_RESOURCE_ERROR_NOT_FOUND:
	case GST_RESOURCE_ERROR_OPEN_READ:
		if (MMPLAYER_IS_HTTP_STREAMING(player) || MMPLAYER_IS_HTTP_LIVE_STREAMING(player)
			|| MMPLAYER_IS_RTSP_STREAMING(player)) {
			trans_err = MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL;
			break;
		}
	case GST_RESOURCE_ERROR_READ:
		if (MMPLAYER_IS_HTTP_STREAMING(player) || MMPLAYER_IS_HTTP_LIVE_STREAMING(player)
			|| MMPLAYER_IS_RTSP_STREAMING(player)) {
			trans_err = MM_ERROR_PLAYER_STREAMING_FAIL;
			break;
		} else if (message != NULL && message->src != NULL) {
			storage_state_e storage_state = STORAGE_STATE_UNMOUNTABLE;
			mmplayer_path_type_e path_type = MMPLAYER_PATH_MAX;

			if (message->src == (GstObject *)player->pipeline->mainbin[MMPLAYER_M_SRC].gst)
				path_type = MMPLAYER_PATH_VOD;
			else if (message->src == (GstObject *)player->pipeline->mainbin[MMPLAYER_M_SUBSRC].gst)
				path_type = MMPLAYER_PATH_TEXT;

			if (path_type != MMPLAYER_PATH_MAX && player->storage_info[path_type].type == STORAGE_TYPE_EXTERNAL) {
				/* check storage state */
				storage_get_state(player->storage_info[path_type].id, &storage_state);
				player->storage_info[path_type].state = storage_state;
				LOGW("path %d, storage state %d:%d", path_type, player->storage_info[path_type].id, storage_state);
			}
		} /* fall through */
	case GST_RESOURCE_ERROR_WRITE:
	case GST_RESOURCE_ERROR_FAILED:
	case GST_RESOURCE_ERROR_SEEK:
	case GST_RESOURCE_ERROR_TOO_LAZY:
	case GST_RESOURCE_ERROR_BUSY:
	case GST_RESOURCE_ERROR_OPEN_WRITE:
	case GST_RESOURCE_ERROR_OPEN_READ_WRITE:
	case GST_RESOURCE_ERROR_CLOSE:
	case GST_RESOURCE_ERROR_SYNC:
	case GST_RESOURCE_ERROR_SETTINGS:
	default:
		trans_err = MM_ERROR_PLAYER_INTERNAL;
	break;
	}

	MMPLAYER_FLEAVE();

	return trans_err;
}

gint
__mmplayer_gst_handle_stream_error(mmplayer_t *player, GError *error, GstMessage *message)
{
	gint trans_err = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
	MMPLAYER_RETURN_VAL_IF_FAIL(error, MM_ERROR_INVALID_ARGUMENT);
	MMPLAYER_RETURN_VAL_IF_FAIL(message, MM_ERROR_INVALID_ARGUMENT);

	switch (error->code) {
	case GST_STREAM_ERROR_FAILED:
	case GST_STREAM_ERROR_TYPE_NOT_FOUND:
	case GST_STREAM_ERROR_DECODE:
	case GST_STREAM_ERROR_WRONG_TYPE:
	case GST_STREAM_ERROR_DECRYPT:
	case GST_STREAM_ERROR_DECRYPT_NOKEY:
	case GST_STREAM_ERROR_CODEC_NOT_FOUND:
		trans_err = __mmplayer_gst_transform_gsterror(player, message, error);
		break;

	case GST_STREAM_ERROR_NOT_IMPLEMENTED:
	case GST_STREAM_ERROR_TOO_LAZY:
	case GST_STREAM_ERROR_ENCODE:
	case GST_STREAM_ERROR_DEMUX:
	case GST_STREAM_ERROR_MUX:
	case GST_STREAM_ERROR_FORMAT:
	default:
		trans_err = MM_ERROR_PLAYER_INVALID_STREAM;
		break;
	}

	MMPLAYER_FLEAVE();

	return trans_err;
}

gboolean
__mmplayer_handle_gst_error(mmplayer_t *player, GstMessage *message, GError *error)
{
	MMMessageParamType msg_param;
	gchar *msg_src_element;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
	MMPLAYER_RETURN_VAL_IF_FAIL(error, FALSE);

	/* NOTE : do somthing necessary inside of __gst_handle_XXX_error. not here */

	memset(&msg_param, 0, sizeof(MMMessageParamType));

	if (error->domain == GST_CORE_ERROR) {
		msg_param.code = __mmplayer_gst_handle_core_error(player, error->code);
	} else if (error->domain == GST_LIBRARY_ERROR) {
		msg_param.code = __mmplayer_gst_handle_library_error(player, error->code);
	} else if (error->domain == GST_RESOURCE_ERROR) {
		msg_param.code = __mmplayer_gst_handle_resource_error(player, error->code, message);
	} else if (error->domain == GST_STREAM_ERROR) {
		msg_param.code = __mmplayer_gst_handle_stream_error(player, error, message);
	} else {
		LOGW("This error domain is not defined.");

		/* we treat system error as an internal error */
		msg_param.code = MM_ERROR_PLAYER_INVALID_STREAM;
	}

	if (message->src) {
		msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));

		msg_param.data = (void *)error->message;

		LOGE("-Msg src : [%s]	Domain : [%s]   Error : [%s]  Code : [%d] is tranlated to error code : [0x%x]",
			msg_src_element, g_quark_to_string(error->domain), error->message, error->code, msg_param.code);
	}

	/* no error */
	if (msg_param.code == MM_ERROR_NONE)
		return TRUE;

	/* skip error to avoid duplicated posting */
	if (((player->storage_info[MMPLAYER_PATH_VOD].type == STORAGE_TYPE_EXTERNAL) &&
		 (player->storage_info[MMPLAYER_PATH_VOD].state <= STORAGE_STATE_REMOVED)) ||
		((player->storage_info[MMPLAYER_PATH_TEXT].type == STORAGE_TYPE_EXTERNAL) &&
		 (player->storage_info[MMPLAYER_PATH_TEXT].state <= STORAGE_STATE_REMOVED))) {

		/* The error will be handled by mused.
		 * @ref _mmplayer_manage_external_storage_state() */

		LOGW("storage is removed, skip error post");
		return TRUE;
	}

	/* post error to application */
	if (!player->msg_posted) {
		MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
		/* don't post more if one was sent already */
		player->msg_posted = TRUE;
	} else {
		LOGD("skip error post because it's sent already.");
	}

	MMPLAYER_FLEAVE();

	return TRUE;
}

static gboolean
__mmplayer_handle_streaming_error(mmplayer_t *player, GstMessage *message)
{
	LOGD("\n");
	MMMessageParamType msg_param;
	gchar *msg_src_element = NULL;
	GstStructure *s = NULL;
	guint error_id = 0;
	gchar *error_string = NULL;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
	MMPLAYER_RETURN_VAL_IF_FAIL(message, FALSE);

	s = gst_structure_copy(gst_message_get_structure(message));


	if (!gst_structure_get_uint(s, "error_id", &error_id))
		error_id = MMPLAYER_STREAMING_ERROR_NONE;

	switch (error_id) {
	case MMPLAYER_STREAMING_ERROR_UNSUPPORTED_AUDIO:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_AUDIO;
		break;
	case MMPLAYER_STREAMING_ERROR_UNSUPPORTED_VIDEO:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_VIDEO;
		break;
	case MMPLAYER_STREAMING_ERROR_CONNECTION_FAIL:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_CONNECTION_FAIL;
		break;
	case MMPLAYER_STREAMING_ERROR_DNS_FAIL:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_DNS_FAIL;
		break;
	case MMPLAYER_STREAMING_ERROR_SERVER_DISCONNECTED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_SERVER_DISCONNECTED;
		break;
	case MMPLAYER_STREAMING_ERROR_BAD_SERVER:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_BAD_SERVER;
		break;
	case MMPLAYER_STREAMING_ERROR_INVALID_PROTOCOL:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_INVALID_PROTOCOL;
		break;
	case MMPLAYER_STREAMING_ERROR_INVALID_URL:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_INVALID_URL;
		break;
	case MMPLAYER_STREAMING_ERROR_UNEXPECTED_MSG:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_UNEXPECTED_MSG;
		break;
	case MMPLAYER_STREAMING_ERROR_OUT_OF_MEMORIES:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_OUT_OF_MEMORIES;
		break;
	case MMPLAYER_STREAMING_ERROR_RTSP_TIMEOUT:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_RTSP_TIMEOUT;
		break;
	case MMPLAYER_STREAMING_ERROR_BAD_REQUEST:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_BAD_REQUEST;
		break;
	case MMPLAYER_STREAMING_ERROR_NOT_AUTHORIZED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_NOT_AUTHORIZED;
		break;
	case MMPLAYER_STREAMING_ERROR_PAYMENT_REQUIRED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_PAYMENT_REQUIRED;
		break;
	case MMPLAYER_STREAMING_ERROR_FORBIDDEN:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_FORBIDDEN;
		break;
	case MMPLAYER_STREAMING_ERROR_CONTENT_NOT_FOUND:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_CONTENT_NOT_FOUND;
		break;
	case MMPLAYER_STREAMING_ERROR_METHOD_NOT_ALLOWED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_METHOD_NOT_ALLOWED;
		break;
	case MMPLAYER_STREAMING_ERROR_NOT_ACCEPTABLE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_NOT_ACCEPTABLE;
		break;
	case MMPLAYER_STREAMING_ERROR_PROXY_AUTHENTICATION_REQUIRED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_PROXY_AUTHENTICATION_REQUIRED;
		break;
	case MMPLAYER_STREAMING_ERROR_SERVER_TIMEOUT:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_SERVER_TIMEOUT;
		break;
	case MMPLAYER_STREAMING_ERROR_GONE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_GONE;
		break;
	case MMPLAYER_STREAMING_ERROR_LENGTH_REQUIRED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_LENGTH_REQUIRED;
		break;
	case MMPLAYER_STREAMING_ERROR_PRECONDITION_FAILED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_PRECONDITION_FAILED;
		break;
	case MMPLAYER_STREAMING_ERROR_REQUEST_ENTITY_TOO_LARGE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_REQUEST_ENTITY_TOO_LARGE;
		break;
	case MMPLAYER_STREAMING_ERROR_REQUEST_URI_TOO_LARGE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_REQUEST_URI_TOO_LARGE;
		break;
	case MMPLAYER_STREAMING_ERROR_UNSUPPORTED_MEDIA_TYPE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_UNSUPPORTED_MEDIA_TYPE;
		break;
	case MMPLAYER_STREAMING_ERROR_PARAMETER_NOT_UNDERSTOOD:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_PARAMETER_NOT_UNDERSTOOD;
		break;
	case MMPLAYER_STREAMING_ERROR_CONFERENCE_NOT_FOUND:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_CONFERENCE_NOT_FOUND;
		break;
	case MMPLAYER_STREAMING_ERROR_NOT_ENOUGH_BANDWIDTH:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_NOT_ENOUGH_BANDWIDTH;
		break;
	case MMPLAYER_STREAMING_ERROR_NO_SESSION_ID:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_NO_SESSION_ID;
		break;
	case MMPLAYER_STREAMING_ERROR_METHOD_NOT_VALID_IN_THIS_STATE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_METHOD_NOT_VALID_IN_THIS_STATE;
		break;
	case MMPLAYER_STREAMING_ERROR_HEADER_FIELD_NOT_VALID_FOR_SOURCE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_HEADER_FIELD_NOT_VALID_FOR_SOURCE;
		break;
	case MMPLAYER_STREAMING_ERROR_INVALID_RANGE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_INVALID_RANGE;
		break;
	case MMPLAYER_STREAMING_ERROR_PARAMETER_IS_READONLY:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_PARAMETER_IS_READONLY;
		break;
	case MMPLAYER_STREAMING_ERROR_AGGREGATE_OP_NOT_ALLOWED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_AGGREGATE_OP_NOT_ALLOWED;
		break;
	case MMPLAYER_STREAMING_ERROR_ONLY_AGGREGATE_OP_ALLOWED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_ONLY_AGGREGATE_OP_ALLOWED;
		break;
	case MMPLAYER_STREAMING_ERROR_BAD_TRANSPORT:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_BAD_TRANSPORT;
		break;
	case MMPLAYER_STREAMING_ERROR_DESTINATION_UNREACHABLE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_DESTINATION_UNREACHABLE;
		break;
	case MMPLAYER_STREAMING_ERROR_INTERNAL_SERVER_ERROR:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_INTERNAL_SERVER_ERROR;
		break;
	case MMPLAYER_STREAMING_ERROR_NOT_IMPLEMENTED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_NOT_IMPLEMENTED;
		break;
	case MMPLAYER_STREAMING_ERROR_BAD_GATEWAY:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_BAD_GATEWAY;
		break;
	case MMPLAYER_STREAMING_ERROR_SERVICE_UNAVAILABLE:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_SERVICE_UNAVAILABLE;
		break;
	case MMPLAYER_STREAMING_ERROR_GATEWAY_TIME_OUT:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_GATEWAY_TIME_OUT;
		break;
	case MMPLAYER_STREAMING_ERROR_RTSP_VERSION_NOT_SUPPORTED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_RTSP_VERSION_NOT_SUPPORTED;
		break;
	case MMPLAYER_STREAMING_ERROR_OPTION_NOT_SUPPORTED:
		msg_param.code = MM_ERROR_PLAYER_STREAMING_OPTION_NOT_SUPPORTED;
		break;
	default:
		{
			gst_structure_free(s);
			return MM_ERROR_PLAYER_STREAMING_FAIL;
		}
	}

	error_string = g_strdup(gst_structure_get_string(s, "error_string"));
	if (error_string)
		msg_param.data = (void *)error_string;

	if (message->src) {
		msg_src_element = GST_ELEMENT_NAME(GST_ELEMENT_CAST(message->src));

		LOGE("-Msg src : [%s] Code : [%x] Error : [%s]",
			msg_src_element, msg_param.code, (char *)msg_param.data);
	}

	/* post error to application */
	if (!player->msg_posted) {
		MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);

		/* don't post more if one was sent already */
		player->msg_posted = TRUE;
	} else {
		LOGD("skip error post because it's sent already.");
	}

	gst_structure_free(s);
	MMPLAYER_FREEIF(error_string);

	MMPLAYER_FLEAVE();
	return TRUE;

}

static void
__mmplayer_get_metadata_360_from_tags(GstTagList *tags, mmplayer_spherical_metadata_t *metadata)
{
	gst_tag_list_get_int(tags, "is_spherical", &metadata->is_spherical);
	gst_tag_list_get_int(tags, "is_stitched", &metadata->is_stitched);
	gst_tag_list_get_string(tags, "stitching_software",
			&metadata->stitching_software);
	gst_tag_list_get_string(tags, "projection_type",
			&metadata->projection_type_string);
	gst_tag_list_get_string(tags, "stereo_mode", &metadata->stereo_mode_string);
	gst_tag_list_get_int(tags, "source_count", &metadata->source_count);
	gst_tag_list_get_int(tags, "init_view_heading",
			&metadata->init_view_heading);
	gst_tag_list_get_int(tags, "init_view_pitch", &metadata->init_view_pitch);
	gst_tag_list_get_int(tags, "init_view_roll", &metadata->init_view_roll);
	gst_tag_list_get_int(tags, "timestamp", &metadata->timestamp);
	gst_tag_list_get_int(tags, "full_pano_width_pixels",
			&metadata->full_pano_width_pixels);
	gst_tag_list_get_int(tags, "full_pano_height_pixels",
			&metadata->full_pano_height_pixels);
	gst_tag_list_get_int(tags, "cropped_area_image_width",
			&metadata->cropped_area_image_width);
	gst_tag_list_get_int(tags, "cropped_area_image_height",
			&metadata->cropped_area_image_height);
	gst_tag_list_get_int(tags, "cropped_area_left",
			&metadata->cropped_area_left);
	gst_tag_list_get_int(tags, "cropped_area_top", &metadata->cropped_area_top);
	gst_tag_list_get_int(tags, "ambisonic_type", &metadata->ambisonic_type);
	gst_tag_list_get_int(tags, "ambisonic_format", &metadata->ambisonic_format);
	gst_tag_list_get_int(tags, "ambisonic_order", &metadata->ambisonic_order);
}

static gboolean
__mmplayer_gst_extract_tag_from_msg(mmplayer_t *player, GstMessage *msg)
{

/* macro for better code readability */
#define MMPLAYER_UPDATE_TAG_STRING(gsttag, attribute, playertag) \
	do { \
		if (gst_tag_list_get_string(tag_list, gsttag, &string)) {\
			if (string != NULL) { \
				SECURE_LOGD("update tag string : %s", string); \
				if (strlen(string) > MM_MAX_STRING_LENGTH) { \
					char *new_string = g_malloc(MM_MAX_STRING_LENGTH); \
					strncpy(new_string, string, MM_MAX_STRING_LENGTH - 1); \
					new_string[MM_MAX_STRING_LENGTH - 1] = '\0'; \
					mm_attrs_set_string_by_name(attribute, playertag, new_string); \
					MMPLAYER_FREEIF(new_string); \
				} else { \
					mm_attrs_set_string_by_name(attribute, playertag, string); \
				} \
				MMPLAYER_FREEIF(string); \
			} \
		} \
	} while (0)

#define MMPLAYER_UPDATE_TAG_IMAGE(gsttag, attribute, playertag) \
	do {	\
		GstSample *sample = NULL;\
		if (gst_tag_list_get_sample_index(tag_list, gsttag, index, &sample)) {\
			GstMapInfo info = GST_MAP_INFO_INIT;\
			buffer = gst_sample_get_buffer(sample);\
			if (!gst_buffer_map(buffer, &info, GST_MAP_READ)) {\
				LOGD("failed to get image data from tag");\
				gst_sample_unref(sample);\
				return FALSE;\
			} \
			SECURE_LOGD("update album cover data : %p, size : %zu", info.data, info.size);\
			MMPLAYER_FREEIF(player->album_art);\
			player->album_art = (gchar *)g_malloc(info.size);\
			if (player->album_art) {\
				memcpy(player->album_art, info.data, info.size);\
				mm_attrs_set_data_by_name(attribute, playertag, (void *)player->album_art, info.size);\
				if (MMPLAYER_IS_HTTP_LIVE_STREAMING(player)) {\
					msg_param.data = (void *)player->album_art;\
					msg_param.size = info.size;\
					MMPLAYER_POST_MSG(player, MM_MESSAGE_IMAGE_BUFFER, &msg_param);\
					SECURE_LOGD("post message image buffer data : %p, size : %zu", info.data, info.size);\
				} \
			} \
			gst_buffer_unmap(buffer, &info);\
			gst_sample_unref(sample);\
		}	\
	} while (0)

#define MMPLAYER_UPDATE_TAG_UINT(gsttag, attribute, playertag) \
	do {	\
		if (gst_tag_list_get_uint(tag_list, gsttag, &v_uint)) { \
			if (v_uint) { \
				int i = 0; \
				mmplayer_track_type_e track_type = MM_PLAYER_TRACK_TYPE_AUDIO; \
				if (strstr(GST_OBJECT_NAME(msg->src), "audio")) \
					track_type = MM_PLAYER_TRACK_TYPE_AUDIO; \
				else if (strstr(GST_OBJECT_NAME(msg->src), "video")) \
					track_type = MM_PLAYER_TRACK_TYPE_VIDEO; \
				else \
					track_type = MM_PLAYER_TRACK_TYPE_TEXT; \
				if (!strncmp(gsttag, GST_TAG_BITRATE, strlen(GST_TAG_BITRATE))) { \
					if (track_type == MM_PLAYER_TRACK_TYPE_AUDIO) \
						mm_attrs_set_int_by_name(attribute, "content_audio_bitrate", v_uint); \
					player->bitrate[track_type] = v_uint; \
					player->total_bitrate = 0; \
					for (i = 0; i < MM_PLAYER_STREAM_COUNT_MAX; i++) \
						player->total_bitrate += player->bitrate[i]; \
					mm_attrs_set_int_by_name(attribute, playertag, player->total_bitrate); \
					SECURE_LOGD("update bitrate %d[bps] of stream #%d.", v_uint, (int)track_type); \
				} else if (!strncmp(gsttag, GST_TAG_MAXIMUM_BITRATE, strlen(GST_TAG_MAXIMUM_BITRATE))) { \
					player->maximum_bitrate[track_type] = v_uint; \
					player->total_maximum_bitrate = 0; \
					for (i = 0; i < MM_PLAYER_STREAM_COUNT_MAX; i++) \
						player->total_maximum_bitrate += player->maximum_bitrate[i]; \
					mm_attrs_set_int_by_name(attribute, playertag, player->total_maximum_bitrate);\
					SECURE_LOGD("update maximum bitrate %d[bps] of stream #%d", v_uint, (int)track_type);\
				} else { \
					mm_attrs_set_int_by_name(attribute, playertag, v_uint); \
				} \
				v_uint = 0;\
			} \
		} \
	} while (0)

#define MMPLAYER_UPDATE_TAG_DATE(gsttag, attribute, playertag) \
	do { \
		if (gst_tag_list_get_date(tag_list, gsttag, &date)) {\
			if (date != NULL) {\
				string = g_strdup_printf("%d", g_date_get_year(date));\
				mm_attrs_set_string_by_name(attribute, playertag, string);\
				SECURE_LOGD("metainfo year : %s", string);\
				MMPLAYER_FREEIF(string);\
				g_date_free(date);\
			} \
		} \
	} while (0)

#define MMPLAYER_UPDATE_TAG_DATE_TIME(gsttag, attribute, playertag) \
	do { \
		if (gst_tag_list_get_date_time(tag_list, gsttag, &datetime)) {\
			if (datetime != NULL) {\
				string = g_strdup_printf("%d", gst_date_time_get_year(datetime));\
				mm_attrs_set_string_by_name(attribute, playertag, string);\
				SECURE_LOGD("metainfo year : %s", string);\
				MMPLAYER_FREEIF(string);\
				gst_date_time_unref(datetime);\
			} \
		} \
	} while (0)

#define MMPLAYER_UPDATE_TAG_UINT64(gsttag, attribute, playertag) \
	do { \
		if (gst_tag_list_get_uint64(tag_list, gsttag, &v_uint64)) {\
			if (v_uint64) {\
				/* FIXIT : don't know how to store date */\
				g_assert(1);\
				v_uint64 = 0;\
			} \
		} \
	} while (0)

#define MMPLAYER_UPDATE_TAG_DOUBLE(gsttag, attribute, playertag) \
	do { \
		if (gst_tag_list_get_double(tag_list, gsttag, &v_double)) {\
			if (v_double) {\
				/* FIXIT : don't know how to store date */\
				g_assert(1);\
				v_double = 0;\
			} \
		} \
	} while (0)

	/* function start */
	GstTagList *tag_list = NULL;

	MMHandleType attrs = 0;

	char *string = NULL;
	guint v_uint = 0;
	GDate *date = NULL;
	GstDateTime *datetime = NULL;
	/* album cover */
	GstBuffer *buffer = NULL;
	gint index = 0;
	MMMessageParamType msg_param = {0, };

	/* currently not used. but those are needed for above macro */
	//guint64 v_uint64 = 0;
	//gdouble v_double = 0;

	MMPLAYER_RETURN_VAL_IF_FAIL(player && msg, FALSE);

	attrs = MMPLAYER_GET_ATTRS(player);

	MMPLAYER_RETURN_VAL_IF_FAIL(attrs, FALSE);

	/* get tag list from gst message */
	gst_message_parse_tag(msg, &tag_list);

	/* store tags to player attributes */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_TITLE, attrs, "tag_title");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_TITLE_SORTNAME, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ARTIST, attrs, "tag_artist");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ARTIST_SORTNAME, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ALBUM, attrs, "tag_album");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ALBUM_SORTNAME, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_COMPOSER, attrs, "tag_author");
	MMPLAYER_UPDATE_TAG_DATE(GST_TAG_DATE, attrs, "tag_date");
	MMPLAYER_UPDATE_TAG_DATE_TIME(GST_TAG_DATE_TIME, attrs, "tag_date");
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_GENRE, attrs, "tag_genre");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_COMMENT, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_EXTENDED_COMMENT, ?, ?); */
	MMPLAYER_UPDATE_TAG_UINT(GST_TAG_TRACK_NUMBER, attrs, "tag_track_num");
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_TRACK_COUNT, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_ALBUM_VOLUME_NUMBER, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_ALBUM_VOLUME_COUNT, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_LOCATION, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_DESCRIPTION, attrs, "tag_description");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_VERSION, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ISRC, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ORGANIZATION, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_COPYRIGHT, attrs, "tag_copyright");
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_COPYRIGHT_URI, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_CONTACT, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_LICENSE, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_LICENSE_URI, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_PERFORMER, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT64(GST_TAG_DURATION, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_CODEC, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_VIDEO_CODEC, attrs, "content_video_codec");
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_AUDIO_CODEC, attrs, "content_audio_codec");
	MMPLAYER_UPDATE_TAG_UINT(GST_TAG_BITRATE, attrs, "content_bitrate");
	MMPLAYER_UPDATE_TAG_UINT(GST_TAG_MAXIMUM_BITRATE, attrs, "content_max_bitrate");
	MMPLAYER_UPDATE_TAG_LOCK(player);
	MMPLAYER_UPDATE_TAG_IMAGE(GST_TAG_IMAGE, attrs, "tag_album_cover");
	MMPLAYER_UPDATE_TAG_UNLOCK(player);
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_NOMINAL_BITRATE, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_MINIMUM_BITRATE, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_SERIAL, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_ENCODER, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_UINT(GST_TAG_ENCODER_VERSION, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_TRACK_GAIN, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_TRACK_PEAK, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_ALBUM_GAIN, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_ALBUM_PEAK, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_REFERENCE_LEVEL, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_STRING(GST_TAG_LANGUAGE_CODE, ?, ?); */
	/* MMPLAYER_UPDATE_TAG_DOUBLE(GST_TAG_BEATS_PER_MINUTE, ?, ?); */
	MMPLAYER_UPDATE_TAG_STRING(GST_TAG_IMAGE_ORIENTATION, attrs, "content_video_orientation");

	if (strstr(GST_OBJECT_NAME(msg->src), "demux")) {
		if (player->video360_metadata.is_spherical == -1) {
			__mmplayer_get_metadata_360_from_tags(tag_list, &player->video360_metadata);
			mm_attrs_set_int_by_name(attrs, "content_video_is_spherical",
					player->video360_metadata.is_spherical);
			if (player->video360_metadata.is_spherical == 1) {
				LOGD("This is spherical content for 360 playback.");
				player->is_content_spherical = TRUE;
			} else {
				LOGD("This is not spherical content");
				player->is_content_spherical = FALSE;
			}

			if (player->video360_metadata.projection_type_string) {
				if (!strcmp(player->video360_metadata.projection_type_string, "equirectangular")) {
					player->video360_metadata.projection_type = VIDEO360_PROJECTION_TYPE_EQUIRECTANGULAR;
				} else {
					LOGE("Projection %s: code not implemented.", player->video360_metadata.projection_type_string);
					player->is_content_spherical = player->is_video360_enabled = FALSE;
				}
			}

			if (player->video360_metadata.stereo_mode_string) {
				if (!strcmp(player->video360_metadata.stereo_mode_string, "mono")) {
					player->video360_metadata.stereo_mode = VIDEO360_MODE_MONOSCOPIC;
				} else if (!strcmp(player->video360_metadata.stereo_mode_string, "left-right")) {
					player->video360_metadata.stereo_mode = VIDEO360_MODE_STEREOSCOPIC_LEFT_RIGHT;
				} else if (!strcmp(player->video360_metadata.stereo_mode_string, "top-bottom")) {
					player->video360_metadata.stereo_mode = VIDEO360_MODE_STEREOSCOPIC_TOP_BOTTOM;
				} else {
					LOGE("Stereo mode %s: code not implemented.", player->video360_metadata.stereo_mode_string);
					player->is_content_spherical = player->is_video360_enabled = FALSE;
				}
			}
		}
	}

	if (mm_attrs_commit_all(attrs))
		LOGE("failed to commit.");

	gst_tag_list_unref(tag_list);

	return TRUE;
}

/* if retval is FALSE, it will be dropped for perfomance. */
static gboolean
__mmplayer_gst_check_useful_message(mmplayer_t *player, GstMessage *message)
{
	gboolean retval = FALSE;

	if (!(player->pipeline && player->pipeline->mainbin)) {
		LOGE("player pipeline handle is null");
		return TRUE;
	}

	switch (GST_MESSAGE_TYPE(message)) {
	case GST_MESSAGE_TAG:
	case GST_MESSAGE_EOS:
	case GST_MESSAGE_ERROR:
	case GST_MESSAGE_WARNING:
	case GST_MESSAGE_CLOCK_LOST:
	case GST_MESSAGE_NEW_CLOCK:
	case GST_MESSAGE_ELEMENT:
	case GST_MESSAGE_DURATION_CHANGED:
	case GST_MESSAGE_ASYNC_START:
		retval = TRUE;
		break;
	case GST_MESSAGE_ASYNC_DONE:
	case GST_MESSAGE_STATE_CHANGED:
		/* we only handle messages from pipeline */
		if ((message->src == (GstObject *)player->pipeline->mainbin[MMPLAYER_M_PIPE].gst) && (!player->gapless.reconfigure))
			retval = TRUE;
		else
			retval = FALSE;
		break;
	case GST_MESSAGE_BUFFERING:
	{
		gint buffer_percent = 0;

		retval = TRUE;
		gst_message_parse_buffering(message, &buffer_percent);
		if (buffer_percent != MAX_BUFFER_PERCENT) {
			LOGD("[%s] buffering msg %d%%!!", GST_OBJECT_NAME(GST_MESSAGE_SRC(message)), buffer_percent);
			break;
		}

		if (!MMPLAYER_CMD_TRYLOCK(player)) {
			LOGW("can't get cmd lock, send msg to bus");
			break;
		}

		if ((player->streamer) && (player->streamer->buffering_state & MM_PLAYER_BUFFERING_IN_PROGRESS)) {
			LOGD("[%s] Buffering DONE is detected !", GST_OBJECT_NAME(GST_MESSAGE_SRC(message)));
			player->streamer->buffering_state |= MM_PLAYER_BUFFERING_COMPLETE;
		}

		MMPLAYER_CMD_UNLOCK(player);

		break;
	}
	default:
		retval = FALSE;
		break;
	}

	return retval;
}

static void
__mmplayer_update_buffer_setting(mmplayer_t *player, GstMessage *buffering_msg)
{
	guint64 data_size = 0;
	gint64 pos_nsec = 0;

	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);

	_mmplayer_gst_get_position(player, &pos_nsec);	/* to update player->last_position */

	if (MMPLAYER_IS_HTTP_STREAMING(player)) {
		data_size = player->http_content_size;
	}

	_mm_player_streaming_buffering(player->streamer, buffering_msg, data_size, player->last_position, player->duration);
	_mm_player_streaming_sync_property(player->streamer, player->pipeline->mainbin[MMPLAYER_M_AUTOPLUG].gst);

	return;
}

static int
__mmplayer_handle_buffering_playback(mmplayer_t *player)
{
	int ret = MM_ERROR_NONE;
	mmplayer_state_e prev_state = MM_PLAYER_STATE_NONE;
	mmplayer_state_e current_state = MM_PLAYER_STATE_NONE;
	mmplayer_state_e target_state = MM_PLAYER_STATE_NONE;
	mmplayer_state_e pending_state = MM_PLAYER_STATE_NONE;

	if (!player || !player->streamer || (MMPLAYER_IS_LIVE_STREAMING(player) && MMPLAYER_IS_RTSP_STREAMING(player))) {
		LOGW("do nothing for buffering msg");
		ret = MM_ERROR_PLAYER_INVALID_STATE;
		goto exit;
	}

	prev_state = MMPLAYER_PREV_STATE(player);
	current_state = MMPLAYER_CURRENT_STATE(player);
	target_state = MMPLAYER_TARGET_STATE(player);
	pending_state = MMPLAYER_PENDING_STATE(player);

	LOGD("player state : prev %s, current %s, pending %s, target %s, buffering state 0x%X",
		MMPLAYER_STATE_GET_NAME(prev_state),
		MMPLAYER_STATE_GET_NAME(current_state),
		MMPLAYER_STATE_GET_NAME(pending_state),
		MMPLAYER_STATE_GET_NAME(target_state),
		player->streamer->buffering_state);

	if (!(player->streamer->buffering_state & MM_PLAYER_BUFFERING_IN_PROGRESS)) {
		/* NOTE : if buffering has done, player has to go to target state. */
		switch (target_state) {
		case MM_PLAYER_STATE_PAUSED:
			{
				switch (pending_state) {
				case MM_PLAYER_STATE_PLAYING:
					_mmplayer_gst_pause(player, TRUE);
					break;

				case MM_PLAYER_STATE_PAUSED:
					LOGD("player is already going to paused state, there is nothing to do.");
					break;

				case MM_PLAYER_STATE_NONE:
				case MM_PLAYER_STATE_NULL:
				case MM_PLAYER_STATE_READY:
				default:
					LOGW("invalid pending state [%s].", MMPLAYER_STATE_GET_NAME(pending_state));
					break;
				}
			}
			break;

		case MM_PLAYER_STATE_PLAYING:
			{
				switch (pending_state) {
				case MM_PLAYER_STATE_NONE:
					{
						if (current_state != MM_PLAYER_STATE_PLAYING)
							_mmplayer_gst_resume(player, TRUE);
					}
					break;

				case MM_PLAYER_STATE_PAUSED:
					/* NOTE: It should be worked as asynchronously.
					 * Because, buffering can be completed during autoplugging when pipeline would try to go playing state directly.
					 */
					if (current_state == MM_PLAYER_STATE_PLAYING) {
						/* NOTE: If the current state is PLAYING, it means, async _mmplayer_gst_pause() is not completed yet.
						 * The current state should be changed to paused purposely to prevent state conflict.
						 */
						MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PAUSED);
					}
					_mmplayer_gst_resume(player, TRUE);
					break;

				case MM_PLAYER_STATE_PLAYING:
					LOGD("player is already going to playing state, there is nothing to do.");
					break;

				case MM_PLAYER_STATE_NULL:
				case MM_PLAYER_STATE_READY:
				default:
					LOGW("invalid pending state [%s].", MMPLAYER_STATE_GET_NAME(pending_state));
					break;
				}
			}
			break;

		case MM_PLAYER_STATE_NULL:
		case MM_PLAYER_STATE_READY:
		case MM_PLAYER_STATE_NONE:
		default:
			LOGW("invalid target state [%s].", MMPLAYER_STATE_GET_NAME(target_state));
			break;
		}
	} else {
		/* NOTE : during the buffering, pause the player for stopping pipeline clock.
		 *	it's for stopping the pipeline clock to prevent dropping the data in sink element.
		 */
		switch (pending_state) {
		case MM_PLAYER_STATE_NONE:
			{
				if (current_state != MM_PLAYER_STATE_PAUSED) {
					/* rtsp streaming pause makes rtsp server stop sending data. */
					if (!MMPLAYER_IS_RTSP_STREAMING(player)) {
						LOGD("set pause state during buffering");
						_mmplayer_gst_pause(player, TRUE);
					}
				}
			}
			break;

		case MM_PLAYER_STATE_PLAYING:
			/* rtsp streaming pause makes rtsp server stop sending data. */
			if (!MMPLAYER_IS_RTSP_STREAMING(player))
				_mmplayer_gst_pause(player, TRUE);
			break;

		case MM_PLAYER_STATE_PAUSED:
			break;

		case MM_PLAYER_STATE_NULL:
		case MM_PLAYER_STATE_READY:
		default:
			LOGW("invalid pending state [%s].", MMPLAYER_STATE_GET_NAME(pending_state));
			break;
		}
	}

exit:
	return ret;
}

static stream_variant_t *
__mmplayer_adaptive_var_info(const stream_variant_t *self, gpointer user_data)
{
	stream_variant_t *var_info = NULL;
	g_return_val_if_fail(self != NULL, NULL);

	var_info = g_new0(stream_variant_t, 1);
	if (!var_info) return NULL;
	var_info->bandwidth = self->bandwidth;
	var_info->width = self->width;
	var_info->height = self->height;
	return var_info;
}

static gboolean
__mmplayer_gst_handle_duration(mmplayer_t *player, GstMessage *msg)
{
	gint64 bytes = 0;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
	MMPLAYER_RETURN_VAL_IF_FAIL(msg, FALSE);

	if ((MMPLAYER_IS_HTTP_STREAMING(player)) &&
		(msg->src) && (msg->src == (GstObject *)player->pipeline->mainbin[MMPLAYER_M_SRC].gst)) {
		LOGD("msg src : [%s]", GST_ELEMENT_NAME(GST_ELEMENT_CAST(msg->src)));

		if (gst_element_query_duration(GST_ELEMENT_CAST(msg->src), GST_FORMAT_BYTES, &bytes)) {
			LOGD("data total size of http content: %"G_GINT64_FORMAT, bytes);
			player->http_content_size = (bytes > 0) ? bytes : 0;
		}
	} else {
		/* handling audio clip which has vbr. means duration is keep changing */
		_mmplayer_update_content_attrs(player, ATTR_DURATION);
	}

	MMPLAYER_FLEAVE();

	return TRUE;
}

static gboolean
__mmplayer_eos_timer_cb(gpointer u_data)
{
	mmplayer_t *player = NULL;
	MMHandleType attrs = 0;
	int count = 0;

	MMPLAYER_RETURN_VAL_IF_FAIL(u_data, FALSE);

	player = (mmplayer_t *)u_data;
	attrs = MMPLAYER_GET_ATTRS(player);

	mm_attrs_get_int_by_name(attrs, "profile_play_count", &count);

	if (count == -1) {
		gint ret_value = 0;
		ret_value = _mmplayer_gst_set_position(player, 0, TRUE);
		if (ret_value != MM_ERROR_NONE)
			LOGE("seeking to 0 failed in repeat play");
	} else {
		/* posting eos */
		MMPLAYER_POST_MSG(player, MM_MESSAGE_END_OF_STREAM, NULL);
	}

	/* we are returning FALSE as we need only one posting */
	return FALSE;
}

static void
__mmplayer_handle_eos_delay(mmplayer_t *player, int delay_in_ms)
{
	MMPLAYER_RETURN_IF_FAIL(player);

	/* post now if delay is zero */
	if (delay_in_ms == 0 || player->audio_decoded_cb) {
		LOGD("eos delay is zero. posting EOS now");
		MMPLAYER_POST_MSG(player, MM_MESSAGE_END_OF_STREAM, NULL);

		if (player->audio_decoded_cb)
			_mmplayer_cancel_eos_timer(player);

		return;
	}

	/* cancel if existing */
	_mmplayer_cancel_eos_timer(player);

	/* init new timeout */
	/* NOTE : consider give high priority to this timer */
	LOGD("posting EOS message after [%d] msec", delay_in_ms);

	player->eos_timer = g_timeout_add(delay_in_ms,
		__mmplayer_eos_timer_cb, player);

	player->context.global_default = g_main_context_default();
	LOGD("global default context = %p, eos timer id = %d", player->context.global_default, player->eos_timer);

	/* check timer is valid. if not, send EOS now */
	if (player->eos_timer == 0) {
		LOGW("creating timer for delayed EOS has failed. sending EOS now");
		MMPLAYER_POST_MSG(player, MM_MESSAGE_END_OF_STREAM, NULL);
	}
}

static int
__mmplayer_gst_pending_seek(mmplayer_t *player)
{
	mmplayer_state_e current_state = MM_PLAYER_STATE_NONE;
	int ret = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);

	if (!player->pending_seek.is_pending) {
		LOGD("pending seek is not reserved. nothing to do.");
		return ret;
	}

	/* check player state if player could pending seek or not. */
	current_state = MMPLAYER_CURRENT_STATE(player);

	if (current_state != MM_PLAYER_STATE_PAUSED && current_state != MM_PLAYER_STATE_PLAYING) {
		LOGW("try to pending seek in %s state, try next time. ",
			MMPLAYER_STATE_GET_NAME(current_state));
		return ret;
	}

	LOGD("trying to play from(%"G_GINT64_FORMAT") pending position", player->pending_seek.pos);

	ret = _mmplayer_gst_set_position(player, player->pending_seek.pos, FALSE);
	if (ret != MM_ERROR_NONE)
		LOGE("failed to seek pending postion. just keep staying current position.");

	player->pending_seek.is_pending = false;

	MMPLAYER_FLEAVE();

	return ret;
}

static void
__mmplayer_gst_set_async(mmplayer_t *player, gboolean async, enum mmplayer_sink_type  type)
{
	mmplayer_gst_element_t *videobin = NULL, *audiobin = NULL, *textbin = NULL;

	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline);

	audiobin = player->pipeline->audiobin; /* can be null */
	videobin = player->pipeline->videobin; /* can be null */
	textbin = player->pipeline->textbin;   /* can be null */

	LOGD("Async will be set to %d about 0x%X type sink", async, type);

	if ((type & MMPLAYER_AUDIO_SINK) && audiobin && audiobin[MMPLAYER_A_SINK].gst)
		g_object_set(audiobin[MMPLAYER_A_SINK].gst, "async", async, NULL);

	if ((type & MMPLAYER_VIDEO_SINK) && videobin && videobin[MMPLAYER_V_SINK].gst)
		g_object_set(videobin[MMPLAYER_V_SINK].gst, "async", async, NULL);

	if ((type & MMPLAYER_TEXT_SINK) && textbin && textbin[MMPLAYER_T_FAKE_SINK].gst)
		g_object_set(textbin[MMPLAYER_T_FAKE_SINK].gst, "async", async, NULL);

	return;
}

static void
__mmplayer_drop_subtitle(mmplayer_t *player, gboolean is_drop)
{
	mmplayer_gst_element_t *textbin;
	MMPLAYER_FENTER();

	MMPLAYER_RETURN_IF_FAIL(player &&
					player->pipeline &&
					player->pipeline->textbin);

	MMPLAYER_RETURN_IF_FAIL(player->pipeline->textbin[MMPLAYER_T_IDENTITY].gst);

	textbin = player->pipeline->textbin;

	if (is_drop) {
		LOGD("Drop subtitle text after getting EOS");

		__mmplayer_gst_set_async(player, FALSE, MMPLAYER_TEXT_SINK);
		g_object_set(textbin[MMPLAYER_T_IDENTITY].gst, "drop-probability", (gfloat)1.0, NULL);

		player->is_subtitle_force_drop = TRUE;
	} else {
		if (player->is_subtitle_force_drop == TRUE) {
			LOGD("Enable subtitle data path without drop");

			g_object_set(textbin[MMPLAYER_T_IDENTITY].gst, "drop-probability", (gfloat)0.0, NULL);
			__mmplayer_gst_set_async(player, TRUE, MMPLAYER_TEXT_SINK);

			LOGD("non-connected with external display");

			player->is_subtitle_force_drop = FALSE;
		}
	}
}

static void
__mmplayer_gst_handle_eos_message(mmplayer_t *player, GstMessage *msg)
{
	MMHandleType attrs = 0;
	gint count = 0;

	MMPLAYER_FENTER();

	/* NOTE : EOS event is comming multiple time. watch out it */
	/* check state. we only process EOS when pipeline state goes to PLAYING */
	if (!(player->cmd == MMPLAYER_COMMAND_START || player->cmd == MMPLAYER_COMMAND_RESUME)) {
		LOGD("EOS received on non-playing state. ignoring it");
		return;
	}

	if (player->pipeline && player->pipeline->textbin)
		__mmplayer_drop_subtitle(player, TRUE);

	if ((player->audio_decoded_cb) && (player->audio_extract_opt & MM_PLAYER_AUDIO_EXTRACT_NO_SYNC_WITH_CLOCK))
		_mmplayer_audio_stream_clear_buffer(player, TRUE);

	/* rewind if repeat count is greater then zero */
	/* get play count */
	attrs = MMPLAYER_GET_ATTRS(player);
	if (attrs) {
		mm_attrs_get_int_by_name(attrs, "profile_play_count", &count);

		LOGD("play count: %d, playback rate: %f", count, player->playback_rate);

		if (count == -1 || player->playback_rate < 0.0) /* default value is 1 */ {
			if (player->playback_rate < 0.0) {
				player->resumed_by_rewind = TRUE;
				_mmplayer_set_mute((MMHandleType)player, false);
				MMPLAYER_POST_MSG(player, MM_MESSAGE_RESUMED_BY_REW, NULL);
			}

			__mmplayer_handle_eos_delay(player, player->ini.delay_before_repeat);

			/* initialize */
			player->sent_bos = FALSE;

			LOGD("do not post eos msg for repeating");
			return;
		}
	}

	if (player->pipeline)
		MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-eos");

	/* post eos message to application */
	__mmplayer_handle_eos_delay(player, player->ini.eos_delay);

	/* reset last position */
	player->last_position = 0;

	MMPLAYER_FLEAVE();
	return;
}

static void
__mmplayer_gst_handle_error_message(mmplayer_t *player, GstMessage *msg)
{
	GError *error = NULL;
	gchar *debug = NULL;

	MMPLAYER_FENTER();

	/* generating debug info before returning error */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-error");

	/* get error code */
	gst_message_parse_error(msg, &error, &debug);

	if (gst_structure_has_name(gst_message_get_structure(msg), "streaming_error")) {
		/* Note : the streaming error from the streaming source is handled
		 *	 using __mmplayer_handle_streaming_error.
		 */
		__mmplayer_handle_streaming_error(player, msg);

		/* dump state of all element */
		_mmplayer_dump_pipeline_state(player);
	} else {
		/* traslate gst error code to msl error code. then post it
		 * to application if needed
		 */
		__mmplayer_handle_gst_error(player, msg, error);

		if (debug)
			LOGE("error debug : %s", debug);
	}

	MMPLAYER_FREEIF(debug);
	g_error_free(error);

	MMPLAYER_FLEAVE();
	return;
}

static void
__mmplayer_gst_handle_buffering_message(mmplayer_t *player, GstMessage *msg)
{
	MMMessageParamType msg_param = {0, };
	int bRet = MM_ERROR_NONE;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);

	if (!MMPLAYER_IS_STREAMING(player)) {
		LOGW("this is not streaming playback.");
		return;
	}

	MMPLAYER_CMD_LOCK(player);

	if (!player->streamer) {
		LOGW("Pipeline is shutting down");
		MMPLAYER_CMD_UNLOCK(player);
		return;
	}

	/* ignore the remained buffering message till getting 100% msg */
	if (player->streamer->buffering_state == MM_PLAYER_BUFFERING_COMPLETE) {
		gint buffer_percent = 0;

		gst_message_parse_buffering(msg, &buffer_percent);

		if (buffer_percent == MAX_BUFFER_PERCENT) {
			LOGD("Ignored all the previous buffering msg!(got %d%%)", buffer_percent);
			__mmplayer_update_buffer_setting(player, NULL); /* update buffering size for next buffering */
			player->streamer->buffering_state = MM_PLAYER_BUFFERING_DEFAULT;
		}
		MMPLAYER_CMD_UNLOCK(player);
		return;
	}

	/* ignore the remained buffering message */
	if (player->streamer->buffering_state == MM_PLAYER_BUFFERING_ABORT) {
		gint buffer_percent = 0;

		gst_message_parse_buffering(msg, &buffer_percent);

		LOGD("interrupted buffering -last posted %d %%, new per %d %%",
					player->streamer->buffering_percent, buffer_percent);

		if (player->streamer->buffering_percent > buffer_percent || buffer_percent <= 0) {
			player->streamer->buffering_state = MM_PLAYER_BUFFERING_DEFAULT;
			player->streamer->buffering_req.is_pre_buffering = FALSE;

			LOGD("interrupted buffering - need to enter the buffering mode again - %d %%", buffer_percent);
		} else {
			LOGD("interrupted buffering - ignored the remained buffering msg!");
			MMPLAYER_CMD_UNLOCK(player);
			return;
		}
	}

	__mmplayer_update_buffer_setting(player, msg);

	bRet = __mmplayer_handle_buffering_playback(player); /* playback control */

	if (bRet == MM_ERROR_NONE) {
		msg_param.connection.buffering = player->streamer->buffering_percent;
		MMPLAYER_POST_MSG(player, MM_MESSAGE_BUFFERING, &msg_param);

		if (MMPLAYER_IS_RTSP_STREAMING(player) &&
			player->pending_resume &&
			(player->streamer->buffering_percent >= MAX_BUFFER_PERCENT)) {

			player->is_external_subtitle_added_now = FALSE;
			player->pending_resume = FALSE;
			_mmplayer_resume((MMHandleType)player);
		}

		if (MMPLAYER_IS_RTSP_STREAMING(player) &&
			(player->streamer->buffering_percent >= MAX_BUFFER_PERCENT)) {

			if (player->seek_state == MMPLAYER_SEEK_IN_PROGRESS) {
				if (MMPLAYER_TARGET_STATE(player) == MM_PLAYER_STATE_PAUSED) {
					player->seek_state = MMPLAYER_SEEK_NONE;
					MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
				} else if (MMPLAYER_TARGET_STATE(player) == MM_PLAYER_STATE_PLAYING) {
					/* Considering the async state trasition in case of RTSP.
					   After getting state change gst msg, seek cmpleted msg will be posted. */
					player->seek_state = MMPLAYER_SEEK_COMPLETED;
				}
			}
		}
	} else if (bRet == MM_ERROR_PLAYER_INVALID_STATE) {
		if (!player->streamer) {
			LOGW("player->streamer is NULL, so discarding the buffering percent update");
			MMPLAYER_CMD_UNLOCK(player);
			return;
		}

		if ((MMPLAYER_IS_LIVE_STREAMING(player)) && (MMPLAYER_IS_RTSP_STREAMING(player))) {

			LOGD("player->last_position=%"G_GINT64_FORMAT" , player->streamer->buffering_percent=%d",
					GST_TIME_AS_SECONDS(player->last_position), player->streamer->buffering_percent);

			if ((GST_TIME_AS_SECONDS(player->last_position) <= 0) && (MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PAUSED)) {
				msg_param.connection.buffering = player->streamer->buffering_percent;
				MMPLAYER_POST_MSG(player, MM_MESSAGE_BUFFERING, &msg_param);
			} else {
				LOGD("Not updating Buffering Message for Live RTSP case !!!");
			}
		} else {
			msg_param.connection.buffering = player->streamer->buffering_percent;
			MMPLAYER_POST_MSG(player, MM_MESSAGE_BUFFERING, &msg_param);
		}
	}
	MMPLAYER_CMD_UNLOCK(player);

	MMPLAYER_FLEAVE();
	return;

}

static void
__mmplayer_gst_handle_state_message(mmplayer_t *player, GstMessage *msg)
{
	mmplayer_gst_element_t *mainbin;
	const GValue *voldstate, *vnewstate, *vpending;
	GstState oldstate = GST_STATE_NULL;
	GstState newstate = GST_STATE_NULL;
	GstState pending = GST_STATE_NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);

	mainbin = player->pipeline->mainbin;

	/* we only handle messages from pipeline */
	if (msg->src != (GstObject *)mainbin[MMPLAYER_M_PIPE].gst)
		return;

	/* get state info from msg */
	voldstate = gst_structure_get_value(gst_message_get_structure(msg), "old-state");
	vnewstate = gst_structure_get_value(gst_message_get_structure(msg), "new-state");
	vpending = gst_structure_get_value(gst_message_get_structure(msg), "pending-state");

	if (!voldstate || !vnewstate) {
		LOGE("received msg has wrong format.");
		return;
	}

	oldstate = (GstState)voldstate->data[0].v_int;
	newstate = (GstState)vnewstate->data[0].v_int;
	if (vpending)
		pending = (GstState)vpending->data[0].v_int;

	LOGD("state changed [%s] : %s ---> %s	  final : %s",
		GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)),
		gst_element_state_get_name((GstState)oldstate),
		gst_element_state_get_name((GstState)newstate),
		gst_element_state_get_name((GstState)pending));

	if (newstate == GST_STATE_PLAYING) {
		if ((MMPLAYER_IS_RTSP_STREAMING(player)) && (player->pending_seek.is_pending)) {

			int retVal = MM_ERROR_NONE;
			LOGD("trying to play from (%"G_GINT64_FORMAT") pending position", player->pending_seek.pos);

			retVal = _mmplayer_gst_set_position(player, player->pending_seek.pos, TRUE);

			if (MM_ERROR_NONE != retVal)
				LOGE("failed to seek pending postion. just keep staying current position.");

			player->pending_seek.is_pending = false;
		}
	}

	if (oldstate == newstate) {
		LOGD("pipeline reports state transition to old state");
		return;
	}

	switch (newstate) {
	case GST_STATE_PAUSED:
		{
			gboolean prepare_async = FALSE;

			if (!player->sent_bos && oldstate == GST_STATE_READY) {
				// managed prepare async case
				mm_attrs_get_int_by_name(player->attrs, "profile_prepare_async", &prepare_async);
				LOGD("checking prepare mode for async transition - %d", prepare_async);
			}

			if (MMPLAYER_IS_STREAMING(player) || MMPLAYER_IS_MS_BUFF_SRC(player) || prepare_async) {
				MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PAUSED);

				if (MMPLAYER_IS_STREAMING(player) && (player->streamer))
					_mm_player_streaming_set_content_bitrate(player->streamer,
						player->total_maximum_bitrate, player->total_bitrate);

				if (player->pending_seek.is_pending) {
					LOGW("trying to do pending seek");
					MMPLAYER_CMD_LOCK(player);
					__mmplayer_gst_pending_seek(player);
					MMPLAYER_CMD_UNLOCK(player);
				}
			}
		}
		break;

	case GST_STATE_PLAYING:
		{
			if (MMPLAYER_IS_STREAMING(player)) {
				// managed prepare async case when buffering is completed
				// pending state should be reset otherwise, it's still playing even though it's resumed after bufferging.
				if ((MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING) ||
					(MMPLAYER_PENDING_STATE(player) == MM_PLAYER_STATE_PLAYING))
					MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PLAYING);

				if (MMPLAYER_IS_RTSP_STREAMING(player) && (MMPLAYER_IS_LIVE_STREAMING(player))) {

					LOGD("Current Buffering Percent = %d", player->streamer->buffering_percent);
					if (player->streamer->buffering_percent < 100) {

						MMMessageParamType msg_param = {0, };
						LOGW("Posting Buffering Completed Message to Application !!!");

						msg_param.connection.buffering = 100;
						MMPLAYER_POST_MSG(player, MM_MESSAGE_BUFFERING, &msg_param);
					}
				}
			}

			if (player->gapless.stream_changed) {
				_mmplayer_update_content_attrs(player, ATTR_ALL);
				player->gapless.stream_changed = FALSE;
			}

			if (player->seek_state == MMPLAYER_SEEK_COMPLETED) {
				player->seek_state = MMPLAYER_SEEK_NONE;
				MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
			}
		}
		break;
	case GST_STATE_VOID_PENDING:
	case GST_STATE_NULL:
	case GST_STATE_READY:
	default:
		break;
	}

	MMPLAYER_FLEAVE();
	return;
}

static void
__mmplayer_gst_handle_element_message(mmplayer_t *player, GstMessage *msg)
{
	const gchar *structure_name;
	gint count = 0, idx = 0;
	MMHandleType attrs = 0;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);

	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("Failed to get content attribute");
		return;
	}

	if (gst_message_get_structure(msg) == NULL)
		return;

	structure_name = gst_structure_get_name(gst_message_get_structure(msg));
	if (!structure_name)
		return;

	LOGD("GST_MESSAGE_ELEMENT %s from %s", structure_name, GST_OBJECT_NAME(GST_MESSAGE_SRC(msg)));

	if (!strcmp(structure_name, "adaptive-streaming-variant")) {
		const GValue *var_info = NULL;

		var_info = gst_structure_get_value(gst_message_get_structure(msg), "video-variant-info");
		if (var_info != NULL) {
			if (player->adaptive_info.var_list)
				g_list_free_full(player->adaptive_info.var_list, g_free);

			/* share addr or copy the list */
			player->adaptive_info.var_list =
				g_list_copy_deep((GList *)g_value_get_pointer(var_info), (GCopyFunc)__mmplayer_adaptive_var_info, NULL);

			count = g_list_length(player->adaptive_info.var_list);
			if (count > 0) {
				stream_variant_t *temp = NULL;

				/* print out for debug */
				LOGD("num of variant_info %d", count);
				for (idx = 0; idx < count; idx++) {
					temp = g_list_nth_data(player->adaptive_info.var_list, idx);
					if (temp)
						LOGD("variant(%d) [b]%d [w]%d [h]%d ", idx, temp->bandwidth, temp->width, temp->height);
				}
			}
		}
	}

	if (!strcmp(structure_name, "prepare-decode-buffers")) {
		gint num_buffers = 0;
		gint extra_num_buffers = 0;

		if (gst_structure_get_int(gst_message_get_structure(msg), "num_buffers", &num_buffers)) {
			LOGD("video_num_buffers : %d", num_buffers);
			mm_attrs_set_int_by_name(player->attrs, MM_PLAYER_VIDEO_BUFFER_TOTAL_SIZE, num_buffers);
		}

		if (gst_structure_get_int(gst_message_get_structure(msg), "extra_num_buffers", &extra_num_buffers)) {
			LOGD("num_of_vout_extra num buffers : %d", extra_num_buffers);
			mm_attrs_set_int_by_name(player->attrs, MM_PLAYER_VIDEO_BUFFER_EXTRA_SIZE, extra_num_buffers);
		}
		return;
	}

	if (!strcmp(structure_name, "Ext_Sub_Language_List"))
		_mmplayer_track_update_text_attr_info(player, msg);

	/* custom message */
	if (!strcmp(structure_name, "audio_codec_not_supported")) {
		MMMessageParamType msg_param = {0,};
		msg_param.code = MM_ERROR_PLAYER_AUDIO_CODEC_NOT_FOUND;
		MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
	}

	/* custom message for RTSP attribute :
		RTSP case, buffer is not come from server before PLAYING state. However,we have to get attribute after PAUSE state chaged.
		sdp which has contents info is received when rtsp connection is opened.
		extract duration ,codec info , resolution from sdp and get it by GstMessage */
	if (!strcmp(structure_name, "rtspsrc_properties")) {
		gchar *audio_codec = NULL;
		gchar *video_codec = NULL;
		gchar *video_frame_size = NULL;

		gst_structure_get(gst_message_get_structure(msg), "rtsp_duration", G_TYPE_UINT64, &player->duration, NULL);
		LOGD("rtsp duration : %"G_GINT64_FORMAT" msec", GST_TIME_AS_MSECONDS(player->duration));
		player->streaming_type = _mmplayer_get_stream_service_type(player);

		gst_structure_get(gst_message_get_structure(msg), "rtsp_audio_codec", G_TYPE_STRING, &audio_codec, NULL);
		LOGD("rtsp_audio_codec : %s", audio_codec);
		if (audio_codec)
			mm_attrs_set_string_by_name(attrs, "content_audio_codec", audio_codec);

		gst_structure_get(gst_message_get_structure(msg), "rtsp_video_codec", G_TYPE_STRING, &video_codec, NULL);
		LOGD("rtsp_video_codec : %s", video_codec);
		if (video_codec)
			mm_attrs_set_string_by_name(attrs, "content_video_codec", video_codec);

		gst_structure_get(gst_message_get_structure(msg), "rtsp_video_frame_size", G_TYPE_STRING, &video_frame_size, NULL);
		LOGD("rtsp_video_frame_size : %s", video_frame_size);
		if (video_frame_size) {
			char *seperator = strchr(video_frame_size, '-');
			if (seperator) {
				char video_width[10] = {0,};
				int frame_size_len = strlen(video_frame_size);
				int separtor_len = strlen(seperator);

				strncpy(video_width, video_frame_size, (frame_size_len - separtor_len));
				mm_attrs_set_int_by_name(attrs, MM_PLAYER_VIDEO_WIDTH, atoi(video_width));

				seperator++;
				mm_attrs_set_int_by_name(attrs, MM_PLAYER_VIDEO_HEIGHT, atoi(seperator));
			}
		}

		if (mm_attrs_commit_all(attrs))
			LOGE("failed to commit.");
	}

	MMPLAYER_FLEAVE();
	return;
}

static void
__mmplayer_gst_handle_async_done_message(mmplayer_t *player, GstMessage *msg)
{
	mmplayer_gst_element_t *mainbin;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_IF_FAIL(player && player->pipeline && player->pipeline->mainbin);

	mainbin = player->pipeline->mainbin;

	LOGD("GST_MESSAGE_ASYNC_DONE : %s", GST_ELEMENT_NAME(GST_MESSAGE_SRC(msg)));

	/* we only handle messages from pipeline */
	if (msg->src != (GstObject *)mainbin[MMPLAYER_M_PIPE].gst)
		return;

	if (player->seek_state == MMPLAYER_SEEK_IN_PROGRESS) {
		if (MMPLAYER_TARGET_STATE(player) == MM_PLAYER_STATE_PAUSED) {
			player->seek_state = MMPLAYER_SEEK_NONE;
			MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
		} else if (MMPLAYER_TARGET_STATE(player) == MM_PLAYER_STATE_PLAYING) {
			if (mainbin[MMPLAYER_M_AUTOPLUG].gst) {
				LOGD("sync %s state(%s) with parent state(%s)",
					GST_ELEMENT_NAME(mainbin[MMPLAYER_M_AUTOPLUG].gst),
					gst_element_state_get_name(GST_STATE(mainbin[MMPLAYER_M_AUTOPLUG].gst)),
					gst_element_state_get_name(GST_STATE(mainbin[MMPLAYER_M_PIPE].gst)));

				/* In case of streaming, pause is required before finishing seeking by buffering.
				   After completing the seek(during buffering), the player and sink elems has paused state but others in playing state.
				   Because the buffering state is controlled according to the state transition for force resume,
				   the decodebin state should be paused as player state. */
				gst_element_sync_state_with_parent(mainbin[MMPLAYER_M_AUTOPLUG].gst);
			}

			if ((MMPLAYER_IS_HTTP_STREAMING(player)) &&
				(player->streamer) &&
				(player->streamer->streaming_buffer_type == BUFFER_TYPE_MUXED) &&
				!(player->streamer->buffering_state & MM_PLAYER_BUFFERING_IN_PROGRESS)) {
				GstQuery *query = NULL;
				gboolean busy = FALSE;
				gint percent = 0;

				if (player->streamer->buffer_handle[BUFFER_TYPE_MUXED].buffer) {
					query = gst_query_new_buffering(GST_FORMAT_PERCENT);
					if (gst_element_query(player->streamer->buffer_handle[BUFFER_TYPE_MUXED].buffer, query))
						gst_query_parse_buffering_percent(query, &busy, &percent);
					gst_query_unref(query);

					LOGD("buffered percent(%s): %d",
						GST_ELEMENT_NAME(player->streamer->buffer_handle[BUFFER_TYPE_MUXED].buffer), percent);
				}

				if (percent >= 100)
					__mmplayer_handle_buffering_playback(player);
			}

			player->seek_state = MMPLAYER_SEEK_COMPLETED;
		}
	}

	MMPLAYER_FLEAVE();
	return;
}

static void
__mmplayer_gst_bus_msg_callback(GstMessage *msg, gpointer data)
{
	mmplayer_t *player = (mmplayer_t *)(data);

	MMPLAYER_RETURN_IF_FAIL(player);
	MMPLAYER_RETURN_IF_FAIL(msg && GST_IS_MESSAGE(msg));

	switch (GST_MESSAGE_TYPE(msg)) {
	case GST_MESSAGE_UNKNOWN:
		LOGD("unknown message received");
		break;

	case GST_MESSAGE_EOS:
		LOGD("GST_MESSAGE_EOS received");
		__mmplayer_gst_handle_eos_message(player, msg);
		break;

	case GST_MESSAGE_ERROR:
		__mmplayer_gst_handle_error_message(player, msg);
		break;

	case GST_MESSAGE_WARNING:
		{
			char *debug = NULL;
			GError *error = NULL;

			gst_message_parse_warning(msg, &error, &debug);

			LOGD("warning : %s", error->message);
			LOGD("debug : %s", debug);

			MMPLAYER_POST_MSG(player, MM_MESSAGE_WARNING, NULL);

			MMPLAYER_FREEIF(debug);
			g_error_free(error);
		}
		break;

	case GST_MESSAGE_TAG:
		{
			LOGD("GST_MESSAGE_TAG");
			if (!__mmplayer_gst_extract_tag_from_msg(player, msg))
				LOGW("failed to extract tags from gstmessage");
		}
		break;

	case GST_MESSAGE_BUFFERING:
		__mmplayer_gst_handle_buffering_message(player, msg);
		break;

	case GST_MESSAGE_STATE_CHANGED:
		__mmplayer_gst_handle_state_message(player, msg);
		break;

	case GST_MESSAGE_CLOCK_LOST:
			{
				GstClock *clock = NULL;
				gboolean need_new_clock = FALSE;

				gst_message_parse_clock_lost(msg, &clock);
				LOGD("GST_MESSAGE_CLOCK_LOST : %s", (clock ? GST_OBJECT_NAME(clock) : "NULL"));

				if (!player->videodec_linked)
					need_new_clock = TRUE;
				else if (!player->ini.use_system_clock)
					need_new_clock = TRUE;

				if (need_new_clock) {
					LOGD("Provide clock is TRUE, do pause->resume");
					_mmplayer_gst_pause(player, FALSE);
					_mmplayer_gst_resume(player, FALSE);
				}
			}
			break;

	case GST_MESSAGE_NEW_CLOCK:
			{
				GstClock *clock = NULL;
				gst_message_parse_new_clock(msg, &clock);
				LOGD("GST_MESSAGE_NEW_CLOCK : %s", (clock ? GST_OBJECT_NAME(clock) : "NULL"));
			}
			break;

	case GST_MESSAGE_ELEMENT:
		__mmplayer_gst_handle_element_message(player, msg);
			break;

	case GST_MESSAGE_DURATION_CHANGED:
		{
			LOGD("GST_MESSAGE_DURATION_CHANGED");
			if (!__mmplayer_gst_handle_duration(player, msg))
				LOGW("failed to update duration");
		}
		break;

	case GST_MESSAGE_ASYNC_START:
			LOGD("GST_MESSAGE_ASYNC_START : %s", GST_ELEMENT_NAME(GST_MESSAGE_SRC(msg)));
		break;

	case GST_MESSAGE_ASYNC_DONE:
		__mmplayer_gst_handle_async_done_message(player, msg);
		break;

#ifdef __DEBUG__
	case GST_MESSAGE_REQUEST_STATE:		LOGD("GST_MESSAGE_REQUEST_STATE"); break;
	case GST_MESSAGE_STEP_START:		LOGD("GST_MESSAGE_STEP_START"); break;
	case GST_MESSAGE_QOS:				LOGD("GST_MESSAGE_QOS"); break;
	case GST_MESSAGE_PROGRESS:			LOGD("GST_MESSAGE_PROGRESS"); break;
	case GST_MESSAGE_ANY:				LOGD("GST_MESSAGE_ANY"); break;
	case GST_MESSAGE_INFO:				LOGD("GST_MESSAGE_STATE_DIRTY"); break;
	case GST_MESSAGE_STATE_DIRTY:		LOGD("GST_MESSAGE_STATE_DIRTY"); break;
	case GST_MESSAGE_STEP_DONE:			LOGD("GST_MESSAGE_STEP_DONE"); break;
	case GST_MESSAGE_CLOCK_PROVIDE:		LOGD("GST_MESSAGE_CLOCK_PROVIDE"); break;
	case GST_MESSAGE_STRUCTURE_CHANGE:	LOGD("GST_MESSAGE_STRUCTURE_CHANGE"); break;
	case GST_MESSAGE_STREAM_STATUS:		LOGD("GST_MESSAGE_STREAM_STATUS"); break;
	case GST_MESSAGE_APPLICATION:		LOGD("GST_MESSAGE_APPLICATION"); break;
	case GST_MESSAGE_SEGMENT_START:		LOGD("GST_MESSAGE_SEGMENT_START"); break;
	case GST_MESSAGE_SEGMENT_DONE:		LOGD("GST_MESSAGE_SEGMENT_DONE"); break;
	case GST_MESSAGE_LATENCY:			LOGD("GST_MESSAGE_LATENCY"); break;
#endif

	default:
		break;
	}

	/* should not call 'gst_message_unref(msg)' */
	return;
}

static GstBusSyncReply
__mmplayer_gst_bus_sync_callback(GstBus *bus, GstMessage *message, gpointer data)
{
	mmplayer_t *player = (mmplayer_t *)data;
	GstBusSyncReply reply = GST_BUS_DROP;

	if (!(player->pipeline && player->pipeline->mainbin)) {
		LOGE("player pipeline handle is null");
		return GST_BUS_PASS;
	}

	if (!__mmplayer_gst_check_useful_message(player, message)) {
		gst_message_unref(message);
		return GST_BUS_DROP;
	}

	switch (GST_MESSAGE_TYPE(message)) {
	case GST_MESSAGE_TAG:
		__mmplayer_gst_extract_tag_from_msg(player, message);

#ifdef __DEBUG__
		{
			GstTagList *tags = NULL;

			gst_message_parse_tag(message, &tags);
			if (tags) {
				LOGE("TAGS received from element \"%s\".",
				GST_STR_NULL(GST_ELEMENT_NAME(GST_MESSAGE_SRC(message))));

				gst_tag_list_foreach(tags, print_tag, NULL);
				gst_tag_list_unref(tags);
				tags = NULL;
			}
			break;
		}
#endif
		break;

	case GST_MESSAGE_DURATION_CHANGED:
		__mmplayer_gst_handle_duration(player, message);
		break;
	case GST_MESSAGE_ASYNC_DONE:
		/* NOTE:Don't call gst_callback directly
		 * because previous frame can be showed even though this message is received for seek.
		 */
	default:
		reply = GST_BUS_PASS;
		break;
	}

	if (reply == GST_BUS_DROP)
		gst_message_unref(message);

	return reply;
}

static void
__mmplayer_gst_appsrc_feed_data_mem(GstElement *element, guint size, gpointer user_data)
{
	GstElement *appsrc = element;
	mmplayer_input_buffer_t *buf = (mmplayer_input_buffer_t *)user_data;
	GstBuffer *buffer = NULL;
	GstFlowReturn ret = GST_FLOW_OK;
	gint len = size;

	MMPLAYER_RETURN_IF_FAIL(element);
	MMPLAYER_RETURN_IF_FAIL(buf);

	buffer = gst_buffer_new();

	if (buf->offset < 0 || buf->len < 0) {
		LOGE("invalid buf info %d %d", buf->offset, buf->len);
		return;
	}

	if (buf->offset >= buf->len) {
		LOGD("call eos appsrc");
		g_signal_emit_by_name(appsrc, "end-of-stream", &ret);
		return;
	}

	if (buf->len - buf->offset < size)
		len = buf->len - buf->offset;

	gst_buffer_insert_memory(buffer, -1, gst_memory_new_wrapped(0, (guint8 *)(buf->buf + buf->offset), len, 0, len, NULL, NULL));
	GST_BUFFER_OFFSET(buffer) = (guint64)buf->offset;
	GST_BUFFER_OFFSET_END(buffer) = (guint64)(buf->offset + len);

#ifdef __DEBUG__
	LOGD("feed buffer %p, offset %u-%u length %u", buffer, buf->offset, (buf->offset+len), len);
#endif
	g_signal_emit_by_name(appsrc, "push-buffer", buffer, &ret);

	buf->offset += len;
}

static gboolean
__mmplayer_gst_appsrc_seek_data_mem(GstElement *element, guint64 size, gpointer user_data)
{
	mmplayer_input_buffer_t *buf = (mmplayer_input_buffer_t *)user_data;

	MMPLAYER_RETURN_VAL_IF_FAIL(buf, FALSE);

	buf->offset  = (int)size;

	return TRUE;
}

void
__mmplayer_gst_appsrc_feed_data(GstElement *element, guint size, gpointer user_data)
{
	mmplayer_t *player  = (mmplayer_t *)user_data;
	mmplayer_stream_type_e stream_type = MM_PLAYER_STREAM_TYPE_DEFAULT;
	MMMessageParamType msg_param = {0,};
	guint64 current_level_bytes = 0;

	MMPLAYER_RETURN_IF_FAIL(player);

	if (g_strrstr(GST_ELEMENT_NAME(element), "audio")) {
		stream_type = MM_PLAYER_STREAM_TYPE_AUDIO;
	} else if (g_strrstr(GST_ELEMENT_NAME(element), "video")) {
		stream_type = MM_PLAYER_STREAM_TYPE_VIDEO;
	} else {
		LOGW("invalid feed-data signal from %s", GST_ELEMENT_NAME(element));
		return;
	}

	g_object_get(G_OBJECT(element), "current-level-bytes", &current_level_bytes, NULL);

	LOGI("stream type: %d, level: %"G_GUINT64_FORMAT, stream_type, current_level_bytes);

	msg_param.union_type = MM_MSG_UNION_BUFFER_STATUS;
	msg_param.buffer_status.stream_type = stream_type;
	msg_param.buffer_status.status = MM_PLAYER_MEDIA_STREAM_BUFFER_UNDERRUN;
	msg_param.buffer_status.bytes = current_level_bytes;

	MMPLAYER_POST_MSG(player, MM_MESSAGE_PUSH_BUFFER_STATUS, &msg_param);
}

void
__mmplayer_gst_appsrc_enough_data(GstElement *element, gpointer user_data)
{
	mmplayer_t *player  = (mmplayer_t *)user_data;
	mmplayer_stream_type_e stream_type = MM_PLAYER_STREAM_TYPE_DEFAULT;
	MMMessageParamType msg_param = {0,};
	guint64 current_level_bytes = 0;

	MMPLAYER_RETURN_IF_FAIL(player);

	if (g_strrstr(GST_ELEMENT_NAME(element), "audio")) {
		stream_type = MM_PLAYER_STREAM_TYPE_AUDIO;
	} else if (g_strrstr(GST_ELEMENT_NAME(element), "video")) {
		stream_type = MM_PLAYER_STREAM_TYPE_VIDEO;
	} else {
		LOGW("invalid enough-data signal from %s", GST_ELEMENT_NAME(element));
		return;
	}

	g_object_get(G_OBJECT(element), "current-level-bytes", &current_level_bytes, NULL);

	LOGI("stream type: %d, level: %"G_GUINT64_FORMAT, stream_type, current_level_bytes);

	msg_param.union_type = MM_MSG_UNION_BUFFER_STATUS;
	msg_param.buffer_status.stream_type = stream_type;
	msg_param.buffer_status.status = MM_PLAYER_MEDIA_STREAM_BUFFER_OVERFLOW;
	msg_param.buffer_status.bytes = current_level_bytes;

	MMPLAYER_POST_MSG(player, MM_MESSAGE_PUSH_BUFFER_STATUS, &msg_param);
}

gboolean
__mmplayer_gst_appsrc_seek_data(GstElement *element, guint64 position, gpointer user_data)
{
	mmplayer_t *player  = (mmplayer_t *)user_data;
	mmplayer_stream_type_e stream_type = MM_PLAYER_STREAM_TYPE_DEFAULT;
	MMMessageParamType msg_param = {0,};

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);

	if (g_strrstr(GST_ELEMENT_NAME(element), "audio")) {
		stream_type = MM_PLAYER_STREAM_TYPE_AUDIO;
	} else if (g_strrstr(GST_ELEMENT_NAME(element), "video")) {
		stream_type = MM_PLAYER_STREAM_TYPE_VIDEO;
	} else {
		LOGW("invalid seek-data signal from %s", GST_ELEMENT_NAME(element));
		return TRUE;
	}

	LOGD("stream type: %d, pos: %"G_GUINT64_FORMAT, stream_type, position);

	msg_param.union_type = MM_MSG_UNION_SEEK_DATA;
	msg_param.seek_data.stream_type = stream_type;
	msg_param.seek_data.offset = position;

	MMPLAYER_POST_MSG(player, MM_MESSAGE_PUSH_BUFFER_SEEK_DATA, &msg_param);

	return TRUE;
}

static gboolean
__mmplayer_gst_create_es_decoder(mmplayer_t *player, mmplayer_stream_type_e type, GstPad *srcpad)
{
#define MAX_LEN_NAME 20

	gboolean ret = FALSE;
	GstPad *sinkpad = NULL;
	gchar *prefix = NULL;
	gchar dec_name[MAX_LEN_NAME] = {0, };
	main_element_id_e elem_id = MMPLAYER_M_NUM;

	mmplayer_gst_element_t *mainbin = NULL;
	GstElement *decodebin = NULL;
	GstCaps *dec_caps = NULL;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player &&
						player->pipeline &&
						player->pipeline->mainbin, FALSE);
	MMPLAYER_RETURN_VAL_IF_FAIL(srcpad, FALSE);

	mainbin = player->pipeline->mainbin;
	switch (type) {
	case MM_PLAYER_STREAM_TYPE_AUDIO:
		prefix = "audio";
		elem_id = MMPLAYER_M_AUTOPLUG_A_DEC;
	break;
	case MM_PLAYER_STREAM_TYPE_VIDEO:
		prefix = "video";
		elem_id = MMPLAYER_M_AUTOPLUG_V_DEC;
	break;
	default:
		LOGE("invalid type %d", type);
		return FALSE;
	}

	if (mainbin[elem_id].gst) {
		LOGE("elem(%d) is already created", elem_id);
		return FALSE;
	}

	snprintf(dec_name, sizeof(dec_name), "%s_decodebin", prefix);

	/* create decodebin */
	decodebin = gst_element_factory_make("decodebin", dec_name);
	if (!decodebin) {
		LOGE("failed to create %s", dec_name);
		return FALSE;
	}

	mainbin[elem_id].id = elem_id;
	mainbin[elem_id].gst = decodebin;

	/* raw pad handling signal */
	_mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "pad-added",
										G_CALLBACK(_mmplayer_gst_decode_pad_added), (gpointer)player);

	/* This signal is emitted whenever decodebin finds a new stream. It is emitted
	before looking for any elements that can handle that stream.*/
	_mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "autoplug-select",
										G_CALLBACK(_mmplayer_gst_decode_autoplug_select), (gpointer)player);

	/* This signal is emitted when a element is added to the bin.*/
	_mmplayer_add_signal_connection(player, G_OBJECT(decodebin), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "element-added",
										G_CALLBACK(_mmplayer_gst_element_added), (gpointer)player);

	if (!gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), decodebin)) {
		LOGE("failed to add new decodebin");
		return FALSE;
	}

	dec_caps = gst_pad_query_caps(srcpad, NULL);
	if (dec_caps) {
#ifdef __DEBUG__
		LOGD("got pad %s:%s , dec_caps %" GST_PTR_FORMAT, GST_DEBUG_PAD_NAME(srcpad), dec_caps);
#endif
		g_object_set(G_OBJECT(decodebin), "sink-caps", dec_caps, NULL);
		gst_caps_unref(dec_caps);
	}

	sinkpad = gst_element_get_static_pad(decodebin, "sink");

	if (!sinkpad || gst_pad_link(srcpad, sinkpad) != GST_PAD_LINK_OK) {
		LOGE("failed to link [%s:%s] to decoder", GST_DEBUG_PAD_NAME(srcpad));
		goto ERROR;
	}
	gst_object_unref(GST_OBJECT(sinkpad));

	gst_element_sync_state_with_parent(decodebin);
	MMPLAYER_FLEAVE();
	return TRUE;

ERROR:
	if (sinkpad)
		gst_object_unref(GST_OBJECT(sinkpad));

	if (mainbin[elem_id].gst) {
		gst_element_set_state(mainbin[elem_id].gst, GST_STATE_NULL);
		gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[elem_id].gst);
		gst_object_unref(mainbin[elem_id].gst);
		mainbin[elem_id].gst = NULL;
	}

	MMPLAYER_FLEAVE();
	return ret;
}

static gboolean
__mmplayer_gst_create_es_path(mmplayer_t *player, mmplayer_stream_type_e type, GstCaps *caps)
{
#define MAX_LEN_NAME 20
	mmplayer_gst_element_t *mainbin = NULL;
	gchar *prefix = NULL;
	main_element_id_e src_id = MMPLAYER_M_NUM, queue_id = MMPLAYER_M_NUM;

	gchar src_name[MAX_LEN_NAME] = {0, }, queue_name[MAX_LEN_NAME] = {0, };
	GstElement *src = NULL, *queue = NULL;
	GstPad *srcpad = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
				player->pipeline->mainbin, FALSE);

	mainbin = player->pipeline->mainbin;

	LOGD("type(%d) path is creating", type);
	switch (type) {
	case MM_PLAYER_STREAM_TYPE_AUDIO:
		prefix = "audio";
		if (mainbin[MMPLAYER_M_SRC].gst)
			src_id = MMPLAYER_M_2ND_SRC;
		else
			src_id = MMPLAYER_M_SRC;
		queue_id = MMPLAYER_M_A_BUFFER;
	break;
	case MM_PLAYER_STREAM_TYPE_VIDEO:
		prefix = "video";
		src_id = MMPLAYER_M_SRC;
		queue_id = MMPLAYER_M_V_BUFFER;
	break;
	case MM_PLAYER_STREAM_TYPE_TEXT:
		prefix = "subtitle";
		src_id = MMPLAYER_M_SUBSRC;
		queue_id = MMPLAYER_M_S_BUFFER;
	break;
	default:
		LOGE("invalid type %d", type);
		return FALSE;
	}

	snprintf(src_name, sizeof(src_name), "%s_appsrc", prefix);
	snprintf(queue_name, sizeof(queue_name), "%s_queue", prefix);

	/* create source */
	src = gst_element_factory_make("appsrc", src_name);
	if (!src) {
		LOGF("failed to create %s", src_name);
		goto ERROR;
	}

	mainbin[src_id].id = src_id;
	mainbin[src_id].gst = src;

	g_object_set(G_OBJECT(src), "format", GST_FORMAT_TIME,
								"caps", caps, NULL);

	/* size of many video frames are larger than default blocksize as 4096 */
	if (type == MM_PLAYER_STREAM_TYPE_VIDEO)
		g_object_set(G_OBJECT(src), "blocksize", (guint)1048576, NULL);

	if (player->media_stream_buffer_max_size[type] > 0)
		g_object_set(G_OBJECT(src), "max-bytes", player->media_stream_buffer_max_size[type], NULL);

	if (player->media_stream_buffer_min_percent[type] > 0)
		g_object_set(G_OBJECT(src), "min-percent", player->media_stream_buffer_min_percent[type], NULL);

	/*Fix Seek External Demuxer: set audio and video appsrc as seekable */
	gst_app_src_set_stream_type((GstAppSrc*)G_OBJECT(src), GST_APP_STREAM_TYPE_SEEKABLE);

	_mmplayer_add_signal_connection(player, G_OBJECT(src), MM_PLAYER_SIGNAL_TYPE_OTHERS, "seek-data",
											G_CALLBACK(__mmplayer_gst_appsrc_seek_data), (gpointer)player);
	_mmplayer_add_signal_connection(player, G_OBJECT(src), MM_PLAYER_SIGNAL_TYPE_OTHERS, "need-data",
											G_CALLBACK(__mmplayer_gst_appsrc_feed_data), (gpointer)player);
	_mmplayer_add_signal_connection(player, G_OBJECT(src), MM_PLAYER_SIGNAL_TYPE_OTHERS, "enough-data",
											G_CALLBACK(__mmplayer_gst_appsrc_enough_data), (gpointer)player);

	/* create queue */
	queue = gst_element_factory_make("queue2", queue_name);
	if (!queue) {
		LOGE("failed to create %s", queue_name);
		goto ERROR;
	}
	g_object_set(G_OBJECT(queue), "max-size-buffers", 2, NULL);

	mainbin[queue_id].id = queue_id;
	mainbin[queue_id].gst = queue;

	if (!gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[src_id].gst)) {
		LOGE("failed to add src");
		goto ERROR;
	}

	if (!gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[queue_id].gst)) {
		LOGE("failed to add queue");
		goto ERROR;
	}

	if (!gst_element_link(mainbin[src_id].gst, mainbin[queue_id].gst)) {
		LOGE("failed to link src and queue");
		goto ERROR;
	}

	/* create decoder */
	srcpad = gst_element_get_static_pad(mainbin[queue_id].gst, "src");
	if (!srcpad) {
		LOGE("failed to get srcpad of queue");
		goto ERROR;
	}

	if (type == MM_PLAYER_STREAM_TYPE_TEXT) {
		_mmplayer_gst_create_decoder(player, srcpad, caps);
	} else {
		if (!__mmplayer_gst_create_es_decoder(player, type, srcpad)) {
			LOGE("failed to create decoder");
			gst_object_unref(GST_OBJECT(srcpad));
			goto ERROR;
		}
	}
	gst_object_unref(GST_OBJECT(srcpad));
	return TRUE;

ERROR:
	if (mainbin[src_id].gst) {
		gst_element_set_state(mainbin[src_id].gst, GST_STATE_NULL);
		gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[src_id].gst);
		gst_object_unref(mainbin[src_id].gst);
		mainbin[src_id].gst = NULL;
	}

	if (mainbin[queue_id].gst) {
		gst_element_set_state(mainbin[queue_id].gst, GST_STATE_NULL);
		gst_bin_remove(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[queue_id].gst);
		gst_object_unref(mainbin[queue_id].gst);
		mainbin[queue_id].gst = NULL;
	}

	return FALSE;
}

static void
__mmplayer_gst_rtp_dynamic_pad(GstElement *element, GstPad *pad, gpointer data)
{
	GstPad *sinkpad = NULL;
	GstCaps *caps = NULL;
	GstElement *new_element = NULL;
	GstStructure *str = NULL;
	const gchar *name = NULL;

	mmplayer_t *player = (mmplayer_t *)data;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_IF_FAIL(element && pad);
	MMPLAYER_RETURN_IF_FAIL(player &&
					player->pipeline &&
					player->pipeline->mainbin);

	/* payload type is recognizable. increase num_dynamic and wait for sinkbin creation.
	 * num_dynamic_pad will decreased after creating a sinkbin.
	 */
	player->num_dynamic_pad++;
	LOGD("stream count inc : %d", player->num_dynamic_pad);

	caps = gst_pad_query_caps(pad, NULL);
	MMPLAYER_CHECK_NULL(caps);

	str = gst_caps_get_structure(caps, 0);
	name = gst_structure_get_string(str, "media");
	if (!name) {
		LOGE("cannot get mimetype from structure.");
		goto ERROR;
	}

	if (strstr(name, "video")) {
		gint stype = 0;
		mm_attrs_get_int_by_name(player->attrs, "display_surface_type", &stype);

		if ((stype == MM_DISPLAY_SURFACE_NULL) && (!player->set_mode.video_export)) {
			if (player->v_stream_caps) {
				gst_caps_unref(player->v_stream_caps);
				player->v_stream_caps = NULL;
			}

			new_element = gst_element_factory_make("fakesink", NULL);
			player->num_dynamic_pad--;
			goto NEW_ELEMENT;
		}
	}

	if (!_mmplayer_gst_create_decoder(player, pad, caps)) {
		LOGE("failed to autoplug for caps");
		goto ERROR;
	}

	gst_caps_unref(caps);
	caps = NULL;

NEW_ELEMENT:

	/* excute new_element if created*/
	if (new_element) {
		LOGD("adding new element to pipeline");

		/* set state to READY before add to bin */
		MMPLAYER_ELEMENT_SET_STATE(new_element, GST_STATE_READY);

		/* add new element to the pipeline */
		if (FALSE == gst_bin_add(GST_BIN(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst), new_element)) {
			LOGE("failed to add autoplug element to bin");
			goto ERROR;
		}

		/* get pad from element */
		sinkpad = gst_element_get_static_pad(GST_ELEMENT(new_element), "sink");
		if (!sinkpad) {
			LOGE("failed to get sinkpad from autoplug element");
			goto ERROR;
		}

		/* link it */
		if (GST_PAD_LINK_OK != gst_pad_link(pad, sinkpad)) {
			LOGE("failed to link autoplug element");
			goto ERROR;
		}

		gst_object_unref(sinkpad);
		sinkpad = NULL;

		/* run. setting PLAYING here since streamming source is live source */
		MMPLAYER_ELEMENT_SET_STATE(new_element, GST_STATE_PLAYING);
	}

	if (caps)
		gst_caps_unref(caps);

	MMPLAYER_FLEAVE();

	return;

STATE_CHANGE_FAILED:
ERROR:
	/* FIXIT : take care if new_element has already added to pipeline */
	if (new_element)
		gst_object_unref(GST_OBJECT(new_element));

	if (sinkpad)
		gst_object_unref(GST_OBJECT(sinkpad));

	if (caps)
		gst_caps_unref(caps);

	/* FIXIT : how to inform this error to MSL ????? */
	/* FIXIT : I think we'd better to use g_idle_add() to destroy pipeline and
	 * then post an error to application
	 */
}

static void
__mmplayer_gst_rtp_no_more_pads(GstElement *element,  gpointer data)
{
	mmplayer_t *player = (mmplayer_t *)data;

	MMPLAYER_FENTER();

	/* NOTE : we can remove fakesink here if there's no rtp_dynamic_pad. because whenever
	 * we connect autoplugging element to the pad which is just added to rtspsrc, we increase
	 * num_dynamic_pad. and this is no-more-pad situation which means no more pad will be added.
	 * So we can say this. if num_dynamic_pad is zero, it must be one of followings

	 * [1] audio and video will be dumped with filesink.
	 * [2] autoplugging is done by just using pad caps.
	 * [3] typefinding has happend in audio but audiosink is created already before no-more-pad signal
	 * and the video will be dumped via filesink.
	 */
	if (player->num_dynamic_pad == 0) {
		LOGD("it seems pad caps is directely used for autoplugging. removing fakesink now");

		if (!_mmplayer_gst_remove_fakesink(player,
			&player->pipeline->mainbin[MMPLAYER_M_SRC_FAKESINK]))
			/* NOTE : __mmplayer_pipeline_complete() can be called several time. because
			 * signaling mechanism(pad-added, no-more-pad, new-decoded-pad) from various
			 * source element are not same. To overcome this situation, this function will called
			 * several places and several times. Therefore, this is not an error case.
			 */
			return;
	}

	/* create dot before error-return. for debugging */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-no-more-pad");

	player->no_more_pad = TRUE;

	MMPLAYER_FLEAVE();
}

static GstElement *
__mmplayer_gst_make_rtsp_src(mmplayer_t *player)
{
	GstElement *element = NULL;
	gchar *user_agent = NULL;
	MMHandleType attrs = 0;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL);

	/* get profile attribute */
	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("failed to get content attribute");
		return NULL;
	}

	element = gst_element_factory_make("rtspsrc", "rtsp source");
	if (!element) {
		LOGE("failed to create rtspsrc element");
		return NULL;
	}

	/* get attribute */
	mm_attrs_get_string_by_name(attrs, "streaming_user_agent", &user_agent);

	SECURE_LOGD("user_agent : %s", user_agent);

	/* setting property to streaming source */
	g_object_set(G_OBJECT(element), "location", player->profile.uri, NULL);
	if (user_agent)
		g_object_set(G_OBJECT(element), "user-agent", user_agent, NULL);

	_mmplayer_add_signal_connection(player, G_OBJECT(element), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "pad-added",
									G_CALLBACK(__mmplayer_gst_rtp_dynamic_pad), (gpointer)player);
	_mmplayer_add_signal_connection(player, G_OBJECT(element), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "no-more-pads",
									G_CALLBACK(__mmplayer_gst_rtp_no_more_pads), (gpointer)player);

	MMPLAYER_FLEAVE();
	return element;
}

static GstElement *
__mmplayer_gst_make_http_src(mmplayer_t *player)
{
#define MAX_RETRY_COUNT 10
	GstElement *element = NULL;
	MMHandleType attrs = 0;
	gchar *user_agent, *cookies, **cookie_list;
	gint http_timeout = DEFAULT_HTTP_TIMEOUT;
	user_agent = cookies = NULL;
	cookie_list = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL);

	/* get profile attribute */
	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("failed to get content attribute");
		return NULL;
	}

	LOGD("using http streamming source [%s]", player->ini.httpsrc_element);

	element = gst_element_factory_make(player->ini.httpsrc_element, "http_streaming_source");
	if (!element) {
		LOGE("failed to create http streaming source element[%s]", player->ini.httpsrc_element);
		return NULL;
	}

	/* get attribute */
	mm_attrs_get_string_by_name(attrs, "streaming_cookie", &cookies);
	mm_attrs_get_string_by_name(attrs, "streaming_user_agent", &user_agent);

	if (player->ini.http_timeout != DEFAULT_HTTP_TIMEOUT)
		http_timeout = player->ini.http_timeout;

	/* get attribute */
	SECURE_LOGD("location : %s", player->profile.uri);
	SECURE_LOGD("cookies : %s", cookies);
	SECURE_LOGD("user_agent :  %s", user_agent);
	LOGD("timeout : %d", http_timeout);

	/* setting property to streaming source */
	g_object_set(G_OBJECT(element), "location", player->profile.uri,
				"timeout", http_timeout, "blocksize", (unsigned long)(64 * 1024),
				"retries", MAX_RETRY_COUNT, NULL);

	/* parsing cookies */
	if ((cookie_list = _mmplayer_get_cookie_list((const char *)cookies))) {
		g_object_set(G_OBJECT(element), "cookies", cookie_list, NULL);
		g_strfreev(cookie_list);
	}

	if (user_agent)
		g_object_set(G_OBJECT(element), "user-agent", user_agent, NULL);

	if (MMPLAYER_URL_HAS_DASH_SUFFIX(player))
		LOGW("[DASH] this is still experimental feature");

	MMPLAYER_FLEAVE();
	return element;
}

static GstElement *
__mmplayer_gst_make_file_src(mmplayer_t *player)
{
	GstElement *element = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player, NULL);

	LOGD("using filesrc for 'file://' handler");
	if (!_mmplayer_get_storage_info(player->profile.uri, &player->storage_info[MMPLAYER_PATH_VOD])) {
		LOGE("failed to get storage info");
		return NULL;
	}

	element = gst_element_factory_make("filesrc", "source");
	if (!element) {
		LOGE("failed to create filesrc");
		return NULL;
	}

	g_object_set(G_OBJECT(element), "location", (player->profile.uri) + 7, NULL); /* uri+7 -> remove "file:// */

	MMPLAYER_FLEAVE();
	return element;
}

static gboolean
__mmplayer_gst_msg_push(GstBus *bus, GstMessage *msg, gpointer data)
{
	mmplayer_t *player = (mmplayer_t *)data;

	g_return_val_if_fail(player, FALSE);
	g_return_val_if_fail(msg && GST_IS_MESSAGE(msg), FALSE);

	gst_message_ref(msg);

	g_mutex_lock(&player->bus_msg_q_lock);
	g_queue_push_tail(player->bus_msg_q, msg);
	g_mutex_unlock(&player->bus_msg_q_lock);

	MMPLAYER_BUS_MSG_THREAD_LOCK(player);
	MMPLAYER_BUS_MSG_THREAD_SIGNAL(player);
	MMPLAYER_BUS_MSG_THREAD_UNLOCK(player);
	return TRUE;
}

static gpointer __mmplayer_gst_bus_msg_thread(gpointer data)
{
	mmplayer_t *player = (mmplayer_t *)(data);
	GstMessage *msg = NULL;
	GstBus *bus = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player &&
						player->pipeline &&
						player->pipeline->mainbin &&
						player->pipeline->mainbin[MMPLAYER_M_PIPE].gst,
						NULL);

	bus = gst_pipeline_get_bus(GST_PIPELINE(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst));
	if (!bus) {
		LOGE("cannot get BUS from the pipeline");
		return NULL;
	}

	MMPLAYER_BUS_MSG_THREAD_LOCK(player);

	LOGD("[handle: %p] gst bus msg thread will be started.", player);
	while (!player->bus_msg_thread_exit) {
		g_mutex_lock(&player->bus_msg_q_lock);
		msg = g_queue_pop_head(player->bus_msg_q);
		g_mutex_unlock(&player->bus_msg_q_lock);
		if (msg == NULL) {
			MMPLAYER_BUS_MSG_THREAD_WAIT(player);
			continue;
		}
		MMPLAYER_BUS_MSG_THREAD_UNLOCK(player);
		/* handle the gst msg */
		__mmplayer_gst_bus_msg_callback(msg, player);
		MMPLAYER_BUS_MSG_THREAD_LOCK(player);
		gst_message_unref(msg);
	}

	MMPLAYER_BUS_MSG_THREAD_UNLOCK(player);
	gst_object_unref(GST_OBJECT(bus));

	MMPLAYER_FLEAVE();
	return NULL;
}

static int
__mmplayer_gst_check_duration(mmplayer_t *player, gint64 position)
{
	gint64 dur_nsec = 0;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);

	if (MMPLAYER_IS_MS_BUFF_SRC(player))
		return MM_ERROR_NONE;

	/* NOTE : duration cannot be zero except live streaming.
	 *		Since some element could have some timing problemn with quering duration, try again.
	 */
	if (player->duration == 0) {
		if (!gst_element_query_duration(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_FORMAT_TIME, &dur_nsec)) {
			/* For RTSP Streaming , duration is not returned in READY state. So seek to the previous position does not work properly.
			 * Added a patch to postpone the actual seek when state changes to PLAY. Sending a fake SEEK_COMPLETED event to finish the current request. */
			if ((MMPLAYER_IS_RTSP_STREAMING(player)) &&
				(_mmplayer_get_stream_service_type(player) == STREAMING_SERVICE_VOD)) {
				player->pending_seek.is_pending = true;
				player->pending_seek.pos = position;
				player->seek_state = MMPLAYER_SEEK_NONE;
				MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
				return MM_ERROR_PLAYER_NO_OP;
			} else {
				player->seek_state = MMPLAYER_SEEK_NONE;
				return MM_ERROR_PLAYER_SEEK;
			}
		}
		player->duration = dur_nsec;
	}

	if (player->duration > 0 && player->duration < position) {
		LOGE("invalid pos %"G_GINT64_FORMAT", dur: %"G_GINT64_FORMAT, position, player->duration);
		return MM_ERROR_INVALID_ARGUMENT;
	}

	MMPLAYER_FLEAVE();
	return MM_ERROR_NONE;
}

static gboolean
__mmplayer_gst_check_seekable(mmplayer_t *player)
{
	GstQuery *query = NULL;
	gboolean seekable = FALSE;

	if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
		return TRUE;
	}

	query = gst_query_new_seeking(GST_FORMAT_TIME);
	if (gst_element_query(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, query)) {
		gst_query_parse_seeking(query, NULL, &seekable, NULL, NULL);
		gst_query_unref(query);

		if (!seekable) {
			LOGW("non-seekable content");
			player->seek_state = MMPLAYER_SEEK_NONE;
			return FALSE;
		}
	} else {
		LOGW("failed to get seeking query");
		gst_query_unref(query); /* keep seeking operation */
	}

	return TRUE;
}

int
_mmplayer_gst_set_state(mmplayer_t *player, GstElement *element,  GstState state, gboolean async, gint timeout)
{
	GstState element_state = GST_STATE_VOID_PENDING;
	GstState element_pending_state = GST_STATE_VOID_PENDING;
	GstStateChangeReturn ret = GST_STATE_CHANGE_FAILURE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
	MMPLAYER_RETURN_VAL_IF_FAIL(element, MM_ERROR_INVALID_ARGUMENT);

	LOGD("setting [%s] element state to : %s", GST_ELEMENT_NAME(element), gst_element_state_get_name(state));

	/* set state */
	ret = gst_element_set_state(element, state);
	if (ret == GST_STATE_CHANGE_FAILURE) {
		LOGE("failed to set [%s] state", GST_ELEMENT_NAME(element));

		/* dump state of all element */
		_mmplayer_dump_pipeline_state(player);

		return MM_ERROR_PLAYER_INTERNAL;
	}

	/* return here so state transition to be done in async mode */
	if (async) {
		LOGD("async state transition. not waiting for state complete.");
		return MM_ERROR_NONE;
	}

	/* wait for state transition */
	ret = gst_element_get_state(element, &element_state, &element_pending_state, timeout * GST_SECOND);
	if (ret == GST_STATE_CHANGE_FAILURE || (state != element_state)) {
		LOGE("failed to change [%s] element state to [%s] within %d sec",
			GST_ELEMENT_NAME(element),
			gst_element_state_get_name(state), timeout);

		LOGE(" [%s] state : %s   pending : %s",
			GST_ELEMENT_NAME(element),
			gst_element_state_get_name(element_state),
			gst_element_state_get_name(element_pending_state));

		/* dump state of all element */
		_mmplayer_dump_pipeline_state(player);

		return MM_ERROR_PLAYER_INTERNAL;
	}

	LOGD("[%s] element state has changed", GST_ELEMENT_NAME(element));

	MMPLAYER_FLEAVE();

	return MM_ERROR_NONE;
}

int
_mmplayer_gst_start(mmplayer_t *player)
{
	int ret = MM_ERROR_NONE;
	gboolean async = FALSE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);

	/* NOTE : if SetPosition was called before Start. do it now
	 * streaming doesn't support it. so it should be always sync
	 * !!create one more api to check if there is pending seek rather than checking variables
	 */
	if (player->pending_seek.is_pending && !MMPLAYER_IS_STREAMING(player)) {
		MMPLAYER_TARGET_STATE(player) = MM_PLAYER_STATE_PAUSED;
		ret = _mmplayer_gst_pause(player, FALSE);
		if (ret != MM_ERROR_NONE) {
			LOGE("failed to set state to PAUSED for pending seek");
			return ret;
		}

		MMPLAYER_TARGET_STATE(player) = MM_PLAYER_STATE_PLAYING;
		if (__mmplayer_gst_pending_seek(player) != MM_ERROR_NONE)
				LOGW("failed to seek pending postion. starting from the begin of content");
	}

	LOGD("current state before doing transition");
	MMPLAYER_PENDING_STATE(player) = MM_PLAYER_STATE_PLAYING;
	MMPLAYER_PRINT_STATE(player);

	/* set pipeline state to PLAYING  */
	ret = _mmplayer_gst_set_state(player,
		player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_STATE_PLAYING, async, MMPLAYER_STATE_CHANGE_TIMEOUT(player));
	if (ret != MM_ERROR_NONE) {
		LOGE("failed to set state to PLAYING");
		return ret;
	}

	MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PLAYING);

	/* generating debug info before returning error */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-start");

	MMPLAYER_FLEAVE();

	return ret;
}

int
_mmplayer_gst_stop(mmplayer_t *player)
{
	GstStateChangeReturn change_ret = GST_STATE_CHANGE_SUCCESS;
	MMHandleType attrs = 0;
	gboolean rewind = FALSE;
	gint timeout = 0;
	int ret = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
	MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	LOGD("current state before doing transition");
	MMPLAYER_PENDING_STATE(player) = MM_PLAYER_STATE_READY;
	MMPLAYER_PRINT_STATE(player);

	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("cannot get content attribute");
		return MM_ERROR_PLAYER_INTERNAL;
	}

	/* Just set state to PAUESED and the rewind. it's usual player behavior. */
	timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player);

	if ((!MMPLAYER_IS_STREAMING(player) && !MMPLAYER_IS_MS_BUFF_SRC(player)) ||
		(player->streaming_type == STREAMING_SERVICE_VOD && player->videodec_linked))
		rewind = TRUE;

	if (player->es_player_push_mode)
		/* disable the async state transition because there could be no data in the pipeline */
		__mmplayer_gst_set_async(player, FALSE, MMPLAYER_SINK_ALL);

	/* set gst state */
	ret = _mmplayer_gst_set_state(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_STATE_PAUSED, FALSE, timeout);

	if (player->es_player_push_mode) {
		/* enable the async state transition as default operation */
		__mmplayer_gst_set_async(player, TRUE, MMPLAYER_SINK_ALL);
	}

	/* return if set_state has failed */
	if (ret != MM_ERROR_NONE) {
		LOGE("failed to set state.");
		return ret;
	}

	/* rewind */
	if (rewind) {
		if (!_mmplayer_gst_seek(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, player->playback_rate,
				GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 0,
				GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
			LOGW("failed to rewind");
			ret = MM_ERROR_PLAYER_SEEK;
		}
	}

	/* initialize */
	player->sent_bos = FALSE;

	if (player->es_player_push_mode) //for cloudgame
		timeout = 0;

	/* wait for seek to complete */
	change_ret = gst_element_get_state(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, NULL, NULL, timeout * GST_SECOND);
	if (change_ret == GST_STATE_CHANGE_SUCCESS || change_ret == GST_STATE_CHANGE_NO_PREROLL) {
		MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_READY);
	} else {
		LOGE("fail to stop player.");
		ret = MM_ERROR_PLAYER_INTERNAL;
		_mmplayer_dump_pipeline_state(player);
	}

	/* generate dot file if enabled */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-stop");

	MMPLAYER_FLEAVE();

	return ret;
}

int
_mmplayer_gst_pause(mmplayer_t *player, gboolean async)
{
	int ret = MM_ERROR_NONE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
	MMPLAYER_RETURN_VAL_IF_FAIL(player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	LOGD("current state before doing transition");
	MMPLAYER_PENDING_STATE(player) = MM_PLAYER_STATE_PAUSED;
	MMPLAYER_PRINT_STATE(player);

	/* set pipeline status to PAUSED */
	ret = _mmplayer_gst_set_state(player,
		player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_STATE_PAUSED, async, MMPLAYER_STATE_CHANGE_TIMEOUT(player));

	if (async)
		goto EXIT;

	if (ret != MM_ERROR_NONE) {
		GstMessage *msg = NULL;
		GTimer *timer = NULL;
		gdouble MAX_TIMEOUT_SEC = 3;

		LOGE("failed to set state to PAUSED");

		if (!player->bus_watcher) {
			LOGE("there is no bus msg thread. pipeline is shutting down.");
			return ret;
		}

		if (player->msg_posted) {
			LOGE("error msg is already posted.");
			return ret;
		}

		timer = g_timer_new();
		g_timer_start(timer);

		GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst));

		do {
			msg = gst_bus_timed_pop(bus, 100 * GST_MSECOND);
			if (msg) {
				if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR) {
					GError *error = NULL;

					/* parse error code */
					gst_message_parse_error(msg, &error, NULL);

					if (gst_structure_has_name(gst_message_get_structure(msg), "streaming_error")) {
						/* Note : the streaming error from the streaming source is handled
							*   using __mmplayer_handle_streaming_error.
							*/
						__mmplayer_handle_streaming_error(player, msg);

					} else if (error) {
						LOGE("paring error posted from bus, domain : %s, code : %d", g_quark_to_string(error->domain), error->code);

						if (error->domain == GST_STREAM_ERROR)
							ret = __mmplayer_gst_handle_stream_error(player, error, msg);
						else if (error->domain == GST_RESOURCE_ERROR)
							ret = __mmplayer_gst_handle_resource_error(player, error->code, NULL);
						else if (error->domain == GST_LIBRARY_ERROR)
							ret = __mmplayer_gst_handle_library_error(player, error->code);
						else if (error->domain == GST_CORE_ERROR)
							ret = __mmplayer_gst_handle_core_error(player, error->code);

						g_error_free(error);
					}
					player->msg_posted = TRUE;
				}
				gst_message_unref(msg);
			}
		} while (!player->msg_posted && (g_timer_elapsed(timer, NULL) < MAX_TIMEOUT_SEC));
		/* clean */
		gst_object_unref(bus);
		g_timer_stop(timer);
		g_timer_destroy(timer);

		return ret;
	}

	if ((!MMPLAYER_IS_RTSP_STREAMING(player)) && (!player->video_decoded_cb) &&
		(!player->pipeline->videobin) && (!player->pipeline->audiobin))
		return MM_ERROR_PLAYER_CODEC_NOT_FOUND;

	MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PAUSED);

EXIT:
	/* generate dot file before returning error */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-pause");

	MMPLAYER_FLEAVE();

	return ret;
}

int
_mmplayer_gst_resume(mmplayer_t *player, gboolean async)
{
	int ret = MM_ERROR_NONE;
	gint timeout = 0;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline,
		MM_ERROR_PLAYER_NOT_INITIALIZED);

	LOGD("current state before doing transition");
	MMPLAYER_PENDING_STATE(player) = MM_PLAYER_STATE_PLAYING;
	MMPLAYER_PRINT_STATE(player);

	if (async)
		LOGD("do async state transition to PLAYING");

	/* set pipeline state to PLAYING */
	timeout = MMPLAYER_STATE_CHANGE_TIMEOUT(player);

	ret = _mmplayer_gst_set_state(player,
		player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_STATE_PLAYING, async, timeout);
	if (ret != MM_ERROR_NONE) {
		LOGE("failed to set state to PLAYING");
		goto EXIT;
	}

	if (!async)
		MMPLAYER_SET_STATE(player, MM_PLAYER_STATE_PLAYING);

EXIT:
	/* generate dot file */
	MMPLAYER_GENERATE_DOT_IF_ENABLED(player, "pipeline-status-resume");

	MMPLAYER_FLEAVE();

	return ret;
}

/* sending event to one of sinkelements */
gboolean
_mmplayer_gst_send_event_to_sink(mmplayer_t *player, GstEvent *event)
{
	GstEvent *event2 = NULL;
	GList *sinks = NULL;
	gboolean res = FALSE;
	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);
	MMPLAYER_RETURN_VAL_IF_FAIL(event, FALSE);

	/* While adding subtitles in live feeds seek is getting called.
	   Adding defensive check in framework layer.*/
	if (GST_EVENT_TYPE(event) == GST_EVENT_SEEK) {
		if (MMPLAYER_IS_LIVE_STREAMING(player)) {
			LOGE("Should not send seek event during live playback");
			return TRUE;
		}
	}

	if (player->play_subtitle)
		event2 = gst_event_copy((const GstEvent *)event);

	sinks = player->sink_elements;
	while (sinks) {
		GstElement *sink = GST_ELEMENT_CAST(sinks->data);

		if (GST_IS_ELEMENT(sink)) {
			/* keep ref to the event */
			gst_event_ref(event);

			if ((res = gst_element_send_event(sink, event))) {
				LOGD("sending event[%s] to sink element [%s] success!",
					GST_EVENT_TYPE_NAME(event), GST_ELEMENT_NAME(sink));

				/* rtsp case, asyn_done is not called after seek during pause state */
				if (MMPLAYER_IS_RTSP_STREAMING(player)) {
					if (GST_EVENT_TYPE(event) == GST_EVENT_SEEK) {
						if (MMPLAYER_TARGET_STATE(player) == MM_PLAYER_STATE_PAUSED) {
							LOGD("RTSP seek completed, after pause state..");
							player->seek_state = MMPLAYER_SEEK_NONE;
							MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
						}

					}
				}

				if (MMPLAYER_IS_MS_BUFF_SRC(player)) {
					sinks = g_list_next(sinks);
					continue;
				} else {
					break;
				}
			}

			LOGD("sending event[%s] to sink element [%s] failed. try with next one.",
				GST_EVENT_TYPE_NAME(event), GST_ELEMENT_NAME(sink));
		}

		sinks = g_list_next(sinks);
	}

	/* Note : Textbin is not linked to the video or audio bin.
	 * It needs to send the event to the text sink seperatelly.
	 */
	if (player->play_subtitle && player->pipeline) {
		GstElement *text_sink = GST_ELEMENT_CAST(player->pipeline->textbin[MMPLAYER_T_FAKE_SINK].gst);

		if (GST_IS_ELEMENT(text_sink)) {
			/* keep ref to the event */
			gst_event_ref(event2);

			if ((res = gst_element_send_event(text_sink, event2)))
				LOGD("sending event[%s] to subtitle sink element [%s] success!",
						GST_EVENT_TYPE_NAME(event2), GST_ELEMENT_NAME(text_sink));
			else
				LOGE("sending event[%s] to subtitle sink element [%s] failed!",
						GST_EVENT_TYPE_NAME(event2), GST_ELEMENT_NAME(text_sink));

			gst_event_unref(event2);
		}
	}

	gst_event_unref(event);

	MMPLAYER_FLEAVE();

	return res;
}

gboolean
_mmplayer_gst_seek(mmplayer_t *player, GstElement *element, gdouble rate,
			GstFormat format, GstSeekFlags flags, GstSeekType cur_type,
			gint64 cur, GstSeekType stop_type, gint64 stop)
{
	GstEvent *event = NULL;
	gboolean result = FALSE;

	MMPLAYER_FENTER();

	MMPLAYER_RETURN_VAL_IF_FAIL(player, FALSE);

	if (player->pipeline && player->pipeline->textbin)
		__mmplayer_drop_subtitle(player, FALSE);

	event = gst_event_new_seek(rate, format, flags, cur_type,
		cur, stop_type, stop);

	result = _mmplayer_gst_send_event_to_sink(player, event);

	MMPLAYER_FLEAVE();

	return result;
}

int
_mmplayer_gst_set_position(mmplayer_t *player, gint64 position, gboolean internal_called)
{
	int ret = MM_ERROR_NONE;
	gint64 pos_nsec = 0;
	gboolean accurated = FALSE;
	GstSeekFlags seek_flags = GST_SEEK_FLAG_FLUSH;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
	MMPLAYER_RETURN_VAL_IF_FAIL(!MMPLAYER_IS_LIVE_STREAMING(player), MM_ERROR_PLAYER_NO_OP);

	if ((MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PLAYING)
		&& (MMPLAYER_CURRENT_STATE(player) != MM_PLAYER_STATE_PAUSED))
		goto PENDING;

	ret = __mmplayer_gst_check_duration(player, position);
	if (ret != MM_ERROR_NONE) {
		LOGE("failed to check duration 0x%X", ret);
		return (ret == MM_ERROR_PLAYER_NO_OP) ? MM_ERROR_NONE : ret;
	}

	if (!__mmplayer_gst_check_seekable(player))
		return MM_ERROR_PLAYER_NO_OP;

	LOGD("seeking to(%"G_GINT64_FORMAT") nsec, rate: %f, dur: %"G_GINT64_FORMAT" nsec",
				position, player->playback_rate, player->duration);

	/* For rtspsrc stack , npt-start value coming from server is used for finding the current position.
	   But when a rtsp clip (especially from Youtube Desktop View) is paused and kept for sometime,npt-start is still increasing.
	   This causes problem is position calculation during normal pause resume scenarios also.
	   Currently during seek , we are sending the current position to rtspsrc module for position saving for later use. */
	if ((MMPLAYER_IS_RTSP_STREAMING(player)) &&
		(_mmplayer_get_stream_service_type(player) == STREAMING_SERVICE_VOD)) {
		if (!gst_element_query_position(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_FORMAT_TIME, &pos_nsec))
			LOGW("getting current position failed in seek");

		player->last_position = pos_nsec;
		g_object_set(player->pipeline->mainbin[MMPLAYER_M_SRC].gst, "resume-position", player->last_position, NULL);
	}

	if (player->seek_state != MMPLAYER_SEEK_NONE) {
		LOGD("not completed seek");
		return MM_ERROR_PLAYER_DOING_SEEK;
	}

	if (!internal_called)
		player->seek_state = MMPLAYER_SEEK_IN_PROGRESS;

	/* rtsp streaming case, there is no sink after READY TO PAUSE state(no preroll state change).
		that's why set position through property. */
	if ((MMPLAYER_IS_RTSP_STREAMING(player)) &&
		(MMPLAYER_CURRENT_STATE(player) == MM_PLAYER_STATE_PAUSED) &&
		(MMPLAYER_PREV_STATE(player) == MM_PLAYER_STATE_READY) &&
		(!player->videodec_linked) && (!player->audiodec_linked)) {

		LOGD("[%s] set position =%"GST_TIME_FORMAT,
				GST_ELEMENT_NAME(player->pipeline->mainbin[MMPLAYER_M_SRC].gst), GST_TIME_ARGS(position));

		g_object_set(player->pipeline->mainbin[MMPLAYER_M_SRC].gst, "pending-start-position", position, NULL);
		player->seek_state = MMPLAYER_SEEK_NONE;
		MMPLAYER_POST_MSG(player, MM_MESSAGE_SEEK_COMPLETED, NULL);
	} else {
		mm_attrs_get_int_by_name(player->attrs, "accurate_seek", &accurated);
		if (accurated)
			seek_flags |= GST_SEEK_FLAG_ACCURATE;
		else
			seek_flags |= GST_SEEK_FLAG_KEY_UNIT;

		if (!_mmplayer_gst_seek(player, player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, player->playback_rate,
						GST_FORMAT_TIME, seek_flags,
						GST_SEEK_TYPE_SET, position, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
			LOGE("failed to set position");
			goto SEEK_ERROR;
		}
	}

	/* NOTE : store last seeking point to overcome some bad operation
	 *     (returning zero when getting current position) of some elements
	 */
	player->last_position = position;

	/* MSL should guarante playback rate when seek is selected during trick play of fast forward. */
	if (player->playback_rate > 1.0)
		_mmplayer_set_playspeed((MMHandleType)player, player->playback_rate, FALSE);

	if ((player->streamer) && (player->streamer->buffering_state & MM_PLAYER_BUFFERING_IN_PROGRESS)) {
		LOGD("buffering should be reset after seeking");
		player->streamer->buffering_state = MM_PLAYER_BUFFERING_ABORT;
		player->streamer->buffering_percent = 100; /* after seeking, new per can be non-zero. */
	}

	MMPLAYER_FLEAVE();
	return MM_ERROR_NONE;

PENDING:
	player->pending_seek.is_pending = true;
	player->pending_seek.pos = position;

	LOGW("player current-state : %s, pending-state : %s, just preserve pending position(%"G_GINT64_FORMAT")",
		MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)),
		MMPLAYER_STATE_GET_NAME(MMPLAYER_PENDING_STATE(player)),
		player->pending_seek.pos);

	return MM_ERROR_NONE;

SEEK_ERROR:
	player->seek_state = MMPLAYER_SEEK_NONE;
	return MM_ERROR_PLAYER_SEEK;
}

int
_mmplayer_gst_get_position(mmplayer_t *player, gint64 *position)
{
#define TRICKPLAY_OFFSET GST_MSECOND

	mmplayer_state_e current_state = MM_PLAYER_STATE_NONE;
	gint64 pos_nsec = 0;
	gboolean ret = TRUE;

	MMPLAYER_RETURN_VAL_IF_FAIL(player && position && player->pipeline && player->pipeline->mainbin,
		MM_ERROR_PLAYER_NOT_INITIALIZED);

	current_state = MMPLAYER_CURRENT_STATE(player);

	/* NOTE : query position except paused state to overcome some bad operation
	 * please refer to below comments in details
	 */
	if (current_state != MM_PLAYER_STATE_PAUSED)
		ret = gst_element_query_position(player->pipeline->mainbin[MMPLAYER_M_PIPE].gst, GST_FORMAT_TIME, &pos_nsec);

	/* NOTE : get last point to overcome some bad operation of some elements
	 *(returning zero when getting current position in paused state
	 * and when failed to get postion during seeking
	 */
	if ((current_state == MM_PLAYER_STATE_PAUSED) || (!ret)) {
		LOGD("pos_nsec = %"GST_TIME_FORMAT" and ret = %d and state = %d", GST_TIME_ARGS(pos_nsec), ret, current_state);

		if (player->playback_rate < 0.0)
			pos_nsec = player->last_position - TRICKPLAY_OFFSET;
		else
			pos_nsec = player->last_position;

		if (!ret)
			pos_nsec = player->last_position;
		else
			player->last_position = pos_nsec;

		LOGD("returning last point : %"GST_TIME_FORMAT, GST_TIME_ARGS(pos_nsec));

	} else {
		if (player->duration > 0 && pos_nsec > player->duration)
			pos_nsec = player->duration;

		player->last_position = pos_nsec;
	}

	*position = pos_nsec;

	return MM_ERROR_NONE;
}

int
_mmplayer_gst_get_buffer_position(mmplayer_t *player, int *start_pos, int *end_pos)
{
#define STREAMING_IS_FINISHED	0
#define BUFFERING_MAX_PER	100
#define DEFAULT_PER_VALUE	-1
#define CHECK_PERCENT_VALUE(a, min, max)(((a) > (min)) ? (((a) < (max)) ? (a) : (max)) : (min))

	mmplayer_gst_element_t *mainbin = NULL;
	gint start_per = DEFAULT_PER_VALUE, end_per = DEFAULT_PER_VALUE;
	gint64 buffered_total = 0;
	gint64 position = 0;
	gint buffered_sec = -1;
	GstBufferingMode mode = GST_BUFFERING_STREAM;
	gint64 content_size_time = player->duration;
	guint64 content_size_bytes = player->http_content_size;

	MMPLAYER_RETURN_VAL_IF_FAIL(player &&
						player->pipeline &&
						player->pipeline->mainbin,
						MM_ERROR_PLAYER_NOT_INITIALIZED);

	MMPLAYER_RETURN_VAL_IF_FAIL(start_pos && end_pos, MM_ERROR_INVALID_ARGUMENT);

	*start_pos = 0;
	*end_pos = 0;

	if (!MMPLAYER_IS_HTTP_STREAMING(player)) {
		/* and rtsp is not ready yet. */
		LOGW("it's only used for http streaming case");
		return MM_ERROR_PLAYER_NO_OP;
	}

	if (content_size_time <= 0 || content_size_bytes <= 0) {
		LOGW("there is no content size");
		return MM_ERROR_NONE;
	}

	if (_mmplayer_gst_get_position(player, &position) != MM_ERROR_NONE) {
		LOGW("fail to get current position");
		return MM_ERROR_NONE;
	}

	LOGD("pos %"G_GINT64_FORMAT" msec, dur %d sec, len %"G_GUINT64_FORMAT" bytes",
		GST_TIME_AS_MSECONDS(position), (guint)GST_TIME_AS_SECONDS(content_size_time), content_size_bytes);

	mainbin = player->pipeline->mainbin;
	start_per = (gint)(floor(100 * (gdouble)position / (gdouble)content_size_time));

	if (mainbin[MMPLAYER_M_MUXED_S_BUFFER].gst) {
		GstQuery *query = NULL;
		gint byte_in_rate = 0, byte_out_rate = 0;
		gint64 estimated_total = 0;

		query = gst_query_new_buffering(GST_FORMAT_BYTES);
		if (!query || !gst_element_query(mainbin[MMPLAYER_M_MUXED_S_BUFFER].gst, query)) {
			LOGW("fail to get buffering query from queue2");
			if (query)
				gst_query_unref(query);
			return MM_ERROR_NONE;
		}

		gst_query_parse_buffering_stats(query, &mode, &byte_in_rate, &byte_out_rate, NULL);
		LOGD("mode %d, in_rate %d, out_rate %d", mode, byte_in_rate, byte_out_rate);

		if (mode == GST_BUFFERING_STREAM) {
			/* using only queue in case of push mode(ts / mp3) */
			if (gst_element_query_position(mainbin[MMPLAYER_M_SRC].gst,
				GST_FORMAT_BYTES, &buffered_total)) {
				LOGD("buffered_total %"G_GINT64_FORMAT, buffered_total);
				end_per = 100 * buffered_total / content_size_bytes;
			}
		} else {
			/* GST_BUFFERING_TIMESHIFT or GST_BUFFERING_DOWNLOAD */
			guint idx = 0;
			guint num_of_ranges = 0;
			gint64 start_byte = 0, stop_byte = 0;

			gst_query_parse_buffering_range(query, NULL, NULL, NULL, &estimated_total);
			if (estimated_total != STREAMING_IS_FINISHED) {
				/* buffered size info from queue2 */
				num_of_ranges = gst_query_get_n_buffering_ranges(query);
				for (idx = 0; idx < num_of_ranges; idx++) {
					gst_query_parse_nth_buffering_range(query, idx, &start_byte, &stop_byte);
					LOGD("range %d, %"G_GINT64_FORMAT" ~ %"G_GUINT64_FORMAT, idx, start_byte, stop_byte);

					buffered_total += (stop_byte - start_byte);
				}
			} else {
				end_per = BUFFERING_MAX_PER;
			}
		}
		gst_query_unref(query);
	}

	if (end_per == DEFAULT_PER_VALUE) {
		guint dur_sec = (guint)(content_size_time/GST_SECOND);
		if (dur_sec > 0) {
			guint avg_byterate = (guint)(content_size_bytes / dur_sec);

			/* buffered size info from multiqueue */
			if (mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].gst) {
				guint curr_size_bytes = 0;
				g_object_get(G_OBJECT(mainbin[MMPLAYER_M_DEMUXED_S_BUFFER].gst),
					"curr-size-bytes", &curr_size_bytes, NULL);
				LOGD("curr_size_bytes of multiqueue = %d", curr_size_bytes);
				buffered_total += curr_size_bytes;
			}

			if (avg_byterate > 0)
				buffered_sec = (gint)(ceil((gdouble)buffered_total / (gdouble)avg_byterate));
			else if (player->total_maximum_bitrate > 0)
				buffered_sec = (gint)(ceil((gdouble)GET_BIT_FROM_BYTE(buffered_total) / (gdouble)player->total_maximum_bitrate));
			else if (player->total_bitrate > 0)
				buffered_sec = (gint)(ceil((gdouble)GET_BIT_FROM_BYTE(buffered_total) / (gdouble)player->total_bitrate));

			if (buffered_sec >= 0)
				end_per = start_per + (gint)(ceil)(100 * (gdouble)buffered_sec / (gdouble)dur_sec);
		}
	}

	*start_pos = CHECK_PERCENT_VALUE(start_per, 0, 100);
	*end_pos = CHECK_PERCENT_VALUE(end_per, *start_pos, 100);

	LOGD("buffered info: %"G_GINT64_FORMAT" bytes, %d sec, per %d~%d",
		buffered_total, buffered_sec, *start_pos, *end_pos);

	return MM_ERROR_NONE;
}

GstElement *
_mmplayer_gst_create_source(mmplayer_t *player)
{
	GstElement *element = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
				player->pipeline->mainbin, NULL);

	/* setup source for gapless play */
	switch (player->profile.uri_type) {
	/* file source */
	case MM_PLAYER_URI_TYPE_FILE:
		element = __mmplayer_gst_make_file_src(player);
		break;
	case MM_PLAYER_URI_TYPE_URL_HTTP:
		element = __mmplayer_gst_make_http_src(player);
		break;
	default:
		LOGE("not support uri type %d", player->profile.uri_type);
		break;
	}

	if (!element) {
		LOGE("failed to create source element");
		return NULL;
	}

	MMPLAYER_FLEAVE();
	return element;
}

int
_mmplayer_gst_build_es_pipeline(mmplayer_t *player)
{
	MMHandleType attrs = 0;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
				player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	/* get profile attribute */
	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("failed to get content attribute");
		return MM_ERROR_PLAYER_INTERNAL;
	}

	SECURE_LOGD("uri : %s", player->profile.uri);

	mm_attrs_set_int_by_name(attrs, "profile_prepare_async", TRUE);
	if (mm_attrs_commit_all(attrs)) /* return -1 if error */
		LOGE("failed to commit");

	if (player->v_stream_caps && !__mmplayer_gst_create_es_path(player, MM_PLAYER_STREAM_TYPE_VIDEO, player->v_stream_caps))
		return MM_ERROR_PLAYER_INTERNAL;

	if (player->a_stream_caps && !__mmplayer_gst_create_es_path(player, MM_PLAYER_STREAM_TYPE_AUDIO, player->a_stream_caps))
		return MM_ERROR_PLAYER_INTERNAL;

	if (player->s_stream_caps && !__mmplayer_gst_create_es_path(player, MM_PLAYER_STREAM_TYPE_TEXT, player->s_stream_caps))
		return MM_ERROR_PLAYER_INTERNAL;

	MMPLAYER_FLEAVE();
	return MM_ERROR_NONE;
}

int
_mmplayer_gst_build_pipeline(mmplayer_t *player)
{
	mmplayer_gst_element_t *mainbin = NULL;
	GstElement *src_elem = NULL;
	GstElement *autoplug_elem = NULL;
	GList *element_bucket = NULL;
	MMHandleType attrs = 0;
	main_element_id_e autoplug_elem_id = MMPLAYER_M_NUM;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
				player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	/* get profile attribute */
	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("failed to get content attribute");
		return MM_ERROR_PLAYER_INTERNAL;
	}

	LOGD("uri type %d", player->profile.uri_type);

	/* create source element */
	switch (player->profile.uri_type) {
	case MM_PLAYER_URI_TYPE_URL_RTSP:
		src_elem = __mmplayer_gst_make_rtsp_src(player);
		break;
	case MM_PLAYER_URI_TYPE_URL_HTTP:
		src_elem = __mmplayer_gst_make_http_src(player);
		break;
	case MM_PLAYER_URI_TYPE_FILE:
		src_elem = __mmplayer_gst_make_file_src(player);
		break;
	case MM_PLAYER_URI_TYPE_SS:
		{
			gint http_timeout = DEFAULT_HTTP_TIMEOUT;
			src_elem = gst_element_factory_make("souphttpsrc", "http streaming source");
			if (!src_elem) {
				LOGE("failed to create http streaming source element[%s]", player->ini.httpsrc_element);
				break;
			}

			if (player->ini.http_timeout != DEFAULT_HTTP_TIMEOUT) {
				LOGD("get timeout from ini");
				http_timeout = player->ini.http_timeout;
			}

			/* setting property to streaming source */
			g_object_set(G_OBJECT(src_elem), "location", player->profile.uri, "timeout", http_timeout, NULL);
		}
		break;
	case MM_PLAYER_URI_TYPE_MEM:
		{
			GstAppStreamType stream_type = GST_APP_STREAM_TYPE_RANDOM_ACCESS;

			src_elem = gst_element_factory_make("appsrc", "mem-source");
			if (!src_elem) {
				LOGE("failed to create appsrc element");
				break;
			}

			g_object_set(src_elem, "stream-type", stream_type,
				"size", (gint64)player->profile.input_mem.len, "blocksize", 20480, NULL);

			_mmplayer_add_signal_connection(player, G_OBJECT(src_elem), MM_PLAYER_SIGNAL_TYPE_OTHERS, "seek-data",
											G_CALLBACK(__mmplayer_gst_appsrc_seek_data_mem), (gpointer)&player->profile.input_mem);
			_mmplayer_add_signal_connection(player, G_OBJECT(src_elem), MM_PLAYER_SIGNAL_TYPE_OTHERS, "need-data",
											G_CALLBACK(__mmplayer_gst_appsrc_feed_data_mem), (gpointer)&player->profile.input_mem);
		}
		break;
	default:
		LOGE("not support uri type");
		break;
	}

	if (!src_elem) {
		LOGE("failed to create source element");
		return MM_ERROR_PLAYER_INTERNAL;
	}

	mainbin = player->pipeline->mainbin;

	/* take source element */
	LOGD("source elem is created %s", GST_ELEMENT_NAME(src_elem));

	mainbin[MMPLAYER_M_SRC].id = MMPLAYER_M_SRC;
	mainbin[MMPLAYER_M_SRC].gst = src_elem;
	element_bucket = g_list_append(element_bucket, &mainbin[MMPLAYER_M_SRC]);

	/* create next element for auto-plugging */
	if (MMPLAYER_IS_HTTP_STREAMING(player)) {
		autoplug_elem_id = MMPLAYER_M_TYPEFIND;
		autoplug_elem = gst_element_factory_make("typefind", "typefinder");
		if (!autoplug_elem) {
			LOGE("failed to create typefind element");
			goto ERROR;
		}

		_mmplayer_add_signal_connection(player, G_OBJECT(autoplug_elem), MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "have-type",
									G_CALLBACK(_mmplayer_typefind_have_type), (gpointer)player);
	} else if (!MMPLAYER_IS_RTSP_STREAMING(player)) {
		autoplug_elem_id = MMPLAYER_M_AUTOPLUG;
		autoplug_elem = _mmplayer_gst_make_decodebin(player);
		if (!autoplug_elem) {
			LOGE("failed to create decodebin");
			goto ERROR;
		}

		/* default size of mq in decodebin is 2M
		 * but it can cause blocking issue during seeking depends on content. */
		g_object_set(G_OBJECT(autoplug_elem), "max-size-bytes", (5 * 1024 * 1024), NULL);
	}

	if (autoplug_elem) {
		LOGD("autoplug elem is created %s", GST_ELEMENT_NAME(autoplug_elem));
		mainbin[autoplug_elem_id].id = autoplug_elem_id;
		mainbin[autoplug_elem_id].gst = autoplug_elem;

		element_bucket = g_list_append(element_bucket, &mainbin[autoplug_elem_id]);
	}

	/* add elements to pipeline */
	if (!_mmplayer_gst_element_add_bucket_to_bin(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), element_bucket)) {
		LOGE("failed to add elements to pipeline");
		goto ERROR;
	}

	/* linking elements in the bucket by added order. */
	if (_mmplayer_gst_element_link_bucket(element_bucket) == -1) {
		LOGE("failed to link some elements");
		goto ERROR;
	}

	/* FIXME: need to check whether this is required or not. */
	if (MMPLAYER_IS_HTTP_STREAMING(player) || MMPLAYER_IS_RTSP_STREAMING(player)) {
		/* create fakesink element for keeping the pipeline state PAUSED. if needed */
		mainbin[MMPLAYER_M_SRC_FAKESINK].id = MMPLAYER_M_SRC_FAKESINK;
		mainbin[MMPLAYER_M_SRC_FAKESINK].gst = gst_element_factory_make("fakesink", "state-holder");

		if (!mainbin[MMPLAYER_M_SRC_FAKESINK].gst) {
			LOGE("failed to create fakesink");
			goto ERROR;
		}
		GST_OBJECT_FLAG_UNSET(mainbin[MMPLAYER_M_SRC_FAKESINK].gst, GST_ELEMENT_FLAG_SINK);

		/* take ownership of fakesink. we are reusing it */
		gst_object_ref(mainbin[MMPLAYER_M_SRC_FAKESINK].gst);

		if (!gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), mainbin[MMPLAYER_M_SRC_FAKESINK].gst)) {
			LOGE("failed to add fakesink to bin");
			gst_object_unref(mainbin[MMPLAYER_M_SRC_FAKESINK].gst);
			goto ERROR;
		}
	}

	g_list_free(element_bucket);

	MMPLAYER_FLEAVE();
	return MM_ERROR_NONE;

ERROR:
	g_list_free(element_bucket);

	if (mainbin[MMPLAYER_M_SRC].gst)
		gst_object_unref(GST_OBJECT(mainbin[MMPLAYER_M_SRC].gst));

	if (mainbin[autoplug_elem_id].gst)
		gst_object_unref(GST_OBJECT(mainbin[autoplug_elem_id].gst));

	if (mainbin[MMPLAYER_M_SRC_FAKESINK].gst)
		gst_object_unref(GST_OBJECT(mainbin[MMPLAYER_M_SRC_FAKESINK].gst));

	mainbin[MMPLAYER_M_SRC].gst = NULL;
	mainbin[autoplug_elem_id].gst = NULL;
	mainbin[MMPLAYER_M_SRC_FAKESINK].gst = NULL;

	return MM_ERROR_PLAYER_INTERNAL;
}

int
_mmplayer_gst_add_bus_watch(mmplayer_t *player)
{
	GstBus	*bus = NULL;
	mmplayer_gst_element_t *mainbin = NULL;

	MMPLAYER_FENTER();
	MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline &&
				player->pipeline->mainbin, MM_ERROR_PLAYER_NOT_INITIALIZED);

	mainbin = player->pipeline->mainbin;

	/* connect bus callback */
	bus = gst_pipeline_get_bus(GST_PIPELINE(mainbin[MMPLAYER_M_PIPE].gst));
	if (!bus) {
		LOGE("cannot get bus from pipeline");
		return MM_ERROR_PLAYER_INTERNAL;
	}

	player->bus_watcher = gst_bus_add_watch(bus, (GstBusFunc)__mmplayer_gst_msg_push, player);
	player->context.thread_default = g_main_context_get_thread_default();
	if (player->context.thread_default == NULL) {
		player->context.thread_default = g_main_context_default();
		LOGD("thread-default context is the global default context");
	}
	LOGW("bus watcher thread context = %p, watcher : %d", player->context.thread_default, player->bus_watcher);

	/* set sync handler to get tag synchronously */
	gst_bus_set_sync_handler(bus, __mmplayer_gst_bus_sync_callback, player, NULL);
	gst_object_unref(GST_OBJECT(bus));

	/* create gst bus_msb_cb thread */
	g_mutex_init(&player->bus_msg_thread_mutex);
	g_cond_init(&player->bus_msg_thread_cond);
	player->bus_msg_thread_exit = FALSE;
	player->bus_msg_thread =
		g_thread_try_new("gst_bus_msg_thread", __mmplayer_gst_bus_msg_thread, (gpointer)player, NULL);
	if (!player->bus_msg_thread) {
		LOGE("failed to create gst BUS msg thread");
		g_mutex_clear(&player->bus_msg_thread_mutex);
		g_cond_clear(&player->bus_msg_thread_cond);
		return MM_ERROR_PLAYER_INTERNAL;
	}

	MMPLAYER_FLEAVE();
	return MM_ERROR_NONE;
}

void
_mmplayer_activate_next_source(mmplayer_t *player, GstState target)
{
	mmplayer_gst_element_t *mainbin = NULL;
	MMMessageParamType msg_param = {0,};
	GstElement *element = NULL;
	MMHandleType attrs = 0;
	char *uri = NULL;
	main_element_id_e elem_idx = MMPLAYER_M_NUM;

	MMPLAYER_FENTER();

	if (!player || !player->pipeline || !player->pipeline->mainbin) {
		LOGE("player is not initialized");
		goto ERROR;
	}

	mainbin = player->pipeline->mainbin;
	msg_param.code = MM_ERROR_PLAYER_INTERNAL;

	attrs = MMPLAYER_GET_ATTRS(player);
	if (!attrs) {
		LOGE("fail to get attributes");
		goto ERROR;
	}

	mm_attrs_get_string_by_name(attrs, "profile_uri", &uri);

	if (_mmplayer_parse_profile((const char *)uri, NULL, &player->profile) != MM_ERROR_NONE) {
		LOGE("failed to parse profile");
		msg_param.code = MM_ERROR_PLAYER_INVALID_URI;
		goto ERROR;
	}

	if ((MMPLAYER_URL_HAS_DASH_SUFFIX(player)) ||
		(MMPLAYER_URL_HAS_HLS_SUFFIX(player))) {
		LOGE("dash or hls is not supportable");
		msg_param.code = MM_ERROR_PLAYER_INVALID_URI;
		goto ERROR;
	}

	element = _mmplayer_gst_create_source(player);
	if (!element) {
		LOGE("no source element was created");
		goto ERROR;
	}

	if (gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), element) == FALSE) {
		LOGE("failed to add source element to pipeline");
		gst_object_unref(GST_OBJECT(element));
		element = NULL;
		goto ERROR;
	}

	/* take source element */
	mainbin[MMPLAYER_M_SRC].id = MMPLAYER_M_SRC;
	mainbin[MMPLAYER_M_SRC].gst = element;

	element = NULL;

	if (MMPLAYER_IS_HTTP_STREAMING(player)) {
		if (player->streamer == NULL) {
			player->streamer = _mm_player_streaming_create();
			_mm_player_streaming_initialize(player->streamer, TRUE);
		}

		elem_idx = MMPLAYER_M_TYPEFIND;
		element = gst_element_factory_make("typefind", "typefinder");
		_mmplayer_add_signal_connection(player, G_OBJECT(element),
			MM_PLAYER_SIGNAL_TYPE_AUTOPLUG, "have-type", G_CALLBACK(_mmplayer_typefind_have_type), (gpointer)player);
	} else {
		elem_idx = MMPLAYER_M_AUTOPLUG;
		element = _mmplayer_gst_make_decodebin(player);
	}

	/* check autoplug element is OK */
	if (!element) {
		LOGE("can not create element(%d)", elem_idx);
		goto ERROR;
	}

	if (gst_bin_add(GST_BIN(mainbin[MMPLAYER_M_PIPE].gst), element) == FALSE) {
		LOGE("failed to add sinkbin to pipeline");
		gst_object_unref(GST_OBJECT(element));
		element = NULL;
		goto ERROR;
	}

	mainbin[elem_idx].id = elem_idx;
	mainbin[elem_idx].gst = element;

	if (gst_element_link(mainbin[MMPLAYER_M_SRC].gst, mainbin[elem_idx].gst) == FALSE) {
		LOGE("Failed to link src - autoplug(or typefind)");
		goto ERROR;
	}

	if (gst_element_set_state(mainbin[MMPLAYER_M_SRC].gst, target) == GST_STATE_CHANGE_FAILURE) {
		LOGE("Failed to change state of src element");
		goto ERROR;
	}

	if (!MMPLAYER_IS_HTTP_STREAMING(player)) {
		if (gst_element_set_state(mainbin[MMPLAYER_M_AUTOPLUG].gst, target) == GST_STATE_CHANGE_FAILURE) {
			LOGE("Failed to change state of decodebin");
			goto ERROR;
		}
	} else {
		if (gst_element_set_state(mainbin[MMPLAYER_M_TYPEFIND].gst, target) == GST_STATE_CHANGE_FAILURE) {
			LOGE("Failed to change state of src element");
			goto ERROR;
		}
	}

	player->gapless.stream_changed = TRUE;
	player->gapless.running = TRUE;
	MMPLAYER_FLEAVE();
	return;

ERROR:
	if (player) {
		MMPLAYER_PLAYBACK_UNLOCK(player);

		if (!player->msg_posted) {
			MMPLAYER_POST_MSG(player, MM_MESSAGE_ERROR, &msg_param);
			player->msg_posted = TRUE;
		}
	}
	return;
}