Add indexing

Original commit message from CVS:
Add indexing
Don't set the speed on the cdparanoia object until the open
This commit is contained in:
Iain Holmes 2003-01-01 23:57:41 +00:00
parent a650f975af
commit e666edcc9a
2 changed files with 233 additions and 161 deletions

View file

@ -159,6 +159,9 @@ static gboolean cdparanoia_query (GstPad *pad, GstQueryType type,
GstFormat *format, gint64 *value);
static const GstQueryType*
cdparanoia_get_query_types (GstPad *pad);
static void cdparanoia_set_index (GstElement *element, GstIndex *index);
static GstIndex *cdparanoia_get_index (GstElement *element);
static GstElementStateReturn cdparanoia_change_state (GstElement *element);
@ -270,6 +273,8 @@ cdparanoia_class_init (CDParanoiaClass *klass)
gobject_class->get_property = cdparanoia_get_property;
gstelement_class->change_state = cdparanoia_change_state;
gstelement_class->set_index = cdparanoia_set_index;
gstelement_class->get_index = cdparanoia_get_index;
}
static void
@ -347,7 +352,6 @@ cdparanoia_set_property (GObject *object, guint prop_id, const GValue *value, GP
break;
case ARG_READ_SPEED:
src->read_speed = g_value_get_int (value);
cdda_speed_set (src->d, src->read_speed);
break;
case ARG_TOC_OFFSET:
src->toc_offset = g_value_get_int (value);
@ -558,6 +562,34 @@ get_cddb_info (TOC *toc, gint tracks, gchar *discid, gint64 *offsets, gint64 *to
}
static void
add_index_associations (CDParanoia *src)
{
int i;
for (i = 0; i < src->d->tracks; i++) {
gint64 sector;
sector = cdda_track_firstsector (src->d, i + 1);
gst_index_add_association (src->index, src->index_id,
GST_ACCOCIATION_FLAG_KEY_UNIT,
track_format, i,
sector_format, sector,
GST_FORMAT_TIME, (gint64) (((CD_FRAMESIZE_RAW >> 2) * sector * GST_SECOND) / 44100),
GST_FORMAT_BYTES, (gint64) (sector << 2),
GST_FORMAT_UNITS, (gint64) ((CD_FRAMESIZE_RAW >> 2) * sector),
NULL);
#if 0
g_print ("Added association for track %d\n", i + 1);
g_print ("Sector: %lld\n", sector);
g_print ("Time: %lld\n", (gint64) (((CD_FRAMESIZE_RAW >> 2) * sector * GST_SECOND) / 44100));
g_print ("Bytes: %lld\n", (gint64) (sector << 2));
g_print ("Units: %lld\n", (gint64) ((CD_FRAMESIZE_RAW >> 2) * sector));
g_print ("-----------\n");
#endif
}
}
/* open the file, necessary to go to RUNNING state */
static gboolean
cdparanoia_open (CDParanoia *src)
@ -656,6 +688,10 @@ cdparanoia_open (CDParanoia *src)
GST_FLAG_SET (src, CDPARANOIA_OPEN);
if (src->index && GST_INDEX_IS_WRITABLE (src->index)) {
add_index_associations (src);
}
GST_DEBUG_LEAVE ("");
return TRUE;
@ -744,8 +780,10 @@ cdparanoia_event (GstPad *pad, GstEvent *event)
src = CDPARANOIA (gst_pad_get_parent (pad));
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN))
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN)) {
g_print ("Not open\n");
goto error;
}
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_SEEK:
@ -809,9 +847,10 @@ cdparanoia_event (GstPad *pad, GstEvent *event)
src->segment_start_sector = seg_start_sector;;
src->cur_sector = src->segment_start_sector;
}
else
else {
goto error;
}
}
if (seg_end_sector != -1) {
seg_end_sector = CLAMP (seg_end_sector,
src->first_sector, src->last_sector);
@ -862,8 +901,9 @@ cdparanoia_convert (GstPad *pad,
src = CDPARANOIA (gst_pad_get_parent (pad));
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN))
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN)) {
return FALSE;
}
switch (src_format) {
case GST_FORMAT_TIME:
@ -929,8 +969,9 @@ cdparanoia_convert (GstPad *pad,
else if (src_format == sector_format) {
sector = src_value;
}
else
else {
return FALSE;
}
switch (*dest_format) {
case GST_FORMAT_TIME:
@ -952,8 +993,9 @@ cdparanoia_convert (GstPad *pad,
else
*dest_value = cdda_sector_gettrack (src->d, sector) - 1;
}
else
else {
return FALSE;
}
break;
}
break;
@ -985,8 +1027,9 @@ cdparanoia_query (GstPad *pad, GstQueryType type,
src = CDPARANOIA (gst_pad_get_parent (pad));
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN))
if (!GST_FLAG_IS_SET (src, CDPARANOIA_OPEN)) {
return FALSE;
}
switch (type) {
case GST_QUERY_TOTAL:
@ -1019,6 +1062,31 @@ cdparanoia_query (GstPad *pad, GstQueryType type,
return res;
}
static void
cdparanoia_set_index (GstElement *element,
GstIndex *index)
{
CDParanoia *cdparanoia;
cdparanoia = CDPARANOIA (element);
cdparanoia->index = index;
gst_index_get_writer_id (index, GST_OBJECT (cdparanoia->srcpad),
&cdparanoia->index_id);
gst_index_add_format (index, cdparanoia->index_id, track_format);
gst_index_add_format (index, cdparanoia->index_id, sector_format);
}
static GstIndex *
cdparanoia_get_index (GstElement *element)
{
CDParanoia *cdparanoia;
cdparanoia = CDPARANOIA (element);
return cdparanoia->index;
}
static gboolean
plugin_init (GModule *module, GstPlugin *plugin)

View file

@ -72,6 +72,10 @@ struct _CDParanoia {
/* pads */
GstPad *srcpad;
/* Index */
GstIndex *index;
int index_id;
gchar *device;
gchar *generic_device;
gint default_sectors;