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
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
|
diff --git a/Makefile b/Makefile
index 9fc45de..921b449 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,21 @@ INCLUDES+=-I./ -Ilinux -Iffmpeg_compiled/usr/local/include/ -I /usr/include/dbus
DIST ?= omxplayer-dist
-SRC=linux/XMemUtils.cpp \
+INCLUDES+=-Ialsa
+LDFLAGS+=-lasound
+SRC += \
+ alsa/omx_semaphore.cpp \
+ alsa/omx_alsasink_component.cpp \
+ alsa/omx_base_audio_port.cpp \
+ alsa/omx_base_clock_port.cpp \
+ alsa/omx_base_component.cpp \
+ alsa/omx_base_port.cpp \
+ alsa/omx_base_sink.cpp \
+ alsa/omx_queue.cpp \
+ alsa/omx_loader_XBMC.cpp
+
+SRC += \
+ linux/XMemUtils.cpp \
utils/log.cpp \
DynamicDll.cpp \
utils/PCMRemap.cpp \
@@ -34,8 +48,9 @@ SRC=linux/XMemUtils.cpp \
Srt.cpp \
KeyConfig.cpp \
OMXControl.cpp \
- Keyboard.cpp \
- omxplayer.cpp \
+ Keyboard.cpp
+
+SRC += omxplayer.cpp
OBJS+=$(filter %.o,$(SRC:.cpp=.o))
diff --git a/Makefile.include b/Makefile.include
index 58e9560..3b99d3b 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -1,40 +1,5 @@
-USE_BUILDROOT=0
-FLOAT=hard
-
-ifeq ($(USE_BUILDROOT), 1)
-BUILDROOT :=/opt/xbmc-bcm/buildroot
-SDKSTAGE :=$(BUILDROOT)/output/staging
-TARGETFS :=$(BUILDROOT)/output/target
-TOOLCHAIN :=$(BUILDROOT)/output/host/usr/
-HOST :=arm-unknown-linux-gnueabi
-SYSROOT :=$(BUILDROOT)/output/host/usr/arm-unknown-linux-gnueabi/sysroot
-else
-BUILDROOT :=/opt/bcm-rootfs
-SDKSTAGE :=/opt/bcm-rootfs
-TARGETFS :=/opt/bcm-rootfs
-TOOLCHAIN :=/home/dc4/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/
-HOST :=arm-linux-gnueabihf
-#SYSROOT :=$(TOOLCHAIN)/arm-bcm2708hardfp-linux-gnueabi/sysroot
-SYSROOT :=/opt/bcm-rootfs
-endif
-
-JOBS=7
-
-CFLAGS := -isystem$(PREFIX)/include
-CXXFLAGS := $(CFLAGS)
-CPPFLAGS := $(CFLAGS)
-LDFLAGS := -L$(BUILDROOT)/lib
-LD := $(TOOLCHAIN)/bin/$(HOST)-ld --sysroot=$(SYSROOT)
-CC := $(TOOLCHAIN)/bin/$(HOST)-gcc --sysroot=$(SYSROOT)
-CXX := $(TOOLCHAIN)/bin/$(HOST)-g++ --sysroot=$(SYSROOT)
-OBJDUMP := $(TOOLCHAIN)/bin/$(HOST)-objdump
-RANLIB := $(TOOLCHAIN)/bin/$(HOST)-ranlib
-STRIP := $(TOOLCHAIN)/bin/$(HOST)-strip
-AR := $(TOOLCHAIN)/bin/$(HOST)-ar
-CXXCP := $(CXX) -E
-PATH := $(PREFIX)/bin:$(BUILDROOT)/output/host/usr/bin:$(PATH)
-
-CFLAGS += -pipe -mfloat-abi=$(FLOAT) -mcpu=arm1176jzf-s -fomit-frame-pointer -mabi=aapcs-linux -mtune=arm1176jzf-s -mfpu=vfp -Wno-psabi -mno-apcs-stack-check -g -mstructure-size-boundary=32 -mno-sched-prolog
-LDFLAGS += -L$(SDKSTAGE)/lib -L$(SDKSTAGE)/usr/lib -L$(SDKSTAGE)/opt/vc/lib/ -Lpcre/build
-#INCLUDES += -isystem$(SDKSTAGE)/usr/include -isystem$(SDKSTAGE)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -isystem$(SDKSTAGE)/usr/include/freetype2
-INCLUDES += -isystem$(SDKSTAGE)/opt/vc/include -isystem$(SYSROOT)/usr/include -isystem$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -Ipcre/build -Iboost-trunk -Ifreetype2/include
+INCLUDES:=-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux
+INCLUDES+=-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include
+LDFLAGS:=-L/opt/vc/lib -Wl,-rpath,/opt/vc/lib
+LDFLAGS+=-lfreetype -ldbus-1
+STRIP:=echo
diff --git a/OMXAudio.cpp b/OMXAudio.cpp
index 41f282d..e1e82c4 100644
--- a/OMXAudio.cpp
+++ b/OMXAudio.cpp
@@ -112,6 +112,11 @@ bool COMXAudio::PortSettingsChanged()
if(!m_omx_render_hdmi.Initialize("OMX.broadcom.audio_render", OMX_IndexParamAudioInit))
return false;
}
+ if (m_config.device == "omx:alsa")
+ {
+ if(!m_omx_render_analog.Initialize("OMX.XBMC.alsa.alsasink", OMX_IndexParamAudioInit))
+ return false;
+ }
UpdateAttenuation();
diff --git a/OMXCore.cpp b/OMXCore.cpp
index 9d5fe61..389c41e 100644
--- a/OMXCore.cpp
+++ b/OMXCore.cpp
@@ -35,6 +35,7 @@
#ifdef TARGET_LINUX
#include "XMemUtils.h"
+#include "alsa/omx_loader_XBMC.h"
#endif
//#define OMX_DEBUG_EVENTS
@@ -1430,6 +1431,12 @@ bool COMXCoreComponent::Initialize( const std::string &component_name, OMX_INDEX
if(!m_handle)
{
omx_err = m_DllOMX->OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks);
+#ifdef TARGET_LINUX
+ if (strncmp("OMX.XBMC.", component_name.c_str(), 9) == 0)
+ omx_err = OMX_GetHandle_XBMC(&m_handle, (char*) component_name.c_str(), this, &m_callbacks);
+ else
+#endif
+ omx_err = m_DllOMX->OMX_GetHandle(&m_handle, (char*)component_name.c_str(), this, &m_callbacks);
if (!m_handle || omx_err != OMX_ErrorNone)
{
CLog::Log(LOGERROR, "COMXCoreComponent::Initialize - could not get component handle for %s omx_err(0x%08x)\n",
@@ -1505,6 +1512,11 @@ bool COMXCoreComponent::Deinitialize()
CLog::Log(LOGDEBUG, "COMXCoreComponent::Deinitialize : %s handle %p\n",
m_componentName.c_str(), m_handle);
+#ifdef TARGET_LINUX
+ if (strncmp("OMX.XBMC.", m_componentName.c_str(), 9) == 0)
+ omx_err = OMX_FreeHandle_XBMC(m_handle);
+ else
+#endif
omx_err = m_DllOMX->OMX_FreeHandle(m_handle);
if (omx_err != OMX_ErrorNone)
{
diff --git a/README.md b/README.md
index 2eb78f3..f70d73c 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,7 @@ Usage: omxplayer [OPTIONS] [FILE]
-v --version Print version info
-k --keys Print key bindings
-n --aidx index Audio stream index : e.g. 1
- -o --adev device Audio out device : e.g. hdmi/local/both
+ -o --adev device Audio out device : e.g. hdmi/local/both/alsa
-i --info Dump stream format and exit
-I --with-info dump stream format before playback
-s --stats Pts and buffer stats
diff --git a/alsa/omx_alsasink_component.cpp b/alsa/omx_alsasink_component.cpp
new file mode 100644
index 0000000..9803e63
--- /dev/null
+++ b/alsa/omx_alsasink_component.cpp
@@ -0,0 +1,1035 @@
+/**
+ @file src/components/alsa/omx_alsasink_component.c
+
+ OpenMAX ALSA sink component. This component is an audio sink that uses ALSA library.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-08-08 06:56:06 +0200 (Fri, 08 Aug 2008) $
+ Revision $Rev: 581 $
+ Author $Author: pankaj_sen $
+
+*/
+
+#undef OMX_SKIP64BIT
+#include <omx_base_component.h>
+#include <omx_base_audio_port.h>
+#include <omx_base_clock_port.h>
+#include <omx_alsasink_component.h>
+
+/** Maximum Number of AlsaSink Instance*/
+#define MAX_COMPONENT_ALSASINK 1
+
+/** Number of AlsaSink Instance*/
+static OMX_U32 noAlsasinkInstance=0;
+
+#ifdef AV_SYNC_LOG /* for checking AV sync */ //TODO : give seg fault if enabled
+static FILE *fd = NULL;
+#endif
+
+/** The Constructor
+ */
+OMX_ERRORTYPE omx_alsasink_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
+ int err;
+ int omxErr;
+ omx_base_audio_PortType *pPort;
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private;
+
+ if (!openmaxStandComp->pComponentPrivate) {
+ openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_alsasink_component_PrivateType));
+ if(openmaxStandComp->pComponentPrivate==NULL) {
+ return OMX_ErrorInsufficientResources;
+ }
+ }
+
+ omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ omx_alsasink_component_Private->ports = NULL;
+
+ omxErr = omx_base_sink_Constructor(openmaxStandComp,cComponentName);
+ if (omxErr != OMX_ErrorNone) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio].nStartPortNumber = 0;
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts = 1;
+
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther].nStartPortNumber = 1;
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts = 1;
+
+ /** Allocate Ports and call port constructor. */
+ if ((omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)
+ && !omx_alsasink_component_Private->ports) {
+ omx_alsasink_component_Private->ports = (omx_base_PortType**)calloc((omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts), sizeof(omx_base_PortType *));
+ if (!omx_alsasink_component_Private->ports) {
+ return OMX_ErrorInsufficientResources;
+ }
+ omx_alsasink_component_Private->ports[0] = (omx_base_PortType*)calloc(1, sizeof(omx_base_audio_PortType));
+ if (!omx_alsasink_component_Private->ports[0]) {
+ return OMX_ErrorInsufficientResources;
+ }
+ base_audio_port_Constructor(openmaxStandComp, &omx_alsasink_component_Private->ports[0], 0, OMX_TRUE);
+
+ omx_alsasink_component_Private->ports[1] = (omx_base_PortType*)calloc(1, sizeof(omx_base_clock_PortType));
+ if (!omx_alsasink_component_Private->ports[1]) {
+ return OMX_ErrorInsufficientResources;
+ }
+ base_clock_port_Constructor(openmaxStandComp, &omx_alsasink_component_Private->ports[1], 1, OMX_TRUE);
+ omx_alsasink_component_Private->ports[1]->sPortParam.bEnabled = OMX_FALSE;
+ }
+
+ pPort = (omx_base_audio_PortType *) omx_alsasink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+
+ // set the pPort params, now that the ports exist
+ /** Domain specific section for the ports. */
+ pPort->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
+ /*Input pPort buffer size is equal to the size of the output buffer of the previous component*/
+ pPort->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
+
+ /* Initializing the function pointers */
+ omx_alsasink_component_Private->BufferMgmtCallback = omx_alsasink_component_BufferMgmtCallback;
+ omx_alsasink_component_Private->destructor = omx_alsasink_component_Destructor;
+ pPort->Port_SendBufferFunction = omx_alsasink_component_port_SendBufferFunction;
+ pPort->FlushProcessingBuffers = omx_alsasink_component_port_FlushProcessingBuffers;
+
+ setHeader(&pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+ pPort->sAudioParam.nPortIndex = 0;
+ pPort->sAudioParam.nIndex = 0;
+ pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingPCM;
+
+ /* OMX_AUDIO_PARAM_PCMMODETYPE */
+ setHeader(&omx_alsasink_component_Private->sPCMModeParam, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ omx_alsasink_component_Private->sPCMModeParam.nPortIndex = 0;
+ omx_alsasink_component_Private->sPCMModeParam.nChannels = 2;
+ omx_alsasink_component_Private->sPCMModeParam.eNumData = OMX_NumericalDataSigned;
+ omx_alsasink_component_Private->sPCMModeParam.eEndian = OMX_EndianLittle;
+ omx_alsasink_component_Private->sPCMModeParam.bInterleaved = OMX_TRUE;
+ omx_alsasink_component_Private->sPCMModeParam.nBitPerSample = 16;
+ omx_alsasink_component_Private->sPCMModeParam.nSamplingRate = 44100;
+ omx_alsasink_component_Private->sPCMModeParam.ePCMMode = OMX_AUDIO_PCMModeLinear;
+ omx_alsasink_component_Private->sPCMModeParam.eChannelMapping[0] = OMX_AUDIO_ChannelNone;
+
+/* testing the A/V sync */
+#ifdef AV_SYNC_LOG
+ fd = fopen("audio_timestamps.out","w");
+ if(!fd) {
+ DEBUG(DEB_LEV_ERR, "Couldn't open audio timestamp log err=%d\n",errno);
+ }
+#endif
+
+ noAlsasinkInstance++;
+ if(noAlsasinkInstance > MAX_COMPONENT_ALSASINK) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ /* Allocate the playback handle and the hardware parameter structure */
+ char* name = "default";
+ if ((err = snd_pcm_open (&omx_alsasink_component_Private->playback_handle, name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot open audio device %s (%s)\n", name, snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ else
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Got playback handle at %p %p in %i\n", omx_alsasink_component_Private->playback_handle, &omx_alsasink_component_Private->playback_handle, getpid());
+
+ if (snd_pcm_status_malloc(&omx_alsasink_component_Private->pcm_status) < 0 ) {
+ DEBUG(DEB_LEV_ERR, "%s: failed allocating pcm_status\n", __func__);
+ return OMX_ErrorHardware;
+ }
+
+ openmaxStandComp->SetParameter = omx_alsasink_component_SetParameter;
+ openmaxStandComp->GetParameter = omx_alsasink_component_GetParameter;
+ openmaxStandComp->GetConfig = omx_alsasink_component_GetConfig;
+
+ /* Write in the default parameters */
+ omx_alsasink_component_Private->AudioPCMConfigured = 0;
+ omx_alsasink_component_Private->eState = OMX_TIME_ClockStateStopped;
+ omx_alsasink_component_Private->xScale = 1<<16;
+
+ if (!omx_alsasink_component_Private->AudioPCMConfigured) {
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Configuring the PCM interface in the Init function\n");
+ omxErr = omx_alsasink_component_SetParameter(openmaxStandComp, OMX_IndexParamAudioPcm, &omx_alsasink_component_Private->sPCMModeParam);
+ if(omxErr != OMX_ErrorNone){
+ DEBUG(DEB_LEV_ERR, "In %s Error %08x\n",__func__,omxErr);
+ }
+ }
+
+ return OMX_ErrorNone;
+}
+
+/** The Destructor
+ */
+OMX_ERRORTYPE omx_alsasink_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ OMX_U32 i;
+
+ if(omx_alsasink_component_Private->pcm_status) {
+ snd_pcm_status_free(omx_alsasink_component_Private->pcm_status);
+ }
+ if(omx_alsasink_component_Private->playback_handle) {
+ snd_pcm_close(omx_alsasink_component_Private->playback_handle);
+ }
+
+ /* frees port/s */
+ if (omx_alsasink_component_Private->ports) {
+ for (i=0; i < (omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts); i++) {
+ if(omx_alsasink_component_Private->ports[i])
+ omx_alsasink_component_Private->ports[i]->PortDestructor(omx_alsasink_component_Private->ports[i]);
+ }
+ free(omx_alsasink_component_Private->ports);
+ omx_alsasink_component_Private->ports=NULL;
+ }
+
+#ifdef AV_SYNC_LOG
+ fclose(fd);
+#endif
+
+ noAlsasinkInstance--;
+
+ return omx_base_sink_Destructor(openmaxStandComp);
+
+}
+
+/** @brief the entry point for sending buffers to the alsa sink port
+ *
+ * This function can be called by the EmptyThisBuffer or FillThisBuffer. It depends on
+ * the nature of the port, that can be an input or output port.
+ */
+OMX_ERRORTYPE omx_alsasink_component_port_SendBufferFunction(omx_base_PortType *openmaxStandPort, OMX_BUFFERHEADERTYPE* pBuffer) {
+
+ OMX_ERRORTYPE err;
+ OMX_U32 portIndex;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ OMX_BOOL SendFrame;
+ omx_base_clock_PortType* pClockPort;
+#if NO_GST_OMX_PATCH
+ unsigned int i;
+#endif
+
+ portIndex = (openmaxStandPort->sPortParam.eDir == OMX_DirInput)?pBuffer->nInputPortIndex:pBuffer->nOutputPortIndex;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s portIndex %lu\n", __func__, (unsigned long)portIndex);
+
+ if (portIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port for this operation portIndex=%d port->portIndex=%d\n",
+ __func__, (int)portIndex, (int)openmaxStandPort->sPortParam.nPortIndex);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if(omx_base_component_Private->state == OMX_StateInvalid) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are in OMX_StateInvalid\n", __func__);
+ return OMX_ErrorInvalidState;
+ }
+
+ if(omx_base_component_Private->state != OMX_StateExecuting &&
+ omx_base_component_Private->state != OMX_StatePause &&
+ omx_base_component_Private->state != OMX_StateIdle) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are not in executing/paused/idle state, but in %d\n", __func__, omx_base_component_Private->state);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ if (!PORT_IS_ENABLED(openmaxStandPort) || (PORT_IS_BEING_DISABLED(openmaxStandPort) && !PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) ||
+ (omx_base_component_Private->transientState == OMX_TransStateExecutingToIdle &&
+ (PORT_IS_TUNNELED(openmaxStandPort) && !PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)))) {
+ DEBUG(DEB_LEV_ERR, "In %s: Port %d is disabled comp = %s \n", __func__, (int)portIndex,omx_base_component_Private->name);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+
+ /* Temporarily disable this check for gst-openmax */
+#if NO_GST_OMX_PATCH
+ {
+ OMX_BOOL foundBuffer = OMX_FALSE;
+ if(pBuffer!=NULL && pBuffer->pBuffer!=NULL) {
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (pBuffer->pBuffer == openmaxStandPort->pInternalBufferStorage[i]->pBuffer) {
+ foundBuffer = OMX_TRUE;
+ break;
+ }
+ }
+ }
+ if (!foundBuffer) {
+ return OMX_ErrorBadParameter;
+ }
+ }
+#endif
+
+ if ((err = checkHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s: received wrong buffer header on input port\n", __func__);
+ return err;
+ }
+
+ /* And notify the buffer management thread we have a fresh new buffer to manage */
+ if(!PORT_IS_BEING_FLUSHED(openmaxStandPort) && !(PORT_IS_BEING_DISABLED(openmaxStandPort) && PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort))){
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ //DEBUG(DEB_LEV_PARAMS, "In %s Signalling bMgmtSem Port Index=%d\n",__func__, (int)portIndex);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }else if(PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)){
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s received io:%d buffer\n",
+ __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ }
+ else { // If port being flushed and not tunneled then return error
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s \n", __func__);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ return OMX_ErrorNone;
+}
+
+OMX_ERRORTYPE omx_alsasink_component_GetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_INOUT OMX_PTR pComponentConfigStructure) {
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (nIndex == OMX_IndexConfigAudioRenderingLatency) {
+ OMX_PARAM_U32TYPE* param = (OMX_PARAM_U32TYPE*)pComponentConfigStructure;
+
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+
+ if (param->nPortIndex == OMX_BASE_SINK_INPUTPORT_INDEX ) {
+ // As this is used only as bool, we can return 'just something' here.
+ // TODO: Add appropriate processing when needed
+ param->nU32 = omx_alsasink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX]->pBufferQueue->nelem;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_IndexConfigAudioRenderingLatency return %d\n", __func__, param->nU32);
+ return OMX_ErrorNone;
+ }
+ }
+
+ return OMX_ErrorNotImplemented;
+}
+
+
+OMX_BOOL omx_alsasink_component_ClockPortHandleFunction(omx_alsasink_component_PrivateType* omx_alsasink_component_Private, OMX_BUFFERHEADERTYPE* inputbuffer){
+ omx_base_clock_PortType* pClockPort;
+ OMX_BUFFERHEADERTYPE* clockBuffer;
+ OMX_TIME_MEDIATIMETYPE* pMediaTime;
+ OMX_HANDLETYPE hclkComponent;
+ OMX_TIME_CONFIG_TIMESTAMPTYPE sClientTimeStamp;
+ OMX_ERRORTYPE err;
+ OMX_BOOL SendFrame=OMX_TRUE;
+ omx_base_audio_PortType *pAudioPort;
+
+ int static count=0; //frame counter
+
+ pClockPort = (omx_base_clock_PortType*)omx_alsasink_component_Private->ports[OMX_BASE_SINK_CLOCKPORT_INDEX];
+ pAudioPort = (omx_base_audio_PortType *) omx_alsasink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+ hclkComponent = pClockPort->hTunneledComponent;
+ setHeader(&pClockPort->sMediaTimeRequest, sizeof(OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE));
+
+ /* check for any scale change information from the clock component */
+ if(pClockPort->pBufferSem->semval>0){
+ omx_tsem_down(pClockPort->pBufferSem);
+ if(pClockPort->pBufferQueue->nelem > 0) {
+ clockBuffer = (OMX_BUFFERHEADERTYPE*)omx_dequeue(pClockPort->pBufferQueue);
+ pMediaTime = (OMX_TIME_MEDIATIMETYPE*)clockBuffer->pBuffer;
+ if(pMediaTime->eUpdateType==OMX_TIME_UpdateScaleChanged) {
+ //if((pMediaTime->xScale>>16)==1){ /* check with Q16 format only */
+ // /* rebase the clock time base when turning to normal play mode*/
+ // hclkComponent = pClockPort->hTunneledComponent;
+ // setHeader(&sClientTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
+ // sClientTimeStamp.nPortIndex = pClockPort->nTunneledPort;
+ // sClientTimeStamp.nTimestamp = inputbuffer->nTimeStamp;
+ // err = OMX_SetConfig(hclkComponent, OMX_IndexConfigTimeCurrentAudioReference, &sClientTimeStamp);
+ // if(err!=OMX_ErrorNone) {
+ // DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig in func=%s line=%d\n",err,__func__, __LINE__);
+ // }
+ //}
+ omx_alsasink_component_Private->eState = pMediaTime->eState;
+ omx_alsasink_component_Private->xScale = pMediaTime->xScale;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s OMX_TIME_UpdateScaleChanged Line=%d new eState=%d xScale=%d\n",
+ __func__, __LINE__, pMediaTime->eState, pMediaTime->xScale);
+ /// AND
+ } else if(pMediaTime->eUpdateType==OMX_TIME_UpdateClockStateChanged) {
+ omx_alsasink_component_Private->eState = pMediaTime->eState;
+ omx_alsasink_component_Private->xScale = pMediaTime->xScale;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s OMX_TIME_UpdateClockStateChanged Line=%d new eState=%d xScale=%d\n",
+ __func__, __LINE__, pMediaTime->eState, pMediaTime->xScale);
+ }
+ /// AND
+ pClockPort->ReturnBufferFunction((omx_base_PortType*)pClockPort,clockBuffer);
+ }
+ }
+
+ /* if first time stamp is received then notify the clock component */
+ if(inputbuffer->nFlags == OMX_BUFFERFLAG_STARTTIME) {
+ DEBUG(DEB_LEV_FULL_SEQ,"In %s first time stamp = %llx \n", __func__,(long long)inputbuffer->nTimeStamp);
+ inputbuffer->nFlags = 0;
+ hclkComponent = pClockPort->hTunneledComponent;
+ setHeader(&sClientTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
+ sClientTimeStamp.nPortIndex = pClockPort->nTunneledPort;
+ sClientTimeStamp.nTimestamp = inputbuffer->nTimeStamp;
+ err = OMX_SetConfig(hclkComponent, OMX_IndexConfigTimeClientStartTime, &sClientTimeStamp);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig in func=%s \n",err,__func__);
+ }
+
+ if(!PORT_IS_BEING_FLUSHED(pAudioPort) && !PORT_IS_BEING_FLUSHED(pClockPort)) {
+ omx_tsem_down(pClockPort->pBufferSem); /* wait for state change notification from clock src*/
+
+ /* update the clock state and clock scale info into the alsa sink private data */
+ if(pClockPort->pBufferQueue->nelem > 0) {
+ clockBuffer = (OMX_BUFFERHEADERTYPE*)omx_dequeue(pClockPort->pBufferQueue);
+ pMediaTime = (OMX_TIME_MEDIATIMETYPE*)clockBuffer->pBuffer;
+ omx_alsasink_component_Private->eState = pMediaTime->eState;
+ omx_alsasink_component_Private->xScale = pMediaTime->xScale;
+ pClockPort->ReturnBufferFunction((omx_base_PortType*)pClockPort,clockBuffer);
+ }
+ }
+ }
+
+ /* do not send the data to alsa and return back, if the clock is not running or the scale is anything but 1*/
+ /*if(!(omx_alsasink_component_Private->eState==OMX_TIME_ClockStateRunning && omx_alsasink_component_Private->xScale==(1<<16))){
+ // TODO: 0 means PAUSED. is correct to keep that frame?
+ if ((omx_alsasink_component_Private->xScale!=0) && (omx_alsasink_component_Private->xScale!=(1<<16))){
+ inputbuffer->nFilledLen=0;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping frame !!!!! eState=%d xScale=%d\n", __func__, omx_alsasink_component_Private->eState, omx_alsasink_component_Private->xScale);
+ }
+ //return;
+ SendFrame = OMX_FALSE;
+ return SendFrame;
+ }*/
+
+ count++;
+ if(count==15) { //send request for every 15th frame
+ count=0;
+
+ OMX_TIME_CONFIG_TIMESTAMPTYPE ts;
+ setHeader(&ts, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
+ ts.nPortIndex = pClockPort->nTunneledPort;
+
+ snd_pcm_sframes_t avail = 0;
+ int diff = 0;
+ snd_pcm_sframes_t delay = 0;
+
+ OMX_AUDIO_PARAM_PCMMODETYPE* sPCMModeParam = &omx_alsasink_component_Private->sPCMModeParam;
+
+ //snd_pcm_delay(omx_alsasink_component_Private->playback_handle, &delay);
+ // snd_pcm_avail() & snd_pcm_avail_update() are broken on raspberry pi!!!!
+ //avail = snd_pcm_avail(omx_alsasink_component_Private->playback_handle);
+
+ if (snd_pcm_status(omx_alsasink_component_Private->playback_handle, omx_alsasink_component_Private->pcm_status) < 0) {
+ DEBUG(DEB_LEV_ERR,"In %s unable to obtain pcm_status.\n",__func__);
+ }
+
+ delay = snd_pcm_status_get_delay(omx_alsasink_component_Private->pcm_status);
+ avail = (snd_pcm_sframes_t) snd_pcm_status_get_avail(omx_alsasink_component_Private->pcm_status);
+
+ diff = ((double)(delay - avail) / sPCMModeParam->nSamplingRate) * 1000 * 1000; // in microseconds !!!
+
+ //DEBUG(DEB_LEV_FULL_SEQ,"In %s delay=%d avail=%d diff=%d inputbuffer->nTimeStamp=%lld corected nTimeStamp=%lld\n",
+ // __func__, delay, avail, diff, inputbuffer->nTimeStamp, inputbuffer->nTimeStamp - (OMX_TICKS)diff);
+
+ ts.nTimestamp = inputbuffer->nTimeStamp - (OMX_TICKS)diff;
+
+ if (OMX_ErrorNone != OMX_SetConfig(hclkComponent, OMX_IndexConfigTimeCurrentAudioReference,&ts)) {
+ DEBUG(DEB_LEV_ERR,"In %s unable to update reference clock.\n",__func__);
+ }
+
+#if 0
+ /* requesting for the timestamp for the data delivery */
+ if(!PORT_IS_BEING_FLUSHED(pAudioPort) && !PORT_IS_BEING_FLUSHED(pClockPort)&&
+ omx_alsasink_component_Private->transientState != OMX_TransStateExecutingToIdle) {
+ pClockPort->sMediaTimeRequest.nOffset = 100; /*set the requested offset */
+ pClockPort->sMediaTimeRequest.nPortIndex = pClockPort->nTunneledPort;
+ pClockPort->sMediaTimeRequest.pClientPrivate = NULL; /* fill the appropriate value */
+ pClockPort->sMediaTimeRequest.nMediaTimestamp = inputbuffer->nTimeStamp;
+ err = OMX_SetConfig(hclkComponent, OMX_IndexConfigTimeMediaTimeRequest, &pClockPort->sMediaTimeRequest);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig in func=%s \n",err,__func__);
+ }
+ if(!PORT_IS_BEING_FLUSHED(pAudioPort) && !PORT_IS_BEING_FLUSHED(pClockPort) &&
+ omx_alsasink_component_Private->transientState != OMX_TransStateExecutingToIdle) {
+ omx_tsem_down(pClockPort->pBufferSem); /* wait for the request fullfillment */
+ if(pClockPort->pBufferQueue->nelem > 0) {
+ clockBuffer = omx_dequeue(pClockPort->pBufferQueue);
+ pMediaTime = (OMX_TIME_MEDIATIMETYPE*)clockBuffer->pBuffer;
+ if(pMediaTime->eUpdateType==OMX_TIME_UpdateScaleChanged) {
+ /// AND
+ //if((pMediaTime->xScale>>16)==1){ /* check with Q16 format only */
+ // /* rebase the clock time base when turning to normal play mode*/
+ // hclkComponent = pClockPort->hTunneledComponent;
+ // setHeader(&sClientTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
+ // sClientTimeStamp.nPortIndex = pClockPort->nTunneledPort;
+ // sClientTimeStamp.nTimestamp = inputbuffer->nTimeStamp;
+ // err = OMX_SetConfig(hclkComponent, OMX_IndexConfigTimeCurrentAudioReference, &sClientTimeStamp);
+ // if(err!=OMX_ErrorNone) {
+ // DEBUG(DEB_LEV_ERR,"Error %08x In OMX_SetConfig in func=%s line=%d\n",err,__func__, __LINE__);
+ // }
+ //}
+ /// AND
+ omx_alsasink_component_Private->eState = pMediaTime->eState;
+ omx_alsasink_component_Private->xScale = pMediaTime->xScale;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s OMX_TIME_UpdateScaleChanged Line=%d new eState=%d xScale=%d\n",
+ __func__, __LINE__, pMediaTime->eState, pMediaTime->xScale);
+ /// AND
+ } else if(pMediaTime->eUpdateType==OMX_TIME_UpdateClockStateChanged) {
+ omx_alsasink_component_Private->eState = pMediaTime->eState;
+ omx_alsasink_component_Private->xScale = pMediaTime->xScale;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s OMX_TIME_UpdateClockStateChanged Line=%d new eState=%d xScale=%d\n",
+ __func__, __LINE__, pMediaTime->eState, pMediaTime->xScale);
+ }
+ /// AND
+ if(pMediaTime->eUpdateType==OMX_TIME_UpdateRequestFulfillment) {
+ if((pMediaTime->nOffset)>0) {
+#ifdef AV_SYNC_LOG
+ fprintf(fd,"%lld %lld\n",inputbuffer->nTimeStamp,pMediaTime->nWallTimeAtMediaTime);
+#endif
+ SendFrame = OMX_TRUE; /* as offset is >0 send the data to the device */
+ }
+ else {
+ SendFrame = OMX_FALSE; /* as offset is <0 do not send the data to the device */
+ //DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Dropping frame !!!!! nOffset>0 !!! nOffset=%ll\n", __func__, pMediaTime->nOffset);
+ }
+ }
+ pClockPort->ReturnBufferFunction((omx_base_PortType*)pClockPort,clockBuffer);
+ }
+ }
+ }
+#endif
+ }
+
+ return(SendFrame);
+}
+
+/** @brief Releases buffers under processing.
+ * This function must be implemented in the derived classes, for the
+ * specific processing
+ */
+OMX_ERRORTYPE omx_alsasink_component_port_FlushProcessingBuffers(omx_base_PortType *openmaxStandPort) {
+ omx_base_component_PrivateType* omx_base_component_Private;
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private;
+ OMX_BUFFERHEADERTYPE* pBuffer;
+ omx_base_clock_PortType *pClockPort;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandPort->standCompContainer->pComponentPrivate;
+ omx_alsasink_component_Private = ( omx_alsasink_component_PrivateType*) omx_base_component_Private;
+
+ pClockPort = (omx_base_clock_PortType*) omx_alsasink_component_Private->ports[OMX_BASE_SINK_CLOCKPORT_INDEX];
+
+ if (!PORT_IS_ENABLED(openmaxStandPort) || PORT_IS_BEING_DISABLED(openmaxStandPort)) {
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s ---------- waiting for buffers. qelem=%d\n",__func__,openmaxStandPort->pBufferQueue->nelem);
+ int nRetry = 0;
+ while((openmaxStandPort->pBufferQueue->nelem != openmaxStandPort->nNumAssignedBuffers) &&
+ (nRetry < TUNNEL_USE_BUFFER_RETRY)){
+ usleep(TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME);
+ nRetry++;
+ }
+ if (nRetry == TUNNEL_USE_BUFFER_RETRY){
+ // In some rare cases we can't collect all buffers back
+ DEBUG(DEB_LEV_ERR, "In %s Failed to get buffers back. Got a buffer qelem=%d\n",__func__,openmaxStandPort->pBufferQueue->nelem);
+ }
+ else{
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s All buffers returned in %d iterations.\n",__func__, nRetry);
+ }
+
+ omx_tsem_reset(openmaxStandPort->pBufferSem);
+ }
+ return OMX_ErrorNone;
+ }
+
+ if(openmaxStandPort->sPortParam.eDomain!=OMX_PortDomainOther) { /* clock buffers not used in the clients buffer managment function */
+ pthread_mutex_lock(&omx_base_component_Private->flush_mutex);
+ openmaxStandPort->bIsPortFlushed=OMX_TRUE;
+ /*Signal the buffer management thread of port flush,if it is waiting for buffers*/
+ if(omx_base_component_Private->bMgmtSem->semval==0) {
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+
+ if(omx_base_component_Private->state==OMX_StatePause ) {
+ /*Waiting at paused state*/
+ omx_tsem_signal(omx_base_component_Private->bStateSem);
+ }
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s waiting for flush all condition port index =%d\n", __func__,(int)openmaxStandPort->sPortParam.nPortIndex);
+ /* Wait until flush is completed */
+ pthread_mutex_unlock(&omx_base_component_Private->flush_mutex);
+
+ /*Dummy signal to clock port*/
+ if(pClockPort->pBufferSem->semval == 0) {
+ omx_tsem_up(pClockPort->pBufferSem);
+ }
+ omx_tsem_down(omx_base_component_Private->flush_all_condition);
+ if(pClockPort->pBufferSem->semval > 0) {
+ omx_tsem_down(pClockPort->pBufferSem);
+ }
+ }
+
+ omx_tsem_reset(omx_base_component_Private->bMgmtSem);
+
+ /* Flush all the buffers not under processing */
+ while (openmaxStandPort->pBufferSem->semval > 0) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s TFlag=%x Flusing Port=%d,Semval=%d Qelem=%d\n",
+ __func__,(int)openmaxStandPort->nTunnelFlags,(int)openmaxStandPort->sPortParam.nPortIndex,
+ (int)openmaxStandPort->pBufferSem->semval,(int)openmaxStandPort->pBufferQueue->nelem);
+
+ omx_tsem_down(openmaxStandPort->pBufferSem);
+ pBuffer = (OMX_BUFFERHEADERTYPE*)omx_dequeue(openmaxStandPort->pBufferQueue);
+ if (PORT_IS_TUNNELED(openmaxStandPort)) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s is returning io:%d buffer\n",
+ __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->FillThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ } else {
+ ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->EmptyThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ }
+ } else {
+ (*(openmaxStandPort->BufferProcessedCallback))(
+ openmaxStandPort->standCompContainer,
+ omx_base_component_Private->callbackData,
+ pBuffer);
+ }
+ }
+
+ pthread_mutex_lock(&omx_base_component_Private->flush_mutex);
+ openmaxStandPort->bIsPortFlushed=OMX_FALSE;
+ pthread_mutex_unlock(&omx_base_component_Private->flush_mutex);
+
+ omx_tsem_up(omx_base_component_Private->flush_condition);
+
+ DEBUG(DEB_LEV_FULL_SEQ, "Out %s Port Index=%d bIsPortFlushed=%d Component %s\n", __func__,
+ (int)openmaxStandPort->sPortParam.nPortIndex,(int)openmaxStandPort->bIsPortFlushed,omx_base_component_Private->name);
+
+ DEBUG(DEB_LEV_PARAMS, "In %s TFlag=%x Qelem=%d BSem=%d bMgmtsem=%d component=%s\n", __func__,
+ (int)openmaxStandPort->nTunnelFlags,
+ (int)openmaxStandPort->pBufferQueue->nelem,
+ (int)openmaxStandPort->pBufferSem->semval,
+ (int)omx_base_component_Private->bMgmtSem->semval,
+ omx_base_component_Private->name);
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "Out %s Port Index=%d\n", __func__,(int)openmaxStandPort->sPortParam.nPortIndex);
+
+ return OMX_ErrorNone;
+}
+
+/**
+ * This function plays the input buffer. When fully consumed it returns.
+ */
+void omx_alsasink_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* inputbuffer) {
+ OMX_U32 frameSize;
+ OMX_S32 written;
+ OMX_S32 totalBuffer;
+ OMX_S32 offsetBuffer;
+ OMX_BOOL allDataSent;
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*) openmaxStandComp->pComponentPrivate;
+
+ frameSize = (omx_alsasink_component_Private->sPCMModeParam.nChannels * omx_alsasink_component_Private->sPCMModeParam.nBitPerSample) >> 3;
+ //DEBUG(DEB_LEV_FULL_SEQ, "Framesize is %u chl=%d bufSize=%d\n",
+ //(int)frameSize, (int)omx_alsasink_component_Private->sPCMModeParam.nChannels, (int)inputbuffer->nFilledLen);
+
+ if(inputbuffer->nFilledLen < frameSize){
+ DEBUG(DEB_LEV_ERR, "Ouch!! In %s input buffer filled len(%d) less than frame size(%d)\n",__func__, (int)inputbuffer->nFilledLen, (int)frameSize);
+ return;
+ }
+
+ allDataSent = OMX_FALSE;
+
+ totalBuffer = inputbuffer->nFilledLen/frameSize;
+
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omx_alsasink_component_Private;
+ omx_base_clock_PortType*pClockPort = (omx_base_clock_PortType*)omx_base_component_Private->ports[OMX_BASE_SINK_CLOCKPORT_INDEX];
+ omx_base_PortType *openmaxStandPort = omx_base_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+ if(PORT_IS_TUNNELED(pClockPort) && !PORT_IS_BEING_FLUSHED(openmaxStandPort) &&
+ (omx_base_component_Private->transientState != OMX_TransStateExecutingToIdle) &&
+ (inputbuffer->nFlags != OMX_BUFFERFLAG_EOS)){
+ omx_alsasink_component_ClockPortHandleFunction(omx_alsasink_component_Private, inputbuffer);
+ if(inputbuffer->nFilledLen == 0)
+ {
+ // Dropped frame by clock
+ return;
+ }
+ }
+
+ /* Feed it to ALSA */
+
+ offsetBuffer = 0;
+ while (!allDataSent) {
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Writing to the device ..\n");
+ written = snd_pcm_writei(omx_alsasink_component_Private->playback_handle, inputbuffer->pBuffer + (offsetBuffer * frameSize), totalBuffer);
+ if (written < 0) {
+ if(written == -EPIPE){
+ DEBUG(DEB_LEV_ERR, "ALSA Underrun..\n");
+ snd_pcm_prepare(omx_alsasink_component_Private->playback_handle);
+ written = 0;
+ } else {
+ DEBUG(DEB_LEV_ERR, "Cannot send any data to the audio device %s (%s)\n", "default", snd_strerror (written));
+ DEBUG(DEB_LEV_ERR, "IB FilledLen=%d,totalBuffer=%d,frame size=%d,offset=%d\n",
+ (int)inputbuffer->nFilledLen, (int)totalBuffer, (int)frameSize, (int)offsetBuffer);
+ break;
+ return;
+ }
+ }
+
+ if(written != totalBuffer){
+ totalBuffer = totalBuffer - written;
+ offsetBuffer = written;
+ } else {
+ DEBUG(DEB_LEV_FULL_SEQ, "Buffer successfully sent to ALSA. Length was %i\n", (int)inputbuffer->nFilledLen);
+ allDataSent = OMX_TRUE;
+ }
+ }
+
+ inputbuffer->nFilledLen=0;
+}
+
+OMX_ERRORTYPE omx_alsasink_component_SetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_IN OMX_PTR ComponentParameterStructure)
+{
+ int err;
+ OMX_ERRORTYPE omxErr = OMX_ErrorNone;
+ OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
+ OMX_OTHER_PARAM_PORTFORMATTYPE *pOtherPortFormat;
+ OMX_AUDIO_PARAM_MP3TYPE * pAudioMp3;
+ OMX_U32 portIndex;
+
+ /* Check which structure we are being fed and make control its header */
+ OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ omx_base_audio_PortType* pPort = (omx_base_audio_PortType *) omx_alsasink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+ omx_base_clock_PortType *pClockPort;
+ snd_pcm_t* playback_handle = omx_alsasink_component_Private->playback_handle;
+
+ if (ComponentParameterStructure == NULL) {
+ return OMX_ErrorBadParameter;
+ }
+
+ DEBUG(DEB_LEV_SIMPLE_SEQ, " Setting parameter %i\n", nParamIndex);
+
+ switch(nParamIndex) {
+ case OMX_IndexParamAudioPortFormat:
+ pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
+ portIndex = pAudioPortFormat->nPortIndex;
+ /*Check Structure Header and verify component state*/
+ omxErr = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+ if(omxErr!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n", __func__, omxErr);
+ break;
+ }
+ if (portIndex < 1) {
+ memcpy(&pPort->sAudioParam,pAudioPortFormat,sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+ } else {
+ return OMX_ErrorBadPortIndex;
+ }
+ break;
+ case OMX_IndexParamOtherPortFormat:
+ pOtherPortFormat = (OMX_OTHER_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
+ portIndex = pOtherPortFormat->nPortIndex;
+ err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pOtherPortFormat, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
+ break;
+ }
+ if(portIndex != 1) {
+ return OMX_ErrorBadPortIndex;
+ }
+ pClockPort = (omx_base_clock_PortType *) omx_alsasink_component_Private->ports[portIndex];
+
+ pClockPort->sOtherParam.eFormat = pOtherPortFormat->eFormat;
+ break;
+ case OMX_IndexParamAudioPcm:
+ {
+ unsigned int rate;
+ OMX_AUDIO_PARAM_PCMMODETYPE* sPCMModeParam = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
+ snd_pcm_hw_params_t *hw_params;
+ snd_pcm_hw_params_alloca(&hw_params);
+
+ /** Each time we are (re)configuring the hw_params thing
+ * we need to reinitialize it, otherwise previous changes will not take effect.
+ * e.g.: changing a previously configured sampling rate does not have
+ * any effect if we are not calling this each time.
+ */
+ snd_pcm_hw_params_any(omx_alsasink_component_Private->playback_handle, hw_params);
+
+ portIndex = sPCMModeParam->nPortIndex;
+ /*Check Structure Header and verify component state*/
+ omxErr = omx_base_component_ParameterSanityCheck(hComponent, portIndex, sPCMModeParam, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ if(omxErr!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n", __func__, omxErr);
+ break;
+ }
+
+ omx_alsasink_component_Private->AudioPCMConfigured = 1;
+ if(sPCMModeParam->nPortIndex != omx_alsasink_component_Private->sPCMModeParam.nPortIndex){
+ DEBUG(DEB_LEV_ERR, "Error setting input pPort index\n");
+ omxErr = OMX_ErrorBadParameter;
+ break;
+ }
+
+ if(snd_pcm_hw_params_set_channels(playback_handle, hw_params, sPCMModeParam->nChannels)){
+ DEBUG(DEB_LEV_ERR, "Error setting number of channels\n");
+ return OMX_ErrorBadParameter;
+ }
+
+ if(sPCMModeParam->bInterleaved == OMX_TRUE){
+ if ((err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set access type intrleaved (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ }
+ else{
+ if ((err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_NONINTERLEAVED)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set access type non interleaved (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ }
+ rate = sPCMModeParam->nSamplingRate;
+ if ((err = snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, 0)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set sample rate (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ else{
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Set correctly sampling rate from %lu to %lu\n", (unsigned long)sPCMModeParam->nSamplingRate, (unsigned long)rate);
+ sPCMModeParam->nSamplingRate = rate;
+ }
+
+ if(sPCMModeParam->ePCMMode == OMX_AUDIO_PCMModeLinear){
+ snd_pcm_format_t snd_pcm_format = SND_PCM_FORMAT_UNKNOWN;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Bit per sample %i, signed=%i, little endian=%i\n",
+ (int)sPCMModeParam->nBitPerSample,
+ (int)sPCMModeParam->eNumData == OMX_NumericalDataSigned,
+ (int)sPCMModeParam->eEndian == OMX_EndianLittle);
+
+ switch(sPCMModeParam->nBitPerSample){
+ case 8:
+ if(sPCMModeParam->eNumData == OMX_NumericalDataSigned) {
+ snd_pcm_format = SND_PCM_FORMAT_S8;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_U8;
+ }
+ break;
+ case 16:
+ if(sPCMModeParam->eNumData == OMX_NumericalDataSigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle) {
+ snd_pcm_format = SND_PCM_FORMAT_S16_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_S16_BE;
+ }
+ }
+ if(sPCMModeParam->eNumData == OMX_NumericalDataUnsigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle){
+ snd_pcm_format = SND_PCM_FORMAT_U16_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_U16_BE;
+ }
+ }
+ break;
+ case 24:
+ if(sPCMModeParam->eNumData == OMX_NumericalDataSigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle) {
+ snd_pcm_format = SND_PCM_FORMAT_S24_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_S24_BE;
+ }
+ }
+ if(sPCMModeParam->eNumData == OMX_NumericalDataUnsigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle) {
+ snd_pcm_format = SND_PCM_FORMAT_U24_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_U24_BE;
+ }
+ }
+ break;
+
+ case 32:
+ if(sPCMModeParam->eNumData == OMX_NumericalDataSigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle) {
+ snd_pcm_format = SND_PCM_FORMAT_S32_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_S32_BE;
+ }
+ }
+ if(sPCMModeParam->eNumData == OMX_NumericalDataUnsigned){
+ if(sPCMModeParam->eEndian == OMX_EndianLittle) {
+ snd_pcm_format = SND_PCM_FORMAT_U32_LE;
+ } else {
+ snd_pcm_format = SND_PCM_FORMAT_U32_BE;
+ }
+ }
+ break;
+ default:
+ omxErr = OMX_ErrorBadParameter;
+ break;
+ }
+
+ if(snd_pcm_format != SND_PCM_FORMAT_UNKNOWN){
+ if ((err = snd_pcm_hw_params_set_format(playback_handle, hw_params, snd_pcm_format)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set sample format (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ memcpy(&omx_alsasink_component_Private->sPCMModeParam, ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ } else{
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "ALSA OMX_IndexParamAudioPcm configured\n");
+ memcpy(&omx_alsasink_component_Private->sPCMModeParam, ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ }
+ }
+ else if(sPCMModeParam->ePCMMode == OMX_AUDIO_PCMModeALaw){
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Configuring ALAW format\n\n");
+ if ((err = snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_A_LAW)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set sample format (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ memcpy(&omx_alsasink_component_Private->sPCMModeParam, ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ }
+ else if(sPCMModeParam->ePCMMode == OMX_AUDIO_PCMModeMULaw){
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Configuring ALAW format\n\n");
+ if ((err = snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_MU_LAW)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set sample format (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ memcpy(&omx_alsasink_component_Private->sPCMModeParam, ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ }
+
+ snd_pcm_uframes_t periodSize, bufferSize;
+ bufferSize = sPCMModeParam->nSamplingRate / 5;
+ periodSize = bufferSize / 4; //sPCMModeParam->nSamplingRate / 20;
+
+ snd_pcm_uframes_t periodSizeMax = bufferSize / 3;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "trying snd_pcm_hw_params_set_period_size_max (%d)\n", (int)periodSizeMax);
+ if ((err = snd_pcm_hw_params_set_period_size_max(omx_alsasink_component_Private->playback_handle, hw_params, &periodSizeMax, NULL)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot snd_pcm_hw_params_set_period_size_max (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "trying snd_pcm_hw_params_set_buffer_size_near (%d)\n", (int)bufferSize);
+ if ((err = snd_pcm_hw_params_set_buffer_size_near(omx_alsasink_component_Private->playback_handle, hw_params, &bufferSize)) < 0) {
+ //if (err = snd_pcm_hw_params_set_buffer_size(omx_alsasink_component_Private->playback_handle, hw_params, bufferSize) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot snd_pcm_hw_params_set_buffer_size_near (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "snd_pcm_hw_params_set_buffer_size_near returned (%d)\n", (int)bufferSize);
+
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "trying snd_pcm_hw_params_set_period_size_near (%d)\n", (int)periodSize);
+ if ((err = snd_pcm_hw_params_set_period_size_near(omx_alsasink_component_Private->playback_handle, hw_params, &periodSize, NULL)) < 0) {
+ //if (err = snd_pcm_hw_params_set_period_size(omx_alsasink_component_Private->playback_handle, hw_params, periodSize, 0) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot snd_pcm_hw_params_set_period_size_near (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "snd_pcm_hw_params_set_period_size_near returned (%d)\n", (int)periodSize);
+ /*
+ unsigned int val = 200000;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "trying snd_pcm_hw_params_set_buffer_time_near (%d)\n", val);
+ if (err = snd_pcm_hw_params_set_buffer_time_near(omx_alsasink_component_Private->playback_handle, hw_params, &val, NULL) < 0 ) {
+ DEBUG(DEB_LEV_ERR, "cannot snd_pcm_hw_params_set_buffer_time (%s)\n", snd_strerror (err));
+ return;
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "snd_pcm_hw_params_set_buffer_time_near returned (%d)\n", val);
+ */
+
+ /** Configure and prepare the ALSA handle */
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Configuring the PCM interface\n");
+ if ((err = snd_pcm_hw_params(playback_handle, hw_params)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot set parameters (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+
+ if ((err = snd_pcm_prepare (playback_handle)) < 0) {
+ DEBUG(DEB_LEV_ERR, "cannot prepare audio interface for use (%s)\n", snd_strerror (err));
+ return OMX_ErrorHardware;
+ }
+ }
+ break;
+ case OMX_IndexParamAudioMp3:
+ pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*)ComponentParameterStructure;
+ /*Check Structure Header and verify component state*/
+ omxErr = omx_base_component_ParameterSanityCheck(hComponent, pAudioMp3->nPortIndex, pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
+ if(omxErr != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n", __func__, omxErr);
+ break;
+ }
+ break;
+ default: /*Call the base component function*/
+ return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
+ }
+ return omxErr;
+}
+
+OMX_ERRORTYPE omx_alsasink_component_GetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_INOUT OMX_PTR ComponentParameterStructure)
+{
+ OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
+ OMX_OTHER_PARAM_PORTFORMATTYPE *pOtherPortFormat;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private = (omx_alsasink_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ omx_base_audio_PortType *pPort = (omx_base_audio_PortType *) omx_alsasink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+ omx_base_clock_PortType *pClockPort = (omx_base_clock_PortType *) omx_alsasink_component_Private->ports[1];
+ if (ComponentParameterStructure == NULL) {
+ return OMX_ErrorBadParameter;
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting parameter %i\n", nParamIndex);
+ /* Check which structure we are being fed and fill its header */
+ switch(nParamIndex) {
+ case OMX_IndexParamAudioInit:
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ memcpy(ComponentParameterStructure, &omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainAudio], sizeof(OMX_PORT_PARAM_TYPE));
+ break;
+ case OMX_IndexParamOtherInit:
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ memcpy(ComponentParameterStructure, &omx_alsasink_component_Private->sPortTypesParam[OMX_PortDomainOther], sizeof(OMX_PORT_PARAM_TYPE));
+ break;
+ case OMX_IndexParamAudioPortFormat:
+ pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ if (pAudioPortFormat->nPortIndex < 1) {
+ memcpy(pAudioPortFormat, &pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+ } else {
+ return OMX_ErrorBadPortIndex;
+ }
+ break;
+ case OMX_IndexParamAudioPcm:
+ if(((OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure)->nPortIndex !=
+ omx_alsasink_component_Private->sPCMModeParam.nPortIndex) {
+ return OMX_ErrorBadParameter;
+ }
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ memcpy(ComponentParameterStructure, &omx_alsasink_component_Private->sPCMModeParam, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+ break;
+ case OMX_IndexParamOtherPortFormat:
+
+ pOtherPortFormat = (OMX_OTHER_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
+
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ if (pOtherPortFormat->nPortIndex == 1) {
+ memcpy(pOtherPortFormat, &pClockPort->sOtherParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
+ } else {
+ return OMX_ErrorBadPortIndex;
+ }
+ break;
+ default: /*Call the base component function*/
+ return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
+ }
+ return err;
+}
diff --git a/alsa/omx_alsasink_component.h b/alsa/omx_alsasink_component.h
new file mode 100644
index 0000000..a6f2e7d
--- /dev/null
+++ b/alsa/omx_alsasink_component.h
@@ -0,0 +1,94 @@
+/**
+ @file src/components/alsa/omx_alsasink_component.h
+
+ OpenMAX ALSA sink component. This component is an audio sink that uses ALSA library.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-08-08 06:56:06 +0200 (Fri, 08 Aug 2008) $
+ Revision $Rev: 581 $
+ Author $Author: pankaj_sen $
+
+*/
+
+#ifndef _OMX_ALSASINK_COMPONENT_H_
+#define _OMX_ALSASINK_COMPONENT_H_
+
+//#include <OMX_Types.h>
+//#include <IL/OMX_Component.h>
+//#include <IL/OMX_Core.h>
+//#include <IL/OMX_Audio.h>
+#include <pthread.h>
+#include <omx_base_sink.h>
+#include <alsa/asoundlib.h>
+
+/** Alsasinkport component private structure.
+ * see the define above
+ * @param sPCMModeParam Audio PCM specific OpenMAX parameter
+ * @param AudioPCMConfigured boolean flag to check if the audio has been configured
+ * @param playback_handle ALSA specif handle for audio player
+ * @param xScale the scale of the media clock
+ * @param eState the state of the media clock
+ * @param hw_params ALSA specif hardware parameters
+ */
+DERIVEDCLASS(omx_alsasink_component_PrivateType, omx_base_sink_PrivateType)
+#define omx_alsasink_component_PrivateType_FIELDS omx_base_sink_PrivateType_FIELDS \
+ OMX_AUDIO_PARAM_PCMMODETYPE sPCMModeParam; \
+ char AudioPCMConfigured; \
+ snd_pcm_t* playback_handle; \
+ snd_pcm_status_t* pcm_status; \
+ OMX_S32 xScale; \
+ OMX_TIME_CLOCKSTATE eState;
+ENDCLASS(omx_alsasink_component_PrivateType)
+
+/* Component private entry points declaration */
+OMX_ERRORTYPE omx_alsasink_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName);
+OMX_ERRORTYPE omx_alsasink_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp);
+
+void omx_alsasink_component_BufferMgmtCallback(
+ OMX_COMPONENTTYPE *openmaxStandComp,
+ OMX_BUFFERHEADERTYPE* inputbuffer);
+
+OMX_ERRORTYPE omx_alsasink_component_port_SendBufferFunction(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer);
+
+/* to handle the communication at the clock port */
+OMX_BOOL omx_alsasink_component_ClockPortHandleFunction(
+ omx_alsasink_component_PrivateType* omx_alsasink_component_Private,
+ OMX_BUFFERHEADERTYPE* inputbuffer);
+
+OMX_ERRORTYPE omx_alsasink_component_GetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_INOUT OMX_PTR ComponentParameterStructure);
+
+OMX_ERRORTYPE omx_alsasink_component_SetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_IN OMX_PTR ComponentParameterStructure);
+
+OMX_ERRORTYPE omx_alsasink_component_GetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_INOUT OMX_PTR pComponentConfigStructure);
+
+OMX_ERRORTYPE omx_alsasink_component_port_FlushProcessingBuffers(omx_base_PortType *openmaxStandPort);
+
+#endif
diff --git a/alsa/omx_base_audio_port.cpp b/alsa/omx_base_audio_port.cpp
new file mode 100644
index 0000000..fb611d7
--- /dev/null
+++ b/alsa/omx_base_audio_port.cpp
@@ -0,0 +1,111 @@
+/**
+ @file src/base/omx_base_audio_port.c
+
+ Base Audio Port class for OpenMAX ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-08-07 12:42:40 +0200 (Thu, 07 Aug 2008) $
+ Revision $Rev: 580 $
+ Author $Author: pankaj_sen $
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+//#include <IL/OMX_Core.h>
+//#include <IL/OMX_Component.h>
+
+#include "omx_base_component.h"
+#include "omx_base_audio_port.h"
+
+/**
+ * @brief The base contructor for the generic OpenMAX ST Audio port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandComp pointer to the Handle of the component
+ * @param openmaxStandPort the ST port to be initialized
+ * @param nPortIndex Index of the port to be constructed
+ * @param isInput specifices if the port is an input or an output
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+
+OMX_ERRORTYPE base_audio_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput) {
+
+ omx_base_audio_PortType *omx_base_audio_Port;
+
+ if (!(*openmaxStandPort)) {
+ *openmaxStandPort = (omx_base_PortType *) calloc(1,sizeof (omx_base_audio_PortType));
+ }
+
+ if (!(*openmaxStandPort)) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ base_port_Constructor(openmaxStandComp,openmaxStandPort,nPortIndex, isInput);
+
+ omx_base_audio_Port = (omx_base_audio_PortType *)*openmaxStandPort;
+
+ setHeader(&omx_base_audio_Port->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+ omx_base_audio_Port->sAudioParam.nPortIndex = nPortIndex;
+ omx_base_audio_Port->sAudioParam.nIndex = 0;
+ omx_base_audio_Port->sAudioParam.eEncoding = OMX_AUDIO_CodingUnused;
+
+ omx_base_audio_Port->sPortParam.eDomain = OMX_PortDomainAudio;
+ omx_base_audio_Port->sPortParam.format.audio.cMIMEType = (OMX_STRING) malloc(DEFAULT_MIME_STRING_LENGTH);
+ strcpy(omx_base_audio_Port->sPortParam.format.audio.cMIMEType, "raw/audio");
+ omx_base_audio_Port->sPortParam.format.audio.pNativeRender = 0;
+ omx_base_audio_Port->sPortParam.format.audio.bFlagErrorConcealment = OMX_FALSE;
+ omx_base_audio_Port->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingUnused;
+
+ omx_base_audio_Port->sPortParam.nBufferSize = (isInput == OMX_TRUE)?DEFAULT_IN_BUFFER_SIZE:DEFAULT_OUT_BUFFER_SIZE ;
+
+ omx_base_audio_Port->PortDestructor = &base_audio_port_Destructor;
+
+ return OMX_ErrorNone;
+}
+
+/**
+ * @brief The base audio port destructor for the generic OpenMAX ST Audio port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the port.
+ * It takes care of destructing the instance of the port
+ *
+ * @param openmaxStandPort the ST port to be destructed
+ *
+ * @return OMX_ErrorNone
+ */
+
+OMX_ERRORTYPE base_audio_port_Destructor(omx_base_PortType *openmaxStandPort){
+
+ if(openmaxStandPort->sPortParam.format.audio.cMIMEType) {
+ free(openmaxStandPort->sPortParam.format.audio.cMIMEType);
+ openmaxStandPort->sPortParam.format.audio.cMIMEType = NULL;
+ }
+
+ base_port_Destructor(openmaxStandPort);
+
+ return OMX_ErrorNone;
+}
diff --git a/alsa/omx_base_audio_port.h b/alsa/omx_base_audio_port.h
new file mode 100644
index 0000000..d03a83c
--- /dev/null
+++ b/alsa/omx_base_audio_port.h
@@ -0,0 +1,88 @@
+/**
+ @file src/base/omx_base_audio_port.h
+
+ Base Audio Port class for OpenMAX ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-07-07 14:30:38 +0200 (Mon, 07 Jul 2008) $
+ Revision $Rev: 562 $
+ Author $Author: gsent $
+
+*/
+
+#include "omx_classmagic.h"
+#include "omx_base_port.h"
+
+#ifndef __OMX_BASE_AUDIO_PORT_H__
+#define __OMX_BASE_AUDIO_PORT_H__
+
+/**
+ * @brief the base audio domain structure that describes each port.
+ *
+ * The data structure is derived from base port class and contain audio
+ * domain specific parameters.
+ * Other elements can be added in the derived components structures.
+ */
+
+DERIVEDCLASS(omx_base_audio_PortType, omx_base_PortType)
+#define omx_base_audio_PortType_FIELDS omx_base_PortType_FIELDS \
+ /** @param sAudioParam Domain specific (audio) OpenMAX port parameter */ \
+ OMX_AUDIO_PARAM_PORTFORMATTYPE sAudioParam;
+ENDCLASS(omx_base_audio_PortType)
+
+/**
+ * @brief the base contructor for the generic OpenMAX ST Audio port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandComp pointer to the Handle of the component
+ * @param openmaxStandPort the ST port to be initialized
+ * @param nPortIndex Index of the port to be constructed
+ * @param isInput specifices if the port is an input or an output
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+
+OMX_ERRORTYPE base_audio_port_Constructor(
+ OMX_COMPONENTTYPE *openmaxStandComp,
+ omx_base_PortType **openmaxStandPort,
+ OMX_U32 nPortIndex,
+ OMX_BOOL isInput);
+
+/**
+ * @brief the base audio port destructor for the generic OpenMAX ST Audio port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the port.
+ * It takes care of destructing the instance of the port
+ *
+ * @param openmaxStandPort the ST port to be destructed
+ *
+ * @return OMX_ErrorNone
+ */
+
+
+OMX_ERRORTYPE base_audio_port_Destructor(
+ omx_base_PortType *openmaxStandPort);
+
+#endif
diff --git a/alsa/omx_base_clock_port.cpp b/alsa/omx_base_clock_port.cpp
new file mode 100644
index 0000000..cf27b71
--- /dev/null
+++ b/alsa/omx_base_clock_port.cpp
@@ -0,0 +1,209 @@
+/**
+ @file src/base/omx_base_clock_port.c
+
+ Base Clock Port class for OpenMAX clock ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-07-04 11:48:31 +0200 (Fri, 04 Jul 2008) $
+ Revision $Rev: 560 $
+ Author $Author: gsent $
+*/
+
+#undef OMX_SKIP64BIT
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+//#include <IL/OMX_Core.h>
+//#include <IL/OMX_Component.h>
+#include "omx_base_component.h"
+#include "omx_base_clock_port.h"
+
+/**
+ * @brief the base contructor for the generic openmax ST Clock port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandComp pointer to the Handle of the component
+ * @param openmaxStandPort the ST port to be initialized
+ * @param nPortIndex Index of the port to be constructed
+ * @param isInput specifices if the port is an input or an output
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+
+OMX_ERRORTYPE base_clock_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput) {
+
+ omx_base_clock_PortType *omx_base_clock_Port;
+
+ if (!(*openmaxStandPort)) {
+ *openmaxStandPort = (omx_base_PortType*)calloc(1,sizeof (omx_base_clock_PortType));
+ }
+
+ if (!(*openmaxStandPort)) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ base_port_Constructor(openmaxStandComp,openmaxStandPort,nPortIndex, isInput);
+
+ omx_base_clock_Port = (omx_base_clock_PortType *)*openmaxStandPort;
+
+ setHeader(&omx_base_clock_Port->sOtherParam, sizeof(OMX_OTHER_PARAM_PORTFORMATTYPE));
+ omx_base_clock_Port->sOtherParam.nPortIndex = nPortIndex;
+ omx_base_clock_Port->sOtherParam.nIndex = 0;
+ omx_base_clock_Port->sOtherParam.eFormat = OMX_OTHER_FormatTime;
+
+ omx_base_clock_Port->sPortParam.eDomain = OMX_PortDomainOther;
+ omx_base_clock_Port->sPortParam.format.other.eFormat = OMX_OTHER_FormatTime;
+ omx_base_clock_Port->sPortParam.nBufferSize = sizeof(OMX_TIME_MEDIATIMETYPE) ;
+ omx_base_clock_Port->sPortParam.nBufferCountActual = 1;
+ omx_base_clock_Port->sPortParam.nBufferCountMin = 1;
+ omx_base_clock_Port->sPortParam.format.other.eFormat = OMX_OTHER_FormatTime;
+
+ setHeader(&omx_base_clock_Port->sTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
+ omx_base_clock_Port->sTimeStamp.nPortIndex = nPortIndex;
+ omx_base_clock_Port->sTimeStamp.nTimestamp = 0x00;
+
+
+ setHeader(&omx_base_clock_Port->sMediaTime, sizeof(OMX_TIME_MEDIATIMETYPE));
+ omx_base_clock_Port->sMediaTime.nClientPrivate = 0;
+ omx_base_clock_Port->sMediaTime.nOffset = 0x0;
+ omx_base_clock_Port->sMediaTime.xScale = 1;
+
+ setHeader(&omx_base_clock_Port->sMediaTimeRequest, sizeof(OMX_TIME_MEDIATIMETYPE));
+ omx_base_clock_Port->sMediaTimeRequest.nPortIndex = nPortIndex;
+ omx_base_clock_Port->sMediaTimeRequest.pClientPrivate = NULL;
+ omx_base_clock_Port->sMediaTimeRequest.nOffset = 0x0;
+
+ omx_base_clock_Port->Port_SendBufferFunction = &base_clock_port_SendBufferFunction;
+ omx_base_clock_Port->PortDestructor = &base_clock_port_Destructor;
+
+ return OMX_ErrorNone;
+}
+
+/**
+ * @brief the base clock port destructor for the generic openmax ST clock port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the port.
+ * It takes care of destructing the instance of the port
+ *
+ * @param openmaxStandPort the ST port to be destructed
+ *
+ * @return OMX_ErrorNone
+ */
+
+OMX_ERRORTYPE base_clock_port_Destructor(omx_base_PortType *openmaxStandPort){
+
+ base_port_Destructor(openmaxStandPort);
+
+ return OMX_ErrorNone;
+}
+
+/** @brief the entry point for sending buffers to the port
+ *
+ * This function can be called by the EmptyThisBuffer or FillThisBuffer. It depends on
+ * the nature of the port, that can be an input or output port.
+ */
+OMX_ERRORTYPE base_clock_port_SendBufferFunction(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer) {
+
+ OMX_ERRORTYPE err;
+ OMX_U32 portIndex;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+#if NO_GST_OMX_PATCH
+ unsigned int i;
+#endif
+ portIndex = (openmaxStandPort->sPortParam.eDir == OMX_DirInput)?pBuffer->nInputPortIndex:pBuffer->nOutputPortIndex;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s portIndex %lu\n", __func__, (unsigned long)portIndex);
+
+ if (portIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port for this operation portIndex=%d port->portIndex=%d\n", __func__, (int)portIndex, (int)openmaxStandPort->sPortParam.nPortIndex);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if(omx_base_component_Private->state == OMX_StateInvalid) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are in OMX_StateInvalid\n", __func__);
+ return OMX_ErrorInvalidState;
+ }
+
+ if(omx_base_component_Private->state != OMX_StateExecuting &&
+ omx_base_component_Private->state != OMX_StatePause &&
+ omx_base_component_Private->state != OMX_StateIdle) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are not in executing/paused/idle state, but in %d\n", __func__, omx_base_component_Private->state);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ if (!PORT_IS_ENABLED(openmaxStandPort) || (PORT_IS_BEING_DISABLED(openmaxStandPort) && !PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) ||
+ (omx_base_component_Private->transientState == OMX_TransStateExecutingToIdle &&
+ (PORT_IS_TUNNELED(openmaxStandPort) && !PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)))) {
+ DEBUG(DEB_LEV_ERR, "In %s: Port %d is disabled comp = %s \n", __func__, (int)portIndex,omx_base_component_Private->name);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+
+ /* Temporarily disable this check for gst-openmax */
+#if NO_GST_OMX_PATCH
+ {
+ OMX_BOOL foundBuffer = OMX_FALSE;
+ if(pBuffer!=NULL && pBuffer->pBuffer!=NULL) {
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (pBuffer->pBuffer == openmaxStandPort->pInternalBufferStorage[i]->pBuffer) {
+ foundBuffer = OMX_TRUE;
+ break;
+ }
+ }
+ }
+ if (!foundBuffer) {
+ return OMX_ErrorBadParameter;
+ }
+ }
+#endif
+
+ if ((err = checkHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s: received wrong buffer header on input port\n", __func__);
+ return err;
+ }
+ /*If port is not tunneled then simply return the buffer except paused state*/
+ if (!PORT_IS_TUNNELED(openmaxStandPort) && (omx_base_component_Private->state != OMX_StatePause)) {
+ openmaxStandPort->ReturnBufferFunction(openmaxStandPort,pBuffer);
+ return OMX_ErrorNone;
+ }
+
+ /* And notify the buffer management thread we have a fresh new buffer to manage */
+ if(!PORT_IS_BEING_FLUSHED(openmaxStandPort) && !(PORT_IS_BEING_DISABLED(openmaxStandPort) && PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort))){
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ DEBUG(DEB_LEV_PARAMS, "In %s Signalling bMgmtSem Port Index=%d\n",__func__, (int)portIndex);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }else if(PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)){
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s received io:%d buffer\n",
+ __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ }
+ else { // If port being flushed and not tunneled then return error
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s \n", __func__);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ return OMX_ErrorNone;
+}
diff --git a/alsa/omx_base_clock_port.h b/alsa/omx_base_clock_port.h
new file mode 100644
index 0000000..97f543e
--- /dev/null
+++ b/alsa/omx_base_clock_port.h
@@ -0,0 +1,95 @@
+/**
+ @file src/base/omx_base_clock_port.h
+
+ Base Clock Port class for OpenMAX clock ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-07-04 11:48:31 +0200 (Fri, 04 Jul 2008) $
+ Revision $Rev: 560 $
+ Author $Author: gsent $
+
+*/
+
+#include "omx_classmagic.h"
+#include "omx_base_port.h"
+
+#ifndef __OMX_BASE_CLOCK_PORT_H__
+#define __OMX_BASE_CLOCK_PORT_H__
+
+/**
+ * @brief the base clock domain structure that describes each port.
+ *
+ * The data structure is derived from base port class and contain clock
+ * domain specific parameters.
+ * Other elements can be added in the derived components structures.
+ *
+ * @param sOtherParam Domain specific (other) OpenMAX port parameter
+ */
+
+DERIVEDCLASS(omx_base_clock_PortType, omx_base_PortType)
+#define omx_base_clock_PortType_FIELDS omx_base_PortType_FIELDS \
+ OMX_TIME_CONFIG_TIMESTAMPTYPE sTimeStamp; /**< General OpenMAX configuration time stamp parameter */ \
+ OMX_TIME_MEDIATIMETYPE sMediaTime; \
+ OMX_TIME_CONFIG_MEDIATIMEREQUESTTYPE sMediaTimeRequest; \
+ OMX_OTHER_PARAM_PORTFORMATTYPE sOtherParam; /**< Domain specific (other) OpenMAX port parameter */
+ENDCLASS(omx_base_clock_PortType)
+
+/**
+ * @brief the base contructor for the generic openmax ST clock port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandComp pointer to the Handle of the component
+ * @param openmaxStandPort the ST port to be initialized
+ * @param nPortIndex Index of the port to be constructed
+ * @param isInput specifices if the port is an input or an output
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+
+OMX_ERRORTYPE base_clock_port_Constructor(
+ OMX_COMPONENTTYPE *openmaxStandComp,
+ omx_base_PortType **openmaxStandPort,
+ OMX_U32 nPortIndex,
+ OMX_BOOL isInput);
+
+/**
+ * @brief the base clock port destructor for the generic openmax ST clock port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the port.
+ * It takes care of destructing the instance of the port
+ *
+ * @param openmaxStandPort the ST port to be destructed
+ *
+ * @return OMX_ErrorNone
+ */
+
+OMX_ERRORTYPE base_clock_port_Destructor(
+ omx_base_PortType *openmaxStandPort);
+
+OMX_ERRORTYPE base_clock_port_SendBufferFunction(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer);
+
+#endif
diff --git a/alsa/omx_base_component.cpp b/alsa/omx_base_component.cpp
new file mode 100644
index 0000000..8396979
--- /dev/null
+++ b/alsa/omx_base_component.cpp
@@ -0,0 +1,1755 @@
+/**
+ @file src/base/omx_base_component.c
+
+ OpenMAX base_component component. This component does not perform any multimedia
+ processing. It is used as a base_component for new components development.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-09-16 15:59:45 +0200 (Tue, 16 Sep 2008) $
+ Revision $Rev: 621 $
+ Author $Author: gsent $
+
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+//#include <IL/OMX_Core.h>
+//#include <IL/OMX_Component.h>
+
+#include "omx_semaphore.h"
+#include "omx_base_component.h"
+
+/**
+ * @brief The base contructor for the OpenMAX st components
+ *
+ * This function is executed by the ST static component loader.
+ * It takes care of constructing the instance of the component.
+ * For the base_component component, the following is done:
+ *
+ * 1) Fills the basic OpenMAX structure. The fields can be overwritten
+ * by derived components.
+ * 2) Allocates (if needed) the omx_base_component_PrivateType private structure
+ *
+ * @param openmaxStandComp the ST component to be initialized
+ * @param cComponentName the OpenMAX string that describes the component
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+OMX_ERRORTYPE omx_base_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
+ omx_base_component_PrivateType* omx_base_component_Private;
+ OMX_U32 i;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (openmaxStandComp->pComponentPrivate) {
+ omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ } else {
+ omx_base_component_Private = (omx_base_component_PrivateType*)calloc(1,sizeof(omx_base_component_PrivateType));
+ if (!omx_base_component_Private) {
+ return OMX_ErrorInsufficientResources;
+ }
+ }
+
+ if(!omx_base_component_Private->messageQueue) {
+ omx_base_component_Private->messageQueue = (omx_queue_t*)calloc(1,sizeof(omx_queue_t));
+ omx_queue_init(omx_base_component_Private->messageQueue);
+ }
+
+ if(!omx_base_component_Private->messageSem) {
+ omx_base_component_Private->messageSem = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ omx_tsem_init(omx_base_component_Private->messageSem, 0);
+ }
+ if(!omx_base_component_Private->bMgmtSem) {
+ omx_base_component_Private->bMgmtSem = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ omx_tsem_init(omx_base_component_Private->bMgmtSem, 0);
+ }
+
+ if(!omx_base_component_Private->bStateSem) {
+ omx_base_component_Private->bStateSem = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ omx_tsem_init(omx_base_component_Private->bStateSem, 0);
+ }
+
+ openmaxStandComp->nSize = sizeof(OMX_COMPONENTTYPE);
+ openmaxStandComp->pApplicationPrivate = NULL;
+ openmaxStandComp->GetComponentVersion = omx_base_component_GetComponentVersion;
+ openmaxStandComp->SendCommand = omx_base_component_SendCommand;
+ openmaxStandComp->GetParameter = omx_base_component_GetParameter;
+ openmaxStandComp->SetParameter = omx_base_component_SetParameter;
+ openmaxStandComp->GetConfig = omx_base_component_GetConfig;
+ openmaxStandComp->SetConfig = omx_base_component_SetConfig;
+ openmaxStandComp->GetExtensionIndex = omx_base_component_GetExtensionIndex;
+ openmaxStandComp->GetState = omx_base_component_GetState;
+ openmaxStandComp->SetCallbacks = omx_base_component_SetCallbacks;
+ openmaxStandComp->ComponentDeInit = omx_base_component_ComponentDeInit;
+ openmaxStandComp->ComponentRoleEnum = omx_base_component_ComponentRoleEnum;
+ openmaxStandComp->ComponentTunnelRequest =omx_base_component_ComponentTunnelRequest;
+
+ /*Will make Specific port Allocate buffer call*/
+ openmaxStandComp->AllocateBuffer = omx_base_component_AllocateBuffer;
+ openmaxStandComp->UseBuffer = omx_base_component_UseBuffer;
+ openmaxStandComp->UseEGLImage = omx_base_component_UseEGLImage;
+ openmaxStandComp->FreeBuffer = omx_base_component_FreeBuffer;
+ openmaxStandComp->EmptyThisBuffer = omx_base_component_EmptyThisBuffer;
+ openmaxStandComp->FillThisBuffer = omx_base_component_FillThisBuffer;
+
+ openmaxStandComp->nVersion.s.nVersionMajor = OMX_VERSION_MAJOR;
+ openmaxStandComp->nVersion.s.nVersionMinor = OMX_VERSION_MINOR;
+ openmaxStandComp->nVersion.s.nRevision = OMX_VERSION_REVISION;
+ openmaxStandComp->nVersion.s.nStep = OMX_VERSION_STEP;
+
+ omx_base_component_Private->name = (char*)calloc(1,OMX_MAX_STRINGNAME_SIZE);
+ if (!omx_base_component_Private->name) {
+ return OMX_ErrorInsufficientResources;
+ }
+ strcpy(omx_base_component_Private->name,cComponentName);
+ omx_base_component_Private->state = OMX_StateLoaded;
+ omx_base_component_Private->transientState = OMX_TransStateMax;
+ omx_base_component_Private->callbacks = NULL;
+ omx_base_component_Private->callbackData = NULL;
+ omx_base_component_Private->nGroupPriority = 0;
+ omx_base_component_Private->nGroupID = 0;
+ omx_base_component_Private->pMark.hMarkTargetComponent = NULL;
+ omx_base_component_Private->pMark.pMarkData = NULL;
+ omx_base_component_Private->openmaxStandComp=openmaxStandComp;
+ omx_base_component_Private->DoStateSet = &omx_base_component_DoStateSet;
+ omx_base_component_Private->messageHandler = omx_base_component_MessageHandler;
+ omx_base_component_Private->destructor = omx_base_component_Destructor;
+ omx_base_component_Private->bufferMgmtThreadID = -1;
+
+ pthread_mutex_init(&omx_base_component_Private->flush_mutex, NULL);
+
+ if(!omx_base_component_Private->flush_all_condition) {
+ omx_base_component_Private->flush_all_condition = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ omx_tsem_init(omx_base_component_Private->flush_all_condition, 0);
+ }
+
+ if(!omx_base_component_Private->flush_condition) {
+ omx_base_component_Private->flush_condition = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ omx_tsem_init(omx_base_component_Private->flush_condition, 0);
+ }
+
+ for(i=0;i<NUM_DOMAINS;i++) {
+ memset(&omx_base_component_Private->sPortTypesParam[i], 0, sizeof(OMX_PORT_PARAM_TYPE));
+ setHeader(&omx_base_component_Private->sPortTypesParam[i], sizeof(OMX_PORT_PARAM_TYPE));
+ }
+
+ omx_base_component_Private->messageHandlerThreadID = pthread_create(&omx_base_component_Private->messageHandlerThread,
+ NULL,
+ compMessageHandlerFunction,
+ openmaxStandComp);
+
+ DEBUG(DEB_LEV_FUNCTION_NAME,"Out of %s\n",__func__);
+ return OMX_ErrorNone;
+}
+
+/** @brief The base destructor for ST OpenMAX components
+ *
+ * This function is called by the standard function ComponentDeInit()
+ * that is called by the IL core during the execution of the FreeHandle()
+ *
+ * @param openmaxStandComp the ST OpenMAX component to be disposed
+ */
+OMX_ERRORTYPE omx_base_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ int err;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ omx_base_component_Private->state = OMX_StateInvalid;
+
+ /*Send Dummy signal to Component Message handler to exit*/
+ omx_tsem_up(omx_base_component_Private->messageSem);
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s messageSem signaled. messageSem->semval=%d\n", __func__, omx_base_component_Private->messageSem->semval);
+
+ err = pthread_join(omx_base_component_Private->messageHandlerThread,NULL);
+ if(err!=0) {
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s pthread_join returned err=%d\n", __func__, err);
+ }
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s past pthread_join\n", __func__);
+
+ omx_base_component_Private->callbacks=NULL;
+
+ /*Deinitialize and free message queue*/
+ if(omx_base_component_Private->messageQueue) {
+ omx_queue_deinit(omx_base_component_Private->messageQueue);
+ free(omx_base_component_Private->messageQueue);
+ omx_base_component_Private->messageQueue=NULL;
+ }
+
+ /*Deinitialize and free buffer management semaphore*/
+ if(omx_base_component_Private->bMgmtSem){
+ omx_tsem_deinit(omx_base_component_Private->bMgmtSem);
+ free(omx_base_component_Private->bMgmtSem);
+ omx_base_component_Private->bMgmtSem=NULL;
+ }
+
+ /*Deinitialize and free message semaphore*/
+ if(omx_base_component_Private->messageSem) {
+ omx_tsem_deinit(omx_base_component_Private->messageSem);
+ free(omx_base_component_Private->messageSem);
+ omx_base_component_Private->messageSem=NULL;
+ }
+
+ if(omx_base_component_Private->bStateSem){
+ omx_tsem_deinit(omx_base_component_Private->bStateSem);
+ free(omx_base_component_Private->bStateSem);
+ omx_base_component_Private->bStateSem=NULL;
+ }
+
+ if(omx_base_component_Private->name){
+ free(omx_base_component_Private->name);
+ omx_base_component_Private->name=NULL;
+ }
+
+ pthread_mutex_destroy(&omx_base_component_Private->flush_mutex);
+
+ if(omx_base_component_Private->flush_all_condition){
+ omx_tsem_deinit(omx_base_component_Private->flush_all_condition);
+ free(omx_base_component_Private->flush_all_condition);
+ omx_base_component_Private->flush_all_condition=NULL;
+ }
+
+ if(omx_base_component_Private->flush_condition){
+ omx_tsem_deinit(omx_base_component_Private->flush_condition);
+ free(omx_base_component_Private->flush_condition);
+ omx_base_component_Private->flush_condition=NULL;
+ }
+
+ DEBUG(DEB_LEV_FUNCTION_NAME,"Out of %s\n",__func__);
+ return OMX_ErrorNone;
+}
+
+/** @brief This standard functionality is called when the component is
+ * destroyed in the FreeHandle standard call.
+ *
+ * In this way the implementation of the FreeHandle is standard,
+ * and it does not need a support by a specific component loader.
+ * The implementaiton of the ComponentDeInit contains the
+ * implementation specific part of the destroying phase.
+ */
+OMX_ERRORTYPE omx_base_component_ComponentDeInit(
+ OMX_IN OMX_HANDLETYPE hComponent) {
+ OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s pComponentPrivate =%x \n", __func__,(int)openmaxStandComp->pComponentPrivate);
+ omx_base_component_Private->destructor(openmaxStandComp);
+
+ free(openmaxStandComp->pComponentPrivate);
+ openmaxStandComp->pComponentPrivate=NULL;
+ return OMX_ErrorNone;
+}
+
+/** Changes the state of a component taking proper actions depending on
+ * the transiotion requested. This base function cover only the state
+ * changes that do not involve any port
+ *
+ * @param openmaxStandComp the OpenMAX component which state is to be changed
+ * @param destinationState the requested target state
+ *
+ * @return OMX_ErrorNotImplemented if the state change is noty handled in this base class, but needs
+ * a specific handling
+ */
+OMX_ERRORTYPE omx_base_component_DoStateSet(OMX_COMPONENTTYPE *openmaxStandComp, OMX_U32 destinationState) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ omx_base_PortType *pPort;
+ OMX_U32 i,j,k;
+ OMX_ERRORTYPE err=OMX_ErrorNone;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ DEBUG(DEB_LEV_PARAMS, "Changing state from %i to %i\n", omx_base_component_Private->state, (int)destinationState);
+
+ if(destinationState == OMX_StateLoaded){
+ switch(omx_base_component_Private->state){
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ case OMX_StateWaitForResources:
+ /* return back from wait for resources */
+ omx_base_component_Private->state = OMX_StateLoaded;
+ break;
+ case OMX_StateLoaded:
+ err = OMX_ErrorSameState;
+ break;
+ case OMX_StateIdle:
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+
+ pPort = omx_base_component_Private->ports[i];
+ if (PORT_IS_TUNNELED(pPort) && PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ while(pPort->pBufferQueue->nelem > 0) {
+ DEBUG(DEB_LEV_PARAMS, "In %s Buffer %d remained in the port %d queue of comp%s\n",
+ __func__,(int)pPort->pBufferQueue->nelem,(int)i,omx_base_component_Private->name);
+ omx_dequeue(pPort->pBufferQueue);
+ }
+ /* Freeing here the buffers allocated for the tunneling:*/
+ err = pPort->Port_FreeTunnelBuffer(pPort,i);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Freeing Tunnel Buffer Error=%x\n",__func__,err);
+ return err;
+ }
+ } else {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s nPortIndex=%d pAllocSem Semval=%x\n", __func__,(int)i,(int)pPort->pAllocSem->semval);
+
+ /*If ports are enabled then wait till all buffers are freed*/
+ if(PORT_IS_ENABLED(pPort)) {
+ omx_tsem_down(pPort->pAllocSem);
+ }
+ }
+ pPort->sPortParam.bPopulated = OMX_FALSE;
+
+ if(pPort->bTunnelTearDown == OMX_TRUE){
+ DEBUG(DEB_LEV_PARAMS, "In %s TearDown tunnel\n", __func__);
+ pPort->hTunneledComponent = 0;
+ pPort->nTunneledPort = 0;
+ pPort->nTunnelFlags = 0;
+ pPort->eBufferSupplier=OMX_BufferSupplyUnspecified;
+ pPort->bTunnelTearDown = OMX_FALSE;
+ }
+
+ if(pPort->pInternalBufferStorage != NULL) {
+ free(pPort->pInternalBufferStorage);
+ pPort->pInternalBufferStorage=NULL;
+ }
+
+ if(pPort->bBufferStateAllocated != NULL) {
+ free(pPort->bBufferStateAllocated);
+ pPort->bBufferStateAllocated=NULL;
+ }
+ }
+ }
+ omx_base_component_Private->state = OMX_StateLoaded;
+
+ if(omx_base_component_Private->bufferMgmtThreadID == 0 ){
+ /*Signal Buffer Management thread to exit*/
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ pthread_join(omx_base_component_Private->bufferMgmtThread,NULL);
+ omx_base_component_Private->bufferMgmtThreadID = -1;
+ if(err != 0) {
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s pthread_join returned err=%d\n",__func__,err);
+ }
+ }
+
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: state transition not allowed\n", __func__);
+ err = OMX_ErrorIncorrectStateTransition;
+ break;
+ }
+ return err;
+ }
+
+ if(destinationState == OMX_StateWaitForResources){
+ switch(omx_base_component_Private->state){
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ case OMX_StateLoaded:
+ omx_base_component_Private->state = OMX_StateWaitForResources;
+ break;
+ case OMX_StateWaitForResources:
+ err = OMX_ErrorSameState;
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: state transition not allowed\n", __func__);
+ err = OMX_ErrorIncorrectStateTransition;
+ break;
+ }
+ return err;
+ }
+
+ if(destinationState == OMX_StateIdle){
+ switch(omx_base_component_Private->state){
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ case OMX_StateWaitForResources:
+ omx_base_component_Private->state = OMX_StateIdle;
+ break;
+ case OMX_StateLoaded:
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort = omx_base_component_Private->ports[i];
+ if (PORT_IS_TUNNELED(pPort) && PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ if(PORT_IS_ENABLED(pPort)) {
+ /** Allocate here the buffers needed for the tunneling */
+ err= pPort->Port_AllocateTunnelBuffer(pPort, i, omx_base_component_Private->ports[i]->sPortParam.nBufferSize);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Allocating Tunnel Buffer Port=%d, Error=%x\n",__func__,i,err);
+ return err;
+ }
+ }
+ } else {
+ if(PORT_IS_ENABLED(pPort)) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: wait for buffers. port enabled %i, port populated %i\n",
+ __func__, pPort->sPortParam.bEnabled,pPort->sPortParam.bPopulated);
+ omx_tsem_down(pPort->pAllocSem);
+ pPort->sPortParam.bPopulated = OMX_TRUE;
+ }
+ else
+ DEBUG(DEB_LEV_ERR, "In %s: Port %i Disabled So no wait\n",__func__,(int)i);
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "---> Tunnel status : port %d flags 0x%x\n",(int)i, (int)pPort->nTunnelFlags);
+ }
+ }
+ omx_base_component_Private->state = OMX_StateIdle;
+ /** starting buffer management thread */
+ omx_base_component_Private->bufferMgmtThreadID = pthread_create(&omx_base_component_Private->bufferMgmtThread,
+ NULL,
+ omx_base_component_Private->BufferMgmtFunction,
+ openmaxStandComp);
+ if(omx_base_component_Private->bufferMgmtThreadID < 0){
+ DEBUG(DEB_LEV_ERR, "Starting buffer management thread failed\n");
+ return OMX_ErrorUndefined;
+ }
+ break;
+ case OMX_StateIdle:
+ err = OMX_ErrorSameState;
+ break;
+ case OMX_StateExecuting:
+ /*Flush Ports*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ DEBUG(DEB_LEV_FULL_SEQ, "Flushing Port %i\n",(int)i);
+ pPort = omx_base_component_Private->ports[i];
+ if(PORT_IS_ENABLED(pPort)) {
+ pPort->FlushProcessingBuffers(pPort);
+ }
+ }
+ }
+ omx_base_component_Private->state = OMX_StateIdle;
+ break;
+ case OMX_StatePause:
+ omx_base_component_Private->state = OMX_StateIdle;
+ /*Signal buffer management thread if waiting at paused state*/
+ omx_tsem_signal(omx_base_component_Private->bStateSem);
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: state transition not allowed\n", __func__);
+ err = OMX_ErrorIncorrectStateTransition;
+ break;
+ }
+ return err;
+ }
+
+ if(destinationState == OMX_StatePause) {
+ switch(omx_base_component_Private->state) {
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ case OMX_StatePause:
+ err = OMX_ErrorSameState;
+ break;
+ case OMX_StateExecuting:
+ case OMX_StateIdle:
+ omx_base_component_Private->state = OMX_StatePause;
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: state transition not allowed\n", __func__);
+ err = OMX_ErrorIncorrectStateTransition;
+ break;
+ }
+ return err;
+ }
+
+ if(destinationState == OMX_StateExecuting) {
+ switch(omx_base_component_Private->state) {
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ case OMX_StateIdle:
+ omx_base_component_Private->state=OMX_StateExecuting;
+ /*Send Tunneled Buffer to the Neighbouring Components*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort = omx_base_component_Private->ports[i];
+ if (PORT_IS_TUNNELED(pPort) && PORT_IS_BUFFER_SUPPLIER(pPort) && PORT_IS_ENABLED(pPort)) {
+ for(k=0;k<pPort->nNumTunnelBuffer;k++) {
+ omx_tsem_up(pPort->pBufferSem);
+ /*signal buffer management thread availability of buffers*/
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+ }
+ omx_base_component_Private->transientState = OMX_TransStateMax;
+ err = OMX_ErrorNone;
+ break;
+ case OMX_StatePause:
+ omx_base_component_Private->state=OMX_StateExecuting;
+
+ /* Tunneled Supplier Ports were enabled in paused state. So signal buffer managment thread*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+
+ pPort=omx_base_component_Private->ports[i];
+ DEBUG(DEB_LEV_PARAMS, "In %s: state transition Paused 2 Executing, nelem=%d,semval=%d,Buf Count Actual=%d\n", __func__,
+ pPort->pBufferQueue->nelem,pPort->pBufferSem->semval,(int)pPort->sPortParam.nBufferCountActual);
+
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(pPort) &&
+ (pPort->pBufferQueue->nelem == (pPort->pBufferSem->semval + pPort->sPortParam.nBufferCountActual))) {
+ for(k=0; k < pPort->sPortParam.nBufferCountActual;k++) {
+ omx_tsem_up(pPort->pBufferSem);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+ }
+ /*Signal buffer management thread if waiting at paused state*/
+ omx_tsem_signal(omx_base_component_Private->bStateSem);
+ break;
+ case OMX_StateExecuting:
+ err = OMX_ErrorSameState;
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: state transition not allowed\n", __func__);
+ err = OMX_ErrorIncorrectStateTransition;
+ break;
+ }
+ return err;
+ }
+
+ if(destinationState == OMX_StateInvalid) {
+ switch(omx_base_component_Private->state) {
+ case OMX_StateInvalid:
+ err = OMX_ErrorInvalidState;
+ break;
+ default:
+ omx_base_component_Private->state = OMX_StateInvalid;
+
+ if(omx_base_component_Private->bufferMgmtThreadID == 0 ){
+ /*Signal Buffer Management Thread to Exit*/
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ pthread_join(omx_base_component_Private->bufferMgmtThread,NULL);
+ omx_base_component_Private->bufferMgmtThreadID = -1;
+ if(err!=0) {
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s pthread_join returned err=%d\n",__func__,err);
+ }
+ }
+ err = OMX_ErrorInvalidState;
+ break;
+ }
+ return err;
+ }
+ return OMX_ErrorNone;
+}
+
+/** @brief Checks the header of a structure for consistency
+ * with size and spec version
+ *
+ * @param header Pointer to the structure to be checked
+ * @param size Size of the structure. it is in general obtained
+ * with a sizeof call applied to the structure
+ *
+ * @return OMX error code. If the header has failed the check,
+ * OMX_ErrorVersionMismatch is returned.
+ * If the header fails the size check OMX_ErrorBadParameter is returned
+ */
+OMX_ERRORTYPE checkHeader(OMX_PTR header, OMX_U32 size) {
+ OMX_VERSIONTYPE* ver;
+ if (header == NULL) {
+ DEBUG(DEB_LEV_ERR, "In %s the header is null\n",__func__);
+ return OMX_ErrorBadParameter;
+ }
+ ver = (OMX_VERSIONTYPE*)((char*)header + sizeof(OMX_U32));
+ if(*((OMX_U32*)header) != size) {
+ DEBUG(DEB_LEV_ERR, "In %s the header has a wrong size %i should be %i\n",__func__,(int)*((OMX_U32*)header),(int)size);
+ return OMX_ErrorBadParameter;
+ }
+ if(ver->s.nVersionMajor != OMX_VERSION_MAJOR ||
+ ver->s.nVersionMinor != OMX_VERSION_MINOR) {
+ DEBUG(DEB_LEV_ERR, "The version does not match\n");
+ return OMX_ErrorVersionMismatch;
+ }
+ return OMX_ErrorNone;
+}
+
+/** @brief Simply fills the first two fields in any OMX structure
+ * with the size and the version
+ *
+ * @param header pointer to the structure to be filled
+ * @param size size of the structure. It can be obtained with
+ * a call to sizeof of the structure type
+ */
+void setHeader(OMX_PTR header, OMX_U32 size) {
+ OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)((char*)header + sizeof(OMX_U32));
+ *((OMX_U32*)header) = size;
+
+ ver->s.nVersionMajor = OMX_VERSION_MAJOR;
+ ver->s.nVersionMinor = OMX_VERSION_MINOR;
+ ver->s.nRevision = OMX_VERSION_REVISION;
+ ver->s.nStep = OMX_VERSION_STEP;
+}
+
+/**
+ * This function verify Component State and Structure header
+ */
+OMX_ERRORTYPE omx_base_component_ParameterSanityCheck(OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pStructure,
+ OMX_IN size_t size) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+ omx_base_PortType *pPort;
+ int nNumPorts;
+
+ nNumPorts = omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts;
+
+ if (nPortIndex >= nNumPorts) {
+ DEBUG(DEB_LEV_ERR, "Bad Port index %i when the component has %i ports\n", (int)nPortIndex, (int)nNumPorts);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ pPort = omx_base_component_Private->ports[nPortIndex];
+
+ if (omx_base_component_Private->state != OMX_StateLoaded && omx_base_component_Private->state != OMX_StateWaitForResources) {
+ if(PORT_IS_ENABLED(pPort)) {
+ DEBUG(DEB_LEV_ERR, "In %s Incorrect State=%x lineno=%d\n",__func__,omx_base_component_Private->state,__LINE__);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ }
+
+ return checkHeader(pStructure , size);
+}
+
+/** @brief Standard OpenMAX function
+ *
+ * it returns the version of the component. See OMX_Core.h
+ */
+OMX_ERRORTYPE omx_base_component_GetComponentVersion(OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_STRING pComponentName,
+ OMX_OUT OMX_VERSIONTYPE* pComponentVersion,
+ OMX_OUT OMX_VERSIONTYPE* pSpecVersion,
+ OMX_OUT OMX_UUIDTYPE* pComponentUUID) {
+
+ OMX_COMPONENTTYPE* omx_component = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omx_component->pComponentPrivate;
+
+ OMX_U32 uuid[3];
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ /* Fill component name */
+ strcpy(pComponentName, omx_base_component_Private->name);
+
+ /* Fill component version */
+ pComponentVersion->s.nVersionMajor = OMX_VERSION_MAJOR;
+ pComponentVersion->s.nVersionMinor = OMX_VERSION_MINOR;
+ pComponentVersion->s.nRevision = OMX_VERSION_REVISION;
+ pComponentVersion->s.nStep = OMX_VERSION_STEP;
+
+ /* Fill spec version (copy from component field) */
+ memcpy(pSpecVersion, &omx_component->nVersion, sizeof(OMX_VERSIONTYPE));
+
+ /* Fill UUID with handle address, PID and UID.
+ * This should guarantee uiniqness */
+ uuid[0] = (OMX_U32)omx_component;
+ uuid[1] = getpid();
+ uuid[2] = getuid();
+ memcpy(*pComponentUUID, uuid, 3*sizeof(uuid));
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
+ return OMX_ErrorNone;
+}
+
+/** @brief Enumerates all the roles of the component.
+ *
+ * This function is intended to be used only by a core. The ST static core
+ * in any case does not use this function, because it can not be used before the
+ * creation of the component, but uses a static list.
+ * It is implemented only for API completion,and it will be not overriden
+ * by a derived component
+ */
+OMX_ERRORTYPE omx_base_component_ComponentRoleEnum(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_U8 *cRole,
+ OMX_IN OMX_U32 nIndex) {
+ strcat((char*)cRole, "\0");
+ return OMX_ErrorNoMore;
+}
+
+/** @brief standard OpenMAX function
+ *
+ * it sets the callback functions given by the IL client.
+ * See OMX_Component.h
+ */
+OMX_ERRORTYPE omx_base_component_SetCallbacks(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_CALLBACKTYPE* pCallbacks,
+ OMX_IN OMX_PTR pAppData) {
+
+ OMX_COMPONENTTYPE *omxcomponent = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxcomponent->pComponentPrivate;
+ omx_base_PortType *pPort;
+ OMX_U32 i,j;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ omx_base_component_Private->callbacks = pCallbacks;
+ omx_base_component_Private->callbackData = pAppData;
+
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort = omx_base_component_Private->ports[i];
+ if (pPort->sPortParam.eDir == OMX_DirInput) {
+ pPort->BufferProcessedCallback = omx_base_component_Private->callbacks->EmptyBufferDone;
+ } else {
+ pPort->BufferProcessedCallback = omx_base_component_Private->callbacks->FillBufferDone;
+ }
+ }
+ }
+ return OMX_ErrorNone;
+}
+
+/** @brief Part of the standard OpenMAX function
+ *
+ * This function return the parameters not related to any port.
+ * These parameters are handled in the derived components
+ * See OMX_Core.h for standard reference
+ *
+ * @return OMX_ErrorUnsupportedIndex if the index is not supported or not handled here
+ */
+OMX_ERRORTYPE omx_base_component_GetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_INOUT OMX_PTR ComponentParameterStructure) {
+
+ OMX_COMPONENTTYPE *omxcomponent = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxcomponent->pComponentPrivate;
+ OMX_PRIORITYMGMTTYPE* pPrioMgmt;
+ OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
+ OMX_PARAM_BUFFERSUPPLIERTYPE *pBufferSupplier;
+ omx_base_PortType *pPort;
+ OMX_PORT_PARAM_TYPE* pPortDomains;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ OMX_VENDOR_PROP_TUNNELSETUPTYPE *pPropTunnelSetup;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ DEBUG(DEB_LEV_PARAMS, "Getting parameter %i\n", nParamIndex);
+ if (ComponentParameterStructure == NULL) {
+ return OMX_ErrorBadParameter;
+ }
+ switch(nParamIndex) {
+ case OMX_IndexParamAudioInit:
+ case OMX_IndexParamVideoInit:
+ case OMX_IndexParamImageInit:
+ case OMX_IndexParamOtherInit:
+ pPortDomains = (OMX_PORT_PARAM_TYPE*)ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ pPortDomains->nPorts = 0;
+ pPortDomains->nStartPortNumber = 0;
+ break;
+ case OMX_IndexParamPortDefinition:
+ pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_PORTDEFINITIONTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ if (pPortDef->nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ memcpy(pPortDef, &omx_base_component_Private->ports[pPortDef->nPortIndex]->sPortParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+ break;
+ case OMX_IndexParamPriorityMgmt:
+ pPrioMgmt = (OMX_PRIORITYMGMTTYPE*)ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PRIORITYMGMTTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ pPrioMgmt->nGroupPriority = omx_base_component_Private->nGroupPriority;
+ pPrioMgmt->nGroupID = omx_base_component_Private->nGroupID;
+ break;
+ case OMX_IndexParamCompBufferSupplier:
+ pBufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE*)ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ if (pBufferSupplier->nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ pPort = omx_base_component_Private->ports[pBufferSupplier->nPortIndex];
+
+ if (pPort->sPortParam.eDir == OMX_DirInput) {
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyInput;
+ } else if (PORT_IS_TUNNELED(pPort)) {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput;
+ } else {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified;
+ }
+ } else {
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyOutput;
+ } else if (PORT_IS_TUNNELED(pPort)) {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyInput;
+ } else {
+ pBufferSupplier->eBufferSupplier = OMX_BufferSupplyUnspecified;
+ }
+ }
+ break;
+ case OMX_IndexVendorCompPropTunnelFlags:
+ pPropTunnelSetup = (OMX_VENDOR_PROP_TUNNELSETUPTYPE*)ComponentParameterStructure;
+
+ if (pPropTunnelSetup->nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+
+ DEBUG(DEB_LEV_ERR,"In %s OMX_IndexVendorCompPropTunnelFlags nPortIndex=%d Line=%d \n",
+ __func__,(int)pPropTunnelSetup->nPortIndex,__LINE__);
+
+ return OMX_ErrorBadPortIndex;
+ }
+
+ pPort = omx_base_component_Private->ports[pPropTunnelSetup->nPortIndex];
+
+ pPropTunnelSetup->nTunnelSetup.nTunnelFlags = pPort->nTunnelFlags;
+ pPropTunnelSetup->nTunnelSetup.eSupplier = pPort->eBufferSupplier;
+ break;
+ default:
+ err = OMX_ErrorUnsupportedIndex;
+ break;
+ }
+ return err;
+}
+
+/** @brief Part of the standard OpenMAX function
+ *
+ * This function sets the parameters not related to any port.
+ * These parameters are handled in the derived components
+ * See OMX_Core.h for standard reference
+ *
+ * @return OMX_ErrorUnsupportedIndex if the index is not supported or not handled here
+ */
+OMX_ERRORTYPE omx_base_component_SetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_IN OMX_PTR ComponentParameterStructure) {
+
+ OMX_PRIORITYMGMTTYPE* pPrioMgmt;
+ OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ OMX_COMPONENTTYPE *omxcomponent = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxcomponent->pComponentPrivate;
+ OMX_PARAM_BUFFERSUPPLIERTYPE *pBufferSupplier;
+ omx_base_PortType *pPort;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ DEBUG(DEB_LEV_PARAMS, "Setting parameter %x\n", nParamIndex);
+ if (ComponentParameterStructure == NULL) {
+ DEBUG(DEB_LEV_ERR, "In %s parameter provided is null! err = %x\n", __func__, err);
+ return OMX_ErrorBadParameter;
+ }
+
+ switch(nParamIndex) {
+ case OMX_IndexParamAudioInit:
+ case OMX_IndexParamVideoInit:
+ case OMX_IndexParamImageInit:
+ case OMX_IndexParamOtherInit:
+ /* pPortParam = (OMX_PORT_PARAM_TYPE* ) ComponentParameterStructure;*/
+ if (omx_base_component_Private->state != OMX_StateLoaded &&
+ omx_base_component_Private->state != OMX_StateWaitForResources) {
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ err = OMX_ErrorUndefined;
+ break;
+ case OMX_IndexParamPortDefinition:
+ pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE*) ComponentParameterStructure;
+ DEBUG(DEB_LEV_PARAMS, "Setting parameter OMX_IndexParamPortDefinition for port %d\n", pPortDef->nPortIndex);
+ err = omx_base_component_ParameterSanityCheck(hComponent, pPortDef->nPortIndex, pPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
+ break;
+ }
+ {
+ OMX_PARAM_PORTDEFINITIONTYPE *pPortParam;
+ OMX_U32 j,old_nBufferCountActual=0;
+ pPortParam = &omx_base_component_Private->ports[pPortDef->nPortIndex]->sPortParam;
+ if(pPortDef->nBufferCountActual < pPortParam->nBufferCountMin) {
+ DEBUG(DEB_LEV_ERR, "In %s nBufferCountActual of param (%i) is < of nBufferCountMin of port(%i)\n",__func__, (int)pPortDef->nBufferCountActual, (int)pPortParam->nBufferCountMin);
+ err = OMX_ErrorBadParameter;
+ break;
+ }
+ old_nBufferCountActual = pPortParam->nBufferCountActual;
+ pPortParam->nBufferCountActual = pPortDef->nBufferCountActual;
+
+ switch(pPortDef->eDomain) {
+ case OMX_PortDomainAudio:
+ memcpy(&pPortParam->format.audio, &pPortDef->format.audio, sizeof(OMX_AUDIO_PORTDEFINITIONTYPE));
+ break;
+ case OMX_PortDomainVideo:
+ pPortParam->format.video.pNativeRender = pPortDef->format.video.pNativeRender;
+ pPortParam->format.video.nFrameWidth = pPortDef->format.video.nFrameWidth;
+ pPortParam->format.video.nFrameHeight = pPortDef->format.video.nFrameHeight;
+ pPortParam->format.video.nStride = pPortDef->format.video.nStride;
+ pPortParam->format.video.xFramerate = pPortDef->format.video.xFramerate;
+ pPortParam->format.video.bFlagErrorConcealment = pPortDef->format.video.bFlagErrorConcealment;
+ pPortParam->format.video.eCompressionFormat = pPortDef->format.video.eCompressionFormat;
+ pPortParam->format.video.eColorFormat = pPortDef->format.video.eColorFormat;
+ pPortParam->format.video.pNativeWindow = pPortDef->format.video.pNativeWindow;
+ break;
+ case OMX_PortDomainImage:
+ pPortParam->format.image.nFrameWidth = pPortDef->format.image.nFrameWidth;
+ pPortParam->format.image.nFrameHeight = pPortDef->format.image.nFrameHeight;
+ pPortParam->format.image.nStride = pPortDef->format.image.nStride;
+ pPortParam->format.image.bFlagErrorConcealment = pPortDef->format.image.bFlagErrorConcealment;
+ pPortParam->format.image.eCompressionFormat = pPortDef->format.image.eCompressionFormat;
+ pPortParam->format.image.eColorFormat = pPortDef->format.image.eColorFormat;
+ pPortParam->format.image.pNativeWindow = pPortDef->format.image.pNativeWindow;
+ break;
+ case OMX_PortDomainOther:
+ memcpy(&pPortParam->format.other, &pPortDef->format.other, sizeof(OMX_OTHER_PORTDEFINITIONTYPE));
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s wrong port domain. Out of OpenMAX scope\n",__func__);
+ err = OMX_ErrorBadParameter;
+ break;
+ }
+
+ /*If component state Idle/Pause/Executing and re-alloc the following private variables */
+ if ((omx_base_component_Private->state == OMX_StateIdle ||
+ omx_base_component_Private->state == OMX_StatePause ||
+ omx_base_component_Private->state == OMX_StateExecuting) &&
+ (pPortParam->nBufferCountActual > old_nBufferCountActual)) {
+
+ pPort = omx_base_component_Private->ports[pPortDef->nPortIndex];
+ if(pPort->pInternalBufferStorage) {
+ if(PORT_IS_TUNNELED(pPort)){
+ DEBUG(DEB_LEV_ERR, "In %s Attempt to reallocate tunneled buffers!\n",__func__);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ pPort->pInternalBufferStorage = (OMX_BUFFERHEADERTYPE**)realloc(pPort->pInternalBufferStorage,pPort->sPortParam.nBufferCountActual*sizeof(OMX_BUFFERHEADERTYPE *));
+ }
+
+ if(pPort->bBufferStateAllocated) {
+ pPort->bBufferStateAllocated = (BUFFER_STATUS_FLAG*)realloc(pPort->bBufferStateAllocated,pPort->sPortParam.nBufferCountActual*sizeof(BUFFER_STATUS_FLAG));
+ for(j=0; j < pPort->sPortParam.nBufferCountActual; j++) {
+ pPort->bBufferStateAllocated[j] = BUFFER_FREE;
+ }
+ }
+ }
+ }
+ break;
+ case OMX_IndexParamPriorityMgmt:
+ if (omx_base_component_Private->state != OMX_StateLoaded &&
+ omx_base_component_Private->state != OMX_StateWaitForResources) {
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ pPrioMgmt = (OMX_PRIORITYMGMTTYPE*)ComponentParameterStructure;
+ if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PRIORITYMGMTTYPE))) != OMX_ErrorNone) {
+ break;
+ }
+ omx_base_component_Private->nGroupPriority = pPrioMgmt->nGroupPriority;
+ omx_base_component_Private->nGroupID = pPrioMgmt->nGroupID;
+ break;
+ case OMX_IndexParamCompBufferSupplier:
+ pBufferSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE*)ComponentParameterStructure;
+
+ DEBUG(DEB_LEV_PARAMS, "In %s Buf Sup Port index=%d\n", __func__,(int)pBufferSupplier->nPortIndex);
+
+ if(pBufferSupplier == NULL) {
+ DEBUG(DEB_LEV_ERR, "In %s pBufferSupplier is null!\n",__func__);
+ return OMX_ErrorBadParameter;
+ }
+ if(pBufferSupplier->nPortIndex > (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ return OMX_ErrorBadPortIndex;
+ }
+ err = omx_base_component_ParameterSanityCheck(hComponent, pBufferSupplier->nPortIndex, pBufferSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
+ if(err==OMX_ErrorIncorrectStateOperation) {
+ if (PORT_IS_ENABLED(omx_base_component_Private->ports[pBufferSupplier->nPortIndex])) {
+ DEBUG(DEB_LEV_ERR, "In %s Incorrect State=%x\n",__func__,omx_base_component_Private->state);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ } else if (err != OMX_ErrorNone) {
+ break;
+ }
+
+ if (pBufferSupplier->eBufferSupplier == OMX_BufferSupplyUnspecified) {
+ DEBUG(DEB_LEV_PARAMS, "In %s: port is already buffer supplier unspecified\n", __func__);
+ return OMX_ErrorNone;
+ }
+ if ((PORT_IS_TUNNELED(omx_base_component_Private->ports[pBufferSupplier->nPortIndex])) == 0) {
+ return OMX_ErrorNone;
+ }
+
+ pPort = omx_base_component_Private->ports[pBufferSupplier->nPortIndex];
+
+ if ((pBufferSupplier->eBufferSupplier == OMX_BufferSupplyInput) &&
+ (pPort->sPortParam.eDir == OMX_DirInput)) {
+ /** These two cases regard the first stage of client override */
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ err = OMX_ErrorNone;
+ }
+ pPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ pBufferSupplier->nPortIndex = pPort->nTunneledPort;
+ err = OMX_SetParameter(pPort->hTunneledComponent, OMX_IndexParamCompBufferSupplier, pBufferSupplier);
+ } else if ((pBufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) &&
+ (pPort->sPortParam.eDir == OMX_DirInput)) {
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ pPort->nTunnelFlags &= ~TUNNEL_IS_SUPPLIER;
+ pBufferSupplier->nPortIndex = pPort->nTunneledPort;
+ err = OMX_SetParameter(pPort->hTunneledComponent, OMX_IndexParamCompBufferSupplier, pBufferSupplier);
+ }
+ err = OMX_ErrorNone;
+ } else if ((pBufferSupplier->eBufferSupplier == OMX_BufferSupplyOutput) &&
+ (pPort->sPortParam.eDir == OMX_DirOutput)) {
+ /** these two cases regard the second stage of client override */
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ err = OMX_ErrorNone;
+ }
+ pPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ } else {
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ pPort->nTunnelFlags &= ~TUNNEL_IS_SUPPLIER;
+ err = OMX_ErrorNone;
+ }
+ err = OMX_ErrorNone;
+ }
+ DEBUG(DEB_LEV_PARAMS, "In %s port %d Tunnel flag=%x \n", __func__,(int)pBufferSupplier->nPortIndex, (int)pPort->nTunnelFlags);
+ break;
+ default:
+ err = OMX_ErrorUnsupportedIndex;
+ break;
+ }
+ return err;
+}
+
+/** @brief base GetConfig function
+ *
+ * This base function is not implemented. If a derived component
+ * needs to support any config, it must implement a derived
+ * version of this function and assign it to the correct pointer
+ * in the private component descriptor
+ */
+OMX_ERRORTYPE omx_base_component_GetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_INOUT OMX_PTR pComponentConfigStructure) {
+ return OMX_ErrorNotImplemented;
+}
+
+/** @brief base SetConfig function
+ *
+ * This base function is not implemented. If a derived component
+ * needs to support any config, it must implement a derived
+ * version of this function and assign it to the correct pointer
+ * in the private component descriptor
+ */
+OMX_ERRORTYPE omx_base_component_SetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_IN OMX_PTR pComponentConfigStructure) {
+ // TODO: For now, do not return OMX_ErrorNotImplemented here because it breaks current COMXAudio
+ return OMX_ErrorNone;
+}
+
+/** @brief base function not implemented
+ *
+ * This function can be eventually implemented by a
+ * derived component if needed
+ */
+OMX_ERRORTYPE omx_base_component_GetExtensionIndex(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_STRING cParameterName,
+ OMX_OUT OMX_INDEXTYPE* pIndexType) {
+
+ DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
+
+ return OMX_ErrorBadParameter;
+}
+
+/** @return the state of the component
+ *
+ * This function does not need any override by derived components
+ */
+OMX_ERRORTYPE omx_base_component_GetState(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_STATETYPE* pState) {
+ OMX_COMPONENTTYPE *omxcomponent = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxcomponent->pComponentPrivate;
+ *pState = omx_base_component_Private->state;
+ return OMX_ErrorNone;
+}
+
+/** @brief standard SendCommand function
+ *
+ * In general this function does not need a overwrite, but
+ * a special derived component could do it.
+ */
+OMX_ERRORTYPE omx_base_component_SendCommand(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_COMMANDTYPE Cmd,
+ OMX_IN OMX_U32 nParam,
+ OMX_IN OMX_PTR pCmdData) {
+ OMX_COMPONENTTYPE* omxComponent = (OMX_COMPONENTTYPE*)hComponent;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ internalRequestMessageType *message;
+ omx_queue_t* messageQueue;
+ omx_tsem_t* messageSem;
+ OMX_U32 i,j,k;
+ omx_base_PortType *pPort;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ messageQueue = omx_base_component_Private->messageQueue;
+ messageSem = omx_base_component_Private->messageSem;
+
+ if (omx_base_component_Private->state == OMX_StateInvalid) {
+ return OMX_ErrorInvalidState;
+ }
+
+ message = (internalRequestMessageType*)calloc(1,sizeof(internalRequestMessageType));
+ message->messageParam = nParam;
+ message->pCmdData=pCmdData;
+ /** Fill in the message */
+ switch (Cmd) {
+ case OMX_CommandStateSet:
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_CommandStateSet desired state=%d\n", __func__, nParam);
+ message->messageType = OMX_CommandStateSet;
+ if ((nParam == OMX_StateIdle) && (omx_base_component_Private->state == OMX_StateLoaded)) {
+ /*Allocate Internal Buffer Storage and Buffer Allocation State flags*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+
+ pPort = omx_base_component_Private->ports[i];
+
+ if(pPort->pInternalBufferStorage == NULL) {
+ pPort->pInternalBufferStorage = (OMX_BUFFERHEADERTYPE**)calloc(pPort->sPortParam.nBufferCountActual,sizeof(OMX_BUFFERHEADERTYPE *));
+ }
+
+ if(pPort->bBufferStateAllocated == NULL) {
+ pPort->bBufferStateAllocated = (BUFFER_STATUS_FLAG*)calloc(pPort->sPortParam.nBufferCountActual,sizeof(BUFFER_STATUS_FLAG));
+ for(k=0; k < pPort->sPortParam.nBufferCountActual; k++)
+ {
+ pPort->bBufferStateAllocated[k] = BUFFER_FREE;
+ }
+ }
+ }
+ }
+
+ omx_base_component_Private->transientState = OMX_TransStateLoadedToIdle;
+ } else if ((nParam == OMX_StateLoaded) && (omx_base_component_Private->state == OMX_StateIdle)) {
+ omx_base_component_Private->transientState = OMX_TransStateIdleToLoaded;
+ } else if ((nParam == OMX_StateIdle) && (omx_base_component_Private->state == OMX_StateExecuting)) {
+ omx_base_component_Private->transientState = OMX_TransStateExecutingToIdle;
+ }
+ break;
+ case OMX_CommandFlush:
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_CommandFlush port=%d\n", __func__, nParam);
+ if (nParam >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) && nParam != OMX_ALL) {
+ return OMX_ErrorBadPortIndex;
+ }
+ message->messageType = OMX_CommandFlush;
+ break;
+ case OMX_CommandPortDisable:
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_CommandPortDisable port=%d\n", __func__, nParam);
+ if (nParam >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) && nParam != OMX_ALL) {
+ return OMX_ErrorBadPortIndex;
+ }
+ message->messageType = OMX_CommandPortDisable;
+ if(message->messageParam == OMX_ALL) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ omx_base_component_Private->ports[i]->bIsTransientToDisabled = OMX_TRUE;
+ }
+ }
+ } else {
+ omx_base_component_Private->ports[message->messageParam]->bIsTransientToDisabled = OMX_TRUE;
+ }
+ break;
+ case OMX_CommandPortEnable:
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_CommandPortEnable port=%d\n", __func__, nParam);
+ if (nParam >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) && nParam != OMX_ALL) {
+ return OMX_ErrorBadPortIndex;
+ }
+ message->messageType = OMX_CommandPortEnable;
+ if(message->messageParam == OMX_ALL) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ omx_base_component_Private->ports[i]->bIsTransientToEnabled = OMX_TRUE;
+ }
+ }
+ } else {
+ omx_base_component_Private->ports[message->messageParam]->bIsTransientToEnabled = OMX_TRUE;
+ }
+ break;
+ case OMX_CommandMarkBuffer:
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s OMX_CommandMarkBuffer port=%d\n", __func__, nParam);
+ if (nParam >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts) && nParam != OMX_ALL) {
+ return OMX_ErrorBadPortIndex;
+ }
+ message->messageType = OMX_CommandMarkBuffer;
+ break;
+ default:
+ err = OMX_ErrorUnsupportedIndex;
+ break;
+ }
+
+ if (err == OMX_ErrorNone)
+ {
+ omx_queue(messageQueue, message);
+ omx_tsem_up(messageSem);
+ }
+
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s messageSem up param=%d\n", __func__,message->messageParam);
+
+ return err;
+}
+
+/** @brief Component's message handler thread function
+ *
+ * Handles all messages coming from components and
+ * processes them by dispatching them back to the
+ * triggering component.
+ */
+void* compMessageHandlerFunction(void* param) {
+ OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)param;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ internalRequestMessageType *message;
+
+ while(1){
+ if (omx_base_component_Private == NULL) {
+ break;
+ }
+
+ /* Wait for an incoming message */
+ omx_tsem_down(omx_base_component_Private->messageSem);
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ /*Destructor has been called. So exit from the loop*/
+ if(omx_base_component_Private->state == OMX_StateInvalid) {
+ break;
+ }
+
+ /* Dequeue it */
+ message = (internalRequestMessageType*)omx_dequeue(omx_base_component_Private->messageQueue);
+ if(message == NULL){
+ DEBUG(DEB_LEV_ERR, "In %s: ouch!! had null message!\n", __func__);
+ break;
+ }
+ /* Process it by calling component's message handler method */
+ omx_base_component_Private->messageHandler(openmaxStandComp,message);
+ /* Message ownership has been transferred to us
+ * so we gonna free it when finished.
+ */
+ free(message);
+ message = NULL;
+ }
+ DEBUG(DEB_LEV_FUNCTION_NAME,"Exiting Message Handler thread\n");
+ return NULL;
+}
+
+/** This is called by the component message entry point.
+ * In thea base version this function is named compMessageHandlerFunction
+ *
+ * A request is made by the component when some asynchronous services are needed:
+ * 1) A SendCommand() is to be processed
+ * 2) An error needs to be notified
+ * 3) ...
+ *
+ * @param openmaxStandComp the component itself
+ * @param message the message that has been passed to core
+ */
+OMX_ERRORTYPE omx_base_component_MessageHandler(OMX_COMPONENTTYPE *openmaxStandComp,internalRequestMessageType* message) {
+ omx_base_component_PrivateType* omx_base_component_Private=(omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ OMX_U32 i,j,k;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ omx_base_PortType* pPort;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ /* Dealing with a SendCommand call.
+ * -messageType contains the command to execute
+ * -messageParam contains the parameter of the command
+ * (destination state in case of a state change command).
+ */
+ switch(message->messageType){
+ case OMX_CommandStateSet: {
+ /* Do the actual state change */
+ err = (*(omx_base_component_Private->DoStateSet))(openmaxStandComp, message->messageParam);
+ if (err != OMX_ErrorNone) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ err, /* The commands was a OMX_CommandStateSet */
+ 0, /* The state has been changed in message->messageParam */
+ NULL);
+ } else {
+ /* And run the callback */
+ DEBUG(DEB_LEV_FULL_SEQ,"running callback in %s\n",__func__);
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandStateSet, /* The commands was a OMX_CommandStateSet */
+ message->messageParam, /* The state has been changed in message->messageParam */
+ NULL);
+ }
+ }
+ break;
+ case OMX_CommandFlush: {
+ /*Flush port/s*/
+ if(message->messageParam == OMX_ALL) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ omx_base_component_Private->ports[i]->bIsPortFlushed = OMX_TRUE;
+ }
+ }
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort=omx_base_component_Private->ports[i];
+ err = pPort->FlushProcessingBuffers(pPort);
+ }
+ }
+ }
+ else {
+ pPort=omx_base_component_Private->ports[message->messageParam];
+ err = pPort->FlushProcessingBuffers(pPort);
+ }
+ if (err != OMX_ErrorNone) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ err, /* The commands was a OMX_CommandStateSet */
+ 0, /* The state has been changed in message->messageParam */
+ NULL);
+ } else {
+ if(message->messageParam == OMX_ALL){ /*Flush all port*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandFlush, /* The commands was a OMX_CommandStateSet */
+ i, /* The state has been changed in message->messageParam */
+ NULL);
+
+ pPort=omx_base_component_Private->ports[i];
+ /* Signal the buffer Semaphore and the buffer managment semaphore, to restart the exchange of buffers after flush */
+ if (PORT_IS_TUNNELED(pPort) && PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ for(k=0;k<pPort->nNumTunnelBuffer;k++) {
+ omx_tsem_up(pPort->pBufferSem);
+ /*signal buffer management thread availability of buffers*/
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+ }
+ } else {/*Flush input/output port*/
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandFlush, /* The commands was a OMX_CommandStateSet */
+ message->messageParam, /* The state has been changed in message->messageParam */
+ NULL);
+ /* Signal the buffer Semaphore and the buffer managment semaphore, to restart the exchange of buffers after flush */
+ if (PORT_IS_TUNNELED(omx_base_component_Private->ports[message->messageParam])
+ && PORT_IS_BUFFER_SUPPLIER(omx_base_component_Private->ports[message->messageParam])) {
+ for(j=0;j<omx_base_component_Private->ports[message->messageParam]->nNumTunnelBuffer;j++) {
+ omx_tsem_up(omx_base_component_Private->ports[message->messageParam]->pBufferSem);
+ /*signal buffer management thread availability of buffers*/
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+ }
+ }
+ break;
+ case OMX_CommandPortDisable: {
+ /*Flush port/s*/
+ if(message->messageParam == OMX_ALL) {
+ /*If Component is not in loaded state,then First Flush all buffers then disable the port*/
+ if(omx_base_component_Private->state!=OMX_StateLoaded) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort=omx_base_component_Private->ports[i];
+ err = pPort->FlushProcessingBuffers(pPort);
+ }
+ }
+ }
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort=omx_base_component_Private->ports[i];
+ err = pPort->Port_DisablePort(pPort);
+ }
+ }
+ }
+ else {
+ pPort=omx_base_component_Private->ports[message->messageParam];
+ if(omx_base_component_Private->state!=OMX_StateLoaded) {
+ err = pPort->FlushProcessingBuffers(pPort);
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Port Flush completed for Comp %s\n",__func__,omx_base_component_Private->name);
+ }
+ err = pPort->Port_DisablePort(pPort);
+ }
+ /** This condition is added to pass the tests, it is not significant for the environment */
+ if (err != OMX_ErrorNone) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ err, /* The commands was a OMX_CommandStateSet */
+ 0, /* The state has been changed in message->messageParam */
+ NULL);
+ } else {
+ if(message->messageParam == OMX_ALL){ /*Disable all ports*/
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandPortDisable, /* The commands was a OMX_CommandStateSet */
+ i, /* The state has been changed in message->messageParam */
+ NULL);
+ }
+ }
+ } else {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandPortDisable, /* The commands was a OMX_CommandStateSet */
+ message->messageParam, /* The state has been changed in message->messageParam */
+ NULL);
+ }
+ }
+ }
+ break;
+ case OMX_CommandPortEnable:{
+ /*Flush port/s*/
+ if(message->messageParam == OMX_ALL) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort=omx_base_component_Private->ports[i];
+ err = pPort->Port_EnablePort(pPort);
+ }
+ }
+ } else {
+ pPort=omx_base_component_Private->ports[message->messageParam];
+ err = pPort->Port_EnablePort(pPort);
+ }
+ if (err != OMX_ErrorNone) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ err, /* The commands was a OMX_CommandStateSet */
+ 0, /* The state has been changed in message->messageParam */
+ NULL);
+ } else {
+ if(message->messageParam != OMX_ALL) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandPortEnable, /* The commands was a OMX_CommandStateSet */
+ message->messageParam, /* The state has been changed in message->messageParam */
+ NULL);
+
+ if (omx_base_component_Private->state==OMX_StateExecuting) {
+ pPort=omx_base_component_Private->ports[message->messageParam];
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ for(i=0; i < pPort->sPortParam.nBufferCountActual;i++) {
+ omx_tsem_up(pPort->pBufferSem);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+
+ } else {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventCmdComplete, /* The command was completed */
+ OMX_CommandPortEnable, /* The commands was a OMX_CommandStateSet */
+ i, /* The state has been changed in message->messageParam */
+ NULL);
+ }
+ }
+
+ if (omx_base_component_Private->state==OMX_StateExecuting) {
+ /* for all ports */
+ for(j = 0; j < NUM_DOMAINS; j++) {
+ for(i = omx_base_component_Private->sPortTypesParam[j].nStartPortNumber;
+ i < omx_base_component_Private->sPortTypesParam[j].nStartPortNumber +
+ omx_base_component_Private->sPortTypesParam[j].nPorts; i++) {
+ pPort=omx_base_component_Private->ports[i];
+ if (PORT_IS_BUFFER_SUPPLIER(pPort)) {
+ for(k=0; k < pPort->sPortParam.nBufferCountActual;k++) {
+ omx_tsem_up(pPort->pBufferSem);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ break;
+ case OMX_CommandMarkBuffer: {
+ omx_base_component_Private->pMark.hMarkTargetComponent = ((OMX_MARKTYPE *)message->pCmdData)->hMarkTargetComponent;
+ omx_base_component_Private->pMark.pMarkData = ((OMX_MARKTYPE *)message->pCmdData)->pMarkData;
+ }
+ break;
+ default:
+ DEBUG(DEB_LEV_ERR, "In %s: Unrecognized command %i\n", __func__, message->messageType);
+ break;
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Returning from %s: \n", __func__);
+ return OMX_ErrorNone;
+}
+
+OMX_ERRORTYPE omx_base_component_AllocateBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pAppPrivate,
+ OMX_IN OMX_U32 nSizeBytes) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+
+ if (nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ pPort = omx_base_component_Private->ports[nPortIndex];
+
+ return pPort->Port_AllocateBuffer(pPort,
+ ppBuffer,
+ nPortIndex,
+ pAppPrivate,
+ nSizeBytes);
+}
+
+OMX_ERRORTYPE omx_base_component_UseBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pAppPrivate,
+ OMX_IN OMX_U32 nSizeBytes,
+ OMX_IN OMX_U8* pBuffer) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+
+ if (nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ pPort = omx_base_component_Private->ports[nPortIndex];
+
+ return pPort->Port_UseBuffer(pPort,
+ ppBufferHdr,
+ nPortIndex,
+ pAppPrivate,
+ nSizeBytes,
+ pBuffer);
+}
+
+OMX_ERRORTYPE omx_base_component_UseEGLImage (
+ OMX_HANDLETYPE hComponent,
+ OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_U32 nPortIndex,
+ OMX_PTR pAppPrivate,
+ void* eglImage) {
+ return OMX_ErrorNotImplemented;
+}
+
+OMX_ERRORTYPE omx_base_component_FreeBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+
+ if (nPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ pPort = omx_base_component_Private->ports[nPortIndex];
+
+ return pPort->Port_FreeBuffer(pPort,
+ nPortIndex,
+ pBuffer);
+}
+
+OMX_ERRORTYPE omx_base_component_EmptyThisBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) {
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+ //DEBUG(DEB_LEV_FUNCTION_NAME, "In %s pBuffer=0x%x pBuffer->pBuffer=0x%x nInputPortIndex=%d nOutputPortIndex=%d nAllocLen=%d nFilledLen=%d\n",
+ // __func__, pBuffer, pBuffer->pBuffer, pBuffer->nInputPortIndex, pBuffer->nOutputPortIndex, pBuffer->nAllocLen, pBuffer->nFilledLen);
+
+ if (pBuffer->nInputPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ pPort = omx_base_component_Private->ports[pBuffer->nInputPortIndex];
+ if (pPort->sPortParam.eDir != OMX_DirInput) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port direction in Component %s\n", __func__,omx_base_component_Private->name);
+ return OMX_ErrorBadPortIndex;
+ }
+ return pPort->Port_SendBufferFunction(pPort, pBuffer);
+}
+
+OMX_ERRORTYPE omx_base_component_FillThisBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer) {
+
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ if (pBuffer->nOutputPortIndex >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ pPort = omx_base_component_Private->ports[pBuffer->nOutputPortIndex];
+ if (pPort->sPortParam.eDir != OMX_DirOutput) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port direction in Component %s\n", __func__,omx_base_component_Private->name);
+ return OMX_ErrorBadPortIndex;
+ }
+ return pPort->Port_SendBufferFunction(pPort, pBuffer);
+}
+
+OMX_ERRORTYPE omx_base_component_ComponentTunnelRequest(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_U32 nPort,
+ OMX_IN OMX_HANDLETYPE hTunneledComp,
+ OMX_IN OMX_U32 nTunneledPort,
+ OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) {
+
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+ omx_base_PortType *pPort;
+
+ if (nPort >= (omx_base_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainImage].nPorts +
+ omx_base_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ pPort = omx_base_component_Private->ports[nPort];
+
+ return pPort->ComponentTunnelRequest(pPort, hTunneledComp, nTunneledPort, pTunnelSetup);
+}
diff --git a/alsa/omx_base_component.h b/alsa/omx_base_component.h
new file mode 100644
index 0000000..9134119
--- /dev/null
+++ b/alsa/omx_base_component.h
@@ -0,0 +1,412 @@
+/**
+ @file src/base/omx_base_component.h
+
+ OpenMAX base component. This component does not perform any multimedia
+ processing.It is used as a base component for new components development.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-09-11 11:45:59 +0200 (Thu, 11 Sep 2008) $
+ Revision $Rev: 613 $
+ Author $Author: pankaj_sen $
+
+*/
+#ifndef _OMX_BASE_COMPONENT_H_
+#define _OMX_BASE_COMPONENT_H_
+
+#include <pthread.h>
+
+#include "omx_semaphore.h"
+#include "omx_queue.h"
+#include "omx_classmagic.h"
+#include "omx_base_port.h"
+
+/** Default size of the internal input buffer */
+#define DEFAULT_IN_BUFFER_SIZE 4 * 1024
+/** Default size of the internal output buffer */
+#define DEFAULT_OUT_BUFFER_SIZE 16 * 1024 /*32 * 1024*/ /*16 * 1024 */ // TODO - check this size is ok
+/** Default MIME string length */
+#define DEFAULT_MIME_STRING_LENGTH 128
+
+#define NUM_DOMAINS 4
+
+/* Check if Component is deinitalizing*/
+#define IS_COMPONENT_DEINIT(component_Private, exit_condition) \
+ pthread_mutex_lock(&component_Private->exit_mutex) ,\
+ exit_condition = component_Private->bIsComponentDeinit ,\
+ pthread_mutex_unlock(&component_Private->exit_mutex) ,\
+ (exit_condition == OMX_TRUE) ? OMX_TRUE:OMX_FALSE \
+
+typedef struct OMX_VENDOR_EXTRADATATYPE {
+ OMX_U32 nPortIndex;
+ OMX_U32 nDataSize; // Size of the supporting data to follow
+ OMX_U8 *pData; // Supporting data hint
+} OMX_VENDOR_EXTRADATATYPE;
+
+typedef struct OMX_VENDOR_PROP_TUNNELSETUPTYPE {
+ OMX_U32 nPortIndex;
+ OMX_TUNNELSETUPTYPE nTunnelSetup; // Tunnel setup flags
+} OMX_VENDOR_PROP_TUNNELSETUPTYPE;
+
+/** this is the list of custom vendor index */
+typedef enum OMX_INDEXVENDORTYPE {
+ /** only one index for file reader component input file */
+ OMX_IndexVendorFileReadInputFilename = 0xFF000001,
+ OMX_IndexVendorParser3gpInputFilename = 0xFF000002,
+ OMX_IndexVendorVideoExtraData = 0xFF000003,
+ OMX_IndexVendorAudioExtraData = 0xFF000004,
+ OMX_IndexVendorCompPropTunnelFlags = 0xFF000005 /* Will use OMX_TUNNELSETUPTYPE structure*/
+} OMX_INDEXVENDORTYPE;
+
+/** This enum defines the transition states of the Component*/
+typedef enum OMX_TRANS_STATETYPE {
+ OMX_TransStateInvalid,
+ OMX_TransStateLoadedToIdle,
+ OMX_TransStateIdleToPause,
+ OMX_TransStatePauseToExecuting,
+ OMX_TransStateIdleToExecuting,
+ OMX_TransStateExecutingToIdle,
+ OMX_TransStateExecutingToPause,
+ OMX_TransStatePauseToIdle,
+ OMX_TransStateIdleToLoaded,
+ OMX_TransStateMax = 0X7FFFFFFF
+} OMX_TRANS_STATETYPE;
+
+/** @brief Enumerates all the possible types of messages
+ * handled internally by the component
+ */
+typedef enum INTERNAL_MESSAGE_TYPE {
+ SENDCOMMAND_MSG_TYPE = 1,/**< this flag specifies that the message send is a command */
+ ERROR_MSG_TYPE,/**< this flag specifies that the message send is an error message */
+ WARNING_MSG_TYPE /**< this flag specifies that the message send is a warning message */
+} INTERNAL_MESSAGE_TYPE;
+
+/** @brief The container of an internal message
+ *
+ * This structure contains a generic OpenMAX request (from send command).
+ * It is processed by the internal message handler thread
+ */
+typedef struct internalRequestMessageType {
+ int messageType; /**< the flag that specifies if the message is a command, a warning or an error */
+ int messageParam; /**< the second field of the message. Its use is the same as specified for the command in OpenMAX spec */
+ OMX_PTR pCmdData; /**< This pointer could contain some proprietary data not covered by the standard */
+} internalRequestMessageType;
+
+/**
+ * @brief the base descriptor for a ST component
+ */
+CLASS(omx_base_component_PrivateType)
+#define omx_base_component_PrivateType_FIELDS \
+ OMX_COMPONENTTYPE *openmaxStandComp; /**< The OpenMAX standard data structure describing a component */ \
+ omx_base_PortType **ports; /** @param ports The ports of the component */ \
+ OMX_PORT_PARAM_TYPE sPortTypesParam[NUM_DOMAINS]; /** @param sPortTypesParam OpenMAX standard parameter that contains a short description of the available ports */ \
+ char uniqueID; /**< ID code that identifies an ST static component*/ \
+ char* name; /**< component name */\
+ OMX_STATETYPE state; /**< The state of the component */ \
+ OMX_TRANS_STATETYPE transientState; /**< The transient state in case of transition between \
+ Loaded/waitForResources - Idle. It is equal to \
+ Invalid if the state or transition are not corect \
+ Loaded when the transition is from Idle to Loaded \
+ Idle when the transition is from Loaded to Idle */ \
+ OMX_CALLBACKTYPE* callbacks; /**< pointer to every client callback function, \
+ as specified by the standard*/ \
+ OMX_PTR callbackData;/**< Private data that can be send with \
+ the client callbacks. Not specified by the standard */ \
+ omx_queue_t* messageQueue;/**< the queue of all the messages recevied by the component */\
+ omx_tsem_t* messageSem;/**< the semaphore that coordinates the access to the message queue */\
+ OMX_U32 nGroupPriority; /**< @param nGroupPriority Resource management field: component priority (common to a group of components) */\
+ OMX_U32 nGroupID; /**< @param nGroupID ID of a group of components that share the same logical chain */\
+ OMX_MARKTYPE pMark; /**< @param pMark This field holds the private data associated with a mark request, if any */\
+ pthread_mutex_t flush_mutex; /** @param flush_mutex mutex for the flush condition from buffers */ \
+ omx_tsem_t* flush_all_condition; /** @param flush_all_condition condition for the flush all buffers */ \
+ omx_tsem_t* flush_condition; /** @param The flush_condition condition */ \
+ omx_tsem_t* bMgmtSem;/**< @param bMgmtSem the semaphore that control BufferMgmtFunction processing */\
+ omx_tsem_t* bStateSem;/**< @param bMgmtSem the semaphore that control BufferMgmtFunction processing */\
+ int messageHandlerThreadID; /** @param messageHandlerThreadID The ID of the pthread that handles the messages for the components */ \
+ pthread_t messageHandlerThread; /** @param messageHandlerThread This field contains the reference to the thread that receives messages for the components */ \
+ int bufferMgmtThreadID; /** @param bufferMgmtThreadID The ID of the pthread that process buffers */ \
+ pthread_t bufferMgmtThread; /** @param bufferMgmtThread This field contains the reference to the thread that process buffers */ \
+ void *loader; /**< pointer to the loader that created this component, used for destruction */ \
+ void* (*BufferMgmtFunction)(void* param); /** @param BufferMgmtFunction This function processes input output buffers */ \
+ OMX_ERRORTYPE (*messageHandler)(OMX_COMPONENTTYPE*,internalRequestMessageType*);/** This function receives messages from the message queue. It is needed for each Linux ST OpenMAX component */ \
+ OMX_ERRORTYPE (*DoStateSet)(OMX_COMPONENTTYPE *openmaxStandComp, OMX_U32); /**< @param DoStateSet internal function called when a generic state transition is requested*/ \
+ OMX_ERRORTYPE (*destructor)(OMX_COMPONENTTYPE *openmaxStandComp); /** Component Destructor*/
+ENDCLASS(omx_base_component_PrivateType)
+
+/**
+ * @brief The base contructor for the OpenMAX ST components
+ *
+ * This function is executed by the ST static component loader.
+ * It takes care of constructing the instance of the component.
+ * For the base_component component, the following is done:
+ *
+ * 1) Fills the basic OpenMAX structure. The fields can be overwritten
+ * by derived components.
+ * 2) Allocates (if needed) the omx_base_component_PrivateType private structure
+ *
+ * @param openmaxStandComp the ST component to be initialized
+ * @param cComponentName the OpenMAX string that describes the component
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+OMX_ERRORTYPE omx_base_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName);
+
+/** @brief the base destructor for ST OpenMAX components
+ *
+ * This function is called by the standard function ComponentDeInit()
+ * that is called by the IL core during the execution of the FreeHandle()
+ *
+ * @param openmaxStandComp the ST OpenMAX component to be disposed
+ */
+OMX_ERRORTYPE omx_base_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp);
+
+/** Changes the state of a component taking proper actions depending on
+ * the transiotion requested. This base function cover only the state
+ * changes that do not involve any port
+ *
+ * @param openmaxStandComp the OpenMAX component which state is to be changed
+ * @param destinationState the requested target state
+ *
+ * @return OMX_ErrorNotImplemented if the state change is noty handled
+ * in this base class, but needs a specific handling
+ */
+OMX_ERRORTYPE omx_base_component_DoStateSet(
+ OMX_COMPONENTTYPE *openmaxStandComp,
+ OMX_U32 destinationState);
+
+/** @brief Checks the header of a structure for consistency
+ * with size and spec version
+ *
+ * @param header Pointer to the structure to be checked
+ * @param size Size of the structure. it is in general obtained
+ * with a sizeof call applied to the structure
+ *
+ * @return OMX error code. If the header has failed the check,
+ * OMX_ErrorVersionMismatch is returned.
+ * If the header fails the size check OMX_ErrorBadParameter is returned
+ */
+OMX_ERRORTYPE checkHeader(OMX_PTR header, OMX_U32 size);
+
+/** @brief Simply fills the first two fields in any OMX structure
+ * with the size and the version
+ *
+ * @param header pointer to the structure to be filled
+ * @param size size of the structure. It can be obtained with
+ * a call to sizeof of the structure type
+ */
+void setHeader(OMX_PTR header, OMX_U32 size);
+
+/** @brief standard openmax function
+ *
+ * it returns the version of the component. See OMX_Core.h
+ */
+OMX_ERRORTYPE omx_base_component_GetComponentVersion(OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_STRING pComponentName,
+ OMX_OUT OMX_VERSIONTYPE* pComponentVersion,
+ OMX_OUT OMX_VERSIONTYPE* pSpecVersion,
+ OMX_OUT OMX_UUIDTYPE* pComponentUUID);
+
+/** @brief Enumerates all the role of the component.
+ *
+ * This function is intended to be used only by a core. The ST static core
+ * in any case does not use this function, because it can not be used before the
+ * creation of the component, but uses a static list.
+ * It is implemented only for API completion, and it will be not overriden
+ * by a derived component.
+ *
+ * @param hComponent handle of the component
+ * @param cRole the output string containing the n-role of the component
+ * @param nIndex the index of the role requested
+ */
+OMX_ERRORTYPE omx_base_component_ComponentRoleEnum(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_U8 *cRole,
+ OMX_IN OMX_U32 nIndex);
+
+/** @brief standard OpenMAX function
+ *
+ * it sets the callback functions given by the IL client.
+ * See OMX_Component.h
+ */
+OMX_ERRORTYPE omx_base_component_SetCallbacks(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_CALLBACKTYPE* pCallbacks,
+ OMX_IN OMX_PTR pAppData);
+
+/** @brief Part of the standard OpenMAX function
+ *
+ * This function return the parameters not related to any port.
+ * These parameters are handled in the derived components
+ * See OMX_Core.h for standard reference.
+ */
+OMX_ERRORTYPE omx_base_component_GetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_INOUT OMX_PTR ComponentParameterStructure);
+
+/** @brief part of the standard openmax function
+ *
+ * This function return the parameters not related to any port,
+ * These parameters are handled in the derived components
+ * See OMX_Core.h for standard reference.
+ *
+ * @return OMX_ErrorUnsupportedIndex if the index is not supported or not handled here
+ */
+OMX_ERRORTYPE omx_base_component_SetParameter(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nParamIndex,
+ OMX_IN OMX_PTR ComponentParameterStructure);
+
+/** @brief base GetConfig function
+ *
+ * This base function is not implemented. If a derived component
+ * needs to support any config, it must implement a derived
+ * version of this function and assign it to the correct pointer
+ * in the private component descriptor.
+ */
+OMX_ERRORTYPE omx_base_component_GetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_INOUT OMX_PTR pComponentConfigStructure);
+
+/** @brief base SetConfig function
+ *
+ * This base function is not implemented. If a derived component
+ * needs to support any config, it must implement a derived
+ * version of this function and assign it to the correct pointer
+ * in the private component descriptor.
+ */
+OMX_ERRORTYPE omx_base_component_SetConfig(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_INDEXTYPE nIndex,
+ OMX_IN OMX_PTR pComponentConfigStructure);
+
+/** @brief base function not implemented
+ *
+ * This function can be eventually implemented by a
+ * derived component if needed.
+ */
+OMX_ERRORTYPE omx_base_component_GetExtensionIndex(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_STRING cParameterName,
+ OMX_OUT OMX_INDEXTYPE* pIndexType);
+
+/** @returns the state of the component
+ *
+ * This function does not need any override by derived components.
+ */
+OMX_ERRORTYPE omx_base_component_GetState(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_OUT OMX_STATETYPE* pState);
+
+/** @brief standard SendCommand function
+ *
+ * In general this function does not need a overwrite, but
+ * a special derived component could do it.
+ */
+OMX_ERRORTYPE omx_base_component_SendCommand(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_COMMANDTYPE Cmd,
+ OMX_IN OMX_U32 nParam,
+ OMX_IN OMX_PTR pCmdData);
+
+/** @brief This standard functionality is called when the component is
+ * destroyed in the FreeHandle standard call.
+ *
+ * In this way the implementation of the FreeHandle is standard,
+ * and it does not need a support by a specific component loader.
+ * The implementaiton of the ComponentDeInit contains the
+ * implementation specific part of the destroying phase.
+ */
+OMX_ERRORTYPE omx_base_component_ComponentDeInit(
+ OMX_IN OMX_HANDLETYPE hComponent);
+
+/** @brief Component's message handler thread function
+ *
+ * Handles all messages coming from components and
+ * processes them by dispatching them back to the
+ * triggering component.
+ */
+void* compMessageHandlerFunction(void*);
+
+/** This is called by the component message entry point.
+ * In thea base version this function is named compMessageHandlerFunction
+ *
+ * A request is made by the component when some asynchronous services are needed:
+ * 1) A SendCommand() is to be processed
+ * 2) An error needs to be notified
+ * 3) ...
+ *
+ * @param openmaxStandComp the component itself
+ * @param message the message that has been passed to core
+ */
+OMX_ERRORTYPE omx_base_component_MessageHandler(OMX_COMPONENTTYPE *openmaxStandComp,internalRequestMessageType* message);
+
+/**
+ * This function verify Component State and Structure header
+ */
+OMX_ERRORTYPE omx_base_component_ParameterSanityCheck(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pStructure,
+ OMX_IN size_t size);
+
+OMX_ERRORTYPE omx_base_component_AllocateBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_INOUT OMX_BUFFERHEADERTYPE** ppBuffer,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pAppPrivate,
+ OMX_IN OMX_U32 nSizeBytes);
+
+OMX_ERRORTYPE omx_base_component_UseBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pAppPrivate,
+ OMX_IN OMX_U32 nSizeBytes,
+ OMX_IN OMX_U8* pBuffer);
+
+OMX_ERRORTYPE omx_base_component_UseEGLImage (
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_PTR pAppPrivate,
+ OMX_IN void* eglImage);
+
+OMX_ERRORTYPE omx_base_component_FreeBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
+
+OMX_ERRORTYPE omx_base_component_EmptyThisBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
+
+OMX_ERRORTYPE omx_base_component_FillThisBuffer(
+ OMX_IN OMX_HANDLETYPE hComponent,
+ OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
+
+OMX_ERRORTYPE omx_base_component_ComponentTunnelRequest(
+ OMX_IN OMX_HANDLETYPE hComp,
+ OMX_IN OMX_U32 nPort,
+ OMX_IN OMX_HANDLETYPE hTunneledComp,
+ OMX_IN OMX_U32 nTunneledPort,
+ OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup);
+
+#endif
diff --git a/alsa/omx_base_port.cpp b/alsa/omx_base_port.cpp
new file mode 100644
index 0000000..67d003a
--- /dev/null
+++ b/alsa/omx_base_port.cpp
@@ -0,0 +1,1163 @@
+/**
+ @file src/base/omx_base_port.c
+
+ Base class for OpenMAX ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-09-11 15:28:59 +0200 (Thu, 11 Sep 2008) $
+ Revision $Rev: 614 $
+ Author $Author: gsent $
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+//#include <IL/OMX_Core.h>
+//#include <IL/OMX_Component.h>
+
+#include "omx_base_component.h"
+#include "omx_base_port.h"
+
+/** The default value for the number of needed buffers for each port. */
+#define DEFAULT_NUMBER_BUFFERS_PER_PORT 4
+/** The default value for the minimum number of needed buffers for each port. */
+#define DEFAULT_MIN_NUMBER_BUFFERS_PER_PORT 4
+/**
+ * @brief The base contructor for the generic OpenMAX ST port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandComp in the component that holds the port
+ * @param openmaxStandPort the ST port to be initialized
+ * @param nPortIndex the index of the port
+ * @param isInput specifices if the port is an input or an output
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+
+OMX_ERRORTYPE base_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput) {
+
+ /* omx_base_component_PrivateType* omx_base_component_Private; */
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ /* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate; */
+
+ // create ports, but only if the subclass hasn't done it
+ if (!(*openmaxStandPort)) {
+ *openmaxStandPort = (omx_base_PortType*)calloc(1,sizeof (omx_base_PortType));
+ }
+
+ if (!(*openmaxStandPort)) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ (*openmaxStandPort)->hTunneledComponent = NULL;
+ (*openmaxStandPort)->nTunnelFlags=0;
+ (*openmaxStandPort)->nTunneledPort=0;
+ (*openmaxStandPort)->eBufferSupplier=OMX_BufferSupplyUnspecified;
+ (*openmaxStandPort)->nNumTunnelBuffer=0;
+ (*openmaxStandPort)->bTunnelTearDown = OMX_FALSE;
+
+ if((*openmaxStandPort)->pAllocSem==NULL) {
+ (*openmaxStandPort)->pAllocSem = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ if((*openmaxStandPort)->pAllocSem==NULL) {
+ return OMX_ErrorInsufficientResources;
+ }
+ omx_tsem_init((*openmaxStandPort)->pAllocSem, 0);
+ }
+ (*openmaxStandPort)->nNumBufferFlushed=0;
+ (*openmaxStandPort)->bIsPortFlushed=OMX_FALSE;
+ /** Allocate and initialize buffer queue */
+ if(!(*openmaxStandPort)->pBufferQueue) {
+ (*openmaxStandPort)->pBufferQueue = (omx_queue_t*)calloc(1,sizeof(omx_queue_t));
+ if((*openmaxStandPort)->pBufferQueue==NULL) return OMX_ErrorInsufficientResources;
+ omx_queue_init((*openmaxStandPort)->pBufferQueue);
+ }
+ /*Allocate and initialise port semaphores*/
+ if(!(*openmaxStandPort)->pBufferSem) {
+ (*openmaxStandPort)->pBufferSem = (omx_tsem_t*)calloc(1,sizeof(omx_tsem_t));
+ if((*openmaxStandPort)->pBufferSem==NULL) return OMX_ErrorInsufficientResources;
+ omx_tsem_init((*openmaxStandPort)->pBufferSem, 0);
+ }
+
+ (*openmaxStandPort)->nNumAssignedBuffers=0;
+ setHeader(&(*openmaxStandPort)->sPortParam, sizeof (OMX_PARAM_PORTDEFINITIONTYPE));
+ (*openmaxStandPort)->sPortParam.nPortIndex = nPortIndex;
+ (*openmaxStandPort)->sPortParam.nBufferCountActual = DEFAULT_NUMBER_BUFFERS_PER_PORT;
+ (*openmaxStandPort)->sPortParam.nBufferCountMin = DEFAULT_MIN_NUMBER_BUFFERS_PER_PORT;
+ (*openmaxStandPort)->sPortParam.bEnabled = OMX_TRUE;
+ (*openmaxStandPort)->sPortParam.bPopulated = OMX_FALSE;
+ (*openmaxStandPort)->sPortParam.eDir = (isInput == OMX_TRUE)?OMX_DirInput:OMX_DirOutput;
+
+ (*openmaxStandPort)->standCompContainer=openmaxStandComp;
+ (*openmaxStandPort)->bIsTransientToEnabled=OMX_FALSE;
+ (*openmaxStandPort)->bIsTransientToDisabled=OMX_FALSE;
+ (*openmaxStandPort)->bIsFullOfBuffers=OMX_FALSE;
+ (*openmaxStandPort)->bIsEmptyOfBuffers=OMX_FALSE;
+ (*openmaxStandPort)->bBufferStateAllocated = NULL;
+ (*openmaxStandPort)->pInternalBufferStorage = NULL;
+
+ (*openmaxStandPort)->PortDestructor = &base_port_Destructor;
+ (*openmaxStandPort)->Port_AllocateBuffer = &base_port_AllocateBuffer;
+ (*openmaxStandPort)->Port_UseBuffer = &base_port_UseBuffer;
+ (*openmaxStandPort)->Port_FreeBuffer = &base_port_FreeBuffer;
+ (*openmaxStandPort)->Port_DisablePort = &base_port_DisablePort;
+ (*openmaxStandPort)->Port_EnablePort = &base_port_EnablePort;
+ (*openmaxStandPort)->Port_SendBufferFunction = &base_port_SendBufferFunction;
+ (*openmaxStandPort)->FlushProcessingBuffers = &base_port_FlushProcessingBuffers;
+ (*openmaxStandPort)->ReturnBufferFunction = &base_port_ReturnBufferFunction;
+ (*openmaxStandPort)->ComponentTunnelRequest = &base_port_ComponentTunnelRequest;
+ (*openmaxStandPort)->Port_AllocateTunnelBuffer = &base_port_AllocateTunnelBuffer;
+ (*openmaxStandPort)->Port_FreeTunnelBuffer = &base_port_FreeTunnelBuffer;
+
+ return OMX_ErrorNone;
+}
+
+OMX_ERRORTYPE base_port_Destructor(omx_base_PortType *openmaxStandPort){
+
+ if(openmaxStandPort->pAllocSem) {
+ omx_tsem_deinit(openmaxStandPort->pAllocSem);
+ free(openmaxStandPort->pAllocSem);
+ openmaxStandPort->pAllocSem=NULL;
+ }
+ /** Allocate and initialize buffer queue */
+ if(openmaxStandPort->pBufferQueue) {
+ omx_queue_deinit(openmaxStandPort->pBufferQueue);
+ free(openmaxStandPort->pBufferQueue);
+ openmaxStandPort->pBufferQueue=NULL;
+ }
+ /*Allocate and initialise port semaphores*/
+ if(openmaxStandPort->pBufferSem) {
+ omx_tsem_deinit(openmaxStandPort->pBufferSem);
+ free(openmaxStandPort->pBufferSem);
+ openmaxStandPort->pBufferSem=NULL;
+ }
+
+ free(openmaxStandPort);
+ openmaxStandPort = NULL;
+ return OMX_ErrorNone;
+}
+
+/** @brief Releases buffers under processing.
+ * This function must be implemented in the derived classes, for the
+ * specific processing
+ */
+OMX_ERRORTYPE base_port_FlushProcessingBuffers(omx_base_PortType *openmaxStandPort) {
+ omx_base_component_PrivateType* omx_base_component_Private;
+ OMX_BUFFERHEADERTYPE* pBuffer;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandPort->standCompContainer->pComponentPrivate;
+
+ if(openmaxStandPort->sPortParam.eDomain!=OMX_PortDomainOther) { /* clock buffers not used in the clients buffer managment function */
+ pthread_mutex_lock(&omx_base_component_Private->flush_mutex);
+ openmaxStandPort->bIsPortFlushed=OMX_TRUE;
+ /*Signal the buffer management thread of port flush,if it is waiting for buffers*/
+ if(omx_base_component_Private->bMgmtSem->semval==0) {
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+
+ if(omx_base_component_Private->state==OMX_StatePause ) {
+ /*Waiting at paused state*/
+ omx_tsem_signal(omx_base_component_Private->bStateSem);
+ }
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s waiting for flush all condition port index =%d\n", __func__,(int)openmaxStandPort->sPortParam.nPortIndex);
+ /* Wait until flush is completed */
+ pthread_mutex_unlock(&omx_base_component_Private->flush_mutex);
+ omx_tsem_down(omx_base_component_Private->flush_all_condition);
+ }
+
+ omx_tsem_reset(omx_base_component_Private->bMgmtSem);
+
+ /* Flush all the buffers not under processing */
+ while (openmaxStandPort->pBufferSem->semval > 0) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s TFlag=%x Flusing Port=%d,Semval=%d Qelem=%d\n",
+ __func__,(int)openmaxStandPort->nTunnelFlags,(int)openmaxStandPort->sPortParam.nPortIndex,
+ (int)openmaxStandPort->pBufferSem->semval,(int)openmaxStandPort->pBufferQueue->nelem);
+
+ omx_tsem_down(openmaxStandPort->pBufferSem);
+ pBuffer = (OMX_BUFFERHEADERTYPE*)omx_dequeue(openmaxStandPort->pBufferQueue);
+ if (PORT_IS_TUNNELED(openmaxStandPort) && !PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s is returning io:%d buffer\n",
+ __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->FillThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ } else {
+ ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->EmptyThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ }
+ } else if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ omx_queue(openmaxStandPort->pBufferQueue,pBuffer);
+ } else {
+ (*(openmaxStandPort->BufferProcessedCallback))(
+ openmaxStandPort->standCompContainer,
+ omx_base_component_Private->callbackData,
+ pBuffer);
+ }
+ }
+ /*Port is tunneled and supplier and didn't received all it's buffer then wait for the buffers*/
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ while(openmaxStandPort->pBufferQueue->nelem!= openmaxStandPort->nNumAssignedBuffers){
+ omx_tsem_down(openmaxStandPort->pBufferSem);
+ DEBUG(DEB_LEV_PARAMS, "In %s Got a buffer qelem=%d\n",__func__,openmaxStandPort->pBufferQueue->nelem);
+ }
+ omx_tsem_reset(openmaxStandPort->pBufferSem);
+ }
+
+ pthread_mutex_lock(&omx_base_component_Private->flush_mutex);
+ openmaxStandPort->bIsPortFlushed=OMX_FALSE;
+ pthread_mutex_unlock(&omx_base_component_Private->flush_mutex);
+
+ omx_tsem_up(omx_base_component_Private->flush_condition);
+
+ DEBUG(DEB_LEV_FULL_SEQ, "Out %s Port Index=%d bIsPortFlushed=%d Component %s\n", __func__,
+ (int)openmaxStandPort->sPortParam.nPortIndex,(int)openmaxStandPort->bIsPortFlushed,omx_base_component_Private->name);
+
+ DEBUG(DEB_LEV_PARAMS, "In %s TFlag=%x Qelem=%d BSem=%d bMgmtsem=%d component=%s\n", __func__,
+ (int)openmaxStandPort->nTunnelFlags,
+ (int)openmaxStandPort->pBufferQueue->nelem,
+ (int)openmaxStandPort->pBufferSem->semval,
+ (int)omx_base_component_Private->bMgmtSem->semval,
+ omx_base_component_Private->name);
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "Out %s Port Index=%d\n", __func__,(int)openmaxStandPort->sPortParam.nPortIndex);
+
+ return OMX_ErrorNone;
+}
+
+/** @brief Disables the port.
+ *
+ * This function is called due to a request by the IL client
+ *
+ * @param openmaxStandPort the reference to the port
+ *
+ */
+OMX_ERRORTYPE base_port_DisablePort(omx_base_PortType *openmaxStandPort) {
+ omx_base_component_PrivateType* omx_base_component_Private;
+ OMX_ERRORTYPE err=OMX_ErrorNone;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Port Index=%d\n", __func__,(int)openmaxStandPort->sPortParam.nPortIndex);
+ omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandPort->standCompContainer->pComponentPrivate;
+ if (! PORT_IS_ENABLED(openmaxStandPort)) {
+ return OMX_ErrorNone;
+ }
+
+ if(omx_base_component_Private->state!=OMX_StateLoaded) {
+ if(!PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)) {
+ /*Signal Buffer Mgmt Thread if it's holding any buffer*/
+ if(omx_base_component_Private->bMgmtSem->semval==0) {
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ /*Wait till all buffers are freed*/
+ omx_tsem_down(openmaxStandPort->pAllocSem);
+ omx_tsem_reset(omx_base_component_Private->bMgmtSem);
+ } else {
+ /*Since port is being disabled then remove buffers from the queue*/
+ while(openmaxStandPort->pBufferQueue->nelem > 0) {
+ omx_dequeue(openmaxStandPort->pBufferQueue);
+ }
+
+ err = openmaxStandPort->Port_FreeTunnelBuffer(openmaxStandPort,openmaxStandPort->sPortParam.nPortIndex);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Freeing Tunnel Buffer Error=%x\n",__func__,err);
+ }
+ DEBUG(DEB_LEV_PARAMS, "In %s Qelem=%d\n", __func__,openmaxStandPort->pBufferQueue->nelem);
+ }
+
+ if(openmaxStandPort->bTunnelTearDown == OMX_TRUE){
+ DEBUG(DEB_LEV_PARAMS, "In %s TearDown tunnel\n", __func__);
+ openmaxStandPort->hTunneledComponent = 0;
+ openmaxStandPort->nTunneledPort = 0;
+ openmaxStandPort->nTunnelFlags = 0;
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyUnspecified;
+ openmaxStandPort->bTunnelTearDown = OMX_FALSE;
+ }
+ }
+
+ DEBUG(DEB_LEV_PARAMS, "In %s TFlag=%x Qelem=%d BSem=%d bMgmtsem=%d component=%s\n", __func__,
+ (int)openmaxStandPort->nTunnelFlags,
+ (int)openmaxStandPort->pBufferQueue->nelem,
+ (int)openmaxStandPort->pBufferSem->semval,
+ (int)omx_base_component_Private->bMgmtSem->semval,
+ omx_base_component_Private->name);
+ openmaxStandPort->bIsTransientToDisabled = OMX_FALSE;
+ openmaxStandPort->sPortParam.bEnabled = OMX_FALSE;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "Out %s Port Index=%d isEnabled=%d\n", __func__,
+ (int)openmaxStandPort->sPortParam.nPortIndex,
+ (int)openmaxStandPort->sPortParam.bEnabled);
+ return err;
+}
+
+/** @brief Enables the port.
+ *
+ * This function is called due to a request by the IL client
+ *
+ * @param openmaxStandPort the reference to the port
+ *
+ */
+OMX_ERRORTYPE base_port_EnablePort(omx_base_PortType *openmaxStandPort) {
+ omx_base_component_PrivateType* omx_base_component_Private;
+ OMX_ERRORTYPE err=OMX_ErrorNone;
+ OMX_U32 i;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ if (PORT_IS_ENABLED(openmaxStandPort)) {
+ return OMX_ErrorNone;
+ }
+ omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandPort->standCompContainer->pComponentPrivate;
+
+ openmaxStandPort->sPortParam.bEnabled = OMX_TRUE;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s port T flag=%x popu=%d state=%x\n", __func__,
+ (int)openmaxStandPort->nTunnelFlags,
+ (int)openmaxStandPort->sPortParam.bPopulated,
+ (int)omx_base_component_Private->state);
+
+
+ if (!PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)) {
+ /*Wait Till All buffers are allocated if the component state is not Loaded*/
+ if (omx_base_component_Private->state!=OMX_StateLoaded && omx_base_component_Private->state!=OMX_StateWaitForResources) {
+ omx_tsem_down(openmaxStandPort->pAllocSem);
+ openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
+ }
+ } else { //Port Tunneled and supplier. Then allocate tunnel buffers
+ err= openmaxStandPort->Port_AllocateTunnelBuffer(openmaxStandPort, openmaxStandPort->sPortParam.nPortIndex, openmaxStandPort->sPortParam.nBufferSize);
+ if(err!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s Allocating Tunnel Buffer Error=%x\n",__func__,err);
+ return err;
+ }
+ openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
+ if (omx_base_component_Private->state==OMX_StateExecuting) {
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual;i++) {
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }
+ }
+ DEBUG(DEB_LEV_PARAMS, "In %s Qelem=%d BSem=%d\n", __func__,openmaxStandPort->pBufferQueue->nelem,openmaxStandPort->pBufferSem->semval);
+ }
+
+ openmaxStandPort->bIsTransientToEnabled = OMX_FALSE;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s\n", __func__);
+
+ return OMX_ErrorNone;
+}
+
+/** @brief Called by the standard allocate buffer, it implements a base functionality.
+ *
+ * This function can be overriden if the allocation of the buffer is not a simply calloc call.
+ * The parameters are the same as the standard function, except for the handle of the port
+ * instead of the handler of the component
+ * When the buffers needed by this port are all assigned or allocated, the variable
+ * bIsFullOfBuffers becomes equal to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_AllocateBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE** pBuffer,
+ OMX_U32 nPortIndex,
+ OMX_PTR pAppPrivate,
+ OMX_U32 nSizeBytes) {
+
+ unsigned int i;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ return OMX_ErrorBadPortIndex;
+ }
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if ((omx_base_component_Private->transientState != OMX_TransStateLoadedToIdle) || (omx_base_component_Private->state!=OMX_StateLoaded)) {
+ if (!openmaxStandPort->bIsTransientToEnabled) {
+ DEBUG(DEB_LEV_ERR, "In %s: The port is not allowed to receive buffers\n", __func__);
+ return OMX_ErrorIncorrectStateTransition;
+ }
+ }
+
+ if(nSizeBytes < openmaxStandPort->sPortParam.nBufferSize) {
+ DEBUG(DEB_LEV_ERR, "In %s: Requested Buffer Size %lu is less than Minimum Buffer Size %lu\n", __func__, (unsigned long)nSizeBytes, (unsigned long)openmaxStandPort->sPortParam.nBufferSize);
+ return OMX_ErrorIncorrectStateTransition;
+ }
+
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (openmaxStandPort->bBufferStateAllocated[i] == BUFFER_FREE) {
+ openmaxStandPort->pInternalBufferStorage[i] = (OMX_BUFFERHEADERTYPE*)calloc(1,sizeof(OMX_BUFFERHEADERTYPE));
+ if (!openmaxStandPort->pInternalBufferStorage[i]) {
+ return OMX_ErrorInsufficientResources;
+ }
+ setHeader(openmaxStandPort->pInternalBufferStorage[i], sizeof(OMX_BUFFERHEADERTYPE));
+ /* allocate the buffer */
+ openmaxStandPort->pInternalBufferStorage[i]->pBuffer = (OMX_U8*)calloc(1,nSizeBytes);
+ if(openmaxStandPort->pInternalBufferStorage[i]->pBuffer==NULL) {
+ return OMX_ErrorInsufficientResources;
+ }
+ openmaxStandPort->pInternalBufferStorage[i]->nAllocLen = nSizeBytes;
+ openmaxStandPort->pInternalBufferStorage[i]->pPlatformPrivate = openmaxStandPort;
+ openmaxStandPort->pInternalBufferStorage[i]->pAppPrivate = pAppPrivate;
+ *pBuffer = openmaxStandPort->pInternalBufferStorage[i];
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_ALLOCATED;
+ openmaxStandPort->bBufferStateAllocated[i] |= HEADER_ALLOCATED;
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ openmaxStandPort->pInternalBufferStorage[i]->nInputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ } else {
+ openmaxStandPort->pInternalBufferStorage[i]->nOutputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ }
+ openmaxStandPort->nNumAssignedBuffers++;
+ DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
+
+ if (openmaxStandPort->sPortParam.nBufferCountActual == openmaxStandPort->nNumAssignedBuffers) {
+ openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
+ openmaxStandPort->bIsFullOfBuffers = OMX_TRUE;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s nPortIndex=%d\n",__func__,(int)nPortIndex);
+ omx_tsem_up(openmaxStandPort->pAllocSem);
+ }
+ return OMX_ErrorNone;
+ }
+ }
+ DEBUG(DEB_LEV_ERR, "In %s Error: no available buffers\n",__func__);
+ return OMX_ErrorInsufficientResources;
+}
+
+/** @brief Called by the standard use buffer, it implements a base functionality.
+ *
+ * This function can be overriden if the use buffer implicate more complicated operations.
+ * The parameters are the same as the standard function, except for the handle of the port
+ * instead of the handler of the component.
+ * When the buffers needed by this port are all assigned or allocated, the variable
+ * bIsFullOfBuffers becomes equal to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_UseBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_U32 nPortIndex,
+ OMX_PTR pAppPrivate,
+ OMX_U32 nSizeBytes,
+ OMX_U8* pBuffer) {
+
+ unsigned int i;
+ OMX_BUFFERHEADERTYPE* returnBufferHeader;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ return OMX_ErrorBadPortIndex;
+ }
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if (omx_base_component_Private->transientState != OMX_TransStateLoadedToIdle) {
+ if (!openmaxStandPort->bIsTransientToEnabled) {
+ DEBUG(DEB_LEV_ERR, "In %s: The port of Comp %s is not allowed to receive buffers\n", __func__,omx_base_component_Private->name);
+ return OMX_ErrorIncorrectStateTransition;
+ }
+ }
+
+ /// AND
+ /*
+ if(nSizeBytes < openmaxStandPort->sPortParam.nBufferSize) {
+ DEBUG(DEB_LEV_ERR, "In %s: Given Buffer Size %lu is less than Minimum Buffer Size %lu\n", __func__, nSizeBytes, openmaxStandPort->sPortParam.nBufferSize);
+ return OMX_ErrorIncorrectStateTransition;
+ }
+ */
+ /// AND
+
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (openmaxStandPort->bBufferStateAllocated[i] == BUFFER_FREE) {
+ openmaxStandPort->pInternalBufferStorage[i] = (OMX_BUFFERHEADERTYPE*)calloc(1,sizeof(OMX_BUFFERHEADERTYPE));
+ if (!openmaxStandPort->pInternalBufferStorage[i]) {
+ return OMX_ErrorInsufficientResources;
+ }
+ openmaxStandPort->bIsEmptyOfBuffers = OMX_FALSE;
+ setHeader(openmaxStandPort->pInternalBufferStorage[i], sizeof(OMX_BUFFERHEADERTYPE));
+
+ openmaxStandPort->pInternalBufferStorage[i]->pBuffer = pBuffer;
+ openmaxStandPort->pInternalBufferStorage[i]->nAllocLen = nSizeBytes;
+ openmaxStandPort->pInternalBufferStorage[i]->pPlatformPrivate = openmaxStandPort;
+ openmaxStandPort->pInternalBufferStorage[i]->pAppPrivate = pAppPrivate;
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_ASSIGNED;
+ openmaxStandPort->bBufferStateAllocated[i] |= HEADER_ALLOCATED;
+ returnBufferHeader = (OMX_BUFFERHEADERTYPE*)calloc(1,sizeof(OMX_BUFFERHEADERTYPE));
+ if (!returnBufferHeader) {
+ return OMX_ErrorInsufficientResources;
+ }
+ setHeader(returnBufferHeader, sizeof(OMX_BUFFERHEADERTYPE));
+ returnBufferHeader->pBuffer = pBuffer;
+ returnBufferHeader->nAllocLen = nSizeBytes;
+ returnBufferHeader->pPlatformPrivate = openmaxStandPort;
+ returnBufferHeader->pAppPrivate = pAppPrivate;
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ openmaxStandPort->pInternalBufferStorage[i]->nInputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ returnBufferHeader->nInputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ } else {
+ openmaxStandPort->pInternalBufferStorage[i]->nOutputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ returnBufferHeader->nOutputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ }
+ *ppBufferHdr = returnBufferHeader;
+ openmaxStandPort->nNumAssignedBuffers++;
+ DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
+
+ if (openmaxStandPort->sPortParam.nBufferCountActual == openmaxStandPort->nNumAssignedBuffers) {
+ openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
+ openmaxStandPort->bIsFullOfBuffers = OMX_TRUE;
+ omx_tsem_up(openmaxStandPort->pAllocSem);
+ }
+ return OMX_ErrorNone;
+ }
+ }
+ DEBUG(DEB_LEV_ERR, "In %s Error: no available buffers CompName=%s\n",__func__,omx_base_component_Private->name);
+ return OMX_ErrorInsufficientResources;
+}
+
+/** @brief Called by the standard function.
+ *
+ * It frees the buffer header and in case also the buffer itself, if needed.
+ * When all the bufers are done, the variable bIsEmptyOfBuffers is set to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_FreeBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_U32 nPortIndex,
+ OMX_BUFFERHEADERTYPE* pBuffer) {
+
+ unsigned int i;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ return OMX_ErrorBadPortIndex;
+ }
+ if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if (omx_base_component_Private->transientState != OMX_TransStateIdleToLoaded) {
+ if (!openmaxStandPort->bIsTransientToDisabled) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: The port is not allowed to free the buffers\n", __func__);
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (omxComponent,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ OMX_ErrorPortUnpopulated, /* The commands was a OMX_CommandStateSet */
+ nPortIndex, /* The state has been changed in message->messageParam2 */
+ NULL);
+ }
+ }
+
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (openmaxStandPort->bBufferStateAllocated[i] & (BUFFER_ASSIGNED | BUFFER_ALLOCATED)) {
+
+ openmaxStandPort->bIsFullOfBuffers = OMX_FALSE;
+ if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ALLOCATED) {
+ if(openmaxStandPort->pInternalBufferStorage[i]->pBuffer){
+ DEBUG(DEB_LEV_PARAMS, "In %s freeing %i pBuffer=%x\n",__func__, (int)i, (int)openmaxStandPort->pInternalBufferStorage[i]->pBuffer);
+ free(openmaxStandPort->pInternalBufferStorage[i]->pBuffer);
+ openmaxStandPort->pInternalBufferStorage[i]->pBuffer=NULL;
+ }
+ } else if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ASSIGNED) {
+ free(pBuffer);
+ }
+ if(openmaxStandPort->bBufferStateAllocated[i] & HEADER_ALLOCATED) {
+ free(openmaxStandPort->pInternalBufferStorage[i]);
+ openmaxStandPort->pInternalBufferStorage[i]=NULL;
+ }
+
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_FREE;
+
+ openmaxStandPort->nNumAssignedBuffers--;
+ DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
+
+ if (openmaxStandPort->nNumAssignedBuffers == 0) {
+ openmaxStandPort->sPortParam.bPopulated = OMX_FALSE;
+ openmaxStandPort->bIsEmptyOfBuffers = OMX_TRUE;
+ omx_tsem_up(openmaxStandPort->pAllocSem);
+ }
+ return OMX_ErrorNone;
+ }
+ }
+ return OMX_ErrorInsufficientResources;
+}
+
+OMX_ERRORTYPE base_port_AllocateTunnelBuffer(omx_base_PortType *openmaxStandPort,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_U32 nSizeBytes)
+{
+ unsigned int i;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ OMX_U8* pBuffer=NULL;
+ OMX_ERRORTYPE eError=OMX_ErrorNone;
+ OMX_U32 numRetry=0;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, nPortIndex=%d, nSizeBytes=%d, nBufferCountActual=%d\n", __func__, nPortIndex, nSizeBytes, openmaxStandPort->sPortParam.nBufferCountActual);
+
+ if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ DEBUG(DEB_LEV_ERR, "In %s: Bad Port Index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ if (! PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ DEBUG(DEB_LEV_ERR, "In %s: Port is not tunneled Flag=%x\n", __func__, (int)openmaxStandPort->nTunnelFlags);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if (omx_base_component_Private->transientState != OMX_TransStateLoadedToIdle) {
+ if (!openmaxStandPort->bIsTransientToEnabled) {
+ DEBUG(DEB_LEV_ERR, "In %s: The port is not allowed to receive buffers\n", __func__);
+ return OMX_ErrorIncorrectStateTransition;
+ }
+ }
+
+ if( NULL == openmaxStandPort->bBufferStateAllocated )
+ {
+ openmaxStandPort->bBufferStateAllocated = (BUFFER_STATUS_FLAG*)calloc(openmaxStandPort->sPortParam.nBufferCountActual, sizeof(openmaxStandPort->bBufferStateAllocated[0] ));
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++)
+ {
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_FREE;
+ }
+ }
+
+ if( NULL == openmaxStandPort->pInternalBufferStorage )
+ {
+ openmaxStandPort->pInternalBufferStorage = (OMX_BUFFERHEADERTYPE**)calloc(openmaxStandPort->sPortParam.nBufferCountActual, sizeof(OMX_BUFFERHEADERTYPE*));
+ /*for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++)
+ {
+ //memset(&openmaxStandPort->pInternalBufferStorage[i], 0, sizeof(OMX_BUFFERHEADERTYPE*));
+ setHeader(&openmaxStandPort->pInternalBufferStorage[i], sizeof(OMX_BUFFERHEADERTYPE*));
+ }*/
+ }
+
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (openmaxStandPort->bBufferStateAllocated[i] == BUFFER_FREE) {
+ pBuffer = (OMX_U8*)calloc(1,nSizeBytes);
+ if(pBuffer==NULL) {
+ return OMX_ErrorInsufficientResources;
+ }
+ /*Retry more than once, if the tunneled component is not in Loaded->Idle State*/
+ while(numRetry <TUNNEL_USE_BUFFER_RETRY) {
+ eError=OMX_UseBuffer(openmaxStandPort->hTunneledComponent,&openmaxStandPort->pInternalBufferStorage[i],
+ openmaxStandPort->nTunneledPort,NULL,nSizeBytes,pBuffer);
+ if (checkHeader(openmaxStandPort->pInternalBufferStorage[i], sizeof(OMX_BUFFERHEADERTYPE)) != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s: received wrong buffer header after OMX_UseBuffer\n", __func__);
+ return OMX_ErrorBadParameter;
+ }
+ if(eError!=OMX_ErrorNone) {
+ OMX_STATETYPE state;
+ OMX_GetState( openmaxStandPort->hTunneledComponent, &state );
+ DEBUG(DEB_LEV_FULL_SEQ,"Tunneled Component Couldn't Use buffer %i From Comp=%s Retry=%d Other state=%d\n",
+ i,omx_base_component_Private->name,(int)numRetry, (int)state);
+ /// AND
+ // see 2.1.1 and 3.2 in http://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Application_Note_318.pdf
+ //if((eError == OMX_ErrorIncorrectStateTransition) && numRetry<TUNNEL_USE_BUFFER_RETRY) {
+ if(((eError == OMX_ErrorIncorrectStateTransition)||(eError == OMX_ErrorIncorrectStateOperation)) && numRetry<TUNNEL_USE_BUFFER_RETRY) {
+ /// AND
+ DEBUG(DEB_LEV_FULL_SEQ,"Waiting for next try %i \n",(int)numRetry);
+ usleep(TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME);
+ numRetry++;
+ continue;
+ }
+ free(pBuffer);
+ pBuffer = NULL;
+ return eError;
+ }
+ else {
+ DEBUG(DEB_LEV_FULL_SEQ,"Tunneled Component Used buffer %i From Comp=%s Retry=%d\n",
+ i,omx_base_component_Private->name,(int)numRetry);
+ break;
+ }
+ }
+ if(eError!=OMX_ErrorNone) {
+ free(pBuffer);
+ pBuffer = NULL;
+ DEBUG(DEB_LEV_ERR,"In %s Tunneled Component Couldn't Use Buffer %x \n",__func__,(int)eError);
+ return eError;
+ }
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_ALLOCATED;
+ openmaxStandPort->nNumAssignedBuffers++;
+ DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
+
+ if (openmaxStandPort->sPortParam.nBufferCountActual == openmaxStandPort->nNumAssignedBuffers) {
+ openmaxStandPort->sPortParam.bPopulated = OMX_TRUE;
+ openmaxStandPort->bIsFullOfBuffers = OMX_TRUE;
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s nPortIndex=%d\n",__func__, (int)nPortIndex);
+ }
+ omx_queue(openmaxStandPort->pBufferQueue, openmaxStandPort->pInternalBufferStorage[i]);
+ }
+ }
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Allocated all buffers\n",__func__);
+ return OMX_ErrorNone;
+}
+
+OMX_ERRORTYPE base_port_FreeTunnelBuffer(omx_base_PortType *openmaxStandPort,OMX_U32 nPortIndex)
+{
+ unsigned int i;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ OMX_ERRORTYPE eError=OMX_ErrorNone;
+ OMX_U32 numRetry=0;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (nPortIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ DEBUG(DEB_LEV_ERR, "In %s: Bad Port Index\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+ if (! PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) {
+ DEBUG(DEB_LEV_ERR, "In %s: Port is not tunneled\n", __func__);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if (omx_base_component_Private->transientState != OMX_TransStateIdleToLoaded) {
+ if (!openmaxStandPort->bIsTransientToDisabled) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: The port is not allowed to free the buffers\n", __func__);
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (omxComponent,
+ omx_base_component_Private->callbackData,
+ OMX_EventError, /* The command was completed */
+ OMX_ErrorPortUnpopulated, /* The commands was a OMX_CommandStateSet */
+ nPortIndex, /* The state has been changed in message->messageParam2 */
+ NULL);
+ }
+ }
+
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (openmaxStandPort->bBufferStateAllocated[i] & (BUFFER_ASSIGNED | BUFFER_ALLOCATED)) {
+
+ openmaxStandPort->bIsFullOfBuffers = OMX_FALSE;
+ if (openmaxStandPort->bBufferStateAllocated[i] & BUFFER_ALLOCATED) {
+ free(openmaxStandPort->pInternalBufferStorage[i]->pBuffer);
+ openmaxStandPort->pInternalBufferStorage[i]->pBuffer = NULL;
+ }
+ /*Retry more than once, if the tunneled component is not in Idle->Loaded State*/
+ while(numRetry <TUNNEL_USE_BUFFER_RETRY) {
+ eError=OMX_FreeBuffer(openmaxStandPort->hTunneledComponent,openmaxStandPort->nTunneledPort,openmaxStandPort->pInternalBufferStorage[i]);
+ if(eError!=OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"Tunneled Component Couldn't free buffer %i \n",i);
+ // see 2.1.2 and 3.1 in http://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Application_Note_318.pdf
+ if((eError == OMX_ErrorIncorrectStateTransition) && numRetry<TUNNEL_USE_BUFFER_RETRY) {
+ DEBUG(DEB_LEV_ERR,"Waiting for next try %i \n",(int)numRetry);
+ usleep(TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME);
+ numRetry++;
+ continue;
+ }
+ return eError;
+ } else {
+ break;
+ }
+ }
+ openmaxStandPort->bBufferStateAllocated[i] = BUFFER_FREE;
+
+ openmaxStandPort->nNumAssignedBuffers--;
+ DEBUG(DEB_LEV_PARAMS, "openmaxStandPort->nNumAssignedBuffers %i\n", (int)openmaxStandPort->nNumAssignedBuffers);
+
+ if (openmaxStandPort->nNumAssignedBuffers == 0) {
+ openmaxStandPort->sPortParam.bPopulated = OMX_FALSE;
+ openmaxStandPort->bIsEmptyOfBuffers = OMX_TRUE;
+ //omx_tsem_up(openmaxStandPort->pAllocSem);
+ }
+ }
+ }
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Qelem=%d BSem=%d\n", __func__,openmaxStandPort->pBufferQueue->nelem,openmaxStandPort->pBufferSem->semval);
+ return OMX_ErrorNone;
+}
+
+/** @brief the entry point for sending buffers to the port
+ *
+ * This function can be called by the EmptyThisBuffer or FillThisBuffer. It depends on
+ * the nature of the port, that can be an input or output port.
+ */
+OMX_ERRORTYPE base_port_SendBufferFunction(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer) {
+
+ OMX_ERRORTYPE err;
+ OMX_U32 portIndex;
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+#if NO_GST_OMX_PATCH
+ unsigned int i;
+#endif
+ portIndex = (openmaxStandPort->sPortParam.eDir == OMX_DirInput)?pBuffer->nInputPortIndex:pBuffer->nOutputPortIndex;
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s portIndex %lu\n", __func__, (unsigned long)portIndex);
+
+ if (portIndex != openmaxStandPort->sPortParam.nPortIndex) {
+ DEBUG(DEB_LEV_ERR, "In %s: wrong port for this operation portIndex=%d port->portIndex=%d\n", __func__, (int)portIndex, (int)openmaxStandPort->sPortParam.nPortIndex);
+ return OMX_ErrorBadPortIndex;
+ }
+
+ if(omx_base_component_Private->state == OMX_StateInvalid) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are in OMX_StateInvalid\n", __func__);
+ return OMX_ErrorInvalidState;
+ }
+
+ if(omx_base_component_Private->state != OMX_StateExecuting &&
+ omx_base_component_Private->state != OMX_StatePause &&
+ omx_base_component_Private->state != OMX_StateIdle) {
+ DEBUG(DEB_LEV_ERR, "In %s: we are not in executing/paused/idle state, but in %d\n", __func__, omx_base_component_Private->state);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ if (!PORT_IS_ENABLED(openmaxStandPort) || (PORT_IS_BEING_DISABLED(openmaxStandPort) && !PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort)) ||
+ (omx_base_component_Private->transientState == OMX_TransStateExecutingToIdle &&
+ (PORT_IS_TUNNELED(openmaxStandPort) && !PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)))) {
+ DEBUG(DEB_LEV_ERR, "In %s: Port %d is disabled comp = %s \n", __func__, (int)portIndex,omx_base_component_Private->name);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+
+ /* Temporarily disable this check for gst-openmax */
+#if NO_GST_OMX_PATCH
+ {
+ OMX_BOOL foundBuffer = OMX_FALSE;
+ if(pBuffer!=NULL && pBuffer->pBuffer!=NULL) {
+ for(i=0; i < openmaxStandPort->sPortParam.nBufferCountActual; i++){
+ if (pBuffer->pBuffer == openmaxStandPort->pInternalBufferStorage[i]->pBuffer) {
+ foundBuffer = OMX_TRUE;
+ break;
+ }
+ }
+ }
+ if (!foundBuffer) {
+ return OMX_ErrorBadParameter;
+ }
+ }
+#endif
+
+ if ((err = checkHeader(pBuffer, sizeof(OMX_BUFFERHEADERTYPE))) != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s: received wrong buffer header on input port\n", __func__);
+ return err;
+ }
+
+ /* And notify the buffer management thread we have a fresh new buffer to manage */
+ if(!PORT_IS_BEING_FLUSHED(openmaxStandPort) && !(PORT_IS_BEING_DISABLED(openmaxStandPort) && PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort))){
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ DEBUG(DEB_LEV_PARAMS, "In %s Signalling bMgmtSem Port Index=%d\n",__func__, (int)portIndex);
+ omx_tsem_up(omx_base_component_Private->bMgmtSem);
+ }else if(PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)){
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s: Comp %s received io:%d buffer\n",
+ __func__,omx_base_component_Private->name,(int)openmaxStandPort->sPortParam.nPortIndex);
+ omx_queue(openmaxStandPort->pBufferQueue, pBuffer);
+ omx_tsem_up(openmaxStandPort->pBufferSem);
+ }
+ else { // If port being flushed and not tunneled then return error
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s \n", __func__);
+ return OMX_ErrorIncorrectStateOperation;
+ }
+ return OMX_ErrorNone;
+}
+
+/**
+ * Returns Input/Output Buffer to the IL client or Tunneled Component
+ */
+OMX_ERRORTYPE base_port_ReturnBufferFunction(omx_base_PortType* openmaxStandPort,OMX_BUFFERHEADERTYPE* pBuffer){
+ omx_base_component_PrivateType* omx_base_component_Private=(omx_base_component_PrivateType*)openmaxStandPort->standCompContainer->pComponentPrivate;
+ omx_queue_t* pQueue = openmaxStandPort->pBufferQueue;
+ omx_tsem_t* pSem = openmaxStandPort->pBufferSem;
+ OMX_ERRORTYPE eError = OMX_ErrorNone;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+ if (PORT_IS_TUNNELED(openmaxStandPort) &&
+ ! PORT_IS_BUFFER_SUPPLIER(openmaxStandPort)) {
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ pBuffer->nOutputPortIndex = openmaxStandPort->nTunneledPort;
+ pBuffer->nInputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ eError = ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->FillThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ if(eError != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s eError %08x in FillThis Buffer from Component %s Non-Supplier\n",
+ __func__, eError,omx_base_component_Private->name);
+ }
+ } else {
+ pBuffer->nInputPortIndex = openmaxStandPort->nTunneledPort;
+ pBuffer->nOutputPortIndex = openmaxStandPort->sPortParam.nPortIndex;
+ eError = ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->EmptyThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ if(eError != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR, "In %s eError %08x in EmptyThis Buffer from Component %s Non-Supplier\n",
+ __func__, eError,omx_base_component_Private->name);
+ }
+ }
+ }
+ else if (PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(openmaxStandPort) &&
+ !PORT_IS_BEING_FLUSHED(openmaxStandPort)) {
+ if (!PORT_IS_ENABLED(openmaxStandPort) || PORT_IS_BEING_DISABLED(openmaxStandPort)) {
+ omx_queue(pQueue, pBuffer);
+ omx_tsem_up(pSem);
+ } else if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ eError = ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->FillThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ /// AND TODO:
+ /// see 2.2 of http://www.khronos.org/registry/omxil/specs/OpenMAX_IL_1_1_2_Application_Note_318.pdf
+ if(eError != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s eError %08x in FillThis Buffer from Component %s Supplier\n",
+ __func__, eError,omx_base_component_Private->name);
+ /*If Error Occured then queue the buffer*/
+ omx_queue(pQueue, pBuffer);
+ omx_tsem_up(pSem);
+ }
+ } else {
+ eError = ((OMX_COMPONENTTYPE*)(openmaxStandPort->hTunneledComponent))->EmptyThisBuffer(openmaxStandPort->hTunneledComponent, pBuffer);
+ if(eError != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s eError %08x in EmptyThis Buffer from Component %s Supplier\n",
+ __func__, eError,omx_base_component_Private->name);
+ /*If Error Occured then queue the buffer*/
+ omx_queue(pQueue, pBuffer);
+ omx_tsem_up(pSem);
+ }
+ }
+ }else if (! PORT_IS_TUNNELED(openmaxStandPort)){
+ (*(openmaxStandPort->BufferProcessedCallback))(
+ openmaxStandPort->standCompContainer,
+ omx_base_component_Private->callbackData,
+ pBuffer);
+ }
+ else {
+ omx_queue(pQueue,pBuffer);
+ openmaxStandPort->nNumBufferFlushed++;
+ }
+
+ return OMX_ErrorNone;
+}
+
+
+OMX_ERRORTYPE base_port_ComponentTunnelRequest(omx_base_PortType* openmaxStandPort,OMX_IN OMX_HANDLETYPE hTunneledComp,OMX_IN OMX_U32 nTunneledPort,OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup) {
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ OMX_PARAM_PORTDEFINITIONTYPE param;
+ OMX_PARAM_BUFFERSUPPLIERTYPE pSupplier;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
+
+ if (pTunnelSetup == NULL || hTunneledComp == 0) {
+ /* cancel previous tunnel */
+ OMX_COMPONENTTYPE* omxComponent = openmaxStandPort->standCompContainer;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)omxComponent->pComponentPrivate;
+ if (PORT_IS_TUNNELED(openmaxStandPort) && (PORT_IS_BEING_DISABLED(openmaxStandPort) || (omx_base_component_Private->transientState == OMX_TransStateIdleToLoaded)))
+ {
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s Scheduled TearDown port=%d PORT_IS_BEING_DISABLED(%d) transientState=%d\n",
+ __func__, openmaxStandPort->sPortParam.nPortIndex, PORT_IS_BEING_DISABLED(openmaxStandPort), omx_base_component_Private->transientState);
+ openmaxStandPort->bTunnelTearDown = OMX_TRUE;
+ }
+ else {
+ openmaxStandPort->hTunneledComponent = 0;
+ openmaxStandPort->nTunneledPort = 0;
+ openmaxStandPort->nTunnelFlags = 0;
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyUnspecified;
+ }
+ return OMX_ErrorNone;
+ }
+
+ if (openmaxStandPort->sPortParam.eDir == OMX_DirInput) {
+ /* Get Port Definition of the Tunnelled Component*/
+ param.nPortIndex=nTunneledPort;
+ setHeader(¶m, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+ err = OMX_GetParameter(hTunneledComp, OMX_IndexParamPortDefinition, ¶m);
+ if (err != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"In %s Get Tunneled Port Definition error=0x%08x Line=%d\n",__func__,err,__LINE__);
+ // compatibility not reached
+ return OMX_ErrorPortsNotCompatible;
+ }
+
+ // Negotiate buffer params
+ param.nBufferCountActual = param.nBufferCountMin > openmaxStandPort->sPortParam.nBufferCountMin ?
+ param.nBufferCountMin : openmaxStandPort->sPortParam.nBufferCountMin;
+ openmaxStandPort->sPortParam.nBufferCountActual = param.nBufferCountActual;
+
+ param.nBufferSize = param.nBufferSize > openmaxStandPort->sPortParam.nBufferSize ?
+ param.nBufferSize : openmaxStandPort->sPortParam.nBufferSize;
+ openmaxStandPort->sPortParam.nBufferSize = param.nBufferSize;
+
+ err = OMX_SetParameter(hTunneledComp, OMX_IndexParamPortDefinition, ¶m);
+ if (err != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"In %s Set Tunneled Port Definition error=0x%08x Line=%d\n",__func__,err,__LINE__);
+ return OMX_ErrorPortsNotCompatible;
+ }
+
+ openmaxStandPort->nNumTunnelBuffer=param.nBufferCountActual; //nBufferCountMin;
+
+ if(param.eDomain!=openmaxStandPort->sPortParam.eDomain) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ if(param.eDomain==OMX_PortDomainAudio) {
+ if(param.format.audio.eEncoding == OMX_AUDIO_CodingMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ } else if(param.eDomain==OMX_PortDomainVideo) {
+ if(param.format.video.eCompressionFormat == OMX_VIDEO_CodingMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ } else if(param.eDomain==OMX_PortDomainOther) {
+ if(param.format.other.eFormat == OMX_OTHER_FormatMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ }
+
+ /* Get Buffer Supplier type of the Tunnelled Component*/
+ pSupplier.nPortIndex=nTunneledPort;
+ setHeader(&pSupplier, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
+ err = OMX_GetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &pSupplier);
+ if (err != OMX_ErrorNone) {
+ // compatibility not reached
+ DEBUG(DEB_LEV_ERR,"In %s Tunneled Buffer Supplier error=0x%08x Line=%d\n",__func__,err,__LINE__);
+ return OMX_ErrorPortsNotCompatible;
+ } else {
+ DEBUG(DEB_LEV_FULL_SEQ,"Tunneled Port eBufferSupplier=%x\n",pSupplier.eBufferSupplier);
+ }
+
+ // store the current callbacks, if defined
+ openmaxStandPort->hTunneledComponent = hTunneledComp;
+ openmaxStandPort->nTunneledPort = nTunneledPort;
+
+ /*Check for and set proprietary communication flag.
+ In case a component support Deep Tunneling should set it's tunnel flag to PROPRIETARY_COMMUNICATION_ESTABLISHED */
+ /// AND: No proprietary communication
+ /*
+ if(PORT_IS_DEEP_TUNNELED(openmaxStandPort)) {
+ OMX_VENDOR_PROP_TUNNELSETUPTYPE pPropTunnelSetup;
+ pPropTunnelSetup.nPortIndex = nTunneledPort;
+
+ err = OMX_GetParameter(hTunneledComp, OMX_IndexVendorCompPropTunnelFlags, &pPropTunnelSetup);
+ if (err != OMX_ErrorNone) {
+ // compatibility not reached
+ DEBUG(DEB_LEV_ERR,"In %s Proprietary Tunneled Buffer Supplier nTunneledPort=%d error=0x%08x Line=%d \n",
+ __func__,(int)pPropTunnelSetup.nPortIndex,err,__LINE__);
+ openmaxStandPort->nTunnelFlags = 0;
+ } else {
+ openmaxStandPort->nTunnelFlags = PROPRIETARY_COMMUNICATION_ESTABLISHED;
+ }
+ } else {
+ openmaxStandPort->nTunnelFlags = 0;
+ }
+ */
+ openmaxStandPort->nTunnelFlags = 0;
+ /// AND
+
+ // Negotiation
+ if (pTunnelSetup->nTunnelFlags & OMX_PORTTUNNELFLAG_READONLY) {
+ // the buffer provider MUST be the output port provider
+ /// AND: WRONG!!!!
+ /*
+ pTunnelSetup->eSupplier = OMX_BufferSupplyInput;
+ openmaxStandPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyInput;
+ */
+ DEBUG(DEB_LEV_ERR,"In %s --------------> OMX_PORTTUNNELFLAG_READONLY Line=%d\n",__func__,__LINE__);
+ pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyOutput;
+ /// AND
+ } else {
+ //if (pTunnelSetup->eSupplier == OMX_BufferSupplyInput) {
+ // DEBUG(DEB_LEV_ERR,"In %s --------------> OMX_BufferSupplyInput Line=%d\n",__func__,__LINE__);
+ // openmaxStandPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ // openmaxStandPort->eBufferSupplier=OMX_BufferSupplyInput;
+ //} else if (pTunnelSetup->eSupplier == OMX_BufferSupplyUnspecified) {
+ // /// AND TODO: Can be reversed????
+ // DEBUG(DEB_LEV_ERR,"In %s --------------> OMX_BufferSupplyUnspecified Line=%d\n",__func__,__LINE__);
+ // pTunnelSetup->eSupplier = OMX_BufferSupplyInput;
+ // openmaxStandPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ // openmaxStandPort->eBufferSupplier=OMX_BufferSupplyInput;
+ // //pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
+ // //openmaxStandPort->eBufferSupplier=OMX_BufferSupplyOutput;
+ // /// AND
+ //} else if (pTunnelSetup->eSupplier == OMX_BufferSupplyOutput){
+ // DEBUG(DEB_LEV_ERR,"In %s --------------> OMX_BufferSupplyOutput Line=%d\n",__func__,__LINE__);
+ // pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
+ // openmaxStandPort->eBufferSupplier=OMX_BufferSupplyOutput;
+ //} else {
+ // DEBUG(DEB_LEV_ERR,"In %s --------------> undefined pTunnelSetup->eSupplier = %d Line=%d\n",__func__,(int)pTunnelSetup->eSupplier,__LINE__);
+ //}
+
+ // fixed to work only in this direction
+ DEBUG(DEB_LEV_ERR,"In %s --------------> OMX_BufferSupply Line=%d\n",__func__,__LINE__);
+ pTunnelSetup->eSupplier = OMX_BufferSupplyInput;
+ openmaxStandPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyInput;
+ /// AND
+
+ }
+ openmaxStandPort->nTunnelFlags |= TUNNEL_ESTABLISHED;
+
+ /* Set Buffer Supplier type of the Tunnelled Component after final negotiation*/
+ pSupplier.nPortIndex=nTunneledPort;
+ pSupplier.eBufferSupplier=openmaxStandPort->eBufferSupplier;
+ err = OMX_SetParameter(hTunneledComp, OMX_IndexParamCompBufferSupplier, &pSupplier);
+ if (err != OMX_ErrorNone) {
+ // compatibility not reached
+ DEBUG(DEB_LEV_ERR,"In %s Tunneled Buffer Supplier error=0x%08x Line=%d\n",__func__,err,__LINE__);
+ openmaxStandPort->nTunnelFlags=0;
+ return OMX_ErrorPortsNotCompatible;
+ }
+ } else {
+ // output port
+ // all the consistency checks are under other component responsibility
+
+ /* Get Port Definition of the Tunnelled Component*/
+ param.nPortIndex=nTunneledPort;
+ setHeader(¶m, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+ err = OMX_GetParameter(hTunneledComp, OMX_IndexParamPortDefinition, ¶m);
+ if (err != OMX_ErrorNone) {
+ DEBUG(DEB_LEV_ERR,"In %s Tunneled Port Definition error=0x%08x Line=%d\n",__func__,err,__LINE__);
+ // compatibility not reached
+ return OMX_ErrorPortsNotCompatible;
+ }
+ if(param.eDomain!=openmaxStandPort->sPortParam.eDomain) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+
+ if(param.eDomain==OMX_PortDomainAudio) {
+ if(param.format.audio.eEncoding == OMX_AUDIO_CodingMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ } else if(param.eDomain==OMX_PortDomainVideo) {
+ if(param.format.video.eCompressionFormat == OMX_VIDEO_CodingMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ } else if(param.eDomain==OMX_PortDomainOther) {
+ if(param.format.other.eFormat == OMX_OTHER_FormatMax) {
+ return OMX_ErrorPortsNotCompatible;
+ }
+ }
+
+ /*Check for and set proprietary communication flag*/
+ if(PORT_IS_DEEP_TUNNELED(openmaxStandPort)) {
+ OMX_VENDOR_PROP_TUNNELSETUPTYPE pPropTunnelSetup;
+ pPropTunnelSetup.nPortIndex = nTunneledPort;
+
+ err = OMX_GetParameter(hTunneledComp, (OMX_INDEXTYPE)OMX_IndexVendorCompPropTunnelFlags, &pPropTunnelSetup);
+ if (err != OMX_ErrorNone) {
+ // compatibility not reached
+ DEBUG(DEB_LEV_ERR,"In %s Proprietary Tunneled Buffer Supplier nTunneledPort=%d error=0x%08x Line=%d \n",
+ __func__,(int)pPropTunnelSetup.nPortIndex,err,__LINE__);
+ openmaxStandPort->nTunnelFlags = 0;
+ } else {
+ openmaxStandPort->nTunnelFlags = PROPRIETARY_COMMUNICATION_ESTABLISHED;
+ }
+ } else {
+ openmaxStandPort->nTunnelFlags = 0;
+ }
+
+ openmaxStandPort->nNumTunnelBuffer=param.nBufferCountMin;
+
+ openmaxStandPort->hTunneledComponent = hTunneledComp;
+ openmaxStandPort->nTunneledPort = nTunneledPort;
+ pTunnelSetup->eSupplier = OMX_BufferSupplyOutput;
+ openmaxStandPort->nTunnelFlags |= TUNNEL_IS_SUPPLIER;
+ openmaxStandPort->nTunnelFlags |= TUNNEL_ESTABLISHED;
+
+ openmaxStandPort->eBufferSupplier=OMX_BufferSupplyOutput;
+ }
+
+ return OMX_ErrorNone;
+}
diff --git a/alsa/omx_base_port.h b/alsa/omx_base_port.h
new file mode 100644
index 0000000..3159b92
--- /dev/null
+++ b/alsa/omx_base_port.h
@@ -0,0 +1,288 @@
+/**
+ @file src/base/omx_base_port.h
+
+ Base class for OpenMAX ports to be used in derived components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-08-08 06:56:06 +0200 (Fri, 08 Aug 2008) $
+ Revision $Rev: 581 $
+ Author $Author: pankaj_sen $
+
+*/
+
+#include "omx_comp_debug_levels.h"
+
+#include "omx_semaphore.h"
+#include "omx_queue.h"
+#include "omx_classmagic.h"
+#pragma pack(4)
+//#include <IL/OMX_Types.h>
+#include <IL/OMX_Core.h>
+#include <IL/OMX_Component.h>
+#include <IL/OMX_Audio.h>
+#pragma pack()
+
+#define OMX_ErrorIncorrectStateTransition OMX_ErrorIncorrectStateOperation
+
+#ifndef __OMX_BASE_PORT_H__
+#define __OMX_BASE_PORT_H__
+
+#define TUNNEL_USE_BUFFER_RETRY 20
+#define TUNNEL_USE_BUFFER_RETRY_USLEEP_TIME 5000
+#define NO_GST_OMX_PATCH 1
+
+/**
+ * Port Specific Macro's
+ */
+#define PORT_IS_BEING_FLUSHED(pPort) (pPort->bIsPortFlushed == OMX_TRUE)
+#define PORT_IS_BEING_DISABLED(pPort) (pPort->bIsTransientToDisabled == OMX_TRUE)
+#define PORT_IS_ENABLED(pPort) (pPort->sPortParam.bEnabled == OMX_TRUE)
+#define PORT_IS_POPULATED(pPort) (pPort->sPortParam.bPopulated == OMX_TRUE)
+#define PORT_IS_TUNNELED(pPort) (pPort->nTunnelFlags & TUNNEL_ESTABLISHED)
+#define PORT_IS_DEEP_TUNNELED(pPort) (pPort->nTunnelFlags & PROPRIETARY_COMMUNICATION_ESTABLISHED)
+#define PORT_IS_BUFFER_SUPPLIER(pPort) (pPort->nTunnelFlags & TUNNEL_IS_SUPPLIER)
+#define PORT_IS_TUNNELED_N_BUFFER_SUPPLIER(pPort) ((pPort->nTunnelFlags & TUNNEL_ESTABLISHED) && (pPort->nTunnelFlags & TUNNEL_IS_SUPPLIER))
+
+/** The following enum values are used to characterize each buffer
+ * allocated or assigned to the component. A buffer list is
+ * created for each port of the component. The buffer can be assigned
+ * to the port, or owned by the port. The buffer flag are applied for each buffer
+ * in each port buffer list. The following use cases are currently implemented:
+ * - When the IL Client asks the component to allocate a buffer
+ * for a given port, with the call to AllocateBuffer, the
+ * buffer created is characterizeed by the flag BUFFER_ALLOCATED
+ * - When the IL Client asks the component to use a buffer allocated
+ * by the client itself, the buffer flag is BUFFER_ASSIGNED
+ * - When the component is tunneled by another component, and the first
+ * is supplier of the buffer, the buffer is marked with the
+ * BUFFER_ALLOCATED flag.
+ * - When the component is tunneled by another component, and the second
+ * is supplier of the buffer, the buffer is marked with the
+ * BUFFER_ASSIGNED flag.
+ * - The case of a buffer supplied by the first component but allocated by another
+ * component or another port inside the same component, as in the case
+ * of shared buffers, is not yet implemented in these components
+ * - During hte deallocation phase each buffer is marked with the BUFFER_FREE
+ * flag, so that the component can check if all the buffers have been deallocated
+ * before switch the component state to Loaded, as specified by
+ * the OpenMAX specs
+ */
+typedef unsigned int BUFFER_STATUS_FLAG;
+
+#define BUFFER_FREE 0
+#define BUFFER_ALLOCATED 0x0001 /**< This flag is applied to a buffer when it is allocated
+ by the given port of the component */
+#define BUFFER_ASSIGNED 0x0002 /**< This flag is applied to a buffer when it is assigned
+ from another port or by the IL client */
+#define HEADER_ALLOCATED 0x0004 /**< This flag is applied to a buffer when buffer header is allocated
+ by the given port of the component */
+
+/** @brief the status of a port related to the tunneling with another component
+ */
+typedef unsigned int TUNNEL_STATUS_FLAG;
+#define NO_TUNNEL 0 /**< No tunnel established */
+#define TUNNEL_ESTABLISHED 0x0001 /**< the TUNNEL_ESTABLISHED specifies if a port is tunneled.
+ * It is assigned to a private field of the port if it is tunneled
+ */
+#define TUNNEL_IS_SUPPLIER 0x0002 /**< the TUNNEL_IS_SUPPLIER specifies if a tunneled port is the supplier.
+ * It is assigned to a private field of the port if it is tunneled and also it is the buffer supplier for the tunnel.
+ */
+#define PROPRIETARY_COMMUNICATION_ESTABLISHED 0x0004 /** The tunnel established is created between two components of the same
+ * vendor. These components can take advantage from a vendor specific
+ * communication
+ */
+
+/**
+ * @brief the base structure that describes each port.
+ *
+ * The data structure that describes a port contains the basic elements used in the
+ * base component. Other elements can be added in the derived components structures.
+ */
+CLASS(omx_base_PortType)
+#define omx_base_PortType_FIELDS \
+ OMX_HANDLETYPE hTunneledComponent; /**< @param hTunneledComponent Handle to the tunnelled component */\
+ OMX_U32 nTunnelFlags; /**< This field contains one or more tags that describe the tunnel status of the port */\
+ OMX_U32 nTunneledPort; /**< @param nTunneledPort Tunneled port number */ \
+ OMX_BOOL bTunnelTearDown; /**< @param nTunneledPort Helper for assinc TearDown */ \
+ OMX_BUFFERSUPPLIERTYPE eBufferSupplier; /**< @param eBufferSupplier the type of supplier in case of tunneling */\
+ OMX_U32 nNumTunnelBuffer; /**< @param nNumTunnelBuffer Number of buffer to be tunnelled */\
+ omx_tsem_t* pAllocSem; /**< @param pFlushSem Semaphore that locks the execution until the buffers have been flushed, if needed */ \
+ OMX_U32 nNumBufferFlushed; /**< @param nNumBufferFlushed Number of buffer Flushed */\
+ OMX_BOOL bIsPortFlushed;/**< @param bIsPortFlushed Boolean variables indicate port is being flushed at the moment */ \
+ omx_queue_t* pBufferQueue; /**< @param pBufferQueue queue for buffer to be processed by the port */\
+ omx_tsem_t* pBufferSem; /**< @param pBufferSem Semaphore for buffer queue access synchronization */\
+ OMX_U32 nNumAssignedBuffers; /**< @param nNumAssignedBuffers Number of buffer assigned on each port */\
+ OMX_PARAM_PORTDEFINITIONTYPE sPortParam; /**< @param sPortParam General OpenMAX port parameter */\
+ OMX_BUFFERHEADERTYPE **pInternalBufferStorage; /**< This array contains the reference to all the buffers hadled by this port and already registered*/\
+ BUFFER_STATUS_FLAG *bBufferStateAllocated; /**< @param bBufferStateAllocated The State of the Buffer whether assigned or allocated */\
+ OMX_COMPONENTTYPE *standCompContainer;/**< The OpenMAX component reference that contains this port */\
+ OMX_BOOL bIsTransientToEnabled;/**< It indicates that the port is going from disabled to enabled */ \
+ OMX_BOOL bIsTransientToDisabled;/**< It indicates that the port is going from enabled to disabled */ \
+ OMX_BOOL bIsFullOfBuffers; /**< It indicates if the port has all the buffers needed */ \
+ OMX_BOOL bIsEmptyOfBuffers;/**< It indicates if the port has no buffers*/ \
+ OMX_ERRORTYPE (*PortConstructor)(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput); /**< The contructor of the port. It fills all the other function pointers */ \
+ OMX_ERRORTYPE (*PortDestructor)(omx_base_PortType *openmaxStandPort); /**< The destructor of the port*/ \
+ OMX_ERRORTYPE (*Port_DisablePort)(omx_base_PortType *openmaxStandPort); /**< Disables the port */ \
+ OMX_ERRORTYPE (*Port_EnablePort)(omx_base_PortType *openmaxStandPort); /**< Enables the port */ \
+ OMX_ERRORTYPE (*Port_SendBufferFunction)(omx_base_PortType *openmaxStandPort, OMX_BUFFERHEADERTYPE* pBuffer); /**< Holds the EmptyThisBuffer of FillThisBuffer function, if the port is input or output */ \
+ OMX_ERRORTYPE (*Port_AllocateBuffer)(omx_base_PortType *openmaxStandPort,OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes);/**< Replaces the AllocateBuffer call for the base port. */ \
+ OMX_ERRORTYPE (*Port_UseBuffer)(omx_base_PortType *openmaxStandPort,OMX_BUFFERHEADERTYPE** ppBufferHdr,OMX_U32 nPortIndex,OMX_PTR pAppPrivate,OMX_U32 nSizeBytes,OMX_U8* pBuffer);/**< The standard use buffer function applied to the port class */ \
+ OMX_ERRORTYPE (*Port_FreeBuffer)(omx_base_PortType *openmaxStandPort,OMX_U32 nPortIndex,OMX_BUFFERHEADERTYPE* pBuffer); /**< The standard free buffer function applied to the port class */ \
+ OMX_ERRORTYPE (*Port_AllocateTunnelBuffer)(omx_base_PortType *openmaxStandPort,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_U32 nSizeBytes);/**< AllocateTunnelBuffer call for the base port. */ \
+ OMX_ERRORTYPE (*Port_FreeTunnelBuffer)(omx_base_PortType *openmaxStandPort,OMX_U32 nPortIndex); /**< The free buffer function used to free tunnelled buffers */ \
+ OMX_ERRORTYPE (*BufferProcessedCallback)(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, OMX_BUFFERHEADERTYPE* pBuffer);/**< Holds the EmptyBufferDone or FillBufferDone callback, if the port is input or output port */ \
+ OMX_ERRORTYPE (*FlushProcessingBuffers)(omx_base_PortType *openmaxStandPort); /**< release all the buffers currently under processing */ \
+ OMX_ERRORTYPE (*ReturnBufferFunction)(omx_base_PortType* openmaxStandPort,OMX_BUFFERHEADERTYPE* pBuffer); /**< Call appropriate function to return buffers to peer or IL Client*/ \
+ OMX_ERRORTYPE (*ComponentTunnelRequest)(omx_base_PortType* openmaxStandPort,OMX_IN OMX_HANDLETYPE hTunneledComp,OMX_IN OMX_U32 nTunneledPort,OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup); /**< Setup tunnel with the port */
+ENDCLASS(omx_base_PortType)
+
+/**
+ * @brief The base contructor for the generic OpenMAX ST port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of constructing the instance of the port and
+ * every object needed by the base port.
+ *
+ * @param openmaxStandPort the ST port to be initialized
+ *
+ * @return OMX_ErrorInsufficientResources if a memory allocation fails
+ */
+OMX_ERRORTYPE base_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,omx_base_PortType **openmaxStandPort,OMX_U32 nPortIndex, OMX_BOOL isInput);
+
+/** @brief The base destructor for the generic OpenMAX ST port
+ *
+ * This function is executed by the component that uses a port.
+ * The parameter contains the info about the component.
+ * It takes care of destructing the instance of the port and
+ * every object used by the base port.
+ *
+ * @param openmaxStandPort the ST port to be disposed
+ */
+OMX_ERRORTYPE base_port_Destructor(omx_base_PortType *openmaxStandPort);
+
+/** @brief Disables the port.
+ *
+ * This function is called due to a request by the IL client
+ *
+ * @param openmaxStandPort the reference to the port
+ *
+ */
+OMX_ERRORTYPE base_port_DisablePort(omx_base_PortType *openmaxStandPort);
+
+/** @brief Enables the port.
+ *
+ * This function is called due to a request by the IL client
+ *
+ * @param openmaxStandPort the reference to the port
+ *
+ */
+OMX_ERRORTYPE base_port_EnablePort(omx_base_PortType *openmaxStandPort);
+
+/** @brief The entry point for sending buffers to the port
+ *
+ * This function can be called by the EmptyThisBuffer or FillThisBuffer. It depends on
+ * the nature of the port, that can be an input or output port.
+ */
+OMX_ERRORTYPE base_port_SendBufferFunction(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer);
+
+/** @brief Called by the standard allocate buffer, it implements a base functionality.
+ *
+ * This function can be overriden if the allocation of the buffer is not a simply malloc call.
+ * The parameters are the same as the standard function, except for the handle of the port
+ * instead of the handler of the component
+ * When the buffers needed by this port are all assigned or allocated, the variable
+ * bIsFullOfBuffers becomes equal to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_AllocateBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE** pBuffer,
+ OMX_U32 nPortIndex,
+ OMX_PTR pAppPrivate,
+ OMX_U32 nSizeBytes);
+
+/** @brief Called by the standard use buffer, it implements a base functionality.
+ *
+ * This function can be overriden if the use buffer implicate more complicated operations.
+ * The parameters are the same as the standard function, except for the handle of the port
+ * instead of the handler of the component
+ * When the buffers needed by this port are all assigned or allocated, the variable
+ * bIsFullOfBuffers becomes equal to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_UseBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_BUFFERHEADERTYPE** ppBufferHdr,
+ OMX_U32 nPortIndex,
+ OMX_PTR pAppPrivate,
+ OMX_U32 nSizeBytes,
+ OMX_U8* pBuffer);
+
+/** @brief Called by the standard function.
+ *
+ * It frees the buffer header and in case also the buffer itself, if needed.
+ * When all the bufers are done, the variable bIsEmptyOfBuffers is set to OMX_TRUE
+ */
+OMX_ERRORTYPE base_port_FreeBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_U32 nPortIndex,
+ OMX_BUFFERHEADERTYPE* pBuffer);
+
+/** @brief Releases buffers under processing.
+ *
+ * This function must be implemented in the derived classes, for the
+ * specific processing
+ */
+OMX_ERRORTYPE base_port_FlushProcessingBuffers(omx_base_PortType *openmaxStandPort);
+
+/** @brief Returns buffers when processed.
+ *
+ * Call appropriate function to return buffers to peer or IL Client
+ */
+
+OMX_ERRORTYPE base_port_ReturnBufferFunction(
+ omx_base_PortType* openmaxStandPort,
+ OMX_BUFFERHEADERTYPE* pBuffer);
+
+/** @brief Setup Tunnel with the port
+ */
+
+OMX_ERRORTYPE base_port_ComponentTunnelRequest(
+ omx_base_PortType* openmaxStandPort,
+ OMX_IN OMX_HANDLETYPE hTunneledComp,
+ OMX_IN OMX_U32 nTunneledPort,
+ OMX_INOUT OMX_TUNNELSETUPTYPE* pTunnelSetup);
+
+/** @brief Allocate Buffers for tunneling use
+ */
+OMX_ERRORTYPE base_port_AllocateTunnelBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_IN OMX_U32 nPortIndex,
+ OMX_IN OMX_U32 nSizeBytes);
+
+/** @brief Free buffers used in tunnel
+ */
+OMX_ERRORTYPE base_port_FreeTunnelBuffer(
+ omx_base_PortType *openmaxStandPort,
+ OMX_U32 nPortIndex);
+
+
+#endif
diff --git a/alsa/omx_base_sink.cpp b/alsa/omx_base_sink.cpp
new file mode 100644
index 0000000..ae8b3e3
--- /dev/null
+++ b/alsa/omx_base_sink.cpp
@@ -0,0 +1,189 @@
+/**
+ @file src/base/omx_base_sink.c
+
+ OpenMAX base sink component. This component does not perform any multimedia
+ processing. It derives from base component and contains a single input port.
+ It can be used as base class for sink components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-09-12 08:12:11 +0200 (Fri, 12 Sep 2008) $
+ Revision $Rev: 615 $
+ Author $Author: pankaj_sen $
+*/
+
+#include <omx_base_sink.h>
+
+OMX_ERRORTYPE omx_base_sink_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ omx_base_sink_PrivateType* omx_base_sink_Private;
+
+ if (openmaxStandComp->pComponentPrivate) {
+ omx_base_sink_Private = (omx_base_sink_PrivateType*)openmaxStandComp->pComponentPrivate;
+ } else {
+ omx_base_sink_Private = (omx_base_sink_PrivateType*)calloc(1,sizeof(omx_base_sink_PrivateType));
+ if (!omx_base_sink_Private) {
+ return OMX_ErrorInsufficientResources;
+ }
+ }
+
+ // we could create our own port structures here
+ // fixme maybe the base class could use a "port factory" function pointer?
+ err = omx_base_component_Constructor(openmaxStandComp,cComponentName);
+
+ /* here we can override whatever defaults the base_component constructor set
+ * e.g. we can override the function pointers in the private struct */
+ omx_base_sink_Private = (omx_base_sink_PrivateType*)openmaxStandComp->pComponentPrivate;
+
+ omx_base_sink_Private->BufferMgmtFunction = omx_base_sink_BufferMgmtFunction;
+
+ return err;
+}
+
+OMX_ERRORTYPE omx_base_sink_Destructor(OMX_COMPONENTTYPE *openmaxStandComp)
+{
+ return omx_base_component_Destructor(openmaxStandComp);
+}
+
+/** This is the central function for component processing. It
+ * is executed in a separate thread, is synchronized with
+ * semaphores at each port, those are released each time a new buffer
+ * is available on the given port.
+ */
+void* omx_base_sink_BufferMgmtFunction (void* param) {
+ OMX_COMPONENTTYPE* openmaxStandComp = (OMX_COMPONENTTYPE*)param;
+ omx_base_component_PrivateType* omx_base_component_Private = (omx_base_component_PrivateType*)openmaxStandComp->pComponentPrivate;
+ omx_base_sink_PrivateType* omx_base_sink_Private = (omx_base_sink_PrivateType*)omx_base_component_Private;
+ omx_base_PortType *pInPort = (omx_base_PortType *)omx_base_sink_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
+ omx_tsem_t* pInputSem = pInPort->pBufferSem;
+ omx_queue_t* pInputQueue = pInPort->pBufferQueue;
+ OMX_BUFFERHEADERTYPE* pInputBuffer = NULL;
+ OMX_COMPONENTTYPE* target_component;
+ OMX_BOOL isInputBufferNeeded = OMX_TRUE;
+ int inBufExchanged = 0;
+
+ DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n", __func__);
+ while(omx_base_component_Private->state == OMX_StateIdle ||
+ omx_base_component_Private->state == OMX_StateExecuting ||
+ omx_base_component_Private->state == OMX_StatePause ||
+ omx_base_component_Private->transientState == OMX_TransStateLoadedToIdle){
+
+ /*Wait till the ports are being flushed*/
+ pthread_mutex_lock(&omx_base_sink_Private->flush_mutex);
+ while( PORT_IS_BEING_FLUSHED(pInPort)) {
+ pthread_mutex_unlock(&omx_base_sink_Private->flush_mutex);
+
+ if(isInputBufferNeeded==OMX_FALSE) {
+ pInPort->ReturnBufferFunction(pInPort,pInputBuffer);
+ inBufExchanged--;
+ pInputBuffer=NULL;
+ isInputBufferNeeded=OMX_TRUE;
+ DEBUG(DEB_LEV_FULL_SEQ, "Ports are flushing,so returning input buffer\n");
+ }
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s signalling flush all condition \n", __func__);
+
+ omx_tsem_up(omx_base_sink_Private->flush_all_condition);
+ omx_tsem_down(omx_base_sink_Private->flush_condition);
+ pthread_mutex_lock(&omx_base_sink_Private->flush_mutex);
+ }
+ pthread_mutex_unlock(&omx_base_sink_Private->flush_mutex);
+
+ /*No buffer to process. So wait here*/
+ if((pInputSem->semval==0 && isInputBufferNeeded==OMX_TRUE ) &&
+ (omx_base_sink_Private->state != OMX_StateLoaded && omx_base_sink_Private->state != OMX_StateInvalid)) {
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Waiting for input buffer \n");
+ omx_tsem_down(omx_base_sink_Private->bMgmtSem);
+ }
+
+ if(omx_base_sink_Private->state == OMX_StateLoaded || omx_base_sink_Private->state == OMX_StateInvalid) {
+ DEBUG(DEB_LEV_FULL_SEQ, "In %s Buffer Management Thread is exiting\n",__func__);
+ break;
+ }
+
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Waiting for input buffer semval=%d \n",pInputSem->semval);
+ if(pInputSem->semval>0 && isInputBufferNeeded==OMX_TRUE ) {
+ omx_tsem_down(pInputSem);
+ if(pInputQueue->nelem>0){
+ inBufExchanged++;
+ isInputBufferNeeded=OMX_FALSE;
+ pInputBuffer = (OMX_BUFFERHEADERTYPE*)omx_dequeue(pInputQueue);
+ if(pInputBuffer == NULL){
+ DEBUG(DEB_LEV_ERR, "Had NULL input buffer!!\n");
+ break;
+ }
+ }
+ }
+
+ if(isInputBufferNeeded==OMX_FALSE) {
+ if(pInputBuffer->nFlags==OMX_BUFFERFLAG_EOS) {
+ DEBUG(DEB_LEV_SIMPLE_SEQ, "Detected EOS flags in input buffer\n");
+
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventBufferFlag, /* The command was completed */
+ 0, /* The commands was a OMX_CommandStateSet */
+ pInputBuffer->nFlags, /* The state has been changed in message->messageParam2 */
+ NULL);
+ pInputBuffer->nFlags=0;
+ }
+
+ target_component=(OMX_COMPONENTTYPE*)pInputBuffer->hMarkTargetComponent;
+ if(target_component==(OMX_COMPONENTTYPE *)openmaxStandComp) {
+ /*Clear the mark and generate an event*/
+ (*(omx_base_component_Private->callbacks->EventHandler))
+ (openmaxStandComp,
+ omx_base_component_Private->callbackData,
+ OMX_EventMark, /* The command was completed */
+ 1, /* The commands was a OMX_CommandStateSet */
+ 0, /* The state has been changed in message->messageParam2 */
+ pInputBuffer->pMarkData);
+ } else if(pInputBuffer->hMarkTargetComponent!=NULL){
+ /*If this is not the target component then pass the mark*/
+ DEBUG(DEB_LEV_FULL_SEQ, "Can't Pass Mark. This is a Sink!!\n");
+ }
+ if (omx_base_sink_Private->BufferMgmtCallback && pInputBuffer->nFilledLen > 0) {
+ (*(omx_base_sink_Private->BufferMgmtCallback))(openmaxStandComp, pInputBuffer);
+ }
+ else {
+ /*If no buffer management call back the explicitly consume input buffer*/
+ DEBUG(DEB_LEV_FULL_SEQ, "If no buffer management call back, explicitly consume input buffer. nInputPortIndex=%d BufferMgmtCallback=0x%p nFilledLen=%d\n",
+ (int)pInputBuffer->nInputPortIndex, omx_base_sink_Private->BufferMgmtCallback, (int)pInputBuffer->nFilledLen);
+ pInputBuffer->nFilledLen = 0;
+ }
+ /*Input Buffer has been completely consumed. So, get new input buffer*/
+
+ if(omx_base_sink_Private->state==OMX_StatePause && !PORT_IS_BEING_FLUSHED(pInPort)) {
+ /*Waiting at paused state*/
+ omx_tsem_wait(omx_base_sink_Private->bStateSem);
+ }
+
+ /*Input Buffer has been completely consumed. So, return input buffer*/
+ if(pInputBuffer->nFilledLen==0) {
+ pInPort->ReturnBufferFunction(pInPort,pInputBuffer);
+ inBufExchanged--;
+ pInputBuffer=NULL;
+ isInputBufferNeeded = OMX_TRUE;
+ }
+
+ }
+ }
+ DEBUG(DEB_LEV_SIMPLE_SEQ,"Exiting Buffer Management Thread\n");
+ return NULL;
+}
diff --git a/alsa/omx_base_sink.h b/alsa/omx_base_sink.h
new file mode 100644
index 0000000..dfe7e9c
--- /dev/null
+++ b/alsa/omx_base_sink.h
@@ -0,0 +1,73 @@
+/**
+ @file src/base/omx_base_sink.h
+
+ OpenMAX base sink component. This component does not perform any multimedia
+ processing. It derives from base component and contains a single port. It can be used
+ as base class for sink components.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-08-28 17:50:08 +0200 (Thu, 28 Aug 2008) $
+ Revision $Rev: 583 $
+ Author $Author: gsent $
+
+*/
+
+#ifndef _OMX_BASE_SINK_COMPONENT_H_
+#define _OMX_BASE_SINK_COMPONENT_H_
+
+//#include <OMX_Types.h>
+//#include <IL/OMX_Component.h>
+//#include <IL/OMX_Core.h>
+#include <pthread.h>
+#include "omx_base_component.h"
+#include <stdlib.h>
+
+
+#define OMX_BASE_SINK_INPUTPORT_INDEX 0 /* The index of the input port for the derived components */
+#define OMX_BASE_SINK_CLOCKPORT_INDEX 1 /* The index of the clock port for the dervied components */
+
+/** OMX_BASE_SINK_ALLPORT_INDEX as the standard specifies, the -1 value for port index is used to point to all the ports
+ */
+#define OMX_BASE_SINK_ALLPORT_INDEX -1
+
+/** base sink component private structure.
+ */
+DERIVEDCLASS(omx_base_sink_PrivateType, omx_base_component_PrivateType)
+#define omx_base_sink_PrivateType_FIELDS omx_base_component_PrivateType_FIELDS \
+ /** @param BufferMgmtCallback function pointer for algorithm callback */ \
+ void (*BufferMgmtCallback)(OMX_COMPONENTTYPE* openmaxStandComp, OMX_BUFFERHEADERTYPE* inputbuffer);
+ENDCLASS(omx_base_sink_PrivateType)
+
+/** Base sink contructor
+ */
+OMX_ERRORTYPE omx_base_sink_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName);
+
+/** The base sink destructor. It simply calls the base destructor
+ */
+OMX_ERRORTYPE omx_base_sink_Destructor(OMX_COMPONENTTYPE *openmaxStandComp);
+
+/** This is the central function for component processing. It
+ * is executed in a separate thread, is synchronized with
+ * semaphores at each port, those are released each time a new buffer
+ * is available on the given port.
+ */
+void* omx_base_sink_BufferMgmtFunction(void* param);
+
+#endif
diff --git a/alsa/omx_classmagic.h b/alsa/omx_classmagic.h
new file mode 100644
index 0000000..2560041
--- /dev/null
+++ b/alsa/omx_classmagic.h
@@ -0,0 +1,100 @@
+/**
+ @file src/base/omx_classmagic.h
+
+ This file contains class handling helper macros
+ It is left as an exercise to the reader how they do the magic (FIXME)
+
+ Usage Rules:
+ 1) include this file
+ 2) if your don't inherit, start your class with CLASS(classname)
+ 3) if you inherit something, start your class with
+ DERIVEDCLASS(classname, inheritedclassname)
+ 4) end your class with ENDCLASS(classname)
+ 5) define your class variables with a #define classname_FIELDS inheritedclassname_FIELDS
+ inside your class and always add a backslash at the end of line (except last)
+ 6) if you want to use doxygen, use C-style comments inside the #define, and
+ enable macro expansion in doxyconf and predefine DOXYGEN_PREPROCESSING there, etc.
+
+ See examples at the end of this file (in #if 0 block)
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-06-27 12:00:23 +0200 (Fri, 27 Jun 2008) $
+ Revision $Rev: 554 $
+ Author $Author: pankaj_sen $
+
+*/
+#ifndef OMX_CLASSMAGIC_H_
+#define OMX_CLASSMAGIC_H_
+
+
+#ifdef DOXYGEN_PREPROCESSING
+#define CLASS(a) class a { public:
+#define DERIVEDCLASS(a, b) class a : public b { public:
+#define ENDCLASS(a) a##_FIELDS };
+#else
+#define CLASS(a) typedef struct a a; \
+ struct a {
+#define DERIVEDCLASS(a, b) typedef struct a a; \
+ struct a {
+#define ENDCLASS(a) a##_FIELDS };
+#endif
+
+#if 0 /*EXAMPLES*/
+/**
+ * Class A is a nice class
+ */
+CLASS(A)
+#define A_FIELDS \
+/** @param a very nice parameter */ \
+ int a; \
+/** @param ash another very nice parameter */ \
+ int ash;
+ENDCLASS(A)
+
+/**
+ * Class B is a nice derived class
+ */
+DERIVEDCLASS(B,A)
+#define B_FIELDS A_FIELDS \
+/** @param b very nice parameter */ \
+ int b;
+ENDCLASS(B)
+
+/**
+ * Class B2 is a nice derived class
+ */
+DERIVEDCLASS(B2,A)
+#define B2_FIELDS A_FIELDS \
+/** @param b2 very nice parameter */ \
+ int b2;
+ENDCLASS(B2)
+
+/**
+ * Class C is an even nicer derived class.
+ */
+DERIVEDCLASS(C,B)
+#define C_FIELDS B_FIELDS \
+/** @param c very nice parameter */ \
+ int c;
+ENDCLASS(C)
+
+#endif /* 0 */
+
+#endif
diff --git a/alsa/omx_comp_debug_levels.h b/alsa/omx_comp_debug_levels.h
new file mode 100644
index 0000000..dda6a79
--- /dev/null
+++ b/alsa/omx_comp_debug_levels.h
@@ -0,0 +1,77 @@
+/**
+ @file src/omx_comp_debug_levels.h
+
+ Define the level of debug prints on standard err. The different levels can
+ be composed with binary OR.
+ The debug levels defined here belong to OpenMAX components and IL core
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-07-16 09:39:31 +0200 (Wed, 16 Jul 2008) $
+ Revision $Rev: 577 $
+ Author $Author: gsent $
+
+*/
+
+#ifndef __OMX_COMP_DEBUG_LEVELS_H__
+#define __OMX_COMP_DEBUG_LEVELS_H__
+
+#include <stdio.h>
+
+/** Remove all debug output lines
+ */
+#define DEB_LEV_NO_OUTPUT 0
+
+/** Messages explaing the reason of critical errors
+ */
+#define DEB_LEV_ERR 1
+
+/** Messages showing values related to the test and the component/s used
+ */
+#define DEB_LEV_PARAMS 2
+
+/** Messages representing steps in the execution. These are the simple messages, because
+ * they avoid iterations
+ */
+#define DEB_LEV_SIMPLE_SEQ 4
+
+/** Messages representing steps in the execution. All the steps are described,
+ * also with iterations. With this level of output the performances are
+ * seriously compromised
+ */
+#define DEB_LEV_FULL_SEQ 8
+
+/** Messages that indicates the beginning and the end of a function.
+ * It can be used to trace the execution
+ */
+#define DEB_LEV_FUNCTION_NAME 16
+
+/** All the messages - max value
+ */
+#define DEB_ALL_MESS 255
+
+/** \def DEBUG_LEVEL is the current level do debug output on standard err */
+#define DEBUG_LEVEL (DEB_ALL_MESS)
+#if DEBUG_LEVEL > 0
+#define DEBUG(n, fmt, args...) do { if (DEBUG_LEVEL & (n)){fprintf(stdout, "OMX-" fmt, ##args);} } while (0)
+#else
+#define DEBUG(n, fmt, args...)
+#endif
+
+#endif
diff --git a/alsa/omx_loader_XBMC.cpp b/alsa/omx_loader_XBMC.cpp
new file mode 100644
index 0000000..5ea1855
--- /dev/null
+++ b/alsa/omx_loader_XBMC.cpp
@@ -0,0 +1,69 @@
+
+#include "omx_loader_XBMC.h"
+#include <omx_alsasink_component.h>
+
+OMX_ERRORTYPE OMX_GetHandle_XBMC(OMX_OUT OMX_HANDLETYPE* pHandle,
+ OMX_IN OMX_STRING cComponentName,
+ OMX_IN OMX_PTR pAppData,
+ OMX_IN OMX_CALLBACKTYPE* pCallBacks)
+{
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ OMX_COMPONENTTYPE* openmaxStandComp;
+ omx_base_component_PrivateType* priv;
+
+ if(!strcmp("OMX.XBMC.alsa.alsasink", cComponentName))
+ {
+ openmaxStandComp = (OMX_COMPONENTTYPE*)calloc(1,sizeof(OMX_COMPONENTTYPE));
+ if (!openmaxStandComp) {
+ return OMX_ErrorInsufficientResources;
+ }
+
+ err = omx_alsasink_component_Constructor(openmaxStandComp,cComponentName);
+ if (err != OMX_ErrorNone)
+ {
+ if (err == OMX_ErrorInsufficientResources)
+ {
+ *pHandle = openmaxStandComp;
+ priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
+ return OMX_ErrorInsufficientResources;
+ }
+ DEBUG(DEB_LEV_ERR, "Error during component construction\n");
+ openmaxStandComp->ComponentDeInit(openmaxStandComp);
+ free(openmaxStandComp);
+ openmaxStandComp = NULL;
+ return OMX_ErrorComponentNotFound;
+ }
+ priv = (omx_base_component_PrivateType *) openmaxStandComp->pComponentPrivate;
+
+ *pHandle = openmaxStandComp;
+ ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
+ }
+ else
+ {
+ err = OMX_ErrorComponentNotFound;
+ }
+
+ return err;
+}
+
+
+OMX_ERRORTYPE OMX_FreeHandle_XBMC(OMX_IN OMX_HANDLETYPE hComponent)
+{
+ int i;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ omx_base_component_PrivateType * priv = (omx_base_component_PrivateType *) ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+
+ if(!strcmp("OMX.XBMC.alsa.alsasink", priv->name))
+ {
+ err = ((OMX_COMPONENTTYPE*)hComponent)->ComponentDeInit(hComponent);
+
+ free((OMX_COMPONENTTYPE*)hComponent);
+ hComponent = NULL;
+ }
+ else
+ {
+ err = OMX_ErrorComponentNotFound;
+ }
+
+ return err;
+}
\ No newline at end of file
diff --git a/alsa/omx_loader_XBMC.h b/alsa/omx_loader_XBMC.h
new file mode 100644
index 0000000..c835043
--- /dev/null
+++ b/alsa/omx_loader_XBMC.h
@@ -0,0 +1,27 @@
+#pragma once
+
+
+#ifndef __OMX_LOADER_XBMC__
+#define __OMX_LOADER_XBMC__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#pragma pack(4)
+#include <IL/OMX_Component.h>
+#include <IL/OMX_Types.h>
+#pragma pack()
+
+OMX_ERRORTYPE OMX_GetHandle_XBMC(OMX_OUT OMX_HANDLETYPE* pHandle,
+ OMX_IN OMX_STRING cComponentName,
+ OMX_IN OMX_PTR pAppData,
+ OMX_IN OMX_CALLBACKTYPE* pCallBacks);
+
+OMX_ERRORTYPE OMX_FreeHandle_XBMC(OMX_IN OMX_HANDLETYPE hComponent);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
diff --git a/alsa/omx_queue.cpp b/alsa/omx_queue.cpp
new file mode 100644
index 0000000..e4ecd25
--- /dev/null
+++ b/alsa/omx_queue.cpp
@@ -0,0 +1,136 @@
+/**
+ @file src/queue.c
+
+ Implements a simple LIFO structure used for queueing OMX buffers.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-06-27 12:00:23 +0200 (Fri, 27 Jun 2008) $
+ Revision $Rev: 554 $
+ Author $Author: pankaj_sen $
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "omx_queue.h"
+#include "omx_comp_debug_levels.h"
+
+/** Initialize a queue descriptor
+ *
+ * @param queue The queue descriptor to initialize.
+ * The user needs to allocate the queue
+ */
+void omx_queue_init(omx_queue_t* queue) {
+ int i;
+ omx_qelem_t* newelem;
+ omx_qelem_t* current;
+ queue->first = (omx_qelem_t*)malloc(sizeof(omx_qelem_t));
+ memset(queue->first, 0, sizeof(omx_qelem_t));
+ current = queue->last = queue->first;
+ queue->nelem = 0;
+ for (i = 0; i<MAX_QUEUE_ELEMENTS - 2; i++) {
+ newelem = (omx_qelem_t*)malloc(sizeof(omx_qelem_t));
+ memset(newelem, 0, sizeof(omx_qelem_t));
+ current->q_forw = newelem;
+ current = newelem;
+ }
+ current->q_forw = queue->first;
+
+ pthread_mutex_init(&queue->mutex, NULL);
+}
+
+/** Deinitialize a queue descriptor
+ * flushing all of its internal data
+ *
+ * @param queue the queue descriptor to dump
+ */
+void omx_queue_deinit(omx_queue_t* queue) {
+ int i;
+ omx_qelem_t* current;
+ current = queue->first;
+ for (i = 0; i<MAX_QUEUE_ELEMENTS - 2; i++) {
+ if (current != NULL) {
+ current = current->q_forw;
+ free(queue->first);
+ queue->first = current;
+ }
+ }
+ if(queue->first) {
+ free(queue->first);
+ queue->first = NULL;
+ }
+ pthread_mutex_destroy(&queue->mutex);
+}
+
+/** Enqueue an element to the given queue descriptor
+ *
+ * @param queue the queue descritpor where to queue data
+ *
+ * @param data the data to be enqueued
+ */
+void omx_queue(omx_queue_t* queue, void* data) {
+ if (queue->last->data != NULL) {
+ DEBUG(DEB_LEV_ERR, "In %s ERROR! Full queue\n",__func__);
+ return;
+ }
+ pthread_mutex_lock(&queue->mutex);
+ queue->last->data = data;
+ queue->last = queue->last->q_forw;
+ queue->nelem++;
+ pthread_mutex_unlock(&queue->mutex);
+}
+
+/** Dequeue an element from the given queue descriptor
+ *
+ * @param queue the queue descriptor from which to dequeue the element
+ *
+ * @return the element that has bee dequeued. If the queue is empty
+ * a NULL value is returned
+ */
+void* omx_dequeue(omx_queue_t* queue) {
+ void* data;
+ if (queue->first->data == NULL) {
+ DEBUG(DEB_LEV_ERR, "In %s ERROR! Empty queue\n",__func__);
+ return NULL;
+ }
+ pthread_mutex_lock(&queue->mutex);
+ data = queue->first->data;
+ queue->first->data = NULL;
+ queue->first = queue->first->q_forw;
+ queue->nelem--;
+ pthread_mutex_unlock(&queue->mutex);
+
+ return data;
+}
+
+/** Returns the number of elements hold in the queue
+ *
+ * @param queue the requested queue
+ *
+ * @return the number of elements in the queue
+ */
+int omx_getquenelem(omx_queue_t* queue) {
+ int qelem;
+ pthread_mutex_lock(&queue->mutex);
+ qelem = queue->nelem;
+ pthread_mutex_unlock(&queue->mutex);
+ return qelem;
+}
diff --git a/alsa/omx_queue.h b/alsa/omx_queue.h
new file mode 100644
index 0000000..bf80f90
--- /dev/null
+++ b/alsa/omx_queue.h
@@ -0,0 +1,94 @@
+/**
+ @file src/omx_queue.h
+
+ Implements a simple LIFO structure used for queueing OMX buffers.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-06-27 12:00:23 +0200 (Fri, 27 Jun 2008) $
+ Revision $Rev: 554 $
+ Author $Author: pankaj_sen $
+*/
+
+#pragma once
+
+#ifndef __OMX_QUEUE_H__
+#define __OMX_QUEUE_H__
+
+#include <pthread.h>
+/** Maximum number of elements in a queue
+ */
+#define MAX_QUEUE_ELEMENTS 20
+/** Output port queue element. Contains an OMX buffer header type
+ */
+typedef struct omx_qelem_t omx_qelem_t;
+struct omx_qelem_t{
+ omx_qelem_t* q_forw;
+ void* data;
+};
+
+/** This structure contains the queue
+ */
+typedef struct omx_queue_t{
+ omx_qelem_t* first; /**< Output buffer queue head */
+ omx_qelem_t* last; /**< Output buffer queue tail */
+ int nelem; /**< Number of elements in the queue */
+ pthread_mutex_t mutex;
+} omx_queue_t;
+
+/** Initialize a queue descriptor
+ *
+ * @param queue The queue descriptor to initialize.
+ * The user needs to allocate the queue
+ */
+void omx_queue_init(omx_queue_t* queue);
+
+/** Deinitialize a queue descriptor
+ * flushing all of its internal data
+ *
+ * @param queue the queue descriptor to dump
+ */
+void omx_queue_deinit(omx_queue_t* queue);
+
+/** Enqueue an element to the given queue descriptor
+ *
+ * @param queue the queue descritpor where to queue data
+ *
+ * @param data the data to be enqueued
+ */
+void omx_queue(omx_queue_t* queue, void* data);
+
+/** Dequeue an element from the given queue descriptor
+ *
+ * @param queue the queue descriptor from which to dequeue the element
+ *
+ * @return the element that has bee dequeued. If the queue is empty
+ * a NULL value is returned
+ */
+void* omx_dequeue(omx_queue_t* queue);
+
+/** Returns the number of elements hold in the queue
+ *
+ * @param queue the requested queue
+ *
+ * @return the number of elements in the queue
+ */
+int omx_getquenelem(omx_queue_t* queue);
+
+#endif
diff --git a/alsa/omx_semaphore.cpp b/alsa/omx_semaphore.cpp
new file mode 100644
index 0000000..eca3a0f
--- /dev/null
+++ b/alsa/omx_semaphore.cpp
@@ -0,0 +1,111 @@
+/**
+ @file src/tsemaphore.c
+
+ Implements a simple inter-thread semaphore so not to have to deal with IPC
+ creation and the like.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-06-27 12:00:23 +0200 (Fri, 27 Jun 2008) $
+ Revision $Rev: 554 $
+ Author $Author: pankaj_sen $
+*/
+
+#include <pthread.h>
+#include <sys/time.h>
+#include <errno.h>
+#include "omx_semaphore.h"
+//#include "omx_comp_debug_levels.h"
+
+/** Initializes the semaphore at a given value
+ *
+ * @param tsem the semaphore to initialize
+ * @param val the initial value of the semaphore
+ *
+ */
+void omx_tsem_init(omx_tsem_t* tsem, unsigned int val) {
+ pthread_cond_init(&tsem->condition, NULL);
+ pthread_mutex_init(&tsem->mutex, NULL);
+ tsem->semval = val;
+}
+
+/** Destroy the semaphore
+ *
+ * @param tsem the semaphore to destroy
+ */
+void omx_tsem_deinit(omx_tsem_t* tsem) {
+ pthread_cond_destroy(&tsem->condition);
+ pthread_mutex_destroy(&tsem->mutex);
+}
+
+/** Decreases the value of the semaphore. Blocks if the semaphore
+ * value is zero.
+ *
+ * @param tsem the semaphore to decrease
+ */
+void omx_tsem_down(omx_tsem_t* tsem) {
+ pthread_mutex_lock(&tsem->mutex);
+ while (tsem->semval == 0) {
+ pthread_cond_wait(&tsem->condition, &tsem->mutex);
+ }
+ tsem->semval--;
+ pthread_mutex_unlock(&tsem->mutex);
+}
+
+/** Increases the value of the semaphore
+ *
+ * @param tsem the semaphore to increase
+ */
+void omx_tsem_up(omx_tsem_t* tsem) {
+ pthread_mutex_lock(&tsem->mutex);
+ tsem->semval++;
+ pthread_cond_signal(&tsem->condition);
+ pthread_mutex_unlock(&tsem->mutex);
+}
+
+/** Reset the value of the semaphore
+ *
+ * @param tsem the semaphore to reset
+ */
+void omx_tsem_reset(omx_tsem_t* tsem) {
+ pthread_mutex_lock(&tsem->mutex);
+ tsem->semval=0;
+ pthread_mutex_unlock(&tsem->mutex);
+}
+
+/** Wait on the condition.
+ *
+ * @param tsem the semaphore to wait
+ */
+void omx_tsem_wait(omx_tsem_t* tsem) {
+ pthread_mutex_lock(&tsem->mutex);
+ pthread_cond_wait(&tsem->condition, &tsem->mutex);
+ pthread_mutex_unlock(&tsem->mutex);
+}
+
+/** Signal the condition,if waiting
+ *
+ * @param tsem the semaphore to signal
+ */
+void omx_tsem_signal(omx_tsem_t* tsem) {
+ pthread_mutex_lock(&tsem->mutex);
+ pthread_cond_signal(&tsem->condition);
+ pthread_mutex_unlock(&tsem->mutex);
+}
+
diff --git a/alsa/omx_semaphore.h b/alsa/omx_semaphore.h
new file mode 100644
index 0000000..1e3f3db
--- /dev/null
+++ b/alsa/omx_semaphore.h
@@ -0,0 +1,92 @@
+/**
+ @file src/omx_semaphore.h
+
+ Implements a simple inter-thread semaphore so not to have to deal with IPC
+ creation and the like.
+
+ Copyright (C) 2007-2008 STMicroelectronics
+ Copyright (C) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
+
+ This library is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 2.1 of the License, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA
+
+ $Date: 2008-06-27 12:00:23 +0200 (Fri, 27 Jun 2008) $
+ Revision $Rev: 554 $
+ Author $Author: pankaj_sen $
+
+*/
+
+#pragma once
+
+#ifndef __OMX_SEMAPHORE_H__
+#define __OMX_SEMAPHORE_H__
+
+#include <pthread.h>
+#include <semaphore.h>
+
+/** The structure contains the semaphore value, mutex and green light flag
+ */
+typedef struct omx_tsem_t {
+ pthread_cond_t condition;
+ pthread_mutex_t mutex;
+ unsigned int semval;
+} omx_tsem_t;
+
+/** Initializes the semaphore at a given value
+ *
+ * @param tsem the semaphore to initialize
+ *
+ * @param val the initial value of the semaphore
+ */
+void omx_tsem_init(omx_tsem_t* tsem, unsigned int val);
+
+/** Destroy the semaphore
+ *
+ * @param tsem the semaphore to destroy
+ */
+void omx_tsem_deinit(omx_tsem_t* tsem);
+
+/** Decreases the value of the semaphore. Blocks if the semaphore
+ * value is zero.
+ *
+ * @param tsem the semaphore to decrease
+ */
+void omx_tsem_down(omx_tsem_t* tsem);
+
+/** Increases the value of the semaphore
+ *
+ * @param tsem the semaphore to increase
+ */
+void omx_tsem_up(omx_tsem_t* tsem);
+
+/** Reset the value of the semaphore
+ *
+ * @param tsem the semaphore to reset
+ */
+void omx_tsem_reset(omx_tsem_t* tsem);
+
+/** Wait on the condition.
+ *
+ * @param tsem the semaphore to wait
+ */
+void omx_tsem_wait(omx_tsem_t* tsem);
+
+/** Signal the condition,if waiting
+ *
+ * @param tsem the semaphore to signal
+ */
+void omx_tsem_signal(omx_tsem_t* tsem);
+
+#endif
diff --git a/omxplayer.cpp b/omxplayer.cpp
index b554a58..3e5b99b 100644
--- a/omxplayer.cpp
+++ b/omxplayer.cpp
@@ -699,7 +699,7 @@ int main(int argc, char *argv[])
break;
case 'o':
m_config_audio.device = optarg;
- if(m_config_audio.device != "local" && m_config_audio.device != "hdmi" && m_config_audio.device != "both")
+ if(m_config_audio.device != "local" && m_config_audio.device != "hdmi" && m_config_audio.device != "both" && m_config_audio.device != "alsa")
{
print_usage();
return 0;
|