#include <stdio.h>
#include <vlc/vlc.h>
+#ifdef HAVE_LIBCDIO
+#include <cdio/cdio.h>
+#include <cdio/cd_types.h>
+#endif /* HAVE_LIBCDIO */
#include <wx/combobox.h>
#include <wx/statline.h>
FileName_Event,
DiscType_Event,
+#ifdef HAVE_LIBCDIO
+ DiscProbe_Event,
+#endif
DiscDevice_Event,
DiscTitle_Event,
DiscChapter_Event,
/* Events generated by the disc panel */
EVT_RADIOBOX(DiscType_Event, OpenDialog::OnDiscTypeChange)
+#ifdef HAVE_LIBCDIO
+ EVT_CHECKBOX(DiscProbe_Event, OpenDialog::OnDiscProbe)
+#endif
EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscDeviceChange)
EVT_TEXT(DiscDevice_Event, OpenDialog::OnDiscPanelChange)
EVT_TEXT(DiscTitle_Event, OpenDialog::OnDiscPanelChange)
WXSIZEOF(disc_type_array), disc_type_array,
WXSIZEOF(disc_type_array), wxRA_SPECIFY_COLS );
+#ifdef HAVE_LIBCDIO
+ disc_probe = new wxCheckBox( panel, DiscProbe_Event,
+ wxU(_("Probe Disc")) );
+#endif
+
sizer_row->Add( disc_type, i_disc_type_selection, wxEXPAND | wxALL, 5 );
+ sizer_row->Add( disc_probe, 0, wxEXPAND | wxALL );
wxStaticText *label = new wxStaticText( panel, -1, wxU(_("Device name")) );
disc_device = new wxTextCtrl( panel, DiscDevice_Event, wxT(""),
UpdateMRL( DISC_ACCESS );
}
+#ifdef HAVE_LIBCDIO
+
+/* Return a device that has a DVD in it. The caller needs to free
+ the returned string.
+*/
+static char * ProbeDVD()
+{
+ char **ppsz_cd_drives = cdio_get_devices(DRIVER_DEVICE);
+ if (ppsz_cd_drives)
+ {
+ char **c;
+ for( c = ppsz_cd_drives; *c != NULL; c++ )
+ {
+ CdIo_t *p_cdio = cdio_open (*c, DRIVER_UNKNOWN);
+ if (p_cdio)
+ {
+ discmode_t discmode = cdio_get_discmode(p_cdio);
+ cdio_destroy(p_cdio);
+ if( cdio_is_discmode_dvd(discmode) )
+ {
+ char *psz_drive = strdup(*c);
+ cdio_free_device_list(ppsz_cd_drives);
+ return strdup(psz_drive);
+ }
+ }
+
+ }
+ cdio_free_device_list(ppsz_cd_drives);
+ }
+ return NULL;
+}
+
+
+static char * ProbeDevice(char **search_devices, cdio_fs_anal_t mask,
+ bool b_any)
+{
+ char **ppsz_devices;
+
+ /* Start out trying the device that has been entered so far. */
+ ppsz_devices = cdio_get_devices_with_cap(search_devices, mask, b_any);
+
+ if (ppsz_devices && *ppsz_devices)
+ {
+ char *psz_device = strdup(*ppsz_devices);
+ cdio_free_device_list(ppsz_devices);
+ return psz_device;
+ }
+
+ /* If there was no device specified on the first try then give up
+ now. Otherwise accept any CD-ROM in the class (e.g. VCD or DVD).
+ */
+ if (!search_devices[0]) return NULL;
+
+ ppsz_devices = cdio_get_devices_with_cap(NULL, mask, b_any);
+
+ if (ppsz_devices && *ppsz_devices)
+ {
+ char *psz_device = strdup(*ppsz_devices);
+ cdio_free_device_list(ppsz_devices);
+ return psz_device;
+ }
+
+ return NULL;
+}
+
+
+/* Return a device that has a CD-DA in it. The caller needs to free
+ the returned string.
+*/
+static char * ProbeCDDA(const wxChar *device)
+{
+ char *ppsz_device[2];
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(device);
+ char *psz_device = (char *) tmp_buf;
+ ppsz_device[0] = (device && *device) ? psz_device : NULL;
+ ppsz_device[1] = NULL;
+ return ProbeDevice(ppsz_device, CDIO_FS_AUDIO, false);
+}
+
+/* Return a device that has a VCD in it. The caller needs to free
+ the returned string.
+*/
+static char * ProbeVCD(const wxChar *device)
+{
+ char *ppsz_device[2];
+ const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(device);
+ char *psz_device = (char *) tmp_buf;
+ ppsz_device[0] = (device && *device) ? psz_device : NULL;
+ ppsz_device[1] = NULL;
+ return ProbeDevice(ppsz_device,
+ (CDIO_FS_ANAL_SVCD|CDIO_FS_ANAL_CVD|CDIO_FS_ANAL_VIDEOCD
+ |CDIO_FS_UNKNOWN), true);
+}
+
+
+/*
+ Probe (find anywhere) a CD-DA, VCD, or a DVD.
+ First we try the device name that may have been entered for the media class
+ selected. If that doesn't work we try any device for the media class.
+ If that doesn't work the try looking for CD-ROMs or DVD drives and set the
+ media selection to whatever we find.
+*/
+void OpenDialog::OnDiscProbe( wxCommandEvent& WXUNUSED(event) )
+{
+ wxCommandEvent dummy_event;
+ char *psz_device = NULL;
+ bool b_probed_DVD = false;
+ bool b_probed_VCD = false;
+
+ retry:
+ switch( disc_type->GetSelection() )
+ {
+
+ case 0: /* DVD with menus */
+ case 1: /* DVD without menus */
+ /* If not a DVD then try for a VCD. If VCD fails it will
+ try for a CD-DA. */
+ if (!psz_device) psz_device = ProbeDVD();
+ if (!psz_device)
+ {
+ b_probed_DVD = true;
+ disc_type->SetSelection(2);
+ OnDiscTypeChange( dummy_event );
+ goto retry;
+ }
+ disc_device->SetValue( wxL2U(psz_device) );
+ free(psz_device);
+ break;
+
+ case 2: /* VCD probe of some sort */
+ if(!psz_device) psz_device = ProbeVCD(disc_device->GetValue());
+ if( psz_device )
+ {
+ CdIo_t *p_cdio = cdio_open (psz_device, DRIVER_UNKNOWN);
+ disc_device->SetValue( wxL2U(psz_device) );
+
+ /* Set track range accurately if possible. */
+ if (p_cdio)
+ {
+ track_t i_last_track = cdio_get_last_track_num(p_cdio);
+ disc_title->SetRange( 0, i_last_track-1 );
+ }
+ free(psz_device);
+ cdio_destroy(p_cdio);
+ break;
+ }
+
+ b_probed_VCD = true;
+
+ /* Not a VCD. Try for a DVD unless we've been there before. */
+ if( !b_probed_DVD && (psz_device = ProbeDVD()) )
+ {
+ disc_type->SetSelection(0);
+ OnDiscTypeChange( dummy_event );
+ goto retry;
+ }
+ b_probed_DVD = true;
+
+ /* Couldn't find a VCD or DVD. See if we can find a CD-DA. */
+ psz_device = ProbeCDDA(disc_device->GetValue());
+ if( psz_device )
+ {
+ disc_type->SetSelection(3);
+ OnDiscTypeChange( dummy_event );
+ goto retry;
+ }
+ break;
+
+ case 3: /* CD-DA Probe */
+ if(!psz_device) psz_device = ProbeCDDA(disc_device->GetValue());
+ if( psz_device )
+ {
+ CdIo_t *p_cdio = cdio_open (psz_device, DRIVER_UNKNOWN);
+ disc_device->SetValue( wxL2U(psz_device) );
+ if (p_cdio)
+ {
+ track_t i_last_track = cdio_get_last_track_num(p_cdio);
+ disc_title->SetRange( 0, i_last_track );
+ }
+ free(psz_device);
+ cdio_destroy(p_cdio);
+ break;
+ }
+
+ /* Not a CD-DA. Try for a DVD unless we've been there before. */
+ if( !b_probed_DVD && (psz_device = ProbeDVD()) )
+ {
+ disc_type->SetSelection(0);
+ OnDiscTypeChange( dummy_event );
+ goto retry;
+ }
+
+ /* Couldn't find a CD-DA or DVD. See if we can find a VCD, unless
+ we've tried that before. */
+ if (!b_probed_VCD) psz_device = ProbeVCD(disc_device->GetValue());
+ if( psz_device )
+ {
+ disc_type->SetSelection(2);
+ OnDiscTypeChange( dummy_event );
+ goto retry;
+ }
+ break;
+
+ default:
+ msg_Err( p_intf, "invalid Disc type selection (%d)",
+ disc_type->GetSelection() );
+ break;
+ }
+
+ disc_probe->SetValue(FALSE);
+
+ UpdateMRL( DISC_ACCESS );
+}
+#endif /* HAVE_LIBCDIO */
+
void OpenDialog::OnDiscTypeChange( wxCommandEvent& WXUNUSED(event) )
{
char *psz_device = NULL;