2004-04-23 01:01:35 +00:00
|
|
|
/*
|
2004-07-13 04:33:05 +00:00
|
|
|
$Id: image_common.h,v 1.11 2004/07/13 04:33:07 rocky Exp $
|
2004-04-23 01:01:35 +00:00
|
|
|
|
|
|
|
|
Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
/*! Common image routines.
|
|
|
|
|
|
|
|
|
|
Because _img_private_t may vary over image formats, the routines are
|
|
|
|
|
included into the image drivers after _img_private_t is defined. In
|
|
|
|
|
order for the below routines to work, there is a large part of
|
|
|
|
|
_img_private_t that is common among image drivers. For example, see
|
|
|
|
|
image.h
|
|
|
|
|
*/
|
2004-04-23 01:01:35 +00:00
|
|
|
|
2004-07-10 02:17:57 +00:00
|
|
|
#ifndef __CDIO_IMAGE_COMMON_H__
|
|
|
|
|
#define __CDIO_IMAGE_COMMON_H__
|
|
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
#define free_if_notnull(obj) \
|
|
|
|
|
if (NULL != obj) { free(obj); obj=NULL; };
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
We don't need the image any more. Free all memory associated with
|
|
|
|
|
it.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
_free_image (void *user_data)
|
|
|
|
|
{
|
2004-07-11 14:25:07 +00:00
|
|
|
_img_private_t *env = user_data;
|
2004-07-10 11:06:00 +00:00
|
|
|
track_t i_track;
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
if (NULL == env) return;
|
2004-07-10 11:06:00 +00:00
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
for (i_track=0; i_track < env->i_tracks; i_track++) {
|
|
|
|
|
free_if_notnull(env->tocent[i_track].filename);
|
|
|
|
|
free_if_notnull(env->tocent[i_track].isrc);
|
|
|
|
|
cdtext_destroy(&(env->tocent[i_track].cdtext));
|
2004-07-10 11:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
free_if_notnull(env->psz_mcn);
|
|
|
|
|
free_if_notnull(env->psz_cue_name);
|
|
|
|
|
cdtext_destroy(&(env->cdtext));
|
|
|
|
|
cdio_generic_stdio_free(env);
|
|
|
|
|
free(env);
|
2004-07-10 11:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
#ifdef NEED_MEDIA_EJECT_IMAGE
|
2004-07-10 11:06:00 +00:00
|
|
|
/*!
|
|
|
|
|
Eject media -- there's nothing to do here except free resources.
|
|
|
|
|
We always return 2.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
_eject_media_image(void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_free_image (user_data);
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
2004-07-11 14:25:07 +00:00
|
|
|
#endif
|
2004-07-10 11:06:00 +00:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Return the value associated with the key "arg".
|
|
|
|
|
*/
|
|
|
|
|
static const char *
|
|
|
|
|
_get_arg_image (void *user_data, const char key[])
|
|
|
|
|
{
|
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source")) {
|
|
|
|
|
return env->gen.source_name;
|
|
|
|
|
} else if (!strcmp (key, "cue")) {
|
|
|
|
|
return env->psz_cue_name;
|
|
|
|
|
} else if (!strcmp(key, "access-mode")) {
|
|
|
|
|
return "image";
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
/*!
|
2004-07-13 04:33:05 +00:00
|
|
|
Return the CD-TEXT structure
|
2004-07-11 14:25:07 +00:00
|
|
|
*/
|
|
|
|
|
static const cdtext_t *
|
2004-07-13 03:45:15 +00:00
|
|
|
_get_cdtext_image (void *user_data)
|
2004-07-11 14:25:07 +00:00
|
|
|
{
|
|
|
|
|
const _img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
if (NULL == env) return NULL;
|
|
|
|
|
return &(env->cdtext);
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-23 01:01:35 +00:00
|
|
|
/*!
|
|
|
|
|
Return the media catalog number (MCN) from the CD or NULL if there
|
|
|
|
|
is none or we don't have the ability to get it.
|
|
|
|
|
|
|
|
|
|
Note: string is malloc'd so caller has to free() the returned
|
|
|
|
|
string when done with it.
|
|
|
|
|
*/
|
|
|
|
|
static char *
|
2004-06-02 00:43:53 +00:00
|
|
|
_get_mcn_image(const void *user_data)
|
2004-04-23 01:01:35 +00:00
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
const _img_private_t *env = user_data;
|
2004-04-23 01:01:35 +00:00
|
|
|
|
2004-07-11 14:25:07 +00:00
|
|
|
if (NULL == env || NULL == env->psz_mcn) return NULL;
|
2004-07-09 02:46:42 +00:00
|
|
|
return strdup(env->psz_mcn);
|
2004-04-23 01:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Return the starting MSF (minutes/secs/frames) for the track number
|
|
|
|
|
track_num in obj. Tracks numbers start at 1.
|
|
|
|
|
The "leadout" track is specified either by
|
|
|
|
|
using track_num LEADOUT_TRACK or the total tracks+1.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
static bool
|
2004-06-02 00:43:53 +00:00
|
|
|
_get_track_msf_image(void *user_data, track_t track_num, msf_t *msf)
|
2004-04-23 01:01:35 +00:00
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
_img_private_t *env = user_data;
|
2004-04-23 01:01:35 +00:00
|
|
|
|
|
|
|
|
if (NULL == msf) return false;
|
|
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
if (track_num == CDIO_CDROM_LEADOUT_TRACK) track_num = env->i_tracks+1;
|
2004-04-23 01:01:35 +00:00
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
if (track_num <= env->i_tracks+1 && track_num != 0) {
|
|
|
|
|
*msf = env->tocent[track_num-env->i_first_track].start_msf;
|
2004-04-23 01:01:35 +00:00
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Return the number of of the first track.
|
|
|
|
|
CDIO_INVALID_TRACK is returned on error.
|
|
|
|
|
*/
|
|
|
|
|
static track_t
|
2004-06-02 00:43:53 +00:00
|
|
|
_get_first_track_num_image(void *user_data)
|
2004-04-23 01:01:35 +00:00
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
_img_private_t *env = user_data;
|
2004-04-23 01:01:35 +00:00
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
return env->i_first_track;
|
2004-04-23 01:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2004-07-10 11:06:00 +00:00
|
|
|
Return the number of tracks.
|
2004-04-23 01:01:35 +00:00
|
|
|
*/
|
|
|
|
|
static track_t
|
2004-06-02 00:43:53 +00:00
|
|
|
_get_num_tracks_image(void *user_data)
|
2004-04-23 01:01:35 +00:00
|
|
|
{
|
2004-06-02 00:43:53 +00:00
|
|
|
_img_private_t *env = user_data;
|
2004-04-23 01:01:35 +00:00
|
|
|
|
2004-06-02 00:43:53 +00:00
|
|
|
return env->i_tracks;
|
2004-04-23 01:01:35 +00:00
|
|
|
}
|
2004-07-10 02:17:57 +00:00
|
|
|
|
2004-07-10 11:06:00 +00:00
|
|
|
/*!
|
|
|
|
|
Set the arg "key" with "value" in the source device.
|
|
|
|
|
Currently "source" to set the source device in I/O operations
|
|
|
|
|
is the only valid key.
|
|
|
|
|
|
|
|
|
|
0 is returned if no error was found, and nonzero if there as an error.
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
_set_arg_image (void *user_data, const char key[], const char value[])
|
|
|
|
|
{
|
|
|
|
|
_img_private_t *env = user_data;
|
|
|
|
|
|
|
|
|
|
if (!strcmp (key, "source"))
|
|
|
|
|
{
|
|
|
|
|
free_if_notnull (env->gen.source_name);
|
|
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
|
|
env->gen.source_name = strdup (value);
|
|
|
|
|
}
|
|
|
|
|
else if (!strcmp (key, "cue"))
|
|
|
|
|
{
|
|
|
|
|
free_if_notnull (env->psz_cue_name);
|
|
|
|
|
|
|
|
|
|
if (!value)
|
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
|
|
env->psz_cue_name = strdup (value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-10 02:17:57 +00:00
|
|
|
#endif /* __CDIO_IMAGE_COMMON_H__ */
|