summaryrefslogtreecommitdiff
path: root/src/input/vcd/xineplug_inp_vcd.c
blob: 70fcfe7ae7905111bf2cb65fd8f7383ad8a33e7a (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
/*

  Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein <rocky@panix.com>

  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, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*/

/*
  These are plugin routines called by the xine engine. See
  Chapter 4. Extending xine's input
  http://www.xine-project.org/hackersguide#INPUT
  and the comments in input_plugin.h

  This is what is referred to below a "the xine plugin spec"

  Please don't add any OS-specific code in here - #if defined(__sun)
  or or #if defined(__linux__) are harbingers of such stuff. It took a
  great deal of effort to get it *out* of here (or most of it); If you
  feel the need to do so, you are doing something wrong and breaking
  modularity.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* Standard includes */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>

#define SHORT_PLUGIN_NAME "VCD"
#define MRL_PREFIX "vcd://"
#define MRL_PREFIX_LEN (sizeof(MRL_PREFIX) - 1)
#define MAX_DEVICE_LEN 1024

#define xine_config_entry_t xine_cfg_entry_t

/* Xine includes */
#include "xineutils.h"
#include "input_plugin.h"

#include "xine-extra.h"

#ifdef HAVE_VCDNAV
#include <cdio/logging.h>
#include <cdio/iso9660.h>
#include <cdio/cd_types.h>
#include <cdio/version.h>

/* libvcd includes */
#include <libvcd/files.h>
#include <libvcd/logging.h>
#else
#include "cdio/logging.h"
#include "cdio/iso9660.h"
#include "cdio/cd_types.h"
/* libvcd includes */
#include "libvcd/files.h"
#include "libvcd/logging.h"
#endif

#include "vcdplayer.h"
#include "vcdio.h"

/* A xine define. */
#ifndef BUF_DEMUX_BLOCK
#define BUF_DEMUX_BLOCK 0x05000000
#endif

/*
   Convert an autoplay enumeration into an vcdinfo itemtype enumeration.
   See definitions in vcdplayer.h and vcdinfo.h to get the below correct.
*/
static const vcdinfo_item_enum_t autoplay2itemtype[]={
  VCDINFO_ITEM_TYPE_TRACK,   /* VCDPLAYER_AUTOPLAY_TRACK */
  VCDINFO_ITEM_TYPE_ENTRY,   /* VCDPLAYER_AUTOPLAY_ENTRY */
  VCDINFO_ITEM_TYPE_SEGMENT, /* VCDPLAYER_AUTOPLAY_SEGMENT */
  VCDINFO_ITEM_TYPE_LID      /* VCDPLAYER_AUTOPLAY_PBC */
};

typedef struct vcd_config_s
{
  char         *title_format;        /* Format string of GUI display title */
  char         *comment_format;      /* Format string of stream comment meta */
} vcd_config_t;

typedef struct vcd_input_plugin_tag vcd_input_plugin_t;

typedef struct vcd_input_class_s {
  input_class_t        input_class;
  xine_t              *xine;
  config_values_t     *config;     /* Pointer to XineRC config file. */
  vcd_input_plugin_t  *ip;

  vcd_config_t         v_config;  /* config stuff passed to child */
  xine_mrl_t           **mrls;    /* list of mrl entries for medium */
  int                  num_mrls;  /* count of above */
  char                *vcd_device;/* Device name to use when
				     none specified in MRL    */
  /*--------------------------------------------------------------
    Media resource locator (MRL) info.

    For the below offsets, use play_item + mrl_xxx_offset to get index
    into "mrls" array
   ---------------------------------------------------------------*/
  int        mrl_track_offset;    /* perhaps -1 for tracks staring with 1*/
  int        mrl_entry_offset;    /* i_tracks for entries starting with 0 */
  int        mrl_play_offset;     /* i_tracks for entries starting with 0 */
  int        mrl_segment_offset;  /* i_tracks + i_entries if segs start 1*/


} vcd_input_class_t;

vcd_input_class_t *vcd_class;

struct vcd_input_plugin_tag {
  input_plugin_t    input_plugin; /* input plugin interface as defined by
                                     by player. For xine it contains a
                                     structure of functions that need
                                     to be implemented.
                                  */
  xine_stream_t      *stream;
  xine_event_queue_t *event_queue;

  time_t	      pause_end_time;
  int                 i_old_still; /* Value of player-i_still before next read.
                                      See also i_still in vcdplayer structure.
                                    */
  int                 i_old_deinterlace; /* value of deinterlace before
                                            entering a still. */

  vcd_input_class_t  *class;
  vcd_config_t        v_config;    /* Config stuff initially inherited   */
  char               *mrl;

  int32_t             i_mouse_button; /* The "button" number associated
                                         with the region that the mouse
                                         is currently located in. If
                                         the mouse is not in any "button"
                                         region then this has value -1.
                                      */
  bool                b_mouse_in;     /* True if mouse is inside a "button"
                                         region; false otherwise */

  vcdplayer_t         player ;
  char               *player_device;
};

vcd_input_plugin_t  my_vcd;

/* Prototype definitions */
static bool vcd_handle_events (void);
static void vcd_close(vcd_input_class_t *class);
#if LIBVCD_VERSION_NUM >= 23
static void send_mouse_enter_leave_event(vcd_input_plugin_t *p_this,
                                         bool b_mouse_in);
#endif

/*
   If class->vcd_device is NULL or the empty string,
   Use libcdio to find a CD drive with a VCD in it.
*/
static bool
vcd_get_default_device(vcd_input_class_t *class, bool log_msg_if_fail)
{
  dbg_print(INPUT_DBG_CALL, "Called with %s\n",
            log_msg_if_fail ? "True" : "False");

  if (NULL == class->vcd_device || strlen(class->vcd_device)==0) {
    char **cd_drives=NULL;
    cd_drives = cdio_get_devices_with_cap(NULL,
(CDIO_FS_ANAL_SVCD|CDIO_FS_ANAL_CVD|CDIO_FS_ANAL_VIDEOCD|CDIO_FS_UNKNOWN),
					true);
    if (NULL == cd_drives || NULL == cd_drives[0]) {
      LOG_MSG("%s", _("failed to find a device with a VCD"));
      return false;
    }
    class->vcd_device = strdup(cd_drives[0]);
    cdio_free_device_list(cd_drives);
#if LIBCDIO_VERSION_NUM <= 72
    free(cd_drives);
#endif
  }
  return true;
}


static void
meta_info_assign(int field, xine_stream_t *stream, const char * info)
{
  if (NULL != info) {
    dbg_print(INPUT_DBG_META, "meta[%d]: %s\n", field, info);
    _x_meta_info_set(stream, field, info);
  }
}

#define stream_info_assign(field, stream, info) \
  _x_stream_info_set(stream, field, info);

/* Set stream information. */
static void
vcd_set_meta_info (vcd_input_plugin_t *xine_vcd)
{
  vcdinfo_obj_t *p_vcdinfo= xine_vcd->player.vcd;
  meta_info_assign(XINE_META_INFO_ALBUM, xine_vcd->stream,
                   vcdinfo_get_album_id(p_vcdinfo));
  meta_info_assign(XINE_META_INFO_ARTIST,  xine_vcd->stream,
                   vcdinfo_get_preparer_id(p_vcdinfo));
  meta_info_assign(XINE_META_INFO_COMMENT, xine_vcd->stream,
                   vcdplayer_format_str(&xine_vcd->player,
                                   xine_vcd->v_config.comment_format));
  meta_info_assign(XINE_META_INFO_GENRE, xine_vcd->stream,
                   vcdinfo_get_format_version_str(p_vcdinfo));
}

static void
vcd_force_redisplay (void)
{
#if 1
    my_vcd.stream->xine->clock->adjust_clock(my_vcd.stream->xine->clock,
    my_vcd.stream->xine->clock->get_current_time(my_vcd.stream->xine->clock)
     + 30 * 90000 );
#else
    /* Alternate method that causes too much disruption... */
    xine_set_param(my_vcd.stream, XINE_PARAM_VO_ASPECT_RATIO,
		 (xine_get_param(my_vcd.stream, XINE_PARAM_VO_ASPECT_RATIO)));
#endif
}

static void
vcd_set_aspect_ratio (int i_aspect_ratio)
{
  /* Alternate method that causes too much disruption... */
  xine_set_param(my_vcd.stream, XINE_PARAM_VO_ASPECT_RATIO, i_aspect_ratio);
}

/*! Add another MRL to the MRL list inside "this" to be displayed.
   mrl is the string name to add; size is the size of the entry in bytes.
   The number of mrls in "this" is incremented.
*/
static void
vcd_add_mrl_slot(vcd_input_class_t *this, const char *mrl, off_t size,
                 unsigned int *i)
{
  dbg_print(INPUT_DBG_MRL, "called to add slot %d: %s, size %u\n",
              *i, mrl, (unsigned int) size);

  this->mrls[*i] = malloc(sizeof(xine_mrl_t));
  if (NULL==this->mrls[*i]) {
    LOG_ERR("Can't malloc %zu bytes for MRL slot %u (%s)",
            sizeof(xine_mrl_t), *i, mrl);
    return;
  }
  this->mrls[*i]->link   = NULL;
  this->mrls[*i]->origin = NULL;
  this->mrls[*i]->type   = mrl_vcd;
  this->mrls[*i]->size   = size * M2F2_SECTOR_SIZE;

  this->mrls[*i]->mrl = strdup(mrl);
  if (NULL==this->mrls[*i]->mrl) {
    LOG_ERR("Can't malloc %zu bytes for MRL name %s", sizeof(xine_mrl_t), mrl);
  }
  (*i)++;
}

/*!
  Return the associated mrl_offset for the given type.
*/
static int
vcd_get_mrl_type_offset(vcd_input_plugin_t *inp,
                        vcdinfo_item_enum_t type, int *size)
{
  switch (type) {
  case VCDINFO_ITEM_TYPE_ENTRY:
    *size = inp->class->mrl_play_offset - inp->class->mrl_entry_offset + 1;
    return inp->class->mrl_entry_offset;
    break;
  case VCDINFO_ITEM_TYPE_SEGMENT:
    *size = inp->class->num_mrls - inp->class->mrl_segment_offset - 1;
    return inp->class->mrl_segment_offset;
  case VCDINFO_ITEM_TYPE_TRACK:
    *size = inp->class->mrl_entry_offset;
    return inp->class->mrl_track_offset;
  case VCDINFO_ITEM_TYPE_LID:
    /* Play list number (LID) */
    *size = (inp->player.i_lids > 0) ? 1 : 0;
    return inp->class->mrl_play_offset;
  case VCDINFO_ITEM_TYPE_NOTFOUND:
  case VCDINFO_ITEM_TYPE_SPAREID2:
  default:
    return -2;
  }
}

/*!
   Create a MRL list inside "class". Any existing MRL list is freed.
 */
static bool
vcd_build_mrl_list(vcd_input_class_t *class, char *vcd_device)
{

  char mrl[MRL_PREFIX_LEN+MAX_DEVICE_LEN+(sizeof("@E")-1)+12];
  vcdplayer_t *vcdplayer;
  unsigned int n, i=0;
  unsigned int i_entries;
  vcdinfo_obj_t *p_vcdinfo;
  int was_open;

  if (NULL == class) {
    LOG_MSG("%s", _("was passed a null class parameter"));
    return false;
  }

  vcdplayer = &(my_vcd.player);

  /* If VCD already open, we gotta close and stop it. */
  if ((was_open = vcdplayer->b_opened)) {
    vcd_close(class);
  }

  if (NULL == vcd_device) {
    if (!vcd_get_default_device(class, true)) return false;
    vcd_device = class->vcd_device;
  }

  if (!vcdio_open(vcdplayer, vcd_device)) {
    /* Error should have been logged  in vcdio_open. If not do the below:
    LOG_ERR(vcdplayer, "%s: %s.\n", _("unable to open"),
            class->vcd_device, strerror(errno));
    */
    return false;
  }

  free (my_vcd.player_device);
  my_vcd.player_device    = strdup (vcd_device);
  p_vcdinfo               = vcdplayer->vcd;
  i_entries               = vcdplayer->i_entries;
  class->mrl_track_offset = -1;

  xine_free_mrls(&(class->num_mrls), class->mrls);

  /* Figure out number of MRLs. Calculation would be real simple if
     didn't have to possibly remove rejected LIDs from list done in the
     loop below.
   */
  class->num_mrls = vcdplayer->i_tracks + vcdplayer->i_entries
    + vcdplayer->i_segments + vcdplayer->i_lids;

  if (!vcdplayer->show_rejected && vcdinfo_get_lot(vcdplayer->vcd)) {
    /* Remove rejected LIDs from count. */
    for (n=0; n<vcdplayer->i_lids; n++) {
      if ( vcdinf_get_lot_offset(vcdinfo_get_lot(vcdplayer->vcd), n)
           == PSD_OFS_DISABLED )
        class->num_mrls--;
    }
  }

  class->mrls = calloc(class->num_mrls, sizeof(xine_mrl_t *));
  if (NULL == class->mrls) {
    LOG_ERR("Can't calloc %d MRL entries", class->num_mrls);
    class->num_mrls = 0;
    if (!was_open)
      vcdio_close(vcdplayer);
    return false;
  }

  /* Record MRL's for tracks */
  for (n=1; n<=vcdplayer->i_tracks; n++) {
    memset(&mrl, 0, sizeof (mrl));
    snprintf(mrl, sizeof(mrl), "%s%s@T%u", MRL_PREFIX, vcd_device, n);
    vcd_add_mrl_slot(class, mrl, vcdplayer->track[n-1].size, &i);
  }

  class->mrl_entry_offset = vcdplayer->i_tracks;
  class->mrl_play_offset  = class->mrl_entry_offset + i_entries - 1;

  /* Record MRL's for entries */
  if (i_entries > 0) {
    for (n=0; n<i_entries; n++) {
      memset(&mrl, 0, sizeof (mrl));
      snprintf(mrl, sizeof(mrl), "%s%s@E%u", MRL_PREFIX, vcd_device, n);
      vcd_add_mrl_slot(class, mrl, vcdplayer->entry[n].size, &i);
    }
  }

  /* Record MRL's for LID entries or selection entries*/
  class->mrl_segment_offset = class->mrl_play_offset;
  if (vcdinfo_get_lot(vcdplayer->vcd)) {
    for (n=0; n<vcdplayer->i_lids; n++) {
      uint16_t ofs = vcdinf_get_lot_offset(vcdinfo_get_lot(vcdplayer->vcd), n);
      if (ofs != PSD_OFS_DISABLED || vcdplayer->show_rejected) {
        memset(&mrl, 0, sizeof (mrl));
        snprintf(mrl, sizeof(mrl), "%s%s@P%u%s", MRL_PREFIX, vcd_device, n+1,
                ofs == PSD_OFS_DISABLED ? "*" : "");
        vcd_add_mrl_slot(class, mrl, 0, &i);
        class->mrl_segment_offset++;
      }
    }
  }

  /* Record MRL's for segments */
  {
    segnum_t i_segments = vcdplayer->i_segments;
    for (n=0; n<i_segments; n++) {
      vcdinfo_video_segment_type_t segtype
        = vcdinfo_get_video_type(p_vcdinfo, n);
      char c='S';
      switch (segtype) {
        {
        case VCDINFO_FILES_VIDEO_NTSC_STILL:
        case VCDINFO_FILES_VIDEO_NTSC_STILL2:
        case VCDINFO_FILES_VIDEO_NTSC_MOTION:
          c='s';
          break;
        case VCDINFO_FILES_VIDEO_PAL_STILL:
        case VCDINFO_FILES_VIDEO_PAL_STILL2:
        case VCDINFO_FILES_VIDEO_PAL_MOTION:
          c='S';
          break;
        default: ;
        }
      }

      memset(&mrl, 0, sizeof (mrl));
      snprintf(mrl, sizeof(mrl), "%s%s@%c%u", MRL_PREFIX, vcd_device, c, n);
      vcd_add_mrl_slot(class, mrl, vcdplayer->segment[n].size, &i);
    }
  }

  dbg_print(INPUT_DBG_MRL,
            "offsets are track: %d, entry: %d, play: %d seg: %d\n",
            class->mrl_track_offset, class->mrl_entry_offset,
            class->mrl_play_offset,  class->mrl_segment_offset);

  return true;
}

/*!
  parses a MRL which has the format

  vcd://[vcd_path][@[EPTS]?number]\*?

  Examples
    vcd://                    - Play (navigate) default device: /dev/cdrom
    vcd://@                   - same as above
    vcd:///dev/cdrom          - probably same as above
    vcd:///dev/cdrom2         - Play (navigate) /dev/cdrom2
    vcd:///dev/cdrom2@        - same as above
    vcd:///dev/cdrom2@T1      - Play Track 1 from /dev/cdrom2
    vcd:///dev/cdrom@S1       - Play selection id 1 from /dev/cdrom
    vcd://dev/cdrom@E0        - Play Entry id 0 from default device
    vcd://@P1                 - probably same as above.
                                 If there is no playback control, MRL will
			         get converted into vcd://@E0
    vcd://@P1*                - probably same as above.
    vcd://@S0                 - Play segment 0 from default device
    vcd://@3                  - Play track 3 from default device
    vcd:///dev/cdrom2@1       - Play track 1 from /dev/cdrom2
    vcd:///tmp/ntsc.bin@      - Play default item from /tmp/ntsc.bin
    vcd:///tmp/ntsc.bin/@E0   - Play entry 0 of /tmp/ntsc.bin

parameters:
  mrl               : mrl to parse
  default_vcd_device: name of device to use when none given
  auto_type         : type of selection (entry, track, LID) when none given
  used_default      : true iff auto_type was used.

 */
static bool
vcd_parse_mrl(/*in*/ const char *default_vcd_device, /*in*/ char *mrl,
              /*out*/ char *device_str, /*out*/ vcdinfo_itemid_t *itemid,
              /*in */ vcdplayer_autoplay_t auto_type,
              /*out*/ bool *used_default)
{
  char type_str[2];
  int count;
  char *p;
  unsigned int num = 0;

  dbg_print(INPUT_DBG_CALL, "called mrl %s\n", mrl);

  type_str[0]   ='\0';
  itemid->type  = (vcdinfo_item_enum_t) auto_type;
  *used_default = false;

  if ( NULL == mrl || strncasecmp(mrl, MRL_PREFIX, MRL_PREFIX_LEN) )
    return false;
  p = &mrl[MRL_PREFIX_LEN - 2];
  while (*p == '/')
    ++p;

  device_str[0] = '/';
  device_str[1] = 0;
  count = sscanf (p, "%1023[^@]@%1[EePpSsTt]%u",
		  device_str + 1, type_str, &num);
  itemid->num = num;

  switch (count) {
  case 1:
    /* Matched device, but nothing beyond that */
    if (strlen(device_str)!=0 && device_str[0] != ':') {
      /* See if we have old-style MRL with no type specifier.
         If so, we assume "track". */
      count = sscanf (p, "%u", &num);
      itemid->num = num;
      if (1==count) {
        type_str[0] = 'T';
        if (default_vcd_device)
          strncpy(device_str, default_vcd_device, MAX_DEVICE_LEN);
        else
          *device_str = 0;
      }
      else
        _x_mrl_unescape (device_str);
      break;
    }
  case 2 ... 9:
    _x_mrl_unescape (device_str);

  case 0:
  case EOF:
    {
      /* No device/file given, so use the default device and try again. */
      if (NULL == default_vcd_device) return false;
      strncpy(device_str, default_vcd_device, MAX_DEVICE_LEN);
      if (p[0] == '@') p++;
      count = sscanf (p, "%1[EePpSsTt]%u", type_str, &num);
      type_str[0] = toupper(type_str[0]);
      itemid->num = num;

      switch (count) {
      case EOF:
	/* Default PBC navigation. */
        return true;
      case 0:
        /* See if we have old-style MRL with no type specifier.
           If so, we assume "track". */
        count = sscanf (p, "%u", &num);
        if (1==count) {
          type_str[0] = 'T';
          break;
        }
	/* Default PBC navigation. */
	return true;
      case 1:
        /* Type given, but no number. Entries start at 0, other things
           start at 1 */
	if (type_str[0] == 'P' || type_str[0] == 'T') itemid->num = 1;
      }
    }
  }

  /* We have some sort of track/selection/entry number */
  switch (type_str[0]) {
  case 'E':
    itemid->type = VCDINFO_ITEM_TYPE_ENTRY;
    break;
  case '\0':
    /* None specified, use config value. */
    itemid->type = (vcdinfo_item_enum_t) auto_type;
    *used_default = true;
    break;
  case 'P':
    itemid->type = VCDINFO_ITEM_TYPE_LID;
    break;
  case 'S':
    itemid->type = VCDINFO_ITEM_TYPE_SEGMENT;
    break;
  case 'T':
    itemid->type = VCDINFO_ITEM_TYPE_TRACK;
    break;
  default: ;
  }

  if ( 0==itemid->num
       && ( (VCDINFO_ITEM_TYPE_LID == itemid->type)
            || (VCDINFO_ITEM_TYPE_TRACK == itemid->type) ) )
    itemid->num = 1;

  return true;
}

/*!
  From xine plugin spec:

  return capabilities of input source
*/
static uint32_t
vcd_plugin_get_capabilities (input_plugin_t *this_gen)
{

  uint32_t ret =
    INPUT_CAP_AUDIOLANG | INPUT_CAP_BLOCK     |
    INPUT_CAP_CHAPTERS  | INPUT_CAP_PREVIEW   |
    (my_vcd.player.i_still ? 0: INPUT_CAP_SEEKABLE) |
    INPUT_CAP_SPULANG;

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "returning %d\n", ret);
  vcd_handle_events();
  return ret;
}

# if FINISHED
/* If needed, will fill out later... */
static void
vcd_read_ahead_cb(void *this_gen, xine_cfg_entry_t *entry)
{
   return;
}
#endif

static void
vcd_flush_buffers(void)
{
  _x_demux_flush_engine(my_vcd.stream);
}

/*!
  From xine plugin spec:

  read nlen bytes, return number of bytes read.
*/
static off_t
vcd_plugin_read (input_plugin_t *this_gen, char *buf, const off_t nlen)
{

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT),
            "Called with nlen %u\n", (unsigned int) nlen);

  /* FIXME: Tricking the demux_mpeg_block plugin */
  buf[0] = 0;
  buf[1] = 0;
  buf[2] = 0x01;
  buf[3] = 0xba;
  return (off_t) 1;
}

/* Allocate and return a no-op buffer. This signals the outside
   to do nothing, but in contrast to returning NULL, it doesn't
   mean the stream has ended. We use this say for still frames.
 */
#define RETURN_NOOP_BUF                                    \
  p_buf = fifo->buffer_pool_alloc (fifo);                  \
  p_buf->type = BUF_CONTROL_NOP;                           \
  return p_buf

/* Handle keyboard events and if there were non which might affect
   playback, then sleep a little bit and return;
 */
#define SLEEP_AND_HANDLE_EVENTS                          \
  xine_usec_sleep(50000);                                \
  if (vcd_handle_events()) goto read_block;              \
  RETURN_NOOP_BUF

/*!
  From xine plugin spec:

  read one block, return newly allocated block (or NULL on failure)
  for blocked input sources len must be == blocksize the fifo
  parameter is only used to get access to the buffer_pool_alloc
  function
*/
static buf_element_t *
vcd_plugin_read_block (input_plugin_t *this_gen, fifo_buffer_t *fifo,
                       const off_t i_len)
{
  vcd_input_plugin_t *vcd_input_plugin= (vcd_input_plugin_t *) this_gen;
  vcdplayer_t   *p_vcdplayer = &my_vcd.player;
  buf_element_t *p_buf;
  uint8_t        data[M2F2_SECTOR_SIZE] = {0};

  if (fifo == NULL) {
    dbg_print(INPUT_DBG_CALL, "NULL fifo");
    return NULL;
  }

  dbg_print(INPUT_DBG_CALL, "Called with i_len %u\n", (unsigned int) i_len);

  /* Should we change this to <= instead of !=? */
  if (i_len != M2F2_SECTOR_SIZE) return NULL;

  /* If VCD isn't open, we need to open it now. */
  if (!p_vcdplayer->b_opened) {
    if (!vcdio_open(p_vcdplayer, my_vcd.player_device)) {
      return NULL;
    }
  }

  if (vcd_handle_events()) goto read_block;

  if (p_vcdplayer->i_still > 0) {
    if ( time(NULL) >= vcd_input_plugin->pause_end_time ) {
      if (STILL_INDEFINITE_WAIT == p_vcdplayer->i_still) {
        dbg_print(INPUT_DBG_STILL, "Continuing still indefinite wait time\n");
        vcd_input_plugin->pause_end_time = time(NULL) + p_vcdplayer->i_still;
        SLEEP_AND_HANDLE_EVENTS;
      } else {
        dbg_print(INPUT_DBG_STILL, "Still time ended\n");
        p_vcdplayer->i_still = 0;
      }
    } else {
      SLEEP_AND_HANDLE_EVENTS;
    }
  }


 read_block:
  switch (vcdplayer_read(p_vcdplayer, data, i_len)) {
  case READ_END:
    /* End reached. Return NULL to indicated this. */
    return NULL;
  case READ_ERROR:
    /* Some sort of error. */
    return NULL;
  case READ_STILL_FRAME:
    {
      dbg_print(INPUT_DBG_STILL, "Handled still event wait time %u\n",
                p_vcdplayer->i_still);
      vcd_input_plugin->pause_end_time = time(NULL) + p_vcdplayer->i_still;
      RETURN_NOOP_BUF;
    }

  default:
  case READ_BLOCK:
    /* Read buffer */
    p_buf = fifo->buffer_pool_alloc (fifo);
    p_buf->type = BUF_DEMUX_BLOCK;
  }

  p_buf->content = p_buf->mem;

  if (STILL_READING == p_vcdplayer->i_still && 0 == my_vcd.i_old_still) {
    my_vcd.i_old_deinterlace = xine_get_param(my_vcd.stream,
                                              XINE_PARAM_VO_DEINTERLACE);
    xine_set_param(my_vcd.stream, XINE_PARAM_VO_DEINTERLACE, 0);
    dbg_print(INPUT_DBG_STILL, "going into still, saving deinterlace %d\n",
              my_vcd.i_old_deinterlace);
  } else if (0 == p_vcdplayer->i_still && 0 != my_vcd.i_old_still) {
    dbg_print(INPUT_DBG_STILL,
              "going out of still, restoring deinterlace\n");
    xine_set_param(my_vcd.stream, XINE_PARAM_VO_DEINTERLACE,
                   my_vcd.i_old_deinterlace);
  }
  my_vcd.i_old_still = p_vcdplayer->i_still;

  /* Ideally this should probably be i_len.  */
  memcpy (p_buf->mem, data, M2F2_SECTOR_SIZE);

  return p_buf;
}

/*!
  From xine plugin spec:

  seek position, return new position

  if seeking failed, -1 is returned
*/
static off_t
vcd_plugin_seek (input_plugin_t *this_gen, off_t offset, int origin)
{
  return vcdio_seek (&my_vcd.player, offset, origin);
}


/*!
  From xine plugin spec:
  return length of input (-1 => unlimited, e.g. stream)

  length size is bytes.
*/

static vcdinfo_itemid_t old_play_item = {VCDINFO_ITEM_TYPE_NOTFOUND, 0};

static off_t old_get_length = 0;
static vcdplayer_slider_length_t old_slider_length;

/* This routine is called a bit. Make reasonably fast. */
static off_t
vcd_plugin_get_length (input_plugin_t *this_gen) {

  vcd_input_plugin_t *ip= (vcd_input_plugin_t *) this_gen;
  vcdplayer_t        *vcdplayer = &(ip->player);

  int n = vcdplayer->play_item.num;

  if (vcdplayer->play_item.num == old_play_item.num
      && vcdplayer->play_item.type == old_play_item.type
      && vcdplayer->slider_length == old_slider_length)
    return old_get_length;

  old_slider_length = vcdplayer->slider_length;
  old_play_item     = vcdplayer->play_item;

  switch (vcdplayer->play_item.type) {
  case VCDINFO_ITEM_TYPE_ENTRY:
    switch (vcdplayer->slider_length) {
    case VCDPLAYER_SLIDER_LENGTH_AUTO:
    case VCDPLAYER_SLIDER_LENGTH_ENTRY:
      n += ip->class->mrl_entry_offset;
      break;
    case VCDPLAYER_SLIDER_LENGTH_TRACK:
      n = vcdinfo_get_track(vcdplayer->vcd, n) + ip->class->mrl_track_offset;
      break;
    default:
      /* FIXME? */
      return -1;
    }
    break;
  case VCDINFO_ITEM_TYPE_TRACK:
    n += ip->class->mrl_track_offset;
    break;
  case VCDINFO_ITEM_TYPE_SEGMENT:
    n += ip->class->mrl_segment_offset;
    break;
  case VCDINFO_ITEM_TYPE_LID:
    /* This is the only situation where the size of the current play item
       is not static. It depends what the current play-item is.
     */
    old_get_length = (vcdplayer->end_lsn - vcdplayer->origin_lsn) *
      M2F2_SECTOR_SIZE;
    return old_get_length;
    break;
  case VCDINFO_ITEM_TYPE_NOTFOUND:
  case VCDINFO_ITEM_TYPE_SPAREID2:
  default:
    /* FIXME? */
    return -1;
  }

  if (n >= 0 && n < ip->class->num_mrls) {
    old_get_length = ip->class->mrls[n]->size;
    dbg_print(INPUT_DBG_MRL, "item: %u, slot %u, size %ld\n",
              vcdplayer->play_item.num,
              (unsigned int) n,  (long int) old_get_length);
  }
  return old_get_length;
}

/*!
 * From xine plugin spec:
 * get current position in stream.
 *
 */
static off_t
vcd_plugin_get_current_pos (input_plugin_t *this_gen){
  // trace_print("Called\n");
  return (vcd_plugin_seek (this_gen, 0, SEEK_CUR));
}


/*!
 * From xine plugin spec:
 * return block size of input source (if supported, 0 otherwise)
 */
static uint32_t
vcd_plugin_get_blocksize (input_plugin_t *this_gen) {
  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");

  return M2F2_SECTOR_SIZE;
}

/*!
  From xine plugin spec:
  ls function
  return value: NULL => filename is a file, **char=> filename is a dir

-- This list returned forms the entries of the GUI MRL "browser".
*/

static xine_mrl_t **
vcd_class_get_dir (input_class_t *this_gen, const char *filename,
                    int *num_files) {

  char             intended_vcd_device[MAX_DEVICE_LEN+1]= { '\0', };
  vcdinfo_itemid_t itemid;

  vcd_input_class_t *class = (vcd_input_class_t *) this_gen;
  vcdplayer_t       *vcdplayer= &my_vcd.player;

  bool used_default;

  if (filename == NULL) {
    dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT),
              "called with NULL\n");
    if ( class->mrls != NULL && NULL != class->mrls[0] ) goto have_mrls;

    if ( !vcd_build_mrl_list(class, vcdplayer->psz_source) ) {
      goto no_mrls;
    }
  } else {
    char *mrl = strdup(filename);
    dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT),
              "called with %s\n", filename);
    if (!vcd_get_default_device(class, true)) goto no_mrls;
    if (!vcd_parse_mrl(class->vcd_device, mrl,
                       intended_vcd_device, &itemid,
                       vcdplayer->default_autoplay, &used_default)) {
      free (mrl);
      goto no_mrls;
    }
    free (mrl);
  }

 have_mrls:
  *num_files = class->num_mrls;
  return class->mrls;

 no_mrls:
  *num_files = 0;
  return NULL;
}

#define FREE_AND_NULL(ptr) if (NULL != ptr) free(ptr); ptr = NULL;

static void
vcd_close(vcd_input_class_t *class)
{
  xine_free_mrls(&(class->num_mrls), class->mrls);
  FREE_AND_NULL(my_vcd.mrl);
  if (my_vcd.player.b_opened)
    vcdio_close(&my_vcd.player);
}


/*!
 * From plugin xine spec:
 * eject/load the media (if it's possible)
 *
 * returns 0 for temporary failures
 */
static int
vcd_class_eject_media (input_class_t *this_gen)
{
  int ret;
  CdIo_t *cdio=vcdinfo_get_cd_image(my_vcd.player.vcd);

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");
  if (NULL == cdio) return 0;

  ret = cdio_eject_media(&cdio);
  if ((ret == 0) || (ret == 2)) {
     if (my_vcd.player.b_opened)
       vcdio_close(&my_vcd.player);
    return 1;
  } else return 0;
}

/*!
 * From spec:
 * return current MRL
 */
static const char *
vcd_plugin_get_mrl (input_plugin_t *this_gen)
{
  vcd_input_plugin_t *t         = (vcd_input_plugin_t *) this_gen;
  vcdplayer_t        *vcdplayer = &my_vcd.player;
  int n;
  int size; /* need something to feed get_mrl_type_offset */
  int offset;

  if (vcdplayer_pbc_is_on(vcdplayer)) {
    n = vcdplayer->i_lid;
    offset = vcd_get_mrl_type_offset(t, VCDINFO_ITEM_TYPE_LID, &size);
  } else {
    n = vcdplayer->play_item.num;
    offset = vcd_get_mrl_type_offset(t, vcdplayer->play_item.type, &size);
  }

  if (-2 == offset) {
    /* Bad type. */
    LOG_ERR("%s %d", _("Invalid current entry type"),
                  vcdplayer->play_item.type);
    return "";
  } else {
    n += offset;
    if (n < t->class->num_mrls) {
      dbg_print(INPUT_DBG_CALL, "Called, returning %s\n",
                t->class->mrls[n]->mrl);
      return t->class->mrls[n]->mrl;
    } else {
      return "";
    }
  }
}

/*!
  From xine plugin spec:

  return human readable (verbose = 1 line) description for this plugin
*/
static const char *
vcd_class_get_description (input_class_t *this_gen)
{
  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");
  return _("Video CD plugin with PBC and support for: (X)VCD, (X)SVCD, HQVCD, CVD ... ");
}

/*!
  From xine plugin spec:

  return short, human readable identifier for this plugin
  this is used for GUI buttons, The identifier must have max. 4 characters
  characters (max. 5 including terminating \0)
*/
static const char *
vcd_class_get_identifier (input_class_t *this_gen) {
  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");
  return SHORT_PLUGIN_NAME;
}

/*
   Handle all queued keyboard/mouse events. Return TRUE if this causes
   a change in the play item.
*/
static bool
vcd_handle_events (void)
{
  vcdplayer_t  *p_vcdplayer = &my_vcd.player;
  xine_event_t *p_event;
  int digit_entered=0;

  /* What you add to the last input number entry. It accumulates all of
     the 10_ADD keypresses */
  static unsigned int number_addend = 0;

  while ((p_event = xine_event_get(my_vcd.event_queue))) {

    dbg_print( (INPUT_DBG_CALL), "processing %d\n", p_event->type );
    digit_entered=0;

    switch(p_event->type) {

    case XINE_EVENT_INPUT_NUMBER_10_ADD:
      number_addend += 10;
      dbg_print(INPUT_DBG_EVENT, "10 added to number. Is now: %d\n",
                number_addend);
      break;

    /* The method used below is oblivious to XINE_EVENT_INPUT encodings
       In particular, it does not assume XINE_EVENT_INPUT_NUMBE_9 =
       XINE_EVENT_INPUT_NUMBER_0 + 9.
     */
    case XINE_EVENT_INPUT_NUMBER_9:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_8:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_7:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_6:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_5:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_4:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_3:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_2:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_1:
      digit_entered++;
    case XINE_EVENT_INPUT_NUMBER_0:
      {
        number_addend *= 10;
        number_addend += digit_entered;
        dbg_print(INPUT_DBG_EVENT,
                  "digit added number is now: %d\n", number_addend);
        break;
      }
    case XINE_EVENT_INPUT_MENU3:
      dbg_print(INPUT_DBG_EVENT, "menu3 setting debug: %d\n", number_addend);
      vcdplayer_debug = number_addend;
      number_addend = 0;
      break;
    case XINE_EVENT_INPUT_MENU1:
    case XINE_EVENT_INPUT_MENU2:
    case XINE_EVENT_INPUT_NEXT:
    case XINE_EVENT_INPUT_PREVIOUS:
      {
        int num = number_addend;
        vcdinfo_itemid_t itemid;

        number_addend = 0;

        /* If no number was given it's really the same as 1, not 0. */
        if (num == 0) num++;

        dbg_print(INPUT_DBG_EVENT,
                  "RETURN/NEXT/PREV/DEFAULT (%d) iteration count %d\n",
                  p_event->type, num);

        for ( ; num > 0; num--) {
          itemid = p_vcdplayer->play_item;
          switch (p_event->type) {
          case XINE_EVENT_INPUT_MENU1:
            if (p_vcdplayer->return_entry == VCDINFO_INVALID_ENTRY) {
              LOG_MSG("%s\n", _("selection has no RETURN entry"));
              return false;
            }
            itemid.num = p_vcdplayer->return_entry;
            dbg_print((INPUT_DBG_PBC|INPUT_DBG_EVENT),
                      "RETURN to %d\n", itemid.num);
            /* Don't loop around -- doesn't make sense to loop a return*/
            num = 0;
            break;
          case XINE_EVENT_INPUT_MENU2:
            if  (vcdplayer_pbc_is_on(p_vcdplayer)) {
              lid_t lid=vcdinfo_get_multi_default_lid(p_vcdplayer->vcd,
                                                      p_vcdplayer->i_lid,
                                                      p_vcdplayer->i_lsn);
              if (VCDINFO_INVALID_LID != lid) {
                itemid.num = lid;
                dbg_print((INPUT_DBG_PBC|INPUT_DBG_EVENT),
                          "DEFAULT to %d\n", itemid.num);
              } else {
                dbg_print((INPUT_DBG_PBC|INPUT_DBG_EVENT),
                          "no DEFAULT for LID %d\n",
                          p_vcdplayer->i_lid);
              }

              /* Don't loop around -- doesn't make sense to loop a return*/
              num = 0;
            } else {
              /* PBC is not on. "default" selection beginning of current
                 selection . Alternative: */
              LOG_MSG("%s\n", _("DEFAULT selected, but PBC is not on."));
            }
            break;
          case XINE_EVENT_INPUT_NEXT:
            if (p_vcdplayer->next_entry == VCDINFO_INVALID_ENTRY) {
              LOG_MSG("%s\n", _("selection has no NEXT entry"));
              return false;
            }
            itemid.num = p_vcdplayer->next_entry;
            dbg_print(INPUT_DBG_PBC, "NEXT to %d\n", itemid.num);
            break;
          case XINE_EVENT_INPUT_PREVIOUS:
            if (p_vcdplayer->prev_entry == VCDINFO_INVALID_ENTRY) {
              LOG_MSG("%s\n", _("selection has no PREVIOUS entry"));
              return false;
            }
            itemid.num = p_vcdplayer->prev_entry;
            dbg_print(INPUT_DBG_PBC, "PREVIOUS to %d\n", itemid.num);
            break;
          default:
            LOG_MSG("%s %d\n", _("Unknown event type: "), p_event->type);
          }
          _x_demux_flush_engine(my_vcd.stream);
          vcdplayer_play(p_vcdplayer, itemid);
          return true;
        }
        break;
      }
    case XINE_EVENT_INPUT_SELECT:
      {
        /* In the future will have to test to see if we are in a menu
           selection. But if not... */
        vcdinfo_itemid_t itemid = p_vcdplayer->play_item;

        itemid.num  = number_addend;
        number_addend = 0;

        if (vcdplayer_pbc_is_on(p_vcdplayer)) {
          lid_t i_next=vcdinfo_selection_get_lid(p_vcdplayer->vcd,
                                                 p_vcdplayer->i_lid,
                                                 itemid.num);
          if (VCDINFO_INVALID_LID != i_next) {
            itemid.num = i_next;
            _x_demux_flush_engine(my_vcd.stream);
            vcdplayer_play(p_vcdplayer, itemid);
            return true;
          }
        }
        break;
      }
    case XINE_EVENT_INPUT_MOUSE_BUTTON:
      if (my_vcd.stream)
      {
        xine_input_data_t *p_input = p_event->data;
        if (p_input->button == 1)
        {
#if LIBVCD_VERSION_NUM >= 23
          int i_selection;
#endif

          dbg_print(INPUT_DBG_EVENT,
                    "Button to x: %d, y: %d, scaled x: %d, scaled y %d\n",
                    p_input->x, p_input->y,
                    p_input->x * 255 / p_vcdplayer->max_x,
                    p_input->y * 255 / p_vcdplayer->max_y);

#if LIBVCD_VERSION_NUM >= 23
          /* xine_dvd_send_button_update(this, 1); */

          if (my_vcd.b_mouse_in)
            send_mouse_enter_leave_event(&my_vcd, false);

          i_selection = vcdinfo_get_area_selection(p_vcdplayer->vcd,
                                                   p_vcdplayer->i_lid,
                                                   p_input->x,
                                                   p_input->y,
                                                   p_vcdplayer->max_x,
                                                   p_vcdplayer->max_y);
          dbg_print(INPUT_DBG_EVENT, "Selection is: %d\n", i_selection);

          if (vcdplayer_pbc_is_on(p_vcdplayer)) {
            vcdinfo_itemid_t itemid = p_vcdplayer->play_item;
            lid_t i_next=vcdinfo_selection_get_lid(p_vcdplayer->vcd,
                                                   p_vcdplayer->i_lid,
                                                   i_selection);
            if (VCDINFO_INVALID_LID != i_next) {
              itemid.num = i_next;
              _x_demux_flush_engine(my_vcd.stream);
              vcdplayer_play(p_vcdplayer, itemid);
              return true;
            }
          }
#endif
        }
      }
      break;
    case XINE_EVENT_INPUT_BUTTON_FORCE:
      break;
    case XINE_EVENT_INPUT_MOUSE_MOVE:
      if (my_vcd.stream)
      {
        xine_input_data_t *p_input = p_event->data;
#if LIBVCD_VERSION_NUM >= 23
        int32_t i_selection = vcdinfo_get_area_selection(p_vcdplayer->vcd,
                                                         p_vcdplayer->i_lid,
                                                         p_input->x,
                                                         p_input->y,
                                                         p_vcdplayer->max_x,
                                                         p_vcdplayer->max_y);
        dbg_print(INPUT_DBG_EVENT, "Move to x: %d, y: %d\n",
                  p_input->x, p_input->y);

        if (my_vcd.i_mouse_button != i_selection) {
          dbg_print(INPUT_DBG_EVENT, "Old selection: %d, selection: %d\n",
                    my_vcd.i_mouse_button, i_selection);
          my_vcd.i_mouse_button = i_selection;
          if (i_selection < 0)
            send_mouse_enter_leave_event(&my_vcd, false);
          else
            send_mouse_enter_leave_event(&my_vcd, true);
        }
#else
      dbg_print(INPUT_DBG_EVENT, "Move to x: %d, y: %d\n",
                p_input->x, p_input->y);
#endif
      }
      break;
    case XINE_EVENT_INPUT_UP:
      dbg_print(INPUT_DBG_EVENT, "Called with up\n");
      vcdplayer_send_button_update(p_vcdplayer, 0);
      break;
    case XINE_EVENT_INPUT_DOWN:
      dbg_print(INPUT_DBG_EVENT, "Called with down\n");
      vcdplayer_send_button_update(p_vcdplayer, 0);
      break;
    case XINE_EVENT_INPUT_LEFT:
      dbg_print(INPUT_DBG_EVENT, "Called with left\n");
      vcdplayer_send_button_update(p_vcdplayer, 0);
      break;
    case XINE_EVENT_INPUT_RIGHT:
      dbg_print(INPUT_DBG_EVENT, "Called with right\n");
      vcdplayer_send_button_update(p_vcdplayer, 0);
      break;
    }
  }
  return false;
}

/*!
  From xine plugin spec:

  request optional data from input plugin.
*/
static int
vcd_get_optional_data (input_plugin_t *this_gen,
                        void *data, int data_type) {

  dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT),
             "called with %d\n", data_type);

  if (NULL == my_vcd.stream) return INPUT_OPTIONAL_UNSUPPORTED;

  /* Fill this out more fully... */
  switch(data_type) {

  case INPUT_OPTIONAL_DATA_AUDIOLANG:
    {
      uint8_t   channel;
      channel = _x_get_audio_channel(my_vcd.stream);

      dbg_print(INPUT_DBG_EXT, "AUDIO CHANNEL = %d\n", channel);
      if (channel == (uint8_t)-1) {
        strcpy(data, "auto");
      } else {
        const vcdinfo_obj_t *p_vcdinfo= my_vcd.player.vcd;
        unsigned int audio_type;
        unsigned int num_channels;
        unsigned int track_num = my_vcd.player.i_track;
        audio_type = vcdinfo_get_track_audio_type(p_vcdinfo, track_num);
        num_channels = vcdinfo_audio_type_num_channels(p_vcdinfo, audio_type);

        if (channel >= num_channels) {
          sprintf(data, "%d ERR", channel);
        } else {
          sprintf(data, "%1d", channel);
        }
      }
      return INPUT_OPTIONAL_SUCCESS;
    }

  case INPUT_OPTIONAL_DATA_SPULANG:
    {
      /*uint16_t lang;*/
      int8_t   channel;
      channel = (int8_t) _x_get_spu_channel(my_vcd.stream);
      dbg_print(INPUT_DBG_EXT, "SPU CHANNEL = %d\n", channel);
      if (-1 == channel) {
        strcpy(data, "auto");
      } else {
        sprintf(data, "%1d", channel);
      }

    }

  default: ;
  }

  return INPUT_OPTIONAL_UNSUPPORTED;
}

/* Array to hold MRLs returned by get_autoplay_list */
#define MAX_DIR_ENTRIES 250

/*!
  From xine plugin spec:

  generate autoplay list
  return value: list of MRLs

-- The list of MRLs returned goes into the playlist.
   This is called when the SHORT_PLUGIN_NAME button is pressed.
*/

static char **
vcd_class_get_autoplay_list (input_class_t *this_gen, int *num_files)
{
  vcd_input_class_t *class = (vcd_input_class_t *) this_gen;
  static char *filelist[MAX_DIR_ENTRIES];

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");

  if ( !vcd_build_mrl_list(class, my_vcd.player.psz_source) ) {
    *num_files = 0;
    return NULL;
  } else {
    int i;
    int size = 0;
    vcdinfo_item_enum_t itemtype =
      autoplay2itemtype[my_vcd.player.default_autoplay];

    int offset = vcd_get_mrl_type_offset(&my_vcd, itemtype, &size);

    /* A VCD is not required to have PBC or LID's, default to entry if
       this is the case...
     */
    if (VCDINFO_ITEM_TYPE_LID == itemtype && size==0) {
      itemtype=VCDINFO_ITEM_TYPE_ENTRY;
      offset = vcd_get_mrl_type_offset(&my_vcd, itemtype, &size);
    }

    /* This is because entries start at 0 while other playable units
       start at 1. Can remove the below when everything has the same
       origin.
     */
    if (VCDINFO_ITEM_TYPE_ENTRY != itemtype) offset++;

    for (i=0; i<size; i++) {
      if (class->mrls[offset+i] != NULL) {
        filelist[i] = class->mrls[offset+i]->mrl;
        dbg_print((INPUT_DBG_MRL), "filelist[%d]: %s\n", i, filelist[i]);
      } else {
        filelist[i] = NULL;
        dbg_print((INPUT_DBG_MRL), "filelist[%d]: NULL\n", i);
      }
    }
    *num_files = i;
    return filelist;
  }
}

/*!
  Things that need to be done when a stream is closed.
*/
static void
vcd_plugin_dispose(input_plugin_t *this_gen)
{

  /* Not sure there's much more to do here...
     In open_plugin we are given a stream which
     we save...
  */
  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");

  my_vcd.stream = NULL;

  if (my_vcd.player.b_opened)
    vcdio_close(&my_vcd.player);
}

/* Pointer to vcdimager default log handler. Set by init_input_plugin
   routine. Perhaps can remove. */
static vcd_log_handler_t  gl_default_vcd_log_handler = NULL;
static cdio_log_handler_t gl_default_cdio_log_handler = NULL;

/*! This routine is called by libvcd routines on error.
   Setup is done by init_input_plugin.
*/
static void
vcd_log_handler (vcd_log_level_t level, const char message[])
{
  switch (level) {
  case VCD_LOG_DEBUG:
  case VCD_LOG_INFO:
    if (!(vcdplayer_debug & INPUT_DBG_VCDINFO))
      return;
    /* Fall through if to warn case */
  case VCD_LOG_WARN:
    LOG_MSG("%s", message);
    break;
  case VCD_LOG_ERROR:
  case VCD_LOG_ASSERT:
    LOG_ERR("%s", message);
    break;
  default:
    LOG_ERR("%s\n%s %d",
            message,
            _("The above message had unknown vcdimager log level"),
            level);
  }

  /* gl_default_vcd_log_handler (level, message); */
}

/*! This routine is called by libcdio routines on error.
   Setup is done by init_input_plugin.
*/
static void
cdio_log_handler (cdio_log_level_t level, const char message[])
{
  switch (level) {
  case CDIO_LOG_DEBUG:
  case CDIO_LOG_INFO:
    if (!(vcdplayer_debug & INPUT_DBG_CDIO)) return;
    /* Fall through if to warn case */
  default:
    vcd_log_handler (level, message);
  }
}

/*! This routine is when xine is not around.
   Setup is done by vcd_class_dispose.
*/
static void
uninit_log_handler (vcd_log_level_t level, const char message[])
{
  switch (level) {
  case VCD_LOG_DEBUG:
  case VCD_LOG_INFO:
    if (!(vcdplayer_debug & (INPUT_DBG_VCDINFO|INPUT_DBG_CDIO)))
      return;
    /* Fall through if to warn case */
  case VCD_LOG_WARN:
    fprintf(stderr, "WARN: %s\n", message);
    break;
  case VCD_LOG_ERROR:
    fprintf(stderr, "ERROR: %s\n", message);
    break;
  case VCD_LOG_ASSERT:
    fprintf(stderr, "ASSERT ERROR: %s\n", message);
    break;
  default:
    fprintf(stderr, "UNKNOWN ERROR: %s\n%s %d",
            message,
            _("The above message had unknown vcdimager log level"),
            level);
  }

  /* gl_default_vcd_log_handler (level, message); */
}

/*!
  Things that need to be done the vcd plugin is closed.
*/
static void
vcd_class_dispose (input_class_t *this_gen) {
  vcd_input_class_t  *class = (vcd_input_class_t *) this_gen;

  class->xine->config->unregister_callback(class->xine->config,
					   "media.vcd.device");
  gl_default_vcd_log_handler  = vcd_log_set_handler (uninit_log_handler);
  gl_default_cdio_log_handler =
    cdio_log_set_handler ((cdio_log_handler_t) uninit_log_handler);

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called\n");

  vcd_close(class);
  free(class->vcd_device);
  free(my_vcd.v_config.title_format);
  free(my_vcd.v_config.comment_format);
  free(class);
}

/* Update the xine player title text. */
static void
vcd_update_title_display(void)
{
  xine_event_t uevent;
  xine_ui_data_t data;

  char *title_str;

  title_str = vcdplayer_format_str(&my_vcd.player,
                                   my_vcd.v_config.title_format);

  meta_info_assign(XINE_META_INFO_TITLE, my_vcd.stream, title_str);
  meta_info_assign(XINE_META_INFO_COMMENT, my_vcd.stream,
                   vcdplayer_format_str(&my_vcd.player,
                                        my_vcd.v_config.comment_format));
  stream_info_assign(XINE_STREAM_INFO_VIDEO_HAS_STILL, my_vcd.stream,
                     my_vcd.player.i_still);

  /* Set_str title/chapter display */
  dbg_print((INPUT_DBG_MRL|INPUT_DBG_CALL),
            "Changing title to read '%s'\n", title_str);
  uevent.type        = XINE_EVENT_UI_SET_TITLE;
  uevent.stream      = my_vcd.stream;
  uevent.data        = &data;
  uevent.data_length = sizeof(data);

  memcpy(data.str, title_str, strlen(title_str) + 1);
  data.str_len = strlen(title_str) + 1;

  xine_event_send(my_vcd.stream, &uevent);
}

#if LIBVCD_VERSION_NUM >= 23
static void
send_mouse_enter_leave_event(vcd_input_plugin_t *p_this, bool b_mouse_in)
{
  if (b_mouse_in && p_this->b_mouse_in) {
    /* Set up to enter the following "if" statement. */
    p_this->b_mouse_in = false;
  }

  if (b_mouse_in != p_this->b_mouse_in) {
    xine_event_t        event;
    xine_spu_button_t   spu_event;

    spu_event.direction = b_mouse_in ? 1 : 0;
    spu_event.button    = p_this->i_mouse_button;

    event.type        = XINE_EVENT_SPU_BUTTON;
    event.stream      = p_this->stream;
    event.data        = &spu_event;
    event.data_length = sizeof(spu_event);
    xine_event_send(p_this->stream, &event);

    p_this->b_mouse_in = b_mouse_in;
  }

  if (!b_mouse_in)
    p_this->i_mouse_button = -1;
}
#endif

/*
   Not much special initialization needed here. All of the initialization
   is either done in the class or when we have an actual MRL we want
   to deal with.
*/
static int
vcd_plugin_open (input_plugin_t *this_gen ) {
  vcd_input_class_t  *class = (vcd_input_class_t *) this_gen->input_class;

  gl_default_vcd_log_handler  = vcd_log_set_handler (vcd_log_handler);
  gl_default_cdio_log_handler = cdio_log_set_handler (cdio_log_handler);

  /* actually, this is also done by class initialization. But just in
     case... */
  class->ip          = &my_vcd;
  my_vcd.i_old_still = 0;

  return 1;
}

/*!
  This basically sets up stream specified by MRL for playing. After this
  routine is called, xine-lib can read blocks from the thing
  specified by the MRL, set the position of the thing specified by the
  MRL, get its size or read its current position...

  See vcdplayer_parses_mrl for the for the format that a valid MRL can take.

  Return values:
     pointer to input plugin
     NULL on failure

*/
static input_plugin_t *
vcd_class_get_instance (input_class_t *class_gen, xine_stream_t *stream,
                        const char *mrl)
{
  vcd_input_class_t  *class = (vcd_input_class_t *) class_gen;

  char intended_vcd_device[MAX_DEVICE_LEN+1]= { '\0', };
  vcdinfo_itemid_t itemid;
  char *check_mrl=NULL;
  bool used_default;

  if (mrl == NULL)
    check_mrl = strdup(MRL_PREFIX);
  else
    check_mrl = strdup(mrl);

  dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT), "called with %s\n", mrl);

  if ( strncasecmp(check_mrl, MRL_PREFIX, MRL_PREFIX_LEN) ) {
    goto free_and_return;
  }

  vcd_get_default_device(class, false);

  if (!vcd_parse_mrl(class->vcd_device, check_mrl,
                     intended_vcd_device, &itemid,
                     my_vcd.player.default_autoplay, &used_default)) {
    dbg_print(INPUT_DBG_MRL, "parsing MRL %s failed\n", check_mrl);
    goto free_and_return;
  }

  free(my_vcd.mrl);
  my_vcd.mrl         = strdup(check_mrl);
  my_vcd.stream      = stream;
  my_vcd.event_queue = xine_event_new_queue (stream);
  class->ip          = &my_vcd; /* Can probably get rid of this... */

  if (!vcd_build_mrl_list(class, intended_vcd_device)) {
    goto free_and_return;
  }

  my_vcd.player.user_data   = (void *) class;

  /* Do we set PBC (via LID) on? */
  my_vcd.player.i_lid =
    ( VCDINFO_ITEM_TYPE_LID == itemid.type
      && my_vcd.player.i_lids > itemid.num )
    ? itemid.num
    :  VCDINFO_INVALID_ENTRY;

  if ( VCDINFO_ITEM_TYPE_LID == itemid.type && used_default) {
    /* LID was selected automatically but we don't have PBC for this VCD.
       So silently change LID to track and continue.
     */
    itemid.type=VCDINFO_ITEM_TYPE_TRACK;
  }

  if ( 0==itemid.num
       && ( (VCDINFO_ITEM_TYPE_LID == itemid.type)
            || (VCDINFO_ITEM_TYPE_TRACK == itemid.type) ) )
    itemid.num = 1;

  dbg_print(INPUT_DBG_PBC, "Jumping to NUM >%i<, type >%i<\n",
            itemid.num, itemid.type);

  vcd_set_meta_info(&my_vcd);
  vcdplayer_play(&my_vcd.player, itemid);


  dbg_print(INPUT_DBG_MRL, "Successfully opened MRL %s.\n",
            my_vcd.mrl);

  free (check_mrl);
  return &(my_vcd.input_plugin);

 free_and_return:
  free (check_mrl);
  return NULL;
}

#define VCD_NUM_CALLBACK(fn_name, var) \
 static void fn_name(void *this_gen, xine_cfg_entry_t *entry) \
{ \
\
  dbg_print(INPUT_DBG_CALL, "Called setting %d\n", entry->num_value); \
\
  my_vcd.player.var = entry->num_value; \
}

#define VCD_ENUM_CALLBACK(fn_name, enum_type, var) \
 static void fn_name(void *this_gen, xine_cfg_entry_t *entry) \
{ \
  dbg_print(INPUT_DBG_CALL, "Called setting %d\n", entry->num_value); \
\
  my_vcd.player.var = (enum_type) entry->num_value; \
}

#define VCD_STR_CALLBACK(fn_name, var) \
 static void fn_name(void *this_gen, xine_cfg_entry_t *entry) \
{ \
\
  dbg_print(INPUT_DBG_CALL, "Called setting %s\n", entry->str_value); \
  if ( NULL == entry->str_value ) return; \
\
  if ( var ) free(var); \
  var = strdup(entry->str_value); \
}

VCD_STR_CALLBACK(vcd_default_dev_changed_cb,
                  my_vcd.class->vcd_device)

VCD_STR_CALLBACK(vcd_title_format_changed_cb,
                  my_vcd.v_config.title_format)

VCD_STR_CALLBACK(vcd_comment_format_changed_cb,
                  my_vcd.v_config.comment_format)

VCD_NUM_CALLBACK(vcd_show_rejected_cb, show_rejected)

VCD_NUM_CALLBACK(vcd_autoadvance_cb, autoadvance)

VCD_ENUM_CALLBACK(vcd_slider_length_cb, vcdplayer_slider_length_t,
                   slider_length)

VCD_ENUM_CALLBACK(vcd_default_autoplay_cb, vcdinfo_item_enum_t,
                   default_autoplay)

static void
vcd_debug_cb(void *this_gen, xine_cfg_entry_t *entry)
{
  dbg_print(INPUT_DBG_CALL, "Called setting %d\n", entry->num_value);
  vcdplayer_debug = entry->num_value;
}

static void *
vcd_init (xine_t *xine, void *data)
{
  vcd_input_class_t  *class;
  config_values_t    *config;

  dbg_print(INPUT_DBG_CALL, "Called\n");

  class = calloc(1, sizeof (vcd_input_class_t));

  class->xine   = xine;
  class->config = config = xine->config;

  vcd_class     = class;
  class->mrls   = NULL;

  class->input_class.get_instance        = vcd_class_get_instance;
  class->input_class.get_identifier      = vcd_class_get_identifier;
  class->input_class.get_description     = vcd_class_get_description;
  class->input_class.get_dir             = vcd_class_get_dir;
  class->input_class.get_autoplay_list   = vcd_class_get_autoplay_list;
  class->input_class.dispose		 = vcd_class_dispose;
  class->input_class.eject_media         = vcd_class_eject_media;

  memset(&my_vcd, 0, sizeof(my_vcd));

  /*------------------------------------------------------------------
    Callback functions.
  ---------------------------------------------------------------------*/
  my_vcd.player.flush_buffers          = &vcd_flush_buffers;
  my_vcd.player.update_title           = &vcd_update_title_display;
  my_vcd.player.log_err                = (generic_fn) &xine_log_err;
  my_vcd.player.log_msg                = (generic_fn) &xine_log_msg;
  my_vcd.player.force_redisplay        = &vcd_force_redisplay;
  my_vcd.player.set_aspect_ratio       = &vcd_set_aspect_ratio;

  /*-------------------------------------------------------------
     Playback control-specific fields
   --------------------------------------------------------------*/

  my_vcd.player.i_lid                  = VCDINFO_INVALID_ENTRY;
  my_vcd.player.end_lsn                = VCDINFO_NULL_LSN;

  my_vcd.player.pdi                    = -1;
  my_vcd.player.pxd.psd                = NULL;

  /*-----------------------------------
     Navigation fields
   ------------------------------------*/
  my_vcd.player.next_entry             = -1;
  my_vcd.player.prev_entry             = -1;
  my_vcd.player.return_entry           = -1;
  my_vcd.player.default_entry          = -1;

  /*--------------------------------------------------------------
    Configuration variables
   ---------------------------------------------------------------*/

  {
    /*Note: these labels have to be listed in the same order as the
      enumeration vcdplayer_autoplay_t in vcdplayer.h.
    */
    static const char *autoplay_modes[] =
      { "MPEG track", "entry", "segment",  "playback-control item", NULL };

    /*Note: these labels have to be listed in the same order as the
      enumeration vcdplayer_slider_length_t in vcdplayer.h.
    */
    static const char *length_reporting_modes[] =
      { "auto", "track", "entry", NULL };

    my_vcd.player.default_autoplay =
      config->register_enum(config,
                            "media.vcd.autoplay",
                            VCDPLAYER_AUTOPLAY_PBC,
                            (char **) autoplay_modes,
                            _("VCD default type to use on autoplay"),
_("The VCD play unit to use when none is specified in an MRL, e.g. "
                            "vcd:// or vcd:///dev/dvd:"),
                            10,
                            vcd_default_autoplay_cb, class);


    class->vcd_device =
      strdup (config->register_filename(config,
                              "media.vcd.device",
                              "", XINE_CONFIG_STRING_IS_DEVICE_NAME,
          _("CD-ROM drive used for VCD when none given"),
_("What to use if no drive specified. If the setting is empty, xine will scan for CD drives."),
                              20,
                              vcd_default_dev_changed_cb,
                              (void *) class));

    my_vcd.player.slider_length =
      config->register_enum(config,
                            "media.vcd.length_reporting",
                            VCDPLAYER_SLIDER_LENGTH_AUTO,
                            (char **) length_reporting_modes,
                            _("VCD position slider range"),
_("range that the stream playback position slider represents playing a VCD."),
                            10,
                            vcd_slider_length_cb, NULL);

#if READAHEAD_FINISHED
    my_vcd.player.readahead =
      config->register_bool(config, "vcd.use_readahead",
                            (int) false,
                            _("VCD read-ahead caching?"),
                            _("Class "
                              "may lead to jerky playback on low-end "
                              "machines."),
                            vcd_read_ahead_cb, NULL);
#endif

  my_vcd.player.autoadvance =
    config->register_bool(config,
                        "media.vcd.autoadvance",
                        (int) true,
                        _("automatically advance VCD track/entry"),
_("If enabled, we should automatically advance to the next entry or track. Used only when playback control (PBC) is disabled."),
                        10,
                        vcd_autoadvance_cb,
                        NULL);

  my_vcd.player.show_rejected =
    config->register_bool(config,
                        "media.vcd.show_rejected",
                        (int) false,
                        _("show 'rejected' VCD LIDs"),
_("Some playback list IDs (LIDs) are marked not showable, "
"but you can see them in the MRL list if this is set. Rejected entries "
"are marked with an asterisk (*) appended to the MRL."),
                        10,
                        vcd_show_rejected_cb,
                        NULL);

  my_vcd.v_config.title_format =
    strdup(config->register_string(config,
                          "media.vcd.title_format",
                          "%F - %I %N%L%S, disk %c of %C - %v %A",
                          _("VCD format string for display banner"),
_("VCD format used in the GUI Title. Similar to the Unix date "
"command. Format specifiers start with a percent sign. Specifiers are:\n"
" %A : The album information\n"
" %C : The VCD volume count - the number of CD's in the collection.\n"
" %c : The VCD volume num - the number of the CD in the collection.\n"
" %F : The VCD Format, e.g. VCD 1.0, VCD 1.1, VCD 2.0, or SVCD\n"
" %I : The current entry/segment/playback type, e.g. ENTRY, TRACK, ...\n"
" %L : The playlist ID prefixed with \" LID\" if it exists\n"
" %N : The current number of the above - a decimal number\n"
" %P : The publisher ID\n"
" %p : The preparer ID\n"
" %S : If we are in a segment (menu), the kind of segment\n"
" %T : The track number\n"
" %V : The volume set ID\n"
" %v : The volume ID\n"
"      A number between 1 and the volume count.\n"
" %% : a %\n"),
                          20,
                          vcd_title_format_changed_cb,
                          NULL));

  my_vcd.v_config.comment_format =
    strdup(config->register_string(config,
                          "media.vcd.comment_format",
                          "%P - Track %T",
                          _("VCD format string for stream comment field"),
_("VCD format used in the GUI Title. Similar to the Unix date "
"command. Format specifiers start with a percent sign. Specifiers are "
"%A, %C, %c, %F, %I, %L, %N, %P, %p, %S, %T, %V, %v, and %%.\n"
"See the help for the title_format for the meanings of these."),
                          20,
                          vcd_comment_format_changed_cb,
                          NULL));

  vcdplayer_debug =
  config->register_num(config,
                       "media.vcd.debug",
                       0,
                       _("VCD debug flag mask"),
_("For tracking down bugs in the VCD plugin. Mask values are:\n"
"   1: Meta information\n"
"   2: input (keyboard/mouse) events\n"
"   4: MRL parsing\n"
"   8: Calls from external routines\n"
"  16: routine calls\n"
"  32: LSN changes\n"
"  64: Playback control\n"
" 128: Debugging from CDIO\n"
" 256: Seeks to set location\n"
" 512: Seeks to find current location\n"
"1024: Still-frame\n"
"2048: Debugging from VCDINFO\n"
),
                        20,
                        vcd_debug_cb,
                        class);
  }

  gl_default_vcd_log_handler  = vcd_log_set_handler (uninit_log_handler);
  gl_default_cdio_log_handler =
    cdio_log_set_handler ((cdio_log_handler_t) uninit_log_handler);

  my_vcd.input_plugin.open               = vcd_plugin_open;
  my_vcd.input_plugin.get_capabilities   = vcd_plugin_get_capabilities;
  my_vcd.input_plugin.read               = vcd_plugin_read;
  my_vcd.input_plugin.read_block         = vcd_plugin_read_block;
  my_vcd.input_plugin.seek               = vcd_plugin_seek;
  my_vcd.input_plugin.get_current_pos    = vcd_plugin_get_current_pos;
  my_vcd.input_plugin.get_length         = vcd_plugin_get_length;
  my_vcd.input_plugin.get_blocksize      = vcd_plugin_get_blocksize;
  my_vcd.input_plugin.get_mrl            = vcd_plugin_get_mrl;
  my_vcd.input_plugin.get_optional_data  = vcd_get_optional_data;
  my_vcd.input_plugin.dispose            = vcd_plugin_dispose;
  my_vcd.input_plugin.input_class        = (input_class_t *) class;

  my_vcd.stream                          = NULL;
  my_vcd.class                           = class;
  my_vcd.i_mouse_button                  = -1;
  my_vcd.b_mouse_in                      = false;

  my_vcd.player.psz_source               = NULL;

  my_vcd.player.b_opened                 = false;
  my_vcd.player.play_item.num            = VCDINFO_INVALID_ENTRY;
  my_vcd.player.play_item.type           = VCDINFO_ITEM_TYPE_ENTRY;

  my_vcd.player_device                   = NULL;

  return class;
}

/*
   Exported plugin catalog entries.

   All plugins listing only the current API number break when the API
   number is increased. This is by design.

   Sometimes in the rush to get out a buggy release, the API number is
   increased without communication let alone a concern for whether it
   is necessary or how many plugins it might break. And that is
   precisely when what happened between API release 12 and API
   13. Input plugin API numbers 12 and 13 are functionally identical.

   Because of problems like this, we'll just put in a future API
   release. If the number was increased for a reason that doesn't
   affect us (such as for nor reason at all), then this plugin will
   work unmodified that future APIs. If on the other hand there was
   incompatible change, we are no worse off than if we hadn't entered
   the next API number since in both cases the plugin is broken.
 */

const plugin_info_t xine_plugin_info[] EXPORTED = {
  /* type, API, "name", version, special_info, init_function */
  { PLUGIN_INPUT | PLUGIN_MUST_PRELOAD, 17, (char *) SHORT_PLUGIN_NAME,
    XINE_VERSION_CODE, NULL, vcd_init },
  { PLUGIN_NONE, 0, (char *) "", 0, NULL, NULL }
};

/*
 * Local variables:
 *  c-file-style: "gnu"
 *  tab-width: 8
 *  indent-tabs-mode: nil
 * End:
 */