2010-01-30 23:26:47 +01:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
2013-07-12 22:11:08 +02:00
|
|
|
* Original author: Albeu
|
|
|
|
*
|
2010-01-30 23:26:47 +01:00
|
|
|
* MPlayer 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.
|
|
|
|
*
|
|
|
|
* MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
#include "config.h"
|
2013-01-23 22:39:24 +01:00
|
|
|
|
|
|
|
#include <cdio/cdio.h>
|
|
|
|
|
|
|
|
#if CDIO_API_VERSION < 6
|
|
|
|
#define OLD_API
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OLD_API
|
2010-06-21 12:19:01 +02:00
|
|
|
#include <cdio/cdda.h>
|
|
|
|
#include <cdio/paranoia.h>
|
2013-01-23 22:39:24 +01:00
|
|
|
#else
|
|
|
|
#include <cdio/paranoia/cdda.h>
|
|
|
|
#include <cdio/paranoia/paranoia.h>
|
|
|
|
#endif
|
2012-03-14 06:36:46 +01:00
|
|
|
|
2006-12-02 12:09:01 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-03-14 06:36:46 +01:00
|
|
|
#include <stdbool.h>
|
2012-07-31 23:37:56 +02:00
|
|
|
#include <sys/types.h>
|
2006-12-02 12:09:01 +01:00
|
|
|
|
2011-07-30 03:03:47 +02:00
|
|
|
#include "talloc.h"
|
|
|
|
|
2002-06-11 16:29:51 +02:00
|
|
|
#include "stream.h"
|
2013-12-17 02:02:25 +01:00
|
|
|
#include "options/m_option.h"
|
2006-11-29 16:02:45 +01:00
|
|
|
#include "libavutil/common.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "compat/mpbswap.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
|
|
|
|
2013-12-17 02:39:45 +01:00
|
|
|
#include "common/msg.h"
|
2005-11-10 22:33:12 +01:00
|
|
|
|
2010-06-21 12:19:01 +02:00
|
|
|
typedef struct {
|
2012-03-21 00:31:54 +01:00
|
|
|
cdrom_drive_t *cd;
|
|
|
|
cdrom_paranoia_t *cdp;
|
|
|
|
int sector;
|
|
|
|
int start_sector;
|
|
|
|
int end_sector;
|
|
|
|
cd_info_t *cd_info;
|
2010-06-21 12:19:01 +02:00
|
|
|
|
2013-08-02 17:02:34 +02:00
|
|
|
// options
|
2012-03-21 00:31:54 +01:00
|
|
|
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;
|
2013-04-21 01:43:09 +02:00
|
|
|
int span[2];
|
2013-08-02 17:02:34 +02:00
|
|
|
} cdda_priv;
|
|
|
|
|
|
|
|
static cdda_priv cdda_dflts = {
|
2012-03-21 00:31:54 +01:00
|
|
|
.search_overlap = -1,
|
2003-04-02 21:29:26 +02:00
|
|
|
};
|
|
|
|
|
2013-08-02 17:02:34 +02:00
|
|
|
#define OPT_BASE_STRUCT cdda_priv
|
2007-12-02 22:37:08 +01:00
|
|
|
static const m_option_t cdda_params_fields[] = {
|
2013-08-02 17:02:34 +02:00
|
|
|
OPT_INTPAIR("span", span, 0),
|
|
|
|
OPT_INTRANGE("speed", speed, 0, 1, 100),
|
|
|
|
OPT_STRING("device", device, 0),
|
2012-03-21 00:31:54 +01:00
|
|
|
{0}
|
2003-04-02 21:29:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// We keep these options but now they set the defaults
|
2007-12-02 22:26:23 +01:00
|
|
|
const m_option_t cdda_opts[] = {
|
2012-03-21 00:31:54 +01: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},
|
2013-04-21 01:43:09 +02:00
|
|
|
{"span", &cdda_dflts.span, CONF_TYPE_INT_PAIR, 0, 0, 0, NULL},
|
2012-03-21 00:31:54 +01:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
2002-06-11 16:29:51 +02:00
|
|
|
};
|
|
|
|
|
2012-03-14 06:36:46 +01:00
|
|
|
static const char *cdtext_name[] = {
|
2013-01-23 22:39:24 +01:00
|
|
|
#ifdef OLD_API
|
2012-03-14 06:36:46 +01:00
|
|
|
[CDTEXT_ARRANGER] = "Arranger",
|
|
|
|
[CDTEXT_COMPOSER] = "Composer",
|
|
|
|
[CDTEXT_MESSAGE] = "Message",
|
|
|
|
[CDTEXT_ISRC] = "ISRC",
|
|
|
|
[CDTEXT_PERFORMER] = "Performer",
|
|
|
|
[CDTEXT_SONGWRITER] = "Songwriter",
|
|
|
|
[CDTEXT_TITLE] = "Title",
|
|
|
|
[CDTEXT_UPC_EAN] = "UPC_EAN",
|
2013-01-23 22:39:24 +01:00
|
|
|
#else
|
|
|
|
[CDTEXT_FIELD_ARRANGER] = "Arranger",
|
|
|
|
[CDTEXT_FIELD_COMPOSER] = "Composer",
|
|
|
|
[CDTEXT_FIELD_MESSAGE] = "Message",
|
|
|
|
[CDTEXT_FIELD_ISRC] = "ISRC",
|
|
|
|
[CDTEXT_FIELD_PERFORMER] = "Performer",
|
|
|
|
[CDTEXT_FIELD_SONGWRITER] = "Songwriter",
|
|
|
|
[CDTEXT_FIELD_TITLE] = "Title",
|
|
|
|
[CDTEXT_FIELD_UPC_EAN] = "UPC_EAN",
|
|
|
|
#endif
|
2012-03-14 06:36:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool print_cdtext(stream_t *s, int track)
|
|
|
|
{
|
|
|
|
cdda_priv* p = (cdda_priv*)s->priv;
|
2013-01-23 22:39:24 +01:00
|
|
|
#ifdef OLD_API
|
2012-03-14 06:36:46 +01:00
|
|
|
cdtext_t *text = cdio_get_cdtext(p->cd->p_cdio, track);
|
2013-01-23 22:39:24 +01:00
|
|
|
#else
|
|
|
|
cdtext_t *text = cdio_get_cdtext(p->cd->p_cdio);
|
|
|
|
#endif
|
2012-03-14 06:36:46 +01:00
|
|
|
if (text) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_INFO(s, "CD-Text (%s):\n", track ? "track" : "CD");
|
2012-03-14 06:36:46 +01:00
|
|
|
for (int i = 0; i < sizeof(cdtext_name) / sizeof(cdtext_name[0]); i++) {
|
|
|
|
const char *name = cdtext_name[i];
|
2013-01-23 22:39:24 +01:00
|
|
|
#ifdef OLD_API
|
2012-03-14 06:36:46 +01:00
|
|
|
const char *value = cdtext_get_const(i, text);
|
2013-01-23 22:39:24 +01:00
|
|
|
#else
|
|
|
|
const char *value = cdtext_get_const(text, i, track);
|
|
|
|
#endif
|
2012-03-14 06:36:46 +01:00
|
|
|
if (name && value)
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_INFO(s, " %s: '%s'\n", name, value);
|
2012-03-14 06:36:46 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_track_info(stream_t *s, int track)
|
|
|
|
{
|
|
|
|
cdda_priv* p = (cdda_priv*)s->priv;
|
|
|
|
cd_track_t *cd_track = cd_info_get_track(p->cd_info, track);
|
|
|
|
if( cd_track!=NULL ) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_INFO(s, "\n%s\n", cd_track->name);
|
|
|
|
MP_INFO(s, "ID_CDDA_TRACK=%d\n",
|
2012-03-14 06:36:46 +01:00
|
|
|
cd_track->track_nb);
|
|
|
|
}
|
|
|
|
if (print_cdtext(s, track)) {
|
|
|
|
// hack for term OSD overwriting the last line of CDTEXT
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_INFO(s, "\n");
|
2012-03-14 06:36:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function)
|
|
|
|
{
|
2010-06-21 12:40:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
static int fill_buffer(stream_t *s, char *buffer, int max_len)
|
|
|
|
{
|
|
|
|
cdda_priv *p = (cdda_priv *)s->priv;
|
|
|
|
int16_t *buf;
|
|
|
|
int i;
|
2010-06-21 12:40:30 +02:00
|
|
|
|
2013-06-05 02:04:21 +02:00
|
|
|
if (max_len < CDIO_CD_FRAMESIZE_RAW)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
if ((p->sector < p->start_sector) || (p->sector > p->end_sector)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2010-06-21 12:40:30 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
buf = paranoia_read(p->cdp, cdparanoia_callback);
|
|
|
|
if (!buf)
|
|
|
|
return 0;
|
2010-06-21 12:40:30 +02:00
|
|
|
|
Remove compile time/runtime CPU detection, and drop some platforms
mplayer had three ways of enabling CPU specific assembler routines:
a) Enable them at compile time; crash if the CPU can't handle it.
b) Enable them at compile time, but let the configure script detect
your CPU. Your binary will only crash if you try to run it on a
different system that has less features than yours.
This was the default, I think.
c) Runtime detection.
The implementation of b) and c) suck. a) is not really feasible (it
sucks for users). Remove all code related to this, and use libav's CPU
detection instead. Now the configure script will always enable CPU
specific features, and disable them at runtime if libav reports them
not as available.
One implication is that now the compiler is always expected to handle
SSE (etc.) inline assembly at runtime, unless it's explicitly disabled.
Only checks for x86 CPU specific features are kept, the rest is either
unused or barely used.
Get rid of all the dump -mpcu, -march etc. flags. Trust the compiler
to select decent settings.
Get rid of support for the following operating systems:
- BSD/OS (some ancient BSD fork)
- QNX (don't care)
- BeOS (dead, Haiku support is still welcome)
- AIX (don't care)
- HP-UX (don't care)
- OS/2 (dead, actual support has been removed a while ago)
Remove the configure code for detecting the endianness. Instead, use
the standard header <endian.h>, which can be used if _GNU_SOURCE or
_BSD_SOURCE is defined. (Maybe these changes should have been in a
separate commit.)
Since this is a quite violent code removal orgy, and I'm testing only
on x86 32 bit Linux, expect regressions.
2012-07-29 17:20:57 +02:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2012-03-21 00:57:58 +01:00
|
|
|
for (i = 0; i < CDIO_CD_FRAMESIZE_RAW / 2; i++)
|
2012-03-21 00:31:54 +01:00
|
|
|
buf[i] = le2me_16(buf[i]);
|
2010-06-21 12:40:30 +02:00
|
|
|
#endif
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
p->sector++;
|
2012-03-21 00:57:58 +01:00
|
|
|
memcpy(buffer, buf, CDIO_CD_FRAMESIZE_RAW);
|
2012-03-21 00:31:54 +01:00
|
|
|
|
|
|
|
for (i = 0; i < p->cd->tracks; i++) {
|
|
|
|
if (p->cd->disc_toc[i].dwStartSector == p->sector - 1) {
|
2012-03-14 06:36:46 +01:00
|
|
|
print_track_info(s, i + 1);
|
2012-03-21 00:31:54 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 12:40:30 +02:00
|
|
|
|
2012-03-21 00:57:58 +01:00
|
|
|
return CDIO_CD_FRAMESIZE_RAW;
|
2010-06-21 12:40:30 +02:00
|
|
|
}
|
|
|
|
|
2012-11-18 20:46:12 +01:00
|
|
|
static int seek(stream_t *s, int64_t newpos)
|
2012-03-21 00:31:54 +01:00
|
|
|
{
|
|
|
|
cdda_priv *p = (cdda_priv *)s->priv;
|
|
|
|
int sec;
|
|
|
|
int current_track = 0, seeked_track = 0;
|
|
|
|
int seek_to_track = 0;
|
|
|
|
int i;
|
|
|
|
|
2013-08-22 18:23:33 +02:00
|
|
|
sec = newpos / CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
if (newpos < 0 || sec > p->end_sector) {
|
2012-03-21 00:31:54 +01:00
|
|
|
p->sector = p->end_sector + 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < p->cd->tracks; i++) {
|
|
|
|
if (p->sector >= p->cd->disc_toc[i].dwStartSector
|
|
|
|
&& p->sector < p->cd->disc_toc[i + 1].dwStartSector)
|
|
|
|
current_track = i;
|
|
|
|
if (sec >= p->cd->disc_toc[i].dwStartSector
|
|
|
|
&& sec < p->cd->disc_toc[i + 1].dwStartSector)
|
|
|
|
{
|
|
|
|
seeked_track = i;
|
|
|
|
seek_to_track = sec == p->cd->disc_toc[i].dwStartSector;
|
|
|
|
}
|
|
|
|
}
|
2012-03-14 06:36:46 +01:00
|
|
|
if (current_track != seeked_track && !seek_to_track)
|
|
|
|
print_track_info(s, seeked_track + 1);
|
2010-06-21 12:40:30 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
p->sector = sec;
|
2010-06-21 12:40:30 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
paranoia_seek(p->cdp, sec, SEEK_SET);
|
|
|
|
return 1;
|
2010-06-21 12:40:30 +02:00
|
|
|
}
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
static void close_cdda(stream_t *s)
|
|
|
|
{
|
|
|
|
cdda_priv *p = (cdda_priv *)s->priv;
|
|
|
|
paranoia_free(p->cdp);
|
|
|
|
cdda_close(p->cd);
|
|
|
|
cd_info_free(p->cd_info);
|
|
|
|
free(p);
|
2010-06-21 12:40:30 +02:00
|
|
|
}
|
2003-04-02 21:29:26 +02:00
|
|
|
|
2012-03-21 00:31:54 +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;
|
2007-12-17 16:20:28 +01:00
|
|
|
}
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
static int control(stream_t *stream, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
cdda_priv *p = stream->priv;
|
|
|
|
switch (cmd) {
|
2011-12-31 13:20:08 +01:00
|
|
|
case STREAM_CTRL_GET_NUM_TITLES:
|
|
|
|
{
|
|
|
|
*(unsigned int *)arg = p->cd->tracks;
|
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2007-12-17 16:20:28 +01:00
|
|
|
case STREAM_CTRL_GET_NUM_CHAPTERS:
|
|
|
|
{
|
2012-03-21 00:31:54 +01:00
|
|
|
int start_track = get_track_by_sector(p, p->start_sector);
|
|
|
|
int end_track = get_track_by_sector(p, p->end_sector);
|
|
|
|
if (start_track == -1 || end_track == -1)
|
|
|
|
return STREAM_ERROR;
|
|
|
|
*(unsigned int *)arg = end_track + 1 - start_track;
|
|
|
|
return STREAM_OK;
|
2007-12-17 16:20:28 +01:00
|
|
|
}
|
2014-03-25 01:24:27 +01:00
|
|
|
case STREAM_CTRL_GET_CHAPTER_TIME:
|
2007-12-17 16:20:28 +01:00
|
|
|
{
|
2014-03-25 01:24:27 +01:00
|
|
|
int track = *(double *)arg;
|
2012-03-21 00:31:54 +01:00
|
|
|
int start_track = get_track_by_sector(p, p->start_sector);
|
|
|
|
int end_track = get_track_by_sector(p, p->end_sector);
|
2014-03-25 01:24:27 +01:00
|
|
|
track += start_track + 1;
|
|
|
|
if (track > end_track)
|
2012-03-21 00:31:54 +01:00
|
|
|
return STREAM_ERROR;
|
2014-03-25 01:24:27 +01:00
|
|
|
int64_t sector = p->cd->disc_toc[track].dwStartSector;
|
2014-03-26 16:51:17 +01:00
|
|
|
int64_t pos = sector * (CDIO_CD_FRAMESIZE_RAW + 1) - 1;
|
2014-03-25 01:24:27 +01:00
|
|
|
// Assume standard audio CD: 44.1khz, 2 channels, s16 samples
|
2014-03-26 16:51:17 +01:00
|
|
|
*(double *)arg = pos / (44100.0 * 2 * 2);
|
2012-03-21 00:31:54 +01:00
|
|
|
return STREAM_OK;
|
|
|
|
}
|
2007-12-17 16:20:28 +01:00
|
|
|
}
|
2012-03-21 00:31:54 +01:00
|
|
|
return STREAM_UNSUPPORTED;
|
2007-12-17 16:20:28 +01:00
|
|
|
}
|
|
|
|
|
2013-08-02 17:02:34 +02:00
|
|
|
static int open_cdda(stream_t *st, int m)
|
2012-03-21 00:31:54 +01:00
|
|
|
{
|
2013-08-02 17:02:34 +02:00
|
|
|
cdda_priv *priv = st->priv;
|
|
|
|
cdda_priv *p = priv;
|
2012-03-21 00:31:54 +01:00
|
|
|
int mode = p->paranoia_mode;
|
|
|
|
int offset = p->toc_offset;
|
|
|
|
cdrom_drive_t *cdd = NULL;
|
2013-07-07 19:40:14 +02:00
|
|
|
cd_info_t *cd_info;
|
2012-03-21 00:31:54 +01:00
|
|
|
unsigned int audiolen = 0;
|
|
|
|
int last_track;
|
|
|
|
int i;
|
2003-04-02 21:29:26 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
if (m != STREAM_READ) {
|
|
|
|
return STREAM_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p->device) {
|
|
|
|
if (cdrom_device)
|
|
|
|
p->device = talloc_strdup(NULL, cdrom_device);
|
|
|
|
else
|
|
|
|
p->device = talloc_strdup(NULL, DEFAULT_CDROM_DEVICE);
|
|
|
|
}
|
2003-08-13 13:18:24 +02:00
|
|
|
|
2003-01-15 18:50:21 +01:00
|
|
|
#if defined(__NetBSD__)
|
2012-03-21 00:31:54 +01:00
|
|
|
cdd = cdda_identify_scsi(p->device, p->device, 0, NULL);
|
2003-01-15 18:50:21 +01:00
|
|
|
#else
|
2012-03-21 00:31:54 +01: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
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
if (!cdd) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_ERR(st, "Can't open CDDA device.\n");
|
2012-03-21 00:31:54 +01:00
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
cdda_verbose_set(cdd, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2012-03-21 00:57:58 +01:00
|
|
|
if (p->sector_size)
|
2012-03-21 00:31:54 +01:00
|
|
|
cdd->nsectors = p->sector_size;
|
|
|
|
|
|
|
|
if (cdda_open(cdd) != 0) {
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_ERR(st, "Can't open disc.\n");
|
2012-03-21 00:31:54 +01:00
|
|
|
cdda_close(cdd);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cd_info = cd_info_new();
|
2013-12-21 20:36:45 +01:00
|
|
|
MP_INFO(st, "Found audio CD with %d tracks.\n",
|
2012-03-21 00:57:58 +01:00
|
|
|
(int)cdda_tracks(cdd));
|
2012-03-21 00:31:54 +01: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);
|
|
|
|
|
|
|
|
priv = malloc(sizeof(cdda_priv));
|
|
|
|
memset(priv, 0, sizeof(cdda_priv));
|
|
|
|
priv->cd = cdd;
|
|
|
|
priv->cd_info = cd_info;
|
|
|
|
|
|
|
|
if (p->toc_bias)
|
|
|
|
offset -= cdda_track_firstsector(cdd, 1);
|
|
|
|
|
|
|
|
if (offset) {
|
2013-07-23 00:45:23 +02:00
|
|
|
for (int n = 0; n < cdd->tracks + 1; n++)
|
|
|
|
cdd->disc_toc[n].dwStartSector += offset;
|
2012-03-21 00:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p->speed > 0)
|
|
|
|
cdda_speed_set(cdd, p->speed);
|
|
|
|
|
|
|
|
last_track = cdda_tracks(cdd);
|
2013-04-21 01:43:09 +02:00
|
|
|
if (p->span[0] > last_track)
|
|
|
|
p->span[0] = last_track;
|
|
|
|
if (p->span[1] < p->span[0])
|
|
|
|
p->span[1] = p->span[0];
|
|
|
|
if (p->span[1] > last_track)
|
|
|
|
p->span[1] = last_track;
|
|
|
|
if (p->span[0])
|
|
|
|
priv->start_sector = cdda_track_firstsector(cdd, p->span[0]);
|
2012-03-21 00:31:54 +01:00
|
|
|
else
|
|
|
|
priv->start_sector = cdda_disc_firstsector(cdd);
|
|
|
|
|
2013-04-21 01:43:09 +02:00
|
|
|
if (p->span[1])
|
|
|
|
priv->end_sector = cdda_track_lastsector(cdd, p->span[1]);
|
2012-03-21 00:31:54 +01:00
|
|
|
else
|
|
|
|
priv->end_sector = cdda_disc_lastsector(cdd);
|
|
|
|
|
|
|
|
priv->cdp = paranoia_init(cdd);
|
|
|
|
if (priv->cdp == NULL) {
|
|
|
|
cdda_close(cdd);
|
|
|
|
free(priv);
|
|
|
|
cd_info_free(cd_info);
|
|
|
|
return STREAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == 0)
|
|
|
|
mode = PARANOIA_MODE_DISABLE;
|
|
|
|
else if (mode == 1)
|
|
|
|
mode = PARANOIA_MODE_OVERLAP;
|
|
|
|
else
|
|
|
|
mode = PARANOIA_MODE_FULL;
|
|
|
|
|
|
|
|
if (p->no_skip)
|
|
|
|
mode |= PARANOIA_MODE_NEVERSKIP;
|
|
|
|
else
|
|
|
|
mode &= ~PARANOIA_MODE_NEVERSKIP;
|
|
|
|
|
|
|
|
if (p->search_overlap > 0)
|
|
|
|
mode |= PARANOIA_MODE_OVERLAP;
|
|
|
|
else if (p->search_overlap == 0)
|
|
|
|
mode &= ~PARANOIA_MODE_OVERLAP;
|
|
|
|
|
|
|
|
paranoia_modeset(priv->cdp, mode);
|
2005-11-06 18:42:20 +01:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
if (p->search_overlap > 0)
|
|
|
|
paranoia_overlapset(priv->cdp, p->search_overlap);
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
paranoia_seek(priv->cdp, priv->start_sector, SEEK_SET);
|
|
|
|
priv->sector = priv->start_sector;
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
st->priv = priv;
|
2012-03-21 00:57:58 +01:00
|
|
|
st->start_pos = priv->start_sector * CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
st->end_pos = (priv->end_sector + 1) * CDIO_CD_FRAMESIZE_RAW;
|
|
|
|
st->sector_size = CDIO_CD_FRAMESIZE_RAW;
|
2003-04-02 21:29:26 +02:00
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
st->fill_buffer = fill_buffer;
|
|
|
|
st->seek = seek;
|
|
|
|
st->control = control;
|
|
|
|
st->close = close_cdda;
|
2003-04-02 21:29:26 +02:00
|
|
|
|
2013-07-11 21:10:42 +02:00
|
|
|
st->demuxer = "rawaudio";
|
2002-06-11 16:29:51 +02:00
|
|
|
|
2012-03-14 06:36:46 +01:00
|
|
|
print_cdtext(st, 0);
|
|
|
|
|
2012-03-21 00:31:54 +01:00
|
|
|
return STREAM_OK;
|
2002-06-11 16:29:51 +02:00
|
|
|
}
|
|
|
|
|
2007-12-02 14:22:53 +01:00
|
|
|
const stream_info_t stream_info_cdda = {
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 22:49:27 +02:00
|
|
|
.name = "cdda",
|
|
|
|
.open = open_cdda,
|
|
|
|
.protocols = (const char*[]){"cdda", NULL },
|
2013-08-02 17:02:34 +02:00
|
|
|
.priv_size = sizeof(cdda_priv),
|
|
|
|
.priv_defaults = &cdda_dflts,
|
|
|
|
.options = cdda_params_fields,
|
stream: fix url_options field, make protocols field not fixed length
The way the url_options field was handled was not entirely sane: it's
actually a flexible array member, so it points to garbage for streams
which do not initialize this member (it just points to the data right
after the struct, which is garbage in theory and practice). This was
not actually a problem, since the field is only used if priv_size is
set (due to how this stuff is used). But it doesn't allow setting
priv_size only, which might be useful in some cases.
Also, make the protocols array not a fixed size array. Most stream
implementations have only 1 protocol prefix, but stream_lavf.c has
over 10 (whitelists ffmpeg protocols). The high size of the fixed
size protocol array wastes space, and it is _still_ annoying to
add new prefixes to stream_lavf (have to bump the maximum length),
so make it arbitrary length.
The two changes (plus some more cosmetic changes) arte conflated into
one, because it was annoying going over all the stream implementations.
2013-08-25 22:49:27 +02:00
|
|
|
.url_options = (const char*[]){
|
|
|
|
"hostname=span",
|
|
|
|
"port=speed",
|
|
|
|
"filename=device",
|
|
|
|
NULL
|
2013-08-02 17:02:34 +02:00
|
|
|
},
|
2003-04-02 21:29:26 +02:00
|
|
|
};
|