6 get_position_info (GstElement *cdparanoia)
8 GstFormat track_format;
9 const GstFormat *formats;
12 track_format = gst_format_get_by_nick ("track");
13 g_assert (track_format != 0);
15 pad = gst_element_get_pad (cdparanoia, "src");
16 formats = gst_pad_get_formats (pad);
19 const GstFormatDefinition *definition;
24 definition = gst_format_get_details (*formats);
27 res = gst_pad_query (pad, GST_QUERY_POSITION,
30 if (format == GST_FORMAT_TIME) {
31 position /= GST_SECOND;
32 g_print ("%s: %lld:%02lld", definition->nick, position/60, position%60);
35 g_print ("%s: %lld", definition->nick, position);
47 get_track_info (GstElement *cdparanoia)
49 GstFormat track_format;
50 gint64 total_tracks = 0, total_time = 0;
52 const GstFormat *formats;
54 gint64 time_count = 0;
56 track_format = gst_format_get_by_nick ("track");
57 g_assert (track_format != 0);
59 pad = gst_element_get_pad (cdparanoia, "src");
60 formats = gst_pad_get_formats (pad);
62 /* we loop over all supported formats and report the total
65 const GstFormatDefinition *definition;
70 definition = gst_format_get_details (*formats);
73 res = gst_pad_query (pad, GST_QUERY_TOTAL,
76 if (format == GST_FORMAT_TIME) {
78 g_print ("%s total: %lld:%02lld\n", definition->nick, total/60, total%60);
81 g_print ("%s total: %lld\n", definition->nick, total);
83 if (format == track_format)
85 else if (format == GST_FORMAT_TIME)
89 g_print ("failed to get %s total\n", definition->nick);
94 /* then we loop over all the tracks to get more info.
95 * since pad_convert always works from 0, the time from track 1 needs
96 * to be substracted from track 2 */
97 for (i = 0; i <= total_tracks; i++) {
101 if (i < total_tracks) {
104 format = GST_FORMAT_TIME;
105 res = gst_pad_convert (pad, track_format, i,
115 /* for the first track (i==0) we wait until we have the
116 * time of the next track */
118 gint64 length = time - time_count;
120 g_print ("track %d: %lld:%02lld -> %lld:%02lld, length: %lld:%02lld\n",
122 time_count / 60, time_count % 60,
123 time / 60, time % 60,
124 length / 60, length % 60);
128 g_print ("could not get time for track %d\n", i);
136 main (int argc, char **argv)
138 GstElement *pipeline;
139 GstElement *cdparanoia;
142 GstFormat track_format;
147 gst_init (&argc, &argv);
149 pipeline = gst_pipeline_new ("pipeline");
151 cdparanoia = gst_element_factory_make ("cdparanoia", "cdparanoia");
152 g_assert (cdparanoia);
153 g_object_set (G_OBJECT (cdparanoia), "paranoia_mode", 0, NULL);
155 osssink = gst_element_factory_make ("osssink", "osssink");
158 gst_bin_add (GST_BIN (pipeline), cdparanoia);
159 gst_bin_add (GST_BIN (pipeline), osssink);
161 gst_element_link_pads (cdparanoia, "src", osssink, "sink");
163 g_signal_connect (G_OBJECT (pipeline), "deep_notify",
164 G_CALLBACK (gst_element_default_deep_notify), NULL);
166 gst_element_set_state (pipeline, GST_STATE_PAUSED);
168 /* now we go into probe mode */
169 get_track_info (cdparanoia);
171 track_format = gst_format_get_by_nick ("track");
172 g_assert (track_format != 0);
174 pad = gst_element_get_pad (cdparanoia, "src");
177 g_print ("playing from track 3\n");
179 event = gst_event_new_seek (track_format |
180 GST_SEEK_METHOD_SET |
184 res = gst_pad_send_event (pad, event);
186 g_warning ("seek failed");
188 gst_element_set_state (pipeline, GST_STATE_PLAYING);
191 while (gst_bin_iterate (GST_BIN (pipeline))) {
192 get_position_info (cdparanoia);
196 gst_element_set_state (pipeline, GST_STATE_PAUSED);
198 g_print ("\nplaying from second 25 to second 29\n");
199 /* seek to some seconds */
200 event = gst_event_new_segment_seek (GST_FORMAT_TIME |
201 GST_SEEK_METHOD_SET |
203 25 * GST_SECOND, 29 * GST_SECOND);
204 res = gst_pad_send_event (pad, event);
206 g_warning ("seek failed");
208 gst_element_set_state (pipeline, GST_STATE_PLAYING);
210 while (gst_bin_iterate (GST_BIN (pipeline))) {
211 get_position_info (cdparanoia);
215 /* shutdown everything again */
216 gst_element_set_state (pipeline, GST_STATE_NULL);