2006-01-18 19:30:36 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2006-02-06 11:34:23 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-cdiocddasrc
|
2011-11-12 21:06:29 +00:00
|
|
|
* @see_also: GstCdParanoiaSrc, GstAudioCdSrc
|
2006-02-06 11:34:23 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <para>
|
|
|
|
* cdiocddasrc reads and extracts raw audio from Audio CDs. It can operate
|
|
|
|
* in one of two modes:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem><para>
|
|
|
|
* treat each track as a separate stream, counting time from the start
|
|
|
|
* of the track to the end of the track and posting EOS at the end of
|
|
|
|
* a track, or
|
|
|
|
* </para></listitem>
|
|
|
|
* <listitem><para>
|
|
|
|
* treat the entire disc as one stream, counting time from the start of
|
|
|
|
* the first track to the end of the last track, posting EOS only at
|
|
|
|
* the end of the last track.
|
|
|
|
* </para></listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* With a recent-enough version of libcdio, the element will extract
|
|
|
|
* CD-TEXT if this is supported by the CD-drive and CD-TEXT information
|
|
|
|
* is available on the CD. The information will be posted on the bus in
|
|
|
|
* form of a tag message.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* When opened, the element will also calculate a CDDB disc ID and a
|
|
|
|
* MusicBrainz disc ID, which applications can use to query online
|
|
|
|
* databases for artist/title information. These disc IDs will also be
|
|
|
|
* posted on the bus as part of the tag messages.
|
|
|
|
* </para>
|
|
|
|
* <para>
|
|
|
|
* cdiocddasrc supports the GstUriHandler interface, so applications can use
|
|
|
|
* playbin with cdda://<track-number> URIs for playback (they will have
|
|
|
|
* to connect to playbin's notify::source signal and set the device on the
|
|
|
|
* cd source in the notify callback if they want to set the device property).
|
|
|
|
* Applications should use seeks in "track" format to switch between different
|
|
|
|
* tracks of the same CD (passing a new cdda:// URI to playbin involves opening
|
|
|
|
* and closing the CD device, which is much slower).
|
|
|
|
* </para>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
|
|
|
* gst-launch cdiocddasrc track=5 device=/dev/cdrom ! audioconvert ! vorbisenc ! oggmux ! filesink location=track5.ogg
|
|
|
|
* </programlisting>
|
|
|
|
* This pipeline extracts track 5 of the audio CD and encodes it into an
|
|
|
|
* Ogg/Vorbis file.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2006-01-18 19:30:36 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2006-01-19 00:10:51 +00:00
|
|
|
#include "gstcdio.h"
|
2006-01-18 19:30:36 +00:00
|
|
|
#include "gstcdiocddasrc.h"
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include "gst/gst-i18n-plugin.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2007-07-20 07:41:57 +00:00
|
|
|
#include <stdlib.h>
|
2006-01-18 19:30:36 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2007-03-02 16:08:17 +00:00
|
|
|
#define DEFAULT_READ_SPEED -1
|
|
|
|
|
2006-01-18 19:30:36 +00:00
|
|
|
enum
|
|
|
|
{
|
2007-03-02 16:08:17 +00:00
|
|
|
PROP_0 = 0,
|
2006-01-18 19:30:36 +00:00
|
|
|
PROP_READ_SPEED
|
|
|
|
};
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
G_DEFINE_TYPE (GstCdioCddaSrc, gst_cdio_cdda_src, GST_TYPE_AUDIO_CD_SRC);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
static gchar *gst_cdio_cdda_src_get_default_device (GstAudioCdSrc * src);
|
|
|
|
static GstBuffer *gst_cdio_cdda_src_read_sector (GstAudioCdSrc * src,
|
2006-01-18 19:30:36 +00:00
|
|
|
gint sector);
|
2011-11-12 21:06:29 +00:00
|
|
|
static gboolean gst_cdio_cdda_src_open (GstAudioCdSrc * src,
|
2006-01-18 19:30:36 +00:00
|
|
|
const gchar * device);
|
2011-11-12 21:06:29 +00:00
|
|
|
static void gst_cdio_cdda_src_close (GstAudioCdSrc * src);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
static gchar *
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_get_default_device (GstAudioCdSrc * audiocdsrc)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
|
|
|
GstCdioCddaSrc *src;
|
|
|
|
gchar *default_device, *ret;
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
src = GST_CDIO_CDDA_SRC (audiocdsrc);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
/* 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 **
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_probe_devices (GstAudioCdSrc * audiocdsrc)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2007-03-02 16:08:17 +00:00
|
|
|
if (devices == NULL)
|
|
|
|
goto no_devices;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2007-03-02 16:08:17 +00:00
|
|
|
if (*devices == NULL)
|
|
|
|
goto empty_devices;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
ret = g_strdupv (devices);
|
|
|
|
for (d = devices; *d != NULL; ++d) {
|
2011-11-12 21:06:29 +00:00
|
|
|
GST_DEBUG_OBJECT (audiocdsrc, "device: %s", GST_STR_NULL (*d));
|
2006-01-18 19:30:36 +00:00
|
|
|
free (*d);
|
|
|
|
}
|
|
|
|
free (devices);
|
|
|
|
|
|
|
|
return ret;
|
2007-03-02 16:08:17 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_devices:
|
|
|
|
{
|
2011-11-12 21:06:29 +00:00
|
|
|
GST_DEBUG_OBJECT (audiocdsrc, "no devices found");
|
2007-03-02 16:08:17 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
empty_devices:
|
|
|
|
{
|
2011-11-12 21:06:29 +00:00
|
|
|
GST_DEBUG_OBJECT (audiocdsrc, "empty device list found");
|
2007-03-02 16:08:17 +00:00
|
|
|
free (devices);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-01-18 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstBuffer *
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_read_sector (GstAudioCdSrc * audiocdsrc, gint sector)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
|
|
|
GstCdioCddaSrc *src;
|
2011-11-12 21:06:29 +00:00
|
|
|
guint8 *data;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
src = GST_CDIO_CDDA_SRC (audiocdsrc);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
data = g_malloc (CDIO_CD_FRAMESIZE_RAW);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
/* can't use pad_alloc because we can't return the GstFlowReturn (FIXME 0.11) */
|
|
|
|
if (cdio_read_audio_sector (src->cdio, data, sector) != 0)
|
2007-03-02 16:08:17 +00:00
|
|
|
goto read_failed;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
return gst_buffer_new_wrapped (data, CDIO_CD_FRAMESIZE_RAW);
|
2007-03-02 16:08:17 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
read_failed:
|
|
|
|
{
|
2006-01-18 19:30:36 +00:00
|
|
|
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)));
|
2011-11-12 21:06:29 +00:00
|
|
|
g_free (data);
|
2006-01-18 19:30:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_open (GstAudioCdSrc * audiocdsrc, const gchar * device)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
|
|
|
GstCdioCddaSrc *src;
|
|
|
|
discmode_t discmode;
|
|
|
|
gint first_track, num_tracks, i;
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
src = GST_CDIO_CDDA_SRC (audiocdsrc);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
g_assert (device != NULL);
|
|
|
|
g_assert (src->cdio == NULL);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (src, "trying to open device %s", device);
|
|
|
|
|
2007-03-02 16:08:17 +00:00
|
|
|
if (!(src->cdio = cdio_open (device, DRIVER_UNKNOWN)))
|
|
|
|
goto open_failed;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
discmode = cdio_get_discmode (src->cdio);
|
|
|
|
GST_LOG_OBJECT (src, "discmode: %d", (gint) discmode);
|
|
|
|
|
2007-03-02 16:08:17 +00:00
|
|
|
if (discmode != CDIO_DISC_MODE_CD_DA && discmode != CDIO_DISC_MODE_CD_MIXED)
|
|
|
|
goto not_audio;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2008-06-07 18:48:54 +00:00
|
|
|
if (src->read_speed != -1)
|
2006-01-18 19:30:36 +00:00
|
|
|
cdio_set_speed (src->cdio, src->read_speed);
|
|
|
|
|
2008-06-09 20:02:05 +00:00
|
|
|
gst_cdio_add_cdtext_album_tags (GST_OBJECT_CAST (src), src->cdio,
|
2011-11-12 21:06:29 +00:00
|
|
|
audiocdsrc->tags);
|
2008-06-09 20:02:05 +00:00
|
|
|
|
2006-01-18 19:30:36 +00:00
|
|
|
GST_LOG_OBJECT (src, "%u tracks, first track: %d", num_tracks, first_track);
|
|
|
|
|
|
|
|
for (i = 0; i < num_tracks; ++i) {
|
2011-11-12 21:06:29 +00:00
|
|
|
GstAudioCdSrcTrack track = { 0, };
|
2006-01-18 19:30:36 +00:00
|
|
|
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? */
|
2006-11-02 14:43:11 +00:00
|
|
|
track.tags = gst_cdio_get_cdtext (GST_OBJECT (src), src->cdio,
|
|
|
|
i + first_track);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_audio_cd_src_add_track (GST_AUDIO_CD_SRC (src), &track);
|
2006-01-18 19:30:36 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2007-03-02 16:08:17 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
|
|
|
(_("Could not open CD device for reading.")),
|
|
|
|
("cdio_open() failed: %s", g_strerror (errno)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
not_audio:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
|
|
|
|
(_("Disc is not an Audio CD.")), ("discmode: %d", (gint) discmode));
|
2007-03-04 17:13:19 +00:00
|
|
|
|
|
|
|
cdio_destroy (src->cdio);
|
|
|
|
src->cdio = NULL;
|
2007-03-02 16:08:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2006-01-18 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_close (GstAudioCdSrc * audiocdsrc)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
2011-11-12 21:06:29 +00:00
|
|
|
GstCdioCddaSrc *src = GST_CDIO_CDDA_SRC (audiocdsrc);
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
if (src->cdio) {
|
|
|
|
cdio_destroy (src->cdio);
|
|
|
|
src->cdio = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-12 21:06:29 +00:00
|
|
|
gst_cdio_cdda_src_init (GstCdioCddaSrc * src)
|
2006-01-18 19:30:36 +00:00
|
|
|
{
|
|
|
|
src->read_speed = DEFAULT_READ_SPEED; /* don't need atomic access here */
|
|
|
|
src->cdio = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_cdio_cdda_src_finalize (GObject * obj)
|
|
|
|
{
|
2007-03-04 17:13:19 +00:00
|
|
|
GstCdioCddaSrc *src = GST_CDIO_CDDA_SRC (obj);
|
|
|
|
|
|
|
|
if (src->cdio) {
|
|
|
|
cdio_destroy (src->cdio);
|
|
|
|
src->cdio = NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
G_OBJECT_CLASS (gst_cdio_cdda_src_parent_class)->finalize (obj);
|
2006-01-18 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_cdio_cdda_src_class_init (GstCdioCddaSrcClass * klass)
|
|
|
|
{
|
2011-11-12 21:06:29 +00:00
|
|
|
GstAudioCdSrcClass *audiocdsrc_class = GST_AUDIO_CD_SRC_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2006-01-18 19:30:36 +00:00
|
|
|
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;
|
|
|
|
|
2011-11-12 21:06:29 +00:00
|
|
|
audiocdsrc_class->open = gst_cdio_cdda_src_open;
|
|
|
|
audiocdsrc_class->close = gst_cdio_cdda_src_close;
|
|
|
|
audiocdsrc_class->read_sector = gst_cdio_cdda_src_read_sector;
|
|
|
|
audiocdsrc_class->probe_devices = gst_cdio_cdda_src_probe_devices;
|
|
|
|
audiocdsrc_class->get_default_device = gst_cdio_cdda_src_get_default_device;
|
2006-01-18 19:30:36 +00:00
|
|
|
|
|
|
|
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,
|
2010-10-19 07:06:33 +00:00
|
|
|
DEFAULT_READ_SPEED, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-11-12 21:06:29 +00:00
|
|
|
|
|
|
|
gst_element_class_set_details_simple (element_class, "CD audio source (CDDA)",
|
|
|
|
"Source/File",
|
|
|
|
"Read audio from CD using libcdio",
|
|
|
|
"Tim-Philipp Müller <tim centricular net>");
|
2006-01-18 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2008-04-17 10:24:32 +00:00
|
|
|
g_atomic_int_set (&src->read_speed, speed);
|
2006-01-18 19:30:36 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|