Index: gstcddabasesrc.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/gst-libs/gst/cdda/gstcddabasesrc.c,v
retrieving revision 1.6
diff -u -3 -p -b -B -d -r1.6 gstcddabasesrc.c
--- gstcddabasesrc.c	12 Mar 2006 14:56:31 -0000	1.6
+++ gstcddabasesrc.c	2 Apr 2006 18:37:38 -0000
@@ -148,7 +148,6 @@ GST_STATIC_PAD_TEMPLATE ("src",
     );
 
 /* our two formats */
-static GstFormat track_format;
 static GstFormat sector_format;
 
 static GType
@@ -178,7 +177,6 @@ gst_cdda_base_src_base_init (gpointer g_
       gst_static_pad_template_get (&gst_cdda_base_src_src_template));
 
   /* our very own formats */
-  track_format = gst_format_register ("track", "CD track");
   sector_format = gst_format_register ("sector", "CD sector");
 
   /* tags */
@@ -417,6 +415,7 @@ gst_cdda_base_src_get_query_types (GstPa
   static const GstQueryType src_query_types[] = {
     GST_QUERY_DURATION,
     GST_QUERY_POSITION,
+    GST_QUERY_FORMATS,
     GST_QUERY_CONVERT,
     0
   };
@@ -441,7 +440,7 @@ gst_cdda_base_src_convert (GstCddaBaseSr
 
   started = GST_OBJECT_FLAG_IS_SET (GST_BASE_SRC (src), GST_BASE_SRC_STARTED);
 
-  if (src_format == track_format) {
+  if (src_format == GST_FORMAT_STREAMS) {
     if (!started)
       goto not_started;
     if (src_val < 0 || src_val >= src->num_tracks) {
@@ -484,7 +483,7 @@ gst_cdda_base_src_convert (GstCddaBaseSr
 
           if (dest_format == sector_format) {
             *dest_val = sector;
-          } else if (dest_format == track_format) {
+          } else if (dest_format == GST_FORMAT_STREAMS) {
             if (!started)
               goto not_started;
             *dest_val = gst_cdda_base_src_get_track_from_sector (src, sector);
@@ -519,7 +518,7 @@ gst_cdda_base_src_convert (GstCddaBaseSr
 
           if (dest_format == sector_format) {
             *dest_val = sector;
-          } else if (dest_format == track_format) {
+          } else if (dest_format == GST_FORMAT_STREAMS) {
             if (!started)
               goto not_started;
             *dest_val = gst_cdda_base_src_get_track_from_sector (src, sector);
@@ -568,13 +567,24 @@ gst_cdda_base_src_query (GstBaseSrc * ba
 {
   GstCddaBaseSrc *src = GST_CDDA_BASE_SRC (basesrc);
   gboolean started;
+  gint stream;
 
   started = GST_OBJECT_FLAG_IS_SET (basesrc, GST_BASE_SRC_STARTED);
 
   GST_LOG_OBJECT (src, "handling %s query",
       gst_query_type_get_name (GST_QUERY_TYPE (query)));
 
+  stream = gst_query_get_stream (query);
+  if (((src->mode == GST_CDDA_BASE_SRC_MODE_NORMAL) && (stream > 0)) ||
+      ((src->mode == GST_CDDA_BASE_SRC_MODE_CONTINUOUS) &&
+       (stream > (gint) src->num_tracks)))
+    return FALSE;
+
   switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_FORMATS:
+      gst_query_set_formats (query, 4, GST_FORMAT_BYTES, GST_FORMAT_TIME,
+          GST_FORMAT_STREAMS, sector_format);
+      break;
     case GST_QUERY_DURATION:{
       GstFormat dest_format;
       gint64 dest_val;
@@ -587,9 +597,13 @@ gst_cdda_base_src_query (GstBaseSrc * ba
 
       g_assert (src->tracks != NULL);
 
-      if (dest_format == track_format) {
+      if (dest_format == GST_FORMAT_STREAMS) {
         GST_LOG_OBJECT (src, "duration: %d tracks", src->num_tracks);
-        gst_query_set_duration (query, track_format, src->num_tracks);
+        if ((src->mode == GST_CDDA_BASE_SRC_MODE_NORMAL) || (stream >= 0))
+          dest_val = 1;
+        else
+          dest_val = src->num_tracks;
+        gst_query_set_duration (query, GST_FORMAT_STREAMS, dest_val);
         return TRUE;
       }
 
@@ -600,8 +614,11 @@ gst_cdda_base_src_query (GstBaseSrc * ba
         sectors = src->tracks[src->cur_track].end -
             src->tracks[src->cur_track].start + 1;
       } else {
+        if (stream < 0)
         sectors = src->tracks[src->num_tracks - 1].end -
             src->tracks[0].start + 1;
+        else
+          sectors = src->tracks[stream].end - src->tracks[stream].start + 1;
       }
 
       /* ... and convert into final format */
@@ -628,9 +645,13 @@ gst_cdda_base_src_query (GstBaseSrc * ba
 
       g_assert (src->tracks != NULL);
 
-      if (dest_format == track_format) {
+      if (dest_format == GST_FORMAT_STREAMS) {
         GST_LOG_OBJECT (src, "position: track %d", src->cur_track);
-        gst_query_set_position (query, track_format, src->cur_track);
+        if ((src->mode == GST_CDDA_BASE_SRC_MODE_NORMAL) || (stream >= 0))
+          dest_val = 0;
+        else
+          dest_val = src->cur_track;
+        gst_query_set_position (query, GST_FORMAT_STREAMS, src->cur_track);
         return TRUE;
       }
 
@@ -640,7 +661,10 @@ gst_cdda_base_src_query (GstBaseSrc * ba
       if (src->mode == GST_CDDA_BASE_SRC_MODE_NORMAL) {
         pos_sector = src->cur_sector - src->tracks[src->cur_track].start;
       } else {
+        if (stream < 0)
         pos_sector = src->cur_sector - src->tracks[0].start;
+        else
+          pos_sector = src->cur_sector - src->tracks[stream].start;
       }
 
       if (!gst_cdda_base_src_convert (src, sector_format, pos_sector,
@@ -690,10 +714,21 @@ gst_cdda_base_src_do_seek (GstBaseSrc * 
   GstCddaBaseSrc *src = GST_CDDA_BASE_SRC (basesrc);
   gint64 seek_sector;
 
+  switch (segment->format) {
+  case GST_FORMAT_TIME:
   GST_DEBUG_OBJECT (src, "segment %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
       GST_TIME_ARGS (segment->start), GST_TIME_ARGS (segment->stop));
+    break;
+  case GST_FORMAT_STREAMS:
+    GST_DEBUG_OBJECT (src, "segment %i-%i", segment->start, segment->stop);
+    break;
+  default:
+    GST_DEBUG_OBJECT (src, "segment of format '%s'",
+        gst_format_get_name (segment->format));
+    break;
+  }
 
-  if (!gst_cdda_base_src_convert (src, GST_FORMAT_TIME, segment->start,
+  if (!gst_cdda_base_src_convert (src, segment->format, segment->start,
           sector_format, &seek_sector)) {
     GST_WARNING_OBJECT (src, "conversion failed");
     return FALSE;
@@ -727,9 +762,9 @@ gst_cdda_base_src_handle_track_seek (Gst
 {
   GstBaseSrc *basesrc = GST_BASE_SRC (src);
   GstEvent *event;
+  gint64 start_time = -1;
 
   if ((flags & GST_SEEK_FLAG_SEGMENT) == GST_SEEK_FLAG_SEGMENT) {
-    gint64 start_time = -1;
     gint64 stop_time = -1;
 
     if (src->mode != GST_CDDA_BASE_SRC_MODE_CONTINUOUS) {
@@ -740,7 +775,7 @@ gst_cdda_base_src_handle_track_seek (Gst
 
     switch (start_type) {
       case GST_SEEK_TYPE_SET:
-        if (!gst_cdda_base_src_convert (src, track_format, start,
+        if (!gst_cdda_base_src_convert (src, GST_FORMAT_STREAMS, start,
                 GST_FORMAT_TIME, &start_time)) {
           GST_DEBUG_OBJECT (src, "cannot convert track %d to time",
               (gint) start);
@@ -748,7 +783,7 @@ gst_cdda_base_src_handle_track_seek (Gst
         }
         break;
       case GST_SEEK_TYPE_END:
-        if (!gst_cdda_base_src_convert (src, track_format,
+        if (!gst_cdda_base_src_convert (src, GST_FORMAT_STREAMS,
                 src->num_tracks - start - 1, GST_FORMAT_TIME, &start_time)) {
           GST_DEBUG_OBJECT (src, "cannot convert track %d to time",
               (gint) start);
@@ -765,7 +800,7 @@ gst_cdda_base_src_handle_track_seek (Gst
 
     switch (stop_type) {
       case GST_SEEK_TYPE_SET:
-        if (!gst_cdda_base_src_convert (src, track_format, stop,
+        if (!gst_cdda_base_src_convert (src, GST_FORMAT_STREAMS, stop,
                 GST_FORMAT_TIME, &stop_time)) {
           GST_DEBUG_OBJECT (src, "cannot convert track %d to time",
               (gint) stop);
@@ -773,7 +808,7 @@ gst_cdda_base_src_handle_track_seek (Gst
         }
         break;
       case GST_SEEK_TYPE_END:
-        if (!gst_cdda_base_src_convert (src, track_format,
+        if (!gst_cdda_base_src_convert (src, GST_FORMAT_STREAMS,
                 src->num_tracks - stop - 1, GST_FORMAT_TIME, &stop_time)) {
           GST_DEBUG_OBJECT (src, "cannot convert track %d to time",
               (gint) stop);
@@ -825,16 +860,20 @@ gst_cdda_base_src_handle_track_seek (Gst
     src->cur_track = (gint) start;
     src->uri_track = -1;
     src->prev_track = -1;
+    if (!gst_cdda_base_src_convert (src, GST_FORMAT_STREAMS, start,
+        GST_FORMAT_TIME, &start_time))
+      return FALSE;
 
     gst_cdda_base_src_update_duration (src);
   } else {
+    start_time = 0;
     GST_DEBUG_OBJECT (src, "is current track, just seeking back to start");
   }
 
   /* send fake segment seek event in TIME format to
    * base class (so we get a newsegment etc.) */
   event = gst_event_new_seek (rate, GST_FORMAT_TIME, flags,
-      GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
+      GST_SEEK_TYPE_SET, start_time, GST_SEEK_TYPE_NONE, -1);
 
   return GST_BASE_SRC_CLASS (parent_class)->event (basesrc, event);
 }
@@ -864,11 +903,18 @@ gst_cdda_base_src_handle_event (GstBaseS
           &stop_type, &stop);
 
       if (format == sector_format) {
-        GST_DEBUG_OBJECT (src, "seek in sector format not supported");
-        break;
+        gint64 start_bytes, stop_bytes;
+
+        format = GST_FORMAT_BYTES;
+        gst_cdda_base_src_convert (src, sector_format, start,
+            GST_FORMAT_BYTES, &start_bytes);
+        gst_cdda_base_src_convert (src, sector_format, stop,
+            GST_FORMAT_BYTES, &stop_bytes);
+        event = gst_event_new_seek (1., GST_FORMAT_BYTES, flags,
+            start_type, start_bytes, stop_type, stop_bytes);
       }
 
-      if (format == track_format) {
+      if (format == GST_FORMAT_STREAMS) {
         ret = gst_cdda_base_src_handle_track_seek (src, rate, flags,
             start_type, start, stop_type, stop);
       } else {
@@ -962,7 +1008,7 @@ gst_cdda_base_src_uri_set_uri (GstURIHan
     GST_OBJECT_UNLOCK (src);
 
     gst_pad_send_event (GST_BASE_SRC_PAD (src),
-        gst_event_new_seek (1.0, track_format, GST_SEEK_FLAG_FLUSH,
+        gst_event_new_seek (1.0, GST_FORMAT_STREAMS, GST_SEEK_FLAG_FLUSH,
             GST_SEEK_TYPE_SET, src->uri_track - 1, GST_SEEK_TYPE_NONE, -1));
   } else {
     /* seek will be done in start() */
@@ -1297,7 +1343,7 @@ gst_cdda_base_src_add_index_associations
     gint64 sector;
 
     sector = src->tracks[i].start;
-    gst_index_add_association (src->index, src->index_id, GST_ASSOCIATION_FLAG_KEY_UNIT, track_format, i,       /* here we count from 0 */
+    gst_index_add_association (src->index, src->index_id, GST_ASSOCIATION_FLAG_KEY_UNIT, GST_FORMAT_STREAMS, i,       /* here we count from 0 */
         sector_format, sector,
         GST_FORMAT_TIME,
         (gint64) (((CD_FRAMESIZE_RAW >> 2) * sector * GST_SECOND) / 44100),
@@ -1314,7 +1360,7 @@ gst_cdda_base_src_set_index (GstElement 
   src->index = index;
 
   gst_index_get_writer_id (index, GST_OBJECT (src), &src->index_id);
-  gst_index_add_format (index, src->index_id, track_format);
+  gst_index_add_format (index, src->index_id, GST_FORMAT_STREAMS);
   gst_index_add_format (index, src->index_id, sector_format);
 }
 
