2002-06-11 16:29:51 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-12-02 12:09:01 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
#include "stream.h"
|
2005-11-18 15:39:25 +01:00
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_struct.h"
|
2006-11-29 16:02:45 +01:00
|
|
|
#include "libavutil/common.h"
|
2006-12-07 12:58:07 +01:00
|
|
|
#include "mpbswap.h"
|
2006-08-04 19:01:29 +02:00
|
|
|
#include "libmpdemux/demuxer.h"
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2002-07-10 10:49:42 +02:00
|
|
|
#include "cdd.h"
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2005-11-10 22:33:12 +01:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
2005-11-06 22:09:07 +01:00
|
|
|
#ifndef CD_FRAMESIZE_RAW
|
|
|
|
#define CD_FRAMESIZE_RAW CDIO_CD_FRAMESIZE_RAW
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-08-13 13:18:24 +02:00
|
|
|
extern char *cdrom_device;
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
static struct cdda_params {
|
|
|
|
int speed;
|
|
|
|
int paranoia_mode;
|
|
|
|
char* generic_dev;
|
|
|
|
int sector_size;
|
|
|
|
int search_overlap;
|
|
|
|
int toc_bias;
|
|
|
|
int toc_offset;
|
|
|
|
int no_skip;
|
|
|
|
char* device;
|
|
|
|
m_span_t span;
|
|
|
|
} cdda_dflts = {
|
|
|
|
-1,
|
2005-11-05 12:40:06 +01:00
|
|
|
0,
|
2003-04-02 21:29:26 +02:00
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2003-08-13 13:18:24 +02:00
|
|
|
NULL,
|
2003-04-02 21:29:26 +02:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ST_OFF(f) M_ST_OFF(struct cdda_params,f)
|
2007-12-02 22:37:08 +01:00
|
|
|
static const m_option_t cdda_params_fields[] = {
|
2003-04-02 21:29:26 +02:00
|
|
|
{ "speed", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL },
|
|
|
|
{ "paranoia", ST_OFF(paranoia_mode), CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL },
|
|
|
|
{ "generic-dev", ST_OFF(generic_dev), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "sector-size", ST_OFF(sector_size), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL },
|
|
|
|
{ "overlap", ST_OFF(search_overlap), CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL },
|
|
|
|
{ "toc-bias", ST_OFF(toc_bias), CONF_TYPE_INT, 0, 0, 0, NULL },
|
|
|
|
{ "toc-offset", ST_OFF(toc_offset), CONF_TYPE_INT, 0, 0, 0, NULL },
|
|
|
|
{ "noskip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 0, 1, NULL },
|
|
|
|
{ "skip", ST_OFF(no_skip), CONF_TYPE_FLAG, 0 , 1, 0, NULL },
|
|
|
|
{ "device", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "span", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def },
|
|
|
|
/// For url parsing
|
|
|
|
{ "hostname", ST_OFF(span), CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def },
|
|
|
|
{ "port", ST_OFF(speed), CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL },
|
|
|
|
{ "filename", ST_OFF(device), CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
2008-01-13 13:34:42 +01:00
|
|
|
static const struct m_struct_st stream_opts = {
|
2003-04-02 21:29:26 +02:00
|
|
|
"cdda",
|
|
|
|
sizeof(struct cdda_params),
|
|
|
|
&cdda_dflts,
|
|
|
|
cdda_params_fields
|
|
|
|
};
|
|
|
|
|
|
|
|
/// We keep these options but now they set the defaults
|
2007-12-02 22:26:23 +01:00
|
|
|
const m_option_t cdda_opts[] = {
|
2003-04-02 21:29:26 +02:00
|
|
|
{ "speed", &cdda_dflts.speed, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL },
|
|
|
|
{ "paranoia", &cdda_dflts.paranoia_mode, CONF_TYPE_INT,M_OPT_RANGE, 0, 2, NULL },
|
|
|
|
{ "generic-dev", &cdda_dflts.generic_dev, CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "sector-size", &cdda_dflts.sector_size, CONF_TYPE_INT, M_OPT_RANGE,1,100, NULL },
|
|
|
|
{ "overlap", &cdda_dflts.search_overlap, CONF_TYPE_INT, M_OPT_RANGE,0,75, NULL },
|
|
|
|
{ "toc-bias", &cdda_dflts.toc_bias, CONF_TYPE_INT, 0, 0, 0, NULL },
|
|
|
|
{ "toc-offset", &cdda_dflts.toc_offset, CONF_TYPE_INT, 0, 0, 0, NULL },
|
|
|
|
{ "noskip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 0, 1, NULL },
|
|
|
|
{ "skip", &cdda_dflts.no_skip, CONF_TYPE_FLAG, 0 , 1, 0, NULL },
|
|
|
|
{ "device", &cdda_dflts.device, CONF_TYPE_STRING, 0, 0, 0, NULL },
|
|
|
|
{ "span", &cdda_dflts.span, CONF_TYPE_OBJ_PARAMS, 0, 0, 0, &m_span_params_def },
|
2002-06-11 16:29:51 +02:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
2008-12-04 00:01:03 +01:00
|
|
|
int cdd_identify(const char *dev);
|
|
|
|
int cddb_resolve(const char *dev, char **xmcd_file);
|
|
|
|
cd_info_t* cddb_parse_xmcd(char *xmcd_file);
|
2003-04-02 21:29:26 +02:00
|
|
|
|
|
|
|
static int seek(stream_t* s,off_t pos);
|
|
|
|
static int fill_buffer(stream_t* s, char* buffer, int max_len);
|
2005-11-06 18:42:20 +01:00
|
|
|
static void close_cdda(stream_t* s);
|
2003-04-02 21:29:26 +02:00
|
|
|
|
2007-12-17 16:20:28 +01:00
|
|
|
static int get_track_by_sector(cdda_priv *p, unsigned int sector) {
|
|
|
|
int i;
|
|
|
|
for (i = p->cd->tracks; i >= 0 ; --i)
|
|
|
|
if (p->cd->disc_toc[i].dwStartSector <= sector)
|
|
|
|
break;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(stream_t *stream, int cmd, void *arg) {
|
|
|
|
cdda_priv* p = stream->priv;
|
|
|
|
switch(cmd) {
|
|
|
|
case STREAM_CTRL_GET_NUM_CHAPTERS:
|
|
|
|
{
|
|
|
|
int start_track = get_track_by_sector(p, p->start_sector);
|
|
|
|
int end_track = get_track_by_sector(p, p->end_sector);
|
|
|
|
*(unsigned int *)arg = end_track + 1 - start_track;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_SEEK_TO_CHAPTER:
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
unsigned int track = *(unsigned int *)arg;
|
|
|
|
int start_track = get_track_by_sector(p, p->start_sector);
|
|
|
|
int seek_sector;
|
|
|
|
track += start_track;
|
|
|
|
if (track >= p->cd->tracks) {
|
|
|
|
stream->eof = 1;
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
seek_sector = track <= 0 ? p->start_sector
|
|
|
|
: p->cd->disc_toc[track].dwStartSector;
|
|
|
|
r = seek(stream, seek_sector * CD_FRAMESIZE_RAW);
|
|
|
|
if (r)
|
|
|
|
return STREAM_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case STREAM_CTRL_GET_CURRENT_CHAPTER:
|
|
|
|
{
|
|
|
|
int start_track = get_track_by_sector(p, p->start_sector);
|
|
|
|
int cur_track = get_track_by_sector(p, p->sector);
|
|
|
|
*(unsigned int *)arg = cur_track - start_track;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
static int open_cdda(stream_t *st,int m, void* opts, int* file_format) {
|
|
|
|
struct cdda_params* p = (struct cdda_params*)opts;
|
|
|
|
int mode = p->paranoia_mode;
|
|
|
|
int offset = p->toc_offset;
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifndef CONFIG_LIBCDIO
|
2002-06-11 16:29:51 +02:00
|
|
|
cdrom_drive* cdd = NULL;
|
2005-11-06 18:42:20 +01:00
|
|
|
#else
|
|
|
|
cdrom_drive_t* cdd = NULL;
|
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
cdda_priv* priv;
|
2003-04-02 21:29:26 +02:00
|
|
|
cd_info_t *cd_info,*cddb_info = NULL;
|
2002-07-10 10:49:42 +02:00
|
|
|
unsigned int audiolen=0;
|
2005-11-06 15:17:51 +01:00
|
|
|
int last_track;
|
2002-07-10 10:49:42 +02:00
|
|
|
int i;
|
2003-04-02 21:29:26 +02:00
|
|
|
char *xmcd_file = NULL;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(m != STREAM_READ) {
|
|
|
|
m_struct_free(&stream_opts,opts);
|
2007-08-29 00:38:45 +02:00
|
|
|
return STREAM_UNSUPPORTED;
|
2003-04-02 21:29:26 +02:00
|
|
|
}
|
|
|
|
|
2003-08-13 13:18:24 +02:00
|
|
|
if(!p->device) {
|
|
|
|
if (cdrom_device)
|
|
|
|
p->device = strdup(cdrom_device);
|
|
|
|
else
|
|
|
|
p->device = strdup(DEFAULT_CDROM_DEVICE);
|
|
|
|
}
|
|
|
|
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifdef CONFIG_CDDB
|
2005-09-19 20:22:09 +02:00
|
|
|
// cdd_identify returns -1 if it cannot read the TOC,
|
|
|
|
// in which case there is no point in calling cddb_resolve
|
|
|
|
if(cdd_identify(p->device) >= 0 && strncmp(st->url,"cddb",4) == 0) {
|
2003-04-02 21:29:26 +02:00
|
|
|
i = cddb_resolve(p->device, &xmcd_file);
|
|
|
|
if(i == 0) {
|
|
|
|
cddb_info = cddb_parse_xmcd(xmcd_file);
|
|
|
|
free(xmcd_file);
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
}
|
2003-04-02 21:29:26 +02:00
|
|
|
#endif
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifndef CONFIG_LIBCDIO
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->generic_dev)
|
|
|
|
cdd = cdda_identify_scsi(p->generic_dev,p->device,0,NULL);
|
2002-06-11 16:29:51 +02:00
|
|
|
else
|
2005-11-06 18:42:20 +01:00
|
|
|
#endif
|
2003-01-15 18:50:21 +01:00
|
|
|
#if defined(__NetBSD__)
|
2003-04-02 21:29:26 +02:00
|
|
|
cdd = cdda_identify_scsi(p->device,p->device,0,NULL);
|
2003-01-15 18:50:21 +01:00
|
|
|
#else
|
2003-04-02 21:29:26 +02:00
|
|
|
cdd = cdda_identify(p->device,0,NULL);
|
2003-01-15 18:50:21 +01:00
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
|
|
|
|
if(!cdd) {
|
2005-11-10 22:33:12 +01:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_MPDEMUX_CDDA_CantOpenCDDADevice);
|
2003-04-02 21:29:26 +02:00
|
|
|
m_struct_free(&stream_opts,opts);
|
2006-04-23 17:14:03 +02:00
|
|
|
free(cddb_info);
|
2003-04-02 21:29:26 +02:00
|
|
|
return STREAM_ERROR;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cdda_verbose_set(cdd, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->sector_size) {
|
|
|
|
cdd->nsectors = p->sector_size;
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifndef CONFIG_LIBCDIO
|
2003-04-02 21:29:26 +02:00
|
|
|
cdd->bigbuff = p->sector_size * CD_FRAMESIZE_RAW;
|
2005-11-06 18:42:20 +01:00
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(cdda_open(cdd) != 0) {
|
2005-11-10 22:33:12 +01:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_ERR,MSGTR_MPDEMUX_CDDA_CantOpenDisc);
|
2002-06-11 16:29:51 +02:00
|
|
|
cdda_close(cdd);
|
2003-04-02 21:29:26 +02:00
|
|
|
m_struct_free(&stream_opts,opts);
|
2006-04-23 17:14:03 +02:00
|
|
|
free(cddb_info);
|
2003-04-02 21:29:26 +02:00
|
|
|
return STREAM_ERROR;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2002-07-10 10:49:42 +02:00
|
|
|
cd_info = cd_info_new();
|
2005-11-10 22:33:12 +01:00
|
|
|
mp_msg(MSGT_OPEN,MSGL_INFO,MSGTR_MPDEMUX_CDDA_AudioCDFoundWithNTracks,cdda_tracks(cdd));
|
2002-07-10 10:49:42 +02:00
|
|
|
for(i=0;i<cdd->tracks;i++) {
|
|
|
|
char track_name[80];
|
|
|
|
long sec=cdda_track_firstsector(cdd,i+1);
|
|
|
|
long off=cdda_track_lastsector(cdd,i+1)-sec+1;
|
|
|
|
|
|
|
|
sprintf(track_name, "Track %d", i+1);
|
|
|
|
cd_info_add_track(cd_info, track_name, i+1, (unsigned int)(off/(60*75)), (unsigned int)((off/75)%60), (unsigned int)(off%75), sec, off );
|
|
|
|
audiolen += off;
|
|
|
|
}
|
|
|
|
cd_info->min = (unsigned int)(audiolen/(60*75));
|
|
|
|
cd_info->sec = (unsigned int)((audiolen/75)%60);
|
|
|
|
cd_info->msec = (unsigned int)(audiolen%75);
|
|
|
|
|
2006-07-13 18:41:13 +02:00
|
|
|
priv = malloc(sizeof(cdda_priv));
|
2002-07-10 10:49:42 +02:00
|
|
|
memset(priv, 0, sizeof(cdda_priv));
|
2002-06-11 16:29:51 +02:00
|
|
|
priv->cd = cdd;
|
2002-07-10 10:49:42 +02:00
|
|
|
priv->cd_info = cd_info;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->toc_bias)
|
2002-06-11 16:29:51 +02:00
|
|
|
offset -= cdda_track_firstsector(cdd,1);
|
|
|
|
|
|
|
|
if(offset) {
|
|
|
|
int i;
|
|
|
|
for(i = 0 ; i < cdd->tracks + 1 ; i++)
|
|
|
|
cdd->disc_toc[i].dwStartSector += offset;
|
|
|
|
}
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->speed)
|
|
|
|
cdda_speed_set(cdd,p->speed);
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2005-11-06 15:17:51 +01:00
|
|
|
last_track = cdda_tracks(cdd);
|
|
|
|
if (p->span.start > last_track) p->span.start = last_track;
|
|
|
|
if (p->span.end < p->span.start) p->span.end = p->span.start;
|
|
|
|
if (p->span.end > last_track) p->span.end = last_track;
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->span.start)
|
|
|
|
priv->start_sector = cdda_track_firstsector(cdd,p->span.start);
|
2002-06-11 16:29:51 +02:00
|
|
|
else
|
|
|
|
priv->start_sector = cdda_disc_firstsector(cdd);
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->span.end) {
|
|
|
|
priv->end_sector = cdda_track_lastsector(cdd,p->span.end);
|
2002-06-11 16:29:51 +02:00
|
|
|
} else
|
|
|
|
priv->end_sector = cdda_disc_lastsector(cdd);
|
|
|
|
|
|
|
|
priv->cdp = paranoia_init(cdd);
|
|
|
|
if(priv->cdp == NULL) {
|
|
|
|
cdda_close(cdd);
|
|
|
|
free(priv);
|
2003-04-02 21:29:26 +02:00
|
|
|
cd_info_free(cd_info);
|
|
|
|
m_struct_free(&stream_opts,opts);
|
2006-04-23 17:14:03 +02:00
|
|
|
free(cddb_info);
|
2003-04-02 21:29:26 +02:00
|
|
|
return STREAM_ERROR;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode == 0)
|
|
|
|
mode = PARANOIA_MODE_DISABLE;
|
|
|
|
else if(mode == 1)
|
|
|
|
mode = PARANOIA_MODE_OVERLAP;
|
|
|
|
else
|
|
|
|
mode = PARANOIA_MODE_FULL;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->no_skip)
|
2002-06-11 16:29:51 +02:00
|
|
|
mode |= PARANOIA_MODE_NEVERSKIP;
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifndef CONFIG_LIBCDIO
|
2005-10-02 18:30:01 +02:00
|
|
|
paranoia_modeset(cdd, mode);
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
if(p->search_overlap >= 0)
|
|
|
|
paranoia_overlapset(cdd,p->search_overlap);
|
2005-11-06 18:42:20 +01:00
|
|
|
#else
|
|
|
|
paranoia_modeset(priv->cdp, mode);
|
|
|
|
|
|
|
|
if(p->search_overlap >= 0)
|
|
|
|
paranoia_overlapset(priv->cdp,p->search_overlap);
|
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
|
|
|
|
paranoia_seek(priv->cdp,priv->start_sector,SEEK_SET);
|
|
|
|
priv->sector = priv->start_sector;
|
|
|
|
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifdef CONFIG_CDDB
|
2003-04-02 21:29:26 +02:00
|
|
|
if(cddb_info) {
|
|
|
|
cd_info_free(cd_info);
|
|
|
|
priv->cd_info = cddb_info;
|
|
|
|
cd_info_debug( cddb_info );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
st->priv = priv;
|
|
|
|
st->start_pos = priv->start_sector*CD_FRAMESIZE_RAW;
|
2007-12-15 16:38:38 +01:00
|
|
|
st->end_pos = (priv->end_sector + 1) * CD_FRAMESIZE_RAW;
|
2003-04-02 21:29:26 +02:00
|
|
|
st->type = STREAMTYPE_CDDA;
|
|
|
|
st->sector_size = CD_FRAMESIZE_RAW;
|
|
|
|
|
|
|
|
st->fill_buffer = fill_buffer;
|
|
|
|
st->seek = seek;
|
2007-12-17 16:20:28 +01:00
|
|
|
st->control = control;
|
2005-11-06 18:42:20 +01:00
|
|
|
st->close = close_cdda;
|
2003-04-02 21:29:26 +02:00
|
|
|
|
|
|
|
*file_format = DEMUXER_TYPE_RAWAUDIO;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
m_struct_free(&stream_opts,opts);
|
|
|
|
|
|
|
|
return STREAM_OK;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifndef CONFIG_LIBCDIO
|
2002-06-11 16:29:51 +02:00
|
|
|
static void cdparanoia_callback(long inpos, int function) {
|
2005-11-06 18:42:20 +01:00
|
|
|
#else
|
|
|
|
static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function) {
|
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
static int fill_buffer(stream_t* s, char* buffer, int max_len) {
|
2002-06-11 16:29:51 +02:00
|
|
|
cdda_priv* p = (cdda_priv*)s->priv;
|
2002-07-10 10:49:42 +02:00
|
|
|
cd_track_t *cd_track;
|
2002-06-11 16:29:51 +02:00
|
|
|
int16_t * buf;
|
2003-04-02 21:29:26 +02:00
|
|
|
int i;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2007-12-15 16:38:38 +01:00
|
|
|
if((p->sector < p->start_sector) || (p->sector > p->end_sector)) {
|
|
|
|
s->eof = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
buf = paranoia_read(p->cdp,cdparanoia_callback);
|
2006-10-13 21:07:11 +02:00
|
|
|
if (!buf)
|
|
|
|
return 0;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2009-07-26 21:53:00 +02:00
|
|
|
#if HAVE_BIGENDIAN
|
2003-12-16 08:35:04 +01:00
|
|
|
for(i=0;i<CD_FRAMESIZE_RAW/2;i++)
|
|
|
|
buf[i]=le2me_16(buf[i]);
|
|
|
|
#endif
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
p->sector++;
|
2003-04-02 21:29:26 +02:00
|
|
|
memcpy(buffer,buf,CD_FRAMESIZE_RAW);
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2002-07-10 10:49:42 +02:00
|
|
|
for(i=0;i<p->cd->tracks;i++){
|
|
|
|
if(p->cd->disc_toc[i].dwStartSector==p->sector-1) {
|
|
|
|
cd_track = cd_info_get_track(p->cd_info, i+1);
|
|
|
|
//printf("Track %d, sector=%d\n", i, p->sector-1);
|
|
|
|
if( cd_track!=NULL ) {
|
2009-05-13 04:58:57 +02:00
|
|
|
mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
|
2006-04-24 09:20:34 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb);
|
2002-07-10 10:49:42 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
return CD_FRAMESIZE_RAW;
|
|
|
|
}
|
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
static int seek(stream_t* s,off_t newpos) {
|
2002-06-11 16:29:51 +02:00
|
|
|
cdda_priv* p = (cdda_priv*)s->priv;
|
2002-07-10 10:49:42 +02:00
|
|
|
cd_track_t *cd_track;
|
|
|
|
int sec;
|
|
|
|
int current_track=0, seeked_track=0;
|
2007-12-14 16:39:46 +01:00
|
|
|
int seek_to_track = 0;
|
2002-07-10 10:49:42 +02:00
|
|
|
int i;
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2003-04-02 21:29:26 +02:00
|
|
|
s->pos = newpos;
|
2007-12-14 09:26:06 +01:00
|
|
|
sec = s->pos/CD_FRAMESIZE_RAW;
|
2007-12-15 16:38:38 +01:00
|
|
|
if (s->pos < 0 || sec > p->end_sector) {
|
2003-03-22 22:14:51 +01:00
|
|
|
s->eof = 1;
|
2003-04-02 21:29:26 +02:00
|
|
|
return 0;
|
2003-03-22 22:14:51 +01:00
|
|
|
}
|
2002-07-10 10:49:42 +02:00
|
|
|
|
2002-12-22 18:22:48 +01:00
|
|
|
//printf("pos: %d, sec: %d ## %d\n", (int)s->pos, (int)sec, CD_FRAMESIZE_RAW);
|
|
|
|
//printf("sector: %d new: %d\n", p->sector, sec );
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2002-07-10 10:49:42 +02:00
|
|
|
for(i=0;i<p->cd->tracks;i++){
|
2002-12-24 23:13:32 +01:00
|
|
|
// printf("trk #%d: %d .. %d\n",i,p->cd->disc_toc[i].dwStartSector,p->cd->disc_toc[i+1].dwStartSector);
|
2002-12-22 18:22:48 +01:00
|
|
|
if( p->sector>=p->cd->disc_toc[i].dwStartSector && p->sector<p->cd->disc_toc[i+1].dwStartSector ) {
|
2002-07-10 10:49:42 +02:00
|
|
|
current_track = i;
|
|
|
|
}
|
2002-12-22 18:22:48 +01:00
|
|
|
if( sec>=p->cd->disc_toc[i].dwStartSector && sec<p->cd->disc_toc[i+1].dwStartSector ) {
|
2002-07-10 10:49:42 +02:00
|
|
|
seeked_track = i;
|
2007-12-14 16:39:46 +01:00
|
|
|
seek_to_track = sec == p->cd->disc_toc[i].dwStartSector;
|
2002-07-10 10:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//printf("current: %d, seeked: %d\n", current_track, seeked_track);
|
2007-12-14 16:39:46 +01:00
|
|
|
if (current_track != seeked_track && !seek_to_track) {
|
2002-07-10 10:49:42 +02:00
|
|
|
//printf("Track %d, sector=%d\n", seeked_track, sec);
|
|
|
|
cd_track = cd_info_get_track(p->cd_info, seeked_track+1);
|
|
|
|
if( cd_track!=NULL ) {
|
2005-09-19 20:22:09 +02:00
|
|
|
mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
|
2006-04-24 09:20:34 +02:00
|
|
|
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n", cd_track->track_nb);
|
2002-07-10 10:49:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-12-22 18:22:48 +01:00
|
|
|
#if 0
|
2002-06-11 16:29:51 +02:00
|
|
|
if(sec < p->start_sector)
|
|
|
|
sec = p->start_sector;
|
|
|
|
else if(sec > p->end_sector)
|
|
|
|
sec = p->end_sector;
|
2002-12-22 18:22:48 +01:00
|
|
|
#endif
|
2002-06-11 16:29:51 +02:00
|
|
|
|
|
|
|
p->sector = sec;
|
2002-07-10 10:49:42 +02:00
|
|
|
// s->pos = sec*CD_FRAMESIZE_RAW;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2002-12-22 18:22:48 +01:00
|
|
|
//printf("seek: %d, sec: %d\n", (int)s->pos, sec);
|
2002-06-11 16:29:51 +02:00
|
|
|
paranoia_seek(p->cdp,sec,SEEK_SET);
|
2003-04-02 21:29:26 +02:00
|
|
|
return 1;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2005-11-06 18:42:20 +01:00
|
|
|
static void close_cdda(stream_t* s) {
|
2002-06-11 16:29:51 +02:00
|
|
|
cdda_priv* p = (cdda_priv*)s->priv;
|
|
|
|
paranoia_free(p->cdp);
|
|
|
|
cdda_close(p->cd);
|
2003-04-02 21:29:26 +02:00
|
|
|
cd_info_free(p->cd_info);
|
|
|
|
free(p);
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2007-12-02 14:22:53 +01:00
|
|
|
const stream_info_t stream_info_cdda = {
|
2003-04-02 21:29:26 +02:00
|
|
|
"CDDA",
|
|
|
|
"cdda",
|
|
|
|
"Albeu",
|
|
|
|
"",
|
|
|
|
open_cdda,
|
2006-12-04 21:20:32 +01:00
|
|
|
{ "cdda",
|
2008-08-07 10:58:07 +02:00
|
|
|
#ifdef CONFIG_CDDB
|
2006-12-04 21:20:32 +01:00
|
|
|
"cddb",
|
|
|
|
#endif
|
|
|
|
NULL },
|
2003-04-02 21:29:26 +02:00
|
|
|
&stream_opts,
|
|
|
|
1 // Urls are an option string
|
|
|
|
};
|