Device...Device(3pm)
๐ฟ Device::Cdio::Device ๐ฟ
(straight from the User Contributed Perl Documentation, page Device...Device(3pm) โ yes that's really the page name bestie, don't @ me)
okay so this class is literally THE one for all the disc-and-device stuff in Cdio. drives, discs, tracks, the whole vibe. slay. let's get into it ๐
๐ธ NAME ๐ธ
Device::Cdio::Device โ the class for disc and device aspects of Cdio. that's the whole assignment. iconic. โจ
๐ SYNOPSIS ๐
use Device::Cdio::Device;
$d = Device::Cdio::Device->new(-driver_id=>$perlcdio::DRIVER_DEVICE);
$drive_name = $d->get_device();
($i_read_cap, $i_write_cap, $i_misc_cap) = $d->get_drive_cap();
$start_lsn = $d->get_first_track()->get_lsn();
$end_lsn=$d->get_disc_last_lsn();
$drc = $d->audio_play_lsn($start_lsn, $end_lsn);
($vendor, $model, $release, $drc) = $d->get_hwinfo();
like look at her go ๐ญ so much capability in so few lines.
๐ METHODS ๐
๐ฆ new
new(source, driver_id, access_mode)->$device_object
Makes you a shiny brand-new Device object. every single one of source, driver_id and access_mode can be undef โ no pressure. and ngl? it's probably best to not give an access_mode at all unless you genuinely know what you're doing. i said what i said. ๐
๐ต audio_pause
audio_pause()-> $status
Pauses the CD that's playing through the analog output. the device status gets handed back to you. ๐
๐ต audio_play_lsn
audio_play_lsn(start_lsn, end_lsn)-> $status
Plays the CD through the analog output starting at the given lsn and going all the way to the ending lsn. device status comes back. simple as. โจ
๐ต audio_resume
audio_resume()-> $status
Un-pauses โ resumes playing the audio CD through the analog interface. device status is returned. ๐ซถ
๐ต audio_stop
audio_stop()-> $status
Stops the audio CD playing through the analog interface. device status returned, as always. ๐
๐ close
close()->bool
Frees up the resources tied to cdio. call this when you're done using the CD reading/control operations for the current device โ like, actually done done, not "done but let me do one more thing" done. โจ
๐ eject_media
eject_media()->drc
Ejects the media in the CD drive if there's a routine around that can do it. status gets returned. ๐
๐ฆ get_arg
get_arg(key)->string
๐ฆ get_device
get_device()->str
Gets the default CD device.
If the CD object already has an opened CD, you get back the name of the device that was used. (fun fact: that's literally the same thing as calling d->get_arg("source").) ๐ซ
And if we haven't initialized a specific device driver yet, she'll go find a suitable one and return the default device for that.
โ ๏ธ heads up bestie: in some situations with certain drivers or OS's, we just can't find a CD device if there's no media in it โ so this routine can totally return undef even though there is a hardware CD-ROM sitting right there. it's giving "not my fault". ๐ญ
๐ get_disc_last_lsn
get_disc_last_lsn(self)->int
Grabs the LSN of the end of the CD. $perlcdio::INVALID_LSN is what you get back if something went wrong. ๐
๐ get_disc_mode
get_disc_mode() -> str
Gets the disc mode โ as in, the kind of CD we've got goin' on: CD-DA, CD-ROM mode 1, CD-MIXED, etc. and yes, the notion of "CD" is extended a little here to include DVDs too. we're inclusive in this house. ๐
๐ฅ get_drive_cap
get_drive_cap()->(read_cap, write_cap, misc_cap)
Gets the drive capabilities of the device.
โ ๏ธ and again with the caveat: in some situations of drivers or OS's we can't find a CD device if there's no media in it โ and in that situation the capabilities show up as empty even though there's a hardware CD-ROM. rude? yes. true? also yes. ๐ญ
๐ฅ get_drive_cap_dev
get_drive_cap_dev(device=undef)->(read_cap, write_cap, misc_cap)
Gets the drive capabilities of the device.
same warning, same energy: sometimes with certain drivers or OS's we can't find a CD device when there's no media in it, and then the capabilities come back empty even though a hardware CD-ROM exists. โจ
๐ธ get_driver_name
get_driver_name()-> string
Returns a string with the name of the driver currently in use. "undef" comes back if there's an error. ๐ซถ
๐ธ get_driver_id
get_driver_id()-> int
Returns the driver id of the driver in use. and if the object hasn't been initialized, or is None, you get $perlcdio::DRIVER_UNKNOWN. ๐
๐ฆ get_first_track
get_first_track()->Track
Returns a Track object for the first track. if something went sideways you'll get $perlcdio::INVALID_TRACK or $perlcdio::BAD_PARAMETER back. no cap. ๐
๐ get_hwinfo
get_hwinfo()->(vendor, model, release, drc)
Gets the CD-ROM hardware info by way of a SCSI MMC INQUIRY command. an exception is raised if we hit an error โ so like, be aware. ๐
๐ audio_get_volume
my($arr, $rc) = $dev->audio_get_volume;
Returns the volume settings of the device's 4 channels plus the device return code. in a scalar context you only get the device return code! check perlcdio::driver_errmsg($rc) to find out what the return values actually mean when "$rc != 0". ๐ง
๐ audio_play_track_index
$drc = $dev->audio_play_track_index($start_track, $start_index, $end_track, $end_track);
Plays the CD through the analog output starting at the track and index you want, running until the end track and index. tracks have to be inside the valid CD track range 0..99, so no funny business. โจ
just like a track number gets burned into the CD, so does an index for a track. ๐ฅ
see perlcdio::driver_errmsg($drc) to decode the return values when "$drc != 0". ๐
๐ audio_set_volume
$drc = $dev->audio_set_volume($channel1_volume, $channel2_volume,
$channel3_volume, $channel4_volume);
Sets the volume levels for channels 1โ4. values from 0โ255 are fair game. stereo CDROM devices (which, let's be real, is most of them) only use channels 1 and 2. ๐๏ธ
use -1 when you want the existing value kept โ it's the "no thoughts, keep as is" option. see perlcdio::driver_errmsg($drc) for what the return values mean when "$drc != 0". ๐
๐ get_disk_cdtext, get_track_cdtext
$hash = $dev->get_disk_cdtext;
$hash = $dev->get_cdtext_for_track(track, field);
$hash = $dev->get_cdtext_field_for_track(track, field);
$hash = $dev->get_cdtext_field_for_track(track, field);
Returns a hash reference hash->{cdtext_field}="text" if it found any cdtext on the disk. ๐ฆ
๐ get_disk_cdtext_field_for_track
$str = $dev->get_cdtext_field_for_track($field, $track=0, $cdtext=$self->{cdtext});
Returns the text associated with field $field of track $track of $cdtext, if there is any. ๐
๐งน cdtext_destroy
$dev->cdtext_destroy()
Removes the CD-TEXT memory resources associated with a disc and sets $dev->{cdtext} to undef. ๐งผ
Use this when you're done accessing CD-TEXT information โ clean up after yourself, bestie.
Note: $def->close() runs this as part of its operation. so it's handled for you there. โจ
๐ข get_cddb_discid
$discid = $dev->get_cddb_discid;
Returns the calculated cddb discid integer. usually it's used as a hexstring! ๐
๐ง audio_get_status
my($hash, $drc) = $dev->audio_get_status;
Returns a hash reference packed with the audio-subchannel-mmc status values: ๐
audio_statusโ valuestatus_textโaudio_statusas text (INVALID,ERROR,NO_STATUS,UNKNOWN,playing,paused,completed)trackโ track numberindexโ index in track- msf time values as ints minutes, seconds, frames:
abs_m,abs_s,abs_fโ total disc time playedrel_m,rel_s,el_fโ track time played
disk_sโ seconds disk playedtrack_sโ seconds track playedaddresscontrol
๐ช is_tray_open
$dev->is_tray_open
Returns true if the tray seems open, 0 otherwise. she's just guessing, but she's confident. ๐
๐ฆ get_joliet_level
get_joliet_level()->int
Returns the Joliet level recognized for cdio. this only makes sense for something that actually has an ISO-9660 filesystem, so don't come at her otherwise. โจ
๐ฆ get_last_session
get_last_session(self) -> (track_lsn, drc)
Gets the LSN of the first track of the last session on the CD. ๐
๐ฆ get_last_track
get_last_track()->Track
Returns a Track object for the last track. $perlcdio::INVALID_TRACK or $perlcdio::BAD_PARAMETER comes back if there was a problem. ๐
๐ฆ get_mcn
get_mcn()->str
Gets the media catalog number (MCN) off the CD. ๐ฅ
๐ฆ get_media_changed
get_media_changed() -> int
Finds out whether the media has changed since the last call. returns 1 if it has changed since the last call, 0 if it hasn't. a negative number means the driver status error. so watch the sign, bestie. ๐
๐ฎ guess_cd_type
$hash = $dev->guess_cd_type($lsn,$track);
Tries to figure out what kind of CD-image and/or filesystem we've got at track $track. the first argument is the start lsn of track $track. returns a hash reference with these keys: ๐ซ
cdio_fs_tโ (enumcdio_fs_tfrom libcdio) FIXME: add textcdio_fs_cap_tโ (enumcdio_fs_cap_tfrom libcdio) FIXME: add textjoliet_levelโ if it 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.
๐ข get_num_tracks
get_num_tracks()->int
Returns the number of tracks on the CD. $perlcdio::INVALID_TRACK gets raised on error. ๐ค
๐ฆ get_track
get_track(track_num)->track
Sets a new track object of the current disc for the track number you handed over. ๐
๐ฆ get_track_for_lsn
get_track_for_lsn(LSN)->Track
Finds the track that contains LSN. undef comes back if the lsn is outside the CD, or if something errored out. ๐
If the LSN is before the pregap of the first track, you get a track object with a 0 track. otherwise she returns the track that spans the lsn. that's the rule. โจ
๐ฆ have_ATAPI
have_ATAPI()->bool
Returns 1 if the CD-ROM understands ATAPI commands. ๐
๐ lseek
lseek(offset, whence)->int
Repositions the read offset. similar to (if not the same as) libc's fseek(). ๐ฏ
offset is how much to seek, and whence is like the corresponding parameter in libc's lseek, e.g. it should be SEEK_SET or SEEK_END.
the offset is returned โ or -1 on error. ๐
๐ open
open(source=undef, driver_id=$libcdio::DRIVER_UNKNOWN,
access_mode=undef)->$cdio_obj
Sets you up to read from the place specified by source, driver_id and the access mode. this should be called before using any other routine except the ones that act on a CD-ROM drive by name. it also gets implicitly called whenever a new is done specifying a source or driver id. so she's a lil automatic like that. โจ
If undef is given as the source, we'll use the default driver device. if undef is given as the driver_id, we'll go find a suitable device driver. the device gets opened so all your subsequent operations can actually happen. ๐ฅ
๐ read
read(size)->(size, data)
Reads the next size bytes. similar to (if not the same as) libc's read(). ๐ฆ
The number of bytes read and the data both come back to you. ๐
๐ read_data_blocks
read_data_blocks(lsn, blocks=1)->($data, $size, $drc)
Reads a number of data sectors (AKA blocks). ๐ฆ
lsn is the sector to read, blocks is the number of bytes.
The size of the data will be a multiple of $perlcdio::ISO_BLOCKSIZE. ๐
The number of data, the size of the data, and the return code status all come back in an array context. in a scalar context you just get the data. and "undef" is returned as the data on error. ๐
๐ read_sectors
read_sectors($lsn, $read_mode, $blocks=1)->($data, $size, $drc)
read_sectors($lsn, $read_mode, $blocks=1)->$data
Reads a number of sectors (AKA blocks). ๐
lsn is the sector to read, bytes is the number of bytes.
If read_mode is $perlcdio::MODE_AUDIO, the return data size will be a multiple of $perlcdio::CDIO_FRAMESIZE_RAW i_blocks bytes. ๐ต
If read_mode is $perlcdio::MODE_DATA, the data will be a multiple of $perlcdio::ISO_BLOCKSIZE, $perlcdio::M1RAW_SECTOR_SIZE or $perlcdio::M2F2_SECTOR_SIZE bytes โ depending on what mode the data is in. โจ
So like, if read_mode is $perlcdio::MODE_M2F1, bestie, your data comes back as a multiple of $perlcdio::M2RAW_SECTOR_SIZE bytes. No cap. ๐ธ
And if read_mode is $perlcdio::MODE_M2F2? Then the return data size is gonna be a multiple of $perlcdio::CD_FRAMESIZE bytes. Slay. โจ
Now the way context changes everything: in an array context you get back the number of data, the size of the data, and the return code status โ the whole trio, iconic. In a scalar context you just get the data, periodt. And on error? undef is returned as the data. ๐ญ yes it will simply hand you undef, be normal about it.
๐ set_blocksize ๐
set_blocksize(blocksize) -> $status
Sets the blocksize for all the reads that come after this. And yeah, the operation status code gets returned to you. ๐
๐ set_speed ๐
set_speed(speed)->drc
That's it, that's the whole vibe โ the operation status code is returned. Go off. โญ
๐ง read_pvd ๐ง
$pvd = $dev->read_pvd;
This one reads the ISO-9660 Primary Volume Descriptor (PVD) off the disk and hands it right back to you. Then you can use stuff like perliso9660::get_pvd_type($pvd) โฆ and the other methods to pull the values out of it. Obsessed. ๐ฆ
โจ SEE ALSO โจ
- Device::Cdio โ for the top-level module, it's giving main character ๐
- Device::Cdio::Track โ for track objects
- Device::Cdio::ISO9660 โ for when you're working with ISO9660 filesystems
perlcdioโ the lower-level interface to libcdio, iykyk<http://www.gnu.org/software/libcdio>โ this has the documentation on libcdio, including a manual and the API via doxygen. Go read it, fr fr. ๐
๐ AUTHORS ๐
Rocky Bernstein โ that's the author, bestie, respect. ๐
๐ COPYRIGHT ๐
Copyright (C) 2006, 2008, 2017 Rocky Bernstein <rocky@cpan.org>
Okay so legally speaking, 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 3 of the License, or (at your option) any later version. Pick your fighter. ๐
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY โ no, literally, not even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. That's a big deal, don't skip it. 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 The GNU General Public License at <http://www.gnu.org/licenses/#GPL>.
๐ and that's the page, babe.perl v5.42.3, dated2026-08-19, from theDevice...Device(3pm)era of the perl docs โ go forth and read those sectors, you absolute icon. ๐๐
๐ฆ where this page comes from
- ubuntu stonking: libdevice-cdio-perl 2.0.0-2build8 ยท GPL-3.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms