This file is indexed.

/usr/include/gmerlin/avdec.h is in libgmerlin-avdec-dev 1.2.0~dfsg-9build2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
/*****************************************************************
 * gmerlin-avdecoder - a general purpose multimedia decoding library
 *
 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
 * gmerlin-general@lists.sourceforge.net
 * http://gmerlin.sourceforge.net
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 * *****************************************************************/

/* Public entry points */

/**
 * @file avdec.h
 * external api header.
 */

#include <gavl/gavl.h>
#include <gavl/compression.h>
#include <gavl/metadata.h>

#include "bgavdefs.h" // This is ugly, but works

#ifdef __cplusplus
extern "C" {
#endif

/** \ingroup edl
 *  \brief Forward declaration
 */

typedef struct bgav_edl_s bgav_edl_t;

/** \defgroup decoding Decoding of multimedia streams
 *
 *  Setting up a decoder is a multi-step process. It might be a bit complicated,
 *  but it provides support for many different multimedia sources through a single
 *  API.
 *
 *  First you need to create a decoder instance (see \ref decoder). Then you might want to
 *  change some options and set callbacks (see \ref options). The opening can happen with
 *  different functions (see \ref opening). If you also open URLs, it can happen, that
 *  you opened a redirector (see \ref redirector).
 *
 *  If you have no redirector, the decoder can have an arbitrary number of tracks. You
 *  can query various informations about the tracks and must select the track you want
 *  (see \ref track).
 *
 *  Once a track is opened, you must set up the streams (See \ref streams). To tell the decoder,
 *  that you are done, call \ref bgav_start. This will start all codecs. Once the codecs are initialized,
 *  you can get informations about the streams (see \ref stream_info).
 *  Then you are ready to decode media frames (see \ref decode).
 *  In many streams you can also seek  (see \ref seeking).
 *  
 */ 

/** \defgroup decoder Creating and destroying a decoder
 *  \ingroup decoding
 */

/*! \ingroup decoder
 * \brief Opaque decoder structure
 *
 * You don't want to know, what's inside here
 */

typedef struct bgav_s bgav_t;

/*! \ingroup decoder
 * \brief Create a decoder instance
 * \returns A newly allocated decoder instance
 */

BGAV_PUBLIC
bgav_t * bgav_create();

/** \defgroup options Configuration of a decoder
 *  \ingroup decoding
 *
 *  These functions are used to configure a decoder and to set callback functions.
 *  After you created a \ref bgav_t object, get it's options
 *  with \ref bgav_get_options. All options are returned in an option container
 *  (\ref bgav_options_t), and the bgav_options_set_* functions allow you
 *  to change single options. 
 *  As an alternative, you can create an independent option container with
 *  \ref bgav_options_create, change it as you like and use \ref bgav_options_copy to
 *  copy them to the container you got with \ref bgav_get_options.
 *
 *  All options become valid with (and should not be changed after) the
 *  call to one of the bgav_open* functions.
 */

/** \defgroup opening Opening a media stream
 *  \ingroup decoding
 *  \brief Various methods of opening a media stream
 */

/** \defgroup metadata Metadata
 */

/** \ingroup metadata
 * \brief Opaque metadata container
 *
 * This structure is returned by \ref bgav_get_metadata
 */

typedef gavl_metadata_t bgav_metadata_t;

/** \ingroup metadata
 * \brief Get the author (or composer) of the track
 * \param metadata Metadata container
 * \returns The author of the track in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_author(const bgav_metadata_t*metadata);

/** \ingroup metadata
 * \brief Get the title of the track
 * \param metadata Metadata container
 * \returns The title of the track in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_title(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get an additional comment of the track
 * \param metadata Metadata container
 * \returns The comment in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_comment(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the copyright notice of the track
 * \param metadata Metadata container
 * \returns The copyright notice in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_copyright(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the album this track comes from
 * \param metadata Metadata container
 * \returns The album in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_album(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the artist (or performer) of this track
 * \param metadata Metadata container
 * \returns The artist in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_artist(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the album artist of this track
 * \param metadata Metadata container
 * \returns The album artist in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_albumartist(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the genre this track belongs to
 * \param metadata Metadata container
 * \returns The genre in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_genre(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the date of the recording
 * \param metadata Metadata container
 * \returns The date in UTF-8 or NULL
 */

BGAV_PUBLIC
const char * bgav_metadata_get_date(const bgav_metadata_t * metadata);

/** \ingroup metadata
 * \brief Get the track index
 * \param metadata Metadata container
 * \returns The track index or 0
 */

BGAV_PUBLIC
int bgav_metadata_get_track(const bgav_metadata_t * metadata);

/***************************************************
 * Housekeeping Functions
 ***************************************************/

/***************************************************
 * Set parameters
 ***************************************************/


/** \ingroup options
 * \brief Opaque option container
 */

typedef struct bgav_options_s bgav_options_t;

/** \ingroup options
 * \brief Get the options of a decoder instance
 * \returns Options
 *
 * Use this to get the options container. You can use the bgav_options_set_* functions
 * to change the options. Options will become valid when you call one of the
 * bgav_open*() functions.
 */

BGAV_PUBLIC
bgav_options_t * bgav_get_options(bgav_t * bgav);

/** \ingroup options
 *  \brief Create an options container
 *  \returns A newly allocated option container
 *
 * This function returns a newly allocated option container
 * filled with default values. Use this, if you need to store
 * decoder options independently from decoder instances.
 * To destroy the container again, use \ref bgav_options_destroy.
 *
 * To pass the options to a decoder structure, use \ref bgav_get_options
 * and \ref bgav_options_copy.
 *
 */

BGAV_PUBLIC
bgav_options_t * bgav_options_create();

/** \ingroup options
 *  \brief Destroy option cotainer.
 *  \param opt option cotainer
 *
 * Use the only to destroy options, you created with \ref bgav_options_create.
 * Options returned by \ref bgav_get_options are owned by the \ref bgav_t instance,
 * and must not be freed by you.
 */

BGAV_PUBLIC
void bgav_options_destroy(bgav_options_t * opt);

/** \ingroup options
 *  \brief Copy options
 *  \param dst Destination
 *  \param src Source
 */

BGAV_PUBLIC
void bgav_options_copy(bgav_options_t * dst, const bgav_options_t * src);

/** \ingroup options
 *  \brief Set connect timeout
 *  \param opt Option container
 *  \param timeout Timeout in milliseconds.
 *
 *  This timeout will be used until the connection is ready to
 *  receive media data.
 */

BGAV_PUBLIC
void bgav_options_set_connect_timeout(bgav_options_t * opt, int timeout);

/** \ingroup options
 *  \brief Set read timeout
 *  \param opt Option container
 *  \param timeout Timeout in milliseconds.
 *
 *  This timeout will be used during streaming to detect server/connection
 *  failures.
 */

BGAV_PUBLIC
void bgav_options_set_read_timeout(bgav_options_t * opt, int timeout);

/** \ingroup options
 *  \brief Set RTP port pase
 *  \param opt Option container
 *  \param p Port base
 *
 *  Values below and including 1024 enable random
 *  ports. Random ports should be used if you have no or an
 *  RTSP aware firewall. Values above 1024 enable a fixed base port.
 *  For usual videos (one audio- one videostream) you need 4 consecutive
 *  open ports starting with the base port. If your firewall blocks all UDP
 *  traffic, use \ref bgav_options_set_rtp_try_tcp.
 */


BGAV_PUBLIC
void bgav_options_set_rtp_port_base(bgav_options_t * opt, int p);

/** \ingroup options
 *  \brief Try TCP before UDP
 *  \param opt Option container
 *  \param enable 1 to try TCP, 0 else
 *
 *  Use this if your firewall blocks all UDP traffic. Not all servers,
 *  however, support TCP fallback.
 */

BGAV_PUBLIC
void bgav_options_set_rtp_try_tcp(bgav_options_t * opt, int enable);

/** \ingroup options
 *  \brief Set network bandwidth
 *  \param opt Option container
 *  \param bandwidth Bandwidth of your internet connection (in bits per second)
 *
 *  Some network protocols allow
 *  to select among multiple streams according to the speed of the internet connection.
 */

BGAV_PUBLIC
void bgav_options_set_network_bandwidth(bgav_options_t * opt, int bandwidth);

/** \ingroup options
 *  \brief Set network buffer size
 *  \param opt Option container
 *  \param size Buffer size in bytes
 *
 *  Set the size of the network buffer.
 *  \todo Make buffer size depend on the stream bitrate.
 */

BGAV_PUBLIC
void bgav_options_set_network_buffer_size(bgav_options_t * opt, int size);

/* HTTP Options */

/** \ingroup options
 *  \brief Set proxy usage
 *  \param opt Option container
 *  \param enable Set 1 of you use a http proxy, 0 else.
 *
 *  Set usage of a http proxy. If you enable proxies, you must specify the proxy
 *  host with \ref bgav_options_set_http_proxy_host and the proxy port with
 *  \ref bgav_options_set_http_proxy_port.
 */

BGAV_PUBLIC
void bgav_options_set_http_use_proxy(bgav_options_t* opt, int enable);

/** \ingroup options
 *  \brief Set proxy host
 *  \param opt Option container
 *  \param host Hostname of the proxy.
 *
 *  Note that you must enable proxies with \ref bgav_options_set_http_use_proxy before
 *  it's actually used.
 */

BGAV_PUBLIC
void bgav_options_set_http_proxy_host(bgav_options_t* opt, const char * host);

/** \ingroup options
 *  \brief Set proxy port
 *  \param opt Option container
 *  \param port Port of the proxy.
 *
 *  Note that you must enable proxies with \ref bgav_options_set_http_use_proxy before
 *  it's actually used.
 */

BGAV_PUBLIC
void bgav_options_set_http_proxy_port(bgav_options_t* opt, int port);

/** \ingroup options
 *  \brief Enable or disable proxy authentication.
 *  \param opt Option container
 *  \param enable Set 1 if your http proxy needs authentication, 0 else.
 *
 *  If you enable http proxy authentication, you must specify the username
 *  host with \ref bgav_options_set_http_proxy_user and the proxy password with
 *  \ref bgav_options_set_http_proxy_pass.
 */

BGAV_PUBLIC
void bgav_options_set_http_proxy_auth(bgav_options_t* opt, int enable);

/** \ingroup options
 *  \brief Set proxy username
 *  \param opt Option container
 *  \param user The username for the proxy.
 *
 *  Note that you must enable proxy authentication with \ref bgav_options_set_http_proxy_auth.
 */

BGAV_PUBLIC
void bgav_options_set_http_proxy_user(bgav_options_t* opt, const char * user);

/** \ingroup options
 *  \brief Set proxy password
 *  \param opt Option container
 *  \param pass The password for the proxy.
 *
 *  Note that you must enable proxy authentication with \ref bgav_options_set_http_proxy_auth.
 */

BGAV_PUBLIC
void bgav_options_set_http_proxy_pass(bgav_options_t* opt, const char * pass);

/** \ingroup options
 *  \brief Enable or disable shoutcast metadata streaming
 *  \param opt Option container
 *  \param enable Set to 1 if the decoder should try to get shoutcast metadata, 0 else
 *
 * Normally it's ok to enable shoutcast metadata streaming even if we connect to non-shoutcast servers.
 */

BGAV_PUBLIC
void bgav_options_set_http_shoutcast_metadata(bgav_options_t* opt, int enable);

/* Set FTP options */

/** \ingroup options
 *  \brief Enable or disable anonymous ftp login
 *  \param opt Option container
 *  \param enable Set to 1 if the decoder should try log anonymously into ftp servers, 0 else
 */

BGAV_PUBLIC
void bgav_options_set_ftp_anonymous(bgav_options_t* opt, int enable);

/** \ingroup options
 *  \brief Set anonymous password
 *  \param opt Option container
 *  \param pass
 *
 *  Note that you must enable anonymous ftp login with \ref bgav_options_set_ftp_anonymous.
 */

BGAV_PUBLIC
void bgav_options_set_ftp_anonymous_password(bgav_options_t* opt, const char* pass);

/** \ingroup options
 *  \brief Set default subtitle encoding
 *  \param opt Option container
 *  \param encoding Encoding
 *
 *  This sets the default encoding for text subtitles, when the right
 *  encoding is unknown. It must be a character set name recognized by
 *  iconv. Type "iconv -l" at the commandline for a list of supported
 *  encodings).
 */

BGAV_PUBLIC
void bgav_options_set_default_subtitle_encoding(bgav_options_t* opt,
                                                const char* encoding);

/** \ingroup options
 *  \brief Enable dynamic range control
 *  \param opt Option container
 *  \param audio_dynrange 1 for enabling dynamic range control.
 *
 *  This enables dynamic range control for codecs, which supports it.
 *  By default dynamic range control is enabled. Use this function to switch it
 *  off for the case, that you have a better dynamic range control in your processing pipe.
 */

BGAV_PUBLIC
void bgav_options_set_audio_dynrange(bgav_options_t* opt,
                                     int audio_dynrange);


/** \ingroup options
 *  \brief Try to be sample accurate
 *  \param opt Option container
 *  \param enable Specifies how sample accurate mode should be enabled (see below)
 *
 *  If enable is 0, sample accuracy will never be enabled. If enable is 1,
 *  sample accuracy will always (whenever possible) be enabled. If enable is 2,
 *  sample accuracy will only be enabled, if the file would not be seekable otherwise.
 *
 *  When switching to sample accurate mode, other demultiplexing
 *  methods are enabled, which might slow things down a bit.
 */

BGAV_PUBLIC
void bgav_options_set_sample_accurate(bgav_options_t*opt, int enable);

/** \ingroup options
 *  \brief Set the index creation time for caching
 *  \param opt Option container
 *  \param t Time (in milliseconds) needed for creating the index
 *
 *  This option controls, which indices are cached, based on the
 *  time needed for creating the index. Indices, whose creation takes
 *  longer than the specified time will be cached. If you set this to
 *  zero, all indices are cached.
 */

BGAV_PUBLIC
void bgav_options_set_cache_time(bgav_options_t*opt, int t);

/** \ingroup options
 *  \brief Set the maximum total size of the index cache
 *  \param opt Option container
 *  \param s Maximum size (in megabytes) of the whole cache directory
 *
 *  If a new index is created and the size becomes larger than
 *  the maximum size, older indices will be deleted. Zero means infinite.
 */

BGAV_PUBLIC
void bgav_options_set_cache_size(bgav_options_t*opt, int s);

/** \ingroup options
 *  \brief Enable external subtitle files
 *  \param opt Option container
 *  \param seek_subtitles If 1, subtitle files will be seeked for video files. If 2, subtitles
        will be seeked for all files.
 *
 *  If the input is a regular file, gmerlin_avdecoder can scan the
 *  directory for matching subtitle files. For a file movie.mpg, possible
 *  subtitle files are e.g. movie_english.srt, movie_german.srt. The
 *  rule is, that the first part of the filename of the subtitle file
 *  must be equal to the movie filename up to the extension (hiere: .mpg).
 *  Furthermore, the subtitle filename must have an extension supported by
 *  any of the subtitle readers.
 */

BGAV_PUBLIC
void bgav_options_set_seek_subtitles(bgav_options_t* opt,
                                    int seek_subtitles);

/** \ingroup options
 *  \brief Set postprocessing level
 *  \param opt Option container
 *  \param pp_level Value between 0 (no postprocessing) and 6 (maximum postprocessing)
 *
 *  Warning: This function is depracated, use \ref bgav_options_set_postprocessing_level
 *  instead.
 */

BGAV_PUBLIC
void bgav_options_set_pp_level(bgav_options_t* opt,
                               int pp_level);

/** \ingroup options
 *  \brief Set postprocessing level
 *  \param opt Option container
 *  \param pp_level Value between 0.0 (no postprocessing) and 1.0 (maximum postprocessing)
 *
 *  Since 1.0.2
 */

BGAV_PUBLIC
void bgav_options_set_postprocessing_level(bgav_options_t* opt,
                                           float pp_level);

/** \ingroup options
 *  \brief Set number of threads
 *  \param opt Option container
 *  \param threads Number of threads to use
 *
 *   Not all codecs support this
 */

BGAV_PUBLIC
void bgav_options_set_threads(bgav_options_t * opt, int threads);

  
/** \ingroup options
 *  \brief Set DVB channels file
 *  \param opt Option container
 *  \param file Name of the channel configurations file
 *
 *  The channels file must have the format of the dvb-utils
 *  programs (like szap, tzap). If you don't set this file,
 *  several locations like $HOME/.tzap/channels.conf will be
 *  searched.
 */

BGAV_PUBLIC
void bgav_options_set_dvb_channels_file(bgav_options_t* opt,
                                        const char * file);

/** \ingroup options
 *  \brief Preference of ffmpeg demultiplexers
 *  \param opt Option container
 *  \param prefer 1 to prefer ffmpeg demultiplexers, 0 else
 *
 *  Usually, native demultiplexers are prefered over the
 *  ffmpeg ones. This function allows you to chnage that.
 *  If gmerlin_avdecoder was compiled without libavformat support,
 *  this function is meaningless.
 */

BGAV_PUBLIC
void bgav_options_set_prefer_ffmpeg_demuxers(bgav_options_t* opt,
                                             int prefer);

/** \ingroup options
 *  \brief Exports the date and time as timecode field of DV streams
 *  \param opt Option container
 *  \param datetime 1 to export date and time as timecodes, 0 else
 */

BGAV_PUBLIC
void bgav_options_set_dv_datetime(bgav_options_t* opt,
                                  int datetime);

/** \ingroup options
 *  \brief Shrink factor
 *  \param opt Option container
 *  \param factor Exponent of the shrink factor
 *
 *  This enables downscaling of images while decoding.
 *  Currently only supported for JPEG-2000.
 */

BGAV_PUBLIC
void bgav_options_set_shrink(bgav_options_t* opt,
                             int factor);

/** \ingroup options
 *  \brief VDPAU acceleration
 *  \param opt Option container
 *  \param vdpau 1 to enable vdpau, 0 else
 *
 *  Since 1.0.2
 */

BGAV_PUBLIC
void bgav_options_set_vdpau(bgav_options_t* opt,
                            int vdpau);

/** \ingroup options
 *  \brief Dump file headers
 *  \param opt Option container
 *  \param enable 1 to dump file headers, 0 else
 *
 *  Since 1.1.1
 */

BGAV_PUBLIC
void bgav_options_set_dump_headers(bgav_options_t* opt,
                                   int enable);

/** \ingroup options
 *  \brief Dump file indices
 *  \param opt Option container
 *  \param enable 1 to dump file indices, 0 else
 *
 *  Since 1.1.1
 */

BGAV_PUBLIC
void bgav_options_set_dump_indices(bgav_options_t* opt,
                                   int enable);

  

/** \ingroup options
 *  \brief Enumeration for log levels
 *
 * These will be called from within log callbacks
 */

typedef enum
  {
    BGAV_LOG_DEBUG   = (1<<0),
    BGAV_LOG_WARNING = (1<<1),
    BGAV_LOG_ERROR   = (1<<2),
    BGAV_LOG_INFO    = (1<<3)
  } bgav_log_level_t;

/** \ingroup options
 *  \brief Function to be called for loggins messages
 *  \param data The data you passed to \ref bgav_options_set_log_callback.
 *  \param level The log level
 *  \param log_domain A string describing the module from which the message comes
 *  \param message The message itself
 */
 
typedef void (*bgav_log_callback)(void*data, bgav_log_level_t level,
                                  const char * log_domain,
                                  const char * message);

/** \ingroup options
 *  \brief Set the callback for log messages
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */

BGAV_PUBLIC void
bgav_options_set_log_callback(bgav_options_t* opt,
                              bgav_log_callback callback,
                              void * data);

/** \ingroup options
 *  \brief Set the verbosity for log messages
 *  \param opt Option container
 *  \param level ORed flags of type bgav_log_level_t
 *
 *  Since 1.1.0
 */

BGAV_PUBLIC void
bgav_options_set_log_level(bgav_options_t* opt,
                           int level);
  
  

/* Set callbacks */

/** \ingroup options
 *  \brief Function to be called if the track name changes
 *  \param data The data you passed to \ref bgav_options_set_name_change_callback.
 *  \param name The new name of the track
 *
 *  This function will be called whenever the name of the track changed. Such changes
 *  can have different reasons, the most obvious one is a song change in a webradio stream.
 */
 
typedef void (*bgav_name_change_callback)(void*data, const char * name);

/** \ingroup options
 *  \brief Set the callback for name change events
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */

BGAV_PUBLIC void
bgav_options_set_name_change_callback(bgav_options_t* opt,
                                      bgav_name_change_callback callback,
                                      void * data);

/** \ingroup options
 *  \brief Function to be called if the metadata change
 *  \param data The data you passed to \ref bgav_options_set_metadata_change_callback.
 *  \param metadata The new metadata of the track
 *
 *  This function will be called whenever the metadata of the track changed. Such changes
 *  can have different reasons, the most obvious one is a song change in a webradio stream.
 */


typedef void (*bgav_metadata_change_callback)(void*data, const bgav_metadata_t * metadata);

/** \ingroup options
 *  \brief Set the callback for metadata change events
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */

BGAV_PUBLIC void
bgav_options_set_metadata_change_callback(bgav_options_t* opt,
                                          bgav_metadata_change_callback callback,
                                          void * data);

/** \ingroup options
 *  \brief Function to be called if the input module is buffering data
 *  \param data The data you passed to \ref bgav_options_set_buffer_callback.
 *  \param percentage The percentage done so far (0.0 .. 1.0)
 *
 *  This function will be called when the input module fills a buffer.
 *  It is called multiple times with increasing percentage.
 */

typedef void (*bgav_buffer_callback)(void*data, float percentage);

/** \ingroup options
 *  \brief Set the callback for buffering notification
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */
  
BGAV_PUBLIC void
bgav_options_set_buffer_callback(bgav_options_t* opt,
                                 bgav_buffer_callback callback,
                                 void * data);

/** \ingroup options
 *  \brief Function to be called if the input module needs authentication data
 *  \param data The data you passed to \ref bgav_options_set_user_pass_callback.
 *  \param resource A string describing the resource (e.g. the hostname of the server)
 *  \param username Returns the username.
 *  \param password Returns the password.
 *  \returns 1 of the username and password are valid, 0 if the user cancelled the authentication.
 *
 *  This is called during one of the bgav_open* calls.
 */

typedef int (*bgav_user_pass_callback)(void*data, const char * resource,
                                       char ** username, char ** password);
  
/** \ingroup options
 *  \brief Set the callback for user authentication
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 *
 *  Note that there is no default authentication built into the library.
 *  Therefore you MUST set a callback, otherwise urls which require the user to
 *  enter authentication data, cannot be openend.
 */

BGAV_PUBLIC void
bgav_options_set_user_pass_callback(bgav_options_t* opt,
                                    bgav_user_pass_callback callback,
                                    void * data);

/** \ingroup options
 *  \brief Function to be called if a change of the aspect ratio was detected
 *  \param data The data you passed to \ref bgav_options_set_aspect_callback.
 *  \param stream Index of the video stream (starts with 0)
 *  \param pixel_width New pixel width
 *  \param pixel_height New pixel height
 *
 *  This is called during \ref bgav_read_video.
 */

typedef void (*bgav_aspect_callback)(void*data, int stream,
                                     int pixel_width, int pixel_height);


/** \ingroup options
 *  \brief Set aspect ratio change callback
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */

BGAV_PUBLIC void
bgav_options_set_aspect_callback(bgav_options_t* opt,
                                 bgav_aspect_callback callback,
                                 void * data);

/** \ingroup options
 *  \brief Function to be called periodically while an index is built
 *  \param data The data you passed to \ref bgav_options_set_index_callback.
 *  \param perc Percentage completed to far
 *
 */

typedef void (*bgav_index_callback)(void*data, float percentage);

/** \ingroup options
 *  \brief Set index build callback
 *  \param opt Option container
 *  \param callback The callback
 *  \param data Some data you want to get passed to the callback
 */

BGAV_PUBLIC void
bgav_options_set_index_callback(bgav_options_t* opt,
                                bgav_index_callback callback,
                                void * data);


/* Device description */

/** \defgroup devices Device description
 *  \brief Device description
 *
 *  The input modules, which access special hardware devices (e.g. CD drives),
 *  have autoscanning functionality built in. You can call one of the bgav_find_devices_* functions
 *  to get a list of supported devices (see \ref bgav_device_info_t). The created list must be
 *  freed with \ref bgav_device_info_destroy when it's no longer used.
 */

/** \ingroup devices
 *  \brief Info structure for a device.
 *
 * This contains information about a device: The device node name (which can be passed to
 * the bgav_open_* function) and, if available, a human readable description. The last element
 * in the array has the device string set to NULL and terminates the array.
 */

typedef struct
  {
  char * device; /*!< Can be passed to the bgav_open_*() function */
  char * name;   /*!< Device name, might be NULL */
  } bgav_device_info_t;

/* Scan for devices */

/** \ingroup devices
 *  \brief Scan for VCD capable devices
 *  \returns A \ref bgav_device_info_t array or NULL
 *
 *  Free the returned array with \ref bgav_device_info_destroy
 */

BGAV_PUBLIC
bgav_device_info_t * bgav_find_devices_vcd();

/** \ingroup devices
 *  \brief Test if a device is VCD capable
 *  \param device The device node name
 *  \param name Returns a human readable decription in a newly allocated string or NULL
 *  \returns 1 if the device can play VCDs, 0 else.
*/

BGAV_PUBLIC
int bgav_check_device_vcd(const char * device, char ** name);

/** \ingroup devices
 *  \brief Scan for DVD capable devices
 *  \returns A \ref bgav_device_info_t array or NULL
 *
 *  Free the returned array with \ref bgav_device_info_destroy
 */

BGAV_PUBLIC
bgav_device_info_t * bgav_find_devices_dvd();

/** \ingroup devices
 *  \brief Test if a device is DVD capable
 *  \param device The device node name
 *  \param name Returns a human readable decription in a newly allocated string or NULL
 *  \returns 1 if the device can play DVDs, 0 else.
*/

BGAV_PUBLIC
int bgav_check_device_dvd(const char * device, char ** name);

/** \ingroup devices
 *  \brief Scan for DVB capable devices
 *  \returns A \ref bgav_device_info_t array or NULL
 *
 *  Free the returned array with \ref bgav_device_info_destroy
 */

BGAV_PUBLIC
bgav_device_info_t * bgav_find_devices_dvb();

/** \ingroup devices
 *  \brief Test if a device is DVB capable
 *  \param device The directory (e.g. /dev/dvb/adaptor0)
 *  \param name Returns a human readable decription in a newly allocated string or NULL
 *  \returns 1 if the device is ready to receive DVB streams, 0 else.
*/

BGAV_PUBLIC
int bgav_check_device_dvb(const char * device, char ** name);

/** \ingroup devices
 *  \brief Destroy a device info array
 *  \param arr A device info returned by \ref bgav_find_devices_dvd, \ref bgav_find_devices_dvb or \ref bgav_find_devices_dvd
 */


BGAV_PUBLIC
void bgav_device_info_destroy(bgav_device_info_t * arr);

/** \ingroup devices
 *  \brief Eject a disc
 *  \param device Device name
 *  \return 1 if the disc could be ejected, 0 else
 */

BGAV_PUBLIC
int bgav_eject_disc(const char * device);

/** \ingroup devices
 *  \brief Get the name of a disc
 *  \param bgav A decoder instance
 *  \return The name of the disc, or NULL if it's not known or irrelevant
 */

BGAV_PUBLIC
const char * bgav_get_disc_name(bgav_t * bgav);

/******************************************************
 * Open
 ******************************************************/

/* Open a file or URL, return 1 on success */

/** \ingroup opening
 *  \brief Open a file or URL
 *  \param bgav A decoder instance
 *  \param location The URL or path to open
 *  \returns 1 if the location was successfully openend, 0 else.
 */

BGAV_PUBLIC
int bgav_open(bgav_t * bgav, const char * location);

/** \ingroup opening
 *  \brief Open a VCD device
 *  \param bgav A decoder instance
 *  \param location The device node
 *  \returns 1 if the VCD device was successfully openend, 0 else.
 */

BGAV_PUBLIC
int bgav_open_vcd(bgav_t * bgav, const char * location);

/** \ingroup opening
 *  \brief Open a DVD device
 *  \param bgav A decoder instance
 *  \param location The device node
 *  \returns 1 if the DVD device was successfully openend, 0 else.
 */

BGAV_PUBLIC
int bgav_open_dvd(bgav_t * bgav, const char * location);

/** \ingroup opening
 *  \brief Open a DVB device
 *  \param bgav A decoder instance
 *  \param location The device directory
 *  \returns 1 if the DVB device was successfully openend, 0 else.
 *
 *  This function will search your system for channel configuration files,
 *  which are created by other tools. The channels are then available as
 *  normal tracks.
 */

BGAV_PUBLIC
int bgav_open_dvb(bgav_t * bgav, const char * location);


/** \ingroup opening
 *  \brief Open a decoder from a filedescriptor
 *  \param bgav A decoder instance
 *  \param fd The filedescriptor
 *  \param total_size The total number of available bytes or 0 if this info is not known.
 *  \param mimetype The mimetype of the input or NULL if this info is not known.
 *  \returns 1 if the filedescriptor was successfully openend, 0 else.
 */

BGAV_PUBLIC
int bgav_open_fd(bgav_t * bgav, int fd,
                 int64_t total_size,
                 const char * mimetype);

/** \ingroup opening
 *  \brief Open a decoder with callbacks
 *  \param bgav A decoder instance
 *  \param read_callback Callback for reading data
 *  \param seek_callback Callback for seeking
 *  \param priv Private argument for the callbacks
 *  \param filename The filename of the input or NULL if this info is not known.
 *  \param mimetype The mimetype of the input or NULL if this info is not known.
 *  \param total_bytes File size in bytes or 0 if this info is not known.
 *  \returns 1 on success, 0 else.
 */

BGAV_PUBLIC
int bgav_open_callbacks(bgav_t * bgav,
                        int (*read_callback)(void * priv, uint8_t * data, int len),
                        int64_t (*seek_callback)(void * priv, uint64_t pos, int whence),
                        void * priv,
                        const char * filename, const char * mimetype, int64_t total_bytes);
 

/* Close and destroy everything */

/** \ingroup decoder
 *  \brief Close a decoder and free all associated memory
 *  \param bgav A decoder instance
 */

BGAV_PUBLIC
void bgav_close(bgav_t * bgav);

/** \defgroup edl EDL support
 *  \ingroup decoding
 *  \brief EDL support
 *
 *  Most media files contain one or more A/V streams. In addition however, there
 *  can be additional instructions, how the media should be played back. Basically
 *  you can have "logical" streams, where the EDL tells how they are composed from
 *  phyiscal streams.
 *
 *  To use EDLs with Gmerlin-avdecoder, call \ref bgav_get_edl, make a local copy of
 *  the EDL structure and call \ref bgav_close.
 *
 *  Some files contain only the EDL (with external references) but no actual media
 *  streams. In this case, \ref bgav_num_tracks will return 0.
 *
 *  Gmerlin-avdecoder has no means of composing the logical EDL tracks from physical
 *  files. The Gmerlin library has an edl decoder plugin.
 *
 * @{
 */

/** \brief One segment of a physical stream to appear in a logical stream
 */

typedef struct
  {
  char * url;   //!< Location of that segment. If NULL, the "master url" in \ref bgav_edl_t is valid.

  int track;        //!<  Track index for multitrack inputs
  int stream;       //!<  Index of the A/V stream
  int timescale;    //!<  Source timescale
    
  int64_t src_time; //!< Time within the source in source timescale
  
  /* Time and duration within the destination in destination
     timescale */
  int64_t dst_time;  //!< Time  within the destination in destination timescale
  int64_t dst_duration; //!< Duration within the destination in destination timescale

  /*  */
  int32_t speed_num; //!< Playback speed numerator
  int32_t speed_den; //!< Playback speed demoninator
  
  } bgav_edl_segment_t;

/** \brief A locical stream
 */

typedef struct
  {
  bgav_edl_segment_t * segments; //!< Segments
  int num_segments;              //!< Number of segments 
  int timescale;                 //!< Destination timescale
  } bgav_edl_stream_t;

/** \brief A locical track
 */

typedef struct
  {
  char * name;                       //!< Name (optional)
  bgav_metadata_t * metadata;        //!< Metadata (optional)
  
  int num_audio_streams;             //!< Number of logical audio streams
  bgav_edl_stream_t * audio_streams; //!< Logical audio streams

  int num_video_streams;             //!< Number of logical video streams
  bgav_edl_stream_t * video_streams; //!< Logical video streams

  int num_subtitle_text_streams;     //!< Number of logical text subtitle streams
  bgav_edl_stream_t * subtitle_text_streams; //!< Logical text subtitle streams

  int num_subtitle_overlay_streams;  //!< Number of logical overlay subtitle streams
  bgav_edl_stream_t * subtitle_overlay_streams; //!< Logical overlay subtitle streams
  
  } bgav_edl_track_t;

/** \brief EDL structure
 */

struct bgav_edl_s
  {
  int num_tracks;             //!< Number of logical tracks
  bgav_edl_track_t * tracks;  //!< Logical tracks
  char * url;                 //!< Filename if all streams are from the same file
  };

/** \ingroup edl
 *  \brief Get an EDL from an open decoder
 *  \param bgav A decoder instance
 *  \returns The edl or NULL
 */

BGAV_PUBLIC
bgav_edl_t * bgav_get_edl(bgav_t * bgav);

/** \brief Dump an EDL to stderr
 *  \param e EDL
 */

BGAV_PUBLIC
void bgav_edl_dump(const bgav_edl_t * e);

/** 
 * @}
 */

/***************************************************
 * Check for redirecting: You MUST check if you opened
 * a redirector, because reading data from redirectors
 * crashes
 * After you read the URLs, close the bgav_t object
 * and open a new one with one of the URLs.
 ***************************************************/

/** \defgroup redirector Redirector support
 *  \ingroup decoding
 *  \brief Redirector support
 *
 *  After opening the decoder with \ref bgav_open, you must check if the
 *  opened stream is actually a redirector with \ref bgav_is_redirector.
 *  If this returns 1, get the number of urls with \ref bgav_redirector_get_num_urls.
 *  Then, for each URL, get the address with \ref bgav_redirector_get_url and the
 *  title of the URL with \ref bgav_redirector_get_name.
 *  After you have this info, close and destroy the decoder with \ref bgav_close and
 *  open a newly created decoder with one of the URLs you got.
 */

/** \ingroup redirector
 *  \brief Query if the decoder opened a redirector
 *  \param bgav A decoder instance
 *  \returns 1 if the decoder opened a redirector, 0 else
 *
 *  This function MUST be called after \ref bgav_open to query if we
 *  openend a redirector.
 */

BGAV_PUBLIC
int bgav_is_redirector(bgav_t * bgav);

/** \ingroup redirector
 *  \brief Get the number of URLs found in the redirector
 *  \param bgav A decoder instance
 *  \returns The number of URLs.
 */

BGAV_PUBLIC
int bgav_redirector_get_num_urls(bgav_t * bgav);

/** \ingroup redirector
 *  \brief Get the address of an URL
 *  \param bgav A decoder instance
 *  \param index Index of the url (starting with 0)
 *  \returns The URL (can be passed to a subsequent \ref bgav_open)
 */

BGAV_PUBLIC
const char * bgav_redirector_get_url(bgav_t * bgav, int index);

/** \ingroup redirector
 *  \brief Get the address of an URL
 *  \param bgav A decoder instance
 *  \param index Index of the url (starting with 0)
 *  \returns The name of the stream or NULL if this information is not present.
 */

BGAV_PUBLIC
const char * bgav_redirector_get_name(bgav_t * bgav, int index);

/***************************************************
 * Get information about the file
 ***************************************************/

/** \defgroup track Query and select tracks
 *  \ingroup decoding
 *
 * Each opened decoder can have multiple tracks. You must select the track you wish to decode before
 * you can do anything else.
 */

/** \ingroup track
 *  \brief Get the number of tracks
 *  \param bgav A decoder instance
 *  \returns The number of tracks.
 */

BGAV_PUBLIC
int bgav_num_tracks(bgav_t * bgav);

/** \ingroup track
 *  \brief Get a technical description of the format
 *  \param bgav A decoder instance
 *  \returns Description
 */

BGAV_PUBLIC
const char * bgav_get_description(bgav_t * bgav);

/** \ingroup track
 *  \brief Get the duration of a track
 *  \param bgav A decoder instance
 *  \param track Track index (starting with 0)
 *  \returns The duration of a track or \ref GAVL_TIME_UNDEFINED if the duration is not known.
 */

BGAV_PUBLIC
gavl_time_t bgav_get_duration(bgav_t * bgav, int track);

/* Query stream numbers */

/** \ingroup track
 *  \brief Get the number of audio streams of a track
 *  \param bgav A decoder instance
 *  \param track Track index (starting with 0)
 *  \returns The number of audio streams
 */

BGAV_PUBLIC
int bgav_num_audio_streams(bgav_t * bgav, int track);

/** \ingroup track
 *  \brief Get the number of video streams of a track
 *  \param bgav A decoder instance
 *  \param track Track index (starting with 0)
 *  \returns The number of video streams
 */

BGAV_PUBLIC
int bgav_num_video_streams(bgav_t * bgav, int track);

/** \ingroup track
 *  \brief Get the number of subtitle streams of a track
 *  \param bgav A decoder instance
 *  \param track Track index (starting with 0)
 *  \returns The number of subtitle streams
 */

BGAV_PUBLIC
int bgav_num_subtitle_streams(bgav_t * bgav, int track);


/** \ingroup track
 *  \brief Get the name a track
 *  \param bgav A decoder instance
 *  \param track Track index (starting with 0)
 *  \returns The track name if present or NULL.
 */

BGAV_PUBLIC
const char * bgav_get_track_name(bgav_t * bgav, int track);

/** \ingroup track
 *  \brief Get metadata for a track.
 *  \param bgav A decoder instance
 *  \param track Track index (starts with 0)
 *  \returns A metadata container (see \ref metadata)
 */

BGAV_PUBLIC
const bgav_metadata_t * bgav_get_metadata(bgav_t * bgav,int track);

/** \ingroup track
 *  \brief Select a track
 *  \param bgav A decoder instance
 *  \param track Track index (starts with 0)
 *  \returns 0 if there was no such track, 1 else
 *
 *  Select the track. All subsequent function calls will refer to the track you
 *  selected.
 */


BGAV_PUBLIC
int bgav_select_track(bgav_t * bgav, int track);

/** \ingroup track
 *  \brief Get the number of chapters
 *  \param bgav A decoder instance
 *  \param track Track index (starts with 0)
 *  \param timescale Returns the timescale of the seekpoints
 *  \returns The number of chapters or 0 if the format doesn't support chapters
 *
 *  Chapters are simply named seekpoints. Use
 *  \ref bgav_get_chapter_time and \ref bgav_get_chapter_name
 *  to query the chapters.
 */

BGAV_PUBLIC
int bgav_get_num_chapters(bgav_t * bgav, int track, int * timescale);

/** \ingroup track
 *  \brief Get the name of a chapter
 *  \param bgav A decoder instance
 *  \param track Track index (starts with 0)
 *  \param chapter Chapter index (starts with 0)
 *  \returns The name of the chapter or NULL
 */

BGAV_PUBLIC const char *
bgav_get_chapter_name(bgav_t * bgav, int track, int chapter);

/** \ingroup track
 *  \brief Get the name of a chapter
 *  \param bgav A decoder instance
 *  \param track Track index (starts with 0)
 *  \param chapter Chapter index (starts with 0)
 *  \returns The time of the chapter
 */

BGAV_PUBLIC
int64_t bgav_get_chapter_time(bgav_t * bgav, int track, int chapter);

/** \defgroup streams Query and select streams
 * \ingroup decoding
 *
 * The numbers of streams are already known before selecting a track (see \ref bgav_num_audio_streams and
 * \ref bgav_num_video_streams. Note that by default, all streams are muted, which means that you cannot
 * skip the stream selection in your application.
 */

/** \ingroup streams
 *  \brief Get the language of an audio stream
 *  \param bgav A decoder instance
 *  \param stream Audio stream index (starting with 0)
 *  \returns A language string.
 */

BGAV_PUBLIC
const char * bgav_get_audio_language(bgav_t * bgav, int stream);

/** \ingroup streams
 *  \brief Get the bitrate of an audio stream
 *  \param bgav A decoder instance
 *  \param stream Audio stream index (starting with 0)
 *  \returns Bitrate in bits / sec. 0 means VBR or unknown
 */

BGAV_PUBLIC
int bgav_get_audio_bitrate(bgav_t * bgav, int stream);

/** \ingroup streams
 *  \brief Get the metadata of an audio stream
 *  \param bgav A decoder instance
 *  \param stream Audio stream index (starting with 0)
 *  \returns The metadata for the stream
 */

BGAV_PUBLIC
const bgav_metadata_t *
bgav_get_audio_metadata(bgav_t * bgav, int stream);
  
/** \ingroup streams
 *  \brief Get the language of a subtitle stream
 *  \param bgav A decoder instance
 *  \param stream Subtitle stream index (starting with 0)
 *  \returns A language string.
 */

BGAV_PUBLIC
const char * bgav_get_subtitle_language(bgav_t * bgav, int stream);

/** \ingroup streams
 *  \brief Get the metadata of a subtitle stream
 *  \param bgav A decoder instance
 *  \param stream Subtitle stream index (starting with 0)
 *  \returns The metadata for the stream
 */

BGAV_PUBLIC
const bgav_metadata_t *
bgav_get_subtitle_metadata(bgav_t * bgav, int stream);

/** \ingroup streams
 *  \brief Get the metadata of a video stream
 *  \param bgav A decoder instance
 *  \param stream Video stream index (starting with 0)
 *  \returns The metadata for the stream
 */

BGAV_PUBLIC
const bgav_metadata_t *
bgav_get_video_metadata(bgav_t * bgav, int stream);

  
/** \ingroup streams
 *  \brief Stream action
 *
 *  This is used to tell the decoder, what to do with the stream.
 *  Only supported actions right now are mute (default) and decode.
 */

typedef enum
  {
    BGAV_STREAM_MUTE    = 0,  /*!< Stream is switched off */
    BGAV_STREAM_DECODE  = 1, /*!< Stream is switched on and will be decoded */
    BGAV_STREAM_PARSE   = 2, /*!< Used internally when building indices */
    BGAV_STREAM_READRAW = 3 /*!< Read compressed packets from the stream */
  }
bgav_stream_action_t;

/** \defgroup readraw Read compressed media packets
 *  \ingroup decoding
 *
 *  This API layer allows you to read compressed media packets from the
 *  stream bypassing the codecs. You can read some streams of a file
 *  as compressed packets while decoding others. You can however not
 *  mix read calls for compressed packets and decompressed frames in a
 *  single stream. Reading compressed packets is supported only for a
 *  subset of codecs, which are defined by the \ref gavl_codec_id_t.
 *  If your application supports compressed packets, you can first get the
 *  compression info with \ref bgav_get_audio_compression_info or
 *  \ref bgav_get_video_compression_info. If you support this compression,
 *  set the stream mode to \ref BGAV_STREAM_READRAW. Before reading you must
 *  call \ref bgav_start. Packets are then read with \ref bgav_read_audio_packet
 *  and \ref bgav_read_video_packet.
 */

  
/** \ingroup readraw
 *  \brief Get audio compression info
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \param info Returns the compression info
 *  \returns 1 if a compression info was returned, 0 else
 *
 *  This function must be called after \ref bgav_select_track. Before
 *  selecting the track the compression info might not be complete.
 *  Free the returned compression info with \ref gavl_compression_info_free.
 */

BGAV_PUBLIC
int bgav_get_audio_compression_info(bgav_t * bgav, int stream,
                                    gavl_compression_info_t * info);

/** \ingroup readraw
 *  \brief Get video compression info
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \param info Returns the compression info
 *  \returns 1 if a compression info was returned, 0 else
 *
 *  This function must be called after \ref bgav_select_track. Before
 *  selecting the track the compression info might not be complete.
 *  Free the returned compression info with \ref gavl_compression_info_free.
 */

BGAV_PUBLIC
int bgav_get_video_compression_info(bgav_t * bgav, int stream,
                                    gavl_compression_info_t * info);

/** \ingroup readraw
 *  \brief Read compressed audio packet
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \param p Returns the packet
 *  \returns 1 if a packet was read, 0 else
 *
 *  You can pass the same packet multiple times to a read fuction.
 *  Use \ref gavl_packet_free when it's no longer used.
 */

BGAV_PUBLIC
int bgav_read_audio_packet(bgav_t * bgav, int stream, gavl_packet_t * p);

/** \ingroup readraw
 *  \brief Read compressed video packet
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \param p Returns the packet
 *  \returns 1 if a packet was read, 0 else
 *
 *  You can pass the same packet multiple times to a read fuction.
 *  Use \ref gavl_packet_free when it's no longer used.
 */

BGAV_PUBLIC
int bgav_read_video_packet(bgav_t * bgav, int stream, gavl_packet_t * p);

  

/** \ingroup streams
 * \brief Select mode for an audio stream
 * \param bgav A decoder instance
 * \param stream Stream index (starting with 0)
 * \param action The stream action.
 *
 * Note that the default stream action is BGAV_STREAM_MUTE, which means that
 * all streams are switched off by default.
 */

BGAV_PUBLIC
int bgav_set_audio_stream(bgav_t * bgav, int stream, bgav_stream_action_t action);

/** \ingroup streams
 * \brief Select mode for a video stream
 * \param bgav A decoder instance
 * \param stream Stream index (starting with 0)
 * \param action The stream action.
 *
 * Note that the default stream action is BGAV_STREAM_MUTE, which means that
 * all streams are switched off by default.
 */

BGAV_PUBLIC
int bgav_set_video_stream(bgav_t * bgav, int stream, bgav_stream_action_t action);

/** \ingroup streams
 * \brief Select mode for a subtitle stream
 * \param bgav A decoder instance
 * \param stream Stream index (starting with 0)
 * \param action The stream action.
 *
 * Note that the default stream action is BGAV_STREAM_MUTE, which means that
 * all streams are switched off by default.
 */

BGAV_PUBLIC
int bgav_set_subtitle_stream(bgav_t * bgav, int stream, bgav_stream_action_t action);

/***************************************************
 * Stream handling functions
 ***************************************************/

/*
 *  You MUST these, if you want to decode anything.
 *  After bgav_open(), all streams are switched off by
 *  default
 */


/** \defgroup start Start codecs
 *  \ingroup decoding
 */

/**  \ingroup start
 *  \brief Start all codecs.
 *  \param bgav A decoder instance
 *  \returns 1 if everything went well, 0 if an error occurred.
 *
 *  Call this function, after you called \ref bgav_set_audio_stream
 *  and/or \ref bgav_set_video_stream.
 */

BGAV_PUBLIC
int bgav_start(bgav_t * bgav);

/** \defgroup stream_info Information about the streams
    \ingroup decoding
 */

/** \ingroup stream_info
 *  \brief Get the format of an audio stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns The format
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_audio_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const gavl_audio_format_t * bgav_get_audio_format(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Get the format of a video stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns The format
 *
 *  Note, that you can trust the return value of this function only, if
 *  you enabled the stream (see \ref bgav_set_video_stream) and started
 *  the decoders (see \ref bgav_start).
 *
 *  Special care has to be taken, if the video stream consists of (a)
 *  still image(s). This is the case, when the framerate_mode member
 *  of the format is \ref GAVL_FRAMERATE_STILL. See
 *  \ref bgav_video_has_still.
 */

BGAV_PUBLIC
const gavl_video_format_t * bgav_get_video_format(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Get the frame table of a video stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns The frame table or NULL
 *
 *  Note, that you can trust the return value of this function only, if
 *  you enabled the stream (see \ref bgav_set_video_stream) and started
 *  the decoders (see \ref bgav_start).
 *
 *  If you want to make sure that the frame table is available for
 *  as many files as possible, use sample accurate mode (see
 *  \ref bgav_options_set_sample_accurate)
 *  The returned table (if non-null) must be freed by the caller with
 *  \ref gavl_frame_table_destroy.
 *
 *  Since 1.0.2
 */
  
BGAV_PUBLIC
gavl_frame_table_t * bgav_get_frame_table(bgav_t * bgav, int stream);

  
/** \ingroup stream_info
 *  \brief Get the video format of a subtitle stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns The format
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_subtitle_stream) and started the decoders
 *  (see \ref bgav_start). For overlay subtitles, this is the video format
 *  of the decoded overlays.
 *  For text subtitles, it's the format of the associated video stream.
 *  The timescale member is always the timescale of the subtitles (not the
 *  video frames).
 */


  
BGAV_PUBLIC const gavl_video_format_t *
bgav_get_subtitle_format(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Check if a subtitle is text or graphics based
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns 1 for text subtitles, 0 for graphic subtitles
 *
 *  If this function returns 1, you must use \ref bgav_read_subtitle_text
 *  to decode subtitles, else use \ref bgav_read_subtitle_overlay
 */

BGAV_PUBLIC
int bgav_subtitle_is_text(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Get the description of an audio stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns A technical decription of the stream 
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_audio_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const char * bgav_get_audio_description(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Get additional info about an audio stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns An info string about the stream or NULL
 *
 *  This returns additional information about the audio stream e.g. if it contains
 *  directors comments, audio for the visually impaired or whatever.
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_audio_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const char * bgav_get_audio_info(bgav_t * bgav, int stream);


/** \ingroup stream_info
 *  \brief Get the description of a video stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns A technical decription of the stream 
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_video_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const char * bgav_get_video_description(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Get the description of a subtitle stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns A technical decription of the stream 
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_subtitle_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const char * bgav_get_subtitle_description(bgav_t * bgav, int stream);


/** \ingroup stream_info
 *  \brief Get additional info about a subtitle stream
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns An info string about the stream or NULL
 *
 *  This returns additional information about the subtitle stream e.g. if it contains
 *  directors comments or whatever.
 *
 *  Note, that you can trust the return value of this function only, if you enabled
 *  the stream (see \ref bgav_set_subtitle_stream) and started the decoders
 *  (see \ref bgav_start).
 */

BGAV_PUBLIC
const char * bgav_get_subtitle_info(bgav_t * bgav, int stream);

/** \ingroup stream_info
 *  \brief Query if a track is pausable
 *  \param bgav A decoder instance
 *  \returns 1 is decoding can be paused for a longer time, 0 else
 *
 *  Check this if you intend to pause decoding. Pausing a livestream
 *  doesn't make sense, so in this case 0 is returned.
 */

BGAV_PUBLIC
int bgav_can_pause(bgav_t * bgav);

/***************************************************
 * Decoding functions
 ***************************************************/

/** \defgroup decode Decode media frames
 *  \ingroup decoding
 */

/** \ingroup decode
 *  \brief Determine if a still image is available for reading
 *  \param bgav A decoder instance
 *  \param stream Stream index (starting with 0)
 *  \returns 1 if a still image is available, 0 else
 *
 *  This should be used, if the framerate_mode of the video format
 *  is \ref GAVL_FRAMERATE_STILL. In earlier versions, streams
 *  consisting of one or more still images outputted the same image
 *  repeatedly as if it was a video stream. Since 1.0.1 each image
 *  is decoded exactly once. The end-of-file detection happens in a
 *  similar way as for subtitles: \ref bgav_video_has_still returns
 *  1 and the following \ref bgav_read_video returns 0.
 *
 *  Since 1.0.1
 */
  
BGAV_PUBLIC
int bgav_video_has_still(bgav_t * bgav, int stream);
  
/** \ingroup decode
    \brief Decode a video frame
    \param bgav A decoder instance
    \param frame The frame to which the image will be decoded.
    \param stream Stream index (starting with 0)
    \returns 1 if a frame could be decoded, 0 for EOF.
*/

BGAV_PUBLIC
int bgav_read_video(bgav_t * bgav, gavl_video_frame_t * frame, int stream);

/** \ingroup decode
    \brief Skip forward in a video stream
    \param bgav A decoder instance
    \param stream Stream index (starting with 0)
    \param time The time to skip to (will be changed to the true time)
    \param scale Scale by which the time is scaled
    \param exact 1 if an exact skip should be done, 0 for faster approximate skip
    
    Use this function if it turns out, that the machine is too weak to
    decode all frames. Set exact to 0 to make the skipping even faster
    but less accurate.
*/

BGAV_PUBLIC
void bgav_skip_video(bgav_t * bgav, int stream,
                     int64_t * time, int scale,
                     int exact);

  
/** \ingroup decode
    \brief Decode audio samples
    \param bgav A decoder instance
    \param frame The frame to which the samples will be decoded.
    \param stream Stream index (starting with 0)
    \param num_samples Number of samples to be decoded
    \returns The number of actually decoded samples, which can be smaller than num_samples. 0 means EOF.
*/

BGAV_PUBLIC
int bgav_read_audio(bgav_t * bgav, gavl_audio_frame_t * frame, int stream,
                    int num_samples);

/** \ingroup decode
    \brief Check, if a new subtitle is available
    \param bgav A decoder instance
    \param stream Stream index (starting with 0)
    \returns 1 if a subtitle is available.

    Use this function to check in advance, if it would make sense to call
    \ref bgav_read_subtitle_overlay or \ref bgav_read_subtitle_text.

*/

BGAV_PUBLIC
int bgav_has_subtitle(bgav_t * bgav, int stream);

/** \ingroup decode
    \brief Decode an overlay subtitle
    \param bgav A decoder instance
    \param ovl The overlay to which the subtitle will be decoded.
    \param stream Stream index (starting with 0)
    \returns 1 if a subtitle could be decoded, 0 else

    If this function returns 1, a subtitle was decoded. If this function returns
    0 and \ref bgav_has_subtitle returned 0 before as well, there is no subtitle
    yet available, but there might come others at a later point in the stream.
    If this function returns 0 and \ref bgav_has_subtitle returned 1 before,
    it means, that you reached the end of the subtitle stream.

*/

BGAV_PUBLIC
int bgav_read_subtitle_overlay(bgav_t * bgav, gavl_overlay_t * ovl, int stream);

/** \ingroup decode
    \brief Decode a text subtitle
    \param bgav       A decoder instance
    \param ret        The string, where the text will be stored.
    \param ret_alloc  The number of allocated bytes for ret
    \param start_time Returns the start time
    \param duration   Returns the duration
    \param stream     Stream index (starting with 0)
    \returns 1 if a subtitle could be decoded, 0 else

    If this function returns 1, a subtitle was decoded. If this function returns
    0 and \ref bgav_has_subtitle returned 0 before as well, there is no subtitle
    yet available, but there might come others at a later point in the stream.
    If this function returns 0 and \ref bgav_has_subtitle returned 1 before,
    it means, that you reached the end of the subtitle stream.
    start_time and duration are scaled by the timescale of the subtitle stream
    (see \ref bgav_get_subtitle_format).
*/

BGAV_PUBLIC
int bgav_read_subtitle_text(bgav_t * bgav, char ** ret, int *ret_alloc,
                            int64_t * start_time, int64_t * duration,
                            int stream);

/***************************************************
 * Seek to a timestamp. This also resyncs all streams
 ***************************************************/

/** \defgroup seeking Simple seek API
 *  \ingroup decoding
 *
 *  gmerlin_avdecoder supports multiple demultiplexing modes, some
 *  are optimized for linear playback, some are optimized for sample
 *  accurate random access. By default, the demuxer will be in linear
 *  playback mode. The associated seek API is described in this section.
 */

/** \defgroup sampleseek Sample accurate seek API
 *  \ingroup decoding
 *
 *  This mode is optimized for sample accurate access. To use this
 *  API, you must call \ref bgav_options_set_sample_accurate before
 *  opening the file. After you opened the file and selected the track,
 *  you must verify, that sample accurate access is available by checking
 *  the return value of \ref bgav_can_seek_sample.
 *
 *  Sample accurate mode has a little more overhead on the demultiplexer side.
 *  Therefore you should not enable it when not needed.
 *  Some formats don't allow sample accurate access, other formats are *only*
 *  seekable in sample accurate mode. For formats, which need to be parsed completely,
 *  index files are written to $HOME/.gmerlin-avdecoder/indices. Filenames of the
 *  indices are the MD5 sums of the filename passed to \ref bgav_open.
 *
 *  Sample accurate mode also implies, that all streams can be positioned
 *  independently.
 */


/** \ingroup seeking
 *  \brief Check if a track is seekabkle
 *  \param bgav A decoder handle
 *  \returns 1 if the track is seekable, 0 else.
 */

BGAV_PUBLIC
int bgav_can_seek(bgav_t * bgav);

/** \ingroup seeking
 *  \brief Seek to a specific time
 *  \param bgav A decoder handle
 *  \param time The time to seek to. 
 *
 * The time argument is changed to the actually seeked time, which can be different.
 */

BGAV_PUBLIC
void bgav_seek(bgav_t * bgav, gavl_time_t * time);


/** \ingroup seeking
 *  \brief Seek to a specific stream position
 *  \param bgav A decoder handle
 *  \param time The time to seek to. 
 *  \param scale Timescale
 *
 * This function allows sample and frame accurate seeking, if
 * the following conditions are met:
 * - The formats allows sample accurate seeking at all
 * - For audio streams, scale is equal to the samplerate
 * - For video streams, scale is equal to the timescale
 *
 * Typically, only one stream will be positioned accurately. For
 * editing applications, it's recommended, that separate decoder instances
 * are opened for audio and video. They can then be positoned independently.
 * 
 * The time argument might be changed to the actually seeked time, which can be
 * different. For sample accurate formats, it should always be unchanged.
 *
 * This function allows sample accurate seeking for some cases even in linear
 * decoding mode. For more sophisticated sample accurate access, see \ref sampleseek.
 */

BGAV_PUBLIC
void bgav_seek_scaled(bgav_t * bgav, int64_t * time, int scale);

/** \ingroup sampleseek
 *  \brief Time value indicating an invalid time
 */

#define BGAV_TIMESTAMP_UNDEFINED GAVL_TIME_UNDEFINED // Don't change this
/** \ingroup sampleseek
 *  \brief Check if a track is seekabkle with sample accuracy
 *  \param bgav A decoder handle
 *  \returns 1 if the track is seekable with sample accuracy, 0 else.
 *
 *  If this function returns zero,  applications, which rely on
 *  \ref bgav_seek_audio \ref bgav_seek_video and \ref bgav_seek_subtitle
 *  should consider the file as unsupported.
 *
 *  The ability of sample accurate seeking also implies, that streams can
 *  be positioned indepentently.
 *
 *  If \ref bgav_options_set_sample_accurate was not called, this function will
 *  return zero for any file.
 */

BGAV_PUBLIC
int bgav_can_seek_sample(bgav_t * bgav);


/** \ingroup sampleseek
 *  \brief Get the audio duration
 *  \param bgav A decoder handle
 *  \param stream Audio stream index (starting with 0)
 *  \returns Duration in samples
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The duration is calculated from the total number or decodable
 *  samples in the file. The start time (as returned by \ref bgav_audio_start_time)
 *  is <b>not</b> included in the duration.
 */

BGAV_PUBLIC
int64_t bgav_audio_duration(bgav_t * bgav, int stream);

/** \ingroup sampleseek
 *  \brief Get the audio start time
 *  \param bgav A decoder handle
 *  \param stream Audio stream index (starting with 0)
 *  \returns Time (in samplerate tics) of the first sample
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The returned value is equal to the timestamp of the first
 *  decoded audio frame.
 */

BGAV_PUBLIC
int64_t bgav_audio_start_time(bgav_t * bgav, int stream);

/** \ingroup sampleseek
 *  \brief Get the video duration
 *  \param bgav A decoder handle
 *  \param stream Video stream index (starting with 0)
 *  \returns Exact duration in stream tics
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The duration is calculated from the total number or decodable
 *  frames in the file. The start time (as returned by \ref bgav_video_start_time)
 *  is <b>not</b> included in the duration.
 */

BGAV_PUBLIC
int64_t bgav_video_duration(bgav_t * bgav, int stream);

/** \ingroup sampleseek
 *  \brief Get the video start time
 *  \param bgav A decoder handle
 *  \param stream Video stream index (starting with 0)
 *  \returns Time of the first video frame in stream tics
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The returned value is equal to the timestamp of the first
 *  decoded video frame.
 */

BGAV_PUBLIC
int64_t bgav_video_start_time(bgav_t * bgav, int stream);


/** \ingroup sampleseek
 *  \brief Get the subtitle duration
 *  \param bgav A decoder handle
 *  \param stream Subtitle stream index (starting with 0)
 *  \returns Exact duration in stream tics
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 */

BGAV_PUBLIC
int64_t bgav_subtitle_duration(bgav_t * bgav, int stream);

/** \ingroup sampleseek
 *  \brief Seek to a specific audio sample
 *  \param bgav A decoder handle
 *  \param stream Audio stream index (starting with 0)
 *  \param sample The sample to seek to
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The time is relative to the first decodable sample
 *  (always starting with 0), the offset returned by
 *  \ref bgav_audio_start_time is <b>not</b> included here.
 *  
 */

BGAV_PUBLIC
void bgav_seek_audio(bgav_t * bgav, int stream, int64_t sample);

/** \ingroup sampleseek
 *  \brief Seek to a specific video time
 *  \param bgav A decoder handle
 *  \param stream Video stream index (starting with 0)
 *  \param time Time
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  If time is between 2 frames, the earlier one will be chosen.
 *  The time is relative to the first decodable frame
 *  (always starting with 0), the offset returned by
 *  \ref bgav_video_start_time is <b>not</b> included here.
 */

BGAV_PUBLIC
void bgav_seek_video(bgav_t * bgav, int stream, int64_t time);

/** \ingroup sampleseek
 *  \brief Get the time of the closest keyframe before a given time
 *  \param bgav A decoder handle
 *  \param stream Video stream index (starting with 0)
 *  \param time Time
 *  \returns Time of the previous keyframe.
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The time argument and return value are relative to the first
 *  decodable frame of the file i.e. <b>not</b> including the offset
 *  returned by \ref bgav_video_start_time .
 *  If there is no keyframe before the given time (i.e if time was 0),
 *  this function returns \ref BGAV_TIMESTAMP_UNDEFINED.
 */

BGAV_PUBLIC
int64_t bgav_video_keyframe_before(bgav_t * bgav, int stream, int64_t time);

/** \ingroup sampleseek
 *  \brief Get the time of the closest keyframe after a given time
 *  \param bgav A decoder handle
 *  \param stream Video stream index (starting with 0)
 *  \param time Time
 *  \returns Time of the next keyframe
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  The time argument and return value are relative to the first
 *  decodable frame of the file i.e. <b>not</b> including the offset
 *  returned by \ref bgav_video_start_time .
 *  If there is no keyframe after the given time,
 *  this function returns \ref BGAV_TIMESTAMP_UNDEFINED.
 */

BGAV_PUBLIC
int64_t bgav_video_keyframe_after(bgav_t * bgav, int stream, int64_t time);


/** \ingroup sampleseek
 *  \brief Seek to a specific subtitle position
 *  \param bgav A decoder handle
 *  \param stream Subtitle stream index (starting with 0)
 *  \param time Time
 *
 *  Use this only after \ref bgav_can_seek_sample returned 1.
 *  If time is between 2 subtitles, the earlier one will be chosen.
 */

BGAV_PUBLIC
void bgav_seek_subtitle(bgav_t * bgav, int stream, int64_t time);


/***************************************************
 * Debugging functions
 ***************************************************/

/** \defgroup debugging Debugging utilities
 */

/** \ingroup debugging
 *  \brief Dump informations of all tracks to stderr
 *  \param bgav A decoder handle
*/

BGAV_PUBLIC
void bgav_dump(bgav_t * bgav);

/* Dump infos about the installed codecs */

/** \ingroup debugging
 *  \brief Dump informations about all available codecs to stderr
 *
 * The output format is html. The main purpose of this function is to generate a feature list
 * for the webpage.
 */

BGAV_PUBLIC
void bgav_codecs_dump();

/* Dump known media formats */

/** \ingroup debugging
 *  \brief Dump informations about all available format demuxers to stderr
 *
 * The output format is html. The main purpose of this function is to generate a feature list
 * for the webpage.
 */

BGAV_PUBLIC
void bgav_formats_dump();

/** \ingroup debugging
 *  \brief Dump informations about all available input modules to stderr
 *
 * The output format is html. The main purpose of this function is to generate a feature list
 * for the webpage.
 */

BGAV_PUBLIC
void bgav_inputs_dump();

/** \ingroup debugging
 *  \brief Dump informations about all available redirectors to stderr
 *
 * The output format is html. The main purpose of this function is to generate a feature list
 * for the webpage.
 */

BGAV_PUBLIC
void bgav_redirectors_dump();

/** \ingroup debugging
 *  \brief Dump informations about all available subtitle readers to stderr
 *
 * The output format is html. The main purpose of this function is to generate a feature list
 * for the webpage.
 */

BGAV_PUBLIC
void bgav_subreaders_dump();


#ifdef __cplusplus
}
#endif