summaryrefslogtreecommitdiff
path: root/software/octdeviceapi/oct6100api/oct6100_api/oct6100_playout_buf.c
blob: 433c87c7016c5aa8344d7c55c2b6a9ecd949a590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

File: oct6100_playout_buf.c

    Copyright (c) 2001-2011 Octasic Inc.
    
Description: 

	This file contains functions used to manage buffer playout.

This file is part of the Octasic OCT6100 GPL API . The OCT6100 GPL API  is 
free software; you can redistribute it and/or modify it under the terms of 
the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

The OCT6100 GPL API 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 General Public License 
for more details. 

You should have received a copy of the GNU General Public License 
along with the OCT6100 GPL API; if not, write to the Free Software 
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

$Octasic_Release: OCT612xAPI-01.04.05 $

$Octasic_Revision: 110 $

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/


/*****************************  INCLUDE FILES  *******************************/

#include "octdef.h"

#include "oct6100api/oct6100_defines.h"
#include "oct6100api/oct6100_errors.h"
#include "oct6100api/oct6100_apiud.h"

#include "apilib/octapi_llman.h"

#include "oct6100api/oct6100_tlv_inst.h"
#include "oct6100api/oct6100_chip_open_inst.h"
#include "oct6100api/oct6100_chip_stats_inst.h"
#include "oct6100api/oct6100_interrupts_inst.h"
#include "oct6100api/oct6100_remote_debug_inst.h"
#include "oct6100api/oct6100_debug_inst.h"
#include "oct6100api/oct6100_api_inst.h"
#include "oct6100api/oct6100_channel_inst.h"
#include "oct6100api/oct6100_playout_buf_inst.h"

#include "oct6100api/oct6100_interrupts_pub.h"
#include "oct6100api/oct6100_chip_open_pub.h"
#include "oct6100api/oct6100_channel_pub.h"
#include "oct6100api/oct6100_events_pub.h"
#include "oct6100api/oct6100_playout_buf_pub.h"

#include "oct6100_chip_open_priv.h"
#include "oct6100_miscellaneous_priv.h"
#include "oct6100_memory_priv.h"
#include "oct6100_channel_priv.h"
#include "oct6100_events_priv.h"
#include "oct6100_playout_buf_priv.h"

/****************************  PUBLIC FUNCTIONS  *****************************/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutLoad

Description:    This function loads a playout buffer into external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferLoad			Pointer to buffer playout load structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutLoadDef(
				tPOCT6100_BUFFER_LOAD			f_pBufferLoad )
{
	f_pBufferLoad->pbyBufferPattern = NULL;
	f_pBufferLoad->ulBufferSize = 128;
	f_pBufferLoad->ulBufferPcmLaw = cOCT6100_PCM_U_LAW;
	
	f_pBufferLoad->pulBufferIndex = NULL;
	f_pBufferLoad->pulPlayoutFreeMemSize = NULL;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutLoad(
				tPOCT6100_INSTANCE_API				f_pApiInstance,
				tPOCT6100_BUFFER_LOAD				f_pBufferLoad )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferLoadSer( f_pApiInstance, f_pBufferLoad, TRUE, cOCT6100_INVALID_INDEX );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutLoadBlockInit

Description:    This function allows the user to initialize loading a buffer 
				into external memory using blocks.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep 
						the present state of the chip and all its resources.

f_pBufferLoadBlockInit	Pointer to buffer playout load block init structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutLoadBlockInitDef(
				tPOCT6100_BUFFER_LOAD_BLOCK_INIT	f_pBufferLoadBlockInit )
{
	f_pBufferLoadBlockInit->ulBufferSize = 128;
	f_pBufferLoadBlockInit->ulBufferPcmLaw = cOCT6100_PCM_U_LAW;
	
	f_pBufferLoadBlockInit->pulBufferIndex = NULL;
	f_pBufferLoadBlockInit->pulPlayoutFreeMemSize = NULL;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutLoadBlockInit(
				tPOCT6100_INSTANCE_API				f_pApiInstance,
				tPOCT6100_BUFFER_LOAD_BLOCK_INIT	f_pBufferLoadBlockInit )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure.*/
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferLoadBlockInitSer( f_pApiInstance, f_pBufferLoadBlockInit );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutLoadBlock

Description:	This function allows the user to load a buffer block into 
				external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep 
						the present state of the chip and all its resources.

f_pBufferLoadBlock		Pointer to buffer playout load block structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutLoadBlockDef(
				tPOCT6100_BUFFER_LOAD_BLOCK		f_pBufferLoadBlock )
{
	f_pBufferLoadBlock->ulBufferIndex = cOCT6100_INVALID_VALUE;
	f_pBufferLoadBlock->ulBlockLength = cOCT6100_INVALID_VALUE;
	f_pBufferLoadBlock->ulBlockOffset = cOCT6100_INVALID_VALUE;
	
	f_pBufferLoadBlock->pbyBufferPattern = NULL;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutLoadBlock(
				tPOCT6100_INSTANCE_API				f_pApiInstance,
				tPOCT6100_BUFFER_LOAD_BLOCK			f_pBufferLoadBlock )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferLoadBlockSer( f_pApiInstance, f_pBufferLoadBlock );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutUnload

Description:    This function unloads a playout buffer from external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferUnload			Pointer to buffer playout unload structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutUnloadDef(
				tPOCT6100_BUFFER_UNLOAD			f_pBufferUnload )
{
	f_pBufferUnload->ulBufferIndex = cOCT6100_INVALID_VALUE;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutUnload(
				tPOCT6100_INSTANCE_API			f_pApiInstance,
				tPOCT6100_BUFFER_UNLOAD			f_pBufferUnload )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferUnloadSer( f_pApiInstance, f_pBufferUnload, TRUE );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutAdd

Description:    This function adds a buffer to a port's playout list on the 
				selected channel.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutAdd		Pointer to buffer playout add structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutAddDef(
				tPOCT6100_BUFFER_PLAYOUT_ADD			f_pBufferPlayoutAdd )
{
	f_pBufferPlayoutAdd->ulChannelHndl = cOCT6100_INVALID_HANDLE;
	f_pBufferPlayoutAdd->ulBufferIndex = cOCT6100_INVALID_VALUE;

	f_pBufferPlayoutAdd->ulPlayoutPort = cOCT6100_CHANNEL_PORT_ROUT;
	f_pBufferPlayoutAdd->ulMixingMode = cOCT6100_MIXING_MINUS_6_DB;
	f_pBufferPlayoutAdd->lGainDb = 0;

	f_pBufferPlayoutAdd->fRepeat = FALSE;
	f_pBufferPlayoutAdd->ulRepeatCount = cOCT6100_REPEAT_INFINITELY;

	f_pBufferPlayoutAdd->ulDuration = cOCT6100_INVALID_VALUE;
	
	f_pBufferPlayoutAdd->ulBufferLength = cOCT6100_AUTO_SELECT;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutAdd(
				tPOCT6100_INSTANCE_API					f_pApiInstance,
				tPOCT6100_BUFFER_PLAYOUT_ADD			f_pBufferPlayoutAdd )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferPlayoutAddSer( f_pApiInstance, f_pBufferPlayoutAdd );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutStart

Description:    This function enables playout of the specified buffer on the 
				requested channel.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutStart	Pointer to buffer playout start structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutStartDef(
				tPOCT6100_BUFFER_PLAYOUT_START	f_pBufferPlayoutStart )
{
	f_pBufferPlayoutStart->ulChannelHndl = cOCT6100_INVALID_HANDLE;
	f_pBufferPlayoutStart->ulPlayoutPort = cOCT6100_CHANNEL_PORT_ROUT;
	f_pBufferPlayoutStart->fNotifyOnPlayoutStop = FALSE;
	f_pBufferPlayoutStart->ulUserEventId = cOCT6100_INVALID_VALUE;
	f_pBufferPlayoutStart->fAllowStartWhileActive = FALSE;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutStart(
				tPOCT6100_INSTANCE_API				f_pApiInstance,
				tPOCT6100_BUFFER_PLAYOUT_START		f_pBufferPlayoutStart )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferPlayoutStartSer( f_pApiInstance, f_pBufferPlayoutStart, cOCT6100_BUFFER_PLAYOUT_EVENT_STOP );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutStop

Description:    This function disables playout of a buffer on the specified 
				channel.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutStop	Pointer to buffer playout stop structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutStopDef(
				tPOCT6100_BUFFER_PLAYOUT_STOP	f_pBufferPlayoutStop )
{
	f_pBufferPlayoutStop->ulChannelHndl = cOCT6100_INVALID_HANDLE;
	f_pBufferPlayoutStop->ulPlayoutPort = cOCT6100_CHANNEL_PORT_ROUT;
	f_pBufferPlayoutStop->fStopCleanly = TRUE;
	f_pBufferPlayoutStop->pfAlreadyStopped = NULL;
	f_pBufferPlayoutStop->pfNotifyOnPlayoutStop = NULL;

	return cOCT6100_ERR_OK;
}

UINT32 Oct6100BufferPlayoutStop(
				tPOCT6100_INSTANCE_API				f_pApiInstance,
				tPOCT6100_BUFFER_PLAYOUT_STOP	f_pBufferPlayoutStop )
{
	tOCT6100_SEIZE_SERIALIZE_OBJECT		SeizeSerObj;
	tOCT6100_RELEASE_SERIALIZE_OBJECT	ReleaseSerObj;
	UINT32								ulSerRes = cOCT6100_ERR_OK;
	UINT32								ulFncRes = cOCT6100_ERR_OK;

	/* Set the process context of the serialize structure. */
	SeizeSerObj.pProcessContext = f_pApiInstance->pProcessContext;
	ReleaseSerObj.pProcessContext = f_pApiInstance->pProcessContext;

	/* Seize all list semaphores needed by this function. */
	SeizeSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	SeizeSerObj.ulTryTimeMs = cOCT6100_WAIT_INFINITELY;
	ulSerRes = Oct6100UserSeizeSerializeObject( &SeizeSerObj );
	if ( ulSerRes == cOCT6100_ERR_OK )
	{
		/* Call the serialized function. */
		ulFncRes = Oct6100BufferPlayoutStopSer( f_pApiInstance, f_pBufferPlayoutStop );
	}
	else
	{
		return ulSerRes;
	}

	/* Release the seized semaphores. */
	ReleaseSerObj.ulSerialObjHndl = f_pApiInstance->ulApiSerObj;
	ulSerRes = Oct6100UserReleaseSerializeObject( &ReleaseSerObj );

	/* If an error occured then return the error code. */
	if ( ulSerRes != cOCT6100_ERR_OK )
		return ulSerRes;
	if ( ulFncRes != cOCT6100_ERR_OK )
		return ulFncRes;

	return cOCT6100_ERR_OK;
}


/****************************  PRIVATE FUNCTIONS  ****************************/

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiGetPlayoutBufferSwSizes

Description:    Gets the sizes of all portions of the API instance pertinent
				to the management of playout buffers.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pOpenChip				Pointer to chip configuration struct.
f_pInstSizes			Pointer to struct containing instance sizes.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiGetPlayoutBufferSwSizes(
				IN		tPOCT6100_CHIP_OPEN				f_pOpenChip,
				OUT		tPOCT6100_API_INSTANCE_SIZES	f_pInstSizes )
{
	UINT32	ulTempVar;
	UINT32	ulResult;

	/* Calculate memory needed for playout buffer list. */
	f_pInstSizes->ulPlayoutBufList = f_pOpenChip->ulMaxPlayoutBuffers * sizeof( tOCT6100_API_BUFFER );

	f_pInstSizes->ulPlayoutBufMemoryNodeList = 0;
	
	/* Calculate memory needed for playout buffer allocation software. */
	if ( f_pOpenChip->ulMaxPlayoutBuffers > 0 )
	{
		ulResult = OctapiLlmAllocGetSize( f_pOpenChip->ulMaxPlayoutBuffers, &f_pInstSizes->ulPlayoutBufAlloc );
		if ( ulResult != cOCT6100_ERR_OK )
			return cOCT6100_ERR_FATAL_3C;
		
		f_pInstSizes->ulPlayoutBufMemoryNodeList = (( 2 * f_pOpenChip->ulMaxPlayoutBuffers) + 1 ) * sizeof( tOCT6100_API_BUFFER_PLAYOUT_MALLOC_NODE );
	}
	else
	{
		f_pInstSizes->ulPlayoutBufAlloc  = 0;
	}

	/* Calculate memory needed for list and allocation software serialization. */
	mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulPlayoutBufList, ulTempVar )
	mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulPlayoutBufAlloc, ulTempVar )
	mOCT6100_ROUND_MEMORY_SIZE( f_pInstSizes->ulPlayoutBufMemoryNodeList, ulTempVar )

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiPlayoutBufferSwInit

Description:    Initializes all elements of the instance structure associated
				to playout buffers.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep
						the present state of the chip and all its resources.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiPlayoutBufferSwInit(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance )
{
	tPOCT6100_SHARED_INFO			pSharedInfo;
	tPOCT6100_API_BUFFER			pBufferList;
	PVOID	pBufferPlayoutAlloc;
	UINT32	ulMaxBufferPlayout;
	UINT32	ulResult, i;

	/* Get local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	/* Get the maximum number of buffer playout. */
	ulMaxBufferPlayout = pSharedInfo->ChipConfig.usMaxPlayoutBuffers;

	/* Set all entries in the buffer playout list to unused. */
	mOCT6100_GET_BUFFER_LIST_PNT( pSharedInfo, pBufferList )

	for ( i = 0; i < ulMaxBufferPlayout; i++ )
	{
		pBufferList[ i ].fReserved = FALSE;
		pBufferList[ i ].ulBufferSize = 0;
		pBufferList[ i ].ulBufferBase = cOCT6100_INVALID_VALUE;
		pBufferList[ i ].usDependencyCnt = 0;
		pBufferList[ i ].byBufferPcmLaw = cOCT6100_PCM_U_LAW;
		
	}

	/* Initialize the buffer playout allocation software to "all free". */
	if ( ulMaxBufferPlayout > 0 )
	{
		mOCT6100_GET_BUFFER_ALLOC_PNT( pSharedInfo, pBufferPlayoutAlloc )
		
		ulResult = OctapiLlmAllocInit( &pBufferPlayoutAlloc, ulMaxBufferPlayout );
		if ( ulResult != cOCT6100_ERR_OK )
			return cOCT6100_ERR_FATAL_3D;
	}

	/* Initialize the amount of free memory used by playout. */
	f_pApiInstance->pSharedInfo->ChipStats.ulPlayoutMemUsed = 0;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferLoadSer

Description:    Loads a buffer in external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferLoad			Pointer to buffer configuration structure. The handle
						identifying the buffer in all future function calls is
						returned in this structure.
						
f_fReserveListStruct	Flag indicating if a list structure should be reserved
						or if the structure has been reserved before.  If this
						is set, the f_ulBufIndex variable must also be set.

f_ulBufIndex			If the f_fReserveListStruct flag is set, this index
						will identify the buffer playout list structure
						that must be used to load the specified buffer.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferLoadSer(
				IN OUT	tPOCT6100_INSTANCE_API		f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_LOAD		f_pBufferLoad,
				IN		BOOL						f_fReserveListStruct, 
				IN		UINT32						f_ulBufIndex )
{
	UINT32	ulBufferIndex;
	UINT32	ulBufferBase;
	UINT32	ulResult;

	/* Check the user's configuration of the buffer for errors. */
	ulResult = Oct6100ApiCheckBufferParams( f_pApiInstance, f_pBufferLoad, TRUE );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Reserve all resources needed by the buffer. */
	ulResult = Oct6100ApiReserveBufferResources( f_pApiInstance, f_pBufferLoad, f_fReserveListStruct, f_ulBufIndex, &ulBufferIndex, &ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	/* Write the buffer in external memory. */
	ulResult = Oct6100ApiWriteBufferInMemory( f_pApiInstance, ulBufferBase, f_pBufferLoad->ulBufferSize, f_pBufferLoad->pbyBufferPattern );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Update the new buffer's entry in the buffer list. */
	ulResult = Oct6100ApiUpdateBufferEntry( f_pApiInstance, f_pBufferLoad, ulBufferIndex, ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferLoadBlockInitSer

Description:    Reserve resources for loading a buffer into external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep 
						the present state of the chip and all its resources.

f_pBufferLoadBlockInit	Pointer to buffer configuration structure. The 
						handle identifying the buffer in all future 
						function calls is returned in this structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferLoadBlockInitSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_LOAD_BLOCK_INIT	f_pBufferLoadBlockInit )
{
	UINT32					ulBufferIndex;
	UINT32					ulBufferBase;
	UINT32					ulResult;
	tOCT6100_BUFFER_LOAD	BufferLoad;

	Oct6100BufferPlayoutLoadDef( &BufferLoad );

	/* Not to replicate the code, we use the BufferLoad functions directly. */
	BufferLoad.pulBufferIndex			= f_pBufferLoadBlockInit->pulBufferIndex;
	BufferLoad.pulPlayoutFreeMemSize	= f_pBufferLoadBlockInit->pulPlayoutFreeMemSize;
	BufferLoad.ulBufferPcmLaw			= f_pBufferLoadBlockInit->ulBufferPcmLaw;
	BufferLoad.ulBufferSize				= f_pBufferLoadBlockInit->ulBufferSize;
	BufferLoad.pbyBufferPattern			= NULL;  /* Must not check this for now */

	/* Check the user's configuration of the buffer for errors, but do */
	/* not check if the buffer pointer is NULL.  It is NULL for sure! */
	ulResult = Oct6100ApiCheckBufferParams( f_pApiInstance, &BufferLoad, FALSE );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Reserve all resources needed by the buffer. */
	ulResult = Oct6100ApiReserveBufferResources( f_pApiInstance, &BufferLoad, TRUE, cOCT6100_INVALID_INDEX, &ulBufferIndex, &ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Update the new buffer's entry in the buffer list. */
	ulResult = Oct6100ApiUpdateBufferEntry( f_pApiInstance, &BufferLoad, ulBufferIndex, ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferLoadBlockSer

Description:    Loads a buffer in external memory using blocks.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep 
						the present state of the chip and all its resources.

f_pBufferLoadBlock		Pointer to buffer block to be loaded into external 
						memory descriptor. 

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferLoadBlockSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_LOAD_BLOCK			f_pBufferLoadBlock )
{
	UINT32	ulBufferBase;
	UINT32	ulResult;

	/* Check the user's configuration for errors. */
	ulResult = Oct6100ApiCheckBufferLoadBlockParams( f_pApiInstance, f_pBufferLoadBlock, &ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Write the buffer in external memory at the appropriate offset - must do some pointer arithmetic. */
	ulResult = Oct6100ApiWriteBufferInMemory( f_pApiInstance, ulBufferBase + f_pBufferLoadBlock->ulBlockOffset, 
					f_pBufferLoadBlock->ulBlockLength, f_pBufferLoadBlock->pbyBufferPattern + f_pBufferLoadBlock->ulBlockOffset );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiCheckBufferParams

Description:    Checks the user's buffer playout load configuration for errors.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferLoad			Pointer to buffer configuration structure.
f_fCheckBufferPtr		Check if the buffer pointer is NULL or not.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiCheckBufferParams(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_LOAD			f_pBufferLoad,
				IN		BOOL							f_fCheckBufferPtr )
{
	/* Check for errors. */
	if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers == 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_DISABLED;

	if ( f_pApiInstance->pSharedInfo->ImageInfo.fBufferPlayout == FALSE )
		return cOCT6100_ERR_NOT_SUPPORTED_BUFFER_PLAYOUT;

	if ( f_pBufferLoad->pulBufferIndex == NULL )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_INDEX;

	if( f_fCheckBufferPtr )
	{
		if ( f_pBufferLoad->pbyBufferPattern == NULL )
			return cOCT6100_ERR_BUFFER_PLAYOUT_PATTERN;
	}

	if ( f_pBufferLoad->ulBufferSize < cOCT6100_MINIMUM_BUFFER_SIZE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_TOO_SMALL;

	if ( ( f_pBufferLoad->ulBufferSize % cOCT6100_BUFFER_SIZE_GRANULARITY ) != 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_SIZE;

	if ( f_pBufferLoad->ulBufferPcmLaw != cOCT6100_PCM_U_LAW && 
		 f_pBufferLoad->ulBufferPcmLaw != cOCT6100_PCM_A_LAW )
		return cOCT6100_ERR_BUFFER_PLAYOUT_PCM_LAW;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiCheckBufferLoadBlockParams

Description:    Checks the user's buffer playout load block configuration for 
				errors.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferLoadBlock		Pointer to buffer block descriptor.
f_pulBufferBase			Pointer to the base address of the buffer in external 
						memory.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiCheckBufferLoadBlockParams(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN		tPOCT6100_BUFFER_LOAD_BLOCK		f_pBufferLoadBlock,
				OUT		PUINT32							f_pulBufferBase )
{
	/* Check for errors. */
	tPOCT6100_API_BUFFER	pBufEntry;

	if ( f_pBufferLoadBlock->ulBufferIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_INDEX;

	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufEntry, f_pBufferLoadBlock->ulBufferIndex )

	if ( pBufEntry->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOT_OPEN;

	if ( ( f_pBufferLoadBlock->ulBlockLength % 2 ) != 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BLOCK_LENGTH_INVALID;

	if ( ( f_pBufferLoadBlock->ulBlockOffset % 2 ) != 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BLOCK_OFFSET_INVALID;

	if ( f_pBufferLoadBlock->pbyBufferPattern == NULL )
		return cOCT6100_ERR_BUFFER_PLAYOUT_PATTERN;

	/* Check boundaries */
	if ( ( f_pBufferLoadBlock->ulBlockLength + f_pBufferLoadBlock->ulBlockOffset ) > pBufEntry->ulBufferSize )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_SIZE;

	*f_pulBufferBase = pBufEntry->ulBufferBase;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiReserveBufferResources

Description:    Reserves all resources needed for the new buffer.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.
	
f_pBufferLoad			Pointer to buffer configuration structure.

f_fReserveListStruct	Flag indicating if a list structure should be reserved
						or if the structure has been reserved before.

f_ulBufIndex			If the f_fReserveListStruct flag is set, this index
						will identifying the buffer playout list structure
						that must be used to load the specified buffer.

f_pulBufferIndex		Allocated entry in buffer playout list.
	
f_pulBufferBase			Allocated external memory block for the buffer.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiReserveBufferResources(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN		tPOCT6100_BUFFER_LOAD			f_pBufferLoad,
				IN		BOOL							f_fReserveListStruct,
				IN		UINT32							f_ulBufIndex,
				OUT		PUINT32							f_pulBufferIndex,
				OUT		PUINT32							f_pulBufferBase )
{
	tPOCT6100_SHARED_INFO	pSharedInfo;
	UINT32	ulResult = cOCT6100_ERR_OK;
	UINT32	ulTempVar;

	/* Obtain local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;
	
	/* Reserve an entry in the buffer list. */
	if ( f_fReserveListStruct == TRUE )
	{
		ulResult = Oct6100ApiReserveBufPlayoutListEntry( f_pApiInstance, f_pulBufferIndex );
	}
	else
	{
		*f_pulBufferIndex = f_ulBufIndex;
	}
	if ( ulResult == cOCT6100_ERR_OK )
	{
		/* Find a free block to store the buffer. */
		ulResult = Oct6100ApiReserveBufferPlayoutMemory( f_pApiInstance, f_pBufferLoad->ulBufferSize, f_pulBufferBase );
		if ( ulResult != cOCT6100_ERR_OK )
		{
			/* Release the list entry. */
			if ( f_fReserveListStruct == TRUE )
			{
				ulTempVar = Oct6100ApiReleaseBufPlayoutListEntry( f_pApiInstance, *f_pulBufferIndex );
				if ( ulTempVar != cOCT6100_ERR_OK )
					return ulTempVar;
			}
		}
	}

	return ulResult;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiWriteBufferInMemory

Description:    Writes the buffer in external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep
						the present state of the chip and all its resources.

f_ulBufferBase			Allocated external memory address for the buffer.

f_ulBufferLength		Length in bytes of the buffer to be copied in memory.

f_pbyBuffer				Address where the buffer should be copied from.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiWriteBufferInMemory( 
				IN OUT	tPOCT6100_INSTANCE_API	f_pApiInstance,
				IN		UINT32					f_ulBufferBase,
				IN		UINT32					f_ulBufferLength,
				IN		PUINT8					f_pbyBuffer )
{
	tPOCT6100_SHARED_INFO		pSharedInfo;
	tOCT6100_WRITE_BURST_PARAMS	BurstParams;
	tOCT6100_WRITE_PARAMS		WriteParams;
	UINT32						ulResult;
	UINT32						ulNumWrites;
	PUINT16						pusSuperArray;
	PUINT8						pbyPlayoutBuffer;
	UINT32						ulByteCount = 0;
	UINT32						i;

	/* Get local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	/* Set the process context and user chip ID parameters once and for all. */
	BurstParams.pProcessContext = f_pApiInstance->pProcessContext;

	BurstParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;

	WriteParams.pProcessContext = f_pApiInstance->pProcessContext;

	WriteParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;

	/* Write the buffer in external memory. */
	ulNumWrites = f_ulBufferLength / 2;

	BurstParams.ulWriteAddress = f_ulBufferBase;
	BurstParams.pusWriteData = pSharedInfo->MiscVars.ausSuperArray;

	pusSuperArray = pSharedInfo->MiscVars.ausSuperArray;
	pbyPlayoutBuffer = f_pbyBuffer;
	
	/* Check if we can maximize the bandwidth through the CPU port. */
	if ( f_pApiInstance->pSharedInfo->ChipStats.usNumberChannels == 0 )
	{
		WriteParams.ulWriteAddress = 0x234;
		WriteParams.usWriteData = 0x08ff;
		mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
		if ( ulResult != cOCT6100_ERR_OK  )
			return ulResult;
	}

	while ( ulNumWrites != 0 )
	{
		if ( ulNumWrites >= pSharedInfo->ChipConfig.usMaxRwAccesses )
			BurstParams.ulWriteLength = pSharedInfo->ChipConfig.usMaxRwAccesses;
		else
			BurstParams.ulWriteLength = ulNumWrites;

		for ( i = 0; i < BurstParams.ulWriteLength; i++ )
		{
			pusSuperArray[ i ]  = ( UINT16 )(( pbyPlayoutBuffer [ ulByteCount++ ]) << 8);
			pusSuperArray[ i ] |= ( UINT16 )pbyPlayoutBuffer [ ulByteCount++ ];
		}

		mOCT6100_DRIVER_WRITE_BURST_API( BurstParams, ulResult )
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		BurstParams.ulWriteAddress += 2 * BurstParams.ulWriteLength;
		ulNumWrites -= BurstParams.ulWriteLength;

	}

	/* Make sure we revert back the changes made to the CPU bandwidth register. */
	if ( f_pApiInstance->pSharedInfo->ChipStats.usNumberChannels == 0 )
	{
		WriteParams.ulWriteAddress = 0x234;
		WriteParams.usWriteData = 0x0804;
		mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;
	}

	return cOCT6100_ERR_OK;
}
	

/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiUpdateBufferEntry

Description:    Updates the new buffer's entry in the buffer playout list.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep
						the present state of the chip and all its resources.

f_pBufferLoad			Pointer to buffer configuration structure.
f_ulBufferIndex			Allocated entry in buffer playout list.
f_ulBufferBase			Allocated external memory block for the buffer.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiUpdateBufferEntry(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_LOAD			f_pBufferLoad,
				IN		UINT32							f_ulBufferIndex,
				IN		UINT32							f_ulBufferBase )
{
	tPOCT6100_API_BUFFER	pBufEntry;
	UINT32					ulBufferSize = f_pBufferLoad->ulBufferSize;

	/* Obtain a pointer to the new buffer's list entry. */
	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufEntry, f_ulBufferIndex )

	/* Copy the buffer's configuration and allocated resources. */
	pBufEntry->ulBufferSize = f_pBufferLoad->ulBufferSize;
	pBufEntry->byBufferPcmLaw = (UINT8)( f_pBufferLoad->ulBufferPcmLaw & 0xFF );
	pBufEntry->ulBufferBase = f_ulBufferBase;
	
	/* Update the entries flags. */
	pBufEntry->usDependencyCnt = 0;

	/* Mark the buffer as opened. */
	pBufEntry->fReserved = TRUE;

	/* Increment the number of buffer loaded into the chip.*/
	f_pApiInstance->pSharedInfo->ChipStats.usNumberPlayoutBuffers++;
	
	/* Refresh the amount of memory used by buffer playout. */

	/* Reserved size is divisible by 64. */
	if ( ulBufferSize % 64 )
		ulBufferSize = ulBufferSize + ( 64 - ( ulBufferSize % 64 ) );
	f_pApiInstance->pSharedInfo->ChipStats.ulPlayoutMemUsed += ulBufferSize;
	
	/* Return the buffer index to the user. */
	*f_pBufferLoad->pulBufferIndex = f_ulBufferIndex;

	/* Return the amount of free memory left in the chip. */
	/* Note that this value does not give the "fragmentation" state of the available memory. */
	/* This value only gives the amount of free memory */
	if( f_pBufferLoad->pulPlayoutFreeMemSize )
		*f_pBufferLoad->pulPlayoutFreeMemSize = ( f_pApiInstance->pSharedInfo->MiscVars.ulTotalMemSize - ( f_pApiInstance->pSharedInfo->MemoryMap.ulFreeMemBaseAddress - cOCT6100_EXTERNAL_MEM_BASE_ADDRESS ) ) - ( f_pApiInstance->pSharedInfo->ChipStats.ulPlayoutMemUsed );

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferUnloadSer

Description:    Unloads a buffer from external memory.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferUnload			Pointer to buffer unload structure.
f_fReleaseListStruct	Whether to release the buffer playout list structure
						or not.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferUnloadSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_UNLOAD				f_pBufferUnload,
				IN		BOOL								f_fReleaseListStruct )
{
	UINT32	ulBufferIndex;
	UINT32	ulBufferBase;
	UINT32	ulResult;

	/* Verify that all the parameters given match the state of the API. */
	ulResult = Oct6100ApiAssertBufferParams( f_pApiInstance, f_pBufferUnload, &ulBufferIndex, &ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Release all resources associated to the unloaded buffer. */
	ulResult = Oct6100ApiReleaseBufferResources( f_pApiInstance, ulBufferIndex, ulBufferBase, f_fReleaseListStruct );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiAssertBufferParams

Description:    Checks the buffer playout unload configuration for errors.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferUnload			Pointer to buffer unload structure.
f_pulBufferIndex		Pointer to the index of the buffer in the API's buffers list.
f_pulBufferBase			Pointer to the base address of the buffer in external memory.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiAssertBufferParams(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_UNLOAD				f_pBufferUnload,
				OUT		PUINT32								f_pulBufferIndex,
				OUT		PUINT32								f_pulBufferBase )
{
	tPOCT6100_API_BUFFER	pBufEntry;

	*f_pulBufferIndex = f_pBufferUnload->ulBufferIndex;

	if ( *f_pulBufferIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_INDEX;

	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufEntry, *f_pulBufferIndex )

	/* Check for errors. */
	if ( pBufEntry->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOT_OPEN;
	if ( pBufEntry->usDependencyCnt != 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ACTIVE_DEPENDENCIES;
	
	/* Return all info needed to invalidate buffer. */
	*f_pulBufferBase = pBufEntry->ulBufferBase;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiReleaseBufferResources

Description:    Release resources needed by the buffer.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.
	
f_ulBufferIndex			Allocated entry in buffer playout list.
f_ulBufferBase			Allocated external memory block for the buffer.
f_fReleaseListStruct	Free the list structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiReleaseBufferResources(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN		UINT32							f_ulBufferIndex,
				IN		UINT32							f_ulBufferBase,
				IN		BOOL							f_fReleaseListStruct )
{
	tPOCT6100_SHARED_INFO	pSharedInfo;
	tPOCT6100_API_BUFFER	pBufEntry;
	UINT32	ulResult;
	UINT32	ulBufferSize;

	/* Obtain local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	/* Free the external memory reserved for the buffer. */
	ulResult = Oct6100ApiReleaseBufferPlayoutMemory( f_pApiInstance, f_ulBufferBase );
	if ( ulResult != cOCT6100_ERR_OK )
		return cOCT6100_ERR_FATAL_3E;

	/* Release the entry from the buffer list. */
	if ( f_fReleaseListStruct == TRUE )
		ulResult = Oct6100ApiReleaseBufPlayoutListEntry( f_pApiInstance, f_ulBufferIndex );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufEntry, f_ulBufferIndex );

	/* Save buffer size before releasing that entry, will be needed to calculate the amount of */
	/* free memory left for the user. */
	ulBufferSize = pBufEntry->ulBufferSize;
	
	/* Flag the buffer entry as free. */
	pBufEntry->fReserved = FALSE;

	/* Decrement the number of buffer loaded into the chip. */
	f_pApiInstance->pSharedInfo->ChipStats.usNumberPlayoutBuffers--;

	/* Refresh the amount of memory used by buffer playout. */
	/* Reserved size is divisible by 64. */
	if ( ulBufferSize % 64 )
		ulBufferSize = ulBufferSize + ( 64 - ( ulBufferSize % 64 ) );
	f_pApiInstance->pSharedInfo->ChipStats.ulPlayoutMemUsed -= ulBufferSize;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutAddSer

Description:    This function adds a buffer to a channel buffer list.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutAdd		Pointer to buffer playout add structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutAddSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_PLAYOUT_ADD		f_pBufferPlayoutAdd )
{
	UINT32	ulBufferIndex;
	UINT32	ulChannelIndex;
	UINT32	ulResult;

	/* Check the user's configuration of the buffer for errors. */
	ulResult = Oct6100ApiCheckPlayoutAddParams( f_pApiInstance, f_pBufferPlayoutAdd, &ulChannelIndex, &ulBufferIndex );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Write to  all resources needed to activate buffer playout. */
	ulResult = Oct6100ApiWriteBufferAddStructs( f_pApiInstance, f_pBufferPlayoutAdd, ulChannelIndex, ulBufferIndex );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiCheckPlayoutAddParams

Description:	Check the validity of the channel and buffer requested.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutAdd		Pointer to buffer playout add structure.  
f_pulChannelIndex		Pointer to the channel index of the selected channel.
f_pulBufferIndex		Pointer to the buffer index within the API's buffer list.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiCheckPlayoutAddParams(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_PLAYOUT_ADD		f_pBufferPlayoutAdd,
				OUT		PUINT32								f_pulChannelIndex, 
				OUT		PUINT32								f_pulBufferIndex )
{
	tPOCT6100_API_BUFFER			pBufferEntry;
	tPOCT6100_API_CHANNEL			pEchoChannel;
	UINT32	ulEntryOpenCnt;

	/* Check for errors. */
	if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers == 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_DISABLED;
	
	if ( f_pBufferPlayoutAdd->ulChannelHndl == cOCT6100_INVALID_HANDLE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	if ( f_pBufferPlayoutAdd->ulPlayoutPort != cOCT6100_CHANNEL_PORT_ROUT && 
		 f_pBufferPlayoutAdd->ulPlayoutPort != cOCT6100_CHANNEL_PORT_SOUT )
		return cOCT6100_ERR_BUFFER_PLAYOUT_PLAYOUT_PORT;

	if ( f_pBufferPlayoutAdd->fRepeat != TRUE && f_pBufferPlayoutAdd->fRepeat != FALSE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_REPEAT;

	if ( f_pBufferPlayoutAdd->fRepeat == TRUE )
	{
		if ( f_pBufferPlayoutAdd->ulRepeatCount != cOCT6100_REPEAT_INFINITELY )
		{
			if ( f_pBufferPlayoutAdd->ulRepeatCount == 0x0 
				|| f_pBufferPlayoutAdd->ulRepeatCount > cOCT6100_REPEAT_MAX)
			{
				return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_REPEAT_COUNT;
			}
		}
	}

	if ( f_pBufferPlayoutAdd->ulMixingMode != cOCT6100_MIXING_0_DB &&
		 f_pBufferPlayoutAdd->ulMixingMode != cOCT6100_MIXING_MINUS_6_DB &&
		 f_pBufferPlayoutAdd->ulMixingMode != cOCT6100_MIXING_MINUS_12_DB &&
		 f_pBufferPlayoutAdd->ulMixingMode != cOCT6100_MIXING_MUTE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_MIXING;

	if ( ( f_pBufferPlayoutAdd->lGainDb < -24 )
		|| ( f_pBufferPlayoutAdd->lGainDb > 24 ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_GAIN_DB;

	/*=====================================================================*/
	/* Check the channel handle. */

	if ( (f_pBufferPlayoutAdd->ulChannelHndl & cOCT6100_HNDL_TAG_MASK) != cOCT6100_HNDL_TAG_CHANNEL )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	*f_pulChannelIndex = f_pBufferPlayoutAdd->ulChannelHndl & cOCT6100_HNDL_INDEX_MASK;
	if ( *f_pulChannelIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxChannels )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( f_pApiInstance->pSharedInfo, pEchoChannel, *f_pulChannelIndex )

	/* Extract the entry open count from the provided handle. */
	ulEntryOpenCnt = (f_pBufferPlayoutAdd->ulChannelHndl >> cOCT6100_ENTRY_OPEN_CNT_SHIFT) & cOCT6100_ENTRY_OPEN_CNT_MASK;

	/* Check for errors. */
	if ( pEchoChannel->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_NOT_OPEN;
	if ( ulEntryOpenCnt != pEchoChannel->byEntryOpenCnt )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	/* Check if repeat flag has been used for this port. */
	if ( ( ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT ) && ( pEchoChannel->fRinBufPlayoutRepeatUsed == TRUE ) )
		|| ( ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) && ( pEchoChannel->fSoutBufPlayoutRepeatUsed == TRUE ) ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_REPEAT_USED;

	/*=====================================================================*/

	/*=====================================================================*/
	/* Check the buffer information. */

	*f_pulBufferIndex = f_pBufferPlayoutAdd->ulBufferIndex;
	if ( *f_pulBufferIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_INDEX;

	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufferEntry, *f_pulBufferIndex )

	if ( pBufferEntry->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOT_OPEN;

	/* Check if the play length is not larger then the currently uploaded buffer. */
	if ( ( f_pBufferPlayoutAdd->ulBufferLength > pBufferEntry->ulBufferSize ) &&
		  ( f_pBufferPlayoutAdd->ulBufferLength != cOCT6100_AUTO_SELECT ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_SIZE;

	if( f_pBufferPlayoutAdd->ulBufferLength != cOCT6100_AUTO_SELECT )
	{
		if ( f_pBufferPlayoutAdd->ulBufferLength < cOCT6100_MINIMUM_BUFFER_SIZE )
			return cOCT6100_ERR_BUFFER_PLAYOUT_TOO_SMALL;

		if ( ( f_pBufferPlayoutAdd->ulBufferLength % cOCT6100_BUFFER_SIZE_GRANULARITY ) != 0 )
			return cOCT6100_ERR_BUFFER_PLAYOUT_BUF_SIZE;
	}

	/*=====================================================================*/

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiWriteBufferAddStructs

Description:    Write the buffer playout event in the channel's port playout
				circular buffer.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.
	
f_pBufferPlayoutAdd		Pointer to buffer playout add structure.  
f_ulChannelIndex		Index of the channel on which the buffer is to be added.
f_ulBufferIndex			Index of the buffer structure within the API's buffer list.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiWriteBufferAddStructs(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_PLAYOUT_ADD		f_pBufferPlayoutAdd,
				IN		UINT32								f_ulChannelIndex, 
				IN		UINT32								f_ulBufferIndex )
{
	tPOCT6100_API_BUFFER		pBufferEntry;
	tPOCT6100_API_CHANNEL		pEchoChannel;
	tPOCT6100_SHARED_INFO		pSharedInfo;
	tOCT6100_READ_PARAMS		ReadParams;
	UINT32	ulResult;
	UINT32	ulTempData;
	UINT32	ulEventBuffer;

	UINT32	ulReadPtrBytesOfst;
	UINT32	ulReadPtrBitOfst;
	UINT32	ulReadPtrFieldSize;

	UINT32	ulWritePtrBytesOfst;
	UINT32	ulWritePtrBitOfst;
	UINT32	ulWritePtrFieldSize;

	UINT32	ulWritePtr;
	UINT32	ulReadPtr;

	UINT32	ulPlayoutBaseAddress;
	UINT32	ulAddress;
	UINT32	ulEventIndex;
	UINT32	ulMask;

	UINT32	ulRepeatCount = 0;
	BOOL	fRepeatCountSet = FALSE;
	UINT32	ulDurationModulo = 0;
	UINT32	ulEventsToCreate = 1;
	UINT32	ulBufferDurationMs;
	
	UINT32	ulBufferLength;
	UINT16	usTempData = 0;

	UINT16	usReadData;
	UINT32	ulChipWritePtr;
	UINT32	ulReadData;
	UINT32	ulLoopCnt = 0;
	BOOL	fStillPlaying = TRUE;
	BOOL	fCheckHardStop = FALSE;
	BOOL	fOldBufferPlayoutVersion = FALSE;

	UINT32			aulWaitTime[ 2 ];

	/* Obtain local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pEchoChannel, f_ulChannelIndex );
	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufferEntry, f_ulBufferIndex );

	/* Select the buffer of interest. */
	if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainRinPlayoutMemOfst;
		ulWritePtr = pEchoChannel->ulRinBufWritePtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.usDwordOffset * 4;
		ulWritePtrBitOfst = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byBitOffset;
		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byFieldSize;

		ulReadPtrBytesOfst = pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.usDwordOffset * 4;
		ulReadPtrBitOfst = pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byBitOffset;
		ulReadPtrFieldSize = pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byFieldSize;
	}
	else /* f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainSoutPlayoutMemOfst;
		ulWritePtr = pEchoChannel->ulSoutBufWritePtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.usDwordOffset * 4;
		ulWritePtrBitOfst = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byBitOffset;
		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byFieldSize;

		ulReadPtrBytesOfst = pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.usDwordOffset * 4;
		ulReadPtrBitOfst = pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byBitOffset;
		ulReadPtrFieldSize = pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byFieldSize;
	}

	/*=======================================================================*/
	/* Calculate the repeat count. */

	/* The buffer length is either the total buffer size or the value specified by the user */
	if ( f_pBufferPlayoutAdd->ulBufferLength == cOCT6100_AUTO_SELECT )
	{
		ulBufferLength = pBufferEntry->ulBufferSize;
	}
	else
	{
		ulBufferLength = f_pBufferPlayoutAdd->ulBufferLength;
	}

	if ( f_pBufferPlayoutAdd->ulDuration != cOCT6100_INVALID_VALUE )
	{
		/* With duration and buffer length, we can find the number of times we must repeat playing this buffer. */
		ulBufferDurationMs = ulBufferLength / cOCT6100_SAMPLES_PER_MS;
		ulRepeatCount = f_pBufferPlayoutAdd->ulDuration / ulBufferDurationMs;
		fRepeatCountSet = TRUE;

		/* Check if buffer is larger then asked duration. */
		if ( ulRepeatCount != 0x0 )
		{
			/* We might have to create more then 1 event to accomodate for the repeat-max limit. */
			ulEventsToCreate = ( ulRepeatCount / cOCT6100_REPEAT_MAX ) + 1;
		}
		else
		{
			/* No repeat event.  Maybe only the duration modulo! */
			ulEventsToCreate = 0x0;
		}

		/* Check if must create a second event for a buffer that cannot be played completely. */
		ulDurationModulo = f_pBufferPlayoutAdd->ulDuration % ulBufferDurationMs;
		if ( ulDurationModulo != 0x0 )
		{
			ulDurationModulo *= cOCT6100_SAMPLES_PER_MS;
			if ( ulDurationModulo / cOCT6100_BUFFER_SIZE_GRANULARITY )
			{
				/* Round the modulo to be on a buffer size granularity. */
				/* This will round down. */
				ulDurationModulo = ( ulDurationModulo / cOCT6100_BUFFER_SIZE_GRANULARITY ) * cOCT6100_BUFFER_SIZE_GRANULARITY;

				/* If the event about to be created is smaller then the minimum buffer size, */
				/* round up to the minimum required by the hardware. */
				if ( ulDurationModulo < cOCT6100_MINIMUM_BUFFER_SIZE )
					ulDurationModulo = cOCT6100_MINIMUM_BUFFER_SIZE;
				ulEventsToCreate++;
			}
			else
			{
				/* The modulo is too small to be played.  Skip. */
				ulDurationModulo = 0;
			}
		}
	}
	else if ( f_pBufferPlayoutAdd->fRepeat == TRUE 
		&& f_pBufferPlayoutAdd->ulRepeatCount != cOCT6100_REPEAT_INFINITELY )
	{
		/* The repeat count is set directly from the user. */
		ulRepeatCount = f_pBufferPlayoutAdd->ulRepeatCount;
		fRepeatCountSet = TRUE;
	}
	
	/*=======================================================================*/

	/* Set the playout feature base address. */
	ulPlayoutBaseAddress = cOCT6100_CHANNEL_ROOT_BASE + ( f_ulChannelIndex * cOCT6100_CHANNEL_ROOT_SIZE ) + pSharedInfo->MemoryMap.ulChanRootConfOfst;

	/* Read the read pointer. */
	ulAddress = ulPlayoutBaseAddress + ulReadPtrBytesOfst;

	/* Must read in memory directly since this value is changed by hardware. */
	ulResult = Oct6100ApiReadDword( f_pApiInstance, ulAddress, &ulTempData );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	mOCT6100_CREATE_FEATURE_MASK( ulReadPtrFieldSize, ulReadPtrBitOfst, &ulMask );
	
	/* Store the read pointer. */
	ulReadPtr = ( ulTempData & ulMask ) >> ulReadPtrBitOfst;

	/* Compare the pointers...  Are they different?  If so, there is something already in the list.  */
	if ( ulReadPtr != ulWritePtr )
	{
		/* Check if there is enough room for the playout events. */
		if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == TRUE )
			&& ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == TRUE ) )
		{
			/* 127 or 31 events image. */
			if ( (UINT8)( ( ulWritePtr - ulReadPtr ) & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 ) ) >= ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - (UINT8)ulEventsToCreate ) )
				fCheckHardStop = TRUE;
		}
		else
		{
			/* Old 31 events image. */
			if ( ( ( ulWritePtr - ulReadPtr ) & 0x1F ) >= ( 0x20 - ulEventsToCreate ) )
				fCheckHardStop = TRUE;

			fOldBufferPlayoutVersion = TRUE;
		}

		if ( fCheckHardStop == TRUE )
		{
			/* Ok.  From what was read, the list is full.  But we might still have a chance if the hard-stop */
			/* version was used.  In this case, some of the buffers in the list might */
			/* become free in a couple of milliseconds, so try to wait for this. */
			
			if ( ( ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT ) && ( pEchoChannel->fRinHardStop == TRUE ) )
				|| ( ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) && ( pEchoChannel->fSoutHardStop == TRUE ) ) )
			{
				/* Read the 'chip' write pointer in the hardware. */
				ReadParams.pProcessContext = f_pApiInstance->pProcessContext;

				ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
				ReadParams.pusReadData = &usReadData;
				ReadParams.ulReadAddress = ulPlayoutBaseAddress + ulReadPtrBytesOfst;

				/* Get the write pointer in the chip. */
				ulAddress = ulPlayoutBaseAddress + ulWritePtrBytesOfst;

				mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInstance, pEchoChannel, ulAddress, &ulReadData, ulResult );
				if ( ulResult != cOCT6100_ERR_OK )
					return ulResult;

				mOCT6100_CREATE_FEATURE_MASK( ulWritePtrFieldSize, ulWritePtrBitOfst, &ulMask );

				/* Store the write pointer. */
				ulChipWritePtr = ( ulReadData & ulMask ) >> ulWritePtrBitOfst;

				/* Optimize this access by only reading the word we are interested in. */
				if ( ulReadPtrBitOfst < 16 )
					ReadParams.ulReadAddress += 2;

				while( fStillPlaying == TRUE )
				{				
					/* Read the read pointer until equals to the write pointer. */
					mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
					if ( ulResult != cOCT6100_ERR_OK )
						return ulResult;

					/* Move data at correct position according to what was read. */
					if ( ulReadPtrBitOfst < 16 )
						ulTempData = usReadData;
					else
						ulTempData = usReadData << 16;
					
					mOCT6100_CREATE_FEATURE_MASK( ulReadPtrFieldSize, ulReadPtrBitOfst, &ulMask );
					
					/* Store the read pointer.*/
					ulReadPtr = ( ulTempData & ulMask ) >> ulReadPtrBitOfst;

					/* Playout has finished when the read pointer reaches the write pointer. */
					if ( ulReadPtr == ulChipWritePtr )
						break;

					ulLoopCnt++;
					if ( ulLoopCnt > cOCT6100_MAX_LOOP )
					{
						return cOCT6100_ERR_FATAL_E7;
					}

					aulWaitTime[ 0 ] = 100;
					aulWaitTime[ 1 ] = 0;
					ulResult = Oct6100ApiWaitForTime( f_pApiInstance, aulWaitTime );
					if ( ulResult != cOCT6100_ERR_OK )
						return ulResult;			
				}

				/* Clear hard-stop flag. */
				if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
				{
					/* No hard stop for now. */
					pEchoChannel->fRinHardStop = FALSE;
				}
				else /* if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) */
				{
					/* No hard stop for now. */
					pEchoChannel->fSoutHardStop = FALSE;
				}

				/* Now check again if the event can be added... */
				if ( fOldBufferPlayoutVersion == FALSE )
				{
					if ( (UINT8)( ( ulWritePtr - ulReadPtr ) & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 ) ) >= ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - (UINT8)ulEventsToCreate ) )
						return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_EVENT_BUF_FULL;
				}
				else /* if ( fOldBufferPlayoutVersion == TRUE ) */
				{
					/* Old 31 events image. */
					if ( ( ( ulWritePtr - ulReadPtr ) & 0x1F ) >= ( 0x20 - ulEventsToCreate ) )
						return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_EVENT_BUF_FULL;
				}

				/* Good, at least another buffer can be added!  Add the buffer to the list. */
			}
			else
			{
				/* Well the list is full! */
				return cOCT6100_ERR_BUFFER_PLAYOUT_ADD_EVENT_BUF_FULL;
			}
		}
	}

	/*=======================================================================*/
	/* Write the events. */

	for ( ulEventIndex = 0; ulEventIndex < ulEventsToCreate; ulEventIndex ++  )
	{
		/* Set the playout event base address. */
		if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == TRUE )
			&& ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == TRUE ) )
		{
			/* 127 or 31 events image. */
			ulAddress = pSharedInfo->MemoryMap.ulChanMainMemBase + (f_ulChannelIndex * pSharedInfo->MemoryMap.ulChanMainMemSize ) + ulEventBuffer + (cOCT6100_PLAYOUT_EVENT_MEM_SIZE * (ulWritePtr & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 )));
		}
		else
		{
			/* Old 31 events image. */
			ulAddress = pSharedInfo->MemoryMap.ulChanMainMemBase + (f_ulChannelIndex * pSharedInfo->MemoryMap.ulChanMainMemSize ) + ulEventBuffer + (cOCT6100_PLAYOUT_EVENT_MEM_SIZE * (ulWritePtr & 0x1F));
		}
	
		/* EVENT BASE + 0 */
		/* Make sure the xIS and xHS bits are cleared. */
		ulTempData = 0;

		/* Set the repeat count. */
		if ( fRepeatCountSet == TRUE )
		{
			if ( ( ulRepeatCount != 0x0 ) && ( ulRepeatCount <= cOCT6100_REPEAT_MAX ) )
			{
				/* Use repeat count directly. */
				ulTempData |= ulRepeatCount;

				/* Will be used later when creating the duration modulo event. */
				ulRepeatCount = 0;
			}
			else if ( ulRepeatCount != 0x0 )
			{
				/* Get ready for next event. */
				ulRepeatCount -= cOCT6100_REPEAT_MAX;

				/* Set maximum for this event. */
				ulTempData |= cOCT6100_REPEAT_MAX;
			}
			else
			{
				/* Duration modulo case.  Nothing to set here. */
			}
		}
		else /* if ( fRepeatCountSet != TRUE ) */
		{
			/* Repeat only once. */
			ulTempData |= 0x1;
		}

		ulResult = Oct6100ApiWriteDword( f_pApiInstance, ulAddress, ulTempData );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		/* EVENT BASE + 4 */
		/* Set the buffer base address and playout configuration. */
		ulAddress += 4;
		ulTempData = pBufferEntry->ulBufferBase & 0x07FFFFFF;

		/* Set play indefinitely or loop N times. */
		if ( ( fRepeatCountSet == FALSE ) && ( f_pBufferPlayoutAdd->fRepeat == TRUE ) )
		{
			/* Repeat indefinitely. */
			ulTempData |= 0x1 << cOCT6100_PLAYOUT_EVENT_REPEAT_OFFSET;

			if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
				pEchoChannel->fRinBufPlayoutRepeatUsed = TRUE;
			else /* if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) */
				pEchoChannel->fSoutBufPlayoutRepeatUsed = TRUE;
		}
		
		/* Use loop N times feature. */
		ulTempData |= 0x1 << cOCT6100_PLAYOUT_EVENT_LOOP_TIMES_OFFSET;

		/* Set the law.*/
		ulTempData |= ( pBufferEntry->byBufferPcmLaw << cOCT6100_PLAYOUT_EVENT_LAW_OFFSET );

		/* Set the mixing configuration.*/
		ulTempData |= f_pBufferPlayoutAdd->ulMixingMode << cOCT6100_PLAYOUT_EVENT_MIX_OFFSET;

		ulResult = Oct6100ApiWriteDword( f_pApiInstance, ulAddress, ulTempData );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		
		/* EVENT BASE + 8 */
		/* Set the buffer size and playout gain. */
		ulAddress += 4;

		/* Check if we are setting the duration modulo.  This would be the last event and this */
		/* event is of a very specific size. */
		if ( ( fRepeatCountSet == TRUE ) 
			&& ( ulEventIndex == ( ulEventsToCreate - 1 ) ) 
			&& ( ulDurationModulo != 0x0 ) )
		{
			/* The duration modulo variable contains all that is needed here. */
			ulBufferLength = ulDurationModulo;
		}
		ulTempData = ulBufferLength;

		/* Adjust playout gain. */
		if ( f_pBufferPlayoutAdd->lGainDb != 0 )
		{
			/* Convert the dB value into OctFloat format. */
			usTempData = Oct6100ApiDbAmpHalfToOctFloat( f_pBufferPlayoutAdd->lGainDb );
			ulTempData |= ( usTempData & 0xFF00 ) << 16;
		}
		else
		{
			ulTempData |= cOCT6100_PLAYOUT_GAIN;
		}

		ulResult = Oct6100ApiWriteDword( f_pApiInstance, ulAddress, ulTempData );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;
			
		/* EVENT BASE + 0xC */
		ulAddress += 4;
		ulTempData = ( ulBufferLength - 1 ) & 0xFFFFFFC0;	/* Must be multiple of 64 bytes */

		/* Adjust playout gain. */
		if ( f_pBufferPlayoutAdd->lGainDb != 0 )
		{
			ulTempData |= ( usTempData & 0xFF ) << 24;
		}

		ulResult = Oct6100ApiWriteDword( f_pApiInstance, ulAddress, ulTempData );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		/* Next event. */
		ulWritePtr++;
	}

	/*=======================================================================*/


	/*=======================================================================*/
	/* Increment the write pointer to make it point to the next empty entry. */

	if ( f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		pEchoChannel->ulRinBufWritePtr = ( pEchoChannel->ulRinBufWritePtr + ulEventsToCreate ) & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 );
		/* Remember that a buffer was added on the rin port. */
		pEchoChannel->fRinBufAdded = TRUE;
	}
	else /* f_pBufferPlayoutAdd->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		pEchoChannel->ulSoutBufWritePtr = ( pEchoChannel->ulSoutBufWritePtr + ulEventsToCreate ) & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 );
		/* Remember that a buffer was added on the sout port. */
		pEchoChannel->fSoutBufAdded = TRUE;
	}

	/*=======================================================================*/

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutStartSer

Description:    Starts buffer playout on a channel.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance				Pointer to API instance. This memory is used to keep the
							present state of the chip and all its resources.

f_pBufferPlayoutStart		Pointer to buffer playout start structure.

f_ulPlayoutStopEventType	Playout stop event type to be generated if required.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutStartSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_PLAYOUT_START		f_pBufferPlayoutStart,
				IN		UINT32								f_ulPlayoutStopEventType )
{
	UINT32	ulBufferIndex;
	UINT32	ulChannelIndex;
	BOOL	fNotifyOnPlayoutStop;
	UINT32	ulUserEventId;
	BOOL	fAddToCurrentlyPlayingList;
	UINT32	ulResult;

	/* Check the user's configuration of the buffer for errors. */
	ulResult = Oct6100ApiCheckPlayoutStartParams( f_pApiInstance, f_pBufferPlayoutStart, &ulChannelIndex, &ulBufferIndex, &fNotifyOnPlayoutStop, &ulUserEventId, &fAddToCurrentlyPlayingList );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Write to all resources needed to activate buffer playout. */
	ulResult = Oct6100ApiWriteChanPlayoutStructs( f_pApiInstance, f_pBufferPlayoutStart, ulChannelIndex, ulBufferIndex, fNotifyOnPlayoutStop, ulUserEventId, fAddToCurrentlyPlayingList, f_ulPlayoutStopEventType );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiCheckPlayoutStartParams

Description:	Check the validity of the channel and buffer requested.
				Check the validity of the flags requested.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutStart	Pointer to buffer playout start structure.  
f_pulChannelIndex		Pointer to the channel index of the selected channel.
f_pulBufferIndex		Pointer to the buffer index within the API's buffer list.
f_pfNotifyOnPlayoutStop	Pointer to the notify on playout stop flag.
f_pulUserEventId		Pointer to the user event id specified.
f_pfAllowStartIfActive	Pointer to the add to currently playing list flag.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiCheckPlayoutStartParams(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_PLAYOUT_START		f_pBufferPlayoutStart,
				OUT		PUINT32								f_pulChannelIndex, 
				OUT		PUINT32								f_pulBufferIndex,
				OUT		PBOOL								f_pfNotifyOnPlayoutStop,
				OUT		PUINT32								f_pulUserEventId,
				OUT		PBOOL								f_pfAllowStartIfActive )
{
	tPOCT6100_API_CHANNEL	pEchoChannel;
	UINT32					ulEntryOpenCnt;

	/* Check for errors. */
	if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers == 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_DISABLED;
	
	if ( f_pBufferPlayoutStart->ulChannelHndl == cOCT6100_INVALID_HANDLE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	if ( f_pBufferPlayoutStart->ulPlayoutPort != cOCT6100_CHANNEL_PORT_ROUT && 
		 f_pBufferPlayoutStart->ulPlayoutPort != cOCT6100_CHANNEL_PORT_SOUT )
		return cOCT6100_ERR_BUFFER_PLAYOUT_PLAYOUT_PORT;

	if ( f_pBufferPlayoutStart->fNotifyOnPlayoutStop != FALSE
		&& f_pBufferPlayoutStart->fNotifyOnPlayoutStop != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOTIFY_ON_STOP;

	if ( f_pBufferPlayoutStart->fAllowStartWhileActive != FALSE
		&& f_pBufferPlayoutStart->fAllowStartWhileActive != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ALLOW_ACTIVE;

	/*=====================================================================*/
	/* Check the channel handle. */

	if ( (f_pBufferPlayoutStart->ulChannelHndl & cOCT6100_HNDL_TAG_MASK) != cOCT6100_HNDL_TAG_CHANNEL )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	*f_pulChannelIndex = f_pBufferPlayoutStart->ulChannelHndl & cOCT6100_HNDL_INDEX_MASK;
	if ( *f_pulChannelIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxChannels )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( f_pApiInstance->pSharedInfo, pEchoChannel, *f_pulChannelIndex )

	/* Extract the entry open count from the provided handle. */
	ulEntryOpenCnt = (f_pBufferPlayoutStart->ulChannelHndl >> cOCT6100_ENTRY_OPEN_CNT_SHIFT) & cOCT6100_ENTRY_OPEN_CNT_MASK;

	/* Check for errors. */
	if ( pEchoChannel->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_NOT_OPEN;
	if ( ulEntryOpenCnt != pEchoChannel->byEntryOpenCnt )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	/* The channel cannot be in POWER_DOWN or HT_FREEZE to start the playout. */
	if ( ( pEchoChannel->byEchoOperationMode == cOCT6100_ECHO_OP_MODE_POWER_DOWN )
		|| ( pEchoChannel->byEchoOperationMode == cOCT6100_ECHO_OP_MODE_HT_FREEZE ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_ECHO_OP_MODE;
	
	/* The channel's NLP must be enabled for playout to occur. */
	if ( pEchoChannel->VqeConfig.fEnableNlp == FALSE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NLP_DISABLED;

	/*=====================================================================*/

	/*=====================================================================*/
	/* Check if the user activated the buffer playout events. */

	if ( f_pBufferPlayoutStart->fNotifyOnPlayoutStop == TRUE
		&& f_pApiInstance->pSharedInfo->ChipConfig.ulSoftBufPlayoutEventsBufSize == 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_EVENT_DISABLED;

	/*=====================================================================*/

	/*=====================================================================*/
	/* Check if there is actually a buffer added in the list. */

	if ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		if ( pEchoChannel->fRinBufAdded == FALSE )
			return cOCT6100_ERR_BUFFER_PLAYOUT_LIST_EMPTY;
	}
	else /* if ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) */
	{
		if ( pEchoChannel->fSoutBufAdded == FALSE )
			return cOCT6100_ERR_BUFFER_PLAYOUT_LIST_EMPTY;
	}

	/*=====================================================================*/

	/* Return the requested information. */
	*f_pfNotifyOnPlayoutStop = f_pBufferPlayoutStart->fNotifyOnPlayoutStop;
	*f_pulUserEventId = f_pBufferPlayoutStart->ulUserEventId;
	*f_pfAllowStartIfActive = f_pBufferPlayoutStart->fAllowStartWhileActive;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiWriteChanPlayoutStructs

Description:    Write the buffer playout event in the channel main structure.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance				Pointer to API instance. This memory is used to keep the
							present state of the chip and all its resources.
	
f_pBufferPlayoutStart		Pointer to buffer playout start structure.
f_ulChannelIndex			Index of the channel within the API's channel list.
f_ulBufferIndex				Index of the buffer within the API's buffer list.
f_fNotifyOnPlayoutStop		Flag for the notify on playout stop.
f_ulUserEventId				User event id passed to the user when a playout event is generated.
f_fAllowStartIfActive		Add to currently playing list flag.
f_ulPlayoutStopEventType	Playout stop event type to be generated if required.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiWriteChanPlayoutStructs(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_PLAYOUT_START		f_pBufferPlayoutStart,
				IN		UINT32								f_ulChannelIndex, 
				IN		UINT32								f_ulBufferIndex,
				IN		BOOL								f_fNotifyOnPlayoutStop,
				IN		UINT32								f_ulUserEventId,
				IN		BOOL								f_fAllowStartIfActive,
				IN		UINT32								f_ulPlayoutStopEventType )
{
	tPOCT6100_API_BUFFER			pBufferEntry;
	tPOCT6100_API_CHANNEL			pEchoChannel;
	tPOCT6100_SHARED_INFO			pSharedInfo;
	tOCT6100_READ_PARAMS			ReadParams;
	
	UINT32	ulResult;

	UINT32	ulWritePtr;
	UINT32	ulChipWritePtr;
	PUINT32	pulSkipPtr;
	UINT32	ulWritePtrBytesOfst;
	UINT32	ulSkipPtrBytesOfst;
	UINT32	ulWritePtrBitOfst;
	UINT32	ulSkipPtrBitOfst;
	UINT32	ulWritePtrFieldSize;
	UINT32	ulSkipPtrFieldSize;

	UINT32	ulIgnoreBytesOfst;
	UINT32	ulIgnoreBitOfst;
	UINT32	ulIgnoreFieldSize;
	
	UINT32	ulHardSkipBytesOfst;
	UINT32	ulHardSkipBitOfst;
	UINT32	ulHardSkipFieldSize;

	UINT32	ulReadPtrBytesOfst;
	UINT32	ulReadPtrBitOfst;
	UINT32	ulReadPtrFieldSize;

	UINT32	ulPlayoutBaseAddress;
	UINT32	ulAddress;
	UINT32	ulTempData;
	UINT32	ulMask;
	UINT32	ulReadData;
	UINT32	ulReadPtr;
	UINT32	ulLoopCnt = 0;

	UINT16	usReadData;

	BOOL	fBufferPlayoutStopDetected;
	BOOL	fWriteSkipPtr = FALSE;
	BOOL	fStillPlaying = TRUE;

	UINT32			aulWaitTime[ 2 ];

	/* Obtain local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pEchoChannel, f_ulChannelIndex );
	mOCT6100_GET_BUFFER_ENTRY_PNT( f_pApiInstance->pSharedInfo, pBufferEntry, f_ulBufferIndex );

	/* First off, check for buffer playout events, if requested for this channel/port. */
	/* At the same time, if requested, check that the playout has stopped for this channel/port. */
	if ( ( ( pEchoChannel->fRinBufPlaying == TRUE )
			&& ( ( pEchoChannel->fRinBufPlayoutNotifyOnStop == TRUE ) || ( f_fAllowStartIfActive == FALSE ) )
			&& ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT ) )
		|| ( ( ( pEchoChannel->fSoutBufPlaying == TRUE ) || ( f_fAllowStartIfActive == FALSE ) )
			&& ( pEchoChannel->fSoutBufPlayoutNotifyOnStop == TRUE )
			&& ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) ) )
	{
		/* Buffer playout might still be going on for this channel/port. */
		ulResult = Oct6100BufferPlayoutCheckForSpecificEvent(	f_pApiInstance, 
																f_ulChannelIndex, 
																f_pBufferPlayoutStart->ulPlayoutPort,
																pEchoChannel->fRinBufPlayoutNotifyOnStop, 
																&fBufferPlayoutStopDetected );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		/* Check if the user requested to only start if playout is over.  Return an error if */
		/* buffer playout is still going on on this channel/port. */
		if ( ( f_fAllowStartIfActive == FALSE ) && ( fBufferPlayoutStopDetected == FALSE ) )
		{
			/* No go!  User should wait for the current list to stop, or call the */
			/* Oct6100BufferPlayoutStop function. */
			return cOCT6100_ERR_BUFFER_PLAYOUT_STILL_ACTIVE;
		}
	}

	/* Select the buffer of interest. */
	if ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		ulWritePtr  = pEchoChannel->ulRinBufWritePtr;
		pulSkipPtr	= &pEchoChannel->ulRinBufSkipPtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.usDwordOffset * 4;
		ulSkipPtrBytesOfst  = pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.usDwordOffset * 4;
		ulIgnoreBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.usDwordOffset * 4;
		ulHardSkipBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.usDwordOffset * 4;
		ulReadPtrBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.usDwordOffset * 4;

		ulWritePtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byBitOffset;
		ulSkipPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.byBitOffset;
		ulIgnoreBitOfst		= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.byBitOffset;
		ulHardSkipBitOfst	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.byBitOffset;
		ulReadPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byBitOffset;

		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byFieldSize;
		ulSkipPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.byFieldSize;
		ulIgnoreFieldSize	= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.byFieldSize;
		ulHardSkipFieldSize	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.byFieldSize;
		ulReadPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byFieldSize;
	}
	else /* f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		ulWritePtr	= pEchoChannel->ulSoutBufWritePtr;
		pulSkipPtr	= &pEchoChannel->ulSoutBufSkipPtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.usDwordOffset * 4;
		ulSkipPtrBytesOfst  = pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.usDwordOffset * 4;
		ulIgnoreBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.usDwordOffset * 4;
		ulHardSkipBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.usDwordOffset * 4;
		ulReadPtrBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.usDwordOffset * 4;

		ulWritePtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byBitOffset;
		ulSkipPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.byBitOffset;
		ulIgnoreBitOfst		= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.byBitOffset;
		ulHardSkipBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.byBitOffset;
		ulReadPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byBitOffset;

		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byFieldSize;
		ulSkipPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.byFieldSize;
		ulIgnoreFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.byFieldSize;
		ulHardSkipFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.byFieldSize;
		ulReadPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byFieldSize;
	}
	


	/* Set the playout feature base address. */
	ulPlayoutBaseAddress = cOCT6100_CHANNEL_ROOT_BASE + ( f_ulChannelIndex * cOCT6100_CHANNEL_ROOT_SIZE ) + pSharedInfo->MemoryMap.ulChanRootConfOfst;

	/* Check if we must wait for stop to complete before starting a new list. */
	if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE )
	{
		if ( ( ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT ) && ( pEchoChannel->fRinHardStop == TRUE ) )
			|| ( ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) && ( pEchoChannel->fSoutHardStop == TRUE ) ) )
		{
			/* Read the read pointer. */
			ReadParams.pProcessContext = f_pApiInstance->pProcessContext;

			ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
			ReadParams.pusReadData = &usReadData;
			ReadParams.ulReadAddress = ulPlayoutBaseAddress + ulReadPtrBytesOfst;

			/* Get the write pointer in the chip. */
			ulAddress = ulPlayoutBaseAddress + ulWritePtrBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInstance, pEchoChannel, ulAddress, &ulReadData, ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;

			mOCT6100_CREATE_FEATURE_MASK( ulWritePtrFieldSize, ulWritePtrBitOfst, &ulMask );

			/* Store the write pointer. */
			ulChipWritePtr = ( ulReadData & ulMask ) >> ulWritePtrBitOfst;

			/* Optimize this access by only reading the word we are interested in. */
			if ( ulReadPtrBitOfst < 16 )
				ReadParams.ulReadAddress += 2;

			while( fStillPlaying == TRUE )
			{				
				/* Read the read pointer until equals to the write pointer. */
				mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
				if ( ulResult != cOCT6100_ERR_OK )
					return ulResult;

				/* Move data at correct position according to what was read. */
				if ( ulReadPtrBitOfst < 16 )
					ulTempData = usReadData;
				else
					ulTempData = usReadData << 16;
				
				mOCT6100_CREATE_FEATURE_MASK( ulReadPtrFieldSize, ulReadPtrBitOfst, &ulMask );
				
				/* Store the read pointer. */
				ulReadPtr = ( ulTempData & ulMask ) >> ulReadPtrBitOfst;

				/* Playout has finished when the read pointer reaches the write pointer. */
				if ( ulReadPtr == ulChipWritePtr )
					break;

				ulLoopCnt++;
				if( ulLoopCnt > cOCT6100_MAX_LOOP )
				{
					return cOCT6100_ERR_FATAL_E6;
				}

				aulWaitTime[ 0 ] = 100;
				aulWaitTime[ 1 ] = 0;
				ulResult = Oct6100ApiWaitForTime( f_pApiInstance, aulWaitTime );
				if ( ulResult != cOCT6100_ERR_OK )
					return ulResult;			
			}
		}
	}

	/* Check if must clear the skip bit. */
	if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE )
	{
		if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == TRUE )
			&& ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == TRUE ) )
		{
			/* Make sure the skip bit is cleared to start playout! */
			ulAddress = ulPlayoutBaseAddress + ulIgnoreBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInstance, pEchoChannel, ulAddress, &ulTempData, ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
			
			mOCT6100_CREATE_FEATURE_MASK( ulIgnoreFieldSize, ulIgnoreBitOfst, &ulMask );

			/* Cleared! */
			ulTempData &= ( ~ulMask );

			mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											ulTempData,
											ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;

			/* Make sure the hard skip bit is cleared to start playout! */
			ulAddress = ulPlayoutBaseAddress + ulHardSkipBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
												pEchoChannel,
												ulAddress,
												&ulTempData,
												ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
			
			mOCT6100_CREATE_FEATURE_MASK( ulIgnoreFieldSize, ulHardSkipBitOfst, &ulMask );

			/* Cleared! */
			ulTempData &= ( ~ulMask );

			mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											ulTempData,
											ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
		}
	}

	/* Write the skip and write pointer to activate buffer playout. */

	/* Update the skip pointer. */
	if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == FALSE )
		|| ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == FALSE ) )
	{
		/* Old 31 events image. */
		if ( ( ( ulWritePtr - *pulSkipPtr ) & 0x7F ) > 63 )
		{
			*pulSkipPtr = ( ulWritePtr - 63 ) & 0x7F;
			fWriteSkipPtr = TRUE;
		}
	}
	else
	{
		/* No need to update the skip pointer, a bit needs to be set when skipping. */
		/* fWriteSkipPtr set to FALSE from variable declaration. */
	}

	if ( fWriteSkipPtr == TRUE )
	{
		/*=======================================================================*/
		/* Fetch and modify the skip pointer. */	

		ulAddress = ulPlayoutBaseAddress + ulSkipPtrBytesOfst;

		mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											&ulTempData,
											ulResult );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;
		
		mOCT6100_CREATE_FEATURE_MASK( ulSkipPtrFieldSize, ulSkipPtrBitOfst, &ulMask );
		
		ulTempData &= ( ~ulMask );
		ulTempData |= *pulSkipPtr << ulSkipPtrBitOfst;
		
		mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
										pEchoChannel,
										ulAddress,
										ulTempData,
										ulResult );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		/*=======================================================================*/
	}


	/*=======================================================================*/
	/* Fetch and modify the write pointer. */	

	ulAddress = ulPlayoutBaseAddress + ulWritePtrBytesOfst;

	mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
										pEchoChannel,
										ulAddress,
										&ulTempData,
										ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	mOCT6100_CREATE_FEATURE_MASK( ulWritePtrFieldSize, ulWritePtrBitOfst, &ulMask );
	
	ulTempData &= ( ~ulMask );
	ulTempData |= ulWritePtr << ulWritePtrBitOfst;
	
	mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
									pEchoChannel,
									ulAddress,
									ulTempData,
									ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	/*=======================================================================*/
	

	/*=======================================================================*/
	/* Now update the state of the channel stating that the buffer playout is activated. */

	/* Select the buffer of interest.*/
	if ( f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		/* Check if the global ports active stat must be incremented. */
		if ( pEchoChannel->fRinBufPlaying == FALSE )
		{
			/* Increment the number of active buffer playout ports. */
			pSharedInfo->ChipStats.usNumberActiveBufPlayoutPorts++;
		}

		pEchoChannel->fRinBufPlaying = TRUE;
		/* Keep the new notify on event flag. */
		pEchoChannel->fRinBufPlayoutNotifyOnStop = (UINT8)( f_fNotifyOnPlayoutStop & 0xFF );
		/* Keep the specified user event id. */
		pEchoChannel->ulRinUserBufPlayoutEventId = f_ulUserEventId;
		/* Keep type of event to be generated. */
		pEchoChannel->byRinPlayoutStopEventType = (UINT8)( f_ulPlayoutStopEventType & 0xFF );
		/* No hard stop for now. */
		pEchoChannel->fRinHardStop = FALSE;
		/* No buffer added in the rin list for now. */
		pEchoChannel->fRinBufAdded = FALSE;
		/* Buffer playout is active on this channel. */
		pEchoChannel->fBufPlayoutActive = TRUE;
	}
	else /* f_pBufferPlayoutStart->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		/* Check if the global ports active stat must be incremented. */
		if ( pEchoChannel->fSoutBufPlaying == FALSE )
		{
			/* Increment the number of active buffer playout ports. */
			pSharedInfo->ChipStats.usNumberActiveBufPlayoutPorts++;
		}

		pEchoChannel->fSoutBufPlaying = TRUE;
		/* Keep the new notify on event flag. */
		pEchoChannel->fSoutBufPlayoutNotifyOnStop = (UINT8)( f_fNotifyOnPlayoutStop & 0xFF );
		/* Keep the specified user event id. */
		pEchoChannel->ulSoutUserBufPlayoutEventId = f_ulUserEventId;
		/* Keep type of event to be generated. */
		pEchoChannel->bySoutPlayoutStopEventType = (UINT8)( f_ulPlayoutStopEventType & 0xFF );
		/* No hard stop for now. */
		pEchoChannel->fSoutHardStop = FALSE;
		/* No buffer added in the sout list for now. */
		pEchoChannel->fSoutBufAdded = FALSE;
		/* Buffer playout is active on this channel. */
		pEchoChannel->fBufPlayoutActive = TRUE;
	}

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100BufferPlayoutStopSer

Description:    Stops buffer playout on a channel.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutStop	Pointer to buffer playout stop structure.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100BufferPlayoutStopSer(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN OUT	tPOCT6100_BUFFER_PLAYOUT_STOP		f_pBufferPlayoutStop )
{
	UINT32	ulChannelIndex;
	UINT16	usEchoMemIndex;
	UINT32	ulResult;

	/* Check the user's configuration of the buffer for errors. */
	ulResult = Oct6100ApiAssertPlayoutStopParams( 
												f_pApiInstance, 
												f_pBufferPlayoutStop, 
												&ulChannelIndex, 
												&usEchoMemIndex );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	/* Write to  all resources needed to deactivate buffer playout. */
	ulResult = Oct6100ApiInvalidateChanPlayoutStructs( 
												f_pApiInstance, 
												f_pBufferPlayoutStop, 
												ulChannelIndex, 
												usEchoMemIndex 

												);
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiAssertPlayoutStopParams

Description:	Check the validity of the channel and buffer requested.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pBufferPlayoutStop	Pointer to buffer playout stop structure.  
f_pulChannelIndex		Pointer to the channel index on which playout is to be stopped.
f_pusEchoMemIndex		Pointer to the echo mem index on which playout is to be stopped.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiAssertPlayoutStopParams(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_PLAYOUT_STOP		f_pBufferPlayoutStop,
				OUT		PUINT32								f_pulChannelIndex,
				OUT		PUINT16								f_pusEchoMemIndex )
{
	tPOCT6100_API_CHANNEL		pEchoChannel;
	UINT32	ulEntryOpenCnt;

	/* Check for errors. */
	if ( f_pApiInstance->pSharedInfo->ChipConfig.usMaxPlayoutBuffers == 0 )
		return cOCT6100_ERR_BUFFER_PLAYOUT_DISABLED;
	
	if ( f_pBufferPlayoutStop->ulChannelHndl == cOCT6100_INVALID_HANDLE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	if ( f_pBufferPlayoutStop->ulPlayoutPort != cOCT6100_CHANNEL_PORT_ROUT && 
		 f_pBufferPlayoutStop->ulPlayoutPort != cOCT6100_CHANNEL_PORT_SOUT )
		return cOCT6100_ERR_BUFFER_PLAYOUT_PLAYOUT_PORT;

	if ( f_pBufferPlayoutStop->fStopCleanly != TRUE && f_pBufferPlayoutStop->fStopCleanly != FALSE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_STOP_CLEANLY;
	
	/*=====================================================================*/
	/* Check the channel handle. */

	if ( (f_pBufferPlayoutStop->ulChannelHndl & cOCT6100_HNDL_TAG_MASK) != cOCT6100_HNDL_TAG_CHANNEL )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	*f_pulChannelIndex = f_pBufferPlayoutStop->ulChannelHndl & cOCT6100_HNDL_INDEX_MASK;
	if ( *f_pulChannelIndex >= f_pApiInstance->pSharedInfo->ChipConfig.usMaxChannels )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( f_pApiInstance->pSharedInfo, pEchoChannel, *f_pulChannelIndex )

	/* Extract the entry open count from the provided handle. */
	ulEntryOpenCnt = (f_pBufferPlayoutStop->ulChannelHndl >> cOCT6100_ENTRY_OPEN_CNT_SHIFT) & cOCT6100_ENTRY_OPEN_CNT_MASK;

	/* Check for errors. */
	if ( pEchoChannel->fReserved != TRUE )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_NOT_OPEN;
	if ( ulEntryOpenCnt != pEchoChannel->byEntryOpenCnt )
		return cOCT6100_ERR_BUFFER_PLAYOUT_CHANNEL_HANDLE_INVALID;

	/* Return echo memory index. */
	*f_pusEchoMemIndex = pEchoChannel->usEchoMemIndex;

	/* Check if buffer playout is active for the selected port. */
	if ( ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
		&& ( pEchoChannel->fRinBufPlaying == FALSE )
		&& ( pEchoChannel->fRinBufAdded == FALSE ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOT_STARTED;

	if ( ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT )
		&& ( pEchoChannel->fSoutBufPlaying == FALSE )
		 && ( pEchoChannel->fSoutBufAdded == FALSE ) )
		return cOCT6100_ERR_BUFFER_PLAYOUT_NOT_STARTED;
	
	/*=====================================================================*/

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiInvalidateChanPlayoutStructs

Description:    Write the buffer playout event in the channel main structure.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance				Pointer to API instance. This memory is used to keep the
							present state of the chip and all its resources.
	
f_pBufferPlayoutStop		Pointer to buffer playout stop structure.  
f_ulChannelIndex			Index of the channel within the API's channel list.
f_usEchoMemIndex			Index of the echo channel in hardware memory.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiInvalidateChanPlayoutStructs(
				IN OUT	tPOCT6100_INSTANCE_API				f_pApiInstance,
				IN		tPOCT6100_BUFFER_PLAYOUT_STOP		f_pBufferPlayoutStop,
				IN		UINT32								f_ulChannelIndex,
				IN		UINT16								f_usEchoMemIndex

				)
{
	tPOCT6100_API_CHANNEL	pEchoChannel;
	tPOCT6100_SHARED_INFO	pSharedInfo;
	tOCT6100_READ_PARAMS	ReadParams;
	tOCT6100_WRITE_PARAMS	WriteParams;

	UINT32	ulResult;

	UINT32	ulWritePtrBytesOfst;
	UINT32	ulWritePtrBitOfst;
	UINT32	ulWritePtrFieldSize;
	UINT32	ulSkipPtrBytesOfst;
	UINT32	ulSkipPtrBitOfst;
	UINT32	ulSkipPtrFieldSize;
	UINT32	ulIgnoreBytesOfst;
	UINT32	ulIgnoreBitOfst;
	UINT32	ulIgnoreFieldSize;
	UINT32	ulHardSkipBytesOfst;
	UINT32	ulHardSkipBitOfst;
	UINT32	ulHardSkipFieldSize;
	UINT32	ulReadPtrBytesOfst;
	UINT32	ulReadPtrBitOfst;
	UINT32	ulReadPtrFieldSize;

	UINT32	ulSkipPtr;
	UINT32	ulWritePtr;
	UINT32	ulReadPtr = 0;
	UINT32	ulCurrentPtr;

	UINT32	ulPlayoutBaseAddress;
	UINT32	ulAddress;
	UINT32	ulTempData;
	UINT32	ulMask;
	UINT32	ulReadData;

	UINT16	usReadData;	
	BOOL	fCheckStop = FALSE;

	UINT32	ulEventBuffer;

	/* Obtain local pointer to shared portion of instance. */
	pSharedInfo = f_pApiInstance->pSharedInfo;

	WriteParams.pProcessContext = f_pApiInstance->pProcessContext;

	WriteParams.ulUserChipId = f_pApiInstance->pSharedInfo->ChipConfig.ulUserChipId;

	ReadParams.pProcessContext = f_pApiInstance->pProcessContext;

	ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
	ReadParams.pusReadData = &usReadData;

	mOCT6100_GET_CHANNEL_ENTRY_PNT( pSharedInfo, pEchoChannel, f_ulChannelIndex );

	/* Select the port of interest. */
	if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		ulWritePtr = pEchoChannel->ulRinBufWritePtr; 
		ulSkipPtr  = ulWritePtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.usDwordOffset * 4;
		ulWritePtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byBitOffset;
		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutRinWritePtrOfst.byFieldSize;

		ulSkipPtrBytesOfst  = pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.usDwordOffset * 4;
		ulSkipPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.byBitOffset;
		ulSkipPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutRinSkipPtrOfst.byFieldSize;

		ulIgnoreBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.usDwordOffset * 4;
		ulIgnoreBitOfst		= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.byBitOffset;
		ulIgnoreFieldSize	= pSharedInfo->MemoryMap.PlayoutRinIgnoreSkipCleanOfst.byFieldSize;

		ulHardSkipBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.usDwordOffset * 4;
		ulHardSkipBitOfst	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.byBitOffset;
		ulHardSkipFieldSize	= pSharedInfo->MemoryMap.PlayoutRinHardSkipOfst.byFieldSize;

		ulReadPtrBytesOfst	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.usDwordOffset * 4;
		ulReadPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byBitOffset;
		ulReadPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutRinReadPtrOfst.byFieldSize;
	}
	else /* f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		ulWritePtr = pEchoChannel->ulSoutBufWritePtr; 
		ulSkipPtr  = ulWritePtr;

		ulWritePtrBytesOfst = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.usDwordOffset * 4;
		ulWritePtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byBitOffset;
		ulWritePtrFieldSize = pSharedInfo->MemoryMap.PlayoutSoutWritePtrOfst.byFieldSize;

		ulSkipPtrBytesOfst  = pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.usDwordOffset * 4;
		ulSkipPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.byBitOffset;
		ulSkipPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutSkipPtrOfst.byFieldSize;

		ulIgnoreBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.usDwordOffset * 4;
		ulIgnoreBitOfst		= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.byBitOffset;
		ulIgnoreFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutIgnoreSkipCleanOfst.byFieldSize;

		ulHardSkipBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.usDwordOffset * 4;
		ulHardSkipBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.byBitOffset;
		ulHardSkipFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutHardSkipOfst.byFieldSize;

		ulReadPtrBytesOfst	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.usDwordOffset * 4;
		ulReadPtrBitOfst	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byBitOffset;
		ulReadPtrFieldSize	= pSharedInfo->MemoryMap.PlayoutSoutReadPtrOfst.byFieldSize;
	}

	/* Set the playout feature base address. */
	ulPlayoutBaseAddress = cOCT6100_CHANNEL_ROOT_BASE + ( f_usEchoMemIndex * cOCT6100_CHANNEL_ROOT_SIZE ) + pSharedInfo->MemoryMap.ulChanRootConfOfst;

	/* Check if something is currently playing. */
	if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		if ( pEchoChannel->fRinBufPlaying == TRUE )
		{
			/* Check if we are stopping it or if it stopped by itself. */
			fCheckStop = TRUE;
		}
		else
		{
			/* Not playing! */
			if ( f_pBufferPlayoutStop->pfAlreadyStopped != NULL )
				*f_pBufferPlayoutStop->pfAlreadyStopped = TRUE;
		}
	}
	else /* if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) */
	{
		if ( pEchoChannel->fSoutBufPlaying == TRUE )
		{
			/* Check if we are stopping it or if it stopped by itself. */
			fCheckStop = TRUE;
		}
		else
		{
			/* Not playing! */
			if ( f_pBufferPlayoutStop->pfAlreadyStopped != NULL )
				*f_pBufferPlayoutStop->pfAlreadyStopped = TRUE;
		}
	}

	if ( ( fCheckStop == TRUE ) || ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE ) )
	{
		/* Read the read pointer. */
		ReadParams.pProcessContext = f_pApiInstance->pProcessContext;

		ReadParams.ulUserChipId = pSharedInfo->ChipConfig.ulUserChipId;
		ReadParams.pusReadData = &usReadData;
		ReadParams.ulReadAddress = ulPlayoutBaseAddress + ulReadPtrBytesOfst;

		/* Optimize this access by only reading the word we are interested in. */
		if ( ulReadPtrBitOfst < 16 )
			ReadParams.ulReadAddress += 2;

		/* Must read in memory directly since this value is changed by hardware */
		mOCT6100_DRIVER_READ_API( ReadParams, ulResult )
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;

		/* Move data at correct position according to what was read. */
		if ( ulReadPtrBitOfst < 16 )
			ulTempData = usReadData;
		else
			ulTempData = usReadData << 16;
		
		mOCT6100_CREATE_FEATURE_MASK( ulReadPtrFieldSize, ulReadPtrBitOfst, &ulMask );
		
		/* Store the read pointer. */
		ulReadPtr = ( ulTempData & ulMask ) >> ulReadPtrBitOfst;

		/* Playout has finished when the read pointer reaches the write pointer. */
		if ( f_pBufferPlayoutStop->pfAlreadyStopped != NULL )
		{
			if ( ulReadPtr != ulWritePtr )
				*f_pBufferPlayoutStop->pfAlreadyStopped = FALSE;
			else /* if ( ulReadPtr == ulWritePtr ) */
				*f_pBufferPlayoutStop->pfAlreadyStopped = TRUE;
		}
	}

	/* If the skip bits are located in the event itself, the playout is stopped by setting the */
	/* skip pointer to the hardware chip write pointer.  Read it directly from the NLP configuration. */
	if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE )
	{
		if ( ulReadPtr != ulWritePtr )
		{
			/* Get the write pointer in the chip. */
			ulAddress = ulPlayoutBaseAddress + ulWritePtrBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInstance, pEchoChannel, ulAddress, &ulReadData, ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;

			mOCT6100_CREATE_FEATURE_MASK( ulWritePtrFieldSize, ulWritePtrBitOfst, &ulMask );

			/* Store the write pointer. */
			ulWritePtr = ( ulReadData & ulMask ) >> ulWritePtrBitOfst;
			ulSkipPtr = ulWritePtr;
		}
	}

	/* Check if must clear repeat bit. */
	if ( ( ( pEchoChannel->fRinBufPlayoutRepeatUsed == TRUE ) && ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT ) )
		|| ( ( pEchoChannel->fSoutBufPlayoutRepeatUsed == TRUE ) && ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) ) )
	{
		if ( ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE )
			|| ( ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE )
				&& ( ulWritePtr != ulReadPtr ) ) )
		{
			if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
			{
				ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainRinPlayoutMemOfst;
			}
			else /* f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
			{
				ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainSoutPlayoutMemOfst;
			}

			/* Set the playout event base address. */
			if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == TRUE )
				&& ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == TRUE ) )
			{
				/* 127 or 31 events image. */
				ulAddress = pSharedInfo->MemoryMap.ulChanMainMemBase + ( f_usEchoMemIndex * pSharedInfo->MemoryMap.ulChanMainMemSize ) + ulEventBuffer + (cOCT6100_PLAYOUT_EVENT_MEM_SIZE * ( ( ulWritePtr - 1 ) & ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 )));
			}
			else
			{
				/* Old 31 events image. */
				ulAddress = pSharedInfo->MemoryMap.ulChanMainMemBase + ( f_usEchoMemIndex * pSharedInfo->MemoryMap.ulChanMainMemSize ) + ulEventBuffer + (cOCT6100_PLAYOUT_EVENT_MEM_SIZE * ( ( ulWritePtr - 1 ) & 0x1F));
			}

			/* EVENT BASE + 4 */
			/* Playout configuration. */
			ulAddress += 4;

			ReadParams.ulReadAddress = ulAddress;
			mOCT6100_DRIVER_READ_API( ReadParams, ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;

			/* Read-clear-write the new repeat bit. */
			usReadData &= 0x7FFF;

			WriteParams.ulWriteAddress = ulAddress;
			WriteParams.usWriteData = usReadData;
			mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
		}
	}

	/* Write the skip to the value of the write pointer to stop buffer playout. */

	/*=======================================================================*/
	/* First set the ignore skip clean bit if required. */	

	if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == FALSE )
		|| ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == FALSE ) )
	{
		ulAddress = ulPlayoutBaseAddress + ulIgnoreBytesOfst;

		mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											&ulTempData,
											ulResult );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;
		
		mOCT6100_CREATE_FEATURE_MASK( ulIgnoreFieldSize, ulIgnoreBitOfst, &ulMask );
		
		ulTempData &= ( ~ulMask );

		/* Check if the skip need to be clean or not. */
		if ( f_pBufferPlayoutStop->fStopCleanly == FALSE )
			ulTempData |= 0x1 << ulIgnoreBitOfst;
		
		mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
										pEchoChannel,
										ulAddress,
										ulTempData,
										ulResult );
		if ( ulResult != cOCT6100_ERR_OK )
			return ulResult;
	}

	/*=======================================================================*/

	
	/*=======================================================================*/
	/* Fetch and modify the write pointer. */	

	ulAddress = ulPlayoutBaseAddress + ulWritePtrBytesOfst;

	mOCT6100_RETRIEVE_NLP_CONF_DWORD( f_pApiInstance, pEchoChannel, ulAddress, &ulTempData, ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	mOCT6100_CREATE_FEATURE_MASK( ulWritePtrFieldSize, ulWritePtrBitOfst, &ulMask );
	
	ulTempData &= ( ~ulMask );
	ulTempData |= ulWritePtr << ulWritePtrBitOfst;
	
	mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
									pEchoChannel,
									ulAddress,
									ulTempData,
									ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	/*=======================================================================*/

	
	/*=======================================================================*/
	/* Fetch and modify the skip pointer. */	

	ulAddress = ulPlayoutBaseAddress + ulSkipPtrBytesOfst;

	mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
										pEchoChannel,
										ulAddress,
										&ulTempData,
										ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	mOCT6100_CREATE_FEATURE_MASK( ulSkipPtrFieldSize, ulSkipPtrBitOfst, &ulMask );
	
	ulTempData &= ( ~ulMask );
	ulTempData |= ulSkipPtr << ulSkipPtrBitOfst;
	
	mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
									pEchoChannel,
									ulAddress,
									ulTempData,
									ulResult );
	if ( ulResult != cOCT6100_ERR_OK )
		return ulResult;
	
	/*=======================================================================*/
	

	/*=======================================================================*/
	/* If in the new buffer playout case, things are in a different order. */	

	if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE )
	{
		if ( ( pSharedInfo->ImageInfo.fRinBufferPlayoutHardSkip == TRUE )
			&& ( pSharedInfo->ImageInfo.fSoutBufferPlayoutHardSkip == TRUE ) )
		{
			ulAddress = ulPlayoutBaseAddress + ulHardSkipBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
												pEchoChannel,
												ulAddress,
												&ulTempData,
												ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
			
			mOCT6100_CREATE_FEATURE_MASK( ulHardSkipFieldSize, ulHardSkipBitOfst, &ulMask );
			
			ulTempData &= ( ~ulMask );

			/* Check if the skip need to be clean or not. */
			if ( f_pBufferPlayoutStop->fStopCleanly == FALSE )
				ulTempData |= 0x1 << ulHardSkipBitOfst;
			
			mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											ulTempData,
											ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;

			/* Now is the appropriate time to skip! */
			ulAddress = ulPlayoutBaseAddress + ulIgnoreBytesOfst;

			mOCT6100_RETRIEVE_NLP_CONF_DWORD(	f_pApiInstance,
												pEchoChannel,
												ulAddress,
												&ulTempData,
												ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
			
			mOCT6100_CREATE_FEATURE_MASK( ulIgnoreFieldSize, ulIgnoreBitOfst, &ulMask );

			ulTempData &= ( ~ulMask );

			/* Set the skip bit. */
			ulTempData |= 0x1 << ulIgnoreBitOfst;
			
			mOCT6100_SAVE_NLP_CONF_DWORD(	f_pApiInstance,
											pEchoChannel,
											ulAddress,
											ulTempData,
											ulResult );
			if ( ulResult != cOCT6100_ERR_OK )
				return ulResult;
		}
	}

	/*=======================================================================*/


	/*=======================================================================*/
	/* The API must set the skip bit in all the events that are queued. */

	if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE )
	{
		if ( fCheckStop == TRUE )
		{
			if ( ulReadPtr != ulWritePtr )
			{
				if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
				{
					ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainRinPlayoutMemOfst;
				}
				else /* f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
				{
					ulEventBuffer = pSharedInfo->MemoryMap.ulChanMainSoutPlayoutMemOfst;
				}

				for ( ulCurrentPtr = ulReadPtr; ulCurrentPtr != ulWritePtr; )
				{
					/* Set the playout event base address. */
					
					/* 127 or 31 events image. */
					ulAddress = pSharedInfo->MemoryMap.ulChanMainMemBase + ( f_usEchoMemIndex * pSharedInfo->MemoryMap.ulChanMainMemSize ) + ulEventBuffer + ( cOCT6100_PLAYOUT_EVENT_MEM_SIZE * ulCurrentPtr );
					ulCurrentPtr++;
					ulCurrentPtr &= ( pSharedInfo->ImageInfo.byMaxNumberPlayoutEvents - 1 );

					/* EVENT BASE + 0 playout configuration. */
					WriteParams.ulWriteAddress = ulAddress;

					/* Set skip bit + hard-skip bit. */
					WriteParams.usWriteData = 0x8000;
					if ( f_pBufferPlayoutStop->fStopCleanly == FALSE )
						WriteParams.usWriteData |= 0x4000;
					mOCT6100_DRIVER_WRITE_API( WriteParams, ulResult );
					if ( ulResult != cOCT6100_ERR_OK )
						return ulResult;
				}
			}
		}
	}

	/*=======================================================================*/
	/* If stop immediatly, wait the stop before leaving the function. */

	if ( f_pBufferPlayoutStop->fStopCleanly == FALSE )
	{
		/* Remember that an "hard stop" was used for the next start. */
		if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
			pEchoChannel->fRinHardStop = TRUE;
		else /* if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT ) */
			pEchoChannel->fSoutHardStop = TRUE;
	}

	/*=======================================================================*/
	/* Update the channel entry to set the playing flag to FALSE. */

	/* Select the port of interest. */
	if ( f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_ROUT )
	{
		/* Check if the global ports active stat must be decremented. */
		if ( pEchoChannel->fRinBufPlaying == TRUE )
		{
			/* Decrement the number of active buffer playout ports. */
			pSharedInfo->ChipStats.usNumberActiveBufPlayoutPorts--;
		}

		pEchoChannel->fRinBufPlaying = FALSE;

		/* Return user information. */
		if ( f_pBufferPlayoutStop->pfNotifyOnPlayoutStop != NULL )
			*f_pBufferPlayoutStop->pfNotifyOnPlayoutStop = pEchoChannel->fRinBufPlayoutNotifyOnStop;

		/* Make sure no new event is recorded for this channel/port. */
		pEchoChannel->fRinBufPlayoutNotifyOnStop = FALSE;
		if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE )
		{
			pEchoChannel->ulRinBufSkipPtr = ulSkipPtr;
			pEchoChannel->ulRinBufWritePtr = ulWritePtr;
		}
		else /* if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE ) */
			pEchoChannel->ulRinBufSkipPtr = pEchoChannel->ulRinBufWritePtr;

		/* The repeat flag can now be used. */
		pEchoChannel->fRinBufPlayoutRepeatUsed = FALSE;

		/* For sure, all buffers have now been cleared on the Rin port. */
		pEchoChannel->fRinBufAdded = FALSE;

		/* Clear optimization flag if possible. */
		if ( ( pEchoChannel->fSoutBufPlaying == FALSE )
			&& ( pEchoChannel->fSoutBufPlayoutNotifyOnStop == FALSE ) )
		{
			/* Buffer playout is no more active on this channel. */
			pEchoChannel->fBufPlayoutActive = FALSE;
		}
	}
	else /* f_pBufferPlayoutStop->ulPlayoutPort == cOCT6100_CHANNEL_PORT_SOUT */
	{
		/* Check if the global ports active stat must be decremented. */
		if ( pEchoChannel->fSoutBufPlaying == TRUE )
		{
			/* Decrement the number of active buffer playout ports. */
			pSharedInfo->ChipStats.usNumberActiveBufPlayoutPorts--;
		}

		pEchoChannel->fSoutBufPlaying = FALSE;

		/* Return user information. */
		if ( f_pBufferPlayoutStop->pfNotifyOnPlayoutStop != NULL )
			*f_pBufferPlayoutStop->pfNotifyOnPlayoutStop = pEchoChannel->fSoutBufPlayoutNotifyOnStop;

		/* Make sure no new event is recorded for this channel/port. */
		pEchoChannel->fSoutBufPlayoutNotifyOnStop = FALSE;
		if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == TRUE )
		{
			pEchoChannel->ulSoutBufSkipPtr = ulSkipPtr;
			pEchoChannel->ulSoutBufWritePtr = ulWritePtr;
		}
		else /* if ( pSharedInfo->ImageInfo.fBufferPlayoutSkipInEvents == FALSE ) */
			pEchoChannel->ulSoutBufSkipPtr = pEchoChannel->ulSoutBufWritePtr;

		/* The repeat flag can now be used. */
		pEchoChannel->fSoutBufPlayoutRepeatUsed = FALSE;

		/* For sure, all buffers have now been cleared on the Sout port. */
		pEchoChannel->fSoutBufAdded = FALSE;

		/* Clear optimization flag if possible. */
		if ( ( pEchoChannel->fRinBufPlaying == FALSE )
			&& ( pEchoChannel->fRinBufPlayoutNotifyOnStop == FALSE ) )
		{
			/* Buffer playout is no more active on this channel. */
			pEchoChannel->fBufPlayoutActive = FALSE;
		}
	}

	/*=======================================================================*/



	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiReserveBufPlayoutListEntry

Description:    Reserves a free entry in the Buffer playout list.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_pulBufferIndex		List entry reserved.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiReserveBufPlayoutListEntry(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				OUT		PUINT32							f_pulBufferIndex )
{
	PVOID	pBufPlayoutAlloc;
	UINT32	ulResult;

	mOCT6100_GET_BUFFER_ALLOC_PNT( f_pApiInstance->pSharedInfo, pBufPlayoutAlloc )

	ulResult = OctapiLlmAllocAlloc( pBufPlayoutAlloc, f_pulBufferIndex );
	if ( ulResult != cOCT6100_ERR_OK )
	{
		if ( ulResult == OCTAPI_LLM_NO_STRUCTURES_LEFT )
			return cOCT6100_ERR_BUFFER_PLAYOUT_ALL_BUFFERS_OPEN;
		else
			return cOCT6100_ERR_FATAL_40;
	}

	return cOCT6100_ERR_OK;
}


/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\

Function:		Oct6100ApiReleaseBufPlayoutListEntry

Description:    Release an entry from the Buffer playout list.

-------------------------------------------------------------------------------
|	Argument		|	Description
-------------------------------------------------------------------------------
f_pApiInstance			Pointer to API instance. This memory is used to keep the
						present state of the chip and all its resources.

f_ulBufferIndex			List entry to be freed.

\*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
UINT32 Oct6100ApiReleaseBufPlayoutListEntry(
				IN OUT	tPOCT6100_INSTANCE_API			f_pApiInstance,
				IN		UINT32							f_ulBufferIndex )
{
	PVOID	pBufPlayoutAlloc;
	UINT32	ulResult;

	mOCT6100_GET_BUFFER_ALLOC_PNT( f_pApiInstance->pSharedInfo, pBufPlayoutAlloc )

	ulResult = OctapiLlmAllocDealloc( pBufPlayoutAlloc, f_ulBufferIndex );
	if ( ulResult != cOCT6100_ERR_OK )
		return cOCT6100_ERR_FATAL_41;

	return cOCT6100_ERR_OK;
}