Port libcdio cdda source, formerly known as cddasrc, now known as cdiocddasrc (fixes #323327). Should also read CD-TE...

Original commit message from CVS:
* configure.ac:
* ext/Makefile.am:
* ext/cdio/Makefile.am:
* ext/cdio/gstcdio.c:
* ext/cdio/gstcdio.h:
* ext/cdio/gstcdiocddasrc.c:
* ext/cdio/gstcdiocddasrc.h:
Port libcdio cdda source, formerly known as cddasrc, now known as
cdiocddasrc (fixes #323327). Should also read CD-TEXT if available,
but that's not tested (fixes #317658).
This commit is contained in:
Tim-Philipp Müller 2006-01-18 19:30:36 +00:00
parent 33a5dff9bb
commit 16333549fd
5 changed files with 558 additions and 0 deletions

22
ext/cdio/Makefile.am Normal file
View file

@ -0,0 +1,22 @@
plugin_LTLIBRARIES = libgstcdio.la
libgstcdio_la_SOURCES = \
gstcdio.c \
gstcdiocddasrc.c
libgstcdio_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(CDIO_CFLAGS) \
$(GST_CFLAGS)
libgstcdio_la_LIBADD = \
$(GST_PLUGINS_BASE_LIBS) -lgstcdda-@GST_MAJORMINOR@ \
$(CDIO_LIBS)
libgstcdio_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = \
gstcdio.h \
gstcdiocddasrc.h

90
ext/cdio/gstcdio.c Normal file
View file

@ -0,0 +1,90 @@
/* GStreamer
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstcdio.h"
#include "gstcdiocddasrc.h"
#include <cdio/logging.h>
GST_DEBUG_CATEGORY (gst_cdio_debug);
#if (LIBCDIO_VERSION_NUM >= 76)
void
gst_cdio_add_cdtext_field (GstObject * src, cdtext_t * cdtext,
cdtext_field_t field, const gchar * gst_tag, GstTagList ** p_tags)
{
const gchar *txt;
txt = cdtext_get_const (cdtext, field);
if (txt == NULL || *txt == '\0') {
GST_DEBUG_OBJECT (src, "empty CD-TEXT field %u (%s)", field, gst_tag);
return;
}
/* FIXME: beautify strings (they might be all uppercase for example)? */
/* FIXME: what encoding are these strings in? Let's hope ASCII or UTF-8 */
if (!g_utf8_validate (txt, -1, NULL)) {
GST_WARNING_OBJECT (src, "CD-TEXT string is not UTF-8! (%s)", gst_tag);
return;
}
if (*p_tags == NULL)
*p_tags = gst_tag_list_new ();
gst_tag_list_add (*p_tags, GST_TAG_MERGE_REPLACE, gst_tag, txt, NULL);
GST_DEBUG_OBJECT (src, "CD-TEXT: %s = %s", gst_tag, txt);
}
#endif
static void
gst_cdio_log_handler (cdio_log_level_t level, const char *msg)
{
const gchar *level_str[] = { "DEBUG", "INFO", "WARN", "ERROR", "ASSERT" };
const gchar *s;
s = level_str[CLAMP (level, 1, G_N_ELEMENTS (level_str)) - 1];
GST_DEBUG ("CDIO-%s: %s", s, GST_STR_NULL (msg));
}
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_element_register (plugin, "cdiocddasrc", GST_RANK_PRIMARY,
GST_TYPE_CDIO_CDDA_SRC))
return FALSE;
cdio_log_set_handler (gst_cdio_log_handler);
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"cddio",
"Read audio from audio CDs",
plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)

42
ext/cdio/gstcdio.h Normal file
View file

@ -0,0 +1,42 @@
/* GStreamer
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_CDIO_H__
#define __GST_CDIO_H__
#include <gst/gstinfo.h>
GST_DEBUG_CATEGORY_EXTERN (gst_cdio_debug);
#define GST_CAT_DEFAULT gst_cdio_debug
#if (LIBCDIO_VERSION_NUM >= 76)
#include <cdio/cdtext.h>
void gst_cdio_add_cdtext_field (GstObject * src,
cdtext_t * cdtext,
cdtext_field_t field,
const gchar * gst_tag,
GstTagList ** p_tags);
#endif
#endif /* __GST_CDIO_H__ */

352
ext/cdio/gstcdiocddasrc.c Normal file
View file

@ -0,0 +1,352 @@
/* GStreamer
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstcdiocddasrc.h"
#include <gst/gst.h>
#include "gst/gst-i18n-plugin.h"
#include <sys/types.h>
#include <string.h>
#include <errno.h>
enum
{
PROP0 = 0,
PROP_READ_SPEED
};
static GstElementDetails gst_cdio_cdda_src_details = {
"CD Audio (cdda) Source",
"Source/File",
"Read audio from CD using libcdio",
"Tim-Philipp Müller <tim centricular net>",
};
GST_BOILERPLATE (GstCdioCddaSrc, gst_cdio_cdda_src, GstCddaBaseSrc,
GST_TYPE_CDDA_BASE_SRC);
static void gst_cdio_cdda_src_finalize (GObject * obj);
static void gst_cdio_cdda_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static void gst_cdio_cdda_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gchar *gst_cdio_cdda_src_get_default_device (GstCddaBaseSrc * src);
static GstBuffer *gst_cdio_cdda_src_read_sector (GstCddaBaseSrc * src,
gint sector);
static gboolean gst_cdio_cdda_src_open (GstCddaBaseSrc * src,
const gchar * device);
static void gst_cdio_cdda_src_close (GstCddaBaseSrc * src);
#define DEFAULT_READ_SPEED -1
static void
gst_cdio_cdda_src_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details (element_class, &gst_cdio_cdda_src_details);
}
static gchar *
gst_cdio_cdda_src_get_default_device (GstCddaBaseSrc * cddabasesrc)
{
GstCdioCddaSrc *src;
gchar *default_device, *ret;
src = GST_CDIO_CDDA_SRC (cddabasesrc);
/* src->cdio may be NULL here */
default_device = cdio_get_default_device (src->cdio);
ret = g_strdup (default_device);
free (default_device);
GST_LOG_OBJECT (src, "returning default device: %s", GST_STR_NULL (ret));
return ret;
}
static gchar **
gst_cdio_cdda_src_probe_devices (GstCddaBaseSrc * cddabasesrc)
{
char **devices, **ret, **d;
/* FIXME: might return the same hardware device twice, e.g.
* as /dev/cdrom and /dev/dvd - gotta do something more sophisticated */
devices = cdio_get_devices (DRIVER_DEVICE);
if (devices == NULL) {
GST_DEBUG_OBJECT (cddabasesrc, "no devices found");
return NULL;
}
if (*devices == NULL) {
GST_DEBUG_OBJECT (cddabasesrc, "no devices found");
free (devices);
return NULL;
}
ret = g_strdupv (devices);
for (d = devices; *d != NULL; ++d) {
GST_DEBUG_OBJECT (cddabasesrc, "device: %s", GST_STR_NULL (*d));
free (*d);
}
free (devices);
return ret;
}
static GstBuffer *
gst_cdio_cdda_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector)
{
GstFlowReturn flowret;
GstCdioCddaSrc *src;
GstBuffer *buf;
src = GST_CDIO_CDDA_SRC (cddabasesrc);
flowret = gst_pad_alloc_buffer (GST_BASE_SRC (src)->srcpad,
GST_BUFFER_OFFSET_NONE, CDIO_CD_FRAMESIZE_RAW,
GST_PAD_CAPS (GST_BASE_SRC (src)->srcpad), &buf);
if (flowret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (src, "gst_pad_alloc_buffer() failed! (ret=%d)", flowret);
return NULL;
}
if (cdio_read_audio_sector (src->cdio, GST_BUFFER_DATA (buf), sector) != 0) {
GST_WARNING_OBJECT (src, "read at sector %d failed!", sector);
GST_ELEMENT_ERROR (src, RESOURCE, READ,
(_("Could not read from CD.")),
("cdio_read_audio_sector at %d failed: %s", sector,
g_strerror (errno)));
gst_buffer_unref (buf);
return NULL;
}
return buf;
}
static gboolean
notcdio_track_is_audio_track (const CdIo * p_cdio, track_t i_track)
{
return (cdio_get_track_format (p_cdio, i_track) == TRACK_FORMAT_AUDIO);
}
#if (LIBCDIO_VERSION_NUM >= 76)
static GstTagList *
gst_cdio_cdda_src_get_cdtext (GstCdioCddaSrc * src, track_t i_track)
{
GstTagList *tags = NULL;
const gchar *artist;
const gchar *title;
cdtext_t *t;
t = cdio_get_cdtext (src->cdio, i_track);
if (t == NULL) {
GST_DEBUG_OBJECT (src, "no CD-TEXT for track %u", i_track);
return NULL;
}
gst_cdio_cdda_src_add_cdtext_field (src, t, CDTEXT_PERFOMER,
GST_TAG_ARTIST, &tags);
gst_cdio_cdda_src_add_cdtext_field (src, t, CDTEXT_TITLE,
GST_TAG_TITLE, &tags);
return tags;
}
#else
static GstTagList *
gst_cdio_cdda_src_get_cdtext (GstCdioCddaSrc * src, track_t i_track)
{
GST_DEBUG_OBJECT (src, "This libcdio version (%u) does not support "
"CDTEXT (want >= 76)", LIBCDIO_VERSION_NUM);
return NULL;
}
#endif
static gboolean
gst_cdio_cdda_src_open (GstCddaBaseSrc * cddabasesrc, const gchar * device)
{
GstCdioCddaSrc *src;
discmode_t discmode;
gint first_track, num_tracks, i;
src = GST_CDIO_CDDA_SRC (cddabasesrc);
g_assert (device != NULL);
g_assert (src->cdio == NULL);
GST_LOG_OBJECT (src, "trying to open device %s", device);
src->cdio = cdio_open (device, DRIVER_UNKNOWN);
if (src->cdio == NULL) {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
(_("Could not open CD device for reading.")),
("cdio_open() failed: %s", g_strerror (errno)));
return FALSE;
}
discmode = cdio_get_discmode (src->cdio);
GST_LOG_OBJECT (src, "discmode: %d", (gint) discmode);
if (discmode != CDIO_DISC_MODE_CD_DA && discmode != CDIO_DISC_MODE_CD_MIXED) {
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
(_("Disc is not an Audio CD.")), ("discmode: %d", (gint) discmode));
return FALSE;
}
first_track = cdio_get_first_track_num (src->cdio);
num_tracks = cdio_get_num_tracks (src->cdio);
if (num_tracks <= 0 || first_track < 0)
return TRUE; /* base class will generate 'has no tracks' error */
if (src->read_speed != -1) {
#if (LIBCDIO_VERSION_NUM >= 76)
cdio_set_speed (src->cdio, src->read_speed);
#else
GST_WARNING_OBJECT (src, "This libcdio version (%u) does not support "
"setting the drive reading speed (want >= 76)", LIBCDIO_VERSION_NUM);
#endif
}
GST_LOG_OBJECT (src, "%u tracks, first track: %d", num_tracks, first_track);
for (i = 0; i < num_tracks; ++i) {
GstCddaBaseSrcTrack track = { 0, };
gint len_sectors;
len_sectors = cdio_get_track_sec_count (src->cdio, i + first_track);
track.num = i + first_track;
track.is_audio = notcdio_track_is_audio_track (src->cdio, i + first_track);
/* Note: LSN/LBA confusion all around us; in any case, this does
* the right thing here (for cddb id calculations etc. as well) */
track.start = cdio_get_track_lsn (src->cdio, i + first_track);
track.end = track.start + len_sectors - 1; /* -1? */
track.tags = gst_cdio_cdda_src_get_cdtext (src, i + first_track);
gst_cdda_base_src_add_track (GST_CDDA_BASE_SRC (src), &track);
}
return TRUE;
}
static void
gst_cdio_cdda_src_close (GstCddaBaseSrc * cddabasesrc)
{
GstCdioCddaSrc *src = GST_CDIO_CDDA_SRC (cddabasesrc);
g_assert (src->cdio != NULL);
if (src->cdio) {
cdio_destroy (src->cdio);
src->cdio = NULL;
}
}
static void
gst_cdio_cdda_src_init (GstCdioCddaSrc * src, GstCdioCddaSrcClass * klass)
{
src->read_speed = DEFAULT_READ_SPEED; /* don't need atomic access here */
src->cdio = NULL;
}
static void
gst_cdio_cdda_src_finalize (GObject * obj)
{
if (G_OBJECT_CLASS (parent_class)->finalize)
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
static void
gst_cdio_cdda_src_class_init (GstCdioCddaSrcClass * klass)
{
GstCddaBaseSrcClass *cddabasesrc_class = GST_CDDA_BASE_SRC_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = gst_cdio_cdda_src_set_property;
gobject_class->get_property = gst_cdio_cdda_src_get_property;
gobject_class->finalize = gst_cdio_cdda_src_finalize;
cddabasesrc_class->open = gst_cdio_cdda_src_open;
cddabasesrc_class->close = gst_cdio_cdda_src_close;
cddabasesrc_class->read_sector = gst_cdio_cdda_src_read_sector;
cddabasesrc_class->probe_devices = gst_cdio_cdda_src_probe_devices;
cddabasesrc_class->get_default_device = gst_cdio_cdda_src_get_default_device;
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_READ_SPEED,
g_param_spec_int ("read-speed", "Read speed",
"Read from device at the specified speed (-1 = default)", -1, 100,
DEFAULT_READ_SPEED, G_PARAM_READWRITE));
}
static void
gst_cdio_cdda_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstCdioCddaSrc *src = GST_CDIO_CDDA_SRC (object);
switch (prop_id) {
case PROP_READ_SPEED:{
gint speed;
speed = g_value_get_int (value);
gst_atomic_int_set (&src->read_speed, speed);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_cdio_cdda_src_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
GstCdioCddaSrc *src = GST_CDIO_CDDA_SRC (object);
switch (prop_id) {
case PROP_READ_SPEED:{
gint speed;
speed = g_atomic_int_get (&src->read_speed);
g_value_set_int (value, speed);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

52
ext/cdio/gstcdiocddasrc.h Normal file
View file

@ -0,0 +1,52 @@
/* GStreamer
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_CDIO_CDDA_SRC_H__
#define __GST_CDIO_CDDA_SRC_H__
#include <gst/cdda/gstcddabasesrc.h>
#include <cdio/cdio.h>
#define GST_TYPE_CDIO_CDDA_SRC (gst_cdio_cdda_src_get_type ())
#define GST_CDIO_CDDA_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_CDIO_CDDA_SRC, GstCdioCddaSrc))
#define GST_CDIO_CDDA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_CDIO_CDDA_SRC, GstCdioCddaSrcClass))
#define GST_IS_CDIO_CDDA_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_CDIO_CDDA_SRC))
#define GST_IS_CDIO_CDDA_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_CDIO_CDDA_SRC))
typedef struct _GstCdioCddaSrc GstCdioCddaSrc;
typedef struct _GstCdioCddaSrcClass GstCdioCddaSrcClass;
struct _GstCdioCddaSrc
{
GstCddaBaseSrc cddabasesrc;
gint read_speed; /* ATOMIC */
CdIo *cdio; /* NULL if not open */
};
struct _GstCdioCddaSrcClass
{
GstCddaBaseSrcClass cddabasesrc_class;
};
GType gst_cdio_cdda_src_get_type ();
#endif /* __GST_CDIO_CDDA_SRC_H__ */