Skip to content

Commit

Permalink
Jerry G Geiger fixed the C routines that return char** so they return…
Browse files Browse the repository at this point in the history
… a Perl list. He also added

cdio_guess_cd_type and cdio_read_pvd.
  • Loading branch information
R. Bernstein committed Aug 16, 2011
1 parent a83f8ee commit 39e7708
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 23 deletions.
10 changes: 6 additions & 4 deletions THANKS
@@ -1,14 +1,16 @@
Many thanks to Jerry G Geiger for resurrecting this project from the dead. He added:

- audio_get_status
- audio_get_volume
- audio_set_volume
- get_disk_cdtext, get_track_cdtext
- audio_get_status
- is_tray_open
- cdio_guess_cd_type
- cdio_read_pvd
- cdio_version (version string of linked library)
- get_cddb_discid
- audio_get_status
- get_disk_cdtext
- get_joliet_level
- get_track_cdtext
- is_tray_open

He also fixed Build.PL so it works again and added many corrections to
my faulty C interface code.;
Expand Down
18 changes: 3 additions & 15 deletions lib/Device/Cdio.pm
Expand Up @@ -251,11 +251,7 @@ sub get_devices {
my($driver_id, @args) = _rearrange(['DRIVER_ID'], @p);
return undef if _extra_args(@args);
$driver_id = $perlcdio::DRIVER_DEVICE if !defined($driver_id);
# There's a bug in the swig code in that the input parameter
# is left on the stack
my @ret = perlcdio::get_devices($driver_id);
shift @ret;
return @ret;
return perlcdio::get_devices($driver_id);
}

=pod
Expand All @@ -277,11 +273,7 @@ sub get_devices_ret {
my($driver_id, @args) = _rearrange(['DRIVER_ID'], @p);
return undef if _extra_args(@args);
$driver_id = $perlcdio::DRIVER_DEVICE if !defined($driver_id);
# There's a bug in the swig code in that the input parameter
# is left on the stack
my @ret = perlcdio::get_devices_ret($driver_id);
shift @ret;
return @ret;
return perlcdio::get_devices_ret($driver_id);
}

=pod
Expand Down Expand Up @@ -311,11 +303,7 @@ sub get_devices_with_cap {
my($cap, $any, @args) = _rearrange(['CAPABILITIES', 'ANY'], @p);
return undef if _extra_args(@args);
$any = 1 if !defined($any);
# There's a bug in the swig code in that the input parameters
# are left on the stack
my @ret = perlcdio::get_devices_with_cap($cap, $any);
shift @ret; shift @ret;
return @ret;
return perlcdio::get_devices_with_cap($cap, $any);
}

=pod
Expand Down
45 changes: 45 additions & 0 deletions lib/Device/Cdio/Device.pm
Expand Up @@ -607,6 +607,33 @@ sub get_media_changed {

=pod
=head2 guess_cd_type
$hash = $dev->guess_cd_type($lsn,$track);
Try to determine what kind of CD-image and/or filesystem we have at
track $track. First argument is the start lsn of track $track. Returns a
hash reference with following keys:
cdio_fs_t (enum cdio_fs_t from libcdio) FIXME: add text
cdio_fs_cap_t (enum cdio_fs_cap_t from libcdio) FIXME: add text
joliet_level If has Joliet extensions, this is the associated level
number (i.e. 1, 2, or 3).
iso_label 32 byte ISO fs label.
isofs_size size of ISO fs.
UDFVerMajor UDF fs version.
UDFVerMinor UDF fs version.
=cut

sub guess_cd_type {
my($self, $session, $track, @p) = @_;
return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 2);
return perlcdio::guess_cd_type($self->{cd}, $session, $track);
}

=pod
=head2 get_num_tracks
get_num_tracks()->int
Expand Down Expand Up @@ -885,6 +912,24 @@ sub set_speed {
return perlcdio::set_speed($self->{cd}, $speed);
}

=pod
=head2 read_pvd
$pvd = $dev->read_pvd;
Reads and returns the ISO-9660 Primary Volume Descriptor (PVD) from the disk.
You can use perliso9660::get_pvd_type($pvd) ... methods to get the values.
=cut


sub read_pvd {
my($self,@p) = @_;
return perlcdio::cdio_read_pvd($self->{cd});
}


1; # Magic true value required at the end of a module

__END__
Expand Down
28 changes: 25 additions & 3 deletions swig/device.swg
Expand Up @@ -39,13 +39,27 @@ typedef char ** DeviceList_t;
num++;
}

if (num+argvi >= items) {
/* Extend the stack by (num - items) objects */
EXTEND(sp, num-items);
}
/* For each element in the array of strings, create a new
* mortalscalar, and stuff it into the above array. */
for (p = $1; *p; p++) {
for (num=0,p = $1; *p; p++) {
/* Have perl compute the length of the string using strlen() */
//PUSHs(sv_2mortal(newSVpv(*p, 0))); // uses SP, modified by dSP (XS)
ST(num++)=(sv_2mortal(newSVpv(*p, 0)));
}
/* FIXME: the + 1 is because p_cdio is still on the stack. */
argvi += num; // fixed ??
/* For each element in the array of strings, create a new
* mortalscalar, and stuff it into the above array.
for (p = $1; *p; p++) {
Have perl compute the length of the string using strlen()
XPUSHs(sv_2mortal(newSVpv(*p, 0)));
}
argvi += num;
argvi = num;
*/
cdio_free_device_list($1);
out: ;
}
Expand Down Expand Up @@ -189,7 +203,7 @@ get_default_device_driver(driver_id_t driver_id, driver_id_t *p_out_driver_id)
}
%}

%rename cdio_get_devices get_devices;
//%rename cdio_get_devices get_devices;
/*! Return an array of device names. If you want a specific
devices for a driver, give that device. If you want hardware
devices, give DRIVER_DEVICE and if you want all possible devices,
Expand All @@ -203,6 +217,14 @@ get_default_device_driver(driver_id_t driver_id, driver_id_t *p_out_driver_id)
*/
DeviceList_t cdio_get_devices (driver_id_t driver_id);

DeviceList_t get_devices(driver_id_t driver_id);


%inline %{
DeviceList_t get_devices(driver_id_t driver_id) {
return cdio_get_devices(driver_id);
}
%}
/* Like cdio_get_devices, but we may change the p_driver_id if we
were given DRIVER_DEVICE or DRIVER_UNKNOWN. This is because
often one wants to get a drive name and then *open* it
Expand Down
22 changes: 21 additions & 1 deletion swig/disc.swg
Expand Up @@ -90,7 +90,6 @@ get_disc_mode (CdIo_t *p_cdio)
return (const char *)newSV(0);
return discmode2str[discmode];
}

%}


Expand Down Expand Up @@ -157,3 +156,24 @@ uint32_t get_cddb_discid(CdIo_t *p_cdio)
}
%}

SV * guess_cd_type(const CdIo_t *cdio, int start_session, track_t track_num);
%inline %{
SV * guess_cd_type(const CdIo_t *cdio, int start_session, track_t track_num) {
cdio_iso_analysis_t t;
int r;
HV * iso_analysis;
r = cdio_guess_cd_type (cdio, start_session, track_num, &t);
iso_analysis = newHV();
hv_store(iso_analysis, "cdio_fs_t",9, newSViv(r&CDIO_FS_MASK),0);
hv_store(iso_analysis, "cdio_fs_cap_t",13, newSViv(r&~CDIO_FS_MASK),0);
hv_store(iso_analysis, "joliet_level",12, newSVuv(t.joliet_level),0);
hv_store(iso_analysis, "iso_label",9,newSVpv(t.iso_label,0),0);
hv_store(iso_analysis, "isofs_size",10, newSVuv(t.isofs_size),0);
hv_store(iso_analysis, "UDFVerMinor",11,
newSVuv((unsigned int)t.UDFVerMinor),0);
hv_store(iso_analysis, "UDFVerMajor",11,
newSVuv((unsigned int)t.UDFVerMajor),0);

return newRV_noinc(sv_2mortal((SV*)iso_analysis));
}
%}
1 change: 1 addition & 0 deletions swig/perlcdio.swg
Expand Up @@ -14,6 +14,7 @@ use this library."
#include <cdio/cdio.h>
#include <cdio/audio.h>
#include <cdio/cd_types.h>
#include <cdio/iso9660.h>
%}

#include <cdio/cdio.h>
Expand Down
12 changes: 12 additions & 0 deletions swig/read.swg
Expand Up @@ -162,3 +162,15 @@ read_data_bytes(const CdIo_t *p_cdio, lsn_t i_lsn,
return p_buf;
}
%}

iso9660_pvd_t *cdio_read_pvd ( const CdIo_t *p_cdio );
%inline %{
iso9660_pvd_t *cdio_read_pvd ( const CdIo_t *p_cdio ) {
static iso9660_pvd_t pvd;
int rc = cdio_read_data_sectors( p_cdio, &pvd, ISO_PVD_SECTOR,
ISO_BLOCKSIZE, 1);
if (rc < 0) return NULL;
return &pvd;
}
%}

0 comments on commit 39e7708

Please sign in to comment.