ext/cdio/gstcdiocddasrc.c: Small code cleanups.

Original commit message from CVS:
* ext/cdio/gstcdiocddasrc.c: (gst_cdio_cdda_src_probe_devices),
(gst_cdio_cdda_src_read_sector), (gst_cdio_cdda_src_open),
(gst_cdio_cdda_src_finalize):
Small code cleanups.
Don't use pad_alloc as the base class cannot deal with the error codes.
This commit is contained in:
Wim Taymans 2007-03-02 16:08:17 +00:00
parent 4fd7bf7a94
commit ba48ddc9a8

View file

@ -85,9 +85,11 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#define DEFAULT_READ_SPEED -1
enum enum
{ {
PROP0 = 0, PROP_0 = 0,
PROP_READ_SPEED PROP_READ_SPEED
}; };
@ -113,8 +115,6 @@ static gboolean gst_cdio_cdda_src_open (GstCddaBaseSrc * src,
const gchar * device); const gchar * device);
static void gst_cdio_cdda_src_close (GstCddaBaseSrc * src); static void gst_cdio_cdda_src_close (GstCddaBaseSrc * src);
#define DEFAULT_READ_SPEED -1
static void static void
gst_cdio_cdda_src_base_init (gpointer g_class) gst_cdio_cdda_src_base_init (gpointer g_class)
{ {
@ -151,16 +151,11 @@ gst_cdio_cdda_src_probe_devices (GstCddaBaseSrc * cddabasesrc)
* as /dev/cdrom and /dev/dvd - gotta do something more sophisticated */ * as /dev/cdrom and /dev/dvd - gotta do something more sophisticated */
devices = cdio_get_devices (DRIVER_DEVICE); devices = cdio_get_devices (DRIVER_DEVICE);
if (devices == NULL) { if (devices == NULL)
GST_DEBUG_OBJECT (cddabasesrc, "no devices found"); goto no_devices;
return NULL;
}
if (*devices == NULL) { if (*devices == NULL)
GST_DEBUG_OBJECT (cddabasesrc, "no devices found"); goto empty_devices;
free (devices);
return NULL;
}
ret = g_strdupv (devices); ret = g_strdupv (devices);
for (d = devices; *d != NULL; ++d) { for (d = devices; *d != NULL; ++d) {
@ -170,27 +165,40 @@ gst_cdio_cdda_src_probe_devices (GstCddaBaseSrc * cddabasesrc)
free (devices); free (devices);
return ret; return ret;
/* ERRORS */
no_devices:
{
GST_DEBUG_OBJECT (cddabasesrc, "no devices found");
return NULL;
}
empty_devices:
{
GST_DEBUG_OBJECT (cddabasesrc, "empty device list found");
free (devices);
return NULL;
}
} }
static GstBuffer * static GstBuffer *
gst_cdio_cdda_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector) gst_cdio_cdda_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector)
{ {
GstFlowReturn flowret;
GstCdioCddaSrc *src; GstCdioCddaSrc *src;
GstBuffer *buf; GstBuffer *buf;
src = GST_CDIO_CDDA_SRC (cddabasesrc); src = GST_CDIO_CDDA_SRC (cddabasesrc);
flowret = gst_pad_alloc_buffer (GST_BASE_SRC (src)->srcpad, /* can't use pad_alloc because we can't return the GstFlowReturn */
GST_BUFFER_OFFSET_NONE, CDIO_CD_FRAMESIZE_RAW, buf = gst_buffer_new_and_alloc (CDIO_CD_FRAMESIZE_RAW);
GST_PAD_CAPS (GST_BASE_SRC (src)->srcpad), &buf);
if (flowret != GST_FLOW_OK) { if (cdio_read_audio_sector (src->cdio, GST_BUFFER_DATA (buf), sector) != 0)
GST_DEBUG_OBJECT (src, "gst_pad_alloc_buffer() failed! (ret=%d)", flowret); goto read_failed;
return NULL;
}
if (cdio_read_audio_sector (src->cdio, GST_BUFFER_DATA (buf), sector) != 0) { return buf;
/* ERRORS */
read_failed:
{
GST_WARNING_OBJECT (src, "read at sector %d failed!", sector); GST_WARNING_OBJECT (src, "read at sector %d failed!", sector);
GST_ELEMENT_ERROR (src, RESOURCE, READ, GST_ELEMENT_ERROR (src, RESOURCE, READ,
(_("Could not read from CD.")), (_("Could not read from CD.")),
@ -199,8 +207,6 @@ gst_cdio_cdda_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector)
gst_buffer_unref (buf); gst_buffer_unref (buf);
return NULL; return NULL;
} }
return buf;
} }
static gboolean static gboolean
@ -223,23 +229,14 @@ gst_cdio_cdda_src_open (GstCddaBaseSrc * cddabasesrc, const gchar * device)
GST_LOG_OBJECT (src, "trying to open device %s", device); GST_LOG_OBJECT (src, "trying to open device %s", device);
src->cdio = cdio_open (device, DRIVER_UNKNOWN); if (!(src->cdio = cdio_open (device, DRIVER_UNKNOWN)))
goto open_failed;
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); discmode = cdio_get_discmode (src->cdio);
GST_LOG_OBJECT (src, "discmode: %d", (gint) discmode); GST_LOG_OBJECT (src, "discmode: %d", (gint) discmode);
if (discmode != CDIO_DISC_MODE_CD_DA && discmode != CDIO_DISC_MODE_CD_MIXED) { if (discmode != CDIO_DISC_MODE_CD_DA && discmode != CDIO_DISC_MODE_CD_MIXED)
GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, goto not_audio;
(_("Disc is not an Audio CD.")), ("discmode: %d", (gint) discmode));
return FALSE;
}
first_track = cdio_get_first_track_num (src->cdio); first_track = cdio_get_first_track_num (src->cdio);
num_tracks = cdio_get_num_tracks (src->cdio); num_tracks = cdio_get_num_tracks (src->cdio);
@ -276,8 +273,22 @@ gst_cdio_cdda_src_open (GstCddaBaseSrc * cddabasesrc, const gchar * device)
gst_cdda_base_src_add_track (GST_CDDA_BASE_SRC (src), &track); gst_cdda_base_src_add_track (GST_CDDA_BASE_SRC (src), &track);
} }
return TRUE; return TRUE;
/* 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));
return FALSE;
}
} }
static void static void
@ -301,8 +312,7 @@ gst_cdio_cdda_src_init (GstCdioCddaSrc * src, GstCdioCddaSrcClass * klass)
static void static void
gst_cdio_cdda_src_finalize (GObject * obj) gst_cdio_cdda_src_finalize (GObject * obj)
{ {
if (G_OBJECT_CLASS (parent_class)->finalize) G_OBJECT_CLASS (parent_class)->finalize (obj);
G_OBJECT_CLASS (parent_class)->finalize (obj);
} }
static void static void